Skip to content

Commit 6c2e0df

Browse files
committed
pln: add --check <BLIF> command line option
1 parent 37e8618 commit 6c2e0df

File tree

6 files changed

+148
-29
lines changed

6 files changed

+148
-29
lines changed

stars/src/RS/rsCheck.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "RS/rsCheck.h"
2+
#include "file_readers/pln_blif_file.h"
3+
4+
namespace pln {
5+
6+
using std::string;
7+
using std::endl;
8+
9+
bool do_check(const rsOpts& opts) {
10+
if (!opts.input_)
11+
return false;
12+
uint16_t tr = ltrace();
13+
auto& ls = lout();
14+
15+
string fn1 = opts.input_;
16+
CStr cfn = fn1.c_str();
17+
ls << " checking BLIF file: " << fn1 << endl;
18+
19+
BLIF_file bfile(fn1);
20+
21+
if (tr >= 4)
22+
bfile.setTrace(3);
23+
24+
bool exi = false;
25+
exi = bfile.fileExists();
26+
if (tr >= 7)
27+
ls << int(exi) << endl;
28+
if (not exi) {
29+
lprintf2("[Error] file '%s' does not exist\n", cfn);
30+
return false;
31+
}
32+
33+
exi = bfile.fileAccessible();
34+
if (tr >= 7)
35+
ls << int(exi) << endl;
36+
if (not exi) {
37+
lprintf2("[Error] file '%s' is not accessible\n", cfn);
38+
return false;
39+
}
40+
41+
bool rd_ok = bfile.readBlif();
42+
if (tr >= 7)
43+
ls << int(rd_ok) << endl;
44+
if (not rd_ok) {
45+
lprintf2("[Error] failed reading file '%s'\n", cfn);
46+
return false;
47+
}
48+
49+
lprintf(" (blif_file) #inputs= %u #outputs= %u\n",
50+
bfile.numInputs(), bfile.numOutputs());
51+
52+
if (tr >= 4) {
53+
lputs();
54+
bfile.printInputs(ls);
55+
lputs();
56+
bfile.printOutputs(ls);
57+
}
58+
59+
lputs();
60+
ls << ">>>>> checking BLIF " << fn1 << " ..." << endl;
61+
62+
bool chk_ok = bfile.checkBlif();
63+
64+
ls << ">>>>> chk_ok: " << int(chk_ok) << endl;
65+
if (chk_ok) {
66+
ls << " === BLIF is OK." << endl;
67+
return true;
68+
}
69+
70+
ls << " !!! BLIF is not OK: " << endl;
71+
ls << " !!! " << bfile.err_msg_ << endl;
72+
73+
return false;
74+
}
75+
76+
}
77+

stars/src/RS/rsCheck.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
// API entry points for checkers
3+
#ifndef _pln_rs_rsCheck_H_h_
4+
#define _pln_rs_rsCheck_H_h_
5+
6+
#include "RS/rsOpts.h"
7+
8+
namespace pln {
9+
10+
bool do_check(const rsOpts& opts);
11+
12+
}
13+
14+
#endif
15+

stars/src/RS/rsDB.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ using std::endl;
88
using std::string;
99
using std::stringstream;
1010
using std::ostream;
11-
using namespace pln;
1211

