ocarina_cmd.adb 24.5 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                          O C A R I N A _ C M D                           --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2004-2009 Telecom ParisTech, 2010-2018 ESA & ISAE.      --
10
--                                                                          --
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
27
28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
32
33
34
--                                                                          --
------------------------------------------------------------------------------

--  This program is used to drive Ocarina, it is a wrapper to all
--  functions provided by the library.

35
with Errors;    use Errors;
36
with Locations; use Locations;
37
38
with Ocarina.Namet;     use Ocarina.Namet;
with Ocarina.Output;    use Ocarina.Output;
39
with Ocarina.Types;     use Ocarina.Types;
40
41
42
43
44
45
46
47
48
49
50

with Ada.Text_IO;

with GNAT.Command_Line;         use GNAT.Command_Line;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.OS_Lib;               use GNAT.OS_Lib;

with Ocarina;                          use Ocarina;
with Ocarina.AADL_Values;              use Ocarina.AADL_Values;
with Ocarina.Analyzer;                 use Ocarina.Analyzer;
with Ocarina.Backends;                 use Ocarina.Backends;
51
with Ocarina.Backends.PO_HI_C;
52
with Ocarina.Backends.PO_HI_Ada;
53
with Ocarina.Backends.Execution_Tests; use Ocarina.Backends.Execution_Tests;
54
with Ocarina.Cmd_Line;
55
56
57
58
59
60
61
62
63
64
65
with Ocarina.Configuration;            use Ocarina.Configuration;
with Ocarina.Files;                    use Ocarina.Files;
with Ocarina.Instances;                use Ocarina.Instances;
with Ocarina.Instances.Queries;        use Ocarina.Instances.Queries;
with Ocarina.ME_AADL.AADL_Tree.Nodes;  use Ocarina.ME_AADL.AADL_Tree.Nodes;
with Ocarina.ME_AADL.AADL_Tree.Nutils; use Ocarina.ME_AADL.AADL_Tree.Nutils;
with Ocarina.Options;                  use Ocarina.Options;
with Ocarina.Parser;                   use Ocarina.Parser;
with Ocarina.Property_Sets;            use Ocarina.Property_Sets;
with Ocarina.FE_AADL.Parser;           use Ocarina.FE_AADL.Parser;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
66
with Ocarina.Scripts;                  use Ocarina.Scripts;
67
68
69
70
71
72
73

procedure Ocarina_Cmd is

   procedure Parse_Scenario_Files;
   --  Parse a set of scenario file and updates the global variable
   --  according to the extracted information.

74
75
   AADL_Root             : Node_Id     := No_Node;
   Success               : Boolean     := True;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
   File_Name             : Name_Id;
   Buffer                : Location;
   Language              : Name_Id;

   -------------------------
   -- Parse_Scenario_File --
   -------------------------

   --  Example of an AADL scenario:

   --  -----------------
   --  -- FILE_1.aadl --
   --  -----------------

   --  system RMA
   --  properties
   --    Ocarina_Config::AADL_Files => ("rma.aadl");
   --    --  "rma.aadl" contains common AADL components (processes,
   --    --  threads, data types)
   --
   --    Ocarina_Config::Needed_Property_Sets =>
   --      (value (Ocarina_Config::ARAO),
   --       value (Ocarina_Config::Cheddar_Properties));
   --    --  The non standard predefined property sets needed by the
   --    --  application.
   --  end RMA;

   --  -----------------
   --  -- FILE_2.aadl --
   --  -----------------

   --  system implementation RMA.Impl_C
   --  properties
   --    Ocarina_Config::AADL_Files +=> ("software_c.aadl");
   --    --  Note that this is an additive property
   --    --  association.
   --
   --    Ocarina_Config::Generator => PolyORB_HI_C;
   --    --  The code generator
   --  end RMA.Impl_C;

   --  -----------------
   --  -- FILE_3.aadl --
   --  -----------------

   --  system implementation RMA.Impl_Ada
   --  properties
   --    Source_Text +=> ("software_ada.aadl");
   --    --  Note that this is an additive property
   --    --  association.
   --
   --    Ocarina_Config::Generator => PolyORB_HI_Ada;
   --    --  The code generator
   --  end RMA.Impl_Ada;

   --  Calling the compiler on FILE_1.aadl and FILE_2.aadl will
   --  generate C code for the Poly_ORB-HI framework starting from
   --  "rma.aadl" and "software_c.aadl".

   --  Calling the compiler on FILE_1.aadl and FILE_3.aadl will
   --  generate Ada code for the Poly_ORB-HI framework starting from
   --  "rma.aadl" and "software_ada.aadl".

   procedure Parse_Scenario_Files is
