OpenAADL / ocarina
1
------------------------------------------------------------------------------
2
--                                                                          --
3
--                           OCARINA COMPONENTS                             --
4
--                                                                          --
5
--               O C A R I N A . B A C K E N D S . P O K _ C                --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--               Copyright (C) 2008-2009 Telecom ParisTech,                 --
10
--                 2010-2019 ESA & ISAE, 2019-2020 OpenAADL                 --
11
--                                                                          --
12
-- Ocarina  is free software; you can redistribute it and/or modify under   --
13
-- terms of the  GNU General Public License as published  by the Free Soft- --
14
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
15
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
16
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
17
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
18
--                                                                          --
19
-- As a special exception under Section 7 of GPL version 3, you are granted --
20
-- additional permissions described in the GCC Runtime Library Exception,   --
21
-- version 3.1, as published by the Free Software Foundation.               --
22
--                                                                          --
23
-- You should have received a copy of the GNU General Public License and    --
24
-- a copy of the GCC Runtime Library Exception along with this program;     --
25
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
26
-- <http://www.gnu.org/licenses/>.                                          --
27
--                                                                          --
28
--                    Ocarina is maintained by OpenAADL team                --
29
--                              (info@openaadl.org)                         --
30
--                                                                          --
31
------------------------------------------------------------------------------
32

33
with Ocarina.Instances;
34
with Ocarina.Backends.Expander;
35
with Ocarina.Backends.Messages;
36
with Ocarina.Backends.C_Tree.Nodes;
37
with Ocarina.Backends.C_Tree.Nutils;
38
with Ocarina.Backends.C_Tree.Generator;
39
with Ocarina.Backends.Utils;
40
with Ocarina.Backends.Execution_Tests;
41
with Ocarina.Backends.Execution_Utils;
42
with Ocarina.Backends.POK_C.Runtime;
43
with Ocarina.Backends.POK_C.Naming;
44
with Ocarina.Backends.POK_C.Main;
45
with Ocarina.Backends.POK_C.Activity;
46
with Ocarina.Backends.POK_C.Deployment;
47
with Ocarina.Backends.C_Common.Types;
48
with Ocarina.Backends.C_Common.Subprograms;
49
with Ocarina.Backends.POK_C.Makefile;
50
with Ocarina.Backends.ARINC653_Conf;
51
with Ocarina.Backends.POK_Cheddar;
52
with Ocarina.Backends.XML_Tree.Generator;
53

54
with GNAT.OS_Lib; use GNAT.OS_Lib;
55

56
with Ocarina.Namet;  use Ocarina.Namet;
57
with Ocarina.Output; use Ocarina.Output;
58

59
package body Ocarina.Backends.POK_C is
60
   use Ocarina.Instances;
61
   use Ocarina.Backends.Expander;
62
   use Ocarina.Backends.Messages;
63
   use Ocarina.Backends.Utils;
64
   use Ocarina.Backends.Execution_Tests;
65

66
   package CTN renames Ocarina.Backends.C_Tree.Nodes;
67
   package CTU renames Ocarina.Backends.C_Tree.Nutils;
68

69
   procedure Visit_Architecture_Instance (E : Node_Id);
70
   --  Most top level visitor routine. E is the root of the AADL
71
   --  instance tree. The procedure does a traversal for each
72
   --  compilation unit to be generated.
73

74
   ---------------------------------
75
   -- Display_Communication_Error --
76
   ---------------------------------
77

78 0
   procedure Display_Communication_Error is
79
   begin
80 0
      Display_Error
81
        ("This kind of communication is not handled " &
82
         "at this time, we support event data and data ports " &
83
         "for inter-partition communication and event data, data " &
84
         "and event ports for intra-partition communication",
85
         Fatal => True);
86 0
   end Display_Communication_Error;
87

88
   --------------
89
   -- Generate --
90
   --------------
91

92 1
   procedure Generate (AADL_Root : Node_Id) is
93 1
      Instance_Root : Node_Id;
94 1
      Success       : Boolean := True;
95
   begin
96 1
      Instance_Root := Instantiate_Model (AADL_Root);
97

98 1
      Expand (Instance_Root);
99

100 1
      Visit_Architecture_Instance (Instance_Root);
101
      --  Abort if the construction of the C tree failed
102

103 1
      if No (AADL_Root) then
104 0
         Display_Error ("Code generation failed", Fatal => True);
105
      end if;
106

107
      --  Enter the output directory
108

109 1
      Enter_Directory (Generated_Sources_Directory);
110

111 1
      if not Remove_Generated_Sources then
112
         --  Create the source files
113

114 1
         C_Tree.Generator.Generate (C_Root);
115
      end if;
116

117 1
      if POK_Flavor /= DEOS and then POK_Flavor /= VXWORKS then
118 0
         Makefile.Visit (Instance_Root);
119
      end if;
120

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

123 1
      if Compile_Generated_Sources then
124
         --  Build the source files
125

126 0
         Makefile.Build (Instance_Root);
127
      end if;
128

129 1
      if POK_Flavor = ARINC653 then
