From cfedcf9205a2948f3eb88ff98d0ed48d2678f48e Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 24 Apr 2019 16:00:53 +0100 Subject: [PATCH 1/1] first commit --- .gitignore | 4 + lexor.lex | 1636 ++++++++++ lexor.py | 2002 +++++++++++++ parse.py | 1491 ++++++++++ parse.y | 6993 +++++++++++++++++++++++++++++++++++++++++++ parse_sv.py | 8225 +++++++++++++++++++++++++++++++++++++++++++++++++++ svparse.py | 23 + 7 files changed, 20374 insertions(+) create mode 100644 .gitignore create mode 100644 lexor.lex create mode 100644 lexor.py create mode 100644 parse.py create mode 100644 parse.y create mode 100644 parse_sv.py create mode 100644 svparse.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d58d739 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.pyc +.*.sw? +parsetab.py* +parsetok.py* diff --git a/lexor.lex b/lexor.lex new file mode 100644 index 0000000..b99329b --- /dev/null +++ b/lexor.lex @@ -0,0 +1,1636 @@ +%{ +/* + * Copyright (c) 1998-2017 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +# include "config.h" + + //# define YYSTYPE lexval + +# include +# include "compiler.h" +# include "parse_misc.h" +# include "parse_api.h" +# include "parse.h" +# include +# include +# include "lexor_keyword.h" +# include "discipline.h" +# include + +# define YY_USER_INIT reset_lexor(); +# define yylval VLlval + +# define YY_NO_INPUT + +/* + * Lexical location information is passed in the yylloc variable to th + * parser. The file names, strings, are kept in a list so that I can + * re-use them. The set_file_name function will return a pointer to + * the name as it exists in the list (and delete the passed string.) + * If the name is new, it will be added to the list. + */ +extern YYLTYPE yylloc; + +char* strdupnew(char const *str) +{ + return str ? strcpy(new char [strlen(str)+1], str) : 0; +} + +static const char* set_file_name(char*text) +{ + perm_string path = filename_strings.make(text); + delete[]text; + + /* Check this file name with the list of library file + names. If there is a match, then turn on the + pform_library_flag. This is how the parser knows that + modules declared in this file are library modules. */ + pform_library_flag = library_file_map[path]; + return path; +} + +void reset_lexor(); +static void line_directive(); +static void line_directive2(); +static void reset_all(); + +verinum*make_unsized_binary(const char*txt); +verinum*make_undef_highz_dec(const char*txt); +verinum*make_unsized_dec(const char*txt); +verinum*make_unsized_octal(const char*txt); +verinum*make_unsized_hex(const char*txt); + +static int dec_buf_div2(char *buf); + +static void process_timescale(const char*txt); +static void process_ucdrive(const char*txt); + +static list keyword_mask_stack; + +static int comment_enter; +static bool in_module = false; +static bool in_UDP = false; +bool in_celldefine = false; +UCDriveType uc_drive = UCD_NONE; + +/* + * The parser sometimes needs to indicate to the lexor that the next + * identifier needs to be understood in the context of a package. The + * parser feeds back that left context with calls to the + * lex_in_package_scope. + */ +static PPackage* in_package_scope = 0; +void lex_in_package_scope(PPackage*pkg) +{ + in_package_scope = pkg; +} + +%} + +/* +%x CCOMMENT +%x PCOMMENT +%x LCOMMENT +%x CSTRING +%s UDPTABLE +%x PPTIMESCALE +%x PPUCDRIVE +%x PPDEFAULT_NETTYPE +%x PPBEGIN_KEYWORDS +%s EDGES +%x REAL_SCALE +*/ + +W [ \t\b\f\r]+ + +S [afpnumkKMGT] + +TU [munpf] + +%% + + /* Recognize the various line directives. */ +^"#line"[ \t]+.+ { line_directive(); } +^[ \t]?"`line"[ \t]+.+ { line_directive2(); } + +[ \t\b\f\r] { ; } +\n { yylloc.first_line += 1; } + + /* C++ style comments start with / / and run to the end of the + current line. These are very easy to handle. The meta-comments + format is a little more tricky to handle, but do what we can. */ + + /* The lexor detects "// synthesis translate_on/off" meta-comments, + we handle them here by turning on/off a flag. The pform uses + that flag to attach implicit attributes to "initial" and + "always" statements. */ + +"//"{W}*"synthesis"{W}+"translate_on"{W}*\n { pform_mc_translate_on(true); } +"//"{W}*"synthesis"{W}+"translate_off"{W}*\n { pform_mc_translate_on(false); } +"//" { comment_enter = YY_START; BEGIN(LCOMMENT); } +. { yymore(); } +\n { yylloc.first_line += 1; BEGIN(comment_enter); } + + + /* The contents of C-style comments are ignored, like white space. */ + +"/*" { comment_enter = YY_START; BEGIN(CCOMMENT); } +. { ; } +\n { yylloc.first_line += 1; } +"*/" { BEGIN(comment_enter); } + + +"(*" { return K_PSTAR; } +"*)" { return K_STARP; } +".*" { return K_DOTSTAR; } +"<<" { return K_LS; } +"<<<" { return K_LS; /* Note: Functionally, <<< is the same as <<. */} +">>" { return K_RS; } +">>>" { return K_RSS; } +"**" { return K_POW; } +"<=" { return K_LE; } +">=" { return K_GE; } +"=>" { return K_EG; } +"+=>"|"-=>" { + /* + * Resolve the ambiguity between the += assignment + * operator and +=> polarity edge path operator + * + * +=> should be treated as two separate tokens '+' and + * '=>' (K_EG), therefore we only consume the first + * character of the matched pattern i.e. either + or - + * and push back the rest of the matches text (=>) in + * the input stream. + */ + yyless(1); + return yytext[0]; + } +"*>" { return K_SG; } +"==" { return K_EQ; } +"!=" { return K_NE; } +"===" { return K_CEQ; } +"!==" { return K_CNE; } +"==?" { return K_WEQ; } +"!=?" { return K_WNE; } +"||" { return K_LOR; } +"&&" { return K_LAND; } +"&&&" { return K_TAND; } +"~|" { return K_NOR; } +"~^" { return K_NXOR; } +"^~" { return K_NXOR; } +"~&" { return K_NAND; } +"->" { return K_TRIGGER; } +"+:" { return K_PO_POS; } +"-:" { return K_PO_NEG; } +"<+" { return K_CONTRIBUTE; } +"+=" { return K_PLUS_EQ; } +"-=" { return K_MINUS_EQ; } +"*=" { return K_MUL_EQ; } +"/=" { return K_DIV_EQ; } +"%=" { return K_MOD_EQ; } +"&=" { return K_AND_EQ; } +"|=" { return K_OR_EQ; } +"^=" { return K_XOR_EQ; } +"<<=" { return K_LS_EQ; } +">>=" { return K_RS_EQ; } +"<<<=" { return K_LS_EQ; } +">>>=" { return K_RSS_EQ; } +"++" { return K_INCR; } +"--" {return K_DECR; } +"'{" { return K_LP; } +"::" { return K_SCOPE_RES; } + + /* Watch out for the tricky case of (*). Cannot parse this as "(*" + and ")", but since I know that this is really ( * ), replace it + with "*" and return that. */ +"("{W}*"*"{W}*")" { return '*'; } + +"]" { BEGIN(0); return yytext[0]; } +[}{;:\[\],()#=.@&!?<>%|^~+*/-] { return yytext[0]; } + +\" { BEGIN(CSTRING); } +\\\\ { yymore(); /* Catch \\, which is a \ escaping itself */ } +\\\" { yymore(); /* Catch \", which is an escaped quote */ } +\n { BEGIN(0); + yylval.text = strdupnew(yytext); + VLerror(yylloc, "Missing close quote of string."); + yylloc.first_line += 1; + return STRING; } +\" { BEGIN(0); + yylval.text = strdupnew(yytext); + yylval.text[strlen(yytext)-1] = 0; + return STRING; } +. { yymore(); } + + /* The UDP Table is a unique lexical environment. These are most + tokens that we can expect in a table. */ +\(\?0\) { return '_'; } +\(\?1\) { return '+'; } +\(\?[xX]\) { return '%'; } +\(\?\?\) { return '*'; } +\(01\) { return 'r'; } +\(0[xX]\) { return 'Q'; } +\(b[xX]\) { return 'q'; } +\(b0\) { return 'f'; /* b0 is 10|00, but only 10 is meaningful */} +\(b1\) { return 'r'; /* b1 is 11|01, but only 01 is meaningful */} +\(0\?\) { return 'P'; } +\(10\) { return 'f'; } +\(1[xX]\) { return 'M'; } +\(1\?\) { return 'N'; } +\([xX]0\) { return 'F'; } +\([xX]1\) { return 'R'; } +\([xX]\?\) { return 'B'; } +[bB] { return 'b'; } +[lL] { return 'l'; /* IVL extension */ } +[hH] { return 'h'; /* IVL extension */ } +[fF] { return 'f'; } +[rR] { return 'r'; } +[xX] { return 'x'; } +[nN] { return 'n'; } +[pP] { return 'p'; } +[01\?\*\-:;] { return yytext[0]; } + +"01" { return K_edge_descriptor; } +"0x" { return K_edge_descriptor; } +"0z" { return K_edge_descriptor; } +"10" { return K_edge_descriptor; } +"1x" { return K_edge_descriptor; } +"1z" { return K_edge_descriptor; } +"x0" { return K_edge_descriptor; } +"x1" { return K_edge_descriptor; } +"z0" { return K_edge_descriptor; } +"z1" { return K_edge_descriptor; } + +[a-zA-Z_][a-zA-Z0-9$_]* { + int rc = lexor_keyword_code(yytext, yyleng); + switch (rc) { + case IDENTIFIER: + yylval.text = strdupnew(yytext); + if (strncmp(yylval.text,"PATHPULSE$", 10) == 0) + rc = PATHPULSE_IDENTIFIER; + break; + + case K_edge: + BEGIN(EDGES); + break; + + case K_module: + case K_macromodule: + in_module = true; + break; + + case K_endmodule: + in_module = false; + break; + + case K_primitive: + in_UDP = true; + break; + + case K_endprimitive: + in_UDP = false; + break; + + case K_table: + BEGIN(UDPTABLE); + break; + + default: + yylval.text = 0; + break; + } + + /* Special case: If this is part of a scoped name, then check + the package for identifier details. For example, if the + source file is foo::bar, the parse.y will note the + PACKAGE_IDENTIFIER and "::" token and mark the + "in_package_scope" variable. Then this lexor will see the + identifier here and interpret it in the package scope. */ + if (in_package_scope) { + if (rc == IDENTIFIER) { + if (data_type_t*type = pform_test_type_identifier(in_package_scope, yylval.text)) { + yylval.type_identifier.text = yylval.text; + yylval.type_identifier.type = type; + rc = TYPE_IDENTIFIER; + } + } + in_package_scope = 0; + return rc; + } + + /* If this identifier names a discipline, then return this as + a DISCIPLINE_IDENTIFIER and return the discipline as the + value instead. */ + if (rc == IDENTIFIER && gn_verilog_ams_flag) { + perm_string tmp = lex_strings.make(yylval.text); + map::iterator cur = disciplines.find(tmp); + if (cur != disciplines.end()) { + delete[]yylval.text; + yylval.discipline = (*cur).second; + rc = DISCIPLINE_IDENTIFIER; + } + } + + /* If this identifier names a previously declared package, then + return this as a PACKAGE_IDENTIFIER instead. */ + if (rc == IDENTIFIER && gn_system_verilog()) { + if (PPackage*pkg = pform_test_package_identifier(yylval.text)) { + delete[]yylval.text; + yylval.package = pkg; + rc = PACKAGE_IDENTIFIER; + } + } + + /* If this identifier names a previously declared type, then + return this as a TYPE_IDENTIFIER instead. */ + if (rc == IDENTIFIER && gn_system_verilog()) { + if (data_type_t*type = pform_test_type_identifier(yylval.text)) { + yylval.type_identifier.text = yylval.text; + yylval.type_identifier.type = type; + rc = TYPE_IDENTIFIER; + } + } + + return rc; + } + + +\\[^ \t\b\f\r\n]+ { + yylval.text = strdupnew(yytext+1); + if (gn_system_verilog()) { + if (PPackage*pkg = pform_test_package_identifier(yylval.text)) { + delete[]yylval.text; + yylval.package = pkg; + return PACKAGE_IDENTIFIER; + } + } + if (gn_system_verilog()) { + if (data_type_t*type = pform_test_type_identifier(yylval.text)) { + yylval.type_identifier.text = yylval.text; + yylval.type_identifier.type = type; + return TYPE_IDENTIFIER; + } + } + return IDENTIFIER; + } + +\$([a-zA-Z0-9$_]+) { + /* The 1364-1995 timing checks. */ + if (strcmp(yytext,"$hold") == 0) + return K_Shold; + if (strcmp(yytext,"$nochange") == 0) + return K_Snochange; + if (strcmp(yytext,"$period") == 0) + return K_Speriod; + if (strcmp(yytext,"$recovery") == 0) + return K_Srecovery; + if (strcmp(yytext,"$setup") == 0) + return K_Ssetup; + if (strcmp(yytext,"$setuphold") == 0) + return K_Ssetuphold; + if (strcmp(yytext,"$skew") == 0) + return K_Sskew; + if (strcmp(yytext,"$width") == 0) + return K_Swidth; + /* The new 1364-2001 timing checks. */ + if (strcmp(yytext,"$fullskew") == 0) + return K_Sfullskew; + if (strcmp(yytext,"$recrem") == 0) + return K_Srecrem; + if (strcmp(yytext,"$removal") == 0) + return K_Sremoval; + if (strcmp(yytext,"$timeskew") == 0) + return K_Stimeskew; + + if (strcmp(yytext,"$attribute") == 0) + return KK_attribute; + + if (gn_system_verilog() && strcmp(yytext,"$unit") == 0) { + yylval.package = pform_units.back(); + return PACKAGE_IDENTIFIER; + } + + yylval.text = strdupnew(yytext); + return SYSTEM_IDENTIFIER; } + + +\'[sS]?[dD][ \t]*[0-9][0-9_]* { + yylval.number = make_unsized_dec(yytext); + return BASED_NUMBER; +} +\'[sS]?[dD][ \t]*[xzXZ?]_* { + yylval.number = make_undef_highz_dec(yytext); + return BASED_NUMBER; +} +\'[sS]?[bB][ \t]*[0-1xzXZ?][0-1xzXZ?_]* { + yylval.number = make_unsized_binary(yytext); + return BASED_NUMBER; +} +\'[sS]?[oO][ \t]*[0-7xzXZ?][0-7xzXZ?_]* { + yylval.number = make_unsized_octal(yytext); + return BASED_NUMBER; +} +\'[sS]?[hH][ \t]*[0-9a-fA-FxzXZ?][0-9a-fA-FxzXZ?_]* { + yylval.number = make_unsized_hex(yytext); + return BASED_NUMBER; +} +\'[01xzXZ] { + if (!gn_system_verilog()) { + cerr << yylloc.text << ":" << yylloc.first_line << ": warning: " + << "Using SystemVerilog 'N bit vector. Use at least " + << "-g2005-sv to remove this warning." << endl; + } + generation_t generation_save = generation_flag; + generation_flag = GN_VER2005_SV; + yylval.number = make_unsized_binary(yytext); + generation_flag = generation_save; + return UNBASED_NUMBER; } + + /* Decimal numbers are the usual. But watch out for the UDPTABLE + mode, where there are no decimal numbers. Reject the match if we + are in the UDPTABLE state. */ +[0-9][0-9_]* { + if (YY_START==UDPTABLE) { + REJECT; + } else { + yylval.number = make_unsized_dec(yytext); + based_size = yylval.number->as_ulong(); + return DEC_NUMBER; + } +} + + /* This rule handles scaled time values for SystemVerilog. */ +[0-9][0-9_]*(\.[0-9][0-9_]*)?{TU}?s { + if (gn_system_verilog()) { + yylval.text = strdupnew(yytext); + return TIME_LITERAL; + } else REJECT; } + + /* These rules handle the scaled real literals from Verilog-AMS. The + value is a number with a single letter scale factor. If + verilog-ams is not enabled, then reject this rule. If it is + enabled, then collect the scale and use it to scale the value. */ +[0-9][0-9_]*\.[0-9][0-9_]*/{S} { + if (!gn_verilog_ams_flag) REJECT; + BEGIN(REAL_SCALE); + yymore(); } + +[0-9][0-9_]*/{S} { + if (!gn_verilog_ams_flag) REJECT; + BEGIN(REAL_SCALE); + yymore(); } + +{S} { + size_t token_len = strlen(yytext); + char*tmp = new char[token_len + 5]; + int scale = 0; + strcpy(tmp, yytext); + switch (tmp[token_len-1]) { + case 'a': scale = -18; break; /* atto- */ + case 'f': scale = -15; break; /* femto- */ + case 'p': scale = -12; break; /* pico- */ + case 'n': scale = -9; break; /* nano- */ + case 'u': scale = -6; break; /* micro- */ + case 'm': scale = -3; break; /* milli- */ + case 'k': scale = 3; break; /* kilo- */ + case 'K': scale = 3; break; /* kilo- */ + case 'M': scale = 6; break; /* mega- */ + case 'G': scale = 9; break; /* giga- */ + case 'T': scale = 12; break; /* tera- */ + default: assert(0); break; + } + snprintf(tmp+token_len-1, 5, "e%d", scale); + yylval.realtime = new verireal(tmp); + delete[]tmp; + + BEGIN(0); + return REALTIME; } + +[0-9][0-9_]*\.[0-9][0-9_]*([Ee][+-]?[0-9][0-9_]*)? { + yylval.realtime = new verireal(yytext); + return REALTIME; } + +[0-9][0-9_]*[Ee][+-]?[0-9][0-9_]* { + yylval.realtime = new verireal(yytext); + return REALTIME; } + + + /* Notice and handle the `timescale directive. */ + +^{W}?`timescale { BEGIN(PPTIMESCALE); } +.* { process_timescale(yytext); } +\n { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`timescale directive can not be inside a module " + "definition." << endl; + error_count += 1; + } + yylloc.first_line += 1; + BEGIN(0); } + + /* Notice and handle the `celldefine and `endcelldefine directives. */ + +^{W}?`celldefine{W}? { in_celldefine = true; } +^{W}?`endcelldefine{W}? { in_celldefine = false; } + + /* Notice and handle the resetall directive. */ + +^{W}?`resetall{W}? { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`resetall directive can not be inside a module " + "definition." << endl; + error_count += 1; + } else if (in_UDP) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`resetall directive can not be inside a UDP " + "definition." << endl; + error_count += 1; + } else { + reset_all(); + } } + + /* Notice and handle the `unconnected_drive directive. */ +^{W}?`unconnected_drive { BEGIN(PPUCDRIVE); } +.* { process_ucdrive(yytext); } +\n { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`unconnected_drive directive can not be inside a " + "module definition." << endl; + error_count += 1; + } + yylloc.first_line += 1; + BEGIN(0); } + +^{W}?`nounconnected_drive{W}? { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`nounconnected_drive directive can not be inside a " + "module definition." << endl; + error_count += 1; + } + uc_drive = UCD_NONE; } + + /* These are directives that I do not yet support. I think that IVL + should handle these, not an external preprocessor. */ + /* From 1364-2005 Chapter 19. */ +^{W}?`pragme{W}?.* { } + + /* From 1364-2005 Annex D. */ +^{W}?`default_decay_time{W}?.* { } +^{W}?`default_trireg_strength{W}?.* { } +^{W}?`delay_mode_distributed{W}?.* { } +^{W}?`delay_mode_path{W}?.* { } +^{W}?`delay_mode_unit{W}?.* { } +^{W}?`delay_mode_zero{W}?.* { } + + /* From other places. */ +^{W}?`disable_portfaults{W}?.* { } +^{W}?`enable_portfaults{W}?.* { } +`endprotect { } +^{W}?`nosuppress_faults{W}?.* { } +`protect { } +^{W}?`suppress_faults{W}?.* { } +^{W}?`uselib{W}?.* { } + +^{W}?`begin_keywords{W}? { BEGIN(PPBEGIN_KEYWORDS); } + +\"[a-zA-Z0-9 -\.]*\".* { + keyword_mask_stack.push_front(lexor_keyword_mask); + + char*word = yytext+1; + char*tail = strchr(word, '"'); + tail[0] = 0; + if (strcmp(word,"1364-1995") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995; + } else if (strcmp(word,"1364-2001") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG; + } else if (strcmp(word,"1364-2001-noconfig") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001; + } else if (strcmp(word,"1364-2005") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005; + } else if (strcmp(word,"1800-2005") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_1800_2005; + } else if (strcmp(word,"1800-2009") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_1800_2005 + |GN_KEYWORDS_1800_2009; + } else if (strcmp(word,"1800-2012") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_1800_2005 + |GN_KEYWORDS_1800_2009 + |GN_KEYWORDS_1800_2012; + } else if (strcmp(word,"VAMS-2.3") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_VAMS_2_3; + } else { + fprintf(stderr, "%s:%d: Ignoring unknown keywords string: %s\n", + yylloc.text, yylloc.first_line, word); + } + BEGIN(0); + } + +.* { + fprintf(stderr, "%s:%d: Malformed keywords specification: %s\n", + yylloc.text, yylloc.first_line, yytext); + BEGIN(0); + } + +^{W}?`end_keywords{W}?.* { + if (!keyword_mask_stack.empty()) { + lexor_keyword_mask = keyword_mask_stack.front(); + keyword_mask_stack.pop_front(); + } else { + fprintf(stderr, "%s:%d: Mismatched end_keywords directive\n", + yylloc.text, yylloc.first_line); + } + } + + /* Notice and handle the default_nettype directive. The lexor + detects the default_nettype keyword, and the second part of the + rule collects the rest of the line and processes it. We only need + to look for the first work, and interpret it. */ + +`default_nettype{W}? { BEGIN(PPDEFAULT_NETTYPE); } +.* { + NetNet::Type net_type; + size_t wordlen = strcspn(yytext, " \t\f\r\n"); + yytext[wordlen] = 0; + /* Add support for other wire types and better error detection. */ + if (strcmp(yytext,"wire") == 0) { + net_type = NetNet::WIRE; + + } else if (strcmp(yytext,"tri") == 0) { + net_type = NetNet::TRI; + + } else if (strcmp(yytext,"tri0") == 0) { + net_type = NetNet::TRI0; + + } else if (strcmp(yytext,"tri1") == 0) { + net_type = NetNet::TRI1; + + } else if (strcmp(yytext,"wand") == 0) { + net_type = NetNet::WAND; + + } else if (strcmp(yytext,"triand") == 0) { + net_type = NetNet::TRIAND; + + } else if (strcmp(yytext,"wor") == 0) { + net_type = NetNet::WOR; + + } else if (strcmp(yytext,"trior") == 0) { + net_type = NetNet::TRIOR; + + } else if (strcmp(yytext,"none") == 0) { + net_type = NetNet::NONE; + + } else { + cerr << yylloc.text << ":" << yylloc.first_line + << ": error: Net type " << yytext + << " is not a valid (or supported)" + << " default net type." << endl; + net_type = NetNet::WIRE; + error_count += 1; + } + pform_set_default_nettype(net_type, yylloc.text, yylloc.first_line); + } +\n { + yylloc.first_line += 1; + BEGIN(0); } + + + /* These are directives that are not supported by me and should have + been handled by an external preprocessor such as ivlpp. */ + +^{W}?`define{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `define not supported. Use an external preprocessor." + << endl; + } + +^{W}?`else{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `else not supported. Use an external preprocessor." + << endl; + } + +^{W}?`elsif{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `elsif not supported. Use an external preprocessor." + << endl; + } + +^{W}?`endif{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `endif not supported. Use an external preprocessor." + << endl; + } + +^{W}?`ifdef{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `ifdef not supported. Use an external preprocessor." + << endl; + } + +^{W}?`ifndef{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `ifndef not supported. Use an external preprocessor." + << endl; + } + +^`include{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `include not supported. Use an external preprocessor." + << endl; + } + +^`undef{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `undef not supported. Use an external preprocessor." + << endl; + } + + +`{W} { cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + << "Stray tic (`) here. Perhaps you put white space" << endl; + cerr << yylloc.text << ":" << yylloc.first_line << ": : " + << "between the tic and preprocessor directive?" + << endl; + error_count += 1; } + +. { return yytext[0]; } + + /* Final catchall. something got lost or mishandled. */ + /* XXX Should we tell the user something about the lexical state? */ + +<*>.|\n { cerr << yylloc.text << ":" << yylloc.first_line + << ": error: unmatched character ("; + if (isprint(yytext[0])) + cerr << yytext[0]; + else + cerr << "hex " << hex << ((unsigned char) yytext[0]); + + cerr << ")" << endl; + error_count += 1; } + +%% + +/* + * The UDP state table needs some slightly different treatment by the + * lexor. The level characters are normally accepted as other things, + * so the parser needs to switch my mode when it believes in needs to. + */ +void lex_end_table() +{ + BEGIN(INITIAL); +} + +static unsigned truncate_to_integer_width(verinum::V*bits, unsigned size) +{ + if (size <= integer_width) return size; + + verinum::V pad = bits[size-1]; + if (pad == verinum::V1) pad = verinum::V0; + + for (unsigned idx = integer_width; idx < size; idx += 1) { + if (bits[idx] != pad) { + yywarn(yylloc, "Unsized numeric constant truncated to integer width."); + break; + } + } + return integer_width; +} + +verinum*make_unsized_binary(const char*txt) +{ + bool sign_flag = false; + bool single_flag = false; + const char*ptr = txt; + assert(*ptr == '\''); + ptr += 1; + + if (tolower(*ptr) == 's') { + sign_flag = true; + ptr += 1; + } + + assert((tolower(*ptr) == 'b') || gn_system_verilog()); + if (tolower(*ptr) == 'b') { + ptr += 1; + } else { + assert(sign_flag == false); + single_flag = true; + } + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + unsigned size = 0; + for (const char*idx = ptr ; *idx ; idx += 1) + if (*idx != '_') size += 1; + + if (size == 0) { + VLerror(yylloc, "Numeric literal has no digits in it."); + verinum*out = new verinum(); + out->has_sign(sign_flag); + out->is_single(single_flag); + return out; + } + + if ((based_size > 0) && (size > based_size)) yywarn(yylloc, + "extra digits given for sized binary constant."); + + verinum::V*bits = new verinum::V[size]; + + unsigned idx = size; + while (*ptr) { + switch (ptr[0]) { + case '0': + bits[--idx] = verinum::V0; + break; + case '1': + bits[--idx] = verinum::V1; + break; + case 'z': case 'Z': case '?': + bits[--idx] = verinum::Vz; + break; + case 'x': case 'X': + bits[--idx] = verinum::Vx; + break; + case '_': + break; + default: + fprintf(stderr, "%c\n", ptr[0]); + assert(0); + } + ptr += 1; + } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*out = new verinum(bits, size, false); + out->has_sign(sign_flag); + out->is_single(single_flag); + delete[]bits; + return out; +} + + +verinum*make_unsized_octal(const char*txt) +{ + bool sign_flag = false; + const char*ptr = txt; + assert(*ptr == '\''); + ptr += 1; + + if (tolower(*ptr) == 's') { + sign_flag = true; + ptr += 1; + } + + assert(tolower(*ptr) == 'o'); + ptr += 1; + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + unsigned size = 0; + for (const char*idx = ptr ; *idx ; idx += 1) + if (*idx != '_') size += 3; + + if (based_size > 0) { + int rem = based_size % 3; + if (rem != 0) based_size += 3 - rem; + if (size > based_size) yywarn(yylloc, + "extra digits given for sized octal constant."); + } + + verinum::V*bits = new verinum::V[size]; + + unsigned idx = size; + while (*ptr) { + unsigned val; + switch (ptr[0]) { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + val = *ptr - '0'; + bits[--idx] = (val&4) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&2) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&1) ? verinum::V1 : verinum::V0; + break; + case 'x': case 'X': + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + break; + case 'z': case 'Z': case '?': + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + break; + case '_': + break; + default: + assert(0); + } + ptr += 1; + } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*out = new verinum(bits, size, false); + out->has_sign(sign_flag); + delete[]bits; + return out; +} + + +verinum*make_unsized_hex(const char*txt) +{ + bool sign_flag = false; + const char*ptr = txt; + assert(*ptr == '\''); + ptr += 1; + + if (tolower(*ptr) == 's') { + sign_flag = true; + ptr += 1; + } + assert(tolower(*ptr) == 'h'); + + ptr += 1; + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + unsigned size = 0; + for (const char*idx = ptr ; *idx ; idx += 1) + if (*idx != '_') size += 4; + + if (based_size > 0) { + int rem = based_size % 4; + if (rem != 0) based_size += 4 - rem; + if (size > based_size) yywarn(yylloc, + "extra digits given for sized hex constant."); + } + + verinum::V*bits = new verinum::V[size]; + + unsigned idx = size; + while (*ptr) { + unsigned val; + switch (ptr[0]) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + val = *ptr - '0'; + bits[--idx] = (val&8) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&4) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&2) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&1) ? verinum::V1 : verinum::V0; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + val = tolower(*ptr) - 'a' + 10; + bits[--idx] = (val&8) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&4) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&2) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&1) ? verinum::V1 : verinum::V0; + break; + case 'x': case 'X': + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + break; + case 'z': case 'Z': case '?': + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + break; + case '_': + break; + default: + assert(0); + } + ptr += 1; + } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*out = new verinum(bits, size, false); + out->has_sign(sign_flag); + delete[]bits; + return out; +} + + +/* Divide the integer given by the string by 2. Return the remainder bit. */ +static int dec_buf_div2(char *buf) +{ + int partial; + int len = strlen(buf); + char *dst_ptr; + int pos; + + partial = 0; + pos = 0; + + /* dst_ptr overwrites buf, but all characters that are overwritten + were already used by the reader. */ + dst_ptr = buf; + + while(buf[pos] == '0') + ++pos; + + for(; pos= 2){ + *dst_ptr = partial/2 + '0'; + partial = partial & 1; + + ++dst_ptr; + } + else{ + *dst_ptr = '0'; + ++dst_ptr; + } + } + + // If result of division was zero string, it should remain that way. + // Don't eat the last zero... + if (dst_ptr == buf){ + *dst_ptr = '0'; + ++dst_ptr; + } + *dst_ptr = 0; + + return partial; +} + +/* Support a single x, z or ? as a decimal constant (from 1364-2005). */ +verinum* make_undef_highz_dec(const char* ptr) +{ + bool signed_flag = false; + + assert(*ptr == '\''); + /* The number may have decorations of the form 'sd, + possibly with space between the d and the . + Also, the 's' is optional, and marks the number as signed. */ + ptr += 1; + + if (tolower(*ptr) == 's') { + signed_flag = true; + ptr += 1; + } + + assert(tolower(*ptr) == 'd'); + ptr += 1; + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + /* Process the code. */ + verinum::V* bits = new verinum::V[1]; + switch (*ptr) { + case 'x': + case 'X': + bits[0] = verinum::Vx; + break; + case 'z': + case 'Z': + case '?': + bits[0] = verinum::Vz; + break; + default: + assert(0); + } + ptr += 1; + while (*ptr == '_') ptr += 1; + assert(*ptr == 0); + + verinum*out = new verinum(bits, 1, false); + out->has_sign(signed_flag); + delete[]bits; + return out; +} + +/* + * Making a decimal number is much easier than the other base numbers + * because there are no z or x values to worry about. It is much + * harder than other base numbers because the width needed in bits is + * hard to calculate. + */ + +verinum*make_unsized_dec(const char*ptr) +{ + char buf[4096]; + bool signed_flag = false; + unsigned idx; + + if (ptr[0] == '\'') { + /* The number has decorations of the form 'sd, + possibly with space between the d and the . + Also, the 's' is optional, and marks the number as + signed. */ + ptr += 1; + + if (tolower(*ptr) == 's') { + signed_flag = true; + ptr += 1; + } + + assert(tolower(*ptr) == 'd'); + ptr += 1; + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + } else { + /* ... or an undecorated decimal number is passed + it. These numbers are treated as signed decimal. */ + assert(isdigit(*ptr)); + signed_flag = true; + } + + + /* Copy the digits into a buffer that I can use to do in-place + decimal divides. */ + idx = 0; + while ((idx < sizeof buf) && (*ptr != 0)) { + if (*ptr == '_') { + ptr += 1; + continue; + } + + buf[idx++] = *ptr++; + } + + if (idx == sizeof buf) { + fprintf(stderr, "Ridiculously long" + " decimal constant will be truncated!\n"); + idx -= 1; + } + + buf[idx] = 0; + unsigned tmp_size = idx * 4 + 1; + verinum::V *bits = new verinum::V[tmp_size]; + + idx = 0; + while (idx < tmp_size) { + int rem = dec_buf_div2(buf); + bits[idx++] = (rem == 1) ? verinum::V1 : verinum::V0; + } + + assert(strcmp(buf, "0") == 0); + + /* Now calculate the minimum number of bits needed to + represent this unsigned number. */ + unsigned size = tmp_size; + while ((size > 1) && (bits[size-1] == verinum::V0)) + size -= 1; + + /* Now account for the signedness. Don't leave a 1 in the high + bit if this is a signed number. */ + if (signed_flag && (bits[size-1] == verinum::V1)) { + size += 1; + assert(size <= tmp_size); + } + + /* Since we never have the real number of bits that a decimal + number represents we do not check for extra bits. */ +// if (based_size > 0) { } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*res = new verinum(bits, size, false); + res->has_sign(signed_flag); + + delete[]bits; + return res; +} + +/* + * Convert the string to a time unit or precision. + * Returns true on failure. + */ +static bool get_timescale_const(const char *&cp, int &res, bool is_unit) +{ + /* Check for the 1 digit. */ + if (*cp != '1') { + if (is_unit) { + VLerror(yylloc, "Invalid `timescale unit constant " + "(1st digit)"); + } else { + VLerror(yylloc, "Invalid `timescale precision constant " + "(1st digit)"); + } + return true; + } + cp += 1; + + /* Check the number of zeros after the 1. */ + res = strspn(cp, "0"); + if (res > 2) { + if (is_unit) { + VLerror(yylloc, "Invalid `timescale unit constant " + "(number of zeros)"); + } else { + VLerror(yylloc, "Invalid `timescale precision constant " + "(number of zeros)"); + } + return true; + } + cp += res; + + /* Skip any space between the digits and the scaling string. */ + cp += strspn(cp, " \t"); + + /* Now process the scaling string. */ + if (strncmp("s", cp, 1) == 0) { + res -= 0; + cp += 1; + return false; + + } else if (strncmp("ms", cp, 2) == 0) { + res -= 3; + cp += 2; + return false; + + } else if (strncmp("us", cp, 2) == 0) { + res -= 6; + cp += 2; + return false; + + } else if (strncmp("ns", cp, 2) == 0) { + res -= 9; + cp += 2; + return false; + + } else if (strncmp("ps", cp, 2) == 0) { + res -= 12; + cp += 2; + return false; + + } else if (strncmp("fs", cp, 2) == 0) { + res -= 15; + cp += 2; + return false; + + } + + if (is_unit) { + VLerror(yylloc, "Invalid `timescale unit scale"); + } else { + VLerror(yylloc, "Invalid `timescale precision scale"); + } + return true; +} + + +/* + * process either a pull0 or a pull1. + */ +static void process_ucdrive(const char*txt) +{ + UCDriveType ucd = UCD_NONE; + const char*cp = txt + strspn(txt, " \t"); + + /* Skip the space after the `unconnected_drive directive. */ + if (cp == txt) { + VLerror(yylloc, "Space required after `unconnected_drive " + "directive."); + return; + } + + /* Check for the pull keyword. */ + if (strncmp("pull", cp, 4) != 0) { + VLerror(yylloc, "pull required for `unconnected_drive " + "directive."); + return; + } + cp += 4; + if (*cp == '0') ucd = UCD_PULL0; + else if (*cp == '1') ucd = UCD_PULL1; + else { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`unconnected_drive does not support 'pull" << *cp + << "'." << endl; + error_count += 1; + return; + } + cp += 1; + + /* Verify that only space and/or a single line comment is left. */ + cp += strspn(cp, " \t"); + if (strncmp(cp, "//", 2) != 0 && + (size_t)(cp-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid `unconnected_drive directive (extra " + "garbage after precision)."); + return; + } + + uc_drive = ucd; +} + +/* + * The timescale parameter has the form: + * " xs / xs" + */ +static void process_timescale(const char*txt) +{ + const char*cp = txt + strspn(txt, " \t"); + + /* Skip the space after the `timescale directive. */ + if (cp == txt) { + VLerror(yylloc, "Space required after `timescale directive."); + return; + } + + int unit = 0; + int prec = 0; + + /* Get the time units. */ + if (get_timescale_const(cp, unit, true)) return; + + /* Skip any space after the time units, the '/' and any + * space after the '/'. */ + cp += strspn(cp, " \t"); + if (*cp != '/') { + VLerror(yylloc, "`timescale separator '/' appears to be missing."); + return; + } + cp += 1; + cp += strspn(cp, " \t"); + + /* Get the time precision. */ + if (get_timescale_const(cp, prec, false)) return; + + /* Verify that only space and/or a single line comment is left. */ + cp += strspn(cp, " \t"); + if (strncmp(cp, "//", 2) != 0 && + (size_t)(cp-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid `timescale directive (extra garbage " + "after precision)."); + return; + } + + /* The time unit must be greater than or equal to the precision. */ + if (unit < prec) { + VLerror(yylloc, "error: `timescale unit must not be less than " + "the precision."); + return; + } + + pform_set_timescale(unit, prec, yylloc.text, yylloc.first_line); +} + +int yywrap() +{ + return 1; +} + +/* + * The line directive matches lines of the form #line "foo" N and + * calls this function. Here I parse out the file name and line + * number, and change the yylloc to suite. + */ +static void line_directive() +{ + char *cpr; + /* Skip any leading space. */ + char *cp = strchr(yytext, '#'); + /* Skip the #line directive. */ + assert(strncmp(cp, "#line", 5) == 0); + cp += 5; + /* Skip the space after the #line directive. */ + cp += strspn(cp, " \t"); + + /* Find the starting " and skip it. */ + char*fn_start = strchr(cp, '"'); + if (cp != fn_start) { + VLerror(yylloc, "Invalid #line directive (file name start)."); + return; + } + fn_start += 1; + + /* Find the last ". */ + char*fn_end = strrchr(fn_start, '"'); + if (!fn_end) { + VLerror(yylloc, "Invalid #line directive (file name end)."); + return; + } + + /* Copy the file name and assign it to yylloc. */ + char*buf = new char[fn_end-fn_start+1]; + strncpy(buf, fn_start, fn_end-fn_start); + buf[fn_end-fn_start] = 0; + + /* Skip the space after the file name. */ + cp = fn_end; + cp += 1; + cpr = cp; + cpr += strspn(cp, " \t"); + if (cp == cpr) { + VLerror(yylloc, "Invalid #line directive (missing space after " + "file name)."); + delete[] buf; + return; + } + cp = cpr; + + /* Get the line number and verify that it is correct. */ + unsigned long lineno = strtoul(cp, &cpr, 10); + if (cp == cpr) { + VLerror(yylloc, "Invalid line number for #line directive."); + delete[] buf; + return; + } + cp = cpr; + + /* Verify that only space is left. */ + cpr += strspn(cp, " \t"); + if ((size_t)(cpr-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid #line directive (extra garbage after " + "line number)."); + delete[] buf; + return; + } + + /* Now we can assign the new values to yyloc. */ + yylloc.text = set_file_name(buf); + yylloc.first_line = lineno; +} + +/* + * The line directive matches lines of the form `line N "foo" M and + * calls this function. Here I parse out the file name and line + * number, and change the yylloc to suite. M is ignored. + */ +static void line_directive2() +{ + char *cpr; + /* Skip any leading space. */ + char *cp = strchr(yytext, '`'); + /* Skip the `line directive. */ + assert(strncmp(cp, "`line", 5) == 0); + cp += 5; + + /* strtoul skips leading space. */ + unsigned long lineno = strtoul(cp, &cpr, 10); + if (cp == cpr) { + VLerror(yylloc, "Invalid line number for `line directive."); + return; + } + lineno -= 1; + cp = cpr; + + /* Skip the space between the line number and the file name. */ + cpr += strspn(cp, " \t"); + if (cp == cpr) { + VLerror(yylloc, "Invalid `line directive (missing space after " + "line number)."); + return; + } + cp = cpr; + + /* Find the starting " and skip it. */ + char*fn_start = strchr(cp, '"'); + if (cp != fn_start) { + VLerror(yylloc, "Invalid `line directive (file name start)."); + return; + } + fn_start += 1; + + /* Find the last ". */ + char*fn_end = strrchr(fn_start, '"'); + if (!fn_end) { + VLerror(yylloc, "Invalid `line directive (file name end)."); + return; + } + + /* Skip the space after the file name. */ + cp = fn_end + 1; + cpr = cp; + cpr += strspn(cp, " \t"); + if (cp == cpr) { + VLerror(yylloc, "Invalid `line directive (missing space after " + "file name)."); + return; + } + cp = cpr; + + /* Check that the level is correct, we do not need the level. */ + if (strspn(cp, "012") != 1) { + VLerror(yylloc, "Invalid level for `line directive."); + return; + } + cp += 1; + + /* Verify that only space and/or a single line comment is left. */ + cp += strspn(cp, " \t"); + if (strncmp(cp, "//", 2) != 0 && + (size_t)(cp-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid `line directive (extra garbage after " + "level)."); + return; + } + + /* Copy the file name and assign it and the line number to yylloc. */ + char*buf = new char[fn_end-fn_start+1]; + strncpy(buf, fn_start, fn_end-fn_start); + buf[fn_end-fn_start] = 0; + + yylloc.text = set_file_name(buf); + yylloc.first_line = lineno; +} + +/* + * Reset all compiler directives. This will be called when a `resetall + * directive is encountered or when a new compilation unit is started. + */ +static void reset_all() +{ + pform_set_default_nettype(NetNet::WIRE, yylloc.text, yylloc.first_line); + in_celldefine = false; + uc_drive = UCD_NONE; + pform_set_timescale(def_ts_units, def_ts_prec, 0, 0); +} + +extern FILE*vl_input; +void reset_lexor() +{ + yyrestart(vl_input); + yylloc.first_line = 1; + + /* Announce the first file name. */ + yylloc.text = set_file_name(strdupnew(vl_file.c_str())); + + if (separate_compilation) { + reset_all(); + if (!keyword_mask_stack.empty()) { + lexor_keyword_mask = keyword_mask_stack.back(); + keyword_mask_stack.clear(); + } + } +} + +/* + * Modern version of flex (>=2.5.9) can clean up the scanner data. + */ +void destroy_lexor() +{ +# ifdef FLEX_SCANNER +# if YY_FLEX_MAJOR_VERSION >= 2 && YY_FLEX_MINOR_VERSION >= 5 +# if YY_FLEX_MINOR_VERSION > 5 || defined(YY_FLEX_SUBMINOR_VERSION) && YY_FLEX_SUBMINOR_VERSION >= 9 + yylex_destroy(); +# endif +# endif +# endif +} diff --git a/lexor.py b/lexor.py new file mode 100644 index 0000000..d19aa3f --- /dev/null +++ b/lexor.py @@ -0,0 +1,2002 @@ +""" +%{ +/* + * Copyright (c) 1998-2017 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +""" + +from ply import lex + +""" +%x CCOMMENT +%x PCOMMENT +%x LCOMMENT +%x CSTRING +%s UDPTABLE +%x PPTIMESCALE +%x PPUCDRIVE +%x PPDEFAULT_NETTYPE +%x PPBEGIN_KEYWORDS +%s EDGES +%x REAL_SCALE + +# for timescales (regex subst patterns) +W = r'[ \t\b\f\r]+' +S = r'[afpnumkKMGT]' +TU r'[munpf]' + +%% + + /* Recognize the various line directives. */ +^"#line"[ \t]+.+ { line_directive(); } +^[ \t]?"`line"[ \t]+.+ { line_directive2(); } + +[ \t\b\f\r] { ; } +\n { yylloc.first_line += 1; } + + /* C++ style comments start with / / and run to the end of the + current line. These are very easy to handle. The meta-comments + format is a little more tricky to handle, but do what we can. */ + + /* The lexor detects "// synthesis translate_on/off" meta-comments, + we handle them here by turning on/off a flag. The pform uses + that flag to attach implicit attributes to "initial" and + "always" statements. */ + +"//"{W}*"synthesis"{W}+"translate_on"{W}*\n { pform_mc_translate_on(true); } +"//"{W}*"synthesis"{W}+"translate_off"{W}*\n { pform_mc_translate_on(false); } +"//" { comment_enter = YY_START; BEGIN(LCOMMENT); } +. { yymore(); } +\n { yylloc.first_line += 1; BEGIN(comment_enter); } + + + /* The contents of C-style comments are ignored, like white space. */ + +"/*" { comment_enter = YY_START; BEGIN(CCOMMENT); } +. { ; } +\n { yylloc.first_line += 1; } +"*/" { BEGIN(comment_enter); } +""" + +states = (#('module', 'exclusive'), + ('timescale', 'exclusive'),) + +from parse_tokens import tokens +tokens += ['timescale', 'LITERAL', 'IDENTIFIER', 'DEC_NUMBER', 'BASED_NUMBER', + 'UNBASED_NUMBER'] + +def t_ccomment(t): + r'/\*(.|\n)*?\*/' + t.lexer.lineno += t.value.count('\n') + +t_ignore_cppcomment = r'//.*' + +t_ignore = ' \t\n' + +t_K_PSTAR = r"\(\*" +t_K_STARP = r"\*\)" +t_K_DOTSTAR = r"\.\*" +t_K_LS = r"(<<|<<<)" +t_K_RS = r">>" +t_K_RSS = r">>>" +t_K_POW = r"\*\*" +t_K_LE = r"<=" +t_K_GE = r">=" +t_K_EG = r"=>" +""" +"+=>"|"-=>" { + /* + * Resolve the ambiguity between the += assignment + * operator and +=> polarity edge path operator + * + * +=> should be treated as two separate tokens '+' and + * '=>' (K_EG), therefore we only consume the first + * character of the matched pattern i.e. either + or - + * and push back the rest of the matches text (=>) in + * the input stream. + */ + yyless(1); + return yytext[0]; + } +""" +t_K_SG = r"\*>" +t_K_EQ = r"==" +t_K_NE = r"!=" +t_K_CEQ = r"===" +t_K_CNE = r"!==" +t_K_WEQ = r"==\?" +t_K_WNE = r"!=\?" +t_K_LOR = r"\|\|" +t_K_LAND = r"\&\&" +t_K_TAND = r"\&\&\&" +t_K_NOR = r"\~\|" +t_K_NXOR = r"(\~\^|\^\~)" +t_K_NAND = r"\~\&" +t_K_TRIGGER = r"\->" +t_K_PO_POS = r"\+:" +t_K_PO_NEG = r"\-:" +t_K_CONTRIBUTE = r"<\+" +t_K_PLUS_EQ = r"\+=" +t_K_MINUS_EQ = r"\-=" +t_K_MUL_EQ = r"\*=" +t_K_DIV_EQ = r"\/=" +t_K_MOD_EQ = r"\%=" +t_K_AND_EQ = r"\&=" +t_K_OR_EQ = r"\|=" +t_K_XOR_EQ = r"\^=" +t_K_LS_EQ = r"(<<=|<<<=)" +t_K_RS_EQ = r">>=" +t_K_RSS_EQ = r">>>=" +t_K_INCR = r"\+\+" +t_K_DECR = r"\\--" +t_K_LP = r"\'\{" +t_K_SCOPE_RES = r"::" + +tokens += [ 'K_PSTAR', 'K_STARP', 'K_DOTSTAR', 'K_LS', + 'K_RS', 'K_RSS', 'K_POW', 'K_LE', 'K_GE', 'K_EG', 'K_SG', + 'K_EQ', 'K_NE', 'K_CEQ', 'K_CNE', 'K_WEQ', 'K_WNE', + 'K_LOR', 'K_LAND', 'K_TAND', 'K_NOR', 'K_NXOR', + 'K_NAND', 'K_TRIGGER', 'K_PO_POS', 'K_PO_NEG', 'K_CONTRIBUTE', + 'K_PLUS_EQ', 'K_MINUS_EQ', 'K_MUL_EQ', 'K_DIV_EQ', 'K_MOD_EQ', + 'K_AND_EQ', 'K_OR_EQ', 'K_XOR_EQ', 'K_LS_EQ', 'K_RS_EQ', + 'K_RSS_EQ', 'K_INCR', 'K_DECR', 'K_LP', + 'K_SCOPE_RES' + ] + +lexor_keyword_code = { + "above" : 'K_above', + "abs" : 'K_abs', + "absdelay" : 'K_absdelay', + "abstol" : 'K_abstol', + "accept_on" : 'K_accept_on', + "access" : 'K_access', + "acos" : 'K_acos', + "acosh" : 'K_acosh', + "ac_stim" : 'K_ac_stim', + "alias" : 'K_alias', + "aliasparam" : 'K_aliasparam', + "always" : 'K_always', + "always_comb" : 'K_always_comb', + "always_ff" : 'K_always_ff', + "always_latch" : 'K_always_latch', + "analog" : 'K_analog', + "analysis" : 'K_analysis', + "and" : 'K_and', + "asin" : 'K_asin', + "asinh" : 'K_asinh', + "assert" : 'K_assert', + "assign" : 'K_assign', + "assume" : 'K_assume', + "atan" : 'K_atan', + "atan2" : 'K_atan2', + "atanh" : 'K_atanh', + "automatic" : 'K_automatic', + "before" : 'K_before', + "begin" : 'K_begin', + "bind" : 'K_bind', + "bins" : 'K_bins', + "binsof" : 'K_binsof', + "bit" : 'K_bit', + "branch" : 'K_branch', + "break" : 'K_break', + "bool" : 'K_bool', + "buf" : 'K_buf', + "bufif0" : 'K_bufif0', + "bufif1" : 'K_bufif1', + "byte" : 'K_byte', + "case" : 'K_case', + "casex" : 'K_casex', + "casez" : 'K_casez', + "ceil" : 'K_ceil', + "cell" : 'K_cell', + "chandle" : 'K_chandle', + "checker" : 'K_checker', + "class" : 'K_class', + "clocking" : 'K_clocking', + "cmos" : 'K_cmos', + "config" : 'K_config', + "connect" : 'K_connect', + "connectmodule" : 'K_connectmodule', + "connectrules" : 'K_connectrules', + "const" : 'K_const', + "constraint" : 'K_constraint', + "context" : 'K_context', + "continue" : 'K_continue', + "continuous" : 'K_continuous', + "cos" : 'K_cos', + "cosh" : 'K_cosh', + "cover" : 'K_cover', + "covergroup" : 'K_covergroup', + "coverpoint" : 'K_coverpoint', + "cross" : 'K_cross', + "ddt" : 'K_ddt', + "ddt_nature" : 'K_ddt_nature', + "ddx" : 'K_ddx', + "deassign" : 'K_deassign', + "default" : 'K_default', + "defparam" : 'K_defparam', + "design" : 'K_design', + "disable" : 'K_disable', + "discipline" : 'K_discipline', + "discrete" : 'K_discrete', + "dist" : 'K_dist', + "do" : 'K_do', + "domain" : 'K_domain', + "driver_update" : 'K_driver_update', + "edge" : 'K_edge', + "else" : 'K_else', + "end" : 'K_end', + "endcase" : 'K_endcase', + "endchecker" : 'K_endchecker', + "endconfig" : 'K_endconfig', + "endclass" : 'K_endclass', + "endclocking" : 'K_endclocking', + "endconnectrules" : 'K_endconnectrules', + "enddiscipline" : 'K_enddiscipline', + "endfunction" : 'K_endfunction', + "endgenerate" : 'K_endgenerate', + "endgroup" : 'K_endgroup', + "endinterface" : 'K_endinterface', + "endmodule" : 'K_endmodule', + "endnature" : 'K_endnature', + "endpackage" : 'K_endpackage', + "endparamset" : 'K_endparamset', + "endprimitive" : 'K_endprimitive', + "endprogram" : 'K_endprogram', + "endproperty" : 'K_endproperty', + "endspecify" : 'K_endspecify', + "endsequence" : 'K_endsequence', + "endtable" : 'K_endtable', + "endtask" : 'K_endtask', + "enum" : 'K_enum', + "event" : 'K_event', + "eventually" : 'K_eventually', + "exclude" : 'K_exclude', + "exp" : 'K_exp', + "expect" : 'K_expect', + "export" : 'K_export', + "extends" : 'K_extends', + "extern" : 'K_extern', + "final" : 'K_final', + "final_step" : 'K_final_step', + "first_match" : 'K_first_match', + "flicker_noise" : 'K_flicker_noise', + "floor" : 'K_floor', + "flow" : 'K_flow', + "for" : 'K_for', + "foreach" : 'K_foreach', + "force" : 'K_force', + "forever" : 'K_forever', + "fork" : 'K_fork', + "forkjoin" : 'K_forkjoin', + "from" : 'K_from', + "function" : 'K_function', + "generate" : 'K_generate', + "genvar" : 'K_genvar', + "global" : 'K_global', + "ground" : 'K_ground', + "highz0" : 'K_highz0', + "highz1" : 'K_highz1', + "hypot" : 'K_hypot', + "idt" : 'K_idt', + "idtmod" : 'K_idtmod', + "idt_nature" : 'K_idt_nature', + "if" : 'K_if', + "iff" : 'K_iff', + "ifnone" : 'K_ifnone', + "ignore_bins" : 'K_ignore_bins', + "illegal_bins" : 'K_illegal_bins', + "implies" : 'K_implies', + "implements" : 'K_implements', + "import" : 'K_import', + "incdir" : 'K_incdir', + "include" : 'K_include', + "inf" : 'K_inf', + "initial" : 'K_initial', + "initial_step" : 'K_initial_step', + "inout" : 'K_inout', + "input" : 'K_input', + "inside" : 'K_inside', + "instance" : 'K_instance', + "int" : 'K_int', + "integer" : 'K_integer', + "interconnect" : 'K_interconnect', + "interface" : 'K_interface', + "intersect" : 'K_intersect', + "join" : 'K_join', + "join_any" : 'K_join_any', + "join_none" : 'K_join_none', + "laplace_nd" : 'K_laplace_nd', + "laplace_np" : 'K_laplace_np', + "laplace_zd" : 'K_laplace_zd', + "laplace_zp" : 'K_laplace_zp', + "large" : 'K_large', + "last_crossing" : 'K_last_crossing', + "let" : 'K_let', + "liblist" : 'K_liblist', + "library" : 'K_library', + "limexp" : 'K_limexp', + "ln" : 'K_ln', + "local" : 'K_local', + "localparam" : 'K_localparam', + "log" : 'K_log', + # This is defined by SystemVerilog 1800-2005 and as an Icarus extension.' + "logic" : 'K_logic', + "longint" : 'K_longint', + "macromodule" : 'K_macromodule', + "matches" : 'K_matches', + "max" : 'K_max', + "medium" : 'K_medium', + "merged" : 'K_merged', + "min" : 'K_min', + "modport" : 'K_modport', + "module" : 'K_module', + "nand" : 'K_nand', + "nature" : 'K_nature', + "negedge" : 'K_negedge', + "net_resolution" : 'K_net_resolution', + "nettype" : 'K_nettype', + "new" : 'K_new', + "nexttime" : 'K_nexttime', + "nmos" : 'K_nmos', + "noise_table" : 'K_noise_table', + "nor" : 'K_nor', + "noshowcancelled" : 'K_noshowcancelled', + "not" : 'K_not', + "notif0" : 'K_notif0', + "notif1" : 'K_notif1', + "null" : 'K_null', + "or" : 'K_or', + "output" : 'K_output', + "package" : 'K_package', + "packed" : 'K_packed', + "parameter" : 'K_parameter', + "paramset" : 'K_paramset', + "pmos" : 'K_pmos', + "posedge" : 'K_posedge', + "potential" : 'K_potential', + "pow" : 'K_pow', + "primitive" : 'K_primitive', + "priority" : 'K_priority', + "program" : 'K_program', + "property" : 'K_property', + "protected" : 'K_protected', + "pull0" : 'K_pull0', + "pull1" : 'K_pull1', + "pulldown" : 'K_pulldown', + "pullup" : 'K_pullup', + "pulsestyle_onevent" : 'K_pulsestyle_onevent', + "pulsestyle_ondetect" : 'K_pulsestyle_ondetect', + "pure" : 'K_pure', + "rand" : 'K_rand', + "randc" : 'K_randc', + "randcase" : 'K_randcase', + "randsequence" : 'K_randsequence', + "rcmos" : 'K_rcmos', + "real" : 'K_real', + "realtime" : 'K_realtime', + "ref" : 'K_ref', + "reg" : 'K_reg', + "reject_on" : 'K_reject_on', + "release" : 'K_release', + "repeat" : 'K_repeat', + "resolveto" : 'K_resolveto', + "restrict" : 'K_restrict', + "return" : 'K_return', + "rnmos" : 'K_rnmos', + "rpmos" : 'K_rpmos', + "rtran" : 'K_rtran', + "rtranif0" : 'K_rtranif0', + "rtranif1" : 'K_rtranif1', + "s_always" : 'K_s_always', + "s_eventually" : 'K_s_eventually', + "s_nexttime" : 'K_s_nexttime', + "s_until" : 'K_s_until', + "s_until_with" : 'K_s_until_with', + "scalared" : 'K_scalared', + "sequence" : 'K_sequence', + "shortint" : 'K_shortint', + "shortreal" : 'K_shortreal', + "showcancelled" : 'K_showcancelled', + "signed" : 'K_signed', + "sin" : 'K_sin', + "sinh" : 'K_sinh', + "slew" : 'K_slew', + "small" : 'K_small', + "soft" : 'K_soft', + "solve" : 'K_solve', + "specify" : 'K_specify', + "specparam" : 'K_specparam', + "split" : 'K_split', + "sqrt" : 'K_sqrt', + "static" : 'K_static', + # This is defined by both SystemVerilog 1800-2005 and Verilog-AMS 2.3', + "string" : 'K_string', + "strong" : 'K_strong', + "strong0" : 'K_strong0', + "strong1" : 'K_strong1', + "struct" : 'K_struct', + "super" : 'K_super', + "supply0" : 'K_supply0', + "supply1" : 'K_supply1', + "sync_accept_on" : 'K_sync_accept_on', + "sync_reject_on" : 'K_sync_reject_on', + "table" : 'K_table', + "tagged" : 'K_tagged', + "tan" : 'K_tan', + "tanh" : 'K_tanh', + "task" : 'K_task', + "this" : 'K_this', + "throughout" : 'K_throughout', + "time" : 'K_time', + "timeprecision" : 'K_timeprecision', + "timer" : 'K_timer', + "timeunit" : 'K_timeunit', + "tran" : 'K_tran', + "tranif0" : 'K_tranif0', + "tranif1" : 'K_tranif1', + "transition" : 'K_transition', + "tri" : 'K_tri', + "tri0" : 'K_tri0', + "tri1" : 'K_tri1', + "triand" : 'K_triand', + "trior" : 'K_trior', + "trireg" : 'K_trireg', + "type" : 'K_type', + "typedef" : 'K_typedef', + "union" : 'K_union', + "unique" : 'K_unique', + "unique0" : 'K_unique', + "units" : 'K_units', + # Reserved for future use!', + "unsigned" : 'K_unsigned', + "until" : 'K_until', + "until_with" : 'K_until_with', + "untyped" : 'K_untyped', + "use" : 'K_use', + "uwire" : 'K_uwire', + "var" : 'K_var', + "vectored" : 'K_vectored', + "virtual" : 'K_virtual', + "void" : 'K_void', + "wait" : 'K_wait', + "wait_order" : 'K_wait_order', + "wand" : 'K_wand', + "weak" : 'K_weak', + "weak0" : 'K_weak0', + "weak1" : 'K_weak1', + "while" : 'K_while', + "white_noise" : 'K_white_noise', + "wildcard" : 'K_wildcard', + "wire" : 'K_wire', + "with" : 'K_with', + "within" : 'K_within', + # This is the name originally proposed for uwire and is deprecated!', + "wone" : 'K_wone', + "wor" : 'K_wor', + # This is defined by Verilog-AMS 2.3 and as an Icarus extension.', + "wreal" : 'K_wreal', + "xnor" : 'K_xnor', + "xor" : 'K_xor', + "zi_nd" : 'K_zi_nd', + "zi_np" : 'K_zi_np', + "zi_zd" : 'K_zi_zd', + "zi_zp" : 'K_zi_zp', +} + +literals = [ '[', '}', '{', ';', ':', '[', ']', ',', '(', ')', + '#', '=', '.', '@', '&', '!', '?', '<', '>', '%', + '|', '^', '~', '+', '*', '/', '-'] + +""" + /* Watch out for the tricky case of (*). Cannot parse this as "(*" + and ")", but since I know that this is really ( * ), replace it + with "*" and return that. */ +"("{W}*"*"{W}*")" { return '*'; } + +"]" { BEGIN(0); return yytext[0]; } +[}{;:\[\],()#=.@&!?<>%|^~+*/-] { return yytext[0]; } + +\" { BEGIN(CSTRING); } +\\\\ { yymore(); /* Catch \\, which is a \ escaping itself */ } +\\\" { yymore(); /* Catch \", which is an escaped quote */ } +\n { BEGIN(0); + yylval.text = strdupnew(yytext); + VLerror(yylloc, "Missing close quote of string."); + yylloc.first_line += 1; + return STRING; } +\" { BEGIN(0); + yylval.text = strdupnew(yytext); + yylval.text[strlen(yytext)-1] = 0; + return STRING; } +. { yymore(); } + + /* The UDP Table is a unique lexical environment. These are most + tokens that we can expect in a table. */ +\(\?0\) { return '_'; } +\(\?1\) { return '+'; } +\(\?[xX]\) { return '%'; } +\(\?\?\) { return '*'; } +\(01\) { return 'r'; } +\(0[xX]\) { return 'Q'; } +\(b[xX]\) { return 'q'; } +\(b0\) { return 'f'; /* b0 is 10|00, but only 10 is meaningful */} +\(b1\) { return 'r'; /* b1 is 11|01, but only 01 is meaningful */} +\(0\?\) { return 'P'; } +\(10\) { return 'f'; } +\(1[xX]\) { return 'M'; } +\(1\?\) { return 'N'; } +\([xX]0\) { return 'F'; } +\([xX]1\) { return 'R'; } +\([xX]\?\) { return 'B'; } +[bB] { return 'b'; } +[lL] { return 'l'; /* IVL extension */ } +[hH] { return 'h'; /* IVL extension */ } +[fF] { return 'f'; } +[rR] { return 'r'; } +[xX] { return 'x'; } +[nN] { return 'n'; } +[pP] { return 'p'; } +[01\?\*\-:;] { return yytext[0]; } + +"01" { return K_edge_descriptor; } +"0x" { return K_edge_descriptor; } +"0z" { return K_edge_descriptor; } +"10" { return K_edge_descriptor; } +"1x" { return K_edge_descriptor; } +"1z" { return K_edge_descriptor; } +"x0" { return K_edge_descriptor; } +"x1" { return K_edge_descriptor; } +"z0" { return K_edge_descriptor; } +"z1" { return K_edge_descriptor; } +""" + +""" +def t_module_end(t): + r'endmodule' + code = t.lexer.lexdata[t.modulestart:t.lexpos] + t.type = 'INITIAL' + t.value = code + t.lexer.lineno += t.value.count('\n') + return t + +t_module_ignore = ' \t' +""" + +def t_LITERAL(t): + r'[a-zA-Z_][a-zA-Z0-9$_]*' + word = t.value + print ("literal", word) + keyword = lexor_keyword_code.get(t.value, 'IDENTIFIER') + #if keyword in ['K_module', 'K_macromodule']: + # t.lexer.modulestart = t.lexpos+len(t.value) + # t.lexer.begin('module') + if keyword == 'IDENTIFIER': + t.type = 'IDENTIFIER' + t.value = keyword + return t + t.type = keyword + return t + +""" + switch (rc) { + case IDENTIFIER: + yylval.text = strdupnew(yytext); + if (strncmp(yylval.text,"PATHPULSE$", 10) == 0) + rc = PATHPULSE_IDENTIFIER; + break; + + case K_edge: + BEGIN(EDGES); + break; + + case K_primitive: + in_UDP = true; + break; + + case K_endprimitive: + in_UDP = false; + break; + + case K_table: + BEGIN(UDPTABLE); + break; + + default: + yylval.text = 0; + break; + } + + /* Special case: If this is part of a scoped name, then check + the package for identifier details. For example, if the + source file is foo::bar, the parse.y will note the + PACKAGE_IDENTIFIER and "::" token and mark the + "in_package_scope" variable. Then this lexor will see the + identifier here and interpret it in the package scope. */ + if (in_package_scope) { + if (rc == IDENTIFIER) { + if (data_type_t*type = pform_test_type_identifier(in_package_scope, yylval.text)) { + yylval.type_identifier.text = yylval.text; + yylval.type_identifier.type = type; + rc = TYPE_IDENTIFIER; + } + } + in_package_scope = 0; + return rc; + } + + /* If this identifier names a discipline, then return this as + a DISCIPLINE_IDENTIFIER and return the discipline as the + value instead. */ + if (rc == IDENTIFIER && gn_verilog_ams_flag) { + perm_string tmp = lex_strings.make(yylval.text); + map::iterator cur = disciplines.find(tmp); + if (cur != disciplines.end()) { + delete[]yylval.text; + yylval.discipline = (*cur).second; + rc = DISCIPLINE_IDENTIFIER; + } + } + + /* If this identifier names a previously declared package, then + return this as a PACKAGE_IDENTIFIER instead. */ + if (rc == IDENTIFIER && gn_system_verilog()) { + if (PPackage*pkg = pform_test_package_identifier(yylval.text)) { + delete[]yylval.text; + yylval.package = pkg; + rc = PACKAGE_IDENTIFIER; + } + } + + /* If this identifier names a previously declared type, then + return this as a TYPE_IDENTIFIER instead. */ + if (rc == IDENTIFIER && gn_system_verilog()) { + if (data_type_t*type = pform_test_type_identifier(yylval.text)) { + yylval.type_identifier.text = yylval.text; + yylval.type_identifier.type = type; + rc = TYPE_IDENTIFIER; + } + } + + return rc; + } +""" + +""" +\\[^ \t\b\f\r\n]+ { + yylval.text = strdupnew(yytext+1); + if (gn_system_verilog()) { + if (PPackage*pkg = pform_test_package_identifier(yylval.text)) { + delete[]yylval.text; + yylval.package = pkg; + return PACKAGE_IDENTIFIER; + } + } + if (gn_system_verilog()) { + if (data_type_t*type = pform_test_type_identifier(yylval.text)) { + yylval.type_identifier.text = yylval.text; + yylval.type_identifier.type = type; + return TYPE_IDENTIFIER; + } + } + return IDENTIFIER; + } + +\$([a-zA-Z0-9$_]+) { + /* The 1364-1995 timing checks. */ + if (strcmp(yytext,"$hold") == 0) + return K_Shold; + if (strcmp(yytext,"$nochange") == 0) + return K_Snochange; + if (strcmp(yytext,"$period") == 0) + return K_Speriod; + if (strcmp(yytext,"$recovery") == 0) + return K_Srecovery; + if (strcmp(yytext,"$setup") == 0) + return K_Ssetup; + if (strcmp(yytext,"$setuphold") == 0) + return K_Ssetuphold; + if (strcmp(yytext,"$skew") == 0) + return K_Sskew; + if (strcmp(yytext,"$width") == 0) + return K_Swidth; + /* The new 1364-2001 timing checks. */ + if (strcmp(yytext,"$fullskew") == 0) + return K_Sfullskew; + if (strcmp(yytext,"$recrem") == 0) + return K_Srecrem; + if (strcmp(yytext,"$removal") == 0) + return K_Sremoval; + if (strcmp(yytext,"$timeskew") == 0) + return K_Stimeskew; + + if (strcmp(yytext,"$attribute") == 0) + return KK_attribute; + + if (gn_system_verilog() && strcmp(yytext,"$unit") == 0) { + yylval.package = pform_units.back(); + return PACKAGE_IDENTIFIER; + } + + yylval.text = strdupnew(yytext); + return SYSTEM_IDENTIFIER; } +""" + +def t_dec_number(t): + r'\'[sS]?[dD][ \t]*[0-9][0-9_]*' + t.type = 'BASED_NUMBER' + #t.value = word # make_unsized_dec(yytext); + return t + +def t_undef_highz_dec(t): + r'\'[sS]?[dD][ \t]*[xzXZ?]_*' + t.type = 'BASED_NUMBER' + #t.value = word # make_undef_highz_dec(yytext); + return t + +def t_based_make_unsized_binary(t): + r'\'[sS]?[bB][ \t]*[0-1xzXZ?][0-1xzXZ?_]*' + t.type = 'BASED_NUMBER' + #t.value = word # make_unsized_binary(yytext); + return t + +def t_make_unsized_octal(t): + r'\'[sS]?[oO][ \t]*[0-7xzXZ?][0-7xzXZ?_]*' + t.type = 'BASED_NUMBER' + #t.value = word # make_unsized_octal(yytext); + return t + +def t_make_unsized_hex(t): + r'\'[sS]?[hH][ \t]*[0-9a-fA-FxzXZ?][0-9a-fA-FxzXZ?_]*' + t.type = 'BASED_NUMBER' + #t.value = word # make_unsized_hex(yytext); + return t + +def t_unbased_make_unsized_binary(t): + r'\'[01xzXZ]' + t.type = 'UNBASED_NUMBER' + #t.value = word # make_unsized_binary(yytext); + return t + +""" + /* Decimal numbers are the usual. But watch out for the UDPTABLE + mode, where there are no decimal numbers. Reject the match if we + are in the UDPTABLE state. */ +""" +""" + if (YY_START==UDPTABLE) { + REJECT; + } else { +""" +def t_make_unsized_dec(t): + r'[0-9][0-9_]*' + t.type = 'DEC_NUMBER' + #t.value = word # make_unsized_dec(yytext); + #based_size = yylval.number->as_ulong(); + return t + +""" + /* Notice and handle the `timescale directive. */ +""" + +def t_timescale(t): + #r'^{W}?`timescale' + r'`timescale' + t.lexer.timestart = t.lexpos+len(t.value) + t.lexer.push_state('timescale') + +#t_timescale_ignore_toeol = r'.+\n' +t_timescale_ignore = ' \t' +#t_timescale_ignore_whitespace = r'\s+' +#t_code_ignore = "" + +def t_timescale_end(t): + r'.+\n' + code = t.lexer.lexdata[t.lexer.timestart:t.lexpos] + t.type = 'timescale' + t.value = code + t.lexer.pop_state() + print "match", code + return t + +""" +.* { process_timescale(yytext); } +\n { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`timescale directive can not be inside a module " + "definition." << endl; + error_count += 1; + } + yylloc.first_line += 1; + BEGIN(0); } +""" + +""" + + /* This rule handles scaled time values for SystemVerilog. */ +[0-9][0-9_]*(\.[0-9][0-9_]*)?{TU}?s { + if (gn_system_verilog()) { + yylval.text = strdupnew(yytext); + return TIME_LITERAL; + } else REJECT; } + + /* These rules handle the scaled real literals from Verilog-AMS. The + value is a number with a single letter scale factor. If + verilog-ams is not enabled, then reject this rule. If it is + enabled, then collect the scale and use it to scale the value. */ +[0-9][0-9_]*\.[0-9][0-9_]*/{S} { + if (!gn_verilog_ams_flag) REJECT; + BEGIN(REAL_SCALE); + yymore(); } + +[0-9][0-9_]*/{S} { + if (!gn_verilog_ams_flag) REJECT; + BEGIN(REAL_SCALE); + yymore(); } + +{S} { + size_t token_len = strlen(yytext); + char*tmp = new char[token_len + 5]; + int scale = 0; + strcpy(tmp, yytext); + switch (tmp[token_len-1]) { + case 'a': scale = -18; break; /* atto- */ + case 'f': scale = -15; break; /* femto- */ + case 'p': scale = -12; break; /* pico- */ + case 'n': scale = -9; break; /* nano- */ + case 'u': scale = -6; break; /* micro- */ + case 'm': scale = -3; break; /* milli- */ + case 'k': scale = 3; break; /* kilo- */ + case 'K': scale = 3; break; /* kilo- */ + case 'M': scale = 6; break; /* mega- */ + case 'G': scale = 9; break; /* giga- */ + case 'T': scale = 12; break; /* tera- */ + default: assert(0); break; + } + snprintf(tmp+token_len-1, 5, "e%d", scale); + yylval.realtime = new verireal(tmp); + delete[]tmp; + + BEGIN(0); + return REALTIME; } + +[0-9][0-9_]*\.[0-9][0-9_]*([Ee][+-]?[0-9][0-9_]*)? { + yylval.realtime = new verireal(yytext); + return REALTIME; } + +[0-9][0-9_]*[Ee][+-]?[0-9][0-9_]* { + yylval.realtime = new verireal(yytext); + return REALTIME; } + + + /* Notice and handle the `celldefine and `endcelldefine directives. */ + +^{W}?`celldefine{W}? { in_celldefine = true; } +^{W}?`endcelldefine{W}? { in_celldefine = false; } + + /* Notice and handle the resetall directive. */ + +^{W}?`resetall{W}? { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`resetall directive can not be inside a module " + "definition." << endl; + error_count += 1; + } else if (in_UDP) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`resetall directive can not be inside a UDP " + "definition." << endl; + error_count += 1; + } else { + reset_all(); + } } + + /* Notice and handle the `unconnected_drive directive. */ +^{W}?`unconnected_drive { BEGIN(PPUCDRIVE); } +.* { process_ucdrive(yytext); } +\n { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`unconnected_drive directive can not be inside a " + "module definition." << endl; + error_count += 1; + } + yylloc.first_line += 1; + BEGIN(0); } + +^{W}?`nounconnected_drive{W}? { + if (in_module) { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`nounconnected_drive directive can not be inside a " + "module definition." << endl; + error_count += 1; + } + uc_drive = UCD_NONE; } + + /* These are directives that I do not yet support. I think that IVL + should handle these, not an external preprocessor. */ + /* From 1364-2005 Chapter 19. */ +^{W}?`pragme{W}?.* { } + + /* From 1364-2005 Annex D. */ +^{W}?`default_decay_time{W}?.* { } +^{W}?`default_trireg_strength{W}?.* { } +^{W}?`delay_mode_distributed{W}?.* { } +^{W}?`delay_mode_path{W}?.* { } +^{W}?`delay_mode_unit{W}?.* { } +^{W}?`delay_mode_zero{W}?.* { } + + /* From other places. */ +^{W}?`disable_portfaults{W}?.* { } +^{W}?`enable_portfaults{W}?.* { } +`endprotect { } +^{W}?`nosuppress_faults{W}?.* { } +`protect { } +^{W}?`suppress_faults{W}?.* { } +^{W}?`uselib{W}?.* { } + +^{W}?`begin_keywords{W}? { BEGIN(PPBEGIN_KEYWORDS); } + +\"[a-zA-Z0-9 -\.]*\".* { + keyword_mask_stack.push_front(lexor_keyword_mask); + + char*word = yytext+1; + char*tail = strchr(word, '"'); + tail[0] = 0; + if (strcmp(word,"1364-1995") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995; + } else if (strcmp(word,"1364-2001") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG; + } else if (strcmp(word,"1364-2001-noconfig") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001; + } else if (strcmp(word,"1364-2005") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005; + } else if (strcmp(word,"1800-2005") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_1800_2005; + } else if (strcmp(word,"1800-2009") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_1800_2005 + |GN_KEYWORDS_1800_2009; + } else if (strcmp(word,"1800-2012") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_1800_2005 + |GN_KEYWORDS_1800_2009 + |GN_KEYWORDS_1800_2012; + } else if (strcmp(word,"VAMS-2.3") == 0) { + lexor_keyword_mask = GN_KEYWORDS_1364_1995 + |GN_KEYWORDS_1364_2001 + |GN_KEYWORDS_1364_2001_CONFIG + |GN_KEYWORDS_1364_2005 + |GN_KEYWORDS_VAMS_2_3; + } else { + fprintf(stderr, "%s:%d: Ignoring unknown keywords string: %s\n", + yylloc.text, yylloc.first_line, word); + } + BEGIN(0); + } + +.* { + fprintf(stderr, "%s:%d: Malformed keywords specification: %s\n", + yylloc.text, yylloc.first_line, yytext); + BEGIN(0); + } + +^{W}?`end_keywords{W}?.* { + if (!keyword_mask_stack.empty()) { + lexor_keyword_mask = keyword_mask_stack.front(); + keyword_mask_stack.pop_front(); + } else { + fprintf(stderr, "%s:%d: Mismatched end_keywords directive\n", + yylloc.text, yylloc.first_line); + } + } + + /* Notice and handle the default_nettype directive. The lexor + detects the default_nettype keyword, and the second part of the + rule collects the rest of the line and processes it. We only need + to look for the first work, and interpret it. */ + +`default_nettype{W}? { BEGIN(PPDEFAULT_NETTYPE); } +.* { + NetNet::Type net_type; + size_t wordlen = strcspn(yytext, " \t\f\r\n"); + yytext[wordlen] = 0; + /* Add support for other wire types and better error detection. */ + if (strcmp(yytext,"wire") == 0) { + net_type = NetNet::WIRE; + + } else if (strcmp(yytext,"tri") == 0) { + net_type = NetNet::TRI; + + } else if (strcmp(yytext,"tri0") == 0) { + net_type = NetNet::TRI0; + + } else if (strcmp(yytext,"tri1") == 0) { + net_type = NetNet::TRI1; + + } else if (strcmp(yytext,"wand") == 0) { + net_type = NetNet::WAND; + + } else if (strcmp(yytext,"triand") == 0) { + net_type = NetNet::TRIAND; + + } else if (strcmp(yytext,"wor") == 0) { + net_type = NetNet::WOR; + + } else if (strcmp(yytext,"trior") == 0) { + net_type = NetNet::TRIOR; + + } else if (strcmp(yytext,"none") == 0) { + net_type = NetNet::NONE; + + } else { + cerr << yylloc.text << ":" << yylloc.first_line + << ": error: Net type " << yytext + << " is not a valid (or supported)" + << " default net type." << endl; + net_type = NetNet::WIRE; + error_count += 1; + } + pform_set_default_nettype(net_type, yylloc.text, yylloc.first_line); + } +\n { + yylloc.first_line += 1; + BEGIN(0); } + + + /* These are directives that are not supported by me and should have + been handled by an external preprocessor such as ivlpp. */ + +^{W}?`define{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `define not supported. Use an external preprocessor." + << endl; + } + +^{W}?`else{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `else not supported. Use an external preprocessor." + << endl; + } + +^{W}?`elsif{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `elsif not supported. Use an external preprocessor." + << endl; + } + +^{W}?`endif{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `endif not supported. Use an external preprocessor." + << endl; + } + +^{W}?`ifdef{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `ifdef not supported. Use an external preprocessor." + << endl; + } + +^{W}?`ifndef{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `ifndef not supported. Use an external preprocessor." + << endl; + } + +^`include{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `include not supported. Use an external preprocessor." + << endl; + } + +^`undef{W}?.* { + cerr << yylloc.text << ":" << yylloc.first_line << + ": warning: `undef not supported. Use an external preprocessor." + << endl; + } + + +`{W} { cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + << "Stray tic (`) here. Perhaps you put white space" << endl; + cerr << yylloc.text << ":" << yylloc.first_line << ": : " + << "between the tic and preprocessor directive?" + << endl; + error_count += 1; } + +. { return yytext[0]; } + + /* Final catchall. something got lost or mishandled. */ + /* XXX Should we tell the user something about the lexical state? */ + +<*>.|\n { cerr << yylloc.text << ":" << yylloc.first_line + << ": error: unmatched character ("; + if (isprint(yytext[0])) + cerr << yytext[0]; + else + cerr << "hex " << hex << ((unsigned char) yytext[0]); + + cerr << ")" << endl; + error_count += 1; } + +%% + +/* + * The UDP state table needs some slightly different treatment by the + * lexor. The level characters are normally accepted as other things, + * so the parser needs to switch my mode when it believes in needs to. + */ +void lex_end_table() +{ + BEGIN(INITIAL); +} + +static unsigned truncate_to_integer_width(verinum::V*bits, unsigned size) +{ + if (size <= integer_width) return size; + + verinum::V pad = bits[size-1]; + if (pad == verinum::V1) pad = verinum::V0; + + for (unsigned idx = integer_width; idx < size; idx += 1) { + if (bits[idx] != pad) { + yywarn(yylloc, "Unsized numeric constant truncated to integer width."); + break; + } + } + return integer_width; +} + +verinum*make_unsized_binary(const char*txt) +{ + bool sign_flag = false; + bool single_flag = false; + const char*ptr = txt; + assert(*ptr == '\''); + ptr += 1; + + if (tolower(*ptr) == 's') { + sign_flag = true; + ptr += 1; + } + + assert((tolower(*ptr) == 'b') || gn_system_verilog()); + if (tolower(*ptr) == 'b') { + ptr += 1; + } else { + assert(sign_flag == false); + single_flag = true; + } + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + unsigned size = 0; + for (const char*idx = ptr ; *idx ; idx += 1) + if (*idx != '_') size += 1; + + if (size == 0) { + VLerror(yylloc, "Numeric literal has no digits in it."); + verinum*out = new verinum(); + out->has_sign(sign_flag); + out->is_single(single_flag); + return out; + } + + if ((based_size > 0) && (size > based_size)) yywarn(yylloc, + "extra digits given for sized binary constant."); + + verinum::V*bits = new verinum::V[size]; + + unsigned idx = size; + while (*ptr) { + switch (ptr[0]) { + case '0': + bits[--idx] = verinum::V0; + break; + case '1': + bits[--idx] = verinum::V1; + break; + case 'z': case 'Z': case '?': + bits[--idx] = verinum::Vz; + break; + case 'x': case 'X': + bits[--idx] = verinum::Vx; + break; + case '_': + break; + default: + fprintf(stderr, "%c\n", ptr[0]); + assert(0); + } + ptr += 1; + } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*out = new verinum(bits, size, false); + out->has_sign(sign_flag); + out->is_single(single_flag); + delete[]bits; + return out; +} + + +verinum*make_unsized_octal(const char*txt) +{ + bool sign_flag = false; + const char*ptr = txt; + assert(*ptr == '\''); + ptr += 1; + + if (tolower(*ptr) == 's') { + sign_flag = true; + ptr += 1; + } + + assert(tolower(*ptr) == 'o'); + ptr += 1; + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + unsigned size = 0; + for (const char*idx = ptr ; *idx ; idx += 1) + if (*idx != '_') size += 3; + + if (based_size > 0) { + int rem = based_size % 3; + if (rem != 0) based_size += 3 - rem; + if (size > based_size) yywarn(yylloc, + "extra digits given for sized octal constant."); + } + + verinum::V*bits = new verinum::V[size]; + + unsigned idx = size; + while (*ptr) { + unsigned val; + switch (ptr[0]) { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + val = *ptr - '0'; + bits[--idx] = (val&4) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&2) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&1) ? verinum::V1 : verinum::V0; + break; + case 'x': case 'X': + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + break; + case 'z': case 'Z': case '?': + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + break; + case '_': + break; + default: + assert(0); + } + ptr += 1; + } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*out = new verinum(bits, size, false); + out->has_sign(sign_flag); + delete[]bits; + return out; +} + + +verinum*make_unsized_hex(const char*txt) +{ + bool sign_flag = false; + const char*ptr = txt; + assert(*ptr == '\''); + ptr += 1; + + if (tolower(*ptr) == 's') { + sign_flag = true; + ptr += 1; + } + assert(tolower(*ptr) == 'h'); + + ptr += 1; + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + unsigned size = 0; + for (const char*idx = ptr ; *idx ; idx += 1) + if (*idx != '_') size += 4; + + if (based_size > 0) { + int rem = based_size % 4; + if (rem != 0) based_size += 4 - rem; + if (size > based_size) yywarn(yylloc, + "extra digits given for sized hex constant."); + } + + verinum::V*bits = new verinum::V[size]; + + unsigned idx = size; + while (*ptr) { + unsigned val; + switch (ptr[0]) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + val = *ptr - '0'; + bits[--idx] = (val&8) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&4) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&2) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&1) ? verinum::V1 : verinum::V0; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + val = tolower(*ptr) - 'a' + 10; + bits[--idx] = (val&8) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&4) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&2) ? verinum::V1 : verinum::V0; + bits[--idx] = (val&1) ? verinum::V1 : verinum::V0; + break; + case 'x': case 'X': + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + bits[--idx] = verinum::Vx; + break; + case 'z': case 'Z': case '?': + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + bits[--idx] = verinum::Vz; + break; + case '_': + break; + default: + assert(0); + } + ptr += 1; + } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*out = new verinum(bits, size, false); + out->has_sign(sign_flag); + delete[]bits; + return out; +} + + +/* Divide the integer given by the string by 2. Return the remainder bit. */ +static int dec_buf_div2(char *buf) +{ + int partial; + int len = strlen(buf); + char *dst_ptr; + int pos; + + partial = 0; + pos = 0; + + /* dst_ptr overwrites buf, but all characters that are overwritten + were already used by the reader. */ + dst_ptr = buf; + + while(buf[pos] == '0') + ++pos; + + for(; pos= 2){ + *dst_ptr = partial/2 + '0'; + partial = partial & 1; + + ++dst_ptr; + } + else{ + *dst_ptr = '0'; + ++dst_ptr; + } + } + + // If result of division was zero string, it should remain that way. + // Don't eat the last zero... + if (dst_ptr == buf){ + *dst_ptr = '0'; + ++dst_ptr; + } + *dst_ptr = 0; + + return partial; +} + +/* Support a single x, z or ? as a decimal constant (from 1364-2005). */ +verinum* make_undef_highz_dec(const char* ptr) +{ + bool signed_flag = false; + + assert(*ptr == '\''); + /* The number may have decorations of the form 'sd, + possibly with space between the d and the . + Also, the 's' is optional, and marks the number as signed. */ + ptr += 1; + + if (tolower(*ptr) == 's') { + signed_flag = true; + ptr += 1; + } + + assert(tolower(*ptr) == 'd'); + ptr += 1; + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + /* Process the code. */ + verinum::V* bits = new verinum::V[1]; + switch (*ptr) { + case 'x': + case 'X': + bits[0] = verinum::Vx; + break; + case 'z': + case 'Z': + case '?': + bits[0] = verinum::Vz; + break; + default: + assert(0); + } + ptr += 1; + while (*ptr == '_') ptr += 1; + assert(*ptr == 0); + + verinum*out = new verinum(bits, 1, false); + out->has_sign(signed_flag); + delete[]bits; + return out; +} + +/* + * Making a decimal number is much easier than the other base numbers + * because there are no z or x values to worry about. It is much + * harder than other base numbers because the width needed in bits is + * hard to calculate. + */ + +verinum*make_unsized_dec(const char*ptr) +{ + char buf[4096]; + bool signed_flag = false; + unsigned idx; + + if (ptr[0] == '\'') { + /* The number has decorations of the form 'sd, + possibly with space between the d and the . + Also, the 's' is optional, and marks the number as + signed. */ + ptr += 1; + + if (tolower(*ptr) == 's') { + signed_flag = true; + ptr += 1; + } + + assert(tolower(*ptr) == 'd'); + ptr += 1; + + while (*ptr && ((*ptr == ' ') || (*ptr == '\t'))) + ptr += 1; + + } else { + /* ... or an undecorated decimal number is passed + it. These numbers are treated as signed decimal. */ + assert(isdigit(*ptr)); + signed_flag = true; + } + + + /* Copy the digits into a buffer that I can use to do in-place + decimal divides. */ + idx = 0; + while ((idx < sizeof buf) && (*ptr != 0)) { + if (*ptr == '_') { + ptr += 1; + continue; + } + + buf[idx++] = *ptr++; + } + + if (idx == sizeof buf) { + fprintf(stderr, "Ridiculously long" + " decimal constant will be truncated!\n"); + idx -= 1; + } + + buf[idx] = 0; + unsigned tmp_size = idx * 4 + 1; + verinum::V *bits = new verinum::V[tmp_size]; + + idx = 0; + while (idx < tmp_size) { + int rem = dec_buf_div2(buf); + bits[idx++] = (rem == 1) ? verinum::V1 : verinum::V0; + } + + assert(strcmp(buf, "0") == 0); + + /* Now calculate the minimum number of bits needed to + represent this unsigned number. */ + unsigned size = tmp_size; + while ((size > 1) && (bits[size-1] == verinum::V0)) + size -= 1; + + /* Now account for the signedness. Don't leave a 1 in the high + bit if this is a signed number. */ + if (signed_flag && (bits[size-1] == verinum::V1)) { + size += 1; + assert(size <= tmp_size); + } + + /* Since we never have the real number of bits that a decimal + number represents we do not check for extra bits. */ +// if (based_size > 0) { } + + if (gn_strict_expr_width_flag && (based_size == 0)) + size = truncate_to_integer_width(bits, size); + + verinum*res = new verinum(bits, size, false); + res->has_sign(signed_flag); + + delete[]bits; + return res; +} + +/* + * Convert the string to a time unit or precision. + * Returns true on failure. + */ +static bool get_timescale_const(const char *&cp, int &res, bool is_unit) +{ + /* Check for the 1 digit. */ + if (*cp != '1') { + if (is_unit) { + VLerror(yylloc, "Invalid `timescale unit constant " + "(1st digit)"); + } else { + VLerror(yylloc, "Invalid `timescale precision constant " + "(1st digit)"); + } + return true; + } + cp += 1; + + /* Check the number of zeros after the 1. */ + res = strspn(cp, "0"); + if (res > 2) { + if (is_unit) { + VLerror(yylloc, "Invalid `timescale unit constant " + "(number of zeros)"); + } else { + VLerror(yylloc, "Invalid `timescale precision constant " + "(number of zeros)"); + } + return true; + } + cp += res; + + /* Skip any space between the digits and the scaling string. */ + cp += strspn(cp, " \t"); + + /* Now process the scaling string. */ + if (strncmp("s", cp, 1) == 0) { + res -= 0; + cp += 1; + return false; + + } else if (strncmp("ms", cp, 2) == 0) { + res -= 3; + cp += 2; + return false; + + } else if (strncmp("us", cp, 2) == 0) { + res -= 6; + cp += 2; + return false; + + } else if (strncmp("ns", cp, 2) == 0) { + res -= 9; + cp += 2; + return false; + + } else if (strncmp("ps", cp, 2) == 0) { + res -= 12; + cp += 2; + return false; + + } else if (strncmp("fs", cp, 2) == 0) { + res -= 15; + cp += 2; + return false; + + } + + if (is_unit) { + VLerror(yylloc, "Invalid `timescale unit scale"); + } else { + VLerror(yylloc, "Invalid `timescale precision scale"); + } + return true; +} + + +/* + * process either a pull0 or a pull1. + */ +static void process_ucdrive(const char*txt) +{ + UCDriveType ucd = UCD_NONE; + const char*cp = txt + strspn(txt, " \t"); + + /* Skip the space after the `unconnected_drive directive. */ + if (cp == txt) { + VLerror(yylloc, "Space required after `unconnected_drive " + "directive."); + return; + } + + /* Check for the pull keyword. */ + if (strncmp("pull", cp, 4) != 0) { + VLerror(yylloc, "pull required for `unconnected_drive " + "directive."); + return; + } + cp += 4; + if (*cp == '0') ucd = UCD_PULL0; + else if (*cp == '1') ucd = UCD_PULL1; + else { + cerr << yylloc.text << ":" << yylloc.first_line << ": error: " + "`unconnected_drive does not support 'pull" << *cp + << "'." << endl; + error_count += 1; + return; + } + cp += 1; + + /* Verify that only space and/or a single line comment is left. */ + cp += strspn(cp, " \t"); + if (strncmp(cp, "//", 2) != 0 && + (size_t)(cp-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid `unconnected_drive directive (extra " + "garbage after precision)."); + return; + } + + uc_drive = ucd; +} + +/* + * The timescale parameter has the form: + * " xs / xs" + */ +static void process_timescale(const char*txt) +{ + const char*cp = txt + strspn(txt, " \t"); + + /* Skip the space after the `timescale directive. */ + if (cp == txt) { + VLerror(yylloc, "Space required after `timescale directive."); + return; + } + + int unit = 0; + int prec = 0; + + /* Get the time units. */ + if (get_timescale_const(cp, unit, true)) return; + + /* Skip any space after the time units, the '/' and any + * space after the '/'. */ + cp += strspn(cp, " \t"); + if (*cp != '/') { + VLerror(yylloc, "`timescale separator '/' appears to be missing."); + return; + } + cp += 1; + cp += strspn(cp, " \t"); + + /* Get the time precision. */ + if (get_timescale_const(cp, prec, false)) return; + + /* Verify that only space and/or a single line comment is left. */ + cp += strspn(cp, " \t"); + if (strncmp(cp, "//", 2) != 0 && + (size_t)(cp-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid `timescale directive (extra garbage " + "after precision)."); + return; + } + + /* The time unit must be greater than or equal to the precision. */ + if (unit < prec) { + VLerror(yylloc, "error: `timescale unit must not be less than " + "the precision."); + return; + } + + pform_set_timescale(unit, prec, yylloc.text, yylloc.first_line); +} + +int yywrap() +{ + return 1; +} + +/* + * The line directive matches lines of the form #line "foo" N and + * calls this function. Here I parse out the file name and line + * number, and change the yylloc to suite. + */ +static void line_directive() +{ + char *cpr; + /* Skip any leading space. */ + char *cp = strchr(yytext, '#'); + /* Skip the #line directive. */ + assert(strncmp(cp, "#line", 5) == 0); + cp += 5; + /* Skip the space after the #line directive. */ + cp += strspn(cp, " \t"); + + /* Find the starting " and skip it. */ + char*fn_start = strchr(cp, '"'); + if (cp != fn_start) { + VLerror(yylloc, "Invalid #line directive (file name start)."); + return; + } + fn_start += 1; + + /* Find the last ". */ + char*fn_end = strrchr(fn_start, '"'); + if (!fn_end) { + VLerror(yylloc, "Invalid #line directive (file name end)."); + return; + } + + /* Copy the file name and assign it to yylloc. */ + char*buf = new char[fn_end-fn_start+1]; + strncpy(buf, fn_start, fn_end-fn_start); + buf[fn_end-fn_start] = 0; + + /* Skip the space after the file name. */ + cp = fn_end; + cp += 1; + cpr = cp; + cpr += strspn(cp, " \t"); + if (cp == cpr) { + VLerror(yylloc, "Invalid #line directive (missing space after " + "file name)."); + delete[] buf; + return; + } + cp = cpr; + + /* Get the line number and verify that it is correct. */ + unsigned long lineno = strtoul(cp, &cpr, 10); + if (cp == cpr) { + VLerror(yylloc, "Invalid line number for #line directive."); + delete[] buf; + return; + } + cp = cpr; + + /* Verify that only space is left. */ + cpr += strspn(cp, " \t"); + if ((size_t)(cpr-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid #line directive (extra garbage after " + "line number)."); + delete[] buf; + return; + } + + /* Now we can assign the new values to yyloc. */ + yylloc.text = set_file_name(buf); + yylloc.first_line = lineno; +} + +/* + * The line directive matches lines of the form `line N "foo" M and + * calls this function. Here I parse out the file name and line + * number, and change the yylloc to suite. M is ignored. + */ +static void line_directive2() +{ + char *cpr; + /* Skip any leading space. */ + char *cp = strchr(yytext, '`'); + /* Skip the `line directive. */ + assert(strncmp(cp, "`line", 5) == 0); + cp += 5; + + /* strtoul skips leading space. */ + unsigned long lineno = strtoul(cp, &cpr, 10); + if (cp == cpr) { + VLerror(yylloc, "Invalid line number for `line directive."); + return; + } + lineno -= 1; + cp = cpr; + + /* Skip the space between the line number and the file name. */ + cpr += strspn(cp, " \t"); + if (cp == cpr) { + VLerror(yylloc, "Invalid `line directive (missing space after " + "line number)."); + return; + } + cp = cpr; + + /* Find the starting " and skip it. */ + char*fn_start = strchr(cp, '"'); + if (cp != fn_start) { + VLerror(yylloc, "Invalid `line directive (file name start)."); + return; + } + fn_start += 1; + + /* Find the last ". */ + char*fn_end = strrchr(fn_start, '"'); + if (!fn_end) { + VLerror(yylloc, "Invalid `line directive (file name end)."); + return; + } + + /* Skip the space after the file name. */ + cp = fn_end + 1; + cpr = cp; + cpr += strspn(cp, " \t"); + if (cp == cpr) { + VLerror(yylloc, "Invalid `line directive (missing space after " + "file name)."); + return; + } + cp = cpr; + + /* Check that the level is correct, we do not need the level. */ + if (strspn(cp, "012") != 1) { + VLerror(yylloc, "Invalid level for `line directive."); + return; + } + cp += 1; + + /* Verify that only space and/or a single line comment is left. */ + cp += strspn(cp, " \t"); + if (strncmp(cp, "//", 2) != 0 && + (size_t)(cp-yytext) != strlen(yytext)) { + VLerror(yylloc, "Invalid `line directive (extra garbage after " + "level)."); + return; + } + + /* Copy the file name and assign it and the line number to yylloc. */ + char*buf = new char[fn_end-fn_start+1]; + strncpy(buf, fn_start, fn_end-fn_start); + buf[fn_end-fn_start] = 0; + + yylloc.text = set_file_name(buf); + yylloc.first_line = lineno; +} + +/* + * Reset all compiler directives. This will be called when a `resetall + * directive is encountered or when a new compilation unit is started. + */ +static void reset_all() +{ + pform_set_default_nettype(NetNet::WIRE, yylloc.text, yylloc.first_line); + in_celldefine = false; + uc_drive = UCD_NONE; + pform_set_timescale(def_ts_units, def_ts_prec, 0, 0); +} + +extern FILE*vl_input; +void reset_lexor() +{ + yyrestart(vl_input); + yylloc.first_line = 1; + + /* Announce the first file name. */ + yylloc.text = set_file_name(strdupnew(vl_file.c_str())); + + if (separate_compilation) { + reset_all(); + if (!keyword_mask_stack.empty()) { + lexor_keyword_mask = keyword_mask_stack.back(); + keyword_mask_stack.clear(); + } + } +} + +/* + * Modern version of flex (>=2.5.9) can clean up the scanner data. + */ +void destroy_lexor() +{ +# ifdef FLEX_SCANNER +# if YY_FLEX_MAJOR_VERSION >= 2 && YY_FLEX_MINOR_VERSION >= 5 +# if YY_FLEX_MINOR_VERSION > 5 || defined(YY_FLEX_SUBMINOR_VERSION) && YY_FLEX_SUBMINOR_VERSION >= 9 + yylex_destroy(); +# endif +# endif +# endif +} +""" + +def t_timescale_error(t): + print("%d: Timescale error '%s'" % (t.lexer.lineno, t.value[0])) + print(t.value) + raise RuntimeError + +""" +def t_module_error(t): + print("%d: Module error '%s'" % (t.lexer.lineno, t.value[0])) + print(t.value) + raise RuntimeError +""" + +def t_error(t): + print("%d: Illegal character '%s'" % (t.lexer.lineno, t.value[0])) + print(t.value) + t.lexer.skip(1) + +tokens = list(set(tokens)) + +lex.lex() + +if __name__ == '__main__': + lex.runmain() + diff --git a/parse.py b/parse.py new file mode 100644 index 0000000..e7b86cf --- /dev/null +++ b/parse.py @@ -0,0 +1,1491 @@ +# %{ +# /* +# * Copyright (c) 1998-2017 Stephen Williams (steve@icarus.com) +# * Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com) +# * +# * This source code is free software; you can redistribute it +# * and/or modify it in source code form under the terms of the GNU +# * General Public License as published by the Free Software +# * Foundation; either version 2 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, write to the Free Software +# * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# */ +# +# # include "config.h" +# +# # include "parse_misc.h" +# # include "compiler.h" +# # include "pform.h" +# # include "Statement.h" +# # include "PSpec.h" +# # include +# # include +# # include +# +# class PSpecPath; +# +# extern void lex_end_table(); +# +# static list* param_active_range = 0; +# static bool param_active_signed = false; +# static ivl_variable_type_t param_active_type = IVL_VT_LOGIC; +# +# /* Port declaration lists use this structure for context. */ +# static struct { +# NetNet::Type port_net_type; +# NetNet::PortType port_type; +# data_type_t* data_type; +# } port_declaration_context = {NetNet::NONE, NetNet::NOT_A_PORT, 0}; +# +# /* Modport port declaration lists use this structure for context. */ +# enum modport_port_type_t { MP_NONE, MP_SIMPLE, MP_TF, MP_CLOCKING }; +# static struct { +# modport_port_type_t type; +# union { +# NetNet::PortType direction; +# bool is_import; +# }; +# } last_modport_port = { MP_NONE, {NetNet::NOT_A_PORT}}; +# +# /* The task and function rules need to briefly hold the pointer to the +# task/function that is currently in progress. */ +# static PTask* current_task = 0; +# static PFunction* current_function = 0; +# static stack current_block_stack; +# +# /* The variable declaration rules need to know if a lifetime has been +# specified. */ +# static LexicalScope::lifetime_t var_lifetime; +# +# static pform_name_t* pform_create_this(void) +# { +# name_component_t name (perm_string::literal("@")); +# pform_name_t*res = new pform_name_t; +# res->push_back(name); +# return res; +# } +# +# static pform_name_t* pform_create_super(void) +# { +# name_component_t name (perm_string::literal("#")); +# pform_name_t*res = new pform_name_t; +# res->push_back(name); +# return res; +# } +# +# /* This is used to keep track of the extra arguments after the notifier +# * in the $setuphold and $recrem timing checks. This allows us to print +# * a warning message that the delayed signals will not be created. We +# * need to do this since not driving these signals creates real +# * simulation issues. */ +# static unsigned args_after_notifier; +# +# /* The rules sometimes push attributes into a global context where +# sub-rules may grab them. This makes parser rules a little easier to +# write in some cases. */ +# static list*attributes_in_context = 0; +# +# /* Later version of bison (including 1.35) will not compile in stack +# extension if the output is compiled with C++ and either the YYSTYPE +# or YYLTYPE are provided by the source code. However, I can get the +# old behavior back by defining these symbols. */ +# # define YYSTYPE_IS_TRIVIAL 1 +# # define YYLTYPE_IS_TRIVIAL 1 +# +# /* Recent version of bison expect that the user supply a +# YYLLOC_DEFAULT macro that makes up a yylloc value from existing +# values. I need to supply an explicit version to account for the +# text field, that otherwise won't be copied. +# +# The YYLLOC_DEFAULT blends the file range for the tokens of Rhs +# rule, which has N tokens. +# */ +# # define YYLLOC_DEFAULT(Current, Rhs, N) do { \ +# if (N) { \ +# (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ +# (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ +# (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ +# (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ +# (Current).text = YYRHSLOC (Rhs, 1).text; \ +# } else { \ +# (Current).first_line = YYRHSLOC (Rhs, 0).last_line; \ +# (Current).first_column = YYRHSLOC (Rhs, 0).last_column; \ +# (Current).last_line = YYRHSLOC (Rhs, 0).last_line; \ +# (Current).last_column = YYRHSLOC (Rhs, 0).last_column; \ +# (Current).text = YYRHSLOC (Rhs, 0).text; \ +# } \ +# } while (0) +# +# /* +# * These are some common strength pairs that are used as defaults when +# * the user is not otherwise specific. +# */ +# static const struct str_pair_t pull_strength = { IVL_DR_PULL, IVL_DR_PULL }; +# static const struct str_pair_t str_strength = { IVL_DR_STRONG, IVL_DR_STRONG }; +# +# static list* make_port_list(char*id, list*udims, PExpr*expr) +# { +# list*tmp = new list; +# tmp->push_back(pform_port_t(lex_strings.make(id), udims, expr)); +# delete[]id; +# return tmp; +# } +# static list* make_port_list(list*tmp, +# char*id, list*udims, PExpr*expr) +# { +# tmp->push_back(pform_port_t(lex_strings.make(id), udims, expr)); +# delete[]id; +# return tmp; +# } +# +# list* make_range_from_width(uint64_t wid) +# { +# pform_range_t range; +# range.first = new PENumber(new verinum(wid-1, integer_width)); +# range.second = new PENumber(new verinum((uint64_t)0, integer_width)); +# +# list*rlist = new list; +# rlist->push_back(range); +# return rlist; +# } +# +# static list* list_from_identifier(char*id) +# { +# list*tmp = new list; +# tmp->push_back(lex_strings.make(id)); +# delete[]id; +# return tmp; +# } +# +# static list* list_from_identifier(list*tmp, char*id) +# { +# tmp->push_back(lex_strings.make(id)); +# delete[]id; +# return tmp; +# } +# +# list* copy_range(list* orig) +# { +# list*copy = 0; +# +# if (orig) +# copy = new list (*orig); +# +# return copy; +# } +# +# template void append(vector&out, const vector&in) +# { +# for (size_t idx = 0 ; idx < in.size() ; idx += 1) +# out.push_back(in[idx]); +# } +# +# /* +# * Look at the list and pull null pointers off the end. +# */ +# static void strip_tail_items(list*lst) +# { +# while (! lst->empty()) { +# if (lst->back() != 0) +# return; +# lst->pop_back(); +# } +# } +# +# /* +# * This is a shorthand for making a PECallFunction that takes a single +# * arg. This is used by some of the code that detects built-ins. +# */ +# static PECallFunction*make_call_function(perm_string tn, PExpr*arg) +# { +# vector parms(1); +# parms[0] = arg; +# PECallFunction*tmp = new PECallFunction(tn, parms); +# return tmp; +# } +# +# static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2) +# { +# vector parms(2); +# parms[0] = arg1; +# parms[1] = arg2; +# PECallFunction*tmp = new PECallFunction(tn, parms); +# return tmp; +# } +# +# static list* make_named_numbers(perm_string name, long first, long last, PExpr*val =0) +# { +# list*lst = new list; +# named_pexpr_t tmp; +# // We are counting up. +# if (first <= last) { +# for (long idx = first ; idx <= last ; idx += 1) { +# ostringstream buf; +# buf << name.str() << idx << ends; +# tmp.name = lex_strings.make(buf.str()); +# tmp.parm = val; +# val = 0; +# lst->push_back(tmp); +# } +# // We are counting down. +# } else { +# for (long idx = first ; idx >= last ; idx -= 1) { +# ostringstream buf; +# buf << name.str() << idx << ends; +# tmp.name = lex_strings.make(buf.str()); +# tmp.parm = val; +# val = 0; +# lst->push_back(tmp); +# } +# } +# return lst; +# } +# +# static list* make_named_number(perm_string name, PExpr*val =0) +# { +# list*lst = new list; +# named_pexpr_t tmp; +# tmp.name = name; +# tmp.parm = val; +# lst->push_back(tmp); +# return lst; +# } +# +# static long check_enum_seq_value(const YYLTYPE&loc, verinum *arg, bool zero_ok) +# { +# long value = 1; +# // We can never have an undefined value in an enumeration name +# // declaration sequence. +# if (! arg->is_defined()) { +# yyerror(loc, "error: undefined value used in enum name sequence."); +# // We can never have a negative value in an enumeration name +# // declaration sequence. +# } else if (arg->is_negative()) { +# yyerror(loc, "error: negative value used in enum name sequence."); +# } else { +# value = arg->as_ulong(); +# // We cannot have a zero enumeration name declaration count. +# if (! zero_ok && (value == 0)) { +# yyerror(loc, "error: zero count used in enum name sequence."); +# value = 1; +# } +# } +# return value; +# } +# +# static void current_task_set_statement(const YYLTYPE&loc, vector*s) +# { +# if (s == 0) { +# /* if the statement list is null, then the parser +# detected the case that there are no statements in the +# task. If this is SystemVerilog, handle it as an +# an empty block. */ +# if (!gn_system_verilog()) { +# yyerror(loc, "error: Support for empty tasks requires SystemVerilog."); +# } +# PBlock*tmp = new PBlock(PBlock::BL_SEQ); +# FILE_NAME(tmp, loc); +# current_task->set_statement(tmp); +# return; +# } +# assert(s); +# +# /* An empty vector represents one or more null statements. Handle +# this as a simple null statement. */ +# if (s->empty()) +# return; +# +# /* A vector of 1 is handled as a simple statement. */ +# if (s->size() == 1) { +# current_task->set_statement((*s)[0]); +# return; +# } +# +# if (!gn_system_verilog()) { +# yyerror(loc, "error: Task body with multiple statements requires SystemVerilog."); +# } +# +# PBlock*tmp = new PBlock(PBlock::BL_SEQ); +# FILE_NAME(tmp, loc); +# tmp->set_statement(*s); +# current_task->set_statement(tmp); +# } +# +# static void current_function_set_statement(const YYLTYPE&loc, vector*s) +# { +# if (s == 0) { +# /* if the statement list is null, then the parser +# detected the case that there are no statements in the +# task. If this is SystemVerilog, handle it as an +# an empty block. */ +# if (!gn_system_verilog()) { +# yyerror(loc, "error: Support for empty functions requires SystemVerilog."); +# } +# PBlock*tmp = new PBlock(PBlock::BL_SEQ); +# FILE_NAME(tmp, loc); +# current_function->set_statement(tmp); +# return; +# } +# assert(s); +# +# /* An empty vector represents one or more null statements. Handle +# this as a simple null statement. */ +# if (s->empty()) +# return; +# +# /* A vector of 1 is handled as a simple statement. */ +# if (s->size() == 1) { +# current_function->set_statement((*s)[0]); +# return; +# } +# +# if (!gn_system_verilog()) { +# yyerror(loc, "error: Function body with multiple statements requires SystemVerilog."); +# } +# +# PBlock*tmp = new PBlock(PBlock::BL_SEQ); +# FILE_NAME(tmp, loc); +# tmp->set_statement(*s); +# current_function->set_statement(tmp); +# } +# +# %} +('tokens = ', "['IDENTIFIER', 'SYSTEM_IDENTIFIER', 'STRING', 'TIME_LITERAL', 'TYPE_IDENTIFIER', 'PACKAGE_IDENTIFIER', 'DISCIPLINE_IDENTIFIER', 'PATHPULSE_IDENTIFIER', 'BASED_NUMBER', 'DEC_NUMBER', 'UNBASED_NUMBER', 'REALTIME', 'K_PLUS_EQ', 'K_MINUS_EQ', 'K_INCR', 'K_DECR', 'K_LE', 'K_GE', 'K_EG', 'K_EQ', 'K_NE', 'K_CEQ', 'K_CNE', 'K_WEQ', 'K_WNE', 'K_LP', 'K_LS', 'K_RS', 'K_RSS', 'K_SG', 'K_CONTRIBUTE', 'K_PO_POS', 'K_PO_NEG', 'K_POW', 'K_PSTAR', 'K_STARP', 'K_DOTSTAR', 'K_LOR', 'K_LAND', 'K_NAND', 'K_NOR', 'K_NXOR', 'K_TRIGGER', 'K_SCOPE_RES', 'K_edge_descriptor', 'K_always', 'K_and', 'K_assign', 'K_begin', 'K_buf', 'K_bufif0', 'K_bufif1', 'K_case', 'K_casex', 'K_casez', 'K_cmos', 'K_deassign', 'K_default', 'K_defparam', 'K_disable', 'K_edge', 'K_else', 'K_end', 'K_endcase', 'K_endfunction', 'K_endmodule', 'K_endprimitive', 'K_endspecify', 'K_endtable', 'K_endtask', 'K_event', 'K_for', 'K_force', 'K_forever', 'K_fork', 'K_function', 'K_highz0', 'K_highz1', 'K_if', 'K_ifnone', 'K_initial', 'K_inout', 'K_input', 'K_integer', 'K_join', 'K_large', 'K_macromodule', 'K_medium', 'K_module', 'K_nand', 'K_negedge', 'K_nmos', 'K_nor', 'K_not', 'K_notif0', 'K_notif1', 'K_or', 'K_output', 'K_parameter', 'K_pmos', 'K_posedge', 'K_primitive', 'K_pull0', 'K_pull1', 'K_pulldown', 'K_pullup', 'K_rcmos', 'K_real', 'K_realtime', 'K_reg', 'K_release', 'K_repeat', 'K_rnmos', 'K_rpmos', 'K_rtran', 'K_rtranif0', 'K_rtranif1', 'K_scalared', 'K_small', 'K_specify', 'K_specparam', 'K_strong0', 'K_strong1', 'K_supply0', 'K_supply1', 'K_table', 'K_task', 'K_time', 'K_tran', 'K_tranif0', 'K_tranif1', 'K_tri', 'K_tri0', 'K_tri1', 'K_triand', 'K_trior', 'K_trireg', 'K_vectored', 'K_wait', 'K_wand', 'K_weak0', 'K_weak1', 'K_while', 'K_wire', 'K_wor', 'K_xnor', 'K_xor', 'K_Shold', 'K_Snochange', 'K_Speriod', 'K_Srecovery', 'K_Ssetup', 'K_Ssetuphold', 'K_Sskew', 'K_Swidth', 'KK_attribute', 'K_bool', 'K_logic', 'K_automatic', 'K_endgenerate', 'K_generate', 'K_genvar', 'K_localparam', 'K_noshowcancelled', 'K_pulsestyle_onevent', 'K_pulsestyle_ondetect', 'K_showcancelled', 'K_signed', 'K_unsigned', 'K_Sfullskew', 'K_Srecrem', 'K_Sremoval', 'K_Stimeskew', 'K_cell', 'K_config', 'K_design', 'K_endconfig', 'K_incdir', 'K_include', 'K_instance', 'K_liblist', 'K_library', 'K_use', 'K_wone', 'K_uwire', 'K_alias', 'K_always_comb', 'K_always_ff', 'K_always_latch', 'K_assert', 'K_assume', 'K_before', 'K_bind', 'K_bins', 'K_binsof', 'K_bit', 'K_break', 'K_byte', 'K_chandle', 'K_class', 'K_clocking', 'K_const', 'K_constraint', 'K_context', 'K_continue', 'K_cover', 'K_covergroup', 'K_coverpoint', 'K_cross', 'K_dist', 'K_do', 'K_endclass', 'K_endclocking', 'K_endgroup', 'K_endinterface', 'K_endpackage', 'K_endprogram', 'K_endproperty', 'K_endsequence', 'K_enum', 'K_expect', 'K_export', 'K_extends', 'K_extern', 'K_final', 'K_first_match', 'K_foreach', 'K_forkjoin', 'K_iff', 'K_ignore_bins', 'K_illegal_bins', 'K_import', 'K_inside', 'K_int', 'K_interface', 'K_intersect', 'K_join_any', 'K_join_none', 'K_local', 'K_longint', 'K_matches', 'K_modport', 'K_new', 'K_null', 'K_package', 'K_packed', 'K_priority', 'K_program', 'K_property', 'K_protected', 'K_pure', 'K_rand', 'K_randc', 'K_randcase', 'K_randsequence', 'K_ref', 'K_return', 'K_sequence', 'K_shortint', 'K_shortreal', 'K_solve', 'K_static', 'K_string', 'K_struct', 'K_super', 'K_tagged', 'K_this', 'K_throughout', 'K_timeprecision', 'K_timeunit', 'K_type', 'K_typedef', 'K_union', 'K_unique', 'K_var', 'K_virtual', 'K_void', 'K_wait_order', 'K_wildcard', 'K_with', 'K_within', 'K_accept_on', 'K_checker', 'K_endchecker', 'K_eventually', 'K_global', 'K_implies', 'K_let', 'K_nexttime', 'K_reject_on', 'K_restrict', 'K_s_always', 'K_s_eventually', 'K_s_nexttime', 'K_s_until', 'K_s_until_with', 'K_strong', 'K_sync_accept_on', 'K_sync_reject_on', 'K_unique0', 'K_until', 'K_until_with', 'K_untyped', 'K_weak', 'K_implements', 'K_interconnect', 'K_nettype', 'K_soft', 'K_above', 'K_abs', 'K_absdelay', 'K_abstol', 'K_access', 'K_acos', 'K_acosh', 'K_ac_stim', 'K_aliasparam', 'K_analog', 'K_analysis', 'K_asin', 'K_asinh', 'K_atan', 'K_atan2', 'K_atanh', 'K_branch', 'K_ceil', 'K_connect', 'K_connectmodule', 'K_connectrules', 'K_continuous', 'K_cos', 'K_cosh', 'K_ddt', 'K_ddt_nature', 'K_ddx', 'K_discipline', 'K_discrete', 'K_domain', 'K_driver_update', 'K_endconnectrules', 'K_enddiscipline', 'K_endnature', 'K_endparamset', 'K_exclude', 'K_exp', 'K_final_step', 'K_flicker_noise', 'K_floor', 'K_flow', 'K_from', 'K_ground', 'K_hypot', 'K_idt', 'K_idtmod', 'K_idt_nature', 'K_inf', 'K_initial_step', 'K_laplace_nd', 'K_laplace_np', 'K_laplace_zd', 'K_laplace_zp', 'K_last_crossing', 'K_limexp', 'K_ln', 'K_log', 'K_max', 'K_merged', 'K_min', 'K_nature', 'K_net_resolution', 'K_noise_table', 'K_paramset', 'K_potential', 'K_pow', 'K_resolveto', 'K_sin', 'K_sinh', 'K_slew', 'K_split', 'K_sqrt', 'K_tan', 'K_tanh', 'K_timer', 'K_transition', 'K_units', 'K_white_noise', 'K_wreal', 'K_zi_nd', 'K_zi_np', 'K_zi_zd', 'K_zi_zp', 'K_TAND', 'K_PLUS_EQ', 'K_MINUS_EQ', 'K_MUL_EQ', 'K_DIV_EQ', 'K_MOD_EQ', 'K_AND_EQ', 'K_OR_EQ', 'K_XOR_EQ', 'K_LS_EQ', 'K_RS_EQ', 'K_RSS_EQ', 'K_inside', 'K_LOR', 'K_LAND', 'K_NXOR', 'K_NOR', 'K_NAND', 'K_EQ', 'K_NE', 'K_CEQ', 'K_CNE', 'K_WEQ', 'K_WNE', 'K_GE', 'K_LE', 'K_LS', 'K_RS', 'K_RSS', 'K_POW', 'UNARY_PREC', 'less_than_K_else', 'K_else', 'K_exclude', 'no_timeunits_declaration', 'one_timeunits_declaration', 'K_timeunit', 'K_timeprecision']") +() +('precedence = ', '[(\'right\', \'K_PLUS_EQ\', \'K_MINUS_EQ\', \'K_MUL_EQ\', \'K_DIV_EQ\', \'K_MOD_EQ\', \'K_AND_EQ\', \'K_OR_EQ\'), (\'right\', \'K_XOR_EQ\', \'K_LS_EQ\', \'K_RS_EQ\', \'K_RSS_EQ\'), (\'right\', "\'?\'", "\':\'", \'K_inside\'), (\'left\', \'K_LOR\'), (\'left\', \'K_LAND\'), (\'left\', "\'|\'"), (\'left\', "\'^\'", \'K_NXOR\', \'K_NOR\'), (\'left\', "\'&\'", \'K_NAND\'), (\'left\', \'K_EQ\', \'K_NE\', \'K_CEQ\', \'K_CNE\', \'K_WEQ\', \'K_WNE\'), (\'left\', \'K_GE\', \'K_LE\', "\'<\'", "\'>\'"), (\'left\', \'K_LS\', \'K_RS\', \'K_RSS\'), (\'left\', "\'+\'", "\'-\'"), (\'left\', "\'*\'", "\'/\'", "\'%\'"), (\'left\', \'K_POW\'), (\'left\', \'UNARY_PREC\'), (\'nonassoc\', \'less_than_K_else\'), (\'nonassoc\', \'K_else\'), (\'nonassoc\', "\'(\'"), (\'nonassoc\', \'K_exclude\'), (\'nonassoc\', \'no_timeunits_declaration\'), (\'nonassoc\', \'one_timeunits_declaration\'), (\'nonassoc\', \'K_timeunit\', \'K_timeprecision\')]') +() +# -------------- RULES ---------------- +() +def p_source_text_1(p): + '''source_text : timeunits_declaration_opt _embed0_source_text description_list ''' + print(p) +() +def p_source_text_2(p): + '''source_text : ''' + print(p) +() +def p__embed0_source_text(p): + '''_embed0_source_text : ''' + # { pform_set_scope_timescale(yyloc); } +() +def p_assertion_item_1(p): + '''assertion_item : concurrent_assertion_item ''' + print(p) +() +def p_assignment_pattern_1(p): + '''assignment_pattern : K_LP expression_list_proper '}' ''' + print(p) + # { PEAssignPattern*tmp = new PEAssignPattern(*$2); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_assignment_pattern_2(p): + '''assignment_pattern : K_LP '}' ''' + print(p) + # { PEAssignPattern*tmp = new PEAssignPattern; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_block_identifier_opt_1(p): + '''block_identifier_opt : IDENTIFIER ':' ''' + print(p) +() +def p_block_identifier_opt_2(p): + '''block_identifier_opt : ''' + print(p) +() +def p_class_declaration_1(p): + '''class_declaration : K_virtual_opt K_class lifetime_opt class_identifier class_declaration_extends_opt ';' _embed0_class_declaration class_items_opt K_endclass _embed1_class_declaration class_declaration_endlabel_opt ''' + print(p) + # { // Wrap up the class. + # if ($11 && $4 && $4->name != $11) { + # yyerror(@11, "error: Class end label doesn't match class name."); + # delete[]$11; + # } + # } +() +def p__embed0_class_declaration(p): + '''_embed0_class_declaration : ''' + # { pform_start_class_declaration(@2, $4, $5.type, $5.exprs, $3); } +() +def p__embed1_class_declaration(p): + '''_embed1_class_declaration : ''' + # { // Process a class. + # pform_end_class_declaration(@9); + # } +() +def p_class_constraint_1(p): + '''class_constraint : constraint_prototype ''' + print(p) +() +def p_class_constraint_2(p): + '''class_constraint : constraint_declaration ''' + print(p) +() +def p_class_identifier_1(p): + '''class_identifier : IDENTIFIER ''' + print(p) + # { // Create a synthetic typedef for the class name so that the + # // lexor detects the name as a type. + # perm_string name = lex_strings.make($1); + # class_type_t*tmp = new class_type_t(name); + # FILE_NAME(tmp, @1); + # pform_set_typedef(name, tmp, NULL); + # delete[]$1; + # $$ = tmp; + # } +() +def p_class_identifier_2(p): + '''class_identifier : TYPE_IDENTIFIER ''' + print(p) + # { class_type_t*tmp = dynamic_cast($1.type); + # if (tmp == 0) { + # yyerror(@1, "Type name \"%s\"is not a predeclared class name.", $1.text); + # } + # delete[]$1.text; + # $$ = tmp; + # } +() +def p_class_declaration_endlabel_opt_1(p): + '''class_declaration_endlabel_opt : ':' TYPE_IDENTIFIER ''' + print(p) + # { class_type_t*tmp = dynamic_cast ($2.type); + # if (tmp == 0) { + # yyerror(@2, "error: class declaration endlabel \"%s\" is not a class name\n", $2.text); + # $$ = 0; + # } else { + # $$ = strdupnew(tmp->name.str()); + # } + # delete[]$2.text; + # } +() +def p_class_declaration_endlabel_opt_2(p): + '''class_declaration_endlabel_opt : ':' IDENTIFIER ''' + print(p) + # { $$ = $2; } +() +def p_class_declaration_endlabel_opt_3(p): + '''class_declaration_endlabel_opt : ''' + print(p) + # { $$ = 0; } +() +def p_class_declaration_extends_opt_1(p): + '''class_declaration_extends_opt : K_extends TYPE_IDENTIFIER ''' + print(p) + # { $$.type = $2.type; + # $$.exprs= 0; + # delete[]$2.text; + # } +() +def p_class_declaration_extends_opt_2(p): + '''class_declaration_extends_opt : K_extends TYPE_IDENTIFIER '(' expression_list_with_nuls ')' ''' + print(p) + # { $$.type = $2.type; + # $$.exprs = $4; + # delete[]$2.text; + # } +() +def p_class_declaration_extends_opt_3(p): + '''class_declaration_extends_opt : ''' + print(p) + # { $$.type = 0; $$.exprs = 0; } +() +def p_class_items_opt_1(p): + '''class_items_opt : class_items ''' + print(p) +() +def p_class_items_opt_2(p): + '''class_items_opt : ''' + print(p) +() +def p_class_items_1(p): + '''class_items : class_items class_item ''' + print(p) +() +def p_class_items_2(p): + '''class_items : class_item ''' + print(p) +() +def p_class_item_1(p): + '''class_item : method_qualifier_opt K_function K_new _embed0_class_item '(' tf_port_list_opt ')' ';' function_item_list_opt statement_or_null_list_opt K_endfunction endnew_opt ''' + print(p) + # { current_function->set_ports($6); + # pform_set_constructor_return(current_function); + # pform_set_this_class(@3, current_function); + # current_function_set_statement(@3, $10); + # pform_pop_scope(); + # current_function = 0; + # } +() +def p_class_item_2(p): + '''class_item : property_qualifier_opt data_type list_of_variable_decl_assignments ';' ''' + print(p) + # { pform_class_property(@2, $1, $2, $3); } +() +def p_class_item_3(p): + '''class_item : K_const class_item_qualifier_opt data_type list_of_variable_decl_assignments ';' ''' + print(p) + # { pform_class_property(@1, $2 | property_qualifier_t::make_const(), $3, $4); } +() +def p_class_item_4(p): + '''class_item : method_qualifier_opt task_declaration ''' + print(p) + # { /* The task_declaration rule puts this into the class */ } +() +def p_class_item_5(p): + '''class_item : method_qualifier_opt function_declaration ''' + print(p) + # { /* The function_declaration rule puts this into the class */ } +() +def p_class_item_6(p): + '''class_item : K_extern method_qualifier_opt K_function K_new ';' ''' + print(p) + # { yyerror(@1, "sorry: External constructors are not yet supported."); } +() +def p_class_item_7(p): + '''class_item : K_extern method_qualifier_opt K_function K_new '(' tf_port_list_opt ')' ';' ''' + print(p) + # { yyerror(@1, "sorry: External constructors are not yet supported."); } +() +def p_class_item_8(p): + '''class_item : K_extern method_qualifier_opt K_function data_type_or_implicit_or_void IDENTIFIER ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $5; + # } +() +def p_class_item_9(p): + '''class_item : K_extern method_qualifier_opt K_function data_type_or_implicit_or_void IDENTIFIER '(' tf_port_list_opt ')' ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $5; + # } +() +def p_class_item_10(p): + '''class_item : K_extern method_qualifier_opt K_task IDENTIFIER ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $4; + # } +() +def p_class_item_11(p): + '''class_item : K_extern method_qualifier_opt K_task IDENTIFIER '(' tf_port_list_opt ')' ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $4; + # } +() +def p_class_item_12(p): + '''class_item : class_constraint ''' + print(p) +() +def p_class_item_13(p): + '''class_item : property_qualifier_opt data_type error ';' ''' + print(p) + # { yyerror(@3, "error: Errors in variable names after data type."); + # yyerrok; + # } +() +def p_class_item_14(p): + '''class_item : property_qualifier_opt IDENTIFIER error ';' ''' + print(p) + # { yyerror(@3, "error: %s doesn't name a type.", $2); + # yyerrok; + # } +() +def p_class_item_15(p): + '''class_item : method_qualifier_opt K_function K_new error K_endfunction endnew_opt ''' + print(p) + # { yyerror(@1, "error: I give up on this class constructor declaration."); + # yyerrok; + # } +() +def p_class_item_16(p): + '''class_item : error ';' ''' + print(p) + # { yyerror(@2, "error: invalid class item."); + # yyerrok; + # } +() +def p__embed0_class_item(p): + '''_embed0_class_item : ''' + # { assert(current_function==0); + # current_function = pform_push_constructor_scope(@3); + # } +() +def p_class_item_qualifier_1(p): + '''class_item_qualifier : K_static ''' + print(p) + # { $$ = property_qualifier_t::make_static(); } +() +def p_class_item_qualifier_2(p): + '''class_item_qualifier : K_protected ''' + print(p) + # { $$ = property_qualifier_t::make_protected(); } +() +def p_class_item_qualifier_3(p): + '''class_item_qualifier : K_local ''' + print(p) + # { $$ = property_qualifier_t::make_local(); } +() +def p_class_item_qualifier_list_1(p): + '''class_item_qualifier_list : class_item_qualifier_list class_item_qualifier ''' + print(p) + # { $$ = $1 | $2; } +() +def p_class_item_qualifier_list_2(p): + '''class_item_qualifier_list : class_item_qualifier ''' + print(p) + # { $$ = $1; } +() +def p_class_item_qualifier_opt_1(p): + '''class_item_qualifier_opt : class_item_qualifier_list ''' + print(p) + # { $$ = $1; } +() +def p_class_item_qualifier_opt_2(p): + '''class_item_qualifier_opt : ''' + print(p) + # { $$ = property_qualifier_t::make_none(); } +() +def p_class_new_1(p): + '''class_new : K_new '(' expression_list_with_nuls ')' ''' + print(p) + # { list*expr_list = $3; + # strip_tail_items(expr_list); + # PENewClass*tmp = new PENewClass(*expr_list); + # FILE_NAME(tmp, @1); + # delete $3; + # $$ = tmp; + # } +() +def p_class_new_2(p): + '''class_new : K_new hierarchy_identifier ''' + print(p) + # { PEIdent*tmpi = new PEIdent(*$2); + # FILE_NAME(tmpi, @2); + # PENewCopy*tmp = new PENewCopy(tmpi); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_class_new_3(p): + '''class_new : K_new ''' + print(p) + # { PENewClass*tmp = new PENewClass; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_concurrent_assertion_item_1(p): + '''concurrent_assertion_item : block_identifier_opt K_assert K_property '(' property_spec ')' statement_or_null ''' + print(p) + # { /* */ + # if (gn_assertions_flag) { + # yyerror(@2, "sorry: concurrent_assertion_item not supported." + # " Try -gno-assertion to turn this message off."); + # } + # } +() +def p_concurrent_assertion_item_2(p): + '''concurrent_assertion_item : block_identifier_opt K_assert K_property '(' error ')' statement_or_null ''' + print(p) + # { yyerrok; + # yyerror(@2, "error: Error in property_spec of concurrent assertion item."); + # } +() +def p_constraint_block_item_1(p): + '''constraint_block_item : constraint_expression ''' + print(p) +() +def p_constraint_block_item_list_1(p): + '''constraint_block_item_list : constraint_block_item_list constraint_block_item ''' + print(p) +() +def p_constraint_block_item_list_2(p): + '''constraint_block_item_list : constraint_block_item ''' + print(p) +() +def p_constraint_block_item_list_opt_1(p): + '''constraint_block_item_list_opt : ''' + print(p) +() +def p_constraint_block_item_list_opt_2(p): + '''constraint_block_item_list_opt : constraint_block_item_list ''' + print(p) +() +def p_constraint_declaration_1(p): + '''constraint_declaration : K_static_opt K_constraint IDENTIFIER '{' constraint_block_item_list_opt '}' ''' + print(p) + # { yyerror(@2, "sorry: Constraint declarations not supported."); } +() +def p_constraint_declaration_2(p): + '''constraint_declaration : K_static_opt K_constraint IDENTIFIER '{' error '}' ''' + print(p) + # { yyerror(@4, "error: Errors in the constraint block item list."); } +() +def p_constraint_expression_1(p): + '''constraint_expression : expression ';' ''' + print(p) +() +def p_constraint_expression_2(p): + '''constraint_expression : expression K_dist '{' '}' ';' ''' + print(p) +() +def p_constraint_expression_3(p): + '''constraint_expression : expression K_TRIGGER constraint_set ''' + print(p) +() +def p_constraint_expression_4(p): + '''constraint_expression : K_if '(' expression ')' constraint_set %prec less_than_K_else ''' + print(p) +() +def p_constraint_expression_5(p): + '''constraint_expression : K_if '(' expression ')' constraint_set K_else constraint_set ''' + print(p) +() +def p_constraint_expression_6(p): + '''constraint_expression : K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' constraint_set ''' + print(p) +() +def p_constraint_expression_list_1(p): + '''constraint_expression_list : constraint_expression_list constraint_expression ''' + print(p) +() +def p_constraint_expression_list_2(p): + '''constraint_expression_list : constraint_expression ''' + print(p) +() +def p_constraint_prototype_1(p): + '''constraint_prototype : K_static_opt K_constraint IDENTIFIER ';' ''' + print(p) + # { yyerror(@2, "sorry: Constraint prototypes not supported."); } +() +def p_constraint_set_1(p): + '''constraint_set : constraint_expression ''' + print(p) +() +def p_constraint_set_2(p): + '''constraint_set : '{' constraint_expression_list '}' ''' + print(p) +() +def p_data_declaration_1(p): + '''data_declaration : attribute_list_opt data_type_or_implicit list_of_variable_decl_assignments ';' ''' + print(p) + # { data_type_t*data_type = $2; + # if (data_type == 0) { + # data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + # FILE_NAME(data_type, @2); + # } + # pform_makewire(@2, 0, str_strength, $3, NetNet::IMPLICIT_REG, data_type); + # } +() +def p_data_type_1(p): + '''data_type : integer_vector_type unsigned_signed_opt dimensions_opt ''' + print(p) + # { ivl_variable_type_t use_vtype = $1; + # bool reg_flag = false; + # if (use_vtype == IVL_VT_NO_TYPE) { + # use_vtype = IVL_VT_LOGIC; + # reg_flag = true; + # } + # vector_type_t*tmp = new vector_type_t(use_vtype, $2, $3); + # tmp->reg_flag = reg_flag; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_2(p): + '''data_type : non_integer_type ''' + print(p) + # { real_type_t*tmp = new real_type_t($1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_3(p): + '''data_type : struct_data_type ''' + print(p) + # { if (!$1->packed_flag) { + # yyerror(@1, "sorry: Unpacked structs not supported."); + # } + # $$ = $1; + # } +() +def p_data_type_4(p): + '''data_type : enum_data_type ''' + print(p) + # { $$ = $1; } +() +def p_data_type_5(p): + '''data_type : atom2_type signed_unsigned_opt ''' + print(p) + # { atom2_type_t*tmp = new atom2_type_t($1, $2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_6(p): + '''data_type : K_integer signed_unsigned_opt ''' + print(p) + # { list*pd = make_range_from_width(integer_width); + # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $2, pd); + # tmp->reg_flag = true; + # tmp->integer_flag = true; + # $$ = tmp; + # } +() +def p_data_type_7(p): + '''data_type : K_time ''' + print(p) + # { list*pd = make_range_from_width(64); + # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, pd); + # tmp->reg_flag = !gn_system_verilog(); + # $$ = tmp; + # } +() +def p_data_type_8(p): + '''data_type : TYPE_IDENTIFIER dimensions_opt ''' + print(p) + # { if ($2) { + # parray_type_t*tmp = new parray_type_t($1.type, $2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } else $$ = $1.type; + # delete[]$1.text; + # } +() +def p_data_type_9(p): + '''data_type : PACKAGE_IDENTIFIER K_SCOPE_RES _embed0_data_type TYPE_IDENTIFIER ''' + print(p) + # { lex_in_package_scope(0); + # $$ = $4.type; + # delete[]$4.text; + # } +() +def p_data_type_10(p): + '''data_type : K_string ''' + print(p) + # { string_type_t*tmp = new string_type_t; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p__embed0_data_type(p): + '''_embed0_data_type : ''' + # { lex_in_package_scope($1); } +() +def p_data_type_or_implicit_1(p): + '''data_type_or_implicit : data_type ''' + print(p) + # { $$ = $1; } +() +def p_data_type_or_implicit_2(p): + '''data_type_or_implicit : signing dimensions_opt ''' + print(p) + # { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $1, $2); + # tmp->implicit_flag = true; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_or_implicit_3(p): + '''data_type_or_implicit : dimensions ''' + print(p) + # { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, $1); + # tmp->implicit_flag = true; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_or_implicit_4(p): + '''data_type_or_implicit : ''' + print(p) + # { $$ = 0; } +() +def p_data_type_or_implicit_or_void_1(p): + '''data_type_or_implicit_or_void : data_type_or_implicit ''' + print(p) + # { $$ = $1; } +() +def p_data_type_or_implicit_or_void_2(p): + '''data_type_or_implicit_or_void : K_void ''' + print(p) + # { void_type_t*tmp = new void_type_t; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_description_1(p): + '''description : module ''' + print(p) +() +def p_description_2(p): + '''description : udp_primitive ''' + print(p) +() +def p_description_3(p): + '''description : config_declaration ''' + print(p) +() +def p_description_4(p): + '''description : nature_declaration ''' + print(p) +() +def p_description_5(p): + '''description : package_declaration ''' + print(p) +() +def p_description_6(p): + '''description : discipline_declaration ''' + print(p) +() +def p_description_7(p): + '''description : package_item ''' + print(p) +() +def p_description_8(p): + '''description : KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ''' + print(p) + # { perm_string tmp3 = lex_strings.make($3); + # pform_set_type_attrib(tmp3, $5, $7); + # delete[] $3; + # delete[] $5; + # } +() +def p_description_list_1(p): + '''description_list : description ''' + print(p) +() +def p_description_list_2(p): + '''description_list : description_list description ''' + print(p) +() +def p_endnew_opt_1(p): + '''endnew_opt : ':' K_new ''' + print(p) +() +def p_endnew_opt_2(p): + '''endnew_opt : ''' + print(p) +() +def p_dynamic_array_new_1(p): + '''dynamic_array_new : K_new '[' expression ']' ''' + print(p) + # { $$ = new PENewArray($3, 0); + # FILE_NAME($$, @1); + # } +() +def p_dynamic_array_new_2(p): + '''dynamic_array_new : K_new '[' expression ']' '(' expression ')' ''' + print(p) + # { $$ = new PENewArray($3, $6); + # FILE_NAME($$, @1); + # } +() +def p_for_step_1(p): + '''for_step : lpvalue '=' expression ''' + print(p) + # { PAssign*tmp = new PAssign($1,$3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_for_step_2(p): + '''for_step : inc_or_dec_expression ''' + print(p) + # { $$ = pform_compressed_assign_from_inc_dec(@1, $1); } +() +def p_for_step_3(p): + '''for_step : compressed_statement ''' + print(p) + # { $$ = $1; } +() +def p_function_declaration_1(p): + '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER ';' _embed0_function_declaration function_item_list statement_or_null_list_opt K_endfunction _embed1_function_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. + # if ($11) { + # if (strcmp($4,$11) != 0) { + # yyerror(@11, "error: End label doesn't match " + # "function name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@11, "error: Function end labels require " + # "SystemVerilog."); + # } + # delete[]$11; + # } + # delete[]$4; + # } +() +def p_function_declaration_2(p): + '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER _embed2_function_declaration '(' tf_port_list_opt ')' ';' block_item_decls_opt statement_or_null_list_opt K_endfunction _embed3_function_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. + # if ($14) { + # if (strcmp($4,$14) != 0) { + # yyerror(@14, "error: End label doesn't match " + # "function name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@14, "error: Function end labels require " + # "SystemVerilog."); + # } + # delete[]$14; + # } + # delete[]$4; + # } +() +def p_function_declaration_3(p): + '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER error K_endfunction _embed4_function_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. + # if ($8) { + # if (strcmp($4,$8) != 0) { + # yyerror(@8, "error: End label doesn't match function name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@8, "error: Function end labels require " + # "SystemVerilog."); + # } + # delete[]$8; + # } + # delete[]$4; + # } +() +def p__embed0_function_declaration(p): + '''_embed0_function_declaration : ''' + # { assert(current_function == 0); + # current_function = pform_push_function_scope(@1, $4, $2); + # } +() +def p__embed1_function_declaration(p): + '''_embed1_function_declaration : ''' + # { current_function->set_ports($7); + # current_function->set_return($3); + # current_function_set_statement($8? @8 : @4, $8); + # pform_set_this_class(@4, current_function); + # pform_pop_scope(); + # current_function = 0; + # } +() +def p__embed2_function_declaration(p): + '''_embed2_function_declaration : ''' + # { assert(current_function == 0); + # current_function = pform_push_function_scope(@1, $4, $2); + # } +() +def p__embed3_function_declaration(p): + '''_embed3_function_declaration : ''' + # { current_function->set_ports($7); + # current_function->set_return($3); + # current_function_set_statement($11? @11 : @4, $11); + # pform_set_this_class(@4, current_function); + # pform_pop_scope(); + # current_function = 0; + # if ($7==0 && !gn_system_verilog()) { + # yyerror(@4, "error: Empty parenthesis syntax requires SystemVerilog."); + # } + # } +() +def p__embed4_function_declaration(p): + '''_embed4_function_declaration : ''' + # { /* */ + # if (current_function) { + # pform_pop_scope(); + # current_function = 0; + # } + # assert(current_function == 0); + # yyerror(@1, "error: Syntax error defining function."); + # yyerrok; + # } +() +def p_import_export_1(p): + '''import_export : K_import ''' + print(p) + # { $$ = true; } +() +def p_import_export_2(p): + '''import_export : K_export ''' + print(p) + # { $$ = false; } +() +def p_implicit_class_handle_1(p): + '''implicit_class_handle : K_this ''' + print(p) + # { $$ = pform_create_this(); } +() +def p_implicit_class_handle_2(p): + '''implicit_class_handle : K_super ''' + print(p) + # { $$ = pform_create_super(); } +() +def p_inc_or_dec_expression_1(p): + '''inc_or_dec_expression : K_INCR lpvalue %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('I', $2); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_inc_or_dec_expression_2(p): + '''inc_or_dec_expression : lpvalue K_INCR %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('i', $1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_inc_or_dec_expression_3(p): + '''inc_or_dec_expression : K_DECR lpvalue %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('D', $2); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_inc_or_dec_expression_4(p): + '''inc_or_dec_expression : lpvalue K_DECR %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('d', $1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_inside_expression_1(p): + '''inside_expression : expression K_inside '{' open_range_list '}' ''' + print(p) + # { yyerror(@2, "sorry: \"inside\" expressions not supported yet."); + # $$ = 0; + # } +() +def p_integer_vector_type_1(p): + '''integer_vector_type : K_reg ''' + print(p) + # { $$ = IVL_VT_NO_TYPE; } +() +def p_integer_vector_type_2(p): + '''integer_vector_type : K_bit ''' + print(p) + # { $$ = IVL_VT_BOOL; } +() +def p_integer_vector_type_3(p): + '''integer_vector_type : K_logic ''' + print(p) + # { $$ = IVL_VT_LOGIC; } +() +def p_integer_vector_type_4(p): + '''integer_vector_type : K_bool ''' + print(p) + # { $$ = IVL_VT_BOOL; } +() +def p_join_keyword_1(p): + '''join_keyword : K_join ''' + print(p) + # { $$ = PBlock::BL_PAR; } +() +def p_join_keyword_2(p): + '''join_keyword : K_join_none ''' + print(p) + # { $$ = PBlock::BL_JOIN_NONE; } +() +def p_join_keyword_3(p): + '''join_keyword : K_join_any ''' + print(p) + # { $$ = PBlock::BL_JOIN_ANY; } +() +def p_jump_statement_1(p): + '''jump_statement : K_break ';' ''' + print(p) + # { yyerror(@1, "sorry: break statements not supported."); + # $$ = 0; + # } +() +def p_jump_statement_2(p): + '''jump_statement : K_return ';' ''' + print(p) + # { PReturn*tmp = new PReturn(0); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_jump_statement_3(p): + '''jump_statement : K_return expression ';' ''' + print(p) + # { PReturn*tmp = new PReturn($2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_lifetime_1(p): + '''lifetime : K_automatic ''' + print(p) + # { $$ = LexicalScope::AUTOMATIC; } +() +def p_lifetime_2(p): + '''lifetime : K_static ''' + print(p) + # { $$ = LexicalScope::STATIC; } +() +def p_lifetime_opt_1(p): + '''lifetime_opt : lifetime ''' + print(p) + # { $$ = $1; } +() +def p_lifetime_opt_2(p): + '''lifetime_opt : ''' + print(p) + # { $$ = LexicalScope::INHERITED; } +() +def p_loop_statement_1(p): + '''loop_statement : K_for '(' lpvalue '=' expression ';' expression ';' for_step ')' statement_or_null ''' + print(p) + # { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_2(p): + '''loop_statement : K_for '(' data_type IDENTIFIER '=' expression ';' expression ';' for_step ')' _embed0_loop_statement statement_or_null ''' + print(p) + # { pform_name_t tmp_hident; + # tmp_hident.push_back(name_component_t(lex_strings.make($4))); + # + # PEIdent*tmp_ident = pform_new_ident(tmp_hident); + # FILE_NAME(tmp_ident, @4); + # + # PForStatement*tmp_for = new PForStatement(tmp_ident, $6, $8, $10, $13); + # FILE_NAME(tmp_for, @1); + # + # pform_pop_scope(); + # vectortmp_for_list (1); + # tmp_for_list[0] = tmp_for; + # PBlock*tmp_blk = current_block_stack.top(); + # current_block_stack.pop(); + # tmp_blk->set_statement(tmp_for_list); + # $$ = tmp_blk; + # delete[]$4; + # } +() +def p_loop_statement_3(p): + '''loop_statement : K_forever statement_or_null ''' + print(p) + # { PForever*tmp = new PForever($2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_4(p): + '''loop_statement : K_repeat '(' expression ')' statement_or_null ''' + print(p) + # { PRepeat*tmp = new PRepeat($3, $5); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_5(p): + '''loop_statement : K_while '(' expression ')' statement_or_null ''' + print(p) + # { PWhile*tmp = new PWhile($3, $5); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_6(p): + '''loop_statement : K_do statement_or_null K_while '(' expression ')' ';' ''' + print(p) + # { PDoWhile*tmp = new PDoWhile($5, $2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_7(p): + '''loop_statement : K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' _embed1_loop_statement statement_or_null ''' + print(p) + # { PForeach*tmp_for = pform_make_foreach(@1, $3, $5, $9); + # + # pform_pop_scope(); + # vectortmp_for_list(1); + # tmp_for_list[0] = tmp_for; + # PBlock*tmp_blk = current_block_stack.top(); + # current_block_stack.pop(); + # tmp_blk->set_statement(tmp_for_list); + # $$ = tmp_blk; + # } +() +def p_loop_statement_8(p): + '''loop_statement : K_for '(' lpvalue '=' expression ';' expression ';' error ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in for loop step assignment."); + # } +() +def p_loop_statement_9(p): + '''loop_statement : K_for '(' lpvalue '=' expression ';' error ';' for_step ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in for loop condition expression."); + # } +() +def p_loop_statement_10(p): + '''loop_statement : K_for '(' error ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Incomprehensible for loop."); + # } +() +def p_loop_statement_11(p): + '''loop_statement : K_while '(' error ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in while loop condition."); + # } +() +def p_loop_statement_12(p): + '''loop_statement : K_do statement_or_null K_while '(' error ')' ';' ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in do/while loop condition."); + # } +() +def p_loop_statement_13(p): + '''loop_statement : K_foreach '(' IDENTIFIER '[' error ']' ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@4, "error: Errors in foreach loop variables list."); + # } +() +def p__embed0_loop_statement(p): + '''_embed0_loop_statement : ''' + # { static unsigned for_counter = 0; + # char for_block_name [64]; + # snprintf(for_block_name, sizeof for_block_name, "$ivl_for_loop%u", for_counter); + # for_counter += 1; + # PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # + # listassign_list; + # decl_assignment_t*tmp_assign = new decl_assignment_t; + # tmp_assign->name = lex_strings.make($4); + # assign_list.push_back(tmp_assign); + # pform_makewire(@4, 0, str_strength, &assign_list, NetNet::REG, $3); + # } +() +def p__embed1_loop_statement(p): + '''_embed1_loop_statement : ''' + # { static unsigned foreach_counter = 0; + # char for_block_name[64]; + # snprintf(for_block_name, sizeof for_block_name, "$ivl_foreach%u", foreach_counter); + # foreach_counter += 1; + # + # PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # + # pform_make_foreach_declarations(@1, $5); + # } +() +def p_list_of_variable_decl_assignments_1(p): + '''list_of_variable_decl_assignments : variable_decl_assignment ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # $$ = tmp; + # } +() +def p_list_of_variable_decl_assignments_2(p): + '''list_of_variable_decl_assignments : list_of_variable_decl_assignments ',' variable_decl_assignment ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_variable_decl_assignment_1(p): + '''variable_decl_assignment : IDENTIFIER dimensions_opt ''' + print(p) + # { decl_assignment_t*tmp = new decl_assignment_t; + # tmp->name = lex_strings.make($1); + # if ($2) { + # tmp->index = *$2; + # delete $2; + # } + # delete[]$1; + # $$ = tmp; + # } +() +def p_variable_decl_assignment_2(p): + '''variable_decl_assignment : IDENTIFIER '=' expression ''' + print(p) + # { decl_assignment_t*tmp = new decl_assignment_t; + # tmp->name = lex_strings.make($1); + # tmp->expr .reset($3); + # delete[]$1; + # $$ = tmp; + # } +() +def p_variable_decl_assignment_3(p): + '''variable_decl_assignment : IDENTIFIER '=' K_new '(' ')' ''' + print(p) + # { decl_assignment_t*tmp = new decl_assignment_t; + # tmp->name = lex_strings.make($1); + # PENewClass*expr = new PENewClass; + # FILE_NAME(expr, @3); + # tmp->expr .reset(expr); + # delete[]$1; + # $$ = tmp; + # } +() +def p_loop_variables_1(p): + '''loop_variables : loop_variables ',' IDENTIFIER ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # delete[]$3; + # $$ = tmp; + # } +() +def p_loop_variables_2(p): + '''loop_variables : IDENTIFIER ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # delete[]$1; + # $$ = tmp; + # } +() +def p_method_qualifier_1(p): + '''method_qualifier : K_virtual ''' + print(p) +() +def p_method_qualifier_2(p): + '''method_qualifier : class_item_qualifier ''' + print(p) +() +def p_method_qualifier_opt_1(p): + '''method_qualifier_opt : method_qualifier ''' + print(p) +() +def p_method_qualifier_opt_2(p): + '''method_qualifier_opt : ''' + print(p) +() + +if __name__ == '__main__': + from ply import * + yacc.yacc() + diff --git a/parse.y b/parse.y new file mode 100644 index 0000000..3533f79 --- /dev/null +++ b/parse.y @@ -0,0 +1,6993 @@ + +%{ +/* + * Copyright (c) 1998-2017 Stephen Williams (steve@icarus.com) + * Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +# include "config.h" + +# include "parse_misc.h" +# include "compiler.h" +# include "pform.h" +# include "Statement.h" +# include "PSpec.h" +# include +# include +# include + +class PSpecPath; + +extern void lex_end_table(); + +static list* param_active_range = 0; +static bool param_active_signed = false; +static ivl_variable_type_t param_active_type = IVL_VT_LOGIC; + +/* Port declaration lists use this structure for context. */ +static struct { + NetNet::Type port_net_type; + NetNet::PortType port_type; + data_type_t* data_type; +} port_declaration_context = {NetNet::NONE, NetNet::NOT_A_PORT, 0}; + +/* Modport port declaration lists use this structure for context. */ +enum modport_port_type_t { MP_NONE, MP_SIMPLE, MP_TF, MP_CLOCKING }; +static struct { + modport_port_type_t type; + union { + NetNet::PortType direction; + bool is_import; + }; +} last_modport_port = { MP_NONE, {NetNet::NOT_A_PORT}}; + +/* The task and function rules need to briefly hold the pointer to the + task/function that is currently in progress. */ +static PTask* current_task = 0; +static PFunction* current_function = 0; +static stack current_block_stack; + +/* The variable declaration rules need to know if a lifetime has been + specified. */ +static LexicalScope::lifetime_t var_lifetime; + +static pform_name_t* pform_create_this(void) +{ + name_component_t name (perm_string::literal("@")); + pform_name_t*res = new pform_name_t; + res->push_back(name); + return res; +} + +static pform_name_t* pform_create_super(void) +{ + name_component_t name (perm_string::literal("#")); + pform_name_t*res = new pform_name_t; + res->push_back(name); + return res; +} + +/* This is used to keep track of the extra arguments after the notifier + * in the $setuphold and $recrem timing checks. This allows us to print + * a warning message that the delayed signals will not be created. We + * need to do this since not driving these signals creates real + * simulation issues. */ +static unsigned args_after_notifier; + +/* The rules sometimes push attributes into a global context where + sub-rules may grab them. This makes parser rules a little easier to + write in some cases. */ +static list*attributes_in_context = 0; + +/* Later version of bison (including 1.35) will not compile in stack + extension if the output is compiled with C++ and either the YYSTYPE + or YYLTYPE are provided by the source code. However, I can get the + old behavior back by defining these symbols. */ +# define YYSTYPE_IS_TRIVIAL 1 +# define YYLTYPE_IS_TRIVIAL 1 + +/* Recent version of bison expect that the user supply a + YYLLOC_DEFAULT macro that makes up a yylloc value from existing + values. I need to supply an explicit version to account for the + text field, that otherwise won't be copied. + + The YYLLOC_DEFAULT blends the file range for the tokens of Rhs + rule, which has N tokens. +*/ +# define YYLLOC_DEFAULT(Current, Rhs, N) do { \ + if (N) { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + (Current).text = YYRHSLOC (Rhs, 1).text; \ + } else { \ + (Current).first_line = YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = YYRHSLOC (Rhs, 0).last_column; \ + (Current).last_line = YYRHSLOC (Rhs, 0).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, 0).last_column; \ + (Current).text = YYRHSLOC (Rhs, 0).text; \ + } \ + } while (0) + +/* + * These are some common strength pairs that are used as defaults when + * the user is not otherwise specific. + */ +static const struct str_pair_t pull_strength = { IVL_DR_PULL, IVL_DR_PULL }; +static const struct str_pair_t str_strength = { IVL_DR_STRONG, IVL_DR_STRONG }; + +static list* make_port_list(char*id, list*udims, PExpr*expr) +{ + list*tmp = new list; + tmp->push_back(pform_port_t(lex_strings.make(id), udims, expr)); + delete[]id; + return tmp; +} +static list* make_port_list(list*tmp, + char*id, list*udims, PExpr*expr) +{ + tmp->push_back(pform_port_t(lex_strings.make(id), udims, expr)); + delete[]id; + return tmp; +} + +list* make_range_from_width(uint64_t wid) +{ + pform_range_t range; + range.first = new PENumber(new verinum(wid-1, integer_width)); + range.second = new PENumber(new verinum((uint64_t)0, integer_width)); + + list*rlist = new list; + rlist->push_back(range); + return rlist; +} + +static list* list_from_identifier(char*id) +{ + list*tmp = new list; + tmp->push_back(lex_strings.make(id)); + delete[]id; + return tmp; +} + +static list* list_from_identifier(list*tmp, char*id) +{ + tmp->push_back(lex_strings.make(id)); + delete[]id; + return tmp; +} + +list* copy_range(list* orig) +{ + list*copy = 0; + + if (orig) + copy = new list (*orig); + + return copy; +} + +template void append(vector&out, const vector&in) +{ + for (size_t idx = 0 ; idx < in.size() ; idx += 1) + out.push_back(in[idx]); +} + +/* + * Look at the list and pull null pointers off the end. + */ +static void strip_tail_items(list*lst) +{ + while (! lst->empty()) { + if (lst->back() != 0) + return; + lst->pop_back(); + } +} + +/* + * This is a shorthand for making a PECallFunction that takes a single + * arg. This is used by some of the code that detects built-ins. + */ +static PECallFunction*make_call_function(perm_string tn, PExpr*arg) +{ + vector parms(1); + parms[0] = arg; + PECallFunction*tmp = new PECallFunction(tn, parms); + return tmp; +} + +static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2) +{ + vector parms(2); + parms[0] = arg1; + parms[1] = arg2; + PECallFunction*tmp = new PECallFunction(tn, parms); + return tmp; +} + +static list* make_named_numbers(perm_string name, long first, long last, PExpr*val =0) +{ + list*lst = new list; + named_pexpr_t tmp; + // We are counting up. + if (first <= last) { + for (long idx = first ; idx <= last ; idx += 1) { + ostringstream buf; + buf << name.str() << idx << ends; + tmp.name = lex_strings.make(buf.str()); + tmp.parm = val; + val = 0; + lst->push_back(tmp); + } + // We are counting down. + } else { + for (long idx = first ; idx >= last ; idx -= 1) { + ostringstream buf; + buf << name.str() << idx << ends; + tmp.name = lex_strings.make(buf.str()); + tmp.parm = val; + val = 0; + lst->push_back(tmp); + } + } + return lst; +} + +static list* make_named_number(perm_string name, PExpr*val =0) +{ + list*lst = new list; + named_pexpr_t tmp; + tmp.name = name; + tmp.parm = val; + lst->push_back(tmp); + return lst; +} + +static long check_enum_seq_value(const YYLTYPE&loc, verinum *arg, bool zero_ok) +{ + long value = 1; + // We can never have an undefined value in an enumeration name + // declaration sequence. + if (! arg->is_defined()) { + yyerror(loc, "error: undefined value used in enum name sequence."); + // We can never have a negative value in an enumeration name + // declaration sequence. + } else if (arg->is_negative()) { + yyerror(loc, "error: negative value used in enum name sequence."); + } else { + value = arg->as_ulong(); + // We cannot have a zero enumeration name declaration count. + if (! zero_ok && (value == 0)) { + yyerror(loc, "error: zero count used in enum name sequence."); + value = 1; + } + } + return value; +} + +static void current_task_set_statement(const YYLTYPE&loc, vector*s) +{ + if (s == 0) { + /* if the statement list is null, then the parser + detected the case that there are no statements in the + task. If this is SystemVerilog, handle it as an + an empty block. */ + if (!gn_system_verilog()) { + yyerror(loc, "error: Support for empty tasks requires SystemVerilog."); + } + PBlock*tmp = new PBlock(PBlock::BL_SEQ); + FILE_NAME(tmp, loc); + current_task->set_statement(tmp); + return; + } + assert(s); + + /* An empty vector represents one or more null statements. Handle + this as a simple null statement. */ + if (s->empty()) + return; + + /* A vector of 1 is handled as a simple statement. */ + if (s->size() == 1) { + current_task->set_statement((*s)[0]); + return; + } + + if (!gn_system_verilog()) { + yyerror(loc, "error: Task body with multiple statements requires SystemVerilog."); + } + + PBlock*tmp = new PBlock(PBlock::BL_SEQ); + FILE_NAME(tmp, loc); + tmp->set_statement(*s); + current_task->set_statement(tmp); +} + +static void current_function_set_statement(const YYLTYPE&loc, vector*s) +{ + if (s == 0) { + /* if the statement list is null, then the parser + detected the case that there are no statements in the + task. If this is SystemVerilog, handle it as an + an empty block. */ + if (!gn_system_verilog()) { + yyerror(loc, "error: Support for empty functions requires SystemVerilog."); + } + PBlock*tmp = new PBlock(PBlock::BL_SEQ); + FILE_NAME(tmp, loc); + current_function->set_statement(tmp); + return; + } + assert(s); + + /* An empty vector represents one or more null statements. Handle + this as a simple null statement. */ + if (s->empty()) + return; + + /* A vector of 1 is handled as a simple statement. */ + if (s->size() == 1) { + current_function->set_statement((*s)[0]); + return; + } + + if (!gn_system_verilog()) { + yyerror(loc, "error: Function body with multiple statements requires SystemVerilog."); + } + + PBlock*tmp = new PBlock(PBlock::BL_SEQ); + FILE_NAME(tmp, loc); + tmp->set_statement(*s); + current_function->set_statement(tmp); +} + +%} + +%union { + bool flag; + + char letter; + int int_val; + + /* text items are C strings allocated by the lexor using + strdup. They can be put into lists with the texts type. */ + char*text; + list*perm_strings; + + list*port_list; + + vector* tf_ports; + + pform_name_t*pform_name; + + ivl_discipline_t discipline; + + hname_t*hier; + + list*strings; + + struct str_pair_t drive; + + PCase::Item*citem; + svector*citems; + + lgate*gate; + svector*gates; + + Module::port_t *mport; + LexicalScope::range_t* value_range; + vector*mports; + + named_number_t* named_number; + list* named_numbers; + + named_pexpr_t*named_pexpr; + list*named_pexprs; + struct parmvalue_t*parmvalue; + list*ranges; + + PExpr*expr; + list*exprs; + + svector*event_expr; + + NetNet::Type nettype; + PGBuiltin::Type gatetype; + NetNet::PortType porttype; + ivl_variable_type_t vartype; + PBlock::BL_TYPE join_keyword; + + PWire*wire; + vector*wires; + + PEventStatement*event_statement; + Statement*statement; + vector*statement_list; + + net_decl_assign_t*net_decl_assign; + enum_type_t*enum_type; + + decl_assignment_t*decl_assignment; + list*decl_assignments; + + struct_member_t*struct_member; + list*struct_members; + struct_type_t*struct_type; + + data_type_t*data_type; + class_type_t*class_type; + real_type_t::type_t real_type; + property_qualifier_t property_qualifier; + PPackage*package; + + struct { + char*text; + data_type_t*type; + } type_identifier; + + struct { + data_type_t*type; + list*exprs; + } class_declaration_extends; + + verinum* number; + + verireal* realtime; + + PSpecPath* specpath; + list *dimensions; + + LexicalScope::lifetime_t lifetime; +}; + +%token IDENTIFIER SYSTEM_IDENTIFIER STRING TIME_LITERAL +%token TYPE_IDENTIFIER +%token PACKAGE_IDENTIFIER +%token DISCIPLINE_IDENTIFIER +%token PATHPULSE_IDENTIFIER +%token BASED_NUMBER DEC_NUMBER UNBASED_NUMBER +%token REALTIME +%token K_PLUS_EQ K_MINUS_EQ K_INCR K_DECR +%token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_WEQ K_WNE K_LP K_LS K_RS K_RSS K_SG + /* K_CONTRIBUTE is <+, the contribution assign. */ +%token K_CONTRIBUTE +%token K_PO_POS K_PO_NEG K_POW +%token K_PSTAR K_STARP K_DOTSTAR +%token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER +%token K_SCOPE_RES +%token K_edge_descriptor + + /* The base tokens from 1364-1995. */ +%token K_always K_and K_assign K_begin K_buf K_bufif0 K_bufif1 K_case +%token K_casex K_casez K_cmos K_deassign K_default K_defparam K_disable +%token K_edge K_else K_end K_endcase K_endfunction K_endmodule +%token K_endprimitive K_endspecify K_endtable K_endtask K_event K_for +%token K_force K_forever K_fork K_function K_highz0 K_highz1 K_if +%token K_ifnone K_initial K_inout K_input K_integer K_join K_large +%token K_macromodule K_medium K_module K_nand K_negedge K_nmos K_nor +%token K_not K_notif0 K_notif1 K_or K_output K_parameter K_pmos K_posedge +%token K_primitive K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_real +%token K_realtime K_reg K_release K_repeat K_rnmos K_rpmos K_rtran +%token K_rtranif0 K_rtranif1 K_scalared K_small K_specify K_specparam +%token K_strong0 K_strong1 K_supply0 K_supply1 K_table K_task K_time +%token K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand K_trior +%token K_trireg K_vectored K_wait K_wand K_weak0 K_weak1 K_while K_wire +%token K_wor K_xnor K_xor + +%token K_Shold K_Snochange K_Speriod K_Srecovery K_Ssetup K_Ssetuphold +%token K_Sskew K_Swidth + + /* Icarus specific tokens. */ +%token KK_attribute K_bool K_logic + + /* The new tokens from 1364-2001. */ +%token K_automatic K_endgenerate K_generate K_genvar K_localparam +%token K_noshowcancelled K_pulsestyle_onevent K_pulsestyle_ondetect +%token K_showcancelled K_signed K_unsigned + +%token K_Sfullskew K_Srecrem K_Sremoval K_Stimeskew + + /* The 1364-2001 configuration tokens. */ +%token K_cell K_config K_design K_endconfig K_incdir K_include K_instance +%token K_liblist K_library K_use + + /* The new tokens from 1364-2005. */ +%token K_wone K_uwire + + /* The new tokens from 1800-2005. */ +%token K_alias K_always_comb K_always_ff K_always_latch K_assert +%token K_assume K_before K_bind K_bins K_binsof K_bit K_break K_byte +%token K_chandle K_class K_clocking K_const K_constraint K_context +%token K_continue K_cover K_covergroup K_coverpoint K_cross K_dist K_do +%token K_endclass K_endclocking K_endgroup K_endinterface K_endpackage +%token K_endprogram K_endproperty K_endsequence K_enum K_expect K_export +%token K_extends K_extern K_final K_first_match K_foreach K_forkjoin +%token K_iff K_ignore_bins K_illegal_bins K_import K_inside K_int + /* Icarus already has defined "logic" above! */ +%token K_interface K_intersect K_join_any K_join_none K_local +%token K_longint K_matches K_modport K_new K_null K_package K_packed +%token K_priority K_program K_property K_protected K_pure K_rand K_randc +%token K_randcase K_randsequence K_ref K_return K_sequence K_shortint +%token K_shortreal K_solve K_static K_string K_struct K_super +%token K_tagged K_this K_throughout K_timeprecision K_timeunit K_type +%token K_typedef K_union K_unique K_var K_virtual K_void K_wait_order +%token K_wildcard K_with K_within + + /* The new tokens from 1800-2009. */ +%token K_accept_on K_checker K_endchecker K_eventually K_global K_implies +%token K_let K_nexttime K_reject_on K_restrict K_s_always K_s_eventually +%token K_s_nexttime K_s_until K_s_until_with K_strong K_sync_accept_on +%token K_sync_reject_on K_unique0 K_until K_until_with K_untyped K_weak + + /* The new tokens from 1800-2012. */ +%token K_implements K_interconnect K_nettype K_soft + + /* The new tokens for Verilog-AMS 2.3. */ +%token K_above K_abs K_absdelay K_abstol K_access K_acos K_acosh + /* 1800-2005 has defined "assert" above! */ +%token K_ac_stim K_aliasparam K_analog K_analysis K_asin K_asinh +%token K_atan K_atan2 K_atanh K_branch K_ceil K_connect K_connectmodule +%token K_connectrules K_continuous K_cos K_cosh K_ddt K_ddt_nature K_ddx +%token K_discipline K_discrete K_domain K_driver_update K_endconnectrules +%token K_enddiscipline K_endnature K_endparamset K_exclude K_exp +%token K_final_step K_flicker_noise K_floor K_flow K_from K_ground +%token K_hypot K_idt K_idtmod K_idt_nature K_inf K_initial_step +%token K_laplace_nd K_laplace_np K_laplace_zd K_laplace_zp +%token K_last_crossing K_limexp K_ln K_log K_max K_merged K_min K_nature +%token K_net_resolution K_noise_table K_paramset K_potential K_pow + /* 1800-2005 has defined "string" above! */ +%token K_resolveto K_sin K_sinh K_slew K_split K_sqrt K_tan K_tanh +%token K_timer K_transition K_units K_white_noise K_wreal +%token K_zi_nd K_zi_np K_zi_zd K_zi_zp + +%type from_exclude block_item_decls_opt +%type number pos_neg_number +%type signing unsigned_signed_opt signed_unsigned_opt +%type import_export +%type K_packed_opt K_reg_opt K_static_opt K_virtual_opt +%type udp_reg_opt edge_operator +%type drive_strength drive_strength_opt dr_strength0 dr_strength1 +%type udp_input_sym udp_output_sym +%type udp_input_list udp_sequ_entry udp_comb_entry +%type udp_input_declaration_list +%type udp_entry_list udp_comb_entry_list udp_sequ_entry_list +%type udp_body +%type udp_port_list +%type udp_port_decl udp_port_decls +%type udp_initial udp_init_opt +%type udp_initial_expr_opt + +%type register_variable net_variable event_variable endlabel_opt class_declaration_endlabel_opt +%type register_variable_list net_variable_list event_variable_list +%type list_of_identifiers loop_variables +%type list_of_port_identifiers list_of_variable_port_identifiers + +%type net_decl_assign net_decl_assigns + +%type port port_opt port_reference port_reference_list +%type port_declaration +%type list_of_ports module_port_list_opt list_of_port_declarations module_attribute_foreign +%type parameter_value_range parameter_value_ranges +%type parameter_value_ranges_opt +%type tf_port_item_expr_opt value_range_expression + +%type enum_name_list enum_name +%type enum_data_type + +%type function_item function_item_list function_item_list_opt +%type task_item task_item_list task_item_list_opt +%type tf_port_declaration tf_port_item tf_port_item_list tf_port_list tf_port_list_opt + +%type modport_simple_port port_name parameter_value_byname +%type port_name_list parameter_value_byname_list + +%type attribute +%type attribute_list attribute_instance_list attribute_list_opt + +%type case_item +%type case_items + +%type gate_instance +%type gate_instance_list + +%type hierarchy_identifier implicit_class_handle +%type assignment_pattern expression expr_mintypmax +%type expr_primary_or_typename expr_primary +%type class_new dynamic_array_new +%type inc_or_dec_expression inside_expression lpvalue +%type branch_probe_expression streaming_concatenation +%type delay_value delay_value_simple +%type delay1 delay3 delay3_opt delay_value_list +%type expression_list_with_nuls expression_list_proper +%type cont_assign cont_assign_list + +%type variable_decl_assignment +%type list_of_variable_decl_assignments + +%type data_type data_type_or_implicit data_type_or_implicit_or_void +%type simple_type_or_string +%type class_identifier +%type struct_union_member +%type struct_union_member_list +%type struct_data_type + +%type class_declaration_extends_opt + +%type class_item_qualifier property_qualifier +%type class_item_qualifier_list property_qualifier_list +%type class_item_qualifier_opt property_qualifier_opt +%type random_qualifier + +%type variable_dimension +%type dimensions_opt dimensions + +%type net_type net_type_opt +%type gatetype switchtype +%type port_direction port_direction_opt +%type bit_logic bit_logic_opt +%type integer_vector_type +%type parameter_value_opt + +%type event_expression_list +%type event_expression +%type event_control +%type statement statement_item statement_or_null +%type compressed_statement +%type loop_statement for_step jump_statement +%type procedural_assertion_statement +%type statement_or_null_list statement_or_null_list_opt + +%type analog_statement + +%type join_keyword + +%type spec_polarity +%type specify_path_identifiers + +%type specify_simple_path specify_simple_path_decl +%type specify_edge_path specify_edge_path_decl + +%type non_integer_type +%type atom2_type +%type module_start module_end + +%type lifetime lifetime_opt + +%token K_TAND +%right K_PLUS_EQ K_MINUS_EQ K_MUL_EQ K_DIV_EQ K_MOD_EQ K_AND_EQ K_OR_EQ +%right K_XOR_EQ K_LS_EQ K_RS_EQ K_RSS_EQ +%right '?' ':' K_inside +%left K_LOR +%left K_LAND +%left '|' +%left '^' K_NXOR K_NOR +%left '&' K_NAND +%left K_EQ K_NE K_CEQ K_CNE K_WEQ K_WNE +%left K_GE K_LE '<' '>' +%left K_LS K_RS K_RSS +%left '+' '-' +%left '*' '/' '%' +%left K_POW +%left UNARY_PREC + + + /* to resolve dangling else ambiguity. */ +%nonassoc less_than_K_else +%nonassoc K_else + + /* to resolve exclude (... ambiguity */ +%nonassoc '(' +%nonassoc K_exclude + + /* to resolve timeunits declaration/redeclaration ambiguity */ +%nonassoc no_timeunits_declaration +%nonassoc one_timeunits_declaration +%nonassoc K_timeunit K_timeprecision + +%% + + + /* IEEE1800-2005: A.1.2 */ + /* source_text ::= [ timeunits_declaration ] { description } */ +source_text + : timeunits_declaration_opt + { pform_set_scope_timescale(yyloc); } + description_list + | /* empty */ + ; + +assertion_item /* IEEE1800-2012: A.6.10 */ + : concurrent_assertion_item + ; + +assignment_pattern /* IEEE1800-2005: A.6.7.1 */ + : K_LP expression_list_proper '}' + { PEAssignPattern*tmp = new PEAssignPattern(*$2); + FILE_NAME(tmp, @1); + delete $2; + $$ = tmp; + } + | K_LP '}' + { PEAssignPattern*tmp = new PEAssignPattern; + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + + /* Some rules have a ... [ block_identifier ':' ] ... part. This + implements it in a LALR way. */ +block_identifier_opt /* */ + : IDENTIFIER ':' + | + ; + +class_declaration /* IEEE1800-2005: A.1.2 */ + : K_virtual_opt K_class lifetime_opt class_identifier class_declaration_extends_opt ';' + { pform_start_class_declaration(@2, $4, $5.type, $5.exprs, $3); } + class_items_opt K_endclass + { // Process a class. + pform_end_class_declaration(@9); + } + class_declaration_endlabel_opt + { // Wrap up the class. + if ($11 && $4 && $4->name != $11) { + yyerror(@11, "error: Class end label doesn't match class name."); + delete[]$11; + } + } + ; + +class_constraint /* IEEE1800-2005: A.1.8 */ + : constraint_prototype + | constraint_declaration + ; + +class_identifier + : IDENTIFIER + { // Create a synthetic typedef for the class name so that the + // lexor detects the name as a type. + perm_string name = lex_strings.make($1); + class_type_t*tmp = new class_type_t(name); + FILE_NAME(tmp, @1); + pform_set_typedef(name, tmp, NULL); + delete[]$1; + $$ = tmp; + } + | TYPE_IDENTIFIER + { class_type_t*tmp = dynamic_cast($1.type); + if (tmp == 0) { + yyerror(@1, "Type name \"%s\"is not a predeclared class name.", $1.text); + } + delete[]$1.text; + $$ = tmp; + } + ; + + /* The endlabel after a class declaration is a little tricky because + the class name is detected by the lexor as a TYPE_IDENTIFIER if it + does indeed match a name. */ +class_declaration_endlabel_opt + : ':' TYPE_IDENTIFIER + { class_type_t*tmp = dynamic_cast ($2.type); + if (tmp == 0) { + yyerror(@2, "error: class declaration endlabel \"%s\" is not a class name\n", $2.text); + $$ = 0; + } else { + $$ = strdupnew(tmp->name.str()); + } + delete[]$2.text; + } + | ':' IDENTIFIER + { $$ = $2; } + | + { $$ = 0; } + ; + + /* This rule implements [ extends class_type ] in the + class_declaration. It is not a rule of its own in the LRM. + + Note that for this to be correct, the identifier after the + extends keyword must be a class name. Therefore, match + TYPE_IDENTIFIER instead of IDENTIFIER, and this rule will return + a data_type. */ + +class_declaration_extends_opt /* IEEE1800-2005: A.1.2 */ + : K_extends TYPE_IDENTIFIER + { $$.type = $2.type; + $$.exprs= 0; + delete[]$2.text; + } + | K_extends TYPE_IDENTIFIER '(' expression_list_with_nuls ')' + { $$.type = $2.type; + $$.exprs = $4; + delete[]$2.text; + } + | + { $$.type = 0; $$.exprs = 0; } + ; + + /* The class_items_opt and class_items rules together implement the + rule snippet { class_item } (zero or more class_item) of the + class_declaration. */ +class_items_opt /* IEEE1800-2005: A.1.2 */ + : class_items + | + ; + +class_items /* IEEE1800-2005: A.1.2 */ + : class_items class_item + | class_item + ; + +class_item /* IEEE1800-2005: A.1.8 */ + + /* IEEE1800 A.1.8: class_constructor_declaration */ + : method_qualifier_opt K_function K_new + { assert(current_function==0); + current_function = pform_push_constructor_scope(@3); + } + '(' tf_port_list_opt ')' ';' + function_item_list_opt + statement_or_null_list_opt + K_endfunction endnew_opt + { current_function->set_ports($6); + pform_set_constructor_return(current_function); + pform_set_this_class(@3, current_function); + current_function_set_statement(@3, $10); + pform_pop_scope(); + current_function = 0; + } + + /* Class properties... */ + + | property_qualifier_opt data_type list_of_variable_decl_assignments ';' + { pform_class_property(@2, $1, $2, $3); } + + | K_const class_item_qualifier_opt data_type list_of_variable_decl_assignments ';' + { pform_class_property(@1, $2 | property_qualifier_t::make_const(), $3, $4); } + + /* Class methods... */ + + | method_qualifier_opt task_declaration + { /* The task_declaration rule puts this into the class */ } + + | method_qualifier_opt function_declaration + { /* The function_declaration rule puts this into the class */ } + + /* External class method definitions... */ + + | K_extern method_qualifier_opt K_function K_new ';' + { yyerror(@1, "sorry: External constructors are not yet supported."); } + | K_extern method_qualifier_opt K_function K_new '(' tf_port_list_opt ')' ';' + { yyerror(@1, "sorry: External constructors are not yet supported."); } + | K_extern method_qualifier_opt K_function data_type_or_implicit_or_void + IDENTIFIER ';' + { yyerror(@1, "sorry: External methods are not yet supported."); + delete[] $5; + } + | K_extern method_qualifier_opt K_function data_type_or_implicit_or_void + IDENTIFIER '(' tf_port_list_opt ')' ';' + { yyerror(@1, "sorry: External methods are not yet supported."); + delete[] $5; + } + | K_extern method_qualifier_opt K_task IDENTIFIER ';' + { yyerror(@1, "sorry: External methods are not yet supported."); + delete[] $4; + } + | K_extern method_qualifier_opt K_task IDENTIFIER '(' tf_port_list_opt ')' ';' + { yyerror(@1, "sorry: External methods are not yet supported."); + delete[] $4; + } + + /* Class constraints... */ + + | class_constraint + + /* Here are some error matching rules to help recover from various + syntax errors within a class declaration. */ + + | property_qualifier_opt data_type error ';' + { yyerror(@3, "error: Errors in variable names after data type."); + yyerrok; + } + + | property_qualifier_opt IDENTIFIER error ';' + { yyerror(@3, "error: %s doesn't name a type.", $2); + yyerrok; + } + + | method_qualifier_opt K_function K_new error K_endfunction endnew_opt + { yyerror(@1, "error: I give up on this class constructor declaration."); + yyerrok; + } + + | error ';' + { yyerror(@2, "error: invalid class item."); + yyerrok; + } + + ; + +class_item_qualifier /* IEEE1800-2005 A.1.8 */ + : K_static { $$ = property_qualifier_t::make_static(); } + | K_protected { $$ = property_qualifier_t::make_protected(); } + | K_local { $$ = property_qualifier_t::make_local(); } + ; + +class_item_qualifier_list + : class_item_qualifier_list class_item_qualifier { $$ = $1 | $2; } + | class_item_qualifier { $$ = $1; } + ; + +class_item_qualifier_opt + : class_item_qualifier_list { $$ = $1; } + | { $$ = property_qualifier_t::make_none(); } + ; + +class_new /* IEEE1800-2005 A.2.4 */ + : K_new '(' expression_list_with_nuls ')' + { list*expr_list = $3; + strip_tail_items(expr_list); + PENewClass*tmp = new PENewClass(*expr_list); + FILE_NAME(tmp, @1); + delete $3; + $$ = tmp; + } + | K_new hierarchy_identifier + { PEIdent*tmpi = new PEIdent(*$2); + FILE_NAME(tmpi, @2); + PENewCopy*tmp = new PENewCopy(tmpi); + FILE_NAME(tmp, @1); + delete $2; + $$ = tmp; + } + | K_new + { PENewClass*tmp = new PENewClass; + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + + /* The concurrent_assertion_item pulls together the + concurrent_assertion_statement and checker_instantiation rules. */ + +concurrent_assertion_item /* IEEE1800-2012 A.2.10 */ + : block_identifier_opt K_assert K_property '(' property_spec ')' statement_or_null + { /* */ + if (gn_assertions_flag) { + yyerror(@2, "sorry: concurrent_assertion_item not supported." + " Try -gno-assertion to turn this message off."); + } + } + | block_identifier_opt K_assert K_property '(' error ')' statement_or_null + { yyerrok; + yyerror(@2, "error: Error in property_spec of concurrent assertion item."); + } + ; + +constraint_block_item /* IEEE1800-2005 A.1.9 */ + : constraint_expression + ; + +constraint_block_item_list + : constraint_block_item_list constraint_block_item + | constraint_block_item + ; + +constraint_block_item_list_opt + : + | constraint_block_item_list + ; + +constraint_declaration /* IEEE1800-2005: A.1.9 */ + : K_static_opt K_constraint IDENTIFIER '{' constraint_block_item_list_opt '}' + { yyerror(@2, "sorry: Constraint declarations not supported."); } + + /* Error handling rules... */ + + | K_static_opt K_constraint IDENTIFIER '{' error '}' + { yyerror(@4, "error: Errors in the constraint block item list."); } + ; + +constraint_expression /* IEEE1800-2005 A.1.9 */ + : expression ';' + | expression K_dist '{' '}' ';' + | expression K_TRIGGER constraint_set + | K_if '(' expression ')' constraint_set %prec less_than_K_else + | K_if '(' expression ')' constraint_set K_else constraint_set + | K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' constraint_set + ; + +constraint_expression_list /* */ + : constraint_expression_list constraint_expression + | constraint_expression + ; + +constraint_prototype /* IEEE1800-2005: A.1.9 */ + : K_static_opt K_constraint IDENTIFIER ';' + { yyerror(@2, "sorry: Constraint prototypes not supported."); } + ; + +constraint_set /* IEEE1800-2005 A.1.9 */ + : constraint_expression + | '{' constraint_expression_list '}' + ; + +data_declaration /* IEEE1800-2005: A.2.1.3 */ + : attribute_list_opt data_type_or_implicit list_of_variable_decl_assignments ';' + { data_type_t*data_type = $2; + if (data_type == 0) { + data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + FILE_NAME(data_type, @2); + } + pform_makewire(@2, 0, str_strength, $3, NetNet::IMPLICIT_REG, data_type); + } + ; + +data_type /* IEEE1800-2005: A.2.2.1 */ + : integer_vector_type unsigned_signed_opt dimensions_opt + { ivl_variable_type_t use_vtype = $1; + bool reg_flag = false; + if (use_vtype == IVL_VT_NO_TYPE) { + use_vtype = IVL_VT_LOGIC; + reg_flag = true; + } + vector_type_t*tmp = new vector_type_t(use_vtype, $2, $3); + tmp->reg_flag = reg_flag; + FILE_NAME(tmp, @1); + $$ = tmp; + } + | non_integer_type + { real_type_t*tmp = new real_type_t($1); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | struct_data_type + { if (!$1->packed_flag) { + yyerror(@1, "sorry: Unpacked structs not supported."); + } + $$ = $1; + } + | enum_data_type + { $$ = $1; } + | atom2_type signed_unsigned_opt + { atom2_type_t*tmp = new atom2_type_t($1, $2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_integer signed_unsigned_opt + { list*pd = make_range_from_width(integer_width); + vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $2, pd); + tmp->reg_flag = true; + tmp->integer_flag = true; + $$ = tmp; + } + | K_time + { list*pd = make_range_from_width(64); + vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, pd); + tmp->reg_flag = !gn_system_verilog(); + $$ = tmp; + } + | TYPE_IDENTIFIER dimensions_opt + { if ($2) { + parray_type_t*tmp = new parray_type_t($1.type, $2); + FILE_NAME(tmp, @1); + $$ = tmp; + } else $$ = $1.type; + delete[]$1.text; + } + | PACKAGE_IDENTIFIER K_SCOPE_RES + { lex_in_package_scope($1); } + TYPE_IDENTIFIER + { lex_in_package_scope(0); + $$ = $4.type; + delete[]$4.text; + } + | K_string + { string_type_t*tmp = new string_type_t; + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + + /* The data_type_or_implicit rule is a little more complex then the + rule documented in the IEEE format syntax in order to allow for + signaling the special case that the data_type is completely + absent. The context may need that information to decide to resort + to left context. */ + +data_type_or_implicit /* IEEE1800-2005: A.2.2.1 */ + : data_type + { $$ = $1; } + | signing dimensions_opt + { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $1, $2); + tmp->implicit_flag = true; + FILE_NAME(tmp, @1); + $$ = tmp; + } + | dimensions + { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, $1); + tmp->implicit_flag = true; + FILE_NAME(tmp, @1); + $$ = tmp; + } + | + { $$ = 0; } + ; + + +data_type_or_implicit_or_void + : data_type_or_implicit + { $$ = $1; } + | K_void + { void_type_t*tmp = new void_type_t; + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + + /* NOTE: The "module" rule of the description combines the + module_declaration, program_declaration, and interface_declaration + rules from the standard description. */ + +description /* IEEE1800-2005: A.1.2 */ + : module + | udp_primitive + | config_declaration + | nature_declaration + | package_declaration + | discipline_declaration + | package_item + | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' + { perm_string tmp3 = lex_strings.make($3); + pform_set_type_attrib(tmp3, $5, $7); + delete[] $3; + delete[] $5; + } + ; + +description_list + : description + | description_list description + ; + + + /* This implements the [ : IDENTIFIER ] part of the constructor + rule documented in IEEE1800-2005: A.1.8 */ +endnew_opt : ':' K_new | ; + + /* The dynamic_array_new rule is kinda like an expression, but it is + treated differently by rules that use this "expression". Watch out! */ + +dynamic_array_new /* IEEE1800-2005: A.2.4 */ + : K_new '[' expression ']' + { $$ = new PENewArray($3, 0); + FILE_NAME($$, @1); + } + | K_new '[' expression ']' '(' expression ')' + { $$ = new PENewArray($3, $6); + FILE_NAME($$, @1); + } + ; + +for_step /* IEEE1800-2005: A.6.8 */ + : lpvalue '=' expression + { PAssign*tmp = new PAssign($1,$3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | inc_or_dec_expression + { $$ = pform_compressed_assign_from_inc_dec(@1, $1); } + | compressed_statement + { $$ = $1; } + ; + + + /* The function declaration rule matches the function declaration + header, then pushes the function scope. This causes the + definitions in the func_body to take on the scope of the function + instead of the module. */ +function_declaration /* IEEE1800-2005: A.2.6 */ + : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER ';' + { assert(current_function == 0); + current_function = pform_push_function_scope(@1, $4, $2); + } + function_item_list statement_or_null_list_opt + K_endfunction + { current_function->set_ports($7); + current_function->set_return($3); + current_function_set_statement($8? @8 : @4, $8); + pform_set_this_class(@4, current_function); + pform_pop_scope(); + current_function = 0; + } + endlabel_opt + { // Last step: check any closing name. + if ($11) { + if (strcmp($4,$11) != 0) { + yyerror(@11, "error: End label doesn't match " + "function name"); + } + if (! gn_system_verilog()) { + yyerror(@11, "error: Function end labels require " + "SystemVerilog."); + } + delete[]$11; + } + delete[]$4; + } + + | K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER + { assert(current_function == 0); + current_function = pform_push_function_scope(@1, $4, $2); + } + '(' tf_port_list_opt ')' ';' + block_item_decls_opt + statement_or_null_list_opt + K_endfunction + { current_function->set_ports($7); + current_function->set_return($3); + current_function_set_statement($11? @11 : @4, $11); + pform_set_this_class(@4, current_function); + pform_pop_scope(); + current_function = 0; + if ($7==0 && !gn_system_verilog()) { + yyerror(@4, "error: Empty parenthesis syntax requires SystemVerilog."); + } + } + endlabel_opt + { // Last step: check any closing name. + if ($14) { + if (strcmp($4,$14) != 0) { + yyerror(@14, "error: End label doesn't match " + "function name"); + } + if (! gn_system_verilog()) { + yyerror(@14, "error: Function end labels require " + "SystemVerilog."); + } + delete[]$14; + } + delete[]$4; + } + + /* Detect and recover from some errors. */ + + | K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER error K_endfunction + { /* */ + if (current_function) { + pform_pop_scope(); + current_function = 0; + } + assert(current_function == 0); + yyerror(@1, "error: Syntax error defining function."); + yyerrok; + } + endlabel_opt + { // Last step: check any closing name. + if ($8) { + if (strcmp($4,$8) != 0) { + yyerror(@8, "error: End label doesn't match function name"); + } + if (! gn_system_verilog()) { + yyerror(@8, "error: Function end labels require " + "SystemVerilog."); + } + delete[]$8; + } + delete[]$4; + } + + ; + +import_export /* IEEE1800-2012: A.2.9 */ + : K_import { $$ = true; } + | K_export { $$ = false; } + ; + +implicit_class_handle /* IEEE1800-2005: A.8.4 */ + : K_this { $$ = pform_create_this(); } + | K_super { $$ = pform_create_super(); } + ; + + /* SystemVerilog adds support for the increment/decrement + expressions, which look like a++, --a, etc. These are primaries + but are in their own rules because they can also be + statements. Note that the operator can only take l-value + expressions. */ + +inc_or_dec_expression /* IEEE1800-2005: A.4.3 */ + : K_INCR lpvalue %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('I', $2); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | lpvalue K_INCR %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('i', $1); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_DECR lpvalue %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('D', $2); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | lpvalue K_DECR %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('d', $1); + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + +inside_expression /* IEEE1800-2005 A.8.3 */ + : expression K_inside '{' open_range_list '}' + { yyerror(@2, "sorry: \"inside\" expressions not supported yet."); + $$ = 0; + } + ; + +integer_vector_type /* IEEE1800-2005: A.2.2.1 */ + : K_reg { $$ = IVL_VT_NO_TYPE; } /* Usually a synonym for logic. */ + | K_bit { $$ = IVL_VT_BOOL; } + | K_logic { $$ = IVL_VT_LOGIC; } + | K_bool { $$ = IVL_VT_BOOL; } /* Icarus Verilog xtypes extension */ + ; + +join_keyword /* IEEE1800-2005: A.6.3 */ + : K_join + { $$ = PBlock::BL_PAR; } + | K_join_none + { $$ = PBlock::BL_JOIN_NONE; } + | K_join_any + { $$ = PBlock::BL_JOIN_ANY; } + ; + +jump_statement /* IEEE1800-2005: A.6.5 */ + : K_break ';' + { yyerror(@1, "sorry: break statements not supported."); + $$ = 0; + } + | K_return ';' + { PReturn*tmp = new PReturn(0); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_return expression ';' + { PReturn*tmp = new PReturn($2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + +lifetime /* IEEE1800-2005: A.2.1.3 */ + : K_automatic { $$ = LexicalScope::AUTOMATIC; } + | K_static { $$ = LexicalScope::STATIC; } + ; + +lifetime_opt /* IEEE1800-2005: A.2.1.3 */ + : lifetime { $$ = $1; } + | { $$ = LexicalScope::INHERITED; } + ; + + /* Loop statements are kinds of statements. */ + +loop_statement /* IEEE1800-2005: A.6.8 */ + : K_for '(' lpvalue '=' expression ';' expression ';' for_step ')' + statement_or_null + { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + // Handle for_variable_declaration syntax by wrapping the for(...) + // statement in a synthetic named block. We can name the block + // after the variable that we are creating, that identifier is + // safe in the controlling scope. + | K_for '(' data_type IDENTIFIER '=' expression ';' expression ';' for_step ')' + { static unsigned for_counter = 0; + char for_block_name [64]; + snprintf(for_block_name, sizeof for_block_name, "$ivl_for_loop%u", for_counter); + for_counter += 1; + PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ); + FILE_NAME(tmp, @1); + current_block_stack.push(tmp); + + listassign_list; + decl_assignment_t*tmp_assign = new decl_assignment_t; + tmp_assign->name = lex_strings.make($4); + assign_list.push_back(tmp_assign); + pform_makewire(@4, 0, str_strength, &assign_list, NetNet::REG, $3); + } + statement_or_null + { pform_name_t tmp_hident; + tmp_hident.push_back(name_component_t(lex_strings.make($4))); + + PEIdent*tmp_ident = pform_new_ident(tmp_hident); + FILE_NAME(tmp_ident, @4); + + PForStatement*tmp_for = new PForStatement(tmp_ident, $6, $8, $10, $13); + FILE_NAME(tmp_for, @1); + + pform_pop_scope(); + vectortmp_for_list (1); + tmp_for_list[0] = tmp_for; + PBlock*tmp_blk = current_block_stack.top(); + current_block_stack.pop(); + tmp_blk->set_statement(tmp_for_list); + $$ = tmp_blk; + delete[]$4; + } + + | K_forever statement_or_null + { PForever*tmp = new PForever($2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + | K_repeat '(' expression ')' statement_or_null + { PRepeat*tmp = new PRepeat($3, $5); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + | K_while '(' expression ')' statement_or_null + { PWhile*tmp = new PWhile($3, $5); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + | K_do statement_or_null K_while '(' expression ')' ';' + { PDoWhile*tmp = new PDoWhile($5, $2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + // When matching a foreach loop, implicitly create a named block + // to hold the definitions for the index variables. + | K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' + { static unsigned foreach_counter = 0; + char for_block_name[64]; + snprintf(for_block_name, sizeof for_block_name, "$ivl_foreach%u", foreach_counter); + foreach_counter += 1; + + PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ); + FILE_NAME(tmp, @1); + current_block_stack.push(tmp); + + pform_make_foreach_declarations(@1, $5); + } + statement_or_null + { PForeach*tmp_for = pform_make_foreach(@1, $3, $5, $9); + + pform_pop_scope(); + vectortmp_for_list(1); + tmp_for_list[0] = tmp_for; + PBlock*tmp_blk = current_block_stack.top(); + current_block_stack.pop(); + tmp_blk->set_statement(tmp_for_list); + $$ = tmp_blk; + } + + /* Error forms for loop statements. */ + + | K_for '(' lpvalue '=' expression ';' expression ';' error ')' + statement_or_null + { $$ = 0; + yyerror(@1, "error: Error in for loop step assignment."); + } + + | K_for '(' lpvalue '=' expression ';' error ';' for_step ')' + statement_or_null + { $$ = 0; + yyerror(@1, "error: Error in for loop condition expression."); + } + + | K_for '(' error ')' statement_or_null + { $$ = 0; + yyerror(@1, "error: Incomprehensible for loop."); + } + + | K_while '(' error ')' statement_or_null + { $$ = 0; + yyerror(@1, "error: Error in while loop condition."); + } + + | K_do statement_or_null K_while '(' error ')' ';' + { $$ = 0; + yyerror(@1, "error: Error in do/while loop condition."); + } + + | K_foreach '(' IDENTIFIER '[' error ']' ')' statement_or_null + { $$ = 0; + yyerror(@4, "error: Errors in foreach loop variables list."); + } + ; + + +/* TODO: Replace register_variable_list with list_of_variable_decl_assignments. */ +list_of_variable_decl_assignments /* IEEE1800-2005 A.2.3 */ + : variable_decl_assignment + { list*tmp = new list; + tmp->push_back($1); + $$ = tmp; + } + | list_of_variable_decl_assignments ',' variable_decl_assignment + { list*tmp = $1; + tmp->push_back($3); + $$ = tmp; + } + ; + +variable_decl_assignment /* IEEE1800-2005 A.2.3 */ + : IDENTIFIER dimensions_opt + { decl_assignment_t*tmp = new decl_assignment_t; + tmp->name = lex_strings.make($1); + if ($2) { + tmp->index = *$2; + delete $2; + } + delete[]$1; + $$ = tmp; + } + | IDENTIFIER '=' expression + { decl_assignment_t*tmp = new decl_assignment_t; + tmp->name = lex_strings.make($1); + tmp->expr .reset($3); + delete[]$1; + $$ = tmp; + } + | IDENTIFIER '=' K_new '(' ')' + { decl_assignment_t*tmp = new decl_assignment_t; + tmp->name = lex_strings.make($1); + PENewClass*expr = new PENewClass; + FILE_NAME(expr, @3); + tmp->expr .reset(expr); + delete[]$1; + $$ = tmp; + } + ; + + +loop_variables /* IEEE1800-2005: A.6.8 */ + : loop_variables ',' IDENTIFIER + { list*tmp = $1; + tmp->push_back(lex_strings.make($3)); + delete[]$3; + $$ = tmp; + } + | IDENTIFIER + { list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + delete[]$1; + $$ = tmp; + } + ; + +method_qualifier /* IEEE1800-2005: A.1.8 */ + : K_virtual + | class_item_qualifier + ; + +method_qualifier_opt + : method_qualifier + | + ; + +modport_declaration /* IEEE1800-2012: A.2.9 */ + : K_modport + { if (!pform_in_interface()) + yyerror(@1, "error: modport declarations are only allowed " + "in interfaces."); + } + modport_item_list ';' + +modport_item_list + : modport_item + | modport_item_list ',' modport_item + ; + +modport_item + : IDENTIFIER + { pform_start_modport_item(@1, $1); } + '(' modport_ports_list ')' + { pform_end_modport_item(@1); } + ; + + /* The modport_ports_list is a LALR(2) grammar. When the parser sees a + ',' it needs to look ahead to the next token to decide whether it is + a continuation of the preceding modport_ports_declaration, or the + start of a new modport_ports_declaration. bison only supports LALR(1), + so we have to handcraft a mini parser for this part of the syntax. + last_modport_port holds the state for this mini parser.*/ + +modport_ports_list + : modport_ports_declaration + | modport_ports_list ',' modport_ports_declaration + | modport_ports_list ',' modport_simple_port + { if (last_modport_port.type == MP_SIMPLE) { + pform_add_modport_port(@3, last_modport_port.direction, + $3->name, $3->parm); + } else { + yyerror(@3, "error: modport expression not allowed here."); + } + delete $3; + } + | modport_ports_list ',' modport_tf_port + { if (last_modport_port.type != MP_TF) + yyerror(@3, "error: task/function declaration not allowed here."); + } + | modport_ports_list ',' IDENTIFIER + { if (last_modport_port.type == MP_SIMPLE) { + pform_add_modport_port(@3, last_modport_port.direction, + lex_strings.make($3), 0); + } else if (last_modport_port.type != MP_TF) { + yyerror(@3, "error: list of identifiers not allowed here."); + } + delete[] $3; + } + | modport_ports_list ',' + { yyerror(@2, "error: NULL port declarations are not allowed"); } + ; + +modport_ports_declaration + : attribute_list_opt port_direction IDENTIFIER + { last_modport_port.type = MP_SIMPLE; + last_modport_port.direction = $2; + pform_add_modport_port(@3, $2, lex_strings.make($3), 0); + delete[] $3; + delete $1; + } + | attribute_list_opt port_direction modport_simple_port + { last_modport_port.type = MP_SIMPLE; + last_modport_port.direction = $2; + pform_add_modport_port(@3, $2, $3->name, $3->parm); + delete $3; + delete $1; + } + | attribute_list_opt import_export IDENTIFIER + { last_modport_port.type = MP_TF; + last_modport_port.is_import = $2; + yyerror(@3, "sorry: modport task/function ports are not yet supported."); + delete[] $3; + delete $1; + } + | attribute_list_opt import_export modport_tf_port + { last_modport_port.type = MP_TF; + last_modport_port.is_import = $2; + yyerror(@3, "sorry: modport task/function ports are not yet supported."); + delete $1; + } + | attribute_list_opt K_clocking IDENTIFIER + { last_modport_port.type = MP_CLOCKING; + last_modport_port.direction = NetNet::NOT_A_PORT; + yyerror(@3, "sorry: modport clocking declaration is not yet supported."); + delete[] $3; + delete $1; + } + ; + +modport_simple_port + : '.' IDENTIFIER '(' expression ')' + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($2); + tmp->parm = $4; + delete[]$2; + $$ = tmp; + } + ; + +modport_tf_port + : K_task IDENTIFIER + | K_task IDENTIFIER '(' tf_port_list_opt ')' + | K_function data_type_or_implicit_or_void IDENTIFIER + | K_function data_type_or_implicit_or_void IDENTIFIER '(' tf_port_list_opt ')' + ; + +non_integer_type /* IEEE1800-2005: A.2.2.1 */ + : K_real { $$ = real_type_t::REAL; } + | K_realtime { $$ = real_type_t::REAL; } + | K_shortreal { $$ = real_type_t::SHORTREAL; } + ; + +number : BASED_NUMBER + { $$ = $1; based_size = 0;} + | DEC_NUMBER + { $$ = $1; based_size = 0;} + | DEC_NUMBER BASED_NUMBER + { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line); + based_size = 0; } + | UNBASED_NUMBER + { $$ = $1; based_size = 0;} + | DEC_NUMBER UNBASED_NUMBER + { yyerror(@1, "error: Unbased SystemVerilog literal cannot have " + "a size."); + $$ = $1; based_size = 0;} + ; + +open_range_list /* IEEE1800-2005 A.2.11 */ + : open_range_list ',' value_range + | value_range + ; + +package_declaration /* IEEE1800-2005 A.1.2 */ + : K_package lifetime_opt IDENTIFIER ';' + { pform_start_package_declaration(@1, $3, $2); } + timeunits_declaration_opt + { pform_set_scope_timescale(@1); } + package_item_list_opt + K_endpackage endlabel_opt + { pform_end_package_declaration(@1); + // If an end label is present make sure it match the package name. + if ($10) { + if (strcmp($3,$10) != 0) { + yyerror(@10, "error: End label doesn't match package name"); + } + delete[]$10; + } + delete[]$3; + } + ; + +module_package_import_list_opt + : + | package_import_list + ; + +package_import_list + : package_import_declaration + | package_import_list package_import_declaration + ; + +package_import_declaration /* IEEE1800-2005 A.2.1.3 */ + : K_import package_import_item_list ';' + { } + ; + +package_import_item + : PACKAGE_IDENTIFIER K_SCOPE_RES IDENTIFIER + { pform_package_import(@2, $1, $3); + delete[]$3; + } + | PACKAGE_IDENTIFIER K_SCOPE_RES '*' + { pform_package_import(@2, $1, 0); + } + ; + +package_import_item_list + : package_import_item_list',' package_import_item + | package_import_item + ; + +package_item /* IEEE1800-2005 A.1.10 */ + : timeunits_declaration + | K_parameter param_type parameter_assign_list ';' + | K_localparam param_type localparam_assign_list ';' + | type_declaration + | function_declaration + | task_declaration + | data_declaration + | class_declaration + ; + +package_item_list + : package_item_list package_item + | package_item + ; + +package_item_list_opt : package_item_list | ; + +port_direction /* IEEE1800-2005 A.1.3 */ + : K_input { $$ = NetNet::PINPUT; } + | K_output { $$ = NetNet::POUTPUT; } + | K_inout { $$ = NetNet::PINOUT; } + | K_ref + { $$ = NetNet::PREF; + if (!gn_system_verilog()) { + yyerror(@1, "error: Reference ports (ref) require SystemVerilog."); + $$ = NetNet::PINPUT; + } + } + ; + + /* port_direction_opt is used in places where the port direction is + optional. The default direction is selected by the context, + which needs to notice the PIMPLICIT direction. */ + +port_direction_opt + : port_direction { $$ = $1; } + | { $$ = NetNet::PIMPLICIT; } + ; + +property_expr /* IEEE1800-2012 A.2.10 */ + : expression + ; + +procedural_assertion_statement /* IEEE1800-2012 A.6.10 */ + : K_assert '(' expression ')' statement %prec less_than_K_else + { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); + $$ = 0; + } + | K_assert '(' expression ')' K_else statement + { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); + $$ = 0; + } + | K_assert '(' expression ')' statement K_else statement + { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); + $$ = 0; + } + ; + + /* The property_qualifier rule is as literally described in the LRM, + but the use is usually as { property_qualifier }, which is + implemented by the property_qualifier_opt rule below. */ + +property_qualifier /* IEEE1800-2005 A.1.8 */ + : class_item_qualifier + | random_qualifier + ; + +property_qualifier_opt /* IEEE1800-2005 A.1.8: ... { property_qualifier } */ + : property_qualifier_list { $$ = $1; } + | { $$ = property_qualifier_t::make_none(); } + ; + +property_qualifier_list /* IEEE1800-2005 A.1.8 */ + : property_qualifier_list property_qualifier { $$ = $1 | $2; } + | property_qualifier { $$ = $1; } + ; + + /* The property_spec rule uses some helper rules to implement this + rule from the LRM: + [ clocking_event ] [ disable iff ( expression_or_dist ) ] property_expr + This does it is a YACC friendly way. */ + +property_spec /* IEEE1800-2012 A.2.10 */ + : clocking_event_opt property_spec_disable_iff_opt property_expr + ; + +property_spec_disable_iff_opt /* */ + : K_disable K_iff '(' expression ')' + | + ; + +random_qualifier /* IEEE1800-2005 A.1.8 */ + : K_rand { $$ = property_qualifier_t::make_rand(); } + | K_randc { $$ = property_qualifier_t::make_randc(); } + ; + + /* real and realtime are exactly the same so save some code + * with a common matching rule. */ +real_or_realtime + : K_real + | K_realtime + ; + +signing /* IEEE1800-2005: A.2.2.1 */ + : K_signed { $$ = true; } + | K_unsigned { $$ = false; } + ; + +simple_type_or_string /* IEEE1800-2005: A.2.2.1 */ + : integer_vector_type + { ivl_variable_type_t use_vtype = $1; + bool reg_flag = false; + if (use_vtype == IVL_VT_NO_TYPE) { + use_vtype = IVL_VT_LOGIC; + reg_flag = true; + } + vector_type_t*tmp = new vector_type_t(use_vtype, false, 0); + tmp->reg_flag = reg_flag; + FILE_NAME(tmp, @1); + $$ = tmp; + } + | non_integer_type + { real_type_t*tmp = new real_type_t($1); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | atom2_type + { atom2_type_t*tmp = new atom2_type_t($1, true); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_integer + { list*pd = make_range_from_width(integer_width); + vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, true, pd); + tmp->reg_flag = true; + tmp->integer_flag = true; + $$ = tmp; + } + | K_time + { list*pd = make_range_from_width(64); + vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, pd); + tmp->reg_flag = !gn_system_verilog(); + $$ = tmp; + } + | TYPE_IDENTIFIER + { $$ = $1.type; + delete[]$1.text; + } + | PACKAGE_IDENTIFIER K_SCOPE_RES + { lex_in_package_scope($1); } + TYPE_IDENTIFIER + { lex_in_package_scope(0); + $$ = $4.type; + delete[]$4.text; + } + | K_string + { string_type_t*tmp = new string_type_t; + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + +statement /* IEEE1800-2005: A.6.4 */ + : attribute_list_opt statement_item + { pform_bind_attributes($2->attributes, $1); + $$ = $2; + } + ; + + /* Many places where statements are allowed can actually take a + statement or a null statement marked with a naked semi-colon. */ + +statement_or_null /* IEEE1800-2005: A.6.4 */ + : statement + { $$ = $1; } + | attribute_list_opt ';' + { $$ = 0; } + ; + +stream_expression + : expression + ; + +stream_expression_list + : stream_expression_list ',' stream_expression + | stream_expression + ; + +stream_operator + : K_LS + | K_RS + ; + +streaming_concatenation /* IEEE1800-2005: A.8.1 */ + : '{' stream_operator '{' stream_expression_list '}' '}' + { /* streaming concatenation is a SystemVerilog thing. */ + if (gn_system_verilog()) { + yyerror(@2, "sorry: Streaming concatenation not supported."); + $$ = 0; + } else { + yyerror(@2, "error: Streaming concatenation requires SystemVerilog"); + $$ = 0; + } + } + ; + + /* The task declaration rule matches the task declaration + header, then pushes the function scope. This causes the + definitions in the task_body to take on the scope of the task + instead of the module. */ + +task_declaration /* IEEE1800-2005: A.2.7 */ + + : K_task lifetime_opt IDENTIFIER ';' + { assert(current_task == 0); + current_task = pform_push_task_scope(@1, $3, $2); + } + task_item_list_opt + statement_or_null_list_opt + K_endtask + { current_task->set_ports($6); + current_task_set_statement(@3, $7); + pform_set_this_class(@3, current_task); + pform_pop_scope(); + current_task = 0; + if ($7 && $7->size() > 1 && !gn_system_verilog()) { + yyerror(@7, "error: Task body with multiple statements requires SystemVerilog."); + } + delete $7; + } + endlabel_opt + { // Last step: check any closing name. This is done late so + // that the parser can look ahead to detect the present + // endlabel_opt but still have the pform_endmodule() called + // early enough that the lexor can know we are outside the + // module. + if ($10) { + if (strcmp($3,$10) != 0) { + yyerror(@10, "error: End label doesn't match task name"); + } + if (! gn_system_verilog()) { + yyerror(@10, "error: Task end labels require " + "SystemVerilog."); + } + delete[]$10; + } + delete[]$3; + } + + | K_task lifetime_opt IDENTIFIER '(' + { assert(current_task == 0); + current_task = pform_push_task_scope(@1, $3, $2); + } + tf_port_list ')' ';' + block_item_decls_opt + statement_or_null_list_opt + K_endtask + { current_task->set_ports($6); + current_task_set_statement(@3, $10); + pform_set_this_class(@3, current_task); + pform_pop_scope(); + current_task = 0; + if ($10) delete $10; + } + endlabel_opt + { // Last step: check any closing name. This is done late so + // that the parser can look ahead to detect the present + // endlabel_opt but still have the pform_endmodule() called + // early enough that the lexor can know we are outside the + // module. + if ($13) { + if (strcmp($3,$13) != 0) { + yyerror(@13, "error: End label doesn't match task name"); + } + if (! gn_system_verilog()) { + yyerror(@13, "error: Task end labels require " + "SystemVerilog."); + } + delete[]$13; + } + delete[]$3; + } + + | K_task lifetime_opt IDENTIFIER '(' ')' ';' + { assert(current_task == 0); + current_task = pform_push_task_scope(@1, $3, $2); + } + block_item_decls_opt + statement_or_null_list + K_endtask + { current_task->set_ports(0); + current_task_set_statement(@3, $9); + pform_set_this_class(@3, current_task); + if (! current_task->method_of()) { + cerr << @3 << ": warning: task definition for \"" << $3 + << "\" has an empty port declaration list!" << endl; + } + pform_pop_scope(); + current_task = 0; + if ($9->size() > 1 && !gn_system_verilog()) { + yyerror(@9, "error: Task body with multiple statements requires SystemVerilog."); + } + delete $9; + } + endlabel_opt + { // Last step: check any closing name. This is done late so + // that the parser can look ahead to detect the present + // endlabel_opt but still have the pform_endmodule() called + // early enough that the lexor can know we are outside the + // module. + if ($12) { + if (strcmp($3,$12) != 0) { + yyerror(@12, "error: End label doesn't match task name"); + } + if (! gn_system_verilog()) { + yyerror(@12, "error: Task end labels require " + "SystemVerilog."); + } + delete[]$12; + } + delete[]$3; + } + + | K_task lifetime_opt IDENTIFIER error K_endtask + { + if (current_task) { + pform_pop_scope(); + current_task = 0; + } + } + endlabel_opt + { // Last step: check any closing name. This is done late so + // that the parser can look ahead to detect the present + // endlabel_opt but still have the pform_endmodule() called + // early enough that the lexor can know we are outside the + // module. + if ($7) { + if (strcmp($3,$7) != 0) { + yyerror(@7, "error: End label doesn't match task name"); + } + if (! gn_system_verilog()) { + yyerror(@7, "error: Task end labels require " + "SystemVerilog."); + } + delete[]$7; + } + delete[]$3; + } + + ; + + +tf_port_declaration /* IEEE1800-2005: A.2.7 */ + : port_direction K_reg_opt unsigned_signed_opt dimensions_opt list_of_identifiers ';' + { vector*tmp = pform_make_task_ports(@1, $1, + $2 ? IVL_VT_LOGIC : + IVL_VT_NO_TYPE, + $3, $4, $5); + $$ = tmp; + } + + /* When the port is an integer, infer a signed vector of the integer + shape. Generate a range ([31:0]) to make it work. */ + + | port_direction K_integer list_of_identifiers ';' + { list*range_stub = make_range_from_width(integer_width); + vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_LOGIC, true, + range_stub, $3, true); + $$ = tmp; + } + + /* Ports can be time with a width of [63:0] (unsigned). */ + + | port_direction K_time list_of_identifiers ';' + { list*range_stub = make_range_from_width(64); + vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_LOGIC, false, + range_stub, $3); + $$ = tmp; + } + + /* Ports can be real or realtime. */ + + | port_direction real_or_realtime list_of_identifiers ';' + { vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_REAL, true, + 0, $3); + $$ = tmp; + } + + + /* Ports can be string. */ + + | port_direction K_string list_of_identifiers ';' + { vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_STRING, true, + 0, $3); + $$ = tmp; + } + + ; + + + /* These rules for tf_port_item are slightly expanded from the + strict rules in the LRM to help with LALR parsing. + + NOTE: Some of these rules should be folded into the "data_type" + variant which uses the data_type rule to match data type + declarations. That some rules do not use the data_type production + is a consequence of legacy. */ + +tf_port_item /* IEEE1800-2005: A.2.7 */ + + : port_direction_opt data_type_or_implicit IDENTIFIER dimensions_opt tf_port_item_expr_opt + { vector*tmp; + NetNet::PortType use_port_type = $1; + if ((use_port_type == NetNet::PIMPLICIT) && (gn_system_verilog() || ($2 == 0))) + use_port_type = port_declaration_context.port_type; + perm_string name = lex_strings.make($3); + list* ilist = list_from_identifier($3); + + if (use_port_type == NetNet::PIMPLICIT) { + yyerror(@1, "error: missing task/function port direction."); + use_port_type = NetNet::PINPUT; // for error recovery + } + if (($2 == 0) && ($1==NetNet::PIMPLICIT)) { + // Detect special case this is an undecorated + // identifier and we need to get the declaration from + // left context. + if ($4 != 0) { + yyerror(@4, "internal error: How can there be an unpacked range here?\n"); + } + tmp = pform_make_task_ports(@3, use_port_type, + port_declaration_context.data_type, + ilist); + + } else { + // Otherwise, the decorations for this identifier + // indicate the type. Save the type for any right + // context that may come later. + port_declaration_context.port_type = use_port_type; + if ($2 == 0) { + $2 = new vector_type_t(IVL_VT_LOGIC, false, 0); + FILE_NAME($2, @3); + } + port_declaration_context.data_type = $2; + tmp = pform_make_task_ports(@3, use_port_type, $2, ilist); + } + if ($4 != 0) { + pform_set_reg_idx(name, $4); + } + + $$ = tmp; + if ($5) { + assert(tmp->size()==1); + tmp->front().defe = $5; + } + } + + /* Rules to match error cases... */ + + | port_direction_opt data_type_or_implicit IDENTIFIER error + { yyerror(@3, "error: Error in task/function port item after port name %s.", $3); + yyerrok; + $$ = 0; + } + ; + + /* This rule matches the [ = ] part of the tf_port_item rules. */ + +tf_port_item_expr_opt + : '=' expression + { if (! gn_system_verilog()) { + yyerror(@1, "error: Task/function default arguments require " + "SystemVerilog."); + } + $$ = $2; + } + | { $$ = 0; } + ; + +tf_port_list /* IEEE1800-2005: A.2.7 */ + : { port_declaration_context.port_type = gn_system_verilog() ? NetNet::PINPUT : NetNet::PIMPLICIT; + port_declaration_context.data_type = 0; + } + tf_port_item_list + { $$ = $2; } + ; + +tf_port_item_list + : tf_port_item_list ',' tf_port_item + { vector*tmp; + if ($1 && $3) { + size_t s1 = $1->size(); + tmp = $1; + tmp->resize(tmp->size()+$3->size()); + for (size_t idx = 0 ; idx < $3->size() ; idx += 1) + tmp->at(s1+idx) = $3->at(idx); + delete $3; + } else if ($1) { + tmp = $1; + } else { + tmp = $3; + } + $$ = tmp; + } + + | tf_port_item + { $$ = $1; } + + /* Rules to handle some errors in tf_port_list items. */ + + | error ',' tf_port_item + { yyerror(@2, "error: Syntax error in task/function port declaration."); + $$ = $3; + } + | tf_port_item_list ',' + { yyerror(@2, "error: NULL port declarations are not allowed."); + $$ = $1; + } + | tf_port_item_list ';' + { yyerror(@2, "error: ';' is an invalid port declaration separator."); + $$ = $1; + } + ; + +timeunits_declaration /* IEEE1800-2005: A.1.2 */ + : K_timeunit TIME_LITERAL ';' + { pform_set_timeunit($2, allow_timeunit_decl); } + | K_timeunit TIME_LITERAL '/' TIME_LITERAL ';' + { bool initial_decl = allow_timeunit_decl && allow_timeprec_decl; + pform_set_timeunit($2, initial_decl); + pform_set_timeprec($4, initial_decl); + } + | K_timeprecision TIME_LITERAL ';' + { pform_set_timeprec($2, allow_timeprec_decl); } + ; + + /* Allow zero, one, or two declarations. The second declaration might + be a repeat declaration, but the pform functions take care of that. */ +timeunits_declaration_opt + : /* empty */ %prec no_timeunits_declaration + | timeunits_declaration %prec one_timeunits_declaration + | timeunits_declaration timeunits_declaration + ; + +value_range /* IEEE1800-2005: A.8.3 */ + : expression + { } + | '[' expression ':' expression ']' + { } + ; + +variable_dimension /* IEEE1800-2005: A.2.5 */ + : '[' expression ':' expression ']' + { list *tmp = new list; + pform_range_t index ($2,$4); + tmp->push_back(index); + $$ = tmp; + } + | '[' expression ']' + { // SystemVerilog canonical range + if (!gn_system_verilog()) { + warn_count += 1; + cerr << @2 << ": warning: Use of SystemVerilog [size] dimension. " + << "Use at least -g2005-sv to remove this warning." << endl; + } + list *tmp = new list; + pform_range_t index; + index.first = new PENumber(new verinum((uint64_t)0, integer_width)); + index.second = new PEBinary('-', $2, new PENumber(new verinum((uint64_t)1, integer_width))); + tmp->push_back(index); + $$ = tmp; + } + | '[' ']' + { list *tmp = new list; + pform_range_t index (0,0); + tmp->push_back(index); + $$ = tmp; + } + | '[' '$' ']' + { // SystemVerilog queue + list *tmp = new list; + pform_range_t index (new PENull,0); + if (!gn_system_verilog()) { + yyerror("error: Queue declarations require SystemVerilog."); + } + tmp->push_back(index); + $$ = tmp; + } + ; + +variable_lifetime + : lifetime + { if (!gn_system_verilog()) { + yyerror(@1, "error: overriding the default variable lifetime " + "requires SystemVerilog."); + } else if ($1 != pform_peek_scope()->default_lifetime) { + yyerror(@1, "sorry: overriding the default variable lifetime " + "is not yet supported."); + } + var_lifetime = $1; + } + ; + + /* Verilog-2001 supports attribute lists, which can be attached to a + variety of different objects. The syntax inside the (* *) is a + comma separated list of names or names with assigned values. */ +attribute_list_opt + : attribute_instance_list + { $$ = $1; } + | + { $$ = 0; } + ; + +attribute_instance_list + : K_PSTAR K_STARP { $$ = 0; } + | K_PSTAR attribute_list K_STARP { $$ = $2; } + | attribute_instance_list K_PSTAR K_STARP { $$ = $1; } + | attribute_instance_list K_PSTAR attribute_list K_STARP + { list*tmp = $1; + if (tmp) { + tmp->splice(tmp->end(), *$3); + delete $3; + $$ = tmp; + } else $$ = $3; + } + ; + +attribute_list + : attribute_list ',' attribute + { list*tmp = $1; + tmp->push_back(*$3); + delete $3; + $$ = tmp; + } + | attribute + { list*tmp = new list; + tmp->push_back(*$1); + delete $1; + $$ = tmp; + } + ; + + +attribute + : IDENTIFIER + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($1); + tmp->parm = 0; + delete[]$1; + $$ = tmp; + } + | IDENTIFIER '=' expression + { PExpr*tmp = $3; + named_pexpr_t*tmp2 = new named_pexpr_t; + tmp2->name = lex_strings.make($1); + tmp2->parm = tmp; + delete[]$1; + $$ = tmp2; + } + ; + + + /* The block_item_decl is used in function definitions, task + definitions, module definitions and named blocks. Wherever a new + scope is entered, the source may declare new registers and + integers. This rule matches those declarations. The containing + rule has presumably set up the scope. */ + +block_item_decl + + /* variable declarations. Note that data_type can be 0 if we are + recovering from an error. */ + + : data_type register_variable_list ';' + { if ($1) pform_set_data_type(@1, $1, $2, NetNet::REG, attributes_in_context); + } + + | variable_lifetime data_type register_variable_list ';' + { if ($2) pform_set_data_type(@2, $2, $3, NetNet::REG, attributes_in_context); + var_lifetime = LexicalScope::INHERITED; + } + + | K_reg data_type register_variable_list ';' + { if ($2) pform_set_data_type(@2, $2, $3, NetNet::REG, attributes_in_context); + } + + | variable_lifetime K_reg data_type register_variable_list ';' + { if ($3) pform_set_data_type(@3, $3, $4, NetNet::REG, attributes_in_context); + var_lifetime = LexicalScope::INHERITED; + } + + | K_event event_variable_list ';' + { if ($2) pform_make_events($2, @1.text, @1.first_line); + } + + | K_parameter param_type parameter_assign_list ';' + | K_localparam param_type localparam_assign_list ';' + + /* Blocks can have type declarations. */ + + | type_declaration + + /* Recover from errors that happen within variable lists. Use the + trailing semi-colon to resync the parser. */ + + | K_integer error ';' + { yyerror(@1, "error: syntax error in integer variable list."); + yyerrok; + } + + | K_time error ';' + { yyerror(@1, "error: syntax error in time variable list."); + yyerrok; + } + + | K_parameter error ';' + { yyerror(@1, "error: syntax error in parameter list."); + yyerrok; + } + | K_localparam error ';' + { yyerror(@1, "error: syntax error localparam list."); + yyerrok; + } + ; + +block_item_decls + : block_item_decl + | block_item_decls block_item_decl + ; + +block_item_decls_opt + : block_item_decls { $$ = true; } + | { $$ = false; } + ; + + /* Type declarations are parsed here. The rule actions call pform + functions that add the declaration to the current lexical scope. */ +type_declaration + : K_typedef data_type IDENTIFIER dimensions_opt ';' + { perm_string name = lex_strings.make($3); + pform_set_typedef(name, $2, $4); + delete[]$3; + } + + /* If the IDENTIFIER already is a typedef, it is possible for this + code to override the definition, but only if the typedef is + inherited from a different scope. */ + | K_typedef data_type TYPE_IDENTIFIER ';' + { perm_string name = lex_strings.make($3.text); + if (pform_test_type_identifier_local(name)) { + yyerror(@3, "error: Typedef identifier \"%s\" is already a type name.", $3.text); + + } else { + pform_set_typedef(name, $2, NULL); + } + delete[]$3.text; + } + + /* These are forward declarations... */ + + | K_typedef K_class IDENTIFIER ';' + { // Create a synthetic typedef for the class name so that the + // lexor detects the name as a type. + perm_string name = lex_strings.make($3); + class_type_t*tmp = new class_type_t(name); + FILE_NAME(tmp, @3); + pform_set_typedef(name, tmp, NULL); + delete[]$3; + } + | K_typedef K_enum IDENTIFIER ';' + { yyerror(@1, "sorry: Enum forward declarations not supported yet."); } + | K_typedef K_struct IDENTIFIER ';' + { yyerror(@1, "sorry: Struct forward declarations not supported yet."); } + | K_typedef K_union IDENTIFIER ';' + { yyerror(@1, "sorry: Union forward declarations not supported yet."); } + | K_typedef IDENTIFIER ';' + { // Create a synthetic typedef for the class name so that the + // lexor detects the name as a type. + perm_string name = lex_strings.make($2); + class_type_t*tmp = new class_type_t(name); + FILE_NAME(tmp, @2); + pform_set_typedef(name, tmp, NULL); + delete[]$2; + } + + | K_typedef error ';' + { yyerror(@2, "error: Syntax error in typedef clause."); + yyerrok; + } + + ; + + /* The structure for an enumeration data type is the keyword "enum", + followed by the enumeration values in curly braces. Also allow + for an optional base type. The default base type is "int", but it + can be any of the integral or vector types. */ + +enum_data_type + : K_enum '{' enum_name_list '}' + { enum_type_t*enum_type = new enum_type_t; + FILE_NAME(enum_type, @1); + enum_type->names .reset($3); + enum_type->base_type = IVL_VT_BOOL; + enum_type->signed_flag = true; + enum_type->integer_flag = false; + enum_type->range.reset(make_range_from_width(32)); + $$ = enum_type; + } + | K_enum atom2_type signed_unsigned_opt '{' enum_name_list '}' + { enum_type_t*enum_type = new enum_type_t; + FILE_NAME(enum_type, @1); + enum_type->names .reset($5); + enum_type->base_type = IVL_VT_BOOL; + enum_type->signed_flag = $3; + enum_type->integer_flag = false; + enum_type->range.reset(make_range_from_width($2)); + $$ = enum_type; + } + | K_enum K_integer signed_unsigned_opt '{' enum_name_list '}' + { enum_type_t*enum_type = new enum_type_t; + FILE_NAME(enum_type, @1); + enum_type->names .reset($5); + enum_type->base_type = IVL_VT_LOGIC; + enum_type->signed_flag = $3; + enum_type->integer_flag = true; + enum_type->range.reset(make_range_from_width(integer_width)); + $$ = enum_type; + } + | K_enum K_logic unsigned_signed_opt dimensions_opt '{' enum_name_list '}' + { enum_type_t*enum_type = new enum_type_t; + FILE_NAME(enum_type, @1); + enum_type->names .reset($6); + enum_type->base_type = IVL_VT_LOGIC; + enum_type->signed_flag = $3; + enum_type->integer_flag = false; + enum_type->range.reset($4 ? $4 : make_range_from_width(1)); + $$ = enum_type; + } + | K_enum K_reg unsigned_signed_opt dimensions_opt '{' enum_name_list '}' + { enum_type_t*enum_type = new enum_type_t; + FILE_NAME(enum_type, @1); + enum_type->names .reset($6); + enum_type->base_type = IVL_VT_LOGIC; + enum_type->signed_flag = $3; + enum_type->integer_flag = false; + enum_type->range.reset($4 ? $4 : make_range_from_width(1)); + $$ = enum_type; + } + | K_enum K_bit unsigned_signed_opt dimensions_opt '{' enum_name_list '}' + { enum_type_t*enum_type = new enum_type_t; + FILE_NAME(enum_type, @1); + enum_type->names .reset($6); + enum_type->base_type = IVL_VT_BOOL; + enum_type->signed_flag = $3; + enum_type->integer_flag = false; + enum_type->range.reset($4 ? $4 : make_range_from_width(1)); + $$ = enum_type; + } + ; + +enum_name_list + : enum_name + { $$ = $1; + } + | enum_name_list ',' enum_name + { list*lst = $1; + lst->splice(lst->end(), *$3); + delete $3; + $$ = lst; + } + ; + +pos_neg_number + : number + { $$ = $1; + } + | '-' number + { verinum tmp = -(*($2)); + *($2) = tmp; + $$ = $2; + } + ; + +enum_name + : IDENTIFIER + { perm_string name = lex_strings.make($1); + delete[]$1; + $$ = make_named_number(name); + } + | IDENTIFIER '[' pos_neg_number ']' + { perm_string name = lex_strings.make($1); + long count = check_enum_seq_value(@1, $3, false); + delete[]$1; + $$ = make_named_numbers(name, 0, count-1); + delete $3; + } + | IDENTIFIER '[' pos_neg_number ':' pos_neg_number ']' + { perm_string name = lex_strings.make($1); + $$ = make_named_numbers(name, check_enum_seq_value(@1, $3, true), + check_enum_seq_value(@1, $5, true)); + delete[]$1; + delete $3; + delete $5; + } + | IDENTIFIER '=' expression + { perm_string name = lex_strings.make($1); + delete[]$1; + $$ = make_named_number(name, $3); + } + | IDENTIFIER '[' pos_neg_number ']' '=' expression + { perm_string name = lex_strings.make($1); + long count = check_enum_seq_value(@1, $3, false); + $$ = make_named_numbers(name, 0, count-1, $6); + delete[]$1; + delete $3; + } + | IDENTIFIER '[' pos_neg_number ':' pos_neg_number ']' '=' expression + { perm_string name = lex_strings.make($1); + $$ = make_named_numbers(name, check_enum_seq_value(@1, $3, true), + check_enum_seq_value(@1, $5, true), $8); + delete[]$1; + delete $3; + delete $5; + } + ; + +struct_data_type + : K_struct K_packed_opt '{' struct_union_member_list '}' + { struct_type_t*tmp = new struct_type_t; + FILE_NAME(tmp, @1); + tmp->packed_flag = $2; + tmp->union_flag = false; + tmp->members .reset($4); + $$ = tmp; + } + | K_union K_packed_opt '{' struct_union_member_list '}' + { struct_type_t*tmp = new struct_type_t; + FILE_NAME(tmp, @1); + tmp->packed_flag = $2; + tmp->union_flag = true; + tmp->members .reset($4); + $$ = tmp; + } + | K_struct K_packed_opt '{' error '}' + { yyerror(@3, "error: Errors in struct member list."); + yyerrok; + struct_type_t*tmp = new struct_type_t; + FILE_NAME(tmp, @1); + tmp->packed_flag = $2; + tmp->union_flag = false; + $$ = tmp; + } + | K_union K_packed_opt '{' error '}' + { yyerror(@3, "error: Errors in union member list."); + yyerrok; + struct_type_t*tmp = new struct_type_t; + FILE_NAME(tmp, @1); + tmp->packed_flag = $2; + tmp->union_flag = true; + $$ = tmp; + } + ; + + /* This is an implementation of the rule snippet: + struct_union_member { struct_union_member } + that is used in the rule matching struct and union types + in IEEE 1800-2012 A.2.2.1. */ +struct_union_member_list + : struct_union_member_list struct_union_member + { list*tmp = $1; + tmp->push_back($2); + $$ = tmp; + } + | struct_union_member + { list*tmp = new list; + tmp->push_back($1); + $$ = tmp; + } + ; + +struct_union_member /* IEEE 1800-2012 A.2.2.1 */ + : attribute_list_opt data_type list_of_variable_decl_assignments ';' + { struct_member_t*tmp = new struct_member_t; + FILE_NAME(tmp, @2); + tmp->type .reset($2); + tmp->names .reset($3); + $$ = tmp; + } + | error ';' + { yyerror(@2, "Error in struct/union member."); + yyerrok; + $$ = 0; + } + ; + +case_item + : expression_list_proper ':' statement_or_null + { PCase::Item*tmp = new PCase::Item; + tmp->expr = *$1; + tmp->stat = $3; + delete $1; + $$ = tmp; + } + | K_default ':' statement_or_null + { PCase::Item*tmp = new PCase::Item; + tmp->stat = $3; + $$ = tmp; + } + | K_default statement_or_null + { PCase::Item*tmp = new PCase::Item; + tmp->stat = $2; + $$ = tmp; + } + | error ':' statement_or_null + { yyerror(@2, "error: Incomprehensible case expression."); + yyerrok; + } + ; + +case_items + : case_items case_item + { svector*tmp; + tmp = new svector(*$1, $2); + delete $1; + $$ = tmp; + } + | case_item + { svector*tmp = new svector(1); + (*tmp)[0] = $1; + $$ = tmp; + } + ; + +charge_strength + : '(' K_small ')' + | '(' K_medium ')' + | '(' K_large ')' + ; + +charge_strength_opt + : charge_strength + | + ; + +defparam_assign + : hierarchy_identifier '=' expression + { pform_set_defparam(*$1, $3); + delete $1; + } + ; + +defparam_assign_list + : defparam_assign + | dimensions defparam_assign + { yyerror(@1, "error: defparam may not include a range."); + delete $1; + } + | defparam_assign_list ',' defparam_assign + ; + +delay1 + : '#' delay_value_simple + { list*tmp = new list; + tmp->push_back($2); + $$ = tmp; + } + | '#' '(' delay_value ')' + { list*tmp = new list; + tmp->push_back($3); + $$ = tmp; + } + ; + +delay3 + : '#' delay_value_simple + { list*tmp = new list; + tmp->push_back($2); + $$ = tmp; + } + | '#' '(' delay_value ')' + { list*tmp = new list; + tmp->push_back($3); + $$ = tmp; + } + | '#' '(' delay_value ',' delay_value ')' + { list*tmp = new list; + tmp->push_back($3); + tmp->push_back($5); + $$ = tmp; + } + | '#' '(' delay_value ',' delay_value ',' delay_value ')' + { list*tmp = new list; + tmp->push_back($3); + tmp->push_back($5); + tmp->push_back($7); + $$ = tmp; + } + ; + +delay3_opt + : delay3 { $$ = $1; } + | { $$ = 0; } + ; + +delay_value_list + : delay_value + { list*tmp = new list; + tmp->push_back($1); + $$ = tmp; + } + | delay_value_list ',' delay_value + { list*tmp = $1; + tmp->push_back($3); + $$ = tmp; + } + ; + +delay_value + : expression + { PExpr*tmp = $1; + $$ = tmp; + } + | expression ':' expression ':' expression + { $$ = pform_select_mtm_expr($1, $3, $5); } + ; + + +delay_value_simple + : DEC_NUMBER + { verinum*tmp = $1; + if (tmp == 0) { + yyerror(@1, "internal error: delay."); + $$ = 0; + } else { + $$ = new PENumber(tmp); + FILE_NAME($$, @1); + } + based_size = 0; + } + | REALTIME + { verireal*tmp = $1; + if (tmp == 0) { + yyerror(@1, "internal error: delay."); + $$ = 0; + } else { + $$ = new PEFNumber(tmp); + FILE_NAME($$, @1); + } + } + | IDENTIFIER + { PEIdent*tmp = new PEIdent(lex_strings.make($1)); + FILE_NAME(tmp, @1); + $$ = tmp; + delete[]$1; + } + | TIME_LITERAL + { int unit; + + based_size = 0; + $$ = 0; + if ($1 == 0 || !get_time_unit($1, unit)) + yyerror(@1, "internal error: delay."); + else { + double p = pow(10.0, + (double)(unit - pform_get_timeunit())); + double time = atof($1) * p; + + verireal *v = new verireal(time); + $$ = new PEFNumber(v); + FILE_NAME($$, @1); + } + } + ; + + /* The discipline and nature declarations used to take no ';' after + the identifier. The 2.3 LRM adds the ';', but since there are + programs written to the 2.1 and 2.2 standard that don't, we + choose to make the ';' optional in this context. */ +optional_semicolon : ';' | ; + +discipline_declaration + : K_discipline IDENTIFIER optional_semicolon + { pform_start_discipline($2); } + discipline_items K_enddiscipline + { pform_end_discipline(@1); delete[] $2; } + ; + +discipline_items + : discipline_items discipline_item + | discipline_item + ; + +discipline_item + : K_domain K_discrete ';' + { pform_discipline_domain(@1, IVL_DIS_DISCRETE); } + | K_domain K_continuous ';' + { pform_discipline_domain(@1, IVL_DIS_CONTINUOUS); } + | K_potential IDENTIFIER ';' + { pform_discipline_potential(@1, $2); delete[] $2; } + | K_flow IDENTIFIER ';' + { pform_discipline_flow(@1, $2); delete[] $2; } + ; + +nature_declaration + : K_nature IDENTIFIER optional_semicolon + { pform_start_nature($2); } + nature_items + K_endnature + { pform_end_nature(@1); delete[] $2; } + ; + +nature_items + : nature_items nature_item + | nature_item + ; + +nature_item + : K_units '=' STRING ';' + { delete[] $3; } + | K_abstol '=' expression ';' + | K_access '=' IDENTIFIER ';' + { pform_nature_access(@1, $3); delete[] $3; } + | K_idt_nature '=' IDENTIFIER ';' + { delete[] $3; } + | K_ddt_nature '=' IDENTIFIER ';' + { delete[] $3; } + ; + +config_declaration + : K_config IDENTIFIER ';' + K_design lib_cell_identifiers ';' + list_of_config_rule_statements + K_endconfig + { cerr << @1 << ": sorry: config declarations are not supported and " + "will be skipped." << endl; + delete[] $2; + } + ; + +lib_cell_identifiers + : /* The BNF implies this can be blank, but I'm not sure exactly what + * this means. */ + | lib_cell_identifiers lib_cell_id + ; + +list_of_config_rule_statements + : /* config rules are optional. */ + | list_of_config_rule_statements config_rule_statement + ; + +config_rule_statement + : K_default K_liblist list_of_libraries ';' + | K_instance hierarchy_identifier K_liblist list_of_libraries ';' + { delete $2; } + | K_instance hierarchy_identifier K_use lib_cell_id opt_config ';' + { delete $2; } + | K_cell lib_cell_id K_liblist list_of_libraries ';' + | K_cell lib_cell_id K_use lib_cell_id opt_config ';' + ; + +opt_config + : /* The use clause takes an optional :config. */ + | ':' K_config + ; + +lib_cell_id + : IDENTIFIER + { delete[] $1; } + | IDENTIFIER '.' IDENTIFIER + { delete[] $1; delete[] $3; } + ; + +list_of_libraries + : /* A NULL library means use the parents cell library. */ + | list_of_libraries IDENTIFIER + { delete[] $2; } + ; + +drive_strength + : '(' dr_strength0 ',' dr_strength1 ')' + { $$.str0 = $2.str0; + $$.str1 = $4.str1; + } + | '(' dr_strength1 ',' dr_strength0 ')' + { $$.str0 = $4.str0; + $$.str1 = $2.str1; + } + | '(' dr_strength0 ',' K_highz1 ')' + { $$.str0 = $2.str0; + $$.str1 = IVL_DR_HiZ; + } + | '(' dr_strength1 ',' K_highz0 ')' + { $$.str0 = IVL_DR_HiZ; + $$.str1 = $2.str1; + } + | '(' K_highz1 ',' dr_strength0 ')' + { $$.str0 = $4.str0; + $$.str1 = IVL_DR_HiZ; + } + | '(' K_highz0 ',' dr_strength1 ')' + { $$.str0 = IVL_DR_HiZ; + $$.str1 = $4.str1; + } + ; + +drive_strength_opt + : drive_strength { $$ = $1; } + | { $$.str0 = IVL_DR_STRONG; $$.str1 = IVL_DR_STRONG; } + ; + +dr_strength0 + : K_supply0 { $$.str0 = IVL_DR_SUPPLY; } + | K_strong0 { $$.str0 = IVL_DR_STRONG; } + | K_pull0 { $$.str0 = IVL_DR_PULL; } + | K_weak0 { $$.str0 = IVL_DR_WEAK; } + ; + +dr_strength1 + : K_supply1 { $$.str1 = IVL_DR_SUPPLY; } + | K_strong1 { $$.str1 = IVL_DR_STRONG; } + | K_pull1 { $$.str1 = IVL_DR_PULL; } + | K_weak1 { $$.str1 = IVL_DR_WEAK; } + ; + +clocking_event_opt /* */ + : event_control + | + ; + +event_control /* A.K.A. clocking_event */ + : '@' hierarchy_identifier + { PEIdent*tmpi = new PEIdent(*$2); + PEEvent*tmpe = new PEEvent(PEEvent::ANYEDGE, tmpi); + PEventStatement*tmps = new PEventStatement(tmpe); + FILE_NAME(tmps, @1); + $$ = tmps; + delete $2; + } + | '@' '(' event_expression_list ')' + { PEventStatement*tmp = new PEventStatement(*$3); + FILE_NAME(tmp, @1); + delete $3; + $$ = tmp; + } + | '@' '(' error ')' + { yyerror(@1, "error: Malformed event control expression."); + $$ = 0; + } + ; + +event_expression_list + : event_expression + { $$ = $1; } + | event_expression_list K_or event_expression + { svector*tmp = new svector(*$1, *$3); + delete $1; + delete $3; + $$ = tmp; + } + | event_expression_list ',' event_expression + { svector*tmp = new svector(*$1, *$3); + delete $1; + delete $3; + $$ = tmp; + } + ; + +event_expression + : K_posedge expression + { PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2); + FILE_NAME(tmp, @1); + svector*tl = new svector(1); + (*tl)[0] = tmp; + $$ = tl; + } + | K_negedge expression + { PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2); + FILE_NAME(tmp, @1); + svector*tl = new svector(1); + (*tl)[0] = tmp; + $$ = tl; + } + | expression + { PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1); + FILE_NAME(tmp, @1); + svector*tl = new svector(1); + (*tl)[0] = tmp; + $$ = tl; + } + ; + + /* A branch probe expression applies a probe function (potential or + flow) to a branch. The branch may be implicit as a pair of nets + or explicit as a named branch. Elaboration will check that the + function name really is a nature attribute identifier. */ +branch_probe_expression + : IDENTIFIER '(' IDENTIFIER ',' IDENTIFIER ')' + { $$ = pform_make_branch_probe_expression(@1, $1, $3, $5); } + | IDENTIFIER '(' IDENTIFIER ')' + { $$ = pform_make_branch_probe_expression(@1, $1, $3); } + ; + +expression + : expr_primary_or_typename + { $$ = $1; } + | inc_or_dec_expression + { $$ = $1; } + | inside_expression + { $$ = $1; } + | '+' attribute_list_opt expr_primary %prec UNARY_PREC + { $$ = $3; } + | '-' attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('-', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | '~' attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('~', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | '&' attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('&', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | '!' attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('!', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | '|' attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('|', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | '^' attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('^', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | '~' '&' attribute_list_opt expr_primary %prec UNARY_PREC + { yyerror(@1, "error: '~' '&' is not a valid expression. " + "Please use operator '~&' instead."); + $$ = 0; + } + | '~' '|' attribute_list_opt expr_primary %prec UNARY_PREC + { yyerror(@1, "error: '~' '|' is not a valid expression. " + "Please use operator '~|' instead."); + $$ = 0; + } + | '~' '^' attribute_list_opt expr_primary %prec UNARY_PREC + { yyerror(@1, "error: '~' '^' is not a valid expression. " + "Please use operator '~^' instead."); + $$ = 0; + } + | K_NAND attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('A', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | K_NOR attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('N', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | K_NXOR attribute_list_opt expr_primary %prec UNARY_PREC + { PEUnary*tmp = new PEUnary('X', $3); + FILE_NAME(tmp, @3); + $$ = tmp; + } + | '!' error %prec UNARY_PREC + { yyerror(@1, "error: Operand of unary ! " + "is not a primary expression."); + $$ = 0; + } + | '^' error %prec UNARY_PREC + { yyerror(@1, "error: Operand of reduction ^ " + "is not a primary expression."); + $$ = 0; + } + | expression '^' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('^', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_POW attribute_list_opt expression + { PEBinary*tmp = new PEBPower('p', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '*' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('*', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '/' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('/', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '%' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('%', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '+' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('+', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '-' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('-', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '&' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('&', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '|' attribute_list_opt expression + { PEBinary*tmp = new PEBinary('|', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_NAND attribute_list_opt expression + { PEBinary*tmp = new PEBinary('A', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_NOR attribute_list_opt expression + { PEBinary*tmp = new PEBinary('O', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_NXOR attribute_list_opt expression + { PEBinary*tmp = new PEBinary('X', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '<' attribute_list_opt expression + { PEBinary*tmp = new PEBComp('<', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '>' attribute_list_opt expression + { PEBinary*tmp = new PEBComp('>', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_LS attribute_list_opt expression + { PEBinary*tmp = new PEBShift('l', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_RS attribute_list_opt expression + { PEBinary*tmp = new PEBShift('r', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_RSS attribute_list_opt expression + { PEBinary*tmp = new PEBShift('R', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_EQ attribute_list_opt expression + { PEBinary*tmp = new PEBComp('e', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_CEQ attribute_list_opt expression + { PEBinary*tmp = new PEBComp('E', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_WEQ attribute_list_opt expression + { PEBinary*tmp = new PEBComp('w', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_LE attribute_list_opt expression + { PEBinary*tmp = new PEBComp('L', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_GE attribute_list_opt expression + { PEBinary*tmp = new PEBComp('G', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_NE attribute_list_opt expression + { PEBinary*tmp = new PEBComp('n', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_CNE attribute_list_opt expression + { PEBinary*tmp = new PEBComp('N', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_WNE attribute_list_opt expression + { PEBinary*tmp = new PEBComp('W', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_LOR attribute_list_opt expression + { PEBinary*tmp = new PEBLogic('o', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression K_LAND attribute_list_opt expression + { PEBinary*tmp = new PEBLogic('a', $1, $4); + FILE_NAME(tmp, @2); + $$ = tmp; + } + | expression '?' attribute_list_opt expression ':' expression + { PETernary*tmp = new PETernary($1, $4, $6); + FILE_NAME(tmp, @2); + $$ = tmp; + } + ; + +expr_mintypmax + : expression + { $$ = $1; } + | expression ':' expression ':' expression + { switch (min_typ_max_flag) { + case MIN: + $$ = $1; + delete $3; + delete $5; + break; + case TYP: + delete $1; + $$ = $3; + delete $5; + break; + case MAX: + delete $1; + delete $3; + $$ = $5; + break; + } + if (min_typ_max_warn > 0) { + cerr << $$->get_fileline() << ": warning: choosing "; + switch (min_typ_max_flag) { + case MIN: + cerr << "min"; + break; + case TYP: + cerr << "typ"; + break; + case MAX: + cerr << "max"; + break; + } + cerr << " expression." << endl; + min_typ_max_warn -= 1; + } + } + ; + + + /* Many contexts take a comma separated list of expressions. Null + expressions can happen anywhere in the list, so there are two + extra rules in expression_list_with_nuls for parsing and + installing those nulls. + + The expression_list_proper rules do not allow null items in the + expression list, so can be used where nul expressions are not allowed. */ + +expression_list_with_nuls + : expression_list_with_nuls ',' expression + { list*tmp = $1; + tmp->push_back($3); + $$ = tmp; + } + | expression + { list*tmp = new list; + tmp->push_back($1); + $$ = tmp; + } + | + { list*tmp = new list; + tmp->push_back(0); + $$ = tmp; + } + | expression_list_with_nuls ',' + { list*tmp = $1; + tmp->push_back(0); + $$ = tmp; + } + ; + +expression_list_proper + : expression_list_proper ',' expression + { list*tmp = $1; + tmp->push_back($3); + $$ = tmp; + } + | expression + { list*tmp = new list; + tmp->push_back($1); + $$ = tmp; + } + ; + +expr_primary_or_typename + : expr_primary + + /* There are a few special cases (notably $bits argument) where the + expression may be a type name. Let the elaborator sort this out. */ + | TYPE_IDENTIFIER + { PETypename*tmp = new PETypename($1.type); + FILE_NAME(tmp,@1); + $$ = tmp; + delete[]$1.text; + } + + ; + +expr_primary + : number + { assert($1); + PENumber*tmp = new PENumber($1); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | REALTIME + { PEFNumber*tmp = new PEFNumber($1); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | STRING + { PEString*tmp = new PEString($1); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | TIME_LITERAL + { int unit; + + based_size = 0; + $$ = 0; + if ($1 == 0 || !get_time_unit($1, unit)) + yyerror(@1, "internal error: delay."); + else { + double p = pow(10.0, (double)(unit - pform_get_timeunit())); + double time = atof($1) * p; + + verireal *v = new verireal(time); + $$ = new PEFNumber(v); + FILE_NAME($$, @1); + } + } + | SYSTEM_IDENTIFIER + { perm_string tn = lex_strings.make($1); + PECallFunction*tmp = new PECallFunction(tn); + FILE_NAME(tmp, @1); + $$ = tmp; + delete[]$1; + } + + /* The hierarchy_identifier rule matches simple identifiers as well as + indexed arrays and part selects */ + + | hierarchy_identifier + { PEIdent*tmp = pform_new_ident(*$1); + FILE_NAME(tmp, @1); + $$ = tmp; + delete $1; + } + + | PACKAGE_IDENTIFIER K_SCOPE_RES hierarchy_identifier + { $$ = pform_package_ident(@2, $1, $3); + delete $3; + } + + /* An identifier followed by an expression list in parentheses is a + function call. If a system identifier, then a system function + call. It can also be a call to a class method (function). */ + + | hierarchy_identifier '(' expression_list_with_nuls ')' + { list*expr_list = $3; + strip_tail_items(expr_list); + PECallFunction*tmp = pform_make_call_function(@1, *$1, *expr_list); + delete $1; + $$ = tmp; + } + | implicit_class_handle '.' hierarchy_identifier '(' expression_list_with_nuls ')' + { pform_name_t*t_name = $1; + while (! $3->empty()) { + t_name->push_back($3->front()); + $3->pop_front(); + } + list*expr_list = $5; + strip_tail_items(expr_list); + PECallFunction*tmp = pform_make_call_function(@1, *t_name, *expr_list); + delete $1; + delete $3; + $$ = tmp; + } + | SYSTEM_IDENTIFIER '(' expression_list_proper ')' + { perm_string tn = lex_strings.make($1); + PECallFunction*tmp = new PECallFunction(tn, *$3); + FILE_NAME(tmp, @1); + delete[]$1; + $$ = tmp; + } + | PACKAGE_IDENTIFIER K_SCOPE_RES IDENTIFIER '(' expression_list_proper ')' + { perm_string use_name = lex_strings.make($3); + PECallFunction*tmp = new PECallFunction($1, use_name, *$5); + FILE_NAME(tmp, @3); + delete[]$3; + $$ = tmp; + } + | SYSTEM_IDENTIFIER '(' ')' + { perm_string tn = lex_strings.make($1); + const vectorempty; + PECallFunction*tmp = new PECallFunction(tn, empty); + FILE_NAME(tmp, @1); + delete[]$1; + $$ = tmp; + if (!gn_system_verilog()) { + yyerror(@1, "error: Empty function argument list requires SystemVerilog."); + } + } + + | implicit_class_handle + { PEIdent*tmp = new PEIdent(*$1); + FILE_NAME(tmp,@1); + delete $1; + $$ = tmp; + } + + | implicit_class_handle '.' hierarchy_identifier + { pform_name_t*t_name = $1; + while (! $3->empty()) { + t_name->push_back($3->front()); + $3->pop_front(); + } + PEIdent*tmp = new PEIdent(*t_name); + FILE_NAME(tmp,@1); + delete $1; + delete $3; + $$ = tmp; + } + + /* Many of the VAMS built-in functions are available as builtin + functions with $system_function equivalents. */ + + | K_acos '(' expression ')' + { perm_string tn = perm_string::literal("$acos"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_acosh '(' expression ')' + { perm_string tn = perm_string::literal("$acosh"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_asin '(' expression ')' + { perm_string tn = perm_string::literal("$asin"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_asinh '(' expression ')' + { perm_string tn = perm_string::literal("$asinh"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_atan '(' expression ')' + { perm_string tn = perm_string::literal("$atan"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_atanh '(' expression ')' + { perm_string tn = perm_string::literal("$atanh"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_atan2 '(' expression ',' expression ')' + { perm_string tn = perm_string::literal("$atan2"); + PECallFunction*tmp = make_call_function(tn, $3, $5); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_ceil '(' expression ')' + { perm_string tn = perm_string::literal("$ceil"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_cos '(' expression ')' + { perm_string tn = perm_string::literal("$cos"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_cosh '(' expression ')' + { perm_string tn = perm_string::literal("$cosh"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_exp '(' expression ')' + { perm_string tn = perm_string::literal("$exp"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_floor '(' expression ')' + { perm_string tn = perm_string::literal("$floor"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_hypot '(' expression ',' expression ')' + { perm_string tn = perm_string::literal("$hypot"); + PECallFunction*tmp = make_call_function(tn, $3, $5); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_ln '(' expression ')' + { perm_string tn = perm_string::literal("$ln"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_log '(' expression ')' + { perm_string tn = perm_string::literal("$log10"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_pow '(' expression ',' expression ')' + { perm_string tn = perm_string::literal("$pow"); + PECallFunction*tmp = make_call_function(tn, $3, $5); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_sin '(' expression ')' + { perm_string tn = perm_string::literal("$sin"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_sinh '(' expression ')' + { perm_string tn = perm_string::literal("$sinh"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_sqrt '(' expression ')' + { perm_string tn = perm_string::literal("$sqrt"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_tan '(' expression ')' + { perm_string tn = perm_string::literal("$tan"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_tanh '(' expression ')' + { perm_string tn = perm_string::literal("$tanh"); + PECallFunction*tmp = make_call_function(tn, $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + /* These mathematical functions are conveniently expressed as unary + and binary expressions. They behave much like unary/binary + operators, even though they are parsed as functions. */ + + | K_abs '(' expression ')' + { PEUnary*tmp = new PEUnary('m', $3); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_max '(' expression ',' expression ')' + { PEBinary*tmp = new PEBinary('M', $3, $5); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + | K_min '(' expression ',' expression ')' + { PEBinary*tmp = new PEBinary('m', $3, $5); + FILE_NAME(tmp,@1); + $$ = tmp; + } + + /* Parenthesized expressions are primaries. */ + + | '(' expr_mintypmax ')' + { $$ = $2; } + + /* Various kinds of concatenation expressions. */ + + | '{' expression_list_proper '}' + { PEConcat*tmp = new PEConcat(*$2); + FILE_NAME(tmp, @1); + delete $2; + $$ = tmp; + } + | '{' expression '{' expression_list_proper '}' '}' + { PExpr*rep = $2; + PEConcat*tmp = new PEConcat(*$4, rep); + FILE_NAME(tmp, @1); + delete $4; + $$ = tmp; + } + | '{' expression '{' expression_list_proper '}' error '}' + { PExpr*rep = $2; + PEConcat*tmp = new PEConcat(*$4, rep); + FILE_NAME(tmp, @1); + delete $4; + $$ = tmp; + yyerror(@5, "error: Syntax error between internal '}' " + "and closing '}' of repeat concatenation."); + yyerrok; + } + + | '{' '}' + { // This is the empty queue syntax. + if (gn_system_verilog()) { + list empty_list; + PEConcat*tmp = new PEConcat(empty_list); + FILE_NAME(tmp, @1); + $$ = tmp; + } else { + yyerror(@1, "error: Concatenations are not allowed to be empty."); + $$ = 0; + } + } + + /* Cast expressions are primaries */ + + | expr_primary "'" '(' expression ')' + { PExpr*base = $4; + if (gn_system_verilog()) { + PECastSize*tmp = new PECastSize($1, base); + FILE_NAME(tmp, @1); + $$ = tmp; + } else { + yyerror(@1, "error: Size cast requires SystemVerilog."); + $$ = base; + } + } + + | simple_type_or_string "'" '(' expression ')' + { PExpr*base = $4; + if (gn_system_verilog()) { + PECastType*tmp = new PECastType($1, base); + FILE_NAME(tmp, @1); + $$ = tmp; + } else { + yyerror(@1, "error: Type cast requires SystemVerilog."); + $$ = base; + } + } + + /* Aggregate literals are primaries. */ + + | assignment_pattern + { $$ = $1; } + + /* SystemVerilog supports streaming concatenation */ + | streaming_concatenation + { $$ = $1; } + + | K_null + { PENull*tmp = new PENull; + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + + /* A function_item_list borrows the task_port_item run to match + declarations of ports. We check later to make sure there are no + output or inout ports actually used. + + The function_item is the same as tf_item_declaration. */ +function_item_list_opt + : function_item_list { $$ = $1; } + | { $$ = 0; } + ; + +function_item_list + : function_item + { $$ = $1; } + | function_item_list function_item + { /* */ + if ($1 && $2) { + vector*tmp = $1; + size_t s1 = tmp->size(); + tmp->resize(s1 + $2->size()); + for (size_t idx = 0 ; idx < $2->size() ; idx += 1) + tmp->at(s1+idx) = $2->at(idx); + delete $2; + $$ = tmp; + } else if ($1) { + $$ = $1; + } else { + $$ = $2; + } + } + ; + +function_item + : tf_port_declaration + { $$ = $1; } + | block_item_decl + { $$ = 0; } + ; + + /* A gate_instance is a module instantiation or a built in part + type. In any case, the gate has a set of connections to ports. */ +gate_instance + : IDENTIFIER '(' expression_list_with_nuls ')' + { lgate*tmp = new lgate; + tmp->name = $1; + tmp->parms = $3; + tmp->file = @1.text; + tmp->lineno = @1.first_line; + delete[]$1; + $$ = tmp; + } + + | IDENTIFIER dimensions '(' expression_list_with_nuls ')' + { lgate*tmp = new lgate; + list*rng = $2; + tmp->name = $1; + tmp->parms = $4; + tmp->range = rng->front(); + rng->pop_front(); + assert(rng->empty()); + tmp->file = @1.text; + tmp->lineno = @1.first_line; + delete[]$1; + delete rng; + $$ = tmp; + } + + | '(' expression_list_with_nuls ')' + { lgate*tmp = new lgate; + tmp->name = ""; + tmp->parms = $2; + tmp->file = @1.text; + tmp->lineno = @1.first_line; + $$ = tmp; + } + + /* Degenerate modules can have no ports. */ + + | IDENTIFIER dimensions + { lgate*tmp = new lgate; + list*rng = $2; + tmp->name = $1; + tmp->parms = 0; + tmp->parms_by_name = 0; + tmp->range = rng->front(); + rng->pop_front(); + assert(rng->empty()); + tmp->file = @1.text; + tmp->lineno = @1.first_line; + delete[]$1; + delete rng; + $$ = tmp; + } + + /* Modules can also take ports by port-name expressions. */ + + | IDENTIFIER '(' port_name_list ')' + { lgate*tmp = new lgate; + tmp->name = $1; + tmp->parms = 0; + tmp->parms_by_name = $3; + tmp->file = @1.text; + tmp->lineno = @1.first_line; + delete[]$1; + $$ = tmp; + } + + | IDENTIFIER dimensions '(' port_name_list ')' + { lgate*tmp = new lgate; + list*rng = $2; + tmp->name = $1; + tmp->parms = 0; + tmp->parms_by_name = $4; + tmp->range = rng->front(); + rng->pop_front(); + assert(rng->empty()); + tmp->file = @1.text; + tmp->lineno = @1.first_line; + delete[]$1; + delete rng; + $$ = tmp; + } + + | IDENTIFIER '(' error ')' + { lgate*tmp = new lgate; + tmp->name = $1; + tmp->parms = 0; + tmp->parms_by_name = 0; + tmp->file = @1.text; + tmp->lineno = @1.first_line; + yyerror(@2, "error: Syntax error in instance port " + "expression(s)."); + delete[]$1; + $$ = tmp; + } + + | IDENTIFIER dimensions '(' error ')' + { lgate*tmp = new lgate; + tmp->name = $1; + tmp->parms = 0; + tmp->parms_by_name = 0; + tmp->file = @1.text; + tmp->lineno = @1.first_line; + yyerror(@3, "error: Syntax error in instance port " + "expression(s)."); + delete[]$1; + $$ = tmp; + } + ; + +gate_instance_list + : gate_instance_list ',' gate_instance + { svector*tmp1 = $1; + lgate*tmp2 = $3; + svector*out = new svector (*tmp1, *tmp2); + delete tmp1; + delete tmp2; + $$ = out; + } + | gate_instance + { svector*tmp = new svector(1); + (*tmp)[0] = *$1; + delete $1; + $$ = tmp; + } + ; + +gatetype + : K_and { $$ = PGBuiltin::AND; } + | K_nand { $$ = PGBuiltin::NAND; } + | K_or { $$ = PGBuiltin::OR; } + | K_nor { $$ = PGBuiltin::NOR; } + | K_xor { $$ = PGBuiltin::XOR; } + | K_xnor { $$ = PGBuiltin::XNOR; } + | K_buf { $$ = PGBuiltin::BUF; } + | K_bufif0 { $$ = PGBuiltin::BUFIF0; } + | K_bufif1 { $$ = PGBuiltin::BUFIF1; } + | K_not { $$ = PGBuiltin::NOT; } + | K_notif0 { $$ = PGBuiltin::NOTIF0; } + | K_notif1 { $$ = PGBuiltin::NOTIF1; } + ; + +switchtype + : K_nmos { $$ = PGBuiltin::NMOS; } + | K_rnmos { $$ = PGBuiltin::RNMOS; } + | K_pmos { $$ = PGBuiltin::PMOS; } + | K_rpmos { $$ = PGBuiltin::RPMOS; } + | K_cmos { $$ = PGBuiltin::CMOS; } + | K_rcmos { $$ = PGBuiltin::RCMOS; } + | K_tran { $$ = PGBuiltin::TRAN; } + | K_rtran { $$ = PGBuiltin::RTRAN; } + | K_tranif0 { $$ = PGBuiltin::TRANIF0; } + | K_tranif1 { $$ = PGBuiltin::TRANIF1; } + | K_rtranif0 { $$ = PGBuiltin::RTRANIF0; } + | K_rtranif1 { $$ = PGBuiltin::RTRANIF1; } + ; + + + /* A general identifier is a hierarchical name, with the right most + name the base of the identifier. This rule builds up a + hierarchical name from the left to the right, forming a list of + names. */ + +hierarchy_identifier + : IDENTIFIER + { $$ = new pform_name_t; + $$->push_back(name_component_t(lex_strings.make($1))); + delete[]$1; + } + | hierarchy_identifier '.' IDENTIFIER + { pform_name_t * tmp = $1; + tmp->push_back(name_component_t(lex_strings.make($3))); + delete[]$3; + $$ = tmp; + } + | hierarchy_identifier '[' expression ']' + { pform_name_t * tmp = $1; + name_component_t&tail = tmp->back(); + index_component_t itmp; + itmp.sel = index_component_t::SEL_BIT; + itmp.msb = $3; + tail.index.push_back(itmp); + $$ = tmp; + } + | hierarchy_identifier '[' '$' ']' + { pform_name_t * tmp = $1; + name_component_t&tail = tmp->back(); + if (! gn_system_verilog()) { + yyerror(@3, "error: Last element expression ($) " + "requires SystemVerilog. Try enabling SystemVerilog."); + } + index_component_t itmp; + itmp.sel = index_component_t::SEL_BIT_LAST; + itmp.msb = 0; + itmp.lsb = 0; + tail.index.push_back(itmp); + $$ = tmp; + } + | hierarchy_identifier '[' expression ':' expression ']' + { pform_name_t * tmp = $1; + name_component_t&tail = tmp->back(); + index_component_t itmp; + itmp.sel = index_component_t::SEL_PART; + itmp.msb = $3; + itmp.lsb = $5; + tail.index.push_back(itmp); + $$ = tmp; + } + | hierarchy_identifier '[' expression K_PO_POS expression ']' + { pform_name_t * tmp = $1; + name_component_t&tail = tmp->back(); + index_component_t itmp; + itmp.sel = index_component_t::SEL_IDX_UP; + itmp.msb = $3; + itmp.lsb = $5; + tail.index.push_back(itmp); + $$ = tmp; + } + | hierarchy_identifier '[' expression K_PO_NEG expression ']' + { pform_name_t * tmp = $1; + name_component_t&tail = tmp->back(); + index_component_t itmp; + itmp.sel = index_component_t::SEL_IDX_DO; + itmp.msb = $3; + itmp.lsb = $5; + tail.index.push_back(itmp); + $$ = tmp; + } + ; + + /* This is a list of identifiers. The result is a list of strings, + each one of the identifiers in the list. These are simple, + non-hierarchical names separated by ',' characters. */ +list_of_identifiers + : IDENTIFIER + { $$ = list_from_identifier($1); } + | list_of_identifiers ',' IDENTIFIER + { $$ = list_from_identifier($1, $3); } + ; + +list_of_port_identifiers + : IDENTIFIER dimensions_opt + { $$ = make_port_list($1, $2, 0); } + | list_of_port_identifiers ',' IDENTIFIER dimensions_opt + { $$ = make_port_list($1, $3, $4, 0); } + ; + +list_of_variable_port_identifiers + : IDENTIFIER dimensions_opt + { $$ = make_port_list($1, $2, 0); } + | IDENTIFIER dimensions_opt '=' expression + { $$ = make_port_list($1, $2, $4); } + | list_of_variable_port_identifiers ',' IDENTIFIER dimensions_opt + { $$ = make_port_list($1, $3, $4, 0); } + | list_of_variable_port_identifiers ',' IDENTIFIER dimensions_opt '=' expression + { $$ = make_port_list($1, $3, $4, $6); } + ; + + + /* The list_of_ports and list_of_port_declarations rules are the + port list formats for module ports. The list_of_ports_opt rule is + only used by the module start rule. + + The first, the list_of_ports, is the 1364-1995 format, a list of + port names, including .name() syntax. + + The list_of_port_declarations the 1364-2001 format, an in-line + declaration of the ports. + + In both cases, the list_of_ports and list_of_port_declarations + returns an array of Module::port_t* items that include the name + of the port internally and externally. The actual creation of the + nets/variables is done in the declaration, whether internal to + the port list or in amongst the module items. */ + +list_of_ports + : port_opt + { vector*tmp + = new vector(1); + (*tmp)[0] = $1; + $$ = tmp; + } + | list_of_ports ',' port_opt + { vector*tmp = $1; + tmp->push_back($3); + $$ = tmp; + } + ; + +list_of_port_declarations + : port_declaration + { vector*tmp + = new vector(1); + (*tmp)[0] = $1; + $$ = tmp; + } + | list_of_port_declarations ',' port_declaration + { vector*tmp = $1; + tmp->push_back($3); + $$ = tmp; + } + | list_of_port_declarations ',' IDENTIFIER + { Module::port_t*ptmp; + perm_string name = lex_strings.make($3); + ptmp = pform_module_port_reference(name, @3.text, + @3.first_line); + vector*tmp = $1; + tmp->push_back(ptmp); + + /* Get the port declaration details, the port type + and what not, from context data stored by the + last port_declaration rule. */ + pform_module_define_port(@3, name, + port_declaration_context.port_type, + port_declaration_context.port_net_type, + port_declaration_context.data_type, 0); + delete[]$3; + $$ = tmp; + } + | list_of_port_declarations ',' + { + yyerror(@2, "error: NULL port declarations are not " + "allowed."); + } + | list_of_port_declarations ';' + { + yyerror(@2, "error: ';' is an invalid port declaration " + "separator."); + } + ; + +port_declaration + : attribute_list_opt K_input net_type_opt data_type_or_implicit IDENTIFIER dimensions_opt + { Module::port_t*ptmp; + perm_string name = lex_strings.make($5); + data_type_t*use_type = $4; + if ($6) use_type = new uarray_type_t(use_type, $6); + ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + pform_module_define_port(@2, name, NetNet::PINPUT, $3, use_type, $1); + port_declaration_context.port_type = NetNet::PINPUT; + port_declaration_context.port_net_type = $3; + port_declaration_context.data_type = $4; + delete[]$5; + $$ = ptmp; + } + | attribute_list_opt + K_input K_wreal IDENTIFIER + { Module::port_t*ptmp; + perm_string name = lex_strings.make($4); + ptmp = pform_module_port_reference(name, @2.text, + @2.first_line); + real_type_t*real_type = new real_type_t(real_type_t::REAL); + FILE_NAME(real_type, @3); + pform_module_define_port(@2, name, NetNet::PINPUT, + NetNet::WIRE, real_type, $1); + port_declaration_context.port_type = NetNet::PINPUT; + port_declaration_context.port_net_type = NetNet::WIRE; + port_declaration_context.data_type = real_type; + delete[]$4; + $$ = ptmp; + } + | attribute_list_opt K_inout net_type_opt data_type_or_implicit IDENTIFIER dimensions_opt + { Module::port_t*ptmp; + perm_string name = lex_strings.make($5); + ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + pform_module_define_port(@2, name, NetNet::PINOUT, $3, $4, $1); + port_declaration_context.port_type = NetNet::PINOUT; + port_declaration_context.port_net_type = $3; + port_declaration_context.data_type = $4; + delete[]$5; + if ($6) { + yyerror(@6, "sorry: Inout ports with unpacked dimensions not supported."); + delete $6; + } + $$ = ptmp; + } + | attribute_list_opt + K_inout K_wreal IDENTIFIER + { Module::port_t*ptmp; + perm_string name = lex_strings.make($4); + ptmp = pform_module_port_reference(name, @2.text, + @2.first_line); + real_type_t*real_type = new real_type_t(real_type_t::REAL); + FILE_NAME(real_type, @3); + pform_module_define_port(@2, name, NetNet::PINOUT, + NetNet::WIRE, real_type, $1); + port_declaration_context.port_type = NetNet::PINOUT; + port_declaration_context.port_net_type = NetNet::WIRE; + port_declaration_context.data_type = real_type; + delete[]$4; + $$ = ptmp; + } + | attribute_list_opt K_output net_type_opt data_type_or_implicit IDENTIFIER dimensions_opt + { Module::port_t*ptmp; + perm_string name = lex_strings.make($5); + data_type_t*use_dtype = $4; + if ($6) use_dtype = new uarray_type_t(use_dtype, $6); + NetNet::Type use_type = $3; + if (use_type == NetNet::IMPLICIT) { + if (vector_type_t*dtype = dynamic_cast ($4)) { + if (dtype->reg_flag) + use_type = NetNet::REG; + else if (dtype->implicit_flag) + use_type = NetNet::IMPLICIT; + else + use_type = NetNet::IMPLICIT_REG; + + // The SystemVerilog types that can show up as + // output ports are implicitly (on the inside) + // variables because "reg" is not valid syntax + // here. + } else if (dynamic_cast ($4)) { + use_type = NetNet::IMPLICIT_REG; + } else if (dynamic_cast ($4)) { + use_type = NetNet::IMPLICIT_REG; + } else if (enum_type_t*etype = dynamic_cast ($4)) { + if(etype->base_type == IVL_VT_LOGIC) + use_type = NetNet::IMPLICIT_REG; + } + } + ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + pform_module_define_port(@2, name, NetNet::POUTPUT, use_type, use_dtype, $1); + port_declaration_context.port_type = NetNet::POUTPUT; + port_declaration_context.port_net_type = use_type; + port_declaration_context.data_type = $4; + delete[]$5; + $$ = ptmp; + } + | attribute_list_opt + K_output K_wreal IDENTIFIER + { Module::port_t*ptmp; + perm_string name = lex_strings.make($4); + ptmp = pform_module_port_reference(name, @2.text, + @2.first_line); + real_type_t*real_type = new real_type_t(real_type_t::REAL); + FILE_NAME(real_type, @3); + pform_module_define_port(@2, name, NetNet::POUTPUT, + NetNet::WIRE, real_type, $1); + port_declaration_context.port_type = NetNet::POUTPUT; + port_declaration_context.port_net_type = NetNet::WIRE; + port_declaration_context.data_type = real_type; + delete[]$4; + $$ = ptmp; + } + | attribute_list_opt K_output net_type_opt data_type_or_implicit IDENTIFIER '=' expression + { Module::port_t*ptmp; + perm_string name = lex_strings.make($5); + NetNet::Type use_type = $3; + if (use_type == NetNet::IMPLICIT) { + if (vector_type_t*dtype = dynamic_cast ($4)) { + if (dtype->reg_flag) + use_type = NetNet::REG; + else + use_type = NetNet::IMPLICIT_REG; + } else { + use_type = NetNet::IMPLICIT_REG; + } + } + ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + pform_module_define_port(@2, name, NetNet::POUTPUT, use_type, $4, $1); + port_declaration_context.port_type = NetNet::PINOUT; + port_declaration_context.port_net_type = use_type; + port_declaration_context.data_type = $4; + + pform_make_var_init(@5, name, $7); + + delete[]$5; + $$ = ptmp; + } + ; + + + +net_type_opt + : net_type { $$ = $1; } + | { $$ = NetNet::IMPLICIT; } + ; + + /* + * The signed_opt rule will return "true" if K_signed is present, + * for "false" otherwise. This rule corresponds to the declaration + * defaults for reg/bit/logic. + * + * The signed_unsigned_opt rule with match K_signed or K_unsigned + * and return true or false as appropriate. The default is + * "true". This corresponds to the declaration defaults for + * byte/shortint/int/longint. + */ +unsigned_signed_opt + : K_signed { $$ = true; } + | K_unsigned { $$ = false; } + | { $$ = false; } + ; + +signed_unsigned_opt + : K_signed { $$ = true; } + | K_unsigned { $$ = false; } + | { $$ = true; } + ; + + /* + * In some places we can take any of the 4 2-value atom-type + * names. All the context needs to know if that type is its width. + */ +atom2_type + : K_byte { $$ = 8; } + | K_shortint { $$ = 16; } + | K_int { $$ = 32; } + | K_longint { $$ = 64; } + ; + + /* An lpvalue is the expression that can go on the left side of a + procedural assignment. This rule handles only procedural + assignments. It is more limited than the general expr_primary + rule to reflect the rules for assignment l-values. */ +lpvalue + : hierarchy_identifier + { PEIdent*tmp = pform_new_ident(*$1); + FILE_NAME(tmp, @1); + $$ = tmp; + delete $1; + } + + | implicit_class_handle '.' hierarchy_identifier + { pform_name_t*t_name = $1; + while (!$3->empty()) { + t_name->push_back($3->front()); + $3->pop_front(); + } + PEIdent*tmp = new PEIdent(*t_name); + FILE_NAME(tmp, @1); + $$ = tmp; + delete $1; + delete $3; + } + + | '{' expression_list_proper '}' + { PEConcat*tmp = new PEConcat(*$2); + FILE_NAME(tmp, @1); + delete $2; + $$ = tmp; + } + + | streaming_concatenation + { yyerror(@1, "sorry: streaming concatenation not supported in l-values."); + $$ = 0; + } + ; + + + /* Continuous assignments have a list of individual assignments. */ + +cont_assign + : lpvalue '=' expression + { list*tmp = new list; + tmp->push_back($1); + tmp->push_back($3); + $$ = tmp; + } + ; + +cont_assign_list + : cont_assign_list ',' cont_assign + { list*tmp = $1; + tmp->splice(tmp->end(), *$3); + delete $3; + $$ = tmp; + } + | cont_assign + { $$ = $1; } + ; + + /* This is the global structure of a module. A module is a start + section, with optional ports, then an optional list of module + items, and finally an end marker. */ + +module + : attribute_list_opt module_start lifetime_opt IDENTIFIER + { pform_startmodule(@2, $4, $2==K_program, $2==K_interface, $3, $1); } + module_package_import_list_opt + module_parameter_port_list_opt + module_port_list_opt + module_attribute_foreign ';' + { pform_module_set_ports($8); } + timeunits_declaration_opt + { pform_set_scope_timescale(@2); } + module_item_list_opt + module_end + { Module::UCDriveType ucd; + // The lexor detected `unconnected_drive directives and + // marked what it found in the uc_drive variable. Use that + // to generate a UCD flag for the module. + switch (uc_drive) { + case UCD_NONE: + default: + ucd = Module::UCD_NONE; + break; + case UCD_PULL0: + ucd = Module::UCD_PULL0; + break; + case UCD_PULL1: + ucd = Module::UCD_PULL1; + break; + } + // Check that program/endprogram and module/endmodule + // keywords match. + if ($2 != $15) { + switch ($2) { + case K_module: + yyerror(@15, "error: module not closed by endmodule."); + break; + case K_program: + yyerror(@15, "error: program not closed by endprogram."); + break; + case K_interface: + yyerror(@15, "error: interface not closed by endinterface."); + break; + default: + break; + } + } + pform_endmodule($4, in_celldefine, ucd); + } + endlabel_opt + { // Last step: check any closing name. This is done late so + // that the parser can look ahead to detect the present + // endlabel_opt but still have the pform_endmodule() called + // early enough that the lexor can know we are outside the + // module. + if ($17) { + if (strcmp($4,$17) != 0) { + switch ($2) { + case K_module: + yyerror(@17, "error: End label doesn't match " + "module name."); + break; + case K_program: + yyerror(@17, "error: End label doesn't match " + "program name."); + break; + case K_interface: + yyerror(@17, "error: End label doesn't match " + "interface name."); + break; + default: + break; + } + } + if (($2 == K_module) && (! gn_system_verilog())) { + yyerror(@8, "error: Module end labels require " + "SystemVerilog."); + } + delete[]$17; + } + delete[]$4; + } + ; + + /* Modules start with a module/macromodule, program, or interface + keyword, and end with a endmodule, endprogram, or endinterface + keyword. The syntax for modules programs, and interfaces is + almost identical, so let semantics sort out the differences. */ +module_start + : K_module { $$ = K_module; } + | K_macromodule { $$ = K_module; } + | K_program { $$ = K_program; } + | K_interface { $$ = K_interface; } + ; + +module_end + : K_endmodule { $$ = K_module; } + | K_endprogram { $$ = K_program; } + | K_endinterface { $$ = K_interface; } + ; + +endlabel_opt + : ':' IDENTIFIER { $$ = $2; } + | { $$ = 0; } + ; + +module_attribute_foreign + : K_PSTAR IDENTIFIER K_integer IDENTIFIER '=' STRING ';' K_STARP { $$ = 0; } + | { $$ = 0; } + ; + +module_port_list_opt + : '(' list_of_ports ')' { $$ = $2; } + | '(' list_of_port_declarations ')' { $$ = $2; } + | { $$ = 0; } + | '(' error ')' + { yyerror(@2, "Errors in port declarations."); + yyerrok; + $$ = 0; + } + ; + + /* Module declarations include optional ANSI style module parameter + ports. These are simply advance ways to declare parameters, so + that the port declarations may use them. */ +module_parameter_port_list_opt + : + | '#' '(' module_parameter_port_list ')' + ; + +module_parameter_port_list + : K_parameter param_type parameter_assign + | module_parameter_port_list ',' parameter_assign + | module_parameter_port_list ',' K_parameter param_type parameter_assign + ; + +module_item + + /* Modules can contain further sub-module definitions. */ + : module + + | attribute_list_opt net_type data_type_or_implicit delay3_opt net_variable_list ';' + + { data_type_t*data_type = $3; + if (data_type == 0) { + data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + FILE_NAME(data_type, @2); + } + pform_set_data_type(@2, data_type, $5, $2, $1); + if ($4 != 0) { + yyerror(@2, "sorry: net delays not supported."); + delete $4; + } + delete $1; + } + + | attribute_list_opt K_wreal delay3 net_variable_list ';' + { real_type_t*tmpt = new real_type_t(real_type_t::REAL); + pform_set_data_type(@2, tmpt, $4, NetNet::WIRE, $1); + if ($3 != 0) { + yyerror(@3, "sorry: net delays not supported."); + delete $3; + } + delete $1; + } + + | attribute_list_opt K_wreal net_variable_list ';' + { real_type_t*tmpt = new real_type_t(real_type_t::REAL); + pform_set_data_type(@2, tmpt, $3, NetNet::WIRE, $1); + delete $1; + } + + /* Very similar to the rule above, but this takes a list of + net_decl_assigns, which are = assignment + declarations. */ + + | attribute_list_opt net_type data_type_or_implicit delay3_opt net_decl_assigns ';' + { data_type_t*data_type = $3; + if (data_type == 0) { + data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + FILE_NAME(data_type, @2); + } + pform_makewire(@2, $4, str_strength, $5, $2, data_type); + if ($1) { + yywarn(@2, "Attributes are not supported on net declaration " + "assignments and will be discarded."); + delete $1; + } + } + + /* This form doesn't have the range, but does have strengths. This + gives strength to the assignment drivers. */ + + | attribute_list_opt net_type data_type_or_implicit drive_strength net_decl_assigns ';' + { data_type_t*data_type = $3; + if (data_type == 0) { + data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + FILE_NAME(data_type, @2); + } + pform_makewire(@2, 0, $4, $5, $2, data_type); + if ($1) { + yywarn(@2, "Attributes are not supported on net declaration " + "assignments and will be discarded."); + delete $1; + } + } + + | attribute_list_opt K_wreal net_decl_assigns ';' + { real_type_t*data_type = new real_type_t(real_type_t::REAL); + pform_makewire(@2, 0, str_strength, $3, NetNet::WIRE, data_type); + if ($1) { + yywarn(@2, "Attributes are not supported on net declaration " + "assignments and will be discarded."); + delete $1; + } + } + + | K_trireg charge_strength_opt dimensions_opt delay3_opt list_of_identifiers ';' + { yyerror(@1, "sorry: trireg nets not supported."); + delete $3; + delete $4; + } + + + /* The next two rules handle port declarations that include a net type, e.g. + input wire signed [h:l] ; + This creates the wire and sets the port type all at once. */ + + | attribute_list_opt port_direction net_type data_type_or_implicit list_of_port_identifiers ';' + { pform_module_define_port(@2, $5, $2, $3, $4, $1); } + + | attribute_list_opt port_direction K_wreal list_of_port_identifiers ';' + { real_type_t*real_type = new real_type_t(real_type_t::REAL); + pform_module_define_port(@2, $4, $2, NetNet::WIRE, real_type, $1); + } + + /* The next three rules handle port declarations that include a variable + type, e.g. + output reg signed [h:l] ; + and also handle incomplete port declarations, e.g. + input signed [h:l] ; + */ + | attribute_list_opt K_inout data_type_or_implicit list_of_port_identifiers ';' + { NetNet::Type use_type = $3 ? NetNet::IMPLICIT : NetNet::NONE; + if (vector_type_t*dtype = dynamic_cast ($3)) { + if (dtype->implicit_flag) + use_type = NetNet::NONE; + } + if (use_type == NetNet::NONE) + pform_set_port_type(@2, $4, NetNet::PINOUT, $3, $1); + else + pform_module_define_port(@2, $4, NetNet::PINOUT, use_type, $3, $1); + } + + | attribute_list_opt K_input data_type_or_implicit list_of_port_identifiers ';' + { NetNet::Type use_type = $3 ? NetNet::IMPLICIT : NetNet::NONE; + if (vector_type_t*dtype = dynamic_cast ($3)) { + if (dtype->implicit_flag) + use_type = NetNet::NONE; + } + if (use_type == NetNet::NONE) + pform_set_port_type(@2, $4, NetNet::PINPUT, $3, $1); + else + pform_module_define_port(@2, $4, NetNet::PINPUT, use_type, $3, $1); + } + + | attribute_list_opt K_output data_type_or_implicit list_of_variable_port_identifiers ';' + { NetNet::Type use_type = $3 ? NetNet::IMPLICIT : NetNet::NONE; + if (vector_type_t*dtype = dynamic_cast ($3)) { + if (dtype->implicit_flag) + use_type = NetNet::NONE; + else if (dtype->reg_flag) + use_type = NetNet::REG; + else + use_type = NetNet::IMPLICIT_REG; + + // The SystemVerilog types that can show up as + // output ports are implicitly (on the inside) + // variables because "reg" is not valid syntax + // here. + } else if (dynamic_cast ($3)) { + use_type = NetNet::IMPLICIT_REG; + } else if (dynamic_cast ($3)) { + use_type = NetNet::IMPLICIT_REG; + } else if (enum_type_t*etype = dynamic_cast ($3)) { + if(etype->base_type == IVL_VT_LOGIC) + use_type = NetNet::IMPLICIT_REG; + } + if (use_type == NetNet::NONE) + pform_set_port_type(@2, $4, NetNet::POUTPUT, $3, $1); + else + pform_module_define_port(@2, $4, NetNet::POUTPUT, use_type, $3, $1); + } + + | attribute_list_opt port_direction net_type data_type_or_implicit error ';' + { yyerror(@2, "error: Invalid variable list in port declaration."); + if ($1) delete $1; + if ($4) delete $4; + yyerrok; + } + + | attribute_list_opt K_inout data_type_or_implicit error ';' + { yyerror(@2, "error: Invalid variable list in port declaration."); + if ($1) delete $1; + if ($3) delete $3; + yyerrok; + } + + | attribute_list_opt K_input data_type_or_implicit error ';' + { yyerror(@2, "error: Invalid variable list in port declaration."); + if ($1) delete $1; + if ($3) delete $3; + yyerrok; + } + + | attribute_list_opt K_output data_type_or_implicit error ';' + { yyerror(@2, "error: Invalid variable list in port declaration."); + if ($1) delete $1; + if ($3) delete $3; + yyerrok; + } + + /* Maybe this is a discipline declaration? If so, then the lexor + will see the discipline name as an identifier. We match it to the + discipline or type name semantically. */ + | DISCIPLINE_IDENTIFIER list_of_identifiers ';' + { pform_attach_discipline(@1, $1, $2); } + + /* block_item_decl rule is shared with task blocks and named + begin/end. Careful to pass attributes to the block_item_decl. */ + + | attribute_list_opt { attributes_in_context = $1; } block_item_decl + { delete attributes_in_context; + attributes_in_context = 0; + } + + /* */ + + | K_defparam + { if (pform_in_interface()) + yyerror(@1, "error: Parameter overrides are not allowed " + "in interfaces."); + } + defparam_assign_list ';' + + /* Most gate types have an optional drive strength and optional + two/three-value delay. These rules handle the different cases. + We check that the actual number of delays is correct later. */ + + | attribute_list_opt gatetype gate_instance_list ';' + { pform_makegates(@2, $2, str_strength, 0, $3, $1); } + + | attribute_list_opt gatetype delay3 gate_instance_list ';' + { pform_makegates(@2, $2, str_strength, $3, $4, $1); } + + | attribute_list_opt gatetype drive_strength gate_instance_list ';' + { pform_makegates(@2, $2, $3, 0, $4, $1); } + + | attribute_list_opt gatetype drive_strength delay3 gate_instance_list ';' + { pform_makegates(@2, $2, $3, $4, $5, $1); } + + /* The switch type gates do not support a strength. */ + | attribute_list_opt switchtype gate_instance_list ';' + { pform_makegates(@2, $2, str_strength, 0, $3, $1); } + + | attribute_list_opt switchtype delay3 gate_instance_list ';' + { pform_makegates(@2, $2, str_strength, $3, $4, $1); } + + /* Pullup and pulldown devices cannot have delays, and their + strengths are limited. */ + + | K_pullup gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLUP, pull_strength, 0, $2, 0); } + | K_pulldown gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLDOWN, pull_strength, 0, $2, 0); } + + | K_pullup '(' dr_strength1 ')' gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLUP, $3, 0, $5, 0); } + + | K_pullup '(' dr_strength1 ',' dr_strength0 ')' gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLUP, $3, 0, $7, 0); } + + | K_pullup '(' dr_strength0 ',' dr_strength1 ')' gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLUP, $5, 0, $7, 0); } + + | K_pulldown '(' dr_strength0 ')' gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLDOWN, $3, 0, $5, 0); } + + | K_pulldown '(' dr_strength1 ',' dr_strength0 ')' gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLDOWN, $5, 0, $7, 0); } + + | K_pulldown '(' dr_strength0 ',' dr_strength1 ')' gate_instance_list ';' + { pform_makegates(@1, PGBuiltin::PULLDOWN, $3, 0, $7, 0); } + + /* This rule handles instantiations of modules and user defined + primitives. These devices to not have delay lists or strengths, + but then can have parameter lists. */ + + | attribute_list_opt + IDENTIFIER parameter_value_opt gate_instance_list ';' + { perm_string tmp1 = lex_strings.make($2); + pform_make_modgates(@2, tmp1, $3, $4, $1); + delete[]$2; + } + + | attribute_list_opt + IDENTIFIER parameter_value_opt error ';' + { yyerror(@2, "error: Invalid module instantiation"); + delete[]$2; + if ($1) delete $1; + } + + /* Continuous assignment can have an optional drive strength, then + an optional delay3 that applies to all the assignments in the + cont_assign_list. */ + + | K_assign drive_strength_opt delay3_opt cont_assign_list ';' + { pform_make_pgassign_list($4, $3, $2, @1.text, @1.first_line); } + + /* Always and initial items are behavioral processes. */ + + | attribute_list_opt K_always statement_item + { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS, $3, $1); + FILE_NAME(tmp, @2); + } + | attribute_list_opt K_always_comb statement_item + { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS_COMB, $3, $1); + FILE_NAME(tmp, @2); + } + | attribute_list_opt K_always_ff statement_item + { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS_FF, $3, $1); + FILE_NAME(tmp, @2); + } + | attribute_list_opt K_always_latch statement_item + { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS_LATCH, $3, $1); + FILE_NAME(tmp, @2); + } + | attribute_list_opt K_initial statement_item + { PProcess*tmp = pform_make_behavior(IVL_PR_INITIAL, $3, $1); + FILE_NAME(tmp, @2); + } + | attribute_list_opt K_final statement_item + { PProcess*tmp = pform_make_behavior(IVL_PR_FINAL, $3, $1); + FILE_NAME(tmp, @2); + } + + | attribute_list_opt K_analog analog_statement + { pform_make_analog_behavior(@2, IVL_PR_ALWAYS, $3); } + + | attribute_list_opt assertion_item + + | timeunits_declaration + + | class_declaration + + | task_declaration + + | function_declaration + + /* A generate region can contain further module items. Actually, it + is supposed to be limited to certain kinds of module items, but + the semantic tests will check that for us. Do check that the + generate/endgenerate regions do not nest. Generate schemes nest, + but generate regions do not. */ + + | K_generate generate_item_list_opt K_endgenerate + { // Test for bad nesting. I understand it, but it is illegal. + if (pform_parent_generate()) { + cerr << @1 << ": error: Generate/endgenerate regions cannot nest." << endl; + cerr << @1 << ": : Try removing optional generate/endgenerate keywords," << endl; + cerr << @1 << ": : or move them to surround the parent generate scheme." << endl; + error_count += 1; + } + } + + | K_genvar list_of_identifiers ';' + { pform_genvars(@1, $2); } + + | K_for '(' IDENTIFIER '=' expression ';' + expression ';' + IDENTIFIER '=' expression ')' + { pform_start_generate_for(@1, $3, $5, $7, $9, $11); } + generate_block + { pform_endgenerate(); } + + | generate_if + generate_block_opt + K_else + { pform_start_generate_else(@1); } + generate_block + { pform_endgenerate(); } + + | generate_if + generate_block_opt %prec less_than_K_else + { pform_endgenerate(); } + + | K_case '(' expression ')' + { pform_start_generate_case(@1, $3); } + generate_case_items + K_endcase + { pform_endgenerate(); } + + | modport_declaration + + | package_import_declaration + + /* 1364-2001 and later allow specparam declarations outside specify blocks. */ + + | attribute_list_opt K_specparam + { if (pform_in_interface()) + yyerror(@1, "error: specparam declarations are not allowed " + "in interfaces."); + } + specparam_decl ';' + + /* specify blocks are parsed but ignored. */ + + | K_specify + { if (pform_in_interface()) + yyerror(@1, "error: specify blocks are not allowed " + "in interfaces."); + } + specify_item_list_opt K_endspecify + + | K_specify error K_endspecify + { yyerror(@1, "error: syntax error in specify block"); + yyerrok; + } + + /* These rules match various errors that the user can type into + module items. These rules try to catch them at a point where a + reasonable error message can be produced. */ + + | error ';' + { yyerror(@2, "error: invalid module item."); + yyerrok; + } + + | K_assign error '=' expression ';' + { yyerror(@1, "error: syntax error in left side " + "of continuous assignment."); + yyerrok; + } + + | K_assign error ';' + { yyerror(@1, "error: syntax error in " + "continuous assignment"); + yyerrok; + } + + | K_function error K_endfunction endlabel_opt + { yyerror(@1, "error: I give up on this " + "function definition."); + if ($4) { + if (!gn_system_verilog()) { + yyerror(@4, "error: Function end names require " + "SystemVerilog."); + } + delete[]$4; + } + yyerrok; + } + + /* These rules are for the Icarus Verilog specific $attribute + extensions. Then catch the parameters of the $attribute keyword. */ + + | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ';' + { perm_string tmp3 = lex_strings.make($3); + perm_string tmp5 = lex_strings.make($5); + pform_set_attrib(tmp3, tmp5, $7); + delete[] $3; + delete[] $5; + } + | KK_attribute '(' error ')' ';' + { yyerror(@1, "error: Malformed $attribute parameter list."); } + + ; + +module_item_list + : module_item_list module_item + | module_item + ; + +module_item_list_opt + : module_item_list + | + ; + +generate_if : K_if '(' expression ')' { pform_start_generate_if(@1, $3); } ; + +generate_case_items + : generate_case_items generate_case_item + | generate_case_item + ; + +generate_case_item + : expression_list_proper ':' { pform_generate_case_item(@1, $1); } generate_block_opt + { pform_endgenerate(); } + | K_default ':' { pform_generate_case_item(@1, 0); } generate_block_opt + { pform_endgenerate(); } + ; + +generate_item + : module_item + /* Handle some anachronistic syntax cases. */ + | K_begin generate_item_list_opt K_end + { /* Detect and warn about anachronistic begin/end use */ + if (generation_flag > GN_VER2001 && warn_anachronisms) { + warn_count += 1; + cerr << @1 << ": warning: Anachronistic use of begin/end to surround generate schemes." << endl; + } + } + | K_begin ':' IDENTIFIER { + pform_start_generate_nblock(@1, $3); + } generate_item_list_opt K_end + { /* Detect and warn about anachronistic named begin/end use */ + if (generation_flag > GN_VER2001 && warn_anachronisms) { + warn_count += 1; + cerr << @1 << ": warning: Anachronistic use of named begin/end to surround generate schemes." << endl; + } + pform_endgenerate(); + } + ; + +generate_item_list + : generate_item_list generate_item + | generate_item + ; + +generate_item_list_opt + : generate_item_list + | + ; + + /* A generate block is the thing within a generate scheme. It may be + a single module item, an anonymous block of module items, or a + named module item. In all cases, the meat is in the module items + inside, and the processing is done by the module_item rules. We + only need to take note here of the scope name, if any. */ + +generate_block + : module_item + | K_begin generate_item_list_opt K_end + | K_begin ':' IDENTIFIER generate_item_list_opt K_end endlabel_opt + { pform_generate_block_name($3); + if ($6) { + if (strcmp($3,$6) != 0) { + yyerror(@6, "error: End label doesn't match " + "begin name"); + } + if (! gn_system_verilog()) { + yyerror(@6, "error: Begin end labels require " + "SystemVerilog."); + } + delete[]$6; + } + delete[]$3; + } + ; + +generate_block_opt : generate_block | ';' ; + + + /* A net declaration assignment allows the programmer to combine the + net declaration and the continuous assignment into a single + statement. + + Note that the continuous assignment statement is generated as a + side effect, and all I pass up is the name of the l-value. */ + +net_decl_assign + : IDENTIFIER '=' expression + { net_decl_assign_t*tmp = new net_decl_assign_t; + tmp->next = tmp; + tmp->name = lex_strings.make($1); + tmp->expr = $3; + delete[]$1; + $$ = tmp; + } + ; + +net_decl_assigns + : net_decl_assigns ',' net_decl_assign + { net_decl_assign_t*tmp = $1; + $3->next = tmp->next; + tmp->next = $3; + $$ = tmp; + } + | net_decl_assign + { $$ = $1; + } + ; + +bit_logic + : K_logic { $$ = IVL_VT_LOGIC; } + | K_bool { $$ = IVL_VT_BOOL; /* Icarus misc */} + | K_bit { $$ = IVL_VT_BOOL; /* IEEE1800 / IEEE1364-2009 */} + ; + +bit_logic_opt + : bit_logic + | { $$ = IVL_VT_NO_TYPE; } + ; + +net_type + : K_wire { $$ = NetNet::WIRE; } + | K_tri { $$ = NetNet::TRI; } + | K_tri1 { $$ = NetNet::TRI1; } + | K_supply0 { $$ = NetNet::SUPPLY0; } + | K_wand { $$ = NetNet::WAND; } + | K_triand { $$ = NetNet::TRIAND; } + | K_tri0 { $$ = NetNet::TRI0; } + | K_supply1 { $$ = NetNet::SUPPLY1; } + | K_wor { $$ = NetNet::WOR; } + | K_trior { $$ = NetNet::TRIOR; } + | K_wone { $$ = NetNet::UNRESOLVED_WIRE; + cerr << @1.text << ":" << @1.first_line << ": warning: " + "'wone' is deprecated, please use 'uwire' " + "instead." << endl; + } + | K_uwire { $$ = NetNet::UNRESOLVED_WIRE; } + ; + +param_type + : bit_logic_opt unsigned_signed_opt dimensions_opt + { param_active_range = $3; + param_active_signed = $2; + if (($1 == IVL_VT_NO_TYPE) && ($3 != 0)) + param_active_type = IVL_VT_LOGIC; + else + param_active_type = $1; + } + | K_integer + { param_active_range = make_range_from_width(integer_width); + param_active_signed = true; + param_active_type = IVL_VT_LOGIC; + } + | K_time + { param_active_range = make_range_from_width(64); + param_active_signed = false; + param_active_type = IVL_VT_LOGIC; + } + | real_or_realtime + { param_active_range = 0; + param_active_signed = true; + param_active_type = IVL_VT_REAL; + } + | atom2_type + { param_active_range = make_range_from_width($1); + param_active_signed = true; + param_active_type = IVL_VT_BOOL; + } + | TYPE_IDENTIFIER + { pform_set_param_from_type(@1, $1.type, $1.text, param_active_range, + param_active_signed, param_active_type); + delete[]$1.text; + } + ; + + /* parameter and localparam assignment lists are broken into + separate BNF so that I can call slightly different parameter + handling code. localparams parse the same as parameters, they + just behave differently when someone tries to override them. */ + +parameter_assign_list + : parameter_assign + | parameter_assign_list ',' parameter_assign + ; + +localparam_assign_list + : localparam_assign + | localparam_assign_list ',' localparam_assign + ; + +parameter_assign + : IDENTIFIER '=' expression parameter_value_ranges_opt + { PExpr*tmp = $3; + pform_set_parameter(@1, lex_strings.make($1), param_active_type, + param_active_signed, param_active_range, tmp, $4); + delete[]$1; + } + ; + +localparam_assign + : IDENTIFIER '=' expression + { PExpr*tmp = $3; + pform_set_localparam(@1, lex_strings.make($1), param_active_type, + param_active_signed, param_active_range, tmp); + delete[]$1; + } + ; + +parameter_value_ranges_opt : parameter_value_ranges { $$ = $1; } | { $$ = 0; } ; + +parameter_value_ranges + : parameter_value_ranges parameter_value_range + { $$ = $2; $$->next = $1; } + | parameter_value_range + { $$ = $1; $$->next = 0; } + ; + +parameter_value_range + : from_exclude '[' value_range_expression ':' value_range_expression ']' + { $$ = pform_parameter_value_range($1, false, $3, false, $5); } + | from_exclude '[' value_range_expression ':' value_range_expression ')' + { $$ = pform_parameter_value_range($1, false, $3, true, $5); } + | from_exclude '(' value_range_expression ':' value_range_expression ']' + { $$ = pform_parameter_value_range($1, true, $3, false, $5); } + | from_exclude '(' value_range_expression ':' value_range_expression ')' + { $$ = pform_parameter_value_range($1, true, $3, true, $5); } + | K_exclude expression + { $$ = pform_parameter_value_range(true, false, $2, false, $2); } + ; + +value_range_expression + : expression { $$ = $1; } + | K_inf { $$ = 0; } + | '+' K_inf { $$ = 0; } + | '-' K_inf { $$ = 0; } + ; + +from_exclude : K_from { $$ = false; } | K_exclude { $$ = true; } ; + + /* The parameters of a module instance can be overridden by writing + a list of expressions in a syntax much like a delay list. (The + difference being the list can have any length.) The pform that + attaches the expression list to the module checks that the + expressions are constant. + + Although the BNF in IEEE1364-1995 implies that parameter value + lists must be in parentheses, in practice most compilers will + accept simple expressions outside of parentheses if there is only + one value, so I'll accept simple numbers here. This also catches + the case of a UDP with a single delay value, so we need to accept + real values as well as decimal ones. + + The parameter value by name syntax is OVI enhancement BTF-B06 as + approved by WG1364 on 6/28/1998. */ + +parameter_value_opt + : '#' '(' expression_list_with_nuls ')' + { struct parmvalue_t*tmp = new struct parmvalue_t; + tmp->by_order = $3; + tmp->by_name = 0; + $$ = tmp; + } + | '#' '(' parameter_value_byname_list ')' + { struct parmvalue_t*tmp = new struct parmvalue_t; + tmp->by_order = 0; + tmp->by_name = $3; + $$ = tmp; + } + | '#' DEC_NUMBER + { assert($2); + PENumber*tmp = new PENumber($2); + FILE_NAME(tmp, @1); + + struct parmvalue_t*lst = new struct parmvalue_t; + lst->by_order = new list; + lst->by_order->push_back(tmp); + lst->by_name = 0; + $$ = lst; + based_size = 0; + } + | '#' REALTIME + { assert($2); + PEFNumber*tmp = new PEFNumber($2); + FILE_NAME(tmp, @1); + + struct parmvalue_t*lst = new struct parmvalue_t; + lst->by_order = new list; + lst->by_order->push_back(tmp); + lst->by_name = 0; + $$ = lst; + } + | '#' error + { yyerror(@1, "error: syntax error in parameter value " + "assignment list."); + $$ = 0; + } + | + { $$ = 0; } + ; + +parameter_value_byname + : '.' IDENTIFIER '(' expression ')' + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($2); + tmp->parm = $4; + delete[]$2; + $$ = tmp; + } + | '.' IDENTIFIER '(' ')' + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($2); + tmp->parm = 0; + delete[]$2; + $$ = tmp; + } + ; + +parameter_value_byname_list + : parameter_value_byname + { list*tmp = new list; + tmp->push_back(*$1); + delete $1; + $$ = tmp; + } + | parameter_value_byname_list ',' parameter_value_byname + { list*tmp = $1; + tmp->push_back(*$3); + delete $3; + $$ = tmp; + } + ; + + + /* The port (of a module) is a fairly complex item. Each port is + handled as a Module::port_t object. A simple port reference has a + name and a PExpr object, but more complex constructs are possible + where the name can be attached to a list of PWire objects. + + The port_reference returns a Module::port_t, and so does the + port_reference_list. The port_reference_list may have built up a + list of PWires in the port_t object, but it is still a single + Module::port_t object. + + The port rule below takes the built up Module::port_t object and + tweaks its name as needed. */ + +port + : port_reference + { $$ = $1; } + + /* This syntax attaches an external name to the port reference so + that the caller can bind by name to non-trivial port + references. The port_t object gets its PWire from the + port_reference, but its name from the IDENTIFIER. */ + + | '.' IDENTIFIER '(' port_reference ')' + { Module::port_t*tmp = $4; + tmp->name = lex_strings.make($2); + delete[]$2; + $$ = tmp; + } + + /* A port can also be a concatenation of port references. In this + case the port does not have a name available to the outside, only + positional parameter passing is possible here. */ + + | '{' port_reference_list '}' + { Module::port_t*tmp = $2; + tmp->name = perm_string(); + $$ = tmp; + } + + /* This attaches a name to a port reference concatenation list so + that parameter passing be name is possible. */ + + | '.' IDENTIFIER '(' '{' port_reference_list '}' ')' + { Module::port_t*tmp = $5; + tmp->name = lex_strings.make($2); + delete[]$2; + $$ = tmp; + } + ; + +port_opt + : port { $$ = $1; } + | { $$ = 0; } + ; + + /* The port_name rule is used with a module is being *instantiated*, + and not when it is being declared. See the port rule if you are + looking for the ports of a module declaration. */ + +port_name + : '.' IDENTIFIER '(' expression ')' + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($2); + tmp->parm = $4; + delete[]$2; + $$ = tmp; + } + | '.' IDENTIFIER '(' error ')' + { yyerror(@3, "error: invalid port connection expression."); + named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($2); + tmp->parm = 0; + delete[]$2; + $$ = tmp; + } + | '.' IDENTIFIER '(' ')' + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($2); + tmp->parm = 0; + delete[]$2; + $$ = tmp; + } + | '.' IDENTIFIER + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make($2); + tmp->parm = new PEIdent(lex_strings.make($2), true); + FILE_NAME(tmp->parm, @1); + delete[]$2; + $$ = tmp; + } + | K_DOTSTAR + { named_pexpr_t*tmp = new named_pexpr_t; + tmp->name = lex_strings.make("*"); + tmp->parm = 0; + $$ = tmp; + } + ; + +port_name_list + : port_name_list ',' port_name + { list*tmp = $1; + tmp->push_back(*$3); + delete $3; + $$ = tmp; + } + | port_name + { list*tmp = new list; + tmp->push_back(*$1); + delete $1; + $$ = tmp; + } + ; + + + /* A port reference is an internal (to the module) name of the port, + possibly with a part of bit select to attach it to specific bits + of a signal fully declared inside the module. + + The parser creates a PEIdent for every port reference, even if the + signal is bound to different ports. The elaboration figures out + the mess that this creates. The port_reference (and the + port_reference_list below) puts the port reference PEIdent into the + port_t object to pass it up to the module declaration code. */ + +port_reference + + : IDENTIFIER + { Module::port_t*ptmp; + perm_string name = lex_strings.make($1); + ptmp = pform_module_port_reference(name, @1.text, @1.first_line); + delete[]$1; + $$ = ptmp; + } + + | IDENTIFIER '[' expression ':' expression ']' + { index_component_t itmp; + itmp.sel = index_component_t::SEL_PART; + itmp.msb = $3; + itmp.lsb = $5; + + name_component_t ntmp (lex_strings.make($1)); + ntmp.index.push_back(itmp); + + pform_name_t pname; + pname.push_back(ntmp); + + PEIdent*wtmp = new PEIdent(pname); + FILE_NAME(wtmp, @1); + + Module::port_t*ptmp = new Module::port_t; + ptmp->name = perm_string(); + ptmp->expr.push_back(wtmp); + + delete[]$1; + $$ = ptmp; + } + + | IDENTIFIER '[' expression ']' + { index_component_t itmp; + itmp.sel = index_component_t::SEL_BIT; + itmp.msb = $3; + itmp.lsb = 0; + + name_component_t ntmp (lex_strings.make($1)); + ntmp.index.push_back(itmp); + + pform_name_t pname; + pname.push_back(ntmp); + + PEIdent*tmp = new PEIdent(pname); + FILE_NAME(tmp, @1); + + Module::port_t*ptmp = new Module::port_t; + ptmp->name = perm_string(); + ptmp->expr.push_back(tmp); + delete[]$1; + $$ = ptmp; + } + + | IDENTIFIER '[' error ']' + { yyerror(@1, "error: invalid port bit select"); + Module::port_t*ptmp = new Module::port_t; + PEIdent*wtmp = new PEIdent(lex_strings.make($1)); + FILE_NAME(wtmp, @1); + ptmp->name = lex_strings.make($1); + ptmp->expr.push_back(wtmp); + delete[]$1; + $$ = ptmp; + } + ; + + +port_reference_list + : port_reference + { $$ = $1; } + | port_reference_list ',' port_reference + { Module::port_t*tmp = $1; + append(tmp->expr, $3->expr); + delete $3; + $$ = tmp; + } + ; + + /* The range is a list of variable dimensions. */ +dimensions_opt + : { $$ = 0; } + | dimensions { $$ = $1; } + ; + +dimensions + : variable_dimension + { $$ = $1; } + | dimensions variable_dimension + { list *tmp = $1; + if ($2) { + tmp->splice(tmp->end(), *$2); + delete $2; + } + $$ = tmp; + } + ; + + /* The register_variable rule is matched only when I am parsing + variables in a "reg" definition. I therefore know that I am + creating registers and I do not need to let the containing rule + handle it. The register variable list simply packs them together + so that bit ranges can be assigned. */ +register_variable + : IDENTIFIER dimensions_opt + { perm_string name = lex_strings.make($1); + pform_makewire(@1, name, NetNet::REG, + NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0); + pform_set_reg_idx(name, $2); + $$ = $1; + } + | IDENTIFIER dimensions_opt '=' expression + { if (pform_peek_scope()->var_init_needs_explicit_lifetime() + && (var_lifetime == LexicalScope::INHERITED)) { + cerr << @3 << ": warning: Static variable initialization requires " + "explicit lifetime in this context." << endl; + warn_count += 1; + } + perm_string name = lex_strings.make($1); + pform_makewire(@1, name, NetNet::REG, + NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0); + pform_set_reg_idx(name, $2); + pform_make_var_init(@1, name, $4); + $$ = $1; + } + ; + +register_variable_list + : register_variable + { list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + $$ = tmp; + delete[]$1; + } + | register_variable_list ',' register_variable + { list*tmp = $1; + tmp->push_back(lex_strings.make($3)); + $$ = tmp; + delete[]$3; + } + ; + +net_variable + : IDENTIFIER dimensions_opt + { perm_string name = lex_strings.make($1); + pform_makewire(@1, name, NetNet::IMPLICIT, + NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0); + pform_set_reg_idx(name, $2); + $$ = $1; + } + ; + +net_variable_list + : net_variable + { list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + $$ = tmp; + delete[]$1; + } + | net_variable_list ',' net_variable + { list*tmp = $1; + tmp->push_back(lex_strings.make($3)); + $$ = tmp; + delete[]$3; + } + ; + +event_variable + : IDENTIFIER dimensions_opt + { if ($2) { + yyerror(@2, "sorry: event arrays are not supported."); + delete $2; + } + $$ = $1; + } + ; + +event_variable_list + : event_variable + { $$ = list_from_identifier($1); } + | event_variable_list ',' event_variable + { $$ = list_from_identifier($1, $3); } + ; + +specify_item + : K_specparam specparam_decl ';' + | specify_simple_path_decl ';' + { pform_module_specify_path($1); + } + | specify_edge_path_decl ';' + { pform_module_specify_path($1); + } + | K_if '(' expression ')' specify_simple_path_decl ';' + { PSpecPath*tmp = $5; + if (tmp) { + tmp->conditional = true; + tmp->condition = $3; + } + pform_module_specify_path(tmp); + } + | K_if '(' expression ')' specify_edge_path_decl ';' + { PSpecPath*tmp = $5; + if (tmp) { + tmp->conditional = true; + tmp->condition = $3; + } + pform_module_specify_path(tmp); + } + | K_ifnone specify_simple_path_decl ';' + { PSpecPath*tmp = $2; + if (tmp) { + tmp->conditional = true; + tmp->condition = 0; + } + pform_module_specify_path(tmp); + } + | K_ifnone specify_edge_path_decl ';' + { yyerror(@1, "Sorry: ifnone with an edge-sensitive path is " + "not supported."); + yyerrok; + } + | K_Sfullskew '(' spec_reference_event ',' spec_reference_event + ',' delay_value ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + delete $9; + } + | K_Shold '(' spec_reference_event ',' spec_reference_event + ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + } + | K_Snochange '(' spec_reference_event ',' spec_reference_event + ',' delay_value ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + delete $9; + } + | K_Speriod '(' spec_reference_event ',' delay_value + spec_notifier_opt ')' ';' + { delete $5; + } + | K_Srecovery '(' spec_reference_event ',' spec_reference_event + ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + } + | K_Srecrem '(' spec_reference_event ',' spec_reference_event + ',' delay_value ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + delete $9; + } + | K_Sremoval '(' spec_reference_event ',' spec_reference_event + ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + } + | K_Ssetup '(' spec_reference_event ',' spec_reference_event + ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + } + | K_Ssetuphold '(' spec_reference_event ',' spec_reference_event + ',' delay_value ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + delete $9; + } + | K_Sskew '(' spec_reference_event ',' spec_reference_event + ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + } + | K_Stimeskew '(' spec_reference_event ',' spec_reference_event + ',' delay_value spec_notifier_opt ')' ';' + { delete $7; + } + | K_Swidth '(' spec_reference_event ',' delay_value ',' expression + spec_notifier_opt ')' ';' + { delete $5; + delete $7; + } + | K_Swidth '(' spec_reference_event ',' delay_value ')' ';' + { delete $5; + } + | K_pulsestyle_onevent specify_path_identifiers ';' + { delete $2; + } + | K_pulsestyle_ondetect specify_path_identifiers ';' + { delete $2; + } + | K_showcancelled specify_path_identifiers ';' + { delete $2; + } + | K_noshowcancelled specify_path_identifiers ';' + { delete $2; + } + ; + +specify_item_list + : specify_item + | specify_item_list specify_item + ; + +specify_item_list_opt + : /* empty */ + { } + | specify_item_list + { } + +specify_edge_path_decl + : specify_edge_path '=' '(' delay_value_list ')' + { $$ = pform_assign_path_delay($1, $4); } + | specify_edge_path '=' delay_value_simple + { list*tmp = new list; + tmp->push_back($3); + $$ = pform_assign_path_delay($1, tmp); + } + ; + +edge_operator : K_posedge { $$ = true; } | K_negedge { $$ = false; } ; + +specify_edge_path + : '(' specify_path_identifiers spec_polarity + K_EG '(' specify_path_identifiers polarity_operator expression ')' ')' + { int edge_flag = 0; + $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, false, $6, $8); } + | '(' edge_operator specify_path_identifiers spec_polarity + K_EG '(' specify_path_identifiers polarity_operator expression ')' ')' + { int edge_flag = $2? 1 : -1; + $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, false, $7, $9);} + | '(' specify_path_identifiers spec_polarity + K_SG '(' specify_path_identifiers polarity_operator expression ')' ')' + { int edge_flag = 0; + $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, true, $6, $8); } + | '(' edge_operator specify_path_identifiers spec_polarity + K_SG '(' specify_path_identifiers polarity_operator expression ')' ')' + { int edge_flag = $2? 1 : -1; + $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, true, $7, $9); } + ; + +polarity_operator + : K_PO_POS + | K_PO_NEG + | ':' + ; + +specify_simple_path_decl + : specify_simple_path '=' '(' delay_value_list ')' + { $$ = pform_assign_path_delay($1, $4); } + | specify_simple_path '=' delay_value_simple + { list*tmp = new list; + tmp->push_back($3); + $$ = pform_assign_path_delay($1, tmp); + } + | specify_simple_path '=' '(' error ')' + { yyerror(@3, "Syntax error in delay value list."); + yyerrok; + $$ = 0; + } + ; + +specify_simple_path + : '(' specify_path_identifiers spec_polarity + K_EG specify_path_identifiers ')' + { $$ = pform_make_specify_path(@1, $2, $3, false, $5); } + | '(' specify_path_identifiers spec_polarity + K_SG specify_path_identifiers ')' + { $$ = pform_make_specify_path(@1, $2, $3, true, $5); } + | '(' error ')' + { yyerror(@1, "Invalid simple path"); + yyerrok; + } + ; + +specify_path_identifiers + : IDENTIFIER + { list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + $$ = tmp; + delete[]$1; + } + | IDENTIFIER '[' expr_primary ']' + { if (gn_specify_blocks_flag) { + yywarn(@4, "Bit selects are not currently supported " + "in path declarations. The declaration " + "will be applied to the whole vector."); + } + list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + $$ = tmp; + delete[]$1; + } + | IDENTIFIER '[' expr_primary polarity_operator expr_primary ']' + { if (gn_specify_blocks_flag) { + yywarn(@4, "Part selects are not currently supported " + "in path declarations. The declaration " + "will be applied to the whole vector."); + } + list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + $$ = tmp; + delete[]$1; + } + | specify_path_identifiers ',' IDENTIFIER + { list*tmp = $1; + tmp->push_back(lex_strings.make($3)); + $$ = tmp; + delete[]$3; + } + | specify_path_identifiers ',' IDENTIFIER '[' expr_primary ']' + { if (gn_specify_blocks_flag) { + yywarn(@4, "Bit selects are not currently supported " + "in path declarations. The declaration " + "will be applied to the whole vector."); + } + list*tmp = $1; + tmp->push_back(lex_strings.make($3)); + $$ = tmp; + delete[]$3; + } + | specify_path_identifiers ',' IDENTIFIER '[' expr_primary polarity_operator expr_primary ']' + { if (gn_specify_blocks_flag) { + yywarn(@4, "Part selects are not currently supported " + "in path declarations. The declaration " + "will be applied to the whole vector."); + } + list*tmp = $1; + tmp->push_back(lex_strings.make($3)); + $$ = tmp; + delete[]$3; + } + ; + +specparam + : IDENTIFIER '=' expression + { PExpr*tmp = $3; + pform_set_specparam(@1, lex_strings.make($1), + param_active_range, tmp); + delete[]$1; + } + | IDENTIFIER '=' expression ':' expression ':' expression + { PExpr*tmp = 0; + switch (min_typ_max_flag) { + case MIN: + tmp = $3; + delete $5; + delete $7; + break; + case TYP: + delete $3; + tmp = $5; + delete $7; + break; + case MAX: + delete $3; + delete $5; + tmp = $7; + break; + } + if (min_typ_max_warn > 0) { + cerr << tmp->get_fileline() << ": warning: choosing "; + switch (min_typ_max_flag) { + case MIN: + cerr << "min"; + break; + case TYP: + cerr << "typ"; + break; + case MAX: + cerr << "max"; + break; + } + cerr << " expression." << endl; + min_typ_max_warn -= 1; + } + pform_set_specparam(@1, lex_strings.make($1), + param_active_range, tmp); + delete[]$1; + } + | PATHPULSE_IDENTIFIER '=' expression + { delete[]$1; + delete $3; + } + | PATHPULSE_IDENTIFIER '=' '(' expression ',' expression ')' + { delete[]$1; + delete $4; + delete $6; + } + ; + +specparam_list + : specparam + | specparam_list ',' specparam + ; + +specparam_decl + : specparam_list + | dimensions + { param_active_range = $1; } + specparam_list + { param_active_range = 0; } + ; + +spec_polarity + : '+' { $$ = '+'; } + | '-' { $$ = '-'; } + | { $$ = 0; } + ; + +spec_reference_event + : K_posedge expression + { delete $2; } + | K_negedge expression + { delete $2; } + | K_posedge expr_primary K_TAND expression + { delete $2; + delete $4; + } + | K_negedge expr_primary K_TAND expression + { delete $2; + delete $4; + } + | K_edge '[' edge_descriptor_list ']' expr_primary + { delete $5; } + | K_edge '[' edge_descriptor_list ']' expr_primary K_TAND expression + { delete $5; + delete $7; + } + | expr_primary K_TAND expression + { delete $1; + delete $3; + } + | expr_primary + { delete $1; } + ; + + /* The edge_descriptor is detected by the lexor as the various + 2-letter edge sequences that are supported here. For now, we + don't care what they are, because we do not yet support specify + edge events. */ +edge_descriptor_list + : edge_descriptor_list ',' K_edge_descriptor + | K_edge_descriptor + ; + +spec_notifier_opt + : /* empty */ + { } + | spec_notifier + { } + ; +spec_notifier + : ',' + { args_after_notifier = 0; } + | ',' hierarchy_identifier + { args_after_notifier = 0; delete $2; } + | spec_notifier ',' + { args_after_notifier += 1; } + | spec_notifier ',' hierarchy_identifier + { args_after_notifier += 1; + if (args_after_notifier >= 3) { + cerr << @3 << ": warning: timing checks are not supported " + "and delayed signal \"" << *$3 + << "\" will not be driven." << endl; + } + delete $3; } + /* How do we match this path? */ + | IDENTIFIER + { args_after_notifier = 0; delete[]$1; } + ; + + +statement_item /* This is roughly statement_item in the LRM */ + + /* assign and deassign statements are procedural code to do + structural assignments, and to turn that structural assignment + off. This is stronger than any other assign, but weaker than the + force assignments. */ + + : K_assign lpvalue '=' expression ';' + { PCAssign*tmp = new PCAssign($2, $4); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + | K_deassign lpvalue ';' + { PDeassign*tmp = new PDeassign($2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + + /* Force and release statements are similar to assignments, + syntactically, but they will be elaborated differently. */ + + | K_force lpvalue '=' expression ';' + { PForce*tmp = new PForce($2, $4); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_release lpvalue ';' + { PRelease*tmp = new PRelease($2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + /* begin-end blocks come in a variety of forms, including named and + anonymous. The named blocks can also carry their own reg + variables, which are placed in the scope created by the block + name. These are handled by pushing the scope name, then matching + the declarations. The scope is popped at the end of the block. */ + + | K_begin K_end + { PBlock*tmp = new PBlock(PBlock::BL_SEQ); + FILE_NAME(tmp, @1); + $$ = tmp; + } + /* In SystemVerilog an unnamed block can contain variable declarations. */ + | K_begin + { PBlock*tmp = pform_push_block_scope(0, PBlock::BL_SEQ); + FILE_NAME(tmp, @1); + current_block_stack.push(tmp); + } + block_item_decls_opt + { if ($3) { + if (! gn_system_verilog()) { + yyerror("error: Variable declaration in unnamed block " + "requires SystemVerilog."); + } + } else { + /* If there are no declarations in the scope then just delete it. */ + pform_pop_scope(); + assert(! current_block_stack.empty()); + PBlock*tmp = current_block_stack.top(); + current_block_stack.pop(); + delete tmp; + } + } + statement_or_null_list K_end + { PBlock*tmp; + if ($3) { + pform_pop_scope(); + assert(! current_block_stack.empty()); + tmp = current_block_stack.top(); + current_block_stack.pop(); + } else { + tmp = new PBlock(PBlock::BL_SEQ); + FILE_NAME(tmp, @1); + } + if ($5) tmp->set_statement(*$5); + delete $5; + $$ = tmp; + } + | K_begin ':' IDENTIFIER + { PBlock*tmp = pform_push_block_scope($3, PBlock::BL_SEQ); + FILE_NAME(tmp, @1); + current_block_stack.push(tmp); + } + block_item_decls_opt + statement_or_null_list_opt K_end endlabel_opt + { pform_pop_scope(); + assert(! current_block_stack.empty()); + PBlock*tmp = current_block_stack.top(); + current_block_stack.pop(); + if ($6) tmp->set_statement(*$6); + delete $6; + if ($8) { + if (strcmp($3,$8) != 0) { + yyerror(@8, "error: End label doesn't match begin name"); + } + if (! gn_system_verilog()) { + yyerror(@8, "error: Begin end labels require " + "SystemVerilog."); + } + delete[]$8; + } + delete[]$3; + $$ = tmp; + } + + /* fork-join blocks are very similar to begin-end blocks. In fact, + from the parser's perspective there is no real difference. All we + need to do is remember that this is a parallel block so that the + code generator can do the right thing. */ + + | K_fork join_keyword + { PBlock*tmp = new PBlock($2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + /* In SystemVerilog an unnamed block can contain variable declarations. */ + | K_fork + { PBlock*tmp = pform_push_block_scope(0, PBlock::BL_PAR); + FILE_NAME(tmp, @1); + current_block_stack.push(tmp); + } + block_item_decls_opt + { if ($3) { + if (! gn_system_verilog()) { + yyerror("error: Variable declaration in unnamed block " + "requires SystemVerilog."); + } + } else { + /* If there are no declarations in the scope then just delete it. */ + pform_pop_scope(); + assert(! current_block_stack.empty()); + PBlock*tmp = current_block_stack.top(); + current_block_stack.pop(); + delete tmp; + } + } + statement_or_null_list join_keyword + { PBlock*tmp; + if ($3) { + pform_pop_scope(); + assert(! current_block_stack.empty()); + tmp = current_block_stack.top(); + current_block_stack.pop(); + tmp->set_join_type($6); + } else { + tmp = new PBlock($6); + FILE_NAME(tmp, @1); + } + if ($5) tmp->set_statement(*$5); + delete $5; + $$ = tmp; + } + | K_fork ':' IDENTIFIER + { PBlock*tmp = pform_push_block_scope($3, PBlock::BL_PAR); + FILE_NAME(tmp, @1); + current_block_stack.push(tmp); + } + block_item_decls_opt + statement_or_null_list_opt join_keyword endlabel_opt + { pform_pop_scope(); + assert(! current_block_stack.empty()); + PBlock*tmp = current_block_stack.top(); + current_block_stack.pop(); + tmp->set_join_type($7); + if ($6) tmp->set_statement(*$6); + delete $6; + if ($8) { + if (strcmp($3,$8) != 0) { + yyerror(@8, "error: End label doesn't match fork name"); + } + if (! gn_system_verilog()) { + yyerror(@8, "error: Fork end labels require " + "SystemVerilog."); + } + delete[]$8; + } + delete[]$3; + $$ = tmp; + } + + | K_disable hierarchy_identifier ';' + { PDisable*tmp = new PDisable(*$2); + FILE_NAME(tmp, @1); + delete $2; + $$ = tmp; + } + | K_disable K_fork ';' + { pform_name_t tmp_name; + PDisable*tmp = new PDisable(tmp_name); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_TRIGGER hierarchy_identifier ';' + { PTrigger*tmp = new PTrigger(*$2); + FILE_NAME(tmp, @1); + delete $2; + $$ = tmp; + } + + | procedural_assertion_statement { $$ = $1; } + + | loop_statement { $$ = $1; } + + | jump_statement { $$ = $1; } + + | K_case '(' expression ')' case_items K_endcase + { PCase*tmp = new PCase(NetCase::EQ, $3, $5); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_casex '(' expression ')' case_items K_endcase + { PCase*tmp = new PCase(NetCase::EQX, $3, $5); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_casez '(' expression ')' case_items K_endcase + { PCase*tmp = new PCase(NetCase::EQZ, $3, $5); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_case '(' expression ')' error K_endcase + { yyerrok; } + | K_casex '(' expression ')' error K_endcase + { yyerrok; } + | K_casez '(' expression ')' error K_endcase + { yyerrok; } + | K_if '(' expression ')' statement_or_null %prec less_than_K_else + { PCondit*tmp = new PCondit($3, $5, 0); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_if '(' expression ')' statement_or_null K_else statement_or_null + { PCondit*tmp = new PCondit($3, $5, $7); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | K_if '(' error ')' statement_or_null %prec less_than_K_else + { yyerror(@1, "error: Malformed conditional expression."); + $$ = $5; + } + | K_if '(' error ')' statement_or_null K_else statement_or_null + { yyerror(@1, "error: Malformed conditional expression."); + $$ = $5; + } + /* SystemVerilog adds the compressed_statement */ + + | compressed_statement ';' + { $$ = $1; } + + /* increment/decrement expressions can also be statements. When used + as statements, we can rewrite a++ as a += 1, and so on. */ + + | inc_or_dec_expression ';' + { $$ = pform_compressed_assign_from_inc_dec(@1, $1); } + + /* */ + + | delay1 statement_or_null + { PExpr*del = $1->front(); + assert($1->size() == 1); + delete $1; + PDelayStatement*tmp = new PDelayStatement(del, $2); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + | event_control statement_or_null + { PEventStatement*tmp = $1; + if (tmp == 0) { + yyerror(@1, "error: Invalid event control."); + $$ = 0; + } else { + tmp->set_statement($2); + $$ = tmp; + } + } + | '@' '*' statement_or_null + { PEventStatement*tmp = new PEventStatement; + FILE_NAME(tmp, @1); + tmp->set_statement($3); + $$ = tmp; + } + | '@' '(' '*' ')' statement_or_null + { PEventStatement*tmp = new PEventStatement; + FILE_NAME(tmp, @1); + tmp->set_statement($5); + $$ = tmp; + } + + /* Various assignment statements */ + + | lpvalue '=' expression ';' + { PAssign*tmp = new PAssign($1,$3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + | error '=' expression ';' + { yyerror(@2, "Syntax in assignment statement l-value."); + yyerrok; + $$ = new PNoop; + } + | lpvalue K_LE expression ';' + { PAssignNB*tmp = new PAssignNB($1,$3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | error K_LE expression ';' + { yyerror(@2, "Syntax in assignment statement l-value."); + yyerrok; + $$ = new PNoop; + } + | lpvalue '=' delay1 expression ';' + { PExpr*del = $3->front(); $3->pop_front(); + assert($3->empty()); + PAssign*tmp = new PAssign($1,del,$4); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_LE delay1 expression ';' + { PExpr*del = $3->front(); $3->pop_front(); + assert($3->empty()); + PAssignNB*tmp = new PAssignNB($1,del,$4); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue '=' event_control expression ';' + { PAssign*tmp = new PAssign($1,0,$3,$4); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue '=' K_repeat '(' expression ')' event_control expression ';' + { PAssign*tmp = new PAssign($1,$5,$7,$8); + FILE_NAME(tmp,@1); + tmp->set_lineno(@1.first_line); + $$ = tmp; + } + | lpvalue K_LE event_control expression ';' + { PAssignNB*tmp = new PAssignNB($1,0,$3,$4); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_LE K_repeat '(' expression ')' event_control expression ';' + { PAssignNB*tmp = new PAssignNB($1,$5,$7,$8); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + /* The IEEE1800 standard defines dynamic_array_new assignment as a + different rule from regular assignment. That implies that the + dynamic_array_new is not an expression in general, which makes + some sense. Elaboration should make sure the lpvalue is an array name. */ + + | lpvalue '=' dynamic_array_new ';' + { PAssign*tmp = new PAssign($1,$3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + /* The class new and dynamic array new expressions are special, so + sit in rules of their own. */ + + | lpvalue '=' class_new ';' + { PAssign*tmp = new PAssign($1,$3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + + | K_wait '(' expression ')' statement_or_null + { PEventStatement*tmp; + PEEvent*etmp = new PEEvent(PEEvent::POSITIVE, $3); + tmp = new PEventStatement(etmp); + FILE_NAME(tmp,@1); + tmp->set_statement($5); + $$ = tmp; + } + | K_wait K_fork ';' + { PEventStatement*tmp = new PEventStatement((PEEvent*)0); + FILE_NAME(tmp,@1); + $$ = tmp; + } + | SYSTEM_IDENTIFIER '(' expression_list_with_nuls ')' ';' + { PCallTask*tmp = new PCallTask(lex_strings.make($1), *$3); + FILE_NAME(tmp,@1); + delete[]$1; + delete $3; + $$ = tmp; + } + | SYSTEM_IDENTIFIER ';' + { listpt; + PCallTask*tmp = new PCallTask(lex_strings.make($1), pt); + FILE_NAME(tmp,@1); + delete[]$1; + $$ = tmp; + } + + | hierarchy_identifier '(' expression_list_with_nuls ')' ';' + { PCallTask*tmp = pform_make_call_task(@1, *$1, *$3); + delete $1; + delete $3; + $$ = tmp; + } + + | hierarchy_identifier K_with '{' constraint_block_item_list_opt '}' ';' + { /* ....randomize with { } */ + if ($1 && peek_tail_name(*$1) == "randomize") { + if (!gn_system_verilog()) + yyerror(@2, "error: Randomize with constraint requires SystemVerilog."); + else + yyerror(@2, "sorry: Randomize with constraint not supported."); + } else { + yyerror(@2, "error: Constraint block can only be applied to randomize method."); + } + listpt; + PCallTask*tmp = new PCallTask(*$1, pt); + FILE_NAME(tmp, @1); + delete $1; + $$ = tmp; + } + + | implicit_class_handle '.' hierarchy_identifier '(' expression_list_with_nuls ')' ';' + { pform_name_t*t_name = $1; + while (! $3->empty()) { + t_name->push_back($3->front()); + $3->pop_front(); + } + PCallTask*tmp = new PCallTask(*t_name, *$5); + FILE_NAME(tmp, @1); + delete $1; + delete $3; + delete $5; + $$ = tmp; + } + + | hierarchy_identifier ';' + { listpt; + PCallTask*tmp = pform_make_call_task(@1, *$1, pt); + delete $1; + $$ = tmp; + } + + /* IEEE1800 A.1.8: class_constructor_declaration with a call to + parent constructor. Note that the implicit_class_handle must + be K_super ("this.new" makes little sense) but that would + cause a conflict. Anyhow, this statement must be in the + beginning of a constructor, but let the elaborator figure that + out. */ + + | implicit_class_handle '.' K_new '(' expression_list_with_nuls ')' ';' + { PChainConstructor*tmp = new PChainConstructor(*$5); + FILE_NAME(tmp, @3); + delete $1; + $$ = tmp; + } + | hierarchy_identifier '(' error ')' ';' + { yyerror(@3, "error: Syntax error in task arguments."); + listpt; + PCallTask*tmp = pform_make_call_task(@1, *$1, pt); + delete $1; + $$ = tmp; + } + + | error ';' + { yyerror(@2, "error: malformed statement"); + yyerrok; + $$ = new PNoop; + } + + ; + +compressed_statement + : lpvalue K_PLUS_EQ expression + { PAssign*tmp = new PAssign($1, '+', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_MINUS_EQ expression + { PAssign*tmp = new PAssign($1, '-', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_MUL_EQ expression + { PAssign*tmp = new PAssign($1, '*', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_DIV_EQ expression + { PAssign*tmp = new PAssign($1, '/', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_MOD_EQ expression + { PAssign*tmp = new PAssign($1, '%', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_AND_EQ expression + { PAssign*tmp = new PAssign($1, '&', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_OR_EQ expression + { PAssign*tmp = new PAssign($1, '|', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_XOR_EQ expression + { PAssign*tmp = new PAssign($1, '^', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_LS_EQ expression + { PAssign *tmp = new PAssign($1, 'l', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_RS_EQ expression + { PAssign*tmp = new PAssign($1, 'r', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + | lpvalue K_RSS_EQ expression + { PAssign *tmp = new PAssign($1, 'R', $3); + FILE_NAME(tmp, @1); + $$ = tmp; + } + ; + + +statement_or_null_list_opt + : statement_or_null_list + { $$ = $1; } + | + { $$ = 0; } + ; + +statement_or_null_list + : statement_or_null_list statement_or_null + { vector*tmp = $1; + if ($2) tmp->push_back($2); + $$ = tmp; + } + | statement_or_null + { vector*tmp = new vector(0); + if ($1) tmp->push_back($1); + $$ = tmp; + } + ; + +analog_statement + : branch_probe_expression K_CONTRIBUTE expression ';' + { $$ = pform_contribution_statement(@2, $1, $3); } + ; + + /* Task items are, other than the statement, task port items and + other block items. */ +task_item + : block_item_decl { $$ = new vector(0); } + | tf_port_declaration { $$ = $1; } + ; + +task_item_list + : task_item_list task_item + { vector*tmp = $1; + size_t s1 = tmp->size(); + tmp->resize(s1 + $2->size()); + for (size_t idx = 0 ; idx < $2->size() ; idx += 1) + tmp->at(s1 + idx) = $2->at(idx); + delete $2; + $$ = tmp; + } + | task_item + { $$ = $1; } + ; + +task_item_list_opt + : task_item_list + { $$ = $1; } + | + { $$ = 0; } + ; + +tf_port_list_opt + : tf_port_list { $$ = $1; } + | { $$ = 0; } + ; + + /* Note that the lexor notices the "table" keyword and starts + the UDPTABLE state. It needs to happen there so that all the + characters in the table are interpreted in that mode. It is still + up to this rule to take us out of the UDPTABLE state. */ +udp_body + : K_table udp_entry_list K_endtable + { lex_end_table(); + $$ = $2; + } + | K_table K_endtable + { lex_end_table(); + yyerror(@1, "error: Empty UDP table."); + $$ = 0; + } + | K_table error K_endtable + { lex_end_table(); + yyerror(@2, "Errors in UDP table"); + yyerrok; + $$ = 0; + } + ; + +udp_entry_list + : udp_comb_entry_list + | udp_sequ_entry_list + ; + +udp_comb_entry + : udp_input_list ':' udp_output_sym ';' + { char*tmp = new char[strlen($1)+3]; + strcpy(tmp, $1); + char*tp = tmp+strlen(tmp); + *tp++ = ':'; + *tp++ = $3; + *tp++ = 0; + delete[]$1; + $$ = tmp; + } + ; + +udp_comb_entry_list + : udp_comb_entry + { list*tmp = new list; + tmp->push_back($1); + delete[]$1; + $$ = tmp; + } + | udp_comb_entry_list udp_comb_entry + { list*tmp = $1; + tmp->push_back($2); + delete[]$2; + $$ = tmp; + } + ; + +udp_sequ_entry_list + : udp_sequ_entry + { list*tmp = new list; + tmp->push_back($1); + delete[]$1; + $$ = tmp; + } + | udp_sequ_entry_list udp_sequ_entry + { list*tmp = $1; + tmp->push_back($2); + delete[]$2; + $$ = tmp; + } + ; + +udp_sequ_entry + : udp_input_list ':' udp_input_sym ':' udp_output_sym ';' + { char*tmp = new char[strlen($1)+5]; + strcpy(tmp, $1); + char*tp = tmp+strlen(tmp); + *tp++ = ':'; + *tp++ = $3; + *tp++ = ':'; + *tp++ = $5; + *tp++ = 0; + $$ = tmp; + } + ; + +udp_initial + : K_initial IDENTIFIER '=' number ';' + { PExpr*etmp = new PENumber($4); + PEIdent*itmp = new PEIdent(lex_strings.make($2)); + PAssign*atmp = new PAssign(itmp, etmp); + FILE_NAME(atmp, @2); + delete[]$2; + $$ = atmp; + } + ; + +udp_init_opt + : udp_initial { $$ = $1; } + | { $$ = 0; } + ; + +udp_input_list + : udp_input_sym + { char*tmp = new char[2]; + tmp[0] = $1; + tmp[1] = 0; + $$ = tmp; + } + | udp_input_list udp_input_sym + { char*tmp = new char[strlen($1)+2]; + strcpy(tmp, $1); + char*tp = tmp+strlen(tmp); + *tp++ = $2; + *tp++ = 0; + delete[]$1; + $$ = tmp; + } + ; + +udp_input_sym + : '0' { $$ = '0'; } + | '1' { $$ = '1'; } + | 'x' { $$ = 'x'; } + | '?' { $$ = '?'; } + | 'b' { $$ = 'b'; } + | '*' { $$ = '*'; } + | '%' { $$ = '%'; } + | 'f' { $$ = 'f'; } + | 'F' { $$ = 'F'; } + | 'l' { $$ = 'l'; } + | 'h' { $$ = 'h'; } + | 'B' { $$ = 'B'; } + | 'r' { $$ = 'r'; } + | 'R' { $$ = 'R'; } + | 'M' { $$ = 'M'; } + | 'n' { $$ = 'n'; } + | 'N' { $$ = 'N'; } + | 'p' { $$ = 'p'; } + | 'P' { $$ = 'P'; } + | 'Q' { $$ = 'Q'; } + | 'q' { $$ = 'q'; } + | '_' { $$ = '_'; } + | '+' { $$ = '+'; } + | DEC_NUMBER { yyerror(@1, "internal error: Input digits parse as decimal number!"); $$ = '0'; } + ; + +udp_output_sym + : '0' { $$ = '0'; } + | '1' { $$ = '1'; } + | 'x' { $$ = 'x'; } + | '-' { $$ = '-'; } + | DEC_NUMBER { yyerror(@1, "internal error: Output digits parse as decimal number!"); $$ = '0'; } + ; + + /* Port declarations create wires for the inputs and the output. The + makes for these ports are scoped within the UDP, so there is no + hierarchy involved. */ +udp_port_decl + : K_input list_of_identifiers ';' + { $$ = pform_make_udp_input_ports($2); } + | K_output IDENTIFIER ';' + { perm_string pname = lex_strings.make($2); + PWire*pp = new PWire(pname, NetNet::IMPLICIT, NetNet::POUTPUT, IVL_VT_LOGIC); + vector*tmp = new vector(1); + (*tmp)[0] = pp; + $$ = tmp; + delete[]$2; + } + | K_reg IDENTIFIER ';' + { perm_string pname = lex_strings.make($2); + PWire*pp = new PWire(pname, NetNet::REG, NetNet::PIMPLICIT, IVL_VT_LOGIC); + vector*tmp = new vector(1); + (*tmp)[0] = pp; + $$ = tmp; + delete[]$2; + } + | K_reg K_output IDENTIFIER ';' + { perm_string pname = lex_strings.make($3); + PWire*pp = new PWire(pname, NetNet::REG, NetNet::POUTPUT, IVL_VT_LOGIC); + vector*tmp = new vector(1); + (*tmp)[0] = pp; + $$ = tmp; + delete[]$3; + } + ; + +udp_port_decls + : udp_port_decl + { $$ = $1; } + | udp_port_decls udp_port_decl + { vector*tmp = $1; + size_t s1 = $1->size(); + tmp->resize(s1+$2->size()); + for (size_t idx = 0 ; idx < $2->size() ; idx += 1) + tmp->at(s1+idx) = $2->at(idx); + $$ = tmp; + delete $2; + } + ; + +udp_port_list + : IDENTIFIER + { list*tmp = new list; + tmp->push_back(lex_strings.make($1)); + delete[]$1; + $$ = tmp; + } + | udp_port_list ',' IDENTIFIER + { list*tmp = $1; + tmp->push_back(lex_strings.make($3)); + delete[]$3; + $$ = tmp; + } + ; + +udp_reg_opt: K_reg { $$ = true; } | { $$ = false; }; + +udp_initial_expr_opt + : '=' expression { $$ = $2; } + | { $$ = 0; } + ; + +udp_input_declaration_list + : K_input IDENTIFIER + { list*tmp = new list; + tmp->push_back(lex_strings.make($2)); + $$ = tmp; + delete[]$2; + } + | udp_input_declaration_list ',' K_input IDENTIFIER + { list*tmp = $1; + tmp->push_back(lex_strings.make($4)); + $$ = tmp; + delete[]$4; + } + ; + +udp_primitive + /* This is the syntax for primitives that uses the IEEE1364-1995 + format. The ports are simply names in the port list, and the + declarations are in the body. */ + + : K_primitive IDENTIFIER '(' udp_port_list ')' ';' + udp_port_decls + udp_init_opt + udp_body + K_endprimitive endlabel_opt + + { perm_string tmp2 = lex_strings.make($2); + pform_make_udp(tmp2, $4, $7, $9, $8, + @2.text, @2.first_line); + if ($11) { + if (strcmp($2,$11) != 0) { + yyerror(@11, "error: End label doesn't match " + "primitive name"); + } + if (! gn_system_verilog()) { + yyerror(@11, "error: Primitive end labels " + "require SystemVerilog."); + } + delete[]$11; + } + delete[]$2; + } + + /* This is the syntax for IEEE1364-2001 format definitions. The port + names and declarations are all in the parameter list. */ + + | K_primitive IDENTIFIER + '(' K_output udp_reg_opt IDENTIFIER udp_initial_expr_opt ',' + udp_input_declaration_list ')' ';' + udp_body + K_endprimitive endlabel_opt + + { perm_string tmp2 = lex_strings.make($2); + perm_string tmp6 = lex_strings.make($6); + pform_make_udp(tmp2, $5, tmp6, $7, $9, $12, + @2.text, @2.first_line); + if ($14) { + if (strcmp($2,$14) != 0) { + yyerror(@14, "error: End label doesn't match " + "primitive name"); + } + if (! gn_system_verilog()) { + yyerror(@14, "error: Primitive end labels " + "require SystemVerilog."); + } + delete[]$14; + } + delete[]$2; + delete[]$6; + } + ; + + /* Many keywords can be optional in the syntax, although their + presence is significant. This is a fairly common pattern so + collect those rules here. */ + +K_packed_opt : K_packed { $$ = true; } | { $$ = false; } ; +K_reg_opt : K_reg { $$ = true; } | { $$ = false; } ; +K_static_opt : K_static { $$ = true; } | { $$ = false; } ; +K_virtual_opt : K_virtual { $$ = true; } | { $$ = false; } ; diff --git a/parse_sv.py b/parse_sv.py new file mode 100644 index 0000000..8180231 --- /dev/null +++ b/parse_sv.py @@ -0,0 +1,8225 @@ +# %{ +# /* +# * Copyright (c) 1998-2017 Stephen Williams (steve@icarus.com) +# * Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com) +# * +# * This source code is free software; you can redistribute it +# * and/or modify it in source code form under the terms of the GNU +# * General Public License as published by the Free Software +# * Foundation; either version 2 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, write to the Free Software +# * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# */ +from ply import * + +#from parse_tokens import tokens +import lexor +tokens = lexor.tokens # list(set(lexor.tokens).union(set(tokens))) +literals = lexor.literals + +precedence = [\ + ('right', 'K_PLUS_EQ', 'K_MINUS_EQ', 'K_MUL_EQ', 'K_DIV_EQ', + 'K_MOD_EQ', 'K_AND_EQ', 'K_OR_EQ'), + ('right', 'K_XOR_EQ', 'K_LS_EQ', 'K_RS_EQ', 'K_RSS_EQ'), + ('right', '?', ':', 'K_inside'), + ('left', 'K_LOR'), + ('left', 'K_LAND'), + ('left', '|'), + ('left', '^', 'K_NXOR', 'K_NOR'), + ('left', '&', 'K_NAND'), + ('left', 'K_EQ', 'K_NE', 'K_CEQ', 'K_CNE', 'K_WEQ', 'K_WNE'), + ('left', 'K_GE', 'K_LE', '<', '>'), + ('left', 'K_LS', 'K_RS', 'K_RSS'), + ('left', '+', '-'), + ('left', '*', '/', '%'), + ('left', 'K_POW'), + ('left', 'UNARY_PREC'), + ('nonassoc', 'less_than_K_else'), + ('nonassoc', 'K_else'), + ('nonassoc', '('), + ('nonassoc', 'K_exclude'), + ('nonassoc', 'no_timeunits_declaration'), + ('nonassoc', 'one_timeunits_declaration'), + ('nonassoc', 'K_timeunit', 'K_timeprecision') + ] +() +# -------------- RULES ---------------- +() +#'''source_text : timeunits_declaration_opt _embed0_source_text description_list +def p_source_text(p): + '''source_text : timeunits_declaration_opt _embed0_source_text description_list + ''' + print(p) +() +def p__embed0_source_text(p): + '''_embed0_source_text : ''' + # { pform_set_scope_timescale(yyloc); } +() +def p_assertion_item_1(p): + '''assertion_item : concurrent_assertion_item ''' + print(p) +() +def p_assignment_pattern_1(p): + '''assignment_pattern : K_LP expression_list_proper '}' ''' + print(p) + # { PEAssignPattern*tmp = new PEAssignPattern(*$2); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_assignment_pattern_2(p): + '''assignment_pattern : K_LP '}' ''' + print(p) + # { PEAssignPattern*tmp = new PEAssignPattern; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_block_identifier_opt_1(p): + '''block_identifier_opt : IDENTIFIER ':' ''' + print(p) +() +def p_block_identifier_opt_2(p): + '''block_identifier_opt : ''' + print(p) +() +def p_class_declaration_1(p): + '''class_declaration : K_virtual_opt K_class lifetime_opt class_identifier class_declaration_extends_opt ';' _embed0_class_declaration class_items_opt K_endclass _embed1_class_declaration class_declaration_endlabel_opt ''' + print(p) + # { // Wrap up the class. + # if ($11 && $4 && $4->name != $11) { + # yyerror(@11, "error: Class end label doesn't match class name."); + # delete[]$11; + # } + # } +() +def p__embed0_class_declaration(p): + '''_embed0_class_declaration : ''' + # { pform_start_class_declaration(@2, $4, $5.type, $5.exprs, $3); } +() +def p__embed1_class_declaration(p): + '''_embed1_class_declaration : ''' + # { // Process a class. + # pform_end_class_declaration(@9); + # } +() +def p_class_constraint_1(p): + '''class_constraint : constraint_prototype ''' + print(p) +() +def p_class_constraint_2(p): + '''class_constraint : constraint_declaration ''' + print(p) +() +def p_class_identifier_1(p): + '''class_identifier : IDENTIFIER ''' + print(p) + # { // Create a synthetic typedef for the class name so that the + # // lexor detects the name as a type. + # perm_string name = lex_strings.make($1); + # class_type_t*tmp = new class_type_t(name); + # FILE_NAME(tmp, @1); + # pform_set_typedef(name, tmp, NULL); + # delete[]$1; + # $$ = tmp; + # } +() +def p_class_identifier_2(p): + '''class_identifier : TYPE_IDENTIFIER ''' + print(p) + # { class_type_t*tmp = dynamic_cast($1.type); + # if (tmp == 0) { + # yyerror(@1, "Type name \"%s\"is not a predeclared class name.", $1.text); + # } + # delete[]$1.text; + # $$ = tmp; + # } +() +def p_class_declaration_endlabel_opt_1(p): + '''class_declaration_endlabel_opt : ':' TYPE_IDENTIFIER ''' + print(p) + # { class_type_t*tmp = dynamic_cast ($2.type); + # if (tmp == 0) { + # yyerror(@2, "error: class declaration endlabel \"%s\" is not a class name\n", $2.text); + # $$ = 0; + # } else { + # $$ = strdupnew(tmp->name.str()); + # } + # delete[]$2.text; + # } +() +def p_class_declaration_endlabel_opt_2(p): + '''class_declaration_endlabel_opt : ':' IDENTIFIER ''' + print(p) + # { $$ = $2; } +() +def p_class_declaration_endlabel_opt_3(p): + '''class_declaration_endlabel_opt : ''' + print(p) + # { $$ = 0; } +() +def p_class_declaration_extends_opt_1(p): + '''class_declaration_extends_opt : K_extends TYPE_IDENTIFIER ''' + print(p) + # { $$.type = $2.type; + # $$.exprs= 0; + # delete[]$2.text; + # } +() +def p_class_declaration_extends_opt_2(p): + '''class_declaration_extends_opt : K_extends TYPE_IDENTIFIER '(' expression_list_with_nuls ')' ''' + print(p) + # { $$.type = $2.type; + # $$.exprs = $4; + # delete[]$2.text; + # } +() +def p_class_declaration_extends_opt_3(p): + '''class_declaration_extends_opt : ''' + print(p) + # { $$.type = 0; $$.exprs = 0; } +() +def p_class_items_opt_1(p): + '''class_items_opt : class_items ''' + print(p) +() +def p_class_items_opt_2(p): + '''class_items_opt : ''' + print(p) +() +def p_class_items_1(p): + '''class_items : class_items class_item ''' + print(p) +() +def p_class_items_2(p): + '''class_items : class_item ''' + print(p) +() +def p_class_item_1(p): + '''class_item : method_qualifier_opt K_function K_new _embed0_class_item '(' tf_port_list_opt ')' ';' function_item_list_opt statement_or_null_list_opt K_endfunction endnew_opt ''' + print(p) + # { current_function->set_ports($6); + # pform_set_constructor_return(current_function); + # pform_set_this_class(@3, current_function); + # current_function_set_statement(@3, $10); + # pform_pop_scope(); + # current_function = 0; + # } +() +def p_class_item_2(p): + '''class_item : property_qualifier_opt data_type list_of_variable_decl_assignments ';' ''' + print(p) + # { pform_class_property(@2, $1, $2, $3); } +() +def p_class_item_3(p): + '''class_item : K_const class_item_qualifier_opt data_type list_of_variable_decl_assignments ';' ''' + print(p) + # { pform_class_property(@1, $2 | property_qualifier_t::make_const(), $3, $4); } +() +def p_class_item_4(p): + '''class_item : method_qualifier_opt task_declaration ''' + print(p) + # { /* The task_declaration rule puts this into the class */ } +() +def p_class_item_5(p): + '''class_item : method_qualifier_opt function_declaration ''' + print(p) + # { /* The function_declaration rule puts this into the class */ } +() +def p_class_item_6(p): + '''class_item : K_extern method_qualifier_opt K_function K_new ';' ''' + print(p) + # { yyerror(@1, "sorry: External constructors are not yet supported."); } +() +def p_class_item_7(p): + '''class_item : K_extern method_qualifier_opt K_function K_new '(' tf_port_list_opt ')' ';' ''' + print(p) + # { yyerror(@1, "sorry: External constructors are not yet supported."); } +() +def p_class_item_8(p): + '''class_item : K_extern method_qualifier_opt K_function data_type_or_implicit_or_void IDENTIFIER ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $5; + # } +() +def p_class_item_9(p): + '''class_item : K_extern method_qualifier_opt K_function data_type_or_implicit_or_void IDENTIFIER '(' tf_port_list_opt ')' ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $5; + # } +() +def p_class_item_10(p): + '''class_item : K_extern method_qualifier_opt K_task IDENTIFIER ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $4; + # } +() +def p_class_item_11(p): + '''class_item : K_extern method_qualifier_opt K_task IDENTIFIER '(' tf_port_list_opt ')' ';' ''' + print(p) + # { yyerror(@1, "sorry: External methods are not yet supported."); + # delete[] $4; + # } +() +def p_class_item_12(p): + '''class_item : class_constraint ''' + print(p) +() +def p_class_item_13(p): + '''class_item : property_qualifier_opt data_type error ';' ''' + print(p) + # { yyerror(@3, "error: Errors in variable names after data type."); + # yyerrok; + # } +() +def p_class_item_14(p): + '''class_item : property_qualifier_opt IDENTIFIER error ';' ''' + print(p) + # { yyerror(@3, "error: %s doesn't name a type.", $2); + # yyerrok; + # } +() +def p_class_item_15(p): + '''class_item : method_qualifier_opt K_function K_new error K_endfunction endnew_opt ''' + print(p) + # { yyerror(@1, "error: I give up on this class constructor declaration."); + # yyerrok; + # } +() +def p_class_item_16(p): + '''class_item : error ';' ''' + print(p) + # { yyerror(@2, "error: invalid class item."); + # yyerrok; + # } +() +def p__embed0_class_item(p): + '''_embed0_class_item : ''' + # { assert(current_function==0); + # current_function = pform_push_constructor_scope(@3); + # } +() +def p_class_item_qualifier_1(p): + '''class_item_qualifier : K_static ''' + print(p) + # { $$ = property_qualifier_t::make_static(); } +() +def p_class_item_qualifier_2(p): + '''class_item_qualifier : K_protected ''' + print(p) + # { $$ = property_qualifier_t::make_protected(); } +() +def p_class_item_qualifier_3(p): + '''class_item_qualifier : K_local ''' + print(p) + # { $$ = property_qualifier_t::make_local(); } +() +def p_class_item_qualifier_list_1(p): + '''class_item_qualifier_list : class_item_qualifier_list class_item_qualifier ''' + print(p) + # { $$ = $1 | $2; } +() +def p_class_item_qualifier_list_2(p): + '''class_item_qualifier_list : class_item_qualifier ''' + print(p) + # { $$ = $1; } +() +def p_class_item_qualifier_opt_1(p): + '''class_item_qualifier_opt : class_item_qualifier_list ''' + print(p) + # { $$ = $1; } +() +def p_class_item_qualifier_opt_2(p): + '''class_item_qualifier_opt : ''' + print(p) + # { $$ = property_qualifier_t::make_none(); } +() +def p_class_new_1(p): + '''class_new : K_new '(' expression_list_with_nuls ')' ''' + print(p) + # { list*expr_list = $3; + # strip_tail_items(expr_list); + # PENewClass*tmp = new PENewClass(*expr_list); + # FILE_NAME(tmp, @1); + # delete $3; + # $$ = tmp; + # } +() +def p_class_new_2(p): + '''class_new : K_new hierarchy_identifier ''' + print(p) + # { PEIdent*tmpi = new PEIdent(*$2); + # FILE_NAME(tmpi, @2); + # PENewCopy*tmp = new PENewCopy(tmpi); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_class_new_3(p): + '''class_new : K_new ''' + print(p) + # { PENewClass*tmp = new PENewClass; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_concurrent_assertion_item_1(p): + '''concurrent_assertion_item : block_identifier_opt K_assert K_property '(' property_spec ')' statement_or_null ''' + print(p) + # { /* */ + # if (gn_assertions_flag) { + # yyerror(@2, "sorry: concurrent_assertion_item not supported." + # " Try -gno-assertion to turn this message off."); + # } + # } +() +def p_concurrent_assertion_item_2(p): + '''concurrent_assertion_item : block_identifier_opt K_assert K_property '(' error ')' statement_or_null ''' + print(p) + # { yyerrok; + # yyerror(@2, "error: Error in property_spec of concurrent assertion item."); + # } +() +def p_constraint_block_item_1(p): + '''constraint_block_item : constraint_expression ''' + print(p) +() +def p_constraint_block_item_list_1(p): + '''constraint_block_item_list : constraint_block_item_list constraint_block_item ''' + print(p) +() +def p_constraint_block_item_list_2(p): + '''constraint_block_item_list : constraint_block_item ''' + print(p) +() +def p_constraint_block_item_list_opt_1(p): + '''constraint_block_item_list_opt : ''' + print(p) +() +def p_constraint_block_item_list_opt_2(p): + '''constraint_block_item_list_opt : constraint_block_item_list ''' + print(p) +() +def p_constraint_declaration_1(p): + '''constraint_declaration : K_static_opt K_constraint IDENTIFIER '{' constraint_block_item_list_opt '}' ''' + print(p) + # { yyerror(@2, "sorry: Constraint declarations not supported."); } +() +def p_constraint_declaration_2(p): + '''constraint_declaration : K_static_opt K_constraint IDENTIFIER '{' error '}' ''' + print(p) + # { yyerror(@4, "error: Errors in the constraint block item list."); } +() +def p_constraint_expression_1(p): + '''constraint_expression : expression ';' ''' + print(p) +() +def p_constraint_expression_2(p): + '''constraint_expression : expression K_dist '{' '}' ';' ''' + print(p) +() +def p_constraint_expression_3(p): + '''constraint_expression : expression K_TRIGGER constraint_set ''' + print(p) +() +def p_constraint_expression_4(p): + '''constraint_expression : K_if '(' expression ')' constraint_set %prec less_than_K_else ''' + print(p) +() +def p_constraint_expression_5(p): + '''constraint_expression : K_if '(' expression ')' constraint_set K_else constraint_set ''' + print(p) +() +def p_constraint_expression_6(p): + '''constraint_expression : K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' constraint_set ''' + print(p) +() +def p_constraint_expression_list_1(p): + '''constraint_expression_list : constraint_expression_list constraint_expression ''' + print(p) +() +def p_constraint_expression_list_2(p): + '''constraint_expression_list : constraint_expression ''' + print(p) +() +def p_constraint_prototype_1(p): + '''constraint_prototype : K_static_opt K_constraint IDENTIFIER ';' ''' + print(p) + # { yyerror(@2, "sorry: Constraint prototypes not supported."); } +() +def p_constraint_set_1(p): + '''constraint_set : constraint_expression ''' + print(p) +() +def p_constraint_set_2(p): + '''constraint_set : '{' constraint_expression_list '}' ''' + print(p) +() +def p_data_declaration_1(p): + '''data_declaration : attribute_list_opt data_type_or_implicit list_of_variable_decl_assignments ';' ''' + print(p) + # { data_type_t*data_type = $2; + # if (data_type == 0) { + # data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + # FILE_NAME(data_type, @2); + # } + # pform_makewire(@2, 0, str_strength, $3, NetNet::IMPLICIT_REG, data_type); + # } +() +def p_data_type_1(p): + '''data_type : integer_vector_type unsigned_signed_opt dimensions_opt ''' + print(p) + # { ivl_variable_type_t use_vtype = $1; + # bool reg_flag = false; + # if (use_vtype == IVL_VT_NO_TYPE) { + # use_vtype = IVL_VT_LOGIC; + # reg_flag = true; + # } + # vector_type_t*tmp = new vector_type_t(use_vtype, $2, $3); + # tmp->reg_flag = reg_flag; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_2(p): + '''data_type : non_integer_type ''' + print(p) + # { real_type_t*tmp = new real_type_t($1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_3(p): + '''data_type : struct_data_type ''' + print(p) + # { if (!$1->packed_flag) { + # yyerror(@1, "sorry: Unpacked structs not supported."); + # } + # $$ = $1; + # } +() +def p_data_type_4(p): + '''data_type : enum_data_type ''' + print(p) + # { $$ = $1; } +() +def p_data_type_5(p): + '''data_type : atom2_type signed_unsigned_opt ''' + print(p) + # { atom2_type_t*tmp = new atom2_type_t($1, $2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_6(p): + '''data_type : K_integer signed_unsigned_opt ''' + print(p) + # { list*pd = make_range_from_width(integer_width); + # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $2, pd); + # tmp->reg_flag = true; + # tmp->integer_flag = true; + # $$ = tmp; + # } +() +def p_data_type_7(p): + '''data_type : K_time ''' + print(p) + # { list*pd = make_range_from_width(64); + # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, pd); + # tmp->reg_flag = !gn_system_verilog(); + # $$ = tmp; + # } +() +def p_data_type_8(p): + '''data_type : TYPE_IDENTIFIER dimensions_opt ''' + print(p) + # { if ($2) { + # parray_type_t*tmp = new parray_type_t($1.type, $2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } else $$ = $1.type; + # delete[]$1.text; + # } +() +def p_data_type_9(p): + '''data_type : PACKAGE_IDENTIFIER K_SCOPE_RES _embed0_data_type TYPE_IDENTIFIER ''' + print(p) + # { lex_in_package_scope(0); + # $$ = $4.type; + # delete[]$4.text; + # } +() +def p_data_type_10(p): + '''data_type : K_string ''' + print(p) + # { string_type_t*tmp = new string_type_t; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p__embed0_data_type(p): + '''_embed0_data_type : ''' + # { lex_in_package_scope($1); } +() +def p_data_type_or_implicit_1(p): + '''data_type_or_implicit : data_type ''' + print(p) + # { $$ = $1; } +() +def p_data_type_or_implicit_2(p): + '''data_type_or_implicit : signing dimensions_opt ''' + print(p) + # { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, $1, $2); + # tmp->implicit_flag = true; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_or_implicit_3(p): + '''data_type_or_implicit : dimensions ''' + print(p) + # { vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, $1); + # tmp->implicit_flag = true; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_data_type_or_implicit_4(p): + '''data_type_or_implicit : ''' + print(p) + # { $$ = 0; } +() +def p_data_type_or_implicit_or_void_1(p): + '''data_type_or_implicit_or_void : data_type_or_implicit ''' + print(p) + # { $$ = $1; } +() +def p_data_type_or_implicit_or_void_2(p): + '''data_type_or_implicit_or_void : K_void ''' + print(p) + # { void_type_t*tmp = new void_type_t; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_description_1(p): + '''description : module ''' + print(p) +() +def p_description_2(p): + '''description : udp_primitive ''' + print(p) +() +def p_description_3(p): + '''description : config_declaration ''' + print(p) +() +def p_description_4(p): + '''description : nature_declaration ''' + print(p) +() +def p_description_5(p): + '''description : package_declaration ''' + print(p) +() +def p_description_6(p): + '''description : discipline_declaration ''' + print(p) +() +def p_description_7(p): + '''description : package_item ''' + print(p) +() +def p_description_8(p): + '''description : KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ''' + print(p) + # { perm_string tmp3 = lex_strings.make($3); + # pform_set_type_attrib(tmp3, $5, $7); + # delete[] $3; + # delete[] $5; + # } +() +def p_description_list_1(p): + '''description_list : description ''' + print(p) +() +def p_description_list_2(p): + '''description_list : description_list description ''' + print(p) +() +def p_endnew_opt_1(p): + '''endnew_opt : ':' K_new ''' + print(p) +() +def p_endnew_opt_2(p): + '''endnew_opt : ''' + print(p) +() +def p_dynamic_array_new_1(p): + '''dynamic_array_new : K_new '[' expression ']' ''' + print(p) + # { $$ = new PENewArray($3, 0); + # FILE_NAME($$, @1); + # } +() +def p_dynamic_array_new_2(p): + '''dynamic_array_new : K_new '[' expression ']' '(' expression ')' ''' + print(p) + # { $$ = new PENewArray($3, $6); + # FILE_NAME($$, @1); + # } +() +def p_for_step_1(p): + '''for_step : lpvalue '=' expression ''' + print(p) + # { PAssign*tmp = new PAssign($1,$3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_for_step_2(p): + '''for_step : inc_or_dec_expression ''' + print(p) + # { $$ = pform_compressed_assign_from_inc_dec(@1, $1); } +() +def p_for_step_3(p): + '''for_step : compressed_statement ''' + print(p) + # { $$ = $1; } +() +def p_function_declaration_1(p): + '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER ';' _embed0_function_declaration function_item_list statement_or_null_list_opt K_endfunction _embed1_function_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. + # if ($11) { + # if (strcmp($4,$11) != 0) { + # yyerror(@11, "error: End label doesn't match " + # "function name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@11, "error: Function end labels require " + # "SystemVerilog."); + # } + # delete[]$11; + # } + # delete[]$4; + # } +() +def p_function_declaration_2(p): + '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER _embed2_function_declaration '(' tf_port_list_opt ')' ';' block_item_decls_opt statement_or_null_list_opt K_endfunction _embed3_function_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. + # if ($14) { + # if (strcmp($4,$14) != 0) { + # yyerror(@14, "error: End label doesn't match " + # "function name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@14, "error: Function end labels require " + # "SystemVerilog."); + # } + # delete[]$14; + # } + # delete[]$4; + # } +() +def p_function_declaration_3(p): + '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER error K_endfunction _embed4_function_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. + # if ($8) { + # if (strcmp($4,$8) != 0) { + # yyerror(@8, "error: End label doesn't match function name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@8, "error: Function end labels require " + # "SystemVerilog."); + # } + # delete[]$8; + # } + # delete[]$4; + # } +() +def p__embed0_function_declaration(p): + '''_embed0_function_declaration : ''' + # { assert(current_function == 0); + # current_function = pform_push_function_scope(@1, $4, $2); + # } +() +def p__embed1_function_declaration(p): + '''_embed1_function_declaration : ''' + # { current_function->set_ports($7); + # current_function->set_return($3); + # current_function_set_statement($8? @8 : @4, $8); + # pform_set_this_class(@4, current_function); + # pform_pop_scope(); + # current_function = 0; + # } +() +def p__embed2_function_declaration(p): + '''_embed2_function_declaration : ''' + # { assert(current_function == 0); + # current_function = pform_push_function_scope(@1, $4, $2); + # } +() +def p__embed3_function_declaration(p): + '''_embed3_function_declaration : ''' + # { current_function->set_ports($7); + # current_function->set_return($3); + # current_function_set_statement($11? @11 : @4, $11); + # pform_set_this_class(@4, current_function); + # pform_pop_scope(); + # current_function = 0; + # if ($7==0 && !gn_system_verilog()) { + # yyerror(@4, "error: Empty parenthesis syntax requires SystemVerilog."); + # } + # } +() +def p__embed4_function_declaration(p): + '''_embed4_function_declaration : ''' + # { /* */ + # if (current_function) { + # pform_pop_scope(); + # current_function = 0; + # } + # assert(current_function == 0); + # yyerror(@1, "error: Syntax error defining function."); + # yyerrok; + # } +() +def p_import_export_1(p): + '''import_export : K_import ''' + print(p) + # { $$ = true; } +() +def p_import_export_2(p): + '''import_export : K_export ''' + print(p) + # { $$ = false; } +() +def p_implicit_class_handle_1(p): + '''implicit_class_handle : K_this ''' + print(p) + # { $$ = pform_create_this(); } +() +def p_implicit_class_handle_2(p): + '''implicit_class_handle : K_super ''' + print(p) + # { $$ = pform_create_super(); } +() +def p_inc_or_dec_expression_1(p): + '''inc_or_dec_expression : K_INCR lpvalue %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('I', $2); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_inc_or_dec_expression_2(p): + '''inc_or_dec_expression : lpvalue K_INCR %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('i', $1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_inc_or_dec_expression_3(p): + '''inc_or_dec_expression : K_DECR lpvalue %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('D', $2); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_inc_or_dec_expression_4(p): + '''inc_or_dec_expression : lpvalue K_DECR %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('d', $1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_inside_expression_1(p): + '''inside_expression : expression K_inside '{' open_range_list '}' ''' + print(p) + # { yyerror(@2, "sorry: \"inside\" expressions not supported yet."); + # $$ = 0; + # } +() +def p_integer_vector_type_1(p): + '''integer_vector_type : K_reg ''' + print(p) + # { $$ = IVL_VT_NO_TYPE; } +() +def p_integer_vector_type_2(p): + '''integer_vector_type : K_bit ''' + print(p) + # { $$ = IVL_VT_BOOL; } +() +def p_integer_vector_type_3(p): + '''integer_vector_type : K_logic ''' + print(p) + # { $$ = IVL_VT_LOGIC; } +() +def p_integer_vector_type_4(p): + '''integer_vector_type : K_bool ''' + print(p) + # { $$ = IVL_VT_BOOL; } +() +def p_join_keyword_1(p): + '''join_keyword : K_join ''' + print(p) + # { $$ = PBlock::BL_PAR; } +() +def p_join_keyword_2(p): + '''join_keyword : K_join_none ''' + print(p) + # { $$ = PBlock::BL_JOIN_NONE; } +() +def p_join_keyword_3(p): + '''join_keyword : K_join_any ''' + print(p) + # { $$ = PBlock::BL_JOIN_ANY; } +() +def p_jump_statement_1(p): + '''jump_statement : K_break ';' ''' + print(p) + # { yyerror(@1, "sorry: break statements not supported."); + # $$ = 0; + # } +() +def p_jump_statement_2(p): + '''jump_statement : K_return ';' ''' + print(p) + # { PReturn*tmp = new PReturn(0); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_jump_statement_3(p): + '''jump_statement : K_return expression ';' ''' + print(p) + # { PReturn*tmp = new PReturn($2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_lifetime_1(p): + '''lifetime : K_automatic ''' + print(p) + # { $$ = LexicalScope::AUTOMATIC; } +() +def p_lifetime_2(p): + '''lifetime : K_static ''' + print(p) + # { $$ = LexicalScope::STATIC; } +() +def p_lifetime_opt_1(p): + '''lifetime_opt : lifetime ''' + print(p) + # { $$ = $1; } +() +def p_lifetime_opt_2(p): + '''lifetime_opt : ''' + print(p) + # { $$ = LexicalScope::INHERITED; } +() +def p_loop_statement_1(p): + '''loop_statement : K_for '(' lpvalue '=' expression ';' expression ';' for_step ')' statement_or_null ''' + print(p) + # { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_2(p): + '''loop_statement : K_for '(' data_type IDENTIFIER '=' expression ';' expression ';' for_step ')' _embed0_loop_statement statement_or_null ''' + print(p) + # { pform_name_t tmp_hident; + # tmp_hident.push_back(name_component_t(lex_strings.make($4))); + # + # PEIdent*tmp_ident = pform_new_ident(tmp_hident); + # FILE_NAME(tmp_ident, @4); + # + # PForStatement*tmp_for = new PForStatement(tmp_ident, $6, $8, $10, $13); + # FILE_NAME(tmp_for, @1); + # + # pform_pop_scope(); + # vectortmp_for_list (1); + # tmp_for_list[0] = tmp_for; + # PBlock*tmp_blk = current_block_stack.top(); + # current_block_stack.pop(); + # tmp_blk->set_statement(tmp_for_list); + # $$ = tmp_blk; + # delete[]$4; + # } +() +def p_loop_statement_3(p): + '''loop_statement : K_forever statement_or_null ''' + print(p) + # { PForever*tmp = new PForever($2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_4(p): + '''loop_statement : K_repeat '(' expression ')' statement_or_null ''' + print(p) + # { PRepeat*tmp = new PRepeat($3, $5); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_5(p): + '''loop_statement : K_while '(' expression ')' statement_or_null ''' + print(p) + # { PWhile*tmp = new PWhile($3, $5); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_6(p): + '''loop_statement : K_do statement_or_null K_while '(' expression ')' ';' ''' + print(p) + # { PDoWhile*tmp = new PDoWhile($5, $2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_loop_statement_7(p): + '''loop_statement : K_foreach '(' IDENTIFIER '[' loop_variables ']' ')' _embed1_loop_statement statement_or_null ''' + print(p) + # { PForeach*tmp_for = pform_make_foreach(@1, $3, $5, $9); + # + # pform_pop_scope(); + # vectortmp_for_list(1); + # tmp_for_list[0] = tmp_for; + # PBlock*tmp_blk = current_block_stack.top(); + # current_block_stack.pop(); + # tmp_blk->set_statement(tmp_for_list); + # $$ = tmp_blk; + # } +() +def p_loop_statement_8(p): + '''loop_statement : K_for '(' lpvalue '=' expression ';' expression ';' error ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in for loop step assignment."); + # } +() +def p_loop_statement_9(p): + '''loop_statement : K_for '(' lpvalue '=' expression ';' error ';' for_step ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in for loop condition expression."); + # } +() +def p_loop_statement_10(p): + '''loop_statement : K_for '(' error ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Incomprehensible for loop."); + # } +() +def p_loop_statement_11(p): + '''loop_statement : K_while '(' error ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in while loop condition."); + # } +() +def p_loop_statement_12(p): + '''loop_statement : K_do statement_or_null K_while '(' error ')' ';' ''' + print(p) + # { $$ = 0; + # yyerror(@1, "error: Error in do/while loop condition."); + # } +() +def p_loop_statement_13(p): + '''loop_statement : K_foreach '(' IDENTIFIER '[' error ']' ')' statement_or_null ''' + print(p) + # { $$ = 0; + # yyerror(@4, "error: Errors in foreach loop variables list."); + # } +() +def p__embed0_loop_statement(p): + '''_embed0_loop_statement : ''' + # { static unsigned for_counter = 0; + # char for_block_name [64]; + # snprintf(for_block_name, sizeof for_block_name, "$ivl_for_loop%u", for_counter); + # for_counter += 1; + # PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # + # listassign_list; + # decl_assignment_t*tmp_assign = new decl_assignment_t; + # tmp_assign->name = lex_strings.make($4); + # assign_list.push_back(tmp_assign); + # pform_makewire(@4, 0, str_strength, &assign_list, NetNet::REG, $3); + # } +() +def p__embed1_loop_statement(p): + '''_embed1_loop_statement : ''' + # { static unsigned foreach_counter = 0; + # char for_block_name[64]; + # snprintf(for_block_name, sizeof for_block_name, "$ivl_foreach%u", foreach_counter); + # foreach_counter += 1; + # + # PBlock*tmp = pform_push_block_scope(for_block_name, PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # + # pform_make_foreach_declarations(@1, $5); + # } +() +def p_list_of_variable_decl_assignments_1(p): + '''list_of_variable_decl_assignments : variable_decl_assignment ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # $$ = tmp; + # } +() +def p_list_of_variable_decl_assignments_2(p): + '''list_of_variable_decl_assignments : list_of_variable_decl_assignments ',' variable_decl_assignment ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_variable_decl_assignment_1(p): + '''variable_decl_assignment : IDENTIFIER dimensions_opt ''' + print(p) + # { decl_assignment_t*tmp = new decl_assignment_t; + # tmp->name = lex_strings.make($1); + # if ($2) { + # tmp->index = *$2; + # delete $2; + # } + # delete[]$1; + # $$ = tmp; + # } +() +def p_variable_decl_assignment_2(p): + '''variable_decl_assignment : IDENTIFIER '=' expression ''' + print(p) + # { decl_assignment_t*tmp = new decl_assignment_t; + # tmp->name = lex_strings.make($1); + # tmp->expr .reset($3); + # delete[]$1; + # $$ = tmp; + # } +() +def p_variable_decl_assignment_3(p): + '''variable_decl_assignment : IDENTIFIER '=' K_new '(' ')' ''' + print(p) + # { decl_assignment_t*tmp = new decl_assignment_t; + # tmp->name = lex_strings.make($1); + # PENewClass*expr = new PENewClass; + # FILE_NAME(expr, @3); + # tmp->expr .reset(expr); + # delete[]$1; + # $$ = tmp; + # } +() +def p_loop_variables_1(p): + '''loop_variables : loop_variables ',' IDENTIFIER ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # delete[]$3; + # $$ = tmp; + # } +() +def p_loop_variables_2(p): + '''loop_variables : IDENTIFIER ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # delete[]$1; + # $$ = tmp; + # } +() +def p_method_qualifier_1(p): + '''method_qualifier : K_virtual ''' + print(p) +() +def p_method_qualifier_2(p): + '''method_qualifier : class_item_qualifier ''' + print(p) +() +def p_method_qualifier_opt_1(p): + '''method_qualifier_opt : method_qualifier ''' + print(p) +() +def p_method_qualifier_opt_2(p): + '''method_qualifier_opt : ''' + print(p) +() +def p_modport_declaration_1(p): + '''modport_declaration : K_modport _embed0_modport_declaration modport_item_list ';' ''' + print(p) +() +def p__embed0_modport_declaration(p): + '''_embed0_modport_declaration : ''' + # { if (!pform_in_interface()) + # yyerror(@1, "error: modport declarations are only allowed " + # "in interfaces."); + # } +() +def p_modport_item_list_1(p): + '''modport_item_list : modport_item ''' + print(p) +() +def p_modport_item_list_2(p): + '''modport_item_list : modport_item_list ',' modport_item ''' + print(p) +() +def p_modport_item_1(p): + '''modport_item : IDENTIFIER _embed0_modport_item '(' modport_ports_list ')' ''' + print(p) + # { pform_end_modport_item(@1); } +() +def p__embed0_modport_item(p): + '''_embed0_modport_item : ''' + # { pform_start_modport_item(@1, $1); } +() +def p_modport_ports_list_1(p): + '''modport_ports_list : modport_ports_declaration ''' + print(p) +() +def p_modport_ports_list_2(p): + '''modport_ports_list : modport_ports_list ',' modport_ports_declaration ''' + print(p) +() +def p_modport_ports_list_3(p): + '''modport_ports_list : modport_ports_list ',' modport_simple_port ''' + print(p) + # { if (last_modport_port.type == MP_SIMPLE) { + # pform_add_modport_port(@3, last_modport_port.direction, + # $3->name, $3->parm); + # } else { + # yyerror(@3, "error: modport expression not allowed here."); + # } + # delete $3; + # } +() +def p_modport_ports_list_4(p): + '''modport_ports_list : modport_ports_list ',' modport_tf_port ''' + print(p) + # { if (last_modport_port.type != MP_TF) + # yyerror(@3, "error: task/function declaration not allowed here."); + # } +() +def p_modport_ports_list_5(p): + '''modport_ports_list : modport_ports_list ',' IDENTIFIER ''' + print(p) + # { if (last_modport_port.type == MP_SIMPLE) { + # pform_add_modport_port(@3, last_modport_port.direction, + # lex_strings.make($3), 0); + # } else if (last_modport_port.type != MP_TF) { + # yyerror(@3, "error: list of identifiers not allowed here."); + # } + # delete[] $3; + # } +() +def p_modport_ports_list_6(p): + '''modport_ports_list : modport_ports_list ',' ''' + print(p) + # { yyerror(@2, "error: NULL port declarations are not allowed"); } +() +def p_modport_ports_declaration_1(p): + '''modport_ports_declaration : attribute_list_opt port_direction IDENTIFIER ''' + print(p) + # { last_modport_port.type = MP_SIMPLE; + # last_modport_port.direction = $2; + # pform_add_modport_port(@3, $2, lex_strings.make($3), 0); + # delete[] $3; + # delete $1; + # } +() +def p_modport_ports_declaration_2(p): + '''modport_ports_declaration : attribute_list_opt port_direction modport_simple_port ''' + print(p) + # { last_modport_port.type = MP_SIMPLE; + # last_modport_port.direction = $2; + # pform_add_modport_port(@3, $2, $3->name, $3->parm); + # delete $3; + # delete $1; + # } +() +def p_modport_ports_declaration_3(p): + '''modport_ports_declaration : attribute_list_opt import_export IDENTIFIER ''' + print(p) + # { last_modport_port.type = MP_TF; + # last_modport_port.is_import = $2; + # yyerror(@3, "sorry: modport task/function ports are not yet supported."); + # delete[] $3; + # delete $1; + # } +() +def p_modport_ports_declaration_4(p): + '''modport_ports_declaration : attribute_list_opt import_export modport_tf_port ''' + print(p) + # { last_modport_port.type = MP_TF; + # last_modport_port.is_import = $2; + # yyerror(@3, "sorry: modport task/function ports are not yet supported."); + # delete $1; + # } +() +def p_modport_ports_declaration_5(p): + '''modport_ports_declaration : attribute_list_opt K_clocking IDENTIFIER ''' + print(p) + # { last_modport_port.type = MP_CLOCKING; + # last_modport_port.direction = NetNet::NOT_A_PORT; + # yyerror(@3, "sorry: modport clocking declaration is not yet supported."); + # delete[] $3; + # delete $1; + # } +() +def p_modport_simple_port_1(p): + '''modport_simple_port : '.' IDENTIFIER '(' expression ')' ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($2); + # tmp->parm = $4; + # delete[]$2; + # $$ = tmp; + # } +() +def p_modport_tf_port_1(p): + '''modport_tf_port : K_task IDENTIFIER ''' + print(p) +() +def p_modport_tf_port_2(p): + '''modport_tf_port : K_task IDENTIFIER '(' tf_port_list_opt ')' ''' + print(p) +() +def p_modport_tf_port_3(p): + '''modport_tf_port : K_function data_type_or_implicit_or_void IDENTIFIER ''' + print(p) +() +def p_modport_tf_port_4(p): + '''modport_tf_port : K_function data_type_or_implicit_or_void IDENTIFIER '(' tf_port_list_opt ')' ''' + print(p) +() +def p_non_integer_type_1(p): + '''non_integer_type : K_real ''' + print(p) + # { $$ = real_type_t::REAL; } +() +def p_non_integer_type_2(p): + '''non_integer_type : K_realtime ''' + print(p) + # { $$ = real_type_t::REAL; } +() +def p_non_integer_type_3(p): + '''non_integer_type : K_shortreal ''' + print(p) + # { $$ = real_type_t::SHORTREAL; } +() +def p_number_1(p): + '''number : BASED_NUMBER ''' + print(p) + # { $$ = $1; based_size = 0;} +() +def p_number_2(p): + '''number : DEC_NUMBER ''' + print(p) + # { $$ = $1; based_size = 0;} +() +def p_number_3(p): + '''number : DEC_NUMBER BASED_NUMBER ''' + print(p) + # { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line); + # based_size = 0; } +() +def p_number_4(p): + '''number : UNBASED_NUMBER ''' + print(p) + # { $$ = $1; based_size = 0;} +() +def p_number_5(p): + '''number : DEC_NUMBER UNBASED_NUMBER ''' + print(p) + # { yyerror(@1, "error: Unbased SystemVerilog literal cannot have " + # "a size."); + # $$ = $1; based_size = 0;} +() +def p_open_range_list_1(p): + '''open_range_list : open_range_list ',' value_range ''' + print(p) +() +def p_open_range_list_2(p): + '''open_range_list : value_range ''' + print(p) +() +def p_package_declaration_1(p): + '''package_declaration : K_package lifetime_opt IDENTIFIER ';' _embed0_package_declaration timeunits_declaration_opt _embed1_package_declaration package_item_list_opt K_endpackage endlabel_opt ''' + print(p) + # { pform_end_package_declaration(@1); + # // If an end label is present make sure it match the package name. + # if ($10) { + # if (strcmp($3,$10) != 0) { + # yyerror(@10, "error: End label doesn't match package name"); + # } + # delete[]$10; + # } + # delete[]$3; + # } +() +def p__embed0_package_declaration(p): + '''_embed0_package_declaration : ''' + # { pform_start_package_declaration(@1, $3, $2); } +() +def p__embed1_package_declaration(p): + '''_embed1_package_declaration : ''' + # { pform_set_scope_timescale(@1); } +() +def p_module_package_import_list_opt_1(p): + '''module_package_import_list_opt : ''' + print(p) +() +def p_module_package_import_list_opt_2(p): + '''module_package_import_list_opt : package_import_list ''' + print(p) +() +def p_package_import_list_1(p): + '''package_import_list : package_import_declaration ''' + print(p) +() +def p_package_import_list_2(p): + '''package_import_list : package_import_list package_import_declaration ''' + print(p) +() +def p_package_import_declaration_1(p): + '''package_import_declaration : K_import package_import_item_list ';' ''' + print(p) + # { } +() +def p_package_import_item_1(p): + '''package_import_item : PACKAGE_IDENTIFIER K_SCOPE_RES IDENTIFIER ''' + print(p) + # { pform_package_import(@2, $1, $3); + # delete[]$3; + # } +() +def p_package_import_item_2(p): + '''package_import_item : PACKAGE_IDENTIFIER K_SCOPE_RES '*' ''' + print(p) + # { pform_package_import(@2, $1, 0); + # } +() +def p_package_import_item_list_1(p): + '''package_import_item_list : package_import_item_list ',' package_import_item ''' + print(p) +() +def p_package_import_item_list_2(p): + '''package_import_item_list : package_import_item ''' + print(p) +() +def p_package_item_1(p): + '''package_item : timeunits_declaration ''' + print(p) +() +def p_package_item_2(p): + '''package_item : K_parameter param_type parameter_assign_list ';' ''' + print(p) +() +def p_package_item_3(p): + '''package_item : K_localparam param_type localparam_assign_list ';' ''' + print(p) +() +def p_package_item_4(p): + '''package_item : type_declaration ''' + print(p) +() +def p_package_item_5(p): + '''package_item : function_declaration ''' + print(p) +() +def p_package_item_6(p): + '''package_item : task_declaration ''' + print(p) +() +def p_package_item_7(p): + '''package_item : data_declaration ''' + print(p) +() +def p_package_item_8(p): + '''package_item : class_declaration ''' + print(p) +() +def p_package_item_list_1(p): + '''package_item_list : package_item_list package_item ''' + print(p) +() +def p_package_item_list_2(p): + '''package_item_list : package_item ''' + print(p) +() +def p_package_item_list_opt_1(p): + '''package_item_list_opt : package_item_list ''' + print(p) +() +def p_package_item_list_opt_2(p): + '''package_item_list_opt : ''' + print(p) +() +def p_port_direction_1(p): + '''port_direction : K_input ''' + print(p) + # { $$ = NetNet::PINPUT; } +() +def p_port_direction_2(p): + '''port_direction : K_output ''' + print(p) + # { $$ = NetNet::POUTPUT; } +() +def p_port_direction_3(p): + '''port_direction : K_inout ''' + print(p) + # { $$ = NetNet::PINOUT; } +() +def p_port_direction_4(p): + '''port_direction : K_ref ''' + print(p) + # { $$ = NetNet::PREF; + # if (!gn_system_verilog()) { + # yyerror(@1, "error: Reference ports (ref) require SystemVerilog."); + # $$ = NetNet::PINPUT; + # } + # } +() +def p_port_direction_opt_1(p): + '''port_direction_opt : port_direction ''' + print(p) + # { $$ = $1; } +() +def p_port_direction_opt_2(p): + '''port_direction_opt : ''' + print(p) + # { $$ = NetNet::PIMPLICIT; } +() +def p_property_expr_1(p): + '''property_expr : expression ''' + print(p) +() +def p_procedural_assertion_statement_1(p): + '''procedural_assertion_statement : K_assert '(' expression ')' statement %prec less_than_K_else ''' + print(p) + # { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); + # $$ = 0; + # } +() +def p_procedural_assertion_statement_2(p): + '''procedural_assertion_statement : K_assert '(' expression ')' K_else statement ''' + print(p) + # { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); + # $$ = 0; + # } +() +def p_procedural_assertion_statement_3(p): + '''procedural_assertion_statement : K_assert '(' expression ')' statement K_else statement ''' + print(p) + # { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); + # $$ = 0; + # } +() +def p_property_qualifier_1(p): + '''property_qualifier : class_item_qualifier ''' + print(p) +() +def p_property_qualifier_2(p): + '''property_qualifier : random_qualifier ''' + print(p) +() +def p_property_qualifier_opt_1(p): + '''property_qualifier_opt : property_qualifier_list ''' + print(p) + # { $$ = $1; } +() +def p_property_qualifier_opt_2(p): + '''property_qualifier_opt : ''' + print(p) + # { $$ = property_qualifier_t::make_none(); } +() +def p_property_qualifier_list_1(p): + '''property_qualifier_list : property_qualifier_list property_qualifier ''' + print(p) + # { $$ = $1 | $2; } +() +def p_property_qualifier_list_2(p): + '''property_qualifier_list : property_qualifier ''' + print(p) + # { $$ = $1; } +() +def p_property_spec_1(p): + '''property_spec : clocking_event_opt property_spec_disable_iff_opt property_expr ''' + print(p) +() +def p_property_spec_disable_iff_opt_1(p): + '''property_spec_disable_iff_opt : K_disable K_iff '(' expression ')' ''' + print(p) +() +def p_property_spec_disable_iff_opt_2(p): + '''property_spec_disable_iff_opt : ''' + print(p) +() +def p_random_qualifier_1(p): + '''random_qualifier : K_rand ''' + print(p) + # { $$ = property_qualifier_t::make_rand(); } +() +def p_random_qualifier_2(p): + '''random_qualifier : K_randc ''' + print(p) + # { $$ = property_qualifier_t::make_randc(); } +() +def p_real_or_realtime_1(p): + '''real_or_realtime : K_real ''' + print(p) +() +def p_real_or_realtime_2(p): + '''real_or_realtime : K_realtime ''' + print(p) +() +def p_signing_1(p): + '''signing : K_signed ''' + print(p) + # { $$ = true; } +() +def p_signing_2(p): + '''signing : K_unsigned ''' + print(p) + # { $$ = false; } +() +def p_simple_type_or_string_1(p): + '''simple_type_or_string : integer_vector_type ''' + print(p) + # { ivl_variable_type_t use_vtype = $1; + # bool reg_flag = false; + # if (use_vtype == IVL_VT_NO_TYPE) { + # use_vtype = IVL_VT_LOGIC; + # reg_flag = true; + # } + # vector_type_t*tmp = new vector_type_t(use_vtype, false, 0); + # tmp->reg_flag = reg_flag; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_simple_type_or_string_2(p): + '''simple_type_or_string : non_integer_type ''' + print(p) + # { real_type_t*tmp = new real_type_t($1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_simple_type_or_string_3(p): + '''simple_type_or_string : atom2_type ''' + print(p) + # { atom2_type_t*tmp = new atom2_type_t($1, true); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_simple_type_or_string_4(p): + '''simple_type_or_string : K_integer ''' + print(p) + # { list*pd = make_range_from_width(integer_width); + # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, true, pd); + # tmp->reg_flag = true; + # tmp->integer_flag = true; + # $$ = tmp; + # } +() +def p_simple_type_or_string_5(p): + '''simple_type_or_string : K_time ''' + print(p) + # { list*pd = make_range_from_width(64); + # vector_type_t*tmp = new vector_type_t(IVL_VT_LOGIC, false, pd); + # tmp->reg_flag = !gn_system_verilog(); + # $$ = tmp; + # } +() +def p_simple_type_or_string_6(p): + '''simple_type_or_string : TYPE_IDENTIFIER ''' + print(p) + # { $$ = $1.type; + # delete[]$1.text; + # } +() +def p_simple_type_or_string_7(p): + '''simple_type_or_string : PACKAGE_IDENTIFIER K_SCOPE_RES _embed0_simple_type_or_string TYPE_IDENTIFIER ''' + print(p) + # { lex_in_package_scope(0); + # $$ = $4.type; + # delete[]$4.text; + # } +() +def p_simple_type_or_string_8(p): + '''simple_type_or_string : K_string ''' + print(p) + # { string_type_t*tmp = new string_type_t; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p__embed0_simple_type_or_string(p): + '''_embed0_simple_type_or_string : ''' + # { lex_in_package_scope($1); } +() +def p_statement_1(p): + '''statement : attribute_list_opt statement_item ''' + print(p) + # { pform_bind_attributes($2->attributes, $1); + # $$ = $2; + # } +() +def p_statement_or_null_1(p): + '''statement_or_null : statement ''' + print(p) + # { $$ = $1; } +() +def p_statement_or_null_2(p): + '''statement_or_null : attribute_list_opt ';' ''' + print(p) + # { $$ = 0; } +() +def p_stream_expression_1(p): + '''stream_expression : expression ''' + print(p) +() +def p_stream_expression_list_1(p): + '''stream_expression_list : stream_expression_list ',' stream_expression ''' + print(p) +() +def p_stream_expression_list_2(p): + '''stream_expression_list : stream_expression ''' + print(p) +() +def p_stream_operator_1(p): + '''stream_operator : K_LS ''' + print(p) +() +def p_stream_operator_2(p): + '''stream_operator : K_RS ''' + print(p) +() +def p_streaming_concatenation_1(p): + '''streaming_concatenation : '{' stream_operator '{' stream_expression_list '}' '}' ''' + print(p) + # { /* streaming concatenation is a SystemVerilog thing. */ + # if (gn_system_verilog()) { + # yyerror(@2, "sorry: Streaming concatenation not supported."); + # $$ = 0; + # } else { + # yyerror(@2, "error: Streaming concatenation requires SystemVerilog"); + # $$ = 0; + # } + # } +() +def p_task_declaration_1(p): + '''task_declaration : K_task lifetime_opt IDENTIFIER ';' _embed0_task_declaration task_item_list_opt statement_or_null_list_opt K_endtask _embed1_task_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. This is done late so + # // that the parser can look ahead to detect the present + # // endlabel_opt but still have the pform_endmodule() called + # // early enough that the lexor can know we are outside the + # // module. + # if ($10) { + # if (strcmp($3,$10) != 0) { + # yyerror(@10, "error: End label doesn't match task name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@10, "error: Task end labels require " + # "SystemVerilog."); + # } + # delete[]$10; + # } + # delete[]$3; + # } +() +def p_task_declaration_2(p): + '''task_declaration : K_task lifetime_opt IDENTIFIER '(' _embed2_task_declaration tf_port_list ')' ';' block_item_decls_opt statement_or_null_list_opt K_endtask _embed3_task_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. This is done late so + # // that the parser can look ahead to detect the present + # // endlabel_opt but still have the pform_endmodule() called + # // early enough that the lexor can know we are outside the + # // module. + # if ($13) { + # if (strcmp($3,$13) != 0) { + # yyerror(@13, "error: End label doesn't match task name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@13, "error: Task end labels require " + # "SystemVerilog."); + # } + # delete[]$13; + # } + # delete[]$3; + # } +() +def p_task_declaration_3(p): + '''task_declaration : K_task lifetime_opt IDENTIFIER '(' ')' ';' _embed4_task_declaration block_item_decls_opt statement_or_null_list K_endtask _embed5_task_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. This is done late so + # // that the parser can look ahead to detect the present + # // endlabel_opt but still have the pform_endmodule() called + # // early enough that the lexor can know we are outside the + # // module. + # if ($12) { + # if (strcmp($3,$12) != 0) { + # yyerror(@12, "error: End label doesn't match task name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@12, "error: Task end labels require " + # "SystemVerilog."); + # } + # delete[]$12; + # } + # delete[]$3; + # } +() +def p_task_declaration_4(p): + '''task_declaration : K_task lifetime_opt IDENTIFIER error K_endtask _embed6_task_declaration endlabel_opt ''' + print(p) + # { // Last step: check any closing name. This is done late so + # // that the parser can look ahead to detect the present + # // endlabel_opt but still have the pform_endmodule() called + # // early enough that the lexor can know we are outside the + # // module. + # if ($7) { + # if (strcmp($3,$7) != 0) { + # yyerror(@7, "error: End label doesn't match task name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@7, "error: Task end labels require " + # "SystemVerilog."); + # } + # delete[]$7; + # } + # delete[]$3; + # } +() +def p__embed0_task_declaration(p): + '''_embed0_task_declaration : ''' + # { assert(current_task == 0); + # current_task = pform_push_task_scope(@1, $3, $2); + # } +() +def p__embed1_task_declaration(p): + '''_embed1_task_declaration : ''' + # { current_task->set_ports($6); + # current_task_set_statement(@3, $7); + # pform_set_this_class(@3, current_task); + # pform_pop_scope(); + # current_task = 0; + # if ($7 && $7->size() > 1 && !gn_system_verilog()) { + # yyerror(@7, "error: Task body with multiple statements requires SystemVerilog."); + # } + # delete $7; + # } +() +def p__embed2_task_declaration(p): + '''_embed2_task_declaration : ''' + # { assert(current_task == 0); + # current_task = pform_push_task_scope(@1, $3, $2); + # } +() +def p__embed3_task_declaration(p): + '''_embed3_task_declaration : ''' + # { current_task->set_ports($6); + # current_task_set_statement(@3, $10); + # pform_set_this_class(@3, current_task); + # pform_pop_scope(); + # current_task = 0; + # if ($10) delete $10; + # } +() +def p__embed4_task_declaration(p): + '''_embed4_task_declaration : ''' + # { assert(current_task == 0); + # current_task = pform_push_task_scope(@1, $3, $2); + # } +() +def p__embed5_task_declaration(p): + '''_embed5_task_declaration : ''' + # { current_task->set_ports(0); + # current_task_set_statement(@3, $9); + # pform_set_this_class(@3, current_task); + # if (! current_task->method_of()) { + # cerr << @3 << ": warning: task definition for \"" << $3 + # << "\" has an empty port declaration list!" << endl; + # } + # pform_pop_scope(); + # current_task = 0; + # if ($9->size() > 1 && !gn_system_verilog()) { + # yyerror(@9, "error: Task body with multiple statements requires SystemVerilog."); + # } + # delete $9; + # } +() +def p__embed6_task_declaration(p): + '''_embed6_task_declaration : ''' + # { + # if (current_task) { + # pform_pop_scope(); + # current_task = 0; + # } + # } +() +def p_tf_port_declaration_1(p): + '''tf_port_declaration : port_direction K_reg_opt unsigned_signed_opt dimensions_opt list_of_identifiers ';' ''' + print(p) + # { vector*tmp = pform_make_task_ports(@1, $1, + # $2 ? IVL_VT_LOGIC : + # IVL_VT_NO_TYPE, + # $3, $4, $5); + # $$ = tmp; + # } +() +def p_tf_port_declaration_2(p): + '''tf_port_declaration : port_direction K_integer list_of_identifiers ';' ''' + print(p) + # { list*range_stub = make_range_from_width(integer_width); + # vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_LOGIC, true, + # range_stub, $3, true); + # $$ = tmp; + # } +() +def p_tf_port_declaration_3(p): + '''tf_port_declaration : port_direction K_time list_of_identifiers ';' ''' + print(p) + # { list*range_stub = make_range_from_width(64); + # vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_LOGIC, false, + # range_stub, $3); + # $$ = tmp; + # } +() +def p_tf_port_declaration_4(p): + '''tf_port_declaration : port_direction real_or_realtime list_of_identifiers ';' ''' + print(p) + # { vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_REAL, true, + # 0, $3); + # $$ = tmp; + # } +() +def p_tf_port_declaration_5(p): + '''tf_port_declaration : port_direction K_string list_of_identifiers ';' ''' + print(p) + # { vector*tmp = pform_make_task_ports(@1, $1, IVL_VT_STRING, true, + # 0, $3); + # $$ = tmp; + # } +() +def p_tf_port_item_1(p): + '''tf_port_item : port_direction_opt data_type_or_implicit IDENTIFIER dimensions_opt tf_port_item_expr_opt ''' + print(p) + # { vector*tmp; + # NetNet::PortType use_port_type = $1; + # if ((use_port_type == NetNet::PIMPLICIT) && (gn_system_verilog() || ($2 == 0))) + # use_port_type = port_declaration_context.port_type; + # perm_string name = lex_strings.make($3); + # list* ilist = list_from_identifier($3); + # + # if (use_port_type == NetNet::PIMPLICIT) { + # yyerror(@1, "error: missing task/function port direction."); + # use_port_type = NetNet::PINPUT; // for error recovery + # } + # if (($2 == 0) && ($1==NetNet::PIMPLICIT)) { + # // Detect special case this is an undecorated + # // identifier and we need to get the declaration from + # // left context. + # if ($4 != 0) { + # yyerror(@4, "internal error: How can there be an unpacked range here?\n"); + # } + # tmp = pform_make_task_ports(@3, use_port_type, + # port_declaration_context.data_type, + # ilist); + # + # } else { + # // Otherwise, the decorations for this identifier + # // indicate the type. Save the type for any right + # // context that may come later. + # port_declaration_context.port_type = use_port_type; + # if ($2 == 0) { + # $2 = new vector_type_t(IVL_VT_LOGIC, false, 0); + # FILE_NAME($2, @3); + # } + # port_declaration_context.data_type = $2; + # tmp = pform_make_task_ports(@3, use_port_type, $2, ilist); + # } + # if ($4 != 0) { + # pform_set_reg_idx(name, $4); + # } + # + # $$ = tmp; + # if ($5) { + # assert(tmp->size()==1); + # tmp->front().defe = $5; + # } + # } +() +def p_tf_port_item_2(p): + '''tf_port_item : port_direction_opt data_type_or_implicit IDENTIFIER error ''' + print(p) + # { yyerror(@3, "error: Error in task/function port item after port name %s.", $3); + # yyerrok; + # $$ = 0; + # } +() +def p_tf_port_item_expr_opt_1(p): + '''tf_port_item_expr_opt : '=' expression ''' + print(p) + # { if (! gn_system_verilog()) { + # yyerror(@1, "error: Task/function default arguments require " + # "SystemVerilog."); + # } + # $$ = $2; + # } +() +def p_tf_port_item_expr_opt_2(p): + '''tf_port_item_expr_opt : ''' + print(p) + # { $$ = 0; } +() +def p_tf_port_list_1(p): + '''tf_port_list : _embed0_tf_port_list tf_port_item_list ''' + print(p) + # { $$ = $2; } +() +def p__embed0_tf_port_list(p): + '''_embed0_tf_port_list : ''' + # { port_declaration_context.port_type = gn_system_verilog() ? NetNet::PINPUT : NetNet::PIMPLICIT; + # port_declaration_context.data_type = 0; + # } +() +def p_tf_port_item_list_1(p): + '''tf_port_item_list : tf_port_item_list ',' tf_port_item ''' + print(p) + # { vector*tmp; + # if ($1 && $3) { + # size_t s1 = $1->size(); + # tmp = $1; + # tmp->resize(tmp->size()+$3->size()); + # for (size_t idx = 0 ; idx < $3->size() ; idx += 1) + # tmp->at(s1+idx) = $3->at(idx); + # delete $3; + # } else if ($1) { + # tmp = $1; + # } else { + # tmp = $3; + # } + # $$ = tmp; + # } +() +def p_tf_port_item_list_2(p): + '''tf_port_item_list : tf_port_item ''' + print(p) + # { $$ = $1; } +() +def p_tf_port_item_list_3(p): + '''tf_port_item_list : error ',' tf_port_item ''' + print(p) + # { yyerror(@2, "error: Syntax error in task/function port declaration."); + # $$ = $3; + # } +() +def p_tf_port_item_list_4(p): + '''tf_port_item_list : tf_port_item_list ',' ''' + print(p) + # { yyerror(@2, "error: NULL port declarations are not allowed."); + # $$ = $1; + # } +() +def p_tf_port_item_list_5(p): + '''tf_port_item_list : tf_port_item_list ';' ''' + print(p) + # { yyerror(@2, "error: ';' is an invalid port declaration separator."); + # $$ = $1; + # } +() +def p_timeunits_declaration_1(p): + '''timeunits_declaration : K_timeunit TIME_LITERAL ';' ''' + print(p) + # { pform_set_timeunit($2, allow_timeunit_decl); } +() +def p_timeunits_declaration_2(p): + '''timeunits_declaration : K_timeunit TIME_LITERAL '/' TIME_LITERAL ';' ''' + print(p) + # { bool initial_decl = allow_timeunit_decl && allow_timeprec_decl; + # pform_set_timeunit($2, initial_decl); + # pform_set_timeprec($4, initial_decl); + # } +() +def p_timeunits_declaration_3(p): + '''timeunits_declaration : K_timeprecision TIME_LITERAL ';' ''' + print(p) + # { pform_set_timeprec($2, allow_timeprec_decl); } +() +def p_timeunits_declaration_opt_1(p): + '''timeunits_declaration_opt : %prec no_timeunits_declaration ''' + print(p) +() +def p_timeunits_declaration_opt_2(p): + '''timeunits_declaration_opt : timeunits_declaration %prec one_timeunits_declaration ''' + print(p) +() +def p_timeunits_declaration_opt_3(p): + '''timeunits_declaration_opt : timeunits_declaration timeunits_declaration ''' + print(p) +() +def p_value_range_1(p): + '''value_range : expression ''' + print(p) + # { } +() +def p_value_range_2(p): + '''value_range : '[' expression ':' expression ']' ''' + print(p) + # { } +() +def p_variable_dimension_1(p): + '''variable_dimension : '[' expression ':' expression ']' ''' + print(p) + # { list *tmp = new list; + # pform_range_t index ($2,$4); + # tmp->push_back(index); + # $$ = tmp; + # } +() +def p_variable_dimension_2(p): + '''variable_dimension : '[' expression ']' ''' + print(p) + # { // SystemVerilog canonical range + # if (!gn_system_verilog()) { + # warn_count += 1; + # cerr << @2 << ": warning: Use of SystemVerilog [size] dimension. " + # << "Use at least -g2005-sv to remove this warning." << endl; + # } + # list *tmp = new list; + # pform_range_t index; + # index.first = new PENumber(new verinum((uint64_t)0, integer_width)); + # index.second = new PEBinary('-', $2, new PENumber(new verinum((uint64_t)1, integer_width))); + # tmp->push_back(index); + # $$ = tmp; + # } +() +def p_variable_dimension_3(p): + '''variable_dimension : '[' ']' ''' + print(p) + # { list *tmp = new list; + # pform_range_t index (0,0); + # tmp->push_back(index); + # $$ = tmp; + # } +() +def p_variable_dimension_4(p): + '''variable_dimension : '[' '$' ']' ''' + print(p) + # { // SystemVerilog queue + # list *tmp = new list; + # pform_range_t index (new PENull,0); + # if (!gn_system_verilog()) { + # yyerror("error: Queue declarations require SystemVerilog."); + # } + # tmp->push_back(index); + # $$ = tmp; + # } +() +def p_variable_lifetime_1(p): + '''variable_lifetime : lifetime ''' + print(p) + # { if (!gn_system_verilog()) { + # yyerror(@1, "error: overriding the default variable lifetime " + # "requires SystemVerilog."); + # } else if ($1 != pform_peek_scope()->default_lifetime) { + # yyerror(@1, "sorry: overriding the default variable lifetime " + # "is not yet supported."); + # } + # var_lifetime = $1; + # } +() +def p_attribute_list_opt_1(p): + '''attribute_list_opt : attribute_instance_list ''' + print(p) + # { $$ = $1; } +() +def p_attribute_list_opt_2(p): + '''attribute_list_opt : ''' + print(p) + # { $$ = 0; } +() +def p_attribute_instance_list_1(p): + '''attribute_instance_list : K_PSTAR K_STARP ''' + print(p) + # { $$ = 0; } +() +def p_attribute_instance_list_2(p): + '''attribute_instance_list : K_PSTAR attribute_list K_STARP ''' + print(p) + # { $$ = $2; } +() +def p_attribute_instance_list_3(p): + '''attribute_instance_list : attribute_instance_list K_PSTAR K_STARP ''' + print(p) + # { $$ = $1; } +() +def p_attribute_instance_list_4(p): + '''attribute_instance_list : attribute_instance_list K_PSTAR attribute_list K_STARP ''' + print(p) + # { list*tmp = $1; + # if (tmp) { + # tmp->splice(tmp->end(), *$3); + # delete $3; + # $$ = tmp; + # } else $$ = $3; + # } +() +def p_attribute_list_1(p): + '''attribute_list : attribute_list ',' attribute ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(*$3); + # delete $3; + # $$ = tmp; + # } +() +def p_attribute_list_2(p): + '''attribute_list : attribute ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(*$1); + # delete $1; + # $$ = tmp; + # } +() +def p_attribute_1(p): + '''attribute : IDENTIFIER ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($1); + # tmp->parm = 0; + # delete[]$1; + # $$ = tmp; + # } +() +def p_attribute_2(p): + '''attribute : IDENTIFIER '=' expression ''' + print(p) + # { PExpr*tmp = $3; + # named_pexpr_t*tmp2 = new named_pexpr_t; + # tmp2->name = lex_strings.make($1); + # tmp2->parm = tmp; + # delete[]$1; + # $$ = tmp2; + # } +() +def p_block_item_decl_1(p): + '''block_item_decl : data_type register_variable_list ';' ''' + print(p) + # { if ($1) pform_set_data_type(@1, $1, $2, NetNet::REG, attributes_in_context); + # } +() +def p_block_item_decl_2(p): + '''block_item_decl : variable_lifetime data_type register_variable_list ';' ''' + print(p) + # { if ($2) pform_set_data_type(@2, $2, $3, NetNet::REG, attributes_in_context); + # var_lifetime = LexicalScope::INHERITED; + # } +() +def p_block_item_decl_3(p): + '''block_item_decl : K_reg data_type register_variable_list ';' ''' + print(p) + # { if ($2) pform_set_data_type(@2, $2, $3, NetNet::REG, attributes_in_context); + # } +() +def p_block_item_decl_4(p): + '''block_item_decl : variable_lifetime K_reg data_type register_variable_list ';' ''' + print(p) + # { if ($3) pform_set_data_type(@3, $3, $4, NetNet::REG, attributes_in_context); + # var_lifetime = LexicalScope::INHERITED; + # } +() +def p_block_item_decl_5(p): + '''block_item_decl : K_event event_variable_list ';' ''' + print(p) + # { if ($2) pform_make_events($2, @1.text, @1.first_line); + # } +() +def p_block_item_decl_6(p): + '''block_item_decl : K_parameter param_type parameter_assign_list ';' ''' + print(p) +() +def p_block_item_decl_7(p): + '''block_item_decl : K_localparam param_type localparam_assign_list ';' ''' + print(p) +() +def p_block_item_decl_8(p): + '''block_item_decl : type_declaration ''' + print(p) +() +def p_block_item_decl_9(p): + '''block_item_decl : K_integer error ';' ''' + print(p) + # { yyerror(@1, "error: syntax error in integer variable list."); + # yyerrok; + # } +() +def p_block_item_decl_10(p): + '''block_item_decl : K_time error ';' ''' + print(p) + # { yyerror(@1, "error: syntax error in time variable list."); + # yyerrok; + # } +() +def p_block_item_decl_11(p): + '''block_item_decl : K_parameter error ';' ''' + print(p) + # { yyerror(@1, "error: syntax error in parameter list."); + # yyerrok; + # } +() +def p_block_item_decl_12(p): + '''block_item_decl : K_localparam error ';' ''' + print(p) + # { yyerror(@1, "error: syntax error localparam list."); + # yyerrok; + # } +() +def p_block_item_decls_1(p): + '''block_item_decls : block_item_decl ''' + print(p) +() +def p_block_item_decls_2(p): + '''block_item_decls : block_item_decls block_item_decl ''' + print(p) +() +def p_block_item_decls_opt_1(p): + '''block_item_decls_opt : block_item_decls ''' + print(p) + # { $$ = true; } +() +def p_block_item_decls_opt_2(p): + '''block_item_decls_opt : ''' + print(p) + # { $$ = false; } +() +def p_type_declaration_1(p): + '''type_declaration : K_typedef data_type IDENTIFIER dimensions_opt ';' ''' + print(p) + # { perm_string name = lex_strings.make($3); + # pform_set_typedef(name, $2, $4); + # delete[]$3; + # } +() +def p_type_declaration_2(p): + '''type_declaration : K_typedef data_type TYPE_IDENTIFIER ';' ''' + print(p) + # { perm_string name = lex_strings.make($3.text); + # if (pform_test_type_identifier_local(name)) { + # yyerror(@3, "error: Typedef identifier \"%s\" is already a type name.", $3.text); + # + # } else { + # pform_set_typedef(name, $2, NULL); + # } + # delete[]$3.text; + # } +() +def p_type_declaration_3(p): + '''type_declaration : K_typedef K_class IDENTIFIER ';' ''' + print(p) + # { // Create a synthetic typedef for the class name so that the + # // lexor detects the name as a type. + # perm_string name = lex_strings.make($3); + # class_type_t*tmp = new class_type_t(name); + # FILE_NAME(tmp, @3); + # pform_set_typedef(name, tmp, NULL); + # delete[]$3; + # } +() +def p_type_declaration_4(p): + '''type_declaration : K_typedef K_enum IDENTIFIER ';' ''' + print(p) + # { yyerror(@1, "sorry: Enum forward declarations not supported yet."); } +() +def p_type_declaration_5(p): + '''type_declaration : K_typedef K_struct IDENTIFIER ';' ''' + print(p) + # { yyerror(@1, "sorry: Struct forward declarations not supported yet."); } +() +def p_type_declaration_6(p): + '''type_declaration : K_typedef K_union IDENTIFIER ';' ''' + print(p) + # { yyerror(@1, "sorry: Union forward declarations not supported yet."); } +() +def p_type_declaration_7(p): + '''type_declaration : K_typedef IDENTIFIER ';' ''' + print(p) + # { // Create a synthetic typedef for the class name so that the + # // lexor detects the name as a type. + # perm_string name = lex_strings.make($2); + # class_type_t*tmp = new class_type_t(name); + # FILE_NAME(tmp, @2); + # pform_set_typedef(name, tmp, NULL); + # delete[]$2; + # } +() +def p_type_declaration_8(p): + '''type_declaration : K_typedef error ';' ''' + print(p) + # { yyerror(@2, "error: Syntax error in typedef clause."); + # yyerrok; + # } +() +def p_enum_data_type_1(p): + '''enum_data_type : K_enum '{' enum_name_list '}' ''' + print(p) + # { enum_type_t*enum_type = new enum_type_t; + # FILE_NAME(enum_type, @1); + # enum_type->names .reset($3); + # enum_type->base_type = IVL_VT_BOOL; + # enum_type->signed_flag = true; + # enum_type->integer_flag = false; + # enum_type->range.reset(make_range_from_width(32)); + # $$ = enum_type; + # } +() +def p_enum_data_type_2(p): + '''enum_data_type : K_enum atom2_type signed_unsigned_opt '{' enum_name_list '}' ''' + print(p) + # { enum_type_t*enum_type = new enum_type_t; + # FILE_NAME(enum_type, @1); + # enum_type->names .reset($5); + # enum_type->base_type = IVL_VT_BOOL; + # enum_type->signed_flag = $3; + # enum_type->integer_flag = false; + # enum_type->range.reset(make_range_from_width($2)); + # $$ = enum_type; + # } +() +def p_enum_data_type_3(p): + '''enum_data_type : K_enum K_integer signed_unsigned_opt '{' enum_name_list '}' ''' + print(p) + # { enum_type_t*enum_type = new enum_type_t; + # FILE_NAME(enum_type, @1); + # enum_type->names .reset($5); + # enum_type->base_type = IVL_VT_LOGIC; + # enum_type->signed_flag = $3; + # enum_type->integer_flag = true; + # enum_type->range.reset(make_range_from_width(integer_width)); + # $$ = enum_type; + # } +() +def p_enum_data_type_4(p): + '''enum_data_type : K_enum K_logic unsigned_signed_opt dimensions_opt '{' enum_name_list '}' ''' + print(p) + # { enum_type_t*enum_type = new enum_type_t; + # FILE_NAME(enum_type, @1); + # enum_type->names .reset($6); + # enum_type->base_type = IVL_VT_LOGIC; + # enum_type->signed_flag = $3; + # enum_type->integer_flag = false; + # enum_type->range.reset($4 ? $4 : make_range_from_width(1)); + # $$ = enum_type; + # } +() +def p_enum_data_type_5(p): + '''enum_data_type : K_enum K_reg unsigned_signed_opt dimensions_opt '{' enum_name_list '}' ''' + print(p) + # { enum_type_t*enum_type = new enum_type_t; + # FILE_NAME(enum_type, @1); + # enum_type->names .reset($6); + # enum_type->base_type = IVL_VT_LOGIC; + # enum_type->signed_flag = $3; + # enum_type->integer_flag = false; + # enum_type->range.reset($4 ? $4 : make_range_from_width(1)); + # $$ = enum_type; + # } +() +def p_enum_data_type_6(p): + '''enum_data_type : K_enum K_bit unsigned_signed_opt dimensions_opt '{' enum_name_list '}' ''' + print(p) + # { enum_type_t*enum_type = new enum_type_t; + # FILE_NAME(enum_type, @1); + # enum_type->names .reset($6); + # enum_type->base_type = IVL_VT_BOOL; + # enum_type->signed_flag = $3; + # enum_type->integer_flag = false; + # enum_type->range.reset($4 ? $4 : make_range_from_width(1)); + # $$ = enum_type; + # } +() +def p_enum_name_list_1(p): + '''enum_name_list : enum_name ''' + print(p) + # { $$ = $1; + # } +() +def p_enum_name_list_2(p): + '''enum_name_list : enum_name_list ',' enum_name ''' + print(p) + # { list*lst = $1; + # lst->splice(lst->end(), *$3); + # delete $3; + # $$ = lst; + # } +() +def p_pos_neg_number_1(p): + '''pos_neg_number : number ''' + print(p) + # { $$ = $1; + # } +() +def p_pos_neg_number_2(p): + '''pos_neg_number : '-' number ''' + print(p) + # { verinum tmp = -(*($2)); + # *($2) = tmp; + # $$ = $2; + # } +() +def p_enum_name_1(p): + '''enum_name : IDENTIFIER ''' + print(p) + # { perm_string name = lex_strings.make($1); + # delete[]$1; + # $$ = make_named_number(name); + # } +() +def p_enum_name_2(p): + '''enum_name : IDENTIFIER '[' pos_neg_number ']' ''' + print(p) + # { perm_string name = lex_strings.make($1); + # long count = check_enum_seq_value(@1, $3, false); + # delete[]$1; + # $$ = make_named_numbers(name, 0, count-1); + # delete $3; + # } +() +def p_enum_name_3(p): + '''enum_name : IDENTIFIER '[' pos_neg_number ':' pos_neg_number ']' ''' + print(p) + # { perm_string name = lex_strings.make($1); + # $$ = make_named_numbers(name, check_enum_seq_value(@1, $3, true), + # check_enum_seq_value(@1, $5, true)); + # delete[]$1; + # delete $3; + # delete $5; + # } +() +def p_enum_name_4(p): + '''enum_name : IDENTIFIER '=' expression ''' + print(p) + # { perm_string name = lex_strings.make($1); + # delete[]$1; + # $$ = make_named_number(name, $3); + # } +() +def p_enum_name_5(p): + '''enum_name : IDENTIFIER '[' pos_neg_number ']' '=' expression ''' + print(p) + # { perm_string name = lex_strings.make($1); + # long count = check_enum_seq_value(@1, $3, false); + # $$ = make_named_numbers(name, 0, count-1, $6); + # delete[]$1; + # delete $3; + # } +() +def p_enum_name_6(p): + '''enum_name : IDENTIFIER '[' pos_neg_number ':' pos_neg_number ']' '=' expression ''' + print(p) + # { perm_string name = lex_strings.make($1); + # $$ = make_named_numbers(name, check_enum_seq_value(@1, $3, true), + # check_enum_seq_value(@1, $5, true), $8); + # delete[]$1; + # delete $3; + # delete $5; + # } +() +def p_struct_data_type_1(p): + '''struct_data_type : K_struct K_packed_opt '{' struct_union_member_list '}' ''' + print(p) + # { struct_type_t*tmp = new struct_type_t; + # FILE_NAME(tmp, @1); + # tmp->packed_flag = $2; + # tmp->union_flag = false; + # tmp->members .reset($4); + # $$ = tmp; + # } +() +def p_struct_data_type_2(p): + '''struct_data_type : K_union K_packed_opt '{' struct_union_member_list '}' ''' + print(p) + # { struct_type_t*tmp = new struct_type_t; + # FILE_NAME(tmp, @1); + # tmp->packed_flag = $2; + # tmp->union_flag = true; + # tmp->members .reset($4); + # $$ = tmp; + # } +() +def p_struct_data_type_3(p): + '''struct_data_type : K_struct K_packed_opt '{' error '}' ''' + print(p) + # { yyerror(@3, "error: Errors in struct member list."); + # yyerrok; + # struct_type_t*tmp = new struct_type_t; + # FILE_NAME(tmp, @1); + # tmp->packed_flag = $2; + # tmp->union_flag = false; + # $$ = tmp; + # } +() +def p_struct_data_type_4(p): + '''struct_data_type : K_union K_packed_opt '{' error '}' ''' + print(p) + # { yyerror(@3, "error: Errors in union member list."); + # yyerrok; + # struct_type_t*tmp = new struct_type_t; + # FILE_NAME(tmp, @1); + # tmp->packed_flag = $2; + # tmp->union_flag = true; + # $$ = tmp; + # } +() +def p_struct_union_member_list_1(p): + '''struct_union_member_list : struct_union_member_list struct_union_member ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($2); + # $$ = tmp; + # } +() +def p_struct_union_member_list_2(p): + '''struct_union_member_list : struct_union_member ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # $$ = tmp; + # } +() +def p_struct_union_member_1(p): + '''struct_union_member : attribute_list_opt data_type list_of_variable_decl_assignments ';' ''' + print(p) + # { struct_member_t*tmp = new struct_member_t; + # FILE_NAME(tmp, @2); + # tmp->type .reset($2); + # tmp->names .reset($3); + # $$ = tmp; + # } +() +def p_struct_union_member_2(p): + '''struct_union_member : error ';' ''' + print(p) + # { yyerror(@2, "Error in struct/union member."); + # yyerrok; + # $$ = 0; + # } +() +def p_case_item_1(p): + '''case_item : expression_list_proper ':' statement_or_null ''' + print(p) + # { PCase::Item*tmp = new PCase::Item; + # tmp->expr = *$1; + # tmp->stat = $3; + # delete $1; + # $$ = tmp; + # } +() +def p_case_item_2(p): + '''case_item : K_default ':' statement_or_null ''' + print(p) + # { PCase::Item*tmp = new PCase::Item; + # tmp->stat = $3; + # $$ = tmp; + # } +() +def p_case_item_3(p): + '''case_item : K_default statement_or_null ''' + print(p) + # { PCase::Item*tmp = new PCase::Item; + # tmp->stat = $2; + # $$ = tmp; + # } +() +def p_case_item_4(p): + '''case_item : error ':' statement_or_null ''' + print(p) + # { yyerror(@2, "error: Incomprehensible case expression."); + # yyerrok; + # } +() +def p_case_items_1(p): + '''case_items : case_items case_item ''' + print(p) + # { svector*tmp; + # tmp = new svector(*$1, $2); + # delete $1; + # $$ = tmp; + # } +() +def p_case_items_2(p): + '''case_items : case_item ''' + print(p) + # { svector*tmp = new svector(1); + # (*tmp)[0] = $1; + # $$ = tmp; + # } +() +def p_charge_strength_1(p): + '''charge_strength : '(' K_small ')' ''' + print(p) +() +def p_charge_strength_2(p): + '''charge_strength : '(' K_medium ')' ''' + print(p) +() +def p_charge_strength_3(p): + '''charge_strength : '(' K_large ')' ''' + print(p) +() +def p_charge_strength_opt_1(p): + '''charge_strength_opt : charge_strength ''' + print(p) +() +def p_charge_strength_opt_2(p): + '''charge_strength_opt : ''' + print(p) +() +def p_defparam_assign_1(p): + '''defparam_assign : hierarchy_identifier '=' expression ''' + print(p) + # { pform_set_defparam(*$1, $3); + # delete $1; + # } +() +def p_defparam_assign_list_1(p): + '''defparam_assign_list : defparam_assign ''' + print(p) +() +def p_defparam_assign_list_2(p): + '''defparam_assign_list : dimensions defparam_assign ''' + print(p) + # { yyerror(@1, "error: defparam may not include a range."); + # delete $1; + # } +() +def p_defparam_assign_list_3(p): + '''defparam_assign_list : defparam_assign_list ',' defparam_assign ''' + print(p) +() +def p_delay1_1(p): + '''delay1 : '#' delay_value_simple ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($2); + # $$ = tmp; + # } +() +def p_delay1_2(p): + '''delay1 : '#' '(' delay_value ')' ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_delay3_1(p): + '''delay3 : '#' delay_value_simple ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($2); + # $$ = tmp; + # } +() +def p_delay3_2(p): + '''delay3 : '#' '(' delay_value ')' ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_delay3_3(p): + '''delay3 : '#' '(' delay_value ',' delay_value ')' ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($3); + # tmp->push_back($5); + # $$ = tmp; + # } +() +def p_delay3_4(p): + '''delay3 : '#' '(' delay_value ',' delay_value ',' delay_value ')' ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($3); + # tmp->push_back($5); + # tmp->push_back($7); + # $$ = tmp; + # } +() +def p_delay3_opt_1(p): + '''delay3_opt : delay3 ''' + print(p) + # { $$ = $1; } +() +def p_delay3_opt_2(p): + '''delay3_opt : ''' + print(p) + # { $$ = 0; } +() +def p_delay_value_list_1(p): + '''delay_value_list : delay_value ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # $$ = tmp; + # } +() +def p_delay_value_list_2(p): + '''delay_value_list : delay_value_list ',' delay_value ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_delay_value_1(p): + '''delay_value : expression ''' + print(p) + # { PExpr*tmp = $1; + # $$ = tmp; + # } +() +def p_delay_value_2(p): + '''delay_value : expression ':' expression ':' expression ''' + print(p) + # { $$ = pform_select_mtm_expr($1, $3, $5); } +() +def p_delay_value_simple_1(p): + '''delay_value_simple : DEC_NUMBER ''' + print(p) + # { verinum*tmp = $1; + # if (tmp == 0) { + # yyerror(@1, "internal error: delay."); + # $$ = 0; + # } else { + # $$ = new PENumber(tmp); + # FILE_NAME($$, @1); + # } + # based_size = 0; + # } +() +def p_delay_value_simple_2(p): + '''delay_value_simple : REALTIME ''' + print(p) + # { verireal*tmp = $1; + # if (tmp == 0) { + # yyerror(@1, "internal error: delay."); + # $$ = 0; + # } else { + # $$ = new PEFNumber(tmp); + # FILE_NAME($$, @1); + # } + # } +() +def p_delay_value_simple_3(p): + '''delay_value_simple : IDENTIFIER ''' + print(p) + # { PEIdent*tmp = new PEIdent(lex_strings.make($1)); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # delete[]$1; + # } +() +def p_delay_value_simple_4(p): + '''delay_value_simple : TIME_LITERAL ''' + print(p) + # { int unit; + # + # based_size = 0; + # $$ = 0; + # if ($1 == 0 || !get_time_unit($1, unit)) + # yyerror(@1, "internal error: delay."); + # else { + # double p = pow(10.0, + # (double)(unit - pform_get_timeunit())); + # double time = atof($1) * p; + # + # verireal *v = new verireal(time); + # $$ = new PEFNumber(v); + # FILE_NAME($$, @1); + # } + # } +() +def p_optional_semicolon_1(p): + '''optional_semicolon : ';' ''' + print(p) +() +def p_optional_semicolon_2(p): + '''optional_semicolon : ''' + print(p) +() +def p_discipline_declaration_1(p): + '''discipline_declaration : K_discipline IDENTIFIER optional_semicolon _embed0_discipline_declaration discipline_items K_enddiscipline ''' + print(p) + # { pform_end_discipline(@1); delete[] $2; } +() +def p__embed0_discipline_declaration(p): + '''_embed0_discipline_declaration : ''' + # { pform_start_discipline($2); } +() +def p_discipline_items_1(p): + '''discipline_items : discipline_items discipline_item ''' + print(p) +() +def p_discipline_items_2(p): + '''discipline_items : discipline_item ''' + print(p) +() +def p_discipline_item_1(p): + '''discipline_item : K_domain K_discrete ';' ''' + print(p) + # { pform_discipline_domain(@1, IVL_DIS_DISCRETE); } +() +def p_discipline_item_2(p): + '''discipline_item : K_domain K_continuous ';' ''' + print(p) + # { pform_discipline_domain(@1, IVL_DIS_CONTINUOUS); } +() +def p_discipline_item_3(p): + '''discipline_item : K_potential IDENTIFIER ';' ''' + print(p) + # { pform_discipline_potential(@1, $2); delete[] $2; } +() +def p_discipline_item_4(p): + '''discipline_item : K_flow IDENTIFIER ';' ''' + print(p) + # { pform_discipline_flow(@1, $2); delete[] $2; } +() +def p_nature_declaration_1(p): + '''nature_declaration : K_nature IDENTIFIER optional_semicolon _embed0_nature_declaration nature_items K_endnature ''' + print(p) + # { pform_end_nature(@1); delete[] $2; } +() +def p__embed0_nature_declaration(p): + '''_embed0_nature_declaration : ''' + # { pform_start_nature($2); } +() +def p_nature_items_1(p): + '''nature_items : nature_items nature_item ''' + print(p) +() +def p_nature_items_2(p): + '''nature_items : nature_item ''' + print(p) +() +def p_nature_item_1(p): + '''nature_item : K_units '=' STRING ';' ''' + print(p) + # { delete[] $3; } +() +def p_nature_item_2(p): + '''nature_item : K_abstol '=' expression ';' ''' + print(p) +() +def p_nature_item_3(p): + '''nature_item : K_access '=' IDENTIFIER ';' ''' + print(p) + # { pform_nature_access(@1, $3); delete[] $3; } +() +def p_nature_item_4(p): + '''nature_item : K_idt_nature '=' IDENTIFIER ';' ''' + print(p) + # { delete[] $3; } +() +def p_nature_item_5(p): + '''nature_item : K_ddt_nature '=' IDENTIFIER ';' ''' + print(p) + # { delete[] $3; } +() +def p_config_declaration_1(p): + '''config_declaration : K_config IDENTIFIER ';' K_design lib_cell_identifiers ';' list_of_config_rule_statements K_endconfig ''' + print(p) + # { cerr << @1 << ": sorry: config declarations are not supported and " + # "will be skipped." << endl; + # delete[] $2; + # } +() +def p_lib_cell_identifiers_1(p): + '''lib_cell_identifiers : ''' + print(p) +() +def p_lib_cell_identifiers_2(p): + '''lib_cell_identifiers : lib_cell_identifiers lib_cell_id ''' + print(p) +() +def p_list_of_config_rule_statements_1(p): + '''list_of_config_rule_statements : ''' + print(p) +() +def p_list_of_config_rule_statements_2(p): + '''list_of_config_rule_statements : list_of_config_rule_statements config_rule_statement ''' + print(p) +() +def p_config_rule_statement_1(p): + '''config_rule_statement : K_default K_liblist list_of_libraries ';' ''' + print(p) +() +def p_config_rule_statement_2(p): + '''config_rule_statement : K_instance hierarchy_identifier K_liblist list_of_libraries ';' ''' + print(p) + # { delete $2; } +() +def p_config_rule_statement_3(p): + '''config_rule_statement : K_instance hierarchy_identifier K_use lib_cell_id opt_config ';' ''' + print(p) + # { delete $2; } +() +def p_config_rule_statement_4(p): + '''config_rule_statement : K_cell lib_cell_id K_liblist list_of_libraries ';' ''' + print(p) +() +def p_config_rule_statement_5(p): + '''config_rule_statement : K_cell lib_cell_id K_use lib_cell_id opt_config ';' ''' + print(p) +() +def p_opt_config_1(p): + '''opt_config : ''' + print(p) +() +def p_opt_config_2(p): + '''opt_config : ':' K_config ''' + print(p) +() +def p_lib_cell_id_1(p): + '''lib_cell_id : IDENTIFIER ''' + print(p) + # { delete[] $1; } +() +def p_lib_cell_id_2(p): + '''lib_cell_id : IDENTIFIER '.' IDENTIFIER ''' + print(p) + # { delete[] $1; delete[] $3; } +() +def p_list_of_libraries_1(p): + '''list_of_libraries : ''' + print(p) +() +def p_list_of_libraries_2(p): + '''list_of_libraries : list_of_libraries IDENTIFIER ''' + print(p) + # { delete[] $2; } +() +def p_drive_strength_1(p): + '''drive_strength : '(' dr_strength0 ',' dr_strength1 ')' ''' + print(p) + # { $$.str0 = $2.str0; + # $$.str1 = $4.str1; + # } +() +def p_drive_strength_2(p): + '''drive_strength : '(' dr_strength1 ',' dr_strength0 ')' ''' + print(p) + # { $$.str0 = $4.str0; + # $$.str1 = $2.str1; + # } +() +def p_drive_strength_3(p): + '''drive_strength : '(' dr_strength0 ',' K_highz1 ')' ''' + print(p) + # { $$.str0 = $2.str0; + # $$.str1 = IVL_DR_HiZ; + # } +() +def p_drive_strength_4(p): + '''drive_strength : '(' dr_strength1 ',' K_highz0 ')' ''' + print(p) + # { $$.str0 = IVL_DR_HiZ; + # $$.str1 = $2.str1; + # } +() +def p_drive_strength_5(p): + '''drive_strength : '(' K_highz1 ',' dr_strength0 ')' ''' + print(p) + # { $$.str0 = $4.str0; + # $$.str1 = IVL_DR_HiZ; + # } +() +def p_drive_strength_6(p): + '''drive_strength : '(' K_highz0 ',' dr_strength1 ')' ''' + print(p) + # { $$.str0 = IVL_DR_HiZ; + # $$.str1 = $4.str1; + # } +() +def p_drive_strength_opt_1(p): + '''drive_strength_opt : drive_strength ''' + print(p) + # { $$ = $1; } +() +def p_drive_strength_opt_2(p): + '''drive_strength_opt : ''' + print(p) + # { $$.str0 = IVL_DR_STRONG; $$.str1 = IVL_DR_STRONG; } +() +def p_dr_strength0_1(p): + '''dr_strength0 : K_supply0 ''' + print(p) + # { $$.str0 = IVL_DR_SUPPLY; } +() +def p_dr_strength0_2(p): + '''dr_strength0 : K_strong0 ''' + print(p) + # { $$.str0 = IVL_DR_STRONG; } +() +def p_dr_strength0_3(p): + '''dr_strength0 : K_pull0 ''' + print(p) + # { $$.str0 = IVL_DR_PULL; } +() +def p_dr_strength0_4(p): + '''dr_strength0 : K_weak0 ''' + print(p) + # { $$.str0 = IVL_DR_WEAK; } +() +def p_dr_strength1_1(p): + '''dr_strength1 : K_supply1 ''' + print(p) + # { $$.str1 = IVL_DR_SUPPLY; } +() +def p_dr_strength1_2(p): + '''dr_strength1 : K_strong1 ''' + print(p) + # { $$.str1 = IVL_DR_STRONG; } +() +def p_dr_strength1_3(p): + '''dr_strength1 : K_pull1 ''' + print(p) + # { $$.str1 = IVL_DR_PULL; } +() +def p_dr_strength1_4(p): + '''dr_strength1 : K_weak1 ''' + print(p) + # { $$.str1 = IVL_DR_WEAK; } +() +def p_clocking_event_opt_1(p): + '''clocking_event_opt : event_control ''' + print(p) +() +def p_clocking_event_opt_2(p): + '''clocking_event_opt : ''' + print(p) +() +def p_event_control_1(p): + '''event_control : '@' hierarchy_identifier ''' + print(p) + # { PEIdent*tmpi = new PEIdent(*$2); + # PEEvent*tmpe = new PEEvent(PEEvent::ANYEDGE, tmpi); + # PEventStatement*tmps = new PEventStatement(tmpe); + # FILE_NAME(tmps, @1); + # $$ = tmps; + # delete $2; + # } +() +def p_event_control_2(p): + '''event_control : '@' '(' event_expression_list ')' ''' + print(p) + # { PEventStatement*tmp = new PEventStatement(*$3); + # FILE_NAME(tmp, @1); + # delete $3; + # $$ = tmp; + # } +() +def p_event_control_3(p): + '''event_control : '@' '(' error ')' ''' + print(p) + # { yyerror(@1, "error: Malformed event control expression."); + # $$ = 0; + # } +() +def p_event_expression_list_1(p): + '''event_expression_list : event_expression ''' + print(p) + # { $$ = $1; } +() +def p_event_expression_list_2(p): + '''event_expression_list : event_expression_list K_or event_expression ''' + print(p) + # { svector*tmp = new svector(*$1, *$3); + # delete $1; + # delete $3; + # $$ = tmp; + # } +() +def p_event_expression_list_3(p): + '''event_expression_list : event_expression_list ',' event_expression ''' + print(p) + # { svector*tmp = new svector(*$1, *$3); + # delete $1; + # delete $3; + # $$ = tmp; + # } +() +def p_event_expression_1(p): + '''event_expression : K_posedge expression ''' + print(p) + # { PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2); + # FILE_NAME(tmp, @1); + # svector*tl = new svector(1); + # (*tl)[0] = tmp; + # $$ = tl; + # } +() +def p_event_expression_2(p): + '''event_expression : K_negedge expression ''' + print(p) + # { PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2); + # FILE_NAME(tmp, @1); + # svector*tl = new svector(1); + # (*tl)[0] = tmp; + # $$ = tl; + # } +() +def p_event_expression_3(p): + '''event_expression : expression ''' + print(p) + # { PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1); + # FILE_NAME(tmp, @1); + # svector*tl = new svector(1); + # (*tl)[0] = tmp; + # $$ = tl; + # } +() +def p_branch_probe_expression_1(p): + '''branch_probe_expression : IDENTIFIER '(' IDENTIFIER ',' IDENTIFIER ')' ''' + print(p) + # { $$ = pform_make_branch_probe_expression(@1, $1, $3, $5); } +() +def p_branch_probe_expression_2(p): + '''branch_probe_expression : IDENTIFIER '(' IDENTIFIER ')' ''' + print(p) + # { $$ = pform_make_branch_probe_expression(@1, $1, $3); } +() +def p_expression_1(p): + '''expression : expr_primary_or_typename ''' + print(p) + # { $$ = $1; } +() +def p_expression_2(p): + '''expression : inc_or_dec_expression ''' + print(p) + # { $$ = $1; } +() +def p_expression_3(p): + '''expression : inside_expression ''' + print(p) + # { $$ = $1; } +() +def p_expression_4(p): + '''expression : '+' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { $$ = $3; } +() +def p_expression_5(p): + '''expression : '-' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('-', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_6(p): + '''expression : '~' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('~', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_7(p): + '''expression : '&' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('&', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_8(p): + '''expression : '!' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('!', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_9(p): + '''expression : '|' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('|', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_10(p): + '''expression : '^' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('^', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_11(p): + '''expression : '~' '&' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { yyerror(@1, "error: '~' '&' is not a valid expression. " + # "Please use operator '~&' instead."); + # $$ = 0; + # } +() +def p_expression_12(p): + '''expression : '~' '|' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { yyerror(@1, "error: '~' '|' is not a valid expression. " + # "Please use operator '~|' instead."); + # $$ = 0; + # } +() +def p_expression_13(p): + '''expression : '~' '^' attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { yyerror(@1, "error: '~' '^' is not a valid expression. " + # "Please use operator '~^' instead."); + # $$ = 0; + # } +() +def p_expression_14(p): + '''expression : K_NAND attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('A', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_15(p): + '''expression : K_NOR attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('N', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_16(p): + '''expression : K_NXOR attribute_list_opt expr_primary %prec UNARY_PREC ''' + print(p) + # { PEUnary*tmp = new PEUnary('X', $3); + # FILE_NAME(tmp, @3); + # $$ = tmp; + # } +() +def p_expression_17(p): + '''expression : '!' error %prec UNARY_PREC ''' + print(p) + # { yyerror(@1, "error: Operand of unary ! " + # "is not a primary expression."); + # $$ = 0; + # } +() +def p_expression_18(p): + '''expression : '^' error %prec UNARY_PREC ''' + print(p) + # { yyerror(@1, "error: Operand of reduction ^ " + # "is not a primary expression."); + # $$ = 0; + # } +() +def p_expression_19(p): + '''expression : expression '^' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('^', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_20(p): + '''expression : expression K_POW attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBPower('p', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_21(p): + '''expression : expression '*' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('*', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_22(p): + '''expression : expression '/' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('/', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_23(p): + '''expression : expression '%' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('%', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_24(p): + '''expression : expression '+' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('+', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_25(p): + '''expression : expression '-' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('-', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_26(p): + '''expression : expression '&' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('&', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_27(p): + '''expression : expression '|' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('|', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_28(p): + '''expression : expression K_NAND attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('A', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_29(p): + '''expression : expression K_NOR attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('O', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_30(p): + '''expression : expression K_NXOR attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBinary('X', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_31(p): + '''expression : expression '<' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('<', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_32(p): + '''expression : expression '>' attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('>', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_33(p): + '''expression : expression K_LS attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBShift('l', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_34(p): + '''expression : expression K_RS attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBShift('r', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_35(p): + '''expression : expression K_RSS attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBShift('R', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_36(p): + '''expression : expression K_EQ attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('e', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_37(p): + '''expression : expression K_CEQ attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('E', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_38(p): + '''expression : expression K_WEQ attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('w', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_39(p): + '''expression : expression K_LE attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('L', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_40(p): + '''expression : expression K_GE attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('G', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_41(p): + '''expression : expression K_NE attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('n', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_42(p): + '''expression : expression K_CNE attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('N', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_43(p): + '''expression : expression K_WNE attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBComp('W', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_44(p): + '''expression : expression K_LOR attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBLogic('o', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_45(p): + '''expression : expression K_LAND attribute_list_opt expression ''' + print(p) + # { PEBinary*tmp = new PEBLogic('a', $1, $4); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expression_46(p): + '''expression : expression '?' attribute_list_opt expression ':' expression ''' + print(p) + # { PETernary*tmp = new PETernary($1, $4, $6); + # FILE_NAME(tmp, @2); + # $$ = tmp; + # } +() +def p_expr_mintypmax_1(p): + '''expr_mintypmax : expression ''' + print(p) + # { $$ = $1; } +() +def p_expr_mintypmax_2(p): + '''expr_mintypmax : expression ':' expression ':' expression ''' + print(p) + # { switch (min_typ_max_flag) { + # case MIN: + # $$ = $1; + # delete $3; + # delete $5; + # break; + # case TYP: + # delete $1; + # $$ = $3; + # delete $5; + # break; + # case MAX: + # delete $1; + # delete $3; + # $$ = $5; + # break; + # } + # if (min_typ_max_warn > 0) { + # cerr << $$->get_fileline() << ": warning: choosing "; + # switch (min_typ_max_flag) { + # case MIN: + # cerr << "min"; + # break; + # case TYP: + # cerr << "typ"; + # break; + # case MAX: + # cerr << "max"; + # break; + # } + # cerr << " expression." << endl; + # min_typ_max_warn -= 1; + # } + # } +() +def p_expression_list_with_nuls_1(p): + '''expression_list_with_nuls : expression_list_with_nuls ',' expression ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_expression_list_with_nuls_2(p): + '''expression_list_with_nuls : expression ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # $$ = tmp; + # } +() +def p_expression_list_with_nuls_3(p): + '''expression_list_with_nuls : ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(0); + # $$ = tmp; + # } +() +def p_expression_list_with_nuls_4(p): + '''expression_list_with_nuls : expression_list_with_nuls ',' ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(0); + # $$ = tmp; + # } +() +def p_expression_list_proper_1(p): + '''expression_list_proper : expression_list_proper ',' expression ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_expression_list_proper_2(p): + '''expression_list_proper : expression ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # $$ = tmp; + # } +() +def p_expr_primary_or_typename_1(p): + '''expr_primary_or_typename : expr_primary ''' + print(p) +() +def p_expr_primary_or_typename_2(p): + '''expr_primary_or_typename : TYPE_IDENTIFIER ''' + print(p) + # { PETypename*tmp = new PETypename($1.type); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # delete[]$1.text; + # } +() +def p_expr_primary_1(p): + '''expr_primary : number ''' + print(p) + # { assert($1); + # PENumber*tmp = new PENumber($1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_expr_primary_2(p): + '''expr_primary : REALTIME ''' + print(p) + # { PEFNumber*tmp = new PEFNumber($1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_expr_primary_3(p): + '''expr_primary : STRING ''' + print(p) + # { PEString*tmp = new PEString($1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_expr_primary_4(p): + '''expr_primary : TIME_LITERAL ''' + print(p) + # { int unit; + # + # based_size = 0; + # $$ = 0; + # if ($1 == 0 || !get_time_unit($1, unit)) + # yyerror(@1, "internal error: delay."); + # else { + # double p = pow(10.0, (double)(unit - pform_get_timeunit())); + # double time = atof($1) * p; + # + # verireal *v = new verireal(time); + # $$ = new PEFNumber(v); + # FILE_NAME($$, @1); + # } + # } +() +def p_expr_primary_5(p): + '''expr_primary : SYSTEM_IDENTIFIER ''' + print(p) + # { perm_string tn = lex_strings.make($1); + # PECallFunction*tmp = new PECallFunction(tn); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # delete[]$1; + # } +() +def p_expr_primary_6(p): + '''expr_primary : hierarchy_identifier ''' + print(p) + # { PEIdent*tmp = pform_new_ident(*$1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # delete $1; + # } +() +def p_expr_primary_7(p): + '''expr_primary : PACKAGE_IDENTIFIER K_SCOPE_RES hierarchy_identifier ''' + print(p) + # { $$ = pform_package_ident(@2, $1, $3); + # delete $3; + # } +() +def p_expr_primary_8(p): + '''expr_primary : hierarchy_identifier '(' expression_list_with_nuls ')' ''' + print(p) + # { list*expr_list = $3; + # strip_tail_items(expr_list); + # PECallFunction*tmp = pform_make_call_function(@1, *$1, *expr_list); + # delete $1; + # $$ = tmp; + # } +() +def p_expr_primary_9(p): + '''expr_primary : implicit_class_handle '.' hierarchy_identifier '(' expression_list_with_nuls ')' ''' + print(p) + # { pform_name_t*t_name = $1; + # while (! $3->empty()) { + # t_name->push_back($3->front()); + # $3->pop_front(); + # } + # list*expr_list = $5; + # strip_tail_items(expr_list); + # PECallFunction*tmp = pform_make_call_function(@1, *t_name, *expr_list); + # delete $1; + # delete $3; + # $$ = tmp; + # } +() +def p_expr_primary_10(p): + '''expr_primary : SYSTEM_IDENTIFIER '(' expression_list_proper ')' ''' + print(p) + # { perm_string tn = lex_strings.make($1); + # PECallFunction*tmp = new PECallFunction(tn, *$3); + # FILE_NAME(tmp, @1); + # delete[]$1; + # $$ = tmp; + # } +() +def p_expr_primary_11(p): + '''expr_primary : PACKAGE_IDENTIFIER K_SCOPE_RES IDENTIFIER '(' expression_list_proper ')' ''' + print(p) + # { perm_string use_name = lex_strings.make($3); + # PECallFunction*tmp = new PECallFunction($1, use_name, *$5); + # FILE_NAME(tmp, @3); + # delete[]$3; + # $$ = tmp; + # } +() +def p_expr_primary_12(p): + '''expr_primary : SYSTEM_IDENTIFIER '(' ')' ''' + print(p) + # { perm_string tn = lex_strings.make($1); + # const vectorempty; + # PECallFunction*tmp = new PECallFunction(tn, empty); + # FILE_NAME(tmp, @1); + # delete[]$1; + # $$ = tmp; + # if (!gn_system_verilog()) { + # yyerror(@1, "error: Empty function argument list requires SystemVerilog."); + # } + # } +() +def p_expr_primary_13(p): + '''expr_primary : implicit_class_handle ''' + print(p) + # { PEIdent*tmp = new PEIdent(*$1); + # FILE_NAME(tmp,@1); + # delete $1; + # $$ = tmp; + # } +() +def p_expr_primary_14(p): + '''expr_primary : implicit_class_handle '.' hierarchy_identifier ''' + print(p) + # { pform_name_t*t_name = $1; + # while (! $3->empty()) { + # t_name->push_back($3->front()); + # $3->pop_front(); + # } + # PEIdent*tmp = new PEIdent(*t_name); + # FILE_NAME(tmp,@1); + # delete $1; + # delete $3; + # $$ = tmp; + # } +() +def p_expr_primary_15(p): + '''expr_primary : K_acos '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$acos"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_16(p): + '''expr_primary : K_acosh '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$acosh"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_17(p): + '''expr_primary : K_asin '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$asin"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_18(p): + '''expr_primary : K_asinh '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$asinh"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_19(p): + '''expr_primary : K_atan '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$atan"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_20(p): + '''expr_primary : K_atanh '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$atanh"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_21(p): + '''expr_primary : K_atan2 '(' expression ',' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$atan2"); + # PECallFunction*tmp = make_call_function(tn, $3, $5); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_22(p): + '''expr_primary : K_ceil '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$ceil"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_23(p): + '''expr_primary : K_cos '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$cos"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_24(p): + '''expr_primary : K_cosh '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$cosh"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_25(p): + '''expr_primary : K_exp '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$exp"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_26(p): + '''expr_primary : K_floor '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$floor"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_27(p): + '''expr_primary : K_hypot '(' expression ',' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$hypot"); + # PECallFunction*tmp = make_call_function(tn, $3, $5); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_28(p): + '''expr_primary : K_ln '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$ln"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_29(p): + '''expr_primary : K_log '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$log10"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_30(p): + '''expr_primary : K_pow '(' expression ',' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$pow"); + # PECallFunction*tmp = make_call_function(tn, $3, $5); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_31(p): + '''expr_primary : K_sin '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$sin"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_32(p): + '''expr_primary : K_sinh '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$sinh"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_33(p): + '''expr_primary : K_sqrt '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$sqrt"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_34(p): + '''expr_primary : K_tan '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$tan"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_35(p): + '''expr_primary : K_tanh '(' expression ')' ''' + print(p) + # { perm_string tn = perm_string::literal("$tanh"); + # PECallFunction*tmp = make_call_function(tn, $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_36(p): + '''expr_primary : K_abs '(' expression ')' ''' + print(p) + # { PEUnary*tmp = new PEUnary('m', $3); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_37(p): + '''expr_primary : K_max '(' expression ',' expression ')' ''' + print(p) + # { PEBinary*tmp = new PEBinary('M', $3, $5); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_38(p): + '''expr_primary : K_min '(' expression ',' expression ')' ''' + print(p) + # { PEBinary*tmp = new PEBinary('m', $3, $5); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_expr_primary_39(p): + '''expr_primary : '(' expr_mintypmax ')' ''' + print(p) + # { $$ = $2; } +() +def p_expr_primary_40(p): + '''expr_primary : '{' expression_list_proper '}' ''' + print(p) + # { PEConcat*tmp = new PEConcat(*$2); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_expr_primary_41(p): + '''expr_primary : '{' expression '{' expression_list_proper '}' '}' ''' + print(p) + # { PExpr*rep = $2; + # PEConcat*tmp = new PEConcat(*$4, rep); + # FILE_NAME(tmp, @1); + # delete $4; + # $$ = tmp; + # } +() +def p_expr_primary_42(p): + '''expr_primary : '{' expression '{' expression_list_proper '}' error '}' ''' + print(p) + # { PExpr*rep = $2; + # PEConcat*tmp = new PEConcat(*$4, rep); + # FILE_NAME(tmp, @1); + # delete $4; + # $$ = tmp; + # yyerror(@5, "error: Syntax error between internal '}' " + # "and closing '}' of repeat concatenation."); + # yyerrok; + # } +() +def p_expr_primary_43(p): + '''expr_primary : '{' '}' ''' + print(p) + # { // This is the empty queue syntax. + # if (gn_system_verilog()) { + # list empty_list; + # PEConcat*tmp = new PEConcat(empty_list); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } else { + # yyerror(@1, "error: Concatenations are not allowed to be empty."); + # $$ = 0; + # } + # } +() +def p_expr_primary_44(p): + '''expr_primary : expr_primary "'" '(' expression ')' ''' + print(p) + # { PExpr*base = $4; + # if (gn_system_verilog()) { + # PECastSize*tmp = new PECastSize($1, base); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } else { + # yyerror(@1, "error: Size cast requires SystemVerilog."); + # $$ = base; + # } + # } +() +def p_expr_primary_45(p): + '''expr_primary : simple_type_or_string "'" '(' expression ')' ''' + print(p) + # { PExpr*base = $4; + # if (gn_system_verilog()) { + # PECastType*tmp = new PECastType($1, base); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } else { + # yyerror(@1, "error: Type cast requires SystemVerilog."); + # $$ = base; + # } + # } +() +def p_expr_primary_46(p): + '''expr_primary : assignment_pattern ''' + print(p) + # { $$ = $1; } +() +def p_expr_primary_47(p): + '''expr_primary : streaming_concatenation ''' + print(p) + # { $$ = $1; } +() +def p_expr_primary_48(p): + '''expr_primary : K_null ''' + print(p) + # { PENull*tmp = new PENull; + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_function_item_list_opt_1(p): + '''function_item_list_opt : function_item_list ''' + print(p) + # { $$ = $1; } +() +def p_function_item_list_opt_2(p): + '''function_item_list_opt : ''' + print(p) + # { $$ = 0; } +() +def p_function_item_list_1(p): + '''function_item_list : function_item ''' + print(p) + # { $$ = $1; } +() +def p_function_item_list_2(p): + '''function_item_list : function_item_list function_item ''' + print(p) + # { /* */ + # if ($1 && $2) { + # vector*tmp = $1; + # size_t s1 = tmp->size(); + # tmp->resize(s1 + $2->size()); + # for (size_t idx = 0 ; idx < $2->size() ; idx += 1) + # tmp->at(s1+idx) = $2->at(idx); + # delete $2; + # $$ = tmp; + # } else if ($1) { + # $$ = $1; + # } else { + # $$ = $2; + # } + # } +() +def p_function_item_1(p): + '''function_item : tf_port_declaration ''' + print(p) + # { $$ = $1; } +() +def p_function_item_2(p): + '''function_item : block_item_decl ''' + print(p) + # { $$ = 0; } +() +def p_gate_instance_1(p): + '''gate_instance : IDENTIFIER '(' expression_list_with_nuls ')' ''' + print(p) + # { lgate*tmp = new lgate; + # tmp->name = $1; + # tmp->parms = $3; + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # delete[]$1; + # $$ = tmp; + # } +() +def p_gate_instance_2(p): + '''gate_instance : IDENTIFIER dimensions '(' expression_list_with_nuls ')' ''' + print(p) + # { lgate*tmp = new lgate; + # list*rng = $2; + # tmp->name = $1; + # tmp->parms = $4; + # tmp->range = rng->front(); + # rng->pop_front(); + # assert(rng->empty()); + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # delete[]$1; + # delete rng; + # $$ = tmp; + # } +() +def p_gate_instance_3(p): + '''gate_instance : '(' expression_list_with_nuls ')' ''' + print(p) + # { lgate*tmp = new lgate; + # tmp->name = ""; + # tmp->parms = $2; + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # $$ = tmp; + # } +() +def p_gate_instance_4(p): + '''gate_instance : IDENTIFIER dimensions ''' + print(p) + # { lgate*tmp = new lgate; + # list*rng = $2; + # tmp->name = $1; + # tmp->parms = 0; + # tmp->parms_by_name = 0; + # tmp->range = rng->front(); + # rng->pop_front(); + # assert(rng->empty()); + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # delete[]$1; + # delete rng; + # $$ = tmp; + # } +() +def p_gate_instance_5(p): + '''gate_instance : IDENTIFIER '(' port_name_list ')' ''' + print(p) + # { lgate*tmp = new lgate; + # tmp->name = $1; + # tmp->parms = 0; + # tmp->parms_by_name = $3; + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # delete[]$1; + # $$ = tmp; + # } +() +def p_gate_instance_6(p): + '''gate_instance : IDENTIFIER dimensions '(' port_name_list ')' ''' + print(p) + # { lgate*tmp = new lgate; + # list*rng = $2; + # tmp->name = $1; + # tmp->parms = 0; + # tmp->parms_by_name = $4; + # tmp->range = rng->front(); + # rng->pop_front(); + # assert(rng->empty()); + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # delete[]$1; + # delete rng; + # $$ = tmp; + # } +() +def p_gate_instance_7(p): + '''gate_instance : IDENTIFIER '(' error ')' ''' + print(p) + # { lgate*tmp = new lgate; + # tmp->name = $1; + # tmp->parms = 0; + # tmp->parms_by_name = 0; + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # yyerror(@2, "error: Syntax error in instance port " + # "expression(s)."); + # delete[]$1; + # $$ = tmp; + # } +() +def p_gate_instance_8(p): + '''gate_instance : IDENTIFIER dimensions '(' error ')' ''' + print(p) + # { lgate*tmp = new lgate; + # tmp->name = $1; + # tmp->parms = 0; + # tmp->parms_by_name = 0; + # tmp->file = @1.text; + # tmp->lineno = @1.first_line; + # yyerror(@3, "error: Syntax error in instance port " + # "expression(s)."); + # delete[]$1; + # $$ = tmp; + # } +() +def p_gate_instance_list_1(p): + '''gate_instance_list : gate_instance_list ',' gate_instance ''' + print(p) + # { svector*tmp1 = $1; + # lgate*tmp2 = $3; + # svector*out = new svector (*tmp1, *tmp2); + # delete tmp1; + # delete tmp2; + # $$ = out; + # } +() +def p_gate_instance_list_2(p): + '''gate_instance_list : gate_instance ''' + print(p) + # { svector*tmp = new svector(1); + # (*tmp)[0] = *$1; + # delete $1; + # $$ = tmp; + # } +() +def p_gatetype_1(p): + '''gatetype : K_and ''' + print(p) + # { $$ = PGBuiltin::AND; } +() +def p_gatetype_2(p): + '''gatetype : K_nand ''' + print(p) + # { $$ = PGBuiltin::NAND; } +() +def p_gatetype_3(p): + '''gatetype : K_or ''' + print(p) + # { $$ = PGBuiltin::OR; } +() +def p_gatetype_4(p): + '''gatetype : K_nor ''' + print(p) + # { $$ = PGBuiltin::NOR; } +() +def p_gatetype_5(p): + '''gatetype : K_xor ''' + print(p) + # { $$ = PGBuiltin::XOR; } +() +def p_gatetype_6(p): + '''gatetype : K_xnor ''' + print(p) + # { $$ = PGBuiltin::XNOR; } +() +def p_gatetype_7(p): + '''gatetype : K_buf ''' + print(p) + # { $$ = PGBuiltin::BUF; } +() +def p_gatetype_8(p): + '''gatetype : K_bufif0 ''' + print(p) + # { $$ = PGBuiltin::BUFIF0; } +() +def p_gatetype_9(p): + '''gatetype : K_bufif1 ''' + print(p) + # { $$ = PGBuiltin::BUFIF1; } +() +def p_gatetype_10(p): + '''gatetype : K_not ''' + print(p) + # { $$ = PGBuiltin::NOT; } +() +def p_gatetype_11(p): + '''gatetype : K_notif0 ''' + print(p) + # { $$ = PGBuiltin::NOTIF0; } +() +def p_gatetype_12(p): + '''gatetype : K_notif1 ''' + print(p) + # { $$ = PGBuiltin::NOTIF1; } +() +def p_switchtype_1(p): + '''switchtype : K_nmos ''' + print(p) + # { $$ = PGBuiltin::NMOS; } +() +def p_switchtype_2(p): + '''switchtype : K_rnmos ''' + print(p) + # { $$ = PGBuiltin::RNMOS; } +() +def p_switchtype_3(p): + '''switchtype : K_pmos ''' + print(p) + # { $$ = PGBuiltin::PMOS; } +() +def p_switchtype_4(p): + '''switchtype : K_rpmos ''' + print(p) + # { $$ = PGBuiltin::RPMOS; } +() +def p_switchtype_5(p): + '''switchtype : K_cmos ''' + print(p) + # { $$ = PGBuiltin::CMOS; } +() +def p_switchtype_6(p): + '''switchtype : K_rcmos ''' + print(p) + # { $$ = PGBuiltin::RCMOS; } +() +def p_switchtype_7(p): + '''switchtype : K_tran ''' + print(p) + # { $$ = PGBuiltin::TRAN; } +() +def p_switchtype_8(p): + '''switchtype : K_rtran ''' + print(p) + # { $$ = PGBuiltin::RTRAN; } +() +def p_switchtype_9(p): + '''switchtype : K_tranif0 ''' + print(p) + # { $$ = PGBuiltin::TRANIF0; } +() +def p_switchtype_10(p): + '''switchtype : K_tranif1 ''' + print(p) + # { $$ = PGBuiltin::TRANIF1; } +() +def p_switchtype_11(p): + '''switchtype : K_rtranif0 ''' + print(p) + # { $$ = PGBuiltin::RTRANIF0; } +() +def p_switchtype_12(p): + '''switchtype : K_rtranif1 ''' + print(p) + # { $$ = PGBuiltin::RTRANIF1; } +() +def p_hierarchy_identifier_1(p): + '''hierarchy_identifier : IDENTIFIER ''' + print(p) + # { $$ = new pform_name_t; + # $$->push_back(name_component_t(lex_strings.make($1))); + # delete[]$1; + # } +() +def p_hierarchy_identifier_2(p): + '''hierarchy_identifier : hierarchy_identifier '.' IDENTIFIER ''' + print(p) + # { pform_name_t * tmp = $1; + # tmp->push_back(name_component_t(lex_strings.make($3))); + # delete[]$3; + # $$ = tmp; + # } +() +def p_hierarchy_identifier_3(p): + '''hierarchy_identifier : hierarchy_identifier '[' expression ']' ''' + print(p) + # { pform_name_t * tmp = $1; + # name_component_t&tail = tmp->back(); + # index_component_t itmp; + # itmp.sel = index_component_t::SEL_BIT; + # itmp.msb = $3; + # tail.index.push_back(itmp); + # $$ = tmp; + # } +() +def p_hierarchy_identifier_4(p): + '''hierarchy_identifier : hierarchy_identifier '[' '$' ']' ''' + print(p) + # { pform_name_t * tmp = $1; + # name_component_t&tail = tmp->back(); + # if (! gn_system_verilog()) { + # yyerror(@3, "error: Last element expression ($) " + # "requires SystemVerilog. Try enabling SystemVerilog."); + # } + # index_component_t itmp; + # itmp.sel = index_component_t::SEL_BIT_LAST; + # itmp.msb = 0; + # itmp.lsb = 0; + # tail.index.push_back(itmp); + # $$ = tmp; + # } +() +def p_hierarchy_identifier_5(p): + '''hierarchy_identifier : hierarchy_identifier '[' expression ':' expression ']' ''' + print(p) + # { pform_name_t * tmp = $1; + # name_component_t&tail = tmp->back(); + # index_component_t itmp; + # itmp.sel = index_component_t::SEL_PART; + # itmp.msb = $3; + # itmp.lsb = $5; + # tail.index.push_back(itmp); + # $$ = tmp; + # } +() +def p_hierarchy_identifier_6(p): + '''hierarchy_identifier : hierarchy_identifier '[' expression K_PO_POS expression ']' ''' + print(p) + # { pform_name_t * tmp = $1; + # name_component_t&tail = tmp->back(); + # index_component_t itmp; + # itmp.sel = index_component_t::SEL_IDX_UP; + # itmp.msb = $3; + # itmp.lsb = $5; + # tail.index.push_back(itmp); + # $$ = tmp; + # } +() +def p_hierarchy_identifier_7(p): + '''hierarchy_identifier : hierarchy_identifier '[' expression K_PO_NEG expression ']' ''' + print(p) + # { pform_name_t * tmp = $1; + # name_component_t&tail = tmp->back(); + # index_component_t itmp; + # itmp.sel = index_component_t::SEL_IDX_DO; + # itmp.msb = $3; + # itmp.lsb = $5; + # tail.index.push_back(itmp); + # $$ = tmp; + # } +() +def p_list_of_identifiers_1(p): + '''list_of_identifiers : IDENTIFIER ''' + print(p) + # { $$ = list_from_identifier($1); } +() +def p_list_of_identifiers_2(p): + '''list_of_identifiers : list_of_identifiers ',' IDENTIFIER ''' + print(p) + # { $$ = list_from_identifier($1, $3); } +() +def p_list_of_port_identifiers_1(p): + '''list_of_port_identifiers : IDENTIFIER dimensions_opt ''' + print(p) + # { $$ = make_port_list($1, $2, 0); } +() +def p_list_of_port_identifiers_2(p): + '''list_of_port_identifiers : list_of_port_identifiers ',' IDENTIFIER dimensions_opt ''' + print(p) + # { $$ = make_port_list($1, $3, $4, 0); } +() +def p_list_of_variable_port_identifiers_1(p): + '''list_of_variable_port_identifiers : IDENTIFIER dimensions_opt ''' + print(p) + # { $$ = make_port_list($1, $2, 0); } +() +def p_list_of_variable_port_identifiers_2(p): + '''list_of_variable_port_identifiers : IDENTIFIER dimensions_opt '=' expression ''' + print(p) + # { $$ = make_port_list($1, $2, $4); } +() +def p_list_of_variable_port_identifiers_3(p): + '''list_of_variable_port_identifiers : list_of_variable_port_identifiers ',' IDENTIFIER dimensions_opt ''' + print(p) + # { $$ = make_port_list($1, $3, $4, 0); } +() +def p_list_of_variable_port_identifiers_4(p): + '''list_of_variable_port_identifiers : list_of_variable_port_identifiers ',' IDENTIFIER dimensions_opt '=' expression ''' + print(p) + # { $$ = make_port_list($1, $3, $4, $6); } +() +def p_list_of_ports_1(p): + '''list_of_ports : port_opt ''' + print(p) + # { vector*tmp + # = new vector(1); + # (*tmp)[0] = $1; + # $$ = tmp; + # } +() +def p_list_of_ports_2(p): + '''list_of_ports : list_of_ports ',' port_opt ''' + print(p) + # { vector*tmp = $1; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_list_of_port_declarations_1(p): + '''list_of_port_declarations : port_declaration ''' + print(p) + # { vector*tmp + # = new vector(1); + # (*tmp)[0] = $1; + # $$ = tmp; + # } +() +def p_list_of_port_declarations_2(p): + '''list_of_port_declarations : list_of_port_declarations ',' port_declaration ''' + print(p) + # { vector*tmp = $1; + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_list_of_port_declarations_3(p): + '''list_of_port_declarations : list_of_port_declarations ',' IDENTIFIER ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($3); + # ptmp = pform_module_port_reference(name, @3.text, + # @3.first_line); + # vector*tmp = $1; + # tmp->push_back(ptmp); + # + # /* Get the port declaration details, the port type + # and what not, from context data stored by the + # last port_declaration rule. */ + # pform_module_define_port(@3, name, + # port_declaration_context.port_type, + # port_declaration_context.port_net_type, + # port_declaration_context.data_type, 0); + # delete[]$3; + # $$ = tmp; + # } +() +def p_list_of_port_declarations_4(p): + '''list_of_port_declarations : list_of_port_declarations ',' ''' + print(p) + # { + # yyerror(@2, "error: NULL port declarations are not " + # "allowed."); + # } +() +def p_list_of_port_declarations_5(p): + '''list_of_port_declarations : list_of_port_declarations ';' ''' + print(p) + # { + # yyerror(@2, "error: ';' is an invalid port declaration " + # "separator."); + # } +() +def p_port_declaration_1(p): + '''port_declaration : attribute_list_opt K_input net_type_opt data_type_or_implicit IDENTIFIER dimensions_opt ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($5); + # data_type_t*use_type = $4; + # if ($6) use_type = new uarray_type_t(use_type, $6); + # ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + # pform_module_define_port(@2, name, NetNet::PINPUT, $3, use_type, $1); + # port_declaration_context.port_type = NetNet::PINPUT; + # port_declaration_context.port_net_type = $3; + # port_declaration_context.data_type = $4; + # delete[]$5; + # $$ = ptmp; + # } +() +def p_port_declaration_2(p): + '''port_declaration : attribute_list_opt K_input K_wreal IDENTIFIER ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($4); + # ptmp = pform_module_port_reference(name, @2.text, + # @2.first_line); + # real_type_t*real_type = new real_type_t(real_type_t::REAL); + # FILE_NAME(real_type, @3); + # pform_module_define_port(@2, name, NetNet::PINPUT, + # NetNet::WIRE, real_type, $1); + # port_declaration_context.port_type = NetNet::PINPUT; + # port_declaration_context.port_net_type = NetNet::WIRE; + # port_declaration_context.data_type = real_type; + # delete[]$4; + # $$ = ptmp; + # } +() +def p_port_declaration_3(p): + '''port_declaration : attribute_list_opt K_inout net_type_opt data_type_or_implicit IDENTIFIER dimensions_opt ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($5); + # ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + # pform_module_define_port(@2, name, NetNet::PINOUT, $3, $4, $1); + # port_declaration_context.port_type = NetNet::PINOUT; + # port_declaration_context.port_net_type = $3; + # port_declaration_context.data_type = $4; + # delete[]$5; + # if ($6) { + # yyerror(@6, "sorry: Inout ports with unpacked dimensions not supported."); + # delete $6; + # } + # $$ = ptmp; + # } +() +def p_port_declaration_4(p): + '''port_declaration : attribute_list_opt K_inout K_wreal IDENTIFIER ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($4); + # ptmp = pform_module_port_reference(name, @2.text, + # @2.first_line); + # real_type_t*real_type = new real_type_t(real_type_t::REAL); + # FILE_NAME(real_type, @3); + # pform_module_define_port(@2, name, NetNet::PINOUT, + # NetNet::WIRE, real_type, $1); + # port_declaration_context.port_type = NetNet::PINOUT; + # port_declaration_context.port_net_type = NetNet::WIRE; + # port_declaration_context.data_type = real_type; + # delete[]$4; + # $$ = ptmp; + # } +() +def p_port_declaration_5(p): + '''port_declaration : attribute_list_opt K_output net_type_opt data_type_or_implicit IDENTIFIER dimensions_opt ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($5); + # data_type_t*use_dtype = $4; + # if ($6) use_dtype = new uarray_type_t(use_dtype, $6); + # NetNet::Type use_type = $3; + # if (use_type == NetNet::IMPLICIT) { + # if (vector_type_t*dtype = dynamic_cast ($4)) { + # if (dtype->reg_flag) + # use_type = NetNet::REG; + # else if (dtype->implicit_flag) + # use_type = NetNet::IMPLICIT; + # else + # use_type = NetNet::IMPLICIT_REG; + # + # // The SystemVerilog types that can show up as + # // output ports are implicitly (on the inside) + # // variables because "reg" is not valid syntax + # // here. + # } else if (dynamic_cast ($4)) { + # use_type = NetNet::IMPLICIT_REG; + # } else if (dynamic_cast ($4)) { + # use_type = NetNet::IMPLICIT_REG; + # } else if (enum_type_t*etype = dynamic_cast ($4)) { + # if(etype->base_type == IVL_VT_LOGIC) + # use_type = NetNet::IMPLICIT_REG; + # } + # } + # ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + # pform_module_define_port(@2, name, NetNet::POUTPUT, use_type, use_dtype, $1); + # port_declaration_context.port_type = NetNet::POUTPUT; + # port_declaration_context.port_net_type = use_type; + # port_declaration_context.data_type = $4; + # delete[]$5; + # $$ = ptmp; + # } +() +def p_port_declaration_6(p): + '''port_declaration : attribute_list_opt K_output K_wreal IDENTIFIER ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($4); + # ptmp = pform_module_port_reference(name, @2.text, + # @2.first_line); + # real_type_t*real_type = new real_type_t(real_type_t::REAL); + # FILE_NAME(real_type, @3); + # pform_module_define_port(@2, name, NetNet::POUTPUT, + # NetNet::WIRE, real_type, $1); + # port_declaration_context.port_type = NetNet::POUTPUT; + # port_declaration_context.port_net_type = NetNet::WIRE; + # port_declaration_context.data_type = real_type; + # delete[]$4; + # $$ = ptmp; + # } +() +def p_port_declaration_7(p): + '''port_declaration : attribute_list_opt K_output net_type_opt data_type_or_implicit IDENTIFIER '=' expression ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($5); + # NetNet::Type use_type = $3; + # if (use_type == NetNet::IMPLICIT) { + # if (vector_type_t*dtype = dynamic_cast ($4)) { + # if (dtype->reg_flag) + # use_type = NetNet::REG; + # else + # use_type = NetNet::IMPLICIT_REG; + # } else { + # use_type = NetNet::IMPLICIT_REG; + # } + # } + # ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + # pform_module_define_port(@2, name, NetNet::POUTPUT, use_type, $4, $1); + # port_declaration_context.port_type = NetNet::PINOUT; + # port_declaration_context.port_net_type = use_type; + # port_declaration_context.data_type = $4; + # + # pform_make_var_init(@5, name, $7); + # + # delete[]$5; + # $$ = ptmp; + # } +() +def p_net_type_opt_1(p): + '''net_type_opt : net_type ''' + print(p) + # { $$ = $1; } +() +def p_net_type_opt_2(p): + '''net_type_opt : ''' + print(p) + # { $$ = NetNet::IMPLICIT; } +() +def p_unsigned_signed_opt_1(p): + '''unsigned_signed_opt : K_signed ''' + print(p) + # { $$ = true; } +() +def p_unsigned_signed_opt_2(p): + '''unsigned_signed_opt : K_unsigned ''' + print(p) + # { $$ = false; } +() +def p_unsigned_signed_opt_3(p): + '''unsigned_signed_opt : ''' + print(p) + # { $$ = false; } +() +def p_signed_unsigned_opt_1(p): + '''signed_unsigned_opt : K_signed ''' + print(p) + # { $$ = true; } +() +def p_signed_unsigned_opt_2(p): + '''signed_unsigned_opt : K_unsigned ''' + print(p) + # { $$ = false; } +() +def p_signed_unsigned_opt_3(p): + '''signed_unsigned_opt : ''' + print(p) + # { $$ = true; } +() +def p_atom2_type_1(p): + '''atom2_type : K_byte ''' + print(p) + # { $$ = 8; } +() +def p_atom2_type_2(p): + '''atom2_type : K_shortint ''' + print(p) + # { $$ = 16; } +() +def p_atom2_type_3(p): + '''atom2_type : K_int ''' + print(p) + # { $$ = 32; } +() +def p_atom2_type_4(p): + '''atom2_type : K_longint ''' + print(p) + # { $$ = 64; } +() +def p_lpvalue_1(p): + '''lpvalue : hierarchy_identifier ''' + print(p) + # { PEIdent*tmp = pform_new_ident(*$1); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # delete $1; + # } +() +def p_lpvalue_2(p): + '''lpvalue : implicit_class_handle '.' hierarchy_identifier ''' + print(p) + # { pform_name_t*t_name = $1; + # while (!$3->empty()) { + # t_name->push_back($3->front()); + # $3->pop_front(); + # } + # PEIdent*tmp = new PEIdent(*t_name); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # delete $1; + # delete $3; + # } +() +def p_lpvalue_3(p): + '''lpvalue : '{' expression_list_proper '}' ''' + print(p) + # { PEConcat*tmp = new PEConcat(*$2); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_lpvalue_4(p): + '''lpvalue : streaming_concatenation ''' + print(p) + # { yyerror(@1, "sorry: streaming concatenation not supported in l-values."); + # $$ = 0; + # } +() +def p_cont_assign_1(p): + '''cont_assign : lpvalue '=' expression ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # tmp->push_back($3); + # $$ = tmp; + # } +() +def p_cont_assign_list_1(p): + '''cont_assign_list : cont_assign_list ',' cont_assign ''' + print(p) + # { list*tmp = $1; + # tmp->splice(tmp->end(), *$3); + # delete $3; + # $$ = tmp; + # } +() +def p_cont_assign_list_2(p): + '''cont_assign_list : cont_assign ''' + print(p) + # { $$ = $1; } +() +def p_module_1(p): + '''module : attribute_list_opt module_start lifetime_opt IDENTIFIER _embed0_module module_package_import_list_opt module_parameter_port_list_opt module_port_list_opt module_attribute_foreign ';' _embed1_module timeunits_declaration_opt _embed2_module module_item_list_opt module_end _embed3_module endlabel_opt ''' + print(p) + # { // Last step: check any closing name. This is done late so + # // that the parser can look ahead to detect the present + # // endlabel_opt but still have the pform_endmodule() called + # // early enough that the lexor can know we are outside the + # // module. + # if ($17) { + # if (strcmp($4,$17) != 0) { + # switch ($2) { + # case K_module: + # yyerror(@17, "error: End label doesn't match " + # "module name."); + # break; + # case K_program: + # yyerror(@17, "error: End label doesn't match " + # "program name."); + # break; + # case K_interface: + # yyerror(@17, "error: End label doesn't match " + # "interface name."); + # break; + # default: + # break; + # } + # } + # if (($2 == K_module) && (! gn_system_verilog())) { + # yyerror(@8, "error: Module end labels require " + # "SystemVerilog."); + # } + # delete[]$17; + # } + # delete[]$4; + # } +() +def p__embed0_module(p): + '''_embed0_module : ''' + # { pform_startmodule(@2, $4, $2==K_program, $2==K_interface, $3, $1); } +() +def p__embed1_module(p): + '''_embed1_module : ''' + # { pform_module_set_ports($8); } +() +def p__embed2_module(p): + '''_embed2_module : ''' + # { pform_set_scope_timescale(@2); } +() +def p__embed3_module(p): + '''_embed3_module : ''' + # { Module::UCDriveType ucd; + # // The lexor detected `unconnected_drive directives and + # // marked what it found in the uc_drive variable. Use that + # // to generate a UCD flag for the module. + # switch (uc_drive) { + # case UCD_NONE: + # default: + # ucd = Module::UCD_NONE; + # break; + # case UCD_PULL0: + # ucd = Module::UCD_PULL0; + # break; + # case UCD_PULL1: + # ucd = Module::UCD_PULL1; + # break; + # } + # // Check that program/endprogram and module/endmodule + # // keywords match. + # if ($2 != $15) { + # switch ($2) { + # case K_module: + # yyerror(@15, "error: module not closed by endmodule."); + # break; + # case K_program: + # yyerror(@15, "error: program not closed by endprogram."); + # break; + # case K_interface: + # yyerror(@15, "error: interface not closed by endinterface."); + # break; + # default: + # break; + # } + # } + # pform_endmodule($4, in_celldefine, ucd); + # } +() +def p_module_start_1(p): + '''module_start : K_module ''' + print(p) + # { $$ = K_module; } +() +def p_module_start_2(p): + '''module_start : K_macromodule ''' + print(p) + # { $$ = K_module; } +() +def p_module_start_3(p): + '''module_start : K_program ''' + print(p) + # { $$ = K_program; } +() +def p_module_start_4(p): + '''module_start : K_interface ''' + print(p) + # { $$ = K_interface; } +() +def p_module_end_1(p): + '''module_end : K_endmodule ''' + print(p) + # { $$ = K_module; } +() +def p_module_end_2(p): + '''module_end : K_endprogram ''' + print(p) + # { $$ = K_program; } +() +def p_module_end_3(p): + '''module_end : K_endinterface ''' + print(p) + # { $$ = K_interface; } +() +def p_endlabel_opt_1(p): + '''endlabel_opt : ':' IDENTIFIER ''' + print(p) + # { $$ = $2; } +() +def p_endlabel_opt_2(p): + '''endlabel_opt : ''' + print(p) + # { $$ = 0; } +() +def p_module_attribute_foreign_1(p): + '''module_attribute_foreign : K_PSTAR IDENTIFIER K_integer IDENTIFIER '=' STRING ';' K_STARP ''' + print(p) + # { $$ = 0; } +() +def p_module_attribute_foreign_2(p): + '''module_attribute_foreign : ''' + print(p) + # { $$ = 0; } +() +def p_module_port_list_opt_1(p): + '''module_port_list_opt : '(' list_of_ports ')' ''' + print(p) + # { $$ = $2; } +() +def p_module_port_list_opt_2(p): + '''module_port_list_opt : '(' list_of_port_declarations ')' ''' + print(p) + # { $$ = $2; } +() +def p_module_port_list_opt_3(p): + '''module_port_list_opt : ''' + print(p) + # { $$ = 0; } +() +def p_module_port_list_opt_4(p): + '''module_port_list_opt : '(' error ')' ''' + print(p) + # { yyerror(@2, "Errors in port declarations."); + # yyerrok; + # $$ = 0; + # } +() +def p_module_parameter_port_list_opt_1(p): + '''module_parameter_port_list_opt : ''' + print(p) +() +def p_module_parameter_port_list_opt_2(p): + '''module_parameter_port_list_opt : '#' '(' module_parameter_port_list ')' ''' + print(p) +() +def p_module_parameter_port_list_1(p): + '''module_parameter_port_list : K_parameter param_type parameter_assign ''' + print(p) +() +def p_module_parameter_port_list_2(p): + '''module_parameter_port_list : module_parameter_port_list ',' parameter_assign ''' + print(p) +() +def p_module_parameter_port_list_3(p): + '''module_parameter_port_list : module_parameter_port_list ',' K_parameter param_type parameter_assign ''' + print(p) +() +def p_module_item_1(p): + '''module_item : module ''' + print(p) +() +def p_module_item_2(p): + '''module_item : attribute_list_opt net_type data_type_or_implicit delay3_opt net_variable_list ';' ''' + print(p) + # { data_type_t*data_type = $3; + # if (data_type == 0) { + # data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + # FILE_NAME(data_type, @2); + # } + # pform_set_data_type(@2, data_type, $5, $2, $1); + # if ($4 != 0) { + # yyerror(@2, "sorry: net delays not supported."); + # delete $4; + # } + # delete $1; + # } +() +def p_module_item_3(p): + '''module_item : attribute_list_opt K_wreal delay3 net_variable_list ';' ''' + print(p) + # { real_type_t*tmpt = new real_type_t(real_type_t::REAL); + # pform_set_data_type(@2, tmpt, $4, NetNet::WIRE, $1); + # if ($3 != 0) { + # yyerror(@3, "sorry: net delays not supported."); + # delete $3; + # } + # delete $1; + # } +() +def p_module_item_4(p): + '''module_item : attribute_list_opt K_wreal net_variable_list ';' ''' + print(p) + # { real_type_t*tmpt = new real_type_t(real_type_t::REAL); + # pform_set_data_type(@2, tmpt, $3, NetNet::WIRE, $1); + # delete $1; + # } +() +def p_module_item_5(p): + '''module_item : attribute_list_opt net_type data_type_or_implicit delay3_opt net_decl_assigns ';' ''' + print(p) + # { data_type_t*data_type = $3; + # if (data_type == 0) { + # data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + # FILE_NAME(data_type, @2); + # } + # pform_makewire(@2, $4, str_strength, $5, $2, data_type); + # if ($1) { + # yywarn(@2, "Attributes are not supported on net declaration " + # "assignments and will be discarded."); + # delete $1; + # } + # } +() +def p_module_item_6(p): + '''module_item : attribute_list_opt net_type data_type_or_implicit drive_strength net_decl_assigns ';' ''' + print(p) + # { data_type_t*data_type = $3; + # if (data_type == 0) { + # data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); + # FILE_NAME(data_type, @2); + # } + # pform_makewire(@2, 0, $4, $5, $2, data_type); + # if ($1) { + # yywarn(@2, "Attributes are not supported on net declaration " + # "assignments and will be discarded."); + # delete $1; + # } + # } +() +def p_module_item_7(p): + '''module_item : attribute_list_opt K_wreal net_decl_assigns ';' ''' + print(p) + # { real_type_t*data_type = new real_type_t(real_type_t::REAL); + # pform_makewire(@2, 0, str_strength, $3, NetNet::WIRE, data_type); + # if ($1) { + # yywarn(@2, "Attributes are not supported on net declaration " + # "assignments and will be discarded."); + # delete $1; + # } + # } +() +def p_module_item_8(p): + '''module_item : K_trireg charge_strength_opt dimensions_opt delay3_opt list_of_identifiers ';' ''' + print(p) + # { yyerror(@1, "sorry: trireg nets not supported."); + # delete $3; + # delete $4; + # } +() +def p_module_item_9(p): + '''module_item : attribute_list_opt port_direction net_type data_type_or_implicit list_of_port_identifiers ';' ''' + print(p) + # { pform_module_define_port(@2, $5, $2, $3, $4, $1); } +() +def p_module_item_10(p): + '''module_item : attribute_list_opt port_direction K_wreal list_of_port_identifiers ';' ''' + print(p) + # { real_type_t*real_type = new real_type_t(real_type_t::REAL); + # pform_module_define_port(@2, $4, $2, NetNet::WIRE, real_type, $1); + # } +() +def p_module_item_11(p): + '''module_item : attribute_list_opt K_inout data_type_or_implicit list_of_port_identifiers ';' ''' + print(p) + # { NetNet::Type use_type = $3 ? NetNet::IMPLICIT : NetNet::NONE; + # if (vector_type_t*dtype = dynamic_cast ($3)) { + # if (dtype->implicit_flag) + # use_type = NetNet::NONE; + # } + # if (use_type == NetNet::NONE) + # pform_set_port_type(@2, $4, NetNet::PINOUT, $3, $1); + # else + # pform_module_define_port(@2, $4, NetNet::PINOUT, use_type, $3, $1); + # } +() +def p_module_item_12(p): + '''module_item : attribute_list_opt K_input data_type_or_implicit list_of_port_identifiers ';' ''' + print(p) + # { NetNet::Type use_type = $3 ? NetNet::IMPLICIT : NetNet::NONE; + # if (vector_type_t*dtype = dynamic_cast ($3)) { + # if (dtype->implicit_flag) + # use_type = NetNet::NONE; + # } + # if (use_type == NetNet::NONE) + # pform_set_port_type(@2, $4, NetNet::PINPUT, $3, $1); + # else + # pform_module_define_port(@2, $4, NetNet::PINPUT, use_type, $3, $1); + # } +() +def p_module_item_13(p): + '''module_item : attribute_list_opt K_output data_type_or_implicit list_of_variable_port_identifiers ';' ''' + print(p) + # { NetNet::Type use_type = $3 ? NetNet::IMPLICIT : NetNet::NONE; + # if (vector_type_t*dtype = dynamic_cast ($3)) { + # if (dtype->implicit_flag) + # use_type = NetNet::NONE; + # else if (dtype->reg_flag) + # use_type = NetNet::REG; + # else + # use_type = NetNet::IMPLICIT_REG; + # + # // The SystemVerilog types that can show up as + # // output ports are implicitly (on the inside) + # // variables because "reg" is not valid syntax + # // here. + # } else if (dynamic_cast ($3)) { + # use_type = NetNet::IMPLICIT_REG; + # } else if (dynamic_cast ($3)) { + # use_type = NetNet::IMPLICIT_REG; + # } else if (enum_type_t*etype = dynamic_cast ($3)) { + # if(etype->base_type == IVL_VT_LOGIC) + # use_type = NetNet::IMPLICIT_REG; + # } + # if (use_type == NetNet::NONE) + # pform_set_port_type(@2, $4, NetNet::POUTPUT, $3, $1); + # else + # pform_module_define_port(@2, $4, NetNet::POUTPUT, use_type, $3, $1); + # } +() +def p_module_item_14(p): + '''module_item : attribute_list_opt port_direction net_type data_type_or_implicit error ';' ''' + print(p) + # { yyerror(@2, "error: Invalid variable list in port declaration."); + # if ($1) delete $1; + # if ($4) delete $4; + # yyerrok; + # } +() +def p_module_item_15(p): + '''module_item : attribute_list_opt K_inout data_type_or_implicit error ';' ''' + print(p) + # { yyerror(@2, "error: Invalid variable list in port declaration."); + # if ($1) delete $1; + # if ($3) delete $3; + # yyerrok; + # } +() +def p_module_item_16(p): + '''module_item : attribute_list_opt K_input data_type_or_implicit error ';' ''' + print(p) + # { yyerror(@2, "error: Invalid variable list in port declaration."); + # if ($1) delete $1; + # if ($3) delete $3; + # yyerrok; + # } +() +def p_module_item_17(p): + '''module_item : attribute_list_opt K_output data_type_or_implicit error ';' ''' + print(p) + # { yyerror(@2, "error: Invalid variable list in port declaration."); + # if ($1) delete $1; + # if ($3) delete $3; + # yyerrok; + # } +() +def p_module_item_18(p): + '''module_item : DISCIPLINE_IDENTIFIER list_of_identifiers ';' ''' + print(p) + # { pform_attach_discipline(@1, $1, $2); } +() +def p_module_item_19(p): + '''module_item : attribute_list_opt _embed0_module_item block_item_decl ''' + print(p) + # { delete attributes_in_context; + # attributes_in_context = 0; + # } +() +def p_module_item_20(p): + '''module_item : K_defparam _embed1_module_item defparam_assign_list ';' ''' + print(p) +() +def p_module_item_21(p): + '''module_item : attribute_list_opt gatetype gate_instance_list ';' ''' + print(p) + # { pform_makegates(@2, $2, str_strength, 0, $3, $1); } +() +def p_module_item_22(p): + '''module_item : attribute_list_opt gatetype delay3 gate_instance_list ';' ''' + print(p) + # { pform_makegates(@2, $2, str_strength, $3, $4, $1); } +() +def p_module_item_23(p): + '''module_item : attribute_list_opt gatetype drive_strength gate_instance_list ';' ''' + print(p) + # { pform_makegates(@2, $2, $3, 0, $4, $1); } +() +def p_module_item_24(p): + '''module_item : attribute_list_opt gatetype drive_strength delay3 gate_instance_list ';' ''' + print(p) + # { pform_makegates(@2, $2, $3, $4, $5, $1); } +() +def p_module_item_25(p): + '''module_item : attribute_list_opt switchtype gate_instance_list ';' ''' + print(p) + # { pform_makegates(@2, $2, str_strength, 0, $3, $1); } +() +def p_module_item_26(p): + '''module_item : attribute_list_opt switchtype delay3 gate_instance_list ';' ''' + print(p) + # { pform_makegates(@2, $2, str_strength, $3, $4, $1); } +() +def p_module_item_27(p): + '''module_item : K_pullup gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLUP, pull_strength, 0, $2, 0); } +() +def p_module_item_28(p): + '''module_item : K_pulldown gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLDOWN, pull_strength, 0, $2, 0); } +() +def p_module_item_29(p): + '''module_item : K_pullup '(' dr_strength1 ')' gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLUP, $3, 0, $5, 0); } +() +def p_module_item_30(p): + '''module_item : K_pullup '(' dr_strength1 ',' dr_strength0 ')' gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLUP, $3, 0, $7, 0); } +() +def p_module_item_31(p): + '''module_item : K_pullup '(' dr_strength0 ',' dr_strength1 ')' gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLUP, $5, 0, $7, 0); } +() +def p_module_item_32(p): + '''module_item : K_pulldown '(' dr_strength0 ')' gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLDOWN, $3, 0, $5, 0); } +() +def p_module_item_33(p): + '''module_item : K_pulldown '(' dr_strength1 ',' dr_strength0 ')' gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLDOWN, $5, 0, $7, 0); } +() +def p_module_item_34(p): + '''module_item : K_pulldown '(' dr_strength0 ',' dr_strength1 ')' gate_instance_list ';' ''' + print(p) + # { pform_makegates(@1, PGBuiltin::PULLDOWN, $3, 0, $7, 0); } +() +def p_module_item_35(p): + '''module_item : attribute_list_opt IDENTIFIER parameter_value_opt gate_instance_list ';' ''' + print(p) + # { perm_string tmp1 = lex_strings.make($2); + # pform_make_modgates(@2, tmp1, $3, $4, $1); + # delete[]$2; + # } +() +def p_module_item_36(p): + '''module_item : attribute_list_opt IDENTIFIER parameter_value_opt error ';' ''' + print(p) + # { yyerror(@2, "error: Invalid module instantiation"); + # delete[]$2; + # if ($1) delete $1; + # } +() +def p_module_item_37(p): + '''module_item : K_assign drive_strength_opt delay3_opt cont_assign_list ';' ''' + print(p) + # { pform_make_pgassign_list($4, $3, $2, @1.text, @1.first_line); } +() +def p_module_item_38(p): + '''module_item : attribute_list_opt K_always statement_item ''' + print(p) + # { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS, $3, $1); + # FILE_NAME(tmp, @2); + # } +() +def p_module_item_39(p): + '''module_item : attribute_list_opt K_always_comb statement_item ''' + print(p) + # { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS_COMB, $3, $1); + # FILE_NAME(tmp, @2); + # } +() +def p_module_item_40(p): + '''module_item : attribute_list_opt K_always_ff statement_item ''' + print(p) + # { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS_FF, $3, $1); + # FILE_NAME(tmp, @2); + # } +() +def p_module_item_41(p): + '''module_item : attribute_list_opt K_always_latch statement_item ''' + print(p) + # { PProcess*tmp = pform_make_behavior(IVL_PR_ALWAYS_LATCH, $3, $1); + # FILE_NAME(tmp, @2); + # } +() +def p_module_item_42(p): + '''module_item : attribute_list_opt K_initial statement_item ''' + print(p) + # { PProcess*tmp = pform_make_behavior(IVL_PR_INITIAL, $3, $1); + # FILE_NAME(tmp, @2); + # } +() +def p_module_item_43(p): + '''module_item : attribute_list_opt K_final statement_item ''' + print(p) + # { PProcess*tmp = pform_make_behavior(IVL_PR_FINAL, $3, $1); + # FILE_NAME(tmp, @2); + # } +() +def p_module_item_44(p): + '''module_item : attribute_list_opt K_analog analog_statement ''' + print(p) + # { pform_make_analog_behavior(@2, IVL_PR_ALWAYS, $3); } +() +def p_module_item_45(p): + '''module_item : attribute_list_opt assertion_item ''' + print(p) +() +def p_module_item_46(p): + '''module_item : timeunits_declaration ''' + print(p) +() +def p_module_item_47(p): + '''module_item : class_declaration ''' + print(p) +() +def p_module_item_48(p): + '''module_item : task_declaration ''' + print(p) +() +def p_module_item_49(p): + '''module_item : function_declaration ''' + print(p) +() +def p_module_item_50(p): + '''module_item : K_generate generate_item_list_opt K_endgenerate ''' + print(p) + # { // Test for bad nesting. I understand it, but it is illegal. + # if (pform_parent_generate()) { + # cerr << @1 << ": error: Generate/endgenerate regions cannot nest." << endl; + # cerr << @1 << ": : Try removing optional generate/endgenerate keywords," << endl; + # cerr << @1 << ": : or move them to surround the parent generate scheme." << endl; + # error_count += 1; + # } + # } +() +def p_module_item_51(p): + '''module_item : K_genvar list_of_identifiers ';' ''' + print(p) + # { pform_genvars(@1, $2); } +() +def p_module_item_52(p): + '''module_item : K_for '(' IDENTIFIER '=' expression ';' expression ';' IDENTIFIER '=' expression ')' _embed2_module_item generate_block ''' + print(p) + # { pform_endgenerate(); } +() +def p_module_item_53(p): + '''module_item : generate_if generate_block_opt K_else _embed3_module_item generate_block ''' + print(p) + # { pform_endgenerate(); } +() +def p_module_item_54(p): + '''module_item : generate_if generate_block_opt %prec less_than_K_else ''' + print(p) + # { pform_endgenerate(); } +() +def p_module_item_55(p): + '''module_item : K_case '(' expression ')' _embed4_module_item generate_case_items K_endcase ''' + print(p) + # { pform_endgenerate(); } +() +def p_module_item_56(p): + '''module_item : modport_declaration ''' + print(p) +() +def p_module_item_57(p): + '''module_item : package_import_declaration ''' + print(p) +() +def p_module_item_58(p): + '''module_item : attribute_list_opt K_specparam _embed5_module_item specparam_decl ';' ''' + print(p) +() +def p_module_item_59(p): + '''module_item : K_specify _embed6_module_item specify_item_list_opt K_endspecify ''' + print(p) +() +def p_module_item_60(p): + '''module_item : K_specify error K_endspecify ''' + print(p) + # { yyerror(@1, "error: syntax error in specify block"); + # yyerrok; + # } +() +def p_module_item_61(p): + '''module_item : error ';' ''' + print(p) + # { yyerror(@2, "error: invalid module item."); + # yyerrok; + # } +() +def p_module_item_62(p): + '''module_item : K_assign error '=' expression ';' ''' + print(p) + # { yyerror(@1, "error: syntax error in left side " + # "of continuous assignment."); + # yyerrok; + # } +() +def p_module_item_63(p): + '''module_item : K_assign error ';' ''' + print(p) + # { yyerror(@1, "error: syntax error in " + # "continuous assignment"); + # yyerrok; + # } +() +def p_module_item_64(p): + '''module_item : K_function error K_endfunction endlabel_opt ''' + print(p) + # { yyerror(@1, "error: I give up on this " + # "function definition."); + # if ($4) { + # if (!gn_system_verilog()) { + # yyerror(@4, "error: Function end names require " + # "SystemVerilog."); + # } + # delete[]$4; + # } + # yyerrok; + # } +() +def p_module_item_65(p): + '''module_item : KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ';' ''' + print(p) + # { perm_string tmp3 = lex_strings.make($3); + # perm_string tmp5 = lex_strings.make($5); + # pform_set_attrib(tmp3, tmp5, $7); + # delete[] $3; + # delete[] $5; + # } +() +def p_module_item_66(p): + '''module_item : KK_attribute '(' error ')' ';' ''' + print(p) + # { yyerror(@1, "error: Malformed $attribute parameter list."); } +() +def p__embed0_module_item(p): + '''_embed0_module_item : ''' + # { attributes_in_context = $1; } +() +def p__embed1_module_item(p): + '''_embed1_module_item : ''' + # { if (pform_in_interface()) + # yyerror(@1, "error: Parameter overrides are not allowed " + # "in interfaces."); + # } +() +def p__embed2_module_item(p): + '''_embed2_module_item : ''' + # { pform_start_generate_for(@1, $3, $5, $7, $9, $11); } +() +def p__embed3_module_item(p): + '''_embed3_module_item : ''' + # { pform_start_generate_else(@1); } +() +def p__embed4_module_item(p): + '''_embed4_module_item : ''' + # { pform_start_generate_case(@1, $3); } +() +def p__embed5_module_item(p): + '''_embed5_module_item : ''' + # { if (pform_in_interface()) + # yyerror(@1, "error: specparam declarations are not allowed " + # "in interfaces."); + # } +() +def p__embed6_module_item(p): + '''_embed6_module_item : ''' + # { if (pform_in_interface()) + # yyerror(@1, "error: specify blocks are not allowed " + # "in interfaces."); + # } +() +def p_module_item_list_1(p): + '''module_item_list : module_item_list module_item ''' + print(p) +() +def p_module_item_list_2(p): + '''module_item_list : module_item ''' + print(p) +() +def p_module_item_list_opt_1(p): + '''module_item_list_opt : module_item_list ''' + print(p) +() +def p_module_item_list_opt_2(p): + '''module_item_list_opt : ''' + print(p) +() +def p_generate_if_1(p): + '''generate_if : K_if '(' expression ')' ''' + print(p) + # { pform_start_generate_if(@1, $3); } +() +def p_generate_case_items_1(p): + '''generate_case_items : generate_case_items generate_case_item ''' + print(p) +() +def p_generate_case_items_2(p): + '''generate_case_items : generate_case_item ''' + print(p) +() +def p_generate_case_item_1(p): + '''generate_case_item : expression_list_proper ':' _embed0_generate_case_item generate_block_opt ''' + print(p) + # { pform_endgenerate(); } +() +def p_generate_case_item_2(p): + '''generate_case_item : K_default ':' _embed1_generate_case_item generate_block_opt ''' + print(p) + # { pform_endgenerate(); } +() +def p__embed0_generate_case_item(p): + '''_embed0_generate_case_item : ''' + # { pform_generate_case_item(@1, $1); } +() +def p__embed1_generate_case_item(p): + '''_embed1_generate_case_item : ''' + # { pform_generate_case_item(@1, 0); } +() +def p_generate_item_1(p): + '''generate_item : module_item ''' + print(p) +() +def p_generate_item_2(p): + '''generate_item : K_begin generate_item_list_opt K_end ''' + print(p) + # { /* Detect and warn about anachronistic begin/end use */ + # if (generation_flag > GN_VER2001 && warn_anachronisms) { + # warn_count += 1; + # cerr << @1 << ": warning: Anachronistic use of begin/end to surround generate schemes." << endl; + # } + # } +() +def p_generate_item_3(p): + '''generate_item : K_begin ':' IDENTIFIER _embed0_generate_item generate_item_list_opt K_end ''' + print(p) + # { /* Detect and warn about anachronistic named begin/end use */ + # if (generation_flag > GN_VER2001 && warn_anachronisms) { + # warn_count += 1; + # cerr << @1 << ": warning: Anachronistic use of named begin/end to surround generate schemes." << endl; + # } + # pform_endgenerate(); + # } +() +def p__embed0_generate_item(p): + '''_embed0_generate_item : ''' + # { + # pform_start_generate_nblock(@1, $3); + # } +() +def p_generate_item_list_1(p): + '''generate_item_list : generate_item_list generate_item ''' + print(p) +() +def p_generate_item_list_2(p): + '''generate_item_list : generate_item ''' + print(p) +() +def p_generate_item_list_opt_1(p): + '''generate_item_list_opt : generate_item_list ''' + print(p) +() +def p_generate_item_list_opt_2(p): + '''generate_item_list_opt : ''' + print(p) +() +def p_generate_block_1(p): + '''generate_block : module_item ''' + print(p) +() +def p_generate_block_2(p): + '''generate_block : K_begin generate_item_list_opt K_end ''' + print(p) +() +def p_generate_block_3(p): + '''generate_block : K_begin ':' IDENTIFIER generate_item_list_opt K_end endlabel_opt ''' + print(p) + # { pform_generate_block_name($3); + # if ($6) { + # if (strcmp($3,$6) != 0) { + # yyerror(@6, "error: End label doesn't match " + # "begin name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@6, "error: Begin end labels require " + # "SystemVerilog."); + # } + # delete[]$6; + # } + # delete[]$3; + # } +() +def p_generate_block_opt_1(p): + '''generate_block_opt : generate_block ''' + print(p) +() +def p_generate_block_opt_2(p): + '''generate_block_opt : ';' ''' + print(p) +() +def p_net_decl_assign_1(p): + '''net_decl_assign : IDENTIFIER '=' expression ''' + print(p) + # { net_decl_assign_t*tmp = new net_decl_assign_t; + # tmp->next = tmp; + # tmp->name = lex_strings.make($1); + # tmp->expr = $3; + # delete[]$1; + # $$ = tmp; + # } +() +def p_net_decl_assigns_1(p): + '''net_decl_assigns : net_decl_assigns ',' net_decl_assign ''' + print(p) + # { net_decl_assign_t*tmp = $1; + # $3->next = tmp->next; + # tmp->next = $3; + # $$ = tmp; + # } +() +def p_net_decl_assigns_2(p): + '''net_decl_assigns : net_decl_assign ''' + print(p) + # { $$ = $1; + # } +() +def p_bit_logic_1(p): + '''bit_logic : K_logic ''' + print(p) + # { $$ = IVL_VT_LOGIC; } +() +def p_bit_logic_2(p): + '''bit_logic : K_bool ''' + print(p) + # { $$ = IVL_VT_BOOL; /* Icarus misc */} +() +def p_bit_logic_3(p): + '''bit_logic : K_bit ''' + print(p) + # { $$ = IVL_VT_BOOL; /* IEEE1800 / IEEE1364-2009 */} +() +def p_bit_logic_opt_1(p): + '''bit_logic_opt : bit_logic ''' + print(p) +() +def p_bit_logic_opt_2(p): + '''bit_logic_opt : ''' + print(p) + # { $$ = IVL_VT_NO_TYPE; } +() +def p_net_type_1(p): + '''net_type : K_wire ''' + print(p) + # { $$ = NetNet::WIRE; } +() +def p_net_type_2(p): + '''net_type : K_tri ''' + print(p) + # { $$ = NetNet::TRI; } +() +def p_net_type_3(p): + '''net_type : K_tri1 ''' + print(p) + # { $$ = NetNet::TRI1; } +() +def p_net_type_4(p): + '''net_type : K_supply0 ''' + print(p) + # { $$ = NetNet::SUPPLY0; } +() +def p_net_type_5(p): + '''net_type : K_wand ''' + print(p) + # { $$ = NetNet::WAND; } +() +def p_net_type_6(p): + '''net_type : K_triand ''' + print(p) + # { $$ = NetNet::TRIAND; } +() +def p_net_type_7(p): + '''net_type : K_tri0 ''' + print(p) + # { $$ = NetNet::TRI0; } +() +def p_net_type_8(p): + '''net_type : K_supply1 ''' + print(p) + # { $$ = NetNet::SUPPLY1; } +() +def p_net_type_9(p): + '''net_type : K_wor ''' + print(p) + # { $$ = NetNet::WOR; } +() +def p_net_type_10(p): + '''net_type : K_trior ''' + print(p) + # { $$ = NetNet::TRIOR; } +() +def p_net_type_11(p): + '''net_type : K_wone ''' + print(p) + # { $$ = NetNet::UNRESOLVED_WIRE; + # cerr << @1.text << ":" << @1.first_line << ": warning: " + # "'wone' is deprecated, please use 'uwire' " + # "instead." << endl; + # } +() +def p_net_type_12(p): + '''net_type : K_uwire ''' + print(p) + # { $$ = NetNet::UNRESOLVED_WIRE; } +() +def p_param_type_1(p): + '''param_type : bit_logic_opt unsigned_signed_opt dimensions_opt ''' + print(p) + # { param_active_range = $3; + # param_active_signed = $2; + # if (($1 == IVL_VT_NO_TYPE) && ($3 != 0)) + # param_active_type = IVL_VT_LOGIC; + # else + # param_active_type = $1; + # } +() +def p_param_type_2(p): + '''param_type : K_integer ''' + print(p) + # { param_active_range = make_range_from_width(integer_width); + # param_active_signed = true; + # param_active_type = IVL_VT_LOGIC; + # } +() +def p_param_type_3(p): + '''param_type : K_time ''' + print(p) + # { param_active_range = make_range_from_width(64); + # param_active_signed = false; + # param_active_type = IVL_VT_LOGIC; + # } +() +def p_param_type_4(p): + '''param_type : real_or_realtime ''' + print(p) + # { param_active_range = 0; + # param_active_signed = true; + # param_active_type = IVL_VT_REAL; + # } +() +def p_param_type_5(p): + '''param_type : atom2_type ''' + print(p) + # { param_active_range = make_range_from_width($1); + # param_active_signed = true; + # param_active_type = IVL_VT_BOOL; + # } +() +def p_param_type_6(p): + '''param_type : TYPE_IDENTIFIER ''' + print(p) + # { pform_set_param_from_type(@1, $1.type, $1.text, param_active_range, + # param_active_signed, param_active_type); + # delete[]$1.text; + # } +() +def p_parameter_assign_list_1(p): + '''parameter_assign_list : parameter_assign ''' + print(p) +() +def p_parameter_assign_list_2(p): + '''parameter_assign_list : parameter_assign_list ',' parameter_assign ''' + print(p) +() +def p_localparam_assign_list_1(p): + '''localparam_assign_list : localparam_assign ''' + print(p) +() +def p_localparam_assign_list_2(p): + '''localparam_assign_list : localparam_assign_list ',' localparam_assign ''' + print(p) +() +def p_parameter_assign_1(p): + '''parameter_assign : IDENTIFIER '=' expression parameter_value_ranges_opt ''' + print(p) + # { PExpr*tmp = $3; + # pform_set_parameter(@1, lex_strings.make($1), param_active_type, + # param_active_signed, param_active_range, tmp, $4); + # delete[]$1; + # } +() +def p_localparam_assign_1(p): + '''localparam_assign : IDENTIFIER '=' expression ''' + print(p) + # { PExpr*tmp = $3; + # pform_set_localparam(@1, lex_strings.make($1), param_active_type, + # param_active_signed, param_active_range, tmp); + # delete[]$1; + # } +() +def p_parameter_value_ranges_opt_1(p): + '''parameter_value_ranges_opt : parameter_value_ranges ''' + print(p) + # { $$ = $1; } +() +def p_parameter_value_ranges_opt_2(p): + '''parameter_value_ranges_opt : ''' + print(p) + # { $$ = 0; } +() +def p_parameter_value_ranges_1(p): + '''parameter_value_ranges : parameter_value_ranges parameter_value_range ''' + print(p) + # { $$ = $2; $$->next = $1; } +() +def p_parameter_value_ranges_2(p): + '''parameter_value_ranges : parameter_value_range ''' + print(p) + # { $$ = $1; $$->next = 0; } +() +def p_parameter_value_range_1(p): + '''parameter_value_range : from_exclude '[' value_range_expression ':' value_range_expression ']' ''' + print(p) + # { $$ = pform_parameter_value_range($1, false, $3, false, $5); } +() +def p_parameter_value_range_2(p): + '''parameter_value_range : from_exclude '[' value_range_expression ':' value_range_expression ')' ''' + print(p) + # { $$ = pform_parameter_value_range($1, false, $3, true, $5); } +() +def p_parameter_value_range_3(p): + '''parameter_value_range : from_exclude '(' value_range_expression ':' value_range_expression ']' ''' + print(p) + # { $$ = pform_parameter_value_range($1, true, $3, false, $5); } +() +def p_parameter_value_range_4(p): + '''parameter_value_range : from_exclude '(' value_range_expression ':' value_range_expression ')' ''' + print(p) + # { $$ = pform_parameter_value_range($1, true, $3, true, $5); } +() +def p_parameter_value_range_5(p): + '''parameter_value_range : K_exclude expression ''' + print(p) + # { $$ = pform_parameter_value_range(true, false, $2, false, $2); } +() +def p_value_range_expression_1(p): + '''value_range_expression : expression ''' + print(p) + # { $$ = $1; } +() +def p_value_range_expression_2(p): + '''value_range_expression : K_inf ''' + print(p) + # { $$ = 0; } +() +def p_value_range_expression_3(p): + '''value_range_expression : '+' K_inf ''' + print(p) + # { $$ = 0; } +() +def p_value_range_expression_4(p): + '''value_range_expression : '-' K_inf ''' + print(p) + # { $$ = 0; } +() +def p_from_exclude_1(p): + '''from_exclude : K_from ''' + print(p) + # { $$ = false; } +() +def p_from_exclude_2(p): + '''from_exclude : K_exclude ''' + print(p) + # { $$ = true; } +() +def p_parameter_value_opt_1(p): + '''parameter_value_opt : '#' '(' expression_list_with_nuls ')' ''' + print(p) + # { struct parmvalue_t*tmp = new struct parmvalue_t; + # tmp->by_order = $3; + # tmp->by_name = 0; + # $$ = tmp; + # } +() +def p_parameter_value_opt_2(p): + '''parameter_value_opt : '#' '(' parameter_value_byname_list ')' ''' + print(p) + # { struct parmvalue_t*tmp = new struct parmvalue_t; + # tmp->by_order = 0; + # tmp->by_name = $3; + # $$ = tmp; + # } +() +def p_parameter_value_opt_3(p): + '''parameter_value_opt : '#' DEC_NUMBER ''' + print(p) + # { assert($2); + # PENumber*tmp = new PENumber($2); + # FILE_NAME(tmp, @1); + # + # struct parmvalue_t*lst = new struct parmvalue_t; + # lst->by_order = new list; + # lst->by_order->push_back(tmp); + # lst->by_name = 0; + # $$ = lst; + # based_size = 0; + # } +() +def p_parameter_value_opt_4(p): + '''parameter_value_opt : '#' REALTIME ''' + print(p) + # { assert($2); + # PEFNumber*tmp = new PEFNumber($2); + # FILE_NAME(tmp, @1); + # + # struct parmvalue_t*lst = new struct parmvalue_t; + # lst->by_order = new list; + # lst->by_order->push_back(tmp); + # lst->by_name = 0; + # $$ = lst; + # } +() +def p_parameter_value_opt_5(p): + '''parameter_value_opt : '#' error ''' + print(p) + # { yyerror(@1, "error: syntax error in parameter value " + # "assignment list."); + # $$ = 0; + # } +() +def p_parameter_value_opt_6(p): + '''parameter_value_opt : ''' + print(p) + # { $$ = 0; } +() +def p_parameter_value_byname_1(p): + '''parameter_value_byname : '.' IDENTIFIER '(' expression ')' ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($2); + # tmp->parm = $4; + # delete[]$2; + # $$ = tmp; + # } +() +def p_parameter_value_byname_2(p): + '''parameter_value_byname : '.' IDENTIFIER '(' ')' ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($2); + # tmp->parm = 0; + # delete[]$2; + # $$ = tmp; + # } +() +def p_parameter_value_byname_list_1(p): + '''parameter_value_byname_list : parameter_value_byname ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(*$1); + # delete $1; + # $$ = tmp; + # } +() +def p_parameter_value_byname_list_2(p): + '''parameter_value_byname_list : parameter_value_byname_list ',' parameter_value_byname ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(*$3); + # delete $3; + # $$ = tmp; + # } +() +def p_port_1(p): + '''port : port_reference ''' + print(p) + # { $$ = $1; } +() +def p_port_2(p): + '''port : '.' IDENTIFIER '(' port_reference ')' ''' + print(p) + # { Module::port_t*tmp = $4; + # tmp->name = lex_strings.make($2); + # delete[]$2; + # $$ = tmp; + # } +() +def p_port_3(p): + '''port : '{' port_reference_list '}' ''' + print(p) + # { Module::port_t*tmp = $2; + # tmp->name = perm_string(); + # $$ = tmp; + # } +() +def p_port_4(p): + '''port : '.' IDENTIFIER '(' '{' port_reference_list '}' ')' ''' + print(p) + # { Module::port_t*tmp = $5; + # tmp->name = lex_strings.make($2); + # delete[]$2; + # $$ = tmp; + # } +() +def p_port_opt_1(p): + '''port_opt : port ''' + print(p) + # { $$ = $1; } +() +def p_port_opt_2(p): + '''port_opt : ''' + print(p) + # { $$ = 0; } +() +def p_port_name_1(p): + '''port_name : '.' IDENTIFIER '(' expression ')' ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($2); + # tmp->parm = $4; + # delete[]$2; + # $$ = tmp; + # } +() +def p_port_name_2(p): + '''port_name : '.' IDENTIFIER '(' error ')' ''' + print(p) + # { yyerror(@3, "error: invalid port connection expression."); + # named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($2); + # tmp->parm = 0; + # delete[]$2; + # $$ = tmp; + # } +() +def p_port_name_3(p): + '''port_name : '.' IDENTIFIER '(' ')' ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($2); + # tmp->parm = 0; + # delete[]$2; + # $$ = tmp; + # } +() +def p_port_name_4(p): + '''port_name : '.' IDENTIFIER ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make($2); + # tmp->parm = new PEIdent(lex_strings.make($2), true); + # FILE_NAME(tmp->parm, @1); + # delete[]$2; + # $$ = tmp; + # } +() +def p_port_name_5(p): + '''port_name : K_DOTSTAR ''' + print(p) + # { named_pexpr_t*tmp = new named_pexpr_t; + # tmp->name = lex_strings.make("*"); + # tmp->parm = 0; + # $$ = tmp; + # } +() +def p_port_name_list_1(p): + '''port_name_list : port_name_list ',' port_name ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(*$3); + # delete $3; + # $$ = tmp; + # } +() +def p_port_name_list_2(p): + '''port_name_list : port_name ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(*$1); + # delete $1; + # $$ = tmp; + # } +() +def p_port_reference_1(p): + '''port_reference : IDENTIFIER ''' + print(p) + # { Module::port_t*ptmp; + # perm_string name = lex_strings.make($1); + # ptmp = pform_module_port_reference(name, @1.text, @1.first_line); + # delete[]$1; + # $$ = ptmp; + # } +() +def p_port_reference_2(p): + '''port_reference : IDENTIFIER '[' expression ':' expression ']' ''' + print(p) + # { index_component_t itmp; + # itmp.sel = index_component_t::SEL_PART; + # itmp.msb = $3; + # itmp.lsb = $5; + # + # name_component_t ntmp (lex_strings.make($1)); + # ntmp.index.push_back(itmp); + # + # pform_name_t pname; + # pname.push_back(ntmp); + # + # PEIdent*wtmp = new PEIdent(pname); + # FILE_NAME(wtmp, @1); + # + # Module::port_t*ptmp = new Module::port_t; + # ptmp->name = perm_string(); + # ptmp->expr.push_back(wtmp); + # + # delete[]$1; + # $$ = ptmp; + # } +() +def p_port_reference_3(p): + '''port_reference : IDENTIFIER '[' expression ']' ''' + print(p) + # { index_component_t itmp; + # itmp.sel = index_component_t::SEL_BIT; + # itmp.msb = $3; + # itmp.lsb = 0; + # + # name_component_t ntmp (lex_strings.make($1)); + # ntmp.index.push_back(itmp); + # + # pform_name_t pname; + # pname.push_back(ntmp); + # + # PEIdent*tmp = new PEIdent(pname); + # FILE_NAME(tmp, @1); + # + # Module::port_t*ptmp = new Module::port_t; + # ptmp->name = perm_string(); + # ptmp->expr.push_back(tmp); + # delete[]$1; + # $$ = ptmp; + # } +() +def p_port_reference_4(p): + '''port_reference : IDENTIFIER '[' error ']' ''' + print(p) + # { yyerror(@1, "error: invalid port bit select"); + # Module::port_t*ptmp = new Module::port_t; + # PEIdent*wtmp = new PEIdent(lex_strings.make($1)); + # FILE_NAME(wtmp, @1); + # ptmp->name = lex_strings.make($1); + # ptmp->expr.push_back(wtmp); + # delete[]$1; + # $$ = ptmp; + # } +() +def p_port_reference_list_1(p): + '''port_reference_list : port_reference ''' + print(p) + # { $$ = $1; } +() +def p_port_reference_list_2(p): + '''port_reference_list : port_reference_list ',' port_reference ''' + print(p) + # { Module::port_t*tmp = $1; + # append(tmp->expr, $3->expr); + # delete $3; + # $$ = tmp; + # } +() +def p_dimensions_opt_1(p): + '''dimensions_opt : ''' + print(p) + # { $$ = 0; } +() +def p_dimensions_opt_2(p): + '''dimensions_opt : dimensions ''' + print(p) + # { $$ = $1; } +() +def p_dimensions_1(p): + '''dimensions : variable_dimension ''' + print(p) + # { $$ = $1; } +() +def p_dimensions_2(p): + '''dimensions : dimensions variable_dimension ''' + print(p) + # { list *tmp = $1; + # if ($2) { + # tmp->splice(tmp->end(), *$2); + # delete $2; + # } + # $$ = tmp; + # } +() +def p_register_variable_1(p): + '''register_variable : IDENTIFIER dimensions_opt ''' + print(p) + # { perm_string name = lex_strings.make($1); + # pform_makewire(@1, name, NetNet::REG, + # NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0); + # pform_set_reg_idx(name, $2); + # $$ = $1; + # } +() +def p_register_variable_2(p): + '''register_variable : IDENTIFIER dimensions_opt '=' expression ''' + print(p) + # { if (pform_peek_scope()->var_init_needs_explicit_lifetime() + # && (var_lifetime == LexicalScope::INHERITED)) { + # cerr << @3 << ": warning: Static variable initialization requires " + # "explicit lifetime in this context." << endl; + # warn_count += 1; + # } + # perm_string name = lex_strings.make($1); + # pform_makewire(@1, name, NetNet::REG, + # NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0); + # pform_set_reg_idx(name, $2); + # pform_make_var_init(@1, name, $4); + # $$ = $1; + # } +() +def p_register_variable_list_1(p): + '''register_variable_list : register_variable ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # $$ = tmp; + # delete[]$1; + # } +() +def p_register_variable_list_2(p): + '''register_variable_list : register_variable_list ',' register_variable ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # $$ = tmp; + # delete[]$3; + # } +() +def p_net_variable_1(p): + '''net_variable : IDENTIFIER dimensions_opt ''' + print(p) + # { perm_string name = lex_strings.make($1); + # pform_makewire(@1, name, NetNet::IMPLICIT, + # NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0); + # pform_set_reg_idx(name, $2); + # $$ = $1; + # } +() +def p_net_variable_list_1(p): + '''net_variable_list : net_variable ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # $$ = tmp; + # delete[]$1; + # } +() +def p_net_variable_list_2(p): + '''net_variable_list : net_variable_list ',' net_variable ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # $$ = tmp; + # delete[]$3; + # } +() +def p_event_variable_1(p): + '''event_variable : IDENTIFIER dimensions_opt ''' + print(p) + # { if ($2) { + # yyerror(@2, "sorry: event arrays are not supported."); + # delete $2; + # } + # $$ = $1; + # } +() +def p_event_variable_list_1(p): + '''event_variable_list : event_variable ''' + print(p) + # { $$ = list_from_identifier($1); } +() +def p_event_variable_list_2(p): + '''event_variable_list : event_variable_list ',' event_variable ''' + print(p) + # { $$ = list_from_identifier($1, $3); } +() +def p_specify_item_1(p): + '''specify_item : K_specparam specparam_decl ';' ''' + print(p) +() +def p_specify_item_2(p): + '''specify_item : specify_simple_path_decl ';' ''' + print(p) + # { pform_module_specify_path($1); + # } +() +def p_specify_item_3(p): + '''specify_item : specify_edge_path_decl ';' ''' + print(p) + # { pform_module_specify_path($1); + # } +() +def p_specify_item_4(p): + '''specify_item : K_if '(' expression ')' specify_simple_path_decl ';' ''' + print(p) + # { PSpecPath*tmp = $5; + # if (tmp) { + # tmp->conditional = true; + # tmp->condition = $3; + # } + # pform_module_specify_path(tmp); + # } +() +def p_specify_item_5(p): + '''specify_item : K_if '(' expression ')' specify_edge_path_decl ';' ''' + print(p) + # { PSpecPath*tmp = $5; + # if (tmp) { + # tmp->conditional = true; + # tmp->condition = $3; + # } + # pform_module_specify_path(tmp); + # } +() +def p_specify_item_6(p): + '''specify_item : K_ifnone specify_simple_path_decl ';' ''' + print(p) + # { PSpecPath*tmp = $2; + # if (tmp) { + # tmp->conditional = true; + # tmp->condition = 0; + # } + # pform_module_specify_path(tmp); + # } +() +def p_specify_item_7(p): + '''specify_item : K_ifnone specify_edge_path_decl ';' ''' + print(p) + # { yyerror(@1, "Sorry: ifnone with an edge-sensitive path is " + # "not supported."); + # yyerrok; + # } +() +def p_specify_item_8(p): + '''specify_item : K_Sfullskew '(' spec_reference_event ',' spec_reference_event ',' delay_value ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # delete $9; + # } +() +def p_specify_item_9(p): + '''specify_item : K_Shold '(' spec_reference_event ',' spec_reference_event ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # } +() +def p_specify_item_10(p): + '''specify_item : K_Snochange '(' spec_reference_event ',' spec_reference_event ',' delay_value ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # delete $9; + # } +() +def p_specify_item_11(p): + '''specify_item : K_Speriod '(' spec_reference_event ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $5; + # } +() +def p_specify_item_12(p): + '''specify_item : K_Srecovery '(' spec_reference_event ',' spec_reference_event ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # } +() +def p_specify_item_13(p): + '''specify_item : K_Srecrem '(' spec_reference_event ',' spec_reference_event ',' delay_value ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # delete $9; + # } +() +def p_specify_item_14(p): + '''specify_item : K_Sremoval '(' spec_reference_event ',' spec_reference_event ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # } +() +def p_specify_item_15(p): + '''specify_item : K_Ssetup '(' spec_reference_event ',' spec_reference_event ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # } +() +def p_specify_item_16(p): + '''specify_item : K_Ssetuphold '(' spec_reference_event ',' spec_reference_event ',' delay_value ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # delete $9; + # } +() +def p_specify_item_17(p): + '''specify_item : K_Sskew '(' spec_reference_event ',' spec_reference_event ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # } +() +def p_specify_item_18(p): + '''specify_item : K_Stimeskew '(' spec_reference_event ',' spec_reference_event ',' delay_value spec_notifier_opt ')' ';' ''' + print(p) + # { delete $7; + # } +() +def p_specify_item_19(p): + '''specify_item : K_Swidth '(' spec_reference_event ',' delay_value ',' expression spec_notifier_opt ')' ';' ''' + print(p) + # { delete $5; + # delete $7; + # } +() +def p_specify_item_20(p): + '''specify_item : K_Swidth '(' spec_reference_event ',' delay_value ')' ';' ''' + print(p) + # { delete $5; + # } +() +def p_specify_item_21(p): + '''specify_item : K_pulsestyle_onevent specify_path_identifiers ';' ''' + print(p) + # { delete $2; + # } +() +def p_specify_item_22(p): + '''specify_item : K_pulsestyle_ondetect specify_path_identifiers ';' ''' + print(p) + # { delete $2; + # } +() +def p_specify_item_23(p): + '''specify_item : K_showcancelled specify_path_identifiers ';' ''' + print(p) + # { delete $2; + # } +() +def p_specify_item_24(p): + '''specify_item : K_noshowcancelled specify_path_identifiers ';' ''' + print(p) + # { delete $2; + # } +() +def p_specify_item_list_1(p): + '''specify_item_list : specify_item ''' + print(p) +() +def p_specify_item_list_2(p): + '''specify_item_list : specify_item_list specify_item ''' + print(p) +() +def p_specify_item_list_opt_1(p): + '''specify_item_list_opt : ''' + print(p) + # { } +() +def p_specify_item_list_opt_2(p): + '''specify_item_list_opt : specify_item_list ''' + print(p) + # { } +() +def p_specify_edge_path_decl_1(p): + '''specify_edge_path_decl : specify_edge_path '=' '(' delay_value_list ')' ''' + print(p) + # { $$ = pform_assign_path_delay($1, $4); } +() +def p_specify_edge_path_decl_2(p): + '''specify_edge_path_decl : specify_edge_path '=' delay_value_simple ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($3); + # $$ = pform_assign_path_delay($1, tmp); + # } +() +def p_edge_operator_1(p): + '''edge_operator : K_posedge ''' + print(p) + # { $$ = true; } +() +def p_edge_operator_2(p): + '''edge_operator : K_negedge ''' + print(p) + # { $$ = false; } +() +def p_specify_edge_path_1(p): + '''specify_edge_path : '(' specify_path_identifiers spec_polarity K_EG '(' specify_path_identifiers polarity_operator expression ')' ')' ''' + print(p) + # { int edge_flag = 0; + # $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, false, $6, $8); } +() +def p_specify_edge_path_2(p): + '''specify_edge_path : '(' edge_operator specify_path_identifiers spec_polarity K_EG '(' specify_path_identifiers polarity_operator expression ')' ')' ''' + print(p) + # { int edge_flag = $2? 1 : -1; + # $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, false, $7, $9);} +() +def p_specify_edge_path_3(p): + '''specify_edge_path : '(' specify_path_identifiers spec_polarity K_SG '(' specify_path_identifiers polarity_operator expression ')' ')' ''' + print(p) + # { int edge_flag = 0; + # $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, true, $6, $8); } +() +def p_specify_edge_path_4(p): + '''specify_edge_path : '(' edge_operator specify_path_identifiers spec_polarity K_SG '(' specify_path_identifiers polarity_operator expression ')' ')' ''' + print(p) + # { int edge_flag = $2? 1 : -1; + # $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, true, $7, $9); } +() +def p_polarity_operator_1(p): + '''polarity_operator : K_PO_POS ''' + print(p) +() +def p_polarity_operator_2(p): + '''polarity_operator : K_PO_NEG ''' + print(p) +() +def p_polarity_operator_3(p): + '''polarity_operator : ':' ''' + print(p) +() +def p_specify_simple_path_decl_1(p): + '''specify_simple_path_decl : specify_simple_path '=' '(' delay_value_list ')' ''' + print(p) + # { $$ = pform_assign_path_delay($1, $4); } +() +def p_specify_simple_path_decl_2(p): + '''specify_simple_path_decl : specify_simple_path '=' delay_value_simple ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($3); + # $$ = pform_assign_path_delay($1, tmp); + # } +() +def p_specify_simple_path_decl_3(p): + '''specify_simple_path_decl : specify_simple_path '=' '(' error ')' ''' + print(p) + # { yyerror(@3, "Syntax error in delay value list."); + # yyerrok; + # $$ = 0; + # } +() +def p_specify_simple_path_1(p): + '''specify_simple_path : '(' specify_path_identifiers spec_polarity K_EG specify_path_identifiers ')' ''' + print(p) + # { $$ = pform_make_specify_path(@1, $2, $3, false, $5); } +() +def p_specify_simple_path_2(p): + '''specify_simple_path : '(' specify_path_identifiers spec_polarity K_SG specify_path_identifiers ')' ''' + print(p) + # { $$ = pform_make_specify_path(@1, $2, $3, true, $5); } +() +def p_specify_simple_path_3(p): + '''specify_simple_path : '(' error ')' ''' + print(p) + # { yyerror(@1, "Invalid simple path"); + # yyerrok; + # } +() +def p_specify_path_identifiers_1(p): + '''specify_path_identifiers : IDENTIFIER ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # $$ = tmp; + # delete[]$1; + # } +() +def p_specify_path_identifiers_2(p): + '''specify_path_identifiers : IDENTIFIER '[' expr_primary ']' ''' + print(p) + # { if (gn_specify_blocks_flag) { + # yywarn(@4, "Bit selects are not currently supported " + # "in path declarations. The declaration " + # "will be applied to the whole vector."); + # } + # list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # $$ = tmp; + # delete[]$1; + # } +() +def p_specify_path_identifiers_3(p): + '''specify_path_identifiers : IDENTIFIER '[' expr_primary polarity_operator expr_primary ']' ''' + print(p) + # { if (gn_specify_blocks_flag) { + # yywarn(@4, "Part selects are not currently supported " + # "in path declarations. The declaration " + # "will be applied to the whole vector."); + # } + # list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # $$ = tmp; + # delete[]$1; + # } +() +def p_specify_path_identifiers_4(p): + '''specify_path_identifiers : specify_path_identifiers ',' IDENTIFIER ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # $$ = tmp; + # delete[]$3; + # } +() +def p_specify_path_identifiers_5(p): + '''specify_path_identifiers : specify_path_identifiers ',' IDENTIFIER '[' expr_primary ']' ''' + print(p) + # { if (gn_specify_blocks_flag) { + # yywarn(@4, "Bit selects are not currently supported " + # "in path declarations. The declaration " + # "will be applied to the whole vector."); + # } + # list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # $$ = tmp; + # delete[]$3; + # } +() +def p_specify_path_identifiers_6(p): + '''specify_path_identifiers : specify_path_identifiers ',' IDENTIFIER '[' expr_primary polarity_operator expr_primary ']' ''' + print(p) + # { if (gn_specify_blocks_flag) { + # yywarn(@4, "Part selects are not currently supported " + # "in path declarations. The declaration " + # "will be applied to the whole vector."); + # } + # list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # $$ = tmp; + # delete[]$3; + # } +() +def p_specparam_1(p): + '''specparam : IDENTIFIER '=' expression ''' + print(p) + # { PExpr*tmp = $3; + # pform_set_specparam(@1, lex_strings.make($1), + # param_active_range, tmp); + # delete[]$1; + # } +() +def p_specparam_2(p): + '''specparam : IDENTIFIER '=' expression ':' expression ':' expression ''' + print(p) + # { PExpr*tmp = 0; + # switch (min_typ_max_flag) { + # case MIN: + # tmp = $3; + # delete $5; + # delete $7; + # break; + # case TYP: + # delete $3; + # tmp = $5; + # delete $7; + # break; + # case MAX: + # delete $3; + # delete $5; + # tmp = $7; + # break; + # } + # if (min_typ_max_warn > 0) { + # cerr << tmp->get_fileline() << ": warning: choosing "; + # switch (min_typ_max_flag) { + # case MIN: + # cerr << "min"; + # break; + # case TYP: + # cerr << "typ"; + # break; + # case MAX: + # cerr << "max"; + # break; + # } + # cerr << " expression." << endl; + # min_typ_max_warn -= 1; + # } + # pform_set_specparam(@1, lex_strings.make($1), + # param_active_range, tmp); + # delete[]$1; + # } +() +def p_specparam_3(p): + '''specparam : PATHPULSE_IDENTIFIER '=' expression ''' + print(p) + # { delete[]$1; + # delete $3; + # } +() +def p_specparam_4(p): + '''specparam : PATHPULSE_IDENTIFIER '=' '(' expression ',' expression ')' ''' + print(p) + # { delete[]$1; + # delete $4; + # delete $6; + # } +() +def p_specparam_list_1(p): + '''specparam_list : specparam ''' + print(p) +() +def p_specparam_list_2(p): + '''specparam_list : specparam_list ',' specparam ''' + print(p) +() +def p_specparam_decl_1(p): + '''specparam_decl : specparam_list ''' + print(p) +() +def p_specparam_decl_2(p): + '''specparam_decl : dimensions _embed0_specparam_decl specparam_list ''' + print(p) + # { param_active_range = 0; } +() +def p__embed0_specparam_decl(p): + '''_embed0_specparam_decl : ''' + # { param_active_range = $1; } +() +def p_spec_polarity_1(p): + '''spec_polarity : '+' ''' + print(p) + # { $$ = '+'; } +() +def p_spec_polarity_2(p): + '''spec_polarity : '-' ''' + print(p) + # { $$ = '-'; } +() +def p_spec_polarity_3(p): + '''spec_polarity : ''' + print(p) + # { $$ = 0; } +() +def p_spec_reference_event_1(p): + '''spec_reference_event : K_posedge expression ''' + print(p) + # { delete $2; } +() +def p_spec_reference_event_2(p): + '''spec_reference_event : K_negedge expression ''' + print(p) + # { delete $2; } +() +def p_spec_reference_event_3(p): + '''spec_reference_event : K_posedge expr_primary K_TAND expression ''' + print(p) + # { delete $2; + # delete $4; + # } +() +def p_spec_reference_event_4(p): + '''spec_reference_event : K_negedge expr_primary K_TAND expression ''' + print(p) + # { delete $2; + # delete $4; + # } +() +def p_spec_reference_event_5(p): + '''spec_reference_event : K_edge '[' edge_descriptor_list ']' expr_primary ''' + print(p) + # { delete $5; } +() +def p_spec_reference_event_6(p): + '''spec_reference_event : K_edge '[' edge_descriptor_list ']' expr_primary K_TAND expression ''' + print(p) + # { delete $5; + # delete $7; + # } +() +def p_spec_reference_event_7(p): + '''spec_reference_event : expr_primary K_TAND expression ''' + print(p) + # { delete $1; + # delete $3; + # } +() +def p_spec_reference_event_8(p): + '''spec_reference_event : expr_primary ''' + print(p) + # { delete $1; } +() +def p_edge_descriptor_list_1(p): + '''edge_descriptor_list : edge_descriptor_list ',' K_edge_descriptor ''' + print(p) +() +def p_edge_descriptor_list_2(p): + '''edge_descriptor_list : K_edge_descriptor ''' + print(p) +() +def p_spec_notifier_opt_1(p): + '''spec_notifier_opt : ''' + print(p) + # { } +() +def p_spec_notifier_opt_2(p): + '''spec_notifier_opt : spec_notifier ''' + print(p) + # { } +() +def p_spec_notifier_1(p): + '''spec_notifier : ',' ''' + print(p) + # { args_after_notifier = 0; } +() +def p_spec_notifier_2(p): + '''spec_notifier : ',' hierarchy_identifier ''' + print(p) + # { args_after_notifier = 0; delete $2; } +() +def p_spec_notifier_3(p): + '''spec_notifier : spec_notifier ',' ''' + print(p) + # { args_after_notifier += 1; } +() +def p_spec_notifier_4(p): + '''spec_notifier : spec_notifier ',' hierarchy_identifier ''' + print(p) + # { args_after_notifier += 1; + # if (args_after_notifier >= 3) { + # cerr << @3 << ": warning: timing checks are not supported " + # "and delayed signal \"" << *$3 + # << "\" will not be driven." << endl; + # } + # delete $3; } +() +def p_spec_notifier_5(p): + '''spec_notifier : IDENTIFIER ''' + print(p) + # { args_after_notifier = 0; delete[]$1; } +() +def p_statement_item_1(p): + '''statement_item : K_assign lpvalue '=' expression ';' ''' + print(p) + # { PCAssign*tmp = new PCAssign($2, $4); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_2(p): + '''statement_item : K_deassign lpvalue ';' ''' + print(p) + # { PDeassign*tmp = new PDeassign($2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_3(p): + '''statement_item : K_force lpvalue '=' expression ';' ''' + print(p) + # { PForce*tmp = new PForce($2, $4); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_4(p): + '''statement_item : K_release lpvalue ';' ''' + print(p) + # { PRelease*tmp = new PRelease($2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_5(p): + '''statement_item : K_begin K_end ''' + print(p) + # { PBlock*tmp = new PBlock(PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_6(p): + '''statement_item : K_begin _embed0_statement_item block_item_decls_opt _embed1_statement_item statement_or_null_list K_end ''' + print(p) + # { PBlock*tmp; + # if ($3) { + # pform_pop_scope(); + # assert(! current_block_stack.empty()); + # tmp = current_block_stack.top(); + # current_block_stack.pop(); + # } else { + # tmp = new PBlock(PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # } + # if ($5) tmp->set_statement(*$5); + # delete $5; + # $$ = tmp; + # } +() +def p_statement_item_7(p): + '''statement_item : K_begin ':' IDENTIFIER _embed2_statement_item block_item_decls_opt statement_or_null_list_opt K_end endlabel_opt ''' + print(p) + # { pform_pop_scope(); + # assert(! current_block_stack.empty()); + # PBlock*tmp = current_block_stack.top(); + # current_block_stack.pop(); + # if ($6) tmp->set_statement(*$6); + # delete $6; + # if ($8) { + # if (strcmp($3,$8) != 0) { + # yyerror(@8, "error: End label doesn't match begin name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@8, "error: Begin end labels require " + # "SystemVerilog."); + # } + # delete[]$8; + # } + # delete[]$3; + # $$ = tmp; + # } +() +def p_statement_item_8(p): + '''statement_item : K_fork join_keyword ''' + print(p) + # { PBlock*tmp = new PBlock($2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_9(p): + '''statement_item : K_fork _embed3_statement_item block_item_decls_opt _embed4_statement_item statement_or_null_list join_keyword ''' + print(p) + # { PBlock*tmp; + # if ($3) { + # pform_pop_scope(); + # assert(! current_block_stack.empty()); + # tmp = current_block_stack.top(); + # current_block_stack.pop(); + # tmp->set_join_type($6); + # } else { + # tmp = new PBlock($6); + # FILE_NAME(tmp, @1); + # } + # if ($5) tmp->set_statement(*$5); + # delete $5; + # $$ = tmp; + # } +() +def p_statement_item_10(p): + '''statement_item : K_fork ':' IDENTIFIER _embed5_statement_item block_item_decls_opt statement_or_null_list_opt join_keyword endlabel_opt ''' + print(p) + # { pform_pop_scope(); + # assert(! current_block_stack.empty()); + # PBlock*tmp = current_block_stack.top(); + # current_block_stack.pop(); + # tmp->set_join_type($7); + # if ($6) tmp->set_statement(*$6); + # delete $6; + # if ($8) { + # if (strcmp($3,$8) != 0) { + # yyerror(@8, "error: End label doesn't match fork name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@8, "error: Fork end labels require " + # "SystemVerilog."); + # } + # delete[]$8; + # } + # delete[]$3; + # $$ = tmp; + # } +() +def p_statement_item_11(p): + '''statement_item : K_disable hierarchy_identifier ';' ''' + print(p) + # { PDisable*tmp = new PDisable(*$2); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_statement_item_12(p): + '''statement_item : K_disable K_fork ';' ''' + print(p) + # { pform_name_t tmp_name; + # PDisable*tmp = new PDisable(tmp_name); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_13(p): + '''statement_item : K_TRIGGER hierarchy_identifier ';' ''' + print(p) + # { PTrigger*tmp = new PTrigger(*$2); + # FILE_NAME(tmp, @1); + # delete $2; + # $$ = tmp; + # } +() +def p_statement_item_14(p): + '''statement_item : procedural_assertion_statement ''' + print(p) + # { $$ = $1; } +() +def p_statement_item_15(p): + '''statement_item : loop_statement ''' + print(p) + # { $$ = $1; } +() +def p_statement_item_16(p): + '''statement_item : jump_statement ''' + print(p) + # { $$ = $1; } +() +def p_statement_item_17(p): + '''statement_item : K_case '(' expression ')' case_items K_endcase ''' + print(p) + # { PCase*tmp = new PCase(NetCase::EQ, $3, $5); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_18(p): + '''statement_item : K_casex '(' expression ')' case_items K_endcase ''' + print(p) + # { PCase*tmp = new PCase(NetCase::EQX, $3, $5); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_19(p): + '''statement_item : K_casez '(' expression ')' case_items K_endcase ''' + print(p) + # { PCase*tmp = new PCase(NetCase::EQZ, $3, $5); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_20(p): + '''statement_item : K_case '(' expression ')' error K_endcase ''' + print(p) + # { yyerrok; } +() +def p_statement_item_21(p): + '''statement_item : K_casex '(' expression ')' error K_endcase ''' + print(p) + # { yyerrok; } +() +def p_statement_item_22(p): + '''statement_item : K_casez '(' expression ')' error K_endcase ''' + print(p) + # { yyerrok; } +() +def p_statement_item_23(p): + '''statement_item : K_if '(' expression ')' statement_or_null %prec less_than_K_else ''' + print(p) + # { PCondit*tmp = new PCondit($3, $5, 0); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_24(p): + '''statement_item : K_if '(' expression ')' statement_or_null K_else statement_or_null ''' + print(p) + # { PCondit*tmp = new PCondit($3, $5, $7); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_25(p): + '''statement_item : K_if '(' error ')' statement_or_null %prec less_than_K_else ''' + print(p) + # { yyerror(@1, "error: Malformed conditional expression."); + # $$ = $5; + # } +() +def p_statement_item_26(p): + '''statement_item : K_if '(' error ')' statement_or_null K_else statement_or_null ''' + print(p) + # { yyerror(@1, "error: Malformed conditional expression."); + # $$ = $5; + # } +() +def p_statement_item_27(p): + '''statement_item : compressed_statement ';' ''' + print(p) + # { $$ = $1; } +() +def p_statement_item_28(p): + '''statement_item : inc_or_dec_expression ';' ''' + print(p) + # { $$ = pform_compressed_assign_from_inc_dec(@1, $1); } +() +def p_statement_item_29(p): + '''statement_item : delay1 statement_or_null ''' + print(p) + # { PExpr*del = $1->front(); + # assert($1->size() == 1); + # delete $1; + # PDelayStatement*tmp = new PDelayStatement(del, $2); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_30(p): + '''statement_item : event_control statement_or_null ''' + print(p) + # { PEventStatement*tmp = $1; + # if (tmp == 0) { + # yyerror(@1, "error: Invalid event control."); + # $$ = 0; + # } else { + # tmp->set_statement($2); + # $$ = tmp; + # } + # } +() +def p_statement_item_31(p): + '''statement_item : '@' '*' statement_or_null ''' + print(p) + # { PEventStatement*tmp = new PEventStatement; + # FILE_NAME(tmp, @1); + # tmp->set_statement($3); + # $$ = tmp; + # } +() +def p_statement_item_32(p): + '''statement_item : '@' '(' '*' ')' statement_or_null ''' + print(p) + # { PEventStatement*tmp = new PEventStatement; + # FILE_NAME(tmp, @1); + # tmp->set_statement($5); + # $$ = tmp; + # } +() +def p_statement_item_33(p): + '''statement_item : lpvalue '=' expression ';' ''' + print(p) + # { PAssign*tmp = new PAssign($1,$3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_34(p): + '''statement_item : error '=' expression ';' ''' + print(p) + # { yyerror(@2, "Syntax in assignment statement l-value."); + # yyerrok; + # $$ = new PNoop; + # } +() +def p_statement_item_35(p): + '''statement_item : lpvalue K_LE expression ';' ''' + print(p) + # { PAssignNB*tmp = new PAssignNB($1,$3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_36(p): + '''statement_item : error K_LE expression ';' ''' + print(p) + # { yyerror(@2, "Syntax in assignment statement l-value."); + # yyerrok; + # $$ = new PNoop; + # } +() +def p_statement_item_37(p): + '''statement_item : lpvalue '=' delay1 expression ';' ''' + print(p) + # { PExpr*del = $3->front(); $3->pop_front(); + # assert($3->empty()); + # PAssign*tmp = new PAssign($1,del,$4); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_38(p): + '''statement_item : lpvalue K_LE delay1 expression ';' ''' + print(p) + # { PExpr*del = $3->front(); $3->pop_front(); + # assert($3->empty()); + # PAssignNB*tmp = new PAssignNB($1,del,$4); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_39(p): + '''statement_item : lpvalue '=' event_control expression ';' ''' + print(p) + # { PAssign*tmp = new PAssign($1,0,$3,$4); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_40(p): + '''statement_item : lpvalue '=' K_repeat '(' expression ')' event_control expression ';' ''' + print(p) + # { PAssign*tmp = new PAssign($1,$5,$7,$8); + # FILE_NAME(tmp,@1); + # tmp->set_lineno(@1.first_line); + # $$ = tmp; + # } +() +def p_statement_item_41(p): + '''statement_item : lpvalue K_LE event_control expression ';' ''' + print(p) + # { PAssignNB*tmp = new PAssignNB($1,0,$3,$4); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_42(p): + '''statement_item : lpvalue K_LE K_repeat '(' expression ')' event_control expression ';' ''' + print(p) + # { PAssignNB*tmp = new PAssignNB($1,$5,$7,$8); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_43(p): + '''statement_item : lpvalue '=' dynamic_array_new ';' ''' + print(p) + # { PAssign*tmp = new PAssign($1,$3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_44(p): + '''statement_item : lpvalue '=' class_new ';' ''' + print(p) + # { PAssign*tmp = new PAssign($1,$3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_item_45(p): + '''statement_item : K_wait '(' expression ')' statement_or_null ''' + print(p) + # { PEventStatement*tmp; + # PEEvent*etmp = new PEEvent(PEEvent::POSITIVE, $3); + # tmp = new PEventStatement(etmp); + # FILE_NAME(tmp,@1); + # tmp->set_statement($5); + # $$ = tmp; + # } +() +def p_statement_item_46(p): + '''statement_item : K_wait K_fork ';' ''' + print(p) + # { PEventStatement*tmp = new PEventStatement((PEEvent*)0); + # FILE_NAME(tmp,@1); + # $$ = tmp; + # } +() +def p_statement_item_47(p): + '''statement_item : SYSTEM_IDENTIFIER '(' expression_list_with_nuls ')' ';' ''' + print(p) + # { PCallTask*tmp = new PCallTask(lex_strings.make($1), *$3); + # FILE_NAME(tmp,@1); + # delete[]$1; + # delete $3; + # $$ = tmp; + # } +() +def p_statement_item_48(p): + '''statement_item : SYSTEM_IDENTIFIER ';' ''' + print(p) + # { listpt; + # PCallTask*tmp = new PCallTask(lex_strings.make($1), pt); + # FILE_NAME(tmp,@1); + # delete[]$1; + # $$ = tmp; + # } +() +def p_statement_item_49(p): + '''statement_item : hierarchy_identifier '(' expression_list_with_nuls ')' ';' ''' + print(p) + # { PCallTask*tmp = pform_make_call_task(@1, *$1, *$3); + # delete $1; + # delete $3; + # $$ = tmp; + # } +() +def p_statement_item_50(p): + '''statement_item : hierarchy_identifier K_with '{' constraint_block_item_list_opt '}' ';' ''' + print(p) + # { /* ....randomize with { } */ + # if ($1 && peek_tail_name(*$1) == "randomize") { + # if (!gn_system_verilog()) + # yyerror(@2, "error: Randomize with constraint requires SystemVerilog."); + # else + # yyerror(@2, "sorry: Randomize with constraint not supported."); + # } else { + # yyerror(@2, "error: Constraint block can only be applied to randomize method."); + # } + # listpt; + # PCallTask*tmp = new PCallTask(*$1, pt); + # FILE_NAME(tmp, @1); + # delete $1; + # $$ = tmp; + # } +() +def p_statement_item_51(p): + '''statement_item : implicit_class_handle '.' hierarchy_identifier '(' expression_list_with_nuls ')' ';' ''' + print(p) + # { pform_name_t*t_name = $1; + # while (! $3->empty()) { + # t_name->push_back($3->front()); + # $3->pop_front(); + # } + # PCallTask*tmp = new PCallTask(*t_name, *$5); + # FILE_NAME(tmp, @1); + # delete $1; + # delete $3; + # delete $5; + # $$ = tmp; + # } +() +def p_statement_item_52(p): + '''statement_item : hierarchy_identifier ';' ''' + print(p) + # { listpt; + # PCallTask*tmp = pform_make_call_task(@1, *$1, pt); + # delete $1; + # $$ = tmp; + # } +() +def p_statement_item_53(p): + '''statement_item : implicit_class_handle '.' K_new '(' expression_list_with_nuls ')' ';' ''' + print(p) + # { PChainConstructor*tmp = new PChainConstructor(*$5); + # FILE_NAME(tmp, @3); + # delete $1; + # $$ = tmp; + # } +() +def p_statement_item_54(p): + '''statement_item : hierarchy_identifier '(' error ')' ';' ''' + print(p) + # { yyerror(@3, "error: Syntax error in task arguments."); + # listpt; + # PCallTask*tmp = pform_make_call_task(@1, *$1, pt); + # delete $1; + # $$ = tmp; + # } +() +def p_statement_item_55(p): + '''statement_item : error ';' ''' + print(p) + # { yyerror(@2, "error: malformed statement"); + # yyerrok; + # $$ = new PNoop; + # } +() +def p__embed0_statement_item(p): + '''_embed0_statement_item : ''' + # { PBlock*tmp = pform_push_block_scope(0, PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # } +() +def p__embed1_statement_item(p): + '''_embed1_statement_item : ''' + # { if ($3) { + # if (! gn_system_verilog()) { + # yyerror("error: Variable declaration in unnamed block " + # "requires SystemVerilog."); + # } + # } else { + # /* If there are no declarations in the scope then just delete it. */ + # pform_pop_scope(); + # assert(! current_block_stack.empty()); + # PBlock*tmp = current_block_stack.top(); + # current_block_stack.pop(); + # delete tmp; + # } + # } +() +def p__embed2_statement_item(p): + '''_embed2_statement_item : ''' + # { PBlock*tmp = pform_push_block_scope($3, PBlock::BL_SEQ); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # } +() +def p__embed3_statement_item(p): + '''_embed3_statement_item : ''' + # { PBlock*tmp = pform_push_block_scope(0, PBlock::BL_PAR); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # } +() +def p__embed4_statement_item(p): + '''_embed4_statement_item : ''' + # { if ($3) { + # if (! gn_system_verilog()) { + # yyerror("error: Variable declaration in unnamed block " + # "requires SystemVerilog."); + # } + # } else { + # /* If there are no declarations in the scope then just delete it. */ + # pform_pop_scope(); + # assert(! current_block_stack.empty()); + # PBlock*tmp = current_block_stack.top(); + # current_block_stack.pop(); + # delete tmp; + # } + # } +() +def p__embed5_statement_item(p): + '''_embed5_statement_item : ''' + # { PBlock*tmp = pform_push_block_scope($3, PBlock::BL_PAR); + # FILE_NAME(tmp, @1); + # current_block_stack.push(tmp); + # } +() +def p_compressed_statement_1(p): + '''compressed_statement : lpvalue K_PLUS_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '+', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_2(p): + '''compressed_statement : lpvalue K_MINUS_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '-', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_3(p): + '''compressed_statement : lpvalue K_MUL_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '*', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_4(p): + '''compressed_statement : lpvalue K_DIV_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '/', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_5(p): + '''compressed_statement : lpvalue K_MOD_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '%', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_6(p): + '''compressed_statement : lpvalue K_AND_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '&', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_7(p): + '''compressed_statement : lpvalue K_OR_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '|', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_8(p): + '''compressed_statement : lpvalue K_XOR_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, '^', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_9(p): + '''compressed_statement : lpvalue K_LS_EQ expression ''' + print(p) + # { PAssign *tmp = new PAssign($1, 'l', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_10(p): + '''compressed_statement : lpvalue K_RS_EQ expression ''' + print(p) + # { PAssign*tmp = new PAssign($1, 'r', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_compressed_statement_11(p): + '''compressed_statement : lpvalue K_RSS_EQ expression ''' + print(p) + # { PAssign *tmp = new PAssign($1, 'R', $3); + # FILE_NAME(tmp, @1); + # $$ = tmp; + # } +() +def p_statement_or_null_list_opt_1(p): + '''statement_or_null_list_opt : statement_or_null_list ''' + print(p) + # { $$ = $1; } +() +def p_statement_or_null_list_opt_2(p): + '''statement_or_null_list_opt : ''' + print(p) + # { $$ = 0; } +() +def p_statement_or_null_list_1(p): + '''statement_or_null_list : statement_or_null_list statement_or_null ''' + print(p) + # { vector*tmp = $1; + # if ($2) tmp->push_back($2); + # $$ = tmp; + # } +() +def p_statement_or_null_list_2(p): + '''statement_or_null_list : statement_or_null ''' + print(p) + # { vector*tmp = new vector(0); + # if ($1) tmp->push_back($1); + # $$ = tmp; + # } +() +def p_analog_statement_1(p): + '''analog_statement : branch_probe_expression K_CONTRIBUTE expression ';' ''' + print(p) + # { $$ = pform_contribution_statement(@2, $1, $3); } +() +def p_task_item_1(p): + '''task_item : block_item_decl ''' + print(p) + # { $$ = new vector(0); } +() +def p_task_item_2(p): + '''task_item : tf_port_declaration ''' + print(p) + # { $$ = $1; } +() +def p_task_item_list_1(p): + '''task_item_list : task_item_list task_item ''' + print(p) + # { vector*tmp = $1; + # size_t s1 = tmp->size(); + # tmp->resize(s1 + $2->size()); + # for (size_t idx = 0 ; idx < $2->size() ; idx += 1) + # tmp->at(s1 + idx) = $2->at(idx); + # delete $2; + # $$ = tmp; + # } +() +def p_task_item_list_2(p): + '''task_item_list : task_item ''' + print(p) + # { $$ = $1; } +() +def p_task_item_list_opt_1(p): + '''task_item_list_opt : task_item_list ''' + print(p) + # { $$ = $1; } +() +def p_task_item_list_opt_2(p): + '''task_item_list_opt : ''' + print(p) + # { $$ = 0; } +() +def p_tf_port_list_opt_1(p): + '''tf_port_list_opt : tf_port_list ''' + print(p) + # { $$ = $1; } +() +def p_tf_port_list_opt_2(p): + '''tf_port_list_opt : ''' + print(p) + # { $$ = 0; } +() +def p_udp_body_1(p): + '''udp_body : K_table udp_entry_list K_endtable ''' + print(p) + # { lex_end_table(); + # $$ = $2; + # } +() +def p_udp_body_2(p): + '''udp_body : K_table K_endtable ''' + print(p) + # { lex_end_table(); + # yyerror(@1, "error: Empty UDP table."); + # $$ = 0; + # } +() +def p_udp_body_3(p): + '''udp_body : K_table error K_endtable ''' + print(p) + # { lex_end_table(); + # yyerror(@2, "Errors in UDP table"); + # yyerrok; + # $$ = 0; + # } +() +def p_udp_entry_list_1(p): + '''udp_entry_list : udp_comb_entry_list ''' + print(p) +() +def p_udp_entry_list_2(p): + '''udp_entry_list : udp_sequ_entry_list ''' + print(p) +() +def p_udp_comb_entry_1(p): + '''udp_comb_entry : udp_input_list ':' udp_output_sym ';' ''' + print(p) + # { char*tmp = new char[strlen($1)+3]; + # strcpy(tmp, $1); + # char*tp = tmp+strlen(tmp); + # *tp++ = ':'; + # *tp++ = $3; + # *tp++ = 0; + # delete[]$1; + # $$ = tmp; + # } +() +def p_udp_comb_entry_list_1(p): + '''udp_comb_entry_list : udp_comb_entry ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # delete[]$1; + # $$ = tmp; + # } +() +def p_udp_comb_entry_list_2(p): + '''udp_comb_entry_list : udp_comb_entry_list udp_comb_entry ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($2); + # delete[]$2; + # $$ = tmp; + # } +() +def p_udp_sequ_entry_list_1(p): + '''udp_sequ_entry_list : udp_sequ_entry ''' + print(p) + # { list*tmp = new list; + # tmp->push_back($1); + # delete[]$1; + # $$ = tmp; + # } +() +def p_udp_sequ_entry_list_2(p): + '''udp_sequ_entry_list : udp_sequ_entry_list udp_sequ_entry ''' + print(p) + # { list*tmp = $1; + # tmp->push_back($2); + # delete[]$2; + # $$ = tmp; + # } +() +def p_udp_sequ_entry_1(p): + '''udp_sequ_entry : udp_input_list ':' udp_input_sym ':' udp_output_sym ';' ''' + print(p) + # { char*tmp = new char[strlen($1)+5]; + # strcpy(tmp, $1); + # char*tp = tmp+strlen(tmp); + # *tp++ = ':'; + # *tp++ = $3; + # *tp++ = ':'; + # *tp++ = $5; + # *tp++ = 0; + # $$ = tmp; + # } +() +def p_udp_initial_1(p): + '''udp_initial : K_initial IDENTIFIER '=' number ';' ''' + print(p) + # { PExpr*etmp = new PENumber($4); + # PEIdent*itmp = new PEIdent(lex_strings.make($2)); + # PAssign*atmp = new PAssign(itmp, etmp); + # FILE_NAME(atmp, @2); + # delete[]$2; + # $$ = atmp; + # } +() +def p_udp_init_opt_1(p): + '''udp_init_opt : udp_initial ''' + print(p) + # { $$ = $1; } +() +def p_udp_init_opt_2(p): + '''udp_init_opt : ''' + print(p) + # { $$ = 0; } +() +def p_udp_input_list_1(p): + '''udp_input_list : udp_input_sym ''' + print(p) + # { char*tmp = new char[2]; + # tmp[0] = $1; + # tmp[1] = 0; + # $$ = tmp; + # } +() +def p_udp_input_list_2(p): + '''udp_input_list : udp_input_list udp_input_sym ''' + print(p) + # { char*tmp = new char[strlen($1)+2]; + # strcpy(tmp, $1); + # char*tp = tmp+strlen(tmp); + # *tp++ = $2; + # *tp++ = 0; + # delete[]$1; + # $$ = tmp; + # } +() +def p_udp_input_sym_1(p): + '''udp_input_sym : '0' ''' + print(p) + # { $$ = '0'; } +() +def p_udp_input_sym_2(p): + '''udp_input_sym : '1' ''' + print(p) + # { $$ = '1'; } +() +def p_udp_input_sym_3(p): + '''udp_input_sym : 'x' ''' + print(p) + # { $$ = 'x'; } +() +def p_udp_input_sym_4(p): + '''udp_input_sym : '?' ''' + print(p) + # { $$ = '?'; } +() +def p_udp_input_sym_5(p): + '''udp_input_sym : 'b' ''' + print(p) + # { $$ = 'b'; } +() +def p_udp_input_sym_6(p): + '''udp_input_sym : '*' ''' + print(p) + # { $$ = '*'; } +() +def p_udp_input_sym_7(p): + '''udp_input_sym : '%' ''' + print(p) + # { $$ = '%'; } +() +def p_udp_input_sym_8(p): + '''udp_input_sym : 'f' ''' + print(p) + # { $$ = 'f'; } +() +def p_udp_input_sym_9(p): + '''udp_input_sym : 'F' ''' + print(p) + # { $$ = 'F'; } +() +def p_udp_input_sym_10(p): + '''udp_input_sym : 'l' ''' + print(p) + # { $$ = 'l'; } +() +def p_udp_input_sym_11(p): + '''udp_input_sym : 'h' ''' + print(p) + # { $$ = 'h'; } +() +def p_udp_input_sym_12(p): + '''udp_input_sym : 'B' ''' + print(p) + # { $$ = 'B'; } +() +def p_udp_input_sym_13(p): + '''udp_input_sym : 'r' ''' + print(p) + # { $$ = 'r'; } +() +def p_udp_input_sym_14(p): + '''udp_input_sym : 'R' ''' + print(p) + # { $$ = 'R'; } +() +def p_udp_input_sym_15(p): + '''udp_input_sym : 'M' ''' + print(p) + # { $$ = 'M'; } +() +def p_udp_input_sym_16(p): + '''udp_input_sym : 'n' ''' + print(p) + # { $$ = 'n'; } +() +def p_udp_input_sym_17(p): + '''udp_input_sym : 'N' ''' + print(p) + # { $$ = 'N'; } +() +def p_udp_input_sym_18(p): + '''udp_input_sym : 'p' ''' + print(p) + # { $$ = 'p'; } +() +def p_udp_input_sym_19(p): + '''udp_input_sym : 'P' ''' + print(p) + # { $$ = 'P'; } +() +def p_udp_input_sym_20(p): + '''udp_input_sym : 'Q' ''' + print(p) + # { $$ = 'Q'; } +() +def p_udp_input_sym_21(p): + '''udp_input_sym : 'q' ''' + print(p) + # { $$ = 'q'; } +() +def p_udp_input_sym_22(p): + '''udp_input_sym : '_' ''' + print(p) + # { $$ = '_'; } +() +def p_udp_input_sym_23(p): + '''udp_input_sym : '+' ''' + print(p) + # { $$ = '+'; } +() +def p_udp_input_sym_24(p): + '''udp_input_sym : DEC_NUMBER ''' + print(p) + # { yyerror(@1, "internal error: Input digits parse as decimal number!"); $$ = '0'; } +() +def p_udp_output_sym_1(p): + '''udp_output_sym : '0' ''' + print(p) + # { $$ = '0'; } +() +def p_udp_output_sym_2(p): + '''udp_output_sym : '1' ''' + print(p) + # { $$ = '1'; } +() +def p_udp_output_sym_3(p): + '''udp_output_sym : 'x' ''' + print(p) + # { $$ = 'x'; } +() +def p_udp_output_sym_4(p): + '''udp_output_sym : '-' ''' + print(p) + # { $$ = '-'; } +() +def p_udp_output_sym_5(p): + '''udp_output_sym : DEC_NUMBER ''' + print(p) + # { yyerror(@1, "internal error: Output digits parse as decimal number!"); $$ = '0'; } +() +def p_udp_port_decl_1(p): + '''udp_port_decl : K_input list_of_identifiers ';' ''' + print(p) + # { $$ = pform_make_udp_input_ports($2); } +() +def p_udp_port_decl_2(p): + '''udp_port_decl : K_output IDENTIFIER ';' ''' + print(p) + # { perm_string pname = lex_strings.make($2); + # PWire*pp = new PWire(pname, NetNet::IMPLICIT, NetNet::POUTPUT, IVL_VT_LOGIC); + # vector*tmp = new vector(1); + # (*tmp)[0] = pp; + # $$ = tmp; + # delete[]$2; + # } +() +def p_udp_port_decl_3(p): + '''udp_port_decl : K_reg IDENTIFIER ';' ''' + print(p) + # { perm_string pname = lex_strings.make($2); + # PWire*pp = new PWire(pname, NetNet::REG, NetNet::PIMPLICIT, IVL_VT_LOGIC); + # vector*tmp = new vector(1); + # (*tmp)[0] = pp; + # $$ = tmp; + # delete[]$2; + # } +() +def p_udp_port_decl_4(p): + '''udp_port_decl : K_reg K_output IDENTIFIER ';' ''' + print(p) + # { perm_string pname = lex_strings.make($3); + # PWire*pp = new PWire(pname, NetNet::REG, NetNet::POUTPUT, IVL_VT_LOGIC); + # vector*tmp = new vector(1); + # (*tmp)[0] = pp; + # $$ = tmp; + # delete[]$3; + # } +() +def p_udp_port_decls_1(p): + '''udp_port_decls : udp_port_decl ''' + print(p) + # { $$ = $1; } +() +def p_udp_port_decls_2(p): + '''udp_port_decls : udp_port_decls udp_port_decl ''' + print(p) + # { vector*tmp = $1; + # size_t s1 = $1->size(); + # tmp->resize(s1+$2->size()); + # for (size_t idx = 0 ; idx < $2->size() ; idx += 1) + # tmp->at(s1+idx) = $2->at(idx); + # $$ = tmp; + # delete $2; + # } +() +def p_udp_port_list_1(p): + '''udp_port_list : IDENTIFIER ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(lex_strings.make($1)); + # delete[]$1; + # $$ = tmp; + # } +() +def p_udp_port_list_2(p): + '''udp_port_list : udp_port_list ',' IDENTIFIER ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(lex_strings.make($3)); + # delete[]$3; + # $$ = tmp; + # } +() +def p_udp_reg_opt_1(p): + '''udp_reg_opt : K_reg ''' + print(p) + # { $$ = true; } +() +def p_udp_reg_opt_2(p): + '''udp_reg_opt : ''' + print(p) + # { $$ = false; } +() +def p_udp_initial_expr_opt_1(p): + '''udp_initial_expr_opt : '=' expression ''' + print(p) + # { $$ = $2; } +() +def p_udp_initial_expr_opt_2(p): + '''udp_initial_expr_opt : ''' + print(p) + # { $$ = 0; } +() +def p_udp_input_declaration_list_1(p): + '''udp_input_declaration_list : K_input IDENTIFIER ''' + print(p) + # { list*tmp = new list; + # tmp->push_back(lex_strings.make($2)); + # $$ = tmp; + # delete[]$2; + # } +() +def p_udp_input_declaration_list_2(p): + '''udp_input_declaration_list : udp_input_declaration_list ',' K_input IDENTIFIER ''' + print(p) + # { list*tmp = $1; + # tmp->push_back(lex_strings.make($4)); + # $$ = tmp; + # delete[]$4; + # } +() +def p_udp_primitive_1(p): + '''udp_primitive : K_primitive IDENTIFIER '(' udp_port_list ')' ';' udp_port_decls udp_init_opt udp_body K_endprimitive endlabel_opt ''' + print(p) + # { perm_string tmp2 = lex_strings.make($2); + # pform_make_udp(tmp2, $4, $7, $9, $8, + # @2.text, @2.first_line); + # if ($11) { + # if (strcmp($2,$11) != 0) { + # yyerror(@11, "error: End label doesn't match " + # "primitive name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@11, "error: Primitive end labels " + # "require SystemVerilog."); + # } + # delete[]$11; + # } + # delete[]$2; + # } +() +def p_udp_primitive_2(p): + '''udp_primitive : K_primitive IDENTIFIER '(' K_output udp_reg_opt IDENTIFIER udp_initial_expr_opt ',' udp_input_declaration_list ')' ';' udp_body K_endprimitive endlabel_opt ''' + print(p) + # { perm_string tmp2 = lex_strings.make($2); + # perm_string tmp6 = lex_strings.make($6); + # pform_make_udp(tmp2, $5, tmp6, $7, $9, $12, + # @2.text, @2.first_line); + # if ($14) { + # if (strcmp($2,$14) != 0) { + # yyerror(@14, "error: End label doesn't match " + # "primitive name"); + # } + # if (! gn_system_verilog()) { + # yyerror(@14, "error: Primitive end labels " + # "require SystemVerilog."); + # } + # delete[]$14; + # } + # delete[]$2; + # delete[]$6; + # } +() +def p_K_packed_opt_1(p): + '''K_packed_opt : K_packed ''' + print(p) + # { $$ = true; } +() +def p_K_packed_opt_2(p): + '''K_packed_opt : ''' + print(p) + # { $$ = false; } +() +def p_K_reg_opt_1(p): + '''K_reg_opt : K_reg ''' + print(p) + # { $$ = true; } +() +def p_K_reg_opt_2(p): + '''K_reg_opt : ''' + print(p) + # { $$ = false; } +() +def p_K_static_opt_1(p): + '''K_static_opt : K_static ''' + print(p) + # { $$ = true; } +() +def p_K_static_opt_2(p): + '''K_static_opt : ''' + print(p) + # { $$ = false; } +() + +def p_K_virtual_opt_1(p): + '''K_virtual_opt : K_virtual ''' + print(p) + # { $$ = true; } +() +def p_K_virtual_opt_2(p): + '''K_virtual_opt : ''' + print(p) + # { $$ = false; } +() + +def p_error(p): + print ("error", p) + exit(0) + +yacc.yacc(debug=0) + diff --git a/svparse.py b/svparse.py new file mode 100644 index 0000000..25c0c68 --- /dev/null +++ b/svparse.py @@ -0,0 +1,23 @@ +import sys + +import lexor +import parse_sv #as parse + +from ply import * + +#tokens = list(set(lexor.tokens).union(set(parse.tokens))) + +def parsedata(data, debug=0): + parser = yacc.parse(debug=2) + parser.error = 0 + p = parser.parse(data, debug=debug) + if parser.error: + return None + return p + +if __name__ == '__main__': + fname = sys.argv[1] + with open(fname) as f: + data = f.read() + yacc.parse(data, debug=3) + -- 2.30.2