ocarina-utils.adb 11.3 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                                  --
--                                                                          --
yoogx's avatar
yoogx committed
9
--                   Copyright (C) 2013-2015 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;
yoogx's avatar
yoogx committed
42
with Utils;                      use Utils;
yoogx's avatar
yoogx committed
43

yoogx's avatar
yoogx committed
44
with Ocarina.Analyzer;           use Ocarina.Analyzer;
yoogx's avatar
yoogx committed
45 46 47
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
48
with Ocarina.FE_AADL.Parser;
yoogx's avatar
yoogx committed
49
with Ocarina.FE_REAL;            use Ocarina.FE_REAL;
yoogx's avatar
yoogx committed
50 51 52 53
with Ocarina.Instances;          use Ocarina.Instances;
with Ocarina.Parser;             use Ocarina.Parser;
with Ocarina.Options;            use Ocarina.Options;
with Ocarina.Files;              use Ocarina.Files;
54 55 56

package body Ocarina.Utils is

yoogx's avatar
yoogx committed
57
   AADL_Root             : Node_Id := No_Node;
58
   File_Name             : Name_Id := No_Name;
yoogx's avatar
yoogx committed
59
   Buffer                : Location;
60 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
   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
86

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

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

      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;

106 107 108 109 110 111 112 113 114
   ------------------
   -- 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
115
      Write_Line ("Load predefined property sets: "
yoogx's avatar
yoogx committed
116
                    & Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets'Img);
117 118
   end Print_Status;

yoogx's avatar
yoogx committed
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
   -----------
   -- 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");
170
      Write_Line ("        behavior_specification");
yoogx's avatar
yoogx committed
171 172 173 174 175 176
      Write_Line ("        real");
      Write_Eol;

      Free (Exec_Suffix);
   end Usage;

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

211
   function Analyze return Boolean is
yoogx's avatar
yoogx committed
212 213 214 215 216 217 218 219
      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;
220
      return Success;
yoogx's avatar
yoogx committed
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
   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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
   -------------------
   -- Get_AADL_Root --
   -------------------

   function Get_AADL_Root return Node_Id is
   begin
      return AADL_Root;
   end Get_AADL_Root;

   -----------------
   -- Get_Node_Id --
   -----------------

   procedure Get_Node_Id (Data : in out Callback_Data'Class;
      N : String) is
   begin
      Set_Return_Value (Data, Integer'Image (Integer
         (Namet.Get_String_Name (N))));
   end Get_Node_Id;

   -----------------------------
   -- Get_Node_Id_From_String --
   -----------------------------

   function Get_Node_Id_From_String (Name : String) return Node_Id is
   begin
      return Node_Id (Integer'Value (Name));
   end Get_Node_Id_From_String;

   -----------------------------
   -- Get_List_Id_From_String --
   -----------------------------

   function Get_List_Id_From_String (Name : String) return List_Id is
   begin
      return List_Id (Integer'Value (Name));
   end Get_List_Id_From_String;

   -----------------------------
   -- Get_Boolean_From_String --
   -----------------------------

   function Get_Boolean_From_String (Name : String) return Boolean is
   begin
      return Boolean'Value (Name);
   end Get_Boolean_From_String;

   --------------------------
   -- Get_Byte_From_String --
   --------------------------

   function Get_Byte_From_String (Name : String) return Byte is
   begin
      return Byte (Integer'Value (Name));
   end Get_Byte_From_String;

   -------------------------
   -- Get_Int_From_String --
   -------------------------

   function Get_Int_From_String (Name : String) return Int is
   begin
      return Int (Integer'Value (Name));
   end Get_Int_From_String;

   ------------------------------
   -- Get_Value_Id_From_String --
   ------------------------------

   function Get_Value_Id_From_String (Name : String) return Value_Id is
   begin
      return Value_Id (Integer'Value (Name));
   end Get_Value_Id_From_String;

   -----------------------------
   -- Get_Name_Id_From_String --
   -----------------------------

   function Get_Name_Id_From_String (Name : String) return Name_Id is
      val : Integer;
   begin
      val := Integer'Value (Name);
      if val > 300_000_000 and then val < 399_999_999 then
         return Name_Id (val);
      else
         return No_Name;
      end if;
   end Get_Name_Id_From_String;

339
end Ocarina.Utils;