ocarina-backends-asn1-deployment.adb 10.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--     O C A R I N A . B A C K E N D S . A S N 1 . D E P L O Y M E N T      --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                 Copyright (C) 2010, GET-Telecom Paris.                   --
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. 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. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
--                 Ocarina is maintained by the Ocarina team                --
--                       (ocarina-users@listes.enst.fr)                     --
--                                                                          --
------------------------------------------------------------------------------

julien.delange's avatar
julien.delange committed
34
with Namet; use Namet;
35
with Utils; use Utils;
36
37
38
39
40
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;

41
with Ocarina.Backends.Utils;
julien.delange's avatar
julien.delange committed
42
with Ocarina.Backends.ASN1_Tree.Nutils;
43
with Ocarina.Backends.ASN1_Tree.Nodes;
julien.delange's avatar
julien.delange committed
44

45
46
47
48
49
50
package body Ocarina.Backends.ASN1.Deployment is

   use Ocarina.ME_AADL;
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
   use Ocarina.ME_AADL.AADL_Instances.Entities;

51
   use Ocarina.Backends.Utils;
julien.delange's avatar
julien.delange committed
52
53
   use Ocarina.Backends.ASN1_Tree.Nutils;

54
   package ASN1N renames Ocarina.Backends.ASN1_Tree.Nodes;
55
56
57
58
59
60
61
62
63
64
   package AAU renames Ocarina.ME_AADL.AADL_Instances.Nutils;

   procedure Visit_Architecture_Instance (E : Node_Id);
   procedure Visit_Component_Instance (E : Node_Id);
   procedure Visit_System_Instance (E : Node_Id);
   procedure Visit_Process_Instance (E : Node_Id);
   procedure Visit_Device_Instance (E : Node_Id);
   procedure Visit_Thread_Instance (E : Node_Id);
   procedure Visit_Subprogram_Instance (E : Node_Id);

65
66
67
68
69
70
   Thread_Enumeration : List_Id;
   Thread_Id : Unsigned_Long_Long := 0;
   Port_Enumeration : List_Id;
   Port_Id : Unsigned_Long_Long := 0;
   Module_Node : Node_Id;

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
   -----------
   -- Visit --
   -----------

   procedure Visit (E : Node_Id) is
   begin
      case Kind (E) is
         when K_Architecture_Instance =>
            Visit_Architecture_Instance (E);

         when K_Component_Instance =>
            Visit_Component_Instance (E);

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

   ---------------------------------
   -- Visit_Architecture_Instance --
   ---------------------------------

   procedure Visit_Architecture_Instance (E : Node_Id) is
   begin
julien.delange's avatar
julien.delange committed
95
96
97
      ASN1_Root := Make_ASN1_File
         (Make_Defining_Identifier
            (Get_String_Name ("deployment")));
98
99
      ASN1N.Set_Name
         (ASN1N.Module_Node (ASN1_Root),
100
101
102
103
104
105
         Get_String_Name ("POHIC-DEPLOYMENT"));
      Module_Node := ASN1N.Module_Node (ASN1_Root);

      Thread_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);
      Port_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);

106
      Visit (Root_System (E));
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

      if Length (Thread_Enumeration) > 0 then
         Append_Node_To_List
         (Make_Type_Definition
            (Get_String_Name ("THREADS"),
            Make_Enumerated (Thread_Enumeration)),
         ASN1N.Definitions (Module_Node));
      end if;

      if Length (Thread_Enumeration) > 0 then
         Append_Node_To_List
         (Make_Type_Definition
            (Get_String_Name ("PORTS"),
            Make_Enumerated (Port_Enumeration)),
         ASN1N.Definitions (Module_Node));
      end if;

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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
   end Visit_Architecture_Instance;

   ------------------------------
   -- Visit_Component_Instance --
   ------------------------------

   procedure Visit_Component_Instance (E : Node_Id) is
      Category : constant Component_Category
        := Get_Category_Of_Component (E);
   begin
      case Category is
         when CC_System =>
            Visit_System_Instance (E);

         when CC_Process =>
            Visit_Process_Instance (E);

         when CC_Thread =>
            Visit_Thread_Instance (E);

         when CC_Device =>
            Visit_Device_Instance (E);

         when CC_Subprogram =>
            Visit_Subprogram_Instance (E);

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

   ----------------------------
   -- Visit_Process_Instance --
   ----------------------------

   procedure Visit_Process_Instance (E : Node_Id) is
      S               : Node_Id;
   begin
      if not AAU.Is_Empty (Subcomponents (E)) then
         S := First_Node (Subcomponents (E));
         while Present (S) loop
            --  Visit the component instance corresponding to the
            --  subcomponent S.

            Visit (Corresponding_Instance (S));
            S := Next_Node (S);
         end loop;
      end if;
   end Visit_Process_Instance;

   ---------------------------
   -- Visit_System_Instance --
   ---------------------------

   procedure Visit_System_Instance (E : Node_Id) is
      S : Node_Id;
   begin
      --  Visit all the subcomponents of the system

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

            Visit (Corresponding_Instance (S));
            S := Next_Node (S);
         end loop;
      end if;
   end Visit_System_Instance;

   ---------------------------
   -- Visit_Thread_Instance --
   ---------------------------

   procedure Visit_Thread_Instance (E : Node_Id) is
      S        : Node_Id;
