@@ -655,6 +655,17 @@ void hierarchy_clean(RTLIL::Design *design, RTLIL::Module *top, bool purge_lib)
655
655
log (" Removed %d unused modules.\n " , del_counter);
656
656
}
657
657
658
+ bool set_keep_print (std::map<RTLIL::Module*, bool > &cache, RTLIL::Module *mod)
659
+ {
660
+ if (cache.count (mod) == 0 )
661
+ for (auto c : mod->cells ()) {
662
+ RTLIL::Module *m = mod->design ->module (c->type );
663
+ if ((m != nullptr && set_keep_print (cache, m)) || c->type == ID ($print))
664
+ return cache[mod] = true ;
665
+ }
666
+ return cache[mod];
667
+ }
668
+
658
669
bool set_keep_assert (std::map<RTLIL::Module*, bool > &cache, RTLIL::Module *mod)
659
670
{
660
671
if (cache.count (mod) == 0 )
@@ -762,6 +773,11 @@ struct HierarchyPass : public Pass {
762
773
log (" -nodefaults\n " );
763
774
log (" do not resolve input port default values\n " );
764
775
log (" \n " );
776
+ log (" -nokeep_prints\n " );
777
+ log (" per default this pass sets the \" keep\" attribute on all modules\n " );
778
+ log (" that directly or indirectly display text on the terminal.\n " );
779
+ log (" This option disables this behavior.\n " );
780
+ log (" \n " );
765
781
log (" -nokeep_asserts\n " );
766
782
log (" per default this pass sets the \" keep\" attribute on all modules\n " );
767
783
log (" that directly or indirectly contain one or more formal properties.\n " );
@@ -818,6 +834,7 @@ struct HierarchyPass : public Pass {
818
834
bool keep_positionals = false ;
819
835
bool keep_portwidths = false ;
820
836
bool nodefaults = false ;
837
+ bool nokeep_prints = false ;
821
838
bool nokeep_asserts = false ;
822
839
std::vector<std::string> generate_cells;
823
840
std::vector<generate_port_decl_t > generate_ports;
@@ -893,6 +910,10 @@ struct HierarchyPass : public Pass {
893
910
nodefaults = true ;
894
911
continue ;
895
912
}
913
+ if (args[argidx] == " -nokeep_prints" ) {
914
+ nokeep_prints = true ;
915
+ continue ;
916
+ }
896
917
if (args[argidx] == " -nokeep_asserts" ) {
897
918
nokeep_asserts = true ;
898
919
continue ;
@@ -1091,6 +1112,15 @@ struct HierarchyPass : public Pass {
1091
1112
}
1092
1113
}
1093
1114
1115
+ if (!nokeep_prints) {
1116
+ std::map<RTLIL::Module*, bool > cache;
1117
+ for (auto mod : design->modules ())
1118
+ if (set_keep_print (cache, mod)) {
1119
+ log (" Module %s directly or indirectly displays text -> setting \" keep\" attribute.\n " , log_id (mod));
1120
+ mod->set_bool_attribute (ID::keep);
1121
+ }
1122
+ }
1123
+
1094
1124
if (!nokeep_asserts) {
1095
1125
std::map<RTLIL::Module*, bool > cache;
1096
1126
for (auto mod : design->modules ())
0 commit comments