From 4610889d27627fdd6dc01518e07fd617e317eeac Mon Sep 17 00:00:00 2001 From: Sean Luchen Date: Tue, 1 Apr 2025 13:01:00 -0700 Subject: [PATCH] Fix two parsing bugs that were causing private regression tests to fail. These were introduced by 0a6d9f4. 1) While in a paren "(", don't error on newline. 2) Don't parse an extra token when parsing vector ranges. Let the caller parse the next token as necessary. --- passes/techmap/libparse.cc | 13 ++++++++----- passes/techmap/libparse.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/passes/techmap/libparse.cc b/passes/techmap/libparse.cc index d85e9d915..e5ed094b3 100644 --- a/passes/techmap/libparse.cc +++ b/passes/techmap/libparse.cc @@ -360,7 +360,7 @@ void LibertyParser::report_unexpected_token(int tok) // FIXME: the AST needs to be extended to store // these vector ranges. -int LibertyParser::parse_vector_range(int tok) +void LibertyParser::parse_vector_range(int tok) { // parse vector range [A] or [A:B] std::string arg; @@ -397,7 +397,6 @@ int LibertyParser::parse_vector_range(int tok) { error("Expected ']' on array range."); } - return lexer(arg); } LibertyAst *LibertyParser::parse() @@ -437,8 +436,10 @@ LibertyAst *LibertyParser::parse() tok = lexer(ast->value); if (tok == 'v') { tok = lexer(str); - if (tok == '[') - tok = parse_vector_range(tok); + if (tok == '[') { + parse_vector_range(tok); + tok = lexer(str); + } } while (tok == '+' || tok == '-' || tok == '*' || tok == '/' || tok == '!') { ast->value += tok; @@ -471,9 +472,11 @@ LibertyAst *LibertyParser::parse() if (tok == '[') { - tok = parse_vector_range(tok); + parse_vector_range(tok); continue; } + if (tok == 'n') + continue; if (tok != 'v') { report_unexpected_token(tok); } diff --git a/passes/techmap/libparse.h b/passes/techmap/libparse.h index 61ae4d334..2f0678513 100644 --- a/passes/techmap/libparse.h +++ b/passes/techmap/libparse.h @@ -106,7 +106,7 @@ namespace Yosys int lexer(std::string &str); void report_unexpected_token(int tok); - int parse_vector_range(int tok); + void parse_vector_range(int tok); LibertyAst *parse(); void error() const; void error(const std::string &str) const;