Skip to content

Commit

Permalink
* Clean up command line interfaces, concentrate all machinery
Browse files Browse the repository at this point in the history
          in new package Ocarina.Cmd_Line, rework all
          frontend/backends to avoid code duplication.

          For issue #33

          Also fix for issue #54
  • Loading branch information
yoogx committed Dec 29, 2015
1 parent aa036ed commit 50f1406
Show file tree
Hide file tree
Showing 31 changed files with 519 additions and 1,412 deletions.
26 changes: 0 additions & 26 deletions src/backends/ocarina-backends-aadl_xml.adb
Expand Up @@ -37,9 +37,6 @@ with Ocarina.Backends.Utils;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
with Ocarina.Backends.XML_Tree.Generator;
with GNAT.Command_Line; use GNAT.Command_Line;

with Ocarina.Namet; use Ocarina.Namet;

package body Ocarina.Backends.AADL_XML is

Expand All @@ -51,8 +48,6 @@ package body Ocarina.Backends.AADL_XML is
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
package XTU renames Ocarina.Backends.XML_Tree.Nutils;

Generated_Sources_Directory : Name_Id := No_Name;

procedure Visit_Architecture_Instance (E : Node_Id);
-- Most top level visitor routine. E is the root of the AADL
-- instance tree. The procedure does a traversal for each
Expand Down Expand Up @@ -99,27 +94,6 @@ package body Ocarina.Backends.AADL_XML is

procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* o:") is
when ASCII.NUL =>
exit;

when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;

when others =>
null;
end case;
end loop;

