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 "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCSubtargetInfo.h"
16 
17 using namespace llvm;
18 
19 namespace {
20 
21 class ARMAsmBackend : public MCAsmBackend {
22   const MCSubtargetInfo *STI;
23   bool isThumbMode;    // Currently emitting Thumb code.
24   bool IsLittleEndian; // Big or little endian.
25 public:
ARMAsmBackend(const Target & T,StringRef TT,bool IsLittle)26   ARMAsmBackend(const Target &T, StringRef TT, bool IsLittle)
27       : MCAsmBackend(), STI(ARM_MC::createARMMCSubtargetInfo(TT, "", "")),
28         isThumbMode(TT.startswith("thumb")), IsLittleEndian(IsLittle) {}
29 
~ARMAsmBackend()30   ~ARMAsmBackend() override { delete STI; }
31 
getNumFixupKinds()32   unsigned getNumFixupKinds() const override {
33     return ARM::NumTargetFixupKinds;
34   }
35 
hasNOP()36   bool hasNOP() const { return (STI->getFeatureBits() & ARM::HasV6T2Ops) != 0; }
37 
38   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
39 
40   /// processFixupValue - Target hook to process the literal value of a fixup
41   /// if necessary.
42   void processFixupValue(const MCAssembler &Asm, const MCAsmLayout &Layout,
43                          const MCFixup &Fixup, const MCFragment *DF,
44                          const MCValue &Target, uint64_t &Value,
45                          bool &IsResolved) override;
46 
47   void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
48                   uint64_t Value, bool IsPCRel) const override;
49 
50   bool mayNeedRelaxation(const MCInst &Inst) const override;
51 
52   bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
53                             const MCRelaxableFragment *DF,
54                             const MCAsmLayout &Layout) const override;
55 
56   void relaxInstruction(const MCInst &Inst, MCInst &Res) const override;
57 
58   bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override;
59 
60   void handleAssemblerFlag(MCAssemblerFlag Flag) override;
61 
getPointerSize()62   unsigned getPointerSize() const { return 4; }
isThumb()63   bool isThumb() const { return isThumbMode; }
setIsThumb(bool it)64   void setIsThumb(bool it) { isThumbMode = it; }
isLittle()65   bool isLittle() const { return IsLittleEndian; }
66 };
67 } // end anonymous namespace
68 
69 #endif
70