ocarina-backends-pok_c.adb 10.2 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 O K _ C                --
--                                                                          --
--                                 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--                                                                          --
------------------------------------------------------------------------------

with Ocarina.Instances;
with Ocarina.Backends.Expander;
with Ocarina.Backends.Messages;
with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Tree.Nutils;
with Ocarina.Backends.C_Tree.Generator;
with Ocarina.Backends.Utils;
with Ocarina.Backends.Execution_Tests;
with Ocarina.Backends.Execution_Utils;
with Ocarina.Backends.POK_C.Runtime;
with Ocarina.Backends.POK_C.Naming;
with Ocarina.Backends.POK_C.Main;
with Ocarina.Backends.POK_C.Activity;
with Ocarina.Backends.POK_C.Deployment;
with Ocarina.Backends.C_Common.Types;
with Ocarina.Backends.C_Common.Subprograms;
with Ocarina.Backends.POK_C.Makefile;
with Ocarina.Backends.ARINC653_Conf;
with Ocarina.Backends.POK_Cheddar;
with Ocarina.Backends.XML_Tree.Generator;

with GNAT.Command_Line; use GNAT.Command_Line;
56
with GNAT.OS_Lib;       use GNAT.OS_Lib;
57

yoogx's avatar
yoogx committed
58
with Ocarina.Namet;  use Ocarina.Namet;
59
with Ocarina.Output; use Ocarina.Output;
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

package body Ocarina.Backends.POK_C is
   use Ocarina.Instances;
   use Ocarina.Backends.Expander;
   use Ocarina.Backends.Messages;
   use Ocarina.Backends.C_Tree.Generator;
   use Ocarina.Backends.Utils;
   use Ocarina.Backends.Execution_Utils;
   use Ocarina.Backends.Execution_Tests;
   use Ocarina.Backends.POK_C.Deployment;
   use Ocarina.Backends.POK_C.Naming;
   use Ocarina.Backends.XML_Tree.Generator;
   use Ocarina.Backends.ARINC653_Conf;

   package CTN renames Ocarina.Backends.C_Tree.Nodes;
   package CTU renames Ocarina.Backends.C_Tree.Nutils;

   Generated_Sources_Directory : Name_Id := No_Name;
   Remove_Generated_Sources    : Boolean := False;
   Build_Generated_Sources     : Boolean := False;
   Do_Regression_Test          : Boolean := False;
   Do_Coverage_Test            : 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
   --  compilation unit to be generated.

   ---------------------------------
   -- Display_Communication_Error --
   ---------------------------------

   procedure Display_Communication_Error is
   begin
      Display_Error
95
96
97
98
        ("This kind of communication is not handled " &
         "at this time, we support event data and data ports " &
         "for inter-partition communication and event data, data " &
         "and event ports for intra-partition communication",
99
100
101
102
103
104
105
106
107
         Fatal => True);
   end Display_Communication_Error;

   --------------
   -- Generate --
   --------------

   procedure Generate (AADL_Root : Node_Id) is
      Instance_Root : Node_Id;
108
      Success       : Boolean := True;
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
   begin
      Instance_Root := Instantiate_Model (AADL_Root);

      Expand (Instance_Root);

      Visit_Architecture_Instance (Instance_Root);
      --  Abort if the construction of the C tree failed

      if No (AADL_Root) then
         Display_Error ("Code generation failed", Fatal => True);
      end if;

      --  Enter the output directory

      Enter_Directory (Generated_Sources_Directory);

      if not Remove_Generated_Sources then
         --  Create the source files

         C_Tree.Generator.Generate (C_Root);
      end if;

