From da1c6b96c253aca9e794af3ded8bcc662215520a Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sat, 15 Oct 2016 07:05:17 +0200 Subject: nodes: remove Int and Fp formats, use multiple fields. --- src/vhdl/iirs.adb | 73 ++++++++++++++++++++++++++++++++++++---------------- src/vhdl/iirs.adb.in | 9 +------ src/vhdl/iirs.ads | 20 +++++++------- src/vhdl/nodes.adb | 31 +--------------------- src/vhdl/nodes.ads | 44 ++++++------------------------- src/xtools/pnodes.py | 3 ++- 6 files changed, 73 insertions(+), 107 deletions(-) (limited to 'src') diff --git a/src/vhdl/iirs.adb b/src/vhdl/iirs.adb index 53779d7a9..4db20bded 100644 --- a/src/vhdl/iirs.adb +++ b/src/vhdl/iirs.adb @@ -74,14 +74,7 @@ package body Iirs is Num (Kind) := Num (Kind) + 1; Format := Get_Format (Kind); Formats (Format) := Formats (Format) + 1; - case Format is - when Format_Medium => - I := I + 2; - when Format_Short - | Format_Fp - | Format_Int => - I := I + 1; - end case; + I := Next_Node (I); end loop; Put_Line ("Stats per iir_kind:"); @@ -260,8 +253,12 @@ package body Iirs is | Iir_Kind_Library_Clause | Iir_Kind_Use_Clause | Iir_Kind_Context_Reference + | Iir_Kind_Integer_Literal + | Iir_Kind_Floating_Point_Literal | Iir_Kind_Null_Literal | Iir_Kind_String_Literal8 + | Iir_Kind_Physical_Int_Literal + | Iir_Kind_Physical_Fp_Literal | Iir_Kind_Simple_Aggregate | Iir_Kind_Overflow_Literal | Iir_Kind_Waveform_Element @@ -517,12 +514,6 @@ package body Iirs is | Iir_Kind_Simple_Simultaneous_Statement | Iir_Kind_Wait_Statement => return Format_Medium; - when Iir_Kind_Floating_Point_Literal - | Iir_Kind_Physical_Fp_Literal => - return Format_Fp; - when Iir_Kind_Integer_Literal - | Iir_Kind_Physical_Int_Literal => - return Format_Int; end case; end Get_Format; @@ -904,20 +895,39 @@ package body Iirs is Set_Field12 (Design_Unit, Int32_To_Iir (Line)); end Set_Design_Unit_Source_Col; - function Get_Value (Lit : Iir) return Iir_Int64 is + type Iir_Int64_Conv is record + Field4: Iir; + Field5: Iir; + end record; + pragma Pack (Iir_Int64_Conv); + pragma Assert (Iir_Int64_Conv'Size = Iir_Int64'Size); + + function Get_Value (Lit : Iir) return Iir_Int64 + is + function To_Iir_Int64 is new Ada.Unchecked_Conversion + (Iir_Int64_Conv, Iir_Int64); + Conv : Iir_Int64_Conv; begin pragma Assert (Lit /= Null_Iir); pragma Assert (Has_Value (Get_Kind (Lit)), "no field Value"); - return Get_Int64 (Lit); + Conv.Field4 := Get_Field4 (Lit); + Conv.Field5 := Get_Field5 (Lit); + return To_Iir_Int64 (Conv); end Get_Value; - procedure Set_Value (Lit : Iir; Val : Iir_Int64) is + procedure Set_Value (Lit : Iir; Val : Iir_Int64) + is + function To_Iir_Int64_Conv is new Ada.Unchecked_Conversion + (Iir_Int64, Iir_Int64_Conv); + Conv : Iir_Int64_Conv; begin pragma Assert (Lit /= Null_Iir); pragma Assert (Has_Value (Get_Kind (Lit)), "no field Value"); - Set_Int64 (Lit, Val); + Conv := To_Iir_Int64_Conv (Val); + Set_Field4 (Lit, Conv.Field4); + Set_Field5 (Lit, Conv.Field5); end Set_Value; function Get_Enum_Pos (Lit : Iir) return Iir_Int32 is @@ -968,20 +978,39 @@ package body Iirs is Set_Field5 (Unit, Lit); end Set_Physical_Unit_Value; - function Get_Fp_Value (Lit : Iir) return Iir_Fp64 is + type Iir_Fp64_Conv is record + Field4: Iir; + Field5: Iir; + end record; + pragma Pack (Iir_Fp64_Conv); + pragma Assert (Iir_Fp64_Conv'Size = Iir_Fp64'Size); + + function Get_Fp_Value (Lit : Iir) return Iir_Fp64 + is + function To_Iir_Fp64 is new Ada.Unchecked_Conversion + (Iir_Fp64_Conv, Iir_Fp64); + Conv : Iir_Fp64_Conv; begin pragma Assert (Lit /= Null_Iir); pragma Assert (Has_Fp_Value (Get_Kind (Lit)), "no field Fp_Value"); - return Get_Fp64 (Lit); + Conv.Field4 := Get_Field4 (Lit); + Conv.Field5 := Get_Field5 (Lit); + return To_Iir_Fp64 (Conv); end Get_Fp_Value; - procedure Set_Fp_Value (Lit : Iir; Val : Iir_Fp64) is + procedure Set_Fp_Value (Lit : Iir; Val : Iir_Fp64) + is + function To_Iir_Fp64_Conv is new Ada.Unchecked_Conversion + (Iir_Fp64, Iir_Fp64_Conv); + Conv : Iir_Fp64_Conv; begin pragma Assert (Lit /= Null_Iir); pragma Assert (Has_Fp_Value (Get_Kind (Lit)), "no field Fp_Value"); - Set_Fp64 (Lit, Val); + Conv := To_Iir_Fp64_Conv (Val); + Set_Field4 (Lit, Conv.Field4); + Set_Field5 (Lit, Conv.Field5); end Set_Fp_Value; function Get_Simple_Aggregate_List (Target : Iir) return Iir_List is diff --git a/src/vhdl/iirs.adb.in b/src/vhdl/iirs.adb.in index a4b789570..7f04a1a15 100644 --- a/src/vhdl/iirs.adb.in +++ b/src/vhdl/iirs.adb.in @@ -74,14 +74,7 @@ package body Iirs is Num (Kind) := Num (Kind) + 1; Format := Get_Format (Kind); Formats (Format) := Formats (Format) + 1; - case Format is - when Format_Medium => - I := I + 2; - when Format_Short - | Format_Fp - | Format_Int => - I := I + 1; - end case; + I := Next_Node (I); end loop; Put_Line ("Stats per iir_kind:"); diff --git a/src/vhdl/iirs.ads b/src/vhdl/iirs.ads index 8a79629aa..56edca1b6 100644 --- a/src/vhdl/iirs.ads +++ b/src/vhdl/iirs.ads @@ -328,10 +328,10 @@ package Iirs is -- True if the integer specifying the length is present. -- Get/Set_Has_Length (Flag3) - -- Iir_Kind_Integer_Literal (Int) + -- Iir_Kind_Integer_Literal (Short) -- -- Get/Set the value of the integer. - -- Get/Set_Value (Int64) + -- Get/Set_Value (Field4,Field5) -- -- Get/Set_Literal_Origin (Field2) -- @@ -339,10 +339,10 @@ package Iirs is -- -- Get/Set_Expr_Staticness (State1) - -- Iir_Kind_Floating_Point_Literal (Fp) + -- Iir_Kind_Floating_Point_Literal (Short) -- -- The value of the literal. - -- Get/Set_Fp_Value (Fp64) + -- Get/Set_Fp_Value (Field4,Field5) -- -- Get/Set_Literal_Origin (Field2) -- @@ -357,8 +357,8 @@ package Iirs is -- -- Get/Set_Expr_Staticness (State1) - -- Iir_Kind_Physical_Int_Literal (Int) - -- Iir_Kind_Physical_Fp_Literal (Fp) + -- Iir_Kind_Physical_Int_Literal (Short) + -- Iir_Kind_Physical_Fp_Literal (Short) -- -- Get/Set_Literal_Origin (Field2) -- @@ -375,11 +375,11 @@ package Iirs is -- -- Only for Iir_Kind_Physical_Int_Literal: -- The multiplicand. - -- Get/Set_Value (Int64) + -- Get/Set_Value (Field4,Field5) -- -- Only for Iir_Kind_Physical_Fp_Literal: -- The multiplicand. - -- Get/Set_Fp_Value (Fp64) + -- Get/Set_Fp_Value (Field4,Field5) -- Iir_Kind_Simple_Aggregate (Short) -- This node can only be generated by evaluation: it is an unidimentional @@ -5718,7 +5718,7 @@ package Iirs is -- literals. -- Value of an integer/physical literal. - -- Field: Int64 + -- Field: Field4,Field5 (grp) function Get_Value (Lit : Iir) return Iir_Int64; procedure Set_Value (Lit : Iir; Val : Iir_Int64); @@ -5737,7 +5737,7 @@ package Iirs is procedure Set_Physical_Unit_Value (Unit : Iir; Lit : Iir); -- Value of a floating point literal. - -- Field: Fp64 + -- Field: Field4,Field5 (grp) function Get_Fp_Value (Lit : Iir) return Iir_Fp64; procedure Set_Fp_Value (Lit : Iir; Val : Iir_Fp64); diff --git a/src/vhdl/nodes.adb b/src/vhdl/nodes.adb index 71ec38512..c5a16f2fe 100644 --- a/src/vhdl/nodes.adb +++ b/src/vhdl/nodes.adb @@ -48,8 +48,6 @@ package body Nodes is pragma Warnings (Off); Init_Short : Node_Record (Format_Short); Init_Medium : Node_Record (Format_Medium); - Init_Fp : Node_Record (Format_Fp); - Init_Int : Node_Record (Format_Int); pragma Warnings (On); function Create_Node (Format : Format_Type) return Node_Type @@ -93,10 +91,6 @@ package body Nodes is others => False); when Format_Medium => raise Program_Error; - when Format_Fp => - Nodet.Table (Res) := Init_Fp; - when Format_Int => - Nodet.Table (Res) := Init_Int; end case; end if; return Res; @@ -121,9 +115,7 @@ package body Nodes is case Nodet.Table (N).Format is when Format_Medium => return N + 2; - when Format_Short - | Format_Int - | Format_Fp => + when Format_Short => return N + 1; end case; end Next_Node; @@ -473,27 +465,6 @@ package body Nodes is Nodet.Table (N + 1).State2 := V; end Set_State4; - function Get_Fp64 (N : Node_Type) return Iir_Fp64 is - begin - return Nodet.Table (N).Fp64; - end Get_Fp64; - - procedure Set_Fp64 (N : Node_Type; V : Iir_Fp64) is - begin - Nodet.Table (N).Fp64 := V; - end Set_Fp64; - - - function Get_Int64 (N : Node_Type) return Iir_Int64 is - begin - return Nodet.Table (N).Int64; - end Get_Int64; - - procedure Set_Int64 (N : Node_Type; V : Iir_Int64) is - begin - Nodet.Table (N).Int64 := V; - end Set_Int64; - procedure Initialize is begin Nodet.Free; diff --git a/src/vhdl/nodes.ads b/src/vhdl/nodes.ads index d32c86673..d9920736c 100644 --- a/src/vhdl/nodes.ads +++ b/src/vhdl/nodes.ads @@ -34,9 +34,7 @@ package Nodes is type Format_Type is ( Format_Short, - Format_Medium, - Format_Fp, - Format_Int + Format_Medium ); -- Common fields are: @@ -63,22 +61,14 @@ package Nodes is -- Field1 : Iir -- Field2 : Iir -- Field3 : Iir - - -- Fields of Format_Fp: - -- Fp64 : Iir_Fp64 - - -- Fields of Format_Int: - -- Int64 : Iir_Int64 - - -- Fields of Format_Short: -- Field4 : Iir -- Field5 : Iir + -- Fields of Format_Short: + -- Fields of Format_Medium: -- State3 : Bit2_Type -- State4 : Bit2_Type - -- Field4 : Iir - -- Field5 : Iir -- Field6 : Iir (location) -- Field7 : Iir (field0) -- Field8 : Iir (field1) @@ -264,16 +254,6 @@ package Nodes is procedure Set_State4 (N : Node_Type; V : Bit2_Type); pragma Inline (Set_State4); - function Get_Fp64 (N : Node_Type) return Iir_Fp64; - pragma Inline (Get_Fp64); - procedure Set_Fp64 (N : Node_Type; V : Iir_Fp64); - pragma Inline (Set_Fp64); - - function Get_Int64 (N : Node_Type) return Iir_Int64; - pragma Inline (Get_Int64); - procedure Set_Int64 (N : Node_Type; V : Iir_Int64); - pragma Inline (Set_Int64); - -- Get the last node allocated. function Get_Last_Node return Node_Type; pragma Inline (Get_Last_Node); @@ -289,9 +269,9 @@ private Flag4 : Boolean := False; Flag5 : Boolean := False; Flag6 : Boolean := False; + Flag7 : Boolean := False; -- Second byte: - Flag7 : Boolean := False; Flag8 : Boolean := False; Flag9 : Boolean := False; Flag10 : Boolean := False; @@ -299,11 +279,12 @@ private Flag12 : Boolean := False; Flag13 : Boolean := False; Flag14 : Boolean := False; + Flag15 : Boolean := False; -- Third byte: - Flag15 : Boolean := False; Flag16 : Boolean := False; Flag17 : Boolean := False; + Flag18 : Boolean := False; -- 2*2 = 4 bits State1 : Bit2_Type := 0; @@ -319,17 +300,8 @@ private Field1 : Node_Type := Null_Node; Field2 : Node_Type := Null_Node; Field3 : Node_Type := Null_Node; - - case Format is - when Format_Short - | Format_Medium => - Field4: Node_Type := Null_Node; - Field5: Node_Type := Null_Node; - when Format_Fp => - Fp64 : Iir_Fp64; - when Format_Int => - Int64 : Iir_Int64; - end case; + Field4 : Node_Type := Null_Node; + Field5 : Node_Type := Null_Node; end record; pragma Pack (Node_Record); diff --git a/src/xtools/pnodes.py b/src/xtools/pnodes.py index 243580de0..4b7e8a5f9 100755 --- a/src/xtools/pnodes.py +++ b/src/xtools/pnodes.py @@ -258,7 +258,8 @@ def read_kinds(filename): raise ParseError(lr, 'unknown conversion ' + conv) else: conv = None - + if len(fields) > 1 and conv != 'grp': + raise ParseError(lr, 'bad conversion for multiple fields') # Read function l = lr.get() mf = pat_func.match(l) -- cgit v1.2.3