Skip to content

Commit 24ff41b

Browse files
authored
Merge pull request #765 from os-fpga/pinc_new_blif_reader
pin_c: new blif reader based on pln::BLIF_file
2 parents 9591c54 + d060ed6 commit 24ff41b

File tree

7 files changed

+99
-32
lines changed

7 files changed

+99
-32
lines changed

planning/src/file_readers/blif_reader.cpp

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
#include "read_blif.h"
2-
#include "vtr_path.h"
3-
4-
#include "blifparse.hpp"
5-
61
#include "file_readers/blif_reader.h"
7-
#include "file_readers/pln_Fio.h"
2+
#include "file_readers/pln_blif_file.h"
83

94
namespace pln {
105

@@ -13,7 +8,78 @@ using std::string;
138
using std::cerr;
149
using std::endl;
1510

16-
// blif parser callback
11+
bool BlifReader::read_blif(const string& blif_fn) {
12+
using namespace fio;
13+
flush_out(true);
14+
inputs_.clear();
15+
outputs_.clear();
16+
17+
CStr cfn = blif_fn.c_str();
18+
uint16_t tr = ltrace();
19+
auto& ls = lout();
20+
21+
BLIF_file bfile(blif_fn);
22+
23+
if (tr >= 4)
24+
bfile.setTrace(3);
25+
26+
bool exi = false;
27+
exi = bfile.fileExists();
28+
if (tr >= 8)
29+
ls << int(exi) << endl;
30+
if (not exi) {
31+
flush_out(true); err_puts();
32+
lprintf2("[Error] BLIF file '%s' does not exist\n", cfn);
33+
err_puts(); flush_out(true);
34+
return false;
35+
}
36+
37+
exi = bfile.fileAccessible();
38+
if (tr >= 8)
39+
ls << int(exi) << endl;
40+
if (not exi) {
41+
flush_out(true); err_puts();
42+
lprintf2("[Error] BLIF file '%s' is not accessible\n", cfn);
43+
err_puts(); flush_out(true);
44+
return false;
45+
}
46+
47+
bool rd_ok = bfile.readBlif();
48+
if (tr >= 8)
49+
ls << int(rd_ok) << endl;
50+
if (not rd_ok) {
51+
flush_out(true); err_puts();
52+
lprintf2("[Error] failed reading BLIF file '%s'\n", cfn);
53+
err_puts(); flush_out(true);
54+
return false;
55+
}
56+
57+
lprintf(" (blif_file) #inputs= %u #outputs= %u topModel= %s\n",
58+
bfile.numInputs(), bfile.numOutputs(), bfile.topModel_.c_str());
59+
60+
if (tr >= 5) {
61+
flush_out(true);
62+
bfile.printInputs(ls);
63+
flush_out(true);
64+
bfile.printOutputs(ls);
65+
}
66+
67+
std::swap(inputs_, bfile.inputs_);
68+
std::swap(outputs_, bfile.outputs_);
69+
if (tr >= 3) {
70+
flush_out(true);
71+
lprintf("pin_c: finished read_blif(). #inputs= %zu #outputs= %zu\n",
72+
inputs_.size(), outputs_.size());
73+
}
74+
75+
flush_out(true);
76+
77+
return true;
78+
}
79+
80+
// ========================= OLD ONE:
81+
#ifdef _PLN_OLD_BLIF_READER_MODE
82+
1783
using namespace blifparse;
1884

1985
struct PlnBlifParserCB : public blifparse::Callback {
@@ -136,4 +202,7 @@ bool BlifReader::read_blif(const string& blif_fn) {
136202
return true;
137203
}
138204

139-
} // namespace pln
205+
#endif // _PLN_OLD_BLIF_READER_MODE
206+
207+
}
208+

