diff options
author | gingold | 2005-10-26 04:01:32 +0000 |
---|---|---|
committer | gingold | 2005-10-26 04:01:32 +0000 |
commit | 89024703a19d25c51f9c10d00a7f6cad15e6c952 (patch) | |
tree | 2c086ab30f8288c10d5f24ad0dca3ac463620d28 /ortho/debug/ortho_ident_hash.adb | |
parent | 3837df869927b515563a33e6732d1da35c262c68 (diff) | |
download | ghdl-89024703a19d25c51f9c10d00a7f6cad15e6c952.tar.gz ghdl-89024703a19d25c51f9c10d00a7f6cad15e6c952.tar.bz2 ghdl-89024703a19d25c51f9c10d00a7f6cad15e6c952.zip |
ortho/debug and ortho/oread added
Diffstat (limited to 'ortho/debug/ortho_ident_hash.adb')
-rw-r--r-- | ortho/debug/ortho_ident_hash.adb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ortho/debug/ortho_ident_hash.adb b/ortho/debug/ortho_ident_hash.adb new file mode 100644 index 0000000..c22b130 --- /dev/null +++ b/ortho/debug/ortho_ident_hash.adb @@ -0,0 +1,54 @@ +package body Ortho_Ident_Hash is + type O_Ident_Array is array (Hash_Type range <>) of O_Ident; + Hash_Max : constant Hash_Type := 511; + Symtable : O_Ident_Array (0 .. Hash_Max - 1) := (others => null); + + function Get_Identifier (Str : String) return O_Ident + is + Hash : Hash_Type; + Ent : Hash_Type; + Res : O_Ident; + begin + -- 1. Compute Hash. + Hash := 0; + for I in Str'Range loop + Hash := Hash * 31 + Character'Pos (Str (I)); + end loop; + + -- 2. Search. + Ent := Hash mod Hash_Max; + Res := Symtable (Ent); + while Res /= null loop + if Res.Hash = Hash and then Res.Ident.all = Str then + return Res; + end if; + Res := Res.Next; + end loop; + + -- Not found: add. + Res := new Ident_Type'(Hash => Hash, + Ident => new String'(Str), + Next => Symtable (Ent)); + Symtable (Ent) := Res; + return Res; + end Get_Identifier; + + function Get_String (Id : O_Ident) return String is + begin + if Id = null then + return "?ANON?"; + else + return Id.Ident.all; + end if; + end Get_String; + + function Is_Nul (Id : O_Ident) return Boolean is + begin + return Id = null; + end Is_Nul; + + function Is_Equal (Id : O_Ident; Str : String) return Boolean is + begin + return Id.Ident.all = Str; + end Is_Equal; +end Ortho_Ident_Hash; |