ocarina-backends-pn.adb 5.49 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                  O C A R I N A . B A C K E N D S . P N                   --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2014 ESA & ISAE.      --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. Ocarina is distributed  in  the  hope  that it will be    --
-- useful, but WITHOUT ANY WARRANTY;  without even the implied warranty of  --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
31
32
33
--                                                                          --
------------------------------------------------------------------------------

34
35
with GNAT.OS_Lib; use GNAT.OS_Lib;

36
with Ocarina.Namet;
37
38
39
40
41
42
43
44
45
46
47

with Ocarina.Backends.Expander;
with Ocarina.Backends.PN.Components;
with Ocarina.Backends.PN.Nodes;
with Ocarina.Instances;

with Ocarina.Backends.PN.Format.Tina;
with Ocarina.Backends.PN.Format.Cami;

with Ocarina.Backends.PN.Printer;

48
with Ocarina.Output;
49
50
51
52
53
54
55
with Ocarina.Backends.Utils;

package body Ocarina.Backends.PN is

   package OPFT renames Ocarina.Backends.PN.Format.Tina;
   package OPFC renames Ocarina.Backends.PN.Format.Cami;

56
   use Ocarina.Namet;
jhugues's avatar
jhugues committed
57
58
59
60
61
62
   use Ocarina.Instances;
   use Ocarina.Backends.Expander;
   use Ocarina.Backends.PN.Components;
   use Ocarina.Backends.PN.Printer;
   use OPFT;
   use OPFC;
63
   use Ocarina.Output;
jhugues's avatar
jhugues committed
64
65
66
67
68
69
70
71
72
73
   use Ocarina.Backends.Utils;

   procedure Generate_TINA (AADL_Root : Types.Node_Id);
   procedure Generate_CAMI (AADL_Root : Types.Node_Id);

   -------------------
   -- Generate_TINA --
   -------------------

   procedure Generate_TINA (AADL_Root : Types.Node_Id) is
74
      PN_Generated, Instance_Root : Node_Id;
75
76
77
78
79
80
81
82
83
84

   begin
      --  Instantiate the AADL tree

      Instance_Root := Instantiate_Model (AADL_Root);

      --  Expand the AADL instance

      Expand (Instance_Root);

85
86
      if Present (Instance_Root) then
         --  Generate Petri Net
87

88
89
90
         PN_Generated := Process_Architecture_Instance (Instance_Root, 1);

         --  Set TINA printers
91
92
93
         Set_Printers (OPFT.Print_Place'Access,
                       OPFT.Print_Trans'Access,
                       OPFT.Print_Formalism_Information'Access);
94
95
96
97

         Set_Output (Create_File ("model.nd", Binary));
         Print_PN_Generated (PN_Generated);
         Set_Standard_Error;
98
      end if;
jhugues's avatar
jhugues committed
99
   end Generate_TINA;
100

jhugues's avatar
jhugues committed
101
102
103
104
105
   -------------------
   -- Generate_CAMI --
   -------------------

   procedure Generate_CAMI (AADL_Root : Types.Node_Id) is
106
      PN_Generated, Instance_Root : Node_Id;
jhugues's avatar
jhugues committed
107
108

   begin
109
110
111
112
113
114
115
116
117
      --  Instantiate the AADL tree

      Instance_Root := Instantiate_Model (AADL_Root);

      --  Expand the AADL instance

      Expand (Instance_Root);

      if Instance_Root /= No_Node then
118
         PN_Generated := Process_Architecture_Instance (Instance_Root, 0);
119
120
121
         Set_Printers (OPFC.Print_Place'Access,
                       OPFC.Print_Trans'Access,
                       OPFC.Print_Formalism_Information'Access);
122
123
124
         Set_Output (Create_File ("model.cami", Binary));
         Print_PN_Generated (PN_Generated);
         Set_Standard_Error;
125
      end if;
jhugues's avatar
jhugues committed
126
   end Generate_CAMI;
127

jhugues's avatar
jhugues committed
128
129
130
131
132
133
134
135
136
   --------------
   -- Generate --
   --------------

   procedure Generate (AADL_Root : Types.Node_Id) is
   begin
      Generate_TINA (AADL_Root);
      Reset_Handlings;
      Generate_CAMI (AADL_Root);
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
   end Generate;

   ----------
   -- Init --
   ----------

   procedure Init is
   begin
      Set_Str_To_Name_Buffer ("_");
      Separator := Name_Find;
      Register_Backend ("petri_nets", Generate'Access, Petri_Nets);
   end Init;

   -----------
   -- Reset --
   -----------

   procedure Reset is
   begin
      Ocarina.Backends.PN.Nodes.Entries.Init;
   end Reset;

end Ocarina.Backends.PN;