1 //===-- llvm/CodeGen/MachineCodeEmitter.h - Code emission -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an abstract interface that is used by the machine code
11 // emission framework to output the code. This allows machine code emission to
12 // be separated from concerns such as resolution of call targets, and where the
13 // machine code will be written (memory or disk, f.e.).
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CODEGEN_MACHINECODEEMITTER_H
18 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
21 #include "Support/DataTypes.h"
22 class MachineFunction;
23 class MachineBasicBlock;
24 class MachineConstantPool;
29 struct MachineCodeEmitter {
30 virtual ~MachineCodeEmitter() {}
32 /// startFunction - This callback is invoked when the specified function is
33 /// about to be code generated.
35 virtual void startFunction(MachineFunction &F) {}
37 /// finishFunction - This callback is invoked when the specified function has
38 /// finished code generation.
40 virtual void finishFunction(MachineFunction &F) {}
42 /// emitConstantPool - This callback is invoked to output the constant pool
44 virtual void emitConstantPool(MachineConstantPool *MCP) {}
46 /// startFunctionStub - This callback is invoked when the JIT needs the
47 /// address of a function that has not been code generated yet. The StubSize
48 /// specifies the total size required by the stub. Stubs are not allowed to
49 /// have constant pools, the can only use the other emit* methods.
51 virtual void startFunctionStub(const Function &F, unsigned StubSize) {}
53 /// finishFunctionStub - This callback is invoked to terminate a function
56 virtual void *finishFunctionStub(const Function &F) { return 0; }
58 /// emitByte - This callback is invoked when a byte needs to be written to the
61 virtual void emitByte(unsigned char B) {}
63 /// emitWord - This callback is invoked when a word needs to be written to the
66 virtual void emitWord(unsigned W) = 0;
68 /// getGlobalValueAddress - This method is used to get the address of the
69 /// specified global value. In some cases, however, the address may not yet
70 /// be known at the point that the method is called (for example, getting the
71 /// address of a function which has not yet been code generated). If this is
72 /// the case, the function returns zero, and the callee has to be able to
73 /// handle the situation.
75 virtual uint64_t getGlobalValueAddress(GlobalValue *V) = 0;
76 virtual uint64_t getGlobalValueAddress(const std::string &Name) = 0;
78 // getConstantPoolEntryAddress - Return the address of the 'Index' entry in
79 // the constant pool that was last emitted with the 'emitConstantPool' method.
81 virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
83 // getCurrentPCValue - This returns the address that the next emitted byte
86 virtual uint64_t getCurrentPCValue() = 0;
88 // forceCompilationOf - Force the compilation of the specified function, and
89 // return its address, because we REALLY need the address now.
91 // FIXME: This is JIT specific!
93 virtual uint64_t forceCompilationOf(Function *F) = 0;
95 /// createDebugEmitter - Return a dynamically allocated machine
96 /// code emitter, which just prints the opcodes and fields out the cout. This
97 /// can be used for debugging users of the MachineCodeEmitter interface.
99 static MachineCodeEmitter *createDebugEmitter();
101 /// createFilePrinterEmitter - Return a dynamically allocated
102 /// machine code emitter, which prints binary code to a file. This
103 /// can be used for debugging users of the MachineCodeEmitter interface.
105 static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);