blob: df439a41b332ac942ce58fad7ab7fb3e8d9a00ec [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"
17#include "llvm/MC/MCObjectWriter.h"
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000018#include "llvm/MC/MCSectionELF.h"
19#include "llvm/MC/MCSectionMachO.h"
20#include "llvm/MC/MachObjectWriter.h"
21#include "llvm/Support/ErrorHandling.h"
22#include "llvm/Support/raw_ostream.h"
23#include "llvm/Target/TargetRegistry.h"
24#include "llvm/Target/TargetAsmBackend.h"
25using namespace llvm;
26
27namespace {
28class ARMAsmBackend : public TargetAsmBackend {
29public:
30 ARMAsmBackend(const Target &T)
Jim Grosbachf73fd722010-09-30 03:21:00 +000031 : TargetAsmBackend(T) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000032 }
33
34 bool MayNeedRelaxation(const MCInst &Inst) const;
35
36 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
37
38 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
Jim Grosbach3787a402010-09-30 17:45:51 +000039
40 unsigned getPointerSize() const {
41 return 4;
42 }
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000043};
44
45bool ARMAsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
46 // FIXME: Thumb targets, different move constant targets..
47 return false;
48}
49
50void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
51 assert(0 && "ARMAsmBackend::RelaxInstruction() unimplemented");
52 return;
53}
54
55bool ARMAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
56 assert(0 && "ARMAsmBackend::WriteNopData() unimplemented");
Jim Grosbachf73fd722010-09-30 03:21:00 +000057 if ((Count % 4) != 0) {
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000058 // Fixme: % 2 for Thumb?
59 return false;
60 }
61 return false;
Jim Grosbach87dc3aa2010-09-30 03:20:34 +000062}
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000063} // end anonymous namespace
64
65namespace {
66// FIXME: This should be in a separate file.
67// ELF is an ELF of course...
68class ELFARMAsmBackend : public ARMAsmBackend {
69public:
70 Triple::OSType OSType;
71 ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
72 : ARMAsmBackend(T), OSType(_OSType) {
73 HasAbsolutizedSet = true;
74 HasScatteredSymbols = true;
75 }
76
77 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
78 uint64_t Value) const;
79
80 bool isVirtualSection(const MCSection &Section) const {
81 const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
82 return SE.getType() == MCSectionELF::SHT_NOBITS;
83 }
84
85 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
86 return new ELFObjectWriter(OS, /*Is64Bit=*/false,
87 OSType,
88 /*IsLittleEndian=*/true,
89 /*HasRelocationAddend=*/false);
90 }
91};
92
Jason W Kima4c27242010-09-30 14:58:19 +000093// Fixme: can we raise this to share code between Darwin and ELF?
Jason W Kimd4d4f4f2010-09-30 02:17:26 +000094void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
95 uint64_t Value) const {
96 assert(0 && "ELFARMAsmBackend::ApplyFixup() unimplemented");
97}
98
99// FIXME: This should be in a separate file.
100class DarwinARMAsmBackend : public ARMAsmBackend {
101public:
102 DarwinARMAsmBackend(const Target &T)
103 : ARMAsmBackend(T) {
104 HasAbsolutizedSet = true;
105 HasScatteredSymbols = true;
106 assert(0 && "DarwinARMAsmBackend::DarwinARMAsmBackend() unimplemented");
107 }
108
109 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
110 uint64_t Value) const;
111
112 bool isVirtualSection(const MCSection &Section) const {
113 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
114 return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
115 SMO.getType() == MCSectionMachO::S_GB_ZEROFILL ||
116 SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
117 }
118
119 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
120 return new MachObjectWriter(OS, /*Is64Bit=*/false);
121 }
122
123 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
124 return false;
125 }
126};
127
128void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
129 uint64_t Value) const {
130 assert(0 && "DarwinARMAsmBackend::ApplyFixup() unimplemented");
131}
Jim Grosbachf73fd722010-09-30 03:21:00 +0000132} // end anonymous namespace
Jason W Kimd4d4f4f2010-09-30 02:17:26 +0000133
134TargetAsmBackend *llvm::createARMAsmBackend(const Target &T,
135 const std::string &TT) {
136 switch (Triple(TT).getOS()) {
137 case Triple::Darwin:
138 return new DarwinARMAsmBackend(T);
139 case Triple::MinGW32:
140 case Triple::Cygwin:
141 case Triple::Win32:
142 assert(0 && "Windows not supported on ARM");
143 default:
144 return new ELFARMAsmBackend(T, Triple(TT).getOS());
145 }
146}