diff options
author | Tristan Gingold <tgingold@free.fr> | 2023-01-11 06:00:15 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2023-01-11 06:00:15 +0100 |
commit | 57ae0c0644abeab372644b7d274a9fee3cea3499 (patch) | |
tree | 92b97ffe27db3f224aa37843dc30aa438f19d1c1 /src/synth | |
parent | f06d64e57d040cd851e2172f63609f77a5423d4f (diff) | |
download | ghdl-57ae0c0644abeab372644b7d274a9fee3cea3499.tar.gz ghdl-57ae0c0644abeab372644b7d274a9fee3cea3499.tar.bz2 ghdl-57ae0c0644abeab372644b7d274a9fee3cea3499.zip |
synth: check float ranges in subtype conversion
Diffstat (limited to 'src/synth')
-rw-r--r-- | src/synth/elab-vhdl_objtypes.adb | 10 | ||||
-rw-r--r-- | src/synth/elab-vhdl_objtypes.ads | 1 | ||||
-rw-r--r-- | src/synth/synth-vhdl_expr.adb | 16 |
3 files changed, 25 insertions, 2 deletions
diff --git a/src/synth/elab-vhdl_objtypes.adb b/src/synth/elab-vhdl_objtypes.adb index 1555c90d3..ebde9f28b 100644 --- a/src/synth/elab-vhdl_objtypes.adb +++ b/src/synth/elab-vhdl_objtypes.adb @@ -216,6 +216,16 @@ package body Elab.Vhdl_Objtypes is end case; end In_Range; + function In_Float_Range (Rng : Float_Range_Type; V : Fp64) return Boolean is + begin + case Rng.Dir is + when Dir_To => + return V >= Rng.Left and then V <= Rng.Right; + when Dir_Downto => + return V <= Rng.Left and then V >= Rng.Right; + end case; + end In_Float_Range; + function Build_Discrete_Range_Type (L : Int64; R : Int64; Dir : Direction_Type) return Discrete_Range_Type is begin diff --git a/src/synth/elab-vhdl_objtypes.ads b/src/synth/elab-vhdl_objtypes.ads index 99f8434e7..c46095a3d 100644 --- a/src/synth/elab-vhdl_objtypes.ads +++ b/src/synth/elab-vhdl_objtypes.ads @@ -283,6 +283,7 @@ package Elab.Vhdl_Objtypes is function In_Bounds (Bnd : Bound_Type; V : Int32) return Boolean; function In_Range (Rng : Discrete_Range_Type; V : Int64) return Boolean; + function In_Float_Range (Rng : Float_Range_Type; V : Fp64) return Boolean; -- Create an Type_Array from an Type_Array_Unbounded by replacing the -- element type. diff --git a/src/synth/synth-vhdl_expr.adb b/src/synth/synth-vhdl_expr.adb index f2c2aae82..884fe9e16 100644 --- a/src/synth/synth-vhdl_expr.adb +++ b/src/synth/synth-vhdl_expr.adb @@ -624,8 +624,20 @@ package body Synth.Vhdl_Expr is end case; when Type_Float => pragma Assert (Vtype.Kind = Type_Float); - -- TODO: check range - return Vt; + if Vt.Val.Kind = Value_Memory then + declare + Val : constant Fp64 := Read_Fp64 (Vt); + begin + if not In_Float_Range (Dtype.Frange, Val) then + Error_Msg_Synth (Syn_Inst, Loc, "value out of range"); + return No_Valtyp; + end if; + return Create_Value_Float (Val, Dtype); + end; + else + -- Is it possible ? Only const ? + return Vt; + end if; when Type_Vector => pragma Assert (Vtype.Kind = Type_Vector or Vtype.Kind = Type_Slice); |