aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-01-29 09:13:27 +0100
committerTristan Gingold <tgingold@free.fr>2023-01-29 09:13:27 +0100
commitf84ffd4a37781bcfa7eab0d1b359dce178924425 (patch)
tree156821eac041594039d259d63c560e0c263632fb /src
parent5e6b4c599933724be5a88d468502ae2d963e5ada (diff)
downloadghdl-f84ffd4a37781bcfa7eab0d1b359dce178924425.tar.gz
ghdl-f84ffd4a37781bcfa7eab0d1b359dce178924425.tar.bz2
ghdl-f84ffd4a37781bcfa7eab0d1b359dce178924425.zip
vhdl: add Is_Owned_Subtype_Indication
Diffstat (limited to 'src')
-rw-r--r--src/synth/elab-vhdl_annotations.adb31
-rw-r--r--src/vhdl/vhdl-utils.adb29
-rw-r--r--src/vhdl/vhdl-utils.ads4
3 files changed, 43 insertions, 21 deletions
diff --git a/src/synth/elab-vhdl_annotations.adb b/src/synth/elab-vhdl_annotations.adb
index 8274d9ea8..019289e87 100644
--- a/src/synth/elab-vhdl_annotations.adb
+++ b/src/synth/elab-vhdl_annotations.adb
@@ -292,7 +292,6 @@ package body Elab.Vhdl_Annotations is
(Block_Info: Sim_Info_Acc; Decl_Chain: Iir)
is
El: Iir;
- Ind : Iir;
begin
El := Decl_Chain;
while El /= Null_Iir loop
@@ -301,21 +300,11 @@ package body Elab.Vhdl_Annotations is
| Iir_Kind_Interface_Variable_Declaration
| Iir_Kind_Interface_Constant_Declaration
| Iir_Kind_Interface_File_Declaration =>
- Ind := Get_Subtype_Indication (El);
- if Ind /= Null_Iir and then not Get_Is_Ref (El) then
- case Get_Kind (Ind) is
- when Iir_Kinds_Subtype_Definition =>
- Annotate_Type_Definition (Block_Info, Ind);
- when Iir_Kinds_Denoting_Name
- | Iir_Kind_Element_Attribute
- | Iir_Kind_Subtype_Attribute =>
- null;
- when others =>
- Error_Kind ("annotate_interface_list_subtype(1)", Ind);
- end case;
+ -- Elaborate the subtype indication only if it not shared.
+ if Is_Owned_Subtype_Indication (El) then
+ Annotate_Type_Definition
+ (Block_Info, Get_Subtype_Indication (El));
end if;
- -- Annotate_Anonymous_Type_Definition
- -- (Block_Info, Get_Type (El));
when others =>
Error_Kind ("annotate_interface_list_subtype", El);
end case;
@@ -348,18 +337,18 @@ package body Elab.Vhdl_Annotations is
procedure Annotate_Interface_Declaration
(Block_Info : Sim_Info_Acc; Decl : Iir; With_Types : Boolean) is
begin
- if With_Types
- and then Get_Kind (Decl) in Iir_Kinds_Interface_Object_Declaration
- and then not Get_Is_Ref (Decl)
- then
- Annotate_Anonymous_Type_Definition (Block_Info, Get_Type (Decl));
- end if;
case Get_Kind (Decl) is
when Iir_Kind_Interface_Signal_Declaration =>
+ if With_Types and then Is_Owned_Subtype_Indication (Decl) then
+ Annotate_Type_Definition (Block_Info, Get_Type (Decl));
+ end if;
Create_Signal_Info (Block_Info, Decl);
when Iir_Kind_Interface_Variable_Declaration
| Iir_Kind_Interface_Constant_Declaration
| Iir_Kind_Interface_File_Declaration =>
+ if With_Types and then Is_Owned_Subtype_Indication (Decl) then
+ Annotate_Type_Definition (Block_Info, Get_Type (Decl));
+ end if;
Create_Object_Info (Block_Info, Decl);
when Iir_Kind_Interface_Package_Declaration =>
Annotate_Interface_Package_Declaration (Block_Info, Decl);
diff --git a/src/vhdl/vhdl-utils.adb b/src/vhdl/vhdl-utils.adb
index 6bd200cc3..e3e04cfe8 100644
--- a/src/vhdl/vhdl-utils.adb
+++ b/src/vhdl/vhdl-utils.adb
@@ -1323,6 +1323,35 @@ package body Vhdl.Utils is
end case;
end Get_Nature_Of_Subnature_Indication;
+ function Is_Owned_Subtype_Indication (Decl : Iir) return Boolean
+ is
+ Def : Iir;
+ begin
+ -- Subtype indication is shared with a previous declaration, like in:
+ -- signal a, b : std_logic_vector (7 downto 0);
+ if Get_Is_Ref (Decl) then
+ return False;
+ end if;
+
+ Def := Get_Subtype_Indication (Decl);
+ -- Implicit functions don't have subtype indication.
+ -- TODO: make them regular ?
+ if Def = Null_Iir then
+ return False;
+ end if;
+
+ case Get_Kind (Def) is
+ when Iir_Kinds_Subtype_Definition =>
+ return True;
+ when Iir_Kinds_Denoting_Name
+ | Iir_Kind_Element_Attribute
+ | Iir_Kind_Subtype_Attribute =>
+ return False;
+ when others =>
+ Error_Kind ("is_owned_subtype_indication", Def);
+ end case;
+ end Is_Owned_Subtype_Indication;
+
function Get_Index_Type (Indexes : Iir_Flist; Idx : Natural) return Iir
is
Index : constant Iir := Get_Nth_Element (Indexes, Idx);
diff --git a/src/vhdl/vhdl-utils.ads b/src/vhdl/vhdl-utils.ads
index 8cce0eb14..5cdef0daa 100644
--- a/src/vhdl/vhdl-utils.ads
+++ b/src/vhdl/vhdl-utils.ads
@@ -258,6 +258,10 @@ package Vhdl.Utils is
-- skip over denoting names.
function Get_Type_Of_Subtype_Indication (Ind : Iir) return Iir;
+ -- Return True iff the subtype indication of DECL is defined/owned by
+ -- DECL.
+ function Is_Owned_Subtype_Indication (Decl : Iir) return Boolean;
+
-- Get the type of an index_subtype_definition or of a discrete_range from
-- an index_constraint.
function Get_Index_Type (Index_Type : Iir) return Iir