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"
20 class FilePrinterEmitter : public MachineCodeEmitter {
23 MachineCodeEmitter &MCE;
28 FilePrinterEmitter(MachineCodeEmitter &M, std::ostream &os)
29 : o(os), MCE(M), counter(0) {
33 ~FilePrinterEmitter() {
39 actual.open("lli.actual.obj");
41 std::cerr << "Cannot open 'lli.actual.obj' for writing\n";
46 void startFunction(MachineFunction &F) {
47 // resolve any outstanding calls
50 void finishFunction(MachineFunction &F) {
51 MCE.finishFunction(F);
54 void emitConstantPool(MachineConstantPool *MCP) {
55 MCE.emitConstantPool(MCP);
57 void initJumpTableInfo(MachineJumpTableInfo *MJTI) {
58 MCE.initJumpTableInfo(MJTI);
60 void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
61 std::map<MachineBasicBlock*,uint64_t> &MBBM) {
62 MCE.emitJumpTableInfo(MJTI, MBBM);
65 void startFunctionStub(unsigned StubSize) {
66 MCE.startFunctionStub(StubSize);
69 void *finishFunctionStub(const Function *F) {
70 return MCE.finishFunctionStub(F);
73 void emitByte(unsigned char B) {
75 actual << B; actual.flush();
77 values[counter] = (unsigned int) B;
78 if (++counter % 4 == 0 && counter != 0) {
80 for (unsigned i=0; i<4; ++i) {
81 if (values[i] < 16) o << "0";
82 o << values[i] << " ";
85 o << std::dec << "\t";
86 for (unsigned i=0; i<4; ++i) {
87 for (int j=7; j>=0; --j) {
88 o << ((values[i] >> j) & 1);
96 for (unsigned i=0; i<4; ++i)
97 instr |= values[i] << (i*8);
99 o << "--- * --- * --- * --- * ---\n";
104 void emitWord(unsigned W) {
107 uint64_t getConstantPoolEntryAddress(unsigned Num) {
108 return MCE.getConstantPoolEntryAddress(Num);
110 uint64_t getJumpTableEntryAddress(unsigned Num) {
111 return MCE.getJumpTableEntryAddress(Num);
113 virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment)
114 { return MCE.allocateGlobal(size, alignment); }
116 uint64_t getCurrentPCValue() {
117 return MCE.getCurrentPCValue();
119 uint64_t getCurrentPCOffset() {
120 return MCE.getCurrentPCOffset();
122 void addRelocation(const MachineRelocation &MR) {
123 return MCE.addRelocation(MR);
129 MachineCodeEmitter::createFilePrinterEmitter(MachineCodeEmitter &MCE) {
130 return new FilePrinterEmitter(MCE, std::cerr);