@@ -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_)) {
@@ -1805,6 +1822,39 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
1805
1822
return true ;
1806
1823
}
1807
1824
1825
+ if (cell->type == ID ($check))
1826
+ {
1827
+ // Sync $check cells are accumulated and handled in dump_module.
1828
+ if (cell->getParam (ID::TRG_ENABLE).as_bool ())
1829
+ return true ;
1830
+
1831
+ f << stringf (" %s" " always @*\n " , indent.c_str ());
1832
+
1833
+ f << stringf (" %s" " if (" , indent.c_str ());
1834
+ dump_sigspec (f, cell->getPort (ID::EN));
1835
+ f << stringf (" ) begin\n " );
1836
+
1837
+ std::string flavor = cell->getParam (ID::FLAVOR).decode_string ();
1838
+ if (flavor == " assert" || flavor == " assume" ) {
1839
+ Fmt fmt;
1840
+ fmt.parse_rtlil (cell);
1841
+ if (!fmt.parts .empty ()) {
1842
+ f << stringf (" %s" " if (!" , indent.c_str ());
1843
+ dump_sigspec (f, cell->getPort (ID::A));
1844
+ f << stringf (" )\n " );
1845
+ dump_cell_expr_print (f, indent + " " , cell);
1846
+ }
1847
+ } else {
1848
+ f << stringf (" %s" " /* message omitted */\n " , indent.c_str ());
1849
+ }
1850
+
1851
+ dump_cell_expr_check (f, indent + " " , cell);
1852
+
1853
+ f << stringf (" %s" " end\n " , indent.c_str ());
1854
+
1855
+ return true ;
1856
+ }
1857
+
1808
1858
// FIXME: $fsm
1809
1859
1810
1860
return false ;
@@ -1894,7 +1944,7 @@ void dump_cell(std::ostream &f, std::string indent, RTLIL::Cell *cell)
1894
1944
}
1895
1945
}
1896
1946
1897
- void dump_sync_print (std::ostream &f, std::string indent, const RTLIL::SigSpec &trg, const RTLIL::Const &polarity, std::vector<const RTLIL::Cell*> &cells)
1947
+ void dump_sync_effect (std::ostream &f, std::string indent, const RTLIL::SigSpec &trg, const RTLIL::Const &polarity, std::vector<const RTLIL::Cell*> &cells)
1898
1948
{
1899
1949
if (trg.size () == 0 ) {
1900
1950
f << stringf (" %s" " initial begin\n " , indent.c_str ());
@@ -1918,9 +1968,29 @@ void dump_sync_print(std::ostream &f, std::string indent, const RTLIL::SigSpec &
1918
1968
for (auto cell : cells) {
1919
1969
f << stringf (" %s" " if (" , indent.c_str ());
1920
1970
dump_sigspec (f, cell->getPort (ID::EN));
1921
- f << stringf (" )\n " );
1971
+ f << stringf (" ) begin\n " );
1972
+
1973
+ if (cell->type == ID ($print)) {
1974
+ dump_cell_expr_print (f, indent + " " , cell);
1975
+ } else if (cell->type == ID ($check)) {
1976
+ std::string flavor = cell->getParam (ID::FLAVOR).decode_string ();
1977
+ if (flavor == " assert" || flavor == " assume" ) {
1978
+ Fmt fmt;
1979
+ fmt.parse_rtlil (cell);
1980
+ if (!fmt.parts .empty ()) {
1981
+ f << stringf (" %s" " if (!" , indent.c_str ());
1982
+ dump_sigspec (f, cell->getPort (ID::A));
1983
+ f << stringf (" )\n " );
1984
+ dump_cell_expr_print (f, indent + " " , cell);
1985
+ }
1986
+ } else {
1987
+ f << stringf (" %s" " /* message omitted */\n " , indent.c_str ());
1988
+ }
1922
1989
1923
- dump_cell_expr_print (f, indent + " " , cell);
1990
+ dump_cell_expr_check (f, indent + " " , cell);
1991
+ }
1992
+
1993
+ f << stringf (" %s" " end\n " , indent.c_str ());
1924
1994
}
1925
1995
1926
1996
f << stringf (" %s" " end\n " , indent.c_str ());
@@ -2171,7 +2241,7 @@ void dump_process(std::ostream &f, std::string indent, RTLIL::Process *proc, boo
2171
2241
2172
2242
void dump_module (std::ostream &f, std::string indent, RTLIL::Module *module)
2173
2243
{
2174
- std::map<std::pair<RTLIL::SigSpec, RTLIL::Const>, std::vector<const RTLIL::Cell*>> sync_print_cells ;
2244
+ std::map<std::pair<RTLIL::SigSpec, RTLIL::Const>, std::vector<const RTLIL::Cell*>> sync_effect_cells ;
2175
2245
2176
2246
reg_wires.clear ();
2177
2247
reset_auto_counter (module);
@@ -2203,8 +2273,8 @@ void dump_module(std::ostream &f, std::string indent, RTLIL::Module *module)
2203
2273
std::set<std::pair<RTLIL::Wire*,int >> reg_bits;
2204
2274
for (auto cell : module->cells ())
2205
2275
{
2206
- if (cell->type == ID ($print) && cell->getParam (ID::TRG_ENABLE).as_bool ()) {
2207
- sync_print_cells [make_pair (cell->getPort (ID::TRG), cell->getParam (ID::TRG_POLARITY))].push_back (cell);
2276
+ if (cell->type . in ( ID ($print), ID ($check) ) && cell->getParam (ID::TRG_ENABLE).as_bool ()) {
2277
+ sync_effect_cells [make_pair (cell->getPort (ID::TRG), cell->getParam (ID::TRG_POLARITY))].push_back (cell);
2208
2278
continue ;
2209
2279
}
2210
2280
@@ -2263,8 +2333,8 @@ void dump_module(std::ostream &f, std::string indent, RTLIL::Module *module)
2263
2333
for (auto cell : module->cells ())
2264
2334
dump_cell (f, indent + " " , cell);
2265
2335
2266
- for (auto &it : sync_print_cells )
2267
- dump_sync_print (f, indent + " " , it.first .first , it.first .second , it.second );
2336
+ for (auto &it : sync_effect_cells )
2337
+ dump_sync_effect (f, indent + " " , it.first .first , it.first .second , it.second );
2268
2338
2269
2339
for (auto it = module->processes .begin (); it != module->processes .end (); ++it)
2270
2340
dump_process (f, indent + " " , it->second );
0 commit comments