Skip to content

Commit 74bd10b

Browse files
committed
Squashed 'libs/EXTERNAL/libblifparse/' changes from c4ba9de..4bbe247
4bbe247 Improve default error message for blif extensions 0590056 Naive support for quotes around .attr values 702bbde Add initial support for YOSYS's BLIF extensions 29a7399 Remove legacy Makefile git-subtree-dir: libs/EXTERNAL/libblifparse git-subtree-split: 4bbe247a3c0c0678ce71f89f317eb27aa297936d
1 parent 8796177 commit 74bd10b

File tree

10 files changed

+167
-147
lines changed

10 files changed

+167
-147
lines changed

Makefile

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

src/blif_common.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,27 @@ struct SubCkt {
2020
std::vector<std::string> nets;
2121
};
2222

23+
/*
24+
* BLIF Extensions
25+
*/
26+
struct Conn {
27+
std::string src;
28+
std::string dst;
29+
};
30+
31+
struct Cname {
32+
std::string name;
33+
};
34+
35+
struct Attr {
36+
std::string name;
37+
std::string value;
38+
};
39+
40+
struct Param {
41+
std::string name;
42+
std::string value;
43+
};
44+
2345
} //namespace
2446
#endif

src/blif_lexer.l

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
%option prefix="blifparse_"
4646

4747
/* Common character classes */
48-
ALPHA_SYMBOLS [-a-zA-Z_~|:*/\[\]\.\{\}^+$]
48+
ALPHA_SYMBOLS [-a-zA-Z_~|:*/\[\]\.\{\}^+$;'"]
4949
DIGITS [0-9]
5050
ALPHA_NUM_SYMBOLS ({ALPHA_SYMBOLS}|{DIGITS})
5151
BACK_SLASH [\\]
@@ -101,6 +101,12 @@ ENDL (\n|\n\r|\r\n)
101101
<*>\.outputs { BEGIN(INITIAL); return blifparse::Parser::make_DOT_OUTPUTS(); }
102102
<*>\.end { BEGIN(INITIAL); return blifparse::Parser::make_DOT_END(); }
103103
<*>\.blackbox { BEGIN(INITIAL); return blifparse::Parser::make_DOT_BLACKBOX(); }
104+
105+
<*>\.conn { BEGIN(INITIAL); return blifparse::Parser::make_DOT_CONN(); /*BLIF extension */}
106+
<*>\.attr { BEGIN(INITIAL); return blifparse::Parser::make_DOT_ATTR(); /*BLIF extension */}
107+
<*>\.param { BEGIN(INITIAL); return blifparse::Parser::make_DOT_PARAM(); /*BLIF extension */}
108+
<*>\.cname { BEGIN(INITIAL); return blifparse::Parser::make_DOT_CNAME(); /*BLIF extension */}
109+
104110
= { return blifparse::Parser::make_EQ();}
105111
<LATCH>fe { return blifparse::Parser::make_LATCH_FE(); }
106112
<LATCH>re { return blifparse::Parser::make_LATCH_RE(); }

src/blif_parser.y

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ using namespace blifparse;
119119
%token EOL "end-of-line"
120120
%token EOF 0 "end-of-file"
121121

122+
/*BLIF extensions */
123+
%token DOT_CONN ".conn"
124+
%token DOT_ATTR ".attr"
125+
%token DOT_PARAM ".param"
126+
%token DOT_CNAME ".cname"
127+
122128
/* declare variable tokens */
123129
%token <std::string> STRING
124130

@@ -132,6 +138,12 @@ using namespace blifparse;
132138
%type <std::string> latch_control
133139
%type <LatchType> latch_type
134140

141+
/* BLIF Extensions */
142+
%type <Conn> conn
143+
%type <Cname> cname
144+
%type <Attr> attr
145+
%type <Param> param
146+
135147
/* Top level rule */
136148
%start blif_data
137149

@@ -151,9 +163,13 @@ blif_data: /*empty*/ { }
151163
callback.lineno(lexer.lineno()-1);
152164
callback.subckt($2.model, $2.ports, $2.nets);
153165
}
154-
| blif_data latch EOL { }
166+
| blif_data latch EOL { /*callback already called */ }
155167
| blif_data DOT_BLACKBOX EOL { callback.lineno(lexer.lineno()-1); callback.blackbox(); }
156168
| blif_data DOT_END EOL { callback.lineno(lexer.lineno()-1); callback.end_model(); }
169+
| blif_data conn EOL { callback.lineno(lexer.lineno()-1); callback.conn($2.src, $2.dst); }
170+
| blif_data cname EOL { callback.lineno(lexer.lineno()-1); callback.cname($2.name); }
171+
| blif_data attr EOL { callback.lineno(lexer.lineno()-1); callback.attr($2.name, $2.value); }
172+
| blif_data param EOL { callback.lineno(lexer.lineno()-1); callback.param($2.name, $2.value); }
157173
| blif_data EOL { /* eat end-of-lines */}
158174
;
159175

