6f47726de4699475445bf737204edc66ab6e6182
[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 class MachineFunction;
14 class MachineBasicBlock;
15 class Value;
16 class GlobalValue;
17
18 struct MachineCodeEmitter {
19   virtual ~MachineCodeEmitter() {}
20
21   /// startFunction - This callback is invoked when the specified function is
22   /// about to be code generated.
23   ///
24   virtual void startFunction(MachineFunction &F) {}
25   
26   /// finishFunction - This callback is invoked when the specified function has
27   /// finished code generation.
28   ///
29   virtual void finishFunction(MachineFunction &F) {}
30
31   /// startBasicBlock - This callback is invoked when a new basic block is about
32   /// to be emitted.
33   ///
34   virtual void startBasicBlock(MachineBasicBlock &BB) {}
35
36   /// emitByte - This callback is invoked when a byte needs to be written to the
37   /// output stream.
38   ///
39   virtual void emitByte(unsigned char B) {}
40
41   /// emitPCRelativeDisp - This callback is invoked when we need to write out a
42   /// PC relative displacement for the specified Value*.  This is used for call
43   /// and jump instructions typically.
44   ///
45   virtual void emitPCRelativeDisp(Value *V) {}
46
47   /// emitGlobalAddress - This callback is invoked when we need to write out the
48   /// address of a global value to machine code.  This is important for indirect
49   /// calls as well as accessing global variables.
50   ///
51   virtual void emitGlobalAddress(GlobalValue *V) {}
52
53
54   /// createDebugMachineCodeEmitter - Return a dynamically allocated machine
55   /// code emitter, which just prints the opcodes and fields out the cout.  This
56   /// can be used for debugging users of the MachineCodeEmitter interface.
57   ///
58   static MachineCodeEmitter *createDebugMachineCodeEmitter();
59 };
60
61 #endif