140
141
142
143
144
145
      AADL_Root              : Node_Id := No_Node;
      Instance_Root          : Node_Id := No_Node;
      Root_System            : Node_Id := No_Node;
      Source_Files           : List_Id;
      Ref_Files              : List_Id;
      Needed_PS              : List_Id;
146
      Enabled_Anx            : List_Id;
147
148
149
150
      Use_CL                 : Boolean := False;
      Used_Generator_Options : List_Id;
      Dirname                : Name_Id;
      Success                : Boolean := False;
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

      The_Backend : Name_Id := No_Name;
      --  The current code generator

      Current_Scenario_Dirname : Name_Id := No_Name;
      --  The current dirname of all the scenario files.

      AADL_Version_Name : Name_Id := No_Name;
      --  The AADL version under which the model will be parsed

      Temp_AADL_Version : AADL_Version_Type;

      Ocarina_Config : constant String := "ocarina_config";
      --  The property set containing the Ocarina configuration
      --  properties.

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
      AADL_Files : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::aadl_files");
      Use_Components_Library : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::use_components_library");
      Referencial_Files : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::referencial_files");
      The_Generator : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::generator");
      Generator_Options : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::generator_options");
      Predefined_PS : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::needed_property_sets");
      RS_Name : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::root_system_name");
      AADL_Version : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::aadl_version");
      Timeout_Property : constant Name_Id :=
        Get_String_Name (Ocarina_Config & "::timeout_property");
185
186
      Enable_Annexes   : constant Name_Id
        := Get_String_Name (Ocarina_Config & "::enable_annexes");
187
188
189
190
191
192

      -------------------------------
      -- Extract_Referencial_Files --
      -------------------------------

      procedure Extract_Referencial_Files
193
194
        (Ref_Files :        List_Id;
         Ref_Map   : in out String_String_Maps.Map)
195
      is
196
         N : Node_Id;
197
         Position : String_String_Maps.Cursor;
198
199
200
201
202
      begin
         if not Is_Empty (Ref_Files) then
            N := First_Node (Ref_Files);
            while Present (N) loop
               declare
203
204
                  App_Name : constant String :=
                    Image (Value (N), Quoted => False);
205
206
207
208
               begin
                  N := Next_Node (N);
                  if Present (N) then
                     declare
209
210
                        File : constant String :=
                          Image (Value (N), Quoted => False);
211
212
                     begin
                        Write_Line ("Inserting : " & App_Name & " / " & File);
213
214
215
216
217
218
                        String_String_Maps.Insert
                          (Container => Ref_Map,
                           Key       => App_Name,
                           New_Item  => File,
                           Position  => Position,
                           Inserted  => Success);
219
220
                     end;
                  else
221
222
223
224
                     Exit_On_Error
                       (True,
                        "Missing parameters in " &
                        "Referencial_Files property");
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
                  end if;
                  N := Next_Node (N);
               end;
            end loop;
         end if;
      end Extract_Referencial_Files;

      --------------------------
      -- Extract_Source_Files --
      --------------------------

      procedure Extract_Source_Files
        (Source_Files : List_Id;
         Needed_PS    : List_Id);
      --  FIXME : Update the sources with the full path of the given AADL
      --  source file list and the needed predefined property sets (???).

      procedure Extract_Source_Files
        (Source_Files : List_Id;
         Needed_PS    : List_Id)
      is
         N : Node_Id;

      begin
         if not Is_Empty (Needed_PS) then
250
            N := First_Node (Needed_PS);
