Commit 12b015cc authored by yoogx's avatar yoogx

* Flush current Python implem.

parent 6f3aef48
...@@ -81,7 +81,7 @@ package body Ocarina.FE_AADL.Parser is ...@@ -81,7 +81,7 @@ package body Ocarina.FE_AADL.Parser is
Initialize_Option_Scan; Initialize_Option_Scan;
loop loop
C := Getopt ("* y s f I:"); C := Getopt ("* y s f w I:");
case C is case C is
when ASCII.NUL => when ASCII.NUL =>
exit; exit;
...@@ -92,7 +92,7 @@ package body Ocarina.FE_AADL.Parser is ...@@ -92,7 +92,7 @@ package body Ocarina.FE_AADL.Parser is
when 'I' => when 'I' =>
Add_Library_Path (Parameter); Add_Library_Path (Parameter);
when 'f' | 's' => when 'f' | 's' | 'w' =>
Add_Pre_Prop_Sets := True; Add_Pre_Prop_Sets := True;
when others => when others =>
......
...@@ -31,18 +31,15 @@ ...@@ -31,18 +31,15 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO; with Ada.Directories; use Ada.Directories;
with GNATCOLL.Scripts; use GNATCOLL.Scripts; with Ada.Environment_Variables; use Ada.Environment_Variables;
with GNATCOLL.Scripts.Python; use GNATCOLL.Scripts.Python; with Ada.Text_IO; use Ada.Text_IO;
with Ocarina.Utils; with GNATCOLL.Scripts; use GNATCOLL.Scripts;
package body Ocarina.Python is with Ocarina.Python_Cmd;
function Register_Scripts_And_Functions package body Ocarina.Python is
return GNATCOLL.Scripts.Scripts_Repository;
-- Register the various scripting languages and the functions we
-- export to them
------------- -------------
-- Console -- -- Console --
...@@ -116,92 +113,73 @@ package body Ocarina.Python is ...@@ -116,92 +113,73 @@ package body Ocarina.Python is
Put (Standard_Error, Txt); Put (Standard_Error, Txt);
end Insert_Error; end Insert_Error;
----------------
-- On_Version --
----------------
procedure On_Version (Data : in out Callback_Data'Class; Command : String);
procedure On_Version
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Data, Command);
begin
Ocarina.Utils.Version;
end On_Version;
---------------
-- On_Status --
---------------
procedure On_Status (Data : in out Callback_Data'Class; Command : String);
procedure On_Status
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Data, Command);
begin
Ocarina.Utils.Print_Status;
end On_Status;
------------------------------------
-- Register_Scripts_And_Functions --
------------------------------------
function Register_Scripts_And_Functions return Scripts_Repository is
Repo : Scripts_Repository;
begin
-- Register all scripting languages. In practice, you only need to
-- register those you intend to support
Repo := new Scripts_Repository_Record;
Register_Python_Scripting (Repo, "Ocarina");
Register_Standard_Classes (Repo, "Console");
-- Register our custom functions
-- version() function
Register_Command
(Repo, "version", 0, 0, Handler => On_Version'Unrestricted_Access);
-- status() function
Register_Command
(Repo, "status", 0, 0, Handler => On_Status'Unrestricted_Access);
return Repo;
end Register_Scripts_And_Functions;
---------------- ----------------
-- Run_Python -- -- Run_Python --
---------------- ----------------
procedure Run_Python is procedure Run_Python is
Repo : Scripts_Repository := Register_Scripts_And_Functions; Repo : Scripts_Repository :=
Ocarina.Python_Cmd.Register_Scripts_And_Functions;
Buffer : String (1 .. 1000); Buffer : String (1 .. 1000);
Last : Integer; Last : Integer;
Errors : Boolean; Errors : Boolean;
Console : aliased Text_Console; Console : aliased Text_Console;
begin
Put_Line ("Ocarina interactive Python shell");
Put_Line ("Please type python commands:");
Set_Default_Console File : Ada.Text_IO.File_Type;
(Lookup_Scripting_Language (Repo, "python"), Console'Unchecked_Access); begin
-- Detect whether we are calling Ocarina directly, implying an
-- interactive session, or using it through a specific scripts.
declare
Env_Underscore : constant String := Value ("_");
-- This magic env. variable stores the name of the current
-- function being used.
begin
if Base_Name (Env_Underscore) = "ocarina" then
-- XXX to be tested on Windows ...
Put_Line ("Ocarina interactive Python shell");
Put_Line ("Please type python commands:");
Set_Default_Console
(Lookup_Scripting_Language (Repo, "python"),
Console'Unchecked_Access);
else
Ada.Text_IO.Open (File, Ada.Text_IO.In_File, Env_Underscore);
Set_Input (File);
end if;
end;
-- Iterate over all lines for the input buffer
loop loop
Get_Line (Buffer, Last); Get_Line (Current_Input, Buffer, Last);
Execute_Command
(Script => Lookup_Scripting_Language (Repo, "python"), -- Remove comments
Command => Buffer (1 .. Last),
Show_Command => False, for J in Buffer'First .. Last loop
Hide_Output => False, if Buffer (J) = '#' then
Errors => Errors); Last := J;
exit;
end if;
end loop;
if Last > Buffer'First then
Execute_Command
(Script => Lookup_Scripting_Language (Repo, "python"),
Command => Buffer (Buffer'First .. Last),
Show_Command => False,
Hide_Output => False,
Errors => Errors);
end if;
end loop; end loop;
exception exception
when End_Error => when End_Error =>
Destroy (Repo); Destroy (Repo);
if Is_Open (File) then
Close (File);
end if;
end Run_Python; end Run_Python;
end Ocarina.Python; end Ocarina.Python;
with GNATCOLL.Scripts; use GNATCOLL.Scripts;
with GNATCOLL.Scripts.Python; use GNATCOLL.Scripts.Python;
with Ocarina.Utils;
package body Ocarina.Python_Cmd is
----------------
-- On_Version --
----------------
procedure On_Version (Data : in out Callback_Data'Class; Command : String);
procedure On_Version
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Data, Command);
begin
Ocarina.Utils.Version;
end On_Version;
---------------
-- On_Status --
---------------
procedure On_Status (Data : in out Callback_Data'Class; Command : String);
procedure On_Status
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Data, Command);
begin
Ocarina.Utils.Print_Status;
end On_Status;
-----------------------
-- On_Load_AADL_File --
-----------------------
procedure On_Load_AADL_File
(Data : in out Callback_Data'Class; Command : String);
procedure On_Load_AADL_File
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Command);
begin
Ocarina.Utils.Load_AADL_File (Nth_Arg (Data, 1, ""));
end On_Load_AADL_File;
--------------------
-- On_Instantiate --
---------------------
procedure On_Instantiate
(Data : in out Callback_Data'Class; Command : String);
procedure On_Instantiate
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Command);
begin
Ocarina.Utils.Instantiate (Nth_Arg (Data, 1, ""));
end On_Instantiate;
----------------
-- On_Analyze --
----------------
procedure On_Analyze
(Data : in out Callback_Data'Class; Command : String);
procedure On_Analyze
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Command, Data);
begin
Ocarina.Utils.Analyze;
end On_Analyze;
-----------------
-- On_Generate --
-----------------
procedure On_Generate
(Data : in out Callback_Data'Class; Command : String);
procedure On_Generate
(Data : in out Callback_Data'Class;
Command : String)
is
pragma Unreferenced (Command);
begin
Ocarina.Utils.Generate (Nth_Arg (Data, 1, ""));
end On_Generate;
------------------------------------
-- Register_Scripts_And_Functions --
------------------------------------
function Register_Scripts_And_Functions return Scripts_Repository is
Repo : Scripts_Repository;
begin
-- Register all scripting languages. In practice, you only need to
-- register those you intend to support
Repo := new Scripts_Repository_Record;
Register_Python_Scripting (Repo, "ocarina");
Register_Standard_Classes (Repo, "Console");
-- Register our custom functions
-- version() function
Register_Command
(Repo, "version", 0, 0, Handler => On_Version'Unrestricted_Access);
-- status() function
Register_Command
(Repo, "status", 0, 0, Handler => On_Status'Unrestricted_Access);
-- load() function
Register_Command
(Repo, "load", 1, 1, Handler => On_Load_AADL_File'Unrestricted_Access);
-- analyze() function
Register_Command
(Repo, "analyze", 0, 0,
Handler => On_Analyze'Unrestricted_Access);
-- instantiate() function
Register_Command
(Repo, "instantiate", 1, 1,
Handler => On_Instantiate'Unrestricted_Access);
-- generate() function
Register_Command
(Repo, "generate", 1, 1,
Handler => On_Generate'Unrestricted_Access);
return Repo;
end Register_Scripts_And_Functions;
end Ocarina.Python_Cmd;
with GNATCOLL.Scripts;
package Ocarina.Python_Cmd is
-- This package provides a central access to register functions to
-- the Python bindings
function Register_Scripts_And_Functions
return GNATCOLL.Scripts.Scripts_Repository;
-- Register the Python scripting language, and the functions we
-- export
end Ocarina.Python_Cmd;
...@@ -32,11 +32,9 @@ ...@@ -32,11 +32,9 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Errors; use Errors; with Errors; use Errors;
with Locations; use Locations;
with Namet; use Namet; with Namet; use Namet;
with Output; use Output; with Output; use Output;
with Types; use Types; with Types; use Types;
with Utils; use Utils;
with Ada.Unchecked_Deallocation; with Ada.Unchecked_Deallocation;
with Ada.Exceptions; use Ada.Exceptions; with Ada.Exceptions; use Ada.Exceptions;
...@@ -45,13 +43,8 @@ with Ada.Text_IO; ...@@ -45,13 +43,8 @@ with Ada.Text_IO;
with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.OS_Lib; use GNAT.OS_Lib;
with Ocarina.Parser; use Ocarina.Parser;
with Ocarina.Backends; use Ocarina.Backends; with Ocarina.Backends; use Ocarina.Backends;
with Ocarina.Files; use Ocarina.Files;
with Ocarina.Instances; use Ocarina.Instances; with Ocarina.Instances; use Ocarina.Instances;
with Ocarina.Options; use Ocarina.Options;
with Ocarina.Analyzer; use Ocarina.Analyzer;
with Ocarina.Transfo.Fusions; use Ocarina.Transfo.Fusions; with Ocarina.Transfo.Fusions; use Ocarina.Transfo.Fusions;
with Ocarina.Transfo.Move; use Ocarina.Transfo.Move; with Ocarina.Transfo.Move; use Ocarina.Transfo.Move;
with Ocarina.Transfo.Optim; use Ocarina.Transfo.Optim; with Ocarina.Transfo.Optim; use Ocarina.Transfo.Optim;
...@@ -64,7 +57,6 @@ package body Ocarina.Scripts is ...@@ -64,7 +57,6 @@ package body Ocarina.Scripts is
------------------- -------------------
procedure Ocarina_Shell is procedure Ocarina_Shell is
use Ada.Text_IO; use Ada.Text_IO;
function "+" (S : String) return String_Access; function "+" (S : String) return String_Access;
...@@ -100,10 +92,7 @@ package body Ocarina.Scripts is ...@@ -100,10 +92,7 @@ package body Ocarina.Scripts is
Cmmd : Command; Cmmd : Command;
Success : Boolean; Success : Boolean;
AADL_Root : Node_Id := No_Node; AADL_Root : constant Node_Id := No_Node;
File_Name : Name_Id;
Buffer : Location;
Language : Name_Id;
--------- ---------
-- "+" -- -- "+" --
...@@ -251,15 +240,12 @@ package body Ocarina.Scripts is ...@@ -251,15 +240,12 @@ package body Ocarina.Scripts is
end Next; end Next;
begin begin
Language := Get_String_Name ("aadl");
if Standard_Input then if Standard_Input then
Write_Line ("Ocarina shell, type help for information"); Write_Line ("Ocarina shell, type help for information");
end if; end if;
-- Console main loop: read inputs and process them -- Console main loop: read inputs and process them
<<Main>>
loop loop
Argc := Count; Argc := Count;
if Argc > 0 if Argc > 0
...@@ -280,59 +266,26 @@ package body Ocarina.Scripts is ...@@ -280,59 +266,26 @@ package body Ocarina.Scripts is
Show_Help; Show_Help;
when Analyze => when Analyze =>
Success := Analyze (Language, AADL_Root); Ocarina.Utils.Analyze;
if not Success then
Write_Line ("Cannot analyze AADL specifications");
else
Write_Line ("Model analyzed sucessfully");
end if;
when Instantiate => when Instantiate =>
if Argc = 2 then if Argc = 2 then
Root_System_Name := To_Lower Ocarina.Utils.Instantiate (Argument (2).all);
(Get_String_Name (Argument (2).all)); else
end if; Ocarina.Utils.Instantiate ("");
AADL_Root := Instantiate_Model (AADL_Root);
if Present (AADL_Root) then
Write_Line ("Model instantiated sucessfully");
end if; end if;
when Generate => when Generate =>
if Argc /= 2 then if Argc /= 2 then
raise Syntax_Error; raise Syntax_Error;
end if; end if;
Set_Current_Backend_Name (Argument (2).all); Ocarina.Utils.Generate (Argument (2).all);
Write_Line ("Generating code for "
& Argument (2).all);
Generate_Code (AADL_Root);
when Load => when Load =>
if Argc /= 2 then if Argc /= 2 then
raise Syntax_Error; raise Syntax_Error;
end if; end if;
Set_Str_To_Name_Buffer (Argument (2).all); Ocarina.Utils.Load_AADL_File (Argument (2).all);
File_Name := Search_File (Name_Find);
if File_Name = No_Name then
Write_Line ("cannot find file "
& Argument (2).all);
goto Main;
end if;
Buffer := Load_File (File_Name);
if File_Name = No_Name then
Write_Line ("cannot read file "
& Argument (2).all);
goto Main;
end if;
AADL_Root := Parse (Language, AADL_Root, Buffer);
Exit_On_Error
(No (AADL_Root),
"cannot parse AADL specifications");
Write_Line
("File " & Argument (2).all
& " loaded and parsed sucessfully");
when Brute_Optimize => when Brute_Optimize =>
declare declare
......
...@@ -35,17 +35,31 @@ with Ada.Command_Line; use Ada.Command_Line; ...@@ -35,17 +35,31 @@ with Ada.Command_Line; use Ada.Command_Line;
with GNAT.Directory_Operations; use GNAT.Directory_Operations; with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.OS_Lib; use GNAT.OS_Lib;
with Errors; use Errors;
with Locations; use Locations;
with Namet; use Namet; with Namet; use Namet;
with Output; use Output; with Output; use Output;
with Types; use Types;
with Utils; use Utils;
with Ocarina.Analyzer; use Ocarina.Analyzer;
with Ocarina.Backends; use Ocarina.Backends; with Ocarina.Backends; use Ocarina.Backends;
with Ocarina.Configuration; use Ocarina.Configuration; with Ocarina.Configuration; use Ocarina.Configuration;
with Ocarina.FE_AADL; use Ocarina.FE_AADL; with Ocarina.FE_AADL; use Ocarina.FE_AADL;
with Ocarina.FE_AADL.Parser;
with Ocarina.FE_REAL; use Ocarina.FE_REAL; with Ocarina.FE_REAL; use Ocarina.FE_REAL;
with Ocarina.Options; use Ocarina.Options; with Ocarina.Instances; use Ocarina.Instances;
with Ocarina.Parser; use Ocarina.Parser;
with Ocarina.Options; use Ocarina.Options;
with Ocarina.Files; use Ocarina.Files;
package body Ocarina.Utils is package body Ocarina.Utils is
AADL_Root : Node_Id := No_Node;
File_Name : Name_Id;
Buffer : Location;
Language : Name_Id;
------------- -------------
-- Version -- -- Version --
------------- -------------
...@@ -74,6 +88,8 @@ package body Ocarina.Utils is ...@@ -74,6 +88,8 @@ package body Ocarina.Utils is
Write_Line ("AADL version: " & Ocarina.AADL_Version'Img); Write_Line ("AADL version: " & Ocarina.AADL_Version'Img);
Write_Line ("Library Path: " Write_Line ("Library Path: "
& Get_Name_String (Default_Library_Path)); & Get_Name_String (Default_Library_Path));
Write_Line ("Load predefined property sets "
& Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets'Img);
end Print_Status; end Print_Status;
----------- -----------
...@@ -134,4 +150,76 @@ package body Ocarina.Utils is ...@@ -134,4 +150,76 @@ package body Ocarina.Utils is
Free (Exec_Suffix); Free (Exec_Suffix);
end Usage; end Usage;
--------------------
-- Load_AADL_File --
--------------------
procedure Load_AADL_File (Filename : String) is
begin
Language := Get_String_Name ("aadl");
Set_Str_To_Name_Buffer (Filename);
File_Name := Search_File (Name_Find);
if File_Name = No_Name then
Write_Line ("Cannot find file " & Filename);
return;
end if;
Buffer := Load_File (File_Name);
if File_Name = No_Name then
Write_Line ("Cannot read file " & Filename);
return;
end if;
AADL_Root := Parse (Language, AADL_Root, Buffer);
Exit_On_Error
(No (AADL_Root),
"Cannot parse AADL specifications");
Write_Line
("File " & Filename
& " loaded and parsed sucessfully");
end Load_AADL_File;
-------------
-- Analyze --
-------------
procedure Analyze is
Success : Boolean;
begin
Success := Analyze (Language, AADL_Root);
if not Success then
Write_Line ("Cannot analyze AADL specifications");
else
Write_Line ("Model analyzed sucessfully");
end if;
end Analyze;
-----------------
-- Instantiate --
-----------------
procedure Instantiate (Root_System : String) is
begin
if Root_System /= "" then
Root_System_Name := To_Lower
(Get_String_Name (Root_System));
end if;
AADL_Root := Instantiate_Model (AADL_Root);
if Present (AADL_Root) then
Write_Line ("Model instantiated sucessfully");
end if;
end Instantiate;
--------------
-- Generate --
--------------
procedure Generate (Backend_Name : String) is
begin
Set_Current_Backend_Name (Backend_Name);
Write_Line ("Generating code using backend " & Backend_Name);
Generate_Code (AADL_Root);
end Generate;
end Ocarina.Utils; end Ocarina.Utils;
...@@ -40,5 +40,11 @@ package Ocarina.Utils is ...@@ -40,5 +40,11 @@ package Ocarina.Utils is
-- Display a message describing the usage of Ocarina -- Display a message describing the usage of Ocarina
procedure Print_Status; procedure Print_Status;
-- Display status information on Ocarina
procedure Load_AADL_File (Filename : String);
procedure Analyze;
procedure Instantiate (Root_System : String);
procedure Generate (Backend_Name : String);
end Ocarina.Utils; end Ocarina.Utils;
...@@ -67,9 +67,9 @@ with Ocarina.Parser; use Ocarina.Parser; ...@@ -67,9 +67,9 @@ with Ocarina.Parser; use Ocarina.Parser;
with Ocarina.Property_Sets; use Ocarina.Property_Sets; with Ocarina.Property_Sets; use Ocarina.Property_Sets;
with Ocarina.FE_AADL.Parser; use Ocarina.FE_AADL.Parser; with Ocarina.FE_AADL.Parser; use Ocarina.FE_AADL.Parser;
with Ocarina.ME_REAL.Tokens; with Ocarina.ME_REAL.Tokens;
with Ocarina.Scripts; use Ocarina.Scripts; with Ocarina.Scripts; use Ocarina.Scripts;
with Ocarina.Utils; use Ocarina.Utils; with Ocarina.Utils; use Ocarina.Utils;
with Ocarina.Python; use Ocarina.Python; with Ocarina.Python; use Ocarina.Python;
with Ocarina.ME_AADL.AADL_Instances.Nodes; with Ocarina.ME_AADL.AADL_Instances.Nodes;
procedure Ocarina_Cmd is procedure Ocarina_Cmd is
...@@ -633,9 +633,9 @@ procedure Ocarina_Cmd is ...@@ -633,9 +633,9 @@ procedure Ocarina_Cmd is
case Getopt ("* aadlv1 aadlv2 help o: c d g: " case Getopt ("* aadlv1 aadlv2 help o: c d g: "
& "r: real_lib: real_theorem: boundt_process: " & "r: real_lib: real_theorem: boundt_process: "
& "disable-annexes=: " & "disable-annexes=: "
& "i p q v V s x t? z") is & "i p q v V s x t? w") is
when 'z' => when 'w' =>
Set_Current_Action (Python_Shell); Set_Current_Action (Python_Shell);
when 'a' => when 'a' =>
...@@ -832,7 +832,7 @@ begin ...@@ -832,7 +832,7 @@ begin