@@ -226,8 +242,15 @@ string_list: /*empty*/ { $$ = std::vector<std::string>(); }
226242
| string_list STRING { $$ = std::move($1); $$.push_back($2); }
227243
;
228244

229-
%%
245+
/*
246+
* BLIF Extensions
247+
*/
248+
conn: DOT_CONN STRING STRING { $$ = Conn(); $$.src = $2; $$.dst = $3; }
249+
cname: DOT_CNAME STRING { $$ = Cname(); $$.name = $2; }
250+
attr: DOT_ATTR STRING STRING { $$ = Attr(); $$.name = $2; $$.value = $3; }
251+
param: DOT_PARAM STRING STRING { $$ = Param(); $$.name = $2; $$.value = $3; }
230252

253+
%%
231254

232255
void blifparse::Parser::error(const std::string& msg) {
233256
blif_error_wrap(callback, lexer.lineno(), lexer.text(), msg.c_str());

src/blif_pretty_print.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ void BlifPrettyPrinter::outputs(std::vector<std::string> output_conns) {
5151
printf("\n");
5252
}
5353
--indent_level_;
54-
55-
printf("\n");
5654
}
5755

5856
void BlifPrettyPrinter::names(std::vector<std::string> nets, std::vector<std::vector<LogicValue>> so_cover) {
57+
printf("\n");
5958
if(print_file_line_) {
6059
printf("#%s:%d\n", filename_.c_str(), lineno_);
6160
}
@@ -82,10 +81,10 @@ void BlifPrettyPrinter::names(std::vector<std::string> nets, std::vector<std::ve
8281
}
8382
printf("\n");
8483
}
85-
printf("\n");
8684
}
8785

8886
void BlifPrettyPrinter::latch(std::string input, std::string output, LatchType type, std::string control, LogicValue init) {
87+
printf("\n");
8988
if(print_file_line_) {
9089
printf("#%s:%d\n", filename_.c_str(), lineno_);
9190
}
@@ -116,13 +115,11 @@ void BlifPrettyPrinter::latch(std::string input, std::string output, LatchType t
116115
case LogicValue::UNKOWN: printf("%s3", indent().c_str()); break;
117116
default: assert(false);
118117
}
119-
printf("\n");
120118
--indent_level_;
121-
122-
printf("\n");
123119
}
124120

125121
void BlifPrettyPrinter::subckt(std::string model, std::vector<std::string> ports, std::vector<std::string> nets) {
122+
printf("\n");
126123
if(print_file_line_) {
127124
printf("#%s:%d\n", filename_.c_str(), lineno_);
128125
}
@@ -140,26 +137,50 @@ void BlifPrettyPrinter::subckt(std::string model, std::vector<std::string> ports
140137
printf("\n");
141138
}
142139
--indent_level_;
143-
144-
printf("\n");
145140
}
146141

