Be a bit more efficient when processing the active and inactive
[oota-llvm.git] / include / llvm / CodeGen / MachineCodeEmitter.h
1 //===-- llvm/CodeGen/MachineCodeEmitter.h - Code emission -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
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.).
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_CODEGEN_MACHINECODEEMITTER_H
18 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
19
20 #include <string>
21 #include "Support/DataTypes.h"
22
23 namespace llvm {
24
25 class MachineFunction;
26 class MachineBasicBlock;
27 class MachineConstantPool;
28 class Value;
29 class GlobalValue;
30 class Function;
31
32 struct MachineCodeEmitter {
33   virtual ~MachineCodeEmitter() {}
34
35   /// startFunction - This callback is invoked when the specified function is
36   /// about to be code generated.
37   ///
38   virtual void startFunction(MachineFunction &F) {}
39   
40   /// finishFunction - This callback is invoked when the specified function has
41   /// finished code generation.
42   ///
43   virtual void finishFunction(MachineFunction &F) {}
44
45   /// emitConstantPool - This callback is invoked to output the constant pool
46   /// for the function.
47   virtual void emitConstantPool(MachineConstantPool *MCP) {}
48
49   /// startFunctionStub - This callback is invoked when the JIT needs the
50   /// address of a function that has not been code generated yet.  The StubSize
51   /// specifies the total size required by the stub.  Stubs are not allowed to
52   /// have constant pools, the can only use the other emit* methods.
53   ///
54   virtual void startFunctionStub(const Function &F, unsigned StubSize) {}
55
56   /// finishFunctionStub - This callback is invoked to terminate a function
57   /// stub.
58   ///
59   virtual void *finishFunctionStub(const Function &F) { return 0; }
60
61   /// emitByte - This callback is invoked when a byte needs to be written to the
62   /// output stream.
63   ///
64   virtual void emitByte(unsigned char B) {}
65
66   /// emitWordAt - This callback is invoked when a word needs to be written to
67   /// the output stream at a different position than the current PC (for
68   /// instance, when performing relocations).
69   ///
70   virtual void emitWordAt(unsigned W, unsigned *Ptr) {}
71
72   /// emitWord - This callback is invoked when a word needs to be written to the
73   /// output stream.
74   ///
75   virtual void emitWord(unsigned W) = 0;
76
77   /// getGlobalValueAddress - This method is used to get the address of the
78   /// specified global value.  In some cases, however, the address may not yet
79   /// be known at the point that the method is called (for example, getting the
80   /// address of a function which has not yet been code generated).  If this is
81   /// the case, the function returns zero, and the callee has to be able to
82   /// handle the situation.
83   ///
84   virtual uint64_t getGlobalValueAddress(GlobalValue *V) = 0;
85   virtual uint64_t getGlobalValueAddress(const std::string &Name) = 0;
86
87   // getConstantPoolEntryAddress - Return the address of the 'Index' entry in
88   // the constant pool that was last emitted with the 'emitConstantPool' method.
89   //
90   virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
91
92   // getCurrentPCValue - This returns the address that the next emitted byte
93   // will be output to.
94   //
95   virtual uint64_t getCurrentPCValue() = 0;
96
97   // forceCompilationOf - Force the compilation of the specified function, and
98   // return its address, because we REALLY need the address now.
99   //
100   // FIXME: This is JIT specific!
101   //
102   virtual uint64_t forceCompilationOf(Function *F) = 0;
103   
104   /// createDebugEmitter - Return a dynamically allocated machine
105   /// code emitter, which just prints the opcodes and fields out the cout.  This
106   /// can be used for debugging users of the MachineCodeEmitter interface.
107   ///
108   static MachineCodeEmitter *createDebugEmitter();
109
110   /// createFilePrinterEmitter - Return a dynamically allocated
111   /// machine code emitter, which prints binary code to a file.  This
112   /// can be used for debugging users of the MachineCodeEmitter interface.
113   ///
114   static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);
115 };
116
117 } // End llvm namespace
118
119 #endif