130 0
         ARINC653_Conf.Visit_Architecture_Instance (Instance_Root);
131

132 0
         if ARINC653_Conf.Get_XML_Root /= No_Node then
133 0
            XML_Tree.Generator.Generate (ARINC653_Conf.Get_XML_Root);
134
         end if;
135
      end if;
136

137 1
      POK_Cheddar.Visit_Architecture_Instance (Instance_Root);
138 1
      XML_Tree.Generator.Generate (POK_Cheddar.Get_XML_Root);
139

140 1
      if Do_Regression_Test or else Do_Coverage_Test then
141
         --  Execution_Utils package initialization
142

143 0
         Execution_Utils.Init;
144 0
         Execution_Utils.Visit (Instance_Root);
145

146 0
         Execution_Tests.Init;
147

148 0
         if Do_Regression_Test then
149
            Success :=
150 0
              Execute_Regression_Test
151 0
                (Scenario_Dir.all,
152
                 Ref_Map,
153 0
                 Integer (Timeout));
154

155 0
            if not Create_Referencial then
156 0
               Write_Eol;
157 0
               if Success then
158 0
                  Write_Line ("--- All regression tests PASSED ---");
159
               else
160 0
                  Write_Line ("--- Regression tests FAILED ---");
161
               end if;
162
            end if;
163
         end if;
164

165 0
         if Do_Coverage_Test then
166 0
            Success :=
167 0
              Success and then Execute_Coverage_Test (Integer (Timeout));
168
         end if;
169

170
         --  Free memory
171

172 0
         Execution_Utils.Reset;
173 0
         Execution_Tests.Reset;
174 0
         Free (Scenario_Dir);
175

176
         --  Exit if non-regression tests failed
177

178 0
         if not Success then
179 0
            OS_Exit (1);
180
         end if;
181
      end if;
182

183
      --  Leave the output directory
184 1
      Leave_Directory;
185 1
   end Generate;
186

187
   ----------------------
188
   -- Use_ARINC653_API --
189
   ----------------------
190

191 1
   function Use_ARINC653_API return Boolean is
192
   begin
193 1
      return POK_Flavor = ARINC653
194 1
        or else POK_Flavor = DEOS
195 1
        or else POK_Flavor = VXWORKS;
196
   end Use_ARINC653_API;
197

198
   --------------------
199
   -- Set_POK_Flavor --
200
   --------------------
201

202 1
   procedure Set_POK_Flavor (S : String) is
203
   begin
204 1
      if S = "arinc653" then
205 0
         POK_Flavor := ARINC653;
206

207 1
      elsif S = "deos" then
208 1
         POK_Flavor := DEOS;
209

210 1
      elsif S = "vxworks653" then
211 1
         POK_Flavor := VXWORKS;
212

213 0
      elsif S = "pok" then
214 0
         POK_Flavor := POK;
215

216 0
      elsif S = "no-assert" then
217 0
         Add_Assertions := False;
218
      else
219 0
         raise Constraint_Error with S;
220
      end if;
221 1
   end Set_POK_Flavor;
222

223
   ----------
224
   -- Init --
225
   ----------
226

227 1
   procedure Init is
228
   begin
229 1
      Register_Backend ("POK_C", Generate'Access, PolyORB_Kernel_C);
230 1
      Ocarina.Backends.POK_C.Runtime.Initialize;
231 1
   end Init;
232

233
   -----------
234
   -- Reset --
235
   -----------
236

237 1
   procedure Reset is
238
   begin
239 1
      Ocarina.Backends.POK_C.Runtime.Reset;
240 1
   end Reset;
241

242
   ---------------------------------
243
   -- Visit_Architecture_Instance --
244
   ---------------------------------
245

246 1
   procedure Visit_Architecture_Instance (E : Node_Id) is
247 1
      D : constant Node_Id := CTU.New_Node (CTN.K_HI_Distributed_Application);
248 1
      N : Name_Id;
249
   begin
250 1
      CTN.Set_Units (D, CTU.New_List (CTN.K_List_Id));
251 1
      CTN.Set_HI_Nodes (D, CTU.New_List (CTN.K_List_Id));
252 1
      N := Get_String_Name ("generated-code");
253 1
      CTN.Set_Name (D, N);
254

255 1
      C_Root := D;
256

257 1
      Naming.Header_File.Visit_First_Pass (E);
258 1
      Naming.Header_File.Visit_Second_Pass (E);
259 1
      C_Common.Types.Header_File.Visit (E, C_Root);
260 1
      Deployment.Header_File.Visit (E);
261 1
      C_Common.Subprograms.Header_File.Visit (E, C_Root);
262 1
      Activity.Header_File.Visit (E);
263

264 1
      C_Common.Types.Source_File.Visit (E, C_Root);
265 1
      Deployment.Source_File.Visit (E);
266 1
      C_Common.Subprograms.Source_File.Visit (E);
267 1
      Activity.Source_File.Visit (E);
268 1
      Main.Source_File.Visit (E);
269

270 1
   end Visit_Architecture_Instance;
271

272
end Ocarina.Backends.POK_C;

Read our documentation on viewing source code .

Loading