Skip to content

Commit

Permalink
Update yosys; Adjust synlig to new yosys version. (#2487)
Browse files Browse the repository at this point in the history
This PR updates yosys and adjusts synlig to it:

* fix $display calls not containing format string
* adds `-parseall` option to allow non-synthesizable constructs

Now yosys also supports $display calls in async context. Due to this,
some of the previously passing tests are now removed or moved to skip
list.
  • Loading branch information
tgorochowik authored Aug 2, 2024
2 parents a00ce45 + fa89400 commit ffbce4e
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 140 deletions.
48 changes: 9 additions & 39 deletions frontends/systemverilog/uhdm_ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1283,40 +1283,6 @@ static AST::AstNode *make_packed_struct_local(AST::AstNode *template_node, std::
return wnode;
}

static void simplify_format_string(AST::AstNode *current_node)
{
std::string sformat = current_node->children[0]->str;
std::string preformatted_string = "";
int next_arg = 1;
for (size_t i = 0; i < sformat.length(); i++) {
if (sformat[i] == '%') {
AST::AstNode *node_arg = current_node->children[next_arg];
char cformat = sformat[++i];
if (cformat == 'b' or cformat == 'B') {
simplify(node_arg, true, false, false, 1, -1, false, false);
if (node_arg->type != AST::AST_CONSTANT)
log_file_error(current_node->filename, current_node->location.first_line,
"Failed to evaluate system task `%s' with non-constant argument.\n", current_node->str.c_str());

RTLIL::Const val = node_arg->bitsAsConst();
for (int j = val.size() - 1; j >= 0; j--) {
// We add ACII value of 0 to convert number to character
preformatted_string += ('0' + val[j]);
}
delete current_node->children[next_arg];
current_node->children.erase(current_node->children.begin() + next_arg);
} else {
next_arg++;
preformatted_string += std::string("%") + cformat;
}
} else {
preformatted_string += sformat[i];
}
}
delete current_node->children[0];
current_node->children[0] = AST::AstNode::mkconst_str(preformatted_string);
}

void resolve_children_reparent(AST::AstNode *current_node)
{
bool have_children_to_reparent = false;
Expand Down Expand Up @@ -1489,8 +1455,6 @@ static void simplify_sv(AST::AstNode *current_node, AST::AstNode *parent_node)
}
break;
case AST::AST_TCALL:
if (current_node->str == "$display" || current_node->str == "$write")
simplify_format_string(current_node);
break;
case AST::AST_COND:
case AST::AST_CONDX:
Expand Down Expand Up @@ -1531,6 +1495,12 @@ static void simplify_sv(AST::AstNode *current_node, AST::AstNode *parent_node)
delete_attribute(current_node, UhdmAst::low_high_bound());
}
break;
case AST::AST_EQ:
if (current_node->children.size() != 2)
log_file_error(
current_node->filename, current_node->location.first_line,
"Equality operator demands two arguments, but got one; it might happen because synlig discards most non-synthesizable code\n");
break;
default:
break;
}
Expand Down Expand Up @@ -4730,9 +4700,9 @@ void UhdmAst::process_sys_func_call()

if (current_node->str == "\\$display" || current_node->str == "\\$write") {
// According to standard, %h and %x mean the same, but %h is currently unsupported by mainline yosys
std::string replaced_string = std::regex_replace(current_node->children[0]->str, std::regex("%[h|H]"), "%x");
delete current_node->children[0];
current_node->children[0] = AST::AstNode::mkconst_str(replaced_string);
if (current_node->children[0]->type == AST::AST_CONSTANT && current_node->children[0]->is_string) {
current_node->children[0]->str = std::regex_replace(current_node->children[0]->str, std::regex("%[h|H]"), "%x");
}
}

