1 //===-- MachOEmitter.h - Target-independent Mach-O Emitter class ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef MACHOCODEEMITTER_H
11 #define MACHOCODEEMITTER_H
13 #include "MachOWriter.h"
14 #include "llvm/CodeGen/MachineCodeEmitter.h"
19 /// MachOCodeEmitter - This class is used by the MachOWriter to emit the code
20 /// for functions to the Mach-O file.
22 class MachOCodeEmitter : public MachineCodeEmitter {
25 /// Target machine description.
28 /// is64Bit/isLittleEndian - This information is inferred from the target
29 /// machine directly, indicating what header values and flags to set.
30 bool is64Bit, isLittleEndian;
32 const TargetAsmInfo *TAI;
34 /// Relocations - These are the relocations that the function needs, as
36 std::vector<MachineRelocation> Relocations;
38 /// CPLocations - This is a map of constant pool indices to offsets from the
39 /// start of the section for that constant pool index.
40 std::vector<uintptr_t> CPLocations;
42 /// CPSections - This is a map of constant pool indices to the MachOSection
43 /// containing the constant pool entry for that index.
44 std::vector<unsigned> CPSections;
46 /// JTLocations - This is a map of jump table indices to offsets from the
47 /// start of the section for that jump table index.
48 std::vector<uintptr_t> JTLocations;
50 /// MBBLocations - This vector is a mapping from MBB ID's to their address.
51 /// It is filled in by the StartMachineBasicBlock callback and queried by
52 /// the getMachineBasicBlockAddress callback.
53 std::vector<uintptr_t> MBBLocations;
56 MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM)
58 is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
59 isLittleEndian = TM.getTargetData()->isLittleEndian();
60 TAI = TM.getTargetAsmInfo();
63 virtual void startFunction(MachineFunction &MF);
64 virtual bool finishFunction(MachineFunction &MF);
66 virtual void addRelocation(const MachineRelocation &MR) {
67 Relocations.push_back(MR);
70 void emitConstantPool(MachineConstantPool *MCP);
71 void emitJumpTables(MachineJumpTableInfo *MJTI);
73 virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const {
74 assert(CPLocations.size() > Index && "CP not emitted!");
75 return CPLocations[Index];
77 virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const {
78 assert(JTLocations.size() > Index && "JT not emitted!");
79 return JTLocations[Index];
82 virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) {
83 if (MBBLocations.size() <= (unsigned)MBB->getNumber())
84 MBBLocations.resize((MBB->getNumber()+1)*2);
85 MBBLocations[MBB->getNumber()] = getCurrentPCOffset();
88 virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const {
89 assert(MBBLocations.size() > (unsigned)MBB->getNumber() &&
90 MBBLocations[MBB->getNumber()] && "MBB not emitted!");
91 return MBBLocations[MBB->getNumber()];
94 virtual uintptr_t getLabelAddress(uint64_t Label) const {
95 assert(0 && "get Label not implemented");
100 virtual void emitLabel(uint64_t LabelID) {
101 assert(0 && "emit Label not implemented");
105 virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { }
107 /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!
108 virtual void startGVStub(const GlobalValue* F, unsigned StubSize,
109 unsigned Alignment = 1) {
110 assert(0 && "JIT specific function called!");
113 virtual void startGVStub(const GlobalValue* F, void *Buffer,
115 assert(0 && "JIT specific function called!");
118 virtual void *finishGVStub(const GlobalValue* F) {
119 assert(0 && "JIT specific function called!");
124 }; // end class MachOCodeEmitter
126 } // end namespace llvm