251
252
253
254

            while Present (N) loop
               declare
                  P         : Name_Id;
255
256
                  File_Name : constant String :=
                    Image (Value (N), Quoted => False);
257
258
259
260
261
               begin
                  Set_Str_To_Name_Buffer (File_Name);
                  Set_Str_To_Name_Buffer
                    (Image
                       (Ocarina_Property_Set_Type'Value
262
                          ("O_" & Name_Buffer (1 .. Name_Len))));
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
                  P := Name_Find;

                  Get_Name_String (Default_Library_Path);
                  Get_Name_String_And_Append (P);
                  Add_Str_To_Name_Buffer (".aadl");

               exception
                  when others =>
                     --  If we fail here, this means that the user gave a
                     --  custom property set file, assume that this file
                     --  is located in the data directory.

                     --  Build the full-path file name
                     Get_Name_String (Default_Library_Path);
                     Add_Str_To_Name_Buffer (File_Name & ".aadl");
               end;

280
281
               Ocarina.Files.Add_File_To_Parse_List
                 (Name_Find, Add_Suffix => True);
282
283
284
285

               N := Next_Node (N);
            end loop;
         end if;
286
287
288
289

         N := First_Node (Source_Files);
         while Present (N) loop
            declare
290
291
               File_Name : constant String :=
                 Image (Value (N), Quoted => False);
292
293
294
            begin
               Get_Name_String (Current_Scenario_Dirname);
               Add_Str_To_Name_Buffer (File_Name);
295
296
               Ocarina.Files.Add_File_To_Parse_List
                 (Name_Find, Add_Suffix => True);
297
298
299
               N := Next_Node (N);
            end;
         end loop;
300
301
302
303
      end Extract_Source_Files;

      package OIQ renames Ocarina.Instances.Queries;

304
      F : Types.Int;
305
      N : Node_Id;
306

307
308
309
   begin
      Current_Scenario_Dirname := No_Name;

310
311
      AADL_Root := Process_Predefined_Property_Sets (AADL_Root);

312
313
314
315
      if Ocarina.AADL_Version = AADL_V2 then
         Sources.Append (Get_String_Name ("ocarina_library.aadl"));
      end if;

316
317
318
      F := Sources.First;

      loop
319
320
321
322
         Dirname :=
           Get_String_Name
             (Dir_Name
                (Normalize_Pathname (Get_Name_String (Sources.Table (F)))));
323
324
325

         if Current_Scenario_Dirname = No_Name then
            Current_Scenario_Dirname := Dirname;
326
327
            Scenario_Dir             :=
              new String'(Get_Name_String (Current_Scenario_Dirname));
328
329
330
331
332
333
334
         end if;

         File_Name := Search_File (Sources.Table (F));
         Exit_On_Error
           ((File_Name = No_Name),
            "Cannot find file " & Get_Name_String (Sources.Table (F)));
         Buffer := Load_File (File_Name);
335
336
337
338
         if Verbose then
            Write_Line ("Loading file " & Get_Name_String (Sources.Table (F)));
         end if;

339
340
341
342
         Exit_On_Error
           ((File_Name = No_Name),
            "Cannot read file " & Get_Name_String (Sources.Table (F)));
         AADL_Root := Parse (Language, AADL_Root, Buffer);
343
         Exit_On_Error (No (AADL_Root), "Cannot parse AADL specifications");
344

345
346
347
         exit when F = Sources.Last; -- XXX Sources.Last may be modified
         F := F + 1;
      end loop;
348
349
350
351
352
353
354
355
356
357
358
359
360
361

      --  Analyze the AADL tree

      Success := Analyze (Language, AADL_Root);
      Exit_On_Error (not Success, "Cannot analyze AADL scenarios");

      --  Instantiate the AADL tree

      Instance_Root := Instantiate_Model (AADL_Root);
      Exit_On_Error (No (Instance_Root), "Cannot instantiate AADL scenarios");

      --  Every thing is fine, extract the information from the
      --  scenario model.

362
363
      Root_System :=
        Ocarina.ME_AADL.AADL_Instances.Nodes.Root_System (Instance_Root);
