aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-11-06 19:26:31 +0100
committerTristan Gingold <tgingold@free.fr>2019-11-06 19:26:31 +0100
commita9c2b17053a324a92e86dd0e3bc65d34bae08db3 (patch)
tree4ee7cd7713aa0d8828102b59f012e43bcfc2f099 /src
parent3a49c7ff29374c6f085e2d9dc46b200afbfc9a2c (diff)
downloadghdl-a9c2b17053a324a92e86dd0e3bc65d34bae08db3.tar.gz
ghdl-a9c2b17053a324a92e86dd0e3bc65d34bae08db3.tar.bz2
ghdl-a9c2b17053a324a92e86dd0e3bc65d34bae08db3.zip
files_map: add Discard_Source_File, Free_Source_File,
Diffstat (limited to 'src')
-rw-r--r--src/files_map.adb29
-rw-r--r--src/files_map.ads20
2 files changed, 44 insertions, 5 deletions
diff --git a/src/files_map.adb b/src/files_map.adb
index 24917592c..14da4c1fc 100644
--- a/src/files_map.adb
+++ b/src/files_map.adb
@@ -823,6 +823,15 @@ package body Files_Map is
return Res;
end Read_Source_File;
+ procedure Discard_Source_File (File : Source_File_Entry)
+ is
+ pragma Assert (File <= Source_Files.Last);
+ F : Source_File_Record renames Source_Files.Table (File);
+ begin
+ F.File_Name := Null_Identifier;
+ F.Directory := Null_Identifier;
+ end Discard_Source_File;
+
procedure Free_Source_File (File : Source_File_Entry)
is
procedure Free is new Ada.Unchecked_Deallocation
@@ -904,6 +913,18 @@ package body Files_Map is
return Source_Files.Table (File).File_Length;
end Get_File_Length;
+ function Get_Content_Length (File : Source_File_Entry) return Source_Ptr
+ is
+ pragma Assert (File <= Source_Files.Last);
+ F : Source_File_Record renames Source_Files.Table (File);
+ begin
+ if F.Gap_Start >= F.File_Length then
+ return F.File_Length;
+ else
+ return F.File_Length - (F.Gap_Last - F.Gap_Start + 1);
+ end if;
+ end Get_Content_Length;
+
function Get_Buffer_Length (File : Source_File_Entry) return Source_Ptr
is
pragma Assert (File <= Source_Files.Last);
@@ -1161,8 +1182,12 @@ package body Files_Map is
end if;
case F.Kind is
when Source_File_File =>
- Log (" buf:" & Source_Ptr'Image (F.Source'First)
- & " -" & Source_Ptr'Image (F.Source'Last));
+ if F.Source = null then
+ Log (" no buf");
+ else
+ Log (" buf:" & Source_Ptr'Image (F.Source'First)
+ & " -" & Source_Ptr'Image (F.Source'Last));
+ end if;
Log_Line;
Log (" nbr lines:"
& Natural'Image (Lines_Tables.Last (F.Lines)));
diff --git a/src/files_map.ads b/src/files_map.ads
index a72c75d07..131da8ffa 100644
--- a/src/files_map.ads
+++ b/src/files_map.ads
@@ -80,6 +80,14 @@ package Files_Map is
-- carefully used as the corresponding locations will be reused.
procedure Unload_Last_Source_File (File : Source_File_Entry);
+ -- Mark FILE as unavailable: clear the name and directory.
+ -- This is needed before creating a new source file with the same name.
+ procedure Discard_Source_File (File : Source_File_Entry);
+
+ -- Free resources used by FILE, but keep the entry.
+ -- (It could be recycled for files that could fit - not implemented).
+ procedure Free_Source_File (File : Source_File_Entry);
+
-- Relocate location LOC (which must be in the reference of INST_FILE)
-- for instrnace INST_FILE.
function Instance_Relocate
@@ -102,13 +110,19 @@ 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;
- -- Set/Get the length of the file (which is less than the size of the
- -- file buffer). The gap is not included in the length.
+ -- Set 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);
+
+ -- Get the position of the first EOT character.
function Get_File_Length (File : Source_File_Entry) return Source_Ptr;
- -- Get the length of the buffer, which includes the gap and the
+ -- Get the length of the content; this is the file length minus the gap,
+ -- if the gap is before the end.
+ function Get_Content_Length (File : Source_File_Entry) return Source_Ptr;
+
+ -- Get the length of the buffer, which always includes the gap and the
-- two terminal EOT.
function Get_Buffer_Length (File : Source_File_Entry) return Source_Ptr;