From 47478b4dce9578b52240dbf12a65a38f5ff1ebb1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 3 Dec 2002 20:56:42 +0000 Subject: [PATCH] Checkin debug implementation of MCE llvm-svn: 4893 --- lib/CodeGen/MachineCodeEmitter.cpp | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/CodeGen/MachineCodeEmitter.cpp diff --git a/lib/CodeGen/MachineCodeEmitter.cpp b/lib/CodeGen/MachineCodeEmitter.cpp new file mode 100644 index 00000000000..e2b4908c742 --- /dev/null +++ b/lib/CodeGen/MachineCodeEmitter.cpp @@ -0,0 +1,41 @@ +//===-- MachineCodeEmitter.cpp - Implement the MachineCodeEmitter itf -----===// +// +// This file implements the MachineCodeEmitter interface. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/MachineCodeEmitter.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/Function.h" +#include + +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 startBasicBlock(MachineBasicBlock &BB) { + std::cout << "\n--- Basic Block: " << BB.getBasicBlock()->getName()<<"\n"; + } + + void emitByte(unsigned char B) { + std::cout << "0x" << std::hex << (unsigned int)B << std::dec << " "; + } + void emitPCRelativeDisp(Value *V) { + std::cout << "<" << V->getName() << ": 0xXX 0xXX 0xXX 0xXX> "; + } + }; +} + + +/// 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::createDebugMachineCodeEmitter() { + return new DebugMachineCodeEmitter(); +}