diff options
author | Tristan Gingold <tgingold@free.fr> | 2016-10-04 20:48:53 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2016-10-04 20:48:53 +0200 |
commit | 05bdcc96e259b338328812f4b3c4fb68f3c13f3c (patch) | |
tree | 0186f64c99f067600322f1338be16e1ff5f95057 /src/vhdl/translate | |
parent | deac06f0a1aee47a6c4504e2a439842584066b84 (diff) | |
download | ghdl-05bdcc96e259b338328812f4b3c4fb68f3c13f3c.tar.gz ghdl-05bdcc96e259b338328812f4b3c4fb68f3c13f3c.tar.bz2 ghdl-05bdcc96e259b338328812f4b3c4fb68f3c13f3c.zip |
Fix attribute specification with non-static expression
Diffstat (limited to 'src/vhdl/translate')
-rw-r--r-- | src/vhdl/translate/trans-chap5.adb | 41 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap6.adb | 17 |
2 files changed, 46 insertions, 12 deletions
diff --git a/src/vhdl/translate/trans-chap5.adb b/src/vhdl/translate/trans-chap5.adb index f6a11be0f..7572032af 100644 --- a/src/vhdl/translate/trans-chap5.adb +++ b/src/vhdl/translate/trans-chap5.adb @@ -47,12 +47,15 @@ package body Trans.Chap5 is procedure Translate_Attribute_Specification (Spec : Iir_Attribute_Specification) is - Spec_Type : constant Iir := Get_Type (Spec); + Spec_Expr : constant Iir := Get_Expression (Spec); + Spec_Type : constant Iir := Get_Type (Spec_Expr); 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; begin Push_Identifier_Prefix_Uniq (Mark); if Is_Anonymous_Type_Definition (Spec_Type) then @@ -60,19 +63,39 @@ package body Trans.Chap5 is Chap3.Translate_Type_Definition (Spec_Type, True); Pop_Identifier_Prefix (Mark2); end if; - Info := Add_Info (Spec, Kind_Object); - Info.Object_Var := Create_Var - (Create_Var_Identifier (Attr), - Chap4.Get_Object_Type (Get_Info (Spec_Type), Mode_Value), - Global_Storage); + + Num := 1; + 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); + + -- Create only one object if the expression is static. + exit when Get_Expr_Staticness (Spec_Expr) /= None; + + Val := Get_Spec_Chain (Val); + Num := Num + 1; + end loop; Pop_Identifier_Prefix (Mark); end Translate_Attribute_Specification; procedure Elab_Attribute_Specification - (Spec : Iir_Attribute_Specification) is + (Spec : Iir_Attribute_Specification) + is + Expr : constant Iir := Get_Expression (Spec); + Val : Iir; begin - Chap3.Elab_Object_Subtype (Get_Type (Spec)); - Chap4.Elab_Object_Value (Spec, Get_Expression (Spec)); + Chap3.Elab_Object_Subtype (Get_Type (Expr)); + + Val := Get_Attribute_Value_Spec_Chain (Spec); + while Is_Valid (Val) loop + Chap4.Elab_Object_Value (Val, Expr); + exit when Get_Expr_Staticness (Expr) /= None; + Val := Get_Spec_Chain (Val); + end loop; end Elab_Attribute_Specification; procedure Gen_Elab_Disconnect_Non_Composite (Targ : Mnode; diff --git a/src/vhdl/translate/trans-chap6.adb b/src/vhdl/translate/trans-chap6.adb index 51c1a4568..e9f2987dd 100644 --- a/src/vhdl/translate/trans-chap6.adb +++ b/src/vhdl/translate/trans-chap6.adb @@ -920,9 +920,20 @@ package body Trans.Chap6 is return Translate_Name (Get_Named_Entity (Name), Mode); when Iir_Kind_Attribute_Value => pragma Assert (Mode = Mode_Value); - return Get_Var - (Get_Info (Get_Attribute_Specification (Name)).Object_Var, - Type_Info, Mode_Value); + declare + Attr : constant Iir := Get_Attribute_Specification (Name); + Val : Iir; + begin + if Get_Expr_Staticness (Get_Expression (Attr)) = None then + Val := Name; + else + -- If the expression is static, an object is created only + -- for the first value. + Val := Get_Attribute_Value_Spec_Chain (Attr); + end if; + return Get_Var (Get_Info (Val).Object_Var, + Type_Info, Mode_Value); + end; when Iir_Kind_Object_Alias_Declaration => -- Alias_Var is not like an object variable, since it is |