return true;
}
+const AsmToken &AsmParser::Lex() {
+ return Lexer.Lex();
+}
+
bool AsmParser::Run() {
// Create the initial section.
//
// Prime the lexer.
- Lexer.Lex();
+ Lex();
bool HadError = false;
void AsmParser::EatToEndOfStatement() {
while (Lexer.isNot(AsmToken::EndOfStatement) &&
Lexer.isNot(AsmToken::Eof))
- Lexer.Lex();
+ Lex();
// Eat EOL.
if (Lexer.is(AsmToken::EndOfStatement))
- Lexer.Lex();
+ Lex();
}
if (Lexer.isNot(AsmToken::RParen))
return TokError("expected ')' in parentheses expression");
EndLoc = Lexer.getLoc();
- Lexer.Lex();
+ Lex();
return false;
}
default:
return TokError("unknown token in expression");
case AsmToken::Exclaim:
- Lexer.Lex(); // Eat the operator.
+ Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res, EndLoc))
return true;
Res = MCUnaryExpr::CreateLNot(Res, getContext());
// This is a symbol reference.
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
EndLoc = Lexer.getLoc();
- Lexer.Lex(); // Eat identifier.
+ Lex(); // Eat identifier.
// If this is an absolute variable reference, substitute it now to preserve
// semantics in the face of reassignment.
case AsmToken::Integer:
Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
EndLoc = Lexer.getLoc();
- Lexer.Lex(); // Eat token.
+ Lex(); // Eat token.
return false;
case AsmToken::LParen:
- Lexer.Lex(); // Eat the '('.
+ Lex(); // Eat the '('.
return ParseParenExpr(Res, EndLoc);
case AsmToken::Minus:
- Lexer.Lex(); // Eat the operator.
+ Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res, EndLoc))
return true;
Res = MCUnaryExpr::CreateMinus(Res, getContext());
return false;
case AsmToken::Plus:
- Lexer.Lex(); // Eat the operator.
+ Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res, EndLoc))
return true;
Res = MCUnaryExpr::CreatePlus(Res, getContext());
return false;
case AsmToken::Tilde:
- Lexer.Lex(); // Eat the operator.
+ Lex(); // Eat the operator.
if (ParsePrimaryExpr(Res, EndLoc))
return true;
Res = MCUnaryExpr::CreateNot(Res, getContext());
if (TokPrec < Precedence)
return false;
- Lexer.Lex();
+ Lex();
// Eat the next primary expression.
const MCExpr *RHS;
/// ::= Label* Identifier OperandList* EndOfStatement
bool AsmParser::ParseStatement() {
if (Lexer.is(AsmToken::EndOfStatement)) {
- Lexer.Lex();
+ Lex();
return false;
}
switch (Lexer.getKind()) {
case AsmToken::Colon: {
// identifier ':' -> Label.
- Lexer.Lex();
+ Lex();
// Diagnose attempt to use a variable as a label.
//
case AsmToken::Equal:
// identifier '=' ... -> assignment statement
- Lexer.Lex();
+ Lex();
return ParseAssignment(IDVal);
return TokError("unexpected token in argument list");
// Eat the end of statement marker.
- Lexer.Lex();
+ Lex();
MCInst Inst;
return TokError("unexpected token in assignment");
// Eat the end of statement marker.
- Lexer.Lex();
+ Lex();
// Validate that the LHS is allowed to be a variable (either it has not been
// used as a symbol, or it is an absolute symbol).
Res = Lexer.getTok().getIdentifier();
- Lexer.Lex(); // Consume the identifier token.
+ Lex(); // Consume the identifier token.
return false;
}
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.set'");
- Lexer.Lex();
+ Lex();
return ParseAssignment(Name);
}
StringRef EOL = Lexer.LexUntilEndOfStatement();
SectionSpec.append(EOL.begin(), EOL.end());
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.section' directive");
- Lexer.Lex();
+ Lex();
StringRef Segment, Section;
unsigned StubSize) {
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in section switching directive");
- Lexer.Lex();
+ Lex();
// FIXME: Arch specific.
Out.SwitchSection(getMachOSection(Segment, Section, TAA, StubSize,
if (ZeroTerminated)
Out.EmitBytes(StringRef("\0", 1), DEFAULT_ADDRSPACE);
- Lexer.Lex();
+ Lex();
if (Lexer.is(AsmToken::EndOfStatement))
break;
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.ascii' or '.asciz' directive");
- Lexer.Lex();
+ Lex();
}
}
- Lexer.Lex();
+ Lex();
return false;
}
// FIXME: Improve diagnostic.
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
}
}
- Lexer.Lex();
+ Lex();
return false;
}
if (Lexer.isNot(AsmToken::EndOfStatement)) {
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.space' directive");
- Lexer.Lex();
+ Lex();
if (ParseAbsoluteExpression(FillExpr))
return true;
return TokError("unexpected token in '.space' directive");
}
- Lexer.Lex();
+ Lex();
if (NumBytes <= 0)
return TokError("invalid number of bytes in '.space' directive");
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.fill' directive");
- Lexer.Lex();
+ Lex();
int64_t FillSize;
if (ParseAbsoluteExpression(FillSize))
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.fill' directive");
- Lexer.Lex();
+ Lex();
int64_t FillExpr;
if (ParseAbsoluteExpression(FillExpr))
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.fill' directive");
- Lexer.Lex();
+ Lex();
if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8)
return TokError("invalid '.fill' size, expected 1, 2, 4, or 8");
if (Lexer.isNot(AsmToken::EndOfStatement)) {
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.org' directive");
- Lexer.Lex();
+ Lex();
if (ParseAbsoluteExpression(FillExpr))
return true;
return TokError("unexpected token in '.org' directive");
}
- Lexer.Lex();
+ Lex();
// FIXME: Only limited forms of relocatable expressions are accepted here, it
// has to be relative to the current section.
if (Lexer.isNot(AsmToken::EndOfStatement)) {
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
// The fill expression can be omitted while specifying a maximum number of
// alignment bytes, e.g:
if (Lexer.isNot(AsmToken::EndOfStatement)) {
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
MaxBytesLoc = Lexer.getLoc();
if (ParseAbsoluteExpression(MaxBytesToFill))
}
}
- Lexer.Lex();
+ Lex();
if (!HasFillExpr) {
// FIXME: Sometimes fill with nop.
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
}
}
- Lexer.Lex();
+ Lex();
return false;
}
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.desc' directive");
- Lexer.Lex();
+ Lex();
SMLoc DescLoc = Lexer.getLoc();
int64_t DescValue;
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.desc' directive");
- Lexer.Lex();
+ Lex();
// Set the n_desc field of this Symbol to this DescValue
Out.EmitSymbolDesc(Sym, DescValue);
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
int64_t Size;
SMLoc SizeLoc = Lexer.getLoc();
int64_t Pow2Alignment = 0;
SMLoc Pow2AlignmentLoc;
if (Lexer.is(AsmToken::Comma)) {
- Lexer.Lex();
+ Lex();
Pow2AlignmentLoc = Lexer.getLoc();
if (ParseAbsoluteExpression(Pow2Alignment))
return true;
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.comm' or '.lcomm' directive");
- Lexer.Lex();
+ Lex();
// NOTE: a size of zero for a .comm should create a undefined symbol
// but a size of .lcomm creates a bss symbol of size zero.
if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected segment name after '.zerofill' directive");
StringRef Segment = Lexer.getTok().getString();
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected section name after comma in '.zerofill' "
"directive");
StringRef Section = Lexer.getTok().getString();
- Lexer.Lex();
+ Lex();
// If this is the end of the line all that was wanted was to create the
// the section but with no symbol.
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::Identifier))
return TokError("expected identifier in directive");
// handle the identifier as the key symbol.
SMLoc IDLoc = Lexer.getLoc();
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString());
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in directive");
- Lexer.Lex();
+ Lex();
int64_t Size;
SMLoc SizeLoc = Lexer.getLoc();
int64_t Pow2Alignment = 0;
SMLoc Pow2AlignmentLoc;
if (Lexer.is(AsmToken::Comma)) {
- Lexer.Lex();
+ Lex();
Pow2AlignmentLoc = Lexer.getLoc();
if (ParseAbsoluteExpression(Pow2Alignment))
return true;
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.zerofill' directive");
- Lexer.Lex();
+ Lex();
if (Size < 0)
return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less "
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.subsections_via_symbols' directive");
- Lexer.Lex();
+ Lex();
Out.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols);
Str = Lexer.getTok().getString();
- Lexer.Lex();
+ Lex();
}
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.abort' directive");
- Lexer.Lex();
+ Lex();
// FIXME: Handle here.
if (Str.empty())
if (Lexer.isNot(AsmToken::Comma))
return TokError("unexpected token in '.lsym' directive");
- Lexer.Lex();
+ Lex();
const MCExpr *Value;
SMLoc StartLoc = Lexer.getLoc();
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.lsym' directive");
- Lexer.Lex();
+ Lex();
// We don't currently support this directive.
//
std::string Filename = Lexer.getTok().getString();
SMLoc IncludeLoc = Lexer.getLoc();
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.include' directive");
if (Lexer.isNot(AsmToken::String))
return TokError("expected string in '.dump' or '.load' directive");
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.dump' or '.load' directive");
- Lexer.Lex();
+ Lex();
// FIXME: If/when .dump and .load are implemented they will be done in the
// the assembly parser and not have any need for an MCStreamer API.
/// ::= .if expression
bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
// Consume the identifier that was the .if directive
- Lexer.Lex();
+ Lex();
TheCondStack.push_back(TheCondState);
TheCondState.TheCond = AsmCond::IfCond;
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.if' directive");
- Lexer.Lex();
+ Lex();
TheCondState.CondMet = ExprValue;
TheCondState.Ignore = !TheCondState.CondMet;
TheCondState.TheCond = AsmCond::ElseIfCond;
// Consume the identifier that was the .elseif directive
- Lexer.Lex();
+ Lex();
bool LastIgnoreState = false;
if (!TheCondStack.empty())
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.elseif' directive");
- Lexer.Lex();
+ Lex();
TheCondState.CondMet = ExprValue;
TheCondState.Ignore = !TheCondState.CondMet;
}
/// ::= .else
bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) {
// Consume the identifier that was the .else directive
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.else' directive");
- Lexer.Lex();
+ Lex();
if (TheCondState.TheCond != AsmCond::IfCond &&
TheCondState.TheCond != AsmCond::ElseIfCond)
/// ::= .endif
bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
// Consume the identifier that was the .endif directive
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.endif' directive");
- Lexer.Lex();
+ Lex();
if ((TheCondState.TheCond == AsmCond::NoCond) ||
TheCondStack.empty())
int64_t FileNumber = -1;
if (Lexer.is(AsmToken::Integer)) {
FileNumber = Lexer.getTok().getIntVal();
- Lexer.Lex();
+ Lex();
if (FileNumber < 1)
return TokError("file number less than one");
return TokError("unexpected token in '.file' directive");
StringRef ATTRIBUTE_UNUSED FileName = Lexer.getTok().getString();
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.file' directive");
int64_t LineNumber = Lexer.getTok().getIntVal();
(void) LineNumber;
- Lexer.Lex();
+ Lex();
// FIXME: Do something with the .line.
}
(void) FileNumber;
// FIXME: Validate file.
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement)) {
if (Lexer.isNot(AsmToken::Integer))
return TokError("unexpected token in '.loc' directive");
int64_t Param2 = Lexer.getTok().getIntVal();
(void) Param2;
- Lexer.Lex();
+ Lex();
if (Lexer.isNot(AsmToken::EndOfStatement)) {
if (Lexer.isNot(AsmToken::Integer))
int64_t Param3 = Lexer.getTok().getIntVal();
(void) Param3;
- Lexer.Lex();
+ Lex();
// FIXME: Do something with the .loc.
}