364
365
366
367
368
369
370
371
372
373
374
375
376

      --  Extract the generator

      Exit_On_Error
        (not Is_Defined_Enumeration_Property (Root_System, The_Generator),
         "You must specify a code generator");

      The_Backend := Get_Enumeration_Property (Root_System, The_Generator);

      --  Extract the AADL files to be parsed

      Exit_On_Error
        (not Is_Defined_List_Property (Root_System, AADL_Files),
377
378
379
         "AADL source files have to be specified by" &
         " means of the standard property" &
         " ""Source_Text""");
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405

      Source_Files := Get_List_Property (Root_System, AADL_Files);

      --  Extract the referencial files for regression tests

      if Is_Defined_List_Property (Root_System, Referencial_Files) then
         Ref_Files := Get_List_Property (Root_System, Referencial_Files);
      else
         Ref_Files := No_List;
      end if;

      --  Extract the timeout used to stop the test

      if OIQ.Is_Defined_Integer_Property (Root_System, Timeout_Property) then
         Timeout := OIQ.Get_Integer_Property (Root_System, Timeout_Property);
      end if;

      --  Extract the predefined property sets needed by the
      --  application

      if Is_Defined_List_Property (Root_System, Predefined_PS) then
         Needed_PS := Get_List_Property (Root_System, Predefined_PS);
      else
         Needed_PS := No_List;
      end if;

406
      if Is_Defined_Boolean_Property (Root_System, Use_Components_Library) then
julien.delange's avatar
julien.delange committed
407
408
409
410
411
         Use_CL := True;
      else
         Use_CL := False;
      end if;

412
      --  See what annexes are enabled for this model. If none are
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
      --  given, assume the user want to disable them all.

      if Is_Defined_List_Property (Root_System, Enable_Annexes) then
         Enabled_Anx := Get_List_Property (Root_System, Enable_Annexes);
      else
         Enabled_Anx := No_List;
      end if;

      declare
         N : Node_Id;
      begin
         if not Is_Empty (Enabled_Anx) then
            N := First_Node (Enabled_Anx);

            Reset_Annex_Action;

            while Present (N) loop
               declare
                  A : constant String := Get_Name_String
                    (Name (Identifier (N)));
               begin
                  if A = "annex_all" then
                     Unset_Annex_Action (Disable_ALL);
                     Unset_Annex_Action (Disable_REAL);
                     Unset_Annex_Action (Disable_BA);
438
                     Unset_Annex_Action (Disable_EMA);
439
440
441
442
443
444
445
446
447
448

                  elsif A = "annex_none" then
                     null;

                  elsif A = "behavior_specification" then
                     Unset_Annex_Action (Disable_BA);

                  elsif A = "real_specification" then
                     Unset_Annex_Action (Disable_REAL);

449
450
451
                  elsif A = "emv2" then
                     Unset_Annex_Action (Disable_EMA);

452
453
454
455
456
457
458
459
460
461
462
463
                  else
                     raise Program_Error
                       with "Internal error : make sure you handle "
                       & "with all annexes declared in ocarina_config.aadl";
                  end if;
               end;

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

464
465
466
      --  Extract the generator options.

      if Is_Defined_List_Property (Root_System, Generator_Options) then
467
468
         Used_Generator_Options :=
           Get_List_Property (Root_System, Generator_Options);
469
470
471
472
473
474
475
476
477
478
479
      else
         Used_Generator_Options := No_List;
      end if;

      --  Process options.

      if not Is_Empty (Used_Generator_Options) then
         N := First_Node (Used_Generator_Options);

         while Present (N) loop
            declare
480
481
               P      : Name_Id;
               Option : constant String := Image (Value (N), Quoted => False);
482
483
484
485
486
487
488
489
490
            begin

               Set_Str_To_Name_Buffer (Option);
               P := Name_Find;

               if P = Get_String_Name ("gprof") then
                  Ocarina.Backends.PO_HI_C.Set_Performance_Analysis (True);
               end if;

491
492
               if P = Get_String_Name ("asn1") then
                  Ocarina.Backends.PO_HI_C.Set_ASN1_Deployment (True);
