7fa73e5f5d405a218871a70651ed3fb21871d3e3
[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 seperated 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 class MachineFunction;
15 class MachineBasicBlock;
16 class MachineConstantPool;
17 class Value;
18 class GlobalValue;
19
20 struct MachineCodeEmitter {
21   virtual ~MachineCodeEmitter() {}
22
23   /// startFunction - This callback is invoked when the specified function is
24   /// about to be code generated.
25   ///
26   virtual void startFunction(MachineFunction &F) {}
27   
28   /// finishFunction - This callback is invoked when the specified function has
29   /// finished code generation.
30   ///
31   virtual void finishFunction(MachineFunction &F) {}
32
33   /// emitConstantPool - This callback is invoked to output the constant pool
34   /// for the function.
35   virtual void emitConstantPool(MachineConstantPool *MCP) {}
36
37   /// startBasicBlock - This callback is invoked when a new basic block is about
38   /// to be emitted.
39   ///
40   virtual void startBasicBlock(MachineBasicBlock &BB) {}
41
42   /// startFunctionStub - This callback is invoked when the JIT needs the
43   /// address of a function that has not been code generated yet.  The StubSize
44   /// specifies the total size required by the stub.  Stubs are not allowed to
45   /// have constant pools, the can only use the other emit* methods.
46   ///
47   virtual void startFunctionStub(Function &F, unsigned StubSize) {}
48
49   /// finishFunctionStub - This callback is invoked to terminate a function
50   /// stub.
51   ///
52   virtual void finishFunctionStub(Function &F) {}
53
54   /// emitByte - This callback is invoked when a byte needs to be written to the
55   /// output stream.
56   ///
57   virtual void emitByte(unsigned char B) {}
58
59   /// emitPCRelativeDisp - This callback is invoked when we need to write out a
60   /// PC relative displacement for the specified Value*.  This is used for call
61   /// and jump instructions typically.
62   ///
63   virtual void emitPCRelativeDisp(Value *V) {}
64
65   /// emitGlobalAddress - This callback is invoked when we need to write out the
66   /// address of a global value to machine code.  This is important for indirect
67   /// calls as well as accessing global variables.
68   ///
69   virtual void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {}
70   virtual void emitGlobalAddress(const std::string &Name, bool isPCRelative) {}
71
72   /// emitFunctionConstantValueAddress - This callback is invoked when the
73   /// address of a constant, which was spilled to memory, needs to be addressed.
74   /// This is used for constants which cannot be directly specified as operands
75   /// to instructions, such as large integer values on the sparc, or floating
76   /// point constants on the X86.
77   ///
78   virtual void emitFunctionConstantValueAddress(unsigned ConstantNum,
79                                                 int Offset) {}
80
81   /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
82   /// code emitter, which just prints the opcodes and fields out the cout.  This
83   /// can be used for debugging users of the MachineCodeEmitter interface.
84   ///
85   static MachineCodeEmitter *createDebugMachineCodeEmitter();
86 };
87
88 #endif