mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-31 09:32:11 +00:00
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
This commit is contained in:
parent
be9c23fef4
commit
74ec1a3b11
@ -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;
|
||||
|
@ -39,8 +39,7 @@ namespace asmtok {
|
||||
// No-value.
|
||||
EndOfStatement,
|
||||
Colon,
|
||||
Plus,
|
||||
Minus,
|
||||
Plus, Minus, Tilde,
|
||||
Slash, // '/'
|
||||
LParen, RParen,
|
||||
Star, Comma, Dollar
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user