diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/synth/synth-files_operations.adb | 23 | ||||
| -rw-r--r-- | src/synth/synth-files_operations.ads | 6 | ||||
| -rw-r--r-- | src/synth/synth-oper.adb | 9 | 
3 files changed, 35 insertions, 3 deletions
| diff --git a/src/synth/synth-files_operations.adb b/src/synth/synth-files_operations.adb index 4b188e157..5be4de041 100644 --- a/src/synth/synth-files_operations.adb +++ b/src/synth/synth-files_operations.adb @@ -26,7 +26,6 @@ with Grt.Files_Operations; use Grt.Files_Operations;  with Vhdl.Annotations;  with Synth.Expr; use Synth.Expr; -with Synth.Source; use Synth.Source;  with Synth.Errors; use Synth.Errors;  package body Synth.Files_Operations is @@ -34,11 +33,14 @@ package body Synth.Files_Operations is     --  Representation of file name compatible with C (so NUL terminated).     subtype C_File_Name is String (1 .. 1025); +   procedure File_Error (Loc : Node; Status : Op_Status); +   pragma No_Return (File_Error); +     procedure File_Error (Loc : Node; Status : Op_Status) is     begin        pragma Assert (Status /= Op_Ok);        Error_Msg_Synth (+Loc, "file operation failed"); -      raise Internal_Error; +      raise File_Execution_Error;     end File_Error;     --  VAL represents a string, so an array of characters. @@ -148,7 +150,7 @@ package body Synth.Files_Operations is           if Status = Op_Name_Error then              Error_Msg_Synth                (+Decl, "cannot open file: " & C_Name (1 .. C_Name_Len)); -            raise Internal_Error; +            raise File_Execution_Error;           else              File_Error (Decl, Status);           end if; @@ -156,4 +158,19 @@ package body Synth.Files_Operations is        return F;     end Elaborate_File_Declaration; + +   function Endfile (F : File_Index; Loc : Syn_Src) return Boolean +   is +      Status : Op_Status; +   begin +      Ghdl_File_Endfile (F, Status); + +      if Status = Op_Ok then +         return False; +      elsif Status = Op_End_Of_File then +         return True; +      else +         File_Error (Loc, Status); +      end if; +   end Endfile;  end Synth.Files_Operations; diff --git a/src/synth/synth-files_operations.ads b/src/synth/synth-files_operations.ads index 81dee4a91..13852906e 100644 --- a/src/synth/synth-files_operations.ads +++ b/src/synth/synth-files_operations.ads @@ -20,10 +20,16 @@  with Vhdl.Nodes; use Vhdl.Nodes; +with Synth.Source; use Synth.Source;  with Synth.Values; use Synth.Values;  with Synth.Context; use Synth.Context;  package Synth.Files_Operations is +   --  Raised in case of un-recoverable error. +   File_Execution_Error : exception; +     function Elaborate_File_Declaration       (Syn_Inst : Synth_Instance_Acc; Decl : Node) return File_Index; + +   function Endfile (F : File_Index; Loc : Syn_Src) return Boolean;  end Synth.Files_Operations; diff --git a/src/synth/synth-oper.adb b/src/synth/synth-oper.adb index 07bcc7dbc..1fe4afca6 100644 --- a/src/synth/synth-oper.adb +++ b/src/synth/synth-oper.adb @@ -37,6 +37,7 @@ with Synth.Errors; use Synth.Errors;  with Synth.Stmts; use Synth.Stmts;  with Synth.Expr; use Synth.Expr;  with Synth.Source; +with Synth.Files_Operations;  package body Synth.Oper is     --  As log2(3m) is directly referenced, the program must be linked with -lm @@ -1093,6 +1094,14 @@ package body Synth.Oper is        end if;        case Def is +         when Iir_Predefined_Endfile => +            declare +               L : constant Value_Acc := Get_Value (Subprg_Inst, Param1); +               Res : Boolean; +            begin +               Res := Synth.Files_Operations.Endfile (L.File, Expr); +               return Create_Value_Discrete (Boolean'Pos (Res), Boolean_Type); +            end;           when Iir_Predefined_Ieee_1164_Rising_Edge =>              declare                 Clk : Net; | 
