taste-aadl_parser.adb 27 KB
Newer Older
1 2
--  ************************ TASTE AADL Parser **************************  --
--  Based on Ocarina ****************************************************  --
3
--  (c) 2019 Maxime Perrotin / European Space Agency - maxime.perrotin@esa.int
4 5
--  LGPL license, see LICENSE file

6
with System.Assertions,
7 8
     Ada.Exceptions,
     Ada.Text_IO,
9
     Ada.Directories,
10
     Ada.Strings.Equal_Case_Insensitive,
11
     Ada.Containers,
12
     GNAT.Command_Line,
13 14 15 16 17
     Errors,
     Locations,
     Ocarina.Namet,
     Ocarina.Configuration,
     Ocarina.Files,
18
     Ocarina.Parser,
19
     Ocarina.FE_AADL.Parser,
Maxime Perrotin's avatar
Maxime Perrotin committed
20
     TASTE.Backend,
Maxime Perrotin's avatar
Maxime Perrotin committed
21
     TASTE.Backend.Build_Script,
Maxime Perrotin's avatar
Maxime Perrotin committed
22
     TASTE.Backend.Code_Generators,
23
     TASTE.Semantic_Check;
24 25 26

use Ada.Text_IO,
    Ada.Exceptions,
27
    Ada.Directories,
28
    Ada.Containers,
29 30 31 32 33 34 35
    Locations,
    Ocarina.Namet,
    Ocarina;

package body TASTE.AADL_Parser is

   function Initialize return Taste_Configuration is
Maxime Perrotin's avatar
Maxime Perrotin committed
36 37 38
      File_Name  : Name_Id;
      File_Descr : Location;
      Cfg        : Taste_Configuration;
39
      use String_Holders;
40 41 42 43
   begin
      Banner;
      --  Parse arguments before initializing Ocarina, otherwise Ocarina eats
      --  some arguments (all file parameters).
Maxime Perrotin's avatar
Maxime Perrotin committed
44
      Parse_Command_Line (Cfg);
45 46 47 48
      Initialize_Ocarina;

      AADL_Language := Get_String_Name ("aadl");

49
      if Cfg.Interface_View.Is_Empty and not Cfg.Check_Data_View then
Maxime Perrotin's avatar
Maxime Perrotin committed
50 51
         --  Use "InterfaceView.aadl" by default, if nothing else is specified
         --  and if the tool is not only called to check the data view
52 53
         --  Cfg.Interface_View := Default_Interface_View'Access;
         Cfg.Interface_View := To_Holder (Default_Interface_View);
54 55
      end if;

Maxime Perrotin's avatar
Maxime Perrotin committed
56
      --  An interface view is expected, look for it and parse it
57 58
      if not Cfg.Interface_View.Is_Empty then
         Set_Str_To_Name_Buffer (Cfg.Interface_View.Element);
59

Maxime Perrotin's avatar
Maxime Perrotin committed
60 61 62
         File_Name := Ocarina.Files.Search_File (Name_Find);
         if File_Name = No_Name then
            raise AADL_Parser_Error
63 64
              with "Interface View file not found : "
              & Cfg.Interface_View.Element;
Maxime Perrotin's avatar
Maxime Perrotin committed
65 66 67
         end if;

         File_Descr := Ocarina.Files.Load_File (File_Name);
68

Maxime Perrotin's avatar
Maxime Perrotin committed
69 70
         Interface_Root := Ocarina.Parser.Parse
           (AADL_Language, Interface_Root, File_Descr);
71

Maxime Perrotin's avatar
Maxime Perrotin committed
72 73 74 75 76 77
         --  Parse TASTE_IV_Properties.aadl
         Set_Str_To_Name_Buffer ("TASTE_IV_Properties.aadl");
         File_Name  := Ocarina.Files.Search_File (Name_Find);
         File_Descr := Ocarina.Files.Load_File (File_Name);
         Interface_Root := Ocarina.Parser.Parse (AADL_Language,
                                                 Interface_Root, File_Descr);
