CurBuffer = 0;
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
CurPtr = CurBuf->getBufferStart();
- CurTok = AsmToken(asmtok::Error, StringRef(CurPtr, 0));
+ CurTok = AsmToken(AsmToken::Error, StringRef(CurPtr, 0));
TokStart = 0;
}
}
/// ReturnError - Set the error to the specified string at the specified
-/// location. This is defined to always return asmtok::Error.
+/// location. This is defined to always return AsmToken::Error.
AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
- return AsmToken(asmtok::Error, StringRef(Loc, 0));
+ return AsmToken(AsmToken::Error, StringRef(Loc, 0));
}
/// EnterIncludeFile - Enter the specified file. This prints an error and
while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||
*CurPtr == '.' || *CurPtr == '@')
++CurPtr;
- return AsmToken(asmtok::Identifier, StringRef(TokStart, CurPtr - TokStart));
+ return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart));
}
/// LexPercent: Register: %[a-zA-Z0-9]+
AsmToken AsmLexer::LexPercent() {
if (!isalnum(*CurPtr))
- return AsmToken(asmtok::Percent, StringRef(CurPtr, 1)); // Single %.
+ return AsmToken(AsmToken::Percent, StringRef(CurPtr, 1)); // Single %.
while (isalnum(*CurPtr))
++CurPtr;
- return AsmToken(asmtok::Register, StringRef(TokStart, CurPtr - TokStart));
+ return AsmToken(AsmToken::Register, StringRef(TokStart, CurPtr - TokStart));
}
/// LexSlash: Slash: /
switch (*CurPtr) {
case '*': break; // C style comment.
case '/': return ++CurPtr, LexLineComment();
- default: return AsmToken(asmtok::Slash, StringRef(CurPtr, 1));
+ default: return AsmToken(AsmToken::Slash, StringRef(CurPtr, 1));
}
// C Style comment.
CurChar = getNextChar();
if (CurChar == EOF)
- return AsmToken(asmtok::Eof, StringRef(CurPtr, 0));
- return AsmToken(asmtok::EndOfStatement, StringRef(CurPtr, 0));
+ return AsmToken(AsmToken::Eof, StringRef(CurPtr, 0));
+ return AsmToken(AsmToken::EndOfStatement, StringRef(CurPtr, 0));
}
if (CurPtr[-1] != '0') {
while (isdigit(*CurPtr))
++CurPtr;
- return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart),
+ return AsmToken(AsmToken::Integer, StringRef(TokStart, CurPtr - TokStart),
strtoll(TokStart, 0, 10));
}
// Requires at least one binary digit.
if (CurPtr == NumStart)
return ReturnError(CurPtr-2, "Invalid binary number");
- return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart),
+ return AsmToken(AsmToken::Integer, StringRef(TokStart, CurPtr - TokStart),
strtoll(NumStart, 0, 2));
}
if (errno == ERANGE)
return ReturnError(CurPtr-2, "Hexadecimal number out of range");
}
- return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart),
+ return AsmToken(AsmToken::Integer, StringRef(TokStart, CurPtr - TokStart),
(int64_t) strtoull(NumStart, 0, 16));
}
// Must be an octal number, it starts with 0.
while (*CurPtr >= '0' && *CurPtr <= '7')
++CurPtr;
- return AsmToken(asmtok::IntVal, StringRef(TokStart, CurPtr - TokStart),
+ return AsmToken(AsmToken::Integer, StringRef(TokStart, CurPtr - TokStart),
strtoll(TokStart, 0, 8));
}
CurChar = getNextChar();
}
- return AsmToken(asmtok::String, StringRef(TokStart, CurPtr - TokStart));
+ return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
}
// Unknown character, emit an error.
return ReturnError(TokStart, "invalid character in input");
- case EOF: return AsmToken(asmtok::Eof, StringRef(TokStart, 0));
+ case EOF: return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
case 0:
case ' ':
case '\t':
return LexToken();
case '\n': // FALL THROUGH.
case '\r': // FALL THROUGH.
- case ';': return AsmToken(asmtok::EndOfStatement, StringRef(TokStart, 1));
- case ':': return AsmToken(asmtok::Colon, StringRef(TokStart, 1));
- case '+': return AsmToken(asmtok::Plus, StringRef(TokStart, 1));
- case '-': return AsmToken(asmtok::Minus, StringRef(TokStart, 1));
- case '~': return AsmToken(asmtok::Tilde, StringRef(TokStart, 1));
- case '(': return AsmToken(asmtok::LParen, StringRef(TokStart, 1));
- case ')': return AsmToken(asmtok::RParen, StringRef(TokStart, 1));
- case '*': return AsmToken(asmtok::Star, StringRef(TokStart, 1));
- case ',': return AsmToken(asmtok::Comma, StringRef(TokStart, 1));
- case '$': return AsmToken(asmtok::Dollar, StringRef(TokStart, 1));
+ case ';': return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
+ case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
+ case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
+ case '-': return AsmToken(AsmToken::Minus, StringRef(TokStart, 1));
+ case '~': return AsmToken(AsmToken::Tilde, StringRef(TokStart, 1));
+ case '(': return AsmToken(AsmToken::LParen, StringRef(TokStart, 1));
+ case ')': return AsmToken(AsmToken::RParen, StringRef(TokStart, 1));
+ case '*': return AsmToken(AsmToken::Star, StringRef(TokStart, 1));
+ case ',': return AsmToken(AsmToken::Comma, StringRef(TokStart, 1));
+ case '$': return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1));
case '=':
if (*CurPtr == '=')
- return ++CurPtr, AsmToken(asmtok::EqualEqual, StringRef(TokStart, 2));
- return AsmToken(asmtok::Equal, StringRef(TokStart, 1));
+ return ++CurPtr, AsmToken(AsmToken::EqualEqual, StringRef(TokStart, 2));
+ return AsmToken(AsmToken::Equal, StringRef(TokStart, 1));
case '|':
if (*CurPtr == '|')
- return ++CurPtr, AsmToken(asmtok::PipePipe, StringRef(TokStart, 2));
- return AsmToken(asmtok::Pipe, StringRef(TokStart, 1));
- case '^': return AsmToken(asmtok::Caret, StringRef(TokStart, 1));
+ return ++CurPtr, AsmToken(AsmToken::PipePipe, StringRef(TokStart, 2));
+ return AsmToken(AsmToken::Pipe, StringRef(TokStart, 1));
+ case '^': return AsmToken(AsmToken::Caret, StringRef(TokStart, 1));
case '&':
if (*CurPtr == '&')
- return ++CurPtr, AsmToken(asmtok::AmpAmp, StringRef(TokStart, 2));
- return AsmToken(asmtok::Amp, StringRef(TokStart, 1));
+ return ++CurPtr, AsmToken(AsmToken::AmpAmp, StringRef(TokStart, 2));
+ return AsmToken(AsmToken::Amp, StringRef(TokStart, 1));
case '!':
if (*CurPtr == '=')
- return ++CurPtr, AsmToken(asmtok::ExclaimEqual, StringRef(TokStart, 2));
- return AsmToken(asmtok::Exclaim, StringRef(TokStart, 1));
+ return ++CurPtr, AsmToken(AsmToken::ExclaimEqual, StringRef(TokStart, 2));
+ return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
case '%': return LexPercent();
case '/': return LexSlash();
case '#': return LexLineComment();
return LexDigit();
case '<':
switch (*CurPtr) {
- case '<': return ++CurPtr, AsmToken(asmtok::LessLess,
+ case '<': return ++CurPtr, AsmToken(AsmToken::LessLess,
StringRef(TokStart, 2));
- case '=': return ++CurPtr, AsmToken(asmtok::LessEqual,
+ case '=': return ++CurPtr, AsmToken(AsmToken::LessEqual,
StringRef(TokStart, 2));
- case '>': return ++CurPtr, AsmToken(asmtok::LessGreater,
+ case '>': return ++CurPtr, AsmToken(AsmToken::LessGreater,
StringRef(TokStart, 2));
- default: return AsmToken(asmtok::Less, StringRef(TokStart, 1));
+ default: return AsmToken(AsmToken::Less, StringRef(TokStart, 1));
}
case '>':
switch (*CurPtr) {
- case '>': return ++CurPtr, AsmToken(asmtok::GreaterGreater,
+ case '>': return ++CurPtr, AsmToken(AsmToken::GreaterGreater,
StringRef(TokStart, 2));
- case '=': return ++CurPtr, AsmToken(asmtok::GreaterEqual,
+ case '=': return ++CurPtr, AsmToken(AsmToken::GreaterEqual,
StringRef(TokStart, 2));
- default: return AsmToken(asmtok::Greater, StringRef(TokStart, 1));
+ default: return AsmToken(AsmToken::Greater, StringRef(TokStart, 1));
}
// TODO: Quoted identifiers (objc methods etc)
class SourceMgr;
class SMLoc;
-namespace asmtok {
- enum TokKind {
+/// AsmToken - Target independent representation for an assembler token.
+struct AsmToken {
+ enum TokenKind {
// Markers
Eof, Error,
String,
// Integer values.
- IntVal,
+ Integer,
// No-value.
EndOfStatement,
Less, LessEqual, LessLess, LessGreater,
Greater, GreaterEqual, GreaterGreater
};
-}
-/// AsmToken - Target independent representation for an assembler token.
-struct AsmToken {
- asmtok::TokKind Kind;
+ TokenKind Kind;
/// A reference to the entire token contents; this is always a pointer into
/// a memory buffer owned by the source manager.
public:
AsmToken() {}
- AsmToken(asmtok::TokKind _Kind, const StringRef &_Str, int64_t _IntVal = 0)
+ AsmToken(TokenKind _Kind, const StringRef &_Str, int64_t _IntVal = 0)
: Kind(_Kind), Str(_Str), IntVal(_IntVal) {}
- asmtok::TokKind getKind() const { return Kind; }
- bool is(asmtok::TokKind K) const { return Kind == K; }
- bool isNot(asmtok::TokKind K) const { return Kind != K; }
+ TokenKind getKind() const { return Kind; }
+ bool is(TokenKind K) const { return Kind == K; }
+ bool isNot(TokenKind K) const { return Kind != K; }
SMLoc getLoc() const;
StringRef getString() const { return Str; }
+ // FIXME: Don't compute this in advance, it makes every token larger, and is
+ // also not generally what we want (it is nicer for recovery etc. to lex 123br
+ // as a single token, then diagnose as an invalid number).
int64_t getIntVal() const {
- assert(Kind == asmtok::IntVal && "This token isn't an integer");
+ assert(Kind == Integer && "This token isn't an integer");
return IntVal;
}
};
AsmLexer(SourceMgr &SrcMgr);
~AsmLexer();
- asmtok::TokKind Lex() {
+ AsmToken::TokenKind Lex() {
return CurTok = LexToken(), getKind();
}
- asmtok::TokKind getKind() const { return CurTok.getKind(); }
- bool is(asmtok::TokKind K) const { return CurTok.is(K); }
- bool isNot(asmtok::TokKind K) const { return CurTok.isNot(K); }
+ AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
+ bool is(AsmToken::TokenKind K) const { return CurTok.is(K); }
+ bool isNot(AsmToken::TokenKind K) const { return CurTok.isNot(K); }
/// getCurStrVal - Get the string for the current token, this includes all
/// characters (for example, the quotes on strings) in the token.
}
SMLoc getLoc() const;
+
+ const AsmToken &getTok() const;
/// EnterIncludeFile - Enter the specified file. This returns true on failure.
bool EnterIncludeFile(const std::string &Filename);
bool HadError = false;
// While we have input, parse each statement.
- while (Lexer.isNot(asmtok::Eof)) {
+ while (Lexer.isNot(AsmToken::Eof)) {
if (!ParseStatement()) continue;
// If we had an error, remember it and recover by skipping to the next line.
/// EatToEndOfStatement - Throw away the rest of the line for testing purposes.
void AsmParser::EatToEndOfStatement() {
- while (Lexer.isNot(asmtok::EndOfStatement) &&
- Lexer.isNot(asmtok::Eof))
+ while (Lexer.isNot(AsmToken::EndOfStatement) &&
+ Lexer.isNot(AsmToken::Eof))
Lexer.Lex();
// Eat EOL.
- if (Lexer.is(asmtok::EndOfStatement))
+ if (Lexer.is(AsmToken::EndOfStatement))
Lexer.Lex();
}
///
bool AsmParser::ParseParenExpr(AsmExpr *&Res) {
if (ParseExpression(Res)) return true;
- if (Lexer.isNot(asmtok::RParen))
+ if (Lexer.isNot(AsmToken::RParen))
return TokError("expected ')' in parentheses expression");
Lexer.Lex();
return false;
switch (Lexer.getKind()) {
default:
return TokError("unknown token in expression");
- case asmtok::Exclaim:
+ case AsmToken::Exclaim:
Lexer.Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res))
return true;
Res = new AsmUnaryExpr(AsmUnaryExpr::LNot, Res);
return false;
- case asmtok::Identifier: {
+ case AsmToken::Identifier: {
// This is a label, this should be parsed as part of an expression, to
// handle things like LFOO+4.
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
Lexer.Lex(); // Eat identifier.
return false;
}
- case asmtok::IntVal:
+ case AsmToken::Integer:
Res = new AsmConstantExpr(Lexer.getCurIntVal());
Lexer.Lex(); // Eat identifier.
return false;
- case asmtok::LParen:
+ case AsmToken::LParen:
Lexer.Lex(); // Eat the '('.
return ParseParenExpr(Res);
- case asmtok::Minus:
+ case AsmToken::Minus:
Lexer.Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res))
return true;
Res = new AsmUnaryExpr(AsmUnaryExpr::Minus, Res);
return false;
- case asmtok::Plus:
+ case AsmToken::Plus:
Lexer.Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res))
return true;
Res = new AsmUnaryExpr(AsmUnaryExpr::Plus, Res);
return false;
- case asmtok::Tilde:
+ case AsmToken::Tilde:
Lexer.Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res))
return true;
return false;
}
-static unsigned getBinOpPrecedence(asmtok::TokKind K,
+static unsigned getBinOpPrecedence(AsmToken::TokenKind K,
AsmBinaryExpr::Opcode &Kind) {
switch (K) {
default: return 0; // not a binop.
// Lowest Precedence: &&, ||
- case asmtok::AmpAmp:
+ case AsmToken::AmpAmp:
Kind = AsmBinaryExpr::LAnd;
return 1;
- case asmtok::PipePipe:
+ case AsmToken::PipePipe:
Kind = AsmBinaryExpr::LOr;
return 1;
// Low Precedence: +, -, ==, !=, <>, <, <=, >, >=
- case asmtok::Plus:
+ case AsmToken::Plus:
Kind = AsmBinaryExpr::Add;
return 2;
- case asmtok::Minus:
+ case AsmToken::Minus:
Kind = AsmBinaryExpr::Sub;
return 2;
- case asmtok::EqualEqual:
+ case AsmToken::EqualEqual:
Kind = AsmBinaryExpr::EQ;
return 2;
- case asmtok::ExclaimEqual:
- case asmtok::LessGreater:
+ case AsmToken::ExclaimEqual:
+ case AsmToken::LessGreater:
Kind = AsmBinaryExpr::NE;
return 2;
- case asmtok::Less:
+ case AsmToken::Less:
Kind = AsmBinaryExpr::LT;
return 2;
- case asmtok::LessEqual:
+ case AsmToken::LessEqual:
Kind = AsmBinaryExpr::LTE;
return 2;
- case asmtok::Greater:
+ case AsmToken::Greater:
Kind = AsmBinaryExpr::GT;
return 2;
- case asmtok::GreaterEqual:
+ case AsmToken::GreaterEqual:
Kind = AsmBinaryExpr::GTE;
return 2;
// Intermediate Precedence: |, &, ^
//
// FIXME: gas seems to support '!' as an infix operator?
- case asmtok::Pipe:
+ case AsmToken::Pipe:
Kind = AsmBinaryExpr::Or;
return 3;
- case asmtok::Caret:
+ case AsmToken::Caret:
Kind = AsmBinaryExpr::Xor;
return 3;
- case asmtok::Amp:
+ case AsmToken::Amp:
Kind = AsmBinaryExpr::And;
return 3;
// Highest Precedence: *, /, %, <<, >>
- case asmtok::Star:
+ case AsmToken::Star:
Kind = AsmBinaryExpr::Mul;
return 4;
- case asmtok::Slash:
+ case AsmToken::Slash:
Kind = AsmBinaryExpr::Div;
return 4;
- case asmtok::Percent:
+ case AsmToken::Percent:
Kind = AsmBinaryExpr::Mod;
return 4;
- case asmtok::LessLess:
+ case AsmToken::LessLess:
Kind = AsmBinaryExpr::Shl;
return 4;
- case asmtok::GreaterGreater:
+ case AsmToken::GreaterGreater:
Kind = AsmBinaryExpr::Shr;
return 4;
}
switch (Lexer.getKind()) {
default:
return TokError("unexpected token at start of statement");
- case asmtok::EndOfStatement:
+ case AsmToken::EndOfStatement:
Lexer.Lex();
return false;
- case asmtok::Identifier:
+ case AsmToken::Identifier:
break;
// TODO: Recurse on local labels etc.
}
// Consume the identifier, see what is after it.
switch (Lexer.Lex()) {
- case asmtok::Colon: {
+ case AsmToken::Colon: {
// identifier ':' -> Label.
Lexer.Lex();
return ParseStatement();
}
- case asmtok::Equal:
+ case AsmToken::Equal:
// identifier '=' ... -> assignment statement
Lexer.Lex();
getTargetParser().ParseInstruction(*this, IDVal, Inst))
return true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in argument list");
// Eat the end of statement marker.
if (ParseRelocatableExpression(Value))
return true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in assignment");
// Eat the end of statement marker.
/// ParseDirectiveSet:
/// ::= .set identifier ',' expression
bool AsmParser::ParseDirectiveSet() {
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier after '.set' directive");
StringRef Name = Lexer.getCurStrVal();
- if (Lexer.Lex() != asmtok::Comma)
+ if (Lexer.Lex() != AsmToken::Comma)
return TokError("unexpected token in '.set'");
Lexer.Lex();
/// FIXME: This should actually parse out the segment, section, attributes and
/// sizeof_stub fields.
bool AsmParser::ParseDirectiveDarwinSection() {
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier after '.section' directive");
std::string Section = Lexer.getCurStrVal();
Lexer.Lex();
// Accept a comma separated list of modifiers.
- while (Lexer.is(asmtok::Comma)) {
+ while (Lexer.is(AsmToken::Comma)) {
Lexer.Lex();
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier in '.section' directive");
Section += ',';
Section += Lexer.getCurStrVal().str();
Lexer.Lex();
}
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.section' directive");
Lexer.Lex();
bool AsmParser::ParseDirectiveSectionSwitch(const char *Section,
const char *Directives) {
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in section switching directive");
Lexer.Lex();
/// ParseDirectiveAscii:
/// ::= ( .ascii | .asciz ) [ "string" ( , "string" )* ]
bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) {
- if (Lexer.isNot(asmtok::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
for (;;) {
- if (Lexer.isNot(asmtok::String))
+ if (Lexer.isNot(AsmToken::String))
return TokError("expected string in '.ascii' or '.asciz' directive");
// FIXME: This shouldn't use a const char* + strlen, the string could have
Lexer.Lex();
- if (Lexer.is(asmtok::EndOfStatement))
+ if (Lexer.is(AsmToken::EndOfStatement))
break;
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.ascii' or '.asciz' directive");
Lexer.Lex();
}
/// ParseDirectiveValue
/// ::= (.byte | .short | ... ) [ expression (, expression)* ]
bool AsmParser::ParseDirectiveValue(unsigned Size) {
- if (Lexer.isNot(asmtok::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
for (;;) {
MCValue Expr;
if (ParseRelocatableExpression(Expr))
Out.EmitValue(Expr, Size);
- if (Lexer.is(asmtok::EndOfStatement))
+ if (Lexer.is(AsmToken::EndOfStatement))
break;
// FIXME: Improve diagnostic.
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lexer.Lex();
}
int64_t FillExpr = 0;
bool HasFillExpr = false;
- if (Lexer.isNot(asmtok::EndOfStatement)) {
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.space' directive");
Lexer.Lex();
HasFillExpr = true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.space' directive");
}
if (ParseAbsoluteExpression(NumValues))
return true;
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.fill' directive");
Lexer.Lex();
if (ParseAbsoluteExpression(FillSize))
return true;
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.fill' directive");
Lexer.Lex();
if (ParseAbsoluteExpression(FillExpr))
return true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.fill' directive");
Lexer.Lex();
// Parse optional fill expression.
int64_t FillExpr = 0;
- if (Lexer.isNot(asmtok::EndOfStatement)) {
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.org' directive");
Lexer.Lex();
if (ParseAbsoluteExpression(FillExpr))
return true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.org' directive");
}
bool HasFillExpr = false;
int64_t FillExpr = 0;
int64_t MaxBytesToFill = 0;
- if (Lexer.isNot(asmtok::EndOfStatement)) {
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lexer.Lex();
// The fill expression can be omitted while specifying a maximum number of
// alignment bytes, e.g:
// .align 3,,4
- if (Lexer.isNot(asmtok::Comma)) {
+ if (Lexer.isNot(AsmToken::Comma)) {
HasFillExpr = true;
if (ParseAbsoluteExpression(FillExpr))
return true;
}
- if (Lexer.isNot(asmtok::EndOfStatement)) {
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lexer.Lex();
if (ParseAbsoluteExpression(MaxBytesToFill))
return true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in directive");
}
}
/// ParseDirectiveSymbolAttribute
/// ::= { ".globl", ".weak", ... } [ identifier ( , identifier )* ]
bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
- if (Lexer.isNot(asmtok::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
for (;;) {
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier in directive");
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
Out.EmitSymbolAttribute(Sym, Attr);
- if (Lexer.is(asmtok::EndOfStatement))
+ if (Lexer.is(AsmToken::EndOfStatement))
break;
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lexer.Lex();
}
/// ParseDirectiveDarwinSymbolDesc
/// ::= .desc identifier , expression
bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier in directive");
// handle the identifier as the key symbol.
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
Lexer.Lex();
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.desc' directive");
Lexer.Lex();
if (ParseAbsoluteExpression(DescValue))
return true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.desc' directive");
Lexer.Lex();
/// ParseDirectiveComm
/// ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ]
bool AsmParser::ParseDirectiveComm(bool IsLocal) {
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier in directive");
// handle the identifier as the key symbol.
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
Lexer.Lex();
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lexer.Lex();
int64_t Pow2Alignment = 0;
SMLoc Pow2AlignmentLoc;
- if (Lexer.is(asmtok::Comma)) {
+ if (Lexer.is(AsmToken::Comma)) {
Lexer.Lex();
Pow2AlignmentLoc = Lexer.getLoc();
if (ParseAbsoluteExpression(Pow2Alignment))
return true;
}
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.comm' or '.lcomm' directive");
Lexer.Lex();
/// ::= .zerofill segname , sectname [, identifier , size_expression [
/// , align_expression ]]
bool AsmParser::ParseDirectiveDarwinZerofill() {
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected segment name after '.zerofill' directive");
std::string Section = Lexer.getCurStrVal();
Lexer.Lex();
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Section += ',';
Lexer.Lex();
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected section name after comma in '.zerofill' "
"directive");
Section += Lexer.getCurStrVal().str();
// If this is the end of the line all that was wanted was to create the
// the section but with no symbol.
- if (Lexer.is(asmtok::EndOfStatement)) {
+ if (Lexer.is(AsmToken::EndOfStatement)) {
// Create the zerofill section but no symbol
Out.EmitZerofill(Ctx.GetSection(Section.c_str()));
return false;
}
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lexer.Lex();
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier in directive");
// handle the identifier as the key symbol.
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
Lexer.Lex();
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
Lexer.Lex();
int64_t Pow2Alignment = 0;
SMLoc Pow2AlignmentLoc;
- if (Lexer.is(asmtok::Comma)) {
+ if (Lexer.is(AsmToken::Comma)) {
Lexer.Lex();
Pow2AlignmentLoc = Lexer.getLoc();
if (ParseAbsoluteExpression(Pow2Alignment))
return true;
}
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.zerofill' directive");
Lexer.Lex();
/// ParseDirectiveDarwinSubsectionsViaSymbols
/// ::= .subsections_via_symbols
bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() {
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.subsections_via_symbols' directive");
Lexer.Lex();
SMLoc Loc = Lexer.getLoc();
StringRef Str = "";
- if (Lexer.isNot(asmtok::EndOfStatement)) {
- if (Lexer.isNot(asmtok::String))
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::String))
return TokError("expected string in '.abort' directive");
Str = Lexer.getCurStrVal();
Lexer.Lex();
}
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.abort' directive");
Lexer.Lex();
/// ParseDirectiveLsym
/// ::= .lsym identifier , expression
bool AsmParser::ParseDirectiveDarwinLsym() {
- if (Lexer.isNot(asmtok::Identifier))
+ if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier in directive");
// handle the identifier as the key symbol.
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal());
Lexer.Lex();
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.lsym' directive");
Lexer.Lex();
if (ParseRelocatableExpression(Expr))
return true;
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.lsym' directive");
Lexer.Lex();
/// ParseDirectiveInclude
/// ::= .include "filename"
bool AsmParser::ParseDirectiveInclude() {
- if (Lexer.isNot(asmtok::String))
+ if (Lexer.isNot(AsmToken::String))
return TokError("expected string in '.include' directive");
std::string Filename = Lexer.getCurStrVal();
SMLoc IncludeLoc = Lexer.getLoc();
Lexer.Lex();
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.include' directive");
// Strip the quotes.
/// ParseDirectiveDarwinDumpOrLoad
/// ::= ( .dump | .load ) "filename"
bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) {
- if (Lexer.isNot(asmtok::String))
+ if (Lexer.isNot(AsmToken::String))
return TokError("expected string in '.dump' or '.load' directive");
Lexer.getCurStrVal();
Lexer.Lex();
- if (Lexer.isNot(asmtok::EndOfStatement))
+ if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.dump' or '.load' directive");
Lexer.Lex();
};
bool AsmParser::ParseX86Register(X86Operand &Op) {
- assert(Lexer.getKind() == asmtok::Register && "Invalid token kind!");
+ assert(Lexer.getKind() == AsmToken::Register && "Invalid token kind!");
// FIXME: Decode register number.
Op = X86Operand::CreateReg(123);
switch (Lexer.getKind()) {
default:
return ParseX86MemOperand(Op);
- case asmtok::Register:
+ case AsmToken::Register:
// FIXME: if a segment register, this could either be just the seg reg, or
// the start of a memory operand.
return ParseX86Register(Op);
- case asmtok::Dollar: {
+ case AsmToken::Dollar: {
// $42 -> immediate.
Lexer.Lex();
MCValue Val;
Op = X86Operand::CreateImm(Val);
return false;
}
- case asmtok::Star: {
+ case AsmToken::Star: {
Lexer.Lex(); // Eat the star.
- if (Lexer.is(asmtok::Register)) {
+ if (Lexer.is(AsmToken::Register)) {
if (ParseX86Register(Op))
return true;
} else if (ParseX86MemOperand(Op))
// only way to do this without lookahead is to eat the ( and see what is after
// it.
MCValue Disp = MCValue::get(0, 0, 0);
- if (Lexer.isNot(asmtok::LParen)) {
+ if (Lexer.isNot(AsmToken::LParen)) {
if (ParseRelocatableExpression(Disp)) return true;
// After parsing the base expression we could either have a parenthesized
// memory address or not. If not, return now. If so, eat the (.
- if (Lexer.isNot(asmtok::LParen)) {
+ if (Lexer.isNot(AsmToken::LParen)) {
Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
return false;
}
// so we have to eat the ( to see beyond it.
Lexer.Lex(); // Eat the '('.
- if (Lexer.is(asmtok::Register) || Lexer.is(asmtok::Comma)) {
+ if (Lexer.is(AsmToken::Register) || Lexer.is(AsmToken::Comma)) {
// Nothing to do here, fall into the code below with the '(' part of the
// memory operand consumed.
} else {
// After parsing the base expression we could either have a parenthesized
// memory address or not. If not, return now. If so, eat the (.
- if (Lexer.isNot(asmtok::LParen)) {
+ if (Lexer.isNot(AsmToken::LParen)) {
Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 0);
return false;
}
// the rest of the memory operand.
unsigned BaseReg = 0, IndexReg = 0, Scale = 0;
- if (Lexer.is(asmtok::Register)) {
+ if (Lexer.is(AsmToken::Register)) {
if (ParseX86Register(Op))
return true;
BaseReg = Op.getReg();
}
- if (Lexer.is(asmtok::Comma)) {
+ if (Lexer.is(AsmToken::Comma)) {
Lexer.Lex(); // Eat the comma.
// Following the comma we should have either an index register, or a scale
//
// Not that even though it would be completely consistent to support syntax
// like "1(%eax,,1)", the assembler doesn't.
- if (Lexer.is(asmtok::Register)) {
+ if (Lexer.is(AsmToken::Register)) {
if (ParseX86Register(Op))
return true;
IndexReg = Op.getReg();
Scale = 1; // If not specified, the scale defaults to 1.
- if (Lexer.isNot(asmtok::RParen)) {
+ if (Lexer.isNot(AsmToken::RParen)) {
// Parse the scale amount:
// ::= ',' [scale-expression]
- if (Lexer.isNot(asmtok::Comma))
+ if (Lexer.isNot(AsmToken::Comma))
return true;
Lexer.Lex(); // Eat the comma.
- if (Lexer.isNot(asmtok::RParen)) {
+ if (Lexer.isNot(AsmToken::RParen)) {
int64_t ScaleVal;
if (ParseAbsoluteExpression(ScaleVal))
return true;
Scale = (unsigned)ScaleVal;
}
}
- } else if (Lexer.isNot(asmtok::RParen)) {
+ } else if (Lexer.isNot(AsmToken::RParen)) {
// Otherwise we have the unsupported form of a scale amount without an
// index.
SMLoc Loc = Lexer.getLoc();
}
// Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
- if (Lexer.isNot(asmtok::RParen))
+ if (Lexer.isNot(AsmToken::RParen))
return TokError("unexpected token in memory operand");
Lexer.Lex(); // Eat the ')'.
bool AsmParser::ParseX86InstOperands(const StringRef &InstName, MCInst &Inst) {
llvm::SmallVector<X86Operand, 3> Operands;
- if (Lexer.isNot(asmtok::EndOfStatement)) {
+ if (Lexer.isNot(AsmToken::EndOfStatement)) {
// Read the first operand.
Operands.push_back(X86Operand());
if (ParseX86Operand(Operands.back()))
return true;
- while (Lexer.is(asmtok::Comma)) {
+ while (Lexer.is(AsmToken::Comma)) {
Lexer.Lex(); // Eat the comma.
// Parse and remember the operand.
bool Error = false;
- asmtok::TokKind Tok = Lexer.Lex();
- while (Tok != asmtok::Eof) {
+ AsmToken::TokenKind Tok = Lexer.Lex();
+ while (Tok != AsmToken::Eof) {
switch (Tok) {
default:
Lexer.PrintMessage(Lexer.getLoc(), "unknown token", "warning");
Error = true;
break;
- case asmtok::Error:
+ case AsmToken::Error:
Error = true; // error already printed.
break;
- case asmtok::Identifier:
+ case AsmToken::Identifier:
outs() << "identifier: " << Lexer.getCurStrVal() << '\n';
break;
- case asmtok::Register:
+ case AsmToken::Register:
outs() << "register: " << Lexer.getCurStrVal() << '\n';
break;
- case asmtok::String:
+ case AsmToken::String:
outs() << "string: " << Lexer.getCurStrVal() << '\n';
break;
- case asmtok::IntVal:
+ case AsmToken::Integer:
outs() << "int: " << Lexer.getCurIntVal() << '\n';
break;
- case asmtok::Amp: outs() << "Amp\n"; break;
- case asmtok::AmpAmp: outs() << "AmpAmp\n"; break;
- case asmtok::Caret: outs() << "Caret\n"; break;
- case asmtok::Colon: outs() << "Colon\n"; break;
- case asmtok::Comma: outs() << "Comma\n"; break;
- case asmtok::Dollar: outs() << "Dollar\n"; break;
- case asmtok::EndOfStatement: outs() << "EndOfStatement\n"; break;
- case asmtok::Eof: outs() << "Eof\n"; break;
- case asmtok::Equal: outs() << "Equal\n"; break;
- case asmtok::EqualEqual: outs() << "EqualEqual\n"; break;
- case asmtok::Exclaim: outs() << "Exclaim\n"; break;
- case asmtok::ExclaimEqual: outs() << "ExclaimEqual\n"; break;
- case asmtok::Greater: outs() << "Greater\n"; break;
- case asmtok::GreaterEqual: outs() << "GreaterEqual\n"; break;
- case asmtok::GreaterGreater: outs() << "GreaterGreater\n"; break;
- case asmtok::LParen: outs() << "LParen\n"; break;
- case asmtok::Less: outs() << "Less\n"; break;
- case asmtok::LessEqual: outs() << "LessEqual\n"; break;
- case asmtok::LessGreater: outs() << "LessGreater\n"; break;
- case asmtok::LessLess: outs() << "LessLess\n"; break;
- case asmtok::Minus: outs() << "Minus\n"; break;
- case asmtok::Percent: outs() << "Percent\n"; break;
- case asmtok::Pipe: outs() << "Pipe\n"; break;
- case asmtok::PipePipe: outs() << "PipePipe\n"; break;
- case asmtok::Plus: outs() << "Plus\n"; break;
- case asmtok::RParen: outs() << "RParen\n"; break;
- case asmtok::Slash: outs() << "Slash\n"; break;
- case asmtok::Star: outs() << "Star\n"; break;
- case asmtok::Tilde: outs() << "Tilde\n"; break;
+ case AsmToken::Amp: outs() << "Amp\n"; break;
+ case AsmToken::AmpAmp: outs() << "AmpAmp\n"; break;
+ case AsmToken::Caret: outs() << "Caret\n"; break;
+ case AsmToken::Colon: outs() << "Colon\n"; break;
+ case AsmToken::Comma: outs() << "Comma\n"; break;
+ case AsmToken::Dollar: outs() << "Dollar\n"; break;
+ case AsmToken::EndOfStatement: outs() << "EndOfStatement\n"; break;
+ case AsmToken::Eof: outs() << "Eof\n"; break;
+ case AsmToken::Equal: outs() << "Equal\n"; break;
+ case AsmToken::EqualEqual: outs() << "EqualEqual\n"; break;
+ case AsmToken::Exclaim: outs() << "Exclaim\n"; break;
+ case AsmToken::ExclaimEqual: outs() << "ExclaimEqual\n"; break;
+ case AsmToken::Greater: outs() << "Greater\n"; break;
+ case AsmToken::GreaterEqual: outs() << "GreaterEqual\n"; break;
+ case AsmToken::GreaterGreater: outs() << "GreaterGreater\n"; break;
+ case AsmToken::LParen: outs() << "LParen\n"; break;
+ case AsmToken::Less: outs() << "Less\n"; break;
+ case AsmToken::LessEqual: outs() << "LessEqual\n"; break;
+ case AsmToken::LessGreater: outs() << "LessGreater\n"; break;
+ case AsmToken::LessLess: outs() << "LessLess\n"; break;
+ case AsmToken::Minus: outs() << "Minus\n"; break;
+ case AsmToken::Percent: outs() << "Percent\n"; break;
+ case AsmToken::Pipe: outs() << "Pipe\n"; break;
+ case AsmToken::PipePipe: outs() << "PipePipe\n"; break;
+ case AsmToken::Plus: outs() << "Plus\n"; break;
+ case AsmToken::RParen: outs() << "RParen\n"; break;
+ case AsmToken::Slash: outs() << "Slash\n"; break;
+ case AsmToken::Star: outs() << "Star\n"; break;
+ case AsmToken::Tilde: outs() << "Tilde\n"; break;
}
Tok = Lexer.Lex();