Skip to content

Commit dc8ba67

Browse files
committed
checker: developing pinGraph, parse blif signals completely
1 parent 516c765 commit dc8ba67

File tree

5 files changed

+139
-36
lines changed

5 files changed

+139
-36
lines changed

planning/src/file_readers/pln_blif_file.cpp

Lines changed: 105 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ bool BLIF_file::checkBlif() noexcept {
373373
flush_out(true);
374374
}
375375
}
376-
if (trace_ >= 6) {
376+
if (trace_ >= 7) {
377377
printCarryNodes(ls);
378378
flush_out(true);
379379
}
@@ -503,6 +503,10 @@ uint BLIF_file::printNodes(std::ostream& os) const noexcept {
503503
const Node& nd = nodePool_[i];
504504
CStr pts = nd.cPrimType();
505505
assert(pts);
506+
507+
if (trace_ >= 5)
508+
lputs();
509+
506510
os_printf(os,
507511
" |%u| L:%u %s ptype:%s inDeg=%u outDeg=%u par=%u out:%s mog:%i/%i ",
508512
i, nd.lnum_, nd.kw_.c_str(), pts,
@@ -515,6 +519,18 @@ uint BLIF_file::printNodes(std::ostream& os) const noexcept {
515519
size_t sz = nd.data_.size();
516520
prnArray(os, A, sz, " ");
517521
}
522+
523+
if (trace_ >= 5) {
524+
const string* A = nd.inPins_.data();
525+
size_t sz = nd.inPins_.size();
526+
os_printf(os, " ##inPins=%zu ", sz);
527+
prnArray(os, A, sz, " ");
528+
//
529+
A = nd.inSigs_.data();
530+
sz = nd.inSigs_.size();
531+
os_printf(os, " ##inSigs=%zu ", sz);
532+
prnArray(os, A, sz, " ");
533+
}
518534
}
519535

520536
os << endl;
@@ -1002,7 +1018,7 @@ bool BLIF_file::createNodes() noexcept {
10021018
if (nd.data_.size() > 1) {
10031019
const string& last = nd.data_.back();
10041020
size_t llen = last.length();
1005-
if (!last.empty() && llen < 2047) {
1021+
if (!last.empty() and llen < 2047) {
10061022
// replace '=' by 'space' and tokenize:
10071023
::strcpy(buf, last.c_str());
10081024
for (uint k = 0; k < llen; k++) {
@@ -1011,6 +1027,37 @@ bool BLIF_file::createNodes() noexcept {
10111027
Fio::split_spa(buf, V);
10121028
if (not V.empty()) nd.out_ = V.back();
10131029
}
1030+
// lputs9();
1031+
// fill inPins_, inSigs_:
1032+
nd.inPins_.clear();
1033+
nd.inSigs_.clear();
1034+
const string* DA = nd.data_.data();
1035+
size_t DA_sz = nd.data_.size();
1036+
if (DA_sz > 2 and nd.kw_ == ".subckt") {
1037+
// skip 1st (type) and last (output) terms in data_
1038+
nd.inSigs_.reserve(DA_sz - 1);
1039+
for (uint di = 1; di < DA_sz - 1; di++) {
1040+
nd.inSigs_.push_back(DA[di]);
1041+
}
1042+
}
1043+
if (not nd.inSigs_.empty()) {
1044+
std::sort(nd.inSigs_.begin(), nd.inSigs_.end());
1045+
pr_get_inputs(nd.ptype_, nd.inPins_);
1046+
assert(nd.inPins_.size() == nd.inSigs_.size());
1047+
std::sort(nd.inPins_.begin(), nd.inPins_.end());
1048+
// strip everything before '=' in inSigs_, e.g. A[1]=sig_a --> sig_a
1049+
for (string& ss : nd.inSigs_) {
1050+
assert(!ss.empty());
1051+
V.clear();
1052+
::strcpy(buf, ss.c_str());
1053+
size_t len = ss.length();
1054+
for (uint k = 0; k < len; k++) {
1055+
if (buf[k] == '=') buf[k] = ' ';
1056+
}
1057+
Fio::split_spa(buf, V);
1058+
if (not V.empty()) ss = V.back();
1059+
}
1060+
}
10141061
}
10151062
fabricNodes_.push_back(&nd);
10161063
continue;
@@ -1149,8 +1196,8 @@ BLIF_file::Node* BLIF_file::findInputPort(const string& contact) noexcept {
11491196
}
11501197

11511198
// searches inputs
1152-
BLIF_file::Node* BLIF_file::findFabricParent(uint of, const string& contact, int& pinIndex) noexcept {
1153-
pinIndex = -1;
1199+
BLIF_file::Node* BLIF_file::findFabricParent(uint of, const string& contact, int& pin) noexcept {
1200+
pin = -1;
11541201
assert(not contact.empty());
11551202
if (fabricNodes_.empty()) return nullptr;
11561203

@@ -1159,13 +1206,33 @@ BLIF_file::Node* BLIF_file::findFabricParent(uint of, const string& contact, int
11591206
if (x->id_ == of) continue;
11601207
int pinIdx = x->in_contact(contact);
11611208
if (pinIdx >= 0) {
1162-
pinIndex = pinIdx;
1209+
pin = pinIdx;
11631210
return x;
11641211
}
11651212
}
11661213
return nullptr;
11671214
}
11681215

1216+
void BLIF_file::getFabricParents(uint of, const string& contact, vector<upair>& PAR) noexcept {
1217+
assert(not contact.empty());
1218+
if (fabricNodes_.empty()) return;
1219+
1220+
// TMP linear
1221+
for (const Node* x : fabricNodes_) {
1222+
if (x->id_ == of) continue;
1223+
const Node& nx = *x;
1224+
if (nx.inSigs_.empty())
1225+
continue;
1226+
size_t in_sz = nx.inSigs_.size();
1227+
assert(nx.inPins_.size() == in_sz);
1228+
for (uint k = 0; k < in_sz; k++) {
1229+
if (nx.inSigs_[k] == contact) {
1230+
PAR.emplace_back(nx.id_, k);
1231+
}
1232+
}
1233+
}
1234+
}
1235+
11691236
// matches out_
11701237
BLIF_file::Node* BLIF_file::findFabricDriver(uint of, const string& contact) noexcept {
11711238
assert(not contact.empty());
@@ -1420,6 +1487,7 @@ bool BLIF_file::createPinGraph() noexcept {
14201487
uint64_t key = 0;
14211488
uint nid = 0, kid = 0, eid = 0;
14221489
vector<string> INP;
1490+
vector<upair> PAR;
14231491

14241492
// -- create pg-nodes for topInputs_
14251493
for (const Node* p : topInputs_) {
@@ -1440,51 +1508,60 @@ bool BLIF_file::createPinGraph() noexcept {
14401508
}
14411509

14421510
// -- link from input ports to fabric
1443-
lputs9();
1511+
// lputs9();
14441512
for (Node* p : topInputs_) {
14451513
INP.clear();
14461514
Node& port = *p;
14471515
assert(!port.out_.empty());
14481516

1517+
PAR.clear();
1518+
getFabricParents(port.id_, port.out_, PAR);
1519+
14491520
if (trace_ >= 5) {
1450-
lprintf(" TopInput: lnum_= %u %s\n",
1451-
port.lnum_, port.out_.c_str());
1521+
lputs();
1522+
lprintf(" TopInput: lnum_= %u %s PAR.size()= %zu\n",
1523+
port.lnum_, port.out_.c_str(), PAR.size());
14521524
}
14531525

1454-
int pinIndex = -1;
1455-
Node* par = findFabricParent(port.id_, port.out_, pinIndex);
1456-
if (!par) {
1457-
continue;
1458-
}
1526+
for (const upair& pa : PAR) {
1527+
const Node& par = nodeRef(pa.first);
1528+
uint pinIndex = pa.second;
14591529

1460-
pr_get_inputs(par->ptype_, INP);
1530+
INP.clear();
1531+
pr_get_inputs(par.ptype_, INP);
14611532

1462-
if (trace_ >= 5) {
1463-
lprintf(" FabricParent par: lnum_= %u kw_= %s ptype_= %s #inputs= %u\n",
1464-
par->lnum_, par->kw_.c_str(), par->cPrimType(),
1465-
pr_num_inputs(par->ptype_));
1466-
logVec(INP, " [par_inputs] ");
1467-
lputs();
1468-
}
1533+
if (trace_ >= 5) {
1534+
lprintf(" FabricParent par: lnum_= %u kw_= %s ptype_= %s #inputs= %u\n",
1535+
par.lnum_, par.kw_.c_str(), par.cPrimType(),
1536+
pr_num_inputs(par.ptype_));
1537+
logVec(INP, " [par_inputs] ");
1538+
lputs();
1539+
}
14691540

1470-
assert(par->cell_hc_);
1471-
key = hashComb(par->cell_hc_, pinIndex);
1472-
assert(key);
1473-
kid = pg_.insK(key);
1474-
assert(kid);
1541+
assert(par.cell_hc_);
1542+
key = hashComb(par.cell_hc_, pinIndex);
1543+
assert(key);
1544+
kid = pg_.insK(key);
1545+
assert(kid);
14751546

1476-
eid = pg_.linK(port.id_, kid);
1477-
assert(eid);
1547+
eid = pg_.linK(port.id_, kid);
1548+
assert(eid);
1549+
}
14781550
}
14791551

14801552
if (1) {
14811553

1554+
pg_.setNwName("pin_graph");
14821555
pg_.dump("\t *** pg_ separ ***");
14831556
lprintf("\t pg_. numN()= %u numE()= %u\n", pg_.numN(), pg_.numE());
14841557
lputs();
14851558
pg_.printSum(ls, 0);
14861559
lputs();
14871560
pg_.dumpEdges("|edges|");
1561+
lputs();
1562+
1563+
bool wrDot_ok = pg_.writeDot("pinGraph.dot", nullptr, true);
1564+
lprintf("wrDot_ok:%i\n", wrDot_ok);
14881565

14891566
}
14901567

planning/src/file_readers/pln_blif_file.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ struct BLIF_file : public fio::MMapReader
2727
string kw_; // keyword: .names, .latch, .subckt, .gate, etc.
2828
vector<string> data_; // everything on the line ater kw, tokenized
2929

30+
vector<string> inPins_; // input pins from Prim-DB
31+
vector<string> inSigs_; // input signals from blif-file
32+
3033
string out_; // SOG output (real or virtual)
3134

3235
uint virtualOrigin_ = 0; // node-ID from which this virtual MOG is created
@@ -231,6 +234,10 @@ struct BLIF_file : public fio::MMapReader
231234
Node* findFabricParent(uint of, const string& contact, int& pinIndex) noexcept; // searches inputs
232235
Node* findFabricDriver(uint of, const string& contact) noexcept; // matches out_
233236

237+
// collects matching input pins from all cells
238+
// pair: 1st - nodeId, 2nd - pinIndex
239+
void getFabricParents(uint of, const string& contact, vector<upair>& PAR) noexcept;
240+
234241
std::vector<Node> nodePool_; // nodePool_[0] is a fake node "parent of root"
235242

236243
std::vector<Node*> topInputs_, topOutputs_;

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

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

planning/src/util/nw/Nw.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ uint NW::printEdges(ostream& os, CStr msg) const noexcept {
365365
if (msg) os << msg << endl;
366366

367367
uint esz = numE();
368-
os_printf(os, " esz= %u\n", esz);
368+
os_printf(os, " nw:%s esz= %u\n", nw_name_.c_str(), esz);
369369
if (esz) {
370370
for (cEI I(*this); I.valid(); ++I) {
371371
I->print(os);
@@ -379,9 +379,10 @@ uint NW::dumpEdges(CStr msg) const noexcept { return printEdges(lout(), msg); }
379379
uint NW::printSum(ostream& os, uint16_t forDot) const noexcept {
380380
dot_comment(os, forDot);
381381
if (empty()) {
382-
os_printf(os, "(empty NW)\n)");
382+
os_printf(os, " nw:%s (empty NW)\n)", nw_name_.c_str());
383383
return 0;
384384
}
385+
os_printf(os, "nw:%s\n", nw_name_.c_str());
385386

386387
upair mmD = getMinMaxDeg();
387388
upair mmL = getMinMaxLbl();
@@ -448,7 +449,12 @@ uint NW::printDot(ostream& os, CStr nwNm, bool nodeTable) const noexcept {
448449
printNodes(os, nullptr, 1);
449450
os_printf(os, "%s====\n", s_dotComment);
450451
}
451-
os_printf(os, "digraph %s {\n", nwNm ? nwNm : "G");
452+
453+
if (!nwNm or !nwNm[0]) {
454+
if (not nw_name_.empty())
455+
nwNm = nw_name_.c_str();
456+
}
457+
os_printf(os, "digraph %s {\n", (nwNm and nwNm[0]) ? nwNm : "G");
452458

453459
// os << " node [rankdir=LR];\n";
454460
os << " node [shape = circle];\n";

planning/src/util/nw/Nw.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using vecu = std::vector<uint>;
2525
using ipair = std::pair<int, int>;
2626
using upair = std::pair<uint, uint>;
2727
using std::ostream;
28+
using std::string;
2829

2930
struct NW {
3031
struct Node;
@@ -76,9 +77,9 @@ struct NW {
7677
key_ = 0;
7778
}
7879

79-
std::string getName() const noexcept {
80+
string getName() const noexcept {
8081
if (name_.empty()) {
81-
std::string nm{"nd_"};
82+
string nm{"nd_"};
8283
nm += std::to_string(id_);
8384
return nm;
8485
}
@@ -143,7 +144,7 @@ struct NW {
143144
// DATA:
144145
bool root_flag_ = false;
145146
bool sink_flag_ = false;
146-
std::string name_;
147+
string name_;
147148
};
148149

149150
struct cNI {
@@ -286,11 +287,22 @@ struct NW {
286287
else
287288
nodeRefCk(id).name_.clear();
288289
}
289-
void setNodeName(uint id, const std::string& nm) noexcept {
290+
void setNodeName(uint id, const string& nm) noexcept {
290291
assert(hasNode(id));
291292
nodeRefCk(id).name_ = nm;
292293
}
293294

295+
void setNwName(CStr nm) noexcept {
296+
if (nm and nm[0])
297+
nw_name_ = nm;
298+
else
299+
nw_name_.clear();
300+
}
301+
void setNwName(const string& nm) noexcept {
302+
nw_name_ = nm;
303+
}
304+
const string& name() const noexcept { return nw_name_; }
305+
294306
Edge& edgeRef(uint i) noexcept {
295307
assert(i and i < edStor_.size());
296308
return edStor_[i];
@@ -497,6 +509,7 @@ struct NW {
497509
NodeStor ndStor_;
498510
EdgeStor edStor_;
499511

512+
string nw_name_;
500513
uint16_t trace_ = 0;
501514
};
502515

0 commit comments

Comments
 (0)