diff options
-rw-r--r-- | python/libghdl/thin/files_map.py | 3 | ||||
-rw-r--r-- | src/files_map.adb | 29 | ||||
-rw-r--r-- | src/files_map.ads | 20 |
3 files changed, 47 insertions, 5 deletions
diff --git a/python/libghdl/thin/files_map.py b/python/libghdl/thin/files_map.py index b0029b0a4..0025c9178 100644 --- a/python/libghdl/thin/files_map.py +++ b/python/libghdl/thin/files_map.py @@ -38,4 +38,7 @@ Read_Source_File = libghdl.files_map__read_source_file Reserve_Source_File = libghdl.files_map__reserve_source_file +Discard_Source_File = libghdl.files_map__discard_source_file +Free_Source_File = libghdl.files_map__free_source_file + Get_Last_Source_File_Entry = libghdl.files_map__get_last_source_file_entry 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; |