taste-concurrency_view.adb 3.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
--  *************************** taste aadl parser ***********************  --
--  (c) 2018 European Space Agency - maxime.perrotin@esa.int
--  LGPL license, see LICENSE file

--  Concurrency View

package body TASTE.Concurrency_View is

   procedure Debug_Dump (CV : Taste_Concurrency_View; Output : File_Type) is
   begin
Maxime Perrotin's avatar
Maxime Perrotin committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
      for Block of CV.Blocks loop
         Put_Line (Output, "Protected Block : " & To_String (Block.Name));
         for Provided of Block.Provided loop
            Put_Line (Output, " |_ PI : " & To_String (Provided.Name));
         end loop;
         for Required of Block.Required loop
            Put_Line (Output, " |_ RI : " & To_String (Required.Name));
         end loop;
         for Thread of Block.Calling_Threads loop
            Put_Line (Output, " |_ Calling_Thread : " & Thread);
         end loop;
         Put_Line (Output, " |_ Node : "
                   & To_String (Block.Node.Value_Or
                     (Taste_Node'(Name => US ("(none)"), others => <>)).Name));
25
26
      end loop;

Maxime Perrotin's avatar
Maxime Perrotin committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
      for Thread of CV.Threads loop
         Put_Line (Output, "Thread : " & To_String (Thread.Name));
         Put_Line (Output, " |_ Port : " & To_String (Thread.Entry_Port_Name));
         Put_Line (Output, " |_ Protected Block : "
                   & To_String (Thread.Protected_Block_Name));
         Put_Line (Output, " |_ Node : "
                   & To_String (Thread.Node.Value_Or
                     (Taste_Node'(Name => US ("(none)"), others => <>)).Name));
         for Out_Port of Thread.Output_Ports loop
            Put_Line (Output, " |_ Output port remote thread : "
                      & To_String (Out_Port.Remote_Thread));
            Put_Line (Output, " |_ Output port remote PI : "
                      & To_String (Out_Port.Remote_PI));
         end loop;
41
42
43
      end loop;
   end Debug_Dump;

44
   --  This function translates a protected block into a template
Maxime Perrotin's avatar
Maxime Perrotin committed
45
   function To_Template (B : Protected_Block) return Translate_Set is
46
47
48
49
50
51
52
53
54
55
56
57
      Calling_Threads : Tag;
      --  TODO: Provided and Required
   begin
      for Thread of B.Calling_Threads loop
         Calling_Threads := Calling_Threads & Thread;
      end loop;

      return Result : constant Translate_Set :=
        (+Assoc  ("Name",            To_String (B.Name))
         & Assoc ("Calling_Threads", Calling_Threads)
         & Assoc ("Node_Name",       To_String (B.Node.Value_Or
           (Taste_Node'(Name => US (""), others => <>)).Name)));
Maxime Perrotin's avatar
Maxime Perrotin committed
58
   end To_Template;
59
60

   --  This function translates a thread definition into a template
Maxime Perrotin's avatar
Maxime Perrotin committed
61
   function To_Template (T : AADL_Thread) return Translate_Set is
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
      Remote_Thread : Vector_Tag;
      Remote_PI     : Vector_Tag;
      Ports_Matrix  : Matrix_Tag;
   begin
      for Out_Port of T.Output_Ports loop
         Remote_Thread := Remote_Thread & To_String (Out_Port.Remote_Thread);
         Remote_PI     := Remote_PI     & To_String (Out_Port.Remote_PI);
      end loop;

      Ports_Matrix := +Remote_Thread & Remote_PI;

      return Result : constant Translate_Set :=
        (+Assoc  ("Name",            To_String (T.Name))
         & Assoc ("Entry_Port_Name", To_String (T.Entry_Port_Name))
         & Assoc ("Pro_Block_Name",  To_String (T.Protected_Block_Name))
         & Assoc ("Node_Name",       To_String (T.Node.Value_Or
           (Taste_Node'(Name => US (""), others => <>)).Name))
         & Assoc ("Out_Ports",       Ports_Matrix));
Maxime Perrotin's avatar
Maxime Perrotin committed
80
   end To_Template;
81

82
   function Concurrency_View_Template (CV : Taste_Concurrency_View)
83
84
                                       return CV_As_Template
   is
85
86
      Result : CV_As_Template;
   begin
87
      for Thread of CV.Threads loop
Maxime Perrotin's avatar
Maxime Perrotin committed
88
         Result.Threads.Append (Thread.To_Template);
89
90
      end loop;
      for Pro of CV.Blocks loop
Maxime Perrotin's avatar
Maxime Perrotin committed
91
         Result.Blocks.Append (Pro.To_Template);
92
      end loop;
93
94
      return Result;
   end Concurrency_View_Template;
95
end TASTE.Concurrency_View;