@@ -1008,7 +1008,7 @@ void dump_cell_expr_binop(std::ostream &f, std::string indent, RTLIL::Cell *cell
1008
1008
1009
1009
void dump_cell_expr_print (std::ostream &f, std::string indent, const RTLIL::Cell *cell)
1010
1010
{
1011
- Fmt fmt = {} ;
1011
+ Fmt fmt;
1012
1012
fmt.parse_rtlil (cell);
1013
1013
std::vector<VerilogFmtArg> args = fmt.emit_verilog ();
1014
1014
@@ -1041,6 +1041,23 @@ void dump_cell_expr_print(std::ostream &f, std::string indent, const RTLIL::Cell
1041
1041
f << stringf (" );\n " );
1042
1042
}
1043
1043
1044
+ void dump_cell_expr_check (std::ostream &f, std::string indent, const RTLIL::Cell *cell)
1045
+ {
1046
+ std::string flavor = cell->getParam (ID (FLAVOR)).decode_string ();
1047
+ if (flavor == " assert" )
1048
+ f << stringf (" %s" " assert (" , indent.c_str ());
1049
+ else if (flavor == " assume" )
1050
+ f << stringf (" %s" " assume (" , indent.c_str ());
1051
+ else if (flavor == " live" )
1052
+ f << stringf (" %s" " assert (eventually " , indent.c_str ());
1053
+ else if (flavor == " fair" )
1054
+ f << stringf (" %s" " assume (eventually " , indent.c_str ());
1055
+ else if (flavor == " cover" )
1056
+ f << stringf (" %s" " cover (" , indent.c_str ());
1057
+ dump_sigspec (f, cell->getPort (ID::A));
1058
+ f << stringf (" );\n " );
1059
+ }
1060
+
1044
1061
bool dump_cell_expr (std::ostream &f, std::string indent, RTLIL::Cell *cell)
1045
1062
{
1046
1063
if (cell->type == ID ($_NOT_)) {
@@ -1814,6 +1831,39 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
1814
1831
return true ;
1815
1832
}
1816
1833
1834
+ if (cell->type == ID ($check))
1835
+ {
1836
+ // Sync $check cells are accumulated and handled in dump_module.
1837
+ if (cell->getParam (ID::TRG_ENABLE).as_bool ())
1838
+ return true ;
1839
+
1840
+ f << stringf (" %s" " always @*\n " , indent.c_str ());
1841
+
1842
+ f << stringf (" %s" " if (" , indent.c_str ());
1843
+ dump_sigspec (f, cell->getPort (ID::EN));
1844
+ f << stringf (" ) begin\n " );
1845
+
1846
+ std::string flavor = cell->getParam (ID::FLAVOR).decode_string ();
1847
+ if (flavor == " assert" || flavor == " assume" ) {
1848
+ Fmt fmt;
1849
+ fmt.parse_rtlil (cell);
1850
+ if (!fmt.parts .empty ()) {
1851
+ f << stringf (" %s" " if (!" , indent.c_str ());
1852
+ dump_sigspec (f, cell->getPort (ID::A));
1853
+ f << stringf (" )\n " );
1854
+ dump_cell_expr_print (f, indent + " " , cell);
1855
+ }
1856
+ } else {
1857
+ f << stringf (" %s" " /* message omitted */\n " , indent.c_str ());
1858
+ }
1859
+
1860
+ dump_cell_expr_check (f, indent + " " , cell);
1861
+
1862
+ f << stringf (" %s" " end\n " , indent.c_str ());
1863
+
1864
+ return true ;
1865
+ }
1866
+
1817
1867
// FIXME: $fsm
1818
1868
1819
1869
return false ;
@@ -1903,7 +1953,7 @@ void dump_cell(std::ostream &f, std::string indent, RTLIL::Cell *cell)
1903
1953
}
1904
1954
}
1905
1955
1906
- void dump_sync_print (std::ostream &f, std::string indent, const RTLIL::SigSpec &trg, const RTLIL::Const &polarity, std::vector<const RTLIL::Cell*> &cells)
1956
+ void dump_sync_effect (std::ostream &f, std::string indent, const RTLIL::SigSpec &trg, const RTLIL::Const &polarity, std::vector<const RTLIL::Cell*> &cells)
1907
1957
{
1908
1958
if (trg.size () == 0 ) {
1909
1959
f << stringf (" %s" " initial begin\n " , indent.c_str ());
@@ -1927,9 +1977,29 @@ void dump_sync_print(std::ostream &f, std::string indent, const RTLIL::SigSpec &
1927
1977
for (auto cell : cells) {
1928
1978
f << stringf (" %s" " if (" , indent.c_str ());
1929
1979
dump_sigspec (f, cell->getPort (ID::EN));
1930
- f << stringf (" )\n " );
1980
+ f << stringf (" ) begin\n " );
1981
+
1982
+ if (cell->type == ID ($print)) {
1983
+ dump_cell_expr_print (f, indent + " " , cell);
1984
+ } else if (cell->type == ID ($check)) {
1985
+ std::string flavor = cell->getParam (ID::FLAVOR).decode_string ();
1986
+ if (flavor == " assert" || flavor == " assume" ) {
1987
+ Fmt fmt;
1988
+ fmt.parse_rtlil (cell);
1989
+ if (!fmt.parts .empty ()) {
1990
+ f << stringf (" %s" " if (!" , indent.c_str ());
1991
+ dump_sigspec (f, cell->getPort (ID::A));
1992
+ f << stringf (" )\n " );
1993
+ dump_cell_expr_print (f, indent + " " , cell);
1994
+ }
1995
+ } else {
1996
+ f << stringf (" %s" " /* message omitted */\n " , indent.c_str ());
1997
+ }
1931
1998
1932
- dump_cell_expr_print (f, indent + " " , cell);
1999
+ dump_cell_expr_check (f, indent + " " , cell);
2000
+ }
2001
+
2002
+ f << stringf (" %s" " end\n " , indent.c_str ());
1933
2003
}
1934
2004
1935
2005
f << stringf (" %s" " end\n " , indent.c_str ());
@@ -2182,7 +2252,7 @@ void dump_process(std::ostream &f, std::string indent, RTLIL::Process *proc, boo
2182
2252
2183
2253
void dump_module (std::ostream &f, std::string indent, RTLIL::Module *module)
2184
2254
{
2185
- std::map<std::pair<RTLIL::SigSpec, RTLIL::Const>, std::vector<const RTLIL::Cell*>> sync_print_cells ;
2255
+ std::map<std::pair<RTLIL::SigSpec, RTLIL::Const>, std::vector<const RTLIL::Cell*>> sync_effect_cells ;
2186
2256
2187
2257
reg_wires.clear ();
2188
2258
reset_auto_counter (module);
@@ -2214,8 +2284,8 @@ void dump_module(std::ostream &f, std::string indent, RTLIL::Module *module)
2214
2284
std::set<std::pair<RTLIL::Wire*,int >> reg_bits;
2215
2285
for (auto cell : module->cells ())
2216
2286
{
2217
- if (cell->type == ID ($print) && cell->getParam (ID::TRG_ENABLE).as_bool ()) {
2218
- sync_print_cells [make_pair (cell->getPort (ID::TRG), cell->getParam (ID::TRG_POLARITY))].push_back (cell);
2287
+ if (cell->type . in ( ID ($print), ID ($check) ) && cell->getParam (ID::TRG_ENABLE).as_bool ()) {
2288
+ sync_effect_cells [make_pair (cell->getPort (ID::TRG), cell->getParam (ID::TRG_POLARITY))].push_back (cell);
2219
2289
continue ;
2220
2290
}
2221
2291
@@ -2274,8 +2344,8 @@ void dump_module(std::ostream &f, std::string indent, RTLIL::Module *module)
2274
2344
for (auto cell : module->cells ())
2275
2345
dump_cell (f, indent + " " , cell);
2276
2346
2277
- for (auto &it : sync_print_cells )
2278
- dump_sync_print (f, indent + " " , it.first .first , it.first .second , it.second );
2347
+ for (auto &it : sync_effect_cells )
2348
+ dump_sync_effect (f, indent + " " , it.first .first , it.first .second , it.second );
2279
2349
2280
2350
for (auto it = module->processes .begin (); it != module->processes .end (); ++it)
2281
2351
dump_process (f, indent + " " , it->second );
0 commit comments