From 30bfebf7ccb4ae0f9fcf48d7cbf6671022bbc065 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 9 Dec 2013 20:26:40 +0000 Subject: [PATCH] Use a more direct check for finding out the file type. No functionality change. llvm-svn: 196811 --- include/llvm/LTO/LTOModule.h | 2 ++ include/llvm/MC/MCObjectFileInfo.h | 6 +++++- lib/LTO/LTOModule.cpp | 8 ++++++-- lib/MC/MCParser/AsmParser.cpp | 28 +++++++++++++++------------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/include/llvm/LTO/LTOModule.h b/include/llvm/LTO/LTOModule.h index f4693c8d226..d7205d8d9a6 100644 --- a/include/llvm/LTO/LTOModule.h +++ b/include/llvm/LTO/LTOModule.h @@ -19,6 +19,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/IR/Module.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCObjectFileInfo.h" #include "llvm/Target/Mangler.h" #include "llvm/Target/TargetMachine.h" #include @@ -49,6 +50,7 @@ private: llvm::OwningPtr _module; llvm::OwningPtr _target; + llvm::MCObjectFileInfo ObjFileInfo; std::vector _symbols; // _defines and _undefines only needed to disambiguate tentative definitions diff --git a/include/llvm/MC/MCObjectFileInfo.h b/include/llvm/MC/MCObjectFileInfo.h index c48dcb02162..277ca579dae 100644 --- a/include/llvm/MC/MCObjectFileInfo.h +++ b/include/llvm/MC/MCObjectFileInfo.h @@ -353,8 +353,12 @@ public: return EHFrameSection; } -private: enum Environment { IsMachO, IsELF, IsCOFF }; + Environment getObjectFileType() const { + return Env; + } + +private: Environment Env; Reloc::Model RelocM; CodeModel::Model CMModel; diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 77eb3cae78b..28a6d61f28a 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -43,8 +43,12 @@ using namespace llvm; LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t) : _module(m), _target(t), - _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), NULL), - _mangler(t) {} + _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), &ObjFileInfo), + _mangler(t) { + ObjFileInfo.InitMCObjectFileInfo(t->getTargetTriple(), + t->getRelocationModel(), t->getCodeModel(), + _context); +} /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM /// bitcode. diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 01fe87e0d66..fe3969a0a78 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -22,6 +22,7 @@ #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCParser/AsmCond.h" #include "llvm/MC/MCParser/AsmLexer.h" #include "llvm/MC/MCParser/MCAsmParser.h" @@ -491,19 +492,20 @@ AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); // Initialize the platform / file format parser. - // - // FIXME: This is a hack, we need to (majorly) cleanup how these objects are - // created. - if (_MAI.hasMicrosoftFastStdCallMangling()) { - PlatformParser = createCOFFAsmParser(); - PlatformParser->Initialize(*this); - } else if (_MAI.hasSubsectionsViaSymbols()) { - PlatformParser = createDarwinAsmParser(); - PlatformParser->Initialize(*this); - IsDarwin = true; - } else { - PlatformParser = createELFAsmParser(); - PlatformParser->Initialize(*this); + switch (_Ctx.getObjectFileInfo()->getObjectFileType()) { + case MCObjectFileInfo::IsCOFF: + PlatformParser = createCOFFAsmParser(); + PlatformParser->Initialize(*this); + break; + case MCObjectFileInfo::IsMachO: + PlatformParser = createDarwinAsmParser(); + PlatformParser->Initialize(*this); + IsDarwin = true; + break; + case MCObjectFileInfo::IsELF: + PlatformParser = createELFAsmParser(); + PlatformParser->Initialize(*this); + break; } initializeDirectiveKindMap();