diff options
Diffstat (limited to 'tools/lto/LTOModule.cpp')
-rw-r--r-- | tools/lto/LTOModule.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index dc99b94..4ba8985 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -27,6 +27,8 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/SourceMgr.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" #include "llvm/Support/system_error.h" #include "llvm/Target/Mangler.h" #include "llvm/MC/MCAsmInfo.h" @@ -38,10 +40,9 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/SubtargetFeature.h" -#include "llvm/Target/TargetAsmParser.h" +#include "llvm/MC/MCTargetAsmParser.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetRegistry.h" -#include "llvm/Target/TargetSelect.h" +#include "llvm/Target/TargetRegisterInfo.h" using namespace llvm; @@ -135,8 +136,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, static bool Initialized = false; if (!Initialized) { InitializeAllTargets(); - InitializeAllMCAsmInfos(); - InitializeAllMCSubtargetInfos(); + InitializeAllTargetMCs(); InitializeAllAsmParsers(); Initialized = true; } @@ -165,7 +165,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, std::string CPU; TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr); LTOModule *Ret = new LTOModule(m.take(), target); - bool Err = Ret->ParseSymbols(); + bool Err = Ret->ParseSymbols(errMsg); if (Err) { delete Ret; return NULL; @@ -581,7 +581,8 @@ namespace { markDefined(*Symbol); } virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {} - virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {} + virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, + unsigned ByteAlignment) {} virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) {} virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {} @@ -612,22 +613,30 @@ namespace { }; } -bool LTOModule::addAsmGlobalSymbols(MCContext &Context) { +bool LTOModule::addAsmGlobalSymbols(MCContext &Context, std::string &errMsg) { const std::string &inlineAsm = _module->getModuleInlineAsm(); + if (inlineAsm.empty()) + return false; OwningPtr<RecordStreamer> Streamer(new RecordStreamer(Context)); MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(inlineAsm); SourceMgr SrcMgr; SrcMgr.AddNewSourceBuffer(Buffer, SMLoc()); - OwningPtr<MCAsmParser> Parser(createMCAsmParser(_target->getTarget(), SrcMgr, + OwningPtr<MCAsmParser> Parser(createMCAsmParser(SrcMgr, Context, *Streamer, *_target->getMCAsmInfo())); OwningPtr<MCSubtargetInfo> STI(_target->getTarget(). createMCSubtargetInfo(_target->getTargetTriple(), _target->getTargetCPU(), _target->getTargetFeatureString())); - OwningPtr<TargetAsmParser> - TAP(_target->getTarget().createAsmParser(*STI, *Parser.get())); + OwningPtr<MCTargetAsmParser> + TAP(_target->getTarget().createMCAsmParser(*STI, *Parser.get())); + if (!TAP) { + errMsg = "target " + std::string(_target->getTarget().getName()) + + " does not define AsmParser."; + return true; + } + Parser->setTargetParser(*TAP); int Res = Parser->Run(false); if (Res) @@ -660,9 +669,9 @@ static bool isAliasToDeclaration(const GlobalAlias &V) { return isDeclaration(*V.getAliasedGlobal()); } -bool LTOModule::ParseSymbols() { +bool LTOModule::ParseSymbols(std::string &errMsg) { // Use mangler to add GlobalPrefix to names to match linker names. - MCContext Context(*_target->getMCAsmInfo(), NULL); + MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL); Mangler mangler(Context, *_target->getTargetData()); // add functions @@ -683,7 +692,7 @@ bool LTOModule::ParseSymbols() { } // add asm globals - if (addAsmGlobalSymbols(Context)) + if (addAsmGlobalSymbols(Context, errMsg)) return true; // add aliases |