ocarina-backends-pok_c-naming.adb 13.8 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 . N A M I N G         --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE.      --
10
--                                                                          --
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
-- 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
--                                                                          --
------------------------------------------------------------------------------

with Locations;
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
37
with Ocarina.Backends.Messages;
38 39 40 41 42 43 44 45 46 47 48 49 50 51
with Ocarina.Backends.Properties;
with Ocarina.Backends.C_Common.Mapping;
with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Tree.Nutils;

package body Ocarina.Backends.POK_C.Naming is

   use Locations;
   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;
   use Ocarina.Backends.C_Common.Mapping;
   use Ocarina.Backends.C_Tree.Nutils;
   use Ocarina.Backends.Properties;
52
   use Ocarina.Backends.Messages;
53 54 55 56 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99

   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
   package CTN renames Ocarina.Backends.C_Tree.Nodes;

   -----------------
   -- Header_File --
   -----------------

   package body Header_File is

      procedure Visit_First_Pass_Component (E : Node_Id);
      procedure Visit_First_Pass_System (E : Node_Id);
      procedure Visit_First_Pass_Process_Or_Device (E : Node_Id);
      procedure Visit_First_Pass_Processor (E : Node_Id);
      procedure Visit_First_Pass_Bus (E : Node_Id);
      procedure Visit_First_Pass_Virtual_Processor (E : Node_Id);

      procedure Visit_Second_Pass_Component (E : Node_Id);
      procedure Visit_Second_Pass_System (E : Node_Id);
      procedure Visit_Second_Pass_Process_Or_Device (E : Node_Id);
      procedure Visit_Second_Pass_Processor (E : Node_Id);
      procedure Visit_Second_Pass_Virtual_Processor (E : Node_Id);

      ----------------------
      -- Visit_First_Pass --
      ----------------------

      procedure Visit_First_Pass (E : Node_Id) is
      begin
         case Kind (E) is
            when K_Architecture_Instance =>
               Visit_First_Pass (Root_System (E));

            when K_Component_Instance =>
               Visit_First_Pass_Component (E);

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

      --------------------------------
      -- Visit_First_Pass_Component --
      --------------------------------

      procedure Visit_First_Pass_Component (E : Node_Id) is
100 101
         Category : constant Component_Category :=
           Get_Category_Of_Component (E);
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
      begin
         case Category is
            when CC_System =>
               Visit_First_Pass_System (E);

            when CC_Process =>
               Visit_First_Pass_Process_Or_Device (E);

            when CC_Device =>
               Visit_First_Pass_Process_Or_Device (E);

            when CC_Processor =>
               Visit_First_Pass_Processor (E);

            when CC_Bus =>
               Visit_First_Pass_Bus (E);

            when CC_Virtual_Processor =>
               Visit_First_Pass_Virtual_Processor (E);

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

      ----------------------------------------
      -- Visit_First_Pass_Process_or_Device --
      ----------------------------------------

131 132
      procedure Visit_First_Pass_Process_Or_Device (E : Node_Id) is
         N              : Node_Id;
133
         Processes_List : List_Id;
134 135

         Proc : constant Node_Id := Get_Bound_Processor (E);
136
      begin
137 138 139 140
         if No (Proc) then
            Display_Located_Error
              (Loc (Parent_Subcomponent (E)),
               "This device or process is not bound to a processor",
yoogx's avatar
yoogx committed
141 142
               Fatal   => True,
               Warning => False);
143 144
         end if;

yoogx's avatar
yoogx committed
145
         Processes_List := CTN.Processes (Backend_Node (Identifier (Proc)));
146 147 148

         N := AINU.Make_Node_Container (E);

149 150
         AINU.Append_Node_To_List (N, Processes_List);
      end Visit_First_Pass_Process_Or_Device;
151 152 153 154 155 156

      --------------------------
      -- Visit_First_Pass_Bus --
      --------------------------

      procedure Visit_First_Pass_Bus (E : Node_Id) is
157
         N             : Node_Id;
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
         Accessed_List : List_Id;
      begin
         N := New_Node (CTN.K_HI_Tree_Bindings);

         AIN.Set_Backend_Node (Identifier (Parent_Subcomponent (E)), N);

         Accessed_List := AINU.New_List (AIN.K_List_Id, No_Location);

         CTN.Set_Processes (N, Accessed_List);
      end Visit_First_Pass_Bus;

      -------------------------------------------------
      -- Visit_First_Pass_Virtual_Processor_Instance --
      -------------------------------------------------

      procedure Visit_First_Pass_Virtual_Processor (E : Node_Id) is
         Processes : List_Id;
         N         : Node_Id;
      begin
         N := New_Node (CTN.K_HI_Tree_Bindings);

         AIN.Set_Backend_Node (Identifier (E), N);

         Processes := AINU.New_List (AIN.K_List_Id, No_Location);

         CTN.Set_Processes (N, Processes);

      end Visit_First_Pass_Virtual_Processor;

      --------------------------------
      -- Visit_First_Pass_Processor --
      --------------------------------

      procedure Visit_First_Pass_Processor (E : Node_Id) is
