ocarina-utils.adb 8.88 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                                  --
--                                                                          --
Jerome Hugues's avatar
Jerome Hugues committed
9
--                   Copyright (C) 2013-2016 ESA & ISAE.                    --
yoogx's avatar
yoogx committed
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/>.                                          --
yoogx's avatar
yoogx committed
26 27 28 29 30
--                                                                          --
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
--                                                                          --
------------------------------------------------------------------------------
31

yoogx's avatar
yoogx committed
32 33
with Errors;                     use Errors;
with Locations;                  use Locations;
yoogx's avatar
yoogx committed
34 35
with Ocarina.Namet;              use Ocarina.Namet;
with Ocarina.Output;             use Ocarina.Output;
yoogx's avatar
yoogx committed
36
with Utils;                      use Utils;
yoogx's avatar
yoogx committed
37

yoogx's avatar
yoogx committed
38
with Ocarina.Analyzer;           use Ocarina.Analyzer;
39
with Ocarina.Analyzer.REAL;      use Ocarina.Analyzer.REAL;
yoogx's avatar
yoogx committed
40 41 42
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
43
with Ocarina.FE_AADL.Parser;
44
with Ocarina.FE_REAL.Parser;     use Ocarina.FE_REAL.Parser;
yoogx's avatar
yoogx committed
45 46 47 48
with Ocarina.Instances;          use Ocarina.Instances;
with Ocarina.Parser;             use Ocarina.Parser;
with Ocarina.Options;            use Ocarina.Options;
with Ocarina.Files;              use Ocarina.Files;
49 50 51

package body Ocarina.Utils is

yoogx's avatar
yoogx committed
52
   AADL_Root             : Node_Id := No_Node;
53
   File_Name             : Name_Id := No_Name;
yoogx's avatar
yoogx committed
54
   Buffer                : Location;
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
   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
81

82 83 84 85 86 87 88 89 90
   ------------------
   -- 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
91
      Write_Line ("Load predefined property sets: "
yoogx's avatar
yoogx committed
92
                    & Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets'Img);
93 94
   end Print_Status;

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

129
   function Analyze return Boolean is
yoogx's avatar
yoogx committed
130 131 132 133 134 135 136 137
      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;
138
      return Success;
yoogx's avatar
yoogx committed
139 140
   end Analyze;

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
   ----------------------
   -- Set_REAL_Theorem --
   ----------------------

   function Set_REAL_Theorem (Theorem_Name : String) return Boolean is
   begin
      if Theorem_Name /= "" then
         Main_Theorem := To_Lower (Get_String_Name (Theorem_Name));
      end if;

      return True;
   end Set_REAL_Theorem;

   ----------------------
   -- Add_REAL_Library --
   ----------------------

   function Add_REAL_Library (Library_Name : String) return Boolean is
   begin
      if Library_Name /= "" then
         Write_Line ("Adding: " & Library_Name);
         Load_REAL_Library (Get_String_Name (Library_Name));
      end if;
      return True;
   end Add_REAL_Library;

yoogx's avatar
yoogx committed
167 168 169 170
   -----------------
   -- Instantiate --
   -----------------

yoogx's avatar
yoogx committed
171 172
   function Instantiate (Root_System : String) return Boolean is
      Success : Boolean;
yoogx's avatar
yoogx committed
173 174 175 176 177 178 179 180
   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");
yoogx's avatar
yoogx committed
181 182 183
         Success := True;
      else
         Success := False;
yoogx's avatar
yoogx committed
184
      end if;
yoogx's avatar
yoogx committed
185 186

      return Success;
yoogx's avatar
yoogx committed
187 188 189 190 191 192 193 194 195 196 197 198 199
   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;

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 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
   -------------------
   -- Get_AADL_Root --
   -------------------

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

   -----------------------------
   -- 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;

278
end Ocarina.Utils;