2010-06-16 22:04:22 +02:00
|
|
|
//===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCOBJECTSTREAMER_H
|
|
|
|
#define LLVM_MC_MCOBJECTSTREAMER_H
|
|
|
|
|
2014-10-23 00:38:06 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2013-04-17 23:18:16 +02:00
|
|
|
#include "llvm/MC/MCAssembler.h"
|
2015-05-26 00:57:48 +02:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2010-06-16 22:04:22 +02:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class MCAssembler;
|
|
|
|
class MCCodeEmitter;
|
2014-01-29 00:12:49 +01:00
|
|
|
class MCSubtargetInfo;
|
2010-07-19 08:13:10 +02:00
|
|
|
class MCExpr;
|
|
|
|
class MCFragment;
|
|
|
|
class MCDataFragment;
|
2011-07-26 01:24:55 +02:00
|
|
|
class MCAsmBackend;
|
2010-06-16 22:04:22 +02:00
|
|
|
class raw_ostream;
|
2015-04-15 00:14:34 +02:00
|
|
|
class raw_pwrite_stream;
|
2010-06-16 22:04:22 +02:00
|
|
|
|
|
|
|
/// \brief Streaming object file generation interface.
|
|
|
|
///
|
|
|
|
/// This class provides an implementation of the MCStreamer interface which is
|
|
|
|
/// suitable for use with the assembler backend. Specific object file formats
|
|
|
|
/// are expected to subclass this interface to implement directives specific
|
|
|
|
/// to that file format or custom semantics expected by the object writer
|
|
|
|
/// implementation.
|
|
|
|
class MCObjectStreamer : public MCStreamer {
|
2017-10-09 20:11:04 +02:00
|
|
|
std::unique_ptr<MCAssembler> Assembler;
|
2015-05-27 17:14:11 +02:00
|
|
|
MCSection::iterator CurInsertionPoint;
|
2014-05-12 16:02:44 +02:00
|
|
|
bool EmitEHFrame;
|
|
|
|
bool EmitDebugFrame;
|
2015-05-29 19:41:59 +02:00
|
|
|
SmallVector<MCSymbol *, 2> PendingLabels;
|
2010-06-16 22:04:22 +02:00
|
|
|
|
2014-01-29 00:12:49 +01:00
|
|
|
virtual void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0;
|
2014-11-03 13:19:03 +01:00
|
|
|
void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
|
2014-03-08 08:02:02 +01:00
|
|
|
void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
|
2010-11-01 17:27:31 +01:00
|
|
|
|
2010-06-16 22:04:22 +02:00
|
|
|
protected:
|
2015-04-15 00:14:34 +02:00
|
|
|
MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS,
|
2015-03-16 19:06:57 +01:00
|
|
|
MCCodeEmitter *Emitter);
|
2015-04-11 04:11:45 +02:00
|
|
|
~MCObjectStreamer() override;
|
2010-06-16 22:04:22 +02:00
|
|
|
|
2012-12-12 23:59:46 +01:00
|
|
|
public:
|
|
|
|
/// state management
|
2014-03-08 08:02:02 +01:00
|
|
|
void reset() override;
|
2012-12-12 23:59:46 +01:00
|
|
|
|
2014-02-13 15:44:26 +01:00
|
|
|
/// Object streamers require the integrated assembler.
|
2014-03-08 08:02:02 +01:00
|
|
|
bool isIntegratedAssemblerRequired() const override { return true; }
|
2014-02-13 15:44:26 +01:00
|
|
|
|
2014-05-12 16:02:44 +02:00
|
|
|
void EmitFrames(MCAsmBackend *MAB);
|
|
|
|
void EmitCFISections(bool EH, bool Debug) override;
|
2014-04-27 19:23:37 +02:00
|
|
|
|
2010-07-19 08:13:10 +02:00
|
|
|
MCFragment *getCurrentFragment() const;
|
|
|
|
|
2014-10-23 00:38:06 +02:00
|
|
|
void insert(MCFragment *F) {
|
|
|
|
flushPendingLabels(F);
|
2015-05-27 23:04:14 +02:00
|
|
|
MCSection *CurSection = getCurrentSectionOnly();
|
2015-05-27 22:52:32 +02:00
|
|
|
CurSection->getFragmentList().insert(CurInsertionPoint, F);
|
|
|
|
F->setParent(CurSection);
|
2013-04-17 23:18:16 +02:00
|
|
|
}
|
|
|
|
|
2010-07-19 08:13:10 +02:00
|
|
|
/// Get a data fragment to write into, creating a new one if the current
|
|
|
|
/// fragment is not a data fragment.
|
2014-10-23 00:38:06 +02:00
|
|
|
MCDataFragment *getOrCreateDataFragment();
|
2010-07-19 08:13:10 +02:00
|
|
|
|
2016-01-29 01:49:42 +01:00
|
|
|
protected:
|
2015-05-21 21:20:38 +02:00
|
|
|
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection);
|
2015-03-20 21:00:01 +01:00
|
|
|
|
2015-04-13 01:42:25 +02:00
|
|
|
/// If any labels have been emitted but not assigned fragments, ensure that
|
|
|
|
/// they get assigned, either to F if possible or to a new data fragment.
|
|
|
|
/// Optionally, it is also possible to provide an offset \p FOffset, which
|
|
|
|
/// will be used as a symbol offset within the fragment.
|
|
|
|
void flushPendingLabels(MCFragment *F, uint64_t FOffset = 0);
|
|
|
|
|
2010-06-16 22:04:22 +02:00
|
|
|
public:
|
2014-06-25 17:45:33 +02:00
|
|
|
void visitUsedSymbol(const MCSymbol &Sym) override;
|
2014-06-25 17:29:54 +02:00
|
|
|
|
2010-06-16 22:04:22 +02:00
|
|
|
MCAssembler &getAssembler() { return *Assembler; }
|
2010-06-16 22:04:25 +02:00
|
|
|
|
2015-05-02 02:44:14 +02:00
|
|
|
/// \name MCStreamer Interface
|
2010-06-16 22:04:25 +02:00
|
|
|
/// @{
|
|
|
|
|
2017-02-10 16:13:12 +01:00
|
|
|
void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
|
2017-04-03 23:50:04 +02:00
|
|
|
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc, MCFragment *F);
|
2014-03-08 08:02:02 +01:00
|
|
|
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
|
2014-04-22 19:27:29 +02:00
|
|
|
void EmitValueImpl(const MCExpr *Value, unsigned Size,
|
2015-09-21 01:35:59 +02:00
|
|
|
SMLoc Loc = SMLoc()) override;
|
2014-03-08 08:02:02 +01:00
|
|
|
void EmitULEB128Value(const MCExpr *Value) override;
|
|
|
|
void EmitSLEB128Value(const MCExpr *Value) override;
|
|
|
|
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
|
2015-05-21 21:20:38 +02:00
|
|
|
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
|
2017-04-14 09:44:23 +02:00
|
|
|
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
|
|
|
|
bool = false) override;
|
2012-12-20 20:05:53 +01:00
|
|
|
|
|
|
|
/// \brief Emit an instruction to a special fragment, because this instruction
|
|
|
|
/// can change its size during relaxation.
|
2014-01-29 00:12:49 +01:00
|
|
|
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &);
|
2012-12-20 20:05:53 +01:00
|
|
|
|
2014-03-08 08:02:02 +01:00
|
|
|
void EmitBundleAlignMode(unsigned AlignPow2) override;
|
|
|
|
void EmitBundleLock(bool AlignToEnd) override;
|
|
|
|
void EmitBundleUnlock() override;
|
|
|
|
void EmitBytes(StringRef Data) override;
|
|
|
|
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
|
|
|
|
unsigned ValueSize = 1,
|
|
|
|
unsigned MaxBytesToEmit = 0) override;
|
|
|
|
void EmitCodeAlignment(unsigned ByteAlignment,
|
|
|
|
unsigned MaxBytesToEmit = 0) override;
|
2016-12-14 11:43:58 +01:00
|
|
|
void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
|
|
|
|
SMLoc Loc) override;
|
2014-03-08 08:02:02 +01:00
|
|
|
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, unsigned Flags,
|
|
|
|
unsigned Isa, unsigned Discriminator,
|
|
|
|
StringRef FileName) override;
|
|
|
|
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
|
|
|
|
const MCSymbol *Label,
|
2014-05-12 16:43:25 +02:00
|
|
|
unsigned PointerSize);
|
2014-03-08 08:02:02 +01:00
|
|
|
void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
|
2014-05-12 16:43:25 +02:00
|
|
|
const MCSymbol *Label);
|
2016-01-29 01:49:42 +01:00
|
|
|
void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
|
|
|
|
unsigned Column, bool PrologueEnd, bool IsStmt,
|
2016-09-07 18:15:31 +02:00
|
|
|
StringRef FileName, SMLoc Loc) override;
|
2016-01-29 01:49:42 +01:00
|
|
|
void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin,
|
|
|
|
const MCSymbol *End) override;
|
2016-09-07 18:15:31 +02:00
|
|
|
void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
|
|
|
|
unsigned SourceFileId,
|
|
|
|
unsigned SourceLineNum,
|
|
|
|
const MCSymbol *FnStartSym,
|
|
|
|
const MCSymbol *FnEndSym) override;
|
2016-02-05 02:55:49 +01:00
|
|
|
void EmitCVDefRangeDirective(
|
|
|
|
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
|
|
|
|
StringRef FixedSizePortion) override;
|
2016-01-29 01:49:42 +01:00
|
|
|
void EmitCVStringTableDirective() override;
|
|
|
|
void EmitCVFileChecksumsDirective() override;
|
2017-09-19 20:14:45 +02:00
|
|
|
void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override;
|
2016-08-22 18:18:42 +02:00
|
|
|
void EmitDTPRel32Value(const MCExpr *Value) override;
|
|
|
|
void EmitDTPRel64Value(const MCExpr *Value) override;
|
|
|
|
void EmitTPRel32Value(const MCExpr *Value) override;
|
|
|
|
void EmitTPRel64Value(const MCExpr *Value) override;
|
2014-03-08 08:02:02 +01:00
|
|
|
void EmitGPRel32Value(const MCExpr *Value) override;
|
|
|
|
void EmitGPRel64Value(const MCExpr *Value) override;
|
2015-11-12 14:33:00 +01:00
|
|
|
bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
|
|
|
|
const MCExpr *Expr, SMLoc Loc) override;
|
2016-06-11 10:12:17 +02:00
|
|
|
using MCStreamer::emitFill;
|
2016-06-01 03:59:58 +02:00
|
|
|
void emitFill(uint64_t NumBytes, uint8_t FillValue) override;
|
2016-05-28 07:57:48 +02:00
|
|
|
void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
|
|
|
|
SMLoc Loc = SMLoc()) override;
|
|
|
|
void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
|
|
|
|
SMLoc Loc = SMLoc()) override;
|
2017-03-03 22:22:06 +01:00
|
|
|
void EmitFileDirective(StringRef Filename) override;
|
2016-05-28 07:57:48 +02:00
|
|
|
|
2014-03-08 08:02:02 +01:00
|
|
|
void FinishImpl() override;
|
2014-06-19 17:52:37 +02:00
|
|
|
|
2015-05-21 04:41:23 +02:00
|
|
|
/// Emit the absolute difference between two symbols if possible.
|
|
|
|
///
|
|
|
|
/// Emit the absolute difference between \c Hi and \c Lo, as long as we can
|
|
|
|
/// compute it. Currently, that requires that both symbols are in the same
|
|
|
|
/// data fragment. Otherwise, do nothing and return \c false.
|
|
|
|
///
|
|
|
|
/// \pre Offset of \c Hi is greater than the offset \c Lo.
|
2015-06-11 20:58:08 +02:00
|
|
|
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
|
2015-05-21 04:41:23 +02:00
|
|
|
unsigned Size) override;
|
|
|
|
|
2015-05-25 20:34:26 +02:00
|
|
|
bool mayHaveInstructions(MCSection &Sec) const override;
|
2010-06-16 22:04:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|