1 //===-- llvm/CodeGen/MachineCodeEmitter.h - Code emission -------*- C++ -*-===//
3 // This file defines an abstract interface that is used by the machine code
4 // emission framework to output the code. This allows machine code emission to
5 // be seperated from concerns such as resolution of call targets, and where the
6 // machine code will be written (memory or disk, f.e.).
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CODEGEN_MACHINE_CODE_EMITTER_H
11 #define LLVM_CODEGEN_MACHINE_CODE_EMITTER_H
14 class MachineFunction;
15 class MachineBasicBlock;
16 class MachineConstantPool;
20 struct MachineCodeEmitter {
21 virtual ~MachineCodeEmitter() {}
23 /// startFunction - This callback is invoked when the specified function is
24 /// about to be code generated.
26 virtual void startFunction(MachineFunction &F) {}
28 /// finishFunction - This callback is invoked when the specified function has
29 /// finished code generation.
31 virtual void finishFunction(MachineFunction &F) {}
33 /// emitConstantPool - This callback is invoked to output the constant pool
35 virtual void emitConstantPool(MachineConstantPool *MCP) {}
37 /// startBasicBlock - This callback is invoked when a new basic block is about
40 virtual void startBasicBlock(MachineBasicBlock &BB) {}
42 /// emitByte - This callback is invoked when a byte needs to be written to the
45 virtual void emitByte(unsigned char B) {}
47 /// emitPCRelativeDisp - This callback is invoked when we need to write out a
48 /// PC relative displacement for the specified Value*. This is used for call
49 /// and jump instructions typically.
51 virtual void emitPCRelativeDisp(Value *V) {}
53 /// emitGlobalAddress - This callback is invoked when we need to write out the
54 /// address of a global value to machine code. This is important for indirect
55 /// calls as well as accessing global variables.
57 virtual void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {}
58 virtual void emitGlobalAddress(const std::string &Name, bool isPCRelative) {}
60 /// emitFunctionConstantValueAddress - This callback is invoked when the
61 /// address of a constant, which was spilled to memory, needs to be addressed.
62 /// This is used for constants which cannot be directly specified as operands
63 /// to instructions, such as large integer values on the sparc, or floating
64 /// point constants on the X86.
66 virtual void emitFunctionConstantValueAddress(unsigned ConstantNum,
69 /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
70 /// code emitter, which just prints the opcodes and fields out the cout. This
71 /// can be used for debugging users of the MachineCodeEmitter interface.
73 static MachineCodeEmitter *createDebugMachineCodeEmitter();