Skip to content

Commit df5b889

Browse files
committed
planner: CSV checker, stars --csv now reads and checks CSV
1 parent c8aa667 commit df5b889

File tree

7 files changed

+134
-30
lines changed

7 files changed

+134
-30
lines changed

pin_c/libpinconst.a

Lines changed: 0 additions & 2 deletions
This file was deleted.

pin_c/pin_c

Lines changed: 0 additions & 4 deletions
This file was deleted.

stars/src/RS/rsCheck.cpp

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
#include "RS/rsCheck.h"
22
#include "file_readers/pln_blif_file.h"
3+
#include "file_readers/pinc_csv_reader.h"
34

45
namespace pln {
56

67
using std::string;
78
using std::endl;
89

9-
bool do_check(const rsOpts& opts) {
10-
if (!opts.input_)
11-
return false;
10+
static bool do_check_blif(CStr cfn) {
11+
assert(cfn);
1212
uint16_t tr = ltrace();
1313
auto& ls = lout();
1414

15-
string fn1 = opts.input_;
16-
CStr cfn = fn1.c_str();
17-
ls << " checking BLIF file: " << fn1 << endl;
18-
19-
BLIF_file bfile(fn1);
15+
BLIF_file bfile(string{cfn});
2016

2117
if (tr >= 4)
2218
bfile.setTrace(3);
@@ -57,7 +53,7 @@ bool do_check(const rsOpts& opts) {
5753
}
5854

5955
lputs();
60-
ls << ">>>>> checking BLIF " << fn1 << " ..." << endl;
56+
ls << ">>>>> checking BLIF " << cfn << " ..." << endl;
6157

6258
bool chk_ok = bfile.checkBlif();
6359
assert(chk_ok == bfile.chk_ok_);
@@ -79,8 +75,89 @@ bool do_check(const rsOpts& opts) {
7975
ls << "[Error] !!! BLIF is not OK !!!" << endl;
8076
ls << "[Error] !!! " << bfile.err_msg_ << endl;
8177

78+
flush_out(true);
79+
lprintf2("ERROR: BLIF verification failed at %s:%zu\n",
80+
bfile.fnm_.c_str(), bfile.err_lnum_);
81+
8282
return false;
8383
}
8484

85+
static bool do_check_csv(CStr cfn) {
86+
assert(cfn);
87+
uint16_t tr = ltrace();
88+
auto& ls = lout();
89+
90+
{
91+
fio::MMapReader fileTester(string{cfn});
92+
93+
if (tr >= 4)
94+
fileTester.setTrace(3);
95+
96+
bool exi = false;
97+
exi = fileTester.fileExists();
98+
if (tr >= 7)
99+
ls << int(exi) << endl;
100+
if (not exi) {
101+
lprintf2("[Error] file '%s' does not exist\n", cfn);
102+
return false;
103+
}
104+
105+
exi = fileTester.fileAccessible();
106+
if (tr >= 7)
107+
ls << int(exi) << endl;
108+
if (not exi) {
109+
lprintf2("[Error] file '%s' is not accessible\n", cfn);
110+
return false;
111+
}
112+
}
113+
114+
flush_out(true);
115+
116+
// run CSV reader
117+
RapidCsvReader csv_rd;
118+
bool chk_ok = csv_rd.read_csv(string{cfn}, 1000);
119+
120+
flush_out(true);
121+
if (chk_ok) {
122+
ls << " === CSV is OK." << endl;
123+
return true;
124+
}
125+
126+
flush_out(true);
127+
lprintf2("ERROR: CSV verification failed at %s:%u\n",
128+
cfn, 0);
129+
130+
return false;
131+
}
132+
133+
bool do_check(const rsOpts& opts, bool blif_vs_csv) {
134+
if (!opts.input_ and !opts.csvFile_)
135+
return false;
136+
uint16_t tr = ltrace();
137+
138+
if (blif_vs_csv and !opts.input_)
139+
return false;
140+
if (!blif_vs_csv and !opts.csvFile_)
141+
return false;
142+
143+
CStr fileType = blif_vs_csv ? "BLIF" : "CSV";
144+
CStr cfn = blif_vs_csv ? opts.input_ : opts.csvFile_;
145+
assert(cfn);
146+
lprintf(" checking %s file: %s\n", fileType, cfn);
147+
148+
bool status;
149+
if (blif_vs_csv)
150+
status = do_check_blif(cfn);
151+
else
152+
status = do_check_csv(cfn);
153+
154+
flush_out(true);
155+
156+
if (tr >= 6) {
157+
lprintf(" do_check() status: %i\n", status);
158+
}
159+
return status;
160+
}
161+
85162
}
86163

stars/src/RS/rsCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace pln {
99

10-
bool do_check(const rsOpts& opts);
10+
bool do_check(const rsOpts& opts, bool blif_vs_csv);
1111

1212
}
1313

stars/src/RS/rsOpts.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ bool rsOpts::is_implicit_pinc() const noexcept {
243243
return true;
244244
}
245245

246+
bool rsOpts::is_implicit_check() const noexcept {
247+
assert(argv_);
248+
assert(argv_[0]);
249+
assert(argc_ > 0);
250+
if (!argv_ or !argv_[0])
251+
return false;
252+
253+
if (!csvFile_ or !csvFile_[0])
254+
return false;
255+
256+
if (argc_ > 4 or assignOrder_)
257+
return false;
258+
259+
return true;
260+
}
261+
246262
void rsOpts::parse(int argc, const char** argv) noexcept {
247263
using namespace ::pln::alias;
248264

@@ -487,6 +503,14 @@ bool rsOpts::hasInputFile() const noexcept {
487503
return input_file_exists(input_);
488504
}
489505

506+
bool rsOpts::hasCsvFile() const noexcept {
507+
if (!csvFile_ || !csvFile_[0]) return false;
508+
size_t len = ::strlen(csvFile_);
509+
if (len < 1 || len > UNIX_Path_Max) return false;
510+
511+
return input_file_exists(csvFile_);
512+
}
513+
490514
bool rsOpts::ends_with_pin_c(CStr z) noexcept {
491515
if (!z or !z[0])
492516
return false;

stars/src/RS/rsOpts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct rsOpts {
3939
}
4040
bool is_arg0_pinc() const noexcept;
4141
bool is_implicit_pinc() const noexcept;
42+
bool is_implicit_check() const noexcept;
4243

4344
static bool isFunctionArg(CStr arg) noexcept;
4445
static bool ends_with_pin_c(CStr z) noexcept;
@@ -100,6 +101,7 @@ struct rsOpts {
100101
bool createVprArgv(vector<string>& W) noexcept;
101102

102103
bool hasInputFile() const noexcept;
104+
bool hasCsvFile() const noexcept;
103105
bool isCmdInput() const noexcept;
104106

105107
private:

stars/src/main.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static const char* _pln_VERSION_STR = "pln0225";
1+
static const char* _pln_VERSION_STR = "pln0227";
22

33
#include "RS/rsEnv.h"
44
#include "util/pln_log.h"
@@ -31,22 +31,29 @@ static bool deal_pinc(const rsOpts& opts, bool orig_args);
3131
static bool deal_check(const rsOpts& opts) {
3232
bool status = false;
3333
uint16_t tr = ltrace();
34-
if (tr >= 4)
35-
lputs("[PLANNER CHECKER] deal_check()");
3634

37-
if (not opts.hasInputFile()) {
38-
err_puts("\n[PLANNER CHECKER] : something wrong with input file\n");
39-
if (!opts.input_) {
40-
lputs("[PLANNER CHECKER] : input file is not specified");
41-
} else {
42-
lprintf("[PLANNER CHECKER] : input file '%s'\n", opts.input_);
43-
lprintf(" : does not exist or not readable\n");
35+
CStr checkWhat = "BLIF";
36+
if (not opts.hasInputFile() and opts.hasCsvFile())
37+
checkWhat = "CSV";
38+
39+
if (tr >= 4)
40+
lprintf("[PLANNER %s-CHECKER] deal_check()\n", checkWhat);
41+
42+
if (checkWhat[0] == 'B') {
43+
if (not opts.hasInputFile()) {
44+
err_puts("\n[PLANNER BLIF-CHECKER] : something wrong with input file\n");
45+
if (!opts.input_) {
46+
lputs("[PLANNER BLIF-CHECKER] : input file is not specified");
47+
} else {
48+
lprintf("[PLANNER BLIF-CHECKER] : input file '%s'\n", opts.input_);
49+
lprintf(" : does not exist or not readable\n");
50+
}
51+
flush_out(true);
52+
return false;
4453
}
45-
flush_out(true);
46-
return false;
4754
}
4855

49-
status = do_check(opts);
56+
status = do_check(opts, checkWhat[0] == 'B');
5057

5158
if (tr >= 3)
5259
lprintf("(deal_check status) %s\n", status ? "TRUE" : "FALSE");
@@ -479,7 +486,7 @@ int main(int argc, char** argv) {
479486
::exit(0);
480487
}
481488

482-
if (opts.check_) {
489+
if (opts.check_ or opts.is_implicit_check()) {
483490
bool check_ok = deal_check(opts);
484491
if (check_ok)
485492
::exit(0);

0 commit comments

Comments
 (0)