new is not a valid default anywhere, so make this pure virtual
[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 "llvm/Support/DataTypes.h"
21
22 namespace llvm {
23
24 class MachineBasicBlock;
25 class MachineConstantPool;
26 class MachineFunction;
27 class MachineRelocation;
28 class Value;
29 class GlobalValue;
30 class Function;
31
32 class MachineCodeEmitter {
33 public:
34   virtual ~MachineCodeEmitter() {}
35
36   /// startFunction - This callback is invoked when the specified function is
37   /// about to be code generated.
38   ///
39   virtual void startFunction(MachineFunction &F) {}
40
41   /// finishFunction - This callback is invoked when the specified function has
42   /// finished code generation.
43   ///
44   virtual void finishFunction(MachineFunction &F) {}
45
46   /// emitConstantPool - This callback is invoked to output the constant pool
47   /// for the function.
48   virtual void emitConstantPool(MachineConstantPool *MCP) {}
49
50   /// startFunctionStub - This callback is invoked when the JIT needs the
51   /// address of a function that has not been code generated yet.  The StubSize
52   /// specifies the total size required by the stub.  Stubs are not allowed to
53   /// have constant pools, the can only use the other emit* methods.
54   ///
55   virtual void startFunctionStub(unsigned StubSize) {}
56
57   /// finishFunctionStub - This callback is invoked to terminate a function
58   /// stub.
59   ///
60   virtual void *finishFunctionStub(const Function *F) { return 0; }
61
62   /// emitByte - This callback is invoked when a byte needs to be written to the
63   /// output stream.
64   ///
65   virtual void emitByte(unsigned char B) {}
66
67   /// emitWordAt - This callback is invoked when a word needs to be written to
68   /// the output stream at a different position than the current PC (for
69   /// instance, when performing relocations).
70   ///
71   virtual void emitWordAt(unsigned W, unsigned *Ptr) {}
72
73   /// emitWord - This callback is invoked when a word needs to be written to the
74   /// output stream.
75   ///
76   virtual void emitWord(unsigned W) = 0;
77
78   /// getCurrentPCValue - This returns the address that the next emitted byte
79   /// will be output to.
80   ///
81   virtual uint64_t getCurrentPCValue() = 0;
82
83
84   /// getCurrentPCOffset - Return the offset from the start of the emitted
85   /// buffer that we are currently writing to.
86   virtual uint64_t getCurrentPCOffset() = 0;
87
88   /// addRelocation - Whenever a relocatable address is needed, it should be
89   /// noted with this interface.
90   virtual void addRelocation(const MachineRelocation &MR) = 0;
91
92   // getConstantPoolEntryAddress - Return the address of the 'Index' entry in
93   // the constant pool that was last emitted with the 'emitConstantPool' method.
94   //
95   virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
96
97   // allocateGlobal - Allocate some space for a global variable.
98   virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment) = 0;
99
100   /// createDebugEmitter - Return a dynamically allocated machine
101   /// code emitter, which just prints the opcodes and fields out the cout.  This
102   /// can be used for debugging users of the MachineCodeEmitter interface.
103   ///
104   static MachineCodeEmitter *createDebugEmitter();
105
106   /// createFilePrinterEmitter - Return a dynamically allocated
107   /// machine code emitter, which prints binary code to a file.  This
108   /// can be used for debugging users of the MachineCodeEmitter interface.
109   ///
110   static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);
111 };
112
113 } // End llvm namespace
114
115 #endif