OpenAADL / ocarina
1
------------------------------------------------------------------------------
2
--                                                                          --
3
--                           OCARINA COMPONENTS                             --
4
--                                                                          --
5
--                        O C A R I N A . U T I L S                         --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--         Copyright (C) 2013-2019 ESA & ISAE, 2019-2020 OpenAADL           --
10
--                                                                          --
11
-- Ocarina  is free software; you can redistribute it and/or modify under   --
12
-- terms of the  GNU General Public License as published  by the Free Soft- --
13
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
15
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
16
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
17
--                                                                          --
18
-- As a special exception under Section 7 of GPL version 3, you are granted --
19
-- additional permissions described in the GCC Runtime Library Exception,   --
20
-- version 3.1, as published by the Free Software Foundation.               --
21
--                                                                          --
22
-- You should have received a copy of the GNU General Public License and    --
23
-- a copy of the GCC Runtime Library Exception along with this program;     --
24
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
27
--                    Ocarina is maintained by OpenAADL team                --
28
--                              (info@openaadl.org)                         --
29
--                                                                          --
30
------------------------------------------------------------------------------
31

32
with Errors;                     use Errors;
33
with Locations;                  use Locations;
34
with Ocarina.Namet;              use Ocarina.Namet;
35
with Ocarina.Output;             use Ocarina.Output;
36
with Utils;                      use Utils;
37

38
with Ocarina.Analyzer;           use Ocarina.Analyzer;
39
with Ocarina.Analyzer.REAL;      use Ocarina.Analyzer.REAL;
40
with Ocarina.Backends;           use Ocarina.Backends;
41
with Ocarina.Configuration;      use Ocarina.Configuration;
42
with Ocarina.FE_AADL;            use Ocarina.FE_AADL;
43
with Ocarina.FE_AADL.Parser;
44
with Ocarina.FE_REAL.Parser;     use Ocarina.FE_REAL.Parser;
45
with Ocarina.Instances;          use Ocarina.Instances;
46
with Ocarina.Parser;             use Ocarina.Parser;
47
with Ocarina.Options;            use Ocarina.Options;
48
with Ocarina.Files;              use Ocarina.Files;
49

50 1
package body Ocarina.Utils is
51

52
   AADL_Root             : Node_Id := No_Node;
53
   File_Name             : Name_Id := No_Name;
54 1
   Buffer                : Location;
55
   Language              : Name_Id := No_Name;
56

57
   -----------
58
   -- Reset --
59
   -----------
60

61 0
   procedure Reset is
62
   begin
63
      --  Reset Ocarina
64

65 0
      Ocarina.Configuration.Reset_Modules;
66 0
      Ocarina.Reset;
67

68
      --  Initialize Ocarina
69

70 0
      Ocarina.AADL_Version := Get_Default_AADL_Version;
71 0
      AADL_Version         := Ocarina.AADL_V2;
72 0
      Ocarina.Initialize;
73 0
      Ocarina.Configuration.Init_Modules;
74

75
      --  Reset library
76

77 0
      AADL_Root := No_Node;
78 0
      File_Name := No_Name;
79 0
      Language := No_Name;
80 0
   end Reset;
81

82
   ------------------
83
   -- Print_Status --
84
   ------------------
85

86 0
   procedure Print_Status is
87
   begin
