private:
MCContext &Context;
- MCAsmBackend &Backend;
+ std::unique_ptr<MCAsmBackend> Backend;
- MCCodeEmitter &Emitter;
+ std::unique_ptr<MCCodeEmitter> Emitter;
- MCObjectWriter &Writer;
+ std::unique_ptr<MCObjectWriter> Writer;
SectionListType Sections;
// concrete and require clients to pass in a target like object. The other
// option is to make this abstract, and have targets provide concrete
// implementations as we do with AsmParser.
- MCAssembler(MCContext &Context, MCAsmBackend &Backend,
- MCCodeEmitter &Emitter, MCObjectWriter &Writer);
+ MCAssembler(MCContext &Context, std::unique_ptr<MCAsmBackend> Backend,
+ std::unique_ptr<MCCodeEmitter> Emitter,
+ std::unique_ptr<MCObjectWriter> Writer);
MCAssembler(const MCAssembler &) = delete;
MCAssembler &operator=(const MCAssembler &) = delete;
~MCAssembler();
MCContext &getContext() const { return Context; }
- MCAsmBackend &getBackend() const { return Backend; }
+ MCAsmBackend *getBackendPtr() const { return Backend.get(); }
- MCCodeEmitter &getEmitter() const { return Emitter; }
+ MCCodeEmitter *getEmitterPtr() const { return Emitter.get(); }
- MCObjectWriter &getWriter() const { return Writer; }
+ MCObjectWriter *getWriterPtr() const { return Writer.get(); }
+
+ MCAsmBackend &getBackend() const { return *Backend; }
+
+ MCCodeEmitter &getEmitter() const { return *Emitter; }
+
+ MCObjectWriter &getWriter() const { return *Writer; }
MCDwarfLineTableParams getDWARFLinetableParams() const { return LTParams; }
void setDWARFLinetableParams(MCDwarfLineTableParams P) { LTParams = P; }
/* *** */
-MCAssembler::MCAssembler(MCContext &Context, MCAsmBackend &Backend,
- MCCodeEmitter &Emitter, MCObjectWriter &Writer)
- : Context(Context), Backend(Backend), Emitter(Emitter), Writer(Writer),
+MCAssembler::MCAssembler(MCContext &Context,
+ std::unique_ptr<MCAsmBackend> Backend,
+ std::unique_ptr<MCCodeEmitter> Emitter,
+ std::unique_ptr<MCObjectWriter> Writer)
+ : Context(Context), Backend(std::move(Backend)),
+ Emitter(std::move(Emitter)), Writer(std::move(Writer)),
BundleAlignSize(0), RelaxAll(false), SubsectionsViaSymbols(false),
IncrementalLinkerCompatible(false), ELFHeaderEFlags(0) {
VersionInfo.Major = 0; // Major version == 0 for "none specified"
VersionInfo.Major = 0;
// reset objects owned by us
- getBackend().reset();
- getEmitter().reset();
- getWriter().reset();
+ if (getBackendPtr())
+ getBackendPtr()->reset();
+ if (getEmitterPtr())
+ getEmitterPtr()->reset();
+ if (getWriterPtr())
+ getWriterPtr()->reset();
getLOHContainer().reset();
}
}
}
- bool IsPCRel = Backend.getFixupKindInfo(
- Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel;
+ assert(getBackendPtr() && "Expected assembler backend");
+ bool IsPCRel = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags &
+ MCFixupKindInfo::FKF_IsPCRel;
bool IsResolved;
if (IsPCRel) {
Value -= Layout.getSymbolOffset(Sym);
}
- bool ShouldAlignPC = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
- MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
+ bool ShouldAlignPC = getBackend().getFixupKindInfo(Fixup.getKind()).Flags &
+ MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
assert((ShouldAlignPC ? IsPCRel : true) &&
"FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!");
}
// Let the backend force a relocation if needed.
- if (IsResolved && Backend.shouldForceRelocation(*this, Fixup, Target))
+ if (IsResolved && getBackend().shouldForceRelocation(*this, Fixup, Target))
IsResolved = false;
return IsResolved;
uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
const MCFragment &F) const {
+ assert(getBackendPtr() && "Requires assembler backend");
switch (F.getKind()) {
case MCFragment::FT_Data:
return cast<MCDataFragment>(F).getContents().size();
void MCAssembler::writeFragmentPadding(const MCFragment &F, uint64_t FSize,
MCObjectWriter *OW) const {
+ assert(getBackendPtr() && "Expected assembler backend");
// Should NOP padding be written out before this fragment?
unsigned BundlePadding = F.getBundlePadding();
if (BundlePadding > 0) {
/// \brief Write the fragment \p F to the output file.
static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment &F) {
- MCObjectWriter *OW = &Asm.getWriter();
+ MCObjectWriter *OW = Asm.getWriterPtr();
+ assert(OW && "Need ObjectWriter to write fragment");
// FIXME: Embed in fragments instead?
uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F);
void MCAssembler::writeSectionData(const MCSection *Sec,
const MCAsmLayout &Layout) const {
+ assert(getBackendPtr() && "Expected assembler backend");
+
// Ignore virtual sections.
if (Sec->isVirtualSection()) {
assert(Layout.getSectionFileSize(Sec) == 0 && "Invalid size for section!");
}
void MCAssembler::layout(MCAsmLayout &Layout) {
+ assert(getBackendPtr() && "Expected assembler backend");
DEBUG_WITH_TYPE("mc-dump", {
errs() << "assembler backend - pre-layout\n--\n";
dump(); });
bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const {
+ assert(getBackendPtr() && "Expected assembler backend");
MCValue Target;
uint64_t Value;
bool Resolved = evaluateFixup(Layout, Fixup, DF, Target, Value);
bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F,
const MCAsmLayout &Layout) const {
+ assert(getBackendPtr() && "Expected assembler backend");
// If this inst doesn't ever need relaxation, ignore it. This occurs when we
// are intentionally pushing out inst fragments, or because we relaxed a
// previous instruction to one that doesn't need relaxation.
bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
MCRelaxableFragment &F) {
+ assert(getEmitterPtr() &&
+ "Expected CodeEmitter defined for relaxInstruction");
if (!fragmentNeedsRelaxation(&F, Layout))
return false;
bool MCAssembler::relaxPaddingFragment(MCAsmLayout &Layout,
MCPaddingFragment &PF) {
+ assert(getBackendPtr() && "Expected assembler backend");
uint64_t OldSize = PF.getSize();
if (!getBackend().relaxFragment(&PF, Layout))
return false;
}
void MCAssembler::finishLayout(MCAsmLayout &Layout) {
+ assert(getBackendPtr() && "Expected assembler backend");
// The layout is done. Mark every fragment as valid.
for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
MCSection &Section = *Layout.getSectionOrder()[i];