Commit 141d694b authored by Maxime Perrotin's avatar Maxime Perrotin

Add buildsupport code

Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
GCCVERSION := $(shell gcc -v 2>&1 | grep ada | wc -l)
UNAME := $(shell uname)
exec = buildsupport
sources = $(wildcard ada/*.ad? c/*.c include/*.h)
all: checkVersion $(exec)
#ifeq ($(UNAME),Linux)
# @if [ $(GCCVERSION) -ne 1 ] ; then echo gcc must point to GNAT... check your PATH ; exit 1 ; fi
$(exec): $(sources)
ifeq ($(UNAME), Linux)
@echo "package buildsupport_version is" > ada/
@echo -n "buildsupport_release : constant string := \"" >> ada/
@svnversion -n . >> ada/
@echo "\";" >> ada/
@echo -n "end buildsupport_version;" >> ada/
@if [ ! -f "ada/" ] ; then \
mv ada/ ada/; \
else \
MD1=`cat ada/ | md5sum` ; \
MD2=`cat ada/ | md5sum` ; \
if [ "$$MD1" != "$$MD2" ] ; then \
mv ada/ ada/ ; \
else \
rm ada/ ; \
fi ; \
mkdir -p tmpBuild
# We have to compile in C99 to support "long long" integers, as imposed by the "aadlinteger" type
# -Wall -Werror -Wextra -Wconversion -Wno-deprecated -Winit-self -Wsign-conversion -Wredundant-decls -Wvla -Wshadow -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wlogical-op -Wmissing-include-dirs -Winit-self -Wpointer-arith -Wcast-qual -Wcast-align -Wold-style-cast -Wno-error=old-style-cast -Wsign-promo -Wundef
#clang -c -Wall -Werror -Iinclude c/*.c
gcc -c -W -g3 -g -Wall -Werror -Wextra -Werror=format-security -Wconversion -Wno-deprecated -Winit-self -Wsign-conversion -Wredundant-decls -Wvla -Wshadow -Wlogical-op -Wmissing-include-dirs -Winit-self -Wpointer-arith -Wcast-qual -Wcast-align -Wno-error=old-style-cast -Wundef -std=c99 -pedantic -Iinclude c/*.c
mv *.o tmpBuild/
ADA_PROJECT_PATH=`ocarina-config --prefix`/lib/gnat:$$ADA_PROJECT_PATH $(gnatpath)gnatmake -x -g $(exec) -p -P buildsupport.gpr -XBUILD="debug"
# strip $(exec)
cp buildsupport `ocarina-config --prefix`/bin/
cp misc/ `ocarina-config --prefix`/bin/
rm -rf tmpBuild
rm -f $(exec)
rm -f *~
release: clean
rm -rf tmp/ release/
mkdir release/
mkdir -p tmp/buildsupport-$(VERSION)
mkdir -p tmp/buildsupport-$(VERSION)/c
mkdir -p tmp/buildsupport-$(VERSION)/ada
mkdir -p tmp/buildsupport-$(VERSION)/include
mkdir -p tmp/buildsupport-$(VERSION)/misc
cp -f c/*.c tmp/buildsupport-$(VERSION)/c/
cp -f ada/*.ads tmp/buildsupport-$(VERSION)/ada/
cp -f ada/*.adb tmp/buildsupport-$(VERSION)/ada/
cp -f include/*.h tmp/buildsupport-$(VERSION)/include/
cp -f Makefile tmp/buildsupport-$(VERSION)/
cp -f buildsupport.gpr tmp/buildsupport-$(VERSION)/
cp -f misc/ tmp/buildsupport-$(VERSION)/misc/
( cd tmp && tar cvvfz buildsupport-$(VERSION).tar.gz buildsupport-$(VERSION) )
mv tmp/buildsupport-$(VERSION).tar.gz release/
mkdir -p tmp/buildsupport-`uname -m`-$(VERSION)/bin
mkdir -p tmp/buildsupport-`uname -m`-$(VERSION)/misc/
cp -f buildsupport tmp/buildsupport-`uname -m`-$(VERSION)/bin
cp -f misc/ tmp/buildsupport-`uname -m`-$(VERSION)/misc/
( cd tmp && tar cvvfz buildsupport-`uname -m`-$(VERSION).tgz buildsupport-`uname -m`-$(VERSION)/)
( cp -f tmp/buildsupport-`uname -m`-$(VERSION).tgz release/)
rm -rf tmp/
.PHONY: release
buildsupport is a low-level TASTE command, responsible for the generation of skeletons and some glue code.
License: LGPL (see LICENSE file)
Copyright (c) 2008-2015 European Space Agency
-- *************************** buildsupport **************************** --
-- (c) 2015 European Space Agency -
-- LGPL license, see LICENSE file
-- pragma Style_Checks (Off);
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
with Ada.Characters.Handling;
with Ada.Command_Line;
with Ada.Text_IO;
with GNAT.OS_Lib;
use GNAT.OS_Lib;
with Errors;
with Locations;
with Namet;
with Types;
with System.Assertions;
with Ocarina.Analyzer;
with Ocarina.Backends.Properties;
with Ocarina.Configuration;
with Ocarina.Files;
with Ocarina.Options;
with Ocarina.Instances;
with Ocarina.Instances.Queries;
with Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.Parser;
with Ocarina.FE_AADL.Parser;
with Imported_Routines;
with Buildsupport_Utils;
with buildsupport_version;
with Ocarina.Backends.Utils;
procedure BuildSupport is
use Ada.Text_IO;
use Ada.Characters.Handling;
use Locations;
use Namet;
use Types;
use Ocarina;
use Ocarina.Analyzer;
use Ocarina.Backends.Properties;
use Ocarina.Instances;
use Ocarina.Instances.Queries;
use Ocarina.ME_AADL;
use Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.ME_AADL.AADL_Instances.Nutils;
use Buildsupport_Utils;
package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
AADL_Language : Name_Id;
Interface_Root : Node_Id := No_Node;
Deployment_root : Node_Id := No_Node;
Success : Boolean;
OutDir : Integer := 0;
Stack_Val : Integer := 0;
Subs : Node_id;
Interface_view : Integer := 0;
Concurrency_view : Integer := 0;
Data_View : Integer := 0;
Generate_glue : Boolean := false;
Keep_case : Boolean := false;
AADL_Version : AADL_Version_Type := Ocarina.AADL_V2;
procedure Parse_Command_Line;
procedure Process_Deployment_View (My_Root : Node_Id);
procedure Process_Interface_View (My_System : Node_Id);
procedure Browse_Deployment_View_System
(My_System : Node_Id; NodeName : String);
-- Find the bus that is connected to a device through a require
-- access.
-- Find_Connected_Bus --
procedure Find_Connected_Bus (Device : Node_Id;
Accessed_Bus : out Node_Id;
Accessed_Port : out Node_Id) is
F : Node_Id;
Src : Node_Id;
Accessed_Bus := No_Node;
Accessed_Port := No_Node;
if not Is_Empty (Features (Device)) then
F := First_Node (Features (Device));
while Present (F) loop
-- The sources of F
if not Is_Empty (Sources (F)) then
Src := First_Node (Sources (F));
if Src /= No_Node then
if Item (Src) /= No_Node and then
not Is_Empty (Sources (Item (Src))) and then
First_Node (Sources (Item (Src))) /= No_Node
Src := Item (First_Node (Sources (Item (Src))));
Accessed_Bus := Src;
Accessed_Port := F;
end if;
end if;
end if;
F := Next_Node (F);
end loop;
end if;
end Find_Connected_Bus;
-- Process_Interface_View --
procedure Process_Interface_View (My_System : Node_Id) is
Len_Name : Integer;
Len_Type : Integer;
Current_Function : Node_Id;
FV_Subco : Node_Id;
CI : Node_Id;
Connection_I : Node_Id;
Distant_FV : Node_Id;
If_I : Node_Id;
RI_To_Add : Node_Id;
Local_RI_Name : Name_Id;
Distant_PI_Name : Name_Id;
Param_I : Node_Id;
ASN1_Module : Name_Id;
ASN1_Filename : Name_Id := No_Name;
Operation_Kind : Supported_RCM_Operation_Kind;
Sub_I : Node_Id;
Encoding : Supported_ASN1_Encoding;
Asntype : Node_Id;
Basic_Type : Supported_ASN1_Basic_Type;
(No (My_System),
"Internal Error, cannot instantiate model");
if not Is_Empty (Subcomponents (My_System)) then
-- Set the output directory
if OutDir > 0 then
(Ada.Command_Line.Argument (Outdir),
Ada.Command_Line.Argument (Outdir)'Length);
end if;
-- Set the stack value
if Stack_Val > 0 then
(Ada.Command_Line.Argument (stack_val),
Ada.Command_Line.Argument (stack_val)'Length);
end if;
-- Current_function is read from the list of system subcomponents
Current_function := First_Node (Subcomponents (My_System));
while Present (Current_Function) loop
CI := Corresponding_Instance (Current_Function);
if Get_Category_Of_Component (CI) = CC_System then
-- Call C function "New_FV" and set the language
(Get_Name_String (Name (Identifier (Current_Function))),
(Name (Identifier (Current_Function)))'Length,
Get_Name_String (Display_Name (Identifier
-- Read the implementation language of the current
-- FV from the Source_Language property
Source_Language : constant Supported_Source_Language
:= Get_Source_Language (CI);
case Source_Language is
when Language_Ada_95 =>
when Language_C =>
when Language_CPP =>
when Language_SDL_OpenGEODE =>
when Language_Scade =>
when Language_Lustre =>
when Language_SDL =>
when Language_SDL_RTDS =>
when Language_Simulink =>
when Language_Rhapsody =>
when Language_Gui =>
when Language_VHDL =>
when Language_System_C =>
when Language_Device =>
when Language_QGenAda =>
when Language_QGenC =>
when others =>
end case;
SourceText : constant Name_Array :=
Get_Source_Text (CI);
ZipId : Name_Id := No_Name;
if SourceText'Length /= 0 then
ZipId := SourceText (1);
end if;
if ZipId /= No_Name then
(Get_Name_String (ZipId),
Get_Name_String (ZipId)'Length);
end if;
-- Parse the functional states of this FV
if not Is_Empty (Subcomponents (CI)) then
FV_Subco := First_Node (Subcomponents (CI));
while Present (FV_Subco) loop
if Get_Category_Of_Component (FV_Subco) =
-- Check that the value of the FS is set
Exit_On_Error (Get_String_Property
(Corresponding_Instance (FV_Subco),
"taste::fs_default_value") = No_Name,
"Error: Missing value for context parameter " &
(Name (Identifier (FV_Subco))) &
" in function " &
(Name (Identifier (Current_Function))));
-- Name of the variable
FS_name : constant String :=
Get_Name_String (Name (Identifier (FV_Subco)));
-- Name of the variable respecting case
FS_fullname : constant String :=
Get_Name_String (Display_Name (Identifier
-- ASN.1 type
Asn1type : constant Node_Id :=
Corresponding_Instance (FV_Subco);
FS_type : constant String :=
(Get_Type_Source_Name (Asn1type));
-- Variable default value
FS_value : constant String :=
Get_Name_String (Get_String_Property
(Asn1type, "taste::fs_default_value"));
FS_module : constant String :=
Get_ASN1_Module_Name (Asn1type);
-- ASN.1 filename
NA : constant Name_Array :=
Get_Source_Text (Asn1type);
FS_File : Unbounded_String;
-- Some special DATA components have no
-- Source_Text property in DataView.aadl
-- (TASTE-Directive and Tunable Parameter)
if NA'Length > 0 then
FS_File := To_Unbounded_String
(Get_Name_String (NA (1)));
FS_File := To_Unbounded_String ("dummy");
end if;
(FS_name, FS_name'Length,
FS_type, FS_type'Length,
FS_value, FS_value'Length,
FS_module, FS_module'Length,
To_String (FS_file),
To_String (FS_file)'Length,
end if;
FV_Subco := Next_Node (FV_Subco);
end loop;
end if;
-- Parse the interfaces of the FV
if not Is_Empty (Features (CI)) then
If_I := First_Node (Features (CI));
while Present (If_I) loop
Sub_I := Get_RCM_Operation (If_I);
if Present (Sub_I) then
-- Call backend Add_PI or Add_RI and for each
-- parameter call C function Add_In_Param or
-- Add_Out_Param
if Is_Subprogram_Access (If_I) and
Is_Provided (If_I)
PI_string : String :=
(Display_Name (Identifier (If_I)));
PI_Name : Name_Id;
PI_Name := Get_Interface_Name (If_I);
if PI_Name /= No_Name then
(Get_Name_String (PI_Name),
Get_Name_String (PI_Name)'Length);
-- Keep compatibility with V1.2
if not Keep_case then
PI_string := to_lower (PI_string);
end if;
(PI_String, PI_String'Length);
end if;
if Kind (If_I) = K_Subcomponent_Access_Instance
and then
(Corresponding_Instance (If_I),
(Corresponding_Instance (If_I),
end if;
-- Set Provided Interface RCM kind
-- (cyclic, sporadic, etc).
Operation_Kind := Get_RCM_Operation_Kind (If_I);
case Operation_Kind is
when Cyclic_Operation =>
when Sporadic_Operation =>