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 /// startFunctionStub - This callback is invoked when the JIT needs the
43 /// address of a function that has not been code generated yet. The StubSize
44 /// specifies the total size required by the stub. Stubs are not allowed to
45 /// have constant pools, the can only use the other emit* methods.
47 virtual void startFunctionStub(Function &F, unsigned StubSize) {}
49 /// finishFunctionStub - This callback is invoked to terminate a function
52 virtual void finishFunctionStub(Function &F) {}
54 /// emitByte - This callback is invoked when a byte needs to be written to the
57 virtual void emitByte(unsigned char B) {}
59 /// emitPCRelativeDisp - This callback is invoked when we need to write out a
60 /// PC relative displacement for the specified Value*. This is used for call
61 /// and jump instructions typically.
63 virtual void emitPCRelativeDisp(Value *V) {}
65 /// emitGlobalAddress - This callback is invoked when we need to write out the
66 /// address of a global value to machine code. This is important for indirect
67 /// calls as well as accessing global variables.
69 virtual void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {}
70 virtual void emitGlobalAddress(const std::string &Name, bool isPCRelative) {}
72 /// emitFunctionConstantValueAddress - This callback is invoked when the
73 /// address of a constant, which was spilled to memory, needs to be addressed.
74 /// This is used for constants which cannot be directly specified as operands
75 /// to instructions, such as large integer values on the sparc, or floating
76 /// point constants on the X86.
78 virtual void emitFunctionConstantValueAddress(unsigned ConstantNum,
81 /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
82 /// code emitter, which just prints the opcodes and fields out the cout. This
83 /// can be used for debugging users of the MachineCodeEmitter interface.
85 static MachineCodeEmitter *createDebugMachineCodeEmitter();