Commit 8178b1ff authored by jhugues's avatar jhugues
Browse files

* Initial import of the AADL to XML backend



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@3192 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 4564a110
......@@ -388,6 +388,7 @@ AC_OUTPUT([
resources/behavioural_properties/Makefile
resources/runtime/Makefile
resources/runtime/cheddar/Makefile
resources/runtime/aadl_xml/Makefile
projects/ocarina.gpr
src/main/Makefile
src/main/ocarina-configuration.adb
......
SUBDIRS = cheddar
SUBDIRS = cheddar aadl_xml
@DEBUG_FALSE@DEBUG_FLAG = --disable-debug
@DEBUG_TRUE@DEBUG_FLAG = --enable-debug
......
AUTOMAKE_OPTIONS = no-dependencies
AADL_XML_FILES = $(srcdir)/aadl.xsd
EXTRA_DIST = $(AADL_XML_FILES)
aadl_xml_xsd = ${shell $(CYGPATH_U) '$(includedir)/ocarina/runtime/aadl_xml'}
install-data-local:
$(INSTALL) -d $(DESTDIR)$(aadl_xml_xsd)
for f in $(AADL_XML_FILES); do $(INSTALL) -m 444 $$f $(DESTDIR)$(aadl_xml_xsd) ; done
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- AADL XML Root node -->
<xs:element name='aadl_xml'>
<xs:annotation>
<xs:documentation>
This node is the root of the XML tree, defining
* A root_system element as the root of the instance tree;
* A list of components
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='components'/>
</xs:sequence>
<xs:attribute name='root_system' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
<xs:element name='components'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='component'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name='component'>
<xs:complexType>
<xs:sequence>
<xs:element ref='classifier'/>
<xs:sequence minOccurs='0' maxOccurs='1'>
<xs:element ref='features'/>
</xs:sequence>
<xs:sequence minOccurs='0' maxOccurs='1'>
<xs:element ref='subcomponents'/>
</xs:sequence>
<xs:sequence minOccurs='0' maxOccurs='1'>
<xs:element ref='connections'/>
</xs:sequence>
<xs:sequence minOccurs='0' maxOccurs='1'>
<xs:element ref='properties'/>
</xs:sequence>
<xs:sequence minOccurs='0' maxOccurs='1'>
<xs:element ref='flows'/>
</xs:sequence>
<xs:sequence minOccurs='0' maxOccurs='1'>
<xs:element ref='modes'/>
</xs:sequence>
<xs:sequence minOccurs='0' maxOccurs='1'>
<xs:element ref='annexes'/>
</xs:sequence>
</xs:sequence>
<xs:attribute name='category' use='required'>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value='abstract'/>
<xs:enumeration value='bus'/>
<xs:enumeration value='data'/>
<xs:enumeration value='device'/>
<xs:enumeration value='process'/>
<xs:enumeration value='processor'/>
<xs:enumeration value='thread'/>
<xs:enumeration value='port'/>
<xs:enumeration value='subprogram'/>
<xs:enumeration value='system'/>
<xs:enumeration value='virtual_bus'/>
<xs:enumeration value='virtual_processor'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name='identifier' type="xs:string" use='optional'/>
</xs:complexType>
</xs:element>
<xs:element name='classifier'>
<xs:complexType mixed='true'>
</xs:complexType>
</xs:element>
<xs:element name='features'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='feature'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name='feature'>
<xs:complexType>
<xs:sequence>
<xs:element ref='direction'/>
<xs:element ref='type'/>
<xs:element ref='classifier' minOccurs='0' maxOccurs='1'/>
<xs:element ref='properties' minOccurs='0' maxOccurs='1'/>
</xs:sequence>
<xs:attribute name='identifier' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
<xs:element name='direction'>
<xs:complexType>
<xs:attribute name='kind' use='required'>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value='in'/>
<xs:enumeration value='out'/>
<xs:enumeration value='in_out'/>
<xs:enumeration value='none'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name='type'>
<xs:complexType>
<xs:attribute name='kind' use='required'>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value='access'/>
<xs:enumeration value='data'/>
<xs:enumeration value='event'/>
<xs:enumeration value='event_data'/>
<xs:enumeration value='feature'/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name='subcomponents'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='component'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- Connections -->
<xs:element name='connections'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='connection'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name='connection'>
<xs:complexType>
<xs:sequence>
<xs:element ref='src' minOccurs='1' maxOccurs='1'/>
<xs:element ref='dst' minOccurs='1' maxOccurs='1'/>
<xs:element ref='properties' minOccurs='0' maxOccurs='1'/>
</xs:sequence>
<xs:attribute name='name' type="xs:string" use='optional'/>
</xs:complexType>
</xs:element>
<xs:element name='src'>
<xs:complexType>
<xs:attribute name='component' type="xs:string" use='required'/>
<xs:attribute name='feature' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
<xs:element name='dst'>
<xs:complexType>
<xs:attribute name='component' type="xs:string" use='required'/>
<xs:attribute name='feature' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
<!-- Properties -->
<xs:element name='properties'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='property'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name='property'>
<xs:complexType>
<xs:sequence minOccurs='1' maxOccurs='unbounded'>
<xs:element ref='property_value'/>
</xs:sequence>
<xs:attribute name='name' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
<xs:element name="property_value">
<xs:complexType>
<xs:choice>
<xs:element name="classifier" type="classifier_prop"/>
<xs:element name="reference" type="reference_prop"/>
<xs:element name="unit" type="unit_prop"/>
<xs:element name="value" type="value_prop"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name='classifier_prop'>
<xs:attribute name='name' type="xs:string" use='required'/>
</xs:complexType>
<xs:complexType name='unit_prop'>
<xs:attribute name='value' type="xs:string" use='required'/>
<xs:attribute name='unit' type="xs:string" use='required'/>
</xs:complexType>
<xs:complexType name='value_prop'>
<xs:attribute name='value' type="xs:string" use='required'/>
</xs:complexType>
<xs:complexType name='reference_prop'>
<xs:attribute name='value' type="xs:string" use='required'/>
</xs:complexType>
<!-- Modes -->
<xs:element name='modes'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='mode'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name='mode'>
<xs:complexType>
<xs:attribute name='name' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
<!-- Flows -->
<xs:element name='flows'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='flow'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name='flow'>
<xs:complexType>
<xs:attribute name='name' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
<!-- Annexes -->
<xs:element name='annexes'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:element ref='annex'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- To be completed -->
<xs:element name='annex'>
<xs:complexType>
<xs:sequence maxOccurs='unbounded'>
<xs:any minOccurs="0"/>
</xs:sequence>
<xs:attribute name='name' type="xs:string" use='required'/>
</xs:complexType>
</xs:element>
</xs:schema>
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . A A D L _ X M L . M A I N --
-- --
-- B o d y --
-- --
-- Copyright (C) 2011, European Space Agency (ESA). --
-- --
-- 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; use Namet;
with Ocarina.Instances.Queries; use Ocarina.Instances.Queries;
with Ocarina.AADL_Values;
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
with Ocarina.Backends.AADL_XML.Mapping;
package body Ocarina.Backends.AADL_XML.Main is
use Ocarina.ME_AADL;
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.Backends.XML_Tree.Nutils;
use Ocarina.Backends.AADL_XML.Mapping;
package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
use type ATN.Node_Kind;
procedure Visit_Component (E : Node_Id);
procedure Visit_Subcomponents_Of (E : Node_Id);
function Map_Component (E : Node_Id) return Node_Id;
-------------------
-- Map_Component --
-------------------
function Map_Component (E : Node_Id) return Node_Id is
Category_Name_String : constant array (Component_Category'Range)
of Name_Id :=
(CC_Abstract => Get_String_Name ("abstract"),
CC_Bus => Get_String_Name ("bus"),
CC_Data => Get_String_Name ("data"),
CC_Device => Get_String_Name ("device"),
CC_Memory => Get_String_Name ("memory"),
CC_Process => Get_String_Name ("process"),
CC_Processor => Get_String_Name ("processor"),
CC_Subprogram => Get_String_Name ("subprogram"),
CC_Subprogram_Group => Get_String_Name ("subprogram group"),
CC_System => Get_String_Name ("system"),
CC_Thread => Get_String_Name ("thread"),
CC_Thread_Group => Get_String_Name ("thread group"),
CC_Unknown => No_Name,
CC_Virtual_Bus => Get_String_Name ("virtual bus"),
CC_Virtual_Processor => Get_String_Name ("virtual processor"));
N : Node_Id;
Classifier_Node : Node_Id;
begin
N := Make_XML_Node ("component");
-- Category
Append_Node_To_List
(Make_Assignement
(Make_Defining_Identifier (Get_String_Name ("category")),
Make_Defining_Identifier
(Category_Name_String (Get_Category_Of_Component (E)))),
XTN.Items (N));
-- Identifier
if Present (Parent_Subcomponent (E)) then
Append_Node_To_List
(Make_Assignement
(Make_Defining_Identifier (Get_String_Name ("identifier")),
Make_Defining_Identifier
(Display_Name (Identifier (Parent_Subcomponent (E))))),
XTN.Items (N));
else
Append_Node_To_List
(Make_Assignement
(Make_Defining_Identifier (Get_String_Name ("identifier")),
Make_Defining_Identifier
(Display_Name (Identifier (E)))),
XTN.Items (N));
end if;
-- Classifier
Classifier_Node := Make_XML_Node ("classifier");
Append_Node_To_List
(Make_Defining_Identifier
(Display_Name (Identifier (E))),
XTN.Subitems (Classifier_Node));
Append_Node_To_List (Classifier_Node, XTN.Subitems (N));
return N;
end Map_Component;
----------------------------
-- Visit_Subcomponents_Of --
----------------------------
procedure Visit_Subcomponents_Of (E : Node_Id) is
S : Node_Id;
begin
if not AINU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E));
while Present (S) loop
-- Visit the component instance corresponding to the
-- subcomponent S.
Visit (Corresponding_Instance (S));
S := Next_Node (S);
end loop;
end if;
end Visit_Subcomponents_Of;
Root_System_Node : Node_Id := No_Node;
AADL_XML_Node : Node_Id := No_Node;
Current_XML_Node : Node_Id := No_Node;
-----------
-- Visit --
-----------
procedure Visit (E : Node_Id) is
begin
case Kind (E) is
when K_Architecture_Instance =>
Root_System_Node := Root_System (E);
Visit (Root_System_Node);
when K_Component_Instance =>
Visit_Component (E);
when others =>
null;
end case;
end Visit;
---------------------
-- Visit_Component --
---------------------
procedure Visit_Component (E : Node_Id) is
Category : constant Component_Category
:= Get_Category_Of_Component (E);
N : Node_Id;
Old_XML_Node : Node_Id;
Subcomponents_Node : Node_Id;
Features_Node : Node_Id;
Properties_Node : Node_Id;
Feature_Node : Node_Id;
F : Node_Id;
P : Node_Id;
U : Node_Id;
Property_Node : Node_Id;
Components_Node : Node_Id;
Property_Value_Node : Node_Id;
AADL_Property_Value : Node_Id;
begin
if Category = CC_System then
P := Map_HI_Node (E);
Push_Entity (P);
U := Map_HI_Unit (E);
Push_Entity (U);
if AADL_XML_Node = No_Node then
AADL_XML_Node := Make_XML_Node ("aadl_xml");
Append_Node_To_List
(Make_Assignement
(Make_Defining_Identifier (Get_String_Name ("root_system")),
Make_Defining_Identifier
(Display_Name (Identifier (Root_System_Node)))),
XTN.Items (AADL_XML_Node));
Append_Node_To_List
(AADL_XML_Node, XTN.Subitems (XTN.Root_Node (XTN.XML_File (U))));
Components_Node := Make_XML_Node ("components");
Append_Node_To_List
(Components_Node, XTN.Subitems (AADL_XML_Node));
end if;
Current_XML_Node := Components_Node;
end if;
-- First bits of the component node
N := Map_Component (E);
Append_Node_To_List (N, XTN.Subitems (Current_XML_Node));
-- Features
Features_Node := Make_XML_Node ("features");
Append_Node_To_List (Features_Node, XTN.Subitems (N));
if Present (Features (E)) then
F := First_Node (Features (E));
while Present (F) loop
Feature_Node := Make_XML_Node ("feature");
-- Identifier
Append_Node_To_List
(Make_Assignement
(Make_Defining_Identifier (Get_String_Name ("identifier")),
Make_Defining_Identifier
(Display_Name (Identifier (F)))),
XTN.Items (Feature_Node));
-- Direction: in/out/inout
declare
Direction_Node : Node_Id;
Direction_Kind : Name_Id;
begin
Direction_Node := Make_XML_Node ("direction");
if Kind (F) = K_Port_Spec_Instance then
if Is_In (F) and then not Is_Out (F) then
Direction_Kind := Get_String_Name ("in");
elsif (not Is_In (F)) and then Is_Out (F) then
Direction_Kind := Get_String_Name ("out");
elsif Is_In (F) and then Is_Out (F) then
Direction_Kind := Get_String_Name ("inout");
end if;
else
Direction_Kind := Get_String_Name ("none");
end if;
Append_Node_To_List
(Make_Assignement
(Make_Defining_Identifier (Get_String_Name ("kind")),
Make_Defining_Identifier (Direction_Kind)),
XTN.Items (Direction_Node));
Append_Node_To_List
(Direction_Node, XTN.Subitems (Feature_Node));
end;
-- Type: event/data/event data
declare
Type_Node : Node_Id;
Type_Kind : Name_Id;
begin
Type_Node := Make_XML_Node ("type");
if Kind (F) = K_Port_Spec_Instance then
if Is_Event (F) and then not Is_Data (F) then
Type_Kind := Get_String_Name ("event");
elsif not (Is_Event (F)) and then Is_Data (F) then
Type_Kind := Get_String_Name ("data");
elsif Is_Event (F) and then Is_Data (F) then
Type_Kind := Get_String_Name ("event_data");
end if;
elsif Kind (F) = K_Subcomponent_Access_Instance then
Type_Kind := Get_String_Name ("access");
else
Type_Kind := Get_String_Name ("feature");
end if;
Append_Node_To_List
(Make_Assignement
(Make_Defining_Identifier (Get_String_Name ("kind")),
Make_Defining_Identifier (Type_Kind)),
XTN.Items (Type_Node));
Append_Node_To_List
(Type_Node, XTN.Subitems (Feature_Node));
end;
-- Classifier
declare