Skip to content

Commit 7cf26a5

Browse files
committed
pin_c: validate -internal_pin names
1 parent 109f382 commit 7cf26a5

File tree

6 files changed

+91
-22
lines changed

6 files changed

+91
-22
lines changed

planning/src/file_readers/pln_csv_reader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void PcCsvReader::reset() noexcept {
2929
rx_cols_.reset();
3030
tx_cols_.reset();
3131
gpio_cols_.reset();
32+
fullchipNames_.clear();
3233

3334
bcd_good_.clear();
3435

@@ -973,12 +974,16 @@ bool PcCsvReader::read_csv(const string& fn, uint num_udes_pins) {
973974

974975
flush_out(false);
975976

977+
fullchipNames_.clear();
976978
S_tmp = crd.getColumn("Fullchip_NAME");
977979
assert(S_tmp.size() > 1);
978980
assert(S_tmp.size() <= num_rows);
979981
S_tmp.resize(num_rows);
982+
fullchipNames_.reserve(num_rows + 2);
980983
for (uint i = 0; i < num_rows; i++) {
981984
bcd_[i]->fullchipName_ = std::move(S_tmp[i]);
985+
if (not bcd_[i]->fullchipName_.empty())
986+
fullchipNames_.insert(bcd_[i]->fullchipName_);
982987
}
983988

984989
flush_out(false);

planning/src/file_readers/pln_csv_reader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ class PcCsvReader {
283283
uint getModeCol(const string& mode) const noexcept;
284284
bool hasMode(const string& key) const noexcept { return getModeCol(key); }
285285

286+
bool hasFullchipName(const string& key) const noexcept {
287+
return fullchipNames_.count(key);
288+
}
289+
286290
uint printModeNames() const;
287291

288292
string bumpName2CustomerName(const string& bump_name) const noexcept;
@@ -336,6 +340,8 @@ class PcCsvReader {
336340
std::bitset<MAX_PT_COLS> tx_cols_; // which columns are "Mode_..._TX"
337341
std::bitset<MAX_PT_COLS> gpio_cols_; // which columns are "Mode_..._GPIO"
338342

343+
std::unordered_set<string> fullchipNames_; // for -internal_pin validation
344+
339345
vector<BCD*> bcd_; // all BCD records, indexed by csv row
340346

341347
vector<BCD*> bcd_AXI_; // BCD records with .isCustomerInternalOnly() predicate (AXI pins)

planning/src/file_readers/pln_pcf_reader.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bool PcfReader::read_pcf(const string& f) {
2626
bool has_error = false;
2727
string set_io_cmd, user_pin, bump_or_ball_name, dash_mode, mode_name;
2828
string optional_dash_internal_pin, optional_internal_pin;
29+
string internal_str;
2930

3031
vector<string> dat;
3132
string row_str;
@@ -65,11 +66,32 @@ bool PcfReader::read_pcf(const string& f) {
6566
optional_internal_pin.clear();
6667

6768
bool has_internal_pin = false;
69+
internal_str.clear();
6870
if (line.find("-internal_pin") != string::npos) {
71+
int index_in_dat = -1;
72+
assert(dat.size() > 1);
73+
for (int k = int(dat.size()) - 1; k > 0; k--) {
74+
if (dat[k] == "-internal_pin") {
75+
index_in_dat = k;
76+
break;
77+
}
78+
}
79+
if (index_in_dat < 0 or index_in_dat == int(dat.size()) - 1) {
80+
flush_out(true);
81+
err_puts();
82+
lprintf2("[Error] PCF Reader: syntax error regarding -internal_pin\n");
83+
flush_out(true);
84+
lprintf(" PCF line with syntax error: %s\n", line.c_str());
85+
flush_out(true);
86+
return false;
87+
}
6988
has_internal_pin = true;
89+
internal_str = dat[index_in_dat + 1];
7090
}
7191

72-
if (tr >= 4) ls << "(pcf line) " << line << endl;
92+
if (tr >= 5) {
93+
ls << "(pcf line) " << line << endl;
94+
}
7395

7496
if (has_internal_pin) {
7597
if (!(iss >> set_io_cmd >> user_pin >> bump_or_ball_name >> dash_mode >>
@@ -87,27 +109,28 @@ bool PcfReader::read_pcf(const string& f) {
87109

88110
if (tr >= 4) {
89111
ls << " user_pin:" << user_pin << " bump_or_ball_name:" << bump_or_ball_name
90-
<< " mode_name:" << mode_name << endl;
112+
<< " mode_name:" << mode_name << " internal_str:" << internal_str << endl;
91113
}
92114

93115
commands_.emplace_back();
94116
Cmd& last = commands_.back();
95-
vector<string>& cur_command = last.cmd_;
117+
last.clearInternalPin();
96118

97-
cur_command.push_back(set_io_cmd);
98-
cur_command.push_back(user_pin);
99-
cur_command.push_back(bump_or_ball_name);
100-
cur_command.push_back(dash_mode);
101-
cur_command.push_back(mode_name);
119+
last.cmd_.push_back(set_io_cmd);
120+
last.cmd_.push_back(user_pin);
121+
last.cmd_.push_back(bump_or_ball_name);
122+
last.cmd_.push_back(dash_mode);
123+
last.cmd_.push_back(mode_name);
102124

103125
if (has_internal_pin) {
104-
cur_command.push_back(optional_dash_internal_pin);
105-
cur_command.push_back(optional_internal_pin);
126+
last.cmd_.push_back(optional_dash_internal_pin);
127+
last.cmd_.push_back(optional_internal_pin);
128+
last.setInternalPin(internal_str);
106129
}
107130

108131
if (row_num > 0) {
109-
cur_command.emplace_back("-pt_row");
110-
cur_command.emplace_back(std::to_string(row_num));
132+
last.cmd_.emplace_back("-pt_row");
133+
last.cmd_.emplace_back(std::to_string(row_num));
111134
}
112135
}
113136

planning/src/file_readers/pln_pcf_reader.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ struct PcfReader {
1111

1212
struct Cmd {
1313
vector<string> cmd_;
14-
bool hasInternalPin_ = false;
14+
string internalPin_;
1515

1616
Cmd() noexcept = default;
1717

1818
size_t size() const noexcept { return cmd_.size(); }
19+
20+
bool hasInternalPin() const noexcept { return not internalPin_.empty(); }
21+
22+
void setInternalPin(const string& nm) noexcept {
23+
assert(not nm.empty());
24+
internalPin_ = nm;
25+
}
26+
void clearInternalPin() noexcept { internalPin_.clear(); }
1927
};
2028

2129
vector<Cmd> commands_;
@@ -25,8 +33,6 @@ struct PcfReader {
2533
PcfReader(const string& f) { read_pcf(f); }
2634

2735
bool read_pcf(const string& f);
28-
29-
//// const vector<Cmd>& get_commands() const noexcept { return commands_; }
3036
};
3137

3238
}

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

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

planning/src/pin_loc/pcf_place.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,21 @@ bool PinPlacer::read_pcf(const PcCsvReader& csv) {
412412
if (rd_pcf.commands_.empty())
413413
return true;
414414

415-
// validate modes
415+
assert(rd_pcf.commands_.size() < UINT_MAX);
416+
uint num_pcf_commands = rd_pcf.commands_.size();
417+
uint num_internal_pins = 0;
418+
419+
// -- validate modes
416420
string mode, key;
417-
for (uint cmd_i = 0; cmd_i < rd_pcf.commands_.size(); cmd_i++) {
418-
const vector<string>& pcf_cmd = rd_pcf.commands_[cmd_i].cmd_;
421+
for (uint cmd_i = 0; cmd_i < num_pcf_commands; cmd_i++) {
422+
const PcfReader::Cmd& cmdObj = rd_pcf.commands_[cmd_i];
423+
if (cmdObj.hasInternalPin())
424+
num_internal_pins++;
425+
const vector<string>& cmdl = cmdObj.cmd_;
419426
mode.clear();
420-
for (uint j = 1; j < pcf_cmd.size() - 1; j++) {
421-
if (pcf_cmd[j] == "-mode") {
422-
mode = pcf_cmd[j + 1];
427+
for (uint j = 1; j < cmdl.size() - 1; j++) {
428+
if (cmdl[j] == "-mode") {
429+
mode = cmdl[j + 1];
423430
break;
424431
}
425432
}
@@ -442,6 +449,28 @@ bool PinPlacer::read_pcf(const PcCsvReader& csv) {
442449
return false;
443450
}
444451

452+
if (tr >= 3) {
453+
lprintf("pin_c PCF: num_pcf_commands= %u num_internal_pins= %u\n",
454+
num_pcf_commands, num_internal_pins);
455+
}
456+
457+
// -- validate internal_pins
458+
for (uint cmd_i = 0; cmd_i < num_pcf_commands; cmd_i++) {
459+
const PcfReader::Cmd& cmdObj = rd_pcf.commands_[cmd_i];
460+
if (not cmdObj.hasInternalPin())
461+
continue;
462+
const string& ip = cmdObj.internalPin_;
463+
if (ip.empty())
464+
continue;
465+
if (csv.hasFullchipName(ip))
466+
continue;
467+
flush_out(true);
468+
err_puts();
469+
lprintf2("[Error] invalid -internal_pin in PCF: %s\n", ip.c_str());
470+
flush_out(true);
471+
return false;
472+
}
473+
445474
pcf_pin_cmds_ = std::move(rd_pcf.commands_);
446475

447476
if (tr >= 3) {

0 commit comments

Comments
 (0)