Add methods for stub function generation
[oota-llvm.git] / lib / CodeGen / MachineCodeEmitter.cpp
1 //===-- MachineCodeEmitter.cpp - Implement the MachineCodeEmitter itf -----===//
2 //
3 // This file implements the MachineCodeEmitter interface.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/CodeGen/MachineCodeEmitter.h"
8 #include "llvm/CodeGen/MachineFunction.h"
9 #include "llvm/Function.h"
10 #include <iostream>
11
12 namespace {
13   struct DebugMachineCodeEmitter : public MachineCodeEmitter {
14     void startFunction(MachineFunction &F) {
15       std::cout << "\n**** Writing machine code for function: "
16                 << F.getFunction()->getName() << "\n";
17     }
18     void finishFunction(MachineFunction &F) {
19       std::cout << "\n";
20     }
21     void startBasicBlock(MachineBasicBlock &BB) {
22       std::cout << "\n--- Basic Block: " << BB.getBasicBlock()->getName()<<"\n";
23     }
24
25     void startFunctionStub(Function &F, unsigned StubSize) {
26       std::cout << "\n--- Function stub for function: " << F.getName() << "\n";
27     }
28     void finishFunctionStub(Function &F) {
29       std::cout << "\n";
30     }
31     
32     void emitByte(unsigned char B) {
33       std::cout << "0x" << std::hex << (unsigned int)B << std::dec << " ";
34     }
35     void emitPCRelativeDisp(Value *V) {
36       std::cout << "<disp %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> ";
37     }
38     void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {
39       std::cout << "<addr %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> ";
40     }
41     void emitGlobalAddress(const std::string &Name, bool isPCRelative) {
42       std::cout << "<addr %" << Name << ": 0xXX 0xXX 0xXX 0xXX> ";
43     }
44
45     void emitFunctionConstantValueAddress(unsigned ConstantNum, int Offset) {
46       std::cout << "<addr const#" << ConstantNum;
47       if (Offset) std::cout << " + " << Offset;
48       std::cout << "> ";
49     }
50   };
51 }
52
53
54 /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
55 /// code emitter, which just prints the opcodes and fields out the cout.  This
56 /// can be used for debugging users of the MachineCodeEmitter interface.
57 ///
58 MachineCodeEmitter *MachineCodeEmitter::createDebugMachineCodeEmitter() {
59   return new DebugMachineCodeEmitter();
60 }