Maxime Perrotin's avatar
Maxime Perrotin committed
78 79 80
         if Interface_Root = No_Node then
            raise AADL_Parser_Error with "Interface view is incorrect";
         end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
81
      end if;
82

Maxime Perrotin's avatar
Maxime Perrotin committed
83 84 85
      if Cfg.Glue then
         --  Look for a deployment view (or DeploymentView.aadl by default)
         --  if the glue generation is requested. Not needed for skeletons.
86 87
         if Cfg.Deployment_View.Is_Empty then
            Cfg.Deployment_View := To_Holder (Default_Deployment_View);
88 89
         end if;

90
         Set_Str_To_Name_Buffer (Cfg.Deployment_View.Element);
91 92 93 94

         File_Name := Ocarina.Files.Search_File (Name_Find);
         if File_Name = No_Name then
            raise AADL_Parser_Error
95 96
              with "Deployment View file not found : "
              & Cfg.Deployment_View.Element;
97 98 99 100 101 102 103 104 105 106 107
         end if;

         File_Descr := Ocarina.Files.Load_File (File_Name);
         Deployment_Root := Ocarina.Parser.Parse
           (AADL_Language, Deployment_Root, File_Descr);

         if Deployment_Root = No_Node then
            raise AADL_Parser_Error with "Deployment View is incorrect";
         end if;
      end if;

Maxime Perrotin's avatar
Maxime Perrotin committed
108 109 110
      for Each of Cfg.Other_Files loop
         --  Add other files to the Interface and (if any) deployment roots
         --  (List of files specified in the command line)
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
         Set_Str_To_Name_Buffer (Each);
         File_Name := Ocarina.Files.Search_File (Name_Find);
         if File_Name = No_Name then
            raise AADL_Parser_Error with "File not found: " & Each;
         end if;
         File_Descr := Ocarina.Files.Load_File (File_Name);

         Interface_Root := Ocarina.Parser.Parse
           (AADL_Language, Interface_Root, File_Descr);
         if Deployment_Root /= No_Node then
            Deployment_Root := Ocarina.Parser.Parse
              (AADL_Language, Deployment_Root, File_Descr);
         end if;
      end loop;

126 127
      if not Cfg.Data_View.Is_Empty then
         Set_Str_To_Name_Buffer (Cfg.Data_View.Element);
128 129
         File_Name := Ocarina.Files.Search_File (Name_Find);
         if File_Name = No_Name then
130 131
            raise AADL_Parser_Error
              with "Could not find " & Cfg.Data_View.Element;
132 133
         end if;
      else
Maxime Perrotin's avatar
Maxime Perrotin committed
134
         --  Try with default name (DataView.aadl)
135 136 137
         Set_Str_To_Name_Buffer (Default_Data_View);
         File_Name := Ocarina.Files.Search_File (Name_Find);
         if File_Name /= No_Name then
138
            Cfg.Data_View := To_Holder (Default_Data_View);
Maxime Perrotin's avatar
Maxime Perrotin committed
139 140 141
         elsif Cfg.Check_Data_View then
            --  No dataview found, while user asked explicitly for a check
            raise AADL_Parser_Error with "Could not find DataView.aadl";
142 143 144 145
         end if;
      end if;

      if File_Name /= No_Name then
146
         Put_Info ("Parsing " & Cfg.Data_View.Element);
Maxime Perrotin's avatar
Maxime Perrotin committed
147

148 149
         File_Descr := Ocarina.Files.Load_File (File_Name);

Maxime Perrotin's avatar
Maxime Perrotin committed
150 151 152 153 154
         --  Add the Data View to the Interface View root, if any
         if Interface_Root /= No_Node then
            Interface_Root := Ocarina.Parser.Parse
              (AADL_Language, Interface_Root, File_Descr);
         end if;
155 156 157 158 159 160

         --  Add the Data View to the Deployment View root, if any
         if Deployment_Root /= No_Node then
            Deployment_Root := Ocarina.Parser.Parse
               (AADL_Language, Deployment_Root, File_Descr);
         end if;
161
         --  Also parse the data view as a root component
162
         Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets := False;
