LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MachineCodeEmitter.h

Go to the documentation of this file.
00001 //===-- llvm/CodeGen/MachineCodeEmitter.h - Code emission -------*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines an abstract interface that is used by the machine code
00011 // emission framework to output the code.  This allows machine code emission to
00012 // be separated from concerns such as resolution of call targets, and where the
00013 // machine code will be written (memory or disk, f.e.).
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_CODEGEN_MACHINECODEEMITTER_H
00018 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
00019 
00020 #include "llvm/Support/DataTypes.h"
00021 
00022 namespace llvm {
00023 
00024 class MachineBasicBlock;
00025 class MachineConstantPool;
00026 class MachineFunction;
00027 class MachineRelocation;
00028 class Value;
00029 class GlobalValue;
00030 class Function;
00031 
00032 class MachineCodeEmitter {
00033 public:
00034   virtual ~MachineCodeEmitter() {}
00035 
00036   /// startFunction - This callback is invoked when the specified function is
00037   /// about to be code generated.
00038   ///
00039   virtual void startFunction(MachineFunction &F) {}
00040   
00041   /// finishFunction - This callback is invoked when the specified function has
00042   /// finished code generation.
00043   ///
00044   virtual void finishFunction(MachineFunction &F) {}
00045 
00046   /// emitConstantPool - This callback is invoked to output the constant pool
00047   /// for the function.
00048   virtual void emitConstantPool(MachineConstantPool *MCP) {}
00049 
00050   /// startFunctionStub - This callback is invoked when the JIT needs the
00051   /// address of a function that has not been code generated yet.  The StubSize
00052   /// specifies the total size required by the stub.  Stubs are not allowed to
00053   /// have constant pools, the can only use the other emit* methods.
00054   ///
00055   virtual void startFunctionStub(unsigned StubSize) {}
00056 
00057   /// finishFunctionStub - This callback is invoked to terminate a function
00058   /// stub.
00059   ///
00060   virtual void *finishFunctionStub(const Function *F) { return 0; }
00061 
00062   /// emitByte - This callback is invoked when a byte needs to be written to the
00063   /// output stream.
00064   ///
00065   virtual void emitByte(unsigned char B) {}
00066 
00067   /// emitWordAt - This callback is invoked when a word needs to be written to
00068   /// the output stream at a different position than the current PC (for
00069   /// instance, when performing relocations).
00070   ///
00071   virtual void emitWordAt(unsigned W, unsigned *Ptr) {}
00072 
00073   /// emitWord - This callback is invoked when a word needs to be written to the
00074   /// output stream.
00075   ///
00076   virtual void emitWord(unsigned W) = 0;
00077 
00078   /// getCurrentPCValue - This returns the address that the next emitted byte
00079   /// will be output to.
00080   ///
00081   virtual uint64_t getCurrentPCValue() = 0;
00082 
00083 
00084   /// getCurrentPCOffset - Return the offset from the start of the emitted
00085   /// buffer that we are currently writing to.
00086   virtual uint64_t getCurrentPCOffset() = 0;
00087 
00088   /// addRelocation - Whenever a relocatable address is needed, it should be
00089   /// noted with this interface.
00090   virtual void addRelocation(const MachineRelocation &MR) = 0;
00091   
00092   // getConstantPoolEntryAddress - Return the address of the 'Index' entry in
00093   // the constant pool that was last emitted with the 'emitConstantPool' method.
00094   //
00095   virtual uint64_t getConstantPoolEntryAddress(unsigned Index) = 0;
00096 
00097   /// createDebugEmitter - Return a dynamically allocated machine
00098   /// code emitter, which just prints the opcodes and fields out the cout.  This
00099   /// can be used for debugging users of the MachineCodeEmitter interface.
00100   ///
00101   static MachineCodeEmitter *createDebugEmitter();
00102 
00103   /// createFilePrinterEmitter - Return a dynamically allocated
00104   /// machine code emitter, which prints binary code to a file.  This
00105   /// can be used for debugging users of the MachineCodeEmitter interface.
00106   ///
00107   static MachineCodeEmitter *createFilePrinterEmitter(MachineCodeEmitter&);
00108 };
00109 
00110 } // End llvm namespace
00111 
00112 #endif