Skip to content

Commit eeadae4

Browse files
authored
Merge pull request #706 from os-fpga/checker_pin_dir_development
blif_checker: pin direction related development
2 parents 9eac0a1 + 019c5d7 commit eeadae4

File tree

5 files changed

+85
-13
lines changed

5 files changed

+85
-13
lines changed

stars/src/file_readers/pln_blif_file.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,11 @@ uint BLIF_file::printNodes(std::ostream& os) const noexcept {
409409
os << "--- nodes (" << n << ") :" << endl;
410410
for (uint i = 1; i <= n; i++) {
411411
const Node& nd = nodePool_[i];
412+
CStr pts = nd.cPrimType();
413+
assert(pts);
412414
os_printf(os,
413-
" |%u| L:%u %s inDeg=%u outDeg=%u par=%u out:%s mog:%i/%i ",
414-
i, nd.lnum_, nd.kw_.c_str(),
415+
" |%u| L:%u %s ptype:%s inDeg=%u outDeg=%u par=%u out:%s mog:%i/%i ",
416+
i, nd.lnum_, nd.kw_.c_str(), pts,
415417
nd.inDeg(), nd.outDeg(), nd.parent_,
416418
nd.cOut(), nd.isMog(), nd.isVirtualMog());
417419
if (nd.data_.empty()) {
@@ -550,6 +552,7 @@ bool BLIF_file::createNodes() noexcept {
550552
nodePool_.emplace_back(".subckt", L);
551553
Node& nd = nodePool_.back();
552554
nd.data_.assign(V.begin() + 1, V.end());
555+
nd.ptype_ = primt_id(nd.data_front());
553556
place_output_at_back(nd.data_);
554557
}
555558
continue;
@@ -562,6 +565,7 @@ bool BLIF_file::createNodes() noexcept {
562565
nodePool_.emplace_back(".gate", L);
563566
Node& nd = nodePool_.back();
564567
nd.data_.assign(V.begin() + 1, V.end());
568+
nd.ptype_ = primt_id(nd.data_front());
565569
place_output_at_back(nd.data_);
566570
}
567571
continue;
@@ -598,7 +602,7 @@ bool BLIF_file::createNodes() noexcept {
598602
bool is_mog = V.size() > 1;
599603
if (is_mog) {
600604
if (trace_ >= 5) {
601-
lprintf("\t\t .... MOG-type: %s\n", nd.cType());
605+
lprintf("\t\t .... MOG-type: %s\n", nd.cPrimType());
602606
lprintf("\t\t .... [terms] V.size()= %zu\n", V.size());
603607
logVec(V, " [V-terms] ");
604608
lputs();

stars/src/file_readers/pln_blif_file.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,32 @@ struct BLIF_file : public fio::MMapReader
6666
// returns pin index in chld_ or -1
6767
int in_contact(const string& x) const noexcept;
6868

69-
bool is_IBUF() const noexcept {
69+
CStr data_front() const noexcept {
70+
return data_.size() > 1 ? data_.front().c_str() : nullptr;
71+
}
72+
73+
bool is_str_IBUF() const noexcept {
7074
return data_.size() > 1 and data_.front() == "I_BUF";
7175
}
72-
bool is_OBUF() const noexcept {
76+
bool is_str_OBUF() const noexcept {
7377
return data_.size() > 1 and data_.front() == "O_BUF";
7478
}
7579

80+
bool is_IBUF() const noexcept {
81+
return ptype_ == I_BUF or ptype_ == I_BUF_DS;
82+
}
83+
bool is_OBUF() const noexcept {
84+
return ptype_ == O_BUF or ptype_ == O_BUF_DS or
85+
ptype_ == O_BUFT or ptype_ == O_BUFT_DS;
86+
}
87+
7688
string firstInputPin() const noexcept;
7789

7890
CStr cOut() const noexcept { return out_.empty() ? "{e}" : out_.c_str(); }
7991

80-
CStr cType() const noexcept { return data_.empty() ? "{e}" : data_.front().c_str(); }
92+
// CStr cType() const noexcept { return data_.empty() ? "{e}" : data_.front().c_str(); }
8193

82-
// cPrimType() will replace cType()
83-
CStr cPrimType() const noexcept { return primt_name(ptype_); }
94+
CStr cPrimType() const noexcept { return ptype_ == A_ZERO ? "{e}" : primt_name(ptype_); }
8495

8596
struct CmpOut {
8697
bool operator()(const Node* a, const Node* b) const noexcept {

stars/src/file_readers/pln_primitives.cpp

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace pln {
44

5-
6-
CStr primt_name(Prim_t enu) noexcept {
5+
namespace {
76
// enumNames are sorted and Prim_t is sorted, it ensures
87
// correct ID -> name mapping. Always keep them in sorted order.
98
static const char* enumNames[] = {
@@ -43,14 +42,67 @@ CStr primt_name(Prim_t enu) noexcept {
4342
"X_UNKNOWN",
4443
"Y_UPPER_GUARD"
4544
};
46-
static_assert(sizeof(enumNames) / sizeof(enumNames[0]) == Y_UPPER_GUARD + 1);
45+
}
4746

47+
CStr primt_name(Prim_t enu) noexcept {
48+
static_assert(sizeof(enumNames) / sizeof(enumNames[0]) == Y_UPPER_GUARD + 1);
4849
uint i = enu;
4950
assert(i <= Prim_MAX_ID);
50-
5151
return enumNames[i];
5252
}
5353

54+
// "A_"
55+
static inline bool starts_w_A(CStr z) noexcept {
56+
assert(z);
57+
if (::strnlen(z, 4) < 2)
58+
return false;
59+
return z[0] == 'A' and z[1] == '_';
60+
}
61+
62+
// "X_"
63+
static inline bool starts_w_X(CStr z) noexcept {
64+
assert(z);
65+
if (::strnlen(z, 4) < 2)
66+
return false;
67+
return z[0] == 'X' and z[1] == '_';
68+
}
69+
70+
// "Y_"
71+
static inline bool starts_w_Y(CStr z) noexcept {
72+
assert(z);
73+
if (::strnlen(z, 4) < 2)
74+
return false;
75+
return z[0] == 'Y' and z[1] == '_';
76+
}
77+
78+
static inline bool starts_w_CAR(CStr z) noexcept {
79+
assert(z);
80+
if (::strnlen(z, 8) < 4)
81+
return false;
82+
return z[0] == 'C' and z[1] == 'A' and z[2] == 'R';
83+
}
84+
85+
// string -> enum, returns A_ZERO on error
86+
Prim_t primt_id(CStr name) noexcept {
87+
if (!name or !name[0])
88+
return A_ZERO;
89+
if (starts_w_X(name))
90+
return X_UNKNOWN;
91+
if (starts_w_Y(name))
92+
return Y_UPPER_GUARD;
93+
if (starts_w_A(name))
94+
return A_ZERO;
95+
if (starts_w_CAR(name))
96+
return CARRY_CHAIN;
97+
98+
uint X = X_UNKNOWN;
99+
for (uint i = 1; i < X; i++) {
100+
if (::strcmp(enumNames[i], name) == 0)
101+
return (Prim_t)i;
102+
}
103+
104+
return A_ZERO;
105+
}
54106

55107
}
56108

stars/src/file_readers/pln_primitives.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ constexpr uint Prim_MAX_ID = X_UNKNOWN;
5656
// enum -> string
5757
CStr primt_name(Prim_t enu) noexcept;
5858

59+
60+
// string -> enum, returns A_ZERO on error
61+
Prim_t primt_id(CStr name) noexcept;
62+
63+
5964
}
6065

6166
#endif

stars/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 = "pln0223";
1+
static const char* _pln_VERSION_STR = "pln0224";
22

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

0 commit comments

Comments
 (0)