Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 1 | //===-- MachOEmitter.h - Target-independent Mach-O Emitter class ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef MACHOCODEEMITTER_H |
| 11 | #define MACHOCODEEMITTER_H |
| 12 | |
| 13 | #include "MachOWriter.h" |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 14 | |
| 15 | namespace llvm { |
| 16 | |
| 17 | /// MachOCodeEmitter - This class is used by the MachOWriter to emit the code |
| 18 | /// for functions to the Mach-O file. |
| 19 | |
Bruno Cardoso Lopes | ac57e6e | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 20 | class MachOCodeEmitter : public ObjectCodeEmitter { |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 21 | MachOWriter &MOW; |
| 22 | |
| 23 | /// Target machine description. |
| 24 | TargetMachine &TM; |
| 25 | |
| 26 | /// is64Bit/isLittleEndian - This information is inferred from the target |
| 27 | /// machine directly, indicating what header values and flags to set. |
| 28 | bool is64Bit, isLittleEndian; |
| 29 | |
| 30 | const TargetAsmInfo *TAI; |
| 31 | |
| 32 | /// Relocations - These are the relocations that the function needs, as |
| 33 | /// emitted. |
| 34 | std::vector<MachineRelocation> Relocations; |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 35 | |
Bruno Cardoso Lopes | ac57e6e | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 36 | std::map<uint64_t, uintptr_t> Labels; |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 37 | |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 38 | public: |
Bruno Cardoso Lopes | ac57e6e | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 39 | MachOCodeEmitter(MachOWriter &mow, MachOSection &mos) : |
| 40 | ObjectCodeEmitter(&mos), MOW(mow), TM(MOW.TM) { |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 41 | is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; |
| 42 | isLittleEndian = TM.getTargetData()->isLittleEndian(); |
| 43 | TAI = TM.getTargetAsmInfo(); |
| 44 | } |
| 45 | |
| 46 | virtual void startFunction(MachineFunction &MF); |
| 47 | virtual bool finishFunction(MachineFunction &MF); |
| 48 | |
| 49 | virtual void addRelocation(const MachineRelocation &MR) { |
| 50 | Relocations.push_back(MR); |
| 51 | } |
| 52 | |
| 53 | void emitConstantPool(MachineConstantPool *MCP); |
| 54 | void emitJumpTables(MachineJumpTableInfo *MJTI); |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 55 | |
Bruno Cardoso Lopes | ac57e6e | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 56 | virtual void emitLabel(uint64_t LabelID) { |
| 57 | Labels[LabelID] = getCurrentPCOffset(); |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | virtual uintptr_t getLabelAddress(uint64_t Label) const { |
Bruno Cardoso Lopes | ac57e6e | 2009-07-06 05:09:34 +0000 | [diff] [blame] | 61 | return Labels.find(Label)->second; |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { } |
| 65 | |
Bruno Cardoso Lopes | a321dcd | 2009-06-03 03:43:31 +0000 | [diff] [blame] | 66 | }; // end class MachOCodeEmitter |
| 67 | |
| 68 | } // end namespace llvm |
| 69 | |
| 70 | #endif |
| 71 | |