2011-07-25 23:24:55 +00:00
|
|
|
//===-- llvm/MC/MCAsmBack.h - MC Asm Backend --------------------*- C++ -*-===//
|
2010-02-21 21:53:53 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-25 23:24:55 +00:00
|
|
|
#ifndef LLVM_MC_MCASMBACKEND_H
|
|
|
|
#define LLVM_MC_MCASMBACKEND_H
|
2010-02-21 21:53:53 +00:00
|
|
|
|
2013-09-09 02:37:14 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2010-12-08 01:16:55 +00:00
|
|
|
#include "llvm/MC/MCDirectives.h"
|
2013-09-09 02:37:14 +00:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2010-12-16 03:20:06 +00:00
|
|
|
#include "llvm/MC/MCFixup.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2012-02-05 22:14:15 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-03-19 09:28:12 +00:00
|
|
|
|
2010-02-21 21:53:53 +00:00
|
|
|
namespace llvm {
|
2011-12-06 00:47:03 +00:00
|
|
|
class MCAsmLayout;
|
2012-01-18 00:23:57 +00:00
|
|
|
class MCAssembler;
|
2011-03-09 18:44:41 +00:00
|
|
|
class MCELFObjectTargetWriter;
|
2012-03-26 06:58:25 +00:00
|
|
|
struct MCFixupKindInfo;
|
2012-01-18 00:23:57 +00:00
|
|
|
class MCFragment;
|
2010-03-23 01:39:09 +00:00
|
|
|
class MCInst;
|
2013-01-08 00:22:56 +00:00
|
|
|
class MCRelaxableFragment;
|
2010-03-19 10:43:26 +00:00
|
|
|
class MCObjectWriter;
|
2010-03-15 21:56:50 +00:00
|
|
|
class MCSection;
|
2012-01-18 00:23:57 +00:00
|
|
|
class MCValue;
|
2010-03-19 10:43:26 +00:00
|
|
|
class raw_ostream;
|
2010-02-21 21:53:53 +00:00
|
|
|
|
2011-07-25 23:24:55 +00:00
|
|
|
/// MCAsmBackend - Generic interface to target specific assembler backends.
|
|
|
|
class MCAsmBackend {
|
2012-08-29 06:28:46 +00:00
|
|
|
MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
|
2013-09-07 11:55:36 +00:00
|
|
|
|
2010-02-21 21:53:53 +00:00
|
|
|
protected: // Can only create subclasses.
|
2011-07-25 23:24:55 +00:00
|
|
|
MCAsmBackend();
|
2010-02-21 21:53:53 +00:00
|
|
|
|
2010-03-18 00:58:53 +00:00
|
|
|
unsigned HasReliableSymbolDifference : 1;
|
2012-10-01 22:20:54 +00:00
|
|
|
unsigned HasDataInCodeSupport : 1;
|
2010-03-18 00:58:53 +00:00
|
|
|
|
2010-02-21 21:53:53 +00:00
|
|
|
public:
|
2011-07-25 23:24:55 +00:00
|
|
|
virtual ~MCAsmBackend();
|
2010-02-21 21:53:53 +00:00
|
|
|
|
2012-12-14 18:52:11 +00:00
|
|
|
/// lifetime management
|
2013-09-07 11:55:36 +00:00
|
|
|
virtual void reset() {}
|
2012-12-14 18:52:11 +00:00
|
|
|
|
2010-03-19 10:43:26 +00:00
|
|
|
/// createObjectWriter - Create a new MCObjectWriter instance for use by the
|
|
|
|
/// assembler backend to emit the final object file.
|
|
|
|
virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
|
|
|
|
|
2011-03-09 18:44:41 +00:00
|
|
|
/// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
|
|
|
|
/// non-standard ELFObjectWriters.
|
2013-09-07 11:55:36 +00:00
|
|
|
virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
|
2012-02-05 22:14:15 +00:00
|
|
|
llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
|
|
|
|
"backend");
|
2011-03-09 18:44:41 +00:00
|
|
|
}
|
|
|
|
|
2010-03-18 00:58:53 +00:00
|
|
|
/// hasReliableSymbolDifference - Check whether this target implements
|
|
|
|
/// accurate relocations for differences between symbols. If not, differences
|
|
|
|
/// between symbols will always be relocatable expressions and any references
|
|
|
|
/// to temporary symbols will be assumed to be in the same atom, unless they
|
|
|
|
/// reside in a different section.
|
|
|
|
///
|
|
|
|
/// This should always be true (since it results in fewer relocations with no
|
|
|
|
/// loss of functionality), but is currently supported as a way to maintain
|
|
|
|
/// exact object compatibility with Darwin 'as' (on non-x86_64). It should
|
2010-10-16 18:23:53 +00:00
|
|
|
/// eventually should be eliminated.
|
2010-03-18 00:58:53 +00:00
|
|
|
bool hasReliableSymbolDifference() const {
|
|
|
|
return HasReliableSymbolDifference;
|
|
|
|
}
|
2010-03-11 01:34:21 +00:00
|
|
|
|
2012-10-01 22:20:54 +00:00
|
|
|
/// hasDataInCodeSupport - Check whether this target implements data-in-code
|
|
|
|
/// markers. If not, data region directives will be ignored.
|
2013-09-07 11:55:36 +00:00
|
|
|
bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
|
2012-10-01 22:20:54 +00:00
|
|
|
|
2010-03-15 21:56:50 +00:00
|
|
|
/// doesSectionRequireSymbols - Check whether the given section requires that
|
|
|
|
/// all symbols (even temporaries) have symbol table entries.
|
|
|
|
virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-19 09:28:12 +00:00
|
|
|
|
2010-05-12 00:38:17 +00:00
|
|
|
/// isSectionAtomizable - Check whether the given section can be split into
|
|
|
|
/// atoms.
|
|
|
|
///
|
|
|
|
/// \see MCAssembler::isSymbolLinkerVisible().
|
|
|
|
virtual bool isSectionAtomizable(const MCSection &Section) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-16 03:20:06 +00:00
|
|
|
/// @name Target Fixup Interfaces
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// getNumFixupKinds - Get the number of target specific fixup kinds.
|
|
|
|
virtual unsigned getNumFixupKinds() const = 0;
|
|
|
|
|
|
|
|
/// getFixupKindInfo - Get information on a fixup kind.
|
|
|
|
virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
|
|
|
|
|
2012-01-18 00:23:57 +00:00
|
|
|
/// processFixupValue - Target hook to adjust the literal value of a fixup
|
2012-02-27 21:36:23 +00:00
|
|
|
/// if necessary. IsResolved signals whether the caller believes a relocation
|
|
|
|
/// is needed; the target can modify the value. The default does nothing.
|
2012-01-18 00:23:57 +00:00
|
|
|
virtual void processFixupValue(const MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout,
|
|
|
|
const MCFixup &Fixup, const MCFragment *DF,
|
2012-02-27 21:36:23 +00:00
|
|
|
MCValue &Target, uint64_t &Value,
|
|
|
|
bool &IsResolved) {}
|
2012-01-18 00:23:57 +00:00
|
|
|
|
2012-09-14 14:57:36 +00:00
|
|
|
/// applyFixup - Apply the \p Value for given \p Fixup into the provided
|
2010-03-19 09:28:12 +00:00
|
|
|
/// data fragment, at the offset specified by the fixup and following the
|
|
|
|
/// fixup kind as appropriate.
|
2012-01-18 18:52:16 +00:00
|
|
|
virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
2010-03-19 09:28:12 +00:00
|
|
|
uint64_t Value) const = 0;
|
2010-03-23 01:39:09 +00:00
|
|
|
|
2010-12-16 03:20:06 +00:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// @name Target Relaxation Interfaces
|
|
|
|
/// @{
|
|
|
|
|
2012-01-18 18:52:16 +00:00
|
|
|
/// mayNeedRelaxation - Check whether the given instruction may need
|
2010-03-23 03:13:05 +00:00
|
|
|
/// relaxation.
|
|
|
|
///
|
2010-05-26 18:15:06 +00:00
|
|
|
/// \param Inst - The instruction to test.
|
2012-01-18 18:52:16 +00:00
|
|
|
virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
|
2010-03-23 03:13:05 +00:00
|
|
|
|
2011-12-06 00:47:03 +00:00
|
|
|
/// fixupNeedsRelaxation - Target specific predicate for whether a given
|
|
|
|
/// fixup requires the associated instruction to be relaxed.
|
2013-09-07 11:55:36 +00:00
|
|
|
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
|
2013-01-08 00:22:56 +00:00
|
|
|
const MCRelaxableFragment *DF,
|
2011-12-06 00:47:03 +00:00
|
|
|
const MCAsmLayout &Layout) const = 0;
|
|
|
|
|
2010-03-23 01:39:09 +00:00
|
|
|
/// RelaxInstruction - Relax the instruction in the given fragment to the next
|
|
|
|
/// wider instruction.
|
2010-05-26 18:15:06 +00:00
|
|
|
///
|
2012-09-12 16:59:47 +00:00
|
|
|
/// \param Inst The instruction to relax, which may be the same as the
|
2010-05-26 18:15:06 +00:00
|
|
|
/// output.
|
2012-09-12 16:59:47 +00:00
|
|
|
/// \param [out] Res On return, the relaxed instruction.
|
2012-01-18 18:52:16 +00:00
|
|
|
virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
|
2010-03-23 02:36:58 +00:00
|
|
|
|
2010-12-16 03:20:06 +00:00
|
|
|
/// @}
|
|
|
|
|
2012-08-29 22:18:56 +00:00
|
|
|
/// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
|
|
|
|
/// target. The assembler will use this to emit excess padding in situations
|
|
|
|
/// where the padding required for simple alignment would be less than the
|
|
|
|
/// minimum nop size.
|
|
|
|
///
|
|
|
|
virtual unsigned getMinimumNopSize() const { return 1; }
|
|
|
|
|
2012-01-18 18:52:16 +00:00
|
|
|
/// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
|
2010-03-23 02:36:58 +00:00
|
|
|
/// output. If the target cannot generate such a sequence, it should return an
|
|
|
|
/// error.
|
|
|
|
///
|
|
|
|
/// \return - True on success.
|
2012-01-18 18:52:16 +00:00
|
|
|
virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
|
2010-12-08 01:16:55 +00:00
|
|
|
|
2012-01-18 18:52:16 +00:00
|
|
|
/// handleAssemblerFlag - Handle any target-specific assembler flags.
|
2010-12-08 01:16:55 +00:00
|
|
|
/// By default, do nothing.
|
2012-01-18 18:52:16 +00:00
|
|
|
virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
|
2013-09-09 02:37:14 +00:00
|
|
|
|
|
|
|
/// \brief Generate the compact unwind encoding for the CFI instructions.
|
2013-09-11 21:47:57 +00:00
|
|
|
virtual uint32_t
|
2013-09-09 02:37:14 +00:00
|
|
|
generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-02-21 21:53:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|