Skip to content

Commit bd95196

Browse files
committed
systemverilog-plugin: fix parsing unsized unbased consts
Signed-off-by: Kamil Rakoczy <[email protected]>
1 parent 4747241 commit bd95196

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

systemverilog-plugin/UhdmAst.cc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,13 +1524,25 @@ AST::AstNode *UhdmAst::process_value(vpiHandle obj_h)
15241524
return ::systemverilog_plugin::const2ast(val.value.str, caseType, false);
15251525
} else {
15261526
auto size = vpi_get(vpiSize, obj_h);
1527-
if (size == 0) {
1528-
auto c = AST::AstNode::mkconst_int(atoi(val.value.str), true, 32);
1527+
std::string size_str;
1528+
if (size > 0) {
1529+
size_str = std::to_string(size);
1530+
} else if (strValType == "\'b") {
1531+
// probably unsized unbased const
1532+
// but to make sure parse vpiDecompile
1533+
auto decompile = vpi_get_str(vpiDecompile, obj_h);
1534+
if (decompile && !std::strchr(decompile, 'b')) {
1535+
// unsized unbased
1536+
// we can't left size_str empty, as then yosys parses this const as 32bit value
1537+
size_str = "1";
1538+
}
1539+
}
1540+
auto c = ::systemverilog_plugin::const2ast(size_str + strValType + val.value.str, caseType, false);
1541+
if (size <= 0) {
1542+
// unsized unbased const
15291543
c->is_unsized = true;
1530-
return c;
1531-
} else {
1532-
return ::systemverilog_plugin::const2ast(std::to_string(size) + strValType + val.value.str, caseType, false);
15331544
}
1545+
return c;
15341546
}
15351547
}
15361548
return nullptr;

0 commit comments

Comments
 (0)