diff options
author | Tristan Gingold | 2015-05-11 21:03:45 +0200 |
---|---|---|
committer | Tristan Gingold | 2015-05-11 21:03:45 +0200 |
commit | f94b64e892c4c5b7cc9b3661a0de0a358e79093c (patch) | |
tree | 98df9f9fd235536855c5474625fee57aff16c7f0 /src/vhdl | |
parent | ae9bf87f0ecb5f8e43f8e1df4ce9fdb5a16bff8d (diff) | |
download | ghdl-f94b64e892c4c5b7cc9b3661a0de0a358e79093c.tar.gz ghdl-f94b64e892c4c5b7cc9b3661a0de0a358e79093c.tar.bz2 ghdl-f94b64e892c4c5b7cc9b3661a0de0a358e79093c.zip |
Allow generic without default values in top-level entity.
Implement ticket #47.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/configuration.adb | 47 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap1.adb | 19 |
2 files changed, 63 insertions, 3 deletions
diff --git a/src/vhdl/configuration.adb b/src/vhdl/configuration.adb index 9ca2793..37817da 100644 --- a/src/vhdl/configuration.adb +++ b/src/vhdl/configuration.adb @@ -595,6 +595,49 @@ package body Configuration is is Has_Error : Boolean := False; + -- Return TRUE if GRT supports override of generic GEN. + function Allow_Generic_Override (Gen : Iir) return Boolean + is + Gen_Type : constant Iir := Get_Type (Gen); + begin + case Get_Kind (Gen_Type) is + when Iir_Kind_Integer_Type_Definition + | Iir_Kind_Integer_Subtype_Definition + | Iir_Kind_Enumeration_Type_Definition + | Iir_Kind_Enumeration_Subtype_Definition => + return True; + when Iir_Kind_Array_Type_Definition + | Iir_Kind_Array_Subtype_Definition => + -- Only one-dimensional arrays of enumeration are allowed. + -- If unconstrained, the index must be of integer type. + if Get_Kind (Get_Base_Type (Get_Element_Subtype (Gen_Type))) + /= Iir_Kind_Enumeration_Type_Definition + then + -- Not an array of enumeration type. + return False; + end if; + declare + Indexes : constant Iir_List := + Get_Index_Subtype_List (Gen_Type); + begin + if Get_Nbr_Elements (Indexes) /= 1 then + -- Not a one-dimensional array. + return False; + end if; + if Get_Constraint_State (Gen_Type) /= Fully_Constrained + and then (Get_Kind (Get_Index_Type (Indexes, 0)) + /= Iir_Kind_Integer_Subtype_Definition) + then + -- Index not constrained or not of integer subtype. + return False; + end if; + end; + return True; + when others => + return False; + end case; + end Allow_Generic_Override; + procedure Error (Msg : String; Loc : Iir) is begin if not Has_Error then @@ -611,7 +654,9 @@ package body Configuration is El := Get_Generic_Chain (Entity); while El /= Null_Iir loop if Get_Default_Value (El) = Null_Iir then - Error ("(" & Disp_Node (El) & " has no default value)", El); + if not Allow_Generic_Override (El) then + Error ("(" & Disp_Node (El) & " has no default value)", El); + end if; end if; El := Get_Chain (El); end loop; diff --git a/src/vhdl/translate/trans-chap1.adb b/src/vhdl/translate/trans-chap1.adb index 8d60992..35cbfb0 100644 --- a/src/vhdl/translate/trans-chap1.adb +++ b/src/vhdl/translate/trans-chap1.adb @@ -41,14 +41,29 @@ package body Trans.Chap1 is procedure Translate_Entity_Init_Generics (Entity : Iir) is - El : Iir; + El : Iir; begin Push_Local_Factory; El := Get_Generic_Chain (Entity); while El /= Null_Iir loop Open_Temp; - Chap4.Elab_Object_Value (El, Get_Default_Value (El)); + + declare + Val : constant Iir := Get_Default_Value (El); + El_Type : constant Iir := Get_Type (El); + begin + if Val = Null_Iir + and then Get_Kind (El_Type) in Iir_Kinds_Array_Type_Definition + and then Get_Constraint_State (El_Type) /= Fully_Constrained + then + -- Do not initialize unconstrained array. They will have + -- to be overriden by user. + null; + else + Chap4.Elab_Object_Value (El, Val); + end if; + end; Close_Temp; El := Get_Chain (El); end loop; |