blob: d91efe2cc1b5bcf8d99c5815410e3006876c9a00 [file] [log] [blame]
Chris Lattnerf815aeb2002-12-03 20:56:42 +00001//===-- 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
12namespace {
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 }
Chris Lattnerfd33fb82003-05-08 21:54:18 +000024
Chris Lattnere0e72172003-05-09 03:27:41 +000025 void startFunctionStub(const Function &F, unsigned StubSize) {
Chris Lattnerfd33fb82003-05-08 21:54:18 +000026 std::cout << "\n--- Function stub for function: " << F.getName() << "\n";
27 }
Chris Lattnere0e72172003-05-09 03:27:41 +000028 void *finishFunctionStub(const Function &F) {
Chris Lattnerfd33fb82003-05-08 21:54:18 +000029 std::cout << "\n";
Chris Lattnere0e72172003-05-09 03:27:41 +000030 return 0;
Chris Lattnerfd33fb82003-05-08 21:54:18 +000031 }
Chris Lattnerf815aeb2002-12-03 20:56:42 +000032
33 void emitByte(unsigned char B) {
34 std::cout << "0x" << std::hex << (unsigned int)B << std::dec << " ";
35 }
36 void emitPCRelativeDisp(Value *V) {
Chris Lattnerb72d2212002-12-04 06:44:41 +000037 std::cout << "<disp %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> ";
38 }
Chris Lattner7775df12003-01-13 00:22:37 +000039 void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {
Chris Lattnerb72d2212002-12-04 06:44:41 +000040 std::cout << "<addr %" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> ";
Chris Lattnerf815aeb2002-12-03 20:56:42 +000041 }
Chris Lattner7775df12003-01-13 00:22:37 +000042 void emitGlobalAddress(const std::string &Name, bool isPCRelative) {
43 std::cout << "<addr %" << Name << ": 0xXX 0xXX 0xXX 0xXX> ";
44 }
45
46 void emitFunctionConstantValueAddress(unsigned ConstantNum, int Offset) {
47 std::cout << "<addr const#" << ConstantNum;
48 if (Offset) std::cout << " + " << Offset;
49 std::cout << "> ";
50 }
Chris Lattnerf815aeb2002-12-03 20:56:42 +000051 };
52}
53
54
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.
58///
59MachineCodeEmitter *MachineCodeEmitter::createDebugMachineCodeEmitter() {
60 return new DebugMachineCodeEmitter();
61}