X-Git-Url: https://git.libre-soc.org/?p=sv2nmigen.git;a=blobdiff_plain;f=parse_sv.py;h=b61df9ea51d41e06f73a82aeffa0583b2e569554;hp=39fe14b9ea29cfff6679b0433d20e8d1ced96790;hb=7bc2bc9b895bb7af15ba30754581a0e4d0ca1239;hpb=a06fc34dfb7bfd870e3af54c275a6a0ff48359f8 diff --git a/parse_sv.py b/parse_sv.py index 39fe14b..b61df9e 100644 --- a/parse_sv.py +++ b/parse_sv.py @@ -55,7 +55,12 @@ precedence = [\ ('nonassoc', 'one_timeunits_declaration'), ('nonassoc', 'K_timeunit', 'K_timeprecision') ] -() + + +IVL_VT_NO_TYPE = 0 +IVL_VT_BOOL = 1 +IVL_VT_LOGIC = 2 + # -------------- RULES ---------------- () def p_source_text_1(p): @@ -157,7 +162,7 @@ def p_class_declaration_endlabel_opt_1(p): # { class_type_t*tmp = dynamic_cast ($2.type); # if (tmp == 0) { # yyerror(@2, "error: class declaration endlabel \"%s\" is not a class name\n", $2.text); - # $$ = 0; + # p[0] = None # } else { # $$ = strdupnew(tmp->name.str()); # } @@ -167,12 +172,12 @@ def p_class_declaration_endlabel_opt_1(p): def p_class_declaration_endlabel_opt_2(p): '''class_declaration_endlabel_opt : ':' IDENTIFIER ''' print('class_declaration_endlabel_opt_2', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p_class_declaration_endlabel_opt_3(p): '''class_declaration_endlabel_opt : ''' print('class_declaration_endlabel_opt_3', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_class_declaration_extends_opt_1(p): '''class_declaration_extends_opt : K_extends TYPE_IDENTIFIER ''' @@ -341,12 +346,12 @@ def p_class_item_qualifier_list_1(p): def p_class_item_qualifier_list_2(p): '''class_item_qualifier_list : class_item_qualifier ''' print('class_item_qualifier_list_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_class_item_qualifier_opt_1(p): '''class_item_qualifier_opt : class_item_qualifier_list ''' print('class_item_qualifier_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_class_item_qualifier_opt_2(p): '''class_item_qualifier_opt : ''' @@ -521,7 +526,7 @@ def p_data_type_3(p): def p_data_type_4(p): '''data_type : enum_data_type ''' print('data_type_4', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_data_type_5(p): '''data_type : atom2_type signed_unsigned_opt ''' @@ -584,7 +589,7 @@ def p__embed0_data_type(p): def p_data_type_or_implicit_1(p): '''data_type_or_implicit : data_type ''' print('data_type_or_implicit_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_data_type_or_implicit_2(p): '''data_type_or_implicit : signing dimensions_opt ''' @@ -607,12 +612,12 @@ def p_data_type_or_implicit_3(p): def p_data_type_or_implicit_4(p): '''data_type_or_implicit : ''' print('data_type_or_implicit_4', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_data_type_or_implicit_or_void_1(p): '''data_type_or_implicit_or_void : data_type_or_implicit ''' print('data_type_or_implicit_or_void_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_data_type_or_implicit_or_void_2(p): '''data_type_or_implicit_or_void : K_void ''' @@ -705,7 +710,7 @@ def p_for_step_2(p): def p_for_step_3(p): '''for_step : compressed_statement ''' print('for_step_3', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_function_declaration_1(p): '''function_declaration : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER ';' _embed0_function_declaration function_item_list statement_or_null_list_opt K_endfunction _embed1_function_declaration endlabel_opt ''' @@ -810,12 +815,12 @@ def p__embed4_function_declaration(p): def p_import_export_1(p): '''import_export : K_import ''' print('import_export_1', list(p)) - # { $$ = true; } + p[0] = True () def p_import_export_2(p): '''import_export : K_export ''' print('import_export_2', list(p)) - # { $$ = false; } + p[0] = False () def p_implicit_class_handle_1(p): '''implicit_class_handle : K_this ''' @@ -863,23 +868,23 @@ def p_inside_expression_1(p): '''inside_expression : expression K_inside '{' open_range_list '}' ''' print('inside_expression_1', list(p)) # { yyerror(@2, "sorry: \"inside\" expressions not supported yet."); - # $$ = 0; + # p[0] = None # } () def p_integer_vector_type_1(p): '''integer_vector_type : K_reg ''' print('integer_vector_type_1', list(p)) - # { $$ = IVL_VT_NO_TYPE; } + p[0] = IVL_VT_NO_TYPE () def p_integer_vector_type_2(p): '''integer_vector_type : K_bit ''' print('integer_vector_type_2', list(p)) - # { $$ = IVL_VT_BOOL; } + p[0] = IVL_VT_BOOL () def p_integer_vector_type_3(p): '''integer_vector_type : K_logic ''' print('integer_vector_type_3', list(p)) - # { $$ = IVL_VT_LOGIC; } + p[0] = IVL_VT_LOGIC () def p_integer_vector_type_4(p): '''integer_vector_type : K_bool ''' @@ -905,7 +910,7 @@ def p_jump_statement_1(p): '''jump_statement : K_break ';' ''' print('jump_statement_1', list(p)) # { yyerror(@1, "sorry: break statements not supported."); - # $$ = 0; + # p[0] = None # } () def p_jump_statement_2(p): @@ -937,7 +942,7 @@ def p_lifetime_2(p): def p_lifetime_opt_1(p): '''lifetime_opt : lifetime ''' print('lifetime_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_lifetime_opt_2(p): '''lifetime_opt : ''' @@ -1023,42 +1028,42 @@ def p_loop_statement_7(p): def p_loop_statement_8(p): '''loop_statement : K_for '(' lpvalue '=' expression ';' expression ';' error ')' statement_or_null ''' print('loop_statement_8', list(p)) - # { $$ = 0; + # { p[0] = None # yyerror(@1, "error: Error in for loop step assignment."); # } () def p_loop_statement_9(p): '''loop_statement : K_for '(' lpvalue '=' expression ';' error ';' for_step ')' statement_or_null ''' print('loop_statement_9', list(p)) - # { $$ = 0; + # { p[0] = None # yyerror(@1, "error: Error in for loop condition expression."); # } () def p_loop_statement_10(p): '''loop_statement : K_for '(' error ')' statement_or_null ''' print('loop_statement_10', list(p)) - # { $$ = 0; + # { p[0] = None # yyerror(@1, "error: Incomprehensible for loop."); # } () def p_loop_statement_11(p): '''loop_statement : K_while '(' error ')' statement_or_null ''' print('loop_statement_11', list(p)) - # { $$ = 0; + # { p[0] = None # yyerror(@1, "error: Error in while loop condition."); # } () def p_loop_statement_12(p): '''loop_statement : K_do statement_or_null K_while '(' error ')' ';' ''' print('loop_statement_12', list(p)) - # { $$ = 0; + # { p[0] = None # yyerror(@1, "error: Error in do/while loop condition."); # } () def p_loop_statement_13(p): '''loop_statement : K_foreach '(' IDENTIFIER '[' error ']' ')' statement_or_null ''' print('loop_statement_13', list(p)) - # { $$ = 0; + # { p[0] = None # yyerror(@4, "error: Errors in foreach loop variables list."); # } () @@ -1348,6 +1353,8 @@ def p_number_1(p): def p_number_2(p): '''number : DEC_NUMBER ''' print('number_2', list(p)) + num = Leaf(token.NUMBER, "%s" % (p[1])) + p[0] = num # { $$ = $1; based_size = 0;} () def p_number_3(p): @@ -1518,7 +1525,7 @@ def p_port_direction_4(p): def p_port_direction_opt_1(p): '''port_direction_opt : port_direction ''' print('port_direction_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_port_direction_opt_2(p): '''port_direction_opt : ''' @@ -1533,21 +1540,21 @@ def p_procedural_assertion_statement_1(p): '''procedural_assertion_statement : K_assert '(' expression ')' statement %prec less_than_K_else ''' print('procedural_assertion_statement_1', list(p)) # { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); - # $$ = 0; + # p[0] = None # } () def p_procedural_assertion_statement_2(p): '''procedural_assertion_statement : K_assert '(' expression ')' K_else statement ''' print('procedural_assertion_statement_2', list(p)) # { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); - # $$ = 0; + # p[0] = None # } () def p_procedural_assertion_statement_3(p): '''procedural_assertion_statement : K_assert '(' expression ')' statement K_else statement ''' print('procedural_assertion_statement_3', list(p)) # { yyerror(@1, "sorry: Simple immediate assertion statements not implemented."); - # $$ = 0; + # p[0] = None # } () def p_property_qualifier_1(p): @@ -1561,7 +1568,7 @@ def p_property_qualifier_2(p): def p_property_qualifier_opt_1(p): '''property_qualifier_opt : property_qualifier_list ''' print('property_qualifier_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_property_qualifier_opt_2(p): '''property_qualifier_opt : ''' @@ -1576,7 +1583,7 @@ def p_property_qualifier_list_1(p): def p_property_qualifier_list_2(p): '''property_qualifier_list : property_qualifier ''' print('property_qualifier_list_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_property_spec_1(p): '''property_spec : clocking_event_opt property_spec_disable_iff_opt property_expr ''' @@ -1611,12 +1618,12 @@ def p_real_or_realtime_2(p): def p_signing_1(p): '''signing : K_signed ''' print('signing_1', list(p)) - # { $$ = true; } + p[0] = True () def p_signing_2(p): '''signing : K_unsigned ''' print('signing_2', list(p)) - # { $$ = false; } + p[0] = False () def p_simple_type_or_string_1(p): '''simple_type_or_string : integer_vector_type ''' @@ -1705,12 +1712,12 @@ def p_statement_1(p): def p_statement_or_null_1(p): '''statement_or_null : statement ''' print('statement_or_null_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_statement_or_null_2(p): '''statement_or_null : attribute_list_opt ';' ''' print('statement_or_null_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_stream_expression_1(p): '''stream_expression : expression ''' @@ -1738,10 +1745,10 @@ def p_streaming_concatenation_1(p): # { /* streaming concatenation is a SystemVerilog thing. */ # if (gn_system_verilog()) { # yyerror(@2, "sorry: Streaming concatenation not supported."); - # $$ = 0; + # p[0] = None # } else { # yyerror(@2, "error: Streaming concatenation requires SystemVerilog"); - # $$ = 0; + # p[0] = None # } # } () @@ -1993,7 +2000,7 @@ def p_tf_port_item_2(p): print('tf_port_item_2', list(p)) # { yyerror(@3, "error: Error in task/function port item after port name %s.", $3); # yyerrok; - # $$ = 0; + # p[0] = None # } () def p_tf_port_item_expr_opt_1(p): @@ -2009,12 +2016,12 @@ def p_tf_port_item_expr_opt_1(p): def p_tf_port_item_expr_opt_2(p): '''tf_port_item_expr_opt : ''' print('tf_port_item_expr_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_tf_port_list_1(p): '''tf_port_list : _embed0_tf_port_list tf_port_item_list ''' print('tf_port_list_1', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p__embed0_tf_port_list(p): '''_embed0_tf_port_list : ''' @@ -2044,7 +2051,7 @@ def p_tf_port_item_list_1(p): def p_tf_port_item_list_2(p): '''tf_port_item_list : tf_port_item ''' print('tf_port_item_list_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_tf_port_item_list_3(p): '''tf_port_item_list : error ',' tf_port_item ''' @@ -2171,27 +2178,27 @@ def p_variable_lifetime_1(p): def p_attribute_list_opt_1(p): '''attribute_list_opt : attribute_instance_list ''' print('attribute_list_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_attribute_list_opt_2(p): '''attribute_list_opt : ''' print('attribute_list_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_attribute_instance_list_1(p): '''attribute_instance_list : K_PSTAR K_STARP ''' print('attribute_instance_list_1', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_attribute_instance_list_2(p): '''attribute_instance_list : K_PSTAR attribute_list K_STARP ''' print('attribute_instance_list_2', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p_attribute_instance_list_3(p): '''attribute_instance_list : attribute_instance_list K_PSTAR K_STARP ''' print('attribute_instance_list_3', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_attribute_instance_list_4(p): '''attribute_instance_list : attribute_instance_list K_PSTAR attribute_list K_STARP ''' @@ -2326,12 +2333,12 @@ def p_block_item_decls_2(p): def p_block_item_decls_opt_1(p): '''block_item_decls_opt : block_item_decls ''' print('block_item_decls_opt_1', list(p)) - # { $$ = true; } + p[0] = True () def p_block_item_decls_opt_2(p): '''block_item_decls_opt : ''' print('block_item_decls_opt_2', list(p)) - # { $$ = false; } + p[0] = False () def p_type_declaration_1(p): '''type_declaration : K_typedef data_type IDENTIFIER dimensions_opt ';' ''' @@ -2642,7 +2649,7 @@ def p_struct_union_member_2(p): print('struct_union_member_2', list(p)) # { yyerror(@2, "Error in struct/union member."); # yyerrok; - # $$ = 0; + # p[0] = None # } () def p_case_item_1(p): @@ -2791,12 +2798,12 @@ def p_delay3_4(p): def p_delay3_opt_1(p): '''delay3_opt : delay3 ''' print('delay3_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_delay3_opt_2(p): '''delay3_opt : ''' print('delay3_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_delay_value_list_1(p): '''delay_value_list : delay_value ''' @@ -2832,7 +2839,7 @@ def p_delay_value_simple_1(p): # { verinum*tmp = $1; # if (tmp == 0) { # yyerror(@1, "internal error: delay."); - # $$ = 0; + # p[0] = None # } else { # $$ = new PENumber(tmp); # FILE_NAME($$, @1); @@ -2846,7 +2853,7 @@ def p_delay_value_simple_2(p): # { verireal*tmp = $1; # if (tmp == 0) { # yyerror(@1, "internal error: delay."); - # $$ = 0; + # p[0] = None # } else { # $$ = new PEFNumber(tmp); # FILE_NAME($$, @1); @@ -3086,7 +3093,7 @@ def p_drive_strength_6(p): def p_drive_strength_opt_1(p): '''drive_strength_opt : drive_strength ''' print('drive_strength_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_drive_strength_opt_2(p): '''drive_strength_opt : ''' @@ -3165,13 +3172,13 @@ def p_event_control_3(p): '''event_control : '@' '(' error ')' ''' print('event_control_3', list(p)) # { yyerror(@1, "error: Malformed event control expression."); - # $$ = 0; + # p[0] = None # } () def p_event_expression_list_1(p): '''event_expression_list : event_expression ''' print('event_expression_list_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_event_expression_list_2(p): '''event_expression_list : event_expression_list K_or event_expression ''' @@ -3235,22 +3242,21 @@ def p_expression_1(p): '''expression : expr_primary_or_typename ''' print('expression_1', list(p)) p[0] = p[1] - # { $$ = $1; } () def p_expression_2(p): '''expression : inc_or_dec_expression ''' print('expression_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_expression_3(p): '''expression : inside_expression ''' print('expression_3', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_expression_4(p): '''expression : '+' attribute_list_opt expr_primary %prec UNARY_PREC ''' print('expression_4', list(p)) - # { $$ = $3; } + p[0] = p[3] () def p_expression_5(p): '''expression : '-' attribute_list_opt expr_primary %prec UNARY_PREC ''' @@ -3305,7 +3311,7 @@ def p_expression_11(p): print('expression_11', list(p)) # { yyerror(@1, "error: '~' '&' is not a valid expression. " # "Please use operator '~&' instead."); - # $$ = 0; + # p[0] = None # } () def p_expression_12(p): @@ -3313,7 +3319,7 @@ def p_expression_12(p): print('expression_12', list(p)) # { yyerror(@1, "error: '~' '|' is not a valid expression. " # "Please use operator '~|' instead."); - # $$ = 0; + # p[0] = None # } () def p_expression_13(p): @@ -3321,7 +3327,7 @@ def p_expression_13(p): print('expression_13', list(p)) # { yyerror(@1, "error: '~' '^' is not a valid expression. " # "Please use operator '~^' instead."); - # $$ = 0; + # p[0] = None # } () def p_expression_14(p): @@ -3353,7 +3359,7 @@ def p_expression_17(p): print('expression_17', list(p)) # { yyerror(@1, "error: Operand of unary ! " # "is not a primary expression."); - # $$ = 0; + # p[0] = None # } () def p_expression_18(p): @@ -3361,7 +3367,7 @@ def p_expression_18(p): print('expression_18', list(p)) # { yyerror(@1, "error: Operand of reduction ^ " # "is not a primary expression."); - # $$ = 0; + # p[0] = None # } () def p_expression_19(p): @@ -3591,7 +3597,7 @@ def p_expression_46(p): def p_expr_mintypmax_1(p): '''expr_mintypmax : expression ''' print('expr_mintypmax_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_expr_mintypmax_2(p): '''expr_mintypmax : expression ':' expression ':' expression ''' @@ -4066,7 +4072,7 @@ def p_expr_primary_38(p): def p_expr_primary_39(p): '''expr_primary : '(' expr_mintypmax ')' ''' print('expr_primary_39', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p_expr_primary_40(p): '''expr_primary : '{' expression_list_proper '}' ''' @@ -4111,7 +4117,7 @@ def p_expr_primary_43(p): # $$ = tmp; # } else { # yyerror(@1, "error: Concatenations are not allowed to be empty."); - # $$ = 0; + # p[0] = None # } # } () @@ -4146,12 +4152,12 @@ def p_expr_primary_45(p): def p_expr_primary_46(p): '''expr_primary : assignment_pattern ''' print('expr_primary_46', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_expr_primary_47(p): '''expr_primary : streaming_concatenation ''' print('expr_primary_47', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_expr_primary_48(p): '''expr_primary : K_null ''' @@ -4164,17 +4170,17 @@ def p_expr_primary_48(p): def p_function_item_list_opt_1(p): '''function_item_list_opt : function_item_list ''' print('function_item_list_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_function_item_list_opt_2(p): '''function_item_list_opt : ''' print('function_item_list_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_function_item_list_1(p): '''function_item_list : function_item ''' print('function_item_list_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_function_item_list_2(p): '''function_item_list : function_item_list function_item ''' @@ -4198,12 +4204,12 @@ def p_function_item_list_2(p): def p_function_item_1(p): '''function_item : tf_port_declaration ''' print('function_item_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_function_item_2(p): '''function_item : block_item_decl ''' print('function_item_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_gate_instance_1(p): '''gate_instance : IDENTIFIER '(' expression_list_with_nuls ')' ''' @@ -4820,7 +4826,7 @@ def p_port_declaration_7(p): def p_net_type_opt_1(p): '''net_type_opt : net_type ''' print('net_type_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_net_type_opt_2(p): '''net_type_opt : ''' @@ -4830,32 +4836,32 @@ def p_net_type_opt_2(p): def p_unsigned_signed_opt_1(p): '''unsigned_signed_opt : K_signed ''' print('unsigned_signed_opt_1', list(p)) - # { $$ = true; } + p[0] = True () def p_unsigned_signed_opt_2(p): '''unsigned_signed_opt : K_unsigned ''' print('unsigned_signed_opt_2', list(p)) - # { $$ = false; } + p[0] = False () def p_unsigned_signed_opt_3(p): '''unsigned_signed_opt : ''' print('unsigned_signed_opt_3', list(p)) - # { $$ = false; } + p[0] = False () def p_signed_unsigned_opt_1(p): '''signed_unsigned_opt : K_signed ''' print('signed_unsigned_opt_1', list(p)) - # { $$ = true; } + p[0] = True () def p_signed_unsigned_opt_2(p): '''signed_unsigned_opt : K_unsigned ''' print('signed_unsigned_opt_2', list(p)) - # { $$ = false; } + p[0] = False () def p_signed_unsigned_opt_3(p): '''signed_unsigned_opt : ''' print('signed_unsigned_opt_3', list(p)) - # { $$ = true; } + p[0] = True () def p_atom2_type_1(p): '''atom2_type : K_byte ''' @@ -4915,7 +4921,7 @@ def p_lpvalue_4(p): '''lpvalue : streaming_concatenation ''' print('lpvalue_4', list(p)) # { yyerror(@1, "sorry: streaming concatenation not supported in l-values."); - # $$ = 0; + # p[0] = None # } () def p_cont_assign_1(p): @@ -4939,17 +4945,27 @@ def p_cont_assign_list_1(p): def p_cont_assign_list_2(p): '''cont_assign_list : cont_assign ''' print('cont_assign_list_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_module_1(p): '''module : attribute_list_opt module_start lifetime_opt IDENTIFIER _embed0_module module_package_import_list_opt module_parameter_port_list_opt module_port_list_opt module_attribute_foreign ';' _embed1_module timeunits_declaration_opt _embed2_module module_item_list_opt module_end _embed3_module endlabel_opt ''' print('module_1', list(p)) + params = p[7] clsname = [Leaf(token.NAME, 'class'), Leaf(token.NAME, p[4], prefix=' '), Leaf(token.COLON, ':')] - stmt = Node(syms.pass_stmt, [Leaf(token.NAME, "pass"),]) - stmts = Node(syms.small_stmt, [stmt, Leaf(token.NEWLINE, '\n')]) - stmts = Node(syms.stmt, [stmts]) + pass_stmt = Node(syms.pass_stmt, [Leaf(token.NAME, "pass"),]) + if params: + params = [Leaf(token.LPAR, '(')] + params + [Leaf(token.RPAR, ')')] + fn = [Leaf(token.NAME, 'def'), + Leaf(token.NAME, '__init__', prefix=' '), + Node(syms.parameters, params), + Leaf(token.COLON, ':')] + fndef = Node(syms.funcdef, fn) + stmts = Node(syms.stmt, [fndef]) + else: + stmts = Node(syms.small_stmt, [pass_stmt, Leaf(token.NEWLINE, '\n')]) + stmts = Node(syms.stmt, [stmts]) suite = Node(syms.suite, [Leaf(token.NEWLINE, '\n'), Leaf(token.INDENT, ' '), stmts, @@ -5083,44 +5099,44 @@ def p_module_end_3(p): def p_endlabel_opt_1(p): '''endlabel_opt : ':' IDENTIFIER ''' print('endlabel_opt_1', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p_endlabel_opt_2(p): '''endlabel_opt : ''' print('endlabel_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_module_attribute_foreign_1(p): '''module_attribute_foreign : K_PSTAR IDENTIFIER K_integer IDENTIFIER '=' STRING ';' K_STARP ''' print('module_attribute_foreign_1', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_module_attribute_foreign_2(p): '''module_attribute_foreign : ''' print('module_attribute_foreign_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_module_port_list_opt_1(p): '''module_port_list_opt : '(' list_of_ports ')' ''' print('module_port_list_opt_1', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p_module_port_list_opt_2(p): '''module_port_list_opt : '(' list_of_port_declarations ')' ''' print('module_port_list_opt_2', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p_module_port_list_opt_3(p): '''module_port_list_opt : ''' print('module_port_list_opt_3', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_module_port_list_opt_4(p): '''module_port_list_opt : '(' error ')' ''' print('module_port_list_opt_4', list(p)) # { yyerror(@2, "Errors in port declarations."); # yyerrok; - # $$ = 0; + # p[0] = None # } () def p_module_parameter_port_list_opt_1(p): @@ -5130,18 +5146,25 @@ def p_module_parameter_port_list_opt_1(p): def p_module_parameter_port_list_opt_2(p): '''module_parameter_port_list_opt : '#' '(' module_parameter_port_list ')' ''' print('module_parameter_port_list_opt_2', list(p)) + p[0] = p[3] () def p_module_parameter_port_list_1(p): '''module_parameter_port_list : K_parameter param_type parameter_assign ''' print('module_parameter_port_list_1', list(p)) + p[0] = [p[3]] () def p_module_parameter_port_list_2(p): '''module_parameter_port_list : module_parameter_port_list ',' parameter_assign ''' print('module_parameter_port_list_2', list(p)) + p[0] = p[1].append(p[3]) () def p_module_parameter_port_list_3(p): '''module_parameter_port_list : module_parameter_port_list ',' K_parameter param_type parameter_assign ''' print('module_parameter_port_list_3', list(p)) + p[1].append(Leaf(token.COMMA, ',')) + p[5].prefix=' ' # add a space after the comma, must go in the parameter + p[1].append(p[5]) + p[0] = p[1] () def p_module_item_1(p): '''module_item : module ''' @@ -5977,6 +6000,9 @@ def p_localparam_assign_list_2(p): def p_parameter_assign_1(p): '''parameter_assign : IDENTIFIER '=' expression parameter_value_ranges_opt ''' print('parameter_assign_1', list(p)) + tpname = Node(syms.tname, [Leaf(token.NAME, p[1])]) + expr = Node(syms.tfpdef, [tpname, Leaf(token.EQUAL, p[2]), p[3] ]) + p[0] = expr # { PExpr*tmp = $3; # pform_set_parameter(@1, lex_strings.make($1), param_active_type, # param_active_signed, param_active_range, tmp, $4); @@ -5995,12 +6021,12 @@ def p_localparam_assign_1(p): def p_parameter_value_ranges_opt_1(p): '''parameter_value_ranges_opt : parameter_value_ranges ''' print('parameter_value_ranges_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_parameter_value_ranges_opt_2(p): '''parameter_value_ranges_opt : ''' print('parameter_value_ranges_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_parameter_value_ranges_1(p): '''parameter_value_ranges : parameter_value_ranges parameter_value_range ''' @@ -6040,32 +6066,32 @@ def p_parameter_value_range_5(p): def p_value_range_expression_1(p): '''value_range_expression : expression ''' print('value_range_expression_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_value_range_expression_2(p): '''value_range_expression : K_inf ''' print('value_range_expression_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_value_range_expression_3(p): '''value_range_expression : '+' K_inf ''' print('value_range_expression_3', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_value_range_expression_4(p): '''value_range_expression : '-' K_inf ''' print('value_range_expression_4', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_from_exclude_1(p): '''from_exclude : K_from ''' print('from_exclude_1', list(p)) - # { $$ = false; } + p[0] = False () def p_from_exclude_2(p): '''from_exclude : K_exclude ''' print('from_exclude_2', list(p)) - # { $$ = true; } + p[0] = True () def p_parameter_value_opt_1(p): '''parameter_value_opt : '#' '(' expression_list_with_nuls ')' ''' @@ -6119,13 +6145,13 @@ def p_parameter_value_opt_5(p): print('parameter_value_opt_5', list(p)) # { yyerror(@1, "error: syntax error in parameter value " # "assignment list."); - # $$ = 0; + # p[0] = None # } () def p_parameter_value_opt_6(p): '''parameter_value_opt : ''' print('parameter_value_opt_6', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_parameter_value_byname_1(p): '''parameter_value_byname : '.' IDENTIFIER '(' expression ')' ''' @@ -6168,7 +6194,7 @@ def p_parameter_value_byname_list_2(p): def p_port_1(p): '''port : port_reference ''' print('port_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_port_2(p): '''port : '.' IDENTIFIER '(' port_reference ')' ''' @@ -6199,12 +6225,12 @@ def p_port_4(p): def p_port_opt_1(p): '''port_opt : port ''' print('port_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_port_opt_2(p): '''port_opt : ''' print('port_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_port_name_1(p): '''port_name : '.' IDENTIFIER '(' expression ')' ''' @@ -6350,7 +6376,7 @@ def p_port_reference_4(p): def p_port_reference_list_1(p): '''port_reference_list : port_reference ''' print('port_reference_list_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_port_reference_list_2(p): '''port_reference_list : port_reference_list ',' port_reference ''' @@ -6364,17 +6390,17 @@ def p_port_reference_list_2(p): def p_dimensions_opt_1(p): '''dimensions_opt : ''' print('dimensions_opt_1', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_dimensions_opt_2(p): '''dimensions_opt : dimensions ''' print('dimensions_opt_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_dimensions_1(p): '''dimensions : variable_dimension ''' print('dimensions_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_dimensions_2(p): '''dimensions : dimensions variable_dimension ''' @@ -6678,12 +6704,12 @@ def p_specify_edge_path_decl_2(p): def p_edge_operator_1(p): '''edge_operator : K_posedge ''' print('edge_operator_1', list(p)) - # { $$ = true; } + p[0] = True () def p_edge_operator_2(p): '''edge_operator : K_negedge ''' print('edge_operator_2', list(p)) - # { $$ = false; } + p[0] = False () def p_specify_edge_path_1(p): '''specify_edge_path : '(' specify_path_identifiers spec_polarity K_EG '(' specify_path_identifiers polarity_operator expression ')' ')' ''' @@ -6739,7 +6765,7 @@ def p_specify_simple_path_decl_3(p): print('specify_simple_path_decl_3', list(p)) # { yyerror(@3, "Syntax error in delay value list."); # yyerrok; - # $$ = 0; + # p[0] = None # } () def p_specify_simple_path_1(p): @@ -6933,7 +6959,7 @@ def p_spec_polarity_2(p): def p_spec_polarity_3(p): '''spec_polarity : ''' print('spec_polarity_3', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_spec_reference_event_1(p): '''spec_reference_event : K_posedge expression ''' @@ -7194,17 +7220,17 @@ def p_statement_item_13(p): def p_statement_item_14(p): '''statement_item : procedural_assertion_statement ''' print('statement_item_14', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_statement_item_15(p): '''statement_item : loop_statement ''' print('statement_item_15', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_statement_item_16(p): '''statement_item : jump_statement ''' print('statement_item_16', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_statement_item_17(p): '''statement_item : K_case '(' expression ')' case_items K_endcase ''' @@ -7278,7 +7304,7 @@ def p_statement_item_26(p): def p_statement_item_27(p): '''statement_item : compressed_statement ';' ''' print('statement_item_27', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_statement_item_28(p): '''statement_item : inc_or_dec_expression ';' ''' @@ -7302,7 +7328,7 @@ def p_statement_item_30(p): # { PEventStatement*tmp = $1; # if (tmp == 0) { # yyerror(@1, "error: Invalid event control."); - # $$ = 0; + # p[0] = None # } else { # tmp->set_statement($2); # $$ = tmp; @@ -7708,12 +7734,12 @@ def p_compressed_statement_11(p): def p_statement_or_null_list_opt_1(p): '''statement_or_null_list_opt : statement_or_null_list ''' print('statement_or_null_list_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_statement_or_null_list_opt_2(p): '''statement_or_null_list_opt : ''' print('statement_or_null_list_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_statement_or_null_list_1(p): '''statement_or_null_list : statement_or_null_list statement_or_null ''' @@ -7744,7 +7770,7 @@ def p_task_item_1(p): def p_task_item_2(p): '''task_item : tf_port_declaration ''' print('task_item_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_task_item_list_1(p): '''task_item_list : task_item_list task_item ''' @@ -7761,27 +7787,27 @@ def p_task_item_list_1(p): def p_task_item_list_2(p): '''task_item_list : task_item ''' print('task_item_list_2', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_task_item_list_opt_1(p): '''task_item_list_opt : task_item_list ''' print('task_item_list_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_task_item_list_opt_2(p): '''task_item_list_opt : ''' print('task_item_list_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_tf_port_list_opt_1(p): '''tf_port_list_opt : tf_port_list ''' print('tf_port_list_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_tf_port_list_opt_2(p): '''tf_port_list_opt : ''' print('tf_port_list_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_udp_body_1(p): '''udp_body : K_table udp_entry_list K_endtable ''' @@ -7795,7 +7821,7 @@ def p_udp_body_2(p): print('udp_body_2', list(p)) # { lex_end_table(); # yyerror(@1, "error: Empty UDP table."); - # $$ = 0; + # p[0] = None # } () def p_udp_body_3(p): @@ -7804,7 +7830,7 @@ def p_udp_body_3(p): # { lex_end_table(); # yyerror(@2, "Errors in UDP table"); # yyerrok; - # $$ = 0; + # p[0] = None # } () def p_udp_entry_list_1(p): @@ -7892,12 +7918,12 @@ def p_udp_initial_1(p): def p_udp_init_opt_1(p): '''udp_init_opt : udp_initial ''' print('udp_init_opt_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_udp_init_opt_2(p): '''udp_init_opt : ''' print('udp_init_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_udp_input_list_1(p): '''udp_input_list : udp_input_sym ''' @@ -8106,7 +8132,7 @@ def p_udp_port_decl_4(p): def p_udp_port_decls_1(p): '''udp_port_decls : udp_port_decl ''' print('udp_port_decls_1', list(p)) - # { $$ = $1; } + p[0] = p[1] () def p_udp_port_decls_2(p): '''udp_port_decls : udp_port_decls udp_port_decl ''' @@ -8141,22 +8167,22 @@ def p_udp_port_list_2(p): def p_udp_reg_opt_1(p): '''udp_reg_opt : K_reg ''' print('udp_reg_opt_1', list(p)) - # { $$ = true; } + p[0] = True () def p_udp_reg_opt_2(p): '''udp_reg_opt : ''' print('udp_reg_opt_2', list(p)) - # { $$ = false; } + p[0] = False () def p_udp_initial_expr_opt_1(p): '''udp_initial_expr_opt : '=' expression ''' print('udp_initial_expr_opt_1', list(p)) - # { $$ = $2; } + p[0] = p[2] () def p_udp_initial_expr_opt_2(p): '''udp_initial_expr_opt : ''' print('udp_initial_expr_opt_2', list(p)) - # { $$ = 0; } + # { p[0] = None } () def p_udp_input_declaration_list_1(p): '''udp_input_declaration_list : K_input IDENTIFIER ''' @@ -8221,43 +8247,43 @@ def p_udp_primitive_2(p): def p_K_packed_opt_1(p): '''K_packed_opt : K_packed ''' print('K_packed_opt', list(p)) - # { $$ = true; } + p[0] = True () def p_K_packed_opt_2(p): '''K_packed_opt : ''' print('K_packed_opt', list(p)) - # { $$ = false; } + p[0] = False () def p_K_reg_opt_1(p): '''K_reg_opt : K_reg ''' print('K_reg_opt', list(p)) - # { $$ = true; } + p[0] = True () def p_K_reg_opt_2(p): '''K_reg_opt : ''' print('K_reg_opt', list(p)) - # { $$ = false; } + p[0] = False () def p_K_static_opt_1(p): '''K_static_opt : K_static ''' print('K_static_opt', list(p)) - # { $$ = true; } + p[0] = True () def p_K_static_opt_2(p): '''K_static_opt : ''' print('K_static_opt', list(p)) - # { $$ = false; } + p[0] = False () def p_K_virtual_opt_1(p): '''K_virtual_opt : K_virtual ''' print(p) - # { $$ = true; } + p[0] = True () def p_K_virtual_opt_2(p): '''K_virtual_opt : ''' print(p) - # { $$ = false; } + p[0] = False () def p_error(p):