mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-02 12:21:23 +00:00
Factor parse_vector_range out into its own function.
This also fixes the parsing a bit. It was consuming 1 fewer token than required.
This commit is contained in:
parent
0a6d9f4dc9
commit
ac1033ecd5
2 changed files with 44 additions and 37 deletions
|
@ -358,6 +358,48 @@ 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)
|
||||||
|
{
|
||||||
|
// parse vector range [A] or [A:B]
|
||||||
|
std::string arg;
|
||||||
|
tok = lexer(arg);
|
||||||
|
if (tok != 'v')
|
||||||
|
{
|
||||||
|
// expected a vector array index
|
||||||
|
error("Expected a number.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fixme: check for number A
|
||||||
|
}
|
||||||
|
tok = lexer(arg);
|
||||||
|
// optionally check for : in case of [A:B]
|
||||||
|
// if it isn't we just expect ']'
|
||||||
|
// as we have [A]
|
||||||
|
if (tok == ':')
|
||||||
|
{
|
||||||
|
tok = lexer(arg);
|
||||||
|
if (tok != 'v')
|
||||||
|
{
|
||||||
|
// expected a vector array index
|
||||||
|
error("Expected a number.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fixme: check for number B
|
||||||
|
tok = lexer(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// expect a closing bracket of array range
|
||||||
|
if (tok != ']')
|
||||||
|
{
|
||||||
|
error("Expected ']' on array range.");
|
||||||
|
}
|
||||||
|
return lexer(arg);
|
||||||
|
}
|
||||||
|
|
||||||
LibertyAst *LibertyParser::parse()
|
LibertyAst *LibertyParser::parse()
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
|
@ -425,45 +467,9 @@ LibertyAst *LibertyParser::parse()
|
||||||
if (tok == ')')
|
if (tok == ')')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// FIXME: the AST needs to be extended to store
|
|
||||||
// these vector ranges.
|
|
||||||
if (tok == '[')
|
if (tok == '[')
|
||||||
{
|
{
|
||||||
// parse vector range [A] or [A:B]
|
tok = parse_vector_range(tok);
|
||||||
std::string arg;
|
|
||||||
tok = lexer(arg);
|
|
||||||
if (tok != 'v')
|
|
||||||
{
|
|
||||||
// expected a vector array index
|
|
||||||
error("Expected a number.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// fixme: check for number A
|
|
||||||
}
|
|
||||||
tok = lexer(arg);
|
|
||||||
// optionally check for : in case of [A:B]
|
|
||||||
// if it isn't we just expect ']'
|
|
||||||
// as we have [A]
|
|
||||||
if (tok == ':')
|
|
||||||
{
|
|
||||||
tok = lexer(arg);
|
|
||||||
if (tok != 'v')
|
|
||||||
{
|
|
||||||
// expected a vector array index
|
|
||||||
error("Expected a number.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// fixme: check for number B
|
|
||||||
tok = lexer(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// expect a closing bracket of array range
|
|
||||||
if (tok != ']')
|
|
||||||
{
|
|
||||||
error("Expected ']' on array range.");
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tok != 'v') {
|
if (tok != 'v') {
|
||||||
|
|
|
@ -106,6 +106,7 @@ namespace Yosys
|
||||||
int lexer(std::string &str);
|
int lexer(std::string &str);
|
||||||
|
|
||||||
void report_unexpected_token(int tok);
|
void report_unexpected_token(int tok);
|
||||||
|
int parse_vector_range(int tok);
|
||||||
LibertyAst *parse();
|
LibertyAst *parse();
|
||||||
void error() const;
|
void error() const;
|
||||||
void error(const std::string &str) const;
|
void error(const std::string &str) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue