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 separated 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_MACHINECODEEMITTER_H
11 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
14 #include "Support/DataTypes.h"
15 class MachineFunction;
16 class MachineBasicBlock;
17 class MachineConstantPool;
22 struct MachineCodeEmitter {
23 virtual ~MachineCodeEmitter() {}
25 /// startFunction - This callback is invoked when the specified function is
26 /// about to be code generated.
28 virtual void startFunction(MachineFunction &F) {}
30 /// finishFunction - This callback is invoked when the specified function has
31 /// finished code generation.
33 virtual void finishFunction(MachineFunction &F) {}
35 /// emitConstantPool - This callback is invoked to output the constant pool
37 virtual void emitConstantPool(MachineConstantPool *MCP) {}
39 /// startFunctionStub - This callback is invoked when the JIT needs the
40 /// address of a function that has not been code generated yet. The StubSize
41 /// specifies the total size required by the stub. Stubs are not allowed to
42 /// have constant pools, the can only use the other emit* methods.
44 virtual void startFunctionStub(const Function &F, unsigned StubSize) {}
46 /// finishFunctionStub - This callback is invoked to terminate a function
49 virtual void *finishFunctionStub(const Function &F) { return 0; }
51 /// emitByte - This callback is invoked when a byte needs to be written to the
54 virtual void emitByte(unsigned char B) {}
56 /// emitWord - This callback is invoked when a word needs to be written to the
59 virtual void emitWord(unsigned W) = 0;
61 /// getGlobalValueAddress - This method is used to get the address of the
62 /// specified global value. In some cases, however, the address may not yet
63 /// be known at the point that the method is called (for example, getting the
64 /// address of a function which has not yet been code generated). If this is
65 /// the case, the function returns zero, and the callee has to be able to
66 /// handle the situation.
68 virtual uint64_t getGlobalValueAddress(GlobalValue *V) = 0;
69 virtual uint64_t getGlobalValueAddress(const std::string &Name) = 0;
71 // getConstantPoolEntryAddress - Return the address of the 'Index' entry in
72 // the constant pool that was last emitted with the 'emitConstantPool' method.
74 virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
76 // getCurrentPCValue - This returns the address that the next emitted byte
79 virtual uint64_t getCurrentPCValue() = 0;
81 // forceCompilationOf - Force the compilation of the specified function, and
82 // return its address, because we REALLY need the address now.
84 // FIXME: This is JIT specific!
86 virtual uint64_t forceCompilationOf(Function *F) = 0;
88 /// createDebugEmitter - Return a dynamically allocated machine
89 /// code emitter, which just prints the opcodes and fields out the cout. This
90 /// can be used for debugging users of the MachineCodeEmitter interface.
92 static MachineCodeEmitter *createDebugEmitter();
94 /// createFilePrinterEmitter - Return a dynamically allocated
95 /// machine code emitter, which prints binary code to a file. This
96 /// can be used for debugging users of the MachineCodeEmitter interface.
98 static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);