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