1 //===-- MachineCodeEmitter.cpp - Implement the MachineCodeEmitter itf -----===//
3 // This file implements the MachineCodeEmitter interface.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/CodeGen/MachineCodeEmitter.h"
8 #include "llvm/CodeGen/MachineFunction.h"
9 #include "llvm/Function.h"
13 struct DebugMachineCodeEmitter : public MachineCodeEmitter {
14 void startFunction(MachineFunction &F) {
15 std::cout << "\n**** Writing machine code for function: "
16 << F.getFunction()->getName() << "\n";
18 void finishFunction(MachineFunction &F) {
21 void startBasicBlock(MachineBasicBlock &BB) {
22 std::cout << "\n--- Basic Block: " << BB.getBasicBlock()->getName()<<"\n";
25 void startFunctionStub(const Function &F, unsigned StubSize) {
26 std::cout << "\n--- Function stub for function: " << F.getName() << "\n";
28 void *finishFunctionStub(const Function &F) {
33 void emitByte(unsigned char B) {
34 std::cout << "0x" << std::hex << (unsigned int)B << std::dec << " ";
36 void emitPCRelativeDisp(Value *V) {
37 std::cout << "<disp %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> ";
39 void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {
40 std::cout << "<addr %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> ";
42 void emitGlobalAddress(const std::string &Name, bool isPCRelative) {
43 std::cout << "<addr %" << Name << ": 0xXX 0xXX 0xXX 0xXX> ";
46 void emitFunctionConstantValueAddress(unsigned ConstantNum, int Offset) {
47 std::cout << "<addr const#" << ConstantNum;
48 if (Offset) std::cout << " + " << Offset;
55 /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
56 /// code emitter, which just prints the opcodes and fields out the cout. This
57 /// can be used for debugging users of the MachineCodeEmitter interface.
59 MachineCodeEmitter *MachineCodeEmitter::createDebugMachineCodeEmitter() {
60 return new DebugMachineCodeEmitter();