diff options
author | Tristan Gingold <tgingold@free.fr> | 2023-03-27 19:12:02 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2023-03-27 19:12:02 +0200 |
commit | 5f105b010f4a2530ff52b9f62e4dc619e1225d01 (patch) | |
tree | f299d928db81e189204245265467670780778572 /src/synth/synth-vhdl_expr.adb | |
parent | 413db2f74665682693f899045feb4f5bdc108c03 (diff) | |
download | ghdl-5f105b010f4a2530ff52b9f62e4dc619e1225d01.tar.gz ghdl-5f105b010f4a2530ff52b9f62e4dc619e1225d01.tar.bz2 ghdl-5f105b010f4a2530ff52b9f62e4dc619e1225d01.zip |
synth: add checks for array conversion
Diffstat (limited to 'src/synth/synth-vhdl_expr.adb')
-rw-r--r-- | src/synth/synth-vhdl_expr.adb | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/synth/synth-vhdl_expr.adb b/src/synth/synth-vhdl_expr.adb index e5ffd933f..b5093cb02 100644 --- a/src/synth/synth-vhdl_expr.adb +++ b/src/synth/synth-vhdl_expr.adb @@ -1699,11 +1699,43 @@ package body Synth.Vhdl_Expr is return No_Valtyp; end if; when Type_Vector - | Type_Unbounded_Vector => - return Val; - when Type_Array - | Type_Unbounded_Array => - return Val; + | Type_Array => + -- Check length, replace bounds. + declare + Src_Typ, Dst_Typ : Type_Acc; + begin + Src_Typ := Val.Typ; + Dst_Typ := Conv_Typ; + loop + if Src_Typ.Abound.Len /= Dst_Typ.Abound.Len then + Error_Msg_Synth (Syn_Inst, Loc, "array length mismatch"); + return No_Valtyp; + end if; + exit when Src_Typ.Alast; + Src_Typ := Src_Typ.Arr_El; + Dst_Typ := Dst_Typ.Arr_El; + end loop; + + return (Typ => Conv_Typ, Val => Val.Val); + end; + when Type_Unbounded_Vector + | Type_Unbounded_Array => + -- Check bounds fit in target + declare + Src_Typ, Dst_Typ : Type_Acc; + begin + Src_Typ := Val.Typ; + Dst_Typ := Conv_Typ; + loop + Elab.Vhdl_Types.Check_Bound_Compatibility + (Syn_Inst, Loc, Src_Typ.Abound, Dst_Typ.Uarr_Idx); + exit when Src_Typ.Alast; + Src_Typ := Src_Typ.Arr_El; + Dst_Typ := Dst_Typ.Arr_El; + end loop; + + return Val; + end; when Type_Bit | Type_Logic => return Val; |