1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

MC/Assembler: Make the MCObjectWriter available through the lifetime of the

assembler.

llvm-svn: 122031
This commit is contained in:
Daniel Dunbar 2010-12-17 02:45:41 +00:00
parent 3bb926adff
commit 54b3f3e5db
3 changed files with 25 additions and 28 deletions

View File

@ -648,6 +648,8 @@ private:
MCCodeEmitter &Emitter; MCCodeEmitter &Emitter;
MCObjectWriter &Writer;
raw_ostream &OS; raw_ostream &OS;
iplist<MCSectionData> Sections; iplist<MCSectionData> Sections;
@ -770,8 +772,9 @@ public:
// concrete and require clients to pass in a target like object. The other // concrete and require clients to pass in a target like object. The other
// option is to make this abstract, and have targets provide concrete // option is to make this abstract, and have targets provide concrete
// implementations as we do with AsmParser. // implementations as we do with AsmParser.
MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, MCAssembler(MCContext &Context_, TargetAsmBackend &Backend_,
MCCodeEmitter &_Emitter, raw_ostream &OS); MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
raw_ostream &OS);
~MCAssembler(); ~MCAssembler();
MCContext &getContext() const { return Context; } MCContext &getContext() const { return Context; }
@ -780,10 +783,12 @@ public:
MCCodeEmitter &getEmitter() const { return Emitter; } MCCodeEmitter &getEmitter() const { return Emitter; }
MCObjectWriter &getWriter() const { return Writer; }
/// Finish - Do final processing and write the object to the output stream. /// Finish - Do final processing and write the object to the output stream.
/// \arg Writer is used for custom object writer (as the MCJIT does), /// \arg Writer is used for custom object writer (as the MCJIT does),
/// if not specified it is automatically created from backend. /// if not specified it is automatically created from backend.
void Finish(MCObjectWriter *Writer = 0); void Finish();
// FIXME: This does not belong here. // FIXME: This does not belong here.
bool getSubsectionsViaSymbols() const { bool getSubsectionsViaSymbols() const {

View File

@ -167,10 +167,11 @@ MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
/* *** */ /* *** */
MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, MCAssembler::MCAssembler(MCContext &Context_, TargetAsmBackend &Backend_,
MCCodeEmitter &_Emitter, raw_ostream &_OS) MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
: Context(_Context), Backend(_Backend), Emitter(_Emitter), raw_ostream &OS_)
OS(_OS), RelaxAll(false), SubsectionsViaSymbols(false) : Context(Context_), Backend(Backend_), Emitter(Emitter_), Writer(Writer_),
OS(OS_), RelaxAll(false), SubsectionsViaSymbols(false)
{ {
} }
@ -495,7 +496,7 @@ uint64_t MCAssembler::HandleFixup(MCObjectWriter &Writer,
return FixedValue; return FixedValue;
} }
void MCAssembler::Finish(MCObjectWriter *Writer) { void MCAssembler::Finish() {
DEBUG_WITH_TYPE("mc-dump", { DEBUG_WITH_TYPE("mc-dump", {
llvm::errs() << "assembler backend - pre-layout\n--\n"; llvm::errs() << "assembler backend - pre-layout\n--\n";
dump(); }); dump(); });
@ -503,8 +504,6 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
// Create the layout object. // Create the layout object.
MCAsmLayout Layout(*this); MCAsmLayout Layout(*this);
// Create dummy fragments and assign section ordinals. // Create dummy fragments and assign section ordinals.
unsigned SectionIndex = 0; unsigned SectionIndex = 0;
for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) { for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
@ -527,17 +526,8 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
it2->setLayoutOrder(FragmentIndex++); it2->setLayoutOrder(FragmentIndex++);
} }
llvm::OwningPtr<MCObjectWriter> OwnWriter(0);
if (Writer == 0) {
//no custom Writer_ : create the default one life-managed by OwningPtr
OwnWriter.reset(getBackend().createObjectWriter(OS));
Writer = OwnWriter.get();
if (!Writer)
report_fatal_error("unable to create object writer!");
}
// Layout until everything fits. // Layout until everything fits.
while (LayoutOnce(*Writer, Layout)) while (LayoutOnce(Writer, Layout))
continue; continue;
DEBUG_WITH_TYPE("mc-dump", { DEBUG_WITH_TYPE("mc-dump", {
@ -555,7 +545,7 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
// Allow the object writer a chance to perform post-layout binding (for // Allow the object writer a chance to perform post-layout binding (for
// example, to set the index fields in the symbol data). // example, to set the index fields in the symbol data).
Writer->ExecutePostLayoutBinding(*this, Layout); Writer.ExecutePostLayoutBinding(*this, Layout);
// Evaluate and apply the fixups, generating relocation entries as necessary. // Evaluate and apply the fixups, generating relocation entries as necessary.
for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) { for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
@ -566,7 +556,7 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(), for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
ie3 = DF->fixup_end(); it3 != ie3; ++it3) { ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
MCFixup &Fixup = *it3; MCFixup &Fixup = *it3;
uint64_t FixedValue = HandleFixup(*Writer, Layout, *DF, Fixup); uint64_t FixedValue = HandleFixup(Writer, Layout, *DF, Fixup);
getBackend().ApplyFixup(Fixup, DF->getContents().data(), getBackend().ApplyFixup(Fixup, DF->getContents().data(),
DF->getContents().size(), FixedValue); DF->getContents().size(), FixedValue);
} }
@ -576,7 +566,7 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
for (MCInstFragment::fixup_iterator it3 = IF->fixup_begin(), for (MCInstFragment::fixup_iterator it3 = IF->fixup_begin(),
ie3 = IF->fixup_end(); it3 != ie3; ++it3) { ie3 = IF->fixup_end(); it3 != ie3; ++it3) {
MCFixup &Fixup = *it3; MCFixup &Fixup = *it3;
uint64_t FixedValue = HandleFixup(*Writer, Layout, *IF, Fixup); uint64_t FixedValue = HandleFixup(Writer, Layout, *IF, Fixup);
getBackend().ApplyFixup(Fixup, IF->getCode().data(), getBackend().ApplyFixup(Fixup, IF->getCode().data(),
IF->getCode().size(), FixedValue); IF->getCode().size(), FixedValue);
} }
@ -585,7 +575,7 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
} }
// Write the object file. // Write the object file.
Writer->WriteObject(*this, Layout); Writer.WriteObject(*this, Layout);
stats::ObjectBytes += OS.tell() - StartOffset; stats::ObjectBytes += OS.tell() - StartOffset;
} }

View File

@ -21,10 +21,11 @@
using namespace llvm; using namespace llvm;
MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB, MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
raw_ostream &_OS, MCCodeEmitter *_Emitter) raw_ostream &OS, MCCodeEmitter *Emitter_)
: MCStreamer(Context), Assembler(new MCAssembler(Context, TAB, : MCStreamer(Context),
*_Emitter, Assembler(new MCAssembler(Context, TAB,
_OS)), *Emitter_, *TAB.createObjectWriter(OS),
OS)),
CurSectionData(0) CurSectionData(0)
{ {
} }
@ -32,6 +33,7 @@ MCObjectStreamer::MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
MCObjectStreamer::~MCObjectStreamer() { MCObjectStreamer::~MCObjectStreamer() {
delete &Assembler->getBackend(); delete &Assembler->getBackend();
delete &Assembler->getEmitter(); delete &Assembler->getEmitter();
delete &Assembler->getWriter();
delete Assembler; delete Assembler;
} }