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;
21 struct MachineCodeEmitter {
22 virtual ~MachineCodeEmitter() {}
24 /// startFunction - This callback is invoked when the specified function is
25 /// about to be code generated.
27 virtual void startFunction(MachineFunction &F) {}
29 /// finishFunction - This callback is invoked when the specified function has
30 /// finished code generation.
32 virtual void finishFunction(MachineFunction &F) {}
34 /// emitConstantPool - This callback is invoked to output the constant pool
36 virtual void emitConstantPool(MachineConstantPool *MCP) {}
38 /// startBasicBlock - This callback is invoked when a new basic block is about
41 virtual void startBasicBlock(MachineBasicBlock &BB) {}
43 /// startFunctionStub - This callback is invoked when the JIT needs the
44 /// address of a function that has not been code generated yet. The StubSize
45 /// specifies the total size required by the stub. Stubs are not allowed to
46 /// have constant pools, the can only use the other emit* methods.
48 virtual void startFunctionStub(const Function &F, unsigned StubSize) {}
50 /// finishFunctionStub - This callback is invoked to terminate a function
53 virtual void *finishFunctionStub(const Function &F) { return 0; }
55 /// emitByte - This callback is invoked when a byte needs to be written to the
58 virtual void emitByte(unsigned char B) {}
60 /// emitPCRelativeDisp - This callback is invoked when we need to write out a
61 /// PC relative displacement for the specified Value*. This is used for call
62 /// and jump instructions typically.
64 virtual void emitPCRelativeDisp(Value *V) {}
66 /// emitGlobalAddress - This callback is invoked when we need to write out the
67 /// address of a global value to machine code. This is important for indirect
68 /// calls as well as accessing global variables.
70 virtual void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {}
71 virtual void emitGlobalAddress(const std::string &Name, bool isPCRelative) {}
73 /// emitFunctionConstantValueAddress - This callback is invoked when the
74 /// address of a constant, which was spilled to memory, needs to be addressed.
75 /// This is used for constants which cannot be directly specified as operands
76 /// to instructions, such as large integer values on the sparc, or floating
77 /// point constants on the X86.
79 virtual void emitFunctionConstantValueAddress(unsigned ConstantNum,
82 /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
83 /// code emitter, which just prints the opcodes and fields out the cout. This
84 /// can be used for debugging users of the MachineCodeEmitter interface.
86 static MachineCodeEmitter *createDebugMachineCodeEmitter();
88 /// createFilePrinterMachineCodeEmitter - Return a dynamically allocated
89 /// machine code emitter, which prints binary code to a file. This
90 /// can be used for debugging users of the MachineCodeEmitter interface.
92 static MachineCodeEmitter*
93 createFilePrinterMachineCodeEmitter(MachineCodeEmitter&);