forked from nickson-jose/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibertyParse.yy
179 lines (152 loc) · 3.44 KB
/
LibertyParse.yy
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
%{
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2020, 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 <stdlib.h>
#include <string.h>
#include "StringUtil.hh"
#include "liberty/LibertyParser.hh"
int LibertyLex_lex();
#define LibertyParse_lex LibertyLex_lex
// Use yacc generated parser errors.
#define YYERROR_VERBOSE
%}
%union {
char *string;
float number;
int line;
sta::LibertyAttrValue *attr_value;
sta::LibertyAttrValueSeq *attr_values;
sta::LibertyGroup *group;
sta::LibertyStmt *stmt;
}
%token <number> FLOAT
%token <string> STRING KEYWORD
%type <stmt> statement complex_attr simple_attr variable group file
%type <attr_values> attr_values
%type <attr_value> attr_value simple_attr_value
%type <string> string
%type <line> line
%type <number> volt_expr volt_token
%start file
%{
%}
%%
file:
group
;
group:
KEYWORD '(' ')' line '{'
{ sta::libertyGroupBegin($1, NULL, $4); }
'}' semi_opt
{ $$ = sta::libertyGroupEnd(); }
| KEYWORD '(' ')' line '{'
{ sta::libertyGroupBegin($1, NULL, $4); }
statements '}' semi_opt
{ $$ = sta::libertyGroupEnd(); }
| KEYWORD '(' attr_values ')' line '{'
{ sta::libertyGroupBegin($1, $3, $5); }
'}' semi_opt
{ $$ = sta::libertyGroupEnd(); }
| KEYWORD '(' attr_values ')' line '{'
{ sta::libertyGroupBegin($1, $3, $5); }
statements '}' semi_opt
{ $$ = sta::libertyGroupEnd(); }
;
line: /* empty */
{ $$ = sta::libertyLine(); }
;
statements:
statement
| statements statement
;
statement:
simple_attr
| complex_attr
| group
| variable
;
simple_attr:
KEYWORD ':' simple_attr_value line semi_opt
{ $$ = sta::makeLibertySimpleAttr($1, $3, $4); }
;
simple_attr_value:
attr_value
| volt_expr
{ $$ = static_cast<sta::LibertyAttrValue*>(NULL); }
/* Unquoted NOT function. */
/* clocked_on : !CP; */
| '!' string
{ $$ = sta::makeLibertyStringAttrValue(sta::stringPrint("!%s", $2)); sta::stringDelete($2); }
;
complex_attr:
KEYWORD '(' ')' line semi_opt
{ $$ = sta::makeLibertyComplexAttr($1, NULL, $4); }
| KEYWORD '(' attr_values ')' line semi_opt
{ $$ = sta::makeLibertyComplexAttr($1, $3, $5); }
;
attr_values:
attr_value
{ $$ = new sta::LibertyAttrValueSeq;
$$->push_back($1);
}
| attr_values ',' attr_value
{ $1->push_back($3);
$$ = $1;
}
| attr_values attr_value
{ $1->push_back($2);
$$ = $1;
}
;
variable:
string '=' FLOAT line semi_opt
{ $$ = sta::makeLibertyVariable($1, $3, $4); }
;
string:
STRING
{ $$ = $1; }
| KEYWORD
{ $$ = $1; }
;
attr_value:
FLOAT
{ $$ = sta::makeLibertyFloatAttrValue($1); }
| string
{ $$ = sta::makeLibertyStringAttrValue($1); }
;
/* Voltage expressions are ignored. */
volt_expr:
volt_token expr_op volt_token
| volt_expr expr_op volt_token
;
volt_token:
FLOAT
| KEYWORD
{ sta::stringDelete($1);
$$ = 0.0;
}
;
expr_op:
'+'
| '-'
| '*'
| '/'
;
semi_opt:
/* empty */
| semi_opt ';'
;
%%