1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it 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. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 ------------------------------------------------------------------------------
23 -- Version shared by various Ada based back-ends (e.g. gnat2scil, gnat2why)
25 with System
.OS_Lib
; use System
.OS_Lib
;
27 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
29 package body Get_Targ
is
31 -----------------------
32 -- Get_Bits_Per_Unit --
33 -----------------------
35 function Get_Bits_Per_Unit
return Pos
is
38 end Get_Bits_Per_Unit
;
40 -----------------------
41 -- Get_Bits_Per_Word --
42 -----------------------
44 function Get_Bits_Per_Word
return Pos
is
47 end Get_Bits_Per_Word
;
53 function Get_Char_Size
return Pos
is
62 function Get_Wchar_T_Size
return Pos
is
71 function Get_Short_Size
return Pos
is
80 function Get_Int_Size
return Pos
is
89 function Get_Long_Size
return Pos
is
94 ------------------------
95 -- Get_Long_Long_Size --
96 ------------------------
98 function Get_Long_Long_Size
return Pos
is
101 end Get_Long_Long_Size
;
103 ----------------------
104 -- Get_Pointer_Size --
105 ----------------------
107 function Get_Pointer_Size
return Pos
is
110 end Get_Pointer_Size
;
112 ---------------------------
113 -- Get_Maximum_Alignment --
114 ---------------------------
116 function Get_Maximum_Alignment
return Pos
is
119 end Get_Maximum_Alignment
;
121 ------------------------------------
122 -- Get_System_Allocator_Alignment --
123 ------------------------------------
125 function Get_System_Allocator_Alignment
return Nat
is
128 end Get_System_Allocator_Alignment
;
130 ------------------------
131 -- Get_Float_Words_BE --
132 ------------------------
134 function Get_Float_Words_BE
return Nat
is
137 end Get_Float_Words_BE
;
143 function Get_Words_BE
return Nat
is
152 function Get_Bytes_BE
return Nat
is
161 function Get_Bits_BE
return Nat
is
166 ---------------------
167 -- Get_Short_Enums --
168 ---------------------
170 function Get_Short_Enums
return Int
is
175 --------------------------
176 -- Get_Strict_Alignment --
177 --------------------------
179 function Get_Strict_Alignment
return Nat
is
182 end Get_Strict_Alignment
;
184 --------------------------------
185 -- Get_Double_Float_Alignment --
186 --------------------------------
188 function Get_Double_Float_Alignment
return Nat
is
191 end Get_Double_Float_Alignment
;
193 ---------------------------------
194 -- Get_Double_Scalar_Alignment --
195 ---------------------------------
197 function Get_Double_Scalar_Alignment
return Nat
is
200 end Get_Double_Scalar_Alignment
;
202 -----------------------------
203 -- Get_Max_Unaligned_Field --
204 -----------------------------
206 function Get_Max_Unaligned_Field
return Pos
is
208 return 64; -- Can be different on some targets (e.g., AAMP)
209 end Get_Max_Unaligned_Field
;
211 ----------------------
212 -- Digits_From_Size --
213 ----------------------
215 function Digits_From_Size
(Size
: Pos
) return Pos
is
220 when 64 => return 15;
221 when 96 => return 18;
222 when 128 => return 18;
223 when others => raise Program_Error
;
225 end Digits_From_Size
;
227 -----------------------------
228 -- Register_Back_End_Types --
229 -----------------------------
231 procedure Register_Back_End_Types
(Call_Back
: Register_Type_Proc
) is
232 Float_Str
: C_String
:= (others => ASCII
.NUL
);
233 Double_Str
: C_String
:= (others => ASCII
.NUL
);
236 Float_Str
(Float_Str
'First .. Float_Str
'First + 4) := "float";
238 (C_Name
=> Float_Str
, Digs
=> 6, Complex
=> False, Count
=> 0,
239 Float_Rep
=> IEEE_Binary
,
240 Precision
=> 32, Size
=> 32, Alignment
=> 32);
242 Double_Str
(Double_Str
'First .. Double_Str
'First + 5) := "double";
244 (C_Name
=> Double_Str
,
248 Float_Rep
=> IEEE_Binary
,
252 end Register_Back_End_Types
;
254 ---------------------
255 -- Width_From_Size --
256 ---------------------
258 function Width_From_Size
(Size
: Pos
) return Pos
is
263 when 32 => return 11;
264 when 64 => return 21;
265 when others => raise Program_Error
;
269 ------------------------------
270 -- Get_Back_End_Config_File --
271 ------------------------------
273 function Get_Back_End_Config_File
return String_Ptr
is
275 function Exec_Name
return String;
276 -- Return name of the current executable (from argv[0])
278 function Get_Target_File
(Dir
: String) return String_Ptr
;
279 -- Return Dir & "target.atp" if found, null otherwise
285 function Exec_Name
return String is
286 type Arg_Array
is array (Nat
) of Big_String_Ptr
;
287 type Arg_Array_Ptr
is access all Arg_Array
;
289 gnat_argv
: Arg_Array_Ptr
;
290 pragma Import
(C
, gnat_argv
);
293 for J
in 1 .. Natural'Last loop
294 if gnat_argv
(0) (J
) = ASCII
.NUL
then
295 return gnat_argv
(0) (1 .. J
- 1);
302 ---------------------
303 -- Get_Target_File --
304 ---------------------
306 function Get_Target_File
(Dir
: String) return String_Ptr
is
307 F
: constant String := Dir
& "target.atp";
309 if Is_Regular_File
(F
) then
310 return new String'(F);
316 Exec : constant String := Exec_Name;
318 -- Start of processing for Get_Back_End_Config_File
321 if Is_Absolute_Path (Exec) then
322 return Get_Target_File (Dir_Name (Exec));
324 return Get_Target_File (Dir_Name (Locate_Exec_On_Path (Exec).all));
326 end Get_Back_End_Config_File;