1312
///@brief Returns the name of a unique unconnected net
1413
static string create_unconn_net(size_t& unconn_count) noexcept {

stars/src/RS/rsOpts.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ static CStr _help_[] = {"H", "h", "help", "hel", "hlp", "he", nullptr};
2121

2222
static CStr _fun_[] = {"F", "fu", "fun", "func", "funct", "function", nullptr};
2323

24-
static CStr _check_[] = {"ch", "che", "chec", "check", nullptr};
24+
static CStr _check_[] = {"CH", "ch", "che", "chec", "check", nullptr};
2525

26-
static CStr _csv_[] = {"CS", "cs", "csv", nullptr};
26+
static CStr _csv_[] = {"CSV", "cs", "csv", nullptr};
2727

2828
static CStr _xml_[] = {"XM", "xm", "xml", "XML", nullptr};
2929

@@ -399,19 +399,6 @@ void rsOpts::parse(int argc, const char** argv) noexcept {
399399
if (test_id_ < 0) test_id_ = 0;
400400
}
401401

402-
// and2_gemini
403-
bool rsOpts::set_VPR_TC1() noexcept {
404-
lputs(" O-set_VPR_TC1: and2_gemini");
405-
assert(argc_ > 0 && argv_);
406-
bool ok = false;
407-
408-
#ifdef RSBE_UNIT_TEST_ON
409-
#endif // RSBE_UNIT_TEST_ON
410-
411-
flush_out(true);
412-
return ok;
413-
}
414-
415402
bool rsOpts::set_STA_testCase(int TC_id) noexcept { return false; }
416403

417404
bool rsOpts::set_VPR_TC_args(CStr raw_tc) noexcept {
@@ -492,6 +479,14 @@ bool rsOpts::isCmdInput() const noexcept {
492479
return input_file_exists(input_);
493480
}
494481

482+
bool rsOpts::hasInputFile() const noexcept {
483+
if (!input_ || !input_[0]) return false;
484+
size_t len = ::strlen(input_);
485+
if (len < 1 || len > UNIX_Path_Max) return false;
486+
487+
return input_file_exists(input_);
488+
}
489+
495490
bool rsOpts::ends_with_pin_c(CStr z) noexcept {
496491
if (!z or !z[0])
497492
return false;

stars/src/RS/rsOpts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ struct rsOpts {
9595
bool trace_specified() const noexcept { return traceIndex_ > 0; }
9696
bool test_id_specified() const noexcept { return test_id_ > 0; }
9797

98-
bool set_VPR_TC1() noexcept; // and2_gemini
9998
bool set_STA_testCase(int TC_id) noexcept;
10099

101100
bool createVprArgv(vector<string>& W) noexcept;
102101

102+
bool hasInputFile() const noexcept;
103103
bool isCmdInput() const noexcept;
104104

105105
private:

stars/src/main.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static const char* _pln_VERSION_STR = "pln0216";
1+
static const char* _pln_VERSION_STR = "pln0218";
22

33
#include "RS/rsEnv.h"
44
#include "util/pln_log.h"
@@ -14,6 +14,7 @@ static const char* _pln_VERSION_STR = "pln0216";
1414
#include "read_options.h"
1515

1616
#include "RS/rsVPR.h"
17+
#include "RS/rsCheck.h"
1718
#include "RS/sta_file_writer.h"
1819

1920
namespace pln {
@@ -27,6 +28,33 @@ static rsEnv s_env;
2728

2829
static bool deal_pinc(const rsOpts& opts, bool orig_args);
2930

31+
static bool deal_check(const rsOpts& opts) {
32+
bool status = false;
33+
uint16_t tr = ltrace();
34+
if (tr >= 4)
35+
lputs("[PLANNER CHECKER] deal_check()");
36+
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");
44+
}
45+
flush_out(true);
46+
return false;
47+
}
48+
49+
status = do_check(opts);
50+
51+
if (tr >= 3)
52+
lprintf("(deal_check status) %s\n", status ? "TRUE" : "FALSE");
53+
54+
flush_out(true);
55+
return status;
56+
}
57+
3058
static bool deal_stars(const rsOpts& opts, bool orig_args) {
3159
bool status = false;
3260

@@ -236,7 +264,7 @@ static bool deal_cmd(rsOpts& opts) {
236264
return false;
237265
}
238266
arg0 = W[0];
239-
if (tr >= 6) {
267+
if (tr >= 7) {
240268
lprintf(" W.size()= %zu W[0]= %s\n", W.size(), arg0.c_str());
241269
lputs();
242270
}
@@ -247,7 +275,7 @@ static bool deal_cmd(rsOpts& opts) {
247275
for (uint j = 1; j < W.size(); j++) {
248276
cmdArgv[cmdArgc++] = ::strdup(W[j].c_str());
249277
}
250-
if (tr >= 3)
278+
if (tr >= 4)
251279
lprintf(" created cmdArgv: cmdArgc= %i\n", cmdArgc);
252280
opts.vprArgc_ = cmdArgc;
253281
opts.vprArgv_ = cmdArgv;
@@ -310,7 +338,7 @@ static bool deal_pinc(const rsOpts& opts, bool orig_args) {
310338
return false;
311339
}
312340

313-
if (tr >= 9 || getenv("pln_trace_env")) {
341+
if (tr >= 11 || getenv("pln_trace_env")) {
314342
string cmd_fn = str::concat("01_deal_pinc.", std::to_string(s_env.pid_), ".pinc.sh");
315343
std::ofstream cmd_os(cmd_fn);
316344
if (cmd_os.is_open()) {
@@ -424,17 +452,14 @@ int main(int argc, char** argv) {
424452

425453
s_env.initVersions(_pln_VERSION_STR);
426454

427-
if (ltrace() >= 2) {
428-
if (ltrace() >= 6)
429-
s_env.printPids(_pln_VERSION_STR);
430-
else
431-
lout() << _pln_VERSION_STR << endl;
455+
if (ltrace() >= 3) {
456+
lprintf("\t %s\n", _pln_VERSION_STR);
432457
lprintf("\t compiled: %s\n", s_env.compTimeCS());
433458
}
434459

435460
s_env.parse(argc, argv);
436461

437-
if (opts.trace_ >= 4 || ltrace() >= 9 || getenv("pln_trace_env")) {
462+
if (opts.trace_ >= 8 || ltrace() >= 9 || getenv("pln_trace_env")) {
438463
s_env.dump("\n----env----\n");
439464
lout() << "-----------" << endl;
440465
}
@@ -445,13 +470,21 @@ int main(int argc, char** argv) {
445470
std::quick_exit(0);
446471
}
447472

473+
if (ltrace() >= 4) {
474+
lprintf("ltrace()= %u cmd.argc= %i\n", ltrace(), argc);
475+
}
476+
448477
if (opts.unit_specified()) {
449478
deal_units(opts);
450479
::exit(0);
451480
}
452481

453-
if (ltrace() >= 3) {
454-
lprintf("ltrace()= %u cmd.argc= %i\n", ltrace(), argc);
482+
if (opts.check_) {
483+
bool check_ok = deal_check(opts);
484+
if (check_ok)
485+
::exit(0);
486+
else
487+
::exit(1);
455488
}
456489

457490
int status = 1;

0 commit comments

Comments
 (0)