1 //===-- MachineCodeEmitter.cpp - Implement the MachineCodeEmitter itf -----===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the MachineCodeEmitter interface.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MachineCodeEmitter.h"
21 class FilePrinterEmitter : public MachineCodeEmitter {
24 MachineCodeEmitter &MCE;
29 FilePrinterEmitter(MachineCodeEmitter &M, std::ostream &os)
30 : o(os), MCE(M), counter(0) {
34 ~FilePrinterEmitter() {
40 actual.open("lli.actual.obj");
42 std::cerr << "Cannot open 'lli.actual.obj' for writing\n";
47 void startFunction(MachineFunction &F) {
48 // resolve any outstanding calls
51 void finishFunction(MachineFunction &F) {
52 MCE.finishFunction(F);
55 void emitConstantPool(MachineConstantPool *MCP) {
56 MCE.emitConstantPool(MCP);
58 void initJumpTableInfo(MachineJumpTableInfo *MJTI) {
59 MCE.initJumpTableInfo(MJTI);
61 void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
62 std::map<MachineBasicBlock*,uint64_t> &MBBM) {
63 MCE.emitJumpTableInfo(MJTI, MBBM);
66 void startFunctionStub(unsigned StubSize) {
67 MCE.startFunctionStub(StubSize);
70 void *finishFunctionStub(const Function *F) {
71 return MCE.finishFunctionStub(F);
74 void emitByte(unsigned char B) {
76 actual << B; actual.flush();
78 values[counter] = (unsigned int) B;
79 if (++counter % 4 == 0 && counter != 0) {
81 for (unsigned i=0; i<4; ++i) {
82 if (values[i] < 16) o << "0";
83 o << values[i] << " ";
86 o << std::dec << "\t";
87 for (unsigned i=0; i<4; ++i) {
88 for (int j=7; j>=0; --j) {
89 o << ((values[i] >> j) & 1);
97 for (unsigned i=0; i<4; ++i)
98 instr |= values[i] << (i*8);
100 o << "--- * --- * --- * --- * ---\n";
105 void emitWord(unsigned W) {
108 void emitWordAt(unsigned W, unsigned *Ptr) {
109 MCE.emitWordAt(W, Ptr);
111 uint64_t getConstantPoolEntryAddress(unsigned Num) {
112 return MCE.getConstantPoolEntryAddress(Num);
114 uint64_t getJumpTableEntryAddress(unsigned Num) {
115 return MCE.getJumpTableEntryAddress(Num);
117 virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment)
118 { return MCE.allocateGlobal(size, alignment); }
120 uint64_t getCurrentPCValue() {
121 return MCE.getCurrentPCValue();
123 uint64_t getCurrentPCOffset() {
124 return MCE.getCurrentPCOffset();
126 void addRelocation(const MachineRelocation &MR) {
127 return MCE.addRelocation(MR);
133 MachineCodeEmitter::createFilePrinterEmitter(MachineCodeEmitter &MCE) {
134 return new FilePrinterEmitter(MCE, std::cerr);