diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-07-28 20:47:52 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-07-28 20:47:52 +0000 |
commit | a2edbabcb86f213eca6daeda5d801f8c7b1e44b2 (patch) | |
tree | 39706b60d8a13250bebc838e11b961a4613b513f /tools/llvm-mc | |
parent | d2f79a13463f8797fbffa0e5d577c5bddc9126fb (diff) | |
download | external_llvm-a2edbabcb86f213eca6daeda5d801f8c7b1e44b2.zip external_llvm-a2edbabcb86f213eca6daeda5d801f8c7b1e44b2.tar.gz external_llvm-a2edbabcb86f213eca6daeda5d801f8c7b1e44b2.tar.bz2 |
Provide generic MCAsmParser when constructing target specific parsers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77362 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc')
-rw-r--r-- | tools/llvm-mc/AsmParser.h | 14 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 34 |
2 files changed, 27 insertions, 21 deletions
diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index dd60338..253bb8b 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -27,7 +27,7 @@ class MCValue; class TargetAsmParser; class Twine; -class AsmParser : MCAsmParser { +class AsmParser : public MCAsmParser { public: struct X86Operand; @@ -35,18 +35,18 @@ private: AsmLexer Lexer; MCContext &Ctx; MCStreamer &Out; - TargetAsmParser &TargetParser; + TargetAsmParser *TargetParser; public: - AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, - TargetAsmParser &_TargetParser) - : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {} + AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out) + : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {} ~AsmParser() {} - + bool Run(); public: - TargetAsmParser &getTargetParser() const { return TargetParser; } + TargetAsmParser &getTargetParser() const { return *TargetParser; } + void setTargetParser(TargetAsmParser &P) { TargetParser = &P; } virtual MCAsmLexer &getLexer() { return Lexer; } diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index a64c8a6..e148e35 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Signals.h" +#include "llvm/Target/TargetAsmParser.h" #include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetSelect.h" #include "AsmParser.h" @@ -140,7 +141,8 @@ static int AsLexInput(const char *ProgName) { return Error; } -static int AssembleInput(const char *ProgName) { +static TargetAsmParser *GetTargetAsmParser(const char *ProgName, + MCAsmParser &Parser) { // Get the target specific parser. std::string Error; const Target *TheTarget = @@ -151,23 +153,24 @@ static int AssembleInput(const char *ProgName) { if (TheTarget == 0) { errs() << ProgName << ": error: unable to get target for '" << TripleName << "', see --version and --triple.\n"; - return 1; + return 0; } - TargetAsmParser *TAP = TheTarget->createAsmParser(); - if (!TAP) { - errs() << ProgName - << ": error: this target does not support assembly parsing.\n"; - return 1; - } + if (TargetAsmParser *TAP = TheTarget->createAsmParser(Parser)) + return TAP; + + errs() << ProgName + << ": error: this target does not support assembly parsing.\n"; + return 0; +} - std::string ErrorMessage; - MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, - &ErrorMessage); +static int AssembleInput(const char *ProgName) { + std::string Error; + MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, &Error); if (Buffer == 0) { errs() << ProgName << ": "; - if (ErrorMessage.size()) - errs() << ErrorMessage << "\n"; + if (Error.size()) + errs() << Error << "\n"; else errs() << "input file didn't read correctly.\n"; return 1; @@ -189,7 +192,10 @@ static int AssembleInput(const char *ProgName) { Str.get()->SwitchSection(Ctx.GetSection("__TEXT,__text," "regular,pure_instructions")); - AsmParser Parser(SrcMgr, Ctx, *Str.get(), *TAP); + AsmParser Parser(SrcMgr, Ctx, *Str.get()); + OwningPtr<TargetAsmParser> TAP(GetTargetAsmParser(ProgName, Parser)); + if (!TAP) + return 1; return Parser.Run(); } |