"clang/lib/git@repo.hca.bsc.es:rferrer/llvm-epi-0.8.git" did not exist on "105dfb5a7236e34a2bc0c5ca5fcb81fd735bccf1"
Newer
Older
//===-- MachineCodeEmitter.cpp - Implement the MachineCodeEmitter itf -----===//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//===----------------------------------------------------------------------===//
//
// This file implements the MachineCodeEmitter interface.
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Function.h"
Misha Brukman
committed
#include <fstream>
#include <iostream>
namespace {
struct DebugMachineCodeEmitter : public MachineCodeEmitter {
void startFunction(MachineFunction &F) {
std::cout << "\n**** Writing machine code for function: "
<< F.getFunction()->getName() << "\n";
}
void finishFunction(MachineFunction &F) {
std::cout << "\n";
}
void startFunctionStub(unsigned StubSize) {
std::cout << "\n--- Function stub:\n";
void *finishFunctionStub(const Function *F) {
std::cout << "\n--- End of stub for Function\n";
void emitByte(unsigned char B) {
std::cout << "0x" << std::hex << (unsigned int)B << std::dec << " ";
}
void emitWord(unsigned W) {
std::cout << "0x" << std::hex << W << std::dec << " ";
void emitWordAt(unsigned W, unsigned *Ptr) {
std::cout << "0x" << std::hex << W << std::dec << " (at "
<< (void*) Ptr << ") ";
}
void addRelocation(const MachineRelocation &MR) {
std::cout << "<relocation> ";
}
virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment)
{ return 0; }
uint64_t getConstantPoolEntryAddress(unsigned Num) { return 0; }
uint64_t getCurrentPCValue() { return 0; }
uint64_t getCurrentPCOffset() { return 0; }
Misha Brukman
committed
class FilePrinterEmitter : public MachineCodeEmitter {
Misha Brukman
committed
std::ostream &o;
MachineCodeEmitter &MCE;
Misha Brukman
committed
unsigned counter;
unsigned values[4];
Misha Brukman
committed
public:
FilePrinterEmitter(MachineCodeEmitter &M, std::ostream &os)
Misha Brukman
committed
openActual();
}
Misha Brukman
committed
o << "\n";
actual.close();
}
void openActual() {
actual.open("lli.actual.obj");
Misha Brukman
committed
std::cerr << "Cannot open 'lli.actual.obj' for writing\n";
abort();
}
}
void startFunction(MachineFunction &F) {
// resolve any outstanding calls
Misha Brukman
committed
}
void finishFunction(MachineFunction &F) {
MCE.finishFunction(F);
Misha Brukman
committed
}
void emitConstantPool(MachineConstantPool *MCP) {
MCE.emitConstantPool(MCP);
}
void startFunctionStub(unsigned StubSize) {
MCE.startFunctionStub(StubSize);
Misha Brukman
committed
}
void *finishFunctionStub(const Function *F) {
return MCE.finishFunctionStub(F);
Misha Brukman
committed
}
Misha Brukman
committed
void emitByte(unsigned char B) {
actual << B; actual.flush();
Misha Brukman
committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
values[counter] = (unsigned int) B;
if (++counter % 4 == 0 && counter != 0) {
o << std::hex;
for (unsigned i=0; i<4; ++i) {
if (values[i] < 16) o << "0";
o << values[i] << " ";
}
o << std::dec << "\t";
for (unsigned i=0; i<4; ++i) {
for (int j=7; j>=0; --j) {
o << ((values[i] >> j) & 1);
}
o << " ";
}
o << "\n";
unsigned instr = 0;
for (unsigned i=0; i<4; ++i)
instr |= values[i] << (i*8);
o << "--- * --- * --- * --- * ---\n";
counter %= 4;
}
}
void emitWord(unsigned W) {
MCE.emitWord(W);
Misha Brukman
committed
}
void emitWordAt(unsigned W, unsigned *Ptr) {
MCE.emitWordAt(W, Ptr);
}
uint64_t getConstantPoolEntryAddress(unsigned Num) {
return MCE.getConstantPoolEntryAddress(Num);
}
virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment)
{ return MCE.allocateGlobal(size, alignment); }
uint64_t getCurrentPCValue() {
return MCE.getCurrentPCValue();
}
uint64_t getCurrentPCOffset() {
return MCE.getCurrentPCOffset();
}
void addRelocation(const MachineRelocation &MR) {
return MCE.addRelocation(MR);
}
Misha Brukman
committed
};
}
/// createDebugMachineCodeEmitter - Return a dynamically allocated machine
/// code emitter, which just prints the opcodes and fields out the cout. This
/// can be used for debugging users of the MachineCodeEmitter interface.
///
MachineCodeEmitter *
MachineCodeEmitter::createDebugEmitter() {
return new DebugMachineCodeEmitter();
}
MachineCodeEmitter *
MachineCodeEmitter::createFilePrinterEmitter(MachineCodeEmitter &MCE) {
return new FilePrinterEmitter(MCE, std::cerr);