Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 78 additions & 10 deletions planning/src/RS/rsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ using std::string;
using std::endl;

// in 'cleanup' mode checker may modify the blif
// if checker wrote blif, 'outFn' is the file name
bool do_check_blif(CStr cfn,
vector<string>& badInputs,
vector<string>& badOutputs,
vector<uspair>& corrected,
string& outFn,
bool cleanup) {
assert(cfn);
uint16_t tr = ltrace();
auto& ls = lout();
badInputs.clear();
badOutputs.clear();
corrected.clear();
outFn.clear();
flush_out(false);

BLIF_file bfile(string{cfn});
Expand Down Expand Up @@ -127,13 +130,12 @@ bool do_check_blif(CStr cfn,
std::filesystem::path base_path = full_path.filename();
std::string base = base_path.string();
//lputs9();
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.
// write to a temporary and rename later.
outFn = str::concat(full_path.lexically_normal().string(),
"+BLIF_CLEANER.tmp_", std::to_string(get_PID()));
} else {
Expand All @@ -144,9 +146,9 @@ bool do_check_blif(CStr cfn,

if (wr_ok.empty()) {
lprintf("---!! FAILED writeBlif to '%s'\n", outFn.c_str());
if (cleanup) {
if (cleanup)
lprintf("[PLANNER BLIF-CLEANER] : FAILED\n");
}
outFn.clear();
} else {
lprintf("+++++ WRITTEN '%s'\n", wr_ok.c_str());
if (cleanup) {
Expand Down Expand Up @@ -180,23 +182,88 @@ bool do_check_blif(CStr cfn,

// 'corrected' : (lnum, removed_net)
bool do_cleanup_blif(CStr cfn, vector<uspair>& corrected) {
using namespace fio;
using namespace std;
assert(cfn);
corrected.clear();
uint16_t tr = ltrace();

vector<string> badInp, badOut;
bool status = do_check_blif(cfn, badInp, badOut, corrected, true);
string outFn;

bool status = do_check_blif(cfn, badInp, badOut, corrected, outFn, 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());
if (tr >= 3) {
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());
if (tr < 4 and i > 40 and cor_sz > 50) {
lputs(" ...");
break;
}
}
lprintf("-- removed dangling nets (%zu).\n", cor_sz);
}
lprintf("-- removed dangling nets (%zu).\n", cor_sz);
flush_out(true);

bool outFn_exists = Fio::nonEmptyFileExists(outFn);
bool cfn_exists = Fio::nonEmptyFileExists(cfn);
//assert(cfn_exists);
if (outFn_exists and cfn_exists) {

bool error1 = false, error2 = false;

// -- 1. add prefix 'orig_' to the original BLIF
{
string newName = str::concat("orig_", cfn);
filesystem::path newPath{newName};
filesystem::path oldPath{cfn};
error_code ec;
filesystem::rename(oldPath, newPath, ec);
if (ec) {
error1 = true;
lout() << endl
<< "BLIF-CLEANER: [Error] renaming original BLIF to "
<< newPath << endl
<< " ERROR: " << ec.message() << '\n' << endl;
}
else if (tr >= 3) {
lprintf("[PLANNER BLIF-CLEANER] : original BLIF saved as '%s'\n",
newName.c_str());
}
}

// -- 2. rename 'outFn' to 'cfn'
if (not error1) {
filesystem::path oldPath{outFn};
filesystem::path newPath{cfn};
error_code ec;
filesystem::rename(oldPath, newPath, ec);
if (ec) {
error2 = true;
lout() << endl
<< "BLIF-CLEANER: [Error] renaming temporary BLIF to "
<< newPath << endl
<< " ERROR: " << ec.message() << '\n' << endl;
}
else if (tr >= 3) {
string newName = newPath.lexically_normal().string();
lprintf("[PLANNER BLIF-CLEANER] : corrected BLIF written : %s\n",
newName.c_str());
}
}

if (error1 or error2) {
status = false;
lputs("[PLANNER BLIF-CLEANER] : FAILED due to filesystem errors\n");
}
}
}

return status;
Expand Down Expand Up @@ -270,7 +337,8 @@ bool do_check(const rsOpts& opts, bool blif_vs_csv) {
if (blif_vs_csv) {
vector<string> badInp, badOut;
vector<uspair> corrected;
status = do_check_blif(cfn, badInp, badOut, corrected, false);
string outFn;
status = do_check_blif(cfn, badInp, badOut, corrected, outFn, false);
} else {
status = do_check_csv(cfn);
}
Expand Down
4 changes: 3 additions & 1 deletion planning/src/RS/rsCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ bool do_check_blif(
std::vector<std::string>& badOutputs,
std::vector<uspair>& corrected,

bool cleanup = false // cleanup => checker may modify the blif
std::string& outFn, // if checker wrote blif, outFn is the file name

bool cleanup = false // cleanup => checker may modify the blif

);

Expand Down
3 changes: 2 additions & 1 deletion planning/src/RS/rsOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static CStr _check_[] = { "CH", "CHECK", "ch", "CC", "cc", "che", "chec",
"check", "check_blif", nullptr };

static CStr _clean_[] = { "CLEAN", "CLEANUP", "clean", "cleanup", "clean_up",
"cleanup_blif", "cleanupblif", "clean_up_blif", nullptr };
"cleanup_blif", "cleanupblif", "clean_up_blif",
"cle", "clea", nullptr };

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

Expand Down
2 changes: 1 addition & 1 deletion planning/src/file_io/pln_blif_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ string BLIF_file::writeBlif(const string& toFn, bool cleanUp,
}
bool error = false;

::fprintf(f, "### written by PLN %s\n\n", pln_get_version());
::fprintf(f, "### written by PLANNER %s\n\n", pln_get_version());
if (::ferror(f)) {
if (trace_ >= 3) {
flush_out(true);
Expand Down
2 changes: 1 addition & 1 deletion planning/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const char* _pln_VERSION_STR = "pln0358";
static const char* _pln_VERSION_STR = "pln0359";

#include "RS/rsEnv.h"
#include "util/pln_log.h"
Expand Down
4 changes: 3 additions & 1 deletion planning/src/pin_loc/read_ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,13 @@ bool PinPlacer::BlifReader::read_blif(const string& blif_fn, bool& checked_ok) n

vector<string> badInputs, badOutputs;
vector<uspair> corrected;
string outFn;

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, corrected, false);
checked_ok = do_check_blif(cfn, badInputs, badOutputs,
corrected, outFn, false);
flush_out(true);
lprintf(" pinc_check_blif STATUS = %s\n\n",
checked_ok ? "PASS" : "FAIL");
Expand Down
Loading