Skip to content

Commit 77b6dc4

Browse files
committed
checker: finished --cleanup_blif
1 parent 214a824 commit 77b6dc4

File tree

6 files changed

+88
-15
lines changed

6 files changed

+88
-15
lines changed

planning/src/RS/rsCheck.cpp

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ using std::string;
1010
using std::endl;
1111

1212
// in 'cleanup' mode checker may modify the blif
13+
// if checker wrote blif, 'outFn' is the file name
1314
bool do_check_blif(CStr cfn,
1415
vector<string>& badInputs,
1516
vector<string>& badOutputs,
1617
vector<uspair>& corrected,
18+
string& outFn,
1719
bool cleanup) {
1820
assert(cfn);
1921
uint16_t tr = ltrace();
2022
auto& ls = lout();
2123
badInputs.clear();
2224
badOutputs.clear();
2325
corrected.clear();
26+
outFn.clear();
2427
flush_out(false);
2528

2629
BLIF_file bfile(string{cfn});
@@ -127,13 +130,12 @@ bool do_check_blif(CStr cfn,
127130
std::filesystem::path base_path = full_path.filename();
128131
std::string base = base_path.string();
129132
//lputs9();
130-
string outFn;
131133
if (cleanup) {
132134
flush_out(true);
133135
lprintf("[PLANNER BLIF-CLEANER] : replacing file '%s' ...\n", cfn);
134136
flush_out(true);
135137
// cannot write to the currently mem-mapped file,
136-
// write to a temproray and rename later.
138+
// write to a temporary and rename later.
137139
outFn = str::concat(full_path.lexically_normal().string(),
138140
"+BLIF_CLEANER.tmp_", std::to_string(get_PID()));
139141
} else {
@@ -144,9 +146,9 @@ bool do_check_blif(CStr cfn,
144146

145147
if (wr_ok.empty()) {
146148
lprintf("---!! FAILED writeBlif to '%s'\n", outFn.c_str());
147-
if (cleanup) {
149+
if (cleanup)
148150
lprintf("[PLANNER BLIF-CLEANER] : FAILED\n");
149-
}
151+
outFn.clear();
150152
} else {
151153
lprintf("+++++ WRITTEN '%s'\n", wr_ok.c_str());
152154
if (cleanup) {
@@ -180,23 +182,88 @@ bool do_check_blif(CStr cfn,
180182

181183
// 'corrected' : (lnum, removed_net)
182184
bool do_cleanup_blif(CStr cfn, vector<uspair>& corrected) {
185+
using namespace fio;
186+
using namespace std;
183187
assert(cfn);
184188
corrected.clear();
189+
uint16_t tr = ltrace();
185190

186191
vector<string> badInp, badOut;
187-
bool status = do_check_blif(cfn, badInp, badOut, corrected, true);
192+
string outFn;
193+
194+
bool status = do_check_blif(cfn, badInp, badOut, corrected, outFn, true);
188195

189196
size_t cor_sz = corrected.size();
190197
if (status and cor_sz) {
198+
191199
flush_out(true);
192200
lprintf("[PLANNER BLIF-CLEANER] : corrected netlist '%s'\n", cfn);
193201
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());
202+
if (tr >= 3) {
203+
for (size_t i = 0; i < cor_sz; i++) {
204+
const uspair& cor = corrected[i];
205+
lprintf(" line %u net %s\n", cor.first, cor.second.c_str());
206+
if (tr < 4 and i > 40 and cor_sz > 50) {
207+
lputs(" ...");
208+
break;
209+
}
210+
}
211+
lprintf("-- removed dangling nets (%zu).\n", cor_sz);
197212
}
198-
lprintf("-- removed dangling nets (%zu).\n", cor_sz);
199213
flush_out(true);
214+
215+
bool outFn_exists = Fio::nonEmptyFileExists(outFn);
216+
bool cfn_exists = Fio::nonEmptyFileExists(cfn);
217+
//assert(cfn_exists);
218+
if (outFn_exists and cfn_exists) {
219+
220+
bool error1 = false, error2 = false;
221+
222+
// -- 1. add prefix 'orig_' to the original BLIF
223+
{
224+
string newName = str::concat("orig_", cfn);
225+
filesystem::path newPath{newName};
226+
filesystem::path oldPath{cfn};
227+
error_code ec;
228+
filesystem::rename(oldPath, newPath, ec);
229+
if (ec) {
230+
error1 = true;
231+
lout() << endl
232+
<< "BLIF-CLEANER: [Error] renaming original BLIF to "
233+
<< newPath << endl
234+
<< " ERROR: " << ec.message() << '\n' << endl;
235+
}
236+
else if (tr >= 3) {
237+
lprintf("[PLANNER BLIF-CLEANER] : original BLIF saved as '%s'\n",
238+
newName.c_str());
239+
}
240+
}
241+
242+
// -- 2. rename 'outFn' to 'cfn'
243+
if (not error1) {
244+
filesystem::path oldPath{outFn};
245+
filesystem::path newPath{cfn};
246+
error_code ec;
247+
filesystem::rename(oldPath, newPath, ec);
248+
if (ec) {
249+
error2 = true;
250+
lout() << endl
251+
<< "BLIF-CLEANER: [Error] renaming temporary BLIF to "
252+
<< newPath << endl
253+
<< " ERROR: " << ec.message() << '\n' << endl;
254+
}
255+
else if (tr >= 3) {
256+
string newName = newPath.lexically_normal().string();
257+
lprintf("[PLANNER BLIF-CLEANER] : corrected BLIF written : %s\n",
258+
newName.c_str());
259+
}
260+
}
261+
262+
if (error1 or error2) {
263+
status = false;
264+
lputs("[PLANNER BLIF-CLEANER] : FAILED due to filesystem errors\n");
265+
}
266+
}
200267
}
201268

202269
return status;
@@ -270,7 +337,8 @@ bool do_check(const rsOpts& opts, bool blif_vs_csv) {
270337
if (blif_vs_csv) {
271338
vector<string> badInp, badOut;
272339
vector<uspair> corrected;
273-
status = do_check_blif(cfn, badInp, badOut, corrected, false);
340+
string outFn;
341+
status = do_check_blif(cfn, badInp, badOut, corrected, outFn, false);
274342
} else {
275343
status = do_check_csv(cfn);
276344
}

planning/src/RS/rsCheck.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ bool do_check_blif(
1515
std::vector<std::string>& badOutputs,
1616
std::vector<uspair>& corrected,
1717

18-
bool cleanup = false // cleanup => checker may modify the blif
18+
std::string& outFn, // if checker wrote blif, outFn is the file name
19+
20+
bool cleanup = false // cleanup => checker may modify the blif
1921

2022
);
2123

planning/src/RS/rsOpts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ static CStr _check_[] = { "CH", "CHECK", "ch", "CC", "cc", "che", "chec",
2828
"check", "check_blif", nullptr };
2929

3030
static CStr _clean_[] = { "CLEAN", "CLEANUP", "clean", "cleanup", "clean_up",
31-
"cleanup_blif", "cleanupblif", "clean_up_blif", nullptr };
31+
"cleanup_blif", "cleanupblif", "clean_up_blif",
32+
"cle", "clea", nullptr };
3233

3334
static CStr _csv_[] = {"CSV", "cs", "csv", "Csv", nullptr};
3435

planning/src/file_io/pln_blif_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ string BLIF_file::writeBlif(const string& toFn, bool cleanUp,
25402540
}
25412541
bool error = false;
25422542

2543-
::fprintf(f, "### written by PLN %s\n\n", pln_get_version());
2543+
::fprintf(f, "### written by PLANNER %s\n\n", pln_get_version());
25442544
if (::ferror(f)) {
25452545
if (trace_ >= 3) {
25462546
flush_out(true);

planning/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static const char* _pln_VERSION_STR = "pln0358";
1+
static const char* _pln_VERSION_STR = "pln0359";
22

33
#include "RS/rsEnv.h"
44
#include "util/pln_log.h"

planning/src/pin_loc/read_ports.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,11 +1119,13 @@ bool PinPlacer::BlifReader::read_blif(const string& blif_fn, bool& checked_ok) n
11191119

11201120
vector<string> badInputs, badOutputs;
11211121
vector<uspair> corrected;
1122+
string outFn;
11221123

11231124
if (not ::getenv("pinc_dont_check_blif")) {
11241125
lprintf("____ BEGIN pinc_check_blif: %s\n", cfn);
11251126
flush_out(true);
1126-
checked_ok = do_check_blif(cfn, badInputs, badOutputs, corrected, false);
1127+
checked_ok = do_check_blif(cfn, badInputs, badOutputs,
1128+
corrected, outFn, false);
11271129
flush_out(true);
11281130
lprintf(" pinc_check_blif STATUS = %s\n\n",
11291131
checked_ok ? "PASS" : "FAIL");

0 commit comments

Comments
 (0)