forked from OSchip/llvm-project
MC: Provide MCAssembler with a TargetAsmBackend.
llvm-svn: 98222
This commit is contained in:
parent
77c4141c8f
commit
c5ddbad237
|
@ -28,6 +28,7 @@ class MCFragment;
|
||||||
class MCSection;
|
class MCSection;
|
||||||
class MCSectionData;
|
class MCSectionData;
|
||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
|
class TargetAsmBackend;
|
||||||
|
|
||||||
/// MCAsmFixup - Represent a fixed size region of bytes inside some fragment
|
/// MCAsmFixup - Represent a fixed size region of bytes inside some fragment
|
||||||
/// which needs to be rewritten. This region will either be rewritten by the
|
/// which needs to be rewritten. This region will either be rewritten by the
|
||||||
|
@ -582,6 +583,8 @@ private:
|
||||||
|
|
||||||
MCContext &Context;
|
MCContext &Context;
|
||||||
|
|
||||||
|
TargetAsmBackend &Backend;
|
||||||
|
|
||||||
raw_ostream &OS;
|
raw_ostream &OS;
|
||||||
|
|
||||||
iplist<MCSectionData> Sections;
|
iplist<MCSectionData> Sections;
|
||||||
|
@ -617,7 +620,7 @@ 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, raw_ostream &OS);
|
MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend, raw_ostream &OS);
|
||||||
~MCAssembler();
|
~MCAssembler();
|
||||||
|
|
||||||
MCContext &getContext() const { return Context; }
|
MCContext &getContext() const { return Context; }
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace llvm {
|
||||||
class MCSection;
|
class MCSection;
|
||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
class StringRef;
|
class StringRef;
|
||||||
|
class TargetAsmBackend;
|
||||||
class Twine;
|
class Twine;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
class formatted_raw_ostream;
|
class formatted_raw_ostream;
|
||||||
|
@ -304,18 +305,10 @@ namespace llvm {
|
||||||
MCCodeEmitter *CE = 0,
|
MCCodeEmitter *CE = 0,
|
||||||
bool ShowInst = false);
|
bool ShowInst = false);
|
||||||
|
|
||||||
// FIXME: These two may end up getting rolled into a single
|
|
||||||
// createObjectStreamer interface, which implements the assembler backend, and
|
|
||||||
// is parameterized on an output object file writer.
|
|
||||||
|
|
||||||
/// createMachOStream - Create a machine code streamer which will generative
|
/// createMachOStream - Create a machine code streamer which will generative
|
||||||
/// Mach-O format object files.
|
/// Mach-O format object files.
|
||||||
MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS,
|
MCStreamer *createMachOStreamer(MCContext &Ctx, TargetAsmBackend &TAB,
|
||||||
MCCodeEmitter *CE);
|
raw_ostream &OS, MCCodeEmitter *CE);
|
||||||
|
|
||||||
/// createELFStreamer - Create a machine code streamer which will generative
|
|
||||||
/// ELF format object files.
|
|
||||||
MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
|
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
|
|
|
@ -224,6 +224,8 @@ public:
|
||||||
/// implemented with the LLVM target-independent code generator.
|
/// implemented with the LLVM target-independent code generator.
|
||||||
///
|
///
|
||||||
class LLVMTargetMachine : public TargetMachine {
|
class LLVMTargetMachine : public TargetMachine {
|
||||||
|
std::string TargetTriple;
|
||||||
|
|
||||||
protected: // Can only create subclasses.
|
protected: // Can only create subclasses.
|
||||||
LLVMTargetMachine(const Target &T, const std::string &TargetTriple);
|
LLVMTargetMachine(const Target &T, const std::string &TargetTriple);
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,8 @@ static cl::opt<bool> EnableSplitGEPGVN("split-gep-gvn", cl::Hidden,
|
||||||
cl::desc("Split GEPs and run no-load GVN"));
|
cl::desc("Split GEPs and run no-load GVN"));
|
||||||
|
|
||||||
LLVMTargetMachine::LLVMTargetMachine(const Target &T,
|
LLVMTargetMachine::LLVMTargetMachine(const Target &T,
|
||||||
const std::string &TargetTriple)
|
const std::string &Triple)
|
||||||
: TargetMachine(T) {
|
: TargetMachine(T), TargetTriple(Triple) {
|
||||||
AsmInfo = T.createAsmInfo(TargetTriple);
|
AsmInfo = T.createAsmInfo(TargetTriple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +143,11 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
|
||||||
// Create the code emitter for the target if it exists. If not, .o file
|
// Create the code emitter for the target if it exists. If not, .o file
|
||||||
// emission fails.
|
// emission fails.
|
||||||
MCCodeEmitter *MCE = getTarget().createCodeEmitter(*this, *Context);
|
MCCodeEmitter *MCE = getTarget().createCodeEmitter(*this, *Context);
|
||||||
if (MCE == 0)
|
TargetAsmBackend *TAB = getTarget().createAsmBackend(TargetTriple);
|
||||||
|
if (MCE == 0 || TAB == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
AsmStreamer.reset(createMachOStreamer(*Context, Out, MCE));
|
AsmStreamer.reset(createMachOStreamer(*Context, *TAB, Out, MCE));
|
||||||
|
|
||||||
// Any output to the asmprinter's "O" stream is bad and needs to be fixed,
|
// Any output to the asmprinter's "O" stream is bad and needs to be fixed,
|
||||||
// force it to come out stderr.
|
// force it to come out stderr.
|
||||||
|
|
|
@ -991,8 +991,9 @@ MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
|
||||||
|
|
||||||
/* *** */
|
/* *** */
|
||||||
|
|
||||||
MCAssembler::MCAssembler(MCContext &_Context, raw_ostream &_OS)
|
MCAssembler::MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
|
||||||
: Context(_Context), OS(_OS), SubsectionsViaSymbols(false)
|
raw_ostream &_OS)
|
||||||
|
: Context(_Context), Backend(_Backend), OS(_OS), SubsectionsViaSymbols(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MCMachOStreamer(MCContext &Context, raw_ostream &_OS, MCCodeEmitter *_Emitter)
|
MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
||||||
: MCStreamer(Context), Assembler(Context, _OS), Emitter(_Emitter),
|
raw_ostream &_OS, MCCodeEmitter *_Emitter)
|
||||||
|
: MCStreamer(Context), Assembler(Context, TAB, _OS), Emitter(_Emitter),
|
||||||
CurSectionData(0) {}
|
CurSectionData(0) {}
|
||||||
~MCMachOStreamer() {}
|
~MCMachOStreamer() {}
|
||||||
|
|
||||||
|
@ -398,7 +399,7 @@ void MCMachOStreamer::Finish() {
|
||||||
Assembler.Finish();
|
Assembler.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
MCStreamer *llvm::createMachOStreamer(MCContext &Context, raw_ostream &OS,
|
MCStreamer *llvm::createMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
||||||
MCCodeEmitter *CE) {
|
raw_ostream &OS, MCCodeEmitter *CE) {
|
||||||
return new MCMachOStreamer(Context, OS, CE);
|
return new MCMachOStreamer(Context, TAB, OS, CE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
|
#include "llvm/Target/TargetAsmBackend.h"
|
||||||
#include "llvm/Target/TargetAsmParser.h"
|
#include "llvm/Target/TargetAsmParser.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
|
@ -259,6 +260,7 @@ static int AssembleInput(const char *ProgName) {
|
||||||
OwningPtr<MCInstPrinter> IP;
|
OwningPtr<MCInstPrinter> IP;
|
||||||
OwningPtr<MCCodeEmitter> CE;
|
OwningPtr<MCCodeEmitter> CE;
|
||||||
OwningPtr<MCStreamer> Str;
|
OwningPtr<MCStreamer> Str;
|
||||||
|
OwningPtr<TargetAsmBackend> TAB;
|
||||||
|
|
||||||
const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName);
|
const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName);
|
||||||
assert(MAI && "Unable to create target asm info!");
|
assert(MAI && "Unable to create target asm info!");
|
||||||
|
@ -274,7 +276,8 @@ static int AssembleInput(const char *ProgName) {
|
||||||
} else {
|
} else {
|
||||||
assert(FileType == OFT_ObjectFile && "Invalid file type!");
|
assert(FileType == OFT_ObjectFile && "Invalid file type!");
|
||||||
CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
|
CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
|
||||||
Str.reset(createMachOStreamer(Ctx, *Out, CE.get()));
|
TAB.reset(TheTarget->createAsmBackend(TripleName));
|
||||||
|
Str.reset(createMachOStreamer(Ctx, *TAB, *Out, CE.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI);
|
AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI);
|
||||||
|
|
Loading…
Reference in New Issue