163 164 165
         Dataview_root := Ocarina.Parser.Parse
                            (AADL_Language, Dataview_root, File_Descr);
      end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
166
      return Cfg;
167 168 169 170 171 172 173
   end Initialize;

   function Parse_Project return TASTE_Model is
      Result : TASTE_Model;
   begin
      Result.Configuration := Initialize;

Maxime Perrotin's avatar
Maxime Perrotin committed
174 175 176 177 178 179 180 181
      if Interface_Root /= No_Node then
         --  Parse Interface and Deployment View
         begin
            Result.Interface_View := Parse_Interface_View (Interface_Root);
         exception
            when System.Assertions.Assert_Failure =>
               raise AADL_Parser_Error with "Interface view parsing error";
         end;
182

183 184 185 186
         if not Result.Configuration.No_Stdlib then
            AADL_Lib.Append ("ocarina_components.aadl");
         end if;

Maxime Perrotin's avatar
Maxime Perrotin committed
187 188 189
         if Deployment_Root /= No_Node
           and not Result.Configuration.Deployment_View.Is_Empty
         then
190
            AADL_Lib.Append (Result.Configuration.Interface_View.Element);
Maxime Perrotin's avatar
Maxime Perrotin committed
191 192
            Result.Deployment_View := Parse_Deployment_View (Deployment_Root);
         end if;
193 194
      end if;

195
      if not Result.Configuration.Data_View.Is_Empty then
196 197
         begin
            Result.Data_View := Parse_Data_View (Dataview_root);
198
            Result.Data_View.Check_Files;
199 200 201 202 203
         exception
            when Constraint_Error =>
               raise Data_View_Error with "Update your data view!";
         end;
      end if;
204

205 206 207
      Ocarina.Configuration.Reset_Modules;
      Ocarina.Reset;

Maxime Perrotin's avatar
Maxime Perrotin committed
208 209 210 211
      if Result.Configuration.Check_Data_View then
         raise Quit_Taste;
      end if;

212 213
      Semantic_Check.Check_Model (Result);

214 215 216 217 218 219 220
      return Result;
   exception
      when Error : AADL_Parser_Error
         | Interface_Error
         | Function_Error
         | No_RCM_Error
         | Deployment_View_Error
221
         | Data_View_Error
222
         | Semantic_Check.Semantic_Error
223
         | Device_Driver_Error =>
224
         Put_Error (Exception_Message (Error));
225 226 227
         raise Quit_Taste;
      when GNAT.Command_Line.Exit_From_Command_Line =>
         New_Line;
228 229
         Put_Info ("For more information, visit " & Underline & White_Bold
                   & "https://taste.tools");
230 231 232 233
         raise Quit_Taste;
      when GNAT.Command_Line.Invalid_Switch
         | GNAT.Command_Line.Invalid_Parameter
         | GNAT.Command_Line.Invalid_Section =>
234
         Put_Error ("Invalid switch or parameter (try --help)" & No_Color);
235
         raise Quit_Taste;
Maxime Perrotin's avatar
Maxime Perrotin committed
236 237
      when Quit_Taste =>
         raise;
238 239 240 241 242
      when E : others =>
         Errors.Display_Bug_Box (E);
         raise Quit_Taste;
   end Parse_Project;

243 244 245 246
   function Find_Binding (Model : TASTE_Model;
                          F     : Unbounded_String)
                          return Option_Partition.Option is
      use Option_Partition;
247 248
      function Is_Equal (Left, Right : String) return Boolean
         renames Ada.Strings.Equal_Case_Insensitive;
249 250 251 252 253
      Function_Name : constant String := To_String (F);
   begin
      for Node of Model.Deployment_View.Nodes loop
         for Each of Node.Partitions loop
            for Binding of Each.Bound_Functions loop
254
               if Is_Equal (Binding, Function_Name) then
255 256 257 258 259 260 261 262
                  return Just (Each);
               end if;
            end loop;
         end loop;
      end loop;
      return Nothing;
   end Find_Binding;

Maxime Perrotin's avatar
Maxime Perrotin committed
263
   procedure Set_Calling_Threads (Partition : in out CV_Partition) is
