mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
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
This commit is contained in:
parent
68f195cc50
commit
9823ca971d
@ -41,7 +41,7 @@ struct AsmToken {
|
||||
Star, Comma, Dollar, Equal, EqualEqual,
|
||||
|
||||
Pipe, PipePipe, Caret,
|
||||
Amp, AmpAmp, Exclaim, ExclaimEqual, Percent,
|
||||
Amp, AmpAmp, Exclaim, ExclaimEqual, Percent, Hash,
|
||||
Less, LessEqual, LessLess, LessGreater,
|
||||
Greater, GreaterEqual, GreaterGreater
|
||||
};
|
||||
|
@ -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':
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user