Commit 56aed8f1 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Complete command line parser

parent 6694e07b
......@@ -35,7 +35,7 @@ endif
#[ $(ARCH) == 64 ] && EXTRAFLAG="--target=x86_64-linux" ; \
OCARINA_PATH=`ocarina-config --prefix` \
$(gnatpath)gprbuild -x -g $(exec) -p -P aadl_parser.gpr -XBUILD="debug" $$EXTRAFLAG
$(gnatpath)gprbuild -j0 -x -g $(exec) -p -P aadl_parser.gpr -XBUILD="debug" $$EXTRAFLAG
install:
$(MAKE)
......
......@@ -3,8 +3,7 @@
-- (c) 2017 European Space Agency - maxime.perrotin@esa.int
-- LGPL license, see LICENSE file
with Ada.Command_Line, -- Remove this ASAP
GNAT.Command_Line,
with GNAT.Command_Line,
Ada.Exceptions,
Ada.Text_IO,
GNAT.OS_Lib,
......@@ -39,268 +38,111 @@ use Ada.Text_IO,
GNAT.OS_Lib;
procedure AADL_Parser is
Exit_With_No_Error : exception;
AADL_Language : Name_Id;
Interface_Root : Node_Id := No_Node;
Deployment_root : Node_Id := No_Node;
Dataview_root : Node_ID := No_Node;
Success : Boolean;
-- OutDir : Natural := 0;
-- Stack_Val : Natural := 0;
-- Timer_Resolution : Natural := 0;
Interface_View : Natural := 0;
Depl_View_Pos : Natural := 0;
Data_View : Natural := 0;
Generate_glue : Boolean := false;
procedure Parse_Command_Line_Old with Unreferenced;
-- procedure Process_DataView (My_Root : Node_Id);
----------------------------
-- Process_Interface_View --
----------------------------
-- Set the output directory
-- if OutDir > 0 then
-- C_Set_OutDir (Ada.Command_Line.Argument (Outdir),
-- Ada.Command_Line.Argument (Outdir)'Length);
-- end if;
--
-- -- Set the stack value
-- if Stack_Val > 0 then
-- C_Set_Stack (Ada.Command_Line.Argument (stack_val),
-- Ada.Command_Line.Argument (stack_val)'Length);
-- end if;
--
-- -- Set the timer resolution value
-- if Timer_Resolution > 0 then
-- C_Set_Timer_Resolution
-- (Ada.Command_Line.Argument (Timer_Resolution),
-- Ada.Command_Line.Argument (Timer_Resolution)'Length);
-- end if;
-- Current_function is read from the list of system subcomponents
-----------------------------------
-- Browse_Deployment_View_System --
-----------------------------------
-- procedure Browse_Deployment_View_System
-- (My_System : Node_Id; NodeName : String) is
-- Processes : Node_Id;
-- Processes2 : Node_Id;
-- Tmp_CI : Node_Id;
-- Tmp_CI2 : Node_Id;
-- Ref : Node_Id;
-- CPU : Node_Id;
-- CPU_Name : Name_Id := No_Name;
-- Pkg_Name : Name_Id := No_Name;
-- CPU_Classifier : Name_Id := No_Name;
-- CPU_Platform : Supported_Execution_Platform := Platform_None;
------------------------
-- Parse_Command_Line --
------------------------
procedure Parse_Command_Line_Old is
FN : Name_Id;
B : Location;
Previous_OutDir : Boolean := False;
Previous_IFview : Boolean := False;
Previous_CView : Boolean := False;
Previous_DataView : Boolean := False;
Previous_TimerRes : Boolean := False;
begin
for J in 1 .. Ada.Command_Line.Argument_Count loop
-- Parse the file corresponding to the Jth argument of the
-- command line and enrich the global AADL tree.
if Previous_IfView then
Interface_View := J;
Previous_Ifview := false;
elsif Previous_Cview then
Depl_View_Pos := J;
Previous_Cview := false;
elsif Previous_DataView then
Data_View := J;
Previous_DataView := false;
elsif Previous_Outdir then
-- OutDir := J;
Previous_OutDir := false;
elsif Previous_TimerRes then
-- Timer_Resolution := J;
Previous_TimerRes := false;
elsif Ada.Command_Line.Argument (J) = "--polyorb-hi-c"
or else Ada.Command_Line.Argument (J) = "-p"
or else Ada.Command_Line.Argument (J) = "-polyorb-hi-c"
then
null;
elsif Ada.Command_Line.Argument (J) = "--glue"
or else Ada.Command_Line.Argument (J) = "-glue"
or else Ada.Command_Line.Argument (J) = "-l"
then
generate_glue := true;
elsif Ada.Command_Line.Argument (J) = "--smp2"
or else Ada.Command_Line.Argument (J) = "-m"
then
null;
elsif Ada.Command_Line.Argument (J) = "--gw"
or else Ada.Command_Line.Argument (J) = "-gw"
or else Ada.Command_Line.Argument (J) = "-w"
then
null;
-- The "test" flag activates a function in the parser,
-- used for debugging purposes (e.g. dump of the model after
-- all preprocessings). Users need not use it.
elsif Ada.Command_Line.Argument (J) = "--test"
or else Ada.Command_Line.Argument (J) = "-test"
or else Ada.Command_Line.Argument (J) = "-t"
then
null;
elsif Ada.Command_Line.Argument (J) = "--aadlv2"
or else Ada.Command_Line.Argument (J) = "-aadlv2"
or else Ada.Command_Line.Argument (J) = "-a"
then
AADL_Version := Ocarina.AADL_V2;
elsif Ada.Command_Line.Argument (J) = "--future" then
null;
elsif Ada.Command_Line.Argument (J) = "--output"
or else Ada.Command_Line.Argument (J) = "-o"
then
Previous_OutDir := True;
elsif Ada.Command_Line.Argument (J) = "--interfaceview"
or else Ada.Command_Line.Argument (J) = "-i"
then
Previous_Ifview := True;
elsif Ada.Command_Line.Argument (J) = "--timer"
or else Ada.Command_Line.Argument (J) = "-timer"
or else Ada.Command_Line.Argument (J) = "-x"
then
Previous_TimerRes := True;
elsif Ada.Command_Line.Argument (J) = "--deploymentview"
or else Ada.Command_Line.Argument (J) = "-c"
then
Previous_Cview := True;
else
Set_Str_To_Name_Buffer (Ada.Command_Line.Argument (J));
FN := Ocarina.Files.Search_File (Name_Find);
if FN = No_Name then
raise AADL_Parser_Error with "File not found: "
& Ada.Command_Line.Argument (J);
end if;
B := Ocarina.Files.Load_File (FN);
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, B);
-- the "else" makes the parser parse any additional aadl files
-- (in complement to the interface/deployment/data views)
-- they must therefore be part of Root AND Deployment_Root trees
Set_Str_To_Name_Buffer (Ada.Command_Line.Argument (J));
FN := Ocarina.Files.Search_File (Name_Find);
B := Ocarina.Files.Load_File (FN);
Deployment_Root := Ocarina.Parser.Parse
(AADL_Language, Deployment_Root, B);
end if;
end loop;
end Parse_Command_Line_Old;
----------------
-- Initialize --
----------------
procedure Initialize is
FN : Name_Id;
B : Location;
Config : Taste_Configuration;
File_Name : Name_Id;
File_Descr : Location;
begin
-- Display the command line syntax
if Ada.Command_Line.Argument_Count = 0 then
raise AADL_Parser_Error
with "Missing command line arguments (try --help)";
end if;
AADL_Language := Get_String_Name ("aadl");
Config := Parse_Command_Line;
Dump_Configuration (Current_Config);
Put_Line ("Interface View: " & Config.Interface_View.all);
if Interface_View = 0 then
-- Try default filename
Set_Str_To_Name_Buffer ("InterfaceView.aadl");
else
Set_Str_To_Name_Buffer (Ada.Command_Line.Argument (Interface_View));
if Current_Config.Interface_View.all'Length = 0 then
Current_Config.Interface_View := Default_Interface_View'Access;
end if;
FN := Ocarina.Files.Search_File (Name_Find);
if FN = No_Name then
raise AADL_Parser_Error with "Interface View missing";
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;
B := Ocarina.Files.Load_File (FN);
File_Descr := Ocarina.Files.Load_File (File_Name);
Interface_Root := Ocarina.Parser.Parse
(AADL_Language, Interface_Root, B);
(AADL_Language, Interface_Root, File_Descr);
if Generate_Glue then
if Depl_View_Pos = 0 then
Set_Str_To_Name_Buffer ("DeploymentView.aadl");
else
Set_Str_To_Name_Buffer (Ada.Command_Line.Argument (Depl_View_Pos));
if Current_Config.Glue then
if Current_Config.Deployment_View.all'Length = 0 then
Current_Config.Deployment_View := Default_Deployment_View'Access;
end if;
FN := Ocarina.Files.Search_File (Name_Find);
B := Ocarina.Files.Load_File (FN);
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, B);
(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 Data_View > 0 then
Set_Str_To_Name_Buffer (Ada.Command_Line.Argument (Data_View));
FN := Ocarina.Files.Search_File (Name_Find);
if FN = No_Name then
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 ("DataView.aadl");
FN := Ocarina.Files.Search_File (Name_Find);
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 FN /= No_Name then
B := Ocarina.Files.Load_File (FN);
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, B);
(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, B);
(AADL_Language, Deployment_Root, File_Descr);
end if;
Dataview_root := Ocarina.Parser.Parse
(AADL_Language, Dataview_root, B);
(AADL_Language, Dataview_root, File_Descr);
end if;
if No (Interface_Root) then
......@@ -313,13 +155,6 @@ procedure AADL_Parser is
if not Success then
raise AADL_Parser_Error with "Could not analyse model";
end if;
exception
when GNAT.Command_Line.Exit_From_Command_Line =>
raise Exit_With_No_Error; -- When --help is used
when GNAT.Command_Line.Invalid_Switch =>
Put (Red_Bold & "[ERROR] " & White_Bold);
Put_Line ("Invalid switch in command line (try --help)" & No_Color);
raise Exit_With_No_Error;
end Initialize;
IV_Root : Node_Id;
......@@ -328,8 +163,11 @@ procedure AADL_Parser is
begin
Banner;
-- Parse arguments before initializing Ocarina, otherwise Ocarina eats
-- some arguments (all file parameters).
Parse_Command_Line (Current_Config);
Initialize_Ocarina;
Initialize;
-- First, we analyze the interface view.
......@@ -345,8 +183,8 @@ begin
-- Now, we are done with the interface view. We now analyze the
-- deployment view.
if Depl_View_Pos > 0 then
AADL_Lib.Append (Ada.Command_Line.Argument (Interface_View));
if Current_Config.Deployment_View.all'Length > 0 then
AADL_Lib.Append (Current_Config.Interface_View.all);
DV_AST := Parse_Deployment_View (Deployment_Root);
DV_AST.Debug_Dump;
end if;
......@@ -364,12 +202,17 @@ exception
Put (Red_Bold & "[ERROR] " & White_Bold);
Put_Line (Exception_Message (Error) & No_Color);
OS_Exit (1);
when Exit_With_No_Error =>
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);
end AADL_Parser;
......@@ -37,9 +37,8 @@ package body Parser_Utils is
Put_Line (The_Banner);
end Banner;
function Parse_Command_Line return Taste_Configuration is
procedure Parse_Command_Line (Result : out Taste_Configuration) is
Config : Command_Line_Configuration;
Result : Taste_Configuration;
begin
Define_Switch (Config, Output => Result.Interface_View'Access,
Switch => "-i:", Long_Switch => "--interfaceview=",
......@@ -67,7 +66,7 @@ package body Parser_Utils is
Switch => "-p", Long_Switch => "--polyorb-hi-c",
Help => "Use PolyORB-HI-C runtime in place of Ada");
Define_Switch (Config, Output => Result.Timer_Resolution'Access,
Switch => "-x", Long_Switch => "--timer",
Switch => "-x:", Long_Switch => "--timer=",
Help => "Specify timer resolution (default 100 ms)");
Define_Switch (Config, Output => Result.Debug_Flag'Access,
Switch => "-g", Long_Switch => "--debug",
......@@ -76,30 +75,39 @@ package body Parser_Utils is
Switch => "-v", Long_Switch => "--version",
Help => "Display tool version");
Getopt (Config);
loop
declare
S : constant String := Get_Argument;
begin
exit when S'Length = 0;
Put_Line ("File argument : " & S);
Result.Other_Files.Append (S);
end;
end loop;
-- Dump (Debug)
Put_Line ("Command line:");
Put_Line (" |_ Interface View : " & Result.Interface_View.all);
Put_Line (" |_ Deployment View : " & Result.Deployment_View.all);
Put_Line (" |_ Data View : " & Result.Data_View.all);
Put_Line (" |_ Output Dir : " & Result.Output_Dir.all);
Put_Line (" |_ Use POHIC : " & Result.Use_POHIC'Img);
Put_Line (" |_ Glue : " & Result.Use_POHIC'Img);
Put_Line (" |_ Skeletons : " & Result.Skeletons'Img);
Put_Line (" |_ Timer Res : " & Result.Timer_Resolution'Img);
Put_Line (" |_ Version : " & Result.Version'Img);
Put_Line (" |_ Debug : " & Result.Debug_Flag'Img);
return Result;
if Result.Version then
raise Exit_From_Command_Line;
end if;
end Parse_Command_Line;
procedure Dump_Configuration (Config : Taste_Configuration) is
begin
Put_Line ("Command line:");
Put_Line (" |_ Interface View : " & Config.Interface_View.all);
Put_Line (" |_ Deployment View : " & Config.Deployment_View.all);
Put_Line (" |_ Data View : " & Config.Data_View.all);
Put_Line (" |_ Output Dir : " & Config.Output_Dir.all);
Put_Line (" |_ Use POHIC : " & Config.Use_POHIC'Img);
Put_Line (" |_ Glue : " & Config.Use_POHIC'Img);
Put_Line (" |_ Skeletons : " & Config.Skeletons'Img);
Put_Line (" |_ Timer Res : " & Config.Timer_Resolution'Img);
Put_Line (" |_ Version : " & Config.Version'Img);
Put_Line (" |_ Debug : " & Config.Debug_Flag'Img);
for Each of Config.Other_Files loop
Put_Line (" |_ Other file : " & Each);
end loop;
end Dump_Configuration;
-----------------------
-- Get_APLC_Binding --
-----------------------
......
......@@ -26,6 +26,10 @@ use Ocarina,
package Parser_Utils is
Default_Interface_View : aliased String := "InterfaceView.aadl";
Default_Deployment_View : aliased String := "DeploymentView.aadl";
Default_Data_View : aliased String := "DataView.aadl";
package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
function US (Source : String) return Unbounded_String renames
......@@ -103,8 +107,13 @@ package Parser_Utils is
Timer_Resolution : aliased Integer := 100;
Debug_Flag : aliased Boolean := False;
Version : aliased Boolean := False;
Other_Files : String_Vectors.Vector;
end record;
function Parse_Command_Line return Taste_Configuration;
Current_Config : Taste_Configuration;
procedure Parse_Command_Line (Result : out Taste_Configuration);
procedure Dump_Configuration (Config : Taste_Configuration);
end Parser_Utils;
package Parser_Version is
Parser_Release : constant String :=
"553b2d9 ; Commit Date: Sun Dec 17 22:21:17 2017 ";
"5b38c95 ; Commit Date: Thu Dec 21 10:41:52 2017 ";
Ocarina_Version : constant String :=
"Ocarina 2017.x (Working Copy from r0b92ed3)";
end Parser_Version;
\ No newline at end of file
......@@ -3,11 +3,11 @@ AADL_PARSER=../../aadl_parser
all: test-parse
test-parse:
$(AADL_PARSER) -glue -i interfaceview.aadl \
-c deploymentview.aadl \
-d dataview.aadl \
../common/ocarina_components.aadl \
../common/TASTE_DV_Properties.aadl \
$(AADL_PARSER) --glue -i interfaceview.aadl \
-c deploymentview.aadl \
-d dataview.aadl \
../common/ocarina_components.aadl \
../common/TASTE_DV_Properties.aadl \
2>&1 | tail -2 | diff expected -
clean:
......
......@@ -3,8 +3,8 @@ AADL_PARSER=../../aadl_parser
all: test-parse
test-parse:
$(AADL_PARSER) -gw \
-glue \
$(AADL_PARSER) --gw \
--glue \
-i InterfaceView.aadl \
-c DeploymentView.aadl \
-d DataView.aadl \
......
......@@ -3,8 +3,8 @@ AADL_PARSER=../../aadl_parser
all: test-parse
test-parse:
$(AADL_PARSER) -gw \
-glue \
$(AADL_PARSER) --gw \
--glue \
-i InterfaceView.aadl \
-c DeploymentView.aadl \
-d DataView.aadl \
......
......@@ -3,8 +3,8 @@ AADL_PARSER=../../aadl_parser
all: test-parse
test-parse:
$(AADL_PARSER) -gw \
-glue \
$(AADL_PARSER) --gw \
--glue \
-i InterfaceView.aadl \
-c DeploymentView.aadl \
-d DataView.aadl \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment