diff options
author | Tristan Gingold <tgingold@free.fr> | 2016-10-31 06:21:50 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2016-11-01 21:36:54 +0100 |
commit | bbe42c9fa216335dd56424014bda666a5d6717de (patch) | |
tree | cb19303410706351a059f2e65f73d7a4f2d28b85 | |
parent | b869a4acb52358fe8ca5decaac826af056bfdfca (diff) | |
download | ghdl-bbe42c9fa216335dd56424014bda666a5d6717de.tar.gz ghdl-bbe42c9fa216335dd56424014bda666a5d6717de.tar.bz2 ghdl-bbe42c9fa216335dd56424014bda666a5d6717de.zip |
name_table: auto-initialize.
-rw-r--r-- | src/ghdldrv/ghdlrun.adb | 2 | ||||
-rw-r--r-- | src/name_table.adb | 23 | ||||
-rw-r--r-- | src/name_table.ads | 9 | ||||
-rw-r--r-- | src/std_names.adb | 2 |
4 files changed, 22 insertions, 14 deletions
diff --git a/src/ghdldrv/ghdlrun.adb b/src/ghdldrv/ghdlrun.adb index 94d760d63..725c16e30 100644 --- a/src/ghdldrv/ghdlrun.adb +++ b/src/ghdldrv/ghdlrun.adb @@ -604,7 +604,7 @@ package body Ghdlrun is Str_Table.Initialize; Nodes.Initialize; Files_Map.Initialize; - Name_Table.Initialize; + Name_Table.Finalize; if Flag_Verbose then Ada.Text_IO.Put_Line ("Starting simulation"); diff --git a/src/name_table.adb b/src/name_table.adb index b4bc24ca4..3d0010bce 100644 --- a/src/name_table.adb +++ b/src/name_table.adb @@ -1,5 +1,5 @@ -- Name table. --- Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold +-- Copyright (C) 2002 - 2016 Tristan Gingold -- -- GHDL is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free @@ -52,6 +52,9 @@ package body Name_Table is type Hash_Array is array (Hash_Value_Type range <>) of Name_Id; type Hash_Array_Acc is access Hash_Array; + procedure Deallocate is new Ada.Unchecked_Deallocation + (Hash_Array, Hash_Array_Acc); + -- Hash table. Lower bound is always 0, upper bound is always -- Hash_Table_Size - 1. Hash_Table: Hash_Array_Acc; @@ -107,7 +110,7 @@ package body Name_Table is Strings_Table.Append (NUL); - -- Reserve entry 0. + -- Reserve entry 0 for Null_Identifier. Strings_Table.Append (NUL); Names_Table.Append ((Hash => 0, Name => Strings_Table.Last, @@ -128,10 +131,19 @@ package body Name_Table is Append_Terminator; + -- Allocate the Hash_Table. + Hash_Table_Size := 1024; Hash_Table := new Hash_Array'(0 .. Hash_Table_Size - 1 => Null_Identifier); end Initialize; + procedure Finalize is + begin + Strings_Table.Free; + Names_Table.Free; + Deallocate (Hash_Table); + end Finalize; + -- Compute the hash value of a string. In case of algorithm change, check -- the performance using Disp_Stats. function Hash return Hash_Value_Type @@ -238,9 +250,6 @@ package body Name_Table is -- Expand the hash table (double the size). procedure Expand is - procedure Deallocate is new Ada.Unchecked_Deallocation - (Hash_Array, Hash_Array_Acc); - Old_Hash_Table : Hash_Array_Acc; Id : Name_Id; begin @@ -309,8 +318,6 @@ package body Name_Table is Hash_Table (Hash_Index) := Res; Append_Terminator; - --Put_Line ("created"); - return Res; end Get_Identifier; @@ -442,4 +449,6 @@ package body Name_Table is end loop; end; end Disp_Stats; +begin + Initialize; end Name_Table; diff --git a/src/name_table.ads b/src/name_table.ads index 5a6219f5e..000b98b2a 100644 --- a/src/name_table.ads +++ b/src/name_table.ads @@ -1,5 +1,5 @@ -- Name table. --- Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold +-- Copyright (C) 2002 - 2016 Tristan Gingold -- -- GHDL is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free @@ -26,9 +26,6 @@ with Types; use Types; -- doubled. package Name_Table is - -- Initialize the package, ie create tables. - procedure Initialize; - -- Get an entry in the name table for a character. -- (entries for characters are already built). Characters are put in the -- name table, but are always different from identifiers. They simply @@ -100,6 +97,10 @@ package Name_Table is -- The length of the name string. Nam_Length: Natural range 0 .. Max_Nam_Length; + -- Free all resources. The package cannot be used anymore after calling + -- this procedure. + procedure Finalize; + -- Disp statistics. -- Used for debugging. procedure Disp_Stats; diff --git a/src/std_names.adb b/src/std_names.adb index 253f844ad..5e8e4bae2 100644 --- a/src/std_names.adb +++ b/src/std_names.adb @@ -28,8 +28,6 @@ package body Std_Names is end if; end Def; begin - Name_Table.Initialize; - Def ("mod", Name_Mod); Def ("rem", Name_Rem); |