Chris Lattner | f815aeb | 2002-12-03 20:56:42 +0000 | [diff] [blame] | 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 emitByte(unsigned char B) { |
| 26 | std::cout << "0x" << std::hex << (unsigned int)B << std::dec << " "; |
| 27 | } |
| 28 | void emitPCRelativeDisp(Value *V) { |
Chris Lattner | b72d221 | 2002-12-04 06:44:41 +0000 | [diff] [blame] | 29 | std::cout << "<disp %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> "; |
| 30 | } |
Chris Lattner | 7775df1 | 2003-01-13 00:22:37 +0000 | [diff] [blame^] | 31 | void emitGlobalAddress(GlobalValue *V, bool isPCRelative) { |
Chris Lattner | b72d221 | 2002-12-04 06:44:41 +0000 | [diff] [blame] | 32 | std::cout << "<addr %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> "; |
Chris Lattner | f815aeb | 2002-12-03 20:56:42 +0000 | [diff] [blame] | 33 | } |
Chris Lattner | 7775df1 | 2003-01-13 00:22:37 +0000 | [diff] [blame^] | 34 | void emitGlobalAddress(const std::string &Name, bool isPCRelative) { |
| 35 | std::cout << "<addr %" << Name << ": 0xXX 0xXX 0xXX 0xXX> "; |
| 36 | } |
| 37 | |
| 38 | void emitFunctionConstantValueAddress(unsigned ConstantNum, int Offset) { |
| 39 | std::cout << "<addr const#" << ConstantNum; |
| 40 | if (Offset) std::cout << " + " << Offset; |
| 41 | std::cout << "> "; |
| 42 | } |
Chris Lattner | f815aeb | 2002-12-03 20:56:42 +0000 | [diff] [blame] | 43 | }; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /// createDebugMachineCodeEmitter - Return a dynamically allocated machine |
| 48 | /// code emitter, which just prints the opcodes and fields out the cout. This |
| 49 | /// can be used for debugging users of the MachineCodeEmitter interface. |
| 50 | /// |
| 51 | MachineCodeEmitter *MachineCodeEmitter::createDebugMachineCodeEmitter() { |
| 52 | return new DebugMachineCodeEmitter(); |
| 53 | } |