Maxime Perrotin's avatar
Maxime Perrotin committed
264
      procedure Rec_Add_Calling_Thread (Thread_Id : String;
Maxime Perrotin's avatar
Maxime Perrotin committed
265
                                        Block_Id  : String) is
Maxime Perrotin's avatar
Maxime Perrotin committed
266 267
      begin
         --  First add thread to its corresponding protected function
Maxime Perrotin's avatar
Maxime Perrotin committed
268 269
         --  Stop recursion if thread is already there...
         if not String_Sets.To_Set (Thread_Id).Is_Subset
Maxime Perrotin's avatar
Maxime Perrotin committed
270
           (Of_Set => Partition.Blocks (Block_Id).Calling_Threads)
Maxime Perrotin's avatar
Maxime Perrotin committed
271
         then
Maxime Perrotin's avatar
Maxime Perrotin committed
272
            Partition.Blocks (Block_Id).Calling_Threads.Insert (Thread_Id);
Maxime Perrotin's avatar
Maxime Perrotin committed
273 274 275 276
         else
            return;
         end if;

Maxime Perrotin's avatar
Maxime Perrotin committed
277
         --  Then recurse on its (Un)protected RIs.
Maxime Perrotin's avatar
Maxime Perrotin committed
278
         for RI of Partition.Blocks (Block_Id).Required loop
Maxime Perrotin's avatar
Maxime Perrotin committed
279 280 281 282 283
            if RI.RCM = Protected_Operation or RI.RCM = Unprotected_Operation
            then
               for Remote of RI.Remote_Interfaces loop
                  Rec_Add_Calling_Thread
                    (Thread_Id => Thread_Id,
Maxime Perrotin's avatar
Maxime Perrotin committed
284
                     Block_Id  => To_String (Remote.Function_Name));
Maxime Perrotin's avatar
Maxime Perrotin committed
285 286 287 288 289
               end loop;
            end if;
         end loop;
      end Rec_Add_Calling_Thread;
   begin
Maxime Perrotin's avatar
Maxime Perrotin committed
290
      for Each of Partition.Threads loop
Maxime Perrotin's avatar
Maxime Perrotin committed
291 292
         Rec_Add_Calling_Thread (Thread_Id => To_String (Each.Name),
                                 Block_Id  => To_String
Maxime Perrotin's avatar
Maxime Perrotin committed
293
                                   (Each.Protected_Block_Name));
Maxime Perrotin's avatar
Maxime Perrotin committed
294 295 296
      end loop;
   end Set_Calling_Threads;

297 298 299 300 301 302
   --  Find the output ports of a thread by following the connections
   function Get_Output_Ports (Model : TASTE_Model;
                              F     : Taste_Terminal_Function) return Ports.Map
   is
      Result            : Ports.Map;
      Visited_Functions : String_Sets.Set;
303

304 305 306 307 308 309 310 311 312 313 314 315 316 317
      procedure Rec_Find_Thread (Ports_Map  : in out Ports.Map;
                                 Visited    : in out String_Sets.Set;
                                 Func       : Taste_Terminal_Function) is
         use String_Sets;
         Current_Function : constant String_Sets.Set :=
           String_Sets.To_Set (To_String (Func.Name));
      begin
         --  Recursively find distand threads by following (un)pro RI paths
         --  Ignore already visited nodes (system may have circular paths)
         if Current_Function.Is_Subset (Of_Set => Visited) then
            return;
         else
            Visited := Visited or Current_Function;
         end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
318 319 320 321
         if Func.Is_Type then
            --  Ignore function types, only work with instances
            return;
         end if;
322 323

         for RI of Func.Required loop
Maxime Perrotin's avatar
Maxime Perrotin committed
324 325 326 327
            if RI.Remote_Interfaces.Is_Empty then
               goto Continue;
            end if;