88 0
      Write_Line ("AADL version: " & Ocarina.AADL_Version'Img);
89 0
      Write_Line ("Library Path: "
90 0
                    & Get_Name_String (Default_Library_Path));
91 0
      Write_Line ("Load predefined property sets: "
92 0
                    & Ocarina.FE_AADL.Parser.Add_Pre_Prop_Sets'Img);
93 0
   end Print_Status;
94

95
   --------------------
96
   -- Load_AADL_File --
97
   --------------------
98

99 1
   procedure Load_AADL_File (Filename : String) is
100
   begin
101 1
      Language := Get_String_Name ("aadl");
102 1
      Set_Str_To_Name_Buffer (Filename);
103

104 1
      File_Name := Search_File (Name_Find);
105 1
      if File_Name = No_Name then
106 1
         Write_Line ("Cannot find file " & Filename);
107 1
         return;
108
      end if;
109

110 0
      Buffer := Load_File (File_Name);
111 0
      if File_Name = No_Name then
112 0
         Write_Line ("Cannot read file " & Filename);
113 0
         return;
114
      end if;
115

116 0
      AADL_Root := Parse (Language, AADL_Root, Buffer);
117 0
      Exit_On_Error
118 0
        (No (AADL_Root),
119
         "Cannot parse AADL specifications");
120 0
      Write_Line
121
        ("File " & Filename
122 0
           & " loaded and parsed sucessfully");
123
   end Load_AADL_File;
124

125
   -------------
126
   -- Analyze --
127
   -------------
128

129 0
   function Analyze return Boolean is
130 0
      Success : Boolean;
131
   begin
132 0
      Success := Analyze (Language, AADL_Root);
133 0
      if not Success then
134 0
         Write_Line ("Cannot analyze AADL specifications");
135
      else
136 0
         Write_Line ("Model analyzed sucessfully");
137
      end if;
138 0
      return Success;
139
   end Analyze;
140

141
   ----------------------
142
   -- Set_REAL_Theorem --
143
   ----------------------
144

145 0
   function Set_REAL_Theorem (Theorem_Name : String) return Boolean is
146
   begin
147 0
      if Theorem_Name /= "" then
148 0
         Main_Theorem := To_Lower (Get_String_Name (Theorem_Name));
149
      end if;
150

151 0
      return True;
152
   end Set_REAL_Theorem;
153

154
   ----------------------
155
   -- Add_REAL_Library --
156
   ----------------------
157

158 0
   function Add_REAL_Library (Library_Name : String) return Boolean is
159
   begin
160 0
      if Library_Name /= "" then
161 0
         Write_Line ("Adding: " & Library_Name);
162 0
         Load_REAL_Library (Get_String_Name (Library_Name));
163
      end if;
164 0
      return True;
165
   end Add_REAL_Library;
166

167
   -----------------
168
   -- Instantiate --
169
   -----------------
170

171 0
   function Instantiate (Root_System : String) return Boolean is
172 0
      Success : Boolean;
173
   begin
174 0
      if Root_System /= "" then
175 0
         Root_System_Name := To_Lower
176 0
           (Get_String_Name (Root_System));
177
      end if;
178 0
      AADL_Root := Instantiate_Model (AADL_Root);
179 0
      if Present (AADL_Root) then
180 0
         Write_Line ("Model instantiated sucessfully");
181 0
         Success := True;
182
      else
183 0
         Success := False;
184
      end if;
185

186 0
      return Success;
187
   end Instantiate;
188

189
   --------------
190
   -- Generate --
191
   --------------
192

193 0
   procedure Generate (Backend_Name : String) is
194
   begin
195 0
      Set_Current_Backend_Name (Backend_Name);
196 0
      Write_Line ("Generating code using backend " & Backend_Name);
197 0
      Generate_Code (AADL_Root);
198 0
   end Generate;
199

200
   -------------------
201
   -- Get_AADL_Root --
202
   -------------------
203

204 0
   function Get_AADL_Root return Node_Id is
205
   begin
206 0
      return AADL_Root;
207
   end Get_AADL_Root;
208

209
   -----------------------------
210
   -- Get_Node_Id_From_String --
211
   -----------------------------
212

213 0
   function Get_Node_Id_From_String (Name : String) return Node_Id is
214
   begin
215 0
      return Node_Id (Integer'Value (Name));
216
   end Get_Node_Id_From_String;
217

218
   -----------------------------
219
   -- Get_List_Id_From_String --
220
   -----------------------------
221

222 0
   function Get_List_Id_From_String (Name : String) return List_Id is
223
   begin
224 0
      return List_Id (Integer'Value (Name));
225
   end Get_List_Id_From_String;
226

227
   -----------------------------
228
   -- Get_Boolean_From_String --
229
   -----------------------------
230

231 0
   function Get_Boolean_From_String (Name : String) return Boolean is
232
   begin
233 0
      return Boolean'Value (Name);
234
   end Get_Boolean_From_String;
235

236
   --------------------------
237
   -- Get_Byte_From_String --
238
   --------------------------
239

240 0
   function Get_Byte_From_String (Name : String) return Byte is
241
   begin
242 0
      return Byte (Integer'Value (Name));
243
   end Get_Byte_From_String;
244

245
   -------------------------
246
   -- Get_Int_From_String --
247
   -------------------------
248

249 0
   function Get_Int_From_String (Name : String) return Int is
250
   begin
251 0
      return Int (Integer'Value (Name));
252
   end Get_Int_From_String;
253

254
   ------------------------------
255
   -- Get_Value_Id_From_String --
256
   ------------------------------
257

258 0
   function Get_Value_Id_From_String (Name : String) return Value_Id is
259
   begin
260 0
      return Value_Id (Integer'Value (Name));
261
   end Get_Value_Id_From_String;
262

263
   -----------------------------
264
   -- Get_Name_Id_From_String --
265
   -----------------------------
266

267 0
   function Get_Name_Id_From_String (Name : String) return Name_Id is
268 0
      val : Integer;
269
   begin
270 0
      val := Integer'Value (Name);
271 0
      if val > 300_000_000 and then val < 399_999_999 then
272 0
         return Name_Id (val);
273
      else
274 0
         return No_Name;
275
      end if;
276
   end Get_Name_Id_From_String;
277

278 1
end Ocarina.Utils;

Read our documentation on viewing source code .

Loading