[llvm-commits] [llvm] r93916 - in /llvm/trunk: include/llvm/MC/MCAsmParser.h lib/MC/MCAsmParser.cpp lib/Target/ARM/AsmParser/ARMAsmParser.cpp lib/Target/X86/AsmParser/X86AsmParser.cpp tools/llvm-mc/AsmParser.cpp
Sean Callanan
scallanan at apple.com
Tue Jan 19 13:44:57 PST 2010
Author: spyffe
Date: Tue Jan 19 15:44:56 2010
New Revision: 93916
URL: http://llvm.org/viewvc/llvm-project?rev=93916&view=rev
Log:
Promoted the getTok() method to MCAsmParser so that
the two token accessor functions are declared consistently.
Modified the clients of MCAsmParser to reflect this change.
Modified:
llvm/trunk/include/llvm/MC/MCAsmParser.h
llvm/trunk/lib/MC/MCAsmParser.cpp
llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/trunk/tools/llvm-mc/AsmParser.cpp
Modified: llvm/trunk/include/llvm/MC/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmParser.h?rev=93916&r1=93915&r2=93916&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmParser.h Tue Jan 19 15:44:56 2010
@@ -55,6 +55,9 @@
/// inclusion first.
virtual const AsmToken &Lex() = 0;
+ /// getTok - Get the current AsmToken from the stream.
+ const AsmToken &getTok();
+
/// ParseExpression - Parse an arbitrary expression.
///
/// @param Res - The value of the expression. The result is undefined
Modified: llvm/trunk/lib/MC/MCAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmParser.cpp?rev=93916&r1=93915&r2=93916&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmParser.cpp Tue Jan 19 15:44:56 2010
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAsmParser.h"
+#include "llvm/MC/MCAsmLexer.h"
#include "llvm/MC/MCParsedAsmOperand.h"
#include "llvm/Support/SourceMgr.h"
using namespace llvm;
@@ -18,12 +19,15 @@
MCAsmParser::~MCAsmParser() {
}
+const AsmToken &MCAsmParser::getTok() {
+ return getLexer().getTok();
+}
+
bool MCAsmParser::ParseExpression(const MCExpr *&Res) {
SMLoc L;
return ParseExpression(Res, L);
}
-
/// getStartLoc - Get the location of the first token of this operand.
SMLoc MCParsedAsmOperand::getStartLoc() const { return SMLoc(); }
SMLoc MCParsedAsmOperand::getEndLoc() const { return SMLoc(); }
Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=93916&r1=93915&r2=93916&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Tue Jan 19 15:44:56 2010
@@ -222,7 +222,7 @@
/// TODO this is likely to change to allow different register types and or to
/// parse for a specific register type.
bool ARMAsmParser::MaybeParseRegister(ARMOperand &Op, bool ParseWriteBack) {
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
// FIXME: Validate register for the current architecture; we have to do
@@ -236,7 +236,7 @@
bool Writeback = false;
if (ParseWriteBack) {
- const AsmToken &ExclaimTok = getLexer().getTok();
+ const AsmToken &ExclaimTok = Parser.getTok();
if (ExclaimTok.is(AsmToken::Exclaim)) {
Writeback = true;
Parser.Lex(); // Eat exclaim token
@@ -251,11 +251,11 @@
/// Parse a register list, return false if successful else return true or an
/// error. The first token must be a '{' when called.
bool ARMAsmParser::ParseRegisterList(ARMOperand &Op) {
- assert(getLexer().getTok().is(AsmToken::LCurly) &&
+ assert(Parser.getTok().is(AsmToken::LCurly) &&
"Token is not an Left Curly Brace");
Parser.Lex(); // Eat left curly brace token.
- const AsmToken &RegTok = getLexer().getTok();
+ const AsmToken &RegTok = Parser.getTok();
SMLoc RegLoc = RegTok.getLoc();
if (RegTok.isNot(AsmToken::Identifier))
return Error(RegLoc, "register expected");
@@ -267,10 +267,10 @@
int HighRegNum = RegNum;
// TODO ranges like "{Rn-Rm}"
- while (getLexer().getTok().is(AsmToken::Comma)) {
+ while (Parser.getTok().is(AsmToken::Comma)) {
Parser.Lex(); // Eat comma token.
- const AsmToken &RegTok = getLexer().getTok();
+ const AsmToken &RegTok = Parser.getTok();
SMLoc RegLoc = RegTok.getLoc();
if (RegTok.isNot(AsmToken::Identifier))
return Error(RegLoc, "register expected");
@@ -287,7 +287,7 @@
Parser.Lex(); // Eat identifier token.
}
- const AsmToken &RCurlyTok = getLexer().getTok();
+ const AsmToken &RCurlyTok = Parser.getTok();
if (RCurlyTok.isNot(AsmToken::RCurly))
return Error(RCurlyTok.getLoc(), "'}' expected");
Parser.Lex(); // Eat left curly brace token.
@@ -300,11 +300,11 @@
/// TODO Only preindexing and postindexing addressing are started, unindexed
/// with option, etc are still to do.
bool ARMAsmParser::ParseMemory(ARMOperand &Op) {
- assert(getLexer().getTok().is(AsmToken::LBrac) &&
+ assert(Parser.getTok().is(AsmToken::LBrac) &&
"Token is not an Left Bracket");
Parser.Lex(); // Eat left bracket token.
- const AsmToken &BaseRegTok = getLexer().getTok();
+ const AsmToken &BaseRegTok = Parser.getTok();
if (BaseRegTok.isNot(AsmToken::Identifier))
return Error(BaseRegTok.getLoc(), "register expected");
if (MaybeParseRegister(Op, false))
@@ -319,7 +319,7 @@
// First look for preindexed address forms, that is after the "[Rn" we now
// have to see if the next token is a comma.
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (Tok.is(AsmToken::Comma)) {
Preindexed = true;
Parser.Lex(); // Eat comma token.
@@ -331,12 +331,12 @@
if(ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount,
Offset, OffsetIsReg, OffsetRegNum))
return true;
- const AsmToken &RBracTok = getLexer().getTok();
+ const AsmToken &RBracTok = Parser.getTok();
if (RBracTok.isNot(AsmToken::RBrac))
return Error(RBracTok.getLoc(), "']' expected");
Parser.Lex(); // Eat right bracket token.
- const AsmToken &ExclaimTok = getLexer().getTok();
+ const AsmToken &ExclaimTok = Parser.getTok();
if (ExclaimTok.is(AsmToken::Exclaim)) {
Writeback = true;
Parser.Lex(); // Eat exclaim token
@@ -360,7 +360,7 @@
const MCExpr *ShiftAmount;
const MCExpr *Offset;
- const AsmToken &NextTok = getLexer().getTok();
+ const AsmToken &NextTok = Parser.getTok();
if (NextTok.isNot(AsmToken::EndOfStatement)) {
if (NextTok.isNot(AsmToken::Comma))
return Error(NextTok.getLoc(), "',' expected");
@@ -398,7 +398,7 @@
OffsetRegShifted = false;
OffsetIsReg = false;
OffsetRegNum = -1;
- const AsmToken &NextTok = getLexer().getTok();
+ const AsmToken &NextTok = Parser.getTok();
if (NextTok.is(AsmToken::Plus))
Parser.Lex(); // Eat plus token.
else if (NextTok.is(AsmToken::Minus)) {
@@ -406,7 +406,7 @@
Parser.Lex(); // Eat minus token
}
// See if there is a register following the "[Rn," or "[Rn]," we have so far.
- const AsmToken &OffsetRegTok = getLexer().getTok();
+ const AsmToken &OffsetRegTok = Parser.getTok();
if (OffsetRegTok.is(AsmToken::Identifier)) {
OffsetIsReg = !MaybeParseRegister(Op, false);
if (OffsetIsReg)
@@ -415,11 +415,11 @@
// If we parsed a register as the offset then their can be a shift after that
if (OffsetRegNum != -1) {
// Look for a comma then a shift
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (Tok.is(AsmToken::Comma)) {
Parser.Lex(); // Eat comma token.
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (ParseShift(ShiftType, ShiftAmount))
return Error(Tok.getLoc(), "shift expected");
OffsetRegShifted = true;
@@ -427,7 +427,7 @@
}
else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm"
// Look for #offset following the "[Rn," or "[Rn],"
- const AsmToken &HashTok = getLexer().getTok();
+ const AsmToken &HashTok = Parser.getTok();
if (HashTok.isNot(AsmToken::Hash))
return Error(HashTok.getLoc(), "'#' expected");
Parser.Lex(); // Eat hash token.
@@ -443,7 +443,7 @@
/// rrx
/// and returns true if it parses a shift otherwise it returns false.
bool ARMAsmParser::ParseShift(ShiftType &St, const MCExpr *&ShiftAmount) {
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (Tok.isNot(AsmToken::Identifier))
return true;
const StringRef &ShiftName = Tok.getString();
@@ -466,7 +466,7 @@
return false;
// Otherwise, there must be a '#' and a shift amount.
- const AsmToken &HashTok = getLexer().getTok();
+ const AsmToken &HashTok = Parser.getTok();
if (HashTok.isNot(AsmToken::Hash))
return Error(HashTok.getLoc(), "'#' expected");
Parser.Lex(); // Eat hash token.
@@ -576,7 +576,7 @@
Op = ARMOperand::CreateImm(ImmVal);
return false;
default:
- return Error(getLexer().getTok().getLoc(), "unexpected token in operand");
+ return Error(Parser.getTok().getLoc(), "unexpected token in operand");
}
}
@@ -585,7 +585,7 @@
SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Operands.push_back(new ARMOperand(ARMOperand::CreateToken(Name)));
- SMLoc Loc = getLexer().getTok().getLoc();
+ SMLoc Loc = Parser.getTok().getLoc();
if (getLexer().isNot(AsmToken::EndOfStatement)) {
// Read the first operand.
@@ -661,10 +661,10 @@
/// ParseDirectiveThumbFunc
/// ::= .thumbfunc symbol_name
bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) {
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
return Error(L, "unexpected token in .syntax directive");
- StringRef ATTRIBUTE_UNUSED SymbolName = getLexer().getTok().getIdentifier();
+ StringRef ATTRIBUTE_UNUSED SymbolName = Parser.getTok().getIdentifier();
Parser.Lex(); // Consume the identifier token.
if (getLexer().isNot(AsmToken::EndOfStatement))
@@ -679,7 +679,7 @@
/// ParseDirectiveSyntax
/// ::= .syntax unified | divided
bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) {
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (Tok.isNot(AsmToken::Identifier))
return Error(L, "unexpected token in .syntax directive");
const StringRef &Mode = Tok.getString();
@@ -696,7 +696,7 @@
return Error(L, "unrecognized syntax mode in .syntax directive");
if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getTok().getLoc(), "unexpected token in directive");
+ return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Parser.Lex();
// TODO tell the MC streamer the mode
@@ -707,10 +707,10 @@
/// ParseDirectiveCode
/// ::= .code 16 | 32
bool ARMAsmParser::ParseDirectiveCode(SMLoc L) {
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (Tok.isNot(AsmToken::Integer))
return Error(L, "unexpected token in .code directive");
- int64_t Val = getLexer().getTok().getIntVal();
+ int64_t Val = Parser.getTok().getIntVal();
bool thumb_mode;
if (Val == 16) {
Parser.Lex();
@@ -724,7 +724,7 @@
return Error(L, "invalid operand to .code directive");
if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getTok().getLoc(), "unexpected token in directive");
+ return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Parser.Lex();
// TODO tell the MC streamer the mode
Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=93916&r1=93915&r2=93916&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Tue Jan 19 15:44:56 2010
@@ -245,12 +245,12 @@
bool X86ATTAsmParser::ParseRegister(unsigned &RegNo,
SMLoc &StartLoc, SMLoc &EndLoc) {
RegNo = 0;
- const AsmToken &TokPercent = getLexer().getTok();
+ const AsmToken &TokPercent = Parser.getTok();
assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
StartLoc = TokPercent.getLoc();
Parser.Lex(); // Eat percent token.
- const AsmToken &Tok = getLexer().getTok();
+ const AsmToken &Tok = Parser.getTok();
if (Tok.isNot(AsmToken::Identifier))
return Error(Tok.getLoc(), "invalid register name");
@@ -279,7 +279,7 @@
}
case AsmToken::Dollar: {
// $42 -> immediate.
- SMLoc Start = getLexer().getTok().getLoc(), End;
+ SMLoc Start = Parser.getTok().getLoc(), End;
Parser.Lex();
const MCExpr *Val;
if (getParser().ParseExpression(Val, End))
@@ -291,7 +291,7 @@
/// ParseMemOperand: segment: disp(basereg, indexreg, scale)
X86Operand *X86ATTAsmParser::ParseMemOperand() {
- SMLoc MemStart = getLexer().getTok().getLoc();
+ SMLoc MemStart = Parser.getTok().getLoc();
// FIXME: If SegReg ':' (e.g. %gs:), eat and remember.
unsigned SegReg = 0;
@@ -319,7 +319,7 @@
} else {
// Okay, we have a '('. We don't know if this is an expression or not, but
// so we have to eat the ( to see beyond it.
- SMLoc LParenLoc = getLexer().getTok().getLoc();
+ SMLoc LParenLoc = Parser.getTok().getLoc();
Parser.Lex(); // Eat the '('.
if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) {
@@ -372,14 +372,14 @@
// Parse the scale amount:
// ::= ',' [scale-expression]
if (getLexer().isNot(AsmToken::Comma)) {
- Error(getLexer().getTok().getLoc(),
+ Error(Parser.getTok().getLoc(),
"expected comma in scale expression");
return 0;
}
Parser.Lex(); // Eat the comma.
if (getLexer().isNot(AsmToken::RParen)) {
- SMLoc Loc = getLexer().getTok().getLoc();
+ SMLoc Loc = Parser.getTok().getLoc();
int64_t ScaleVal;
if (getParser().ParseAbsoluteExpression(ScaleVal))
@@ -396,7 +396,7 @@
} else if (getLexer().isNot(AsmToken::RParen)) {
// Otherwise we have the unsupported form of a scale amount without an
// index.
- SMLoc Loc = getLexer().getTok().getLoc();
+ SMLoc Loc = Parser.getTok().getLoc();
int64_t Value;
if (getParser().ParseAbsoluteExpression(Value))
@@ -409,10 +409,10 @@
// Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
if (getLexer().isNot(AsmToken::RParen)) {
- Error(getLexer().getTok().getLoc(), "unexpected token in memory operand");
+ Error(Parser.getTok().getLoc(), "unexpected token in memory operand");
return 0;
}
- SMLoc MemEnd = getLexer().getTok().getLoc();
+ SMLoc MemEnd = Parser.getTok().getLoc();
Parser.Lex(); // Eat the ')'.
return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
@@ -429,7 +429,7 @@
// Parse '*' modifier.
if (getLexer().is(AsmToken::Star)) {
- SMLoc Loc = getLexer().getTok().getLoc();
+ SMLoc Loc = Parser.getTok().getLoc();
Operands.push_back(X86Operand::CreateToken("*", Loc));
Parser.Lex(); // Eat the star.
}
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=93916&r1=93915&r2=93916&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jan 19 15:44:56 2010
@@ -126,7 +126,7 @@
// Handle conditional assembly here before calling ParseStatement()
if (Lexer.getKind() == AsmToken::Identifier) {
// If we have an identifier, handle it as the key symbol.
- AsmToken ID = Lexer.getTok();
+ AsmToken ID = getTok();
SMLoc IDLoc = ID.getLoc();
StringRef IDVal = ID.getString();
@@ -233,7 +233,7 @@
case AsmToken::String:
case AsmToken::Identifier: {
// This is a symbol reference.
- MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
+ MCSymbol *Sym = CreateSymbol(getTok().getIdentifier());
EndLoc = Lexer.getLoc();
Lex(); // Eat identifier.
@@ -249,7 +249,7 @@
return false;
}
case AsmToken::Integer:
- Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
+ Res = MCConstantExpr::Create(getTok().getIntVal(), getContext());
EndLoc = Lexer.getLoc();
Lex(); // Eat token.
return false;
@@ -435,7 +435,7 @@
}
// Statements always start with an identifier.
- AsmToken ID = Lexer.getTok();
+ AsmToken ID = getTok();
SMLoc IDLoc = ID.getLoc();
StringRef IDVal;
if (ParseIdentifier(IDVal))
@@ -811,7 +811,7 @@
Lexer.isNot(AsmToken::String))
return true;
- Res = Lexer.getTok().getIdentifier();
+ Res = getTok().getIdentifier();
Lex(); // Consume the identifier token.
@@ -908,7 +908,7 @@
assert(Lexer.is(AsmToken::String) && "Unexpected current token!");
Data = "";
- StringRef Str = Lexer.getTok().getStringContents();
+ StringRef Str = getTok().getStringContents();
for (unsigned i = 0, e = Str.size(); i != e; ++i) {
if (Str[i] != '\\') {
Data += Str[i];
@@ -1337,7 +1337,7 @@
if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected segment name after '.zerofill' directive");
- StringRef Segment = Lexer.getTok().getString();
+ StringRef Segment = getTok().getString();
Lex();
if (Lexer.isNot(AsmToken::Comma))
@@ -1347,7 +1347,7 @@
if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected section name after comma in '.zerofill' "
"directive");
- StringRef Section = Lexer.getTok().getString();
+ StringRef Section = getTok().getString();
Lex();
// If this is the end of the line all that was wanted was to create the
@@ -1369,7 +1369,7 @@
// handle the identifier as the key symbol.
SMLoc IDLoc = Lexer.getLoc();
- MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString());
+ MCSymbol *Sym = CreateSymbol(getTok().getString());
Lex();
if (Lexer.isNot(AsmToken::Comma))
@@ -1444,7 +1444,7 @@
if (Lexer.isNot(AsmToken::String))
return TokError("expected string in '.abort' directive");
- Str = Lexer.getTok().getString();
+ Str = getTok().getString();
Lex();
}
@@ -1500,7 +1500,7 @@
if (Lexer.isNot(AsmToken::String))
return TokError("expected string in '.include' directive");
- std::string Filename = Lexer.getTok().getString();
+ std::string Filename = getTok().getString();
SMLoc IncludeLoc = Lexer.getLoc();
Lex();
@@ -1664,7 +1664,7 @@
// FIXME: I'm not sure what this is.
int64_t FileNumber = -1;
if (Lexer.is(AsmToken::Integer)) {
- FileNumber = Lexer.getTok().getIntVal();
+ FileNumber = getTok().getIntVal();
Lex();
if (FileNumber < 1)
@@ -1674,7 +1674,7 @@
if (Lexer.isNot(AsmToken::String))
return TokError("unexpected token in '.file' directive");
- StringRef ATTRIBUTE_UNUSED FileName = Lexer.getTok().getString();
+ StringRef ATTRIBUTE_UNUSED FileName = getTok().getString();
Lex();
if (Lexer.isNot(AsmToken::EndOfStatement))
@@ -1692,7 +1692,7 @@
if (Lexer.isNot(AsmToken::Integer))
return TokError("unexpected token in '.line' directive");
- int64_t LineNumber = Lexer.getTok().getIntVal();
+ int64_t LineNumber = getTok().getIntVal();
(void) LineNumber;
Lex();
@@ -1713,7 +1713,7 @@
return TokError("unexpected token in '.loc' directive");
// FIXME: What are these fields?
- int64_t FileNumber = Lexer.getTok().getIntVal();
+ int64_t FileNumber = getTok().getIntVal();
(void) FileNumber;
// FIXME: Validate file.
@@ -1722,7 +1722,7 @@
if (Lexer.isNot(AsmToken::Integer))
return TokError("unexpected token in '.loc' directive");
- int64_t Param2 = Lexer.getTok().getIntVal();
+ int64_t Param2 = getTok().getIntVal();
(void) Param2;
Lex();
@@ -1730,7 +1730,7 @@
if (Lexer.isNot(AsmToken::Integer))
return TokError("unexpected token in '.loc' directive");
- int64_t Param3 = Lexer.getTok().getIntVal();
+ int64_t Param3 = getTok().getIntVal();
(void) Param3;
Lex();
More information about the llvm-commits
mailing list