taste-concurrency_view.adb 4.25 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
45
   function To_Template (B : Protected_Block) return Block_As_Template is
46
      Calling_Threads : Tag;
47
      Result : Block_As_Template;
48
49
50
51
52
   begin
      for Thread of B.Calling_Threads loop
         Calling_Threads := Calling_Threads & Thread;
      end loop;

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
      for PI of B.Provided loop
         declare
            Basic : constant Translate_Set := PI.PI.To_Template
              & Assoc ("Protected_Block_Name", To_String (PI.Name))
              & Assoc ("Caller_Is_Local", PI.Local_Caller);
         begin
            Result.Provided.Append (Basic);
         end;
      end loop;

      for RI of B.Required loop
         Result.Required.Append (RI.To_Template);
      end loop;

      Result.Header := +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));
      return Result;
Maxime Perrotin's avatar
Maxime Perrotin committed
72
   end To_Template;
73
74

   --  This function translates a thread definition into a template
Maxime Perrotin's avatar
Maxime Perrotin committed
75
   function To_Template (T : AADL_Thread) return Translate_Set is
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
      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
94
   end To_Template;
95

96
   function Concurrency_View_Template (CV : Taste_Concurrency_View)
97
98
                                       return CV_As_Template
   is
99
100
      Result : CV_As_Template;
   begin
101
      for Thread of CV.Threads loop
Maxime Perrotin's avatar
Maxime Perrotin committed
102
         Result.Threads.Append (Thread.To_Template);
103
104
      end loop;
      for Pro of CV.Blocks loop
Maxime Perrotin's avatar
Maxime Perrotin committed
105
         Result.Blocks.Append (Pro.To_Template);
106
      end loop;
107
108
      return Result;
   end Concurrency_View_Template;
109
end TASTE.Concurrency_View;