aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-11-16 20:23:03 +0100
committerTristan Gingold <tgingold@free.fr>2018-11-16 20:23:03 +0100
commitbef801a0ac1f46f40e56b38c8860689d379b72ea (patch)
treed0dcc127a144222411796ac2a129570fb98a68e4
parentd231838679aefd39370742f995b3c5a5e8055bc5 (diff)
downloadghdl-bef801a0ac1f46f40e56b38c8860689d379b72ea.tar.gz
ghdl-bef801a0ac1f46f40e56b38c8860689d379b72ea.tar.bz2
ghdl-bef801a0ac1f46f40e56b38c8860689d379b72ea.zip
files_map: add Set_File_Length, Reverse_Source_File
-rw-r--r--src/files_map.adb67
-rw-r--r--src/files_map.ads9
2 files changed, 58 insertions, 18 deletions
diff --git a/src/files_map.adb b/src/files_map.adb
index f422cbaff..b30772f60 100644
--- a/src/files_map.adb
+++ b/src/files_map.adb
@@ -685,8 +685,6 @@ package body Files_Map is
Buffer (Source_Ptr_Org .. Source_Ptr_Org + Len - 1) :=
File_Buffer (Content);
end if;
- Buffer (Source_Ptr_Org + Len) := EOT;
- Buffer (Source_Ptr_Org + Len + 1) := EOT;
-- Create entry.
Res := Source_Files.Allocate;
@@ -698,7 +696,9 @@ package body Files_Map is
Directory => Null_Identifier,
Checksum => No_File_Checksum_Id,
Source => Buffer,
- File_Length => Natural (Len));
+ File_Length => 0);
+
+ Set_File_Length (Res, Len);
Next_Location := Source_Files.Table (Res).Last_Location + 1;
@@ -784,6 +784,30 @@ package body Files_Map is
end if;
end Location_Instance_To_Location;
+ function Reserve_Source_File
+ (Directory : Name_Id; Name: Name_Id; Length : Source_Ptr)
+ return Source_File_Entry
+ is
+ Res : Source_File_Entry;
+
+ Buffer : File_Buffer_Acc;
+ begin
+ Res := Create_Source_File_Entry (Directory, Name);
+
+ Buffer :=
+ new File_Buffer (Source_Ptr_Org .. Source_Ptr_Org + Length - 1);
+
+ -- Read_Source_File call must follow its Create_Source_File.
+ pragma Assert (Source_Files.Table (Res).First_Location = Next_Location);
+
+ Source_Files.Table (Res).Last_Location :=
+ Next_Location + Location_Type (Length) + 1;
+ Next_Location := Source_Files.Table (Res).Last_Location + 1;
+ Source_Files.Table (Res).Source := Buffer;
+
+ return Res;
+ end Reserve_Source_File;
+
-- Return an entry for a filename.
-- Load the filename if necessary.
function Read_Source_File (Directory : Name_Id; Name: Name_Id)
@@ -831,12 +855,15 @@ package body Files_Map is
return No_Source_File_Entry;
end if;
- Res := Create_Source_File_Entry (Directory, Name);
-
Length := Source_Ptr (Raw_Length);
- Buffer :=
- new File_Buffer (Source_Ptr_Org .. Source_Ptr_Org + Length + 1);
+ Res := Reserve_Source_File (Directory, Name, Length + 2);
+ if Res = No_Source_File_Entry then
+ Close (Fd);
+ return No_Source_File_Entry;
+ end if;
+
+ Buffer := Get_File_Source (Res);
if Read (Fd, Buffer (Source_Ptr_Org)'Address, Integer (Length))
/= Integer (Length)
@@ -844,12 +871,9 @@ package body Files_Map is
Close (Fd);
raise Internal_Error;
end if;
- Buffer (Source_Ptr_Org + Length) := EOT;
- Buffer (Source_Ptr_Org + Length + 1) := EOT;
Close (Fd);
- -- Read_Source_File call must follow its Create_Source_File.
- pragma Assert (Source_Files.Table (Res).First_Location = Next_Location);
+ Set_File_Length (Res, Length);
-- Compute the SHA1.
declare
@@ -873,12 +897,6 @@ package body Files_Map is
end loop;
end;
- Source_Files.Table (Res).Last_Location :=
- Next_Location + Location_Type (Length) + 1;
- Next_Location := Source_Files.Table (Res).Last_Location + 1;
- Source_Files.Table (Res).Source := Buffer;
- Source_Files.Table (Res).File_Length := Integer (Length);
-
return Res;
end Read_Source_File;
@@ -935,6 +953,21 @@ package body Files_Map is
(Source_Files.Table (File).Source (Source_Ptr_Org)'Address);
end Get_File_Buffer;
+ procedure Set_File_Length (File : Source_File_Entry; Length : Source_Ptr) is
+ begin
+ Check_File (File);
+ declare
+ F : Source_File_Record renames Source_Files.Table (File);
+ Buffer : File_Buffer_Acc renames F.Source;
+ begin
+ pragma Assert (Length <= Buffer'Length - 2);
+
+ F.File_Length := Natural (Length);
+ Buffer (Source_Ptr_Org + Length) := EOT;
+ Buffer (Source_Ptr_Org + Length + 1) := EOT;
+ end;
+ end Set_File_Length;
+
-- Return the length of the file (which is the size of the file buffer).
function Get_File_Length (File: Source_File_Entry) return Source_Ptr is
begin
diff --git a/src/files_map.ads b/src/files_map.ads
index f09e5b6e0..7d23f45c6 100644
--- a/src/files_map.ads
+++ b/src/files_map.ads
@@ -46,6 +46,11 @@ package Files_Map is
function Read_Source_File (Directory : Name_Id; Name : Name_Id)
return Source_File_Entry;
+ -- Reserve an entry, but do not read any file.
+ function Reserve_Source_File
+ (Directory : Name_Id; Name : Name_Id; Length : Source_Ptr)
+ return Source_File_Entry;
+
-- Each file in memory has two terminal EOT.
EOT : constant Character := Character'Val (4);
@@ -89,7 +94,9 @@ package Files_Map is
-- Likewise but return a pointer. To be used only from non-Ada code.
function Get_File_Buffer (File : Source_File_Entry) return File_Buffer_Ptr;
- -- Return the length of the file (which is the size of the file buffer).
+ -- Set/Get the length of the file (which is less than the size of the
+ -- file buffer). Set also append two EOT at the end of the file.
+ procedure Set_File_Length (File : Source_File_Entry; Length : Source_Ptr);
function Get_File_Length (File : Source_File_Entry) return Source_Ptr;
-- Return the name of the file.