The word `separate' only has one `e'.
[oota-llvm.git] / include / llvm / CodeGen / MachineCodeEmitter.h
1 //===-- llvm/CodeGen/MachineCodeEmitter.h - Code emission -------*- C++ -*-===//
2 //
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.).
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CODEGEN_MACHINE_CODE_EMITTER_H
11 #define LLVM_CODEGEN_MACHINE_CODE_EMITTER_H
12
13 #include <string>
14 #include "Support/DataTypes.h"
15 class MachineFunction;
16 class MachineBasicBlock;
17 class MachineConstantPool;
18 class Value;
19 class GlobalValue;
20 class Function;
21
22 struct MachineCodeEmitter {
23   virtual ~MachineCodeEmitter() {}
24
25   /// startFunction - This callback is invoked when the specified function is
26   /// about to be code generated.
27   ///
28   virtual void startFunction(MachineFunction &F) {}
29   
30   /// finishFunction - This callback is invoked when the specified function has
31   /// finished code generation.
32   ///
33   virtual void finishFunction(MachineFunction &F) {}
34
35   /// emitConstantPool - This callback is invoked to output the constant pool
36   /// for the function.
37   virtual void emitConstantPool(MachineConstantPool *MCP) {}
38
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.
43   ///
44   virtual void startFunctionStub(const Function &F, unsigned StubSize) {}
45
46   /// finishFunctionStub - This callback is invoked to terminate a function
47   /// stub.
48   ///
49   virtual void *finishFunctionStub(const Function &F) { return 0; }
50
51   /// emitByte - This callback is invoked when a byte needs to be written to the
52   /// output stream.
53   ///
54   virtual void emitByte(unsigned char B) {}
55
56   /// emitWord - This callback is invoked when a word needs to be written to the
57   /// output stream.
58   ///
59   virtual void emitWord(unsigned W) = 0;
60
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.
67   ///
68   virtual uint64_t getGlobalValueAddress(GlobalValue *V) = 0;
69   virtual uint64_t getGlobalValueAddress(const std::string &Name) = 0;
70
71   // getConstantPoolEntryAddress - Return the address of the 'Index' entry in
72   // the constant pool that was last emitted with the 'emitConstantPool' method.
73   //
74   virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
75
76
77   // getCurrentPCValue - This returns the address that the next emitted byte
78   // will be output to.
79   //
80   virtual uint64_t getCurrentPCValue() = 0;
81
82   // forceCompilationOf - Force the compilation of the specified function, and
83   // return its address, because we REALLY need the address now.
84   //
85   // FIXME: This is JIT specific!
86   //
87   virtual uint64_t forceCompilationOf(Function *F) = 0;
88   
89
90   /// createDebugEmitter - Return a dynamically allocated machine
91   /// code emitter, which just prints the opcodes and fields out the cout.  This
92   /// can be used for debugging users of the MachineCodeEmitter interface.
93   ///
94   static MachineCodeEmitter *createDebugEmitter();
95
96   /// createFilePrinterEmitter - Return a dynamically allocated
97   /// machine code emitter, which prints binary code to a file.  This
98   /// can be used for debugging users of the MachineCodeEmitter interface.
99   ///
100   static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);
101 };
102
103 #endif