mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-14 21:08:47 +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
|
@ -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()
|
||||
{
|
||||
std::string str;
|
||||
|
@ -425,45 +467,9 @@ LibertyAst *LibertyParser::parse()
|
|||
if (tok == ')')
|
||||
break;
|
||||
|
||||
// FIXME: the AST needs to be extended to store
|
||||
// these vector ranges.
|
||||
if (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.");
|
||||
}
|
||||
tok = parse_vector_range(tok);
|
||||
continue;
|
||||
}
|
||||
if (tok != 'v') {
|
||||
|
|
|
@ -106,6 +106,7 @@ namespace Yosys
|
|||
int lexer(std::string &str);
|
||||
|
||||
void report_unexpected_token(int tok);
|
||||
int parse_vector_range(int tok);
|
||||
LibertyAst *parse();
|
||||
void error() const;
|
||||
void error(const std::string &str) const;
|
||||
|
|
Loading…
Reference in a new issue