201
      F        : Node_Id;
202
203
      Call_Seq : Node_Id;
      Spg_Call : Node_Id;
204
205
206
      Thread_Name : Name_Id;
      Parent_Name : Name_Id;
      Port_Name : Name_Id;
207
   begin
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

      Set_Str_To_Name_Buffer ("thread-");
      Parent_Name := Display_Name
         (Identifier
          (Parent_Subcomponent
           (Parent_Component
            (Parent_Subcomponent (E)))));
      Get_Name_String_And_Append (Parent_Name);
      Add_Str_To_Name_Buffer ("-");
      Get_Name_String_And_Append
         (Display_Name
           (Identifier
            (Parent_Subcomponent (E))));
      Thread_Name := Name_Find;

      Thread_Name := To_Upper (Thread_Name);

      Append_Node_To_List
         (Make_Enumerated_Value
            (Thread_Name, Thread_Id),
         Thread_Enumeration);

      Thread_Id := Thread_Id + 1;

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
      if not AAU.Is_Empty (Subcomponents (E)) then
         S := First_Node (Subcomponents (E));
         while Present (S) loop
            --  Visit the component instance corresponding to the
            --  subcomponent S.

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

      if not AAU.Is_Empty (Calls (E)) then
         Call_Seq := First_Node (Calls (E));

         while Present (Call_Seq) loop
            --  For each call sequence visit all the called
            --  subprograms.

            if not AAU.Is_Empty (Subprogram_Calls (Call_Seq)) then
               Spg_Call := First_Node (Subprogram_Calls (Call_Seq));

               while Present (Spg_Call) loop
                  Visit (Corresponding_Instance (Spg_Call));

                  Spg_Call := Next_Node (Spg_Call);
               end loop;
            end if;

            Call_Seq := Next_Node (Call_Seq);
         end loop;
      end if;

264
265
266
267
268
269
270
271
272
273
274
275
276
      if Has_Ports (E) then
         F := First_Node (Features (E));

         while Present (F) loop
            if Kind (F) = K_Port_Spec_Instance then
               Set_Str_To_Name_Buffer ("port-");
               Get_Name_String_And_Append (Thread_Name);
               Add_Str_To_Name_Buffer ("-");
               Get_Name_String_And_Append
                  (Display_Name (Identifier (F)));
               Port_Name := Name_Find;
               Port_Name := To_Upper (Port_Name);

277
278
               Port_Name := Replace_Char (Port_Name, '_', '-');

279
280
281
282
283
284
285
286
287
288
289
               Append_Node_To_List
               (Make_Enumerated_Value
                (Port_Name, Port_Id),
                Port_Enumeration);

               Port_Id := Port_Id + 1;

            end if;
            F := Next_Node (F);
         end loop;
      end if;
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
   end Visit_Thread_Instance;

   -------------------------------
   -- Visit_Subprogram_Instance --
   -------------------------------

   procedure Visit_Subprogram_Instance (E : Node_Id) is
      pragma Unreferenced (E);
   begin
      null;
   end Visit_Subprogram_Instance;

      ---------------------------
      -- Visit_Device_Instance --
      ---------------------------

   procedure Visit_Device_Instance (E : Node_Id) is
      pragma Unreferenced (E);
   begin
      null;
   end Visit_Device_Instance;

end Ocarina.Backends.ASN1.Deployment;