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

--  Concurrency View

Maxime Perrotin's avatar
Maxime Perrotin committed
7
8
9
10
11
12
with Ada.Directories,
     Ada.IO_Exceptions,
     Ada.Exceptions;

use Ada.Directories;

13
14
15
16
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      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));
31
32
      end loop;

Maxime Perrotin's avatar
Maxime Perrotin committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
      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;
47
48
49
      end loop;
   end Debug_Dump;

50
   --  This function translates a protected block into a template
51
   function To_Template (B : Protected_Block) return Block_As_Template is
52
      Calling_Threads : Tag;
53
      Result : Block_As_Template;
54
55
56
57
58
   begin
      for Thread of B.Calling_Threads loop
         Calling_Threads := Calling_Threads & Thread;
      end loop;

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
      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
78
   end To_Template;
79
80

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

102
   function Concurrency_View_Template (CV : Taste_Concurrency_View)
103
104
                                       return CV_As_Template
   is
105
106
      Result : CV_As_Template;
   begin
107
      for Thread of CV.Threads loop
Maxime Perrotin's avatar
Maxime Perrotin committed
108
         Result.Threads.Append (Thread.To_Template);
109
110
      end loop;
      for Pro of CV.Blocks loop
Maxime Perrotin's avatar
Maxime Perrotin committed
111
         Result.Blocks.Append (Pro.To_Template);
112
      end loop;
113
114
      return Result;
   end Concurrency_View_Template;
Maxime Perrotin's avatar
Maxime Perrotin committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

   --  Parse the template files to generate the CV output with Templates_parser
   procedure Generate_CV (CV                 : Taste_Concurrency_View;
                          Base_Template_Path : String;
                          Base_Output_Path   : String)
   is
      Prefix   : constant String := Base_Template_Path
        & "templates/concurrency_view";
      Template : constant CV_As_Template := CV.Concurrency_View_Template;
      pragma Unreferenced (Template);
      --  To iterate over template folders
      ST       : Search_Type;
      Current  : Directory_Entry_Type;
      Filter   : constant Filter_Type := (Directory => True,
                                          others    => False);
      Output_File : File_Type;
      Output_Dir  : constant String := Base_Output_Path & "/concurrency_view";
      Content  : constant String := "Hello";
      File_Name : constant String := "Concurrency_View.aadl";
   begin
      Put_Info ("Generating Concurrency View");
      --  All files are created in the same folder - create it
      Create_Path (Output_Dir);

      Start_Search (Search    => ST,
                    Pattern   => "",
                    Directory => Prefix,
                    Filter    => Filter);

      if not More_Entries (ST) then
         --  On Unix, this will never happen because "." and ".." are part
         --  of the search result. We'll only get an IO Error if the
         --  concurrency_view folder itself does not exist
         raise Concurrency_View_Error with
           "No folders with templates for concurrency view";
      end if;

      --  Iterate over the folders and process templates
      while More_Entries (ST) loop
         Get_Next_Entry (ST, Current);

         --  Ignore Unix special directories
         if Simple_Name (Current) = "." or Simple_Name (Current) = ".." then
            goto continue;
         end if;

         Put_Info ("Generating from " & Full_Name (Current));

         Create (File => Output_File,
                 Mode => Out_File,
                 Name => Output_Dir & File_Name);
         Put_Line (Output_File, Content);

         Close (Output_File);
         <<continue>>
      end loop;
   exception
      when Error : Concurrency_View_Error | Ada.IO_Exceptions.Name_Error =>
         Put_Error ("Concurrency View : "
                    & Ada.Exceptions.Exception_Message (Error));
         raise Quit_Taste;
   end Generate_CV;
177
end TASTE.Concurrency_View;