Skip to content

Commit 7d4af3b

Browse files
committed
pin_c: finalize edits after PCF EDA-2821
1 parent eab9421 commit 7d4af3b

File tree

9 files changed

+467
-122
lines changed

9 files changed

+467
-122
lines changed

stars/src/file_readers/pinc_Fio.cpp

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sys/stat.h>
1010
#include <sys/types.h>
1111
#include <unistd.h>
12+
#include <libgen.h>
1213
#include <filesystem>
1314

1415
namespace fio {
@@ -58,6 +59,53 @@ void Info::init() noexcept {
5859
}
5960
}
6061

62+
string Info::get_abs_name(const string& nm) noexcept {
63+
namespace fs = std::filesystem;
64+
if (nm.empty()) return {};
65+
try {
66+
fs::path p{nm};
67+
p = p.lexically_normal();
68+
p = fs::absolute(p);
69+
return p.string();
70+
} catch (...) {
71+
// noexcept
72+
}
73+
return {};
74+
}
75+
76+
string Info::get_realpath(const string& nm) noexcept {
77+
string abs_nm = get_abs_name(nm);
78+
if (abs_nm.empty())
79+
return {};
80+
81+
char buf[8192];
82+
buf[0] = 0;
83+
buf[1] = 0;
84+
buf[8190] = 0;
85+
buf[8191] = 0;
86+
87+
if (::realpath(abs_nm.c_str(), buf)) {
88+
return buf;
89+
} else {
90+
::perror("realpath()");
91+
return abs_nm;
92+
}
93+
}
94+
95+
string Info::get_basename(const string& nm) noexcept {
96+
size_t len = nm.length();
97+
if (!len or len > 8192)
98+
return {};
99+
100+
char buf[len + 2] = {};
101+
102+
::strncpy(buf, nm.c_str(), len);
103+
104+
CStr bn = ::basename(buf);
105+
if (!bn) bn = "";
106+
return bn;
107+
}
108+
61109
void Fio::setTrace(int t) noexcept {
62110
if (t <= 0) {
63111
trace_ = 0;
@@ -506,7 +554,7 @@ int64_t MMapReader::printWC(std::ostream& os) const noexcept {
506554
return numLines;
507555
}
508556

509-
int64_t MMapReader::printLines(std::ostream& os) noexcept {
557+
size_t MMapReader::printLines(std::ostream& os) noexcept {
510558
if (!fsz_ || !sz_ || !buf_ || fnm_.empty()) return 0;
511559
bool hasl = hasLines();
512560
if (!hasl) {
@@ -524,6 +572,64 @@ int64_t MMapReader::printLines(std::ostream& os) noexcept {
524572
return cnt;
525573
}
526574

575+
int64_t MMapReader::writeFile(const string& nm) noexcept {
576+
if (nm.empty())
577+
return -1;
578+
if (!fsz_ || !sz_ || !buf_ || fnm_.empty())
579+
return -1;
580+
if (nm == fnm_)
581+
return -1;
582+
583+
auto tr = trace();
584+
CStr cnm = nm.c_str();
585+
FILE* f = ::fopen(cnm, "w");
586+
if (!f) {
587+
if (tr >= 3) {
588+
flush_out(true);
589+
lprintf("ERROR writeFile() could not open file for writing: %s\n", cnm);
590+
flush_out(true);
591+
}
592+
return -1;
593+
}
594+
595+
if (hasLines()) {
596+
// write line-by-line
597+
size_t cnt = 0, n = lines_.size();
598+
for (size_t i = 0; i < n; i++) {
599+
CStr cs = lines_[i];
600+
if (!cs || !cs[0]) continue;
601+
::fputs(cs, f);
602+
::fputc('\n', f);
603+
if (::ferror(f)) {
604+
if (tr >= 3) {
605+
flush_out(true);
606+
lprintf("ERROR writeFile() error during writing: %s\n", cnm);
607+
flush_out(true);
608+
}
609+
break;
610+
}
611+
cnt++;
612+
}
613+
::fclose(f);
614+
return cnt;
615+
}
616+
617+
// no lines, write raw buffer
618+
int64_t ret = sz_;
619+
::fwrite(buf_, sz_, 1, f);
620+
if (::ferror(f)) {
621+
if (tr >= 3) {
622+
flush_out(true);
623+
lprintf("ERROR writeFile() error during writing: %s\n", cnm);
624+
flush_out(true);
625+
}
626+
ret = -1;
627+
}
628+
629+
::fclose(f);
630+
return ret;
631+
}
632+
527633
uint64_t MMapReader::hashSum() const noexcept {
528634
assert(fsz_ == sz_);
529635
if (!fsz_ || !sz_ || !buf_) return 0;

stars/src/file_readers/pinc_Fio.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ inline char* p_strdup(CStr p) noexcept {
3838
return ::strdup(p);
3939
}
4040

41-
struct Info
42-
{
41+
struct Info {
4342
string name_, absName_;
44-
4543
size_t size_ = 0;
4644
bool exists_ = false;
4745
bool accessible_ = false;
@@ -53,6 +51,10 @@ struct Info
5351
Info(CStr nm) noexcept;
5452
Info(const string& nm) noexcept;
5553
void init() noexcept;
54+
55+
static string get_abs_name(const string& nm) noexcept;
56+
static string get_realpath(const string& nm) noexcept;
57+
static string get_basename(const string& nm) noexcept;
5658
};
5759

5860
class Fio {
@@ -243,7 +245,8 @@ class MMapReader : public Fio
243245
int64_t countWC(int64_t& numWords) const noexcept; // ~ wc command
244246
int64_t printWC(std::ostream& os) const noexcept; // ~ wc command
245247

246-
int64_t printLines(std::ostream& os) noexcept;
248+
size_t printLines(std::ostream& os) noexcept;
249+
int64_t writeFile(const string& nm) noexcept;
247250

248251
char* skipLine(char* curL) noexcept;
249252
bool advanceLine(char*& curL) noexcept;

stars/src/file_readers/pinc_csv_reader.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ static inline bool ends_with_tx_rx(const char* z, size_t len) noexcept {
5555
z[len - 3] == '_';
5656
}
5757

58-
static inline bool ends_with_rx(const char* z, size_t len) noexcept {
58+
bool RapidCsvReader::ends_with_rx(const char* z, size_t len) noexcept {
5959
assert(z);
6060
if (len < 4) return false;
6161
return z[len - 1] == 'x' and z[len - 2] == 'r' and z[len - 3] == '_';
6262
}
6363

64-
static inline bool ends_with_tx(const char* z, size_t len) noexcept {
64+
bool RapidCsvReader::ends_with_tx(const char* z, size_t len) noexcept {
6565
assert(z);
6666
if (len < 4) return false;
6767
return z[len - 1] == 'x' and z[len - 2] == 't' and z[len - 3] == '_';
@@ -263,7 +263,7 @@ struct RX_TX_val {
263263

264264
bool enabled() const noexcept { return val_ == "Y"; }
265265
bool is_rx() const noexcept {
266-
return ends_with_rx(hdr_.c_str(), hdr_.length());
266+
return RapidCsvReader::ends_with_rx(hdr_.c_str(), hdr_.length());
267267
}
268268
};
269269

@@ -1236,6 +1236,9 @@ bool RapidCsvReader::read_csv(const string& fn, uint num_udes_pins) {
12361236

12371237
bool always_print = ::getenv("pinc_always_print_csv");
12381238
bool write_debug = (tr >= 8 or ::getenv("pinc_write_debug_csv"));
1239+
bool copy_to_CWD = always_print or write_debug;
1240+
if (!copy_to_CWD)
1241+
copy_to_CWD = ::getenv("pinc_copy_input");
12391242

12401243
if (tr >= 6) {
12411244
flush_out(false);
@@ -1253,6 +1256,31 @@ bool RapidCsvReader::read_csv(const string& fn, uint num_udes_pins) {
12531256
if (write_debug)
12541257
write_debug_csv();
12551258

1259+
if (copy_to_CWD) {
1260+
string cwd = get_CWD();
1261+
string bn = fio::Info::get_basename(fn);
1262+
string cn = str::concat("cp_", bn);
1263+
1264+
if (tr >= 4) {
1265+
flush_out(true);
1266+
lprintf("read_csv: copy_to_CWD in work_dir = %s\n", cwd.c_str());
1267+
lprintf(" input csv: %s\n", fn.c_str());
1268+
lprintf(" basename: %s\n", bn.c_str());
1269+
lprintf(" copyname: %s\n", cn.c_str());
1270+
flush_out(true);
1271+
}
1272+
1273+
int64_t wr_status = crd.writeFile(cn);
1274+
if (wr_status > 0) {
1275+
if(tr >= 4)
1276+
lprintf("read_csv: copy_to_CWD OK wr_status= %zu\n", size_t(wr_status));
1277+
} else {
1278+
if(tr >= 3)
1279+
lprintf("read_csv: copy_to_CWD FAILED\n");
1280+
}
1281+
flush_out(true);
1282+
}
1283+
12561284
flush_out(false);
12571285
return true;
12581286
}

stars/src/file_readers/pinc_csv_reader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ class RapidCsvReader {
313313

314314
static string label_of_column(int i) noexcept;
315315

316+
static bool ends_with_rx(const char* z, size_t len) noexcept;
317+
static bool ends_with_tx(const char* z, size_t len) noexcept;
318+
316319
private:
317320

318321
bool initCols(const fio::CSV_Reader& crd);

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

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

stars/src/pin_loc/pcf_place.cpp

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,22 @@ bool PinPlacer::read_pcf(const RapidCsvReader& csv) {
445445

446446
pcf_pin_cmds_ = std::move(rd_pcf.commands_);
447447

448-
// translate pin-references in cmds_
449-
if (pcf_pin_cmds_.size() and
450-
pin_names_translated_ and is_fabric_eblif_ and all_edits_.size()) {
448+
if (tr >= 3) {
449+
flush_out(true);
450+
lputs("\t *** pin_c read_pcf SUCCEEDED ***");
451+
}
452+
453+
return true;
454+
}
455+
456+
void PinPlacer::translate_pcf_cmds() {
457+
if (pcf_pin_cmds_.empty() or all_edits_.empty())
458+
return;
459+
460+
uint16_t tr = ltrace();
461+
flush_out(tr >= 6);
462+
463+
if (1) {
451464

452465
if (tr >= 6) {
453466
lprintf(" ---- pcf_pin_cmds_ before translation (%zu):\n",
@@ -475,6 +488,7 @@ bool PinPlacer::read_pcf(const RapidCsvReader& csv) {
475488
}
476489
}
477490

491+
flush_out(tr >= 6);
478492
if (tr >= 3) {
479493
lprintf("PCF command translation: #input translations= %u #output translations= %u\n",
480494
numInpTr, numOutTr);
@@ -486,15 +500,44 @@ bool PinPlacer::read_pcf(const RapidCsvReader& csv) {
486500
for (const auto& cmd : pcf_pin_cmds_)
487501
logVec(cmd, " ");
488502
lprintf(" ++++ \n");
503+
flush_out(true);
489504
}
490505
}
491506

492-
if (tr >= 3) {
493-
flush_out(true);
494-
lputs("\t *** pin_c read_pcf SUCCEEDED ***");
495-
}
507+
flush_out(false);
508+
}
496509

497-
return true;
510+
void PinPlacer::get_pcf_directions( vector<string>& inps, vector<string>& outs,
511+
vector<string>& undefs ) const noexcept {
512+
inps.clear();
513+
outs.clear();
514+
undefs.clear();
515+
516+
if (pcf_pin_cmds_.empty())
517+
return;
518+
519+
size_t n = pcf_pin_cmds_.size();
520+
inps.reserve(n/2 + 2);
521+
outs.reserve(n/2 + 2);
522+
523+
string mod;
524+
for (const vector<string>& cmd : pcf_pin_cmds_) {
525+
if (cmd.size() < 5)
526+
continue;
527+
const string& pin = cmd[1];
528+
assert(!pin.empty());
529+
if (pin.empty())
530+
continue;
531+
mod = str::s2lower(cmd[4]);
532+
CStr cmod = mod.c_str();
533+
size_t len = mod.length();
534+
if (RapidCsvReader::ends_with_rx(cmod, len))
535+
inps.push_back(pin);
536+
else if (RapidCsvReader::ends_with_tx(cmod, len))
537+
outs.push_back(pin);
538+
else
539+
undefs.push_back(pin);
540+
}
498541
}
499542

500543
bool PinPlacer::write_dot_place(const RapidCsvReader& csv) {
@@ -516,6 +559,13 @@ bool PinPlacer::write_dot_place(const RapidCsvReader& csv) {
516559
logVec(cmd, " ");
517560
}
518561
lprintf(" ___\n");
562+
vector<string> inps, outs, undefs;
563+
get_pcf_directions(inps, outs, undefs);
564+
lprintf(" ___\n");
565+
logVec(inps, " [pcf_inputs] ");
566+
lprintf(" ___\n");
567+
logVec(outs, " [pcf_outputs] ");
568+
lprintf(" ___\n");
519569
}
520570
}
521571

stars/src/pin_loc/pin_placer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ bool PinPlacer::read_and_write() {
304304
return false;
305305
}
306306

307-
// --4 optionally, read netlist edits (--edits option)
307+
// --4. read netlist edits (--edits option)
308308
bool has_edits = read_edits();
309309
flush_out(false);
310310
if (tr >= 3)
311311
lprintf("\t has_edits : %i\n", has_edits);
312312

313313

314-
// usage 2: if no user pcf is provided, created a temp one
314+
// if no user pcf is provided, created a temp one
315315
if (usage_requirement_2 || (usage_requirement_0 && user_pcf_ == "")) {
316316
flush_out(true);
317317
if (has_edits) {
@@ -445,7 +445,10 @@ bool PinPlacer::read_and_write() {
445445
return false;
446446
}
447447

448-
// --6. create .place file
448+
// --6. adjust edits based on PCF pin-lists
449+
finalize_edits();
450+
451+
// --7. create .place file
449452
if (!write_dot_place(csv_rd)) {
450453
// error messages will be issued in callee
451454
if (tr) {
@@ -458,7 +461,7 @@ bool PinPlacer::read_and_write() {
458461
return false;
459462
}
460463

461-
// --7. optionally, map logical clocks to physical clocks
464+
// --8. optionally, map logical clocks to physical clocks
462465
// status = 0 if NOP, -1 if error
463466
int map_clk_status = map_clocks();
464467
if (map_clk_status < 0) {

0 commit comments

Comments
 (0)