493
                  Ocarina.Backends.PO_HI_Ada.Set_ASN1_Deployment (True);
494
495
               end if;

496
497
498
499
500
               N := Next_Node (N);
            end;
         end loop;
      end if;

501
502
503
      --  Extract the AADL version

      if Is_Defined_Enumeration_Property (Root_System, AADL_Version) then
504
505
         AADL_Version_Name :=
           Get_Enumeration_Property (Root_System, AADL_Version);
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523

         if Get_Name_String (AADL_Version_Name) = "aadlv1" then
            Temp_AADL_Version := Ocarina.AADL_V1;
         elsif Get_Name_String (AADL_Version_Name) = "aadlv2" then
            Temp_AADL_Version := Ocarina.AADL_V2;
         else
            raise Program_Error;
         end if;
      else
         Temp_AADL_Version := Ocarina.AADL_V1;
      end if;

      Ocarina.AADL_Version := Temp_AADL_Version;

      Sources.Free;
      Sources.Init;
      Extract_Source_Files (Source_Files, Needed_PS);

julien.delange's avatar
julien.delange committed
524
525
      if Use_CL then
         Set_Str_To_Name_Buffer ("ocarina_components.aadl");
526
         Ocarina.Files.Add_File_To_Parse_List (Name_Find, Add_Suffix => True);
julien.delange's avatar
julien.delange committed
527
         Set_Str_To_Name_Buffer ("base_types.aadl");
528
         Ocarina.Files.Add_File_To_Parse_List (Name_Find, Add_Suffix => True);
julien.delange's avatar
julien.delange committed
529
530
      end if;

531
532
533
534
535
536
537
538
539
540
541
      Extract_Referencial_Files (Ref_Files, Ref_Map);

      --  Extract the name of the root of the instance tree

      if Is_Defined_String_Property (Root_System, RS_Name) then
         Root_System_Name := Get_String_Property (Root_System, RS_Name);
      end if;

      --  Reset Ocarina to have a clean set up for the next step

      declare
542
543
         The_Backend_Name : constant String := Get_Name_String (The_Backend);
         Result           : Argument_List_Access :=
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
           new Argument_List
           (Integer (Sources.First) .. Integer (Sources.Last));
         Root_System_Name_Ptr : String_Access;
      begin
         if Root_System_Name /= No_Name then
            Root_System_Name_Ptr :=
              new String'(Get_Name_String (Root_System_Name));
         else
            Root_System_Name_Ptr := new String'("");
         end if;

         for J in Sources.First .. Sources.Last loop
            Result (Integer (J)) :=
              new String'(Get_Name_String (Sources.Table (J)));
         end loop;

         Ocarina.Configuration.Reset_Modules;
         Ocarina.Reset;
562
         --         Ocarina.Files.Sources.Init;
563
564

         Ocarina.Initialize;
565
         Language             := Get_String_Name ("aadl");
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
         Ocarina.AADL_Version := Temp_AADL_Version;
         Set_Current_Backend_Name (The_Backend_Name);

         Ocarina.Configuration.Init_Modules;
         Sources.Free;
         Sources.Init;

         --  Restore the root system name

         if Root_System_Name_Ptr.all /= "" then
            Set_Str_To_Name_Buffer (Root_System_Name_Ptr.all);
            Root_System_Name := Name_Find;
         else
            Root_System_Name := No_Name;
         end if;

         for J in Result'Range loop
            Set_Str_To_Name_Buffer (Result (J).all);
584
585
            Ocarina.Files.Add_File_To_Parse_List
              (Name_Find, Add_Suffix => True);
586
587
588
589
590
591
592
593
594
595
596
597
598
         end loop;

         --  Avoid memory leaks

         Free (Result);
         Free (Root_System_Name_Ptr);
      end;
   end Parse_Scenario_Files;

begin
   --  Init

   Ocarina.Initialize;
599
   Language             := Get_String_Name ("aadl");
600
601
602
603
604
   Default_AADL_Version := Get_Default_AADL_Version;
   AADL_Version         := Default_AADL_Version;

   --  Process the command line