131
132
133
      if POK_Flavor /= DEOS then
         Makefile.Visit (Instance_Root);
      end if;
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

      --  If the user requested to build the applications then build it

      if Build_Generated_Sources then
         --  Build the source files

         Makefile.Build (Instance_Root);
      end if;

      if POK_Flavor = ARINC653 then
         ARINC653_Conf.Visit_Architecture_Instance (Instance_Root);

         if ARINC653_Conf.Get_XML_Root /= No_Node then
            XML_Tree.Generator.Generate (ARINC653_Conf.Get_XML_Root);
         end if;
      end if;

      POK_Cheddar.Visit_Architecture_Instance (Instance_Root);
      XML_Tree.Generator.Generate (POK_Cheddar.Get_XML_Root);

      if Do_Regression_Test or else Do_Coverage_Test then
         --  Execution_Utils package initialization

         Execution_Utils.Init;
         Execution_Utils.Visit (Instance_Root);

         Execution_Tests.Init;

         if Do_Regression_Test then
163
164
165
166
167
            Success :=
              Execute_Regression_Test
                (Scenario_Dir.all,
                 Ref_Map,
                 Integer (Timeout));
168
169
170
171
172
173
174
175
176
177
178
179

            if not Create_Referencial then
               Write_Eol;
               if Success then
                  Write_Line ("--- All regression tests PASSED ---");
               else
                  Write_Line ("--- Regression tests FAILED ---");
               end if;
            end if;
         end if;

         if Do_Coverage_Test then
180
181
            Success :=
              Success and then Execute_Coverage_Test (Integer (Timeout));
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
         end if;

         --  Free memory

         Execution_Utils.Reset;
         Execution_Tests.Reset;
         Free (Scenario_Dir);

         --  Exit if non-regression tests failed

         if not Success then
            OS_Exit (1);
         end if;
      end if;

      --  Leave the output directory
      Leave_Directory;
   end Generate;

Julien's avatar
Julien committed
201
202
203
204
205
   function Use_ARINC653_API return Boolean is
   begin
      return POK_Flavor = ARINC653 or else POK_Flavor = DEOS;
   end Use_ARINC653_API;

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
   ----------
   -- Init --
   ----------

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

            when 'k' =>
               if Parameter = "arinc653" then
                  POK_Flavor := ARINC653;
               end if;

Julien's avatar
Julien committed
224
225
226
227
               if Parameter = "deos" then
                  POK_Flavor := DEOS;
               end if;

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
               if Parameter = "no-assert" then
                  Add_Assertions := False;
               end if;

            when 'b' =>
               Build_Generated_Sources := True;

            when 'e' =>
               if Full_Switch = "er" then
                  Do_Regression_Test := True;
               elsif Full_Switch = "ec" then
                  Do_Coverage_Test := True;
               end if;

            when 'z' =>
               Remove_Generated_Sources := True;

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

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

      Register_Backend ("POK_C", Generate'Access, PolyORB_Kernel_C);
      Ocarina.Backends.POK_C.Runtime.Initialize;
   end Init;

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

   procedure Reset is
   begin
      Ocarina.Backends.POK_C.Runtime.Reset;
   end Reset;

   ---------------------------------
   -- Visit_Architecture_Instance --
   ---------------------------------

   procedure Visit_Architecture_Instance (E : Node_Id) is
      D : constant Node_Id := CTU.New_Node (CTN.K_HI_Distributed_Application);
      N : Name_Id;
   begin
      CTN.Set_Units (D, CTU.New_List (CTN.K_List_Id));
      CTN.Set_HI_Nodes (D, CTU.New_List (CTN.K_List_Id));
      N := Get_String_Name ("generated-code");
      CTN.Set_Name (D, N);

      C_Root := D;

      Naming.Header_File.Visit_First_Pass (E);
      Naming.Header_File.Visit_Second_Pass (E);
      C_Common.Types.Header_File.Visit (E, C_Root);
      Deployment.Header_File.Visit (E);
      C_Common.Subprograms.Header_File.Visit (E, C_Root);
      Activity.Header_File.Visit (E);

      C_Common.Types.Source_File.Visit (E, C_Root);
      Deployment.Source_File.Visit (E);
      C_Common.Subprograms.Source_File.Visit (E);
      Activity.Source_File.Visit (E);
      Main.Source_File.Visit (E);

   end Visit_Architecture_Instance;

end Ocarina.Backends.POK_C;