2014-09-16 11:18:23 +02:00
|
|
|
//===-- llvm/MC/MCAsmBackend.h - MC Asm Backend -----------------*- C++ -*-===//
|
2010-02-21 22:53:53 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-26 01:24:55 +02:00
|
|
|
#ifndef LLVM_MC_MCASMBACKEND_H
|
|
|
|
#define LLVM_MC_MCASMBACKEND_H
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2013-09-09 04:37:14 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2010-12-08 02:16:55 +01:00
|
|
|
#include "llvm/MC/MCDirectives.h"
|
2013-09-09 04:37:14 +02:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2010-12-16 04:20:06 +01:00
|
|
|
#include "llvm/MC/MCFixup.h"
|
2010-11-29 19:16:10 +01:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2012-02-05 23:14:15 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-03-19 10:28:12 +01:00
|
|
|
|
2010-02-21 22:53:53 +01:00
|
|
|
namespace llvm {
|
2011-12-06 01:47:03 +01:00
|
|
|
class MCAsmLayout;
|
2012-01-18 01:23:57 +01:00
|
|
|
class MCAssembler;
|
2011-03-09 19:44:41 +01:00
|
|
|
class MCELFObjectTargetWriter;
|
2012-03-26 08:58:25 +02:00
|
|
|
struct MCFixupKindInfo;
|
2012-01-18 01:23:57 +01:00
|
|
|
class MCFragment;
|
2010-03-23 02:39:09 +01:00
|
|
|
class MCInst;
|
2013-01-08 01:22:56 +01:00
|
|
|
class MCRelaxableFragment;
|
2010-03-19 11:43:26 +01:00
|
|
|
class MCObjectWriter;
|
2010-03-15 22:56:50 +01:00
|
|
|
class MCSection;
|
2012-01-18 01:23:57 +01:00
|
|
|
class MCValue;
|
2010-03-19 11:43:26 +01:00
|
|
|
class raw_ostream;
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2011-07-26 01:24:55 +02:00
|
|
|
/// MCAsmBackend - Generic interface to target specific assembler backends.
|
|
|
|
class MCAsmBackend {
|
2015-02-15 23:54:22 +01:00
|
|
|
MCAsmBackend(const MCAsmBackend &) = delete;
|
|
|
|
void operator=(const MCAsmBackend &) = delete;
|
2013-09-07 13:55:36 +02:00
|
|
|
|
2010-02-21 22:53:53 +01:00
|
|
|
protected: // Can only create subclasses.
|
2011-07-26 01:24:55 +02:00
|
|
|
MCAsmBackend();
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2012-10-02 00:20:54 +02:00
|
|
|
unsigned HasDataInCodeSupport : 1;
|
2010-03-18 01:58:53 +01:00
|
|
|
|
2010-02-21 22:53:53 +01:00
|
|
|
public:
|
2011-07-26 01:24:55 +02:00
|
|
|
virtual ~MCAsmBackend();
|
2010-02-21 22:53:53 +01:00
|
|
|
|
2012-12-14 19:52:11 +01:00
|
|
|
/// lifetime management
|
2013-09-07 13:55:36 +02:00
|
|
|
virtual void reset() {}
|
2012-12-14 19:52:11 +01:00
|
|
|
|
2010-03-19 11:43:26 +01: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 19:44:41 +01:00
|
|
|
/// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
|
|
|
|
/// non-standard ELFObjectWriters.
|
2013-09-07 13:55:36 +02:00
|
|
|
virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
|
2012-02-05 23:14:15 +01:00
|
|
|
llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
|
|
|
|
"backend");
|
2011-03-09 19:44:41 +01:00
|
|
|
}
|
|
|
|
|
2012-10-02 00:20:54 +02:00
|
|
|
/// hasDataInCodeSupport - Check whether this target implements data-in-code
|
|
|
|
/// markers. If not, data region directives will be ignored.
|
2013-09-07 13:55:36 +02:00
|
|
|
bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
|
2012-10-02 00:20:54 +02:00
|
|
|
|
2010-12-16 04:20:06 +01: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 01:23:57 +01:00
|
|
|
/// processFixupValue - Target hook to adjust the literal value of a fixup
|
2012-02-27 22:36:23 +01: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 01:23:57 +01:00
|
|
|
virtual void processFixupValue(const MCAssembler &Asm,
|
|
|
|
const MCAsmLayout &Layout,
|
|
|
|
const MCFixup &Fixup, const MCFragment *DF,
|
2014-03-28 17:06:09 +01:00
|
|
|
const MCValue &Target, uint64_t &Value,
|
2012-02-27 22:36:23 +01:00
|
|
|
bool &IsResolved) {}
|
2012-01-18 01:23:57 +01:00
|
|
|
|
2012-09-14 16:57:36 +02:00
|
|
|
/// applyFixup - Apply the \p Value for given \p Fixup into the provided
|
2010-03-19 10:28:12 +01:00
|
|
|
/// data fragment, at the offset specified by the fixup and following the
|
|
|
|
/// fixup kind as appropriate.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
|
2014-03-29 07:26:49 +01:00
|
|
|
uint64_t Value, bool IsPCRel) const = 0;
|
2010-03-23 02:39:09 +01:00
|
|
|
|
2010-12-16 04:20:06 +01:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// @name Target Relaxation Interfaces
|
|
|
|
/// @{
|
|
|
|
|
2012-01-18 19:52:16 +01:00
|
|
|
/// mayNeedRelaxation - Check whether the given instruction may need
|
2010-03-23 04:13:05 +01:00
|
|
|
/// relaxation.
|
|
|
|
///
|
2010-05-26 20:15:06 +02:00
|
|
|
/// \param Inst - The instruction to test.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
|
2010-03-23 04:13:05 +01:00
|
|
|
|
2011-12-06 01:47:03 +01:00
|
|
|
/// fixupNeedsRelaxation - Target specific predicate for whether a given
|
|
|
|
/// fixup requires the associated instruction to be relaxed.
|
2013-09-07 13:55:36 +02:00
|
|
|
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
|
2013-01-08 01:22:56 +01:00
|
|
|
const MCRelaxableFragment *DF,
|
2011-12-06 01:47:03 +01:00
|
|
|
const MCAsmLayout &Layout) const = 0;
|
|
|
|
|
2010-03-23 02:39:09 +01:00
|
|
|
/// RelaxInstruction - Relax the instruction in the given fragment to the next
|
|
|
|
/// wider instruction.
|
2010-05-26 20:15:06 +02:00
|
|
|
///
|
2012-09-12 18:59:47 +02:00
|
|
|
/// \param Inst The instruction to relax, which may be the same as the
|
2010-05-26 20:15:06 +02:00
|
|
|
/// output.
|
2012-09-12 18:59:47 +02:00
|
|
|
/// \param [out] Res On return, the relaxed instruction.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
|
2010-03-23 03:36:58 +01:00
|
|
|
|
2010-12-16 04:20:06 +01:00
|
|
|
/// @}
|
|
|
|
|
2012-08-30 00:18:56 +02: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 19:52:16 +01:00
|
|
|
/// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
|
2010-03-23 03:36:58 +01:00
|
|
|
/// output. If the target cannot generate such a sequence, it should return an
|
|
|
|
/// error.
|
|
|
|
///
|
|
|
|
/// \return - True on success.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
|
2010-12-08 02:16:55 +01:00
|
|
|
|
2012-01-18 19:52:16 +01:00
|
|
|
/// handleAssemblerFlag - Handle any target-specific assembler flags.
|
2010-12-08 02:16:55 +01:00
|
|
|
/// By default, do nothing.
|
2012-01-18 19:52:16 +01:00
|
|
|
virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
|
2013-09-09 04:37:14 +02:00
|
|
|
|
|
|
|
/// \brief Generate the compact unwind encoding for the CFI instructions.
|
2013-09-11 23:47:57 +02:00
|
|
|
virtual uint32_t
|
2014-09-16 11:18:23 +02:00
|
|
|
generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
|
2013-09-09 04:37:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-02-21 22:53:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|