From 56432a920f9c2189ead2f724f18cde20aad7bf99 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 4 Jul 2013 14:12:33 +0200 Subject: Added defparam support to Verilog/AST frontend --- frontends/verilog/parser.y | 48 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'frontends/verilog/parser.y') diff --git a/frontends/verilog/parser.y b/frontends/verilog/parser.y index 68ac26bf..ba0efcf5 100644 --- a/frontends/verilog/parser.y +++ b/frontends/verilog/parser.y @@ -94,7 +94,7 @@ static void free_attr(std::map *al) %token TOK_STRING TOK_ID TOK_CONST TOK_PRIMITIVE %token ATTR_BEGIN ATTR_END DEFATTR_BEGIN DEFATTR_END -%token TOK_MODULE TOK_ENDMODULE TOK_PARAMETER TOK_LOCALPARAM +%token TOK_MODULE TOK_ENDMODULE TOK_PARAMETER TOK_LOCALPARAM TOK_DEFPARAM %token TOK_INPUT TOK_OUTPUT TOK_INOUT TOK_WIRE TOK_REG %token TOK_INTEGER TOK_SIGNED TOK_ASSIGN TOK_ALWAYS TOK_INITIAL %token TOK_BEGIN TOK_END TOK_IF TOK_ELSE TOK_FOR @@ -106,7 +106,7 @@ static void free_attr(std::map *al) %token TOK_SUPPLY0 TOK_SUPPLY1 TOK_TO_SIGNED TOK_TO_UNSIGNED %type wire_type range expr basic_expr concat_list rvalue lvalue lvalue_concat_list -%type opt_label tok_prim_wrapper +%type opt_label tok_prim_wrapper hierarchical_id %type opt_signed %type attr @@ -176,19 +176,32 @@ attr_list: attr_list ',' attr_assign; attr_assign: - TOK_ID { + hierarchical_id { if (attr_list.count(*$1) != 0) delete attr_list[*$1]; attr_list[*$1] = AstNode::mkconst_int(0, false, 0); delete $1; } | - TOK_ID '=' expr { + hierarchical_id '=' expr { if (attr_list.count(*$1) != 0) delete attr_list[*$1]; attr_list[*$1] = $3; delete $1; }; +hierarchical_id: + TOK_ID { + $$ = $1; + } | + hierarchical_id '.' TOK_ID { + if ($3->substr(0, 1) == "\\") + *$1 += "." + $3->substr(1); + else + *$1 += "." + *$3; + delete $3; + $$ = $1; + }; + module: attr TOK_MODULE TOK_ID { AstNode *mod = new AstNode(AST_MODULE); @@ -309,7 +322,7 @@ module_body: /* empty */; module_body_stmt: - task_func_decl | param_decl | localparam_decl | wire_decl | assign_stmt | cell_stmt | + task_func_decl | param_decl | localparam_decl | defparam_decl | wire_decl | assign_stmt | cell_stmt | always_stmt | TOK_GENERATE module_gen_body TOK_ENDGENERATE | defattr; task_func_decl: @@ -389,6 +402,23 @@ single_localparam_decl: delete $2; }; +defparam_decl: + TOK_DEFPARAM defparam_decl_list ';'; + +defparam_decl_list: + single_defparam_decl | defparam_decl_list ',' single_defparam_decl; + +single_defparam_decl: + range hierarchical_id '=' expr { + AstNode *node = new AstNode(AST_DEFPARAM); + node->str = *$2; + node->children.push_back($4); + if ($1 != NULL) + node->children.push_back($1); + ast_stack.back()->children.push_back(node); + delete $2; + }; + wire_decl: attr wire_type range { albuf = $1; @@ -671,7 +701,7 @@ simple_behavioral_stmt: behavioral_stmt: defattr | simple_behavioral_stmt ';' | - TOK_ID attr { + hierarchical_id attr { AstNode *node = new AstNode(AST_TCALL); node->str = *$1; delete $1; @@ -808,12 +838,12 @@ case_expr_list: }; rvalue: - TOK_ID '[' expr ']' '.' rvalue { + hierarchical_id '[' expr ']' '.' rvalue { $$ = new AstNode(AST_PREFIX, $3, $6); $$->str = *$1; delete $1; } | - TOK_ID range { + hierarchical_id range { $$ = new AstNode(AST_IDENTIFIER, $2); $$->str = *$1; delete $1; @@ -931,7 +961,7 @@ basic_expr: $$->str = str; delete $1; } | - TOK_ID attr { + hierarchical_id attr { AstNode *node = new AstNode(AST_FCALL); node->str = *$1; delete $1; -- cgit v1.2.3