572772dde70ad1611a7e69d0ef2a73a1271029ce
[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   /// emitByte - This callback is invoked when a byte needs to be written to the
43   /// output stream.
44   ///
45   virtual void emitByte(unsigned char B) {}
46
47   /// emitPCRelativeDisp - This callback is invoked when we need to write out a
48   /// PC relative displacement for the specified Value*.  This is used for call
49   /// and jump instructions typically.
50   ///
51   virtual void emitPCRelativeDisp(Value *V) {}
52
53   /// emitGlobalAddress - This callback is invoked when we need to write out the
54   /// address of a global value to machine code.  This is important for indirect
55   /// calls as well as accessing global variables.
56   ///
57   virtual void emitGlobalAddress(GlobalValue *V, bool isPCRelative) {}
58   virtual void emitGlobalAddress(const std::string &Name, bool isPCRelative) {}
59
60   /// emitFunctionConstantValueAddress - This callback is invoked when the
61   /// address of a constant, which was spilled to memory, needs to be addressed.
62   /// This is used for constants which cannot be directly specified as operands
63   /// to instructions, such as large integer values on the sparc, or floating
64   /// point constants on the X86.
65   ///
66   virtual void emitFunctionConstantValueAddress(unsigned ConstantNum,
67                                                 int Offset) {}
68
69   /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
70   /// code emitter, which just prints the opcodes and fields out the cout.  This
71   /// can be used for debugging users of the MachineCodeEmitter interface.
72   ///
73   static MachineCodeEmitter *createDebugMachineCodeEmitter();
74 };
75
76 #endif