2014-03-08 06:43:09 +08:00
|
|
|
//===-- llvm/CodeGen/ByteStreamer.h - ByteStreamer class --------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a class that can take bytes that would normally be
|
|
|
|
// streamed via the AsmPrinter.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
|
2014-03-08 06:43:09 +08:00
|
|
|
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "DIEHash.h"
|
2014-03-08 06:43:09 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2015-03-03 06:02:33 +08:00
|
|
|
#include "llvm/Support/LEB128.h"
|
|
|
|
#include <string>
|
2014-03-08 06:43:09 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class ByteStreamer {
|
|
|
|
public:
|
2014-03-08 06:53:36 +08:00
|
|
|
virtual ~ByteStreamer() {}
|
|
|
|
|
2014-03-08 06:43:09 +08:00
|
|
|
// For now we're just handling the calls we need for dwarf emission/hashing.
|
|
|
|
virtual void EmitInt8(uint8_t Byte, const Twine &Comment = "") = 0;
|
|
|
|
virtual void EmitSLEB128(uint64_t DWord, const Twine &Comment = "") = 0;
|
|
|
|
virtual void EmitULEB128(uint64_t DWord, const Twine &Comment = "") = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class APByteStreamer : public ByteStreamer {
|
|
|
|
private:
|
|
|
|
AsmPrinter &AP;
|
|
|
|
|
|
|
|
public:
|
|
|
|
APByteStreamer(AsmPrinter &Asm) : AP(Asm) {}
|
2014-03-08 14:31:39 +08:00
|
|
|
void EmitInt8(uint8_t Byte, const Twine &Comment) override {
|
2015-04-25 03:11:51 +08:00
|
|
|
AP.OutStreamer->AddComment(Comment);
|
2014-03-08 06:43:09 +08:00
|
|
|
AP.EmitInt8(Byte);
|
|
|
|
}
|
2014-03-08 14:31:39 +08:00
|
|
|
void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
|
2015-04-25 03:11:51 +08:00
|
|
|
AP.OutStreamer->AddComment(Comment);
|
2014-03-08 06:43:09 +08:00
|
|
|
AP.EmitSLEB128(DWord);
|
|
|
|
}
|
2014-03-08 14:31:39 +08:00
|
|
|
void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
|
2015-04-25 03:11:51 +08:00
|
|
|
AP.OutStreamer->AddComment(Comment);
|
2014-03-08 06:43:09 +08:00
|
|
|
AP.EmitULEB128(DWord);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class HashingByteStreamer : public ByteStreamer {
|
|
|
|
private:
|
|
|
|
DIEHash &Hash;
|
|
|
|
public:
|
|
|
|
HashingByteStreamer(DIEHash &H) : Hash(H) {}
|
2014-03-08 14:31:39 +08:00
|
|
|
void EmitInt8(uint8_t Byte, const Twine &Comment) override {
|
2014-03-08 06:43:09 +08:00
|
|
|
Hash.update(Byte);
|
|
|
|
}
|
2014-03-08 14:31:39 +08:00
|
|
|
void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
|
2014-03-08 06:43:09 +08:00
|
|
|
Hash.addSLEB128(DWord);
|
|
|
|
}
|
2014-03-08 14:31:39 +08:00
|
|
|
void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
|
2014-03-08 06:43:09 +08:00
|
|
|
Hash.addULEB128(DWord);
|
|
|
|
}
|
|
|
|
};
|
2015-03-03 06:02:33 +08:00
|
|
|
|
|
|
|
class BufferByteStreamer : public ByteStreamer {
|
|
|
|
private:
|
|
|
|
SmallVectorImpl<char> &Buffer;
|
|
|
|
SmallVectorImpl<std::string> &Comments;
|
|
|
|
|
2015-05-21 06:51:27 +08:00
|
|
|
/// \brief Only verbose textual output needs comments. This will be set to
|
|
|
|
/// true for that case, and false otherwise. If false, comments passed in to
|
|
|
|
/// the emit methods will be ignored.
|
|
|
|
bool GenerateComments;
|
|
|
|
|
2015-03-03 06:02:33 +08:00
|
|
|
public:
|
|
|
|
BufferByteStreamer(SmallVectorImpl<char> &Buffer,
|
2015-05-21 06:51:27 +08:00
|
|
|
SmallVectorImpl<std::string> &Comments,
|
|
|
|
bool GenerateComments)
|
|
|
|
: Buffer(Buffer), Comments(Comments), GenerateComments(GenerateComments) {}
|
2015-03-03 06:02:33 +08:00
|
|
|
void EmitInt8(uint8_t Byte, const Twine &Comment) override {
|
|
|
|
Buffer.push_back(Byte);
|
2015-05-21 06:51:27 +08:00
|
|
|
if (GenerateComments)
|
|
|
|
Comments.push_back(Comment.str());
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
|
|
|
void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
|
|
|
|
raw_svector_ostream OSE(Buffer);
|
|
|
|
encodeSLEB128(DWord, OSE);
|
2015-05-21 06:51:27 +08:00
|
|
|
if (GenerateComments)
|
|
|
|
Comments.push_back(Comment.str());
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
|
|
|
void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
|
|
|
|
raw_svector_ostream OSE(Buffer);
|
|
|
|
encodeULEB128(DWord, OSE);
|
2015-05-21 06:51:27 +08:00
|
|
|
if (GenerateComments)
|
|
|
|
Comments.push_back(Comment.str());
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-19 23:57:42 +08:00
|
|
|
} // namespace llvm
|
2014-03-08 06:43:09 +08:00
|
|
|
|
|
|
|
#endif
|