forked from The-OpenROAD-Project/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SdfLex.ll
197 lines (161 loc) · 4.23 KB
/
SdfLex.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
%{
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2023, Parallax Software, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "util/FlexDisableRegister.hh"
#include "sdf/SdfReaderPvt.hh"
#include "SdfParse.hh"
#define YY_NO_INPUT
static std::string sdf_token;
void
sdfFlushBuffer()
{
YY_FLUSH_BUFFER;
}
%}
/* %option debug */
%option noyywrap
%option nounput
%option never-interactive
%x COMMENT
%x QUOTE
%x COND_EXPR
ID ([A-Za-z_]|\\.)([A-Za-z0-9_\[\]]|\\.)*
HCHAR "."|"/"
BLANK [ \n\t\r\b]
EOL \r?\n
%%
"/*" { BEGIN COMMENT; }
<COMMENT>{
"*/" { BEGIN INITIAL; }
.
{EOL} { sta::sdf_reader->incrLine(); }
<<EOF>> {
SdfParse_error("unterminated comment");
BEGIN(INITIAL);
yyterminate();
}
}
"\"" { BEGIN QUOTE; sdf_token.erase(); }
<QUOTE>{
"\\". { sdf_token += yytext[1]; }
"\"" {
BEGIN INITIAL;
SdfParse_lval.string = sta::stringCopy(sdf_token.c_str());
return QSTRING;
}
. { sdf_token += yytext[0]; }
<<EOF>> {
SdfParse_error("unterminated quoted string");
BEGIN(INITIAL);
yyterminate();
}
}
"//"[^\n]*{EOL} { sta::sdf_reader->incrLine(); }
("-"|"+")?([0-9]*)("."[0-9]+)([eE]("-"|"+")?[0-9]+)? {
SdfParse_lval.number = static_cast<float>(atof(yytext));
return FNUMBER;
}
"+"?[0-9]+ {
SdfParse_lval.integer = atoi(yytext);
return DNUMBER;
}
":"|"{"|"}"|"["|"]"|","|"*"|";"|"="|"-"|"+"|"|"|"("|")"|{HCHAR} {
return ((int) yytext[0]);
}
ABSOLUTE { return ABSOLUTE; }
CELL { return CELL; }
CELLTYPE { return CELLTYPE; }
DATE { return DATE; }
DELAY { return DELAY; }
DELAYFILE { return DELAYFILE; }
DESIGN { return DESIGN; }
DEVICE { return DEVICE; }
DIVIDER { return DIVIDER; }
HOLD { return HOLD; }
INCREMENTAL|INCREMENT { return INCREMENTAL; }
INSTANCE { return INSTANCE; }
INTERCONNECT { return INTERCONNECT; }
IOPATH { return IOPATH; }
NOCHANGE { return NOCHANGE; }
PERIOD { return PERIOD; }
PORT { return PORT; }
PROCESS { return PROCESS; }
PROGRAM { return PROGRAM; }
RECOVERY { return RECOVERY; }
RECREM { return RECREM; }
REMOVAL { return REMOVAL; }
RETAIN { return RETAIN; }
SDFVERSION { return SDFVERSION; }
SETUP { return SETUP; }
SETUPHOLD { return SETUPHOLD; }
SKEW { return SKEW; }
TEMPERATURE { return TEMPERATURE; }
TIMESCALE { return TIMESCALE; }
TIMINGCHECK { return TIMINGCHECK; }
VENDOR { return VENDOR; }
VERSION { return PVERSION; }
VOLTAGE { return VOLTAGE; }
WIDTH { return WIDTH; }
negedge { return NEGEDGE; }
posedge { return POSEDGE; }
CONDELSE { return CONDELSE; }
COND {
BEGIN COND_EXPR;
sdf_token.erase();
return COND;
}
<COND_EXPR>"("{BLANK}*IOPATH {
BEGIN INITIAL;
SdfParse_lval.string = sta::stringCopy(sdf_token.c_str());
return EXPR_OPEN_IOPATH;
}
<COND_EXPR>"(" {
/* Timing check conditions don't allow parens,
* so use the paren as a marker for the end of the expr.
*/
if (sta::sdf_reader->inTimingCheck()) {
BEGIN INITIAL;
SdfParse_lval.string= sta::stringCopy(sdf_token.c_str());
return EXPR_OPEN;
}
else
sdf_token += yytext[0];
}
<COND_EXPR>{BLANK}+{ID}{BLANK}*")" {
/* (COND expr port) */
if (sta::sdf_reader->inTimingCheck()) {
BEGIN INITIAL;
/* remove trailing ")" */
yytext[strlen(yytext)-1] = '\0';
sdf_token += yytext;
SdfParse_lval.string= sta::stringCopy(sdf_token.c_str());
/* No way to pass expr and id separately, so pass them together. */
return EXPR_ID_CLOSE;
}
else
sdf_token += yytext;
}
<COND_EXPR>{BLANK} {}
<COND_EXPR>. { sdf_token += yytext[0]; }
{ID} {
SdfParse_lval.string = sta::stringCopy(yytext);
return ID;
}
{EOL} { sta::sdf_reader->incrLine(); }
{BLANK} { /* Ignore blanks. */ }
/* Send out of bound characters to parser. */
. { return ((int) yytext[0]); }
%%