Hi Ben,
The reason you have to specify 'static' here is because variables initialization needs this keyword. Here is the text from LRM (section 6.21):
Variables declared in a static task, function, or procedural block default to a static lifetime and a local scope. However, an explicit static keyword shall be required when an initialization value is specified as part of a static variable's declaration to indicate the user's intent of executing that initialization only once at the beginning of simulation.
So, this behaviour is consistent with any other begin...end block.
Manisha
________________________________
From: owner-sv-ac@eda.org [mailto:owner-sv-ac@eda.org] On Behalf Of ben cohen
Sent: Tuesday, July 19, 2011 12:02 PM
To: sv-ac@eda-stds.org; Korchemny, Dmitry
Subject: [sv-ac] Hierarchical ref of local variable in action blocks
Ran the following 3 models:
From the current simulator that I have:
1) Action block local variable must be declared as "static" or "automatic"
2) If "static", then local var maintains its old value as expected.
3) assertion_label.var_name (e.g., a1.x) does not work
Ben
-----------------------------------------
module asn;
static int result, count=0;
logic a=1, b=1, clk=1;
initial forever #10 clk=!clk;
a1: assert property (@(posedge clk)a |-> ##3 b) begin
static int x=0; x +=1; result = x;
end
always @(posedge clk) begin
count+=1;
if(count>=6) begin
b<=0;
$display("count=%d, result=%d", count, result);
end
end
endmodule
# count= 6, result= 2
# count= 7, result= 3
# ** Error: Assertion error.
# Time: 140 ns Started: 80 ns Scope: asn.a1 File: asn.sv Line: 18 Expr: b
# count= 8, result= 3
# ** Error: Assertion error.
# Time: 160 ns Started: 100 ns Scope: asn.a1 File: asn.sv Line: 18 Expr: b
# count= 9, result= 3
# ** Error: Assertion error.
# Time: 180 ns Started: 120 ns Scope: asn.a1 File: asn.sv Line: 18 Expr: b
# count= 10, result= 3
# ** Error: Assertion error.
# Time: 200 ns Started: 140 ns Scope: asn.a1 File: asn.sv Line: 18 Expr: b
============================================================
module asn_auto;
static int result, count=0;
logic a=1, b=1, clk=1;
initial forever #10 clk=!clk;
a1: assert property (@(posedge clk)a |-> ##3 b) begin
automatic int x=0; x +=1; result = x;
end
always @(posedge clk) begin
count+=1;
if(count>=6) begin
b<=0;
$display("count=%d, result=%d", count, result);
end
end
endmodule : asn_auto
# count= 6, result= 1
# count= 7, result= 1
# ** Error: Assertion error.
# Time: 140 ns Started: 80 ns Scope: asn_auto.a1 File: asn_auto.sv Line: 18 Expr: b
# count= 8, result= 1
# ** Error: Assertion error.
# Time: 160 ns Started: 100 ns Scope: asn_auto.a1 File: asn_auto.sv Line: 18 Expr: b
# count= 9, result= 1
# ** Error: Assertion error.
# Time: 180 ns Started: 120 ns Scope: asn_auto.a1 File: asn_auto.sv Line: 18 Expr: b
# count= 10, result= 1
# ** Error: Assertion error.
# Time: 200 ns Started: 140 ns Scope: asn_auto.a1 File: asn_auto.sv Line: 18 Expr: b
==================================
module asn_2;
static int result, count=0, path_result;
logic a=1, b=1, clk=1;
initial forever #10 clk=!clk;
a1: assert property (@(posedge clk)a |-> ##3 b) begin
static int x=0; x +=1; result = x;
end
always @(posedge clk) begin
count+=1;
path_result <= a1.x +1; // line 23
if(count>=6) begin
b<=0;
$display("count=%d, result=%d", count, result);
$display("path_result=%d", path_result);
end
end
endmodule
** Error: asn_2.sv(23): Unresolved reference to 'x'.
-- This message has been scanned for viruses and dangerous content by MailScanner <http://www.mailscanner.info/> , and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Tue Jul 19 12:32:14 2011
This archive was generated by hypermail 2.1.8 : Tue Jul 19 2011 - 12:32:19 PDT