ocarina-backends-pok_c.adb 9.12 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 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE.      --
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27 28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
--                                                                          --
------------------------------------------------------------------------------

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;

yoogx's avatar
yoogx committed
53
with GNAT.OS_Lib; use GNAT.OS_Lib;
54

yoogx's avatar
yoogx committed
55
with Ocarina.Namet;  use Ocarina.Namet;
56
with Ocarina.Output; use Ocarina.Output;
57 58 59 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

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;

   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
86 87 88 89
        ("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",
90 91 92 93 94 95 96 97 98
         Fatal => True);
   end Display_Communication_Error;

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

   procedure Generate (AADL_Root : Node_Id) is
      Instance_Root : Node_Id;
99
      Success       : Boolean := True;
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
   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;

122
      if POK_Flavor /= DEOS and then POK_Flavor /= VXWORKS then
123 124
         Makefile.Visit (Instance_Root);
      end if;
125 126 127

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

128
      if Compile_Generated_Sources then
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
         --  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
154 155 156 157 158
            Success :=
              Execute_Regression_Test
                (Scenario_Dir.all,
                 Ref_Map,
                 Integer (Timeout));
159 160 161 162 163 164 165 166 167 168 169 170

            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
171 172
            Success :=
              Success and then Execute_Coverage_Test (Integer (Timeout));
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
         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;

192 193 194 195
   ----------------------
   -- Use_ARINC653_API --
   ----------------------

Julien's avatar
Julien committed
196 197
   function Use_ARINC653_API return Boolean is
   begin
yoogx's avatar
yoogx committed
198 199 200
      return POK_Flavor = ARINC653
        or else POK_Flavor = DEOS
        or else POK_Flavor = VXWORKS;
Julien's avatar
Julien committed
201 202
   end Use_ARINC653_API;

203 204 205
   --------------------
   -- Set_POK_Flavor --
   --------------------
206

207
   procedure Set_POK_Flavor (S : String) is
208
   begin
209 210
      if S = "arinc653" then
         POK_Flavor := ARINC653;
211

212 213
      elsif S = "deos" then
         POK_Flavor := DEOS;
Julien's avatar
Julien committed
214

215 216
      elsif S = "vxworks653" then
         POK_Flavor := VXWORKS;
217

yoogx's avatar
yoogx committed
218 219 220
      elsif S = "pok" then
         POK_Flavor := POK;

221 222 223 224 225 226
      elsif S = "no-assert" then
         Add_Assertions := False;
      else
         raise Constraint_Error with S;
      end if;
   end Set_POK_Flavor;
227

228 229 230
   ----------
   -- Init --
   ----------
231

232 233
   procedure Init is
   begin
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
      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;