Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
Ocarina
Commits
12b015cc
Commit
12b015cc
authored
Dec 05, 2013
by
yoogx
Browse files
* Flush current Python implem.
parent
6f3aef48
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/frontends/aadl/ocarina-fe_aadl-parser.adb
View file @
12b015cc
...
...
@@ -81,7 +81,7 @@ package body Ocarina.FE_AADL.Parser is
Initialize_Option_Scan
;
loop
C
:=
Getopt
(
"* y s f I:"
);
C
:=
Getopt
(
"* y s f
w
I:"
);
case
C
is
when
ASCII
.
NUL
=>
exit
;
...
...
@@ -92,7 +92,7 @@ package body Ocarina.FE_AADL.Parser is
when
'I'
=>
Add_Library_Path
(
Parameter
);
when
'f'
|
's'
=>
when
'f'
|
's'
|
'w'
=>
Add_Pre_Prop_Sets
:=
True
;
when
others
=>
...
...
src/main/ocarina-python.adb
View file @
12b015cc
...
...
@@ -31,18 +31,15 @@
-- --
------------------------------------------------------------------------------
with
Ada
.
Text_IO
;
use
Ada
.
Text_IO
;
with
GNATCOLL
.
Scripts
;
use
GNATCOLL
.
Script
s
;
with
GNATCOLL
.
Scripts
.
Python
;
use
GNATCOLL
.
Scripts
.
Python
;
with
Ada
.
Directories
;
use
Ada
.
Directories
;
with
Ada
.
Environment_Variables
;
use
Ada
.
Environment_Variable
s
;
with
Ada
.
Text_IO
;
use
Ada
.
Text_IO
;
with
Ocarina
.
Util
s
;
with
GNATCOLL
.
Scripts
;
use
GNATCOLL
.
Script
s
;
package
body
Ocarina
.
Python
is
with
Ocarina
.
Python
_Cmd
;
function
Register_Scripts_And_Functions
return
GNATCOLL
.
Scripts
.
Scripts_Repository
;
-- Register the various scripting languages and the functions we
-- export to them
package
body
Ocarina
.
Python
is
-------------
-- Console --
...
...
@@ -116,92 +113,73 @@ package body Ocarina.Python is
Put
(
Standard_Error
,
Txt
);
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 --
----------------
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
);
Last
:
Integer
;
Errors
:
Boolean
;
Console
:
aliased
Text_Console
;
begin
Put_Line
(
"Ocarina interactive Python shell"
);
Put_Line
(
"Please type python commands:"
);
Set_Default_Console
(
Lookup_Scripting_Language
(
Repo
,
"python"
),
Console
'
Unchecked_Access
);
File
:
Ada
.
Text_IO
.
File_Type
;
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
Get_Line
(
Buffer
,
Last
);
Execute_Command
(
Script
=>
Lookup_Scripting_Language
(
Repo
,
"python"
),
Command
=>
Buffer
(
1
..
Last
),
Show_Command
=>
False
,
Hide_Output
=>
False
,
Errors
=>
Errors
);
Get_Line
(
Current_Input
,
Buffer
,
Last
);
-- Remove comments
for
J
in
Buffer
'
First
..
Last
loop
if
Buffer
(
J
)
=
'#'
then
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
;
exception
when
End_Error
=>
Destroy
(
Repo
);
if
Is_Open
(
File
)
then
Close
(
File
);
end
if
;
end
Run_Python
;
end
Ocarina
.
Python
;
src/main/ocarina-python_cmd.adb
0 → 100644
View file @
12b015cc
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
;
src/main/ocarina-python_cmd.ads
0 → 100644
View file @
12b015cc
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
;
src/main/ocarina-scripts.adb
View file @
12b015cc
...
...
@@ -32,11 +32,9 @@
------------------------------------------------------------------------------
with
Errors
;
use
Errors
;
with
Locations
;
use
Locations
;
with
Namet
;
use
Namet
;
with
Output
;
use
Output
;
with
Types
;
use
Types
;
with
Utils
;
use
Utils
;
with
Ada
.
Unchecked_Deallocation
;
with
Ada
.
Exceptions
;
use
Ada
.
Exceptions
;
...
...
@@ -45,13 +43,8 @@ with Ada.Text_IO;
with
GNAT
.
OS_Lib
;
use
GNAT
.
OS_Lib
;
with
Ocarina
.
Parser
;
use
Ocarina
.
Parser
;
with
Ocarina
.
Backends
;
use
Ocarina
.
Backends
;
with
Ocarina
.
Files
;
use
Ocarina
.
Files
;
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
.
Move
;
use
Ocarina
.
Transfo
.
Move
;
with
Ocarina
.
Transfo
.
Optim
;
use
Ocarina
.
Transfo
.
Optim
;
...
...
@@ -64,7 +57,6 @@ package body Ocarina.Scripts is
-------------------
procedure
Ocarina_Shell
is
use
Ada
.
Text_IO
;
function
"+"
(
S
:
String
)
return
String_Access
;
...
...
@@ -100,10 +92,7 @@ package body Ocarina.Scripts is
Cmmd
:
Command
;
Success
:
Boolean
;
AADL_Root
:
Node_Id
:=
No_Node
;
File_Name
:
Name_Id
;
Buffer
:
Location
;
Language
:
Name_Id
;
AADL_Root
:
constant
Node_Id
:=
No_Node
;
---------
-- "+" --
...
...
@@ -251,15 +240,12 @@ package body Ocarina.Scripts is
end
Next
;
begin
Language
:=
Get_String_Name
(
"aadl"
);
if
Standard_Input
then
Write_Line
(
"Ocarina shell, type help for information"
);
end
if
;
-- Console main loop: read inputs and process them
<<Main>>
loop
Argc
:=
Count
;
if
Argc
>
0
...
...
@@ -280,59 +266,26 @@ package body Ocarina.Scripts is
Show_Help
;
when
Analyze
=>
Success
:=
Analyze
(
Language
,
AADL_Root
);
if
not
Success
then
Write_Line
(
"Cannot analyze AADL specifications"
);
else
Write_Line
(
"Model analyzed sucessfully"
);
end
if
;
Ocarina
.
Utils
.
Analyze
;
when
Instantiate
=>
if
Argc
=
2
then
Root_System_Name
:=
To_Lower
(
Get_String_Name
(
Argument
(
2
).
all
));
end
if
;
AADL_Root
:=
Instantiate_Model
(
AADL_Root
);
if
Present
(
AADL_Root
)
then
Write_Line
(
"Model instantiated sucessfully"
);
Ocarina
.
Utils
.
Instantiate
(
Argument
(
2
).
all
);
else
Ocarina
.
Utils
.
Instantiate
(
""
);
end
if
;
when
Generate
=>
if
Argc
/=
2
then
raise
Syntax_Error
;
end
if
;
Set_Current_Backend_Name
(
Argument
(
2
).
all
);
Write_Line
(
"Generating code for "
&
Argument
(
2
).
all
);
Generate_Code
(
AADL_Root
);
Ocarina
.
Utils
.
Generate
(
Argument
(
2
).
all
);
when
Load
=>
if
Argc
/=
2
then
raise
Syntax_Error
;
end
if
;
Set_Str_To_Name_Buffer
(
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"
);
Ocarina
.
Utils
.
Load_AADL_File
(
Argument
(
2
).
all
);
when
Brute_Optimize
=>
declare
...
...
src/main/ocarina-utils.adb
View file @
12b015cc
...
...
@@ -35,17 +35,31 @@ with Ada.Command_Line; use Ada.Command_Line;
with
GNAT
.
Directory_Operations
;
use
GNAT
.
Directory_Operations
;
with
GNAT
.
OS_Lib
;
use
GNAT
.
OS_Lib
;
with
Errors
;
use
Errors
;
with
Locations
;
use
Locations
;
with
Namet
;
use
Namet
;
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
.
Configuration
;
use
Ocarina
.
Configuration
;
with
Ocarina
.
FE_AADL
;
use
Ocarina
.
FE_AADL
;
with
Ocarina
.
FE_AADL
.
Parser
;
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
AADL_Root
:
Node_Id
:=
No_Node
;
File_Name
:
Name_Id
;
Buffer
:
Location
;
Language
:
Name_Id
;
-------------
-- Version --
-------------
...
...
@@ -74,6 +88,8 @@ package body Ocarina.Utils is
Write_Line
(
"AADL version: "
&
Ocarina
.
AADL_Version
'
Img
);
Write_Line
(
"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
;
-----------
...
...
@@ -134,4 +150,76 @@ package body Ocarina.Utils is
Free
(
Exec_Suffix
);
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
;
src/main/ocarina-utils.ads
View file @
12b015cc
...
...
@@ -40,5 +40,11 @@ package Ocarina.Utils is
-- Display a message describing the usage of Ocarina
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
;
src/main/ocarina_cmd.adb
View file @
12b015cc
...
...
@@ -67,9 +67,9 @@ with Ocarina.Parser; use Ocarina.Parser;
with
Ocarina
.
Property_Sets
;
use
Ocarina
.
Property_Sets
;
with
Ocarina
.
FE_AADL
.
Parser
;
use
Ocarina
.
FE_AADL
.
Parser
;
with
Ocarina
.
ME_REAL
.
Tokens
;
with
Ocarina
.
Scripts
;
use
Ocarina
.
Scripts
;
with
Ocarina
.
Utils
;
use
Ocarina
.
Utils
;
with
Ocarina
.
Python
;
use
Ocarina
.
Python
;
with
Ocarina
.
Scripts
;
use
Ocarina
.
Scripts
;
with
Ocarina
.
Utils
;
use
Ocarina
.
Utils
;
with
Ocarina
.
Python
;
use
Ocarina
.
Python
;
with
Ocarina
.
ME_AADL
.
AADL_Instances
.
Nodes
;