mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-07 11:33:44 +00:00
Added a Lex function to the AsmParser, to allow handling
of include directives to occur within the parser itself. This will break the lexer's dependency on a SourceMgr as input. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93899 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8c5ee7147b
commit
79ed1a8734
@ -100,6 +100,10 @@ bool AsmParser::TokError(const char *Msg) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AsmToken &AsmParser::Lex() {
|
||||||
|
return Lexer.Lex();
|
||||||
|
}
|
||||||
|
|
||||||
bool AsmParser::Run() {
|
bool AsmParser::Run() {
|
||||||
// Create the initial section.
|
// Create the initial section.
|
||||||
//
|
//
|
||||||
@ -111,7 +115,7 @@ bool AsmParser::Run() {
|
|||||||
|
|
||||||
|
|
||||||
// Prime the lexer.
|
// Prime the lexer.
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
bool HadError = false;
|
bool HadError = false;
|
||||||
|
|
||||||
@ -178,11 +182,11 @@ bool AsmParser::ParseConditionalAssemblyDirectives(StringRef Directive,
|
|||||||
void AsmParser::EatToEndOfStatement() {
|
void AsmParser::EatToEndOfStatement() {
|
||||||
while (Lexer.isNot(AsmToken::EndOfStatement) &&
|
while (Lexer.isNot(AsmToken::EndOfStatement) &&
|
||||||
Lexer.isNot(AsmToken::Eof))
|
Lexer.isNot(AsmToken::Eof))
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// Eat EOL.
|
// Eat EOL.
|
||||||
if (Lexer.is(AsmToken::EndOfStatement))
|
if (Lexer.is(AsmToken::EndOfStatement))
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -196,7 +200,7 @@ bool AsmParser::ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc) {
|
|||||||
if (Lexer.isNot(AsmToken::RParen))
|
if (Lexer.isNot(AsmToken::RParen))
|
||||||
return TokError("expected ')' in parentheses expression");
|
return TokError("expected ')' in parentheses expression");
|
||||||
EndLoc = Lexer.getLoc();
|
EndLoc = Lexer.getLoc();
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +225,7 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
|
|||||||
default:
|
default:
|
||||||
return TokError("unknown token in expression");
|
return TokError("unknown token in expression");
|
||||||
case AsmToken::Exclaim:
|
case AsmToken::Exclaim:
|
||||||
Lexer.Lex(); // Eat the operator.
|
Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res, EndLoc))
|
if (ParsePrimaryExpr(Res, EndLoc))
|
||||||
return true;
|
return true;
|
||||||
Res = MCUnaryExpr::CreateLNot(Res, getContext());
|
Res = MCUnaryExpr::CreateLNot(Res, getContext());
|
||||||
@ -231,7 +235,7 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
|
|||||||
// This is a symbol reference.
|
// This is a symbol reference.
|
||||||
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
|
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
|
||||||
EndLoc = Lexer.getLoc();
|
EndLoc = Lexer.getLoc();
|
||||||
Lexer.Lex(); // Eat identifier.
|
Lex(); // Eat identifier.
|
||||||
|
|
||||||
// If this is an absolute variable reference, substitute it now to preserve
|
// If this is an absolute variable reference, substitute it now to preserve
|
||||||
// semantics in the face of reassignment.
|
// semantics in the face of reassignment.
|
||||||
@ -247,25 +251,25 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
|
|||||||
case AsmToken::Integer:
|
case AsmToken::Integer:
|
||||||
Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
|
Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
|
||||||
EndLoc = Lexer.getLoc();
|
EndLoc = Lexer.getLoc();
|
||||||
Lexer.Lex(); // Eat token.
|
Lex(); // Eat token.
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::LParen:
|
case AsmToken::LParen:
|
||||||
Lexer.Lex(); // Eat the '('.
|
Lex(); // Eat the '('.
|
||||||
return ParseParenExpr(Res, EndLoc);
|
return ParseParenExpr(Res, EndLoc);
|
||||||
case AsmToken::Minus:
|
case AsmToken::Minus:
|
||||||
Lexer.Lex(); // Eat the operator.
|
Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res, EndLoc))
|
if (ParsePrimaryExpr(Res, EndLoc))
|
||||||
return true;
|
return true;
|
||||||
Res = MCUnaryExpr::CreateMinus(Res, getContext());
|
Res = MCUnaryExpr::CreateMinus(Res, getContext());
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::Plus:
|
case AsmToken::Plus:
|
||||||
Lexer.Lex(); // Eat the operator.
|
Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res, EndLoc))
|
if (ParsePrimaryExpr(Res, EndLoc))
|
||||||
return true;
|
return true;
|
||||||
Res = MCUnaryExpr::CreatePlus(Res, getContext());
|
Res = MCUnaryExpr::CreatePlus(Res, getContext());
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::Tilde:
|
case AsmToken::Tilde:
|
||||||
Lexer.Lex(); // Eat the operator.
|
Lex(); // Eat the operator.
|
||||||
if (ParsePrimaryExpr(Res, EndLoc))
|
if (ParsePrimaryExpr(Res, EndLoc))
|
||||||
return true;
|
return true;
|
||||||
Res = MCUnaryExpr::CreateNot(Res, getContext());
|
Res = MCUnaryExpr::CreateNot(Res, getContext());
|
||||||
@ -398,7 +402,7 @@ bool AsmParser::ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res,
|
|||||||
if (TokPrec < Precedence)
|
if (TokPrec < Precedence)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// Eat the next primary expression.
|
// Eat the next primary expression.
|
||||||
const MCExpr *RHS;
|
const MCExpr *RHS;
|
||||||
@ -426,7 +430,7 @@ bool AsmParser::ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res,
|
|||||||
/// ::= Label* Identifier OperandList* EndOfStatement
|
/// ::= Label* Identifier OperandList* EndOfStatement
|
||||||
bool AsmParser::ParseStatement() {
|
bool AsmParser::ParseStatement() {
|
||||||
if (Lexer.is(AsmToken::EndOfStatement)) {
|
if (Lexer.is(AsmToken::EndOfStatement)) {
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,7 +447,7 @@ bool AsmParser::ParseStatement() {
|
|||||||
switch (Lexer.getKind()) {
|
switch (Lexer.getKind()) {
|
||||||
case AsmToken::Colon: {
|
case AsmToken::Colon: {
|
||||||
// identifier ':' -> Label.
|
// identifier ':' -> Label.
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// Diagnose attempt to use a variable as a label.
|
// Diagnose attempt to use a variable as a label.
|
||||||
//
|
//
|
||||||
@ -462,7 +466,7 @@ bool AsmParser::ParseStatement() {
|
|||||||
|
|
||||||
case AsmToken::Equal:
|
case AsmToken::Equal:
|
||||||
// identifier '=' ... -> assignment statement
|
// identifier '=' ... -> assignment statement
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
return ParseAssignment(IDVal);
|
return ParseAssignment(IDVal);
|
||||||
|
|
||||||
@ -734,7 +738,7 @@ bool AsmParser::ParseStatement() {
|
|||||||
return TokError("unexpected token in argument list");
|
return TokError("unexpected token in argument list");
|
||||||
|
|
||||||
// Eat the end of statement marker.
|
// Eat the end of statement marker.
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
|
|
||||||
MCInst Inst;
|
MCInst Inst;
|
||||||
@ -771,7 +775,7 @@ bool AsmParser::ParseAssignment(const StringRef &Name) {
|
|||||||
return TokError("unexpected token in assignment");
|
return TokError("unexpected token in assignment");
|
||||||
|
|
||||||
// Eat the end of statement marker.
|
// Eat the end of statement marker.
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// Validate that the LHS is allowed to be a variable (either it has not been
|
// 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).
|
// used as a symbol, or it is an absolute symbol).
|
||||||
@ -809,7 +813,7 @@ bool AsmParser::ParseIdentifier(StringRef &Res) {
|
|||||||
|
|
||||||
Res = Lexer.getTok().getIdentifier();
|
Res = Lexer.getTok().getIdentifier();
|
||||||
|
|
||||||
Lexer.Lex(); // Consume the identifier token.
|
Lex(); // Consume the identifier token.
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -824,7 +828,7 @@ bool AsmParser::ParseDirectiveSet() {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.set'");
|
return TokError("unexpected token in '.set'");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
return ParseAssignment(Name);
|
return ParseAssignment(Name);
|
||||||
}
|
}
|
||||||
@ -852,10 +856,10 @@ bool AsmParser::ParseDirectiveDarwinSection() {
|
|||||||
StringRef EOL = Lexer.LexUntilEndOfStatement();
|
StringRef EOL = Lexer.LexUntilEndOfStatement();
|
||||||
SectionSpec.append(EOL.begin(), EOL.end());
|
SectionSpec.append(EOL.begin(), EOL.end());
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.section' directive");
|
return TokError("unexpected token in '.section' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
|
|
||||||
StringRef Segment, Section;
|
StringRef Segment, Section;
|
||||||
@ -880,7 +884,7 @@ bool AsmParser::ParseDirectiveSectionSwitch(const char *Segment,
|
|||||||
unsigned StubSize) {
|
unsigned StubSize) {
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in section switching directive");
|
return TokError("unexpected token in section switching directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// FIXME: Arch specific.
|
// FIXME: Arch specific.
|
||||||
Out.SwitchSection(getMachOSection(Segment, Section, TAA, StubSize,
|
Out.SwitchSection(getMachOSection(Segment, Section, TAA, StubSize,
|
||||||
@ -974,18 +978,18 @@ bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) {
|
|||||||
if (ZeroTerminated)
|
if (ZeroTerminated)
|
||||||
Out.EmitBytes(StringRef("\0", 1), DEFAULT_ADDRSPACE);
|
Out.EmitBytes(StringRef("\0", 1), DEFAULT_ADDRSPACE);
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.is(AsmToken::EndOfStatement))
|
if (Lexer.is(AsmToken::EndOfStatement))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.ascii' or '.asciz' directive");
|
return TokError("unexpected token in '.ascii' or '.asciz' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1007,11 +1011,11 @@ bool AsmParser::ParseDirectiveValue(unsigned Size) {
|
|||||||
// FIXME: Improve diagnostic.
|
// FIXME: Improve diagnostic.
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1027,7 +1031,7 @@ bool AsmParser::ParseDirectiveSpace() {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.space' directive");
|
return TokError("unexpected token in '.space' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (ParseAbsoluteExpression(FillExpr))
|
if (ParseAbsoluteExpression(FillExpr))
|
||||||
return true;
|
return true;
|
||||||
@ -1038,7 +1042,7 @@ bool AsmParser::ParseDirectiveSpace() {
|
|||||||
return TokError("unexpected token in '.space' directive");
|
return TokError("unexpected token in '.space' directive");
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (NumBytes <= 0)
|
if (NumBytes <= 0)
|
||||||
return TokError("invalid number of bytes in '.space' directive");
|
return TokError("invalid number of bytes in '.space' directive");
|
||||||
@ -1058,7 +1062,7 @@ bool AsmParser::ParseDirectiveFill() {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.fill' directive");
|
return TokError("unexpected token in '.fill' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
int64_t FillSize;
|
int64_t FillSize;
|
||||||
if (ParseAbsoluteExpression(FillSize))
|
if (ParseAbsoluteExpression(FillSize))
|
||||||
@ -1066,7 +1070,7 @@ bool AsmParser::ParseDirectiveFill() {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.fill' directive");
|
return TokError("unexpected token in '.fill' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
int64_t FillExpr;
|
int64_t FillExpr;
|
||||||
if (ParseAbsoluteExpression(FillExpr))
|
if (ParseAbsoluteExpression(FillExpr))
|
||||||
@ -1075,7 +1079,7 @@ bool AsmParser::ParseDirectiveFill() {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.fill' directive");
|
return TokError("unexpected token in '.fill' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8)
|
if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8)
|
||||||
return TokError("invalid '.fill' size, expected 1, 2, 4, or 8");
|
return TokError("invalid '.fill' size, expected 1, 2, 4, or 8");
|
||||||
@ -1100,7 +1104,7 @@ bool AsmParser::ParseDirectiveOrg() {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.org' directive");
|
return TokError("unexpected token in '.org' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (ParseAbsoluteExpression(FillExpr))
|
if (ParseAbsoluteExpression(FillExpr))
|
||||||
return true;
|
return true;
|
||||||
@ -1109,7 +1113,7 @@ bool AsmParser::ParseDirectiveOrg() {
|
|||||||
return TokError("unexpected token in '.org' directive");
|
return TokError("unexpected token in '.org' directive");
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// FIXME: Only limited forms of relocatable expressions are accepted here, it
|
// FIXME: Only limited forms of relocatable expressions are accepted here, it
|
||||||
// has to be relative to the current section.
|
// has to be relative to the current section.
|
||||||
@ -1133,7 +1137,7 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// The fill expression can be omitted while specifying a maximum number of
|
// The fill expression can be omitted while specifying a maximum number of
|
||||||
// alignment bytes, e.g:
|
// alignment bytes, e.g:
|
||||||
@ -1147,7 +1151,7 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
MaxBytesLoc = Lexer.getLoc();
|
MaxBytesLoc = Lexer.getLoc();
|
||||||
if (ParseAbsoluteExpression(MaxBytesToFill))
|
if (ParseAbsoluteExpression(MaxBytesToFill))
|
||||||
@ -1158,7 +1162,7 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (!HasFillExpr) {
|
if (!HasFillExpr) {
|
||||||
// FIXME: Sometimes fill with nop.
|
// FIXME: Sometimes fill with nop.
|
||||||
@ -1216,11 +1220,11 @@ bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1236,7 +1240,7 @@ bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.desc' directive");
|
return TokError("unexpected token in '.desc' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
SMLoc DescLoc = Lexer.getLoc();
|
SMLoc DescLoc = Lexer.getLoc();
|
||||||
int64_t DescValue;
|
int64_t DescValue;
|
||||||
@ -1246,7 +1250,7 @@ bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.desc' directive");
|
return TokError("unexpected token in '.desc' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// Set the n_desc field of this Symbol to this DescValue
|
// Set the n_desc field of this Symbol to this DescValue
|
||||||
Out.EmitSymbolDesc(Sym, DescValue);
|
Out.EmitSymbolDesc(Sym, DescValue);
|
||||||
@ -1267,7 +1271,7 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
int64_t Size;
|
int64_t Size;
|
||||||
SMLoc SizeLoc = Lexer.getLoc();
|
SMLoc SizeLoc = Lexer.getLoc();
|
||||||
@ -1277,7 +1281,7 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
|||||||
int64_t Pow2Alignment = 0;
|
int64_t Pow2Alignment = 0;
|
||||||
SMLoc Pow2AlignmentLoc;
|
SMLoc Pow2AlignmentLoc;
|
||||||
if (Lexer.is(AsmToken::Comma)) {
|
if (Lexer.is(AsmToken::Comma)) {
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
Pow2AlignmentLoc = Lexer.getLoc();
|
Pow2AlignmentLoc = Lexer.getLoc();
|
||||||
if (ParseAbsoluteExpression(Pow2Alignment))
|
if (ParseAbsoluteExpression(Pow2Alignment))
|
||||||
return true;
|
return true;
|
||||||
@ -1293,7 +1297,7 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.comm' or '.lcomm' directive");
|
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
|
// 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.
|
// but a size of .lcomm creates a bss symbol of size zero.
|
||||||
@ -1334,17 +1338,17 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
|
|||||||
if (Lexer.isNot(AsmToken::Identifier))
|
if (Lexer.isNot(AsmToken::Identifier))
|
||||||
return TokError("expected segment name after '.zerofill' directive");
|
return TokError("expected segment name after '.zerofill' directive");
|
||||||
StringRef Segment = Lexer.getTok().getString();
|
StringRef Segment = Lexer.getTok().getString();
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
if (Lexer.isNot(AsmToken::Identifier))
|
||||||
return TokError("expected section name after comma in '.zerofill' "
|
return TokError("expected section name after comma in '.zerofill' "
|
||||||
"directive");
|
"directive");
|
||||||
StringRef Section = Lexer.getTok().getString();
|
StringRef Section = Lexer.getTok().getString();
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// If this is the end of the line all that was wanted was to create the
|
// If this is the end of the line all that was wanted was to create the
|
||||||
// the section but with no symbol.
|
// the section but with no symbol.
|
||||||
@ -1358,7 +1362,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Identifier))
|
if (Lexer.isNot(AsmToken::Identifier))
|
||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
@ -1366,11 +1370,11 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
|
|||||||
// handle the identifier as the key symbol.
|
// handle the identifier as the key symbol.
|
||||||
SMLoc IDLoc = Lexer.getLoc();
|
SMLoc IDLoc = Lexer.getLoc();
|
||||||
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString());
|
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString());
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
int64_t Size;
|
int64_t Size;
|
||||||
SMLoc SizeLoc = Lexer.getLoc();
|
SMLoc SizeLoc = Lexer.getLoc();
|
||||||
@ -1380,7 +1384,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
|
|||||||
int64_t Pow2Alignment = 0;
|
int64_t Pow2Alignment = 0;
|
||||||
SMLoc Pow2AlignmentLoc;
|
SMLoc Pow2AlignmentLoc;
|
||||||
if (Lexer.is(AsmToken::Comma)) {
|
if (Lexer.is(AsmToken::Comma)) {
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
Pow2AlignmentLoc = Lexer.getLoc();
|
Pow2AlignmentLoc = Lexer.getLoc();
|
||||||
if (ParseAbsoluteExpression(Pow2Alignment))
|
if (ParseAbsoluteExpression(Pow2Alignment))
|
||||||
return true;
|
return true;
|
||||||
@ -1389,7 +1393,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.zerofill' directive");
|
return TokError("unexpected token in '.zerofill' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Size < 0)
|
if (Size < 0)
|
||||||
return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less "
|
return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less "
|
||||||
@ -1422,7 +1426,7 @@ bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.subsections_via_symbols' directive");
|
return TokError("unexpected token in '.subsections_via_symbols' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
Out.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols);
|
Out.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols);
|
||||||
|
|
||||||
@ -1442,13 +1446,13 @@ bool AsmParser::ParseDirectiveAbort() {
|
|||||||
|
|
||||||
Str = Lexer.getTok().getString();
|
Str = Lexer.getTok().getString();
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.abort' directive");
|
return TokError("unexpected token in '.abort' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// FIXME: Handle here.
|
// FIXME: Handle here.
|
||||||
if (Str.empty())
|
if (Str.empty())
|
||||||
@ -1471,7 +1475,7 @@ bool AsmParser::ParseDirectiveDarwinLsym() {
|
|||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.lsym' directive");
|
return TokError("unexpected token in '.lsym' directive");
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
const MCExpr *Value;
|
const MCExpr *Value;
|
||||||
SMLoc StartLoc = Lexer.getLoc();
|
SMLoc StartLoc = Lexer.getLoc();
|
||||||
@ -1481,7 +1485,7 @@ bool AsmParser::ParseDirectiveDarwinLsym() {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.lsym' directive");
|
return TokError("unexpected token in '.lsym' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// We don't currently support this directive.
|
// We don't currently support this directive.
|
||||||
//
|
//
|
||||||
@ -1498,7 +1502,7 @@ bool AsmParser::ParseDirectiveInclude() {
|
|||||||
|
|
||||||
std::string Filename = Lexer.getTok().getString();
|
std::string Filename = Lexer.getTok().getString();
|
||||||
SMLoc IncludeLoc = Lexer.getLoc();
|
SMLoc IncludeLoc = Lexer.getLoc();
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.include' directive");
|
return TokError("unexpected token in '.include' directive");
|
||||||
@ -1524,12 +1528,12 @@ bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) {
|
|||||||
if (Lexer.isNot(AsmToken::String))
|
if (Lexer.isNot(AsmToken::String))
|
||||||
return TokError("expected string in '.dump' or '.load' directive");
|
return TokError("expected string in '.dump' or '.load' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.dump' or '.load' directive");
|
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
|
// 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.
|
// the assembly parser and not have any need for an MCStreamer API.
|
||||||
@ -1545,7 +1549,7 @@ bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) {
|
|||||||
/// ::= .if expression
|
/// ::= .if expression
|
||||||
bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
|
bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
|
||||||
// Consume the identifier that was the .if directive
|
// Consume the identifier that was the .if directive
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
TheCondStack.push_back(TheCondState);
|
TheCondStack.push_back(TheCondState);
|
||||||
TheCondState.TheCond = AsmCond::IfCond;
|
TheCondState.TheCond = AsmCond::IfCond;
|
||||||
@ -1560,7 +1564,7 @@ bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.if' directive");
|
return TokError("unexpected token in '.if' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
TheCondState.CondMet = ExprValue;
|
TheCondState.CondMet = ExprValue;
|
||||||
TheCondState.Ignore = !TheCondState.CondMet;
|
TheCondState.Ignore = !TheCondState.CondMet;
|
||||||
@ -1579,7 +1583,7 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) {
|
|||||||
TheCondState.TheCond = AsmCond::ElseIfCond;
|
TheCondState.TheCond = AsmCond::ElseIfCond;
|
||||||
|
|
||||||
// Consume the identifier that was the .elseif directive
|
// Consume the identifier that was the .elseif directive
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
bool LastIgnoreState = false;
|
bool LastIgnoreState = false;
|
||||||
if (!TheCondStack.empty())
|
if (!TheCondStack.empty())
|
||||||
@ -1596,7 +1600,7 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) {
|
|||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.elseif' directive");
|
return TokError("unexpected token in '.elseif' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
TheCondState.CondMet = ExprValue;
|
TheCondState.CondMet = ExprValue;
|
||||||
TheCondState.Ignore = !TheCondState.CondMet;
|
TheCondState.Ignore = !TheCondState.CondMet;
|
||||||
}
|
}
|
||||||
@ -1608,12 +1612,12 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) {
|
|||||||
/// ::= .else
|
/// ::= .else
|
||||||
bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) {
|
bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) {
|
||||||
// Consume the identifier that was the .else directive
|
// Consume the identifier that was the .else directive
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.else' directive");
|
return TokError("unexpected token in '.else' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (TheCondState.TheCond != AsmCond::IfCond &&
|
if (TheCondState.TheCond != AsmCond::IfCond &&
|
||||||
TheCondState.TheCond != AsmCond::ElseIfCond)
|
TheCondState.TheCond != AsmCond::ElseIfCond)
|
||||||
@ -1635,12 +1639,12 @@ bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) {
|
|||||||
/// ::= .endif
|
/// ::= .endif
|
||||||
bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
|
bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
|
||||||
// Consume the identifier that was the .endif directive
|
// Consume the identifier that was the .endif directive
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.endif' directive");
|
return TokError("unexpected token in '.endif' directive");
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if ((TheCondState.TheCond == AsmCond::NoCond) ||
|
if ((TheCondState.TheCond == AsmCond::NoCond) ||
|
||||||
TheCondStack.empty())
|
TheCondStack.empty())
|
||||||
@ -1661,7 +1665,7 @@ bool AsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) {
|
|||||||
int64_t FileNumber = -1;
|
int64_t FileNumber = -1;
|
||||||
if (Lexer.is(AsmToken::Integer)) {
|
if (Lexer.is(AsmToken::Integer)) {
|
||||||
FileNumber = Lexer.getTok().getIntVal();
|
FileNumber = Lexer.getTok().getIntVal();
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (FileNumber < 1)
|
if (FileNumber < 1)
|
||||||
return TokError("file number less than one");
|
return TokError("file number less than one");
|
||||||
@ -1671,7 +1675,7 @@ bool AsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) {
|
|||||||
return TokError("unexpected token in '.file' directive");
|
return TokError("unexpected token in '.file' directive");
|
||||||
|
|
||||||
StringRef ATTRIBUTE_UNUSED FileName = Lexer.getTok().getString();
|
StringRef ATTRIBUTE_UNUSED FileName = Lexer.getTok().getString();
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||||
return TokError("unexpected token in '.file' directive");
|
return TokError("unexpected token in '.file' directive");
|
||||||
@ -1690,7 +1694,7 @@ bool AsmParser::ParseDirectiveLine(StringRef, SMLoc DirectiveLoc) {
|
|||||||
|
|
||||||
int64_t LineNumber = Lexer.getTok().getIntVal();
|
int64_t LineNumber = Lexer.getTok().getIntVal();
|
||||||
(void) LineNumber;
|
(void) LineNumber;
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// FIXME: Do something with the .line.
|
// FIXME: Do something with the .line.
|
||||||
}
|
}
|
||||||
@ -1713,14 +1717,14 @@ bool AsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) {
|
|||||||
(void) FileNumber;
|
(void) FileNumber;
|
||||||
// FIXME: Validate file.
|
// FIXME: Validate file.
|
||||||
|
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
if (Lexer.isNot(AsmToken::Integer))
|
if (Lexer.isNot(AsmToken::Integer))
|
||||||
return TokError("unexpected token in '.loc' directive");
|
return TokError("unexpected token in '.loc' directive");
|
||||||
|
|
||||||
int64_t Param2 = Lexer.getTok().getIntVal();
|
int64_t Param2 = Lexer.getTok().getIntVal();
|
||||||
(void) Param2;
|
(void) Param2;
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
if (Lexer.isNot(AsmToken::EndOfStatement)) {
|
||||||
if (Lexer.isNot(AsmToken::Integer))
|
if (Lexer.isNot(AsmToken::Integer))
|
||||||
@ -1728,7 +1732,7 @@ bool AsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) {
|
|||||||
|
|
||||||
int64_t Param3 = Lexer.getTok().getIntVal();
|
int64_t Param3 = Lexer.getTok().getIntVal();
|
||||||
(void) Param3;
|
(void) Param3;
|
||||||
Lexer.Lex();
|
Lex();
|
||||||
|
|
||||||
// FIXME: Do something with the .loc.
|
// FIXME: Do something with the .loc.
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class AsmCond;
|
class AsmCond;
|
||||||
|
class AsmToken;
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class MCExpr;
|
class MCExpr;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
@ -79,6 +80,8 @@ public:
|
|||||||
virtual void Warning(SMLoc L, const Twine &Meg);
|
virtual void Warning(SMLoc L, const Twine &Meg);
|
||||||
virtual bool Error(SMLoc L, const Twine &Msg);
|
virtual bool Error(SMLoc L, const Twine &Msg);
|
||||||
|
|
||||||
|
const AsmToken &Lex();
|
||||||
|
|
||||||
bool ParseExpression(const MCExpr *&Res);
|
bool ParseExpression(const MCExpr *&Res);
|
||||||
virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc);
|
virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc);
|
||||||
virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc);
|
virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc);
|
||||||
|
Loading…
Reference in New Issue
Block a user