aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-01-27 18:46:24 +0100
committerTristan Gingold <tgingold@free.fr>2023-01-27 20:30:08 +0100
commit33a923a2be7c78d4e95e31c69c7c125acb2619bc (patch)
tree24e75038ee245f942256a81e879a6154c91ea1b3
parent6c7ecaa1e1489395e1df86a97d19edff22e1871b (diff)
downloadghdl-33a923a2be7c78d4e95e31c69c7c125acb2619bc.tar.gz
ghdl-33a923a2be7c78d4e95e31c69c7c125acb2619bc.tar.bz2
ghdl-33a923a2be7c78d4e95e31c69c7c125acb2619bc.zip
grt-files_operations: use grt.files
-rw-r--r--Makefile.in1
-rw-r--r--src/grt/grt-files.adb3
-rw-r--r--src/grt/grt-files_operations.adb77
-rw-r--r--src/grt/grt-files_operations.ads10
-rw-r--r--src/synth/elab-vhdl_files.adb5
-rw-r--r--src/synth/elab-vhdl_values.ads4
6 files changed, 19 insertions, 81 deletions
diff --git a/Makefile.in b/Makefile.in
index 7ae10305f..b541b24bb 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -274,6 +274,7 @@ copy-sources.gcc: version.ads scripts/gcc/Make-lang.in
$(CP) -p $(srcdir)/src/grt/grt-stdio.ad? $(gcc_vhdl_dir)
$(CP) -p $(srcdir)/src/grt/grt-table.ad? $(gcc_vhdl_dir)
$(CP) -p $(srcdir)/src/grt/grt-files_operations.ad? $(gcc_vhdl_dir)
+ $(CP) -p $(srcdir)/src/grt/grt-files.ad? $(gcc_vhdl_dir)
$(CP) -p $(srcdir)/src/grt/grt-to_strings.ad? $(gcc_vhdl_dir)
$(CP) -p $(srcdir)/src/grt/grt-strings.ad? $(gcc_vhdl_dir)
$(CP) -p $(srcdir)/src/grt/grt-severity.ads $(gcc_vhdl_dir)
diff --git a/src/grt/grt-files.adb b/src/grt/grt-files.adb
index 0b0430ace..34f03e910 100644
--- a/src/grt/grt-files.adb
+++ b/src/grt/grt-files.adb
@@ -20,8 +20,7 @@
-- covered by the GNU General Public License. This exception does not
-- however invalidate any other reasons why the executable file might be
-- covered by the GNU Public License.
-with Grt.Errors; use Grt.Errors;
-with Grt.Errors_Exec; use Grt.Errors_Exec;
+
with Grt.Stdio; use Grt.Stdio;
with Grt.Table;
with System; use System;
diff --git a/src/grt/grt-files_operations.adb b/src/grt/grt-files_operations.adb
index 097165855..a66d1d3cb 100644
--- a/src/grt/grt-files_operations.adb
+++ b/src/grt/grt-files_operations.adb
@@ -20,70 +20,34 @@
-- covered by the GNU General Public License. This exception does not
-- however invalidate any other reasons why the executable file might be
-- covered by the GNU Public License.
+with System; use System;
+
with Grt.Stdio; use Grt.Stdio;
with Grt.C; use Grt.C;
-with Grt.Table;
-with System; use System;
-pragma Elaborate_All (Grt.Table);
package body Grt.Files_Operations is
- subtype C_Files is Grt.Stdio.FILEs;
-
-- The end of lines
C_LF : constant int := 10; -- \n
C_CR : constant int := 13; -- \r
Auto_Flush : constant Boolean := False;
- type File_Entry_Type is record
- -- The corresponding C stream.
- Stream : C_Files;
-
- Signature : Ghdl_C_String;
-
- -- Open kind: r, a or w.
- Kind : Character;
-
- Is_Text : Boolean;
-
- -- True if the file entry is used.
- Is_Alive : Boolean;
- end record;
-
- package Files_Table is new Grt.Table
- (Table_Component_Type => File_Entry_Type,
- Table_Index_Type => Ghdl_File_Index,
- Table_Low_Bound => 1,
- Table_Initial => 2);
-
-- Get the C stream for INDEX.
procedure Get_File
(Index : Ghdl_File_Index; Res : out C_Files; Status : out Op_Status) is
begin
- if Index not in Files_Table.First .. Files_Table.Last then
+ if not Check_File_Index (Index) then
Status := Op_Bad_Index;
else
Status := Op_Ok;
- Res := Files_Table.Table (Index).Stream;
+ Res := Get_File_Stream (Index);
end if;
end Get_File;
- -- Assume INDEX is correct.
- function Is_Open (Index : Ghdl_File_Index) return Boolean is
- begin
- return Files_Table.Table (Index).Stream /= NULL_Stream;
- end Is_Open;
-
- -- Assume INDEX is correct.
- function Get_Kind (Index : Ghdl_File_Index) return Character is
- begin
- return Files_Table.Table (Index).Kind;
- end Get_Kind;
-
procedure Check_File_Mode
(Index : Ghdl_File_Index; Is_Text : Boolean; Status : out Op_Status) is
begin
- if Files_Table.Table (Index).Is_Text /= Is_Text then
+ if Is_Text_File (Index) /= Is_Text then
Status := Op_Bad_Mode;
else
Status := Op_Ok;
@@ -136,18 +100,6 @@ package body Grt.Files_Operations is
Status := Op_Ok;
end Check_Write;
- function Create_File
- (Is_Text : Boolean; Kind : Character; Sig : Ghdl_C_String)
- return Ghdl_File_Index is
- begin
- Files_Table.Append ((Stream => NULL_Stream,
- Signature => Sig,
- Kind => Kind,
- Is_Text => Is_Text,
- Is_Alive => True));
- return Files_Table.Last;
- end Create_File;
-
procedure Destroy_File
(Is_Text : Boolean; Index : Ghdl_File_Index; Status : out Op_Status)
is
@@ -167,14 +119,7 @@ package body Grt.Files_Operations is
end if;
-- Cleanup.
- Files_Table.Table (Index).Is_Alive := False;
- if Index = Files_Table.Last then
- while Files_Table.Last >= Files_Table.First
- and then Files_Table.Table (Files_Table.Last).Is_Alive = False
- loop
- Files_Table.Decrement_Last;
- end loop;
- end if;
+ Destroy_File (Index);
end Destroy_File;
function Ghdl_Text_File_Elaborate return Ghdl_File_Index is
@@ -307,7 +252,7 @@ package body Grt.Files_Operations is
F := stdout;
else
Str_Mode (1) := Kind;
- if Files_Table.Table (File).Is_Text then
+ if Is_Text_File (File) then
Str_Mode (2) := NUL;
else
Str_Mode (2) := 'b';
@@ -323,7 +268,7 @@ package body Grt.Files_Operations is
-- end if;
end if;
- Sig := Files_Table.Table (File).Signature;
+ Sig := Get_File_Signature (File);
if Sig /= null then
Sig_Len := strlen (Sig);
case Mode is
@@ -371,8 +316,7 @@ package body Grt.Files_Operations is
end case;
end if;
- Files_Table.Table (File).Stream := F;
- Files_Table.Table (File).Kind := Kind;
+ Set_File_Stream (File, F, Kind);
Status := Op_Ok;
end File_Open;
@@ -614,7 +558,8 @@ package body Grt.Files_Operations is
Status := Op_Close_Error;
return;
end if;
- Files_Table.Table (File).Stream := NULL_Stream;
+ Set_File_Stream (File, NULL_Stream, ' ');
+
Status := Op_Ok;
end File_Close;
diff --git a/src/grt/grt-files_operations.ads b/src/grt/grt-files_operations.ads
index e9da80597..2c1fa313b 100644
--- a/src/grt/grt-files_operations.ads
+++ b/src/grt/grt-files_operations.ads
@@ -21,20 +21,12 @@
-- however invalidate any other reasons why the executable file might be
-- covered by the GNU Public License.
-with Interfaces;
-
with Grt.Types; use Grt.Types;
with Grt.Vhdl_Types; use Grt.Vhdl_Types;
with Grt.Stdio;
+with Grt.Files; use Grt.Files;
package Grt.Files_Operations is
- type Ghdl_File_Index is new Interfaces.Integer_32;
-
- -- File open mode.
- Read_Mode : constant Ghdl_I32 := 0;
- Write_Mode : constant Ghdl_I32 := 1;
- Append_Mode : constant Ghdl_I32 := 2;
-
-- file_open_status.
Open_Ok : constant Ghdl_I32 := 0;
Status_Error : constant Ghdl_I32 := 1;
diff --git a/src/synth/elab-vhdl_files.adb b/src/synth/elab-vhdl_files.adb
index aec343170..a1fb471f1 100644
--- a/src/synth/elab-vhdl_files.adb
+++ b/src/synth/elab-vhdl_files.adb
@@ -25,6 +25,7 @@ with Vhdl.Utils; use Vhdl.Utils;
with Grt.Types; use Grt.Types;
with Grt.Vhdl_Types; use Grt.Vhdl_Types;
+with Grt.Files;
with Grt.Files_Operations; use Grt.Files_Operations;
with Grt.Stdio;
@@ -224,9 +225,9 @@ package body Elab.Vhdl_Files is
else
case Get_Mode (Decl) is
when Iir_In_Mode =>
- File_Mode := Read_Mode;
+ File_Mode := Grt.Files.Read_Mode;
when Iir_Out_Mode =>
- File_Mode := Write_Mode;
+ File_Mode := Grt.Files.Write_Mode;
when others =>
raise Internal_Error;
end case;
diff --git a/src/synth/elab-vhdl_values.ads b/src/synth/elab-vhdl_values.ads
index 0e72fd128..adf11ae8e 100644
--- a/src/synth/elab-vhdl_values.ads
+++ b/src/synth/elab-vhdl_values.ads
@@ -21,7 +21,7 @@ with Ada.Unchecked_Deallocation;
with Types; use Types;
with Areapools; use Areapools;
-with Grt.Files_Operations;
+with Grt.Files;
with Vhdl.Nodes; use Vhdl.Nodes;
@@ -76,7 +76,7 @@ package Elab.Vhdl_Values is
type Protected_Index is new Uns32;
No_Protected_Index : constant Protected_Index := 0;
- subtype File_Index is Grt.Files_Operations.Ghdl_File_Index;
+ subtype File_Index is Grt.Files.Ghdl_File_Index;
type Signal_Index_Type is new Uns32;
No_Signal_Index : constant Signal_Index_Type := 0;