------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2016, Frank Singhoff, Alain Plantec, Jerome Legrand -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285 laboratory, Université de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in AUTHORS.txt and SPONSORS.txt -- -- This program 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 of the License, or -- (at your option) any later version. -- -- This program 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 this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ------------------------------------------------------------------------------ -- Last update : -- $Rev: 1249 $ -- $Date: 2014-08-28 07:02:15 +0200 (Fri, 28 Aug 2014) $ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Ada.Exceptions; use Ada.Exceptions; with CFG_Nodes; use CFG_Nodes; with CFG_Nodes; use CFG_Nodes.CFG_Nodes_Table_Package; with Objects; use Objects; with Objects.extended; use Objects.extended; with Text_IO; use Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Integer_Arrays; use Integer_Arrays; with Translate; use Translate; with Tables; with CFG_Nodes.Extended; use CFG_Nodes.Extended; with sets; with CFG_Edges; use CFG_Edges; package body CFG_Set is -- In this package, we work with both CFG_Node_Table and CFG_Node_Set. -- The reason for that is because: -- + In the system, we use CFG_Node_Set -- + In the task, we use CFG_Node_Table -- We did by this way because this is the current implementation for other -- models of Cheddars such as processor and core_unit. ---------------------------------------------------- -- CHECK ---------------------------------------------------- procedure Check_CFG (name : in Unbounded_String; cfg_nodes_tbl : in CFG_Nodes_Table; cfg_edges_tbl : in CFG_Edges_Table) is begin if (name = "") then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_CFG (Current_Language) & Lb_Mandatory (Current_Language))); end if; if not Is_A_Valid_Identifier (Name) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_CFG (Current_Language) & Name & " : " & Lb_CFG_Name (Current_Language) & Lb_Colon & Lb_Invalid_Identifier (Current_Language))); end if; end Check_CFG; ---------------------------------------------------- -- ADD ---------------------------------------------------- procedure Add_CFG (my_cfgs : in out CFGs_Set; a_cfg : in out CFG_Ptr) is begin add(my_cfgs,a_cfg); end Add_CFG; procedure Add_CFG (my_cfgs : in out CFGs_Set; a_cfg : in out CFG_Ptr; name : in Unbounded_String; cfg_nodes_tbl : in CFG_Nodes_Table; cfg_edges_tbl : in CFG_Edges_Table) is my_iterator : CFGs_Iterator; begin Check_CFG(name, cfg_nodes_tbl, cfg_edges_tbl); if (get_number_of_elements (my_cfgs) > 0) then reset_iterator(my_cfgs,my_iterator); loop current_element(my_cfgs,a_cfg,my_iterator); if(name = a_cfg.name) then Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_CFG (Current_Language) & " " & Name & " : " & Lb_CFG_Name (Current_Language) & Lb_Already_Defined (Current_Language))); end if; exit when is_last_element (my_cfgs, my_iterator); next_element (my_cfgs, my_iterator); end loop; end if; a_cfg := new CFG; a_cfg.name := name; a_cfg.nodes := cfg_nodes_tbl; a_cfg.edges := cfg_edges_tbl; add(my_cfgs,a_cfg); exception when full_set => Raise_Exception (Invalid_Parameter'Identity, To_String (Lb_Can_Not_Define_More_CFG (Current_Language))); end Add_CFG; procedure Add_CFG (my_cfgs : in out CFGs_Set; name : in Unbounded_String; cfg_nodes_tbl : in CFG_Nodes_Table; cfg_edges_tbl : in CFG_Edges_Table) is a_cfg : CFG_Ptr; begin Add_CFG(my_cfgs => my_cfgs, a_cfg => a_cfg, name => name, cfg_nodes_tbl => cfg_nodes_tbl, cfg_edges_tbl => cfg_edges_tbl); end Add_CFG; ------------------------------------------------------ -- SEARCH ------------------------------------------------------ function Search_CFG (my_cfgs : in CFGs_Set; name : in Unbounded_String) return CFG_Ptr is my_iterator : CFGs_Iterator; a_cfg : CFG_Ptr; result : CFG_Ptr; found : Boolean := False; begin if not is_empty(my_cfgs) then reset_iterator(my_cfgs,my_iterator); loop current_element (my_cfgs, a_cfg, my_iterator); if (a_cfg.name = name) then found := True; result := a_cfg; end if; exit when is_last_element (my_cfgs,my_iterator); next_element (my_cfgs,my_iterator); end loop; end if; if not Found then Raise_Exception (CFG_Not_Found'Identity, To_String (Lb_CFG_Name (Current_Language) & "=" & Name)); end if; return Result; end Search_CFG; function Search_CFG_By_Id (my_cfgs : in CFGs_Set; id : in Unbounded_String) return CFG_Ptr is my_iterator : CFGs_Iterator; a_cfg : CFG_Ptr; result : CFG_Ptr; found : Boolean := False; begin if not is_empty(my_cfgs) then reset_iterator(my_cfgs,my_iterator); loop current_element (my_cfgs, a_cfg, my_iterator); if (a_cfg.cheddar_private_id = id) then found := True; result := a_cfg; end if; exit when is_last_element (my_cfgs,my_iterator); next_element (my_cfgs,my_iterator); end loop; end if; if not Found then Raise_Exception (CFG_Not_Found'Identity, To_String (Lb_CFG_Node_Name (Current_Language) & "=" & id)); end if; return Result; end Search_CFG_By_Id; end CFG_Set;