diff options
author | Chris Lattner <sabre@nondot.org> | 2009-06-22 06:32:03 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-06-22 06:32:03 +0000 |
commit | 74ec1a3b115a889e1a70dd22d8dcc6a5e753a5d2 (patch) | |
tree | 8f0aedd663adb265ff421b56f1b34fcff394804f | |
parent | be9c23fef4422aba89050213f002f0628e3df8b3 (diff) |
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
-rw-r--r-- | tools/llvm-mc/AsmLexer.cpp | 1 | ||||
-rw-r--r-- | tools/llvm-mc/AsmLexer.h | 3 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.cpp | 40 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.h | 2 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 1 |
5 files changed, 42 insertions, 5 deletions
diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp index 740215b683..36faeb3fac 100644 --- a/tools/llvm-mc/AsmLexer.cpp +++ b/tools/llvm-mc/AsmLexer.cpp @@ -235,6 +235,7 @@ asmtok::TokKind AsmLexer::LexToken() { 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 bad2cb931b..a6c93230c6 100644 --- a/tools/llvm-mc/AsmLexer.h +++ b/tools/llvm-mc/AsmLexer.h @@ -39,8 +39,7 @@ namespace asmtok { // 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 c9583549bd..397c5fe9c7 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -213,10 +213,25 @@ bool AsmParser::ParseX86MemOperand(X86Operand &Op) { 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 @@ bool AsmParser::ParseExpression(int64_t &Res) { 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 670d987bfc..82eb433b61 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -39,6 +39,8 @@ private: 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 7d0c571c72..52205c48d0 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -99,6 +99,7 @@ static int AsLexInput(const char *ProgName) { 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; |