From 07a7f419eea89b3ab901642291650f49dfb24a36 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 8 Dec 2020 06:23:21 +0100 Subject: vhdl: handle locally static attributes on entity/architecture/configurations Attributes of entity/architecture/configurations are expected to be locally static so that they can be referenced from outside (so on the non-instantiated entity). But many designs break this assumption. In relaxed mode, non-locally static attributes are allowed but now cannot be referenced outside the entity. Locally static attributes can be referenced from outside. Fix #1528 --- src/vhdl/translate/trans-chap5.adb | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/vhdl/translate/trans-chap5.adb') diff --git a/src/vhdl/translate/trans-chap5.adb b/src/vhdl/translate/trans-chap5.adb index 990392dea..60c44b208 100644 --- a/src/vhdl/translate/trans-chap5.adb +++ b/src/vhdl/translate/trans-chap5.adb @@ -61,13 +61,14 @@ package body Trans.Chap5 is is Spec_Expr : constant Iir := Get_Expression (Spec); Spec_Type : constant Iir := Get_Type (Spec_Expr); - Attr : constant Iir_Attribute_Declaration := + Attr : constant Iir_Attribute_Declaration := Get_Named_Entity (Get_Attribute_Designator (Spec)); - Mark : Id_Mark_Type; - Mark2 : Id_Mark_Type; - Info : Object_Info_Acc; - Val : Iir; - Num : Natural; + Mark : Id_Mark_Type; + Mark2 : Id_Mark_Type; + Info : Object_Info_Acc; + Val : Iir; + Num : Natural; + Vtype : O_Tnode; begin Push_Identifier_Prefix_Uniq (Mark); if Is_Anonymous_Type_Definition (Spec_Type) then @@ -80,10 +81,19 @@ package body Trans.Chap5 is Val := Get_Attribute_Value_Spec_Chain (Spec); while Is_Valid (Val) loop Info := Add_Info (Val, Kind_Object); - Info.Object_Var := Create_Var - (Create_Var_Identifier (Attr, "V", Num), - Chap4.Get_Object_Type (Get_Info (Spec_Type), Mode_Value), - Global_Storage); + Vtype := Chap4.Get_Object_Type (Get_Info (Spec_Type), Mode_Value); + if Get_Static_Attribute_Flag (Spec) + and then Get_Expr_Staticness (Spec_Expr) = Locally + then + -- Create a global var so that the attribute can be referenced + -- from outside. This is possible only if the attribute is + -- locally static. + Info.Object_Var := Create_Global_Var + (Create_Identifier (Attr, "V"), Vtype, Global_Storage); + else + Info.Object_Var := Create_Var + (Create_Var_Identifier (Attr, "V", Num), Vtype, Global_Storage); + end if; -- Create only one object if the expression is static. exit when Get_Expr_Staticness (Spec_Expr) /= None; -- cgit v1.2.3