aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-02-18 20:25:15 +0100
committerTristan Gingold <tgingold@free.fr>2020-02-18 20:25:15 +0100
commit5abd825112fcddd8a61407a422a38a6bdd3f94a8 (patch)
treeb1ce1a4a0b1e2f5aff9a03ac3ce7266b5461e81d /src
parent96716ed59e3ffd00511e462122abd67aac1de4cc (diff)
downloadghdl-5abd825112fcddd8a61407a422a38a6bdd3f94a8.tar.gz
ghdl-5abd825112fcddd8a61407a422a38a6bdd3f94a8.tar.bz2
ghdl-5abd825112fcddd8a61407a422a38a6bdd3f94a8.zip
synth: handle file_open.
Diffstat (limited to 'src')
-rw-r--r--src/synth/synth-files_operations.adb42
-rw-r--r--src/synth/synth-files_operations.ads4
-rw-r--r--src/synth/synth-static_proc.adb2
3 files changed, 48 insertions, 0 deletions
diff --git a/src/synth/synth-files_operations.adb b/src/synth/synth-files_operations.adb
index 782908913..3fa075468 100644
--- a/src/synth/synth-files_operations.adb
+++ b/src/synth/synth-files_operations.adb
@@ -173,6 +173,48 @@ package body Synth.Files_Operations is
end if;
end Endfile;
+ -- Declaration
+ -- procedure FILE_OPEN (file F : FT:
+ -- External_Name : String;
+ -- Open_Kind : File_Open_Kind);
+ procedure Synth_File_Open (Syn_Inst : Synth_Instance_Acc;
+ Imp : Node;
+ Loc : Node)
+ is
+ Inters : constant Node := Get_Interface_Declaration_Chain (Imp);
+ F : constant File_Index := Get_Value (Syn_Inst, Inters).File;
+ Param2 : constant Node := Get_Chain (Inters);
+ File_Name : constant Value_Acc := Get_Value (Syn_Inst, Param2);
+ Param3 : constant Node := Get_Chain (Param2);
+ Open_Kind : constant Value_Acc := Get_Value (Syn_Inst, Param3);
+ C_Name : C_File_Name;
+ C_Name_Len : Natural;
+ File_Mode : Ghdl_I32;
+ Status : Op_Status;
+ begin
+ Convert_File_Name (File_Name, C_Name, C_Name_Len, Status);
+ if Status = Op_Ok then
+ File_Mode := Ghdl_I32 (Open_Kind.Scal);
+ if Get_Text_File_Flag (Get_Type (Inters)) then
+ Ghdl_Text_File_Open
+ (F, File_Mode, To_Ghdl_C_String (C_Name'Address), Status);
+ else
+ Ghdl_File_Open
+ (F, File_Mode, To_Ghdl_C_String (C_Name'Address), Status);
+ end if;
+ end if;
+
+ if Status /= Op_Ok then
+ if Status = Op_Name_Error then
+ Error_Msg_Synth
+ (+Loc, "cannot open file: " & C_Name (1 .. C_Name_Len));
+ raise File_Execution_Error;
+ else
+ File_Error (Loc, Status);
+ end if;
+ end if;
+ end Synth_File_Open;
+
-- Declaration:
-- procedure untruncated_text_read --!V87
-- (file f : text; str : out string; len : out natural); --!V87
diff --git a/src/synth/synth-files_operations.ads b/src/synth/synth-files_operations.ads
index a683e5022..35a92dbb0 100644
--- a/src/synth/synth-files_operations.ads
+++ b/src/synth/synth-files_operations.ads
@@ -33,6 +33,10 @@ package Synth.Files_Operations is
function Endfile (F : File_Index; Loc : Syn_Src) return Boolean;
+ procedure Synth_File_Open (Syn_Inst : Synth_Instance_Acc;
+ Imp : Node;
+ Loc : Node);
+
procedure Synth_Untruncated_Text_Read (Syn_Inst : Synth_Instance_Acc;
Imp : Node;
Loc : Node);
diff --git a/src/synth/synth-static_proc.adb b/src/synth/synth-static_proc.adb
index c93f3bb1f..cc92b9ee7 100644
--- a/src/synth/synth-static_proc.adb
+++ b/src/synth/synth-static_proc.adb
@@ -41,6 +41,8 @@ package body Synth.Static_Proc is
Loc : Node) is
begin
case Get_Implicit_Definition (Imp) is
+ when Iir_Predefined_File_Open =>
+ Synth_File_Open (Syn_Inst, Imp, Loc);
when Iir_Predefined_Foreign_Untruncated_Text_Read =>
Synth_Untruncated_Text_Read (Syn_Inst, Imp, Loc);
when Iir_Predefined_Deallocate =>