Commit 4e247c44 authored by yoogx's avatar yoogx
Browse files

* First part of the air_conf backend, generation of AIR XML

          configuration file

          For openaadl/ocarina#160
parent 909bd0a4
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- OCARINA.BACKENDS.AIR_CONF.AIR_CONFIGURATION --
-- --
-- B o d y --
-- --
-- Copyright (C) 2018 ESA & ISAE. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- Ocarina is maintained by the TASTE project --
-- (taste-users@lists.tuxfamily.org) --
-- --
------------------------------------------------------------------------------
with Ocarina.Namet; use Ocarina.Namet;
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Utils;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
package body Ocarina.Backends.AIR_Conf.AIR_Configuration is
use Ocarina.ME_AADL;
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.Backends.Utils;
use Ocarina.Backends.XML_Tree.Nutils;
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
procedure Visit_Architecture_Instance (E : Node_Id);
procedure Visit_Component_Instance (E : Node_Id);
procedure Visit_System_Instance (E : Node_Id);
procedure Visit_Processor_Instance (E : Node_Id);
procedure Visit_Subcomponents_Of is new Visit_Subcomponents_Of_G (Visit);
-----------
-- Visit --
-----------
procedure Visit (E : Node_Id) is
begin
case Kind (E) is
when K_Architecture_Instance =>
Visit_Architecture_Instance (E);
when K_Component_Instance =>
Visit_Component_Instance (E);
when others =>
null;
end case;
end Visit;
---------------------------------
-- Visit_Architecture_Instance --
---------------------------------
procedure Visit_Architecture_Instance (E : Node_Id) is
begin
Visit (Root_System (E));
end Visit_Architecture_Instance;
------------------------------
-- Visit_Component_Instance --
------------------------------
procedure Visit_Component_Instance (E : Node_Id) is
Category : constant Component_Category := Get_Category_Of_Component (E);
begin
case Category is
when CC_System =>
Visit_System_Instance (E);
when CC_Processor =>
Visit_Processor_Instance (E);
when others =>
null;
end case;
end Visit_Component_Instance;
---------------------------
-- Visit_System_Instance --
---------------------------
procedure Visit_System_Instance (E : Node_Id) is
U : Node_Id;
R : Node_Id;
begin
U := XTN.Unit (Backend_Node (Identifier (E)));
R := XTN.Node (Backend_Node (Identifier (E)));
Current_XML_Node := XTN.Root_Node (XTN.XML_File (U));
Push_Entity (U);
Push_Entity (R);
Visit_Subcomponents_Of (E);
Pop_Entity;
Pop_Entity;
end Visit_System_Instance;
procedure Map_AIR_Configuration_Node (E : Node_Id)
with Pre => (Get_Category_Of_Component (E) = CC_Processor);
--------------------------------
-- Map_AIR_Configuration_Node --
--------------------------------
procedure Map_AIR_Configuration_Node (E : Node_Id) is
AIR_Configuration_Node : Node_Id;
P : Node_Id;
Q : Node_Id;
begin
Append_Node_To_List
(Make_XML_Comment (Get_String_Name ("Module configuration")),
XTN.Subitems (Current_XML_Node));
-- Create the AIR_Configuration node
AIR_Configuration_Node := Make_XML_Node ("AIR_Configuration");
Set_Str_To_Name_Buffer ("TicksPerSecond");
P := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("200"); -- XXX Hardcoded ?
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List
(Make_Assignement (P, Q),
XTN.Items (AIR_Configuration_Node));
Set_Str_To_Name_Buffer ("RequiredCores");
P := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("1"); -- XXX Hardcoded ?
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List
(Make_Assignement (P, Q),
XTN.Items (AIR_Configuration_Node));
Append_Node_To_List
(AIR_Configuration_Node,
XTN.Subitems (Current_XML_Node));
end Map_AIR_Configuration_Node;
------------------------------
-- Visit_Processor_Instance --
------------------------------
procedure Visit_Processor_Instance (E : Node_Id) is
begin
Map_Air_Configuration_Node (E);
Visit_Subcomponents_Of (E);
end Visit_Processor_Instance;
end Ocarina.Backends.AIR_Conf.AIR_Configuration;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- OCARINA.BACKENDS.AIR_CONF.AIR_CONFIGURATION --
-- --
-- S p e c --
-- --
-- Copyright (C) 2018 ESA & ISAE. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- Ocarina is maintained by the TASTE project --
-- (taste-users@lists.tuxfamily.org) --
-- --
------------------------------------------------------------------------------
package Ocarina.Backends.AIR_Conf.AIR_Configuration is
procedure Visit (E : Node_Id);
end Ocarina.Backends.AIR_Conf.AIR_Configuration;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . A I R _ C O N F . M A P P I N G --
-- --
-- B o d y --
-- --
-- Copyright (C) 2018 ESA & ISAE. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- Ocarina is maintained by the TASTE project --
-- (taste-users@lists.tuxfamily.org) --
-- --
------------------------------------------------------------------------------
with Ocarina.Namet; use Ocarina.Namet;
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Utils;
with Ocarina.Backends.XML_Common.Mapping;
with Ocarina.Backends.XML_Values;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
package body Ocarina.Backends.AIR_Conf.Mapping is
use Ocarina.ME_AADL;
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.Backends.Utils;
use Ocarina.Backends.XML_Common.Mapping;
use Ocarina.Backends.XML_Tree.Nodes;
use Ocarina.Backends.XML_Tree.Nutils;
package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
package XV renames Ocarina.Backends.XML_Values;
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
-------------------
-- Map_Scheduler --
-------------------
procedure Map_Scheduler (E : Node_Id; N : Node_Id) is
Scheduler : Supported_POK_Scheduler;
R : Node_Id;
Q : Node_Id;
begin
Scheduler := Get_POK_Scheduler (E);
Set_Str_To_Name_Buffer ("scheduler");
R := Make_Defining_Identifier (Name_Find);
if Scheduler = RMS then
Set_Str_To_Name_Buffer ("rms");
elsif Scheduler = EDF then
Set_Str_To_Name_Buffer ("edf");
elsif Scheduler = Static then
Set_Str_To_Name_Buffer ("static");
else
Set_Str_To_Name_Buffer ("unknown");
end if;
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (R, Q), XTN.Items (N));
end Map_Scheduler;
---------------------------------
-- Map_Distributed_Application --
---------------------------------
function Map_Distributed_Application (E : Node_Id) return Node_Id is
D : constant Node_Id := New_Node (XTN.K_HI_Distributed_Application);
begin
pragma Assert (AINU.Is_System (E) or else AINU.Is_Processor (E));
-- Update the global variable to be able to fetch the root of
-- the distributed application and generate the source files.
XML_Root := D;
XTN.Set_Name (D, To_XML_Name (AIN.Name (AIN.Identifier (E))));
XTN.Set_Units (D, New_List (XTN.K_List_Id));
XTN.Set_HI_Nodes (D, New_List (XTN.K_List_Id));
return D;
end Map_Distributed_Application;
-----------------
-- Map_HI_Node --
-----------------
function Map_HI_Node (E : Node_Id) return Node_Id is
N : constant Node_Id := New_Node (XTN.K_HI_Node);
begin
pragma Assert
(AINU.Is_Process (E)
or else AINU.Is_System (E)
or else AINU.Is_Processor (E));
if AINU.Is_System (E) then
Set_Str_To_Name_Buffer ("general");
else
Get_Name_String
(To_XML_Name
(AIN.Name (AIN.Identifier (AIN.Parent_Subcomponent (E)))));
Add_Str_To_Name_Buffer ("_arinc653");
end if;
XTN.Set_Name (N, Name_Find);
Set_Units (N, New_List (K_List_Id));
-- Append the partition N to the node list
Append_Node_To_List (N, HI_Nodes (Current_Entity));
Set_Distributed_Application (N, Current_Entity);
return N;
end Map_HI_Node;
-----------------
-- Map_HI_Unit --
-----------------
function Map_HI_Unit (E : Node_Id) return Node_Id is
U : Node_Id;
N : Node_Id;
P : Node_Id;
Q : Node_Id;
R : Node_Id;
Root : Node_Id;
begin
pragma Assert
(AINU.Is_System (E)
or else AINU.Is_Process (E)
or else AINU.Is_Processor (E));
U := New_Node (XTN.K_HI_Unit, AIN.Identifier (E));
-- XML Configuration file
Get_Name_String (To_XML_Name (Display_Name (Identifier (E))));
Add_Str_To_Name_Buffer ("_air-conf");
N := Make_Defining_Identifier (Name_Find);
P := Make_XML_File (N);
Set_Distributed_Application_Unit (P, U);
XTN.Set_XML_File (U, P);
-- Root of the XML Configuration file
Root := Make_XML_Node ("ARINC_653_Module");
Set_Str_To_Name_Buffer ("xmlns:xsi");
R := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("http://www.w3.org/2001/XMLSchema-instance");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (R, Q), XTN.Items (Root));
Set_Str_To_Name_Buffer ("ModuleName");
R := Make_Defining_Identifier (Name_Find);
Get_Name_String (To_XML_Name (Display_Name (Identifier (E))));
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (R, Q), XTN.Items (Root));
XTN.Set_Root_Node (P, Root);
Append_Node_To_List (U, Units (Current_Entity));
XTN.Set_Entity (U, Current_Entity);
return U;
end Map_HI_Unit;
-------------------------
-- Map_Port_Connection --
-------------------------
function Map_Port_Connection (E : Node_Id) return Node_Id is
N : Node_Id;
R : Node_Id;
Q : Node_Id;
Src : Node_Id;
Dst : Node_Id;
begin
N := Make_XML_Node ("Connection");
Set_Str_To_Name_Buffer ("type");
R := Make_Defining_Identifier (Name_Find);
if Get_Category_Of_Connection (E) = CT_Data then
if Get_Category_Of_Connection (E) = CT_Event then
Set_Str_To_Name_Buffer ("eventdata");
else
Set_Str_To_Name_Buffer ("data");
end if;
elsif Get_Category_Of_Connection (E) = CT_Event then
Set_Str_To_Name_Buffer ("event");
end if;
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (R, Q), XTN.Items (N));
Src := Item (AIN.First_Node (Path (Source (E))));
Dst := Item (AIN.First_Node (Path (Destination (E))));
R :=
Make_Defining_Identifier
(To_XML_Name (Display_Name (Identifier (Src))));
Set_Str_To_Name_Buffer ("src");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, R), XTN.Items (N));
R :=
Make_Defining_Identifier
(To_XML_Name (Display_Name (Identifier (Dst))));
Set_Str_To_Name_Buffer ("dst");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, R), XTN.Items (N));
return N;
end Map_Port_Connection;
--------------------
-- Map_Bus_Access --
--------------------
function Map_Bus_Access (E : Node_Id) return Node_Id is
N : Node_Id;
R : Node_Id;
Q : Node_Id;
Src : Node_Id;
Dst : Node_Id;
begin
N := Make_XML_Node ("access");
Set_Str_To_Name_Buffer ("type");
R := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("bus");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (R, Q), XTN.Items (N));
Src := Item (AIN.First_Node (Path (Source (E))));
Dst := Item (AIN.First_Node (Path (Destination (E))));
R :=
Make_Defining_Identifier
(To_XML_Name (Display_Name (Identifier (Src))));
Set_Str_To_Name_Buffer ("src");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, R), XTN.Items (N));
R :=
Make_Defining_Identifier
(To_XML_Name (Display_Name (Identifier (Dst))));
Set_Str_To_Name_Buffer ("dst");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, R), XTN.Items (N));
return N;
end Map_Bus_Access;
---------------------
-- Map_Data_Access --
---------------------
function Map_Data_Access (E : Node_Id) return Node_Id is
N : Node_Id;
R : Node_Id;
Q : Node_Id;
Src : Node_Id;
Dst : Node_Id;
begin
N := Make_XML_Node ("access");
Set_Str_To_Name_Buffer ("type");
R := Make_Defining_Identifier (Name_Find);
Set_Str_To_Name_Buffer ("data");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (R, Q), XTN.Items (N));
Src := Item (AIN.First_Node (Path (Source (E))));
Dst := Item (AIN.First_Node (Path (Destination (E))));
R :=
Make_Defining_Identifier
(To_XML_Name (Display_Name (Identifier (Src))));
Set_Str_To_Name_Buffer ("src");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, R), XTN.Items (N));
R :=
Make_Defining_Identifier
(To_XML_Name (Display_Name (Identifier (Dst))));
Set_Str_To_Name_Buffer ("dst");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, R), XTN.Items (N));
return N;
end Map_Data_Access;
----------------
-- Map_System --
----------------
function Map_System (E : Node_Id) return Node_Id is
N : Node_Id;
Q : Node_Id;
P : Node_Id;
begin
N := Make_XML_Node ("ARINC653_Module");
-- Set the name of the system
P := Make_Defining_Identifier (To_XML_Name (AIN.Name (Identifier (E))));
Set_Str_To_Name_Buffer ("ModuleName");
Q := Make_Defining_Identifier (Name_Find);
Append_Node_To_List (Make_Assignement (Q, P), XTN.Items (N));
return N;
end Map_System;
-----------------
-- Map_Process --
-----------------
function Map_Process
(E : Node_Id;
Partition_Identifier : Unsigned_Long_Long) return Node_Id
is
N : Node_Id;
P : Node_Id;
Q : Node_Id;
begin
N := Make_XML_Node ("Partition");
P :=