std::string remove_backslash[] = {"\\$display", "\\$strobe", "\\$write", "\\$monitor", "\\$time", "\\$finish",
Expand Down
4 changes: 4 additions & 0 deletions frontends/systemverilog/uhdm_ast_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class UhdmAstShared
// Allows verification constructs in Surelog
bool formal = false;

// Flag that disables -synth flag when compiling systemverilog with surelog
// applies only to read_systemverilog comand
bool disable_synth;

// Top nodes of the design (modules, interfaces)
std::unordered_map<std::string, ::Yosys::AST::AstNode *> top_nodes;

Expand Down
5 changes: 5 additions & 0 deletions frontends/systemverilog/uhdm_common_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ void UhdmCommonFrontend::print_read_options()
log(" enable support for SystemVerilog assertions and some Yosys extensions\n");
log(" replace the implicit -D SYNTHESIS with -D FORMAL\n");
log("\n");
log(" -parseall\n");
log(" enable non-synthesizable SystemVerilog code which is discarded by default\n");
log("\n");
}

void UhdmCommonFrontend::execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
Expand Down Expand Up @@ -141,6 +144,8 @@ void UhdmCommonFrontend::execute(std::istream *&f, std::string filename, std::ve
this->shared.formal = true;
// Surelog needs it in the command line to annotate UHDM
unhandled_args.push_back(args[i]);
} else if (args[i] == "-parseall") {
this->shared.disable_synth = true;
} else {
unhandled_args.push_back(args[i]);
}
Expand Down
4 changes: 3 additions & 1 deletion frontends/systemverilog/uhdm_surelog_ast_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ struct UhdmSurelogAstFrontend : public UhdmCommonFrontend {
clp->setParse(true);
clp->fullSVMode(true);
clp->setCacheAllowed(true);
clp->setReportNonSynthesizable(true);
if (!this->shared.disable_synth) {
clp->setReportNonSynthesizable(true);
}
if (this->shared.defer) {
clp->setCompile(false);
clp->setElaborate(false);
Expand Down
128 changes: 128 additions & 0 deletions tests/formal/extra_arg_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Below tests contain non-synthesizable code which is discarded
# by synlig by default, this behavior can be changed (by adding
# -parseall flag), and it needs to be changed for formal
# verification.
# Some of below test are not passing and were added to skiplist
# so their entry in this file is not used at all, but they are
# mentioned here to mark that they require -parseall flag.
# -------------------------------------------------------------
# synlig tests
simple:DisplayWithBinFormatSpecifier/top.sv -parseall
simple:DisplayWithHexFormatSpecifier/top.sv -parseall
# yosys tests
yosys:simple/string_format.v -parseall
yosys:fmt/always_comb.v -parseall
# sv2v tests
sv2v:core/package_self_reference_shadow.v -parseall
sv2v:core/unpacked_localparam.v -parseall
sv2v:core/top_tf.v -parseall
sv2v:core/package_ident.v -parseall
sv2v:lex/macro_macro.v -parseall
sv2v:error/size_cast_neg_lit_1.sv -parseall
sv2v:core/simplify_func.v -parseall
sv2v:core/paramtype_param_default.v -parseall
sv2v:core/string_type.sv -parseall
sv2v:core/interface_struct_param.v -parseall
sv2v:core/ambiguous_tore.v -parseall
sv2v:core/end_labels.v -parseall
sv2v:core/interface_func.sv -parseall
sv2v:lex/number_literal_whitespace.v -parseall
sv2v:core/package_export_wildcard.sv -parseall
sv2v:core/case_inside_cast.v -parseall
sv2v:core/struct_array_inline.v -parseall
sv2v:basic/shift.sv -parseall
sv2v:lex/number.sv -parseall
sv2v:error/size_cast_neg_lit_2.sv -parseall
sv2v:lex/comment_no_space.sv -parseall
sv2v:core/simple_loop_jump.v -parseall
sv2v:core/struct_part_select.v -parseall
sv2v:core/interface_func.v -parseall
sv2v:core/interface_array_indirect.v -parseall
sv2v:core/typename_deep.sv -parseall
sv2v:core/package_export_nothing.v -parseall
sv2v:core/package_global.sv -parseall
sv2v:core/typename_deep.v -parseall
sv2v:core/package_enum_5.v -parseall
sv2v:core/sign_cast.sv -parseall
sv2v:core/empty_args_hier.v -parseall
sv2v:core/unused_imports.sv -parseall
sv2v:core/interface_array_single.v -parseall
sv2v:core/bit.sv -parseall
sv2v:core/paramtype_param.v -parseall
sv2v:core/package_param.sv -parseall
sv2v:lex/macro_string.sv -parseall
sv2v:core/package_decl_reorder.v -parseall
sv2v:core/struct_hier_nocast.v -parseall
sv2v:basic/generate_else_branch.sv -parseall
sv2v:core/struct_shadow.v -parseall
sv2v:core/package_self_reference_import.v -parseall
sv2v:core/sign_cast.v -parseall
sv2v:core/struct_array_param.sv -parseall
sv2v:core/package_shadow.sv -parseall
sv2v:core/for_loop_inits.v -parseall
sv2v:core/package_self_reference.v -parseall
sv2v:core/shadow_recurse.v -parseall
sv2v:basic/typeof_op.sv -parseall
sv2v:basic/simplify_binop.sv -parseall
sv2v:core/paramtype_expr.v -parseall
sv2v:basic/string_param_plain.sv -parseall
sv2v:core/package_export_wildcard.v -parseall
sv2v:core/interface_type_param.sv -parseall
sv2v:core/paramtype_stagger.v -parseall
sv2v:core/param_list_unpacked.sv -parseall
sv2v:core/simple_loop_jump.sv -parseall
sv2v:core/package_ident.sv -parseall
sv2v:core/struct_param.v -parseall
sv2v:nosim/min_typ_max.sv -parseall
sv2v:core/struct_array_param.v -parseall
sv2v:core/package_global.v -parseall
sv2v:core/empty_args_hier.sv -parseall
sv2v:core/package_decl_init.v -parseall
sv2v:core/class_ident.v -parseall
sv2v:core/localparamtype.v -parseall
sv2v:core/param_list_unpacked.v -parseall
sv2v:core/function_ret_unpacked.v -parseall
sv2v:core/array_in_package.v -parseall
sv2v:core/number_concat.v -parseall
sv2v:lex/macro_arg_escape.sv -parseall
sv2v:core/struct_hier_nocast.sv -parseall
sv2v:core/struct_array_inline.sv -parseall
sv2v:core/package.v -parseall
sv2v:core/string_cast.sv -parseall
sv2v:core/cast_literal.sv -parseall
sv2v:core/package_shadow.v -parseall
sv2v:core/enum_typedef_keep.v -parseall
sv2v:core/unused_imports.v -parseall
sv2v:core/paramtype.v -parseall
sv2v:core/package_enum_4.sv -parseall
sv2v:core/nest_order.sv -parseall
sv2v:core/package_param.v -parseall
sv2v:core/nest_order.v -parseall
sv2v:basic/gen_case.sv -parseall
sv2v:core/paramtype_expr.sv -parseall
sv2v:basic/simplify_localparam_shadow.sv -parseall
sv2v:core/package_implied.v -parseall
sv2v:core/string_type.v -parseall
sv2v:basic/simplify_type.sv -parseall
sv2v:basic/mutual_recursion.sv -parseall
sv2v:lex/string_macro.v -parseall
sv2v:core/package_self_reference_import.sv -parseall
sv2v:core/number_concat.sv -parseall
sv2v:core/union.v -parseall
sv2v:core/package_self_reference.sv -parseall
sv2v:core/header_import.sv -parseall
sv2v:core/header_import.v -parseall
sv2v:core/package_enum_4.v -parseall
sv2v:lex/macro_arg_comment.v -parseall
sv2v:basic/simplify_genvar_shadow.sv -parseall
sv2v:basic/simplify_arg_shadow.sv -parseall
sv2v:lex/line.v -parseall
sv2v:core/no_default_param.v -parseall
sv2v:core/class_param_nest.v -parseall
sv2v:core/bit.v -parseall
sv2v:core/class_ident.sv -parseall
sv2v:core/cast_conflict.sv -parseall
sv2v:core/package_scope.v -parseall
sv2v:core/struct_part_select_param.v -parseall
sv2v:core/class_param_nest.sv -parseall
sv2v:core/package_implied.sv -parseall
Loading

0 comments on commit ffbce4e

Please sign in to comment.