3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-26 10:35:38 +00:00

Added defparam support to Verilog/AST frontend

This commit is contained in:
Clifford Wolf 2013-07-04 14:12:33 +02:00
parent 3b294b3912
commit 56432a920f
7 changed files with 79 additions and 13 deletions

View file

@ -94,7 +94,7 @@ static void free_attr(std::map<std::string, AstNode*> *al)
%token <string> 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<std::string, AstNode*> *al)
%token TOK_SUPPLY0 TOK_SUPPLY1 TOK_TO_SIGNED TOK_TO_UNSIGNED
%type <ast> wire_type range expr basic_expr concat_list rvalue lvalue lvalue_concat_list
%type <string> opt_label tok_prim_wrapper
%type <string> opt_label tok_prim_wrapper hierarchical_id
%type <boolean> opt_signed
%type <al> 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;