@@ -9,14 +9,19 @@ using std::vector;
99using std::string;
1010using std::endl;
1111
12+ // in 'cleanup' mode checker may modify the blif
1213bool do_check_blif (CStr cfn,
1314 vector<string>& badInputs,
14- vector<string>& badOutputs) {
15+ vector<string>& badOutputs,
16+ vector<uspair>& corrected,
17+ bool cleanup) {
1518 assert (cfn);
1619 uint16_t tr = ltrace ();
1720 auto & ls = lout ();
1821 badInputs.clear ();
1922 badOutputs.clear ();
23+ corrected.clear ();
24+ flush_out (false );
2025
2126 BLIF_file bfile (string{cfn});
2227
@@ -25,26 +30,26 @@ bool do_check_blif(CStr cfn,
2530
2631 bool exi = false ;
2732 exi = bfile.fileExists ();
28- if (tr >= 7 )
29- ls << int (exi) << endl;
3033 if (not exi) {
34+ err_puts (); flush_out (true );
3135 lprintf2 (" [Error] file '%s' does not exist\n " , cfn);
36+ flush_out (true ); err_puts ();
3237 return false ;
3338 }
3439
3540 exi = bfile.fileAccessible ();
36- if (tr >= 7 )
37- ls << int (exi) << endl;
3841 if (not exi) {
42+ err_puts (); flush_out (true );
3943 lprintf2 (" [Error] file '%s' is not accessible\n " , cfn);
44+ flush_out (true ); err_puts ();
4045 return false ;
4146 }
4247
4348 bool rd_ok = bfile.readBlif ();
44- if (tr >= 7 )
45- ls << int (rd_ok) << endl;
4649 if (not rd_ok) {
50+ err_puts (); flush_out (true );
4751 lprintf2 (" [Error] failed reading file '%s'\n " , cfn);
52+ flush_out (true ); err_puts ();
4853 return false ;
4954 }
5055
@@ -122,14 +127,32 @@ bool do_check_blif(CStr cfn,
122127 std::filesystem::path base_path = full_path.filename ();
123128 std::string base = base_path.string ();
124129 // lputs9();
125- string outFn = str::concat (" PLN_W" , std::to_string (numWarn), " _" , base);
126-
127- string wr_ok = bfile.writeBlif (outFn, numWarn);
128-
129- if (wr_ok.empty ())
130+ string outFn;
131+ if (cleanup) {
132+ flush_out (true );
133+ lprintf (" [PLANNER BLIF-CLEANER] : replacing file '%s' ...\n " , cfn);
134+ flush_out (true );
135+ // cannot write to the currently mem-mapped file,
136+ // write to a temproray and rename later.
137+ outFn = str::concat (full_path.lexically_normal ().string (),
138+ " +BLIF_CLEANER.tmp_" , std::to_string (get_PID ()));
139+ } else {
140+ outFn = str::concat (" PLN_WARN" , std::to_string (numWarn), " _" , base);
141+ }
142+
143+ string wr_ok = bfile.writeBlif (outFn, bool (numWarn), corrected);
144+
145+ if (wr_ok.empty ()) {
130146 lprintf (" ---!! FAILED writeBlif to '%s'\n " , outFn.c_str ());
131- else
147+ if (cleanup) {
148+ lprintf (" [PLANNER BLIF-CLEANER] : FAILED\n " );
149+ }
150+ } else {
132151 lprintf (" +++++ WRITTEN '%s'\n " , wr_ok.c_str ());
152+ if (cleanup) {
153+ lprintf (" [PLANNER BLIF-CLEANER] : replaced file '%s'\n " , cfn);
154+ }
155+ }
133156 }
134157 }
135158 lprintf (" ===== passed: %s\n " , chk_ok ? " YES" : " NO" );
@@ -156,11 +179,27 @@ bool do_check_blif(CStr cfn,
156179}
157180
158181// 'corrected' : (lnum, removed_net)
159- bool do_cleanup_blif (CStr cfn, std:: vector<uspair>& corrected) {
182+ bool do_cleanup_blif (CStr cfn, vector<uspair>& corrected) {
160183 assert (cfn);
161184 corrected.clear ();
162185
163- return false ;
186+ vector<string> badInp, badOut;
187+ bool status = do_check_blif (cfn, badInp, badOut, corrected, true );
188+
189+ size_t cor_sz = corrected.size ();
190+ if (status and cor_sz) {
191+ flush_out (true );
192+ lprintf (" [PLANNER BLIF-CLEANER] : corrected netlist '%s'\n " , cfn);
193+ lprintf (" -- removed dangling nets (%zu):\n " , cor_sz);
194+ for (size_t i = 0 ; i < cor_sz; i++) {
195+ const uspair& cor = corrected[i];
196+ lprintf (" line %u net %s\n " , cor.first , cor.second .c_str ());
197+ }
198+ lprintf (" -- removed dangling nets (%zu).\n " , cor_sz);
199+ flush_out (true );
200+ }
201+
202+ return status;
164203}
165204
166205static bool do_check_csv (CStr cfn) {
@@ -230,7 +269,8 @@ bool do_check(const rsOpts& opts, bool blif_vs_csv) {
230269 bool status;
231270 if (blif_vs_csv) {
232271 vector<string> badInp, badOut;
233- status = do_check_blif (cfn, badInp, badOut);
272+ vector<uspair> corrected;
273+ status = do_check_blif (cfn, badInp, badOut, corrected, false );
234274 } else {
235275 status = do_check_csv (cfn);
236276 }
0 commit comments