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/MCObjectWriter.h"
18 #include "llvm/MC/MCSectionCOFF.h"
19 #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"
29 class ARMAsmBackend : public TargetAsmBackend {
31 ARMAsmBackend(const Target &T)
32 : TargetAsmBackend(T) {
35 bool MayNeedRelaxation(const MCInst &Inst) const;
37 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
39 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
42 bool ARMAsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
43 // FIXME: Thumb targets, different move constant targets..
47 void ARMAsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
48 assert(0 && "ARMAsmBackend::RelaxInstruction() unimplemented");
52 bool ARMAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
53 assert(0 && "ARMAsmBackend::WriteNopData() unimplemented");
54 if ((Count % 4) != 0) {
55 // Fixme: % 2 for Thumb?
60 } // end anonymous namespace
63 // FIXME: This should be in a separate file.
64 // ELF is an ELF of course...
65 class ELFARMAsmBackend : public ARMAsmBackend {
67 Triple::OSType OSType;
68 ELFARMAsmBackend(const Target &T, Triple::OSType _OSType)
69 : ARMAsmBackend(T), OSType(_OSType) {
70 HasAbsolutizedSet = true;
71 HasScatteredSymbols = true;
74 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
75 uint64_t Value) const;
77 bool isVirtualSection(const MCSection &Section) const {
78 const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
79 return SE.getType() == MCSectionELF::SHT_NOBITS;
82 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
83 return new ELFObjectWriter(OS, /*Is64Bit=*/false,
85 /*IsLittleEndian=*/true,
86 /*HasRelocationAddend=*/false);
90 // Fixme: can we raise this to share code bet. Darwin and ELF?
91 void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
92 uint64_t Value) const {
93 assert(0 && "ELFARMAsmBackend::ApplyFixup() unimplemented");
96 // FIXME: This should be in a separate file.
97 class DarwinARMAsmBackend : public ARMAsmBackend {
99 DarwinARMAsmBackend(const Target &T)
101 HasAbsolutizedSet = true;
102 HasScatteredSymbols = true;
103 assert(0 && "DarwinARMAsmBackend::DarwinARMAsmBackend() unimplemented");
106 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
107 uint64_t Value) const;
109 bool isVirtualSection(const MCSection &Section) const {
110 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
111 return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
112 SMO.getType() == MCSectionMachO::S_GB_ZEROFILL ||
113 SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
116 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
117 return new MachObjectWriter(OS, /*Is64Bit=*/false);
120 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
125 void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
126 uint64_t Value) const {
127 assert(0 && "DarwinARMAsmBackend::ApplyFixup() unimplemented");
129 } // end anonymous namespace
131 TargetAsmBackend *llvm::createARMAsmBackend(const Target &T,
132 const std::string &TT) {
133 switch (Triple(TT).getOS()) {
135 return new DarwinARMAsmBackend(T);
136 case Triple::MinGW32:
139 assert(0 && "Windows not supported on ARM");
141 return new ELFARMAsmBackend(T, Triple(TT).getOS());