------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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-2020, Frank Singhoff, Alain Plantec, Jerome Legrand, -- Hai Nam Tran, Stephane Rubini -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285, 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: 3657 $ -- $Date: 2020-12-13 13:25:49 +0100 (dim. 13 déc. 2020) $ -- $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 cfg_node_set; use cfg_node_set; with execution_units; use execution_units; with execution_units; use execution_units.execution_units_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 sets; with cfg_edge_set; use cfg_edge_set; with cfg_edges; use cfg_edges; package body cfg_node_set.execution_unit_set is ---------------------------------------------------- -- CHECK - execution_unit ---------------------------------------------------- procedure check_execution_unit (name : in Unbounded_String; A_Execution_Unit_Record : in Execution_Unit_Record) is begin if (name = "") then Raise_Exception (invalid_parameter'identity, To_String (lb_cfg_node (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_node (current_language) & name & " : " & lb_cfg_node_name (current_language) & lb_colon & lb_invalid_identifier (current_language))); end if; if A_Execution_Unit_Record.Capacity < 0 then Raise_Exception (invalid_parameter'identity, To_String (lb_cfg_node (current_language) & " " & name & " : " & lb_Capacity (current_language) & lb_must_be (current_language) & To_Unbounded_String (" >= 1"))); end if; end check_execution_unit; ---------------------------------------------------- -- ADD - execution_unit ---------------------------------------------------- procedure add_execution_unit (my_execution_units : in out execution_units_set; a_execution_unit : in out execution_unit_ptr; name : in Unbounded_String; A_Execution_Unit_Record : in Execution_Unit_Record) is my_iterator : execution_units_iterator; begin check_execution_unit (name, A_Execution_Unit_Record); if (get_number_of_elements (my_execution_units) > 1) then reset_iterator (my_execution_units, my_iterator); loop current_element (my_execution_units, a_execution_unit, my_iterator); if name = a_execution_unit.name then Raise_Exception (invalid_parameter'identity, To_String (lb_cfg_node (current_language) & " " & name & " : " & lb_cfg_node_name (current_language) & lb_already_defined (current_language))); end if; exit when is_last_element (my_execution_units, my_iterator); next_element (my_execution_units, my_iterator); end loop; end if; a_execution_unit := new execution_unit; a_execution_unit.name := name; a_execution_unit.Unit_type := A_Execution_Unit_Record.Unit_type; a_execution_unit.Time_Constraint_Name := A_Execution_Unit_Record.Time_Constraint_Name; a_execution_unit.Capacity := A_Execution_Unit_Record.Capacity; a_execution_unit.node_type := A_Execution_Unit_Record.node_type; a_execution_unit.graph_type := A_Execution_Unit_Record.graph_type; add (my_execution_units, a_execution_unit); exception when cfg_node_set.full_set => Raise_Exception (invalid_parameter'identity, To_String (lb_can_not_define_more_cfg_node (current_language))); end add_execution_unit; procedure add_execution_unit (my_execution_units : in out execution_units_set; name : in Unbounded_String; A_Execution_Unit_Record : in Execution_Unit_Record) is a_execution_unit : execution_unit_ptr; begin add_execution_unit (my_execution_units => my_execution_units, a_execution_unit => a_execution_unit, name => name, A_Execution_Unit_Record => A_Execution_Unit_Record); exception when cfg_node_set.full_set => Raise_Exception (invalid_parameter'identity, To_String (lb_can_not_define_more_cfg_node (current_language))); end add_execution_unit; procedure add_execution_unit (my_cfg_nodes : in out cfg_nodes_set; a_cfg_node : in out cfg_node_ptr; name : in Unbounded_String; A_Execution_Unit_Record : in Execution_Unit_Record) is a_execution_unit : execution_unit_ptr; my_iterator : cfg_nodes_iterator; begin check_execution_unit (name, A_Execution_Unit_Record); if (get_number_of_elements (my_cfg_nodes) > 1) then reset_iterator (my_cfg_nodes, my_iterator); loop current_element (my_cfg_nodes, a_cfg_node, my_iterator); if name = a_cfg_node.name then Raise_Exception (invalid_parameter'identity, To_String (lb_cfg_node (current_language) & " " & name & " : " & lb_cfg_node_name (current_language) & lb_already_defined (current_language))); end if; exit when is_last_element (my_cfg_nodes, my_iterator); next_element (my_cfg_nodes, my_iterator); end loop; end if; a_execution_unit := new execution_unit; a_execution_unit.name := name; a_execution_unit.Unit_type := A_Execution_Unit_Record.Unit_type; a_execution_unit.Time_Constraint_Name := A_Execution_Unit_Record.Time_Constraint_Name; a_execution_unit.Capacity := A_Execution_Unit_Record.Capacity; a_execution_unit.node_type := A_Execution_Unit_Record.node_type; a_execution_unit.graph_type := A_Execution_Unit_Record.graph_type; a_cfg_node := cfg_node_ptr (a_execution_unit); add (my_cfg_nodes, a_cfg_node); exception when cfg_node_set.full_set => Raise_Exception (invalid_parameter'identity, To_String (lb_can_not_define_more_cfg_node (current_language))); end add_execution_unit; procedure add_execution_unit (my_cfg_nodes : in out cfg_nodes_set; name : in Unbounded_String; A_Execution_Unit_Record : in Execution_Unit_Record) is a_cfg_node : cfg_node_ptr; begin add_execution_unit (my_cfg_nodes => my_cfg_nodes, a_cfg_node => a_cfg_node, name => name, A_Execution_Unit_Record => A_Execution_Unit_Record); exception when cfg_node_set.full_set => Raise_Exception (invalid_parameter'identity, To_String (lb_can_not_define_more_cfg_node (current_language))); end add_execution_unit; ------------------------------------------------------ -- UPDATE - execution_unit ------------------------------------------------------ procedure update_execution_unit (my_execution_units : in out execution_units_set; name : in Unbounded_String; A_Execution_Unit_Record : in Execution_Unit_Record) is a_execution_unit : execution_unit_ptr; begin a_execution_unit := search_execution_unit (my_execution_units, name); delete_execution_unit (my_execution_units, a_execution_unit); add_execution_unit (my_execution_units => my_execution_units, a_execution_unit => a_execution_unit, name => name, A_Execution_Unit_Record => A_Execution_Unit_Record); end update_execution_unit; ------------------------------------------------------ -- SEARCH ------------------------------------------------------ function search_execution_unit (my_execution_units : in execution_units_set; name : in Unbounded_String) return execution_unit_ptr is my_iterator : execution_units_iterator; a_execution_unit : execution_unit_ptr; result : execution_unit_ptr; found : Boolean := False; begin if not is_empty (my_execution_units) then reset_iterator (my_execution_units, my_iterator); loop current_element (my_execution_units, a_execution_unit, my_iterator); if (a_execution_unit.name = name) then found := True; result := a_execution_unit; end if; exit when is_last_element (my_execution_units, my_iterator); next_element (my_execution_units, my_iterator); end loop; end if; if not found then Raise_Exception (cfg_node_not_found'identity, To_String (lb_cfg_node_name (current_language) & "=" & name)); end if; return result; end search_execution_unit; function search_execution_unit_by_id (my_execution_units : in execution_units_set; id : in Unbounded_String) return execution_unit_ptr is my_iterator : execution_units_iterator; a_execution_unit : execution_unit_ptr; result : execution_unit_ptr; found : Boolean := False; begin if not is_empty (my_execution_units) then reset_iterator (my_execution_units, my_iterator); loop current_element (my_execution_units, a_execution_unit, my_iterator); if (a_execution_unit.cheddar_private_id = id) then found := True; result := a_execution_unit; end if; exit when is_last_element (my_execution_units, my_iterator); next_element (my_execution_units, my_iterator); end loop; end if; if not found then Raise_Exception (cfg_node_not_found'identity, To_String (lb_cfg_node_name (current_language) & "=" & id)); end if; return result; end search_execution_unit_by_id; ------------------------------------------------------ -- DELETE ------------------------------------------------------ procedure delete_execution_unit (my_execution_units : in out execution_units_set; a_execution_unit : in out execution_unit_ptr) is begin delete (my_execution_units, a_execution_unit); end delete_execution_unit; procedure delete_execution_unit (my_execution_units : in out execution_units_set; name : in Unbounded_String) is a_execution_unit : execution_unit_ptr; begin a_execution_unit := search_execution_unit (my_execution_units, name); delete (my_execution_units, a_execution_unit); end delete_execution_unit; end cfg_node_set.execution_unit_set;