blob: c280706e488b0049e4f174e7f3a57e66cecfd79d [file] [log] [blame]
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +00001//===-- 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 Lopesa321dcd2009-06-03 03:43:31 +000014
15namespace 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 Lopesac57e6e2009-07-06 05:09:34 +000020class MachOCodeEmitter : public ObjectCodeEmitter {
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000021 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 Lopesa321dcd2009-06-03 03:43:31 +000035
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000036 std::map<uint64_t, uintptr_t> Labels;
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000037
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000038public:
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000039 MachOCodeEmitter(MachOWriter &mow, MachOSection &mos) :
40 ObjectCodeEmitter(&mos), MOW(mow), TM(MOW.TM) {
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000041 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 Lopesa321dcd2009-06-03 03:43:31 +000055
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000056 virtual void emitLabel(uint64_t LabelID) {
57 Labels[LabelID] = getCurrentPCOffset();
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000058 }
59
60 virtual uintptr_t getLabelAddress(uint64_t Label) const {
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000061 return Labels.find(Label)->second;
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000062 }
63
64 virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { }
65
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000066}; // end class MachOCodeEmitter
67
68} // end namespace llvm
69
70#endif
71