diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-08-17 02:28:54 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-08-17 02:28:54 +0200 |
commit | e57ba3e335d1f3692805f46d7d9cba49ffea4219 (patch) | |
tree | 6cfbe15ad39389ea98c98ffdd14c442119f8c587 /src | |
parent | a1f5a8797f36e68a3ca61568a25db67e29fda613 (diff) | |
download | ghdl-e57ba3e335d1f3692805f46d7d9cba49ffea4219.tar.gz ghdl-e57ba3e335d1f3692805f46d7d9cba49ffea4219.tar.bz2 ghdl-e57ba3e335d1f3692805f46d7d9cba49ffea4219.zip |
simul: create terminals (WIP)
Diffstat (limited to 'src')
-rw-r--r-- | src/simul/simul-vhdl_elab.adb | 3 | ||||
-rw-r--r-- | src/simul/simul-vhdl_elab.ads | 10 | ||||
-rw-r--r-- | src/simul/simul-vhdl_simul.adb | 55 | ||||
-rw-r--r-- | src/simul/simul-vhdl_simul.ads | 2 |
4 files changed, 62 insertions, 8 deletions
diff --git a/src/simul/simul-vhdl_elab.adb b/src/simul/simul-vhdl_elab.adb index f3ca2ff87..884d83c28 100644 --- a/src/simul/simul-vhdl_elab.adb +++ b/src/simul/simul-vhdl_elab.adb @@ -102,7 +102,8 @@ package body Simul.Vhdl_Elab is Across_Typ := Get_Subtype_Object (Inst, Get_Across_Type (Def)); Through_Typ := Get_Subtype_Object (Inst, Get_Through_Type (Def)); pragma Assert (Val.Val.T = No_Terminal_Index); - Terminal_Table.Append ((Decl, Inst, Across_Typ, Through_Typ, null)); + Terminal_Table.Append ((Decl, Inst, Across_Typ, Through_Typ, null, + No_Scalar_Quantity, No_Scalar_Terminal)); Val.Val.T := Terminal_Table.Last; end Gather_Terminal; diff --git a/src/simul/simul-vhdl_elab.ads b/src/simul/simul-vhdl_elab.ads index 795df7245..ed58ca0d6 100644 --- a/src/simul/simul-vhdl_elab.ads +++ b/src/simul/simul-vhdl_elab.ads @@ -190,6 +190,8 @@ package Simul.Vhdl_Elab is Val : Memory_Ptr; -- Index in the scalar table. Idx : Scalar_Quantity_Index; + -- For across quantity, we need the terminals to compute the value + -- For a through quantity, we need the terminals to compute the contrib end record; package Quantity_Table is new Tables @@ -198,12 +200,20 @@ package Simul.Vhdl_Elab is Table_Low_Bound => No_Quantity_Index + 1, Table_Initial => 128); + type Scalar_Terminal_Index is new Uns32; + No_Scalar_Terminal : constant Scalar_Terminal_Index := 0; + type Terminal_Entry is record Decl : Iir; Inst : Synth_Instance_Acc; Across_Typ : Type_Acc; Through_Typ : Type_Acc; + -- The reference value. Ref_Val : Memory_Ptr; + -- Index in the scalar quantity table for the reference value. + Ref_Idx : Scalar_Quantity_Index; + -- Index in the scalar terminal table for the contribution. + Term_Idx : Scalar_Terminal_Index; end record; package Terminal_Table is new Tables diff --git a/src/simul/simul-vhdl_simul.adb b/src/simul/simul-vhdl_simul.adb index 5ae5a8c1b..b4f480c0c 100644 --- a/src/simul/simul-vhdl_simul.adb +++ b/src/simul/simul-vhdl_simul.adb @@ -1584,15 +1584,44 @@ package body Simul.Vhdl_Simul is end loop; end Create_Signals; + procedure Create_Terminals + is + begin + for I in Terminal_Table.First .. Terminal_Table.Last loop + declare + T : Terminal_Entry renames Terminal_Table.Table (I); + begin + -- Allocate Ref_Val and set it to 0. + pragma Assert (T.Across_Typ.Kind = Type_Float); + T.Ref_Val := Alloc_Memory (T.Across_Typ); + Write_Fp64 (T.Ref_Val, 0.0); + + if not Get_Reference_Terminal_Flag (T.Decl) then + -- A non-ground reference. + -- Allocate the reference quantity. + T.Ref_Idx := Scalar_Quantities_Table.Last + 1; + Scalar_Quantities_Table.Append + ((Idx => Nbr_Solver_Variables, + Deriv => No_Scalar_Quantity, + Integ => No_Scalar_Quantity)); + + Nbr_Solver_Variables := + Nbr_Solver_Variables + Natural (T.Across_Typ.W); + end if; + end; + end loop; + end Create_Terminals; + -- Compute solver variables, allocate memory for quantities. procedure Create_Quantities is use Grt.Analog_Solver; Num : Natural; + Idx : Integer; Vec : F64_C_Arr_Ptr; begin -- Compute number of scalar quantities. - Num := 0; + Num := Nbr_Solver_Variables; for I in Quantity_Table.First .. Quantity_Table.Last loop declare Q : Quantity_Entry renames Quantity_Table.Table (I); @@ -1600,18 +1629,22 @@ package body Simul.Vhdl_Simul is Pfx_Info : Target_Info; begin case Get_Kind (Q.Decl) is - when Iir_Kind_Free_Quantity_Declaration => + when Iir_Kind_Free_Quantity_Declaration + | Iir_Kind_Through_Quantity_Declaration => -- For a free or branch quantity: -- * if it is the actual of a OUT formal, then use the -- variable from the formal. -- TODO: handle OUT associations. pragma Assert (Q.Typ.Kind = Type_Float); -- TODO + + Idx := Num; + Num := Num + Natural (Q.Typ.W); + Q.Idx := Scalar_Quantities_Table.Last + 1; Scalar_Quantities_Table.Append - ((Idx => Num, + ((Idx => Idx, Deriv => No_Scalar_Quantity, Integ => No_Scalar_Quantity)); - Num := Num + Natural (Q.Typ.W); Def := Get_Default_Value (Q.Decl); if Def /= Null_Node then @@ -1621,6 +1654,12 @@ package body Simul.Vhdl_Simul is Q.Val := Alloc_Memory (Q.Typ); Write_Fp64 (Q.Val, 0.0); + -- TODO: + -- For through quantities, add contribution to terminals. + + when Iir_Kind_Across_Quantity_Declaration => + null; + when Iir_Kind_Dot_Attribute => Pfx_Info := Synth_Target (Q.Inst, Get_Prefix (Q.Decl)); pragma Assert (Pfx_Info.Kind = Target_Simple); @@ -1692,10 +1731,13 @@ package body Simul.Vhdl_Simul is for I in Quantity_Table.First .. Quantity_Table.Last loop declare Q : Quantity_Entry renames Quantity_Table.Table (I); + Idx : Integer; begin pragma Assert (Q.Typ.Kind = Type_Float); -- TODO - Vec (Scalar_Quantities_Table.Table (Q.Idx).Idx) := - Ghdl_F64 (Read_Fp64 (Q.Val)); + Idx := Scalar_Quantities_Table.Table (Q.Idx).Idx; + if Idx >= 0 then + Vec (Idx) := Ghdl_F64 (Read_Fp64 (Q.Val)); + end if; end; end loop; end Create_Quantities; @@ -1890,6 +1932,7 @@ package body Simul.Vhdl_Simul is -- Create_Disconnections; Create_Processes; -- Create_PSL; + Create_Terminals; Create_Quantities; -- Allow Synth_Expression to handle signals. diff --git a/src/simul/simul-vhdl_simul.ads b/src/simul/simul-vhdl_simul.ads index 5a24f6dc1..5e837d454 100644 --- a/src/simul/simul-vhdl_simul.ads +++ b/src/simul/simul-vhdl_simul.ads @@ -81,7 +81,7 @@ package Simul.Vhdl_Simul is type Scalar_Quantity_Record is record -- Index in Y or Yp vector. - Idx : Natural; + Idx : Integer; -- If there is a 'Dot, the corresponding entry. Deriv : Scalar_Quantity_Index; -- If there is a 'Integ, the corresponding entry. |