---------------------------------------------------------- ---------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . P N . R O O T -- -- -- -- B o d y -- -- -- -- Copyright (C) 2006, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina 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 distributed with Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Namet; with Ocarina.PN.Nodes; with Ocarina.PN.Nutils; package body Ocarina.PN.Root is ---------------------------- -- Create_PN_Declarations -- ---------------------------- procedure Create_PN_Declarations (PN_Root : Types.node_id) is use Types; use Namet; use Ocarina.PN.Nutils; use Ocarina.PN.Nodes; use Ocarina.AADL_Values; Decl, Val : node_id; begin -- Value Decl := Class_Value (PN_Root); Set_Symbolic_Values (Decl, New_List (k_list_id)); Val := New_Node (k_color_variable); Set_Str_To_Name_Buffer ("u"); Set_Value (Val, New_String_Value (Name_Find)); Append_Node_To_List (Val, Symbolic_Values (Decl)); Val := New_Node (k_color_variable); Set_Str_To_Name_Buffer ("d"); Set_Value (Val, New_String_Value (Name_Find)); Append_Node_To_List (Val, Symbolic_Values (Decl)); Append_Node_To_List (Decl, Color_Declarations (PN_Root)); -- Control Decl := Class_Control (PN_Root); Append_Node_To_List (Decl, Color_Declarations (PN_Root)); -- Comm Decl := Domain_Comm (PN_Root); Set_Classes (Decl, New_List (k_list_id)); Val := New_Node (k_color_variable); Set_Str_To_Name_Buffer ("Value"); Set_Value (Val, New_String_Value (Name_Find)); Append_Node_To_List (Val, Classes (Decl)); Val := New_Node (k_color_variable); Set_Str_To_Name_Buffer ("Control"); Set_Value (Val, New_String_Value (Name_Find)); Append_Node_To_List (Val, Classes (Decl)); Append_Node_To_List (Decl, Color_Declarations (PN_Root)); end Create_PN_Declarations; ------------------------ -- Declare_New_Thread -- ------------------------ function Declare_New_Thread (PN_Root : Types.node_id) return Ocarina.AADL_Values.value_type is use Types; use Ocarina.AADL_Values; use Ocarina.PN.Nodes; Nb : value_type; begin Nb := Get_Value_Type (Number_Of_Threads (PN_Root)); Nb.IVal := Nb.IVal + 1; Set_Value (Number_Of_Threads (PN_Root), Nb); return Nb; end Declare_New_Thread; ------------------------------ -- Get_New_Control_Variable -- ------------------------------ function Get_New_Control_Variable (PN_Root, Current_Variable : Types.node_id) return Types.node_id is use Types; use Namet; use Ocarina.PN.Nodes; use Ocarina.AADL_Values; use Ocarina.PN.Nutils; pragma assert (PN_Root /= No_Node and then Kind (PN_Root) = k_root_node); pragma assert (Current_Variable = No_Node or else Kind (Current_Variable) = k_color_variable); New_Var : node_id; Nb_Of_Vars : value_type; begin if Current_Variable = No_Node then New_Var := First_Node (Variables (Control_Variables (PN_Root))); else New_Var := Next_Node (Current_Variable); end if; if New_Var = No_Node then Nb_Of_Vars := Get_Value_Type (Number_Of_Control_Vars (PN_Root)); Nb_Of_Vars.IVal := Nb_Of_Vars.IVal + 1; Set_Value (Number_Of_Control_Vars (PN_Root), Nb_Of_Vars); New_Var := New_Node (k_color_variable); declare S : constant String := unsigned_long_long'image (Nb_Of_Vars.IVal); begin Set_Str_To_Name_Buffer ("c" & S (S'first + 1 .. S'last)); end; Set_Value (New_Var, New_String_Value (Name_Find)); Append_Node_To_List (New_Var, Variables (Control_Variables (PN_Root))); end if; return New_Var; end Get_New_Control_Variable; ---------------------------- -- Get_New_Value_Variable -- ---------------------------- function Get_New_Value_Variable (PN_Root, Current_Variable : Types.node_id) return Types.node_id is use Types; use Namet; use Ocarina.PN.Nodes; use Ocarina.AADL_Values; use Ocarina.PN.Nutils; pragma assert (PN_Root /= No_Node and then Kind (PN_Root) = k_root_node); pragma assert (Current_Variable = No_Node or else Kind (Current_Variable) = k_color_variable); New_Var : node_id; Nb_Of_Vars : value_type; begin if Current_Variable = No_Node then New_Var := First_Node (Variables (Value_Variables (PN_Root))); else New_Var := Next_Node (Current_Variable); end if; if New_Var = No_Node then Nb_Of_Vars := Get_Value_Type (Number_Of_Value_Vars (PN_Root)); Nb_Of_Vars.IVal := Nb_Of_Vars.IVal + 1; Set_Value (Number_Of_Value_Vars (PN_Root), Nb_Of_Vars); New_Var := New_Node (k_color_variable); declare S : constant String := unsigned_long_long'image (Nb_Of_Vars.IVal); begin Set_Str_To_Name_Buffer ("v" & S (S'first + 1 .. S'last)); end; Set_Value (New_Var, New_String_Value (Name_Find)); Append_Node_To_List (New_Var, Variables (Value_Variables (PN_Root))); end if; return New_Var; end Get_New_Value_Variable; -------------------- -- Make_Root_Node -- -------------------- function Make_Root_Node return Types.node_id is use Types; use Namet; use Ocarina.AADL_Values; use Ocarina.PN.Nutils; use Ocarina.PN.Nodes; PN_Root : constant node_id := New_Node (k_root_node); Decl, Ident : node_id; begin Set_Places (PN_Root, New_List (k_list_id)); Set_Arcs (PN_Root, New_List (k_list_id)); Set_Connections (PN_Root, New_List (k_list_id)); Set_Place_Fusions (PN_Root, New_List (k_list_id)); Set_Arc_Fusions (PN_Root, New_List (k_list_id)); Set_Subnets (PN_Root, New_List (k_list_id)); Set_Color_Declarations (PN_Root, New_List (k_list_id)); Set_Number_Of_Value_Vars (PN_Root, New_Integer_Value (0)); Set_Number_Of_Control_Vars (PN_Root, New_Integer_Value (0)); Set_Number_Of_Threads (PN_Root, New_Integer_Value (0)); -- Value Decl := New_Node (k_enumeration_class_declaration); Set_Str_To_Name_Buffer ("Value"); Ident := Make_Identifier (Decl, Name_Find); Set_Identifier (Decl, Ident); Set_Class_Value (PN_Root, Decl); -- Control Decl := New_Node (k_range_class_declaration); Set_Str_To_Name_Buffer ("Control"); Ident := Make_Identifier (Decl, Name_Find); Set_Identifier (Decl, Ident); Set_Lower_Value (Decl, New_Integer_Value (1)); Set_Higher_Value (Decl, Number_Of_Threads (PN_Root)); Set_Class_Control (PN_Root, Decl); -- Comm Decl := New_Node (k_domain_declaration); Set_Str_To_Name_Buffer ("Comm"); Ident := Make_Identifier (Decl, Name_Find); Set_Identifier (Decl, Ident); Set_Domain_Comm (PN_Root, Decl); -- Variables Set_Value_Variables (PN_Root, New_Node (k_variables_declaration)); Set_Variables (Value_Variables (PN_Root), New_List (k_list_id)); Set_Identifier (Value_Variables (PN_Root), Make_Identifier (Value_Variables (PN_Root), Name (Identifier (Class_Value (PN_Root))))); Append_Node_To_List (Value_Variables (PN_Root), Color_Declarations (PN_Root)); Set_Control_Variables (PN_Root, New_Node (k_variables_declaration)); Set_Variables (Control_Variables (PN_Root), New_List (k_list_id)); Set_Identifier (Control_Variables (PN_Root), Make_Identifier (Control_Variables (PN_Root), Name (Identifier (Class_Control (PN_Root))))); Append_Node_To_List (Control_Variables (PN_Root), Color_Declarations (PN_Root)); return PN_Root; end Make_Root_Node; end Ocarina.PN.Root;