Register_Backend ("aadl_xml", Generate'Access, AADLXML);
end Init;

Expand Down
16 changes: 1 addition & 15 deletions src/backends/ocarina-backends-alloy.adb
Expand Up @@ -37,7 +37,6 @@ with Ocarina.Instances; use Ocarina.Instances;
with Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.ME_AADL.AADL_Instances.Entities;

with GNAT.Command_Line;
with Ocarina.Backends.Utils;
with Ada.Text_IO;

Expand Down Expand Up @@ -224,9 +223,8 @@ package body Ocarina.Backends.Alloy is
--------------

procedure Generate (AADL_Root : Node_Id) is
use GNAT.Command_Line;

Instance_Root : Node_Id;

begin
-- Instantiate the AADL tree

Expand All @@ -235,18 +233,6 @@ package body Ocarina.Backends.Alloy is
raise Program_Error;
end if;

Initialize_Option_Scan;
loop
case Getopt ("* ") is

when ASCII.NUL =>
exit;

when others =>
null;
end case;
end loop;

-- Open a new .als file

Create (File => FD, Name => "con_model.als");
Expand Down
29 changes: 0 additions & 29 deletions src/backends/ocarina-backends-arinc653_conf.adb
Expand Up @@ -44,8 +44,6 @@ with Ocarina.Backends.ARINC653_Conf.System_HM;
with Ocarina.Backends.ARINC653_Conf.Module_HM;
with Ocarina.Backends.Utils;

with GNAT.Command_Line; use GNAT.Command_Line;

with Ocarina.Namet; use Ocarina.Namet;

package body Ocarina.Backends.ARINC653_Conf is
Expand All @@ -59,9 +57,6 @@ package body Ocarina.Backends.ARINC653_Conf is
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
package XTU renames Ocarina.Backends.XML_Tree.Nutils;

Remove_Generated_Sources : Boolean := False;
Generated_Sources_Directory : Name_Id := No_Name;

--------------
-- Generate --
--------------
Expand Down Expand Up @@ -107,30 +102,6 @@ package body Ocarina.Backends.ARINC653_Conf is

procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* b z o:") is
when ASCII.NUL =>
exit;

when 'z' =>
Remove_Generated_Sources := True;

when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;

when others =>
null;
end case;
end loop;

Register_Backend ("ARINC653_Conf", Generate'Access, Statistics);
end Init;

Expand Down
30 changes: 0 additions & 30 deletions src/backends/ocarina-backends-asn1.adb
Expand Up @@ -36,25 +36,16 @@ with Ocarina.Backends.ASN1_Tree.Generator;
with Ocarina.Backends.ASN1_Tree.Nutils;
with Ocarina.Backends.ASN1.Deployment;
with Ocarina.Backends.Utils;
with GNAT.Command_Line;

with Ocarina.Namet;

package body Ocarina.Backends.ASN1 is

use GNAT.Command_Line;

use Ocarina.Namet;

use Ocarina.Backends.Messages;
use Ocarina.Backends.ASN1_Tree.Generator;
use Ocarina.Backends.ASN1_Tree.Nutils;
use Ocarina.Backends.Utils;
use Ocarina.Backends.Expander;
use Ocarina.Instances;

Generated_Sources_Directory : Name_Id := No_Name;

procedure Visit_Architecture_Instance (E : Node_Id);
-- Most top level visitor routine. E is the root of the AADL
-- instance tree. The procedure does a traversal for each
Expand Down Expand Up @@ -99,27 +90,6 @@ package body Ocarina.Backends.ASN1 is
procedure Init is
begin
ASN1_Tree.Nutils.Initialize;
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* b z ec er o: perf") is
when ASCII.NUL =>
exit;

when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;

when others =>
null;
end case;
end loop;

Register_Backend ("asn1_deployment", Generate'Access, ASN1_Deployment);
end Init;

Expand Down
24 changes: 2 additions & 22 deletions src/backends/ocarina-backends-boundt.adb
Expand Up @@ -39,7 +39,7 @@ with Ocarina.Instances; use Ocarina.Instances;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Properties; use Ocarina.Backends.Properties;
with Ocarina.Options; use Ocarina.Options;
with GNAT.Command_Line;

with Utils; use Utils;

with Ada.Text_IO;
Expand Down Expand Up @@ -290,8 +290,6 @@ package body Ocarina.Backends.BoundT is

procedure Init is
begin
-- Registration of the generator

Register_Backend ("boundt", Generate'Access, Bound_T);
end Init;

Expand All @@ -300,9 +298,8 @@ package body Ocarina.Backends.BoundT is
--------------

procedure Generate (AADL_Root : Node_Id) is
use GNAT.Command_Line;

Instance_Root : Node_Id;

begin
-- Instantiate the AADL tree

Expand All @@ -311,23 +308,6 @@ package body Ocarina.Backends.BoundT is
raise Program_Error;
end if;

Initialize_Option_Scan;
loop
case Getopt ("* boundt_process:") is

when ASCII.NUL =>
exit;

when 'b' =>
if Full_Switch = "boundt_process" then
Boundt_Process := To_Lower (Get_String_Name (Parameter));
end if;

when others =>
null;
end case;
end loop;

-- Open a new TPO file

if Boundt_Process = No_Name then
Expand Down
28 changes: 0 additions & 28 deletions src/backends/ocarina-backends-carts.adb
Expand Up @@ -37,7 +37,6 @@ with Ocarina.Backends.Utils;
with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
with Ocarina.Backends.XML_Tree.Generator;
with GNAT.Command_Line; use GNAT.Command_Line;

with Ocarina.Namet; use Ocarina.Namet;

Expand All @@ -51,9 +50,6 @@ package body Ocarina.Backends.Carts is
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
package XTU renames Ocarina.Backends.XML_Tree.Nutils;

Generated_Sources_Directory : Name_Id := No_Name;
Remove_Generated_Sources : Boolean := False;

procedure Visit_Architecture_Instance (E : Node_Id);
-- Most top level visitor routine. E is the root of the AADL
-- instance tree. The procedure does a traversal for each
Expand Down Expand Up @@ -97,30 +93,6 @@ package body Ocarina.Backends.Carts is

procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* z o:") is
when ASCII.NUL =>
exit;

when 'z' =>
Remove_Generated_Sources := True;

when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;

when others =>
null;
end case;
end loop;

Register_Backend ("carts", Generate'Access, Carts_XML);
end Init;

Expand Down
27 changes: 0 additions & 27 deletions src/backends/ocarina-backends-cheddar.adb
Expand Up @@ -38,10 +38,6 @@ with Ocarina.Backends.XML_Tree.Nodes;
with Ocarina.Backends.XML_Tree.Nutils;
with Ocarina.Backends.XML_Tree.Generator;

with GNAT.Command_Line; use GNAT.Command_Line;

with Ocarina.Namet; use Ocarina.Namet;

package body Ocarina.Backends.Cheddar is

use Ocarina.Instances;
Expand All @@ -52,8 +48,6 @@ package body Ocarina.Backends.Cheddar is
package XTN renames Ocarina.Backends.XML_Tree.Nodes;
package XTU renames Ocarina.Backends.XML_Tree.Nutils;

Generated_Sources_Directory : Name_Id := No_Name;

procedure Visit_Architecture_Instance (E : Node_Id);
-- Most top level visitor routine. E is the root of the AADL
-- instance tree. The procedure does a traversal for each
Expand Down Expand Up @@ -102,27 +96,6 @@ package body Ocarina.Backends.Cheddar is

procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* b o:") is
when ASCII.NUL =>
exit;

when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;

when others =>
null;
end case;
end loop;

Register_Backend ("cheddar", Generate'Access, Cheddar_XML);
end Init;

Expand Down
31 changes: 0 additions & 31 deletions src/backends/ocarina-backends-connection_matrix.adb
Expand Up @@ -36,10 +36,6 @@ with Ocarina.Backends.XML_Tree.Generator;
with Ocarina.Backends.Utils;
with Ocarina.Backends.Connection_Matrix.Main;

with GNAT.Command_Line; use GNAT.Command_Line;

with Ocarina.Namet; use Ocarina.Namet;

package body Ocarina.Backends.Connection_Matrix is

use Ocarina.Instances;
Expand All @@ -48,9 +44,6 @@ package body Ocarina.Backends.Connection_Matrix is
use Ocarina.Backends.XML_Tree.Generator;
use Ocarina.Backends.Utils;

Remove_Generated_Sources : Boolean := False;
Generated_Sources_Directory : Name_Id := No_Name;

procedure Visit_Architecture_Instance (E : Node_Id);
-- Most top level visitor routine. E is the root of the AADL
-- instance tree. The procedure does a traversal for each
Expand Down Expand Up @@ -99,30 +92,6 @@ package body Ocarina.Backends.Connection_Matrix is

procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* b z o:") is
when ASCII.NUL =>
exit;

when 'z' =>
Remove_Generated_Sources := True;

when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;

when others =>
null;
end case;
end loop;

Register_Backend
("Connection_Matrix",
Generate'Access,
Expand Down

0 comments on commit 50f1406

Please sign in to comment.