Add file and line information for parameters, etc.
[sverilog.git] / parse.y
blob9f3bdb3a5e8a4789e5e525bf5c67bd1491241fa2
2 %{
3 /*
4 * Copyright (c) 1998-2008 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 # include "config.h"
24 # include "parse_misc.h"
25 # include "compiler.h"
26 # include "pform.h"
27 # include "Statement.h"
28 # include "PSpec.h"
29 # include <stack>
30 # include <cstring>
31 # include <sstream>
33 class PSpecPath;
35 extern void lex_start_table();
36 extern void lex_end_table();
38 static svector<PExpr*>* active_range = 0;
39 static bool active_signed = false;
41 /* Port declaration lists use this structure for context. */
42 static struct {
43 NetNet::Type port_net_type;
44 NetNet::PortType port_type;
45 ivl_variable_type_t var_type;
46 bool sign_flag;
47 svector<PExpr*>* range;
48 } port_declaration_context = {NetNet::NONE, NetNet::NOT_A_PORT,
49 IVL_VT_NO_TYPE, false, 0};
51 /* The task and function rules need to briefly hold the pointer to the
52 task/function that is currently in progress. */
53 static PTask* current_task = 0;
54 static PFunction* current_function = 0;
55 static stack<PBlock*> current_block_stack;
57 /* Later version of bison (including 1.35) will not compile in stack
58 extension if the output is compiled with C++ and either the YYSTYPE
59 or YYLTYPE are provided by the source code. However, I can get the
60 old behavior back by defining these symbols. */
61 # define YYSTYPE_IS_TRIVIAL 1
62 # define YYLTYPE_IS_TRIVIAL 1
64 /* Recent version of bison expect that the user supply a
65 YYLLOC_DEFAULT macro that makes up a yylloc value from existing
66 values. I need to supply an explicit version to account for the
67 text field, that otherwise won't be copied. */
68 # define YYLLOC_DEFAULT(Current, Rhs, N) do { \
69 (Current).first_line = (Rhs)[1].first_line; \
70 (Current).first_column = (Rhs)[1].first_column; \
71 (Current).last_line = (Rhs)[N].last_line; \
72 (Current).last_column = (Rhs)[N].last_column; \
73 (Current).text = (Rhs)[1].text; } while (0)
76 * These are some common strength pairs that are used as defaults when
77 * the user is not otherwise specific.
79 const static struct str_pair_t pull_strength = { PGate::PULL, PGate::PULL };
80 const static struct str_pair_t str_strength = { PGate::STRONG, PGate::STRONG };
82 static list<perm_string>* list_from_identifier(char*id)
84 list<perm_string>*tmp = new list<perm_string>;
85 tmp->push_back(lex_strings.make(id));
86 delete[]id;
87 return tmp;
90 static list<perm_string>* list_from_identifier(list<perm_string>*tmp, char*id)
92 tmp->push_back(lex_strings.make(id));
93 delete[]id;
94 return tmp;
97 static inline void FILE_NAME(LineInfo*tmp, const struct vlltype&where)
99 tmp->set_lineno(where.first_line);
100 tmp->set_file(filename_strings.make(where.text));
103 static svector<PExpr*>* copy_range(svector<PExpr*>* orig)
105 svector<PExpr*>*copy = 0;
107 if (orig) {
108 copy = new svector<PExpr*>(2);
109 (*copy)[0] = (*orig)[0];
110 (*copy)[1] = (*orig)[1];
113 return copy;
117 * This is a shorthand for making a PECallFunction that takes a single
118 * arg. This is used by some of the code that detects built-ins.
120 static PECallFunction*make_call_function(perm_string tn, PExpr*arg)
122 svector<PExpr*> parms(1);
123 parms[0] = arg;
124 PECallFunction*tmp = new PECallFunction(tn, parms);
125 return tmp;
128 static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2)
130 svector<PExpr*> parms(2);
131 parms[0] = arg1;
132 parms[1] = arg2;
133 PECallFunction*tmp = new PECallFunction(tn, parms);
134 return tmp;
139 %union {
140 bool flag;
142 char letter;
144 /* text items are C strings allocated by the lexor using
145 strdup. They can be put into lists with the texts type. */
146 char*text;
147 list<perm_string>*perm_strings;
148 pform_name_t*pform_name;
150 hname_t*hier;
152 list<string>*strings;
154 struct str_pair_t drive;
156 PCase::Item*citem;
157 svector<PCase::Item*>*citems;
159 lgate*gate;
160 svector<lgate>*gates;
162 Module::port_t *mport;
163 svector<Module::port_t*>*mports;
165 named_pexpr_t*named_pexpr;
166 svector<named_pexpr_t*>*named_pexprs;
167 struct parmvalue_t*parmvalue;
169 PExpr*expr;
170 svector<PExpr*>*exprs;
172 svector<PEEvent*>*event_expr;
174 NetNet::Type nettype;
175 PGBuiltin::Type gatetype;
176 NetNet::PortType porttype;
177 ivl_variable_type_t datatype;
179 PWire*wire;
180 svector<PWire*>*wires;
182 PEventStatement*event_statement;
183 Statement*statement;
184 svector<Statement*>*statement_list;
186 PTaskFuncArg function_type;
188 net_decl_assign_t*net_decl_assign;
190 verinum* number;
192 verireal* realtime;
194 PSpecPath* specpath;
195 list<index_component_t> *dimensions;
198 %token <text> IDENTIFIER SYSTEM_IDENTIFIER STRING
199 %token <text> PATHPULSE_IDENTIFIER
200 %token <number> BASED_NUMBER DEC_NUMBER
201 %token <realtime> REALTIME
202 %token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_LS K_RS K_RSS K_SG
203 %token K_PO_POS K_PO_NEG K_POW
204 %token K_PSTAR K_STARP
205 %token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER
206 %token K_abs K_acos K_acosh K_asin K_asinh K_atan K_atanh K_atan2
207 %token K_always K_and K_assign K_begin K_bool K_buf K_bufif0 K_bufif1 K_case
208 %token K_casex K_casez K_ceil K_cmos K_cos K_cosh
209 %token K_deassign K_default K_defparam K_disable
210 %token K_edge K_edge_descriptor
211 %token K_else K_end K_endcase K_endfunction K_endgenerate K_endmodule
212 %token K_endprimitive K_endspecify K_endtable K_endtask K_event K_exp K_floor
213 %token K_for K_force K_forever K_fork K_function K_generate K_genvar
214 %token K_highz0 K_highz1 K_hypot K_if K_ifnone
215 %token K_initial K_inout K_input K_integer K_join K_large K_ln K_localparam
216 %token K_log K_logic K_macromodule K_max
217 %token K_medium K_min K_module K_nand K_negedge K_nmos K_nor K_not K_notif0
218 %token K_notif1 K_or K_output K_parameter K_pmos K_posedge K_pow K_primitive
219 %token K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_real K_realtime
220 %token K_reg K_release K_repeat
221 %token K_rnmos K_rpmos K_rtran K_rtranif0 K_rtranif1 K_scalared
222 %token K_signed K_sin K_sinh K_small K_specify
223 %token K_specparam K_sqrt K_strong0 K_strong1 K_supply0 K_supply1 K_table
224 %token K_tan K_tanh K_task
225 %token K_time K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand
226 %token K_trior K_trireg K_vectored K_wait K_wand K_weak0 K_weak1
227 %token K_while K_wire
228 %token K_wone K_wor K_xnor K_xor
229 %token K_Shold K_Speriod K_Srecovery K_Srecrem K_Ssetup K_Swidth K_Ssetuphold
231 %token KK_attribute
233 %type <number> number
234 %type <flag> signed_opt udp_reg_opt edge_operator
235 %type <drive> drive_strength drive_strength_opt dr_strength0 dr_strength1
236 %type <letter> udp_input_sym udp_output_sym
237 %type <text> udp_input_list udp_sequ_entry udp_comb_entry
238 %type <perm_strings> udp_input_declaration_list
239 %type <strings> udp_entry_list udp_comb_entry_list udp_sequ_entry_list
240 %type <strings> udp_body
241 %type <perm_strings> udp_port_list
242 %type <wires> udp_port_decl udp_port_decls
243 %type <statement> udp_initial udp_init_opt
244 %type <expr> udp_initial_expr_opt
246 %type <text> register_variable net_variable real_variable
247 %type <perm_strings> register_variable_list net_variable_list real_variable_list list_of_identifiers
249 %type <net_decl_assign> net_decl_assign net_decl_assigns
251 %type <mport> port port_opt port_reference port_reference_list
252 %type <mport> port_declaration
253 %type <mports> list_of_ports module_port_list_opt list_of_port_declarations
255 %type <wires> task_item task_item_list task_item_list_opt
256 %type <wires> task_port_item task_port_decl task_port_decl_list
257 %type <wires> function_item function_item_list
259 %type <named_pexpr> port_name parameter_value_byname
260 %type <named_pexprs> port_name_list parameter_value_byname_list
262 %type <named_pexpr> attribute
263 %type <named_pexprs> attribute_list attribute_list_opt
265 %type <citem> case_item
266 %type <citems> case_items
268 %type <gate> gate_instance
269 %type <gates> gate_instance_list
271 %type <pform_name> hierarchy_identifier
272 %type <expr> expression expr_primary expr_mintypmax
273 %type <expr> lpvalue
274 %type <expr> delay_value delay_value_simple
275 %type <exprs> delay1 delay3 delay3_opt delay_value_list
276 %type <exprs> expression_list_with_nuls expression_list_proper
277 %type <exprs> cont_assign cont_assign_list
279 %type <exprs> range range_opt
280 %type <dimensions> dimensions_opt dimensions
281 %type <nettype> net_type var_type net_type_opt
282 %type <gatetype> gatetype
283 %type <porttype> port_type
284 %type <datatype> primitive_type primitive_type_opt
285 %type <parmvalue> parameter_value_opt
287 %type <function_type> function_range_or_type_opt
288 %type <event_expr> event_expression_list
289 %type <event_expr> event_expression
290 %type <event_statement> event_control
291 %type <statement> statement statement_or_null
292 %type <statement_list> statement_list
294 %type <letter> spec_polarity
295 %type <perm_strings> specify_path_identifiers
297 %type <specpath> specify_simple_path specify_simple_path_decl
298 %type <specpath> specify_edge_path specify_edge_path_decl
300 %token K_TAND
301 %right '?' ':'
302 %left K_LOR
303 %left K_LAND
304 %left '|'
305 %left '^' K_NXOR K_NOR
306 %left '&' K_NAND
307 %left K_EQ K_NE K_CEQ K_CNE
308 %left K_GE K_LE '<' '>'
309 %left K_LS K_RS K_RSS
310 %left '+' '-'
311 %left '*' '/' '%'
312 %left K_POW
313 %left UNARY_PREC
315 /* to resolve dangling else ambiguity. */
316 %nonassoc less_than_K_else
317 %nonassoc K_else
321 /* A degenerate source file can be completely empty. */
322 main : source_file | ;
324 source_file
325 : description
326 | source_file description
329 number : BASED_NUMBER
330 { $$ = $1; based_size = 0;}
331 | DEC_NUMBER
332 { $$ = $1; based_size = 0;}
333 | DEC_NUMBER BASED_NUMBER
334 { $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line);
335 based_size = 0; }
338 /* Verilog-2001 supports attribute lists, which can be attached to a
339 variety of different objects. The syntax inside the (* *) is a
340 comma separated list of names or names with assigned values. */
341 attribute_list_opt
342 : K_PSTAR attribute_list K_STARP { $$ = $2; }
343 | K_PSTAR K_STARP { $$ = 0; }
344 | { $$ = 0; }
347 attribute_list
348 : attribute_list ',' attribute
349 { svector<named_pexpr_t*>*tmp =
350 new svector<named_pexpr_t*>(*$1,$3);
351 delete $1;
352 $$ = tmp;
354 | attribute
355 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
356 (*tmp)[0] = $1;
357 $$ = tmp;
362 attribute
363 : IDENTIFIER
364 { named_pexpr_t*tmp = new named_pexpr_t;
365 tmp->name = lex_strings.make($1);
366 tmp->parm = 0;
367 delete[]$1;
368 $$ = tmp;
370 | IDENTIFIER '=' expression
371 { PExpr*tmp = $3;
372 if (!pform_expression_is_constant(tmp)) {
373 yyerror(@3, "error: attribute value "
374 "expression must be constant.");
375 delete tmp;
376 tmp = 0;
378 named_pexpr_t*tmp2 = new named_pexpr_t;
379 tmp2->name = lex_strings.make($1);
380 tmp2->parm = tmp;
381 delete[]$1;
382 $$ = tmp2;
387 /* The block_item_decl is used in function definitions, task
388 definitions, module definitions and named blocks. Wherever a new
389 scope is entered, the source may declare new registers and
390 integers. This rule matches those declarations. The containing
391 rule has presumably set up the scope. */
393 block_item_decl
394 : attribute_list_opt K_reg
395 primitive_type_opt signed_opt range
396 register_variable_list ';'
397 { ivl_variable_type_t dtype = $3;
398 if (dtype == IVL_VT_NO_TYPE)
399 dtype = IVL_VT_LOGIC;
400 pform_set_net_range($6, $5, $4, dtype);
401 if ($1) delete $1;
404 /* This differs from the above pattern only in the absence of the
405 range. This is the rule for a scalar. */
407 | attribute_list_opt K_reg
408 primitive_type_opt signed_opt
409 register_variable_list ';'
410 { ivl_variable_type_t dtype = $3;
411 if (dtype == IVL_VT_NO_TYPE)
412 dtype = IVL_VT_LOGIC;
413 pform_set_net_range($5, 0, $4, dtype);
414 if ($1) delete $1;
417 /* Integer declarations are simpler in that they do not have all the
418 trappings of a general variable declaration. All of that is
419 implicit in the "integer" of the declaratin. */
421 | attribute_list_opt K_integer register_variable_list ';'
422 { pform_set_reg_integer($3);
423 if ($1) delete $1;
426 | attribute_list_opt K_time register_variable_list ';'
427 { pform_set_reg_time($3);
430 /* real declarations are fairly simple as there is no range of
431 signed flag in the declaration. Create the real as a NetNet::REG
432 with real value. Note that real and realtime are interchangable
433 in this context. */
435 | attribute_list_opt K_real real_variable_list ';'
436 { delete $3; }
437 | attribute_list_opt K_realtime real_variable_list ';'
438 { delete $3; }
440 | K_parameter parameter_assign_decl ';'
441 | K_localparam localparam_assign_decl ';'
443 /* Recover from errors that happen within variable lists. Use the
444 trailing semi-colon to resync the parser. */
446 | attribute_list_opt K_reg error ';'
447 { yyerror(@2, "error: syntax error in reg variable list.");
448 yyerrok;
449 if ($1) delete $1;
451 | attribute_list_opt K_integer error ';'
452 { yyerror(@2, "error: syntax error in integer variable list.");
453 yyerrok;
454 if ($1) delete $1;
456 | attribute_list_opt K_time error ';'
457 { yyerror(@2, "error: syntax error in time variable list.");
458 yyerrok;
460 | attribute_list_opt K_real error ';'
461 { yyerror(@2, "error: syntax error in real variable list.");
462 yyerrok;
464 | attribute_list_opt K_realtime error ';'
465 { yyerror(@2, "error: syntax error in realtime variable list.");
466 yyerrok;
468 | K_parameter error ';'
469 { yyerror(@1, "error: syntax error in parameter list.");
470 yyerrok;
472 | K_localparam error ';'
473 { yyerror(@1, "error: syntax error localparam list.");
474 yyerrok;
478 block_item_decls
479 : block_item_decl
480 | block_item_decls block_item_decl
483 block_item_decls_opt
484 : block_item_decls
488 case_item
489 : expression_list_proper ':' statement_or_null
490 { PCase::Item*tmp = new PCase::Item;
491 tmp->expr = *$1;
492 tmp->stat = $3;
493 delete $1;
494 $$ = tmp;
496 | K_default ':' statement_or_null
497 { PCase::Item*tmp = new PCase::Item;
498 tmp->stat = $3;
499 $$ = tmp;
501 | K_default statement_or_null
502 { PCase::Item*tmp = new PCase::Item;
503 tmp->stat = $2;
504 $$ = tmp;
506 | error ':' statement_or_null
507 { yyerror(@2, "error: Incomprehensible case expression.");
508 yyerrok;
512 case_items
513 : case_items case_item
514 { svector<PCase::Item*>*tmp;
515 tmp = new svector<PCase::Item*>(*$1, $2);
516 delete $1;
517 $$ = tmp;
519 | case_item
520 { svector<PCase::Item*>*tmp = new svector<PCase::Item*>(1);
521 (*tmp)[0] = $1;
522 $$ = tmp;
526 charge_strength
527 : '(' K_small ')'
528 | '(' K_medium ')'
529 | '(' K_large ')'
532 charge_strength_opt
533 : charge_strength
537 defparam_assign
538 : hierarchy_identifier '=' expression
539 { PExpr*tmp = $3;
540 if (!pform_expression_is_constant(tmp)) {
541 yyerror(@3, "error: parameter value "
542 "must be constant.");
543 delete tmp;
544 tmp = 0;
546 pform_set_defparam(*$1, $3);
547 delete $1;
551 defparam_assign_list
552 : defparam_assign
553 | range defparam_assign
554 { yyerror(@1, "error: defparam may not include a range.");
555 delete $1;
557 | defparam_assign_list ',' defparam_assign
560 delay1
561 : '#' delay_value_simple
562 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
563 (*tmp)[0] = $2;
564 $$ = tmp;
566 | '#' '(' delay_value ')'
567 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
568 (*tmp)[0] = $3;
569 $$ = tmp;
573 delay3
574 : '#' delay_value_simple
575 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
576 (*tmp)[0] = $2;
577 $$ = tmp;
579 | '#' '(' delay_value ')'
580 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
581 (*tmp)[0] = $3;
582 $$ = tmp;
584 | '#' '(' delay_value ',' delay_value ')'
585 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
586 (*tmp)[0] = $3;
587 (*tmp)[1] = $5;
588 $$ = tmp;
590 | '#' '(' delay_value ',' delay_value ',' delay_value ')'
591 { svector<PExpr*>*tmp = new svector<PExpr*>(3);
592 (*tmp)[0] = $3;
593 (*tmp)[1] = $5;
594 (*tmp)[2] = $7;
595 $$ = tmp;
599 delay3_opt
600 : delay3 { $$ = $1; }
601 | { $$ = 0; }
604 delay_value_list
605 : delay_value
606 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
607 (*tmp)[0] = $1;
608 $$ = tmp;
610 | delay_value_list ',' delay_value
611 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
612 delete $1;
613 $$ = tmp;
617 delay_value
618 : expression
619 { PExpr*tmp = $1;
620 $$ = tmp;
622 | expression ':' expression ':' expression
623 { $$ = pform_select_mtm_expr($1, $3, $5); }
627 delay_value_simple
628 : DEC_NUMBER
629 { verinum*tmp = $1;
630 if (tmp == 0) {
631 yyerror(@1, "internal error: delay.");
632 $$ = 0;
633 } else {
634 $$ = new PENumber(tmp);
635 FILE_NAME($$, @1);
637 based_size = 0;
639 | REALTIME
640 { verireal*tmp = $1;
641 if (tmp == 0) {
642 yyerror(@1, "internal error: delay.");
643 $$ = 0;
644 } else {
645 $$ = new PEFNumber(tmp);
646 FILE_NAME($$, @1);
649 | IDENTIFIER
650 { PEIdent*tmp = new PEIdent(lex_strings.make($1));
651 FILE_NAME(tmp, @1);
652 $$ = tmp;
653 delete[]$1;
657 description
658 : module
659 | udp_primitive
660 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')'
661 { perm_string tmp3 = lex_strings.make($3);
662 pform_set_type_attrib(tmp3, $5, $7);
663 delete[]$3;
664 delete $5;
668 drive_strength
669 : '(' dr_strength0 ',' dr_strength1 ')'
670 { $$.str0 = $2.str0;
671 $$.str1 = $4.str1;
673 | '(' dr_strength1 ',' dr_strength0 ')'
674 { $$.str0 = $4.str0;
675 $$.str1 = $2.str1;
677 | '(' dr_strength0 ',' K_highz1 ')'
678 { $$.str0 = $2.str0;
679 $$.str1 = PGate::HIGHZ;
681 | '(' dr_strength1 ',' K_highz0 ')'
682 { $$.str0 = PGate::HIGHZ;
683 $$.str1 = $2.str1;
685 | '(' K_highz1 ',' dr_strength0 ')'
686 { $$.str0 = $4.str0;
687 $$.str1 = PGate::HIGHZ;
689 | '(' K_highz0 ',' dr_strength1 ')'
690 { $$.str0 = PGate::HIGHZ;
691 $$.str1 = $4.str1;
695 drive_strength_opt
696 : drive_strength { $$ = $1; }
697 | { $$.str0 = PGate::STRONG; $$.str1 = PGate::STRONG; }
700 dr_strength0
701 : K_supply0 { $$.str0 = PGate::SUPPLY; }
702 | K_strong0 { $$.str0 = PGate::STRONG; }
703 | K_pull0 { $$.str0 = PGate::PULL; }
704 | K_weak0 { $$.str0 = PGate::WEAK; }
707 dr_strength1
708 : K_supply1 { $$.str1 = PGate::SUPPLY; }
709 | K_strong1 { $$.str1 = PGate::STRONG; }
710 | K_pull1 { $$.str1 = PGate::PULL; }
711 | K_weak1 { $$.str1 = PGate::WEAK; }
714 event_control
715 : '@' hierarchy_identifier
716 { PEIdent*tmpi = new PEIdent(*$2);
717 PEEvent*tmpe = new PEEvent(PEEvent::ANYEDGE, tmpi);
718 PEventStatement*tmps = new PEventStatement(tmpe);
719 FILE_NAME(tmps, @1);
720 $$ = tmps;
721 delete $2;
723 | '@' '(' event_expression_list ')'
724 { PEventStatement*tmp = new PEventStatement(*$3);
725 FILE_NAME(tmp, @1);
726 delete $3;
727 $$ = tmp;
729 | '@' '(' error ')'
730 { yyerror(@1, "error: Malformed event control expression.");
731 $$ = 0;
735 event_expression_list
736 : event_expression
737 { $$ = $1; }
738 | event_expression_list K_or event_expression
739 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
740 delete $1;
741 delete $3;
742 $$ = tmp;
744 | event_expression_list ',' event_expression
745 { svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
746 delete $1;
747 delete $3;
748 $$ = tmp;
752 event_expression
753 : K_posedge expression
754 { PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2);
755 FILE_NAME(tmp, @1);
756 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
757 (*tl)[0] = tmp;
758 $$ = tl;
760 | K_negedge expression
761 { PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2);
762 FILE_NAME(tmp, @1);
763 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
764 (*tl)[0] = tmp;
765 $$ = tl;
767 | expression
768 { PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1);
769 FILE_NAME(tmp, @1);
770 svector<PEEvent*>*tl = new svector<PEEvent*>(1);
771 (*tl)[0] = tmp;
772 $$ = tl;
776 expression
777 : expr_primary
778 { $$ = $1; }
779 | '+' expr_primary %prec UNARY_PREC
780 { $$ = $2; }
781 | '-' expr_primary %prec UNARY_PREC
782 { PEUnary*tmp = new PEUnary('-', $2);
783 FILE_NAME(tmp, @2);
784 $$ = tmp;
786 | '~' expr_primary %prec UNARY_PREC
787 { PEUnary*tmp = new PEUnary('~', $2);
788 FILE_NAME(tmp, @2);
789 $$ = tmp;
791 | '&' expr_primary %prec UNARY_PREC
792 { PEUnary*tmp = new PEUnary('&', $2);
793 FILE_NAME(tmp, @2);
794 $$ = tmp;
796 | '!' expr_primary %prec UNARY_PREC
797 { PEUnary*tmp = new PEUnary('!', $2);
798 FILE_NAME(tmp, @2);
799 $$ = tmp;
801 | '|' expr_primary %prec UNARY_PREC
802 { PEUnary*tmp = new PEUnary('|', $2);
803 FILE_NAME(tmp, @2);
804 $$ = tmp;
806 | '^' expr_primary %prec UNARY_PREC
807 { PEUnary*tmp = new PEUnary('^', $2);
808 FILE_NAME(tmp, @2);
809 $$ = tmp;
811 | K_NAND expr_primary %prec UNARY_PREC
812 { PEUnary*tmp = new PEUnary('A', $2);
813 FILE_NAME(tmp, @2);
814 $$ = tmp;
816 | K_NOR expr_primary %prec UNARY_PREC
817 { PEUnary*tmp = new PEUnary('N', $2);
818 FILE_NAME(tmp, @2);
819 $$ = tmp;
821 | K_NXOR expr_primary %prec UNARY_PREC
822 { PEUnary*tmp = new PEUnary('X', $2);
823 FILE_NAME(tmp, @2);
824 $$ = tmp;
826 | '!' error %prec UNARY_PREC
827 { yyerror(@1, "error: Operand of unary ! "
828 "is not a primary expression.");
829 $$ = 0;
831 | '^' error %prec UNARY_PREC
832 { yyerror(@1, "error: Operand of reduction ^ "
833 "is not a primary expression.");
834 $$ = 0;
836 | expression '^' expression
837 { PEBinary*tmp = new PEBinary('^', $1, $3);
838 FILE_NAME(tmp, @2);
839 $$ = tmp;
841 | expression K_POW expression
842 { PEBinary*tmp = new PEBinary('p', $1, $3);
843 FILE_NAME(tmp, @2);
844 $$ = tmp;
846 | expression '*' expression
847 { PEBinary*tmp = new PEBinary('*', $1, $3);
848 FILE_NAME(tmp, @2);
849 $$ = tmp;
851 | expression '/' expression
852 { PEBinary*tmp = new PEBinary('/', $1, $3);
853 FILE_NAME(tmp, @2);
854 $$ = tmp;
856 | expression '%' expression
857 { PEBinary*tmp = new PEBinary('%', $1, $3);
858 FILE_NAME(tmp, @2);
859 $$ = tmp;
861 | expression '+' expression
862 { PEBinary*tmp = new PEBinary('+', $1, $3);
863 FILE_NAME(tmp, @2);
864 $$ = tmp;
866 | expression '-' expression
867 { PEBinary*tmp = new PEBinary('-', $1, $3);
868 FILE_NAME(tmp, @2);
869 $$ = tmp;
871 | expression '&' expression
872 { PEBinary*tmp = new PEBinary('&', $1, $3);
873 FILE_NAME(tmp, @2);
874 $$ = tmp;
876 | expression '|' expression
877 { PEBinary*tmp = new PEBinary('|', $1, $3);
878 FILE_NAME(tmp, @2);
879 $$ = tmp;
881 | expression K_NAND expression
882 { PEBinary*tmp = new PEBinary('A', $1, $3);
883 FILE_NAME(tmp, @2);
884 $$ = tmp;
886 | expression K_NOR expression
887 { PEBinary*tmp = new PEBinary('O', $1, $3);
888 FILE_NAME(tmp, @2);
889 $$ = tmp;
891 | expression K_NXOR expression
892 { PEBinary*tmp = new PEBinary('X', $1, $3);
893 FILE_NAME(tmp, @2);
894 $$ = tmp;
896 | expression '<' expression
897 { PEBinary*tmp = new PEBComp('<', $1, $3);
898 FILE_NAME(tmp, @2);
899 $$ = tmp;
901 | expression '>' expression
902 { PEBinary*tmp = new PEBComp('>', $1, $3);
903 FILE_NAME(tmp, @2);
904 $$ = tmp;
906 | expression K_LS expression
907 { PEBinary*tmp = new PEBShift('l', $1, $3);
908 FILE_NAME(tmp, @2);
909 $$ = tmp;
911 | expression K_RS expression
912 { PEBinary*tmp = new PEBShift('r', $1, $3);
913 FILE_NAME(tmp, @2);
914 $$ = tmp;
916 | expression K_RSS expression
917 { PEBinary*tmp = new PEBShift('R', $1, $3);
918 FILE_NAME(tmp, @2);
919 $$ = tmp;
921 | expression K_EQ expression
922 { PEBinary*tmp = new PEBComp('e', $1, $3);
923 FILE_NAME(tmp, @2);
924 $$ = tmp;
926 | expression K_CEQ expression
927 { PEBinary*tmp = new PEBComp('E', $1, $3);
928 FILE_NAME(tmp, @2);
929 $$ = tmp;
931 | expression K_LE expression
932 { PEBinary*tmp = new PEBComp('L', $1, $3);
933 FILE_NAME(tmp, @2);
934 $$ = tmp;
936 | expression K_GE expression
937 { PEBinary*tmp = new PEBComp('G', $1, $3);
938 FILE_NAME(tmp, @2);
939 $$ = tmp;
941 | expression K_NE expression
942 { PEBinary*tmp = new PEBComp('n', $1, $3);
943 FILE_NAME(tmp, @2);
944 $$ = tmp;
946 | expression K_CNE expression
947 { PEBinary*tmp = new PEBComp('N', $1, $3);
948 FILE_NAME(tmp, @2);
949 $$ = tmp;
951 | expression K_LOR expression
952 { PEBinary*tmp = new PEBinary('o', $1, $3);
953 FILE_NAME(tmp, @2);
954 $$ = tmp;
956 | expression K_LAND expression
957 { PEBinary*tmp = new PEBinary('a', $1, $3);
958 FILE_NAME(tmp, @2);
959 $$ = tmp;
961 | expression '?' expression ':' expression
962 { PETernary*tmp = new PETernary($1, $3, $5);
963 FILE_NAME(tmp, @2);
964 $$ = tmp;
968 expr_mintypmax
969 : expression
970 { $$ = $1; }
971 | expression ':' expression ':' expression
972 { switch (min_typ_max_flag) {
973 case MIN:
974 $$ = $1;
975 delete $3;
976 delete $5;
977 break;
978 case TYP:
979 delete $1;
980 $$ = $3;
981 delete $5;
982 break;
983 case MAX:
984 delete $1;
985 delete $3;
986 $$ = $5;
987 break;
989 if (min_typ_max_warn > 0) {
990 cerr << $$->get_fileline() << ": warning: choosing ";
991 switch (min_typ_max_flag) {
992 case MIN:
993 cerr << "min";
994 break;
995 case TYP:
996 cerr << "typ";
997 break;
998 case MAX:
999 cerr << "max";
1000 break;
1002 cerr << " expression." << endl;
1003 min_typ_max_warn -= 1;
1009 /* Many contexts take a comma separated list of expressions. Null
1010 expressions can happen anywhere in the list, so there are two
1011 extra rules in expression_list_with_nuls for parsing and
1012 installing those nulls.
1014 The expression_list_proper rules do not allow null items in the
1015 expression list, so can be used where nul expressions are not allowed. */
1017 expression_list_with_nuls
1018 : expression_list_with_nuls ',' expression
1019 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
1020 delete $1;
1021 $$ = tmp;
1023 | expression
1024 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1025 (*tmp)[0] = $1;
1026 $$ = tmp;
1029 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1030 (*tmp)[0] = 0;
1031 $$ = tmp;
1034 | expression_list_with_nuls ','
1035 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, 0);
1036 delete $1;
1037 $$ = tmp;
1041 expression_list_proper
1042 : expression_list_proper ',' expression
1043 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
1044 delete $1;
1045 $$ = tmp;
1047 | expression
1048 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
1049 (*tmp)[0] = $1;
1050 $$ = tmp;
1054 expr_primary
1055 : number
1056 { assert($1);
1057 PENumber*tmp = new PENumber($1);
1058 FILE_NAME(tmp, @1);
1059 $$ = tmp;
1061 | REALTIME
1062 { PEFNumber*tmp = new PEFNumber($1);
1063 FILE_NAME(tmp, @1);
1064 $$ = tmp;
1066 | STRING
1067 { PEString*tmp = new PEString($1);
1068 FILE_NAME(tmp, @1);
1069 $$ = tmp;
1071 | SYSTEM_IDENTIFIER
1072 { perm_string tn = lex_strings.make($1);
1073 PECallFunction*tmp = new PECallFunction(tn);
1074 FILE_NAME(tmp, @1);
1075 $$ = tmp;
1076 delete[]$1;
1079 /* The hierarchy_identifier rule matches simple identifiers as well as
1080 indexed arrays and part selects */
1082 | hierarchy_identifier
1083 { PEIdent*tmp = new PEIdent(*$1);
1084 FILE_NAME(tmp, @1);
1085 $$ = tmp;
1086 delete $1;
1089 /* An identifier followed by an expression list in parentheses is a
1090 function call. If a system identifier, then a system function
1091 call. */
1093 | hierarchy_identifier '(' expression_list_proper ')'
1094 { PECallFunction*tmp = new PECallFunction(*$1, *$3);
1095 FILE_NAME(tmp, @1);
1096 delete $1;
1097 $$ = tmp;
1099 | SYSTEM_IDENTIFIER '(' expression_list_proper ')'
1100 { perm_string tn = lex_strings.make($1);
1101 PECallFunction*tmp = new PECallFunction(tn, *$3);
1102 FILE_NAME(tmp, @1);
1103 delete[]$1;
1104 $$ = tmp;
1107 /* Many of the VAMS built-in functions are available as builtin
1108 functions with $system_function equivilents. */
1110 | K_acos '(' expression ')'
1111 { perm_string tn = perm_string::literal("$acos");
1112 PECallFunction*tmp = make_call_function(tn, $3);
1113 FILE_NAME(tmp,@1);
1114 $$ = tmp;
1117 | K_acosh '(' expression ')'
1118 { perm_string tn = perm_string::literal("$acosh");
1119 PECallFunction*tmp = make_call_function(tn, $3);
1120 FILE_NAME(tmp,@1);
1121 $$ = tmp;
1124 | K_asin '(' expression ')'
1125 { perm_string tn = perm_string::literal("$asin");
1126 PECallFunction*tmp = make_call_function(tn, $3);
1127 FILE_NAME(tmp,@1);
1128 $$ = tmp;
1131 | K_asinh '(' expression ')'
1132 { perm_string tn = perm_string::literal("$asinh");
1133 PECallFunction*tmp = make_call_function(tn, $3);
1134 FILE_NAME(tmp,@1);
1135 $$ = tmp;
1138 | K_atan '(' expression ')'
1139 { perm_string tn = perm_string::literal("$atan");
1140 PECallFunction*tmp = make_call_function(tn, $3);
1141 FILE_NAME(tmp,@1);
1142 $$ = tmp;
1145 | K_atanh '(' expression ')'
1146 { perm_string tn = perm_string::literal("$atanh");
1147 PECallFunction*tmp = make_call_function(tn, $3);
1148 FILE_NAME(tmp,@1);
1149 $$ = tmp;
1152 | K_atan2 '(' expression ',' expression ')'
1153 { perm_string tn = perm_string::literal("$atan2");
1154 PECallFunction*tmp = make_call_function(tn, $3, $5);
1155 FILE_NAME(tmp,@1);
1156 $$ = tmp;
1159 | K_ceil '(' expression ')'
1160 { perm_string tn = perm_string::literal("$ceil");
1161 PECallFunction*tmp = make_call_function(tn, $3);
1162 FILE_NAME(tmp,@1);
1163 $$ = tmp;
1166 | K_cos '(' expression ')'
1167 { perm_string tn = perm_string::literal("$cos");
1168 PECallFunction*tmp = make_call_function(tn, $3);
1169 FILE_NAME(tmp,@1);
1170 $$ = tmp;
1173 | K_cosh '(' expression ')'
1174 { perm_string tn = perm_string::literal("$cosh");
1175 PECallFunction*tmp = make_call_function(tn, $3);
1176 FILE_NAME(tmp,@1);
1177 $$ = tmp;
1180 | K_exp '(' expression ')'
1181 { perm_string tn = perm_string::literal("$exp");
1182 PECallFunction*tmp = make_call_function(tn, $3);
1183 FILE_NAME(tmp,@1);
1184 $$ = tmp;
1187 | K_floor '(' expression ')'
1188 { perm_string tn = perm_string::literal("$floor");
1189 PECallFunction*tmp = make_call_function(tn, $3);
1190 FILE_NAME(tmp,@1);
1191 $$ = tmp;
1194 | K_hypot '(' expression ',' expression ')'
1195 { perm_string tn = perm_string::literal("$hypot");
1196 PECallFunction*tmp = make_call_function(tn, $3, $5);
1197 FILE_NAME(tmp,@1);
1198 $$ = tmp;
1201 | K_ln '(' expression ')'
1202 { perm_string tn = perm_string::literal("$ln");
1203 PECallFunction*tmp = make_call_function(tn, $3);
1204 FILE_NAME(tmp,@1);
1205 $$ = tmp;
1208 | K_log '(' expression ')'
1209 { perm_string tn = perm_string::literal("$log10");
1210 PECallFunction*tmp = make_call_function(tn, $3);
1211 FILE_NAME(tmp,@1);
1212 $$ = tmp;
1215 | K_pow '(' expression ',' expression ')'
1216 { perm_string tn = perm_string::literal("$pow");
1217 PECallFunction*tmp = make_call_function(tn, $3, $5);
1218 FILE_NAME(tmp,@1);
1219 $$ = tmp;
1222 | K_sin '(' expression ')'
1223 { perm_string tn = perm_string::literal("$sin");
1224 PECallFunction*tmp = make_call_function(tn, $3);
1225 FILE_NAME(tmp,@1);
1226 $$ = tmp;
1229 | K_sinh '(' expression ')'
1230 { perm_string tn = perm_string::literal("$sinh");
1231 PECallFunction*tmp = make_call_function(tn, $3);
1232 FILE_NAME(tmp,@1);
1233 $$ = tmp;
1236 | K_sqrt '(' expression ')'
1237 { perm_string tn = perm_string::literal("$sqrt");
1238 PECallFunction*tmp = make_call_function(tn, $3);
1239 FILE_NAME(tmp,@1);
1240 $$ = tmp;
1243 | K_tan '(' expression ')'
1244 { perm_string tn = perm_string::literal("$tan");
1245 PECallFunction*tmp = make_call_function(tn, $3);
1246 FILE_NAME(tmp,@1);
1247 $$ = tmp;
1250 | K_tanh '(' expression ')'
1251 { perm_string tn = perm_string::literal("$tanh");
1252 PECallFunction*tmp = make_call_function(tn, $3);
1253 FILE_NAME(tmp,@1);
1254 $$ = tmp;
1257 /* These mathematical functions are conveniently expressed as unary
1258 and binary expressions. They behave much like unary/binary
1259 operators, even though they are parsed as functions. */
1261 | K_abs '(' expression ')'
1262 { PEUnary*tmp = new PEUnary('m', $3);
1263 FILE_NAME(tmp,@1);
1264 $$ = tmp;
1267 | K_max '(' expression ',' expression ')'
1268 { PEBinary*tmp = new PEBinary('M', $3, $5);
1269 FILE_NAME(tmp,@1);
1270 $$ = tmp;
1273 | K_min '(' expression ',' expression ')'
1274 { PEBinary*tmp = new PEBinary('m', $3, $5);
1275 FILE_NAME(tmp,@1);
1276 $$ = tmp;
1279 /* Parenthesized expressions are primaries. */
1281 | '(' expr_mintypmax ')'
1282 { $$ = $2; }
1284 /* Various kinds of concatenation expressions. */
1286 | '{' expression_list_proper '}'
1287 { PEConcat*tmp = new PEConcat(*$2);
1288 FILE_NAME(tmp, @1);
1289 delete $2;
1290 $$ = tmp;
1292 | '{' expression '{' expression_list_proper '}' '}'
1293 { PExpr*rep = $2;
1294 PEConcat*tmp = new PEConcat(*$4, rep);
1295 FILE_NAME(tmp, @1);
1296 delete $4;
1297 $$ = tmp;
1299 | '{' expression '{' expression_list_proper '}' error '}'
1300 { PExpr*rep = $2;
1301 PEConcat*tmp = new PEConcat(*$4, rep);
1302 FILE_NAME(tmp, @1);
1303 delete $4;
1304 $$ = tmp;
1305 yyerror(@5, "error: Syntax error between internal '}' "
1306 "and closing '}' of repeat concatenation.");
1307 yyerrok;
1311 /* A function_item_list borrows the task_port_item run to match
1312 declarations of ports. We check later to make sure there are no
1313 output or inout ports actually used. */
1314 function_item_list
1315 : function_item
1316 { $$ = $1; }
1317 | function_item_list function_item
1318 { if ($1 && $2) {
1319 svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
1320 delete $1;
1321 delete $2;
1322 $$ = tmp;
1323 } else if ($1) {
1324 $$ = $1;
1325 } else {
1326 $$ = $2;
1331 function_item
1332 : task_port_item
1333 { $$ = $1; }
1334 | block_item_decl
1335 { $$ = 0; }
1338 /* A gate_instance is a module instantiation or a built in part
1339 type. In any case, the gate has a set of connections to ports. */
1340 gate_instance
1341 : IDENTIFIER '(' expression_list_with_nuls ')'
1342 { lgate*tmp = new lgate;
1343 tmp->name = $1;
1344 tmp->parms = $3;
1345 tmp->file = @1.text;
1346 tmp->lineno = @1.first_line;
1347 delete[]$1;
1348 $$ = tmp;
1351 | IDENTIFIER range '(' expression_list_with_nuls ')'
1352 { lgate*tmp = new lgate;
1353 svector<PExpr*>*rng = $2;
1354 tmp->name = $1;
1355 tmp->parms = $4;
1356 tmp->range[0] = (*rng)[0];
1357 tmp->range[1] = (*rng)[1];
1358 tmp->file = @1.text;
1359 tmp->lineno = @1.first_line;
1360 delete[]$1;
1361 delete rng;
1362 $$ = tmp;
1364 | '(' expression_list_with_nuls ')'
1365 { lgate*tmp = new lgate;
1366 tmp->name = "";
1367 tmp->parms = $2;
1368 tmp->file = @1.text;
1369 tmp->lineno = @1.first_line;
1370 $$ = tmp;
1373 /* Degenerate modules can have no ports. */
1375 | IDENTIFIER range
1376 { lgate*tmp = new lgate;
1377 svector<PExpr*>*rng = $2;
1378 tmp->name = $1;
1379 tmp->parms = 0;
1380 tmp->parms_by_name = 0;
1381 tmp->range[0] = (*rng)[0];
1382 tmp->range[1] = (*rng)[1];
1383 tmp->file = @1.text;
1384 tmp->lineno = @1.first_line;
1385 delete[]$1;
1386 delete rng;
1387 $$ = tmp;
1390 /* Modules can also take ports by port-name expressions. */
1392 | IDENTIFIER '(' port_name_list ')'
1393 { lgate*tmp = new lgate;
1394 tmp->name = $1;
1395 tmp->parms = 0;
1396 tmp->parms_by_name = $3;
1397 tmp->file = @1.text;
1398 tmp->lineno = @1.first_line;
1399 delete[]$1;
1400 $$ = tmp;
1403 | IDENTIFIER range '(' port_name_list ')'
1404 { lgate*tmp = new lgate;
1405 svector<PExpr*>*rng = $2;
1406 tmp->name = $1;
1407 tmp->parms = 0;
1408 tmp->parms_by_name = $4;
1409 tmp->range[0] = (*rng)[0];
1410 tmp->range[1] = (*rng)[1];
1411 tmp->file = @1.text;
1412 tmp->lineno = @1.first_line;
1413 delete[]$1;
1414 delete rng;
1415 $$ = tmp;
1419 gate_instance_list
1420 : gate_instance_list ',' gate_instance
1421 { svector<lgate>*tmp1 = $1;
1422 lgate*tmp2 = $3;
1423 svector<lgate>*out = new svector<lgate> (*tmp1, *tmp2);
1424 delete tmp1;
1425 delete tmp2;
1426 $$ = out;
1428 | gate_instance
1429 { svector<lgate>*tmp = new svector<lgate>(1);
1430 (*tmp)[0] = *$1;
1431 delete $1;
1432 $$ = tmp;
1436 gatetype
1437 : K_and { $$ = PGBuiltin::AND; }
1438 | K_nand { $$ = PGBuiltin::NAND; }
1439 | K_or { $$ = PGBuiltin::OR; }
1440 | K_nor { $$ = PGBuiltin::NOR; }
1441 | K_xor { $$ = PGBuiltin::XOR; }
1442 | K_xnor { $$ = PGBuiltin::XNOR; }
1443 | K_buf { $$ = PGBuiltin::BUF; }
1444 | K_bufif0 { $$ = PGBuiltin::BUFIF0; }
1445 | K_bufif1 { $$ = PGBuiltin::BUFIF1; }
1446 | K_not { $$ = PGBuiltin::NOT; }
1447 | K_notif0 { $$ = PGBuiltin::NOTIF0; }
1448 | K_notif1 { $$ = PGBuiltin::NOTIF1; }
1449 | K_nmos { $$ = PGBuiltin::NMOS; }
1450 | K_rnmos { $$ = PGBuiltin::RNMOS; }
1451 | K_pmos { $$ = PGBuiltin::PMOS; }
1452 | K_rpmos { $$ = PGBuiltin::RPMOS; }
1453 | K_cmos { $$ = PGBuiltin::CMOS; }
1454 | K_rcmos { $$ = PGBuiltin::RCMOS; }
1455 | K_tran { $$ = PGBuiltin::TRAN; }
1456 | K_rtran { $$ = PGBuiltin::RTRAN; }
1457 | K_tranif0 { $$ = PGBuiltin::TRANIF0; }
1458 | K_tranif1 { $$ = PGBuiltin::TRANIF1; }
1459 | K_rtranif0 { $$ = PGBuiltin::RTRANIF0; }
1460 | K_rtranif1 { $$ = PGBuiltin::RTRANIF1; }
1464 /* A general identifier is a hierarchical name, with the right most
1465 name the base of the identifier. This rule builds up a
1466 hierarchical name from the left to the right, forming a list of
1467 names. */
1469 hierarchy_identifier
1470 : IDENTIFIER
1471 { $$ = new pform_name_t;
1472 $$->push_back(name_component_t(lex_strings.make($1)));
1473 delete[]$1;
1475 | hierarchy_identifier '.' IDENTIFIER
1476 { pform_name_t * tmp = $1;
1477 tmp->push_back(name_component_t(lex_strings.make($3)));
1478 delete[]$3;
1479 $$ = tmp;
1481 | hierarchy_identifier '[' expression ']'
1482 { pform_name_t * tmp = $1;
1483 name_component_t&tail = tmp->back();
1484 index_component_t itmp;
1485 itmp.sel = index_component_t::SEL_BIT;
1486 itmp.msb = $3;
1487 tail.index.push_back(itmp);
1488 $$ = tmp;
1490 | hierarchy_identifier '[' expression ':' expression ']'
1491 { pform_name_t * tmp = $1;
1492 name_component_t&tail = tmp->back();
1493 index_component_t itmp;
1494 itmp.sel = index_component_t::SEL_PART;
1495 itmp.msb = $3;
1496 itmp.lsb = $5;
1497 tail.index.push_back(itmp);
1498 $$ = tmp;
1500 | hierarchy_identifier '[' expression K_PO_POS expression ']'
1501 { pform_name_t * tmp = $1;
1502 name_component_t&tail = tmp->back();
1503 index_component_t itmp;
1504 itmp.sel = index_component_t::SEL_IDX_UP;
1505 itmp.msb = $3;
1506 itmp.lsb = $5;
1507 tail.index.push_back(itmp);
1508 $$ = tmp;
1510 | hierarchy_identifier '[' expression K_PO_NEG expression ']'
1511 { pform_name_t * tmp = $1;
1512 name_component_t&tail = tmp->back();
1513 index_component_t itmp;
1514 itmp.sel = index_component_t::SEL_IDX_DO;
1515 itmp.msb = $3;
1516 itmp.lsb = $5;
1517 tail.index.push_back(itmp);
1518 $$ = tmp;
1522 /* This is a list of identifiers. The result is a list of strings,
1523 each one of the identifiers in the list. These are simple,
1524 non-hierarchical names separated by ',' characters. */
1525 list_of_identifiers
1526 : IDENTIFIER
1527 { $$ = list_from_identifier($1); }
1528 | list_of_identifiers ',' IDENTIFIER
1529 { $$ = list_from_identifier($1, $3); }
1533 /* The list_of_ports and list_of_port_declarations rules are the
1534 port list formats for module ports. The list_of_ports_opt rule is
1535 only used by the module start rule.
1537 The first, the list_of_ports, is the 1364-1995 format, a list of
1538 port names, including .name() syntax.
1540 The list_of_port_declarations the 1364-2001 format, an in-line
1541 declaration of the ports.
1543 In both cases, the list_of_ports and list_of_port_declarations
1544 returns an array of Module::port_t* items that include the name
1545 of the port internally and externally. The actual creation of the
1546 nets/variables is done in the declaration, whether internal to
1547 the port list or in amongst the module items. */
1549 list_of_ports
1550 : port_opt
1551 { svector<Module::port_t*>*tmp
1552 = new svector<Module::port_t*>(1);
1553 (*tmp)[0] = $1;
1554 $$ = tmp;
1556 | list_of_ports ',' port_opt
1557 { svector<Module::port_t*>*tmp
1558 = new svector<Module::port_t*>(*$1, $3);
1559 delete $1;
1560 $$ = tmp;
1564 list_of_port_declarations
1565 : port_declaration
1566 { svector<Module::port_t*>*tmp
1567 = new svector<Module::port_t*>(1);
1568 (*tmp)[0] = $1;
1569 $$ = tmp;
1571 | list_of_port_declarations ',' port_declaration
1572 { svector<Module::port_t*>*tmp
1573 = new svector<Module::port_t*>(*$1, $3);
1574 delete $1;
1575 $$ = tmp;
1577 | list_of_port_declarations ',' IDENTIFIER
1578 { Module::port_t*ptmp;
1579 perm_string name = lex_strings.make($3);
1580 ptmp = pform_module_port_reference(name, @3.text,
1581 @3.first_line);
1582 svector<Module::port_t*>*tmp
1583 = new svector<Module::port_t*>(*$1, ptmp);
1585 /* Get the port declaration details, the port type
1586 and what not, from context data stored by the
1587 last port_declaration rule. */
1588 pform_module_define_port(@3, name,
1589 port_declaration_context.port_type,
1590 port_declaration_context.port_net_type,
1591 port_declaration_context.sign_flag,
1592 port_declaration_context.range, 0);
1593 delete $1;
1594 delete[]$3;
1595 $$ = tmp;
1597 | list_of_port_declarations ','
1599 yyerror(@2, "error: NULL port declarations are not "
1600 "allowed.");
1602 | list_of_port_declarations ';'
1604 yyerror(@2, "error: ';' is an invalid port declaration "
1605 "separator.");
1609 port_declaration
1610 : attribute_list_opt
1611 K_input net_type_opt signed_opt range_opt IDENTIFIER
1612 { Module::port_t*ptmp;
1613 perm_string name = lex_strings.make($6);
1614 ptmp = pform_module_port_reference(name, @2.text,
1615 @2.first_line);
1616 pform_module_define_port(@2, name, NetNet::PINPUT,
1617 $3, $4, $5, $1);
1618 port_declaration_context.port_type = NetNet::PINPUT;
1619 port_declaration_context.port_net_type = $3;
1620 port_declaration_context.sign_flag = $4;
1621 delete port_declaration_context.range;
1622 port_declaration_context.range = $5;
1623 delete $1;
1624 delete[]$6;
1625 $$ = ptmp;
1627 | attribute_list_opt
1628 K_inout net_type_opt signed_opt range_opt IDENTIFIER
1629 { Module::port_t*ptmp;
1630 perm_string name = lex_strings.make($6);
1631 ptmp = pform_module_port_reference(name, @2.text,
1632 @2.first_line);
1633 pform_module_define_port(@2, name, NetNet::PINOUT,
1634 $3, $4, $5, $1);
1635 port_declaration_context.port_type = NetNet::PINOUT;
1636 port_declaration_context.port_net_type = $3;
1637 port_declaration_context.sign_flag = $4;
1638 delete port_declaration_context.range;
1639 port_declaration_context.range = $5;
1640 delete $1;
1641 delete[]$6;
1642 $$ = ptmp;
1644 | attribute_list_opt
1645 K_output net_type_opt signed_opt range_opt IDENTIFIER
1646 { Module::port_t*ptmp;
1647 perm_string name = lex_strings.make($6);
1648 ptmp = pform_module_port_reference(name, @2.text,
1649 @2.first_line);
1650 pform_module_define_port(@2, name, NetNet::POUTPUT,
1651 $3, $4, $5, $1);
1652 port_declaration_context.port_type = NetNet::POUTPUT;
1653 port_declaration_context.port_net_type = $3;
1654 port_declaration_context.sign_flag = $4;
1655 delete port_declaration_context.range;
1656 port_declaration_context.range = $5;
1657 delete $1;
1658 delete[]$6;
1659 $$ = ptmp;
1661 | attribute_list_opt
1662 K_output var_type signed_opt range_opt IDENTIFIER
1663 { Module::port_t*ptmp;
1664 perm_string name = lex_strings.make($6);
1665 ptmp = pform_module_port_reference(name, @2.text,
1666 @2.first_line);
1667 pform_module_define_port(@2, name, NetNet::POUTPUT,
1668 $3, $4, $5, $1);
1669 port_declaration_context.port_type = NetNet::POUTPUT;
1670 port_declaration_context.port_net_type = $3;
1671 port_declaration_context.sign_flag = $4;
1672 delete port_declaration_context.range;
1673 port_declaration_context.range = $5;
1674 delete $1;
1675 delete[]$6;
1676 $$ = ptmp;
1678 | attribute_list_opt
1679 K_output var_type signed_opt range_opt IDENTIFIER '=' expression
1680 { Module::port_t*ptmp;
1681 perm_string name = lex_strings.make($6);
1682 ptmp = pform_module_port_reference(name, @2.text,
1683 @2.first_line);
1684 pform_module_define_port(@2, name, NetNet::POUTPUT,
1685 $3, $4, $5, $1);
1686 port_declaration_context.port_type = NetNet::POUTPUT;
1687 port_declaration_context.port_net_type = $3;
1688 port_declaration_context.sign_flag = $4;
1689 delete port_declaration_context.range;
1690 port_declaration_context.range = $5;
1692 if (! pform_expression_is_constant($8))
1693 yyerror(@8, "error: register declaration assignment"
1694 " value must be a constant expression.");
1695 pform_make_reginit(@6, name, $8);
1697 delete $1;
1698 delete[]$6;
1699 $$ = ptmp;
1705 net_type_opt
1706 : net_type { $$ = $1; }
1707 | { $$ = NetNet::IMPLICIT; }
1710 signed_opt : K_signed { $$ = true; } | {$$ = false; } ;
1712 /* An lpvalue is the expression that can go on the left side of a
1713 procedural assignment. This rule handles only procedural
1714 assignments. It is more limited then the general expr_primary
1715 rule to reflect the rules for assignment l-values. */
1716 lpvalue
1717 : hierarchy_identifier
1718 { PEIdent*tmp = new PEIdent(*$1);
1719 FILE_NAME(tmp, @1);
1720 $$ = tmp;
1721 delete $1;
1723 | '{' expression_list_proper '}'
1724 { PEConcat*tmp = new PEConcat(*$2);
1725 FILE_NAME(tmp, @1);
1726 delete $2;
1727 $$ = tmp;
1732 /* Continuous assignments have a list of individual assignments. */
1734 cont_assign
1735 : lpvalue '=' expression
1736 { svector<PExpr*>*tmp = new svector<PExpr*>(2);
1737 (*tmp)[0] = $1;
1738 (*tmp)[1] = $3;
1739 $$ = tmp;
1743 cont_assign_list
1744 : cont_assign_list ',' cont_assign
1745 { svector<PExpr*>*tmp = new svector<PExpr*>(*$1, *$3);
1746 delete $1;
1747 delete $3;
1748 $$ = tmp;
1750 | cont_assign
1751 { $$ = $1; }
1755 /* This is the global structure of a module. A module in a start
1756 section, with optional ports, then an optional list of module
1757 items, and finally an end marker. */
1759 module : attribute_list_opt module_start IDENTIFIER
1760 { pform_startmodule($3, @2.text, @2.first_line, $1); }
1761 module_parameter_port_list_opt
1762 module_port_list_opt ';'
1763 { pform_module_set_ports($6); }
1764 module_item_list_opt
1765 K_endmodule
1766 { pform_endmodule($3);
1767 delete[]$3;
1772 module_start : K_module | K_macromodule ;
1774 module_port_list_opt
1775 : '(' list_of_ports ')' { $$ = $2; }
1776 | '(' list_of_port_declarations ')' { $$ = $2; }
1777 | { $$ = 0; }
1780 /* Module declarations include optional ANSI style module parameter
1781 ports. These are simply advance ways to declare parameters, so
1782 that the port declarations may use them. */
1783 module_parameter_port_list_opt
1785 | '#' '(' module_parameter_port_list ')'
1788 module_parameter_port_list
1789 : K_parameter parameter_assign
1790 | module_parameter_port_list ',' parameter_assign
1791 | module_parameter_port_list ',' K_parameter parameter_assign
1794 module_item
1796 /* This rule detects net declarations that possibly include a
1797 primitive type, an optional vector range and signed flag. This
1798 also includes an optional delay set. The values are then applied
1799 to a list of names. If the primitive type is not specified, then
1800 resort to the default type LOGIC. */
1802 : attribute_list_opt net_type
1803 primitive_type_opt signed_opt range_opt
1804 delay3_opt
1805 net_variable_list ';'
1807 { ivl_variable_type_t dtype = $3;
1808 if (dtype == IVL_VT_NO_TYPE)
1809 dtype = IVL_VT_LOGIC;
1810 pform_makewire(@2, $5, $4, $7, $2,
1811 NetNet::NOT_A_PORT, dtype, $1);
1812 if ($6 != 0) {
1813 yyerror(@6, "sorry: net delays not supported.");
1814 delete $6;
1816 if ($1) delete $1;
1819 /* Very similar to the rule above, but this takes a list of
1820 net_decl_assigns, which are <name> = <expr> assignment
1821 declarations. */
1823 | attribute_list_opt net_type
1824 primitive_type_opt signed_opt range_opt
1825 delay3_opt net_decl_assigns ';'
1827 { ivl_variable_type_t dtype = $3;
1828 if (dtype == IVL_VT_NO_TYPE)
1829 dtype = IVL_VT_LOGIC;
1830 pform_makewire(@2, $5, $4, $6,
1831 str_strength, $7, $2, dtype);
1832 if ($1) {
1833 yyerror(@2, "sorry: Attributes not supported "
1834 "on net declaration assignments.");
1835 delete $1;
1839 /* This form doesn't have the range, but does have strengths. This
1840 gives strength to the assignment drivers. */
1842 | attribute_list_opt net_type
1843 primitive_type_opt signed_opt
1844 drive_strength net_decl_assigns ';'
1846 { ivl_variable_type_t dtype = $3;
1847 if (dtype == IVL_VT_NO_TYPE)
1848 dtype = IVL_VT_LOGIC;
1849 pform_makewire(@2, 0, $4, 0, $5, $6, $2, dtype);
1850 if ($1) {
1851 yyerror(@2, "sorry: Attributes not supported "
1852 "on net declaration assignments.");
1853 delete $1;
1857 | K_trireg charge_strength_opt range_opt delay3_opt list_of_identifiers ';'
1858 { yyerror(@1, "sorry: trireg nets not supported.");
1859 delete $3;
1860 delete $4;
1863 | port_type signed_opt range_opt delay3_opt list_of_identifiers ';'
1864 { pform_set_port_type(@1, $5, $3, $2, $1);
1867 /* The next two rules handle Verilog 2001 statements of the form:
1868 input wire signed [h:l] <list>;
1869 This creates the wire and sets the port type all at once. */
1871 | port_type net_type signed_opt range_opt list_of_identifiers ';'
1872 { pform_makewire(@1, $4, $3, $5, $2, $1, IVL_VT_NO_TYPE, 0,
1873 SR_BOTH);
1876 | K_output var_type signed_opt range_opt list_of_identifiers ';'
1877 { pform_makewire(@1, $4, $3, $5, $2, NetNet::POUTPUT,
1878 IVL_VT_NO_TYPE, 0, SR_BOTH);
1881 /* var_type declaration (reg variables) cannot be input or output,
1882 because the port declaration implies an external driver, which
1883 cannot be attached to a reg. These rules catch that error early. */
1885 | K_input var_type signed_opt range_opt list_of_identifiers ';'
1886 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINPUT,
1887 IVL_VT_NO_TYPE, 0);
1888 yyerror(@2, "error: reg variables cannot be inputs.");
1891 | K_inout var_type signed_opt range_opt list_of_identifiers ';'
1892 { pform_makewire(@1, $4, $3, $5, $2, NetNet::PINOUT,
1893 IVL_VT_NO_TYPE, 0);
1894 yyerror(@2, "error: reg variables cannot be inouts.");
1897 | port_type signed_opt range_opt delay3_opt error ';'
1898 { yyerror(@1, "error: Invalid variable list"
1899 " in port declaration.");
1900 if ($3) delete $3;
1901 if ($4) delete $4;
1902 yyerrok;
1905 /* block_item_decl rule is shared with task blocks and named
1906 begin/end. */
1908 | block_item_decl
1910 /* */
1912 | K_defparam defparam_assign_list ';'
1913 | K_event list_of_identifiers ';'
1914 { pform_make_events($2, @1.text, @1.first_line);
1917 /* Most gate types have an optional drive strength and optional
1918 three-value delay. These rules handle the different cases. */
1920 | attribute_list_opt gatetype gate_instance_list ';'
1921 { pform_makegates($2, str_strength, 0, $3, $1);
1924 | attribute_list_opt gatetype delay3 gate_instance_list ';'
1925 { pform_makegates($2, str_strength, $3, $4, $1);
1928 | attribute_list_opt gatetype drive_strength gate_instance_list ';'
1929 { pform_makegates($2, $3, 0, $4, $1);
1932 | attribute_list_opt gatetype drive_strength delay3 gate_instance_list ';'
1933 { pform_makegates($2, $3, $4, $5, $1);
1936 /* Pullup and pulldown devices cannot have delays, and their
1937 strengths are limited. */
1939 | K_pullup gate_instance_list ';'
1940 { pform_makegates(PGBuiltin::PULLUP, pull_strength, 0,
1941 $2, 0);
1943 | K_pulldown gate_instance_list ';'
1944 { pform_makegates(PGBuiltin::PULLDOWN, pull_strength,
1945 0, $2, 0);
1948 | K_pullup '(' dr_strength1 ')' gate_instance_list ';'
1949 { pform_makegates(PGBuiltin::PULLUP, $3, 0, $5, 0);
1952 | K_pulldown '(' dr_strength0 ')' gate_instance_list ';'
1953 { pform_makegates(PGBuiltin::PULLDOWN, $3, 0, $5, 0);
1956 /* This rule handles instantiations of modules and user defined
1957 primitives. These devices to not have delay lists or strengths,
1958 but then can have parameter lists. */
1960 | attribute_list_opt
1961 IDENTIFIER parameter_value_opt gate_instance_list ';'
1962 { perm_string tmp1 = lex_strings.make($2);
1963 pform_make_modgates(tmp1, $3, $4);
1964 delete[]$2;
1965 if ($1) delete $1;
1968 | attribute_list_opt
1969 IDENTIFIER parameter_value_opt error ';'
1970 { yyerror(@2, "error: Invalid module instantiation");
1971 delete[]$2;
1972 if ($1) delete $1;
1975 /* Continuous assignment can have an optional drive strength, then
1976 an optional delay3 that applies to all the assignments in the
1977 cont_assign_list. */
1979 | K_assign drive_strength_opt delay3_opt cont_assign_list ';'
1980 { pform_make_pgassign_list($4, $3, $2, @1.text, @1.first_line); }
1982 /* Always and initial items are behavioral processes. */
1984 | attribute_list_opt K_always statement
1985 { PProcess*tmp = pform_make_behavior(PProcess::PR_ALWAYS,
1986 $3, $1);
1987 FILE_NAME(tmp, @2);
1989 | attribute_list_opt K_initial statement
1990 { PProcess*tmp = pform_make_behavior(PProcess::PR_INITIAL,
1991 $3, $1);
1992 FILE_NAME(tmp, @2);
1995 /* The task declaration rule matches the task declaration
1996 header, then pushes the function scope. This causes the
1997 definitions in the task_body to take on the scope of the task
1998 instead of the module. Note that these runs accept for the task
1999 body statement_or_null, although the standard does not allow null
2000 statements in the task body. But we continue to accept it as an
2001 extension. */
2003 | K_task IDENTIFIER ';'
2004 { assert(current_task == 0);
2005 current_task = pform_push_task_scope($2);
2006 FILE_NAME(current_task, @1);
2008 task_item_list_opt
2009 statement_or_null
2010 K_endtask
2011 { current_task->set_ports($5);
2012 current_task->set_statement($6);
2013 pform_pop_scope();
2014 current_task = 0;
2015 delete[]$2;
2018 | K_task IDENTIFIER
2019 { assert(current_task == 0);
2020 current_task = pform_push_task_scope($2);
2021 FILE_NAME(current_task, @1);
2023 '(' task_port_decl_list ')' ';'
2024 block_item_decls_opt
2025 statement_or_null
2026 K_endtask
2027 { current_task->set_ports($5);
2028 current_task->set_statement($9);
2029 pform_pop_scope();
2030 current_task = 0;
2031 delete[]$2;
2033 | K_task IDENTIFIER error K_endtask
2035 pform_pop_scope();
2036 current_task = 0;
2037 delete[]$2;
2040 /* The function declaration rule matches the function declaration
2041 header, then pushes the function scope. This causes the
2042 definitions in the func_body to take on the scope of the function
2043 instead of the module. */
2045 | K_function function_range_or_type_opt IDENTIFIER ';'
2046 { assert(current_function == 0);
2047 current_function = pform_push_function_scope($3);
2048 FILE_NAME(current_function, @1);
2050 function_item_list statement
2051 K_endfunction
2052 { current_function->set_ports($6);
2053 current_function->set_statement($7);
2054 current_function->set_return($2);
2055 pform_pop_scope();
2056 current_function = 0;
2057 delete[]$3;
2060 | K_function function_range_or_type_opt IDENTIFIER
2061 { assert(current_function == 0);
2062 current_function = pform_push_function_scope($3);
2063 FILE_NAME(current_function, @1);
2065 '(' task_port_decl_list ')' ';'
2066 block_item_decls_opt
2067 statement
2068 K_endfunction
2069 { current_function->set_ports($6);
2070 current_function->set_statement($10);
2071 current_function->set_return($2);
2072 pform_pop_scope();
2073 current_function = 0;
2074 delete[]$3;
2076 | K_function function_range_or_type_opt IDENTIFIER error K_endfunction
2078 pform_pop_scope();
2079 current_task = 0;
2080 delete[]$3;
2083 /* A generate region can contain further module items. Actually, it
2084 is supposed to be limited to certain kinds of module items, but
2085 the semantic tests will check that for us. */
2087 | K_generate module_item_list_opt K_endgenerate
2089 | K_genvar list_of_identifiers ';'
2090 { pform_genvars(@1, $2); }
2092 | K_for '(' IDENTIFIER '=' expression ';'
2093 expression ';'
2094 IDENTIFIER '=' expression ')'
2095 { pform_start_generate_for(@1, $3, $5, $7, $9, $11); }
2096 generate_block
2097 { pform_endgenerate(); }
2099 | generate_if
2100 generate_block_opt
2101 K_else
2102 { pform_start_generate_else(@1); }
2103 generate_block
2104 { pform_endgenerate(); }
2106 | generate_if
2107 generate_block_opt %prec less_than_K_else
2108 { pform_endgenerate(); }
2110 | K_case '(' expression ')'
2111 { pform_start_generate_case(@1, $3); }
2112 generate_case_items
2113 K_endcase
2114 { pform_endgenerate(); }
2116 /* specify blocks are parsed but ignored. */
2118 | K_specify K_endspecify
2119 { /* empty lists are legal syntax. */ }
2121 | K_specify specify_item_list K_endspecify
2125 | K_specify error K_endspecify
2126 { yyerror(@1, "error: syntax error in specify block");
2127 yyerrok;
2130 /* These rules match various errors that the user can type into
2131 module items. These rules try to catch them at a point where a
2132 reasonable error message can be produced. */
2134 | K_module error ';'
2135 { yyerror(@1, "error: missing endmodule or attempt to "
2136 "nest modules.");
2137 pform_error_nested_modules();
2138 yyerrok;
2141 | error ';'
2142 { yyerror(@2, "error: invalid module item.");
2143 yyerrok;
2146 | K_assign error '=' expression ';'
2147 { yyerror(@1, "error: syntax error in left side "
2148 "of continuous assignment.");
2149 yyerrok;
2152 | K_assign error ';'
2153 { yyerror(@1, "error: syntax error in "
2154 "continuous assignment");
2155 yyerrok;
2158 | K_function error K_endfunction
2159 { yyerror(@1, "error: I give up on this "
2160 "function definition.");
2161 yyerrok;
2164 /* These rules are for the Icarus Verilog specific $attribute
2165 extensions. Then catch the parameters of the $attribute keyword. */
2167 | KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')' ';'
2168 { perm_string tmp3 = lex_strings.make($3);
2169 perm_string tmp5 = lex_strings.make($5);
2170 pform_set_attrib(tmp3, tmp5, $7);
2171 delete[]$3;
2172 delete $5;
2174 | KK_attribute '(' error ')' ';'
2175 { yyerror(@1, "error: Malformed $attribute parameter list."); }
2178 generate_if : K_if '(' expression ')' { pform_start_generate_if(@1, $3); }
2180 generate_case_items
2181 : generate_case_items generate_case_item
2182 | generate_case_item
2185 generate_case_item
2186 : expression ':' { pform_generate_case_item(@1, $1); } generate_block
2187 { pform_endgenerate(); }
2188 | K_default ':' { pform_generate_case_item(@1, 0); } generate_block
2189 { pform_endgenerate(); }
2192 module_item_list
2193 : module_item_list module_item
2194 | module_item
2197 module_item_list_opt
2198 : module_item_list
2202 /* A generate block is the thing within a generate scheme. It may be
2203 a single module item, an anonymous block of module items, or a
2204 named module item. In all cases, the meat is in the module items
2205 inside, and the processing is done by the module_item rules. We
2206 only need to take note here of the scope name, if any. */
2208 generate_block
2209 : module_item
2210 | K_begin module_item_list_opt K_end
2211 | K_begin ':' IDENTIFIER module_item_list_opt K_end
2212 { pform_generate_block_name($3); }
2215 generate_block_opt : generate_block | ';' ;
2218 /* A net declaration assignment allows the programmer to combine the
2219 net declaration and the continuous assignment into a single
2220 statement.
2222 Note that the continuous assignment statement is generated as a
2223 side effect, and all I pass up is the name of the l-value. */
2225 net_decl_assign
2226 : IDENTIFIER '=' expression
2227 { net_decl_assign_t*tmp = new net_decl_assign_t;
2228 tmp->next = tmp;
2229 tmp->name = lex_strings.make($1);
2230 tmp->expr = $3;
2231 delete[]$1;
2232 $$ = tmp;
2236 net_decl_assigns
2237 : net_decl_assigns ',' net_decl_assign
2238 { net_decl_assign_t*tmp = $1;
2239 $3->next = tmp->next;
2240 tmp->next = $3;
2241 $$ = tmp;
2243 | net_decl_assign
2244 { $$ = $1;
2248 primitive_type
2249 : K_logic { $$ = IVL_VT_LOGIC; }
2250 | K_bool { $$ = IVL_VT_BOOL; }
2251 | K_real { $$ = IVL_VT_REAL; }
2254 primitive_type_opt : primitive_type { $$ = $1; } | { $$ = IVL_VT_NO_TYPE; } ;
2256 net_type
2257 : K_wire { $$ = NetNet::WIRE; }
2258 | K_tri { $$ = NetNet::TRI; }
2259 | K_tri1 { $$ = NetNet::TRI1; }
2260 | K_supply0 { $$ = NetNet::SUPPLY0; }
2261 | K_wand { $$ = NetNet::WAND; }
2262 | K_triand { $$ = NetNet::TRIAND; }
2263 | K_tri0 { $$ = NetNet::TRI0; }
2264 | K_supply1 { $$ = NetNet::SUPPLY1; }
2265 | K_wor { $$ = NetNet::WOR; }
2266 | K_trior { $$ = NetNet::TRIOR; }
2267 | K_wone { $$ = NetNet::WONE; }
2270 var_type
2271 : K_reg { $$ = NetNet::REG; }
2274 /* In this rule we have matched the "parameter" keyword. The rule
2275 generates a type (optional) and a list of assignments. */
2277 parameter_assign_decl
2278 : parameter_assign_list
2279 | range { active_range = $1; active_signed = false; }
2280 parameter_assign_list
2281 { active_range = 0;
2282 active_signed = false;
2284 | K_signed range { active_range = $2; active_signed = true; }
2285 parameter_assign_list
2286 { active_range = 0;
2287 active_signed = false;
2289 | K_integer { active_range = 0; active_signed = true; }
2290 parameter_assign_list
2291 { active_range = 0;
2292 active_signed = false;
2296 parameter_assign_list
2297 : parameter_assign
2298 | parameter_assign_list ',' parameter_assign
2301 parameter_assign
2302 : IDENTIFIER '=' expression
2303 { PExpr*tmp = $3;
2304 if (!pform_expression_is_constant(tmp)) {
2305 yyerror(@3, "error: parameter value "
2306 "must be a constant expression.");
2307 delete tmp;
2308 tmp = 0;
2309 } else {
2310 pform_set_parameter(lex_strings.make($1),
2311 active_signed,
2312 active_range, tmp,
2313 @1.text, @1.first_line);
2315 delete[]$1;
2319 /* Localparam assignments and assignment lists are broken into
2320 separate BNF so that I can call slightly different parameter
2321 handling code. They parse the same as parameters, they just
2322 behave differently when someone tries to override them. */
2324 localparam_assign
2325 : IDENTIFIER '=' expression
2326 { PExpr*tmp = $3;
2327 if (!pform_expression_is_constant(tmp)) {
2328 yyerror(@3, "error: parameter value "
2329 "must be constant.");
2330 delete tmp;
2331 tmp = 0;
2332 } else {
2333 pform_set_localparam(lex_strings.make($1),
2334 active_signed,
2335 active_range, tmp,
2336 @1.text, @1.first_line);
2338 delete[]$1;
2342 localparam_assign_decl
2343 : localparam_assign_list
2344 | range { active_range = $1; active_signed = false; }
2345 localparam_assign_list
2346 { active_range = 0;
2347 active_signed = false;
2349 | K_signed range { active_range = $2; active_signed = true; }
2350 localparam_assign_list
2351 { active_range = 0;
2352 active_signed = false;
2354 | K_integer { active_range = 0; active_signed = true; }
2355 localparam_assign_list
2356 { active_range = 0;
2357 active_signed = false;
2361 localparam_assign_list
2362 : localparam_assign
2363 | localparam_assign_list ',' localparam_assign
2368 /* The parameters of a module instance can be overridden by writing
2369 a list of expressions in a syntax much like a delay list. (The
2370 difference being the list can have any length.) The pform that
2371 attaches the expression list to the module checks that the
2372 expressions are constant.
2374 Although the BNF in IEEE1364-1995 implies that parameter value
2375 lists must be in parentheses, in practice most compilers will
2376 accept simple expressions outside of parentheses if there is only
2377 one value, so I'll accept simple numbers here.
2379 The parameter value by name syntax is OVI enhancement BTF-B06 as
2380 approved by WG1364 on 6/28/1998. */
2382 parameter_value_opt
2383 : '#' '(' expression_list_with_nuls ')'
2384 { struct parmvalue_t*tmp = new struct parmvalue_t;
2385 tmp->by_order = $3;
2386 tmp->by_name = 0;
2387 $$ = tmp;
2389 | '#' '(' parameter_value_byname_list ')'
2390 { struct parmvalue_t*tmp = new struct parmvalue_t;
2391 tmp->by_order = 0;
2392 tmp->by_name = $3;
2393 $$ = tmp;
2395 | '#' DEC_NUMBER
2396 { assert($2);
2397 PENumber*tmp = new PENumber($2);
2398 FILE_NAME(tmp, @1);
2400 struct parmvalue_t*lst = new struct parmvalue_t;
2401 lst->by_order = new svector<PExpr*>(1);
2402 (*lst->by_order)[0] = tmp;
2403 lst->by_name = 0;
2404 $$ = lst;
2405 based_size = 0;
2407 | '#' error
2408 { yyerror(@1, "error: syntax error in parameter value "
2409 "assignment list.");
2410 $$ = 0;
2413 { $$ = 0; }
2416 parameter_value_byname
2417 : '.' IDENTIFIER '(' expression ')'
2418 { named_pexpr_t*tmp = new named_pexpr_t;
2419 tmp->name = lex_strings.make($2);
2420 tmp->parm = $4;
2421 delete[]$2;
2422 $$ = tmp;
2424 | '.' IDENTIFIER '(' ')'
2425 { named_pexpr_t*tmp = new named_pexpr_t;
2426 tmp->name = lex_strings.make($2);
2427 tmp->parm = 0;
2428 delete[]$2;
2429 $$ = tmp;
2433 parameter_value_byname_list
2434 : parameter_value_byname
2435 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2436 (*tmp)[0] = $1;
2437 $$ = tmp;
2439 | parameter_value_byname_list ',' parameter_value_byname
2440 { svector<named_pexpr_t*>*tmp =
2441 new svector<named_pexpr_t*>(*$1,$3);
2442 delete $1;
2443 $$ = tmp;
2448 /* The port (of a module) is a fairly complex item. Each port is
2449 handled as a Module::port_t object. A simple port reference has a
2450 name and a PExpr object, but more complex constructs are possible
2451 where the name can be attached to a list of PWire objects.
2453 The port_reference returns a Module::port_t, and so does the
2454 port_reference_list. The port_reference_list may have built up a
2455 list of PWires in the port_t object, but it is still a single
2456 Module::port_t object.
2458 The port rule below takes the built up Module::port_t object and
2459 tweaks its name as needed. */
2461 port
2462 : port_reference
2463 { $$ = $1; }
2465 /* This syntax attaches an external name to the port reference so
2466 that the caller can bind by name to non-trivial port
2467 references. The port_t object gets its PWire from the
2468 port_reference, but its name from the IDENTIFIER. */
2470 | '.' IDENTIFIER '(' port_reference ')'
2471 { Module::port_t*tmp = $4;
2472 tmp->name = lex_strings.make($2);
2473 delete[]$2;
2474 $$ = tmp;
2477 /* A port can also be a concatenation of port references. In this
2478 case the port does not have a name available to the outside, only
2479 positional parameter passing is possible here. */
2481 | '{' port_reference_list '}'
2482 { Module::port_t*tmp = $2;
2483 tmp->name = perm_string();
2484 $$ = tmp;
2487 /* This attaches a name to a port reference concatenation list so
2488 that parameter passing be name is possible. */
2490 | '.' IDENTIFIER '(' '{' port_reference_list '}' ')'
2491 { Module::port_t*tmp = $5;
2492 tmp->name = lex_strings.make($2);
2493 delete[]$2;
2494 $$ = tmp;
2498 port_opt
2499 : port { $$ = $1; }
2500 | { $$ = 0; }
2504 /* A port reference is an internal (to the module) name of the port,
2505 possibly with a part of bit select to attach it to specific bits
2506 of a signal fully declared inside the module.
2508 The parser creates a PEIdent for every port reference, even if the
2509 signal is bound to different ports. The elaboration figures out
2510 the mess that this creates. The port_reference (and the
2511 port_reference_list below) puts the port reference PEIdent into the
2512 port_t object to pass it up to the module declaration code. */
2514 port_reference
2516 : IDENTIFIER
2517 { Module::port_t*ptmp;
2518 perm_string name = lex_strings.make($1);
2519 ptmp = pform_module_port_reference(name, @1.text, @1.first_line);
2520 delete[]$1;
2521 $$ = ptmp;
2524 | IDENTIFIER '[' expression ':' expression ']'
2525 { if (!pform_expression_is_constant($3)) {
2526 yyerror(@3, "error: msb expression of "
2527 "port part select must be constant.");
2529 if (!pform_expression_is_constant($5)) {
2530 yyerror(@5, "error: lsb expression of "
2531 "port part select must be constant.");
2533 index_component_t itmp;
2534 itmp.sel = index_component_t::SEL_PART;
2535 itmp.msb = $3;
2536 itmp.lsb = $5;
2538 name_component_t ntmp (lex_strings.make($1));
2539 ntmp.index.push_back(itmp);
2541 pform_name_t pname;
2542 pname.push_back(ntmp);
2544 PEIdent*wtmp = new PEIdent(pname);
2545 FILE_NAME(wtmp, @1);
2547 Module::port_t*ptmp = new Module::port_t;
2548 ptmp->name = perm_string();
2549 ptmp->expr = svector<PEIdent*>(1);
2550 ptmp->expr[0] = wtmp;
2552 delete[]$1;
2553 $$ = ptmp;
2556 | IDENTIFIER '[' expression ']'
2557 { if (!pform_expression_is_constant($3)) {
2558 yyerror(@3, "error: port bit select "
2559 "must be constant.");
2561 index_component_t itmp;
2562 itmp.sel = index_component_t::SEL_BIT;
2563 itmp.msb = $3;
2564 itmp.lsb = 0;
2566 name_component_t ntmp (lex_strings.make($1));
2567 ntmp.index.push_back(itmp);
2569 pform_name_t pname;
2570 pname.push_back(ntmp);
2572 PEIdent*tmp = new PEIdent(pname);
2573 FILE_NAME(tmp, @1);
2575 Module::port_t*ptmp = new Module::port_t;
2576 ptmp->name = perm_string();
2577 ptmp->expr = svector<PEIdent*>(1);
2578 ptmp->expr[0] = tmp;
2579 delete[]$1;
2580 $$ = ptmp;
2583 | IDENTIFIER '[' error ']'
2584 { yyerror(@1, "error: invalid port bit select");
2585 Module::port_t*ptmp = new Module::port_t;
2586 PEIdent*wtmp = new PEIdent(lex_strings.make($1));
2587 FILE_NAME(wtmp, @1);
2588 ptmp->name = lex_strings.make($1);
2589 ptmp->expr = svector<PEIdent*>(1);
2590 ptmp->expr[0] = wtmp;
2591 delete[]$1;
2592 $$ = ptmp;
2597 port_reference_list
2598 : port_reference
2599 { $$ = $1; }
2600 | port_reference_list ',' port_reference
2601 { Module::port_t*tmp = $1;
2602 tmp->expr = svector<PEIdent*>(tmp->expr, $3->expr);
2603 delete $3;
2604 $$ = tmp;
2608 /* The port_name rule is used with a module is being *instantiated*,
2609 and not when it is being declared. See the port rule if you are
2610 looking for the ports of a module declaration. */
2612 port_name
2613 : '.' IDENTIFIER '(' expression ')'
2614 { named_pexpr_t*tmp = new named_pexpr_t;
2615 tmp->name = lex_strings.make($2);
2616 tmp->parm = $4;
2617 delete[]$2;
2618 $$ = tmp;
2620 | '.' IDENTIFIER '(' error ')'
2621 { yyerror(@3, "error: invalid port connection expression.");
2622 named_pexpr_t*tmp = new named_pexpr_t;
2623 tmp->name = lex_strings.make($2);
2624 tmp->parm = 0;
2625 delete[]$2;
2626 $$ = tmp;
2628 | '.' IDENTIFIER '(' ')'
2629 { named_pexpr_t*tmp = new named_pexpr_t;
2630 tmp->name = lex_strings.make($2);
2631 tmp->parm = 0;
2632 delete[]$2;
2633 $$ = tmp;
2637 port_name_list
2638 : port_name_list ',' port_name
2639 { svector<named_pexpr_t*>*tmp;
2640 tmp = new svector<named_pexpr_t*>(*$1, $3);
2641 delete $1;
2642 $$ = tmp;
2644 | port_name
2645 { svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
2646 (*tmp)[0] = $1;
2647 $$ = tmp;
2651 port_type
2652 : K_input { $$ = NetNet::PINPUT; }
2653 | K_output { $$ = NetNet::POUTPUT; }
2654 | K_inout { $$ = NetNet::PINOUT; }
2657 range
2658 : '[' expression ':' expression ']'
2659 { svector<PExpr*>*tmp = new svector<PExpr*> (2);
2660 if (!pform_expression_is_constant($2))
2661 yyerror(@2, "error: msb of range must be constant.");
2663 (*tmp)[0] = $2;
2665 if (!pform_expression_is_constant($4))
2666 yyerror(@4, "error: lsb of range must be constant.");
2668 (*tmp)[1] = $4;
2670 $$ = tmp;
2674 range_opt
2675 : range
2676 | { $$ = 0; }
2678 dimensions_opt
2679 : { $$ = 0; }
2680 | dimensions { $$ = $1; }
2682 dimensions
2683 : '[' expression ':' expression ']'
2684 { list<index_component_t> *tmp = new list<index_component_t>;
2685 index_component_t index;
2686 if (!pform_expression_is_constant($2))
2687 yyerror(@2, "error: left array address must be "
2688 "constant.");
2689 index.msb = $2;
2690 if (!pform_expression_is_constant($4))
2691 yyerror(@4, "error: right array address must be "
2692 "constant.");
2693 index.lsb = $4;
2694 tmp->push_back(index);
2695 $$ = tmp;
2697 | dimensions '[' expression ':' expression ']'
2698 { list<index_component_t> *tmp = $1;
2699 index_component_t index;
2700 if (!pform_expression_is_constant($3))
2701 yyerror(@3, "error: left array address must be "
2702 "constant.");
2703 index.msb = $3;
2704 if (!pform_expression_is_constant($5))
2705 yyerror(@5, "error: right array address must be "
2706 "constant.");
2707 index.lsb = $5;
2708 tmp->push_back(index);
2709 $$ = tmp;
2712 /* This is used to express the return type of a function. */
2713 function_range_or_type_opt
2714 : range { $$.range = $1; $$.type = PTF_REG; }
2715 | K_signed range { $$.range = $2; $$.type = PTF_REG_S; }
2716 | K_integer { $$.range = 0; $$.type = PTF_INTEGER; }
2717 | K_real { $$.range = 0; $$.type = PTF_REAL; }
2718 | K_realtime { $$.range = 0; $$.type = PTF_REALTIME; }
2719 | K_time { $$.range = 0; $$.type = PTF_TIME; }
2720 | { $$.range = 0; $$.type = PTF_REG; }
2723 /* The register_variable rule is matched only when I am parsing
2724 variables in a "reg" definition. I therefore know that I am
2725 creating registers and I do not need to let the containing rule
2726 handle it. The register variable list simply packs them together
2727 so that bit ranges can be assigned. */
2728 register_variable
2729 : IDENTIFIER dimensions_opt
2730 { perm_string ident_name = lex_strings.make($1);
2731 pform_makewire(@1, ident_name, NetNet::REG,
2732 NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0);
2733 if ($2 != 0) {
2734 index_component_t index;
2735 if ($2->size() > 1) {
2736 yyerror(@2, "sorry: only 1 dimensional arrays "
2737 "are currently supported.");
2739 index = $2->front();
2740 pform_set_reg_idx(ident_name, index.msb, index.lsb);
2741 delete $2;
2743 $$ = $1;
2745 | IDENTIFIER '=' expression
2746 { perm_string ident_name = lex_strings.make($1);
2747 pform_makewire(@1, ident_name, NetNet::REG,
2748 NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0);
2749 if (! pform_expression_is_constant($3))
2750 yyerror(@3, "error: register declaration assignment"
2751 " value must be a constant expression.");
2752 pform_make_reginit(@1, ident_name, $3);
2753 $$ = $1;
2757 register_variable_list
2758 : register_variable
2759 { list<perm_string>*tmp = new list<perm_string>;
2760 tmp->push_back(lex_strings.make($1));
2761 $$ = tmp;
2762 delete[]$1;
2764 | register_variable_list ',' register_variable
2765 { list<perm_string>*tmp = $1;
2766 tmp->push_back(lex_strings.make($3));
2767 $$ = tmp;
2768 delete[]$3;
2772 real_variable
2773 : IDENTIFIER dimensions_opt
2774 { perm_string name = lex_strings.make($1);
2775 pform_makewire(@1, name, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2776 if ($2 != 0) {
2777 yyerror(@2, "sorry: real variables do not currently support arrays.");
2778 delete $2;
2780 $$ = $1;
2782 | IDENTIFIER '=' expression
2783 { perm_string name = lex_strings.make($1);
2784 pform_makewire(@1, name, NetNet::REG, NetNet::NOT_A_PORT, IVL_VT_REAL, 0);
2785 pform_make_reginit(@1, name, $3);
2786 $$ = $1;
2790 real_variable_list
2791 : real_variable
2792 { list<perm_string>*tmp = new list<perm_string>;
2793 tmp->push_back(lex_strings.make($1));
2794 $$ = tmp;
2795 delete[]$1;
2797 | real_variable_list ',' real_variable
2798 { list<perm_string>*tmp = $1;
2799 tmp->push_back(lex_strings.make($3));
2800 $$ = tmp;
2801 delete[]$3;
2805 net_variable
2806 : IDENTIFIER dimensions_opt
2807 { perm_string name = lex_strings.make($1);
2808 pform_makewire(@1, name, NetNet::IMPLICIT,
2809 NetNet::NOT_A_PORT, IVL_VT_NO_TYPE, 0);
2810 if ($2 != 0) {
2811 index_component_t index;
2812 if ($2->size() > 1) {
2813 yyerror(@2, "sorry: only 1 dimensional arrays "
2814 "are currently supported.");
2816 index = $2->front();
2817 pform_set_reg_idx(name, index.msb, index.lsb);
2818 delete $2;
2820 $$ = $1;
2824 net_variable_list
2825 : net_variable
2826 { list<perm_string>*tmp = new list<perm_string>;
2827 tmp->push_back(lex_strings.make($1));
2828 $$ = tmp;
2829 delete[]$1;
2831 | net_variable_list ',' net_variable
2832 { list<perm_string>*tmp = $1;
2833 tmp->push_back(lex_strings.make($3));
2834 $$ = tmp;
2835 delete[]$3;
2839 specify_item
2840 : K_specparam specparam_list ';'
2841 | specify_simple_path_decl ';'
2842 { pform_module_specify_path($1);
2844 | specify_edge_path_decl ';'
2845 { pform_module_specify_path($1);
2847 | K_if '(' expression ')' specify_simple_path_decl ';'
2848 { PSpecPath*tmp = $5;
2849 if (tmp) {
2850 tmp->conditional = true;
2851 tmp->condition = $3;
2853 pform_module_specify_path(tmp);
2855 | K_if '(' expression ')' specify_edge_path_decl ';'
2856 { PSpecPath*tmp = $5;
2857 if (tmp) {
2858 tmp->conditional = true;
2859 tmp->condition = $3;
2861 pform_module_specify_path(tmp);
2863 | K_ifnone specify_simple_path_decl ';'
2864 { PSpecPath*tmp = $2;
2865 if (tmp) {
2866 tmp->conditional = true;
2867 tmp->condition = 0;
2869 pform_module_specify_path(tmp);
2871 | K_Shold '(' spec_reference_event ',' spec_reference_event
2872 ',' delay_value spec_notifier_opt ')' ';'
2873 { delete $7;
2875 | K_Speriod '(' spec_reference_event ',' delay_value
2876 spec_notifier_opt ')' ';'
2877 { delete $5;
2879 | K_Srecovery '(' spec_reference_event ',' spec_reference_event
2880 ',' delay_value spec_notifier_opt ')' ';'
2881 { delete $7;
2883 | K_Ssetup '(' spec_reference_event ',' spec_reference_event
2884 ',' delay_value spec_notifier_opt ')' ';'
2885 { delete $7;
2887 | K_Ssetuphold '(' spec_reference_event ',' spec_reference_event
2888 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2889 { delete $7;
2890 delete $9;
2892 | K_Srecrem '(' spec_reference_event ',' spec_reference_event
2893 ',' delay_value ',' delay_value spec_notifier_opt ')' ';'
2894 { delete $7;
2895 delete $9;
2897 | K_Swidth '(' spec_reference_event ',' delay_value ',' expression
2898 spec_notifier_opt ')' ';'
2899 { delete $5;
2900 delete $7;
2902 | K_Swidth '(' spec_reference_event ',' delay_value ')' ';'
2903 { delete $5;
2907 specify_item_list
2908 : specify_item
2909 | specify_item_list specify_item
2912 specify_edge_path_decl
2913 : specify_edge_path '=' '(' delay_value_list ')'
2914 { $$ = pform_assign_path_delay($1, $4); }
2915 | specify_edge_path '=' delay_value_simple
2916 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2917 (*tmp)[0] = $3;
2918 $$ = pform_assign_path_delay($1, tmp);
2922 edge_operator : K_posedge { $$ = true; } | K_negedge { $$ = false; } ;
2924 specify_edge_path
2925 : '(' specify_path_identifiers spec_polarity
2926 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2927 { int edge_flag = 0;
2928 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, false, $6, $8); }
2929 | '(' edge_operator specify_path_identifiers spec_polarity
2930 K_EG '(' specify_path_identifiers polarity_operator expression ')' ')'
2931 { int edge_flag = $2? 1 : -1;
2932 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, false, $7, $9);}
2933 | '(' specify_path_identifiers spec_polarity
2934 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2935 { int edge_flag = 0;
2936 $$ = pform_make_specify_edge_path(@1, edge_flag, $2, $3, true, $6, $8); }
2937 | '(' edge_operator specify_path_identifiers spec_polarity
2938 K_SG '(' specify_path_identifiers polarity_operator expression ')' ')'
2939 { int edge_flag = $2? 1 : -1;
2940 $$ = pform_make_specify_edge_path(@1, edge_flag, $3, $4, true, $7, $9); }
2943 polarity_operator
2944 : K_PO_POS
2945 | K_PO_NEG
2946 | ':'
2949 specify_simple_path_decl
2950 : specify_simple_path '=' '(' delay_value_list ')'
2951 { $$ = pform_assign_path_delay($1, $4); }
2952 | specify_simple_path '=' delay_value_simple
2953 { svector<PExpr*>*tmp = new svector<PExpr*>(1);
2954 (*tmp)[0] = $3;
2955 $$ = pform_assign_path_delay($1, tmp);
2957 | specify_simple_path '=' '(' error ')'
2958 { yyerror(@3, "Syntax error in delay value list.");
2959 yyerrok;
2960 $$ = 0;
2964 specify_simple_path
2965 : '(' specify_path_identifiers spec_polarity
2966 K_EG specify_path_identifiers ')'
2967 { $$ = pform_make_specify_path(@1, $2, $3, false, $5); }
2968 | '(' specify_path_identifiers spec_polarity
2969 K_SG specify_path_identifiers ')'
2970 { $$ = pform_make_specify_path(@1, $2, $3, true, $5); }
2971 | '(' error ')'
2972 { yyerror(@1, "Invalid simple path");
2973 yyerrok;
2977 specify_path_identifiers
2978 : IDENTIFIER
2979 { list<perm_string>*tmp = new list<perm_string>;
2980 tmp->push_back(lex_strings.make($1));
2981 $$ = tmp;
2982 delete[]$1;
2984 | IDENTIFIER '[' expr_primary ']'
2985 { list<perm_string>*tmp = new list<perm_string>;
2986 tmp->push_back(lex_strings.make($1));
2987 $$ = tmp;
2988 delete[]$1;
2990 | specify_path_identifiers ',' IDENTIFIER
2991 { list<perm_string>*tmp = $1;
2992 tmp->push_back(lex_strings.make($3));
2993 $$ = tmp;
2994 delete[]$3;
2996 | specify_path_identifiers ',' IDENTIFIER '[' expr_primary ']'
2997 { list<perm_string>*tmp = $1;
2998 tmp->push_back(lex_strings.make($3));
2999 $$ = tmp;
3000 delete[]$3;
3004 specparam
3005 : IDENTIFIER '=' expression
3006 { PExpr*tmp = $3;
3007 pform_set_specparam(lex_strings.make($1), tmp);
3008 delete[]$1;
3010 | IDENTIFIER '=' expression ':' expression ':' expression
3011 { PExpr*tmp = 0;
3012 switch (min_typ_max_flag) {
3013 case MIN:
3014 tmp = $3;
3015 delete $5;
3016 delete $7;
3017 break;
3018 case TYP:
3019 delete $3;
3020 tmp = $5;
3021 delete $7;
3022 break;
3023 case MAX:
3024 delete $3;
3025 delete $5;
3026 tmp = $7;
3027 break;
3029 if (min_typ_max_warn > 0) {
3030 cerr << tmp->get_fileline() << ": warning: choosing ";
3031 switch (min_typ_max_flag) {
3032 case MIN:
3033 cerr << "min";
3034 break;
3035 case TYP:
3036 cerr << "typ";
3037 break;
3038 case MAX:
3039 cerr << "max";
3040 break;
3042 cerr << " expression." << endl;
3043 min_typ_max_warn -= 1;
3045 pform_set_specparam(lex_strings.make($1), tmp);
3046 delete[]$1;
3048 | PATHPULSE_IDENTIFIER '=' expression
3049 { delete[]$1;
3050 delete $3;
3052 | PATHPULSE_IDENTIFIER '=' '(' expression ',' expression ')'
3053 { delete[]$1;
3054 delete $4;
3055 delete $6;
3059 specparam_list
3060 : specparam
3061 | specparam_list ',' specparam
3064 spec_polarity
3065 : '+' { $$ = '+'; }
3066 | '-' { $$ = '-'; }
3067 | { $$ = 0; }
3070 spec_reference_event
3071 : K_posedge expression
3072 { delete $2; }
3073 | K_negedge expression
3074 { delete $2; }
3075 | K_posedge expr_primary K_TAND expression
3076 { delete $2;
3077 delete $4;
3079 | K_negedge expr_primary K_TAND expression
3080 { delete $2;
3081 delete $4;
3083 | K_edge '[' edge_descriptor_list ']' expr_primary
3084 { delete $5; }
3085 | K_edge '[' edge_descriptor_list ']' expr_primary K_TAND expression
3086 { delete $5;
3087 delete $7;
3089 | expr_primary K_TAND expression
3090 { delete $1;
3091 delete $3;
3093 | expr_primary
3094 { delete $1; }
3097 /* The edge_descriptor is detected by the lexor as the various
3098 2-letter edge sequences that are supported here. For now, we
3099 don't care what they are, because we do not yet support specify
3100 edge events. */
3101 edge_descriptor_list
3102 : edge_descriptor_list ',' K_edge_descriptor
3103 | K_edge_descriptor
3106 spec_notifier_opt
3107 : /* empty */
3109 | spec_notifier
3112 spec_notifier
3113 : ','
3115 | ',' hierarchy_identifier
3116 { delete $2; }
3117 | spec_notifier ','
3119 | spec_notifier ',' hierarchy_identifier
3120 { delete $3; }
3121 | IDENTIFIER
3122 { delete[]$1; }
3126 statement
3128 /* assign and deassign statements are procedural code to do
3129 structural assignments, and to turn that structural assignment
3130 off. This stronger then any other assign, but weaker then the
3131 force assignments. */
3133 : K_assign lpvalue '=' expression ';'
3134 { PCAssign*tmp = new PCAssign($2, $4);
3135 FILE_NAME(tmp, @1);
3136 $$ = tmp;
3139 | K_deassign lpvalue ';'
3140 { PDeassign*tmp = new PDeassign($2);
3141 FILE_NAME(tmp, @1);
3142 $$ = tmp;
3146 /* Force and release statements are similar to assignments,
3147 syntactically, but they will be elaborated differently. */
3149 | K_force lpvalue '=' expression ';'
3150 { PForce*tmp = new PForce($2, $4);
3151 FILE_NAME(tmp, @1);
3152 $$ = tmp;
3154 | K_release lpvalue ';'
3155 { PRelease*tmp = new PRelease($2);
3156 FILE_NAME(tmp, @1);
3157 $$ = tmp;
3160 /* begin-end blocks come in a variety of forms, including named and
3161 anonymous. The named blocks can also carry their own reg
3162 variables, which are placed in the scope created by the block
3163 name. These are handled by pushing the scope name then matching
3164 the declarations. The scope is popped at the end of the block. */
3166 | K_begin statement_list K_end
3167 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
3168 FILE_NAME(tmp, @1);
3169 tmp->set_statement(*$2);
3170 delete $2;
3171 $$ = tmp;
3173 | K_begin ':' IDENTIFIER
3174 { PBlock*tmp = pform_push_block_scope($3, PBlock::BL_SEQ);
3175 FILE_NAME(tmp, @1);
3176 current_block_stack.push(tmp);
3178 block_item_decls_opt
3179 statement_list K_end
3180 { pform_pop_scope();
3181 assert(! current_block_stack.empty());
3182 PBlock*tmp = current_block_stack.top();
3183 current_block_stack.pop();
3184 tmp->set_statement(*$6);
3185 delete[]$3;
3186 delete $6;
3187 $$ = tmp;
3189 | K_begin K_end
3190 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
3191 FILE_NAME(tmp, @1);
3192 $$ = tmp;
3194 | K_begin ':' IDENTIFIER K_end
3195 { PBlock*tmp = new PBlock(PBlock::BL_SEQ);
3196 FILE_NAME(tmp, @1);
3197 delete[]$3;
3198 $$ = tmp;
3200 | K_begin error K_end
3201 { yyerrok; }
3203 /* fork-join blocks are very similar to begin-end blocks. In fact,
3204 from the parser's perspective there is no real difference. All we
3205 need to do is remember that this is a parallel block so that the
3206 code generator can do the right thing. */
3208 | K_fork ':' IDENTIFIER
3209 { PBlock*tmp = pform_push_block_scope($3, PBlock::BL_PAR);
3210 FILE_NAME(tmp, @1);
3211 current_block_stack.push(tmp);
3213 block_item_decls_opt
3214 statement_list K_join
3215 { pform_pop_scope();
3216 assert(! current_block_stack.empty());
3217 PBlock*tmp = current_block_stack.top();
3218 current_block_stack.pop();
3219 tmp->set_statement(*$6);
3220 delete[]$3;
3221 delete $6;
3222 $$ = tmp;
3224 | K_fork K_join
3225 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
3226 FILE_NAME(tmp, @1);
3227 $$ = tmp;
3229 | K_fork ':' IDENTIFIER K_join
3230 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
3231 FILE_NAME(tmp, @1);
3232 delete[]$3;
3233 $$ = tmp;
3236 | K_disable hierarchy_identifier ';'
3237 { PDisable*tmp = new PDisable(*$2);
3238 FILE_NAME(tmp, @1);
3239 delete $2;
3240 $$ = tmp;
3242 | K_TRIGGER hierarchy_identifier ';'
3243 { PTrigger*tmp = new PTrigger(*$2);
3244 FILE_NAME(tmp, @1);
3245 delete $2;
3246 $$ = tmp;
3248 | K_forever statement
3249 { PForever*tmp = new PForever($2);
3250 FILE_NAME(tmp, @1);
3251 $$ = tmp;
3253 | K_fork statement_list K_join
3254 { PBlock*tmp = new PBlock(PBlock::BL_PAR);
3255 FILE_NAME(tmp, @1);
3256 tmp->set_statement(*$2);
3257 delete $2;
3258 $$ = tmp;
3260 | K_repeat '(' expression ')' statement
3261 { PRepeat*tmp = new PRepeat($3, $5);
3262 FILE_NAME(tmp, @1);
3263 $$ = tmp;
3265 | K_case '(' expression ')' case_items K_endcase
3266 { PCase*tmp = new PCase(NetCase::EQ, $3, $5);
3267 FILE_NAME(tmp, @1);
3268 $$ = tmp;
3270 | K_casex '(' expression ')' case_items K_endcase
3271 { PCase*tmp = new PCase(NetCase::EQX, $3, $5);
3272 FILE_NAME(tmp, @1);
3273 $$ = tmp;
3275 | K_casez '(' expression ')' case_items K_endcase
3276 { PCase*tmp = new PCase(NetCase::EQZ, $3, $5);
3277 FILE_NAME(tmp, @1);
3278 $$ = tmp;
3280 | K_case '(' expression ')' error K_endcase
3281 { yyerrok; }
3282 | K_casex '(' expression ')' error K_endcase
3283 { yyerrok; }
3284 | K_casez '(' expression ')' error K_endcase
3285 { yyerrok; }
3286 | K_if '(' expression ')' statement_or_null %prec less_than_K_else
3287 { PCondit*tmp = new PCondit($3, $5, 0);
3288 FILE_NAME(tmp, @1);
3289 $$ = tmp;
3291 | K_if '(' expression ')' statement_or_null K_else statement_or_null
3292 { PCondit*tmp = new PCondit($3, $5, $7);
3293 FILE_NAME(tmp, @1);
3294 $$ = tmp;
3296 | K_if '(' error ')' statement_or_null %prec less_than_K_else
3297 { yyerror(@1, "error: Malformed conditional expression.");
3298 $$ = $5;
3300 | K_if '(' error ')' statement_or_null K_else statement_or_null
3301 { yyerror(@1, "error: Malformed conditional expression.");
3302 $$ = $5;
3304 | K_for '(' lpvalue '=' expression ';' expression ';'
3305 lpvalue '=' expression ')' statement
3306 { PForStatement*tmp = new PForStatement($3, $5, $7, $9, $11, $13);
3307 FILE_NAME(tmp, @1);
3308 $$ = tmp;
3310 | K_for '(' lpvalue '=' expression ';' expression ';'
3311 error ')' statement
3312 { $$ = 0;
3313 yyerror(@1, "error: Error in for loop step assignment.");
3315 | K_for '(' lpvalue '=' expression ';' error ';'
3316 lpvalue '=' expression ')' statement
3317 { $$ = 0;
3318 yyerror(@1, "error: Error in for loop condition expression.");
3320 | K_for '(' error ')' statement
3321 { $$ = 0;
3322 yyerror(@1, "error: Incomprehensible for loop.");
3324 | K_while '(' expression ')' statement
3325 { PWhile*tmp = new PWhile($3, $5);
3326 FILE_NAME(tmp, @1);
3327 $$ = tmp;
3329 | K_while '(' error ')' statement
3330 { $$ = 0;
3331 yyerror(@1, "error: Error in while loop condition.");
3333 | delay1 statement_or_null
3334 { PExpr*del = (*$1)[0];
3335 assert($1->count() == 1);
3336 PDelayStatement*tmp = new PDelayStatement(del, $2);
3337 FILE_NAME(tmp, @1);
3338 $$ = tmp;
3340 | event_control statement_or_null
3341 { PEventStatement*tmp = $1;
3342 if (tmp == 0) {
3343 yyerror(@1, "error: Invalid event control.");
3344 $$ = 0;
3345 } else {
3346 tmp->set_statement($2);
3347 $$ = tmp;
3350 | '@' '*' statement_or_null
3351 { PEventStatement*tmp = new PEventStatement;
3352 FILE_NAME(tmp, @1);
3353 tmp->set_statement($3);
3354 $$ = tmp;
3356 | '@' '(' '*' ')' statement_or_null
3357 { PEventStatement*tmp = new PEventStatement;
3358 FILE_NAME(tmp, @1);
3359 tmp->set_statement($5);
3360 $$ = tmp;
3362 | lpvalue '=' expression ';'
3363 { PAssign*tmp = new PAssign($1,$3);
3364 FILE_NAME(tmp, @1);
3365 $$ = tmp;
3367 | error '=' expression ';'
3368 { yyerror(@2, "Syntax in assignment statement l-value.");
3369 yyerrok;
3370 $$ = new PNoop;
3372 | lpvalue K_LE expression ';'
3373 { PAssignNB*tmp = new PAssignNB($1,$3);
3374 FILE_NAME(tmp, @1);
3375 $$ = tmp;
3377 | error K_LE expression ';'
3378 { yyerror(@2, "Syntax in assignment statement l-value.");
3379 yyerrok;
3380 $$ = new PNoop;
3382 | lpvalue '=' delay1 expression ';'
3383 { assert($3->count() == 1);
3384 PExpr*del = (*$3)[0];
3385 PAssign*tmp = new PAssign($1,del,$4);
3386 FILE_NAME(tmp, @1);
3387 $$ = tmp;
3389 | lpvalue K_LE delay1 expression ';'
3390 { assert($3->count() == 1);
3391 PExpr*del = (*$3)[0];
3392 PAssignNB*tmp = new PAssignNB($1,del,$4);
3393 FILE_NAME(tmp, @1);
3394 $$ = tmp;
3396 | lpvalue '=' event_control expression ';'
3397 { PAssign*tmp = new PAssign($1,$3,$4);
3398 FILE_NAME(tmp, @1);
3399 $$ = tmp;
3401 | lpvalue '=' K_repeat '(' expression ')' event_control expression ';'
3402 { PAssign*tmp = new PAssign($1,$7,$8);
3403 FILE_NAME(tmp,@1);
3404 tmp->set_lineno(@1.first_line);
3405 yyerror(@3, "sorry: repeat event control not supported.");
3406 delete $5;
3407 $$ = tmp;
3409 | lpvalue K_LE event_control expression ';'
3410 { yyerror(@1, "sorry: Event controls not supported here.");
3411 PAssignNB*tmp = new PAssignNB($1,$4);
3412 FILE_NAME(tmp, @1);
3413 $$ = tmp;
3415 | lpvalue K_LE K_repeat '(' expression ')' event_control expression ';'
3416 { yyerror(@1, "sorry: Event controls not supported here.");
3417 delete $5;
3418 PAssignNB*tmp = new PAssignNB($1,$8);
3419 FILE_NAME(tmp, @1);
3420 $$ = tmp;
3422 | K_wait '(' expression ')' statement_or_null
3423 { PEventStatement*tmp;
3424 PEEvent*etmp = new PEEvent(PEEvent::POSITIVE, $3);
3425 tmp = new PEventStatement(etmp);
3426 FILE_NAME(tmp,@1);
3427 tmp->set_statement($5);
3428 $$ = tmp;
3430 | SYSTEM_IDENTIFIER '(' expression_list_with_nuls ')' ';'
3431 { PCallTask*tmp = new PCallTask(lex_strings.make($1), *$3);
3432 FILE_NAME(tmp,@1);
3433 delete[]$1;
3434 delete $3;
3435 $$ = tmp;
3437 | SYSTEM_IDENTIFIER ';'
3438 { svector<PExpr*>pt (0);
3439 PCallTask*tmp = new PCallTask(lex_strings.make($1), pt);
3440 FILE_NAME(tmp,@1);
3441 delete[]$1;
3442 $$ = tmp;
3444 | hierarchy_identifier '(' expression_list_proper ')' ';'
3445 { PCallTask*tmp = new PCallTask(*$1, *$3);
3446 FILE_NAME(tmp, @1);
3447 delete $1;
3448 delete $3;
3449 $$ = tmp;
3452 /* NOTE: The standard doesn't really support an empty argument list
3453 between parentheses, but it seems natural, and people commonly
3454 want it. So accept it explicitly. */
3456 | hierarchy_identifier '(' ')' ';'
3457 { svector<PExpr*>pt (0);
3458 PCallTask*tmp = new PCallTask(*$1, pt);
3459 FILE_NAME(tmp, @1);
3460 delete $1;
3461 $$ = tmp;
3463 | hierarchy_identifier ';'
3464 { svector<PExpr*>pt (0);
3465 PCallTask*tmp = new PCallTask(*$1, pt);
3466 FILE_NAME(tmp, @1);
3467 delete $1;
3468 $$ = tmp;
3470 | error ';'
3471 { yyerror(@2, "error: malformed statement");
3472 yyerrok;
3473 $$ = new PNoop;
3477 statement_list
3478 : statement_list statement
3479 { svector<Statement*>*tmp = new svector<Statement*>(*$1, $2);
3480 delete $1;
3481 $$ = tmp;
3483 | statement
3484 { svector<Statement*>*tmp = new svector<Statement*>(1);
3485 (*tmp)[0] = $1;
3486 $$ = tmp;
3490 statement_or_null
3491 : statement
3492 | ';' { $$ = 0; }
3495 /* Task items are, other than the statement, task port items and
3496 other block items. */
3497 task_item
3498 : block_item_decl { $$ = new svector<PWire*>(0); }
3499 | task_port_item { $$ = $1; }
3502 task_port_item
3504 : K_input signed_opt range_opt list_of_identifiers ';'
3505 { svector<PWire*>*tmp
3506 = pform_make_task_ports(NetNet::PINPUT,
3507 IVL_VT_NO_TYPE, $2,
3508 $3, $4,
3509 @1.text, @1.first_line);
3510 $$ = tmp;
3512 | K_output signed_opt range_opt list_of_identifiers ';'
3513 { svector<PWire*>*tmp
3514 = pform_make_task_ports(NetNet::POUTPUT,
3515 IVL_VT_LOGIC, $2,
3516 $3, $4,
3517 @1.text, @1.first_line);
3518 $$ = tmp;
3520 | K_inout signed_opt range_opt list_of_identifiers ';'
3521 { svector<PWire*>*tmp
3522 = pform_make_task_ports(NetNet::PINOUT,
3523 IVL_VT_LOGIC, $2,
3524 $3, $4,
3525 @1.text, @1.first_line);
3526 $$ = tmp;
3529 /* When the port is an integer, infer a signed vector of the integer
3530 shape. Generate a range to make it work. */
3532 | K_input K_integer list_of_identifiers ';'
3533 { svector<PExpr*>*range_stub
3534 = new svector<PExpr*>(2);
3535 PExpr*re;
3536 re = new PENumber(new verinum(integer_width-1,
3537 integer_width));
3538 (*range_stub)[0] = re;
3539 re = new PENumber(new verinum((uint64_t)0, integer_width));
3540 (*range_stub)[1] = re;
3541 svector<PWire*>*tmp
3542 = pform_make_task_ports(NetNet::PINPUT,
3543 IVL_VT_LOGIC, true,
3544 range_stub, $3,
3545 @1.text, @1.first_line);
3546 $$ = tmp;
3548 | K_output K_integer list_of_identifiers ';'
3549 { svector<PExpr*>*range_stub
3550 = new svector<PExpr*>(2);
3551 PExpr*re;
3552 re = new PENumber(new verinum(integer_width-1,
3553 integer_width));
3554 (*range_stub)[0] = re;
3555 re = new PENumber(new verinum((uint64_t)0, integer_width));
3556 (*range_stub)[1] = re;
3557 svector<PWire*>*tmp
3558 = pform_make_task_ports(NetNet::POUTPUT,
3559 IVL_VT_LOGIC, true,
3560 range_stub, $3,
3561 @1.text, @1.first_line);
3562 $$ = tmp;
3564 | K_inout K_integer list_of_identifiers ';'
3565 { svector<PExpr*>*range_stub
3566 = new svector<PExpr*>(2);
3567 PExpr*re;
3568 re = new PENumber(new verinum(integer_width-1,
3569 integer_width));
3570 (*range_stub)[0] = re;
3571 re = new PENumber(new verinum((uint64_t)0, integer_width));
3572 (*range_stub)[1] = re;
3573 svector<PWire*>*tmp
3574 = pform_make_task_ports(NetNet::PINOUT,
3575 IVL_VT_LOGIC, true,
3576 range_stub, $3,
3577 @1.text, @1.first_line);
3578 $$ = tmp;
3581 /* Ports can be real. */
3583 | K_input K_real list_of_identifiers ';'
3584 { svector<PWire*>*tmp
3585 = pform_make_task_ports(NetNet::PINPUT,
3586 IVL_VT_REAL, false,
3587 0, $3,
3588 @1.text, @1.first_line);
3589 $$ = tmp;
3591 | K_output K_real list_of_identifiers ';'
3592 { svector<PWire*>*tmp
3593 = pform_make_task_ports(NetNet::POUTPUT,
3594 IVL_VT_REAL, true,
3595 0, $3,
3596 @1.text, @1.first_line);
3597 $$ = tmp;
3599 | K_inout K_real list_of_identifiers ';'
3600 { svector<PWire*>*tmp
3601 = pform_make_task_ports(NetNet::PINOUT,
3602 IVL_VT_REAL, true,
3603 0, $3,
3604 @1.text, @1.first_line);
3605 $$ = tmp;
3609 task_item_list
3610 : task_item_list task_item
3611 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3612 delete $1;
3613 delete $2;
3614 $$ = tmp;
3616 | task_item
3617 { $$ = $1; }
3620 task_item_list_opt
3621 : task_item_list
3622 { $$ = $1; }
3624 { $$ = 0; }
3627 task_port_decl
3629 : K_input signed_opt range_opt IDENTIFIER
3630 { port_declaration_context.port_type = NetNet::PINPUT;
3631 port_declaration_context.var_type = IVL_VT_LOGIC;
3632 port_declaration_context.sign_flag = $2;
3633 delete port_declaration_context.range;
3634 port_declaration_context.range = copy_range($3);
3635 svector<PWire*>*tmp
3636 = pform_make_task_ports(NetNet::PINPUT,
3637 IVL_VT_LOGIC, $2,
3638 $3, list_from_identifier($4),
3639 @1.text, @1.first_line);
3640 $$ = tmp;
3643 | K_output signed_opt range_opt IDENTIFIER
3644 { port_declaration_context.port_type = NetNet::POUTPUT;
3645 port_declaration_context.var_type = IVL_VT_LOGIC;
3646 port_declaration_context.sign_flag = $2;
3647 delete port_declaration_context.range;
3648 port_declaration_context.range = copy_range($3);
3649 svector<PWire*>*tmp
3650 = pform_make_task_ports(NetNet::POUTPUT,
3651 IVL_VT_LOGIC, $2,
3652 $3, list_from_identifier($4),
3653 @1.text, @1.first_line);
3654 $$ = tmp;
3656 | K_inout signed_opt range_opt IDENTIFIER
3657 { port_declaration_context.port_type = NetNet::PINOUT;
3658 port_declaration_context.var_type = IVL_VT_LOGIC;
3659 port_declaration_context.sign_flag = $2;
3660 delete port_declaration_context.range;
3661 port_declaration_context.range = copy_range($3);
3662 svector<PWire*>*tmp
3663 = pform_make_task_ports(NetNet::PINOUT,
3664 IVL_VT_LOGIC, $2,
3665 $3, list_from_identifier($4),
3666 @1.text, @1.first_line);
3667 $$ = tmp;
3670 | K_input K_integer IDENTIFIER
3671 { svector<PExpr*>*range_stub
3672 = new svector<PExpr*>(2);
3673 PExpr*re;
3674 re = new PENumber(new verinum(integer_width-1,
3675 integer_width));
3676 (*range_stub)[0] = re;
3677 re = new PENumber(new verinum((uint64_t)0, integer_width));
3678 (*range_stub)[1] = re;
3679 port_declaration_context.port_type = NetNet::PINPUT;
3680 port_declaration_context.var_type = IVL_VT_LOGIC;
3681 port_declaration_context.sign_flag = true;
3682 delete port_declaration_context.range;
3683 port_declaration_context.range = copy_range(range_stub);
3684 svector<PWire*>*tmp
3685 = pform_make_task_ports(NetNet::PINPUT,
3686 IVL_VT_LOGIC, true,
3687 range_stub,
3688 list_from_identifier($3),
3689 @1.text, @1.first_line);
3690 $$ = tmp;
3692 | K_output K_integer IDENTIFIER
3693 { svector<PExpr*>*range_stub
3694 = new svector<PExpr*>(2);
3695 PExpr*re;
3696 re = new PENumber(new verinum(integer_width-1,
3697 integer_width));
3698 (*range_stub)[0] = re;
3699 re = new PENumber(new verinum((uint64_t)0, integer_width));
3700 (*range_stub)[1] = re;
3701 port_declaration_context.port_type = NetNet::POUTPUT;
3702 port_declaration_context.var_type = IVL_VT_LOGIC;
3703 port_declaration_context.sign_flag = true;
3704 delete port_declaration_context.range;
3705 port_declaration_context.range = copy_range(range_stub);
3706 svector<PWire*>*tmp
3707 = pform_make_task_ports(NetNet::POUTPUT,
3708 IVL_VT_LOGIC, true,
3709 range_stub,
3710 list_from_identifier($3),
3711 @1.text, @1.first_line);
3712 $$ = tmp;
3714 | K_inout K_integer IDENTIFIER
3715 { svector<PExpr*>*range_stub
3716 = new svector<PExpr*>(2);
3717 PExpr*re;
3718 re = new PENumber(new verinum(integer_width-1,
3719 integer_width));
3720 (*range_stub)[0] = re;
3721 re = new PENumber(new verinum((uint64_t)0, integer_width));
3722 (*range_stub)[1] = re;
3723 port_declaration_context.port_type = NetNet::PINOUT;
3724 port_declaration_context.var_type = IVL_VT_LOGIC;
3725 port_declaration_context.sign_flag = true;
3726 delete port_declaration_context.range;
3727 port_declaration_context.range = copy_range(range_stub);
3728 svector<PWire*>*tmp
3729 = pform_make_task_ports(NetNet::PINOUT,
3730 IVL_VT_LOGIC, true,
3731 range_stub,
3732 list_from_identifier($3),
3733 @1.text, @1.first_line);
3734 $$ = tmp;
3737 /* Ports can be real. */
3739 | K_input K_real IDENTIFIER
3740 { port_declaration_context.port_type = NetNet::PINPUT;
3741 port_declaration_context.var_type = IVL_VT_REAL;
3742 port_declaration_context.sign_flag = false;
3743 delete port_declaration_context.range;
3744 port_declaration_context.range = 0;
3745 svector<PWire*>*tmp
3746 = pform_make_task_ports(NetNet::PINPUT,
3747 IVL_VT_REAL, false,
3748 0, list_from_identifier($3),
3749 @1.text, @1.first_line);
3750 $$ = tmp;
3752 | K_output K_real IDENTIFIER
3753 { port_declaration_context.port_type = NetNet::POUTPUT;
3754 port_declaration_context.var_type = IVL_VT_REAL;
3755 port_declaration_context.sign_flag = false;
3756 delete port_declaration_context.range;
3757 port_declaration_context.range = 0;
3758 svector<PWire*>*tmp
3759 = pform_make_task_ports(NetNet::POUTPUT,
3760 IVL_VT_REAL, false,
3761 0, list_from_identifier($3),
3762 @1.text, @1.first_line);
3763 $$ = tmp;
3765 | K_inout K_real IDENTIFIER
3766 { port_declaration_context.port_type = NetNet::PINOUT;
3767 port_declaration_context.var_type = IVL_VT_REAL;
3768 port_declaration_context.sign_flag = false;
3769 delete port_declaration_context.range;
3770 port_declaration_context.range = 0;
3771 svector<PWire*>*tmp
3772 = pform_make_task_ports(NetNet::PINOUT,
3773 IVL_VT_REAL, false,
3774 0, list_from_identifier($3),
3775 @1.text, @1.first_line);
3776 $$ = tmp;
3780 task_port_decl_list
3781 : task_port_decl_list ',' task_port_decl
3782 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$3);
3783 delete $1;
3784 delete $3;
3785 $$ = tmp;
3787 | task_port_decl
3788 { $$ = $1; }
3789 | task_port_decl_list ',' IDENTIFIER
3790 { svector<PWire*>*new_decl
3791 = pform_make_task_ports(
3792 port_declaration_context.port_type,
3793 port_declaration_context.var_type,
3794 port_declaration_context.sign_flag,
3795 copy_range(port_declaration_context.range),
3796 list_from_identifier($3),
3797 @3.text, @3.first_line);
3798 svector<PWire*>*tmp = new svector<PWire*>(*$1, *new_decl);
3799 delete $1;
3800 delete new_decl;
3801 $$ = tmp;
3803 | task_port_decl_list ','
3805 yyerror(@2, "error: NULL port declarations are not "
3806 "allowed.");
3808 | task_port_decl_list ';'
3810 yyerror(@2, "error: ';' is an invalid port declaration "
3811 "separator.");
3816 udp_body
3817 : K_table { lex_start_table(); }
3818 udp_entry_list
3819 K_endtable { lex_end_table(); $$ = $3; }
3822 udp_entry_list
3823 : udp_comb_entry_list
3824 | udp_sequ_entry_list
3827 udp_comb_entry
3828 : udp_input_list ':' udp_output_sym ';'
3829 { char*tmp = new char[strlen($1)+3];
3830 strcpy(tmp, $1);
3831 char*tp = tmp+strlen(tmp);
3832 *tp++ = ':';
3833 *tp++ = $3;
3834 *tp++ = 0;
3835 delete[]$1;
3836 $$ = tmp;
3840 udp_comb_entry_list
3841 : udp_comb_entry
3842 { list<string>*tmp = new list<string>;
3843 tmp->push_back($1);
3844 delete[]$1;
3845 $$ = tmp;
3847 | udp_comb_entry_list udp_comb_entry
3848 { list<string>*tmp = $1;
3849 tmp->push_back($2);
3850 delete[]$2;
3851 $$ = tmp;
3855 udp_sequ_entry_list
3856 : udp_sequ_entry
3857 { list<string>*tmp = new list<string>;
3858 tmp->push_back($1);
3859 delete[]$1;
3860 $$ = tmp;
3862 | udp_sequ_entry_list udp_sequ_entry
3863 { list<string>*tmp = $1;
3864 tmp->push_back($2);
3865 delete[]$2;
3866 $$ = tmp;
3870 udp_sequ_entry
3871 : udp_input_list ':' udp_input_sym ':' udp_output_sym ';'
3872 { char*tmp = new char[strlen($1)+5];
3873 strcpy(tmp, $1);
3874 char*tp = tmp+strlen(tmp);
3875 *tp++ = ':';
3876 *tp++ = $3;
3877 *tp++ = ':';
3878 *tp++ = $5;
3879 *tp++ = 0;
3880 $$ = tmp;
3884 udp_initial
3885 : K_initial IDENTIFIER '=' number ';'
3886 { PExpr*etmp = new PENumber($4);
3887 PEIdent*itmp = new PEIdent(lex_strings.make($2));
3888 PAssign*atmp = new PAssign(itmp, etmp);
3889 FILE_NAME(atmp, @2);
3890 delete[]$2;
3891 $$ = atmp;
3895 udp_init_opt
3896 : udp_initial { $$ = $1; }
3897 | { $$ = 0; }
3900 udp_input_list
3901 : udp_input_sym
3902 { char*tmp = new char[2];
3903 tmp[0] = $1;
3904 tmp[1] = 0;
3905 $$ = tmp;
3907 | udp_input_list udp_input_sym
3908 { char*tmp = new char[strlen($1)+2];
3909 strcpy(tmp, $1);
3910 char*tp = tmp+strlen(tmp);
3911 *tp++ = $2;
3912 *tp++ = 0;
3913 delete[]$1;
3914 $$ = tmp;
3918 udp_input_sym
3919 : '0' { $$ = '0'; }
3920 | '1' { $$ = '1'; }
3921 | 'x' { $$ = 'x'; }
3922 | '?' { $$ = '?'; }
3923 | 'b' { $$ = 'b'; }
3924 | '*' { $$ = '*'; }
3925 | '%' { $$ = '%'; }
3926 | 'f' { $$ = 'f'; }
3927 | 'F' { $$ = 'F'; }
3928 | 'l' { $$ = 'l'; }
3929 | 'h' { $$ = 'H'; }
3930 | 'B' { $$ = 'B'; }
3931 | 'r' { $$ = 'r'; }
3932 | 'R' { $$ = 'R'; }
3933 | 'M' { $$ = 'M'; }
3934 | 'n' { $$ = 'n'; }
3935 | 'N' { $$ = 'N'; }
3936 | 'p' { $$ = 'p'; }
3937 | 'P' { $$ = 'P'; }
3938 | 'Q' { $$ = 'Q'; }
3939 | 'q' { $$ = 'q'; }
3940 | '_' { $$ = '_'; }
3941 | '+' { $$ = '+'; }
3944 udp_output_sym
3945 : '0' { $$ = '0'; }
3946 | '1' { $$ = '1'; }
3947 | 'x' { $$ = 'x'; }
3948 | '-' { $$ = '-'; }
3951 /* Port declarations create wires for the inputs and the output. The
3952 makes for these ports are scoped within the UDP, so there is no
3953 hierarchy involved. */
3954 udp_port_decl
3955 : K_input list_of_identifiers ';'
3956 { $$ = pform_make_udp_input_ports($2); }
3957 | K_output IDENTIFIER ';'
3958 { perm_string pname = lex_strings.make($2);
3959 PWire*pp = new PWire(pname, NetNet::IMPLICIT, NetNet::POUTPUT, IVL_VT_LOGIC);
3960 svector<PWire*>*tmp = new svector<PWire*>(1);
3961 (*tmp)[0] = pp;
3962 $$ = tmp;
3963 delete[]$2;
3965 | K_reg IDENTIFIER ';'
3966 { perm_string pname = lex_strings.make($2);
3967 PWire*pp = new PWire(pname, NetNet::REG, NetNet::PIMPLICIT, IVL_VT_LOGIC);
3968 svector<PWire*>*tmp = new svector<PWire*>(1);
3969 (*tmp)[0] = pp;
3970 $$ = tmp;
3971 delete[]$2;
3973 | K_reg K_output IDENTIFIER ';'
3974 { perm_string pname = lex_strings.make($3);
3975 PWire*pp = new PWire(pname, NetNet::REG, NetNet::POUTPUT, IVL_VT_LOGIC);
3976 svector<PWire*>*tmp = new svector<PWire*>(1);
3977 (*tmp)[0] = pp;
3978 $$ = tmp;
3979 delete[]$3;
3983 udp_port_decls
3984 : udp_port_decl
3985 { $$ = $1; }
3986 | udp_port_decls udp_port_decl
3987 { svector<PWire*>*tmp = new svector<PWire*>(*$1, *$2);
3988 delete $1;
3989 delete $2;
3990 $$ = tmp;
3994 udp_port_list
3995 : IDENTIFIER
3996 { list<perm_string>*tmp = new list<perm_string>;
3997 tmp->push_back(lex_strings.make($1));
3998 delete[]$1;
3999 $$ = tmp;
4001 | udp_port_list ',' IDENTIFIER
4002 { list<perm_string>*tmp = $1;
4003 tmp->push_back(lex_strings.make($3));
4004 delete[]$3;
4005 $$ = tmp;
4009 udp_reg_opt: K_reg { $$ = true; } | { $$ = false; };
4011 udp_initial_expr_opt
4012 : '=' expression { $$ = $2; }
4013 | { $$ = 0; }
4016 udp_input_declaration_list
4017 : K_input IDENTIFIER
4018 { list<perm_string>*tmp = new list<perm_string>;
4019 tmp->push_back(lex_strings.make($2));
4020 $$ = tmp;
4021 delete[]$2;
4023 | udp_input_declaration_list ',' K_input IDENTIFIER
4024 { list<perm_string>*tmp = $1;
4025 tmp->push_back(lex_strings.make($4));
4026 $$ = tmp;
4027 delete[]$4;
4031 udp_primitive
4032 /* This is the syntax for primitives that uses the IEEE1364-1995
4033 format. The ports are simply names in the port list, and the
4034 declarations are in the body. */
4036 : K_primitive IDENTIFIER '(' udp_port_list ')' ';'
4037 udp_port_decls
4038 udp_init_opt
4039 udp_body
4040 K_endprimitive
4042 { perm_string tmp2 = lex_strings.make($2);
4043 pform_make_udp(tmp2, $4, $7, $9, $8,
4044 @2.text, @2.first_line);
4045 delete[]$2;
4048 /* This is the syntax for IEEE1364-2001 format definitions. The port
4049 names and declarations are all in the parameter list. */
4051 | K_primitive IDENTIFIER
4052 '(' K_output udp_reg_opt IDENTIFIER udp_initial_expr_opt ','
4053 udp_input_declaration_list ')' ';'
4054 udp_body
4055 K_endprimitive
4057 { perm_string tmp2 = lex_strings.make($2);
4058 perm_string tmp6 = lex_strings.make($6);
4059 pform_make_udp(tmp2, $5, tmp6, $7, $9, $12,
4060 @2.text, @2.first_line);
4061 delete[]$2;
4062 delete[]$6;