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