328 329 330 331 332 333 334 335 336 337 338 339
            if RI.RCM = Unprotected_Operation or RI.RCM = Protected_Operation
            then
               Rec_Find_Thread (Ports_Map => Ports_Map,
                                Visited   => Visited,
                                Func      =>
                                  Model.Interface_View.Flat_Functions
                                  (To_String
                          (RI.Remote_Interfaces.First_Element.Function_Name)));
            else
               declare
                  --  Assume only one remote connection per RI
                  --  Have to iterate on Remote_Interfaces if that changes
340 341

                  Dist      : constant Remote_Entity :=
342
                    RI.Remote_Interfaces.First_Element;
343 344
                  Remote_Thread_Name : constant Unbounded_String :=
                    Dist.Function_Name & "_" & Dist.Interface_Name;
Maxime Perrotin's avatar
Maxime Perrotin committed
345 346
                  Port_Name : constant Unbounded_String := RI.Name;
                  --  Remote_Thread_Name & "_" & Dist.Interface_Name;
347
                  New_P     : constant Thread_Port :=
348 349
                    (Name          => Port_Name,
                     Remote_Thread => Remote_Thread_Name,
Maxime Perrotin's avatar
Maxime Perrotin committed
350 351
                     Remote_PI     => Dist.Interface_Name,
                     RI            => RI);
352
               begin
353 354
                  Ports_Map.Include (Key      => To_String (Port_Name),
                                     New_Item => New_P);
355 356
               end;
            end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
357
            <<Continue>>
358 359 360 361 362 363 364 365 366
         end loop;
      end Rec_Find_Thread;
   begin
      Rec_Find_Thread (Ports_Map => Result,
                       Visited   => Visited_Functions,
                       Func      => F);
      return Result;
   end Get_Output_Ports;

367
   procedure Add_Concurrency_View (Model : in out TASTE_Model) is
Maxime Perrotin's avatar
Maxime Perrotin committed
368 369 370
      CV : Taste_Concurrency_View :=
        (Base_Template_Path => Model.Configuration.Binary_Path,
         Base_Output_Path   => Model.Configuration.Output_Dir,
371
         Deployment         => Model.Deployment_View,
Maxime Perrotin's avatar
Maxime Perrotin committed
372
         Configuration      => Model.Configuration,
Maxime Perrotin's avatar
Maxime Perrotin committed
373
         others             => <>);
374
      use String_Vectors;
375
   begin
Maxime Perrotin's avatar
Maxime Perrotin committed
376 377 378
      --  Initialize the lists of nodes and partitions based on the DV
      for Node of Model.Deployment_View.Nodes loop
         declare
379 380
            New_Node : CV_Node :=
              (Deployment_Node => Node, others => <>);
Maxime Perrotin's avatar
Maxime Perrotin committed
381 382 383
         begin
            for Partition of Node.Partitions loop
               declare
384 385
                  New_Partition : constant CV_Partition :=
                    (Deployment_Partition => Partition, others => <>);
Maxime Perrotin's avatar
Maxime Perrotin committed
386 387 388 389 390 391 392 393 394 395 396
               begin
                  New_Node.Partitions.Insert
                    (Key      => To_String (Partition.Name),
                     New_Item => New_Partition);
               end;
            end loop;
            CV.Nodes.Insert (Key      => To_String (Node.Name),
                             New_Item => New_Node);
         end;
      end loop;

397 398
      --  Create one thread per Cyclic and Sporadic interface
      --  Create one protected block per application code
Maxime Perrotin's avatar
Maxime Perrotin committed
399
      --  and map them on the Concurrency View nodes/partitions
400
      for F of Model.Interface_View.Flat_Functions loop
401 402 403
         if F.Is_Type then
            goto Continue;
         end if;
404
         declare
Maxime Perrotin's avatar
Maxime Perrotin committed
405 406 407 408 409 410 411 412 413 414 415 416 417
            Function_Name : constant String := To_String (F.Name);
            Node : constant Option_Node.Option :=
              Model.Deployment_View.Find_Node (Function_Name);
            Node_Name : constant String :=
              (if Node.Has_Value
               then To_String (Node.Unsafe_Just.Name)
               else "");
            Partition_Name : constant String :=
              (if Node.Has_Value
               then To_String (Node.Unsafe_Just.Find_Partition
                 (Function_Name).Unsafe_Just.Name)
               else "");