192 193 194 195
         A         : constant Node_Id := Map_Distributed_Application (E);
         S         : Node_Id;
         P         : Node_Id;
         U         : Node_Id;
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
         N         : Node_Id;
         Processes : List_Id;
      begin
         Push_Entity (C_Root);
         Push_Entity (A);

         P := Map_HI_Node (E, Kernel => True);
         Push_Entity (P);

         U := Map_HI_Unit (E);
         Push_Entity (U);

         if not AINU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.

               Visit_First_Pass (Corresponding_Instance (S));
               S := Next_Node (S);
            end loop;
         end if;

         N := New_Node (CTN.K_HI_Tree_Bindings);

         Processes := AINU.New_List (K_List_Id, No_Location);

         CTN.Set_Processes (N, Processes);

         CTN.Set_Deployment_Node (N, A);
         CTN.Set_Naming_Node (N, U);

         AIN.Set_Backend_Node (Identifier (E), N);

         Append_Node_To_List (A, CTN.HI_Nodes (C_Root));

         Pop_Entity;
         Pop_Entity;
         Pop_Entity; --  A
      end Visit_First_Pass_Processor;

      -----------------------------
      -- Visit_First_Pass_System --
      -----------------------------

      procedure Visit_First_Pass_System (E : Node_Id) is
242
         S                  : Node_Id;
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
         Component_Instance : Node_Id;
      begin
         if not AINU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               Component_Instance := Corresponding_Instance (S);
               if AINU.Is_Processor (Component_Instance) then
                  Visit_First_Pass_Processor (Component_Instance);
               elsif AINU.Is_Bus (Component_Instance) then
                  Visit_First_Pass_Bus (Component_Instance);
               end if;
               S := Next_Node (S);
            end loop;
         end if;

         if not AINU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.
               if AINU.Is_Process_Or_Device (Corresponding_Instance (S)) then
                  Visit_First_Pass (Corresponding_Instance (S));
               end if;
               S := Next_Node (S);
            end loop;
         end if;

      end Visit_First_Pass_System;

      ----------------------
      -- Visit_Second_Pass --
      ----------------------

      procedure Visit_Second_Pass (E : Node_Id) is
      begin
         case Kind (E) is
            when K_Architecture_Instance =>
               Visit_Second_Pass (Root_System (E));

            when K_Component_Instance =>
               Visit_Second_Pass_Component (E);

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

      --------------------------------
      -- Visit_Second_Pass_Component --
      --------------------------------

      procedure Visit_Second_Pass_Component (E : Node_Id) is
295 296
         Category : constant Component_Category :=
           Get_Category_Of_Component (E);
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
      begin
         case Category is
            when CC_System =>
               Visit_Second_Pass_System (E);

            when CC_Process =>
               Visit_Second_Pass_Process_Or_Device (E);

            when CC_Device =>
               Visit_Second_Pass_Process_Or_Device (E);

            when CC_Processor =>
               Visit_Second_Pass_Processor (E);

            when CC_Virtual_Processor =>
               Visit_Second_Pass_Virtual_Processor (E);

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

      -------------------------------
      -- Visit_Second_Pass_Process --
      -------------------------------

      procedure Visit_Second_Pass_Process_Or_Device (E : Node_Id) is
324 325
         P : constant Node_Id := Map_HI_Node (E);
         U : Node_Id;
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
      begin
         Push_Entity (P);
         U := Map_HI_Unit (E);
         Push_Entity (U);

         Set_Naming_Header (U);

         Pop_Entity;
         Pop_Entity;
      end Visit_Second_Pass_Process_Or_Device;

      --------------------------------
      -- Visit_Second_Pass_Processor --
      --------------------------------

      procedure Visit_Second_Pass_Processor (E : Node_Id) is
         S : Node_Id;
343 344
         A : constant Node_Id :=
           CTN.Deployment_Node (Backend_Node (Identifier (E)));
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
      begin
         Push_Entity (C_Root);
         Push_Entity (A);

         if not AINU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               --  Visit the component instance corresponding to the
               --  subcomponent S.

               Visit_Second_Pass (Corresponding_Instance (S));
               S := Next_Node (S);
            end loop;
         end if;

         Pop_Entity;
         Pop_Entity;
      end Visit_Second_Pass_Processor;

      -----------------------------------------
      -- Visit_Second_Pass_Virtual_Processor --
      -----------------------------------------

      procedure Visit_Second_Pass_Virtual_Processor (E : Node_Id) is
369 370
         Processes : List_Id;
         S         : Node_Id;
371 372 373
      begin
         if Present (Backend_Node (Identifier (E))) then
            Processes := CTN.Processes (Backend_Node (Identifier (E)));
374
            S         := AIN.First_Node (Processes);
375 376 377 378 379 380 381 382 383 384 385 386
            while Present (S) loop
               Visit_Second_Pass (AIN.Item (S));
               S := AIN.Next_Node (S);
            end loop;
         end if;
      end Visit_Second_Pass_Virtual_Processor;

      -----------------------------
      -- Visit_Second_Pass_System --
      -----------------------------

      procedure Visit_Second_Pass_System (E : Node_Id) is
387 388
         Component_Instance : Node_Id;
         S                  : Node_Id;
389 390 391 392 393 394 395 396 397 398 399 400 401 402
      begin
         if not AINU.Is_Empty (Subcomponents (E)) then
            S := First_Node (Subcomponents (E));
            while Present (S) loop
               Component_Instance := Corresponding_Instance (S);
               if AINU.Is_Processor (Component_Instance) then
                  Visit_Second_Pass_Processor (Component_Instance);
               end if;
               S := Next_Node (S);
            end loop;
         end if;
      end Visit_Second_Pass_System;
   end Header_File;
end Ocarina.Backends.POK_C.Naming;