1 //===-- llvm/MC/MCAsmBackend.h - MC Asm Backend -----------------*- C++ -*-===//
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 #ifndef LLVM_MC_MCASMBACKEND_H
11 #define LLVM_MC_MCASMBACKEND_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/MC/MCDirectives.h"
15 #include "llvm/MC/MCDwarf.h"
16 #include "llvm/MC/MCFixup.h"
17 #include "llvm/Support/DataTypes.h"
18 #include "llvm/Support/ErrorHandling.h"
23 class MCELFObjectTargetWriter;
24 struct MCFixupKindInfo;
27 class MCRelaxableFragment;
33 /// MCAsmBackend - Generic interface to target specific assembler backends.
35 MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
36 void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
38 protected: // Can only create subclasses.
41 unsigned HasDataInCodeSupport : 1;
44 virtual ~MCAsmBackend();
46 /// lifetime management
47 virtual void reset() {}
49 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
50 /// assembler backend to emit the final object file.
51 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
53 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
54 /// non-standard ELFObjectWriters.
55 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
56 llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
60 /// hasDataInCodeSupport - Check whether this target implements data-in-code
61 /// markers. If not, data region directives will be ignored.
62 bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
64 /// @name Target Fixup Interfaces
67 /// getNumFixupKinds - Get the number of target specific fixup kinds.
68 virtual unsigned getNumFixupKinds() const = 0;
70 /// getFixupKindInfo - Get information on a fixup kind.
71 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
73 /// processFixupValue - Target hook to adjust the literal value of a fixup
74 /// if necessary. IsResolved signals whether the caller believes a relocation
75 /// is needed; the target can modify the value. The default does nothing.
76 virtual void processFixupValue(const MCAssembler &Asm,
77 const MCAsmLayout &Layout,
78 const MCFixup &Fixup, const MCFragment *DF,
79 const MCValue &Target, uint64_t &Value,
82 /// applyFixup - Apply the \p Value for given \p Fixup into the provided
83 /// data fragment, at the offset specified by the fixup and following the
84 /// fixup kind as appropriate.
85 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
86 uint64_t Value, bool IsPCRel) const = 0;
90 /// @name Target Relaxation Interfaces
93 /// mayNeedRelaxation - Check whether the given instruction may need
96 /// \param Inst - The instruction to test.
97 virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
99 /// fixupNeedsRelaxation - Target specific predicate for whether a given
100 /// fixup requires the associated instruction to be relaxed.
101 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
102 const MCRelaxableFragment *DF,
103 const MCAsmLayout &Layout) const = 0;
105 /// RelaxInstruction - Relax the instruction in the given fragment to the next
106 /// wider instruction.
108 /// \param Inst The instruction to relax, which may be the same as the
110 /// \param [out] Res On return, the relaxed instruction.
111 virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
115 /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
116 /// target. The assembler will use this to emit excess padding in situations
117 /// where the padding required for simple alignment would be less than the
118 /// minimum nop size.
120 virtual unsigned getMinimumNopSize() const { return 1; }
122 /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
123 /// output. If the target cannot generate such a sequence, it should return an
126 /// \return - True on success.
127 virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
129 /// handleAssemblerFlag - Handle any target-specific assembler flags.
130 /// By default, do nothing.
131 virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
133 /// \brief Generate the compact unwind encoding for the CFI instructions.
135 generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
140 } // End llvm namespace