1 //===-- ARMAsmBackend.h - ARM Assembler Backend -----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
10 #define LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
11 
12 #include "MCTargetDesc/ARMFixupKinds.h"
13 #include "MCTargetDesc/ARMMCTargetDesc.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCSubtargetInfo.h"
16 #include "llvm/MC/TargetRegistry.h"
17 
18 namespace llvm {
19 
20 class ARMAsmBackend : public MCAsmBackend {
21   bool isThumbMode;    // Currently emitting Thumb code.
22 public:
23   ARMAsmBackend(const Target &T, bool isThumb, support::endianness Endian)
24       : MCAsmBackend(Endian), isThumbMode(isThumb) {}
25 
26   unsigned getNumFixupKinds() const override {
27     return ARM::NumTargetFixupKinds;
28   }
29 
30   bool hasNOP(const MCSubtargetInfo *STI) const {
31     return STI->getFeatureBits()[ARM::HasV6T2Ops];
32   }
33 
34   std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
35 
36   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
37 
38   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
39                              const MCValue &Target) override;
40 
41   unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
42                             const MCValue &Target, uint64_t Value,
43                             bool IsResolved, MCContext &Ctx,
44                             const MCSubtargetInfo *STI) const;
45 
46   void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
47                   const MCValue &Target, MutableArrayRef<char> Data,
48                   uint64_t Value, bool IsResolved,
49                   const MCSubtargetInfo *STI) const override;
50 
51   unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
52 
53   bool mayNeedRelaxation(const MCInst &Inst,
54                          const MCSubtargetInfo &STI) const override;
55 
56   const char *reasonForFixupRelaxation(const MCFixup &Fixup,
57                                        uint64_t Value) const;
58 
59   bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
60                             const MCRelaxableFragment *DF,
61                             const MCAsmLayout &Layout) const override;
62 
63   void relaxInstruction(MCInst &Inst,
64                         const MCSubtargetInfo &STI) const override;
65 
66   bool writeNopData(raw_ostream &OS, uint64_t Count,
67                     const MCSubtargetInfo *STI) const override;
68 
69   void handleAssemblerFlag(MCAssemblerFlag Flag) override;
70 
71   unsigned getPointerSize() const { return 4; }
72   bool isThumb() const { return isThumbMode; }
73   void setIsThumb(bool it) { isThumbMode = it; }
74 };
75 } // end namespace llvm
76 
77 #endif
78