#ifndef LLVM_UNITTESTS_CODEGEN_TESTASMPRINTER_H
#define LLVM_UNITTESTS_CODEGEN_TESTASMPRINTER_H
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/MC/MCStreamer.h"
#include "gmock/gmock.h"
#include <memory>
namespace llvm {
class AsmPrinter;
class MCContext;
class Target;
class TargetMachine;
class MockMCStreamer : public MCStreamer {
public:
explicit MockMCStreamer(MCContext *Ctx);
~MockMCStreamer();
MOCK_METHOD2(emitSymbolAttribute,
bool(MCSymbol *Symbol, MCSymbolAttr Attribute));
MOCK_METHOD3(emitCommonSymbol,
void(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment));
MOCK_METHOD5(emitZerofill,
void(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment, SMLoc Loc));
MOCK_METHOD2(emitLabel, void(MCSymbol *Symbol, SMLoc Loc));
MOCK_METHOD2(emitIntValue, void(uint64_t Value, unsigned Size));
MOCK_METHOD3(emitValueImpl,
void(const MCExpr *Value, unsigned Size, SMLoc Loc));
MOCK_METHOD3(emitAbsoluteSymbolDiff,
void(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size));
MOCK_METHOD2(emitCOFFSecRel32, void(MCSymbol const *Symbol, uint64_t Offset));
};
class TestAsmPrinter {
std::unique_ptr<MCContext> MC;
MockMCStreamer *MS = nullptr; std::unique_ptr<TargetMachine> TM;
std::unique_ptr<AsmPrinter> Asm;
TestAsmPrinter();
llvm::Error init(const Target *TheTarget, StringRef TripleStr,
uint16_t DwarfVersion, dwarf::DwarfFormat DwarfFormat);
public:
static llvm::Expected<std::unique_ptr<TestAsmPrinter>>
create(const std::string &TripleStr, uint16_t DwarfVersion,
dwarf::DwarfFormat DwarfFormat);
~TestAsmPrinter();
void setDwarfUsesRelocationsAcrossSections(bool Enable);
AsmPrinter *getAP() const { return Asm.get(); }
AsmPrinter *releaseAP() { return Asm.release(); }
MCContext &getCtx() const { return *MC; }
MockMCStreamer &getMS() const { return *MS; }
};
}
#endif