418
            Block : Protected_Block :=
419
              (Name     => F.Name,
Maxime Perrotin's avatar
Maxime Perrotin committed
420
               Language => US (TASTE.Backend.Language_Spelling (F)),
421 422
               Node     => Node,
               others   => <>);
423
         begin
Maxime Perrotin's avatar
Maxime Perrotin committed
424 425 426 427 428
            if not Node.Has_Value then
               --  Ignore functions that are not mapped to a node/partition
               goto Continue;
            end if;

429 430 431 432 433 434 435
            for PI of F.Provided loop
               declare
                  New_PI : Protected_Block_PI := (Name   => PI.Name,
                                                  PI     => PI,
                                                  others => <>);
               begin
                  New_PI.PI.RCM := (if F.Provided.Length = 1
436 437 438
                                    then (if PI.RCM = Protected_Operation
                                          then PI.RCM
                                          else Unprotected_Operation)
439
                                    else Protected_Operation);
Maxime Perrotin's avatar
Maxime Perrotin committed
440
                  --  Check in the DV if any caller is remote
441 442 443 444 445 446
                  for Remote of PI.Remote_Interfaces loop
                     declare
                        Remote_Node : constant Option_Node.Option :=
                          Model.Deployment_View.Find_Node
                            (To_String (Remote.Function_Name));
                     begin
Maxime Perrotin's avatar
Maxime Perrotin committed
447 448 449
                        if not Remote_Node.Has_Value
                          or not Block.Node.Has_Value
                        then
450
                           raise Concurrency_View_Error with
Maxime Perrotin's avatar
Maxime Perrotin committed
451
                             "Concurrency Generation Error (parser bug?)";
452
                        end if;
Maxime Perrotin's avatar
Maxime Perrotin committed
453

454 455 456 457 458 459
                        if Block.Node.Unsafe_Just /= Remote_Node.Unsafe_Just
                        then
                           --  At least one caller is on a different node
                           New_PI.Local_Caller := False;
                        end if;
                     end;
Maxime Perrotin's avatar
Maxime Perrotin committed
460
                  end loop;
461
                  Block.Provided.Insert (Key      => To_String (PI.Name),
Maxime Perrotin's avatar
Maxime Perrotin committed
462
                                         New_Item => New_PI);
463
               end;
Maxime Perrotin's avatar
Maxime Perrotin committed
464 465
               if PI.RCM = Cyclic_Operation or PI.RCM = Sporadic_Operation then
                  declare
466
                     Thread : constant AADL_Thread :=
