1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Casing
; use Casing
;
27 with Fname
; use Fname
;
28 with Gnatvsn
; use Gnatvsn
;
30 with Namet
; use Namet
;
32 with Osint
; use Osint
;
33 with Osint
.B
; use Osint
.B
;
34 with Output
; use Output
;
35 with Rident
; use Rident
;
37 with Targparm
; use Targparm
;
38 with Types
; use Types
;
41 with System
.WCh_Con
; use System
.WCh_Con
;
43 with GNAT
.Heap_Sort_A
; use GNAT
.Heap_Sort_A
;
46 package body Bindgen
is
47 Statement_Buffer
: String (1 .. 1000);
48 -- Buffer used for constructing output statements
50 Stm_Last
: Natural := 0;
51 -- Stm_Last location in Statement_Buffer currently set
53 With_GNARL
: Boolean := False;
54 -- Flag which indicates whether the program uses the GNARL library
55 -- (presence of the unit System.OS_Interface)
57 Num_Elab_Calls
: Nat
:= 0;
58 -- Number of generated calls to elaboration routines
60 Num_Primary_Stacks
: Int
:= 0;
61 -- Number of default-sized primary stacks the binder needs to allocate for
62 -- task objects declared in the program.
64 Num_Sec_Stacks
: Int
:= 0;
65 -- Number of default-sized primary stacks the binder needs to allocate for
66 -- task objects declared in the program.
68 System_Restrictions_Used
: Boolean := False;
69 -- Flag indicating whether the unit System.Restrictions is in the closure
70 -- of the partition. This is set by Resolve_Binder_Options, and is used
71 -- to determine whether or not to initialize the restrictions information
72 -- in the body of the binder generated file (we do not want to do this
73 -- unconditionally, since it drags in the System.Restrictions unit
74 -- unconditionally, which is unpleasand, especially for ZFP etc.)
76 Dispatching_Domains_Used
: Boolean := False;
77 -- Flag indicating whether multiprocessor dispatching domains are used in
78 -- the closure of the partition. This is set by Resolve_Binder_Options, and
79 -- is used to call the routine to disallow the creation of new dispatching
80 -- domains just before calling the main procedure from the environment
83 System_Tasking_Restricted_Stages_Used
: Boolean := False;
84 -- Flag indicating whether the unit System.Tasking.Restricted.Stages is in
85 -- the closure of the partition. This is set by Resolve_Binder_Options,
86 -- and it used to call a routine to active all the tasks at the end of
87 -- the elaboration when partition elaboration policy is sequential.
89 System_Interrupts_Used
: Boolean := False;
90 -- Flag indicating whether the unit System.Interrups is in the closure of
91 -- the partition. This is set by Resolve_Binder_Options, and it used to
92 -- attach interrupt handlers at the end of the elaboration when partition
93 -- elaboration policy is sequential.
95 System_BB_CPU_Primitives_Multiprocessors_Used
: Boolean := False;
96 -- Flag indicating whether unit System.BB.CPU_Primitives.Multiprocessors
97 -- is in the closure of the partition. This is set by procedure
98 -- Resolve_Binder_Options, and it is used to call a procedure that starts
101 System_Version_Control_Used
: Boolean := False;
102 -- Flag indicating whether unit System.Version_Control is in the closure.
103 -- This unit is implicitly withed by the compiler when Version or
104 -- Body_Version attributes are used. If the package is not in the closure,
105 -- the version definitions can be removed.
107 Lib_Final_Built
: Boolean := False;
108 -- Flag indicating whether the finalize_library rountine has been built
110 Bind_Env_String_Built
: Boolean := False;
111 -- Flag indicating whether a bind environment string has been built
113 CodePeer_Wrapper_Name
: constant String := "call_main_subprogram";
114 -- For CodePeer, introduce a wrapper subprogram which calls the
115 -- user-defined main subprogram.
117 -- Name for local C-String variable
119 Adainit_String_Obj_Name
: constant String := "Adainit_Name_C_String";
121 -- Name and link_name for CUDA device initialization procedure
123 Device_Ada_Init_Subp_Name
: constant String := "Device_Initialization";
124 Device_Link_Name_Prefix
: constant String := "__device_";
126 function Device_Link_Name
(Suffix
: String) return String is
127 (Device_Link_Name_Prefix
&
128 (if CUDA_Device_Library_Name
= null
129 then "ada" -- is this an error path?
130 else CUDA_Device_Library_Name
.all) & Suffix
);
132 function Device_Ada_Init_Link_Name
return String
133 is (Device_Link_Name
(Suffix
=> "init"));
135 ----------------------------------
136 -- Interface_State Pragma Table --
137 ----------------------------------
139 -- This table assembles the interface state pragma information from
140 -- all the units in the partition. Note that Bcheck has already checked
141 -- that the information is consistent across units. The entries
142 -- in this table are n/u/r/s for not set/user/runtime/system.
144 package IS_Pragma_Settings
is new Table
.Table
145 (Table_Component_Type
=> Character,
146 Table_Index_Type
=> Int
,
147 Table_Low_Bound
=> 0,
148 Table_Initial
=> 100,
149 Table_Increment
=> 200,
150 Table_Name
=> "IS_Pragma_Settings");
152 -- This table assembles the Priority_Specific_Dispatching pragma
153 -- information from all the units in the partition. Note that Bcheck has
154 -- already checked that the information is consistent across units.
155 -- The entries in this table are the upper case first character of the
156 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
158 package PSD_Pragma_Settings
is new Table
.Table
159 (Table_Component_Type
=> Character,
160 Table_Index_Type
=> Int
,
161 Table_Low_Bound
=> 0,
162 Table_Initial
=> 100,
163 Table_Increment
=> 200,
164 Table_Name
=> "PSD_Pragma_Settings");
166 ----------------------------
167 -- Bind_Environment Table --
168 ----------------------------
170 subtype Header_Num
is Int
range 0 .. 36;
172 function Hash
(Nam
: Name_Id
) return Header_Num
;
174 package Bind_Environment
is new GNAT
.HTable
.Simple_HTable
175 (Header_Num
=> Header_Num
,
177 No_Element
=> No_Name
,
182 ----------------------
183 -- Run-Time Globals --
184 ----------------------
186 -- This section documents the global variables that are set from the
187 -- generated binder file.
189 -- Main_Priority : Integer;
190 -- Time_Slice_Value : Integer;
191 -- Heap_Size : Natural;
192 -- WC_Encoding : Character;
193 -- Locking_Policy : Character;
194 -- Queuing_Policy : Character;
195 -- Task_Dispatching_Policy : Character;
196 -- Priority_Specific_Dispatching : System.Address;
197 -- Num_Specific_Dispatching : Integer;
198 -- Restrictions : System.Address;
199 -- Interrupt_States : System.Address;
200 -- Num_Interrupt_States : Integer;
201 -- Unreserve_All_Interrupts : Integer;
202 -- Exception_Tracebacks : Integer;
203 -- Exception_Tracebacks_Symbolic : Integer;
204 -- Detect_Blocking : Integer;
205 -- Default_Stack_Size : Integer;
206 -- Default_Secondary_Stack_Size : System.Parameters.Size_Type;
207 -- Leap_Seconds_Support : Integer;
208 -- Main_CPU : Integer;
209 -- Default_Sized_SS_Pool : System.Address;
210 -- Binder_Sec_Stacks_Count : Natural;
211 -- XDR_Stream : Integer;
213 -- Main_Priority is the priority value set by pragma Priority in the main
214 -- program. If no such pragma is present, the value is -1.
216 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
217 -- main program, or by the use of a -Tnnn parameter for the binder (if both
218 -- are present, the binder value overrides). The value is in milliseconds.
219 -- A value of zero indicates that time slicing should be suppressed. If no
220 -- pragma is present, and no -T switch was used, the value is -1.
222 -- WC_Encoding shows the wide character encoding method used for the main
223 -- program. This is one of the encoding letters defined in
224 -- System.WCh_Con.WC_Encoding_Letters.
226 -- Locking_Policy is a space if no locking policy was specified for the
227 -- partition. If a locking policy was specified, the value is the upper
228 -- case first character of the locking policy name, for example, 'C' for
231 -- Queuing_Policy is a space if no queuing policy was specified for the
232 -- partition. If a queuing policy was specified, the value is the upper
233 -- case first character of the queuing policy name for example, 'F' for
236 -- Task_Dispatching_Policy is a space if no task dispatching policy was
237 -- specified for the partition. If a task dispatching policy was specified,
238 -- the value is the upper case first character of the policy name, e.g. 'F'
239 -- for FIFO_Within_Priorities.
241 -- Priority_Specific_Dispatching is the address of a string used to store
242 -- the task dispatching policy specified for the different priorities in
243 -- the partition. The length of this string is determined by the last
244 -- priority for which such a pragma applies (the string will be a null
245 -- string if no specific dispatching policies were used). If pragma were
246 -- present, the entries apply to the priorities in sequence from the first
247 -- priority. The value stored is the upper case first character of the
248 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
249 -- for those priority ranges not specified.
251 -- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
252 -- string. It will be set to zero if no Priority_Specific_Dispatching
253 -- pragmas are present.
255 -- Restrictions is the address of a null-terminated string specifying the
256 -- restrictions information for the partition. The format is identical to
257 -- that of the parameter string found on R lines in ali files (see Lib.Writ
258 -- spec in lib-writ.ads for full details). The difference is that in this
259 -- context the values are the cumulative ones for the entire partition.
261 -- Interrupt_States is the address of a string used to specify the
262 -- cumulative results of Interrupt_State pragmas used in the partition.
263 -- The length of this string is determined by the last interrupt for which
264 -- such a pragma is given (the string will be a null string if no pragmas
265 -- were used). If pragma were present the entries apply to the interrupts
266 -- in sequence from the first interrupt, and are set to one of four
267 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
268 -- time, 's' for system, see description of Interrupt_State pragma for
271 -- Num_Interrupt_States is the length of the Interrupt_States string. It
272 -- will be set to zero if no Interrupt_State pragmas are present.
274 -- Unreserve_All_Interrupts is set to one if at least one unit in the
275 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
277 -- Exception_Tracebacks is set to one if the -Ea or -E parameter was
278 -- present in the bind and to zero otherwise. Note that on some targets
279 -- exception tracebacks are provided by default, so a value of zero for
280 -- this parameter does not necessarily mean no trace backs are available.
282 -- Exception_Tracebacks_Symbolic is set to one if the -Es parameter was
283 -- present in the bind and to zero otherwise.
285 -- Detect_Blocking indicates whether pragma Detect_Blocking is active or
286 -- not. A value of zero indicates that the pragma is not present, while a
287 -- value of 1 signals its presence in the partition.
289 -- Default_Stack_Size is the default stack size used when creating an Ada
290 -- task with no explicit Storage_Size clause.
292 -- Default_Secondary_Stack_Size is the default secondary stack size used
293 -- when creating an Ada task with no explicit Secondary_Stack_Size clause.
295 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
296 -- disabled. A value of zero indicates that leap seconds are turned "off",
297 -- while a value of one signifies "on" status.
299 -- Main_CPU is the processor set by pragma CPU in the main program. If no
300 -- such pragma is present, the value is -1.
302 -- Default_Sized_SS_Pool is set to the address of the default-sized
303 -- secondary stacks array generated by the binder. This pool of stacks is
304 -- generated when either the restriction No_Implicit_Heap_Allocations
305 -- or No_Implicit_Task_Allocations is active.
307 -- Binder_Sec_Stacks_Count is the number of generated secondary stacks in
308 -- the Default_Sized_SS_Pool.
310 -- XDR_Stream indicates whether streaming should be performed using the
311 -- XDR protocol. A value of one indicates that XDR streaming is enabled.
313 procedure WBI
(Info
: String) renames Osint
.B
.Write_Binder_Info
;
314 -- Convenient shorthand used throughout
316 -----------------------
317 -- Local Subprograms --
318 -----------------------
320 procedure Gen_Adainit
(Elab_Order
: Unit_Id_Array
);
321 -- Generates the Adainit procedure
323 procedure Gen_Adafinal
;
324 -- Generate the Adafinal procedure
326 procedure Gen_Bind_Env_String
;
327 -- Generate the bind environment buffer
329 procedure Gen_CodePeer_Wrapper
;
330 -- For CodePeer, generate wrapper which calls user-defined main subprogram
332 procedure Gen_CUDA_Defs
;
333 -- Generate definitions needed in order to register kernels
335 procedure Gen_CUDA_Init
;
336 -- Generate calls needed in order to register kernels
338 procedure Gen_Elab_Calls
(Elab_Order
: Unit_Id_Array
);
339 -- Generate sequence of elaboration calls
341 procedure Gen_Elab_Externals
(Elab_Order
: Unit_Id_Array
);
342 -- Generate sequence of external declarations for elaboration
344 procedure Gen_Elab_Order
(Elab_Order
: Unit_Id_Array
);
345 -- Generate comments showing elaboration order chosen
347 procedure Gen_Finalize_Library
(Elab_Order
: Unit_Id_Array
);
348 -- Generate a sequence of finalization calls to elaborated packages
351 -- Generate procedure main
353 procedure Gen_Object_Files_Options
(Elab_Order
: Unit_Id_Array
);
354 -- Output comments containing a list of the full names of the object
355 -- files to be linked and the list of linker options supplied by
356 -- Linker_Options pragmas in the source.
358 procedure Gen_Output_File_Ada
360 Elab_Order
: Unit_Id_Array
);
361 -- Generate Ada output file
363 procedure Gen_Restrictions
;
364 -- Generate initialization of restrictions variable
366 procedure Gen_Versions
;
367 -- Output series of definitions for unit versions
369 function Get_Ada_Main_Name
return String;
370 -- This function is used for the Ada main output to compute a usable name
371 -- for the generated main program. The normal main program name is
372 -- Ada_Main, but this won't work if the user has a unit with this name.
373 -- This function tries Ada_Main first, and if there is such a clash, then
374 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
376 function Get_Main_Unit_Name
(S
: String) return String;
377 -- Return the main unit name corresponding to S by replacing '.' with '_'
379 function Get_Main_Name
return String;
380 -- This function is used in the main output case to compute the correct
381 -- external main program. It is "main" by default, unless the flag
382 -- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
383 -- of the Ada main name without the "_ada". This default can be overridden
384 -- explicitly using the -Mname binder switch.
386 function Get_WC_Encoding
return Character;
387 -- Return wide character encoding method to set as WC_Encoding in output.
388 -- If -W has been used, returns the specified encoding, otherwise returns
389 -- the encoding method used for the main program source. If there is no
390 -- main program source (-z switch used), returns brackets ('b').
392 function Has_Finalizer
(Elab_Order
: Unit_Id_Array
) return Boolean;
393 -- Determine whether the current unit has at least one library-level
396 function Lt_Linker_Option
(Op1
: Natural; Op2
: Natural) return Boolean;
397 -- Compare linker options, when sorting, first according to
398 -- Is_Internal_File (internal files come later) and then by
399 -- elaboration order position (latest to earliest).
401 procedure Move_Linker_Option
(From
: Natural; To
: Natural);
402 -- Move routine for sorting linker options
404 procedure Resolve_Binder_Options
(Elab_Order
: Unit_Id_Array
);
405 -- Set the value of With_GNARL
407 procedure Set_Char
(C
: Character);
408 -- Set given character in Statement_Buffer at the Stm_Last + 1 position
409 -- and increment Stm_Last by one to reflect the stored character.
411 procedure Set_Int
(N
: Int
);
412 -- Set given value in decimal in Statement_Buffer with no spaces starting
413 -- at the Stm_Last + 1 position, and updating Stm_Last past the value. A
414 -- minus sign is output for a negative value.
416 procedure Set_Boolean
(B
: Boolean);
417 -- Set given boolean value in Statement_Buffer at the Stm_Last + 1 position
418 -- and update Stm_Last past the value.
420 procedure Set_IS_Pragma_Table
;
421 -- Initializes contents of IS_Pragma_Settings table from ALI table
423 procedure Set_Main_Program_Name
;
424 -- Given the main program name in Name_Buffer (length in Name_Len) generate
425 -- the name of the routine to be used in the call. The name is generated
426 -- starting at Stm_Last + 1, and Stm_Last is updated past it.
428 procedure Set_Name_Buffer
;
429 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
431 procedure Set_PSD_Pragma_Table
;
432 -- Initializes contents of PSD_Pragma_Settings table from ALI table
434 procedure Set_String
(S
: String);
435 -- Sets characters of given string in Statement_Buffer, starting at the
436 -- Stm_Last + 1 position, and updating last past the string value.
438 procedure Set_String_Replace
(S
: String);
439 -- Replaces the last S'Length characters in the Statement_Buffer with the
440 -- characters of S. The caller must ensure that these characters do in fact
441 -- exist in the Statement_Buffer.
443 procedure Set_Unit_Name
;
444 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
445 -- starting at the Stm_Last + 1 position and update Stm_Last past the
446 -- value. Each dot (.) will be qualified into double underscores (__).
448 procedure Set_Unit_Number
(U
: Unit_Id
);
449 -- Sets unit number (first unit is 1, leading zeroes output to line up all
450 -- output unit numbers nicely as required by the value, and by the total
453 procedure Write_Statement_Buffer
;
454 -- Write out contents of statement buffer up to Stm_Last, and reset
457 procedure Write_Statement_Buffer
(S
: String);
458 -- First writes its argument (using Set_String (S)), then writes out the
459 -- contents of statement buffer up to Stm_Last, and resets Stm_Last to 0.
461 procedure Write_Bind_Line
(S
: String);
462 -- Write S (an LF-terminated string) to the binder file (for use with
463 -- Set_Special_Output).
469 procedure Gen_Adafinal
is
471 WBI
(" procedure " & Ada_Final_Name
.all & " is");
473 -- Call s_stalib_adafinal to await termination of tasks and so on. We
474 -- want to do this if there is a main program, either in Ada or in some
475 -- other language. (Note that Bind_Main_Program is True for Ada mains,
476 -- but False for mains in other languages.) We do not want to do this if
477 -- we're binding a library.
479 if not Bind_For_Library
and not CodePeer_Mode
then
480 WBI
(" procedure s_stalib_adafinal;");
481 Set_String
(" pragma Import (Ada, s_stalib_adafinal, ");
482 Set_String
("""system__standard_library__adafinal"");");
483 Write_Statement_Buffer
;
487 WBI
(" procedure Runtime_Finalize;");
488 WBI
(" pragma Import (C, Runtime_Finalize, " &
489 """__gnat_runtime_finalize"");");
493 if not CodePeer_Mode
then
494 WBI
(" if not Is_Elaborated then");
497 WBI
(" Is_Elaborated := False;");
500 WBI
(" Runtime_Finalize;");
502 -- By default (real targets), finalization is done differently depending
503 -- on whether this is the main program or a library.
505 if not CodePeer_Mode
then
506 if not Bind_For_Library
then
507 WBI
(" s_stalib_adafinal;");
508 elsif Lib_Final_Built
then
509 WBI
(" finalize_library;");
514 -- Pragma Import C cannot be used on virtual targets, therefore call the
515 -- runtime finalization routine directly in CodePeer mode, where
516 -- imported functions are ignored.
519 WBI
(" System.Standard_Library.Adafinal;");
522 WBI
(" end " & Ada_Final_Name
.all & ";");
530 procedure Gen_Adainit
(Elab_Order
: Unit_Id_Array
) is
531 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
532 Main_CPU
: Int
renames ALIs
.Table
(ALIs
.First
).Main_CPU
;
534 -- Declare the access-to-subprogram type used for initialization of
535 -- of __gnat_finalize_library_objects. This is declared at library
536 -- level for compatibility with the type used in System.Soft_Links.
537 -- The import of the soft link which performs library-level object
538 -- finalization does not work for CodePeer, so regular Ada is used in
539 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
540 -- tasks are non-terminating, so we do not want finalization.
542 if not Suppress_Standard_Library_On_Target
543 and then not CodePeer_Mode
544 and then not Configurable_Run_Time_On_Target
546 WBI
(" type No_Param_Proc is access procedure;");
547 WBI
(" pragma Favor_Top_Level (No_Param_Proc);");
551 WBI
(" procedure " & Ada_Init_Name
.all & " is");
553 -- In CodePeer mode, simplify adainit procedure by only calling
554 -- elaboration procedures.
556 if CodePeer_Mode
then
559 -- If the standard library is suppressed, then the only global variables
560 -- that might be needed (by the Ravenscar profile) are the priority and
561 -- the processor for the environment task.
563 elsif Suppress_Standard_Library_On_Target
then
564 if Main_Priority
/= No_Main_Priority
then
565 WBI
(" Main_Priority : Integer;");
566 WBI
(" pragma Import (C, Main_Priority," &
567 " ""__gl_main_priority"");");
571 if Main_CPU
/= No_Main_CPU
then
572 WBI
(" Main_CPU : Integer;");
573 WBI
(" pragma Import (C, Main_CPU," &
574 " ""__gl_main_cpu"");");
578 if System_Interrupts_Used
579 and then Partition_Elaboration_Policy_Specified
= 'S'
581 WBI
(" procedure Install_Restricted_Handlers_Sequential;");
582 WBI
(" pragma Import (C," &
583 "Install_Restricted_Handlers_Sequential," &
584 " ""__gnat_attach_all_handlers"");");
588 if System_Tasking_Restricted_Stages_Used
589 and then Partition_Elaboration_Policy_Specified
= 'S'
591 WBI
(" Partition_Elaboration_Policy : Character;");
592 WBI
(" pragma Import (C, Partition_Elaboration_Policy," &
593 " ""__gnat_partition_elaboration_policy"");");
595 WBI
(" procedure Activate_All_Tasks_Sequential;");
596 WBI
(" pragma Import (C, Activate_All_Tasks_Sequential," &
597 " ""__gnat_activate_all_tasks"");");
601 if System_BB_CPU_Primitives_Multiprocessors_Used
then
602 WBI
(" procedure Start_Slave_CPUs;");
603 WBI
(" pragma Import (C, Start_Slave_CPUs," &
604 " ""__gnat_start_slave_cpus"");");
608 -- Import the default stack object if a size has been provided to the
611 if Opt
.Default_Stack_Size
/= Opt
.No_Stack_Size
then
612 WBI
(" Default_Stack_Size : Integer;");
613 WBI
(" pragma Import (C, Default_Stack_Size, " &
614 """__gl_default_stack_size"");");
617 -- Initialize stack limit variable of the environment task if the
618 -- stack check method is stack limit and stack check is enabled.
620 if Stack_Check_Limits_On_Target
621 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
624 WBI
(" procedure Initialize_Stack_Limit;");
625 WBI
(" pragma Import (C, Initialize_Stack_Limit, " &
626 """__gnat_initialize_stack_limit"");");
629 if Num_Sec_Stacks
> 0 then
630 WBI
(" Binder_Sec_Stacks_Count : Natural;");
631 WBI
(" pragma Import (Ada, Binder_Sec_Stacks_Count, " &
632 """__gnat_binder_ss_count"");");
636 -- Import secondary stack pool variables if the secondary stack is
637 -- used. They are not referenced otherwise.
639 if Sec_Stack_Used
then
640 WBI
(" Default_Secondary_Stack_Size : " &
641 "System.Parameters.Size_Type;");
642 WBI
(" pragma Import (C, Default_Secondary_Stack_Size, " &
643 """__gnat_default_ss_size"");");
645 WBI
(" Default_Sized_SS_Pool : System.Address;");
646 WBI
(" pragma Import (Ada, Default_Sized_SS_Pool, " &
647 """__gnat_default_ss_pool"");");
654 -- Set the default stack size if provided to the binder
656 if Opt
.Default_Stack_Size
/= Opt
.No_Stack_Size
then
657 Set_String
(" Default_Stack_Size := ");
658 Set_Int
(Default_Stack_Size
);
660 Write_Statement_Buffer
;
663 if Main_Priority
/= No_Main_Priority
then
664 Set_String
(" Main_Priority := ");
665 Set_Int
(Main_Priority
);
667 Write_Statement_Buffer
;
670 if Main_CPU
/= No_Main_CPU
then
671 Set_String
(" Main_CPU := ");
674 Write_Statement_Buffer
;
677 if System_Tasking_Restricted_Stages_Used
678 and then Partition_Elaboration_Policy_Specified
= 'S'
680 Set_String
(" Partition_Elaboration_Policy := '");
681 Set_Char
(Partition_Elaboration_Policy_Specified
);
683 Write_Statement_Buffer
;
686 if Main_Priority
= No_Main_Priority
687 and then Opt
.Default_Stack_Size
= Opt
.No_Stack_Size
688 and then Main_CPU
= No_Main_CPU
689 and then not System_Tasking_Restricted_Stages_Used
694 -- Generate the default-sized secondary stack pool if the secondary
695 -- stack is used by the program.
697 if Sec_Stack_Used
then
698 -- Elaborate the body of the binder to initialize the default-
699 -- sized secondary stack pool.
702 WBI
(" " & Get_Ada_Main_Name
& "'Elab_Body;");
704 -- Generate the default-sized secondary stack pool and set the
705 -- related secondary stack globals.
707 Set_String
(" Default_Secondary_Stack_Size := ");
709 if Opt
.Default_Sec_Stack_Size
/= Opt
.No_Stack_Size
then
710 Set_Int
(Opt
.Default_Sec_Stack_Size
);
713 ("System.Parameters.Runtime_Default_Sec_Stack_Size");
717 Write_Statement_Buffer
;
719 Set_String
(" Binder_Sec_Stacks_Count := ");
720 Set_Int
(Num_Sec_Stacks
);
722 Write_Statement_Buffer
;
724 WBI
(" Default_Sized_SS_Pool := " &
725 "Sec_Default_Sized_Stacks'Address;");
729 -- Normal case (standard library not suppressed). Set all global values
730 -- used by the run time.
733 WBI
(" Main_Priority : Integer;");
734 WBI
(" pragma Import (C, Main_Priority, " &
735 """__gl_main_priority"");");
736 WBI
(" Time_Slice_Value : Integer;");
737 WBI
(" pragma Import (C, Time_Slice_Value, " &
738 """__gl_time_slice_val"");");
739 WBI
(" WC_Encoding : Character;");
740 WBI
(" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
741 WBI
(" Locking_Policy : Character;");
742 WBI
(" pragma Import (C, Locking_Policy, " &
743 """__gl_locking_policy"");");
744 WBI
(" Queuing_Policy : Character;");
745 WBI
(" pragma Import (C, Queuing_Policy, " &
746 """__gl_queuing_policy"");");
747 WBI
(" Task_Dispatching_Policy : Character;");
748 WBI
(" pragma Import (C, Task_Dispatching_Policy, " &
749 """__gl_task_dispatching_policy"");");
750 WBI
(" Priority_Specific_Dispatching : System.Address;");
751 WBI
(" pragma Import (C, Priority_Specific_Dispatching, " &
752 """__gl_priority_specific_dispatching"");");
753 WBI
(" Num_Specific_Dispatching : Integer;");
754 WBI
(" pragma Import (C, Num_Specific_Dispatching, " &
755 """__gl_num_specific_dispatching"");");
756 WBI
(" Main_CPU : Integer;");
757 WBI
(" pragma Import (C, Main_CPU, " &
758 """__gl_main_cpu"");");
760 WBI
(" Interrupt_States : System.Address;");
761 WBI
(" pragma Import (C, Interrupt_States, " &
762 """__gl_interrupt_states"");");
763 WBI
(" Num_Interrupt_States : Integer;");
764 WBI
(" pragma Import (C, Num_Interrupt_States, " &
765 """__gl_num_interrupt_states"");");
766 WBI
(" Unreserve_All_Interrupts : Integer;");
767 WBI
(" pragma Import (C, Unreserve_All_Interrupts, " &
768 """__gl_unreserve_all_interrupts"");");
770 if Exception_Tracebacks
or Exception_Tracebacks_Symbolic
then
771 WBI
(" Exception_Tracebacks : Integer;");
772 WBI
(" pragma Import (C, Exception_Tracebacks, " &
773 """__gl_exception_tracebacks"");");
775 if Exception_Tracebacks_Symbolic
then
776 WBI
(" Exception_Tracebacks_Symbolic : Integer;");
777 WBI
(" pragma Import (C, Exception_Tracebacks_Symbolic, " &
778 """__gl_exception_tracebacks_symbolic"");");
782 WBI
(" Detect_Blocking : Integer;");
783 WBI
(" pragma Import (C, Detect_Blocking, " &
784 """__gl_detect_blocking"");");
785 WBI
(" Default_Stack_Size : Integer;");
786 WBI
(" pragma Import (C, Default_Stack_Size, " &
787 """__gl_default_stack_size"");");
789 if Sec_Stack_Used
then
790 WBI
(" Default_Secondary_Stack_Size : " &
791 "System.Parameters.Size_Type;");
792 WBI
(" pragma Import (C, Default_Secondary_Stack_Size, " &
793 """__gnat_default_ss_size"");");
796 if Leap_Seconds_Support
then
797 WBI
(" Leap_Seconds_Support : Integer;");
798 WBI
(" pragma Import (C, Leap_Seconds_Support, " &
799 """__gl_leap_seconds_support"");");
802 WBI
(" Bind_Env_Addr : System.Address;");
803 WBI
(" pragma Import (C, Bind_Env_Addr, " &
804 """__gl_bind_env_addr"");");
807 WBI
(" XDR_Stream : Integer;");
808 WBI
(" pragma Import (C, XDR_Stream, ""__gl_xdr_stream"");");
811 -- Import entry point for elaboration time signal handler
812 -- installation, and indication of if it's been called previously.
815 WBI
(" procedure Runtime_Initialize " &
816 "(Install_Handler : Integer);");
817 WBI
(" pragma Import (C, Runtime_Initialize, " &
818 """__gnat_runtime_initialize"");");
820 -- Import handlers attach procedure for sequential elaboration policy
822 if System_Interrupts_Used
823 and then Partition_Elaboration_Policy_Specified
= 'S'
825 WBI
(" procedure Install_Restricted_Handlers_Sequential;");
826 WBI
(" pragma Import (C," &
827 "Install_Restricted_Handlers_Sequential," &
828 " ""__gnat_attach_all_handlers"");");
832 -- Import task activation procedure for sequential elaboration
835 if System_Tasking_Restricted_Stages_Used
836 and then Partition_Elaboration_Policy_Specified
= 'S'
838 WBI
(" Partition_Elaboration_Policy : Character;");
839 WBI
(" pragma Import (C, Partition_Elaboration_Policy," &
840 " ""__gnat_partition_elaboration_policy"");");
842 WBI
(" procedure Activate_All_Tasks_Sequential;");
843 WBI
(" pragma Import (C, Activate_All_Tasks_Sequential," &
844 " ""__gnat_activate_all_tasks"");");
847 -- Import procedure to start slave cpus for bareboard runtime
849 if System_BB_CPU_Primitives_Multiprocessors_Used
then
850 WBI
(" procedure Start_Slave_CPUs;");
851 WBI
(" pragma Import (C, Start_Slave_CPUs," &
852 " ""__gnat_start_slave_cpus"");");
855 -- For restricted run-time libraries (ZFP and Ravenscar)
856 -- tasks are non-terminating, so we do not want finalization.
858 if not Configurable_Run_Time_On_Target
then
860 WBI
(" Finalize_Library_Objects : No_Param_Proc;");
861 WBI
(" pragma Import (C, Finalize_Library_Objects, " &
862 """__gnat_finalize_library_objects"");");
865 -- Initialize stack limit variable of the environment task if the
866 -- stack check method is stack limit and stack check is enabled.
868 if Stack_Check_Limits_On_Target
869 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
872 WBI
(" procedure Initialize_Stack_Limit;");
873 WBI
(" pragma Import (C, Initialize_Stack_Limit, " &
874 """__gnat_initialize_stack_limit"");");
877 -- When dispatching domains are used then we need to signal it
878 -- before calling the main procedure.
880 if Dispatching_Domains_Used
then
881 WBI
(" procedure Freeze_Dispatching_Domains;");
882 WBI
(" pragma Import");
883 WBI
(" (Ada, Freeze_Dispatching_Domains, "
884 & """__gnat_freeze_dispatching_domains"");");
887 -- Secondary stack global variables
889 WBI
(" Binder_Sec_Stacks_Count : Natural;");
890 WBI
(" pragma Import (Ada, Binder_Sec_Stacks_Count, " &
891 """__gnat_binder_ss_count"");");
893 WBI
(" Default_Sized_SS_Pool : System.Address;");
894 WBI
(" pragma Import (Ada, Default_Sized_SS_Pool, " &
895 """__gnat_default_ss_pool"");");
899 -- Start of processing for Adainit
902 WBI
(" if Is_Elaborated then");
905 WBI
(" Is_Elaborated := True;");
907 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
908 -- restriction No_Standard_Allocators_After_Elaboration is active.
910 if Cumulative_Restrictions
.Set
911 (No_Standard_Allocators_After_Elaboration
)
913 WBI
(" System.Elaboration_Allocators."
914 & "Mark_Start_Of_Elaboration;");
917 -- Generate assignments to initialize globals
919 Set_String
(" Main_Priority := ");
920 Set_Int
(Main_Priority
);
922 Write_Statement_Buffer
;
924 Set_String
(" Time_Slice_Value := ");
926 if Task_Dispatching_Policy_Specified
= 'F'
927 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
931 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
935 Write_Statement_Buffer
;
937 Set_String
(" WC_Encoding := '");
938 Set_Char
(Get_WC_Encoding
);
941 Write_Statement_Buffer
;
943 Set_String
(" Locking_Policy := '");
944 Set_Char
(Locking_Policy_Specified
);
946 Write_Statement_Buffer
;
948 Set_String
(" Queuing_Policy := '");
949 Set_Char
(Queuing_Policy_Specified
);
951 Write_Statement_Buffer
;
953 Set_String
(" Task_Dispatching_Policy := '");
954 Set_Char
(Task_Dispatching_Policy_Specified
);
956 Write_Statement_Buffer
;
958 if System_Tasking_Restricted_Stages_Used
959 and then Partition_Elaboration_Policy_Specified
= 'S'
961 Set_String
(" Partition_Elaboration_Policy := '");
962 Set_Char
(Partition_Elaboration_Policy_Specified
);
964 Write_Statement_Buffer
;
969 WBI
(" Priority_Specific_Dispatching :=");
970 WBI
(" Local_Priority_Specific_Dispatching'Address;");
972 Set_String
(" Num_Specific_Dispatching := ");
973 Set_Int
(PSD_Pragma_Settings
.Last
+ 1);
975 Write_Statement_Buffer
;
977 Set_String
(" Main_CPU := ");
980 Write_Statement_Buffer
;
982 WBI
(" Interrupt_States := Local_Interrupt_States'Address;");
984 Set_String
(" Num_Interrupt_States := ");
985 Set_Int
(IS_Pragma_Settings
.Last
+ 1);
987 Write_Statement_Buffer
;
989 Set_String
(" Unreserve_All_Interrupts := ");
991 if Unreserve_All_Interrupts_Specified
then
998 Write_Statement_Buffer
;
1000 if Exception_Tracebacks
or Exception_Tracebacks_Symbolic
then
1001 WBI
(" Exception_Tracebacks := 1;");
1003 if Exception_Tracebacks_Symbolic
then
1004 WBI
(" Exception_Tracebacks_Symbolic := 1;");
1008 Set_String
(" Detect_Blocking := ");
1010 if Detect_Blocking
then
1017 Write_Statement_Buffer
;
1019 Set_String
(" Default_Stack_Size := ");
1020 Set_Int
(Default_Stack_Size
);
1022 Write_Statement_Buffer
;
1024 if Leap_Seconds_Support
then
1025 WBI
(" Leap_Seconds_Support := 1;");
1029 WBI
(" XDR_Stream := 1;");
1032 if Bind_Env_String_Built
then
1033 WBI
(" Bind_Env_Addr := Bind_Env'Address;");
1038 -- Generate default-sized secondary stack pool and set secondary
1041 if Sec_Stack_Used
then
1043 -- Elaborate the body of the binder to initialize the default-
1044 -- sized secondary stack pool.
1046 WBI
(" " & Get_Ada_Main_Name
& "'Elab_Body;");
1048 -- Generate the default-sized secondary stack pool and set the
1049 -- related secondary stack globals.
1051 Set_String
(" Default_Secondary_Stack_Size := ");
1053 if Opt
.Default_Sec_Stack_Size
/= Opt
.No_Stack_Size
then
1054 Set_Int
(Opt
.Default_Sec_Stack_Size
);
1056 Set_String
("System.Parameters.Runtime_Default_Sec_Stack_Size");
1060 Write_Statement_Buffer
;
1062 Set_String
(" Binder_Sec_Stacks_Count := ");
1063 Set_Int
(Num_Sec_Stacks
);
1065 Write_Statement_Buffer
;
1067 Set_String
(" Default_Sized_SS_Pool := ");
1069 if Num_Sec_Stacks
> 0 then
1070 Set_String
("Sec_Default_Sized_Stacks'Address;");
1072 Set_String
("System.Null_Address;");
1075 Write_Statement_Buffer
;
1079 -- Generate call to Runtime_Initialize
1081 WBI
(" Runtime_Initialize (1);");
1084 -- Generate call to set Initialize_Scalar values if active
1086 if Initialize_Scalars_Used
then
1088 Set_String
(" System.Scalar_Values.Initialize ('");
1089 Set_Char
(Initialize_Scalars_Mode1
);
1090 Set_String
("', '");
1091 Set_Char
(Initialize_Scalars_Mode2
);
1093 Write_Statement_Buffer
;
1096 -- Initialize stack limit variable of the environment task if the stack
1097 -- check method is stack limit and stack check is enabled.
1099 if Stack_Check_Limits_On_Target
1100 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
1103 WBI
(" Initialize_Stack_Limit;");
1106 -- On CodePeer, the finalization of library objects is not relevant
1108 if CodePeer_Mode
then
1111 -- If this is the main program case, attach finalize_library to the soft
1112 -- link. Do it only when not using a restricted run time, in which case
1113 -- tasks are non-terminating, so we do not want library-level
1116 elsif not Bind_For_Library
1117 and then not Configurable_Run_Time_On_Target
1118 and then not Suppress_Standard_Library_On_Target
1122 if Lib_Final_Built
then
1123 Set_String
(" Finalize_Library_Objects := ");
1124 Set_String
("finalize_library'access;");
1126 Set_String
(" Finalize_Library_Objects := null;");
1129 Write_Statement_Buffer
;
1132 -- Generate elaboration calls
1134 if not CodePeer_Mode
then
1140 Gen_Elab_Calls
(Elab_Order
);
1142 if not CodePeer_Mode
then
1144 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
1145 -- restriction No_Standard_Allocators_After_Elaboration is active.
1147 if Cumulative_Restrictions
.Set
1148 (No_Standard_Allocators_After_Elaboration
)
1151 (" System.Elaboration_Allocators.Mark_End_Of_Elaboration;");
1154 -- From this point, no new dispatching domain can be created
1156 if Dispatching_Domains_Used
then
1157 WBI
(" Freeze_Dispatching_Domains;");
1160 -- Sequential partition elaboration policy
1162 if Partition_Elaboration_Policy_Specified
= 'S' then
1163 if System_Interrupts_Used
then
1164 WBI
(" Install_Restricted_Handlers_Sequential;");
1167 if System_Tasking_Restricted_Stages_Used
then
1168 WBI
(" Activate_All_Tasks_Sequential;");
1172 if System_BB_CPU_Primitives_Multiprocessors_Used
then
1173 WBI
(" Start_Slave_CPUs;");
1177 WBI
(" end " & Ada_Init_Name
.all & ";");
1181 -------------------------
1182 -- Gen_Bind_Env_String --
1183 -------------------------
1185 procedure Gen_Bind_Env_String
is
1186 procedure Write_Name_With_Len
(Nam
: Name_Id
);
1187 -- Write Nam as a string literal, prefixed with one
1188 -- character encoding Nam's length.
1190 -------------------------
1191 -- Write_Name_With_Len --
1192 -------------------------
1194 procedure Write_Name_With_Len
(Nam
: Name_Id
) is
1196 Get_Name_String
(Nam
);
1197 Write_Str
("Character'Val (");
1198 Write_Int
(Int
(Name_Len
));
1199 Write_Str
(") & """);
1200 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1202 end Write_Name_With_Len
;
1206 First
: Boolean := True;
1207 KN
: Name_Id
:= No_Name
;
1208 VN
: Name_Id
:= No_Name
;
1210 -- Start of processing for Gen_Bind_Env_String
1213 Bind_Environment
.Get_First
(KN
, VN
);
1215 if VN
= No_Name
then
1219 Set_Special_Output
(Write_Bind_Line
'Access);
1221 WBI
(" Bind_Env : aliased constant String :=");
1223 while VN
/= No_Name
loop
1230 Write_Name_With_Len
(KN
);
1232 Write_Name_With_Len
(VN
);
1235 Bind_Environment
.Get_Next
(KN
, VN
);
1239 WBI
(" & ASCII.NUL;");
1241 Cancel_Special_Output
;
1242 Bind_Env_String_Built
:= True;
1243 end Gen_Bind_Env_String
;
1249 procedure Gen_CUDA_Defs
is
1250 Unit_Name
: constant String :=
1251 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1252 Unit
: constant String :=
1253 Unit_Name
(Unit_Name
'First .. Unit_Name
'Last - 2);
1255 if not Enable_CUDA_Expansion
then
1262 WBI
(" procedure CUDA_Register_Function");
1263 WBI
(" (Fat_Binary_Handle : System.Address;");
1264 WBI
(" Func : System.Address;");
1265 WBI
(" Kernel_Name : Interfaces.C.Strings.chars_ptr;");
1266 WBI
(" Kernel_Name_2 : Interfaces.C.Strings.chars_ptr;");
1267 WBI
(" Minus_One : Integer;");
1268 WBI
(" Nullptr1 : System.Address;");
1269 WBI
(" Nullptr2 : System.Address;");
1270 WBI
(" Nullptr3 : System.Address;");
1271 WBI
(" Nullptr4 : System.Address;");
1272 WBI
(" Nullptr5 : System.Address);");
1273 WBI
(" pragma Import");
1274 WBI
(" (Convention => C,");
1275 WBI
(" Entity => CUDA_Register_Function,");
1276 WBI
(" External_Name => ""__cudaRegisterFunction"");");
1278 WBI
(" function CUDA_Register_Fat_Binary");
1279 WBI
(" (Fat_Binary : System.Address)");
1280 WBI
(" return System.Address;");
1281 WBI
(" pragma Import");
1282 WBI
(" (Convention => C,");
1283 WBI
(" Entity => CUDA_Register_Fat_Binary,");
1284 WBI
(" External_Name => ""__cudaRegisterFatBinary"");");
1286 WBI
(" procedure CUDA_Register_Fat_Binary_End");
1287 WBI
(" (Fat_Binary : System.Address);");
1288 WBI
(" pragma Import");
1289 WBI
(" (Convention => C,");
1290 WBI
(" Entity => CUDA_Register_Fat_Binary_End,");
1291 WBI
(" External_Name => ""__cudaRegisterFatBinaryEnd"");");
1293 WBI
(" type Fatbin_Wrapper is record");
1294 WBI
(" Magic : Interfaces.C.int;");
1295 WBI
(" Version : Interfaces.C.int;");
1296 WBI
(" Data : System.Address;");
1297 WBI
(" Filename_Or_Fatbins : System.Address;");
1298 WBI
(" end record;");
1300 WBI
(" Fat_Binary : System.Address;");
1301 WBI
(" pragma Import");
1302 WBI
(" (Convention => C,");
1303 WBI
(" Entity => Fat_Binary,");
1304 WBI
(" External_Name => ""_binary_" & Unit
& "_fatbin_start"");");
1306 WBI
(" Wrapper : Fatbin_Wrapper :=");
1307 WBI
(" (16#466243b1#,");
1309 WBI
(" Fat_Binary'Address,");
1310 WBI
(" System.Null_Address);");
1312 WBI
(" Fat_Binary_Handle : System.Address;");
1315 for K
in CUDA_Kernels
.First
.. CUDA_Kernels
.Last
loop
1317 K_String
: constant String := CUDA_Kernel_Id
'Image (K
);
1318 N
: constant String :=
1319 K_String
(K_String
'First + 1 .. K_String
'Last);
1320 Kernel_Symbol
: constant String := "Kernel_" & N
;
1321 -- K_Symbol is a unique identifier used to derive all symbol names
1322 -- related to kernel K.
1324 Kernel_Proc
: constant String := Kernel_Symbol
& "_Proc";
1325 -- Kernel_Proc is the name of the symbol representing the
1326 -- host-side procedure of the kernel. The address is
1327 -- pragma-imported and then used while registering the kernel with
1328 -- the CUDA runtime.
1329 Kernel_String
: constant String := Kernel_Symbol
& "_String";
1330 -- Kernel_String is the name of the C-string containing the name
1331 -- of the kernel. It is used for registering the kernel with the
1333 Kernel_Name
: constant String :=
1334 Get_Name_String
(CUDA_Kernels
.Table
(K
).Kernel_Name
);
1335 -- Kernel_Name is the name of the kernel, after package expansion.
1338 -- Import host-side kernel address.
1339 WBI
(" procedure " & Kernel_Proc
& ";");
1340 WBI
(" pragma Import");
1341 WBI
(" (Convention => C,");
1342 WBI
(" Entity => " & Kernel_Proc
& ",");
1343 WBI
(" External_Name => """ & Kernel_Name
& """);");
1346 -- Generate C-string containing name of kernel.
1348 (" " & Kernel_String
& " : Interfaces.C.Strings.Chars_Ptr;");
1354 WBI
(" procedure " & Device_Ada_Init_Subp_Name
& ";");
1355 WBI
(" pragma Export (C, " & Device_Ada_Init_Subp_Name
&
1356 ", Link_Name => """ & Device_Ada_Init_Link_Name
& """);");
1358 -- C-string declaration for adainit
1359 WBI
(" " & Adainit_String_Obj_Name
1360 & " : Interfaces.C.Strings.Chars_Ptr;");
1370 procedure Gen_CUDA_Init
is
1371 -- Generate call to register one function
1372 procedure Gen_CUDA_Register_Function_Call
1373 (Kernel_Name
: String;
1374 Kernel_String
: String;
1375 Kernel_Proc
: String);
1377 -------------------------------------
1378 -- Gen_CUDA_Register_Function_Call --
1379 -------------------------------------
1381 procedure Gen_CUDA_Register_Function_Call
1382 (Kernel_Name
: String;
1383 Kernel_String
: String;
1384 Kernel_Proc
: String) is
1386 WBI
(" " & Kernel_String
& " :=");
1387 WBI
(" Interfaces.C.Strings.New_Char_Array ("""
1391 -- Generate call to CUDA runtime to register function.
1392 WBI
(" CUDA_Register_Function (");
1393 WBI
(" Fat_Binary_Handle, ");
1394 WBI
(" " & Kernel_Proc
& "'Address,");
1395 WBI
(" " & Kernel_String
& ",");
1396 WBI
(" " & Kernel_String
& ",");
1398 WBI
(" System.Null_Address,");
1399 WBI
(" System.Null_Address,");
1400 WBI
(" System.Null_Address,");
1401 WBI
(" System.Null_Address,");
1402 WBI
(" System.Null_Address);");
1404 end Gen_CUDA_Register_Function_Call
;
1407 if not Enable_CUDA_Expansion
then
1411 WBI
(" Fat_Binary_Handle :=");
1412 WBI
(" CUDA_Register_Fat_Binary (Wrapper'Address);");
1414 for K
in CUDA_Kernels
.First
.. CUDA_Kernels
.Last
loop
1416 K_String
: constant String := CUDA_Kernel_Id
'Image (K
);
1417 N
: constant String :=
1418 K_String
(K_String
'First + 1 .. K_String
'Last);
1419 Kernel_Symbol
: constant String := "Kernel_" & N
;
1420 -- K_Symbol is a unique identifier used to derive all symbol names
1421 -- related to kernel K.
1423 Kernel_Proc
: constant String := Kernel_Symbol
& "_Proc";
1424 -- Kernel_Proc is the name of the symbol representing the
1425 -- host-side procedure of the kernel. The address is
1426 -- pragma-imported and then used while registering the kernel with
1427 -- the CUDA runtime.
1428 Kernel_String
: constant String := Kernel_Symbol
& "_String";
1429 -- Kernel_String is the name of the C-string containing the name
1430 -- of the kernel. It is used for registering the kernel with the
1432 Kernel_Name
: constant String :=
1433 Get_Name_String
(CUDA_Kernels
.Table
(K
).Kernel_Name
);
1434 -- Kernel_Name is the name of the kernel, after package expansion.
1436 Gen_CUDA_Register_Function_Call
1437 (Kernel_Name
=> Kernel_Name
,
1438 Kernel_String
=> Kernel_String
,
1439 Kernel_Proc
=> Kernel_Proc
);
1443 -- Register device-side Adainit
1444 Gen_CUDA_Register_Function_Call
1445 (Kernel_Name
=> Device_Ada_Init_Link_Name
,
1446 Kernel_String
=> Adainit_String_Obj_Name
,
1447 Kernel_Proc
=> Device_Ada_Init_Subp_Name
);
1449 WBI
(" CUDA_Register_Fat_Binary_End (Fat_Binary_Handle);");
1451 -- perform device (as opposed to host) elaboration
1452 WBI
(" pragma CUDA_Execute (" &
1453 Device_Ada_Init_Subp_Name
& ", 1, 1);");
1456 --------------------------
1457 -- Gen_CodePeer_Wrapper --
1458 --------------------------
1460 procedure Gen_CodePeer_Wrapper
is
1461 Callee_Name
: constant String := "Ada_Main_Program";
1464 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1465 WBI
(" procedure " & CodePeer_Wrapper_Name
& " is ");
1467 WBI
(" " & Callee_Name
& ";");
1470 WBI
(" function " & CodePeer_Wrapper_Name
& " return Integer is");
1472 WBI
(" return " & Callee_Name
& ";");
1475 WBI
(" end " & CodePeer_Wrapper_Name
& ";");
1477 end Gen_CodePeer_Wrapper
;
1479 --------------------
1480 -- Gen_Elab_Calls --
1481 --------------------
1483 procedure Gen_Elab_Calls
(Elab_Order
: Unit_Id_Array
) is
1484 Check_Elab_Flag
: Boolean;
1487 -- Loop through elaboration order entries
1489 for E
in Elab_Order
'Range loop
1491 Unum
: constant Unit_Id
:= Elab_Order
(E
);
1492 U
: Unit_Record
renames Units
.Table
(Unum
);
1494 Unum_Spec
: Unit_Id
;
1495 -- This is the unit number of the spec that corresponds to
1496 -- this entry. It is the same as Unum except when the body
1497 -- and spec are different and we are currently processing
1498 -- the body, in which case it is the spec (Unum + 1).
1501 if U
.Utype
= Is_Body
then
1502 Unum_Spec
:= Unum
+ 1;
1507 -- Nothing to do if predefined unit in no run time mode
1509 if No_Run_Time_Mode
and then Is_Predefined_File_Name
(U
.Sfile
) then
1512 -- Likewise if this is an interface to a stand alone library
1514 elsif U
.SAL_Interface
then
1517 -- Case of no elaboration code
1521 -- In CodePeer mode, we special case subprogram bodies which
1522 -- are handled in the 'else' part below, and lead to a call
1523 -- to <subp>'Elab_Subp_Body.
1525 and then (not CodePeer_Mode
1529 or else U
.Utype
= Is_Spec
1530 or else U
.Utype
= Is_Spec_Only
1531 or else U
.Unit_Kind
/= 's')
1533 -- In the case of a body with a separate spec, where the
1534 -- separate spec has an elaboration entity defined, this is
1535 -- where we increment the elaboration entity if one exists.
1537 -- Likewise for lone specs with an elaboration entity defined
1538 -- despite No_Elaboration_Code, e.g. when requested to preserve
1541 if (U
.Utype
= Is_Body
or else U
.Utype
= Is_Spec_Only
)
1542 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1543 and then not CodePeer_Mode
1546 Set_Unit_Number
(Unum_Spec
);
1547 Set_String
(" := E");
1548 Set_Unit_Number
(Unum_Spec
);
1549 Set_String
(" + 1;");
1550 Write_Statement_Buffer
;
1553 -- Here if elaboration code is present. If binding a library
1554 -- or if there is a non-Ada main subprogram then we generate:
1556 -- if uname_E = 0 then
1557 -- uname'elab_[spec|body];
1559 -- uname_E := uname_E + 1;
1561 -- Otherwise, elaboration routines are called unconditionally:
1563 -- uname'elab_[spec|body];
1564 -- uname_E := uname_E + 1;
1566 -- The uname_E increment is skipped if this is a separate spec,
1567 -- since it will be done when we process the body.
1569 -- In CodePeer mode, we do not generate any reference to xxx_E
1570 -- variables, only calls to 'Elab* subprograms.
1573 -- Check incompatibilities with No_Multiple_Elaboration
1575 if not CodePeer_Mode
1576 and then Cumulative_Restrictions
.Set
(No_Multiple_Elaboration
)
1578 -- Force_Checking_Of_Elaboration_Flags (-F) not allowed
1580 if Force_Checking_Of_Elaboration_Flags
then
1582 ("-F (force elaboration checks) switch not allowed "
1583 & "with restriction No_Multiple_Elaboration active");
1585 -- Interfacing of libraries not allowed
1587 elsif Interface_Library_Unit
then
1589 ("binding of interfaced libraries not allowed "
1590 & "with restriction No_Multiple_Elaboration active");
1592 -- Non-Ada main program not allowed
1594 elsif not Bind_Main_Program
then
1596 ("non-Ada main program not allowed "
1597 & "with restriction No_Multiple_Elaboration active");
1601 -- OK, see if we need to test elaboration flag
1604 Units
.Table
(Unum_Spec
).Set_Elab_Entity
1605 and then Check_Elaboration_Flags
1606 and then not CodePeer_Mode
1607 and then (Force_Checking_Of_Elaboration_Flags
1608 or Interface_Library_Unit
1609 or not Bind_Main_Program
);
1611 if Check_Elab_Flag
then
1612 Set_String
(" if E");
1613 Set_Unit_Number
(Unum_Spec
);
1614 Set_String
(" = 0 then");
1615 Write_Statement_Buffer
;
1620 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
1622 if Name_Buffer
(Name_Len
) = 's' then
1623 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1625 Name_Len
:= Name_Len
+ 8;
1627 -- Special case in CodePeer mode for subprogram bodies
1628 -- which correspond to CodePeer 'Elab_Subp_Body special
1631 elsif U
.Unit_Kind
= 's' and CodePeer_Mode
then
1632 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 13) :=
1634 Name_Len
:= Name_Len
+ 13;
1637 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1639 Name_Len
:= Name_Len
+ 8;
1642 Set_Casing
(U
.Icasing
);
1645 Write_Statement_Buffer
;
1647 if Check_Elab_Flag
then
1651 if U
.Utype
/= Is_Spec
1652 and then not CodePeer_Mode
1653 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1656 Set_Unit_Number
(Unum_Spec
);
1657 Set_String
(" := E");
1658 Set_Unit_Number
(Unum_Spec
);
1659 Set_String
(" + 1;");
1660 Write_Statement_Buffer
;
1667 ------------------------
1668 -- Gen_Elab_Externals --
1669 ------------------------
1671 procedure Gen_Elab_Externals
(Elab_Order
: Unit_Id_Array
) is
1673 if CodePeer_Mode
then
1677 for E
in Elab_Order
'Range loop
1679 Unum
: constant Unit_Id
:= Elab_Order
(E
);
1680 U
: Unit_Record
renames Units
.Table
(Unum
);
1683 -- Check for Elab_Entity to be set for this unit
1685 if U
.Set_Elab_Entity
1687 -- Don't generate reference for stand alone library
1689 and then not U
.SAL_Interface
1691 -- Don't generate reference for predefined file in No_Run_Time
1692 -- mode, since we don't include the object files in this case
1696 and then Is_Predefined_File_Name
(U
.Sfile
))
1698 Get_Name_String
(U
.Sfile
);
1701 Set_Unit_Number
(Unum
);
1702 Set_String
(" : Short_Integer; pragma Import (Ada, E");
1703 Set_Unit_Number
(Unum
);
1704 Set_String
(", """);
1705 Get_Name_String
(U
.Uname
);
1707 Set_String
("_E"");");
1708 Write_Statement_Buffer
;
1714 end Gen_Elab_Externals
;
1716 --------------------
1717 -- Gen_Elab_Order --
1718 --------------------
1720 procedure Gen_Elab_Order
(Elab_Order
: Unit_Id_Array
) is
1723 WBI
(" -- BEGIN ELABORATION ORDER");
1725 for J
in Elab_Order
'Range loop
1726 Set_String
(" -- ");
1727 Get_Name_String
(Units
.Table
(Elab_Order
(J
)).Uname
);
1729 Write_Statement_Buffer
;
1732 WBI
(" -- END ELABORATION ORDER");
1735 --------------------------
1736 -- Gen_Finalize_Library --
1737 --------------------------
1739 procedure Gen_Finalize_Library
(Elab_Order
: Unit_Id_Array
) is
1740 procedure Gen_Header
;
1741 -- Generate the header of the finalization routine
1747 procedure Gen_Header
is
1749 WBI
(" procedure finalize_library is");
1757 Uspec
: Unit_Record
;
1760 -- Start of processing for Gen_Finalize_Library
1763 if CodePeer_Mode
then
1767 for E
in reverse Elab_Order
'Range loop
1768 Unum
:= Elab_Order
(E
);
1769 U
:= Units
.Table
(Unum
);
1771 -- Dealing with package bodies is a little complicated. In such
1772 -- cases we must retrieve the package spec since it contains the
1773 -- spec of the body finalizer.
1775 if U
.Utype
= Is_Body
then
1777 Uspec
:= Units
.Table
(Unum
);
1782 Get_Name_String
(Uspec
.Uname
);
1784 -- We are only interested in non-generic packages
1786 if U
.Unit_Kind
/= 'p' or else U
.Is_Generic
then
1789 -- That aren't an interface to a stand alone library
1791 elsif U
.SAL_Interface
then
1794 -- Case of no finalization
1796 elsif not U
.Has_Finalizer
then
1798 -- The only case in which we have to do something is if this
1799 -- is a body, with a separate spec, where the separate spec
1800 -- has a finalizer. In that case, this is where we decrement
1801 -- the elaboration entity.
1803 if U
.Utype
= Is_Body
and then Uspec
.Has_Finalizer
then
1804 if not Lib_Final_Built
then
1806 Lib_Final_Built
:= True;
1810 Set_Unit_Number
(Unum
);
1811 Set_String
(" := E");
1812 Set_Unit_Number
(Unum
);
1813 Set_String
(" - 1;");
1814 Write_Statement_Buffer
;
1818 if not Lib_Final_Built
then
1820 Lib_Final_Built
:= True;
1825 -- procedure F<Count>;
1827 Set_String
(" declare");
1828 Write_Statement_Buffer
;
1830 Set_String
(" procedure F");
1833 Write_Statement_Buffer
;
1836 -- pragma Import (Ada, F<Count>,
1837 -- "xx__yy__finalize_[body|spec]");
1839 Set_String
(" pragma Import (Ada, F");
1841 Set_String
(", """);
1843 -- Perform name construction
1846 Set_String
("__finalize_");
1848 -- Package spec processing
1850 if U
.Utype
= Is_Spec
1851 or else U
.Utype
= Is_Spec_Only
1853 Set_String
("spec");
1855 -- Package body processing
1858 Set_String
("body");
1861 Set_String
(""");");
1862 Write_Statement_Buffer
;
1864 -- If binding a library or if there is a non-Ada main subprogram
1865 -- then we generate:
1868 -- uname_E := uname_E - 1;
1869 -- if uname_E = 0 then
1874 -- Otherwise, finalization routines are called unconditionally:
1877 -- uname_E := uname_E - 1;
1881 -- The uname_E decrement is skipped if this is a separate spec,
1882 -- since it will be done when we process the body.
1886 if U
.Utype
/= Is_Spec
then
1888 Set_Unit_Number
(Unum
);
1889 Set_String
(" := E");
1890 Set_Unit_Number
(Unum
);
1891 Set_String
(" - 1;");
1892 Write_Statement_Buffer
;
1895 if Interface_Library_Unit
or not Bind_Main_Program
then
1896 Set_String
(" if E");
1897 Set_Unit_Number
(Unum
);
1898 Set_String
(" = 0 then");
1899 Write_Statement_Buffer
;
1906 Write_Statement_Buffer
;
1908 if Interface_Library_Unit
or not Bind_Main_Program
then
1918 if Lib_Final_Built
then
1920 -- It is possible that the finalization of a library-level object
1921 -- raised an exception. In that case import the actual exception
1922 -- and the routine necessary to raise it.
1925 WBI
(" procedure Reraise_Library_Exception_If_Any;");
1927 Set_String
(" pragma Import (Ada, ");
1928 Set_String
("Reraise_Library_Exception_If_Any, ");
1929 Set_String
("""__gnat_reraise_library_exception_if_any"");");
1930 Write_Statement_Buffer
;
1933 WBI
(" Reraise_Library_Exception_If_Any;");
1935 WBI
(" end finalize_library;");
1938 end Gen_Finalize_Library
;
1944 procedure Gen_Main
is
1946 if not No_Main_Subprogram
then
1948 -- To call the main program, we declare it using a pragma Import
1949 -- Ada with the right link name.
1951 -- It might seem more obvious to "with" the main program, and call
1952 -- it in the normal Ada manner. We do not do this for three
1955 -- 1. It is more efficient not to recompile the main program
1956 -- 2. We are not entitled to assume the source is accessible
1957 -- 3. We don't know what options to use to compile it
1959 -- It is really reason 3 that is most critical (indeed we used
1960 -- to generate the "with", but several regression tests failed).
1962 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1963 WBI
(" function Ada_Main_Program return Integer;");
1965 WBI
(" procedure Ada_Main_Program;");
1968 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1969 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1970 Set_Main_Program_Name
;
1971 Set_String
(""");");
1973 Write_Statement_Buffer
;
1976 -- For CodePeer, declare a wrapper for the user-defined main program
1978 if CodePeer_Mode
then
1979 Gen_CodePeer_Wrapper
;
1983 if Exit_Status_Supported_On_Target
then
1984 Set_String
(" function ");
1986 Set_String
(" procedure ");
1989 Set_String
(Get_Main_Name
);
1991 if Command_Line_Args_On_Target
then
1992 Write_Statement_Buffer
;
1993 WBI
(" (argc : Integer;");
1994 WBI
(" argv : System.Address;");
1995 WBI
(" envp : System.Address)");
1997 if Exit_Status_Supported_On_Target
then
1998 WBI
(" return Integer");
2004 if Exit_Status_Supported_On_Target
then
2005 Set_String
(" return Integer is");
2010 Write_Statement_Buffer
;
2013 if Opt
.Default_Exit_Status
/= 0
2014 and then Bind_Main_Program
2015 and then not Configurable_Run_Time_Mode
2017 WBI
(" procedure Set_Exit_Status (Status : Integer);");
2018 WBI
(" pragma Import (C, Set_Exit_Status, " &
2019 """__gnat_set_exit_status"");");
2023 -- Initialize and Finalize
2025 if not CodePeer_Mode
2026 and then not Cumulative_Restrictions
.Set
(No_Finalization
)
2028 WBI
(" procedure Initialize (Addr : System.Address);");
2029 WBI
(" pragma Import (C, Initialize, ""__gnat_initialize"");");
2031 WBI
(" procedure Finalize;");
2032 WBI
(" pragma Import (C, Finalize, ""__gnat_finalize"");");
2035 -- If we want to analyze the stack, we must import corresponding symbols
2037 if Dynamic_Stack_Measurement
then
2039 WBI
(" procedure Output_Results;");
2040 WBI
(" pragma Import (C, Output_Results, " &
2041 """__gnat_stack_usage_output_results"");");
2045 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
2046 WBI
(" pragma Import (C, Initialize_Stack_Analysis, " &
2047 """__gnat_stack_usage_initialize"");");
2050 -- Deal with declarations for main program case
2052 if not No_Main_Subprogram
then
2053 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
2054 WBI
(" Result : Integer;");
2058 if Bind_Main_Program
2059 and not Suppress_Standard_Library_On_Target
2060 and not CodePeer_Mode
2062 WBI
(" SEH : aliased array (1 .. 2) of Integer;");
2067 -- Generate a reference to Ada_Main_Program_Name. This symbol is not
2068 -- referenced elsewhere in the generated program, but is needed by
2069 -- the debugger (that's why it is generated in the first place). The
2070 -- reference stops Ada_Main_Program_Name from being optimized away by
2073 -- Because this variable is unused, we make this variable "aliased"
2074 -- with a pragma Volatile in order to tell the compiler to preserve
2075 -- this variable at any level of optimization.
2077 -- CodePeer and CCG do not need this extra code. The code is also not
2078 -- needed if the binder is in "Minimal Binder" mode.
2080 if Bind_Main_Program
2081 and then not Minimal_Binder
2082 and then not CodePeer_Mode
2083 and then not Generate_C_Code
2085 WBI
(" Ensure_Reference : aliased System.Address := " &
2086 "Ada_Main_Program_Name'Address;");
2087 WBI
(" pragma Volatile (Ensure_Reference);");
2093 -- Acquire command-line arguments if present on target
2095 if CodePeer_Mode
then
2098 elsif Command_Line_Args_On_Target
then
2100 -- Initialize gnat_argc/gnat_argv only if not already initialized,
2101 -- to avoid losing the result of any command-line processing done by
2102 -- earlier GNAT run-time initialization.
2104 WBI
(" if gnat_argc = 0 then");
2105 WBI
(" gnat_argc := argc;");
2106 WBI
(" gnat_argv := argv;");
2108 WBI
(" gnat_envp := envp;");
2111 -- If configurable run-time and no command-line args, then nothing needs
2112 -- to be done since the gnat_argc/argv/envp variables are suppressed in
2115 elsif Configurable_Run_Time_On_Target
then
2118 -- Otherwise set dummy values (to be filled in by some other unit?)
2121 WBI
(" gnat_argc := 0;");
2122 WBI
(" gnat_argv := System.Null_Address;");
2123 WBI
(" gnat_envp := System.Null_Address;");
2126 if Opt
.Default_Exit_Status
/= 0
2127 and then Bind_Main_Program
2128 and then not Configurable_Run_Time_Mode
2130 Set_String
(" Set_Exit_Status (");
2131 Set_Int
(Opt
.Default_Exit_Status
);
2133 Write_Statement_Buffer
;
2136 if Dynamic_Stack_Measurement
then
2137 Set_String
(" Initialize_Stack_Analysis (");
2138 Set_Int
(Dynamic_Stack_Measurement_Array_Size
);
2140 Write_Statement_Buffer
;
2143 if not Cumulative_Restrictions
.Set
(No_Finalization
)
2144 and then not CodePeer_Mode
2146 if not No_Main_Subprogram
2147 and then Bind_Main_Program
2148 and then not Suppress_Standard_Library_On_Target
2150 WBI
(" Initialize (SEH'Address);");
2152 WBI
(" Initialize (System.Null_Address);");
2156 WBI
(" " & Ada_Init_Name
.all & ";");
2158 if not No_Main_Subprogram
then
2159 if CodePeer_Mode
then
2160 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
2161 WBI
(" " & CodePeer_Wrapper_Name
& ";");
2163 WBI
(" Result := " & CodePeer_Wrapper_Name
& ";");
2166 elsif ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
2167 WBI
(" Ada_Main_Program;");
2170 WBI
(" Result := Ada_Main_Program;");
2174 -- Adafinal call is skipped if no finalization
2176 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2180 -- Prints the result of static stack analysis
2182 if Dynamic_Stack_Measurement
then
2183 WBI
(" Output_Results;");
2186 -- Finalize is only called if we have a run time
2188 if not Cumulative_Restrictions
.Set
(No_Finalization
)
2189 and then not CodePeer_Mode
2196 if Exit_Status_Supported_On_Target
then
2197 if No_Main_Subprogram
2198 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
2200 WBI
(" return (gnat_exit_status);");
2202 WBI
(" return (Result);");
2210 ------------------------------
2211 -- Gen_Object_Files_Options --
2212 ------------------------------
2214 procedure Gen_Object_Files_Options
(Elab_Order
: Unit_Id_Array
) is
2216 -- This keeps track of the position in the sorted set of entries in the
2217 -- Linker_Options table of where the first entry from an internal file
2220 Linker_Option_List_Started
: Boolean := False;
2221 -- Set to True when "LINKER OPTION LIST" is displayed
2223 procedure Write_Linker_Option
;
2224 -- Write binder info linker option
2226 -------------------------
2227 -- Write_Linker_Option --
2228 -------------------------
2230 procedure Write_Linker_Option
is
2235 -- Loop through string, breaking at null's
2238 while Start
< Name_Len
loop
2240 -- Find null ending this section
2243 while Name_Buffer
(Stop
) /= ASCII
.NUL
2244 and then Stop
<= Name_Len
loop
2248 -- Process section if non-null
2250 if Stop
> Start
then
2251 if Output_Linker_Option_List
then
2252 if not Zero_Formatting
then
2253 if not Linker_Option_List_Started
then
2254 Linker_Option_List_Started
:= True;
2256 Write_Str
(" LINKER OPTION LIST");
2264 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
2267 WBI
(" -- " & Name_Buffer
(Start
.. Stop
- 1));
2272 end Write_Linker_Option
;
2274 -- Start of processing for Gen_Object_Files_Options
2277 WBI
("-- BEGIN Object file/option list");
2279 if Object_List_Filename
/= null then
2280 Set_List_File
(Object_List_Filename
.all);
2283 for E
in Elab_Order
'Range loop
2285 -- If not spec that has an associated body, then generate a comment
2286 -- giving the name of the corresponding object file.
2288 if not Units
.Table
(Elab_Order
(E
)).SAL_Interface
2289 and then Units
.Table
(Elab_Order
(E
)).Utype
/= Is_Spec
2293 (Units
.Table
(Elab_Order
(E
)).My_ALI
).Ofile_Full_Name
);
2295 -- If the presence of an object file is necessary or if it exists,
2298 if not Hostparm
.Exclude_Missing_Objects
2300 System
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
2302 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
2304 if Output_Object_List
then
2305 Write_Str
(Name_Buffer
(1 .. Name_Len
));
2312 if Object_List_Filename
/= null then
2316 -- Add a "-Ldir" for each directory in the object path
2318 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
2320 Dir
: constant String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
2324 Add_Str_To_Name_Buffer
("-L");
2325 Add_Str_To_Name_Buffer
(Dir
.all);
2326 Write_Linker_Option
;
2330 if not (Opt
.No_Run_Time_Mode
or Opt
.No_Stdlib
) then
2333 if Opt
.Shared_Libgnat
then
2334 Add_Str_To_Name_Buffer
("-shared");
2336 Add_Str_To_Name_Buffer
("-static");
2339 -- Write directly to avoid inclusion in -K output as -static and
2340 -- -shared are not usually specified linker options.
2342 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
2345 -- Sort linker options
2347 -- This sort accomplishes two important purposes:
2349 -- a) All application files are sorted to the front, and all GNAT
2350 -- internal files are sorted to the end. This results in a well
2351 -- defined dividing line between the two sets of files, for the
2352 -- purpose of inserting certain standard library references into
2353 -- the linker arguments list.
2355 -- b) Given two different units, we sort the linker options so that
2356 -- those from a unit earlier in the elaboration order comes later
2357 -- in the list. This is a heuristic designed to create a more
2358 -- friendly order of linker options when the operations appear in
2359 -- separate units. The idea is that if unit A must be elaborated
2360 -- before unit B, then it is more likely that B references
2361 -- libraries included by A, than vice versa, so we want libraries
2362 -- included by A to come after libraries included by B.
2364 -- These two criteria are implemented by function Lt_Linker_Option. Note
2365 -- that a special case of b) is that specs are elaborated before bodies,
2366 -- so linker options from specs come after linker options for bodies,
2367 -- and again, the assumption is that libraries used by the body are more
2368 -- likely to reference libraries used by the spec, than vice versa.
2371 (Linker_Options
.Last
,
2372 Move_Linker_Option
'Access,
2373 Lt_Linker_Option
'Access);
2375 -- Write user linker options, i.e. the set of linker options that come
2376 -- from all files other than GNAT internal files, Lgnat is left set to
2377 -- point to the first entry from a GNAT internal file, or past the end
2378 -- of the entries if there are no internal files.
2380 Lgnat
:= Linker_Options
.Last
+ 1;
2382 for J
in 1 .. Linker_Options
.Last
loop
2383 if not Linker_Options
.Table
(J
).Internal_File
then
2384 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2385 Write_Linker_Option
;
2392 -- Now we insert standard linker options that must appear after the
2393 -- entries from user files, and before the entries from GNAT run-time
2394 -- files. The reason for this decision is that libraries referenced
2395 -- by internal routines may reference these standard library entries.
2397 -- Note that we do not insert anything when pragma No_Run_Time has
2398 -- been specified or when the standard libraries are not to be used,
2399 -- otherwise on some platforms, we may get duplicate symbols when
2400 -- linking (not clear if this is still the case, but it is harmless).
2402 if not (Opt
.No_Run_Time_Mode
or else Opt
.No_Stdlib
) then
2406 if Opt
.Shared_Libgnat
then
2407 Add_Str_To_Name_Buffer
(Shared_Lib
("gnarl"));
2409 Add_Str_To_Name_Buffer
("-lgnarl");
2412 Write_Linker_Option
;
2417 if Opt
.Shared_Libgnat
then
2418 Add_Str_To_Name_Buffer
(Shared_Lib
("gnat"));
2420 Add_Str_To_Name_Buffer
("-lgnat");
2423 Write_Linker_Option
;
2426 -- Write linker options from all internal files
2428 for J
in Lgnat
.. Linker_Options
.Last
loop
2429 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2430 Write_Linker_Option
;
2433 if Output_Linker_Option_List
and then not Zero_Formatting
then
2437 WBI
("-- END Object file/option list ");
2438 end Gen_Object_Files_Options
;
2440 ---------------------
2441 -- Gen_Output_File --
2442 ---------------------
2444 procedure Gen_Output_File
2446 Elab_Order
: Unit_Id_Array
)
2449 -- Acquire settings for Interrupt_State pragmas
2451 Set_IS_Pragma_Table
;
2453 -- Acquire settings for Priority_Specific_Dispatching pragma
2455 Set_PSD_Pragma_Table
;
2457 -- Override time slice value if -T switch is set
2459 if Time_Slice_Set
then
2460 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
2463 -- Count number of elaboration calls
2465 for E
in Elab_Order
'Range loop
2466 if Units
.Table
(Elab_Order
(E
)).No_Elab
then
2469 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
2473 -- Count the number of statically allocated stacks to be generated by
2474 -- the binder. If the user has specified the number of default-sized
2475 -- secondary stacks, use that number. Otherwise start the count at one
2476 -- as the binder is responsible for creating a secondary stack for the
2479 if Opt
.Quantity_Of_Default_Size_Sec_Stacks
/= -1 then
2480 Num_Sec_Stacks
:= Quantity_Of_Default_Size_Sec_Stacks
;
2481 elsif Sec_Stack_Used
then
2482 Num_Sec_Stacks
:= 1;
2485 for J
in Units
.First
.. Units
.Last
loop
2486 Num_Primary_Stacks
:=
2487 Num_Primary_Stacks
+ Units
.Table
(J
).Primary_Stack_Count
;
2490 Num_Sec_Stacks
+ Units
.Table
(J
).Sec_Stack_Count
;
2493 -- Generate output file in appropriate language
2495 Gen_Output_File_Ada
(Filename
, Elab_Order
);
2496 end Gen_Output_File
;
2498 -------------------------
2499 -- Gen_Output_File_Ada --
2500 -------------------------
2502 procedure Gen_Output_File_Ada
2503 (Filename
: String; Elab_Order
: Unit_Id_Array
)
2505 Ada_Main
: constant String := Get_Ada_Main_Name
;
2506 -- Name to be used for generated Ada main program. See the body of
2507 -- function Get_Ada_Main_Name for details on the form of the name.
2509 Needs_Library_Finalization
: constant Boolean :=
2510 not Configurable_Run_Time_On_Target
2511 and then Has_Finalizer
(Elab_Order
);
2512 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2513 -- non-terminating, so we do not want finalization.
2516 -- Name of generated bind file (spec)
2519 -- Name of generated bind file (body)
2522 -- Create spec first
2524 Create_Binder_Output
(Filename
, 's', Bfiles
);
2526 -- We always compile the binder file in Ada 95 mode so that we properly
2527 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2528 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
2530 WBI
("pragma Warnings (Off);");
2531 WBI
("pragma Ada_95;");
2533 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2534 -- then we need to make sure that the binder program is compiled with
2535 -- the same restriction, so that no exception tables are generated.
2537 if Cumulative_Restrictions
.Set
(No_Exception_Handlers
) then
2538 WBI
("pragma Restrictions (No_Exception_Handlers);");
2541 -- Same processing for Restrictions (No_Exception_Propagation)
2543 if Cumulative_Restrictions
.Set
(No_Exception_Propagation
) then
2544 WBI
("pragma Restrictions (No_Exception_Propagation);");
2547 -- Same processing for pragma No_Run_Time
2549 if No_Run_Time_Mode
then
2550 WBI
("pragma No_Run_Time;");
2553 -- Generate with of System so we can reference System.Address
2555 WBI
("with System;");
2557 -- Generate with of System.Initialize_Scalars if active
2559 if Initialize_Scalars_Used
then
2560 WBI
("with System.Scalar_Values;");
2563 -- Generate withs of System.Secondary_Stack and System.Parameters to
2564 -- allow the generation of the default-sized secondary stack pool.
2566 if Sec_Stack_Used
then
2567 WBI
("with System.Parameters;");
2568 WBI
("with System.Secondary_Stack;");
2571 if Enable_CUDA_Expansion
then
2572 WBI
("with Interfaces.C;");
2573 WBI
("with Interfaces.C.Strings;");
2575 -- with of CUDA.Internal needed for CUDA_Execute pragma expansion
2576 WBI
("with CUDA.Internal;");
2579 Resolve_Binder_Options
(Elab_Order
);
2581 -- Generate standard with's
2583 if not Suppress_Standard_Library_On_Target
then
2584 if CodePeer_Mode
then
2585 WBI
("with System.Standard_Library;");
2589 WBI
("package " & Ada_Main
& " is");
2591 -- Main program case
2593 if Bind_Main_Program
then
2594 -- Generate argc/argv stuff unless suppressed
2596 if Command_Line_Args_On_Target
2597 or not Configurable_Run_Time_On_Target
2600 WBI
(" gnat_argc : Integer;");
2601 WBI
(" gnat_argv : System.Address;");
2602 WBI
(" gnat_envp : System.Address;");
2604 -- If the standard library is not suppressed, these variables
2605 -- are in the run-time data area for easy run time access.
2607 if not Suppress_Standard_Library_On_Target
then
2609 WBI
(" pragma Import (C, gnat_argc);");
2610 WBI
(" pragma Import (C, gnat_argv);");
2611 WBI
(" pragma Import (C, gnat_envp);");
2615 -- Define exit status. Again in normal mode, this is in the run-time
2616 -- library, and is initialized there, but in the configurable
2617 -- run-time case, the variable is declared and initialized in this
2622 if Configurable_Run_Time_Mode
then
2623 if Exit_Status_Supported_On_Target
then
2624 WBI
(" gnat_exit_status : Integer := 0;");
2628 WBI
(" gnat_exit_status : Integer;");
2629 WBI
(" pragma Import (C, gnat_exit_status);");
2632 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2633 -- the main program. Otherwise, it can lead under some circumstances
2634 -- to a symbol duplication during the link (for instance when a C
2635 -- program uses two Ada libraries). Also zero terminate the string
2636 -- so that its end can be found reliably at run time.
2638 if not Minimal_Binder
then
2640 WBI
(" GNAT_Version : constant String :=");
2641 WBI
(" """ & Ver_Prefix
&
2642 Gnat_Version_String
&
2644 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2646 WBI
(" GNAT_Version_Address : constant System.Address := " &
2647 "GNAT_Version'Address;");
2648 WBI
(" pragma Export (C, GNAT_Version_Address, " &
2649 """__gnat_version_address"");");
2651 Set_String
(" Ada_Main_Program_Name : constant String := """);
2652 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2654 Set_Main_Program_Name
;
2655 Set_String
(""" & ASCII.NUL;");
2657 Write_Statement_Buffer
;
2660 (" pragma Export (C, Ada_Main_Program_Name, " &
2661 """__gnat_ada_main_program_name"");");
2666 WBI
(" procedure " & Ada_Init_Name
.all & ";");
2667 if Enable_CUDA_Device_Expansion
then
2668 WBI
(" pragma Export (C, " & Ada_Init_Name
.all &
2669 ", Link_Name => """ & Device_Link_Name_Prefix
2670 & Ada_Init_Name
.all & """);");
2671 WBI
(" pragma CUDA_Global (" & Ada_Init_Name
.all & ");");
2673 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
2674 Ada_Init_Name
.all & """);");
2677 -- If -a has been specified use pragma Linker_Constructor for the init
2678 -- procedure and pragma Linker_Destructor for the final procedure.
2680 if Use_Pragma_Linker_Constructor
then
2681 WBI
(" pragma Linker_Constructor (" & Ada_Init_Name
.all & ");");
2684 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2686 WBI
(" procedure " & Ada_Final_Name
.all & ";");
2687 if Enable_CUDA_Device_Expansion
then
2688 WBI
(" pragma Export (C, " & Ada_Final_Name
.all &
2689 ", Link_Name => """ & Device_Link_Name_Prefix
&
2690 Ada_Final_Name
.all & """);");
2691 WBI
(" pragma CUDA_Global (" & Ada_Final_Name
.all & ");");
2693 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
2694 Ada_Final_Name
.all & """);");
2697 if Use_Pragma_Linker_Constructor
then
2698 WBI
(" pragma Linker_Destructor (" & Ada_Final_Name
.all & ");");
2702 if Bind_Main_Program
then
2706 if Exit_Status_Supported_On_Target
then
2707 Set_String
(" function ");
2709 Set_String
(" procedure ");
2712 Set_String
(Get_Main_Name
);
2714 -- Generate argument list if present
2716 if Command_Line_Args_On_Target
then
2717 Write_Statement_Buffer
;
2718 WBI
(" (argc : Integer;");
2719 WBI
(" argv : System.Address;");
2721 (" envp : System.Address)");
2723 if Exit_Status_Supported_On_Target
then
2724 Write_Statement_Buffer
;
2725 WBI
(" return Integer;");
2727 Write_Statement_Buffer
(";");
2731 if Exit_Status_Supported_On_Target
then
2732 Write_Statement_Buffer
(" return Integer;");
2734 Write_Statement_Buffer
(";");
2738 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
2739 Get_Main_Name
& """);");
2744 -- Generate version numbers for units, only if needed. Be very safe on
2747 if not Configurable_Run_Time_On_Target
2748 or else System_Version_Control_Used
2749 or else not Bind_Main_Program
2754 Gen_Elab_Order
(Elab_Order
);
2759 WBI
("end " & Ada_Main
& ";");
2760 Close_Binder_Output
;
2762 -- Prepare to write body
2764 Create_Binder_Output
(Filename
, 'b', Bfileb
);
2766 -- We always compile the binder file in Ada 95 mode so that we properly
2767 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2768 -- of the Ada 2005/2012 constructs are needed by the binder file.
2770 WBI
("pragma Warnings (Off);");
2771 WBI
("pragma Ada_95;");
2773 -- Output Source_File_Name pragmas which look like
2775 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2776 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2778 -- where sss/bbb are the spec/body file names respectively
2780 Get_Name_String
(Bfiles
);
2781 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2783 WBI
("pragma Source_File_Name (" &
2785 ", Spec_File_Name => """ &
2786 Name_Buffer
(1 .. Name_Len
+ 3));
2788 Get_Name_String
(Bfileb
);
2789 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2791 WBI
("pragma Source_File_Name (" &
2793 ", Body_File_Name => """ &
2794 Name_Buffer
(1 .. Name_Len
+ 3));
2796 -- Generate pragma Suppress (Overflow_Check). This is needed for recent
2797 -- versions of the compiler which have overflow checks on by default.
2798 -- We do not want overflow checking enabled for the increments of the
2799 -- elaboration variables (since this can cause an unwanted reference to
2800 -- the last chance exception handler for limited run-times).
2802 WBI
("pragma Suppress (Overflow_Check);");
2804 -- Generate with of System.Restrictions to initialize
2805 -- Run_Time_Restrictions.
2807 if System_Restrictions_Used
2808 and not Suppress_Standard_Library_On_Target
2811 WBI
("with System.Restrictions;");
2814 -- Generate with of Ada.Exceptions if needs library finalization
2816 if Needs_Library_Finalization
then
2817 WBI
("with Ada.Exceptions;");
2820 -- Generate with of System.Elaboration_Allocators if the restriction
2821 -- No_Standard_Allocators_After_Elaboration was present.
2823 if Cumulative_Restrictions
.Set
2824 (No_Standard_Allocators_After_Elaboration
)
2826 WBI
("with System.Elaboration_Allocators;");
2829 -- Generate start of package body
2832 WBI
("package body " & Ada_Main
& " is");
2835 -- Generate externals for elaboration entities
2837 Gen_Elab_Externals
(Elab_Order
);
2839 -- Generate default-sized secondary stacks pool. At least one stack is
2840 -- created and assigned to the environment task if secondary stacks are
2841 -- used by the program.
2843 if Sec_Stack_Used
then
2844 Set_String
(" Sec_Default_Sized_Stacks");
2845 Set_String
(" : array (1 .. ");
2846 Set_Int
(Num_Sec_Stacks
);
2847 Set_String
(") of aliased System.Secondary_Stack.SS_Stack (");
2849 if Opt
.Default_Sec_Stack_Size
/= No_Stack_Size
then
2850 Set_Int
(Opt
.Default_Sec_Stack_Size
);
2852 Set_String
("System.Parameters.Runtime_Default_Sec_Stack_Size");
2856 Write_Statement_Buffer
;
2860 -- Generate reference
2862 if not CodePeer_Mode
then
2863 if not Suppress_Standard_Library_On_Target
then
2865 -- Generate Priority_Specific_Dispatching pragma string
2868 (" Local_Priority_Specific_Dispatching : " &
2869 "constant String := """);
2871 for J
in 0 .. PSD_Pragma_Settings
.Last
loop
2872 Set_Char
(PSD_Pragma_Settings
.Table
(J
));
2876 Write_Statement_Buffer
;
2878 -- Generate Interrupt_State pragma string
2880 Set_String
(" Local_Interrupt_States : constant String := """);
2882 for J
in 0 .. IS_Pragma_Settings
.Last
loop
2883 Set_Char
(IS_Pragma_Settings
.Table
(J
));
2887 Write_Statement_Buffer
;
2891 if not Suppress_Standard_Library_On_Target
then
2893 -- The B.1(39) implementation advice says that the adainit and
2894 -- adafinal routines should be idempotent. Generate a flag to
2895 -- ensure that. This is not needed if we are suppressing the
2896 -- standard library since it would never be referenced.
2898 WBI
(" Is_Elaborated : Boolean := False;");
2900 -- Generate bind environment string
2902 Gen_Bind_Env_String
;
2908 -- Generate the adafinal routine unless there is no finalization to do
2910 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2911 if Needs_Library_Finalization
then
2912 Gen_Finalize_Library
(Elab_Order
);
2918 Gen_Adainit
(Elab_Order
);
2920 if Enable_CUDA_Expansion
then
2921 WBI
(" procedure " & Device_Ada_Init_Subp_Name
& " is");
2923 WBI
(" raise Program_Error;");
2924 WBI
(" end " & Device_Ada_Init_Subp_Name
& ";");
2927 if Bind_Main_Program
then
2931 -- Output object file list and the Ada body is complete
2933 Gen_Object_Files_Options
(Elab_Order
);
2936 WBI
("end " & Ada_Main
& ";");
2938 Close_Binder_Output
;
2939 end Gen_Output_File_Ada
;
2941 ----------------------
2942 -- Gen_Restrictions --
2943 ----------------------
2945 procedure Gen_Restrictions
is
2949 if Suppress_Standard_Library_On_Target
2950 or not System_Restrictions_Used
2955 WBI
(" System.Restrictions.Run_Time_Restrictions :=");
2961 for J
in Cumulative_Restrictions
.Set
'Range loop
2962 Set_Boolean
(Cumulative_Restrictions
.Set
(J
));
2966 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2967 Write_Statement_Buffer
;
2973 Set_String_Replace
("),");
2974 Write_Statement_Buffer
;
2975 Set_String
(" Value => (");
2977 for J
in Cumulative_Restrictions
.Value
'Range loop
2978 Set_Int
(Int
(Cumulative_Restrictions
.Value
(J
)));
2982 Set_String_Replace
("),");
2983 Write_Statement_Buffer
;
2984 WBI
(" Violated =>");
2988 for J
in Cumulative_Restrictions
.Violated
'Range loop
2989 Set_Boolean
(Cumulative_Restrictions
.Violated
(J
));
2993 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2994 Write_Statement_Buffer
;
3000 Set_String_Replace
("),");
3001 Write_Statement_Buffer
;
3002 Set_String
(" Count => (");
3004 for J
in Cumulative_Restrictions
.Count
'Range loop
3005 Set_Int
(Int
(Cumulative_Restrictions
.Count
(J
)));
3009 Set_String_Replace
("),");
3010 Write_Statement_Buffer
;
3011 Set_String
(" Unknown => (");
3013 for J
in Cumulative_Restrictions
.Unknown
'Range loop
3014 Set_Boolean
(Cumulative_Restrictions
.Unknown
(J
));
3018 Set_String_Replace
("))");
3020 Write_Statement_Buffer
;
3021 end Gen_Restrictions
;
3027 -- This routine generates lines such as:
3029 -- unnnnn : constant Integer := 16#hhhhhhhh#;
3030 -- pragma Export (C, unnnnn, unam);
3032 -- for each unit, where unam is the unit name suffixed by either B or S for
3033 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
3034 -- the version number, and nnnnn is a 5-digits serial number.
3036 procedure Gen_Versions
is
3037 Ubuf
: String (1 .. 6) := "u00000";
3039 procedure Increment_Ubuf
;
3040 -- Little procedure to increment the serial number
3042 --------------------
3043 -- Increment_Ubuf --
3044 --------------------
3046 procedure Increment_Ubuf
is
3048 for J
in reverse Ubuf
'Range loop
3049 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
3050 exit when Ubuf
(J
) <= '9';
3055 -- Start of processing for Gen_Versions
3060 WBI
(" type Version_32 is mod 2 ** 32;");
3061 for U
in Units
.First
.. Units
.Last
loop
3062 if not Units
.Table
(U
).SAL_Interface
3063 and then (not Bind_For_Library
3064 or else Units
.Table
(U
).Directly_Scanned
)
3067 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
3068 Units
.Table
(U
).Version
& "#;");
3069 Set_String
(" pragma Export (C, ");
3071 Set_String
(", """);
3073 Get_Name_String
(Units
.Table
(U
).Uname
);
3075 for K
in 1 .. Name_Len
loop
3076 if Name_Buffer
(K
) = '.' then
3080 elsif Name_Buffer
(K
) = '%' then
3084 Set_Char
(Name_Buffer
(K
));
3088 if Name_Buffer
(Name_Len
) = 's' then
3094 Set_String
(""");");
3095 Write_Statement_Buffer
;
3100 ------------------------
3101 -- Get_Main_Unit_Name --
3102 ------------------------
3104 function Get_Main_Unit_Name
(S
: String) return String is
3105 Result
: String := S
;
3108 for J
in S
'Range loop
3109 if Result
(J
) = '.' then
3115 end Get_Main_Unit_Name
;
3117 -----------------------
3118 -- Get_Ada_Main_Name --
3119 -----------------------
3121 function Get_Ada_Main_Name
return String is
3122 Suffix
: constant String := "_00";
3123 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
3124 Opt
.Ada_Main_Name
.all & Suffix
;
3128 -- For CodePeer, we want reproducible names (independent of other mains
3129 -- that may or may not be present) that don't collide when analyzing
3130 -- multiple mains and which are easily recognizable as "ada_main" names.
3132 if CodePeer_Mode
then
3133 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
3137 Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
- 2));
3140 -- This loop tries the following possibilities in order
3146 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
3147 -- it is set to 'ada_main'.
3149 for J
in 0 .. 99 loop
3151 Nlen
:= Name
'Length - Suffix
'Length;
3153 Nlen
:= Name
'Length;
3154 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
3155 Name
(Name
'Last - 1) :=
3156 Character'Val (J
/ 10 + Character'Pos ('0'));
3159 for K
in ALIs
.First
.. ALIs
.Last
loop
3160 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
3162 -- Get unit name, removing %b or %e at end
3164 Get_Name_String
(Units
.Table
(L
).Uname
);
3165 Name_Len
:= Name_Len
- 2;
3167 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
3173 return Name
(1 .. Nlen
);
3179 -- If we fall through, just use a peculiar unlikely name
3181 return ("Qwertyuiop");
3182 end Get_Ada_Main_Name
;
3188 function Get_Main_Name
return String is
3190 -- Explicit name given with -M switch
3192 if Bind_Alternate_Main_Name
then
3193 return Alternate_Main_Name
.all;
3195 -- Case of main program name to be used directly
3197 elsif Use_Ada_Main_Program_Name_On_Target
then
3199 -- Get main program name
3201 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
3203 -- If this is a child name, return only the name of the child, since
3204 -- we can't have dots in a nested program name. Note that we do not
3205 -- include the %b at the end of the unit name.
3207 for J
in reverse 1 .. Name_Len
- 2 loop
3208 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
3209 return Name_Buffer
(J
.. Name_Len
- 2);
3213 raise Program_Error
; -- impossible exit
3215 -- Case where "main" is to be used as default
3222 ---------------------
3223 -- Get_WC_Encoding --
3224 ---------------------
3226 function Get_WC_Encoding
return Character is
3228 -- If encoding method specified by -W switch, then return it
3230 if Wide_Character_Encoding_Method_Specified
then
3231 return WC_Encoding_Letters
(Wide_Character_Encoding_Method
);
3233 -- If no main program, and not specified, set brackets, we really have
3234 -- no better choice. If some other encoding is required when there is
3235 -- no main, it must be set explicitly using -Wx.
3237 -- Note: if the ALI file always passed the wide character encoding of
3238 -- every file, then we could use the encoding of the initial specified
3239 -- file, but this information is passed only for potential main
3240 -- programs. We could fix this sometime, but it is a very minor point
3241 -- (wide character default encoding for [Wide_[Wide_]]Text_IO when there
3242 -- is no main program).
3244 elsif No_Main_Subprogram
then
3247 -- Otherwise if there is a main program, take encoding from it
3250 return ALIs
.Table
(ALIs
.First
).WC_Encoding
;
3252 end Get_WC_Encoding
;
3258 function Has_Finalizer
(Elab_Order
: Unit_Id_Array
) return Boolean is
3263 for E
in reverse Elab_Order
'Range loop
3264 Unum
:= Elab_Order
(E
);
3265 U
:= Units
.Table
(Unum
);
3267 -- We are only interested in non-generic packages
3269 if U
.Unit_Kind
= 'p'
3270 and then U
.Has_Finalizer
3271 and then not U
.Is_Generic
3272 and then not U
.No_Elab
3285 function Hash
(Nam
: Name_Id
) return Header_Num
is
3287 return Int
(Nam
- Names_Low_Bound
) rem Header_Num
'Last;
3290 ----------------------
3291 -- Lt_Linker_Option --
3292 ----------------------
3294 function Lt_Linker_Option
(Op1
: Natural; Op2
: Natural) return Boolean is
3296 -- Sort internal files last
3298 if Linker_Options
.Table
(Op1
).Internal_File
3300 Linker_Options
.Table
(Op2
).Internal_File
3302 -- Note: following test uses False < True
3304 return Linker_Options
.Table
(Op1
).Internal_File
3306 Linker_Options
.Table
(Op2
).Internal_File
;
3308 -- If both internal or both non-internal, sort according to the
3309 -- elaboration position. A unit that is elaborated later should come
3310 -- earlier in the linker options list.
3313 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
3315 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
3317 end Lt_Linker_Option
;
3319 ------------------------
3320 -- Move_Linker_Option --
3321 ------------------------
3323 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
3325 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
3326 end Move_Linker_Option
;
3328 ----------------------------
3329 -- Resolve_Binder_Options --
3330 ----------------------------
3332 procedure Resolve_Binder_Options
(Elab_Order
: Unit_Id_Array
) is
3333 procedure Check_Package
(Var
: in out Boolean; Name
: String);
3334 -- Set Var to true iff the current identifier in Namet is Name. Do
3335 -- nothing if it doesn't match. This procedure is just a helper to
3336 -- avoid explicitly dealing with length.
3342 procedure Check_Package
(Var
: in out Boolean; Name
: String) is
3344 if Name_Len
= Name
'Length
3345 and then Name_Buffer
(1 .. Name_Len
) = Name
3351 -- Start of processing for Resolve_Binder_Options
3354 for E
in Elab_Order
'Range loop
3355 Get_Name_String
(Units
.Table
(Elab_Order
(E
)).Uname
);
3357 -- This is not a perfect approach, but is the current protocol
3358 -- between the run-time and the binder to indicate that tasking is
3359 -- used: System.OS_Interface should always be used by any tasking
3362 Check_Package
(With_GNARL
, "system.os_interface%s");
3364 -- Ditto for the use of restricted tasking
3367 (System_Tasking_Restricted_Stages_Used
,
3368 "system.tasking.restricted.stages%s");
3370 -- Ditto for the use of interrupts
3372 Check_Package
(System_Interrupts_Used
, "system.interrupts%s");
3374 -- Ditto for the use of dispatching domains
3377 (Dispatching_Domains_Used
,
3378 "system.multiprocessors.dispatching_domains%s");
3380 -- Ditto for the use of restrictions
3382 Check_Package
(System_Restrictions_Used
, "system.restrictions%s");
3384 -- Ditto for use of an SMP bareboard runtime
3386 Check_Package
(System_BB_CPU_Primitives_Multiprocessors_Used
,
3387 "system.bb.cpu_primitives.multiprocessors%s");
3389 -- Ditto for System.Version_Control, which is used for Version and
3390 -- Body_Version attributes.
3392 Check_Package
(System_Version_Control_Used
,
3393 "system.version_control%s");
3395 end Resolve_Binder_Options
;
3401 procedure Set_Bind_Env
(Key
, Value
: String) is
3403 -- The lengths of Key and Value are stored as single bytes
3405 if Key
'Length > 255 then
3406 Osint
.Fail
("bind environment key """ & Key
& """ too long");
3409 if Value
'Length > 255 then
3410 Osint
.Fail
("bind environment value """ & Value
& """ too long");
3413 Bind_Environment
.Set
(Name_Find
(Key
), Name_Find
(Value
));
3420 procedure Set_Boolean
(B
: Boolean) is
3421 False_Str
: constant String := "False";
3422 True_Str
: constant String := "True";
3426 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ True_Str
'Length) :=
3428 Stm_Last
:= Stm_Last
+ True_Str
'Length;
3430 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ False_Str
'Length) :=
3432 Stm_Last
:= Stm_Last
+ False_Str
'Length;
3440 procedure Set_Char
(C
: Character) is
3442 Stm_Last
:= Stm_Last
+ 1;
3443 Statement_Buffer
(Stm_Last
) := C
;
3450 procedure Set_Int
(N
: Int
) is
3461 Stm_Last
:= Stm_Last
+ 1;
3462 Statement_Buffer
(Stm_Last
) :=
3463 Character'Val (N
mod 10 + Character'Pos ('0'));
3467 -------------------------
3468 -- Set_IS_Pragma_Table --
3469 -------------------------
3471 procedure Set_IS_Pragma_Table
is
3473 for F
in ALIs
.First
.. ALIs
.Last
loop
3474 for K
in ALIs
.Table
(F
).First_Interrupt_State
..
3475 ALIs
.Table
(F
).Last_Interrupt_State
3478 Inum
: constant Int
:=
3479 Interrupt_States
.Table
(K
).Interrupt_Id
;
3480 Stat
: constant Character :=
3481 Interrupt_States
.Table
(K
).Interrupt_State
;
3484 while IS_Pragma_Settings
.Last
< Inum
loop
3485 IS_Pragma_Settings
.Append
('n');
3488 IS_Pragma_Settings
.Table
(Inum
) := Stat
;
3492 end Set_IS_Pragma_Table
;
3494 ---------------------------
3495 -- Set_Main_Program_Name --
3496 ---------------------------
3498 procedure Set_Main_Program_Name
is
3500 -- Note that name has %b on the end which we ignore
3502 -- First we output the initial _ada_ since we know that the main program
3503 -- is a library level subprogram.
3505 Set_String
("_ada_");
3507 -- Copy name, changing dots to double underscores
3509 for J
in 1 .. Name_Len
- 2 loop
3510 if Name_Buffer
(J
) = '.' then
3513 Set_Char
(Name_Buffer
(J
));
3516 end Set_Main_Program_Name
;
3518 ---------------------
3519 -- Set_Name_Buffer --
3520 ---------------------
3522 procedure Set_Name_Buffer
is
3524 for J
in 1 .. Name_Len
loop
3525 Set_Char
(Name_Buffer
(J
));
3527 end Set_Name_Buffer
;
3529 -------------------------
3530 -- Set_PSD_Pragma_Table --
3531 -------------------------
3533 procedure Set_PSD_Pragma_Table
is
3535 for F
in ALIs
.First
.. ALIs
.Last
loop
3536 for K
in ALIs
.Table
(F
).First_Specific_Dispatching
..
3537 ALIs
.Table
(F
).Last_Specific_Dispatching
3540 DTK
: Specific_Dispatching_Record
3541 renames Specific_Dispatching
.Table
(K
);
3544 while PSD_Pragma_Settings
.Last
< DTK
.Last_Priority
loop
3545 PSD_Pragma_Settings
.Append
('F');
3548 for Prio
in DTK
.First_Priority
.. DTK
.Last_Priority
loop
3549 PSD_Pragma_Settings
.Table
(Prio
) := DTK
.Dispatching_Policy
;
3554 end Set_PSD_Pragma_Table
;
3560 procedure Set_String
(S
: String) is
3562 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ S
'Length) := S
;
3563 Stm_Last
:= Stm_Last
+ S
'Length;
3566 ------------------------
3567 -- Set_String_Replace --
3568 ------------------------
3570 procedure Set_String_Replace
(S
: String) is
3572 Statement_Buffer
(Stm_Last
- S
'Length + 1 .. Stm_Last
) := S
;
3573 end Set_String_Replace
;
3579 procedure Set_Unit_Name
is
3581 for J
in 1 .. Name_Len
- 2 loop
3582 if Name_Buffer
(J
) = '.' then
3585 Set_Char
(Name_Buffer
(J
));
3590 ---------------------
3591 -- Set_Unit_Number --
3592 ---------------------
3594 procedure Set_Unit_Number
(U
: Unit_Id
) is
3595 Num_Units
: constant Nat
:= Nat
(Units
.Last
) - Nat
(Unit_Id
'First);
3596 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
3599 if Num_Units
>= 10 and then Unum
< 10 then
3603 if Num_Units
>= 100 and then Unum
< 100 then
3608 end Set_Unit_Number
;
3610 ---------------------
3611 -- Write_Bind_Line --
3612 ---------------------
3614 procedure Write_Bind_Line
(S
: String) is
3616 -- Need to strip trailing LF from S
3618 WBI
(S
(S
'First .. S
'Last - 1));
3619 end Write_Bind_Line
;
3621 ----------------------------
3622 -- Write_Statement_Buffer --
3623 ----------------------------
3625 procedure Write_Statement_Buffer
is
3627 WBI
(Statement_Buffer
(1 .. Stm_Last
));
3629 end Write_Statement_Buffer
;
3631 procedure Write_Statement_Buffer
(S
: String) is
3634 Write_Statement_Buffer
;
3635 end Write_Statement_Buffer
;