diff --git a/planning/src/RS/rsCheck.cpp b/planning/src/RS/rsCheck.cpp index 74fa973e..24c9298b 100644 --- a/planning/src/RS/rsCheck.cpp +++ b/planning/src/RS/rsCheck.cpp @@ -9,14 +9,19 @@ using std::vector; using std::string; using std::endl; +// in 'cleanup' mode checker may modify the blif bool do_check_blif(CStr cfn, vector& badInputs, - vector& badOutputs) { + vector& badOutputs, + vector& corrected, + bool cleanup) { assert(cfn); uint16_t tr = ltrace(); auto& ls = lout(); badInputs.clear(); badOutputs.clear(); + corrected.clear(); + flush_out(false); BLIF_file bfile(string{cfn}); @@ -25,26 +30,26 @@ bool do_check_blif(CStr cfn, bool exi = false; exi = bfile.fileExists(); - if (tr >= 7) - ls << int(exi) << endl; if (not exi) { + err_puts(); flush_out(true); lprintf2("[Error] file '%s' does not exist\n", cfn); + flush_out(true); err_puts(); return false; } exi = bfile.fileAccessible(); - if (tr >= 7) - ls << int(exi) << endl; if (not exi) { + err_puts(); flush_out(true); lprintf2("[Error] file '%s' is not accessible\n", cfn); + flush_out(true); err_puts(); return false; } bool rd_ok = bfile.readBlif(); - if (tr >= 7) - ls << int(rd_ok) << endl; if (not rd_ok) { + err_puts(); flush_out(true); lprintf2("[Error] failed reading file '%s'\n", cfn); + flush_out(true); err_puts(); return false; } @@ -122,14 +127,32 @@ bool do_check_blif(CStr cfn, std::filesystem::path base_path = full_path.filename(); std::string base = base_path.string(); //lputs9(); - string outFn = str::concat("PLN_W", std::to_string(numWarn), "_", base); - - string wr_ok = bfile.writeBlif(outFn, numWarn); - - if (wr_ok.empty()) + string outFn; + if (cleanup) { + flush_out(true); + lprintf("[PLANNER BLIF-CLEANER] : replacing file '%s' ...\n", cfn); + flush_out(true); + // cannot write to the currently mem-mapped file, + // write to a temproray and rename later. + outFn = str::concat(full_path.lexically_normal().string(), + "+BLIF_CLEANER.tmp_", std::to_string(get_PID())); + } else { + outFn = str::concat("PLN_WARN", std::to_string(numWarn), "_", base); + } + + string wr_ok = bfile.writeBlif(outFn, bool(numWarn), corrected); + + if (wr_ok.empty()) { lprintf("---!! FAILED writeBlif to '%s'\n", outFn.c_str()); - else + if (cleanup) { + lprintf("[PLANNER BLIF-CLEANER] : FAILED\n"); + } + } else { lprintf("+++++ WRITTEN '%s'\n", wr_ok.c_str()); + if (cleanup) { + lprintf("[PLANNER BLIF-CLEANER] : replaced file '%s'\n", cfn); + } + } } } lprintf("===== passed: %s\n", chk_ok ? "YES" : "NO"); @@ -156,11 +179,27 @@ bool do_check_blif(CStr cfn, } // 'corrected' : (lnum, removed_net) -bool do_cleanup_blif(CStr cfn, std::vector& corrected) { +bool do_cleanup_blif(CStr cfn, vector& corrected) { assert(cfn); corrected.clear(); - return false; + vector badInp, badOut; + bool status = do_check_blif(cfn, badInp, badOut, corrected, true); + + size_t cor_sz = corrected.size(); + if (status and cor_sz) { + flush_out(true); + lprintf("[PLANNER BLIF-CLEANER] : corrected netlist '%s'\n", cfn); + lprintf("-- removed dangling nets (%zu):\n", cor_sz); + for (size_t i = 0; i < cor_sz; i++) { + const uspair& cor = corrected[i]; + lprintf(" line %u net %s\n", cor.first, cor.second.c_str()); + } + lprintf("-- removed dangling nets (%zu).\n", cor_sz); + flush_out(true); + } + + return status; } static bool do_check_csv(CStr cfn) { @@ -230,7 +269,8 @@ bool do_check(const rsOpts& opts, bool blif_vs_csv) { bool status; if (blif_vs_csv) { vector badInp, badOut; - status = do_check_blif(cfn, badInp, badOut); + vector corrected; + status = do_check_blif(cfn, badInp, badOut, corrected, false); } else { status = do_check_csv(cfn); } diff --git a/planning/src/RS/rsCheck.h b/planning/src/RS/rsCheck.h index c7d5c2d0..764fd631 100644 --- a/planning/src/RS/rsCheck.h +++ b/planning/src/RS/rsCheck.h @@ -9,15 +9,23 @@ namespace pln { bool do_check(const rsOpts& opts, bool blif_vs_csv); -bool do_check_blif(CStr cfn, - std::vector& badInputs, - std::vector& badOutputs); +bool do_check_blif( + CStr fileName, + std::vector& badInputs, + std::vector& badOutputs, + std::vector& corrected, + + bool cleanup = false // cleanup => checker may modify the blif + + ); + bool do_cleanup_blif( - CStr cfn, + CStr fileName, std::vector& corrected // (lnum, removed_net) ); + } #endif diff --git a/planning/src/file_io/pln_blif_file.cpp b/planning/src/file_io/pln_blif_file.cpp index fa2612d7..c7733db3 100644 --- a/planning/src/file_io/pln_blif_file.cpp +++ b/planning/src/file_io/pln_blif_file.cpp @@ -2501,7 +2501,10 @@ string BLIF_file::writePinGraph(CStr fn0) const noexcept { return {}; } -string BLIF_file::writeBlif(const string& toFn, bool cleanUp) noexcept { + +string BLIF_file::writeBlif(const string& toFn, bool cleanUp, + vector& corrected) noexcept { + corrected.clear(); if (toFn.empty()) return {}; if (!fsz_ || !sz_ || !buf_ || fnm_.empty()) @@ -2513,7 +2516,8 @@ string BLIF_file::writeBlif(const string& toFn, bool cleanUp) noexcept { if (trace_ >= 4) { lout() << "pln_blif_file: writing BLIF to " << fn2 - << "\n CWD= " << get_CWD() << endl; + << "\n CWD= " << get_CWD() + << "\n clean-up mode : " << int(cleanUp) << endl; } CStr cnm = fn2.c_str(); @@ -2521,7 +2525,7 @@ string BLIF_file::writeBlif(const string& toFn, bool cleanUp) noexcept { if (!f) { if (trace_ >= 3) { flush_out(true); - lprintf("ERROR writeBlif() could not open file for writing: %s\n", cnm); + lprintf2("[Error] writeBlif() could not open file for writing: %s\n", cnm); flush_out(true); } return {}; @@ -2540,7 +2544,7 @@ string BLIF_file::writeBlif(const string& toFn, bool cleanUp) noexcept { if (::ferror(f)) { if (trace_ >= 3) { flush_out(true); - lprintf("ERROR writeBlif() error during writing: %s\n", cnm); + lprintf2("ERROR writeBlif() error during writing: %s\n", cnm); flush_out(true); } error = true; @@ -2578,6 +2582,7 @@ string BLIF_file::writeBlif(const string& toFn, bool cleanUp) noexcept { if (dNode.isDanglingTerm(i)) { if (trace_ >= 6) lprintf("\t (wrBlif) skipping dangling term %zu\n", i); + corrected.emplace_back(lineNum, dNode.realData_[i]); skipCnt++; continue; } @@ -2598,7 +2603,7 @@ string BLIF_file::writeBlif(const string& toFn, bool cleanUp) noexcept { if (::ferror(f)) { if (trace_ >= 3) { flush_out(true); - lprintf("ERROR writeBlif() error during writing: %s\n", cnm); + lprintf2("ERROR writeBlif() error during writing: %s\n", cnm); flush_out(true); } error = true; diff --git a/planning/src/file_io/pln_blif_file.h b/planning/src/file_io/pln_blif_file.h index 50cbada5..285ed5fd 100644 --- a/planning/src/file_io/pln_blif_file.h +++ b/planning/src/file_io/pln_blif_file.h @@ -290,7 +290,8 @@ struct BLIF_file : public fio::MMapReader bool readBlif() noexcept; - string writeBlif(const string& toFn, bool cleanUp) noexcept; + string writeBlif(const string& toFn, bool cleanUp, + std::vector& corrected) noexcept; bool checkBlif(vector& badInputs, vector& badOutputs) noexcept; diff --git a/planning/src/main.cpp b/planning/src/main.cpp index bae6b674..3c832839 100644 --- a/planning/src/main.cpp +++ b/planning/src/main.cpp @@ -1,4 +1,4 @@ -static const char* _pln_VERSION_STR = "pln0357"; +static const char* _pln_VERSION_STR = "pln0358"; #include "RS/rsEnv.h" #include "util/pln_log.h" @@ -87,7 +87,8 @@ static bool deal_cleanup(const rsOpts& opts) { status = do_cleanup_blif(opts.input_, corrected); if (tr >= 3) { - lprintf(" deal_cleanup status: %s\n", status ? "TRUE" : "FALSE"); + flush_out(true); + lprintf(" deal_cleanup: status= %s\n", status ? "TRUE" : "FALSE"); if (corrected.empty()) { if (status) lprintf(" deal_cleanup: BLIF was not modified (NOP)\n"); diff --git a/planning/src/pin_loc/read_ports.cpp b/planning/src/pin_loc/read_ports.cpp index 58760bf1..22fb4ea6 100644 --- a/planning/src/pin_loc/read_ports.cpp +++ b/planning/src/pin_loc/read_ports.cpp @@ -1118,11 +1118,12 @@ bool PinPlacer::BlifReader::read_blif(const string& blif_fn, bool& checked_ok) n } vector badInputs, badOutputs; + vector corrected; if (not ::getenv("pinc_dont_check_blif")) { lprintf("____ BEGIN pinc_check_blif: %s\n", cfn); flush_out(true); - checked_ok = do_check_blif(cfn, badInputs, badOutputs); + checked_ok = do_check_blif(cfn, badInputs, badOutputs, corrected, false); flush_out(true); lprintf(" pinc_check_blif STATUS = %s\n\n", checked_ok ? "PASS" : "FAIL");