#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCMachOSymbolFlags.h"
namespace {
-class MCMachOStreamer : public MCStreamer {
+class MCMachOStreamer : public MCObjectStreamer {
private:
- MCAssembler Assembler;
MCSectionData *CurSectionData;
/// Track the current atom for each section.
public:
MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
- raw_ostream &_OS, MCCodeEmitter *_Emitter)
- : MCStreamer(Context), Assembler(Context, TAB, *_Emitter, _OS),
- CurSectionData(0) {}
- ~MCMachOStreamer() {}
-
- MCAssembler &getAssembler() { return Assembler; }
+ raw_ostream &OS, MCCodeEmitter *Emitter)
+ : MCObjectStreamer(Context, TAB, OS, Emitter), CurSectionData(0) {}
const MCExpr *AddValueSymbols(const MCExpr *Value) {
switch (Value->getKind()) {
}
case MCExpr::SymbolRef:
- Assembler.getOrCreateSymbolData(
+ getAssembler().getOrCreateSymbolData(
cast<MCSymbolRefExpr>(Value)->getSymbol());
break;
if (Section == CurSection) return;
CurSection = Section;
- CurSectionData = &Assembler.getOrCreateSectionData(*Section);
+ CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
}
void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
assert(CurSection && "Cannot emit before setting section!");
- MCSymbolData &SD = Assembler.getOrCreateSymbolData(*Symbol);
+ MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
// Update the current atom map, if necessary.
bool MustCreateFragment = false;
- if (Assembler.isSymbolLinkerVisible(&SD)) {
+ if (getAssembler().isSymbolLinkerVisible(&SD)) {
CurrentAtomMap[CurSectionData] = &SD;
// We have to create a new fragment, fragments cannot span atoms.
void MCMachOStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
switch (Flag) {
case MCAF_SubsectionsViaSymbols:
- Assembler.setSubsectionsViaSymbols(true);
+ getAssembler().setSubsectionsViaSymbols(true);
return;
}
void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
// FIXME: Lift context changes into super class.
- Assembler.getOrCreateSymbolData(*Symbol);
+ getAssembler().getOrCreateSymbolData(*Symbol);
Symbol->setVariableValue(AddValueSymbols(Value));
}
IndirectSymbolData ISD;
ISD.Symbol = Symbol;
ISD.SectionData = CurSectionData;
- Assembler.getIndirectSymbols().push_back(ISD);
+ getAssembler().getIndirectSymbols().push_back(ISD);
return;
}
// Adding a symbol attribute always introduces the symbol, note that an
// important side effect of calling getOrCreateSymbolData here is to register
// the symbol with the assembler.
- MCSymbolData &SD = Assembler.getOrCreateSymbolData(*Symbol);
+ MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
// The implementation of symbol attributes is designed to match 'as', but it
// leaves much to desired. It doesn't really make sense to arbitrarily add and
// Encode the 'desc' value into the lowest implementation defined bits.
assert(DescValue == (DescValue & SF_DescFlagsMask) &&
"Invalid .desc value!");
- Assembler.getOrCreateSymbolData(*Symbol).setFlags(DescValue&SF_DescFlagsMask);
+ getAssembler().getOrCreateSymbolData(*Symbol).setFlags(
+ DescValue & SF_DescFlagsMask);
}
void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
// FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
- MCSymbolData &SD = Assembler.getOrCreateSymbolData(*Symbol);
+ MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
SD.setExternal(true);
SD.setCommon(Size, ByteAlignment);
}
void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
unsigned Size, unsigned ByteAlignment) {
- MCSectionData &SectData = Assembler.getOrCreateSectionData(*Section);
+ MCSectionData &SectData = getAssembler().getOrCreateSectionData(*Section);
// The symbol may not be present, which only creates the section.
if (!Symbol)
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
- MCSymbolData &SD = Assembler.getOrCreateSymbolData(*Symbol);
+ MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
// Emit an align fragment if necessary.
if (ByteAlignment != 1)
MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
SD.setFragment(F);
- if (Assembler.isSymbolLinkerVisible(&SD))
+ if (getAssembler().isSymbolLinkerVisible(&SD))
F->setAtom(&SD);
Symbol->setSection(*Section);
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
- Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
+ getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
VecOS.flush();
IF->getCode() = Code;
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
- Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
+ getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
VecOS.flush();
// Add the fixups and data.
CurSectionData->setHasInstructions(true);
// If this instruction doesn't need relaxation, just emit it as data.
- if (!Assembler.getBackend().MayNeedRelaxation(Inst)) {
+ if (!getAssembler().getBackend().MayNeedRelaxation(Inst)) {
EmitInstToData(Inst);
return;
}
// Otherwise, if we are relaxing everything, relax the instruction as much as
// possible and emit it as data.
- if (Assembler.getRelaxAll()) {
+ if (getAssembler().getRelaxAll()) {
MCInst Relaxed;
- Assembler.getBackend().RelaxInstruction(Inst, Relaxed);
- while (Assembler.getBackend().MayNeedRelaxation(Relaxed))
- Assembler.getBackend().RelaxInstruction(Relaxed, Relaxed);
+ getAssembler().getBackend().RelaxInstruction(Inst, Relaxed);
+ while (getAssembler().getBackend().MayNeedRelaxation(Relaxed))
+ getAssembler().getBackend().RelaxInstruction(Relaxed, Relaxed);
EmitInstToData(Relaxed);
return;
}
}
void MCMachOStreamer::Finish() {
- Assembler.Finish();
+ getAssembler().Finish();
}
MCStreamer *llvm::createMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,