MCAsmBackend.h revision f1d0f7781e766df878bec4e7977fa3204374f394
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//===-- llvm/MC/MCAsmBack.h - MC Asm Backend --------------------*- C++ -*-===// 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The LLVM Compiler Infrastructure 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// License. See LICENSE.TXT for details. 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//===----------------------------------------------------------------------===// 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef LLVM_MC_MCASMBACKEND_H 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define LLVM_MC_MCASMBACKEND_H 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "llvm/MC/MCDirectives.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "llvm/MC/MCFixup.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "llvm/Support/DataTypes.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "llvm/Support/ErrorHandling.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace llvm { 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCAsmLayout; 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCAssembler; 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCELFObjectTargetWriter; 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct MCFixupKindInfo; 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCFragment; 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCInst; 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCInstFragment; 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCObjectWriter; 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCSection; 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCValue; 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class raw_ostream; 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// MCAsmBackend - Generic interface to target specific assembler backends. 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MCAsmBackend { 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MCAsmBackend(const MCAsmBackend &); // DO NOT IMPLEMENT 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void operator=(const MCAsmBackend &); // DO NOT IMPLEMENT 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)protected: // Can only create subclasses. 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MCAsmBackend(); 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) unsigned HasReliableSymbolDifference : 1; 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public: 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~MCAsmBackend(); 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// createObjectWriter - Create a new MCObjectWriter instance for use by the 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) /// assembler backend to emit the final object file. 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0; 46 47 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable 48 /// non-standard ELFObjectWriters. 49 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const { 50 llvm_unreachable("createELFObjectTargetWriter is not supported by asm " 51 "backend"); 52 } 53 54 /// hasReliableSymbolDifference - Check whether this target implements 55 /// accurate relocations for differences between symbols. If not, differences 56 /// between symbols will always be relocatable expressions and any references 57 /// to temporary symbols will be assumed to be in the same atom, unless they 58 /// reside in a different section. 59 /// 60 /// This should always be true (since it results in fewer relocations with no 61 /// loss of functionality), but is currently supported as a way to maintain 62 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should 63 /// eventually should be eliminated. 64 bool hasReliableSymbolDifference() const { 65 return HasReliableSymbolDifference; 66 } 67 68 /// doesSectionRequireSymbols - Check whether the given section requires that 69 /// all symbols (even temporaries) have symbol table entries. 70 virtual bool doesSectionRequireSymbols(const MCSection &Section) const { 71 return false; 72 } 73 74 /// isSectionAtomizable - Check whether the given section can be split into 75 /// atoms. 76 /// 77 /// \see MCAssembler::isSymbolLinkerVisible(). 78 virtual bool isSectionAtomizable(const MCSection &Section) const { 79 return true; 80 } 81 82 /// @name Target Fixup Interfaces 83 /// @{ 84 85 /// getNumFixupKinds - Get the number of target specific fixup kinds. 86 virtual unsigned getNumFixupKinds() const = 0; 87 88 /// getFixupKindInfo - Get information on a fixup kind. 89 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const; 90 91 /// processFixupValue - Target hook to adjust the literal value of a fixup 92 /// if necessary. IsResolved signals whether the caller believes a relocation 93 /// is needed; the target can modify the value. The default does nothing. 94 virtual void processFixupValue(const MCAssembler &Asm, 95 const MCAsmLayout &Layout, 96 const MCFixup &Fixup, const MCFragment *DF, 97 MCValue &Target, uint64_t &Value, 98 bool &IsResolved) {} 99 100 /// @} 101 102 /// applyFixup - Apply the \arg Value for given \arg Fixup into the provided 103 /// data fragment, at the offset specified by the fixup and following the 104 /// fixup kind as appropriate. 105 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, 106 uint64_t Value) const = 0; 107 108 /// @} 109 110 /// @name Target Relaxation Interfaces 111 /// @{ 112 113 /// mayNeedRelaxation - Check whether the given instruction may need 114 /// relaxation. 115 /// 116 /// \param Inst - The instruction to test. 117 virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0; 118 119 /// fixupNeedsRelaxation - Target specific predicate for whether a given 120 /// fixup requires the associated instruction to be relaxed. 121 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, 122 uint64_t Value, 123 const MCInstFragment *DF, 124 const MCAsmLayout &Layout) const = 0; 125 126 /// RelaxInstruction - Relax the instruction in the given fragment to the next 127 /// wider instruction. 128 /// 129 /// \param Inst - The instruction to relax, which may be the same as the 130 /// output. 131 /// \parm Res [output] - On return, the relaxed instruction. 132 virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0; 133 134 /// @} 135 136 /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given 137 /// output. If the target cannot generate such a sequence, it should return an 138 /// error. 139 /// 140 /// \return - True on success. 141 virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0; 142 143 /// handleAssemblerFlag - Handle any target-specific assembler flags. 144 /// By default, do nothing. 145 virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {} 146}; 147 148} // End llvm namespace 149 150#endif 151