4145851006569e046102c048da28860026623fc4
[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 class MachineFunction;
23 class MachineBasicBlock;
24 class MachineConstantPool;
25 class Value;
26 class GlobalValue;
27 class Function;
28
29 struct MachineCodeEmitter {
30   virtual ~MachineCodeEmitter() {}
31
32   /// startFunction - This callback is invoked when the specified function is
33   /// about to be code generated.
34   ///
35   virtual void startFunction(MachineFunction &F) {}
36   
37   /// finishFunction - This callback is invoked when the specified function has
38   /// finished code generation.
39   ///
40   virtual void finishFunction(MachineFunction &F) {}
41
42   /// emitConstantPool - This callback is invoked to output the constant pool
43   /// for the function.
44   virtual void emitConstantPool(MachineConstantPool *MCP) {}
45
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.
50   ///
51   virtual void startFunctionStub(const Function &F, unsigned StubSize) {}
52
53   /// finishFunctionStub - This callback is invoked to terminate a function
54   /// stub.
55   ///
56   virtual void *finishFunctionStub(const Function &F) { return 0; }
57
58   /// emitByte - This callback is invoked when a byte needs to be written to the
59   /// output stream.
60   ///
61   virtual void emitByte(unsigned char B) {}
62
63   /// emitWord - This callback is invoked when a word needs to be written to the
64   /// output stream.
65   ///
66   virtual void emitWord(unsigned W) = 0;
67
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.
74   ///
75   virtual uint64_t getGlobalValueAddress(GlobalValue *V) = 0;
76   virtual uint64_t getGlobalValueAddress(const std::string &Name) = 0;
77
78   // getConstantPoolEntryAddress - Return the address of the 'Index' entry in
79   // the constant pool that was last emitted with the 'emitConstantPool' method.
80   //
81   virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
82
83   // getCurrentPCValue - This returns the address that the next emitted byte
84   // will be output to.
85   //
86   virtual uint64_t getCurrentPCValue() = 0;
87
88   // forceCompilationOf - Force the compilation of the specified function, and
89   // return its address, because we REALLY need the address now.
90   //
91   // FIXME: This is JIT specific!
92   //
93   virtual uint64_t forceCompilationOf(Function *F) = 0;
94   
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.
98   ///
99   static MachineCodeEmitter *createDebugEmitter();
100
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.
104   ///
105   static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);
106 };
107
108 #endif