def p_port_dec_more(self, args): ''' comma_port_declarations ::= comma_port_declarations COMMA port_declaration comma_port_declarations ::= ''' if len(args) > 0: return AST('MORE', [args[0], args[2]]) return AST('None', [None])
def p_block_assign(self, args): ''' ## great -> [LPAREN expression (COMMA expression)* RPAREN] ['<=' [delay_or_event_control] [expression] ] blocking_assignment ::= variable_lvalue great2_opt SEMICOLON ''' if len(args) > 0: return AST('BLOCK_ASSIGN', [args[0], AST('B_LEFT_OVER', [None]), args[1]])
def p_port_expression(self, args): ''' port_expression ::= port_reference port_expression ::= LBRACE port_reference comma_port_references RBRACE ''' if len(args) == 1: return AST('single', [args[0]]) else: return AST('PORT_COMBINE', [args[1], args[2]])
def p_exp_nlr_1(self, args): ''' expression_nlrs ::= expression_nlrs expression_nlr expression_nlrs ::= ''' if len(args) == 0: return AST('None', []) else: return AST('More', [args[0], args[1]])
def p_var_left(self, args): ''' variable_lvalue ::= hierarchical_identifier_range variable_lvalue ::= LBRACE variable_lvalue COMMA_variable_lvalues RBRACE ''' if len(args) > 1: return AST('More', [args[0], args[1]]) else: return AST('single', [args[0]])
def p_assign_dec_3_0_2(self, args): ''' COMMA_net_lvalues ::= COMMA_net_lvalues COMMA net_lvalue COMMA_net_lvalues ::= ''' if len(args) == 0: return AST('None', None) else: return AST('More', [args[0], args[2]])
def p_exp_content_0(self, args): ''' expression ::= unary_operator_opt primary expression_nlrs ''' # 目前忽略operator if args[1] == 'single' and args[2].kind == 'None': return AST('single', [args[1]]) else: return AST('EXPR', [args[1], args[2]])
def p_assign_dec_2(self, args): ''' net_assignment ::= net_lvalue IS_EQUAL expression ''' return AST('ASSIGN_2', [ args[0], AST('LEFT_OVER', [None]), args[2], AST('ASSIGN_OVER', [None]) ])
def p_const_range_exp_1(self, args): ''' COLON_lsb_constant_expression_opt ::= COLON lsb_constant_expression COLON_lsb_constant_expression_opt ::= ''' if len(args) == 0: return AST('None', []) else: return AST('More', [args[1]])
def p_list_var_2(self, args): ''' IS_EQUAL_constant_expression_opt ::= IS_EQUAL constant_expression IS_EQUAL_constant_expression_opt ::= ''' if len(args) > 0: return AST('EQUAL', [args[1]]) else: return AST('None', [None])
def p_exp_nlr_2(self, args): ''' expression_nlr ::= binary_operator expression expression_nlr ::= QUES expression COLON expression ''' if len(args) == 2: return AST('UNION', [args[0], args[1], AST('do_cal', [None])]) else: return AST('Ques', [args[1], args[3]])
def p_hie_ident_range_1_2(self, args): ''' great3_opt_s ::= great3_opt_s great3_opt_chosen great3_opt_s ::= ''' ##ignore more opts if len(args) == 0: return AST('None', None) else: return AST('single', [args[1]])
def p_list_var_1(self, args): ''' ###(COMMA port_identifier [IS_EQUAL constant_expression])* list_of_variable_identifiers ::= port_identifier IS_EQUAL_constant_expression_opt COMMA_port_identifier_IS_EQUAL_constant_expression_opt_s ''' ## ignore more commas if args[1].kind == 'None': return AST('single', [args[0]]) else: return AST('plex', [args[0], args[1]])
def p_dim_1(self, args): ''' dor_dim_and_exp ::= dimension+ dor_dim_and_exp ::= IS_EQUAL expression ''' if len(args) == 1: return AST('plex', [args[0]]) else: return AST('EQUAL', [args[1]])
def p_port_dec_more_in_items(self, args): ''' module_items ::= module_items module_item module_items ::= ''' if len(args) > 0: return AST('Module_items', [args[0], args[1]]) else: return AST('No More', []) pass
def p_port(self, args): ''' port ::= port_expression port ::= DOT port_identifier LPAREN port_expression_opt RPAREN ''' if len(args) == 1: return AST('PORT', [args[0]]) else: return AST('PORT', [None])
def p_const_expr(self, args): ''' ## constant_expression ::= [ unary_operator ] constant_primary constant_expression_nlrs constant_expression ::= unary_operator_opt constant_primary constant_expression_nlrs ''' if len(args) > 0 and args[2] != None: return AST('single', [args[1], args[2]]) else: return AST('single', [args[1]]) pass
def p_port_range_decla(self, args): ''' range_opt ::= range range_opt ::= ''' tmp = None if len(args) == 0: tmp = AST('WIDTH', [None]) else: tmp = AST('WIDTH', [args[0]]) return tmp
def p_hie_ident_range_1(self, args): ''' ## hierarchical_identifier_range ::= identifier ( DOT identifier [ LBRACKET range_expression RBRACKET ] | LBRACKET range_expression RBRACKET )* hierarchical_identifier_range ::= identifier great3_opt_s ''' if len(args) == 2: if args[1].kind == 'None': return AST('single', [args[0]]) else: return AST('More', [args[0], args[1]])
def p_assign_dec_3_0(self, args): ''' net_lvalue ::= hierarchical_identifier_range_const net_lvalue ::= LBRACE net_lvalue COMMA_net_lvalues RBRACE ''' if len(args) == 1: return AST('NET_LEFT', [args[0]]) else: return AST('COMBINE', [args[1], args[2], AST('COMBINE_OVER', [None])])
def p_list_of_ports(self, args): ''' ## 这里的port真的需要左右有中括号吗? list_of_ports ::= port (COMMA [port])* ## new comma_port_opt_s list_of_ports ::= port comma_port_opt_s list_of_port_declarations ::= port_declaration comma_port_declarations ''' if len(args) > 1: return AST('PORTs', [args[0], args[1]]) return AST('single', [args[0]])
def p_always_top_1(self, args): ''' event_control ::= AT LPAREN event_expression RPAREN ##dor!!! STAR must be caution event_control ::= AT LPAREN BINOP RPAREN event_control ::= AT BINOP ''' if len(args) > 2: return AST('Trigger', [args[2], AST('TriggerEnd', [None])]) return AST('Trigger_any', [None])
def p_net_wire_1(self, args): ''' ## dor dimension and expression // line 67 ## list_of_net_decl_assignments_or_identifiers ::= net_identifier [ dor_dim_and_exp ] (COMMA net_identifier dor_dim_and_exp )* list_of_net_decl_assignments_or_identifiers ::= net_identifier dor_dim_and_exp_opt COMMA_net_identifier_dor_dim_and_exps ''' if (args[1] != None): return AST('plex', [args[0], args[1]]) else: return AST('single', [args[0]])
def p_hie_ident_range_const_1(self, args): ''' hierarchical_identifier_range_const ::= identifier LBRACKET_constant_range_expression_RBRACKETs LBRACKET_constant_range_expression_RBRACKETs ::= LBRACKET_constant_range_expression_RBRACKETs LBRACKET constant_range_expression RBRACKET LBRACKET_constant_range_expression_RBRACKETs ::= ''' if len(args) == 0: return AST('None', []) elif len(args) == 2: return AST('ident_and_range', [args[0], args[1]]) else: return AST('More', [args[0], args[2]])
def p_primary_1(self, args): ''' ## primary ::= hierarchical_identifier_range [ LPAREN expression (COMMA expression)* RPAREN ] primary ::= hierarchical_identifier_range LPAREN_expression_COMMA_expressions_RPAREN_opt LPAREN_expression_COMMA_expressions_RPAREN_opt ::= LPAREN expression COMMA_expressions RPAREN LPAREN_expression_COMMA_expressions_RPAREN_opt ::= ''' ## ignore args[1] if len(args) == 0: return AST('None', None) else: if args[1].kind == 'None': return AST('single', [args[0]]) else: return AST('More', [args[0], args[1]])
def p_generate_single(self, args): ''' msb_constant_expression ::= constant_expression lsb_constant_expression ::= constant_expression constant_primary ::= number number ::= real_number module_item ::= non_port_module_item non_port_module_item ::= module_or_generate_item non_port_module_item ::= generate_region module_or_generate_item ::= module_or_generate_item_declaration module_or_generate_item ::= continuous_assign module_or_generate_item ::= gate_instantiation module_or_generate_item ::= always_construct module_or_generate_item ::= loop_generate_construct module_or_generate_item ::= conditional_generate_construct module_or_generate_item_declaration ::= net_declaration module_or_generate_item_declaration ::= reg_declaration module_or_generate_item_declaration ::= integer_declaration module_or_generate_item_declaration ::= genvar_declaration ##---- always statement statement ::= blocking_assignment statement ::= case_statement statement ::= conditional_statement statement ::= loop_statement statement ::= procedural_continuous_assignments SEMICOLON statement ::= SEMICOLON ''' return AST('single', [args[0]])
def p_single_opt(self, args): ''' statement_or_null ::= statement? expression_opt ::= expression? ''' if len(args) > 0: return AST('single', [args[0]])
def p_binary(self, args): ''' binary_operator ::= BINOP binary_operator ::= PLUS binary_operator ::= MINUS ''' return AST('cal_op', [args[0]])
def p_gen_single_or_not(self, args): ''' ### dim_and_exp : 数组长度 dor_dim_and_exp_opt ::= dor_dim_and_exp? ''' if args[0] != None: return AST('single', [args[0]])
def p_list_var_1_1(self, args): ''' COMMA_port_identifier_IS_EQUAL_constant_expression_opt_s ::= COMMA_port_identifier_IS_EQUAL_constant_expression_opt_s COMMA port_identifier IS_EQUAL_constant_expression_opt COMMA_port_identifier_IS_EQUAL_constant_expression_opt_s ::= ''' if len(args) > 0: return AST('more', [args[0], args[2], args[3]])