Skip to content

Commit e94fc54

Browse files
authored
Merge pull request #899 from os-fpga/checker_add_writeBlif_method
checker: add writeBlif() method
2 parents c95c3e2 + 9efbadd commit e94fc54

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

planning/src/RS/rsCheck.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool do_check_blif(CStr cfn,
6666
bool chk_ok = bfile.checkBlif(badInputs, badOutputs);
6767
assert(chk_ok == bfile.chk_ok_);
6868

69-
lprintf("===== passed: %s\n", chk_ok ? "YES" : "NO");
69+
lprintf("===== passed: %s\n", chk_ok ? "YES" : "NO");
7070

7171
ls << "----- topModel: " << bfile.topModel_ << endl;
7272
ls << "----- file: " << bfile.fnm_ << endl;
@@ -116,8 +116,16 @@ bool do_check_blif(CStr cfn,
116116
if (numWarn)
117117
lprintf(" # WARNINGS= %u", numWarn);
118118
lputs();
119+
if (::getenv("pln_always_write_blif")) {
120+
string outFn = str::concat("PLN_", cfn);
121+
string wr_ok = bfile.writeBlif(outFn, false);
122+
if (wr_ok.empty())
123+
lprintf("---!! FAILED writeBlif to '%s'\n", outFn.c_str());
124+
else
125+
lprintf("+++++ WRITTEN '%s'\n", wr_ok.c_str());
126+
}
119127
}
120-
lprintf("===== passed: %s\n", chk_ok ? "YES" : "NO");
128+
lprintf("===== passed: %s\n", chk_ok ? "YES" : "NO");
121129

122130
flush_out(true);
123131
if (chk_ok) {

planning/src/file_io/pln_Fio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ int64_t MMapReader::writeFile(const string& nm) noexcept {
703703
if (nm == fnm_)
704704
return -1;
705705

706-
auto tr = trace();
706+
uint16_t tr = trace();
707707
CStr cnm = nm.c_str();
708708
FILE* f = ::fopen(cnm, "w");
709709
if (!f) {

planning/src/file_io/pln_blif_file.cpp

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,9 +1747,8 @@ bool BLIF_file::linkNodes() noexcept {
17471747
if (!par) {
17481748
if (nd.is_RAM() or nd.is_DSP()) {
17491749
const string& net = nd.out_;
1750-
bool is_ram = nd.is_RAM();
17511750
uint rid = nd.realId(*this);
1752-
const BNode& realNd = bnodeRef(rid);
1751+
BNode& realNd = bnodeRef(rid);
17531752
const vector<string>& realData = realNd.realData_;
17541753
assert(not realData.empty());
17551754
int dataTerm = findTermByNet(realData, net);
@@ -1760,12 +1759,13 @@ bool BLIF_file::linkNodes() noexcept {
17601759
// RAM or DSP output bits may be unused
17611760
if (trace_ >= 4) {
17621761
lprintf("skipping dangling cell output issue for %s at line %u\n",
1763-
is_ram ? "RAM" : "DSP", realNd.lnum_);
1762+
realNd.cPrimType(), realNd.lnum_);
17641763
lprintf(" dangling net: %s term# %i %s\n",
17651764
net.c_str(), dataTerm, realData[dataTerm].c_str());
17661765
lputs();
17671766
}
1768-
if (is_ram)
1767+
realNd.dangTerms_.push_back(dataTerm);
1768+
if (nd.is_RAM())
17691769
dang_RAM_outputs_.emplace_back(realNd.id_, dataTerm);
17701770
else
17711771
dang_DSP_outputs_.emplace_back(realNd.id_, dataTerm);
@@ -2482,5 +2482,54 @@ string BLIF_file::writePinGraph(CStr fn0) const noexcept {
24822482
return {};
24832483
}
24842484

2485+
string BLIF_file::writeBlif(const string& toFn, bool cleanUp) noexcept {
2486+
if (toFn.empty())
2487+
return {};
2488+
if (!fsz_ || !sz_ || !buf_ || fnm_.empty())
2489+
return {};
2490+
if (not hasLines())
2491+
return {};
2492+
2493+
string fn2 = (toFn == fnm_ ? str::concat("2_", toFn) : toFn);
2494+
2495+
CStr cnm = fn2.c_str();
2496+
FILE* f = ::fopen(cnm, "w");
2497+
if (!f) {
2498+
if (trace_ >= 3) {
2499+
flush_out(true);
2500+
lprintf("ERROR writeBlif() could not open file for writing: %s\n", cnm);
2501+
flush_out(true);
2502+
}
2503+
return {};
2504+
}
2505+
2506+
size_t cnt = 0, n = lines_.size();
2507+
for (size_t i = 0; i < n; i++) {
2508+
CStr cs = lines_[i];
2509+
if (!cs || !cs[0]) continue;
2510+
::fputs(cs, f);
2511+
::fputc('\n', f);
2512+
if (::ferror(f)) {
2513+
if (trace_ >= 3) {
2514+
flush_out(true);
2515+
lprintf("ERROR writeBlif() error during writing: %s\n", cnm);
2516+
flush_out(true);
2517+
}
2518+
break;
2519+
}
2520+
cnt++;
2521+
}
2522+
2523+
::fclose(f);
2524+
2525+
if (trace_ >= 4) {
2526+
flush_out(trace_ >= 5);
2527+
lprintf(" writeBlif OK written #lines= %zu\n", cnt);
2528+
}
2529+
flush_out(trace_ >= 5);
2530+
2531+
return fn2;
2532+
}
2533+
24852534
}
24862535

planning/src/file_io/pln_blif_file.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct BLIF_file : public fio::MMapReader
3535

3636
vector<string> data_; // like realData_, but has only 1 output term (virtual SOG)
3737

38+
vector<uint> dangTerms_; // realData_ indexes of dangling bits
39+
3840
vector<string> inPins_; // input pins from Prim-DB
3941
vector<string> inSigs_; // input signals from blif-file
4042

@@ -270,6 +272,9 @@ struct BLIF_file : public fio::MMapReader
270272
virtual void reset(CStr nm, uint16_t tr = 0) noexcept override;
271273

272274
bool readBlif() noexcept;
275+
276+
string writeBlif(const string& toFn, bool cleanUp) noexcept;
277+
273278
bool checkBlif(vector<string>& badInputs, vector<string>& badOutputs) noexcept;
274279

275280
uint numInputs() const noexcept { return inputs_.size(); }

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 = "pln0353";
1+
static const char* _pln_VERSION_STR = "pln0354";
22

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

0 commit comments

Comments
 (0)