blob: d113cf5b9ec3897e051400414aa77c10fe1d0ec1 [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"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/raw_ostream.h"
24#include "llvm/Target/TargetRegistry.h"
25#include "llvm/Target/TargetAsmBackend.h"
26using namespace llvm;
27
28namespace {
29class ARMAsmBackend : public TargetAsmBackend {
30public:
31 ARMAsmBackend(const Target &T)
Jim Grosbachf73fd722010-09-30 03:21:00 +000032 : TargetAsmBackend(T) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000033 }
34
35 bool MayNeedRelaxation(const MCInst &Inst) const;
36
37 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
38
39 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
Jim Grosbach3787a402010-09-30 17:45:51 +000040
41 unsigned getPointerSize() const {
42 return 4;
43 }
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000044};
45
46bool ARMAsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
47 // FIXME: Thumb targets, different move constant targets..
48 return false;
49}
50
51void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
52 assert(0 && "ARMAsmBackend::RelaxInstruction() unimplemented");
53 return;
54}
55
56bool ARMAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
57 assert(0 && "ARMAsmBackend::WriteNopData() unimplemented");
Jim Grosbachf73fd722010-09-30 03:21:00 +000058 if ((Count % 4) != 0) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000059 // Fixme: % 2 for Thumb?
60 return false;
61 }
62 return false;
Jim Grosbach87dc3aa2010-09-30 03:20:34 +000063}
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000064} // end anonymous namespace
65
66namespace {
67// FIXME: This should be in a separate file.
68// ELF is an ELF of course...
69class ELFARMAsmBackend : public ARMAsmBackend {
Rafael Espindolaf230df92010-10-16 18:23:53 +000070 MCELFObjectFormat Format;
71
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000072public:
73 Triple::OSType OSType;
74 ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
75 : ARMAsmBackend(T), OSType(_OSType) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000076 HasScatteredSymbols = true;
77 }
78
Rafael Espindolaf230df92010-10-16 18:23:53 +000079 virtual const MCObjectFormat &getObjectFormat() const {
80 return Format;
81 }
82
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000083 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
84 uint64_t Value) const;
85
86 bool isVirtualSection(const MCSection &Section) const {
87 const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
88 return SE.getType() == MCSectionELF::SHT_NOBITS;
89 }
90
91 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
92 return new ELFObjectWriter(OS, /*Is64Bit=*/false,
93 OSType,
94 /*IsLittleEndian=*/true,
95 /*HasRelocationAddend=*/false);
96 }
97};
98
Jason W Kima4c27242010-09-30 14:58:19 +000099// Fixme: can we raise this to share code between Darwin and ELF?
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000100void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
101 uint64_t Value) const {
102 assert(0 && "ELFARMAsmBackend::ApplyFixup() unimplemented");
103}
104
105// FIXME: This should be in a separate file.
106class DarwinARMAsmBackend : public ARMAsmBackend {
Rafael Espindolaf230df92010-10-16 18:23:53 +0000107 MCMachOObjectFormat Format;
108
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000109public:
110 DarwinARMAsmBackend(const Target &T)
111 : ARMAsmBackend(T) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000112 HasScatteredSymbols = true;
113 assert(0 && "DarwinARMAsmBackend::DarwinARMAsmBackend() unimplemented");
114 }
115
Rafael Espindolaf230df92010-10-16 18:23:53 +0000116 virtual const MCObjectFormat &getObjectFormat() const {
117 return Format;
118 }
119
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000120 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
121 uint64_t Value) const;
122
123 bool isVirtualSection(const MCSection &Section) const {
124 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
125 return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
126 SMO.getType() == MCSectionMachO::S_GB_ZEROFILL ||
127 SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
128 }
129
130 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
131 return new MachObjectWriter(OS, /*Is64Bit=*/false);
132 }
133
134 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
135 return false;
136 }
137};
138
139void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
140 uint64_t Value) const {
141 assert(0 && "DarwinARMAsmBackend::ApplyFixup() unimplemented");
142}
Jim Grosbachf73fd722010-09-30 03:21:00 +0000143} // end anonymous namespace
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000144
145TargetAsmBackend *llvm::createARMAsmBackend(const Target &T,
146 const std::string &TT) {
147 switch (Triple(TT).getOS()) {
148 case Triple::Darwin:
149 return new DarwinARMAsmBackend(T);
150 case Triple::MinGW32:
151 case Triple::Cygwin:
152 case Triple::Win32:
153 assert(0 && "Windows not supported on ARM");
154 default:
155 return new ELFARMAsmBackend(T, Triple(TT).getOS());
156 }
157}