blob: 96ba68f1dbf2747904f6b436f7416683d2f447c6 [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
Bruno Cardoso Lopes752e9282009-07-06 06:40:51 +000013#include "llvm/CodeGen/ObjectCodeEmitter.h"
14#include <map>
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000015
16namespace llvm {
17
Bruno Cardoso Lopes752e9282009-07-06 06:40:51 +000018class MachOWriter;
19
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000020/// MachOCodeEmitter - This class is used by the MachOWriter to emit the code
21/// for functions to the Mach-O file.
22
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000023class MachOCodeEmitter : public ObjectCodeEmitter {
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000024 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 Lopesa321dcd2009-06-03 03:43:31 +000038
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000039 std::map<uint64_t, uintptr_t> Labels;
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000040
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000041public:
Bruno Cardoso Lopes752e9282009-07-06 06:40:51 +000042 MachOCodeEmitter(MachOWriter &mow, MachOSection &mos);
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000043
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 Lopes752e9282009-07-06 06:40:51 +000050
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000051 void emitConstantPool(MachineConstantPool *MCP);
52 void emitJumpTables(MachineJumpTableInfo *MJTI);
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000053
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000054 virtual void emitLabel(uint64_t LabelID) {
55 Labels[LabelID] = getCurrentPCOffset();
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000056 }
57
58 virtual uintptr_t getLabelAddress(uint64_t Label) const {
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +000059 return Labels.find(Label)->second;
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000060 }
61
62 virtual void setModuleInfo(llvm::MachineModuleInfo* MMI) { }
63
Bruno Cardoso Lopesa321dcd2009-06-03 03:43:31 +000064}; // end class MachOCodeEmitter
65
66} // end namespace llvm
67
68#endif
69