Maxime Perrotin's avatar
Maxime Perrotin committed
467
                       (Name                 => F.Name & "_" & PI.Name,
468
                        RCM                  => US (PI.RCM'Img),
Maxime Perrotin's avatar
Maxime Perrotin committed
469
                        Need_Mutex           => (F.Provided.Length > 1),
Maxime Perrotin's avatar
Maxime Perrotin committed
470 471 472
                        Entry_Port_Name      => PI.Name,
                        Protected_Block_name => Block.Name,
                        Node                 => Block.Node,
473
                        PI                   => PI,
474
                        Output_Ports         => Get_Output_Ports (Model, F));
Maxime Perrotin's avatar
Maxime Perrotin committed
475
                  begin
Maxime Perrotin's avatar
Maxime Perrotin committed
476 477
                     CV.Nodes
                       (Node_Name).Partitions (Partition_Name).Threads.Include
Maxime Perrotin's avatar
Maxime Perrotin committed
478 479 480 481
                       (Key      => To_String (Thread.Name),
                        New_Item => Thread);
                  end;
               end if;
482
            end loop;
483
            Block.Required := F.Required;
484
            --  Add the block to the Concurrency View
Maxime Perrotin's avatar
Maxime Perrotin committed
485 486 487
            CV.Nodes (Node_Name).Partitions (Partition_Name).Blocks.Insert
              (Key      => To_String (Block.Name),
               New_Item => Block);
488
         end;
489
         <<Continue>>
490
      end loop;
491

Maxime Perrotin's avatar
Maxime Perrotin committed
492 493
      for Node of CV.Nodes loop
         for Partition of Node.Partitions loop
494
            --  Find and set protected blocks calling threads
Maxime Perrotin's avatar
Maxime Perrotin committed
495
            Set_Calling_Threads (Partition);
496

Maxime Perrotin's avatar
Maxime Perrotin committed
497 498 499 500 501 502 503 504 505
            --  Check that all blocks have a calling thread, otherwise
            --  they will never run
            for B of Partition.Blocks loop
               if B.Calling_Threads.Length = 0 then
                  raise Concurrency_View_Error with
                    "Function " & To_String (B.Name) & " has no active caller";
               end if;
            end loop;

506
            --  Define ports at partition (process) level
507 508
            --  (ports are for all interfaces of a function not located
            --  in the same partition of the system)
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
            for T of Partition.Threads loop
               --  Check each Remote PI of the entry port of the thread
               for Remote of T.PI.Remote_Interfaces loop
                  declare
                     Node : constant Option_Node.Option  :=
                       CV.Deployment.Find_Node
                         (To_String (Remote.Function_Name));
                     Part : Option_Partition.Option;
                     --  Optional type of the parameter:
                     Sort : constant Unbounded_String :=
                       (if not T.PI.Params.Is_Empty
                        then T.PI.Params.First_Element.Sort
                        else US (""));
                  begin
                     if Node.Has_Value then
                        Part :=
                          Node.Unsafe_Just.Find_Partition
                            (To_String (Remote.Function_Name));

                        if Part.Has_Value
                          and then Part.Unsafe_Just.Name
                            /= Partition.Deployment_Partition.Name
531 532
                             and then not Partition.In_Ports.Contains
                               (To_String (T.Entry_Port_Name))
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
                        then
                           --  shouldn't we check for presence first in case
                           --  there are multiple callers?
                           Partition.In_Ports.Insert
                             (Key      => To_String (T.Entry_Port_Name),
                              New_Item => (Port_Name   => T.Entry_Port_Name,
                                           Thread_Name => T.Name,
                                           Type_Name   => Sort,
                                           Remote_Partition_Name
                                                    => Part.Unsafe_Just.Name));
                        end if;
                     else
                        Put_Error ("This should never happen.");
                     end if;
                  end;
               end loop;
               --  Do the same for output ports
               for Out_Port of T.Output_Ports loop
                  for Remote of Out_Port.RI.Remote_Interfaces loop
                     declare
                        Node : constant Option_Node.Option  :=
                          CV.Deployment.Find_Node
                            (To_String (Remote.Function_Name));
                        Part : Option_Partition.Option;
                        --  Optional type of the parameter:
                        Sort : constant Unbounded_String :=
Maxime Perrotin's avatar
Maxime Perrotin committed
559 560
                          (if not Out_Port.RI.Params.Is_Empty
                           then Out_Port.RI.Params.First_Element.Sort
561 562 563 564 565 566 567 568 569
                           else US (""));
                     begin
                        if Node.Has_Value then
                           Part := Node.Unsafe_Just.Find_Partition
                             (To_String (Remote.Function_Name));

                           if Part.Has_Value and then Part.Unsafe_Just.Name
                             /= Partition.Deployment_Partition.Name
                           then
570 571 572 573 574 575 576 577 578 579 580 581 582
                              if not Partition.Out_Ports.Contains
                                (To_String (Out_Port.RI.Name))
                              then
                                 --  Create a new port and reference the thread
                                 Partition.Out_Ports.Insert
                                   (Key      => To_String (Out_Port.RI.Name),
                                    New_Item => (Port_Name   =>
                                                     Out_Port.RI.Name,
                                                 Connected_Threads =>
                                                   String_Vectors.Empty_Vector
                                                 & To_String (T.Name),
                                                 Type_Name   => Sort,
                                                 Remote_Partition_Name =>
583 584 585
                                                   Part.Unsafe_Just.Name,
                                                 Remote_Port_Name =>
                                                   Remote.Interface_Name));
586 587 588 589 590 591 592
                              else
                                 --  Port already exists: just add this thread
                                 Partition.Out_Ports
                                   (To_String
                                      (Out_Port.RI.Name)).Connected_Threads
                                     .Append (To_String (T.Name));
                              end if;
593 594 595 596 597 598 599 600
                           end if;
                        else
                           Put_Error ("This should never happen.");
                        end if;
                     end;
                  end loop;
               end loop;
            end loop;
Maxime Perrotin's avatar
Maxime Perrotin committed
601 602
         end loop;
      end loop;
603

Maxime Perrotin's avatar
Maxime Perrotin committed
604
      Model.Concurrency_View := CV;
605 606
   end Add_Concurrency_View;

607
   procedure Dump (Model : TASTE_Model) is
608 609
      Output_Path : constant String :=
        Model.Configuration.Output_Dir.Element & "/Debug";
610
      Output  : File_Type;
611
   begin
612 613 614 615 616 617 618 619 620
      if Model.Configuration.Debug_Flag then
         Create_Path (Output_Path);
         Create (File => Output,
                 Mode => Out_File,
                 Name => Output_Path & "/InterfaceView.dump");
         Put_Info ("Dump of the Interface View");
         Model.Interface_View.Debug_Dump (Output);
         Close (Output);

621
         if not Model.Configuration.Deployment_View.Is_Empty then
622 623 624 625 626 627 628
            Create (File => Output,
                    Mode => Out_File,
                    Name => Output_Path & "/DeploymentView.dump");
            Put_Info ("Dump of the Deployment View");
            Model.Deployment_View.Debug_Dump (Output);
            Close (Output);
         end if;
629 630 631 632 633 634 635 636 637 638

         if Model.Configuration.Glue then
            Create (File => Output,
                    Mode => Out_File,
                    Name => Output_Path & "/ConcurrencyView.dump");
            Put_Info ("Dump of the Concurrency View");
            Model.Concurrency_View.Debug_Dump (Output);
            Close (Output);
         end if;

639 640 641 642
         Create (File => Output,
                 Mode => Out_File,
                 Name => Output_Path & "/DataView.dump");
         Put_Info ("Dump of the Data View");
Maxime Perrotin's avatar
Maxime Perrotin committed
643
         Model.Data_View.Debug_Dump (Output);
644
         Close (Output);
645

646 647 648 649
         Create (File => Output,
                 Mode => Out_File,
                 Name => Output_Path & "/commandline.dump");
         Put_Info ("Dump of the Command Line");
Maxime Perrotin's avatar
Maxime Perrotin committed
650
         Model.Configuration.Debug_Dump (Output);
651
         Close (Output);
652 653 654 655

         Put_Info ("Make a local copy of ASN.1 files for export");
         Create_Path (Output_Path & "/Export");
         Model.Data_View.Export_ASN1_Files (Output_Path & "/Export/");
656
      end if;
657 658 659 660
   exception
      when Error : others =>
         Put_Error ("Debug Dump : " & Exception_Message (Error));
         raise Quit_Taste;
661 662
   end Dump;

663 664 665 666 667
   procedure Generate_Build_Script (Model : TASTE_Model) is
   begin
      TASTE.Backend.Build_Script.Generate (Model);
   end Generate_Build_Script;

Maxime Perrotin's avatar
Maxime Perrotin committed
668
   procedure Generate_Code (Model : TASTE_Model) is
Maxime Perrotin's avatar
Maxime Perrotin committed
669
   begin
Maxime Perrotin's avatar
Maxime Perrotin committed
670
      TASTE.Backend.Code_Generators.Generate (Model);
671
   exception
Maxime Perrotin's avatar
Maxime Perrotin committed
672
      when Error : TASTE.Backend.Code_Generators.ACG_Error =>
673 674
         Put_Error (Exception_Message (Error));
         raise Quit_Taste;
675 676
      when Error : others =>
         Errors.Display_Bug_Box (Error);
677
         raise Quit_Taste;
Maxime Perrotin's avatar
Maxime Perrotin committed
678
   end Generate_Code;
679
end TASTE.AADL_Parser;