Commit 1275d362 authored by Maxime Perrotin's avatar Maxime Perrotin

Reshape the project as a library

parent 95913803
......@@ -8,32 +8,31 @@ all: build
build:
ifeq ($(UNAME), Linux)
@echo "package Parser_Version is" > src/parser_version.ads.new
@echo " Parser_Release : constant String :=" >> src/parser_version.ads.new
@echo -n ' "' >> src/parser_version.ads.new
@git log --oneline | head -1 | cut -f1 -d' ' | tr -d '\012' >> src/parser_version.ads.new
@echo " ; Commit " | tr -d '\r\n' >> src/parser_version.ads.new
@git log | head -3 | tail -1 | cut -f1 -d"+" | tr -d '\r\n' >> src/parser_version.ads.new
@echo "\";" >> src/parser_version.ads.new
@echo " Ocarina_Version : constant String :=" >> src/parser_version.ads.new
@echo -n ' "' >> src/parser_version.ads.new
@ocarina --version | head -1 | tr -d '\012' >> src/parser_version.ads.new
@echo "\";" >> src/parser_version.ads.new
@echo -n "end Parser_Version;" >> src/parser_version.ads.new
@if [ ! -f "src/parser_version.ads" ] ; then \
mv src/parser_version.ads.new src/parser_version.ads; \
@echo "package TASTE.Parser_Version is" > src/taste-parser_version.ads.new
@echo " Parser_Release : constant String :=" >> src/taste-parser_version.ads.new
@echo -n ' "' >> src/taste-parser_version.ads.new
@git log --oneline | head -1 | cut -f1 -d' ' | tr -d '\012' >> src/taste-parser_version.ads.new
@echo " ; Commit " | tr -d '\r\n' >> src/taste-parser_version.ads.new
@git log | head -3 | tail -1 | cut -f1 -d"+" | tr -d '\r\n' >> src/taste-parser_version.ads.new
@echo "\";" >> src/taste-parser_version.ads.new
@echo " Ocarina_Version : constant String :=" >> src/taste-parser_version.ads.new
@echo -n ' "' >> src/taste-parser_version.ads.new
@ocarina --version | head -1 | tr -d '\012' >> src/taste-parser_version.ads.new
@echo "\";" >> src/taste-parser_version.ads.new
@echo -n "end TASTE.Parser_Version;" >> src/taste-parser_version.ads.new
@if [ ! -f "src/taste-parser_version.ads" ] ; then \
mv src/taste-parser_version.ads.new src/taste-parser_version.ads; \
else \
MD1=`cat src/parser_version.ads | md5sum` ; \
MD2=`cat src/parser_version.ads.new | md5sum` ; \
MD1=`cat src/taste-parser_version.ads | md5sum` ; \
MD2=`cat src/taste-parser_version.ads.new | md5sum` ; \
if [ "$$MD1" != "$$MD2" ] ; then \
mv src/parser_version.ads.new src/parser_version.ads ; \
mv src/taste-parser_version.ads.new src/taste-parser_version.ads ; \
else \
rm src/parser_version.ads.new ; \
rm src/taste-parser_version.ads.new ; \
fi ; \
fi
endif
#[ $(ARCH) == 64 ] && EXTRAFLAG="--target=x86_64-linux" ; \
@#[ $(ARCH) == 64 ] && EXTRAFLAG="--target=x86_64-linux" ;
OCARINA_PATH=`ocarina-config --prefix` \
$(gnatpath)gprbuild -j0 -x -g $(exec) -p -P aadl_parser.gpr -XBUILD="debug" $$EXTRAFLAG
......
-- ************************ TASTE AADL Parser ************************** --
-- Based on Ocarina **************************************************** --
-- (c) 2017 European Space Agency - maxime.perrotin@esa.int
-- LGPL license, see LICENSE file
with GNAT.Command_Line,
Ada.Exceptions,
Ada.Text_IO,
GNAT.OS_Lib,
Errors,
Locations,
Ocarina.Namet,
Ocarina.Types,
Ocarina.Configuration,
Ocarina.Files,
Ocarina.Parser,
Parser_Utils,
Interface_View,
Deployment_View;
with GNAT.OS_Lib;
use Ada.Text_IO,
Ada.Exceptions,
Locations,
Ocarina.Namet,
Ocarina.Types,
Ocarina,
Parser_Utils,
Interface_View,
Deployment_View,
GNAT.OS_Lib;
with TASTE,
TASTE.AADL_Parser;
use TASTE.AADL_Parser;
procedure AADL_Parser is
IV_AST : Complete_Interface_View;
DV_AST : Complete_Deployment_View;
Interface_Root : Node_Id := No_Node;
Deployment_root : Node_Id := No_Node;
Dataview_root : Node_ID := No_Node;
----------------
-- Initialize --
----------------
procedure Initialize is
File_Name : Name_Id;
File_Descr : Location;
begin
Banner;
-- Parse arguments before initializing Ocarina, otherwise Ocarina eats
-- some arguments (all file parameters).
Parse_Command_Line (Current_Config);
Initialize_Ocarina;
Dump_Configuration (Current_Config);
AADL_Language := Get_String_Name ("aadl");
if Current_Config.Interface_View.all'Length = 0 then
Current_Config.Interface_View := Default_Interface_View'Access;
end if;
Set_Str_To_Name_Buffer (Current_Config.Interface_View.all);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error
with "File not found : " & Current_Config.Interface_View.all;
end if;
File_Descr := Ocarina.Files.Load_File (File_Name);
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, File_Descr);
if Current_Config.Glue then
if Current_Config.Deployment_View.all'Length = 0 then
Current_Config.Deployment_View := Default_Deployment_View'Access;
end if;
Set_Str_To_Name_Buffer (Current_Config.Deployment_View.all);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error
with "File not found : " & Current_Config.Deployment_View.all;
end if;
File_Descr := Ocarina.Files.Load_File (File_Name);
Deployment_Root := Ocarina.Parser.Parse
(AADL_Language, Deployment_Root, File_Descr);
if Deployment_Root = No_Node then
raise AADL_Parser_Error with "Deployment View is incorrect";
end if;
end if;
for Each of Current_Config.Other_Files loop
Set_Str_To_Name_Buffer (Each);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error with "File not found: " & Each;
end if;
File_Descr := Ocarina.Files.Load_File (File_Name);
-- Add other files to the Interface and (if any) deployment roots
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, File_Descr);
if Deployment_Root /= No_Node then
Deployment_Root := Ocarina.Parser.Parse
(AADL_Language, Deployment_Root, File_Descr);
end if;
end loop;
-- Missing data view is actually not an error.
-- Systems can live with parameterless messages
if Current_Config.Data_View.all'Length > 0 then
Set_Str_To_Name_Buffer (Current_Config.Data_View.all);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error with "Cannot find the Data View file";
end if;
else
-- Try with default name
Set_Str_To_Name_Buffer (Default_Data_View);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name /= No_Name then
Current_Config.Data_View := Default_Data_View'Access;
end if;
end if;
if File_Name /= No_Name then
File_Descr := Ocarina.Files.Load_File (File_Name);
-- Add the Data View to the Interface View root
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, File_Descr);
-- Add the Data View to the Deployment View root, if any
if Deployment_Root /= No_Node then
Deployment_Root := Ocarina.Parser.Parse
(AADL_Language, Deployment_Root, File_Descr);
end if;
Dataview_root := Ocarina.Parser.Parse
(AADL_Language, Dataview_root, File_Descr);
end if;
end Initialize;
Model : TASTE_Model;
begin
Initialize;
IV_AST := Parse_Interface_View (Interface_Root);
IV_AST.Debug_Dump;
if Current_Config.Deployment_View.all'Length > 0 then
DV_AST := Parse_Deployment_View (Deployment_Root);
DV_AST.Debug_Dump;
end if;
Ocarina.Configuration.Reset_Modules;
Ocarina.Reset;
Model := Parse_Project;
Model.Dump;
exception
when Error : AADL_Parser_Error
| Interface_Error
| Function_Error
| No_RCM_Error
| Deployment_View_Error
| Device_Driver_Error =>
Put (Red_Bold & "[ERROR] " & White_Bold);
Put_Line (Exception_Message (Error) & No_Color);
OS_Exit (1);
when GNAT.Command_Line.Exit_From_Command_Line =>
New_Line;
Put (Yellow_Bold & "[INFO] " & No_Color);
Put ("For more information, visit " & Underline & White_Bold);
Put_Line ("https://taste.tools" & No_Color);
when GNAT.Command_Line.Invalid_Switch
| GNAT.Command_Line.Invalid_Parameter
| GNAT.Command_Line.Invalid_Section =>
Put (Red_Bold & "[ERROR] " & White_Bold);
Put_Line ("Invalid switch or parameter (try --help)" & No_Color);
OS_Exit (1);
when E : others =>
Errors.Display_Bug_Box (E);
when TASTE.Quit_TASTE =>
GNAT.OS_Lib.OS_Exit (1);
end AADL_Parser;
-- ************************ TASTE AADL Parser ************************** --
-- Based on Ocarina **************************************************** --
-- (c) 2017 European Space Agency - maxime.perrotin@esa.int
-- LGPL license, see LICENSE file
with GNAT.Command_Line,
Ada.Exceptions,
Ada.Text_IO,
Errors,
Locations,
Ocarina.Namet,
Ocarina.Configuration,
Ocarina.Files,
Ocarina.Parser;
use Ada.Text_IO,
Ada.Exceptions,
Locations,
Ocarina.Namet,
Ocarina;
package body TASTE.AADL_Parser is
function Initialize return Taste_Configuration is
File_Name : Name_Id;
File_Descr : Location;
Current_Config : Taste_Configuration;
begin
Banner;
-- Parse arguments before initializing Ocarina, otherwise Ocarina eats
-- some arguments (all file parameters).
Parse_Command_Line (Current_Config);
Initialize_Ocarina;
AADL_Language := Get_String_Name ("aadl");
if Current_Config.Interface_View.all'Length = 0 then
Current_Config.Interface_View := Default_Interface_View'Access;
end if;
Set_Str_To_Name_Buffer (Current_Config.Interface_View.all);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error
with "File not found : " & Current_Config.Interface_View.all;
end if;
File_Descr := Ocarina.Files.Load_File (File_Name);
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, File_Descr);
if Current_Config.Glue then
if Current_Config.Deployment_View.all'Length = 0 then
Current_Config.Deployment_View := Default_Deployment_View'Access;
end if;
Set_Str_To_Name_Buffer (Current_Config.Deployment_View.all);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error
with "File not found : " & Current_Config.Deployment_View.all;
end if;
File_Descr := Ocarina.Files.Load_File (File_Name);
Deployment_Root := Ocarina.Parser.Parse
(AADL_Language, Deployment_Root, File_Descr);
if Deployment_Root = No_Node then
raise AADL_Parser_Error with "Deployment View is incorrect";
end if;
end if;
for Each of Current_Config.Other_Files loop
Set_Str_To_Name_Buffer (Each);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error with "File not found: " & Each;
end if;
File_Descr := Ocarina.Files.Load_File (File_Name);
-- Add other files to the Interface and (if any) deployment roots
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, File_Descr);
if Deployment_Root /= No_Node then
Deployment_Root := Ocarina.Parser.Parse
(AADL_Language, Deployment_Root, File_Descr);
end if;
end loop;
-- Missing data view is actually not an error.
-- Systems can live with parameterless messages
if Current_Config.Data_View.all'Length > 0 then
Set_Str_To_Name_Buffer (Current_Config.Data_View.all);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name = No_Name then
raise AADL_Parser_Error with "Cannot find the Data View file";
end if;
else
-- Try with default name
Set_Str_To_Name_Buffer (Default_Data_View);
File_Name := Ocarina.Files.Search_File (Name_Find);
if File_Name /= No_Name then
Current_Config.Data_View := Default_Data_View'Access;
end if;
end if;
if File_Name /= No_Name then
File_Descr := Ocarina.Files.Load_File (File_Name);
-- Add the Data View to the Interface View root
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, File_Descr);
-- Add the Data View to the Deployment View root, if any
if Deployment_Root /= No_Node then
Deployment_Root := Ocarina.Parser.Parse
(AADL_Language, Deployment_Root, File_Descr);
end if;
Dataview_root := Ocarina.Parser.Parse
(AADL_Language, Dataview_root, File_Descr);
end if;
return Current_Config;
end Initialize;
function Parse_Project return TASTE_Model is
Result : TASTE_Model;
begin
Result.Configuration := Initialize;
Result.Interface_View := Parse_Interface_View (Interface_Root);
if Result.Configuration.Deployment_View.all'Length > 0 then
AADL_Lib.Append (Result.Configuration.Interface_View.all);
Result.Deployment_View := Parse_Deployment_View (Deployment_Root);
end if;
Ocarina.Configuration.Reset_Modules;
Ocarina.Reset;
return Result;
exception
when Error : AADL_Parser_Error
| Interface_Error
| Function_Error
| No_RCM_Error
| Deployment_View_Error
| Device_Driver_Error =>
Put (Red_Bold & "[ERROR] " & White_Bold);
Put_Line (Exception_Message (Error) & No_Color);
raise Quit_Taste;
when GNAT.Command_Line.Exit_From_Command_Line =>
New_Line;
Put (Yellow_Bold & "[INFO] " & No_Color);
Put ("For more information, visit " & Underline & White_Bold);
Put_Line ("https://taste.tools" & No_Color);
raise Quit_Taste;
when GNAT.Command_Line.Invalid_Switch
| GNAT.Command_Line.Invalid_Parameter
| GNAT.Command_Line.Invalid_Section =>
Put (Red_Bold & "[ERROR] " & White_Bold);
Put_Line ("Invalid switch or parameter (try --help)" & No_Color);
raise Quit_Taste;
when E : others =>
Errors.Display_Bug_Box (E);
raise Quit_Taste;
end Parse_Project;
procedure Dump (Model : TASTE_Model) is
begin
Put_Line ("==== Dump of the Interface View ====");
Model.Interface_View.Debug_Dump;
if Model.Configuration.Deployment_View.all'Length > 0 then
Put_Line ("==== Dump of the Deployment View ====");
Model.Deployment_View.Debug_Dump;
end if;
Put_Line ("==== Dump of the Command Line ====");
Model.Configuration.Debug_Dump;
end Dump;
end TASTE.AADL_Parser;
-- ************************ TASTE AADL Parser ************************** --
-- (c) 2017 European Space Agency - maxime.perrotin@esa.int
-- LGPL license, see LICENSE file
with Ocarina.Types,
TASTE.Parser_Utils,
TASTE.Interface_View,
TASTE.Deployment_View;
use Ocarina.Types,
TASTE.Parser_Utils,
TASTE.Interface_View,
TASTE.Deployment_View;
package TASTE.AADL_Parser is
Interface_Root : Node_Id := No_Node;
Deployment_Root : Node_Id := No_Node;
Dataview_Root : Node_Id := No_Node;
type TASTE_Model is tagged
record
Interface_View : Complete_Interface_View;
Deployment_View : Complete_Deployment_View;
Configuration : Taste_Configuration;
end record;
function Parse_Project return TASTE_Model;
procedure Dump (Model : TASTE_Model);
private
function Initialize return Taste_Configuration;
end TASTE.AADL_Parser;
......@@ -8,7 +8,6 @@ with Ada.Text_IO,
Ada.Exceptions,
Ada.Strings.Fixed,
System.Assertions,
-- Ada.Command_Line,
Ocarina.Instances.Queries,
Ocarina.Instances,
Ocarina.Files,
......@@ -21,9 +20,8 @@ with Ada.Text_IO,
Ocarina.ME_AADL.AADL_Instances.Nodes,
Ocarina.ME_AADL.AADL_Instances.Nutils,
Ocarina.ME_AADL.AADL_Instances.Entities;
-- Ocarina.Backends.Utils;
package body Deployment_View is
package body TASTE.Deployment_View is
use Ada.Text_IO,
Ada.Exceptions,
......@@ -38,11 +36,6 @@ package body Deployment_View is
Ocarina.ME_AADL.AADL_Instances.Nutils,
Ocarina.ME_AADL.AADL_Instances.Entities,
Ocarina.ME_AADL;
-- Ocarina.Backends.Utils;
----------------
-- Initialize --
----------------
function Initialize (Root : Node_Id) return Node_Id is
Root_Depl : Node_Id := Root;
......@@ -55,8 +48,6 @@ package body Deployment_View is
Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets := True;
-- Parse all AADL files possibly needed to instantiate the model
-- Add the interface view, first...
AADL_Lib.Append (Current_Config.Interface_View.all);
for Each of AADL_Lib loop
Set_Str_To_Name_Buffer (Each);
F := Ocarina.Files.Search_File (Name_Find);
......@@ -545,4 +536,4 @@ package body Deployment_View is
DV.Dump_Connections;
end Debug_Dump;
end Deployment_View;
end TASTE.Deployment_View;
......@@ -10,16 +10,16 @@ with Ocarina,
Ada.Containers.Indefinite_Vectors,
Ada.Strings.Unbounded,
Ocarina.Backends.Properties,
Parser_Utils;
TASTE.Parser_Utils;
use Ocarina,
Ocarina.Types,
Ocarina.Backends.Properties,
Ada.Containers,
Ada.Strings.Unbounded,
Parser_Utils;
TASTE.Parser_Utils;
package Deployment_View is
package TASTE.Deployment_View is
use Option_UString;
use Option_ULL;
......@@ -128,4 +128,4 @@ package Deployment_View is
procedure Dump_Busses (DV : Complete_Deployment_View);
procedure Debug_Dump (DV : Complete_Deployment_View);
end Deployment_View;
end TASTE.Deployment_View;
......@@ -12,12 +12,11 @@ with Ada.Text_IO,
Ocarina.Instances,
Ocarina.ME_AADL.AADL_Instances.Nodes,
Ocarina.Namet,
Ocarina.ME_AADL.AADL_Instances.Nutils,
Ocarina.ME_AADL.AADL_Instances.Nutils,
Ocarina.ME_AADL.AADL_Instances.Entities,
Ocarina.Backends.Utils;
-- Ada.Characters.Latin_1;
package body Interface_View is
package body TASTE.Interface_View is
use Ada.Text_IO,
Ada.Exceptions,
......@@ -845,4 +844,4 @@ package body Interface_View is
New_Line;
end loop;
end Debug_Dump;
end Interface_View;
end TASTE.Interface_View;
......@@ -11,16 +11,16 @@ with Ocarina,
Ada.Containers.Indefinite_Vectors,
Ada.Strings.Unbounded,
Option_Type,
Parser_Utils;
TASTE.Parser_Utils;
use Ocarina,
Ocarina.Types,
Ocarina.Backends.Properties,
Ada.Containers,
Ada.Strings.Unbounded,
Parser_Utils;
TASTE.Parser_Utils;
package Interface_View is
package TASTE.Interface_View is
use Option_UString;
use Option_ULL;
......@@ -181,4 +181,4 @@ package Interface_View is
procedure Debug_Dump (IV : Complete_Interface_View);
end Interface_View;
end TASTE.Interface_View;
......@@ -3,38 +3,33 @@
-- LGPL license, see LICENSE file
with Ada.Text_IO,
Parser_Version,
GNAT.OS_Lib,
GNAT.Command_Line,
Ocarina.AADL_Values,
Ocarina.Configuration,
Ocarina.FE_AADL.Parser,
Ocarina.Instances.Queries,
GNAT.OS_Lib,
GNAT.Command_Line;
TASTE.Parser_Version;
package body Parser_Utils is
package body TASTE.Parser_Utils is
use Ada.Text_IO,
Ocarina.Instances.Queries,
GNAT.OS_Lib,
Ocarina.ME_AADL,
GNAT.Command_Line;
------------
-- Banner --
------------
GNAT.Command_Line,
Ocarina.Instances.Queries,
Ocarina.ME_AADL;
procedure Banner is
The_Banner : constant String :=
Yellow_Bold & "TASTE AADL Parser" & No_Color & " (Version "
& Parser_Version.Parser_Release & ") "
& ASCII.LF & ASCII.CR & No_Color
& "Contact: " & Underline
& "Maxime.Perrotin@esa.int" & No_Color & " or " & Underline
& "Thanassis.Tsiodras@esa.int"
& TASTE.Parser_Version.Parser_Release & ")"
& ASCII.LF & ASCII.CR & White_Bold
& "Copyright (C) European Space Agency"
& ASCII.LF & ASCII.CR & No_Color
& "Based on " & Parser_Version.Ocarina_Version;
& "Based on " & TASTE.Parser_Version.Ocarina_Version;
begin
Put_Line (The_Banner);
New_Line;
end Banner;
procedure Parse_Command_Line (Result : out Taste_Configuration) is
......@@ -91,7 +86,7 @@ package body Parser_Utils is
end if;
end Parse_Command_Line;
procedure Dump_Configuration (Config : Taste_Configuration) is
procedure Debug_Dump (Config : Taste_Configuration) is
begin
Put_Line ("Command line:");
Put_Line (" |_ Interface View : " & Config.Interface_View.all);
......@@ -107,7 +102,7 @@ package body Parser_Utils is
for Each of Config.Other_Files loop
Put_Line (" |_ Other file : " & Each);
end loop;
end Dump_Configuration;
end Debug_Dump;
-----------------------
-- Get_APLC_Binding --
......@@ -199,4 +194,4 @@ package body Parser_Utils is
Ocarina.Configuration.Init_Modules;
Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets := True;
end Initialize_Ocarina;
end Parser_Utils;
end TASTE.Parser_Utils;
......@@ -24,7 +24,7 @@ use Ocarina,
Ada.Strings.Unbounded,
Interfaces.C_Streams;
package Parser_Utils is
package TASTE.Parser_Utils is
AADL_Language : Name_Id;
Default_Interface_View : aliased String := "InterfaceView.aadl";
......@@ -96,7 +96,7 @@ package Parser_Utils is
procedure Initialize_Ocarina;
type Taste_Configuration is
type Taste_Configuration is tagged
record
Interface_View : aliased GNAT.Strings.String_Access;
Deployment_View : aliased GNAT.Strings.String_Access;
......@@ -111,10 +111,6 @@ package Parser_Utils is
Other_Files : String_Vectors.Vector;
end record;
Current_Config : Taste_Configuration;
procedure Debug_Dump (Config : Taste_Configuration);
procedure Parse_Command_Line (Result : out Taste_Configuration);
procedure Dump_Configuration (Config : Taste_Configuration);
end Parser_Utils;
end TASTE.Parser_Utils;