605
   Ocarina.Cmd_Line.Process;
606
607
608
609
610

   --  Initialization Modules

   Ocarina.Configuration.Init_Modules;

611
612
613
   --  Process command line parameters

   if Verbose then
614
      Set_Standard_Error;
yoogx's avatar
yoogx committed
615
616
617
      if not Display_Version then
         Version;
      end if;
618
619
   end if;

620
621
622
623
624
625
626
627
   if Display_Version then
      Version;
      OS_Exit (0);

   elsif Show_Search_Directory then
      Write_Line (Get_Name_String (Default_Library_Path));
      OS_Exit (0);

yoogx's avatar
yoogx committed
628
629
630
631
   elsif Get_Current_Action = List_Backends then
      Write_Backends (1);
      OS_Exit (0);

632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
   elsif Get_Current_Action = Shell then
      Ocarina_Shell;
      OS_Exit (0);

   elsif Sources.Last = 0 then
      Ada.Text_IO.Put ("No AADL files given, ");
      Try_Help;
      OS_Exit (1);
   end if;

   --  If not action has been set, set it to analyse the models only

   if Get_Current_Action = None then
      Set_Current_Action (Analyze_Model);
   end if;

   if Get_Current_Action = Parse_Scenario_Files_First then
      Parse_Scenario_Files;
      Reset_Current_Action;
      Set_Current_Action (After_Scenario_Action);
   end if;
653

yoogx's avatar
yoogx committed
654
   --  Parse the AADL files
655

yoogx's avatar
yoogx committed
656
657
658
659
660
661
662
663
664
665
666
667
668
   AADL_Root := No_Node;
   declare
      F : Types.Int := Sources.First;
   begin
      loop
         File_Name := Search_File (Sources.Table (F));
         Exit_On_Error
           ((File_Name = No_Name),
            "Cannot find file " & Get_Name_String (Sources.Table (F)));
         Buffer := Load_File (File_Name);
         Exit_On_Error
           ((File_Name = No_Name),
            "Cannot read file " & Get_Name_String (Sources.Table (F)));
669
670
671
672
673

         if Verbose then
            Write_Line ("Loading file " & Get_Name_String (Sources.Table (F)));
         end if;

yoogx's avatar
yoogx committed
674
675
676
677
678
679
         AADL_Root := Parse (Language, AADL_Root, Buffer);
         Exit_On_Error (No (AADL_Root), "Cannot parse AADL specifications");
         exit when F = Sources.Last;
         F := F + 1;
      end loop;
   end;
680
681
682
   if Verbose then
      Write_Line ("Loading of all files done");
   end if;
683

yoogx's avatar
yoogx committed
684
685
   Success := Analyze (Language, AADL_Root);
   Exit_On_Error (not Success, "Cannot analyze AADL specifications");
686

687
   if Verbose then
yoogx's avatar
yoogx committed
688
689
      Write_Line ("Model parsing: completed");
      Write_Eol;
690
691
692
693
694
695
696
697
698
   end if;

   case Get_Current_Action is
      when Analyze_Model =>
         null;

      when Instantiate_Model =>
         AADL_Root := Instantiate_Model (AADL_Root);
         Exit_On_Error (No (AADL_Root), "Cannot instantiate AADL models");
699
         if Verbose then
700
            Set_Standard_Error;
701
702
            Write_Line ("Model instantiation: completed");
            Write_Eol;
703
            Set_Standard_Output;
704
         end if;
705
706
707

      when Generate_Code =>
         Generate_Code (AADL_Root);
708
         if Verbose then
709
            Set_Standard_Error;
710
711
            Write_Line ("Code generation: completed");
            Write_Eol;
712
            Set_Standard_Output;
713
         end if;
714
715
716
717

      when others =>
         null;
   end case;
718
719
720
721
722
723

exception
   when GNAT.Command_Line.Exit_From_Command_Line =>
      --  Expected when Getopt processes -h or --help
      null;

yoogx's avatar
yoogx committed
724
725
726
   when E : others =>
      Display_Bug_Box (E);

727
end Ocarina_Cmd;