Implement full support for parsing primary expressions. We can now parse
all of health and voronoi (ignoring directives). We only get 409 lines into
176.gcc though because we don't have binary operators yet:
Parsing 176.gcc.llc.s:409: unexpected token in operand list
movsbl _arityvec+1(,%edi,8), %eax
^
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73877 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp
index 740215b..36faeb3 100644
--- a/tools/llvm-mc/AsmLexer.cpp
+++ b/tools/llvm-mc/AsmLexer.cpp
@@ -235,6 +235,7 @@
case ':': return asmtok::Colon;
case '+': return asmtok::Plus;
case '-': return asmtok::Minus;
+ case '~': return asmtok::Tilde;
case '(': return asmtok::LParen;
case ')': return asmtok::RParen;
case '*': return asmtok::Star;
diff --git a/tools/llvm-mc/AsmLexer.h b/tools/llvm-mc/AsmLexer.h
index bad2cb9..a6c9323 100644
--- a/tools/llvm-mc/AsmLexer.h
+++ b/tools/llvm-mc/AsmLexer.h
@@ -39,8 +39,7 @@
// No-value.
EndOfStatement,
Colon,
- Plus,
- Minus,
+ Plus, Minus, Tilde,
Slash, // '/'
LParen, RParen,
Star, Comma, Dollar
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp
index c958354..397c5fe 100644
--- a/tools/llvm-mc/AsmParser.cpp
+++ b/tools/llvm-mc/AsmParser.cpp
@@ -213,10 +213,25 @@
return false;
}
+/// ParseParenExpr - Parse a paren expression and return it.
+/// NOTE: This assumes the leading '(' has already been consumed.
+///
+/// parenexpr ::= expr)
+///
+bool AsmParser::ParseParenExpr(int64_t &Res) {
+ if (ParseExpression(Res)) return true;
+ if (Lexer.isNot(asmtok::RParen))
+ return TokError("expected ')' in parentheses expression");
+ Lexer.Lex();
+ return false;
+}
-/// ParseExpression - Parse an expression and return it.
-/// FIXME: This should handle real expressions, we do something trivial for now.
-bool AsmParser::ParseExpression(int64_t &Res) {
+/// ParsePrimaryExpr - Parse a primary expression and return it.
+/// primaryexpr ::= (parenexpr
+/// primaryexpr ::= symbol
+/// primaryexpr ::= number
+/// primaryexpr ::= ~,+,- primaryexpr
+bool AsmParser::ParsePrimaryExpr(int64_t &Res) {
switch (Lexer.getKind()) {
default:
return TokError("unknown token in expression");
@@ -230,8 +245,27 @@
Res = Lexer.getCurIntVal();
Lexer.Lex(); // Eat identifier.
return false;
+ case asmtok::LParen:
+ Lexer.Lex(); // Eat the '('.
+ return ParseParenExpr(Res);
+ case asmtok::Tilde:
+ case asmtok::Plus:
+ case asmtok::Minus:
+ Lexer.Lex(); // Eat the operator.
+ return ParsePrimaryExpr(Res);
}
}
+
+/// ParseExpression - Parse an expression and return it.
+///
+/// expr ::= expr +,- expr -> lowest.
+/// expr ::= expr |,^,&,! expr -> middle.
+/// expr ::= expr *,/,%,<<,>> expr -> highest.
+/// expr ::= primaryexpr
+///
+bool AsmParser::ParseExpression(int64_t &Res) {
+ return ParsePrimaryExpr(Res);
+}
diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h
index 670d987..82eb433 100644
--- a/tools/llvm-mc/AsmParser.h
+++ b/tools/llvm-mc/AsmParser.h
@@ -39,6 +39,8 @@
bool ParseX86Operand(X86Operand &Op);
bool ParseX86MemOperand(X86Operand &Op);
bool ParseExpression(int64_t &Res);
+ bool ParsePrimaryExpr(int64_t &Res);
+ bool ParseParenExpr(int64_t &Res);
};
} // end namespace llvm
diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp
index 7d0c571..52205c4 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -99,6 +99,7 @@
case asmtok::Colon: outs() << "Colon\n"; break;
case asmtok::Plus: outs() << "Plus\n"; break;
case asmtok::Minus: outs() << "Minus\n"; break;
+ case asmtok::Tilde: outs() << "Tilde\n"; break;
case asmtok::Slash: outs() << "Slash\n"; break;
case asmtok::LParen: outs() << "LParen\n"; break;
case asmtok::RParen: outs() << "RParen\n"; break;