From b9c2c358ac74c66736537d5b1eb44d42819f6ec1 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Thu, 9 May 2019 18:20:41 +0200 Subject: Make lists a generic package, add vhdl-lists. --- src/ghdldrv/ghdlrun.adb | 4 ++-- src/lists.adb | 10 +++++----- src/lists.ads | 15 ++++++++------- src/vhdl/vhdl-lists.ads | 21 +++++++++++++++++++++ src/vhdl/vhdl-nodes.adb | 2 +- src/vhdl/vhdl-nodes.adb.in | 2 +- src/vhdl/vhdl-nodes.ads | 2 +- 7 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 src/vhdl/vhdl-lists.ads (limited to 'src') diff --git a/src/ghdldrv/ghdlrun.adb b/src/ghdldrv/ghdlrun.adb index 5cf5ca4dd..a781d3ec9 100644 --- a/src/ghdldrv/ghdlrun.adb +++ b/src/ghdldrv/ghdlrun.adb @@ -43,7 +43,7 @@ with Trans_Be; with Translation; with Vhdl.Ieee.Std_Logic_1164; -with Lists; +with Vhdl.Lists; with Str_Table; with Hash; with Interning; @@ -757,7 +757,7 @@ package body Ghdlrun is Ortho_Jit.Finish; Translation.Finalize; - Lists.Initialize; + Vhdl.Lists.Initialize; Str_Table.Initialize; Vhdl.Nodes.Initialize; Files_Map.Initialize; diff --git a/src/lists.adb b/src/lists.adb index 65407d943..f6739cd36 100644 --- a/src/lists.adb +++ b/src/lists.adb @@ -68,7 +68,7 @@ package body Lists is return Listt.Table (List).Nbr = 0; end Is_Empty; - procedure Append_Element (List: List_Type; Element: Node_Type) + procedure Append_Element (List: List_Type; Element: El_Type) is L : List_Record renames Listt.Table (List); C : Chunk_Index_Type; @@ -91,7 +91,7 @@ package body Lists is L.Nbr := L.Nbr + 1; end Append_Element; - function Get_First_Element (List: List_Type) return Node_Type + function Get_First_Element (List: List_Type) return El_Type is L : List_Record renames Listt.Table (List); begin @@ -100,7 +100,7 @@ package body Lists is end Get_First_Element; -- Add (append) an element only if it was not already present in the list. - procedure Add_Element (List: List_Type; El: Node_Type) + procedure Add_Element (List: List_Type; El: El_Type) is It : Iterator; begin @@ -201,12 +201,12 @@ package body Lists is It.Remain := It.Remain - 1; end Next; - function Get_Element (It : Iterator) return Node_Type is + function Get_Element (It : Iterator) return El_Type is begin return Chunkt.Table (It.Chunk).Els (It.Chunk_Idx); end Get_Element; - procedure Set_Element (It : Iterator; El : Node_Type) is + procedure Set_Element (It : Iterator; El : El_Type) is begin Chunkt.Table (It.Chunk).Els (It.Chunk_Idx) := El; end Set_Element; diff --git a/src/lists.ads b/src/lists.ads index fc015d84a..06fd601d9 100644 --- a/src/lists.ads +++ b/src/lists.ads @@ -16,8 +16,9 @@ -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. with Types; use Types; -with Vhdl.Nodes_Priv; use Vhdl.Nodes_Priv; +generic + type El_Type is range <>; package Lists is type List_Type is new Nat32; for List_Type'Size use 32; @@ -73,13 +74,13 @@ package Lists is procedure Initialize; -- Append ELEMENT to the list. It's an O(1) operation. - procedure Append_Element (List : List_Type; Element : Node_Type); + procedure Append_Element (List : List_Type; Element : El_Type); -- Return the first element of the list. - function Get_First_Element (List : List_Type) return Node_Type; + function Get_First_Element (List : List_Type) return El_Type; -- Append EL if not already in LIST. It's an O(n) operation. - procedure Add_Element (List : List_Type; El : Node_Type); + procedure Add_Element (List : List_Type; El : El_Type); -- Return the number of elements in the list. -- This is also 1 + the position of the last element. @@ -101,8 +102,8 @@ package Lists is function Iterate (List : List_Type) return Iterator; function Is_Valid (It : Iterator) return Boolean; procedure Next (It : in out Iterator); - function Get_Element (It : Iterator) return Node_Type; - procedure Set_Element (It : Iterator; El : Node_Type); + function Get_Element (It : Iterator) return El_Type; + procedure Set_Element (It : Iterator; El : El_Type); -- Use the C convention for all these subprograms, so that the Iterator is -- always passed by reference. @@ -123,7 +124,7 @@ private Chunk_Len : constant := 7; type Node_Type_Array is - array (Nat32 range 0 .. Chunk_Len - 1) of Node_Type; + array (Nat32 range 0 .. Chunk_Len - 1) of El_Type; type Chunk_Type is record Next : Chunk_Index_Type; diff --git a/src/vhdl/vhdl-lists.ads b/src/vhdl/vhdl-lists.ads new file mode 100644 index 000000000..6d16b81bf --- /dev/null +++ b/src/vhdl/vhdl-lists.ads @@ -0,0 +1,21 @@ +-- Variable-length lists. +-- Copyright (C) 2019 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 +-- Software Foundation; either version 2, or (at your option) any later +-- version. +-- +-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or +-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +-- for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with GHDL; see the file COPYING. If not, write to the Free +-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA +-- 02111-1307, USA. +with Vhdl.Types; +with Lists; + +package Vhdl.Lists is new Standard.Lists (El_Type => Vhdl.Types.Node); diff --git a/src/vhdl/vhdl-nodes.adb b/src/vhdl/vhdl-nodes.adb index e4c6c979e..007209b23 100644 --- a/src/vhdl/vhdl-nodes.adb +++ b/src/vhdl/vhdl-nodes.adb @@ -19,7 +19,7 @@ with Ada.Unchecked_Conversion; with Tables; with Logging; use Logging; -with Lists; use Lists; +with Vhdl.Lists; use Vhdl.Lists; with Vhdl.Nodes_Meta; use Vhdl.Nodes_Meta; with Vhdl.Nodes_Priv; use Vhdl.Nodes_Priv; diff --git a/src/vhdl/vhdl-nodes.adb.in b/src/vhdl/vhdl-nodes.adb.in index 1e9dd37c1..761676b3b 100644 --- a/src/vhdl/vhdl-nodes.adb.in +++ b/src/vhdl/vhdl-nodes.adb.in @@ -19,7 +19,7 @@ with Ada.Unchecked_Conversion; with Tables; with Logging; use Logging; -with Lists; use Lists; +with Vhdl.Lists; use Vhdl.Lists; with Vhdl.Nodes_Meta; use Vhdl.Nodes_Meta; with Vhdl.Nodes_Priv; use Vhdl.Nodes_Priv; diff --git a/src/vhdl/vhdl-nodes.ads b/src/vhdl/vhdl-nodes.ads index 80c0c80e3..261633812 100644 --- a/src/vhdl/vhdl-nodes.ads +++ b/src/vhdl/vhdl-nodes.ads @@ -19,7 +19,7 @@ with Ada.Unchecked_Deallocation; with Types; use Types; with Vhdl.Tokens; use Vhdl.Tokens; with Vhdl.Nodes_Priv; -with Lists; +with Vhdl.Lists; with Vhdl.Flists; package Vhdl.Nodes is -- cgit v1.2.3