diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-09-17 11:52:42 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-09-17 11:52:42 +0200 |
commit | 5d95674685a4a5c557757cc51c61b0fb6ec8fd18 (patch) | |
tree | 724d6bd8bb0f5a7e119cea4d1f93658499283ed6 /src | |
parent | 7548e438616dfc9fcfd05d1df8d6b4d88796e279 (diff) | |
download | ghdl-5d95674685a4a5c557757cc51c61b0fb6ec8fd18.tar.gz ghdl-5d95674685a4a5c557757cc51c61b0fb6ec8fd18.tar.bz2 ghdl-5d95674685a4a5c557757cc51c61b0fb6ec8fd18.zip |
synth: improve file handling (skip extra data, errors)
Diffstat (limited to 'src')
-rw-r--r-- | src/synth/elab-vhdl_files.adb | 49 | ||||
-rw-r--r-- | src/synth/synth-vhdl_eval.adb | 3 | ||||
-rw-r--r-- | src/synth/synth-vhdl_static_proc.adb | 4 |
3 files changed, 53 insertions, 3 deletions
diff --git a/src/synth/elab-vhdl_files.adb b/src/synth/elab-vhdl_files.adb index be00296af..d5a92a966 100644 --- a/src/synth/elab-vhdl_files.adb +++ b/src/synth/elab-vhdl_files.adb @@ -492,6 +492,49 @@ package body Elab.Vhdl_Files is end case; end File_Read_Value; + procedure File_Skip_Value (File : File_Index; Typ : Type_Acc; Loc : Node) + is + Status : Op_Status; + begin + case Typ.Kind is + when Type_Discrete + | Type_Bit + | Type_Logic + | Type_Float => + declare + Mem : Memory_Array (0 .. 7); + pragma Assert (Typ.Sz <= 8); + begin + Ghdl_Read_Scalar (File, Ghdl_Ptr (Mem'Address), + Ghdl_Index_Type (Typ.Sz), Status); + if Status /= Op_Ok then + File_Error (Loc, Status); + end if; + end; + when Type_Vector + | Type_Array => + declare + El_Typ : constant Type_Acc := Get_Array_Element (Typ); + begin + for I in 1 .. Get_Bound_Length (Typ) loop + File_Skip_Value (File, El_Typ, Loc); + end loop; + end; + when Type_Record => + for I in Typ.Rec.E'Range loop + File_Skip_Value (File, Typ.Rec.E (I).Typ, Loc); + end loop; + when Type_Unbounded_Record + | Type_Unbounded_Array + | Type_Unbounded_Vector + | Type_Protected + | Type_Slice + | Type_File + | Type_Access => + raise Internal_Error; + end case; + end File_Skip_Value; + procedure Synth_File_Read (Syn_Inst : Synth_Instance_Acc; Imp : Node; Loc : Node) is @@ -552,9 +595,9 @@ package body Elab.Vhdl_Files is File_Read_Value (File, (El_Typ, Value.Val.Mem + Off), Loc); Off := Off + El_Typ.Sz; else - -- FIXME: for empty arrays ?? - -- Lose_Binary (File, Value.Val_Array (0)); - raise Internal_Error; + -- Loose extra data. + File_Skip_Value (File, El_Typ, Loc); + Len := Len - 1; end if; end loop; Write_Discrete (Length, Int64 (Len)); diff --git a/src/synth/synth-vhdl_eval.adb b/src/synth/synth-vhdl_eval.adb index cddcc5a5d..1ca559dec 100644 --- a/src/synth/synth-vhdl_eval.adb +++ b/src/synth/synth-vhdl_eval.adb @@ -2403,6 +2403,9 @@ package body Synth.Vhdl_Eval is begin Res := Elab.Vhdl_Files.Endfile (Param1.Val.File, Expr); return Create_Memory_U8 (Boolean'Pos (Res), Boolean_Type); + exception + when Elab.Vhdl_Files.File_Execution_Error => + return Null_Memtyp; end; when Iir_Predefined_Integer_To_String => diff --git a/src/synth/synth-vhdl_static_proc.adb b/src/synth/synth-vhdl_static_proc.adb index 2bfc9dc06..585b16e58 100644 --- a/src/synth/synth-vhdl_static_proc.adb +++ b/src/synth/synth-vhdl_static_proc.adb @@ -26,6 +26,7 @@ with Elab.Memtype; with Elab.Vhdl_Values; use Elab.Vhdl_Values; with Elab.Vhdl_Heap; with Elab.Vhdl_Files; use Elab.Vhdl_Files; +with Elab.Debugger; with Synth.Errors; use Synth.Errors; @@ -111,5 +112,8 @@ package body Synth.Vhdl_Static_Proc is Error_Msg_Synth (+Loc, "call to implicit %n is not supported", +Imp); end case; + exception + when File_Execution_Error => + Elab.Debugger.Debug_Error (Syn_Inst, Loc); end Synth_Static_Procedure; end Synth.Vhdl_Static_Proc; |