diff options
author | Kevin Enderby <enderby@apple.com> | 2009-09-04 21:45:34 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2009-09-04 21:45:34 +0000 |
commit | 685689cae6703e4ca9fce5805b44e99ca8047d4e (patch) | |
tree | 96b87e75cf825093e41b7784be3f0042e50d587f /tools | |
parent | 08fe10526f25d21437fd484b007a6ab772ef794d (diff) | |
download | external_llvm-685689cae6703e4ca9fce5805b44e99ca8047d4e.zip external_llvm-685689cae6703e4ca9fce5805b44e99ca8047d4e.tar.gz external_llvm-685689cae6703e4ca9fce5805b44e99ca8047d4e.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81046 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-mc/AsmLexer.cpp | 20 | ||||
-rw-r--r-- | tools/llvm-mc/AsmLexer.h | 5 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.h | 7 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 41 |
4 files changed, 48 insertions, 25 deletions
diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp index 4dafa0e..f6be886 100644 --- a/tools/llvm-mc/AsmLexer.cpp +++ b/tools/llvm-mc/AsmLexer.cpp @@ -15,12 +15,14 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Config/config.h" // for strtoull. +#include "llvm/MC/MCAsmInfo.h" #include <cerrno> #include <cstdio> #include <cstdlib> using namespace llvm; -AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) { +AsmLexer::AsmLexer(SourceMgr &SM, const MCAsmInfo &_MAI) : SrcMgr(SM), + MAI(_MAI) { CurBuffer = 0; CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); CurPtr = CurBuf->getBufferStart(); @@ -230,12 +232,16 @@ AsmToken AsmLexer::LexQuote() { StringRef AsmLexer::LexUntilEndOfStatement() { TokStart = CurPtr; - while (*CurPtr != '#' && // Start of line comment. - *CurPtr != ';' && // End of statement marker. + while (*CurPtr != ';' && // End of statement marker. *CurPtr != '\n' && *CurPtr != '\r' && - (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) + (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) { + // check for start of line comment. + for (const char *p = MAI.getCommentString(); *p != 0; ++p) + if (*CurPtr == *p) + break; ++CurPtr; + } return StringRef(TokStart, CurPtr-TokStart); } @@ -244,6 +250,10 @@ AsmToken AsmLexer::LexToken() { // This always consumes at least one character. int CurChar = getNextChar(); + for (const char *p = MAI.getCommentString(); *p != 0; ++p) + if (CurChar == *p) + return LexLineComment(); + switch (CurChar) { default: // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* @@ -289,7 +299,7 @@ AsmToken AsmLexer::LexToken() { return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1)); case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1)); case '/': return LexSlash(); - case '#': return LexLineComment(); + case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1)); case '"': return LexQuote(); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': diff --git a/tools/llvm-mc/AsmLexer.h b/tools/llvm-mc/AsmLexer.h index 000df59..32b0c5f 100644 --- a/tools/llvm-mc/AsmLexer.h +++ b/tools/llvm-mc/AsmLexer.h @@ -16,6 +16,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/MC/MCAsmLexer.h" +#include "llvm/MC/MCAsmInfo.h" #include "llvm/Support/DataTypes.h" #include <string> #include <cassert> @@ -24,10 +25,12 @@ namespace llvm { class MemoryBuffer; class SourceMgr; class SMLoc; +class MCAsmInfo; /// AsmLexer - Lexer class for assembly files. class AsmLexer : public MCAsmLexer { SourceMgr &SrcMgr; + const MCAsmInfo MAI; const char *CurPtr; const MemoryBuffer *CurBuf; @@ -46,7 +49,7 @@ protected: virtual AsmToken LexToken(); public: - AsmLexer(SourceMgr &SrcMgr); + AsmLexer(SourceMgr &SrcMgr, const MCAsmInfo &MAI); ~AsmLexer(); SMLoc getLoc() const; diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index 7471a90..7f038c9 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -20,6 +20,7 @@ #include "llvm/MC/MCAsmParser.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCAsmInfo.h" namespace llvm { class AsmCond; @@ -27,6 +28,7 @@ class MCContext; class MCExpr; class MCInst; class MCStreamer; +class MCAsmInfo; class MCValue; class TargetAsmParser; class Twine; @@ -46,8 +48,9 @@ private: mutable void *SectionUniquingMap; public: - AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out) - : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0), + AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, + const MCAsmInfo &_MAI) + : Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), TargetParser(0), SectionUniquingMap(0) {} ~AsmParser(); diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 84131c7..bf3c017 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/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<MCCodeEmitter> CE; OwningPtr<MCStreamer> 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<TargetAsmParser> TAP(TheTarget->createAsmParser(Parser)); if (!TAP) { errs() << ProgName |