liberty parse unquoted functions

This commit is contained in:
James Cherry 2021-03-16 10:27:17 -07:00
parent d9b2af8587
commit 045b7a7c19
3 changed files with 88 additions and 30 deletions

View File

@ -256,7 +256,7 @@ flex_target(LibertyLex ${STA_HOME}/liberty/LibertyLex.ll ${CMAKE_CURRENT_BINARY_
COMPILE_FLAGS --prefix=LibertyLex_ COMPILE_FLAGS --prefix=LibertyLex_
) )
bison_target(LibertyParser ${STA_HOME}/liberty/LibertyParse.yy ${CMAKE_CURRENT_BINARY_DIR}/LibertyParse.cc bison_target(LibertyParser ${STA_HOME}/liberty/LibertyParse.yy ${CMAKE_CURRENT_BINARY_DIR}/LibertyParse.cc
COMPILE_FLAGS --name-prefix=LibertyParse_ COMPILE_FLAGS "--name-prefix=LibertyParse_ -v"
) )
add_flex_bison_dependency(LibertyLex LibertyParser) add_flex_bison_dependency(LibertyLex LibertyParser)

View File

@ -14,7 +14,7 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -26,27 +26,35 @@ int LibertyLex_lex();
// Use yacc generated parser errors. // Use yacc generated parser errors.
#define YYERROR_VERBOSE #define YYERROR_VERBOSE
#define YYDEBUG 1
%} %}
%union { %union {
char *string; char *string;
float number; float number;
int line; int line;
char ch;
sta::LibertyAttrValue *attr_value; sta::LibertyAttrValue *attr_value;
sta::LibertyAttrValueSeq *attr_values; sta::LibertyAttrValueSeq *attr_values;
sta::LibertyGroup *group; sta::LibertyGroup *group;
sta::LibertyStmt *stmt; sta::LibertyStmt *stmt;
} }
%left '+' '|'
%left '*' '&'
%left '^'
%left '!'
%token <number> FLOAT %token <number> FLOAT
%token <string> STRING KEYWORD %token <string> STRING KEYWORD
%type <stmt> statement complex_attr simple_attr variable group file %type <stmt> statement complex_attr simple_attr variable group file
%type <attr_values> attr_values %type <attr_values> attr_values
%type <attr_value> attr_value simple_attr_value %type <attr_value> attr_value
%type <string> string %type <string> string expr expr_term expr_term1 volt_expr
%type <line> line %type <line> line
%type <number> volt_expr volt_token %type <ch> expr_op volt_op
%start file %start file
@ -61,11 +69,11 @@ file:
group: group:
KEYWORD '(' ')' line '{' KEYWORD '(' ')' line '{'
{ sta::libertyGroupBegin($1, NULL, $4); } { sta::libertyGroupBegin($1, nullptr, $4); }
'}' semi_opt '}' semi_opt
{ $$ = sta::libertyGroupEnd(); } { $$ = sta::libertyGroupEnd(); }
| KEYWORD '(' ')' line '{' | KEYWORD '(' ')' line '{'
{ sta::libertyGroupBegin($1, NULL, $4); } { sta::libertyGroupBegin($1, nullptr, $4); }
statements '}' semi_opt statements '}' semi_opt
{ $$ = sta::libertyGroupEnd(); } { $$ = sta::libertyGroupEnd(); }
| KEYWORD '(' attr_values ')' line '{' | KEYWORD '(' attr_values ')' line '{'
@ -95,23 +103,13 @@ statement:
; ;
simple_attr: simple_attr:
KEYWORD ':' simple_attr_value line semi_opt KEYWORD ':' attr_value line semi_opt
{ $$ = sta::makeLibertySimpleAttr($1, $3, $4); } { $$ = 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: complex_attr:
KEYWORD '(' ')' line semi_opt KEYWORD '(' ')' line semi_opt
{ $$ = sta::makeLibertyComplexAttr($1, NULL, $4); } { $$ = sta::makeLibertyComplexAttr($1, nullptr, $4); }
| KEYWORD '(' attr_values ')' line semi_opt | KEYWORD '(' attr_values ')' line semi_opt
{ $$ = sta::makeLibertyComplexAttr($1, $3, $5); } { $$ = sta::makeLibertyComplexAttr($1, $3, $5); }
; ;
@ -146,29 +144,86 @@ string:
attr_value: attr_value:
FLOAT FLOAT
{ $$ = sta::makeLibertyFloatAttrValue($1); } { $$ = sta::makeLibertyFloatAttrValue($1); }
| string | expr
{ $$ = sta::makeLibertyStringAttrValue($1); }
| volt_expr
{ $$ = sta::makeLibertyStringAttrValue($1); } { $$ = sta::makeLibertyStringAttrValue($1); }
; ;
/* Voltage expressions are ignored. */ /* Voltage expressions are ignored. */
/* Crafted to avoid conflicts with expr */
volt_expr: volt_expr:
volt_token expr_op volt_token FLOAT volt_op FLOAT
| volt_expr expr_op volt_token { $$ = sta::stringPrint("%e%c%e", $1, $2, $3); }
| string volt_op FLOAT
{ $$ = sta::stringPrint("%s%c%e", $1, $2, $3);
sta::stringDelete($1);
}
| FLOAT volt_op string
{ $$ = sta::stringPrint("%e%c%s", $1, $2, $3);
sta::stringDelete($3);
}
| volt_expr volt_op FLOAT
{ $$ = sta::stringPrint("%s%c%e", $1, $2, $3);
sta::stringDelete($1);
}
;
volt_op:
'+'
{ $$ = '+'; }
| '-'
{ $$ = '-'; }
| '*'
{ $$ = '*'; }
| '/'
{ $$ = '/'; }
; ;
volt_token: expr:
FLOAT expr_term1
| KEYWORD | expr_term1 expr_op expr
{ sta::stringDelete($1); { $$ = sta::stringPrint("%s%c%s", $1, $2, $3);
$$ = 0.0; sta::stringDelete($1);
} sta::stringDelete($3);
}
;
expr_term:
string
| '0'
{ $$ = sta::stringPrint("0"); }
| '1'
{ $$ = sta::stringPrint("1"); }
| '(' expr ')'
{ $$ = sta::stringPrint("(%s)", $2);
sta::stringDelete($2);
}
;
expr_term1:
expr_term
| '!' expr_term
{ $$ = sta::stringPrint("!%s", $2);
sta::stringDelete($2);
}
| expr_term '\''
{ $$ = sta::stringPrint("%s'", $1);
sta::stringDelete($1);
}
; ;
expr_op: expr_op:
'+' '+'
| '-' { $$ = '+'; }
| '|'
{ $$ = '|'; }
| '*' | '*'
| '/' { $$ = '*'; }
| '&'
{ $$ = '&'; }
| '^'
{ $$ = '^'; }
; ;
semi_opt: semi_opt:

View File

@ -40,6 +40,8 @@
#include "ParseBus.hh" #include "ParseBus.hh"
#include "Network.hh" #include "Network.hh"
extern int LibertyParse_debug;
namespace sta { namespace sta {
static void static void
@ -138,6 +140,7 @@ LibertyReader::readLibertyFile(const char *filename,
have_slew_upper_threshold_[rf_index] = false; have_slew_upper_threshold_[rf_index] = false;
} }
//::LibertyParse_debug = 1;
parseLibertyFile(filename, this, report_); parseLibertyFile(filename, this, report_);
return library_; return library_;
} }