planning/src/file_readers/blif_reader.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ namespace pln {
99
using std::string;
1010
using std::vector;
1111

12-
/*
13-
Supported PCF commands:
14-
15-
* set_io <net> <pad> - constrain a given <net> to a given physical <pad> in eFPGA pinout.
16-
* set_clk <pin> <net> - constrain a given global clock <pin> to a given <net>
17-
18-
Every tile where <net> is present will be constrained to use a given global clock.
19-
*/
20-
2112
class BlifReader {
2213
vector<string> inputs_;
2314
vector<string> outputs_;

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

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

planning/src/pin_loc/pcf_place.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,10 @@ void PinPlacer::print_summary(const string& csv_name) const {
316316
const vector<Pin>& inputs = user_design_inputs_;
317317
const vector<Pin>& outputs = user_design_outputs_;
318318

319-
flush_out((tr >= 7));
320-
321-
ls << "======== pin_c summary:" << endl;
322-
323-
ls << " Pin Table csv : " << csv_name << endl;
319+
flush_out((tr >= 5));
320+
lputs("======== pin_c summary:");
321+
lprintf(" Pin Table csv : %s\n", csv_name.c_str());
322+
lprintf(" BLIF file : %s\n", blif_fn_.c_str());
324323

325324
if (num_warnings_) {
326325
lprintf("\t pin_c: NOTE ERRORs: %u\n", num_warnings_);

planning/src/pin_loc/pin_placer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ void PinPlacer::resetState() noexcept {
165165
num_warnings_ = 0;
166166
num_critical_warnings_ = 0;
167167
user_pcf_.clear();
168+
blif_fn_.clear();
168169
has_edits_.clear();
169170
clk_map_file_.clear();
170171
clear_err_code();

planning/src/pin_loc/pin_placer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct PinPlacer {
124124

125125
bool auto_pcf_created_ = false;
126126
string user_pcf_;
127+
string blif_fn_;
127128
string has_edits_;
128129
string clk_map_file_;
129130

planning/src/pin_loc/read_ports.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bool PinPlacer::read_design_ports() {
5151
flush_out(true);
5252
}
5353

54+
blif_fn_.clear();
5455
user_design_inputs_.clear();
5556
user_design_outputs_.clear();
5657

@@ -91,24 +92,24 @@ bool PinPlacer::read_design_ports() {
9192
}
9293
json_ifs.close();
9394
} else {
94-
string blif_fn = cl_.get_param("--blif");
95-
if (tr >= 2) lprintf("... reading %s\n", blif_fn.c_str());
96-
str_path = blif_fn;
95+
blif_fn_ = cl_.get_param("--blif");
96+
if (tr >= 2) lprintf("... reading %s\n", blif_fn_.c_str());
97+
str_path = blif_fn_;
9798
if (not Fio::regularFileExists(str_path)) {
9899
lprintf("\npin_c WARNING: blif file %s does not exist\n", str_path.c_str());
99100
std::filesystem::path fs_path{str_path}, eblif_ext{"eblif"};
100101
fs_path.replace_extension(eblif_ext);
101102
string eblif_fn = fs_path.string();
102103
if (Fio::regularFileExists(fs_path)) {
103-
blif_fn = eblif_fn;
104-
str_path = blif_fn;
104+
blif_fn_ = eblif_fn;
105+
str_path = blif_fn_;
105106
lprintf("\npin_c INFO: using eblif file %s\n", eblif_fn.c_str());
106107
} else {
107108
lprintf("pin_c WARNING: eblif file %s does not exist\n", eblif_fn.c_str());
108109
}
109110
}
110111
BlifReader rd_blif;
111-
if (!rd_blif.read_blif(blif_fn)) {
112+
if (!rd_blif.read_blif(blif_fn_)) {
112113
flush_out(true);
113114
err_puts();
114115
CERROR << err_lookup("PORT_INFO_PARSE_ERROR") << endl;
@@ -129,7 +130,7 @@ bool PinPlacer::read_design_ports() {
129130
return false;
130131
}
131132

132-
is_fabric_eblif_ = s_is_fabric_eblif(blif_fn);
133+
is_fabric_eblif_ = s_is_fabric_eblif(blif_fn_);
133134
}
134135

135136
size_t sz = raw_design_inputs_.size();
@@ -638,12 +639,17 @@ void PinPlacer::dump_edits(const string& memo) noexcept {
638639

639640
if (tr >= 5) {
640641
vector<uint> undefs;
642+
char nmA[128 + 2] = {};
641643
lprintf(" ==== [%s] ==== dumping all_edits ====\n", memo.c_str());
642644
for (uint i = 0; i < esz; i++) {
643645
const EditItem& ed = all_edits_[i];
646+
if (ed.name_.length() <= 20)
647+
::sprintf(nmA, "%s", ed.name_.c_str());
648+
else
649+
::sprintf(nmA, "%zu", ed.nameHash());
644650
lprintf(
645-
" |%u| %zu module: %s js_dir:%s dir:%i old: %s new: %s",
646-
i+1, ed.nameHash(), ed.c_mod(), ed.c_jsdir(), ed.dir_, ed.c_old(), ed.c_new());
651+
" |%u| %s mod: %s jsd:%s dir:%i old: %s n: %s",
652+
i+1, nmA, ed.c_mod(), ed.c_jsdir(), ed.dir_, ed.c_old(), ed.c_new());
647653
if (ed.isQBus())
648654
lprintf(" QBUS-%u", ed.qbusSize());
649655
lputs();

0 commit comments

Comments
 (0)