mirror of https://github.com/YosysHQ/yosys.git
Added $display %m support, fixed mem leak in $display, fixes #128
This commit is contained in:
parent
ff5c61b120
commit
e5d42ebb4d
|
@ -193,13 +193,13 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
// but should be good enough for most uses
|
||||
if ((type == AST_TCALL) && ((str == "$display") || (str == "$write")))
|
||||
{
|
||||
size_t nargs = GetSize(children);
|
||||
int nargs = GetSize(children);
|
||||
if (nargs < 1)
|
||||
log_error("System task `%s' got %d arguments, expected >= 1 at %s:%d.\n",
|
||||
str.c_str(), int(children.size()), filename.c_str(), linenum);
|
||||
|
||||
// First argument is the format string
|
||||
AstNode *node_string = children[0]->clone();
|
||||
AstNode *node_string = children[0];
|
||||
while (node_string->simplify(true, false, false, stage, width_hint, sign_hint, false)) { }
|
||||
if (node_string->type != AST_CONSTANT)
|
||||
log_error("Failed to evaluate system task `%s' with non-constant 1st argument at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
|
||||
|
@ -207,7 +207,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
|
||||
// Other arguments are placeholders. Process the string as we go through it
|
||||
std::string sout;
|
||||
size_t next_arg = 1;
|
||||
int next_arg = 1;
|
||||
for (size_t i = 0; i < sformat.length(); i++)
|
||||
{
|
||||
// format specifier
|
||||
|
@ -226,17 +226,37 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
continue;
|
||||
}
|
||||
|
||||
// If we're out of arguments, that's a problem!
|
||||
if(next_arg >= nargs)
|
||||
log_error("System task `%s' called with more format specifiers than arguments at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
|
||||
|
||||
// Simplify the argument
|
||||
AstNode *node_arg = children[next_arg ++]->clone();
|
||||
AstNode *node_arg = nullptr;
|
||||
|
||||
// Everything from here on depends on the format specifier
|
||||
switch (cformat)
|
||||
{
|
||||
case 's':
|
||||
case 'S':
|
||||
case 'd':
|
||||
case 'D':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (next_arg >= GetSize(children))
|
||||
log_error("Missing argument for %%%c format specifier in system task `%s' at %s:%d.\n",
|
||||
cformat, str.c_str(), filename.c_str(), linenum);
|
||||
|
||||
node_arg = children[next_arg++];
|
||||
while (node_arg->simplify(true, false, false, stage, width_hint, sign_hint, false)) { }
|
||||
if (node_arg->type != AST_CONSTANT)
|
||||
log_error("Failed to evaluate system task `%s' with non-constant argument at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
case 'M':
|
||||
break;
|
||||
|
||||
default:
|
||||
log_error("System task `%s' called with invalid/unsupported format specifier at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
|
||||
break;
|
||||
}
|
||||
|
||||
// Everything from here on depends on the format specifier
|
||||
switch (cformat)
|
||||
{
|
||||
case 's':
|
||||
|
@ -262,9 +282,13 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
log_error("System task `%s' called with invalid format specifier at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
|
||||
case 'm':
|
||||
case 'M':
|
||||
sout += log_id(current_module->name);
|
||||
break;
|
||||
|
||||
default:
|
||||
log_abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue