ocarina-utils.adb 9 KB
Newer Older
yoogx's avatar
yoogx committed
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--                        O C A R I N A . U T I L S                         --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--                   Copyright (C) 2013-2014 ESA & ISAE.                    --
yoogx's avatar
yoogx committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
--                                                                          --
-- 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 TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
--                                                                          --
------------------------------------------------------------------------------
33

yoogx's avatar
yoogx committed
34 35 36 37
with Ada.Command_Line;           use Ada.Command_Line;
with GNAT.Directory_Operations;  use GNAT.Directory_Operations;
with GNAT.OS_Lib;                use GNAT.OS_Lib;

yoogx's avatar
yoogx committed
38 39
with Errors;                     use Errors;
with Locations;                  use Locations;
40 41
with Ocarina.Namet;                      use Ocarina.Namet;
with Ocarina.Output;                     use Ocarina.Output;
42
with Ocarina.Types;                      use Ocarina.Types;
yoogx's avatar
yoogx committed
43
with Utils;                      use Utils;
yoogx's avatar
yoogx committed
44

yoogx's avatar
yoogx committed
45
with Ocarina.Analyzer;           use Ocarina.Analyzer;
yoogx's avatar
yoogx committed
46 47 48
with Ocarina.Backends;           use Ocarina.Backends;
with Ocarina.Configuration;      use Ocarina.Configuration;
with Ocarina.FE_AADL;            use Ocarina.FE_AADL;
yoogx's avatar
yoogx committed
49
with Ocarina.FE_AADL.Parser;
yoogx's avatar
yoogx committed
50
with Ocarina.FE_REAL;            use Ocarina.FE_REAL;
yoogx's avatar
yoogx committed
51 52 53 54
with Ocarina.Instances;          use Ocarina.Instances;
with Ocarina.Parser;             use Ocarina.Parser;
with Ocarina.Options;            use Ocarina.Options;
with Ocarina.Files;              use Ocarina.Files;
55 56 57

package body Ocarina.Utils is

yoogx's avatar
yoogx committed
58
   AADL_Root             : Node_Id := No_Node;
59
   File_Name             : Name_Id := No_Name;
yoogx's avatar
yoogx committed
60
   Buffer                : Location;
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
   Language              : Name_Id := No_Name;

   -----------
   -- Reset --
   -----------

   procedure Reset is
   begin
      --  Reset Ocarina

      Ocarina.Configuration.Reset_Modules;
      Ocarina.Reset;

      --  Initialize Ocarina

      Ocarina.AADL_Version := Get_Default_AADL_Version;
      AADL_Version         := Ocarina.AADL_V2;
      Ocarina.Initialize;
      Ocarina.Configuration.Init_Modules;

      --  Reset library

      AADL_Root := No_Node;
      File_Name := No_Name;
      Language := No_Name;
   end Reset;
yoogx's avatar
yoogx committed
87

88 89 90 91 92 93 94 95
   -------------
   -- Version --
   -------------

   procedure Version is
   begin
      Write_Line
        ("Ocarina " & Ocarina_Version
96
           & " (" & Ocarina_Revision & ")");
97 98 99 100 101 102 103 104 105 106

      if Ocarina_Last_Configure_Date /= "" then
         Write_Line ("Build date: " & Ocarina_Last_Configure_Date);
      end if;

      Write_Line
        ("Copyright (c) 2003-2009 Telecom ParisTech, 2010-"
           & Ocarina_Last_Configure_Year & " ESA & ISAE");
   end Version;

107 108 109 110 111 112 113 114 115
   ------------------
   -- Print_Status --
   ------------------

   procedure Print_Status is
   begin
      Write_Line ("AADL version: " & Ocarina.AADL_Version'Img);
      Write_Line ("Library Path: "
                    & Get_Name_String (Default_Library_Path));
yoogx's avatar
yoogx committed
116
      Write_Line ("Load predefined property sets: "
yoogx's avatar
yoogx committed
117
                    & Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets'Img);
118 119
   end Print_Status;

yoogx's avatar
yoogx committed
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 177
   -----------
   -- Usage --
   -----------

   procedure Usage is
      Exec_Suffix : String_Access := Get_Executable_Suffix;
   begin
      Set_Standard_Error;
      Write_Line ("Usage: ");
      Write_Line ("      "
                    & Base_Name (Command_Name, Exec_Suffix.all)
                    & " [options] files");
      Write_Line ("      OR");
      Write_Line ("      "
                    & Base_Name (Command_Name, Exec_Suffix.all)
                    & " -help");
      Write_Line ("  files are a non null sequence of AADL files");

      Write_Eol;
      Write_Line ("  General purpose options:");
      Write_Line ("   -V  Output Ocarina version, then exit");
      Write_Line ("   -s  Output Ocarina search directory, then exit");

      Write_Eol;
      Write_Line ("  Scenario file options:");
      Write_Line ("   -b  Generate and build code from the AADL model");
      Write_Line ("   -z  Clean code generated from the AADL model");
      Write_Line ("   -ec Execute the generated application code and");
      Write_Line ("       retrieve coverage information");
      Write_Line ("   -er Execute the generated application code and");
      Write_Line ("       verify that there is no regression");
      Write_Line ("   -p  Only parse and instantiate the application model");
      Write_Line ("   -c  Only perform schedulability analysis");

      Write_Eol;
      Write_Line ("  Advanced user options:");
      Write_Line ("   -d  Debug mode for developpers");
      Write_Line ("   -q  Quiet mode (default)");
      Write_Line ("   -t  [script] Run Ocarina in terminal interactive mode.");
      Write_Line ("       If a script is given, interpret it then exit.");
      Write_Line ("   -v  Verbose mode for users");
      Write_Line ("   -x  Parse AADL file as an AADL scenario file");

      Ocarina.FE_AADL.Usage;
      Ocarina.FE_REAL.Usage;
      Ocarina.Backends.Usage;

      Write_Line ("   -disable-annexes={annexes}"
                    & "  Desactive one or all annexes");
      Write_Line ("       Annexes :");
      Write_Line ("        all");
      Write_Line ("        behavior");
      Write_Line ("        real");
      Write_Eol;

      Free (Exec_Suffix);
   end Usage;

yoogx's avatar
yoogx committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 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
   --------------------
   -- Load_AADL_File --
   --------------------

   procedure Load_AADL_File (Filename : String) is
   begin
      Language := Get_String_Name ("aadl");
      Set_Str_To_Name_Buffer (Filename);

      File_Name := Search_File (Name_Find);
      if File_Name = No_Name then
         Write_Line ("Cannot find file " & Filename);
         return;
      end if;

      Buffer := Load_File (File_Name);
      if File_Name = No_Name then
         Write_Line ("Cannot read file " & Filename);
         return;
      end if;

      AADL_Root := Parse (Language, AADL_Root, Buffer);
      Exit_On_Error
        (No (AADL_Root),
         "Cannot parse AADL specifications");
      Write_Line
        ("File " & Filename
           & " loaded and parsed sucessfully");
   end Load_AADL_File;

   -------------
   -- Analyze --
   -------------

   procedure Analyze is
      Success : Boolean;
   begin
      Success := Analyze (Language, AADL_Root);
      if not Success then
         Write_Line ("Cannot analyze AADL specifications");
      else
         Write_Line ("Model analyzed sucessfully");
      end if;
   end Analyze;

   -----------------
   -- Instantiate --
   -----------------

   procedure Instantiate (Root_System : String) is
   begin
      if Root_System /= "" then
         Root_System_Name := To_Lower
           (Get_String_Name (Root_System));
      end if;
      AADL_Root := Instantiate_Model (AADL_Root);
      if Present (AADL_Root) then
         Write_Line ("Model instantiated sucessfully");
      end if;
   end Instantiate;

   --------------
   -- Generate --
   --------------

   procedure Generate (Backend_Name : String) is
   begin
      Set_Current_Backend_Name (Backend_Name);
      Write_Line ("Generating code using backend " & Backend_Name);
      Generate_Code (AADL_Root);
   end Generate;

250
end Ocarina.Utils;