147142
void BlifPrettyPrinter::blackbox() {
148143
if(print_file_line_) {
149144
printf("#%s:%d\n", filename_.c_str(), lineno_);
150145
}
151146
printf(".blackbox\n");
152-
printf("\n");
153147
}
154148

155149
void BlifPrettyPrinter::end_model() {
156150
if(print_file_line_) {
157151
printf("#%s:%d\n", filename_.c_str(), lineno_);
158152
}
159153
printf(".end\n");
160-
printf("\n");
161154
}
162155

156+
void BlifPrettyPrinter::conn(std::string src, std::string dst) {
157+
if(print_file_line_) {
158+
printf("#%s:%d\n", filename_.c_str(), lineno_);
159+
}
160+
printf(".conn %s %s\n", src.c_str(), dst.c_str());
161+
162+
}
163+
164+
void BlifPrettyPrinter::cname(std::string cell_name) {
165+
if(print_file_line_) {
166+
printf("#%s:%d\n", filename_.c_str(), lineno_);
167+
}
168+
printf(".cname %s\n", cell_name.c_str());
169+
}
170+
171+
void BlifPrettyPrinter::attr(std::string name, std::string value) {
172+
if(print_file_line_) {
173+
printf("#%s:%d\n", filename_.c_str(), lineno_);
174+
}
175+
printf(".attr %s %s\n", name.c_str(), value.c_str());
176+
}
177+
178+
void BlifPrettyPrinter::param(std::string name, std::string value) {
179+
if(print_file_line_) {
180+
printf("#%s:%d\n", filename_.c_str(), lineno_);
181+
}
182+
printf(".param %s %s\n", name.c_str(), value.c_str());
183+
}
163184

164185
void BlifPrettyPrinter::filename(std::string fname) {
165186
filename_ = fname;

src/blif_pretty_print.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class BlifPrettyPrinter : public Callback {
2929

3030
void end_model() override;
3131

32+
//BLIF Extensions
33+
void conn(std::string src, std::string dst) override;
34+
void cname(std::string cell_name) override;
35+
void attr(std::string name, std::string value) override;
36+
void param(std::string name, std::string value) override;
37+
3238
void finish_parse() override;
3339

3440
void parse_error(const int curr_lineno, const std::string& near_text, const std::string& msg) override {

src/blifparse.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99

1010
namespace blifparse {
1111

12+
//.conn [Extended BLIF]
13+
void Callback::conn(std::string /*src*/, std::string /*dst*/) {
14+
parse_error(-1, ".conn", "Unsupported BLIF extension");
15+
}
16+
17+
//.cname [Extended BLIF]
18+
void Callback::cname(std::string /*cell_name*/) {
19+
parse_error(-1, ".cname", "Unsupported BLIF extension");
20+
}
21+
22+
//.attr [Extended BLIF]
23+
void Callback::attr(std::string /*name*/, std::string /*value*/) {
24+
parse_error(-1, ".attr", "Unsupported BLIF extension");
25+
}
26+
27+
//.param [Extended BLIF]
28+
void Callback::param(std::string /*name*/, std::string /*value*/) {
29+
parse_error(-1, ".param", "Unsupported BLIF extension");
30+
}
31+
1232
/*
1333
* Given a filename parses the file as an BLIF file
1434
* and returns a pointer to a struct containing all

src/blifparse.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ class Callback {
7272
//.end (of a .model)
7373
virtual void end_model() = 0;
7474

75+
//.conn [Extended BLIF, produces an error if not overriden]
76+
virtual void conn(std::string src, std::string dst);
77+
78+
//.cname [Extended BLIF, produces an error if not overriden]
79+
virtual void cname(std::string cell_name);
80+
81+
//.attr [Extended BLIF, produces an error if not overriden]
82+
virtual void attr(std::string name, std::string value);
83+
84+
//.param [Extended BLIF, produces an error if not overriden]
85+
virtual void param(std::string name, std::string value);
86+
7587
//End of parsing
7688
virtual void finish_parse() = 0;
7789

0 commit comments

Comments
 (0)