From f92f9909c4e5943cc115b9662fb5540a2eb59984 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Fri, 4 Sep 2009 21:45:34 +0000 Subject: Added the AsmToken::Hash enum constant to MCAsmLexer.h in preparation of supporting other targets. Changed the code to pass MCAsmInfo to the parser and the lexer. Then changed the lexer to use CommentString from MCAsmInfo instead of a literal '#' character. llvm-svn: 81046 --- llvm/tools/llvm-mc/llvm-mc.cpp | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'llvm/tools/llvm-mc/llvm-mc.cpp') diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index 84131c7ca66..bf3c01794bc 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -82,6 +82,18 @@ Action(cl::desc("Action to perform:"), "Assemble a .s file (default)"), clEnumValEnd)); +static const Target *GetTarget(const char *ProgName) { + // Get the target specific parser. + std::string Error; + const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error); + if (TheTarget) + return TheTarget; + + errs() << ProgName << ": error: unable to get target for '" << TripleName + << "', see --version and --triple.\n"; + return 0; +} + static int AsLexInput(const char *ProgName) { std::string ErrorMessage; MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, @@ -104,7 +116,14 @@ static int AsLexInput(const char *ProgName) { // it later. SrcMgr.setIncludeDirs(IncludeDirs); - AsmLexer Lexer(SrcMgr); + const Target *TheTarget = GetTarget(ProgName); + if (!TheTarget) + return 1; + + const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName); + assert(MAI && "Unable to create target asm info!"); + + AsmLexer Lexer(SrcMgr, *MAI); bool Error = false; @@ -162,18 +181,6 @@ static int AsLexInput(const char *ProgName) { return Error; } -static const Target *GetTarget(const char *ProgName) { - // Get the target specific parser. - std::string Error; - const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error); - if (TheTarget) - return TheTarget; - - errs() << ProgName << ": error: unable to get target for '" << TripleName - << "', see --version and --triple.\n"; - return 0; -} - static formatted_raw_ostream *GetOutputStream() { if (OutputFilename == "") OutputFilename = "-"; @@ -239,10 +246,10 @@ static int AssembleInput(const char *ProgName) { OwningPtr CE; OwningPtr Str; - if (FileType == OFT_AssemblyFile) { - const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName); - assert(MAI && "Unable to create target asm info!"); + const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName); + assert(MAI && "Unable to create target asm info!"); + if (FileType == OFT_AssemblyFile) { AP.reset(TheTarget->createAsmPrinter(*Out, *TM, MAI, true)); if (ShowEncoding) CE.reset(TheTarget->createCodeEmitter(*TM)); @@ -253,7 +260,7 @@ static int AssembleInput(const char *ProgName) { Str.reset(createMachOStreamer(Ctx, *Out, CE.get())); } - AsmParser Parser(SrcMgr, Ctx, *Str.get()); + AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI); OwningPtr TAP(TheTarget->createAsmParser(Parser)); if (!TAP) { errs() << ProgName -- cgit v1.2.3