blob: 72f6e2b4ce717a10cb2403a0f8ab19ad538d7297 [file] [log] [blame]
Jason W Kimd4d4f4f2010-09-30 02:17:26 +00001//===-- ARMAsmBackend.cpp - ARM Assembler Backend -------------------------===//
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#include "llvm/Target/TargetAsmBackend.h"
11#include "ARM.h"
12//FIXME: add #include "ARMFixupKinds.h"
13#include "llvm/ADT/Twine.h"
14#include "llvm/MC/ELFObjectWriter.h"
15#include "llvm/MC/MCAssembler.h"
16#include "llvm/MC/MCExpr.h"
Rafael Espindolaf230df92010-10-16 18:23:53 +000017#include "llvm/MC/MCObjectFormat.h"
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000018#include "llvm/MC/MCObjectWriter.h"
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000019#include "llvm/MC/MCSectionELF.h"
20#include "llvm/MC/MCSectionMachO.h"
21#include "llvm/MC/MachObjectWriter.h"
Wesley Peckeecb8582010-10-22 15:52:49 +000022#include "llvm/Support/ELF.h"
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000023#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/raw_ostream.h"
25#include "llvm/Target/TargetRegistry.h"
26#include "llvm/Target/TargetAsmBackend.h"
27using namespace llvm;
28
29namespace {
30class ARMAsmBackend : public TargetAsmBackend {
31public:
32 ARMAsmBackend(const Target &T)
Jim Grosbachf73fd722010-09-30 03:21:00 +000033 : TargetAsmBackend(T) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000034 }
35
36 bool MayNeedRelaxation(const MCInst &Inst) const;
37
38 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
39
40 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
Jim Grosbach3787a402010-09-30 17:45:51 +000041
42 unsigned getPointerSize() const {
43 return 4;
44 }
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000045};
46
47bool ARMAsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
48 // FIXME: Thumb targets, different move constant targets..
49 return false;
50}
51
52void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
53 assert(0 && "ARMAsmBackend::RelaxInstruction() unimplemented");
54 return;
55}
56
57bool ARMAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
58 assert(0 && "ARMAsmBackend::WriteNopData() unimplemented");
Jim Grosbachf73fd722010-09-30 03:21:00 +000059 if ((Count % 4) != 0) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000060 // Fixme: % 2 for Thumb?
61 return false;
62 }
63 return false;
Jim Grosbach87dc3aa2010-09-30 03:20:34 +000064}
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000065} // end anonymous namespace
66
67namespace {
68// FIXME: This should be in a separate file.
69// ELF is an ELF of course...
70class ELFARMAsmBackend : public ARMAsmBackend {
Rafael Espindolaf230df92010-10-16 18:23:53 +000071 MCELFObjectFormat Format;
72
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000073public:
74 Triple::OSType OSType;
75 ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
76 : ARMAsmBackend(T), OSType(_OSType) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000077 HasScatteredSymbols = true;
78 }
79
Rafael Espindolaf230df92010-10-16 18:23:53 +000080 virtual const MCObjectFormat &getObjectFormat() const {
81 return Format;
82 }
83
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000084 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
85 uint64_t Value) const;
86
87 bool isVirtualSection(const MCSection &Section) const {
88 const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
89 return SE.getType() == MCSectionELF::SHT_NOBITS;
90 }
91
92 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
93 return new ELFObjectWriter(OS, /*Is64Bit=*/false,
Wesley Peckeecb8582010-10-22 15:52:49 +000094 OSType, ELF::EM_ARM,
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000095 /*IsLittleEndian=*/true,
96 /*HasRelocationAddend=*/false);
97 }
98};
99
Jason W Kima4c27242010-09-30 14:58:19 +0000100// Fixme: can we raise this to share code between Darwin and ELF?
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000101void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
102 uint64_t Value) const {
103 assert(0 && "ELFARMAsmBackend::ApplyFixup() unimplemented");
104}
105
106// FIXME: This should be in a separate file.
107class DarwinARMAsmBackend : public ARMAsmBackend {
Rafael Espindolaf230df92010-10-16 18:23:53 +0000108 MCMachOObjectFormat Format;
109
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000110public:
111 DarwinARMAsmBackend(const Target &T)
112 : ARMAsmBackend(T) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000113 HasScatteredSymbols = true;
114 assert(0 && "DarwinARMAsmBackend::DarwinARMAsmBackend() unimplemented");
115 }
116
Rafael Espindolaf230df92010-10-16 18:23:53 +0000117 virtual const MCObjectFormat &getObjectFormat() const {
118 return Format;
119 }
120
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000121 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
122 uint64_t Value) const;
123
124 bool isVirtualSection(const MCSection &Section) const {
125 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
126 return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
127 SMO.getType() == MCSectionMachO::S_GB_ZEROFILL ||
128 SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
129 }
130
131 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
132 return new MachObjectWriter(OS, /*Is64Bit=*/false);
133 }
134
135 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
136 return false;
137 }
138};
139
140void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
141 uint64_t Value) const {
142 assert(0 && "DarwinARMAsmBackend::ApplyFixup() unimplemented");
143}
Jim Grosbachf73fd722010-09-30 03:21:00 +0000144} // end anonymous namespace
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000145
146TargetAsmBackend *llvm::createARMAsmBackend(const Target &T,
147 const std::string &TT) {
148 switch (Triple(TT).getOS()) {
149 case Triple::Darwin:
150 return new DarwinARMAsmBackend(T);
151 case Triple::MinGW32:
152 case Triple::Cygwin:
153 case Triple::Win32:
154 assert(0 && "Windows not supported on ARM");
155 default:
156 return new ELFARMAsmBackend(T, Triple(TT).getOS());
157 }
158}