LLVM API Documentation

MachOCodeEmitter.h

Go to the documentation of this file.
00001 //===-- MachOEmitter.h - Target-independent Mach-O Emitter class ----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef MACHOCODEEMITTER_H
00011 #define MACHOCODEEMITTER_H
00012 
00013 #include "llvm/CodeGen/ObjectCodeEmitter.h"
00014 #include <map>
00015 
00016 namespace llvm {
00017 
00018 class MachOWriter;
00019 
00020 /// MachOCodeEmitter - This class is used by the MachOWriter to emit the code 
00021 /// for functions to the Mach-O file.
00022 
00023 class MachOCodeEmitter : public ObjectCodeEmitter {
00024   MachOWriter &MOW;
00025 
00026   /// Target machine description.
00027   TargetMachine &TM;
00028 
00029   /// is64Bit/isLittleEndian - This information is inferred from the target
00030   /// machine directly, indicating what header values and flags to set.
00031   bool is64Bit, isLittleEndian;
00032 
00033   const TargetAsmInfo *TAI;
00034 
00035   /// Relocations - These are the relocations that the function needs, as
00036   /// emitted.
00037   std::vector<MachineRelocation> Relocations;
00038 
00039   std::map<uint64_t, uintptr_t> Labels;
00040 
00041 public:
00042   MachOCodeEmitter(MachOWriter &mow, MachOSection &mos);
00043 
00044   virtual void startFunction(MachineFunction &MF);
00045   virtual bool finishFunction(MachineFunction &MF);
00046 
00047   virtual void addRelocation(const MachineRelocation &MR) {
00048     Relocations.push_back(MR);
00049   }
00050 
00051   void emitConstantPool(MachineConstantPool *MCP);
00052   void emitJumpTables(MachineJumpTableInfo *MJTI);
00053 
00054   virtual void emitLabel(uint64_t LabelID) {
00055     Labels[LabelID] = getCurrentPCOffset();
00056   }
00057 
00058   virtual uintptr_t getLabelAddress(uint64_t Label) const {
00059     return Labels.find(Label)->second;
00060   }
00061 
00062   virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { }
00063 
00064 }; // end class MachOCodeEmitter
00065 
00066 } // end namespace llvm
00067 
00068 #endif
00069