aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth/synth-files_operations.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-11-13 07:55:05 +0100
committerTristan Gingold <tgingold@free.fr>2019-11-13 07:55:05 +0100
commit9d9179a97c5c89781f9a2578273e1490c23a5c00 (patch)
treebd72d7d41e92ff0aea0e0d8b697417f6d1a41825 /src/synth/synth-files_operations.adb
parent57182dfe1306ba624e04bf97559c8fc3c3a9dcf8 (diff)
downloadghdl-9d9179a97c5c89781f9a2578273e1490c23a5c00.tar.gz
ghdl-9d9179a97c5c89781f9a2578273e1490c23a5c00.tar.bz2
ghdl-9d9179a97c5c89781f9a2578273e1490c23a5c00.zip
synth: add support for endfile.
Diffstat (limited to 'src/synth/synth-files_operations.adb')
-rw-r--r--src/synth/synth-files_operations.adb23
1 files changed, 20 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;