diff options
-rw-r--r-- | src/synth/synth-expr.adb | 77 | ||||
-rw-r--r-- | src/synth/synth-stmts.adb | 25 | ||||
-rw-r--r-- | src/synth/synth-stmts.ads | 5 | ||||
-rw-r--r-- | src/synth/synth-values.adb | 27 | ||||
-rw-r--r-- | src/synth/synth-values.ads | 7 |
5 files changed, 115 insertions, 26 deletions
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index 498c2e6f0..e2f7b09a9 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -27,10 +27,13 @@ with Vhdl.Std_Package; with Vhdl.Errors; use Vhdl.Errors; with Vhdl.Utils; use Vhdl.Utils; with Vhdl.Evaluation; use Vhdl.Evaluation; + +with Areapools; with Simul.Annotations; use Simul.Annotations; with Synth.Errors; use Synth.Errors; with Synth.Types; use Synth.Types; +with Synth.Stmts; with Netlists; use Netlists; with Netlists.Gates; use Netlists.Gates; @@ -663,6 +666,7 @@ package body Synth.Expr is | Iir_Predefined_Ieee_1164_Scalar_Xor => return Synth_Bit_Dyadic (Id_Xor); when Iir_Predefined_Bit_Or + | Iir_Predefined_Boolean_Or | Iir_Predefined_Ieee_1164_Scalar_Or => return Synth_Bit_Dyadic (Id_Or); when Iir_Predefined_Ieee_1164_Vector_And => @@ -1125,6 +1129,75 @@ package body Synth.Expr is return Res; end Synth_String_Literal; + function Eval_To_Unsigned (Arg : Int64; Sz : Int64) return Value_Acc + is + Len : constant Iir_Index32 := Iir_Index32 (Sz); + Arr : Value_Array_Acc; + Bnds : Value_Bound_Array_Acc; + begin + Arr := Create_Value_Array (Len); + for I in 1 .. Len loop + Arr.V (Len - I + 1) := Create_Value_Discrete + ((Arg / 2 ** Natural (I - 1)) mod 2); + end loop; + Bnds := Create_Value_Bound_Array (1); + Bnds.D (1) := Create_Value_Bound + ((Dir => Iir_Downto, Left => Int32 (Len - 1), Right => 0, + Len => Uns32 (Len))); + return Create_Value_Array (Bnds, Arr); + end Eval_To_Unsigned; + + function Synth_Predefined_Function_Call + (Syn_Inst : Synth_Instance_Acc; Expr : Node) return Value_Acc + is + Imp : constant Node := Get_Implementation (Expr); + Def : constant Iir_Predefined_Functions := + Get_Implicit_Definition (Imp); + Assoc_Chain : constant Node := Get_Parameter_Association_Chain (Expr); + Inter_Chain : constant Node := Get_Interface_Declaration_Chain (Imp); + Subprg_Inst : Synth_Instance_Acc; + M : Areapools.Mark_Type; + begin + Areapools.Mark (M, Instance_Pool.all); + Subprg_Inst := Make_Instance (Syn_Inst, Get_Info (Imp)); + + Stmts.Synth_Subprogram_Association + (Subprg_Inst, Syn_Inst, Inter_Chain, Assoc_Chain); + + case Def is + when Iir_Predefined_Ieee_Numeric_Std_Touns_Nat_Nat_Uns => + declare + Arg : constant Value_Acc := Subprg_Inst.Objects (1); + Size : constant Value_Acc := Subprg_Inst.Objects (2); + Arg_Net : Net; + begin + if not Is_Const (Size) then + Error_Msg_Synth (+Expr, "to_unsigned size must be constant"); + return Arg; + else + -- FIXME: what if the arg is constant too ? + if Is_Const (Arg) then + return Eval_To_Unsigned (Arg.Scal, Size.Scal); + else + Arg_Net := Get_Net (Arg, Get_Type (Inter_Chain)); + return Create_Value_Net + (Synth_Uresize (Arg_Net, Uns32 (Size.Scal)), + Create_Res_Bound (Arg, Arg_Net)); + end if; + end if; + end; + when others => + Error_Msg_Synth + (+Expr, + "unhandled function: " & Iir_Predefined_Functions'Image (Def)); + end case; + + Free_Instance (Subprg_Inst); + Areapools.Release (M, Instance_Pool.all); + + return null; + end Synth_Predefined_Function_Call; + function Synth_Expression_With_Type (Syn_Inst : Synth_Instance_Acc; Expr : Node; Expr_Type : Node) return Value_Acc is @@ -1218,9 +1291,7 @@ package body Synth.Expr is Edge := Build_Edge (Build_Context, Clk); return Create_Value_Net (Edge, No_Bound); elsif Get_Implicit_Definition (Imp) /= Iir_Predefined_None then - Error_Msg_Synth - (+Expr, "predefined function call to %i is not handled", - +Imp); + return Synth_Predefined_Function_Call (Syn_Inst, Expr); else Error_Msg_Synth (+Expr, "user function call to %i is not handled", +Imp); diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb index 306441e6f..934584566 100644 --- a/src/synth/synth-stmts.adb +++ b/src/synth/synth-stmts.adb @@ -702,26 +702,23 @@ package body Synth.Stmts is raise Internal_Error; end case; + case Iir_Parameter_Modes (Get_Mode (Inter)) is + when Iir_In_Mode => + Val := Synth_Expression_With_Type + (Caller_Inst, Actual, Get_Type (Inter)); + when Iir_Out_Mode | Iir_Inout_Mode => + -- FIXME: todo + raise Internal_Error; + end case; + case Iir_Kinds_Interface_Object_Declaration (Get_Kind (Inter)) is when Iir_Kind_Interface_Constant_Declaration | Iir_Kind_Interface_Variable_Declaration => -- FIXME: Arguments are passed by copy. - Create_Object (Subprg_Inst, Inter, null); + Create_Object (Subprg_Inst, Inter, Val); when Iir_Kind_Interface_Signal_Declaration => - Create_Object (Subprg_Inst, Inter, null); - when Iir_Kind_Interface_File_Declaration => - raise Internal_Error; - end case; - - case Iir_Parameter_Modes (Get_Mode (Inter)) is - when Iir_In_Mode => - Val := Synth_Expression_With_Type - (Caller_Inst, Actual, Get_Type (Inter)); Create_Object (Subprg_Inst, Inter, Val); - when Iir_Out_Mode => - Synth_Declaration (Subprg_Inst, Inter); - when Iir_Inout_Mode => - -- FIXME: todo + when Iir_Kind_Interface_File_Declaration => raise Internal_Error; end case; diff --git a/src/synth/synth-stmts.ads b/src/synth/synth-stmts.ads index 5b8b0d9a3..102d63c7d 100644 --- a/src/synth/synth-stmts.ads +++ b/src/synth/synth-stmts.ads @@ -22,6 +22,11 @@ with Vhdl.Nodes; use Vhdl.Nodes; with Synth.Context; use Synth.Context; package Synth.Stmts is + procedure Synth_Subprogram_Association (Subprg_Inst : Synth_Instance_Acc; + Caller_Inst : Synth_Instance_Acc; + Inter_Chain : Node; + Assoc_Chain : Node); + -- Generate netlists for concurrent statements STMTS. procedure Synth_Concurrent_Statements (Syn_Inst : Synth_Instance_Acc; Stmts : Node); diff --git a/src/synth/synth-values.adb b/src/synth/synth-values.adb index 902bc0b9b..c603bdf1c 100644 --- a/src/synth/synth-values.adb +++ b/src/synth/synth-values.adb @@ -92,10 +92,10 @@ package body Synth.Values is (Kind => Value_Float, Fp => Val))); end Create_Value_Float; - function Create_Value_Array (Ndim : Iir_Index32) return Value_Array_Acc + function Create_Value_Array (Len : Iir_Index32) return Value_Array_Acc is use System; - subtype Data_Type is Values.Value_Array_Type (Ndim); + subtype Data_Type is Values.Value_Array_Type (Len); Res : Address; begin -- Manually allocate the array to handle large arrays without @@ -119,6 +119,21 @@ package body Synth.Values is return To_Value_Array_Acc (Res); end Create_Value_Array; + function Create_Value_Array (Bounds : Value_Bound_Array_Acc; + Arr : Value_Array_Acc) + return Value_Acc + is + subtype Value_Type_Array is Value_Type (Value_Array); + function Alloc is new Areapools.Alloc_On_Pool_Addr (Value_Type_Array); + + Res : Value_Acc; + begin + Res := To_Value_Acc (Alloc (Current_Pool, + (Kind => Value_Array, + Arr => Arr, Bounds => Bounds))); + return Res; + end Create_Value_Array; + procedure Create_Array_Data (Arr : Value_Acc) is Len : Width; @@ -131,17 +146,13 @@ package body Synth.Values is Arr.Arr := Create_Value_Array (Iir_Index32 (Len)); end Create_Array_Data; + function Create_Value_Array (Bounds : Value_Bound_Array_Acc) return Value_Acc is - subtype Value_Type_Array is Value_Type (Value_Array); - function Alloc is new Areapools.Alloc_On_Pool_Addr (Value_Type_Array); - Res : Value_Acc; begin - Res := To_Value_Acc (Alloc (Current_Pool, - (Kind => Value_Array, - Arr => null, Bounds => Bounds))); + Res := Create_Value_Array (Bounds, null); Create_Array_Data (Res); return Res; end Create_Value_Array; diff --git a/src/synth/synth-values.ads b/src/synth/synth-values.ads index 283443ffe..d60484c25 100644 --- a/src/synth/synth-values.ads +++ b/src/synth/synth-values.ads @@ -176,11 +176,16 @@ package Synth.Values is function Create_Value_Float (Val : Fp64) return Value_Acc; - function Create_Value_Array (Ndim : Iir_Index32) return Value_Array_Acc; + function Create_Value_Array (Len : Iir_Index32) return Value_Array_Acc; function Create_Value_Bound_Array (Ndim : Iir_Index32) return Value_Bound_Array_Acc; -- Create a Value_Array. + function Create_Value_Array (Bounds : Value_Bound_Array_Acc; + Arr : Value_Array_Acc) + return Value_Acc; + + -- Like the previous one but automatically build the array. function Create_Value_Array (Bounds : Value_Bound_Array_Acc) return Value_Acc; |