1 //===-- ARMAsmBackend.h - ARM Assembler Backend -----------------*- C++ -*-===//
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 #ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
11 #define LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
12 
13 #include "MCTargetDesc/ARMFixupKinds.h"
14 #include "MCTargetDesc/ARMMCTargetDesc.h"
15 #include "llvm/MC/MCAsmBackend.h"
16 #include "llvm/MC/MCSubtargetInfo.h"
17 #include "llvm/Support/TargetRegistry.h"
18 
19 namespace llvm {
20 
21 class ARMAsmBackend : public MCAsmBackend {
22   // The STI from the target triple the MCAsmBackend was instantiated with
23   // note that MCFragments may have a different local STI that should be
24   // used in preference.
25   const MCSubtargetInfo &STI;
26   bool isThumbMode;    // Currently emitting Thumb code.
27 public:
ARMAsmBackend(const Target & T,const MCSubtargetInfo & STI,support::endianness Endian)28   ARMAsmBackend(const Target &T, const MCSubtargetInfo &STI,
29                 support::endianness Endian)
30       : MCAsmBackend(Endian), STI(STI),
31         isThumbMode(STI.getTargetTriple().isThumb()) {}
32 
getNumFixupKinds()33   unsigned getNumFixupKinds() const override {
34     return ARM::NumTargetFixupKinds;
35   }
36 
37   // FIXME: this should be calculated per fragment as the STI may be
38   // different.
hasNOP()39   bool hasNOP() const { return STI.getFeatureBits()[ARM::HasV6T2Ops]; }
40 
41   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
42 
43   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
44                              const MCValue &Target) override;
45 
46   unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
47                             const MCValue &Target, uint64_t Value,
48                             bool IsResolved, MCContext &Ctx,
49                             const MCSubtargetInfo *STI) const;
50 
51   void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
52                   const MCValue &Target, MutableArrayRef<char> Data,
53                   uint64_t Value, bool IsResolved,
54                   const MCSubtargetInfo *STI) const override;
55 
56   unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
57 
58   bool mayNeedRelaxation(const MCInst &Inst,
59                          const MCSubtargetInfo &STI) const override;
60 
61   const char *reasonForFixupRelaxation(const MCFixup &Fixup,
62                                        uint64_t Value) const;
63 
64   bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
65                             const MCRelaxableFragment *DF,
66                             const MCAsmLayout &Layout) const override;
67 
68   void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
69                         MCInst &Res) const override;
70 
71   bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
72 
73   void handleAssemblerFlag(MCAssemblerFlag Flag) override;
74 
getPointerSize()75   unsigned getPointerSize() const { return 4; }
isThumb()76   bool isThumb() const { return isThumbMode; }
setIsThumb(bool it)77   void setIsThumb(bool it) { isThumbMode = it; }
78 };
79 } // end namespace llvm
80 
81 #endif
82