]> git.proxmox.com Git - rustc.git/blame - src/llvm/include/llvm/MC/MCAsmBackend.h
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / include / llvm / MC / MCAsmBackend.h
CommitLineData
1a4d82fc 1//===-- llvm/MC/MCAsmBackend.h - MC Asm Backend -----------------*- C++ -*-===//
223e47cc
LB
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_MC_MCASMBACKEND_H
11#define LLVM_MC_MCASMBACKEND_H
12
1a4d82fc 13#include "llvm/ADT/ArrayRef.h"
223e47cc 14#include "llvm/MC/MCDirectives.h"
1a4d82fc 15#include "llvm/MC/MCDwarf.h"
223e47cc
LB
16#include "llvm/MC/MCFixup.h"
17#include "llvm/Support/DataTypes.h"
18#include "llvm/Support/ErrorHandling.h"
19
20namespace llvm {
21class MCAsmLayout;
22class MCAssembler;
23class MCELFObjectTargetWriter;
24struct MCFixupKindInfo;
25class MCFragment;
26class MCInst;
970d7e83 27class MCRelaxableFragment;
223e47cc
LB
28class MCObjectWriter;
29class MCSection;
30class MCValue;
31class raw_ostream;
32
33/// MCAsmBackend - Generic interface to target specific assembler backends.
34class MCAsmBackend {
35 MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
36 void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
1a4d82fc 37
223e47cc
LB
38protected: // Can only create subclasses.
39 MCAsmBackend();
40
970d7e83 41 unsigned HasDataInCodeSupport : 1;
223e47cc
LB
42
43public:
44 virtual ~MCAsmBackend();
45
970d7e83 46 /// lifetime management
1a4d82fc 47 virtual void reset() {}
970d7e83 48
223e47cc
LB
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;
52
53 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
54 /// non-standard ELFObjectWriters.
1a4d82fc 55 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
223e47cc
LB
56 llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
57 "backend");
58 }
59
970d7e83
LB
60 /// hasDataInCodeSupport - Check whether this target implements data-in-code
61 /// markers. If not, data region directives will be ignored.
1a4d82fc 62 bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
970d7e83 63
223e47cc
LB
64 /// doesSectionRequireSymbols - Check whether the given section requires that
65 /// all symbols (even temporaries) have symbol table entries.
66 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
67 return false;
68 }
69
223e47cc
LB
70 /// @name Target Fixup Interfaces
71 /// @{
72
73 /// getNumFixupKinds - Get the number of target specific fixup kinds.
74 virtual unsigned getNumFixupKinds() const = 0;
75
76 /// getFixupKindInfo - Get information on a fixup kind.
77 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
78
79 /// processFixupValue - Target hook to adjust the literal value of a fixup
80 /// if necessary. IsResolved signals whether the caller believes a relocation
81 /// is needed; the target can modify the value. The default does nothing.
82 virtual void processFixupValue(const MCAssembler &Asm,
83 const MCAsmLayout &Layout,
84 const MCFixup &Fixup, const MCFragment *DF,
1a4d82fc 85 const MCValue &Target, uint64_t &Value,
223e47cc
LB
86 bool &IsResolved) {}
87
223e47cc
LB
88 /// applyFixup - Apply the \p Value for given \p Fixup into the provided
89 /// data fragment, at the offset specified by the fixup and following the
90 /// fixup kind as appropriate.
91 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
1a4d82fc 92 uint64_t Value, bool IsPCRel) const = 0;
223e47cc
LB
93
94 /// @}
95
96 /// @name Target Relaxation Interfaces
97 /// @{
98
99 /// mayNeedRelaxation - Check whether the given instruction may need
100 /// relaxation.
101 ///
102 /// \param Inst - The instruction to test.
103 virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
104
105 /// fixupNeedsRelaxation - Target specific predicate for whether a given
106 /// fixup requires the associated instruction to be relaxed.
1a4d82fc 107 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
970d7e83 108 const MCRelaxableFragment *DF,
223e47cc
LB
109 const MCAsmLayout &Layout) const = 0;
110
111 /// RelaxInstruction - Relax the instruction in the given fragment to the next
112 /// wider instruction.
113 ///
114 /// \param Inst The instruction to relax, which may be the same as the
115 /// output.
116 /// \param [out] Res On return, the relaxed instruction.
117 virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
118
119 /// @}
120
121 /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
122 /// target. The assembler will use this to emit excess padding in situations
123 /// where the padding required for simple alignment would be less than the
124 /// minimum nop size.
125 ///
126 virtual unsigned getMinimumNopSize() const { return 1; }
127
128 /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
129 /// output. If the target cannot generate such a sequence, it should return an
130 /// error.
131 ///
132 /// \return - True on success.
133 virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
134
135 /// handleAssemblerFlag - Handle any target-specific assembler flags.
136 /// By default, do nothing.
137 virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
1a4d82fc
JJ
138
139 /// \brief Generate the compact unwind encoding for the CFI instructions.
140 virtual uint32_t
141 generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
142 return 0;
143 }
223e47cc
LB
144};
145
146} // End llvm namespace
147
148#endif