Commit 6694e07b authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

work on command line parser

parent 553b2d91
......@@ -3,7 +3,8 @@
-- (c) 2017 European Space Agency - maxime.perrotin@esa.int
-- LGPL license, see LICENSE file
with Ada.Command_Line,
with Ada.Command_Line, -- Remove this ASAP
GNAT.Command_Line,
Ada.Exceptions,
Ada.Text_IO,
GNAT.OS_Lib,
......@@ -39,6 +40,8 @@ use Ada.Text_IO,
procedure AADL_Parser is
Exit_With_No_Error : exception;
AADL_Language : Name_Id;
Interface_Root : Node_Id := No_Node;
......@@ -53,7 +56,7 @@ procedure AADL_Parser is
Data_View : Natural := 0;
Generate_glue : Boolean := false;
procedure Parse_Command_Line;
procedure Parse_Command_Line_Old with Unreferenced;
-- procedure Process_DataView (My_Root : Node_Id);
----------------------------
......@@ -102,7 +105,7 @@ procedure AADL_Parser is
-- Parse_Command_Line --
------------------------
procedure Parse_Command_Line is
procedure Parse_Command_Line_Old is
FN : Name_Id;
B : Location;
Previous_OutDir : Boolean := False;
......@@ -197,27 +200,6 @@ procedure AADL_Parser is
then
Previous_Cview := True;
elsif Ada.Command_Line.Argument (J) = "--version"
or else Ada.Command_Line.Argument (J) = "-v"
then
OS_Exit (0);
elsif Ada.Command_Line.Argument (J) = "--dataview"
or else Ada.Command_Line.Argument (J) = "-d"
then
Previous_DataView := True;
elsif Ada.Command_Line.Argument (J) = "--debug"
or else Ada.Command_Line.Argument (J) = "-g"
then
null;
elsif Ada.Command_Line.Argument (J) = "--help"
or else Ada.Command_Line.Argument (J) = "-h"
then
Usage;
OS_Exit (0);
else
Set_Str_To_Name_Buffer (Ada.Command_Line.Argument (J));
FN := Ocarina.Files.Search_File (Name_Find);
......@@ -240,25 +222,28 @@ procedure AADL_Parser is
(AADL_Language, Deployment_Root, B);
end if;
end loop;
end Parse_Command_Line;
end Parse_Command_Line_Old;
----------------
-- Initialize --
----------------
procedure Initialize is
FN : Name_Id;
B : Location;
FN : Name_Id;
B : Location;
Config : Taste_Configuration;
begin
-- Display the command line syntax
if Ada.Command_Line.Argument_Count = 0 then
Usage;
raise AADL_Parser_Error with "Missing command line arguments";
raise AADL_Parser_Error
with "Missing command line arguments (try --help)";
end if;
AADL_Language := Get_String_Name ("aadl");
Parse_Command_Line;
Config := Parse_Command_Line;
Put_Line ("Interface View: " & Config.Interface_View.all);
if Interface_View = 0 then
-- Try default filename
Set_Str_To_Name_Buffer ("InterfaceView.aadl");
......@@ -328,6 +313,13 @@ 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;
......@@ -372,6 +364,11 @@ exception
Put (Red_Bold & "[ERROR] " & White_Bold);
Put_Line (Exception_Message (Error) & No_Color);
OS_Exit (1);
when Exit_With_No_Error =>
New_Line;
Put (Yellow_Bold & "[INFO] " & No_Color);
Put ("For more information, visit " & Underline & White_Bold);
Put_Line ("https://taste.tools" & No_Color);
when E : others =>
Errors.Display_Bug_Box (E);
......
......@@ -9,14 +9,12 @@ with Ada.Text_IO,
Ocarina.FE_AADL.Parser,
Ocarina.Instances.Queries,
GNAT.OS_Lib,
Ada.Characters.Latin_1,
GNAT.Command_Line;
package body Parser_Utils is
use Ada.Text_IO,
Ocarina.Instances.Queries,
Ada.Characters.Latin_1,
GNAT.OS_Lib,
Ocarina.ME_AADL,
GNAT.Command_Line;
......@@ -30,8 +28,8 @@ package body Parser_Utils is
Yellow_Bold & "TASTE AADL Parser" & No_Color & " (Version "
& Parser_Version.Parser_Release & ") "
& ASCII.LF & ASCII.CR & No_Color
& "Contact: " & Underscore
& "Maxime.Perrotin@esa.int" & No_Color & " or " & Underscore
& "Contact: " & Underline
& "Maxime.Perrotin@esa.int" & No_Color & " or " & Underline
& "Thanassis.Tsiodras@esa.int"
& ASCII.LF & ASCII.CR & No_Color
& "Based on " & Parser_Version.Ocarina_Version;
......@@ -39,55 +37,6 @@ package body Parser_Utils is
Put_Line (The_Banner);
end Banner;
-----------
-- Usage --
-----------
procedure Usage is
begin
Put ("-l, --glue" & HT & HT & HT & HT);
Put_Line ("Generate glue code");
Put ("-w, --gw" & HT & HT & HT & HT);
Put_Line ("Generate code skeletons");
Put ("-o, --output <outputDir>" & HT & HT);
Put_Line ("Root directory for the output files");
Put ("-c, --deploymentview <d_view.aadl>" & HT);
Put_Line ("The deployment view in AADL");
Put ("-d, --dataview <dataview.aadl>" & HT & HT);
Put_Line ("The data view in AADL");
Put ("-t, --test" & HT & HT & HT & HT);
Put_Line ("Dump model information");
Put ("-g, --debug" & HT & HT & HT & HT);
Put_Line ("Generate runtime debug output");
Put ("-x, --timer <timer-resolution in ms>" & HT);
Put_Line ("Set the timer resolution (default 100 ms)");
Put ("-v, --version" & HT & HT & HT & HT);
Put_Line ("Display taste-aadl-parser version number");
Put ("-p, --polyorb-hi-c" & HT & HT & HT);
Put_Line ("Interface glue code with PolyORB-HI-C");
Put ("otherfiles" & HT & HT & HT & HT);
Put_Line ("Any other aadl file you want to parse");
Put_Line ("For example, this command will generate your application"
& " skeletons:");
New_Line;
Put_Line ("taste-aadl-parser -i InterfaceView.aadl -d DataView.aadl"
& " -o code --gw --keep-case");
New_Line;
end Usage;
function Parse_Command_Line return Taste_Configuration is
Config : Command_Line_Configuration;
Result : Taste_Configuration;
......@@ -104,6 +53,28 @@ package body Parser_Utils is
Switch => "-d:", Long_Switch => "--dataview=",
Help => "Optional data view (AADL model)",
Argument => "DataView.aadl");
Define_Switch (Config, Output => Result.Output_Dir'Access,
Switch => "-o:", Long_Switch => "--output=",
Help => "Output directory (to be created if absent)",
Argument => "Folder");
Define_Switch (Config, Output => Result.Skeletons'Access,
Switch => "-w", Long_Switch => "--gw",
Help => "Generate models and code skeletons");
Define_Switch (Config, Output => Result.Glue'Access,
Switch => "-l", Long_Switch => "--glue",
Help => "Generate glue code");
Define_Switch (Config, Output => Result.Use_POHIC'Access,
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",
Help => "Specify timer resolution (default 100 ms)");
Define_Switch (Config, Output => Result.Debug_Flag'Access,
Switch => "-g", Long_Switch => "--debug",
Help => "Set debug mode");
Define_Switch (Config, Output => Result.Version'Access,
Switch => "-v", Long_Switch => "--version",
Help => "Display tool version");
Getopt (Config);
loop
declare
......@@ -113,6 +84,19 @@ package body Parser_Utils is
Put_Line ("File argument : " & 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;
end Parse_Command_Line;
......
......@@ -42,14 +42,12 @@ package Parser_Utils is
(if Is_Tty then Yellow & Bold else "");
function No_Color return String is
(if Is_Tty then ASCII.ESC & "[0m" else "");
function Underscore return String is
function Underline return String is
(if Is_Tty then ASCII.ESC & "[4m" else "");
function White_Bold return String is (if Is_Tty then White & Bold else "");
procedure Banner;
procedure Usage;
AADL_Parser_Error : exception;
function Get_APLC_Binding (E : Node_Id) return List_Id;
......@@ -98,17 +96,13 @@ package Parser_Utils is
Interface_View : aliased GNAT.Strings.String_Access;
Deployment_View : aliased GNAT.Strings.String_Access;
Data_View : aliased GNAT.Strings.String_Access;
Use_POHIC : aliased Boolean;
Glue : aliased Boolean;
Smp2 : aliased Boolean;
Skeletons : aliased Boolean;
Test_Flag : aliased Boolean;
Aadlv2 : aliased Boolean;
Future_Flag : aliased Boolean;
Output_Dir : aliased GNAT.Strings.String_Access;
Timer_Resolution : aliased Natural;
Version : aliased Boolean;
Debug_Flag : aliased Boolean;
Skeletons : aliased Boolean := False;
Glue : aliased Boolean := False;
Use_POHIC : aliased Boolean := False;
Timer_Resolution : aliased Integer := 100;
Debug_Flag : aliased Boolean := False;
Version : aliased Boolean := False;
end record;
function Parse_Command_Line return Taste_Configuration;
......
package Parser_Version is
Parser_Release : constant String :=
"6db4c5b ; Commit Date: Thu Dec 7 14:05:24 2017 ";
"553b2d9 ; Commit Date: Sun Dec 17 22:21:17 2017 ";
Ocarina_Version : constant String :=
"Ocarina 2017.x (Working Copy from r0b92ed3)";
end Parser_Version;
\ No newline at end of file
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