1 //===-- ARMAsmBackend.cpp - ARM Assembler Backend -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Target/TargetAsmBackend.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/MCObjectFormat.h"
18 #include "llvm/MC/MCObjectWriter.h"
19 #include "llvm/MC/MCSectionELF.h"
20 #include "llvm/MC/MCSectionMachO.h"
21 #include "llvm/MC/MachObjectWriter.h"
22 #include "llvm/Support/ELF.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/Target/TargetRegistry.h"
26 #include "llvm/Target/TargetAsmBackend.h"
30 class ARMAsmBackend : public TargetAsmBackend {
32 ARMAsmBackend(const Target &T)
33 : TargetAsmBackend(T) {
36 bool MayNeedRelaxation(const MCInst &Inst) const;
38 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
40 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
42 unsigned getPointerSize() const {
47 bool ARMAsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
48 // FIXME: Thumb targets, different move constant targets..
52 void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
53 assert(0 && "ARMAsmBackend::RelaxInstruction() unimplemented");
57 bool ARMAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
58 assert(0 && "ARMAsmBackend::WriteNopData() unimplemented");
59 if ((Count % 4) != 0) {
60 // Fixme: % 2 for Thumb?
65 } // end anonymous namespace
68 // FIXME: This should be in a separate file.
69 // ELF is an ELF of course...
70 class ELFARMAsmBackend : public ARMAsmBackend {
71 MCELFObjectFormat Format;
74 Triple::OSType OSType;
75 ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
76 : ARMAsmBackend(T), OSType(_OSType) {
77 HasScatteredSymbols = true;
80 virtual const MCObjectFormat &getObjectFormat() const {
84 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
85 uint64_t Value) const;
87 bool isVirtualSection(const MCSection &Section) const {
88 const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
89 return SE.getType() == MCSectionELF::SHT_NOBITS;
92 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
93 return new ELFObjectWriter(OS, /*Is64Bit=*/false,
95 /*IsLittleEndian=*/true,
96 /*HasRelocationAddend=*/false);
100 // Fixme: can we raise this to share code between Darwin and ELF?
101 void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
102 uint64_t Value) const {
103 assert(0 && "ELFARMAsmBackend::ApplyFixup() unimplemented");
106 // FIXME: This should be in a separate file.
107 class DarwinARMAsmBackend : public ARMAsmBackend {
108 MCMachOObjectFormat Format;
111 DarwinARMAsmBackend(const Target &T)
113 HasScatteredSymbols = true;
114 assert(0 && "DarwinARMAsmBackend::DarwinARMAsmBackend() unimplemented");
117 virtual const MCObjectFormat &getObjectFormat() const {
121 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
122 uint64_t Value) const;
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);
131 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
132 return new MachObjectWriter(OS, /*Is64Bit=*/false);
135 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
140 void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
141 uint64_t Value) const {
142 assert(0 && "DarwinARMAsmBackend::ApplyFixup() unimplemented");
144 } // end anonymous namespace
146 TargetAsmBackend *llvm::createARMAsmBackend(const Target &T,
147 const std::string &TT) {
148 switch (Triple(TT).getOS()) {
150 return new DarwinARMAsmBackend(T);
151 case Triple::MinGW32:
154 assert(0 && "Windows not supported on ARM");
156 return new ELFARMAsmBackend(T, Triple(TT).getOS());