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
696 -- Generate the default-sized secondary stack pool if the secondary
697 -- stack is used by the program.
699 if Sec_Stack_Used
then
700 -- Elaborate the body of the binder to initialize the default-
701 -- sized secondary stack pool.
704 WBI
(" " & Get_Ada_Main_Name
& "'Elab_Body;");
706 -- Generate the default-sized secondary stack pool and set the
707 -- related secondary stack globals.
709 Set_String
(" Default_Secondary_Stack_Size := ");
711 if Opt
.Default_Sec_Stack_Size
/= Opt
.No_Stack_Size
then
712 Set_Int
(Opt
.Default_Sec_Stack_Size
);
715 ("System.Parameters.Runtime_Default_Sec_Stack_Size");
719 Write_Statement_Buffer
;
721 Set_String
(" Binder_Sec_Stacks_Count := ");
722 Set_Int
(Num_Sec_Stacks
);
724 Write_Statement_Buffer
;
726 WBI
(" Default_Sized_SS_Pool := " &
727 "Sec_Default_Sized_Stacks'Address;");
731 -- Normal case (standard library not suppressed). Set all global values
732 -- used by the run time.
735 WBI
(" Main_Priority : Integer;");
736 WBI
(" pragma Import (C, Main_Priority, " &
737 """__gl_main_priority"");");
738 WBI
(" Time_Slice_Value : Integer;");
739 WBI
(" pragma Import (C, Time_Slice_Value, " &
740 """__gl_time_slice_val"");");
741 WBI
(" WC_Encoding : Character;");
742 WBI
(" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
743 WBI
(" Locking_Policy : Character;");
744 WBI
(" pragma Import (C, Locking_Policy, " &
745 """__gl_locking_policy"");");
746 WBI
(" Queuing_Policy : Character;");
747 WBI
(" pragma Import (C, Queuing_Policy, " &
748 """__gl_queuing_policy"");");
749 WBI
(" Task_Dispatching_Policy : Character;");
750 WBI
(" pragma Import (C, Task_Dispatching_Policy, " &
751 """__gl_task_dispatching_policy"");");
752 WBI
(" Priority_Specific_Dispatching : System.Address;");
753 WBI
(" pragma Import (C, Priority_Specific_Dispatching, " &
754 """__gl_priority_specific_dispatching"");");
755 WBI
(" Num_Specific_Dispatching : Integer;");
756 WBI
(" pragma Import (C, Num_Specific_Dispatching, " &
757 """__gl_num_specific_dispatching"");");
758 WBI
(" Main_CPU : Integer;");
759 WBI
(" pragma Import (C, Main_CPU, " &
760 """__gl_main_cpu"");");
762 WBI
(" Interrupt_States : System.Address;");
763 WBI
(" pragma Import (C, Interrupt_States, " &
764 """__gl_interrupt_states"");");
765 WBI
(" Num_Interrupt_States : Integer;");
766 WBI
(" pragma Import (C, Num_Interrupt_States, " &
767 """__gl_num_interrupt_states"");");
768 WBI
(" Unreserve_All_Interrupts : Integer;");
769 WBI
(" pragma Import (C, Unreserve_All_Interrupts, " &
770 """__gl_unreserve_all_interrupts"");");
772 if Exception_Tracebacks
or Exception_Tracebacks_Symbolic
then
773 WBI
(" Exception_Tracebacks : Integer;");
774 WBI
(" pragma Import (C, Exception_Tracebacks, " &
775 """__gl_exception_tracebacks"");");
777 if Exception_Tracebacks_Symbolic
then
778 WBI
(" Exception_Tracebacks_Symbolic : Integer;");
779 WBI
(" pragma Import (C, Exception_Tracebacks_Symbolic, " &
780 """__gl_exception_tracebacks_symbolic"");");
784 WBI
(" Detect_Blocking : Integer;");
785 WBI
(" pragma Import (C, Detect_Blocking, " &
786 """__gl_detect_blocking"");");
787 WBI
(" Default_Stack_Size : Integer;");
788 WBI
(" pragma Import (C, Default_Stack_Size, " &
789 """__gl_default_stack_size"");");
791 if Sec_Stack_Used
then
792 WBI
(" Default_Secondary_Stack_Size : " &
793 "System.Parameters.Size_Type;");
794 WBI
(" pragma Import (C, Default_Secondary_Stack_Size, " &
795 """__gnat_default_ss_size"");");
798 if Leap_Seconds_Support
then
799 WBI
(" Leap_Seconds_Support : Integer;");
800 WBI
(" pragma Import (C, Leap_Seconds_Support, " &
801 """__gl_leap_seconds_support"");");
804 WBI
(" Bind_Env_Addr : System.Address;");
805 WBI
(" pragma Import (C, Bind_Env_Addr, " &
806 """__gl_bind_env_addr"");");
809 WBI
(" XDR_Stream : Integer;");
810 WBI
(" pragma Import (C, XDR_Stream, ""__gl_xdr_stream"");");
813 -- Import entry point for elaboration time signal handler
814 -- installation, and indication of if it's been called previously.
817 WBI
(" procedure Runtime_Initialize " &
818 "(Install_Handler : Integer);");
819 WBI
(" pragma Import (C, Runtime_Initialize, " &
820 """__gnat_runtime_initialize"");");
822 -- Import handlers attach procedure for sequential elaboration policy
824 if System_Interrupts_Used
825 and then Partition_Elaboration_Policy_Specified
= 'S'
827 WBI
(" procedure Install_Restricted_Handlers_Sequential;");
828 WBI
(" pragma Import (C," &
829 "Install_Restricted_Handlers_Sequential," &
830 " ""__gnat_attach_all_handlers"");");
834 -- Import task activation procedure for sequential elaboration
837 if System_Tasking_Restricted_Stages_Used
838 and then Partition_Elaboration_Policy_Specified
= 'S'
840 WBI
(" Partition_Elaboration_Policy : Character;");
841 WBI
(" pragma Import (C, Partition_Elaboration_Policy," &
842 " ""__gnat_partition_elaboration_policy"");");
844 WBI
(" procedure Activate_All_Tasks_Sequential;");
845 WBI
(" pragma Import (C, Activate_All_Tasks_Sequential," &
846 " ""__gnat_activate_all_tasks"");");
849 -- Import procedure to start slave cpus for bareboard runtime
851 if System_BB_CPU_Primitives_Multiprocessors_Used
then
852 WBI
(" procedure Start_Slave_CPUs;");
853 WBI
(" pragma Import (C, Start_Slave_CPUs," &
854 " ""__gnat_start_slave_cpus"");");
857 -- For restricted run-time libraries (ZFP and Ravenscar)
858 -- tasks are non-terminating, so we do not want finalization.
860 if not Configurable_Run_Time_On_Target
then
862 WBI
(" Finalize_Library_Objects : No_Param_Proc;");
863 WBI
(" pragma Import (C, Finalize_Library_Objects, " &
864 """__gnat_finalize_library_objects"");");
867 -- Initialize stack limit variable of the environment task if the
868 -- stack check method is stack limit and stack check is enabled.
870 if Stack_Check_Limits_On_Target
871 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
874 WBI
(" procedure Initialize_Stack_Limit;");
875 WBI
(" pragma Import (C, Initialize_Stack_Limit, " &
876 """__gnat_initialize_stack_limit"");");
879 -- When dispatching domains are used then we need to signal it
880 -- before calling the main procedure.
882 if Dispatching_Domains_Used
then
883 WBI
(" procedure Freeze_Dispatching_Domains;");
884 WBI
(" pragma Import");
885 WBI
(" (Ada, Freeze_Dispatching_Domains, "
886 & """__gnat_freeze_dispatching_domains"");");
889 -- Secondary stack global variables
891 WBI
(" Binder_Sec_Stacks_Count : Natural;");
892 WBI
(" pragma Import (Ada, Binder_Sec_Stacks_Count, " &
893 """__gnat_binder_ss_count"");");
895 WBI
(" Default_Sized_SS_Pool : System.Address;");
896 WBI
(" pragma Import (Ada, Default_Sized_SS_Pool, " &
897 """__gnat_default_ss_pool"");");
901 -- Start of processing for Adainit
904 WBI
(" if Is_Elaborated then");
907 WBI
(" Is_Elaborated := True;");
909 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
910 -- restriction No_Standard_Allocators_After_Elaboration is active.
912 if Cumulative_Restrictions
.Set
913 (No_Standard_Allocators_After_Elaboration
)
915 WBI
(" System.Elaboration_Allocators."
916 & "Mark_Start_Of_Elaboration;");
919 -- Generate assignments to initialize globals
921 Set_String
(" Main_Priority := ");
922 Set_Int
(Main_Priority
);
924 Write_Statement_Buffer
;
926 Set_String
(" Time_Slice_Value := ");
928 if Task_Dispatching_Policy_Specified
= 'F'
929 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
933 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
937 Write_Statement_Buffer
;
939 Set_String
(" WC_Encoding := '");
940 Set_Char
(Get_WC_Encoding
);
943 Write_Statement_Buffer
;
945 Set_String
(" Locking_Policy := '");
946 Set_Char
(Locking_Policy_Specified
);
948 Write_Statement_Buffer
;
950 Set_String
(" Queuing_Policy := '");
951 Set_Char
(Queuing_Policy_Specified
);
953 Write_Statement_Buffer
;
955 Set_String
(" Task_Dispatching_Policy := '");
956 Set_Char
(Task_Dispatching_Policy_Specified
);
958 Write_Statement_Buffer
;
960 if System_Tasking_Restricted_Stages_Used
961 and then Partition_Elaboration_Policy_Specified
= 'S'
963 Set_String
(" Partition_Elaboration_Policy := '");
964 Set_Char
(Partition_Elaboration_Policy_Specified
);
966 Write_Statement_Buffer
;
971 WBI
(" Priority_Specific_Dispatching :=");
972 WBI
(" Local_Priority_Specific_Dispatching'Address;");
974 Set_String
(" Num_Specific_Dispatching := ");
975 Set_Int
(PSD_Pragma_Settings
.Last
+ 1);
977 Write_Statement_Buffer
;
979 Set_String
(" Main_CPU := ");
982 Write_Statement_Buffer
;
984 WBI
(" Interrupt_States := Local_Interrupt_States'Address;");
986 Set_String
(" Num_Interrupt_States := ");
987 Set_Int
(IS_Pragma_Settings
.Last
+ 1);
989 Write_Statement_Buffer
;
991 Set_String
(" Unreserve_All_Interrupts := ");
993 if Unreserve_All_Interrupts_Specified
then
1000 Write_Statement_Buffer
;
1002 if Exception_Tracebacks
or Exception_Tracebacks_Symbolic
then
1003 WBI
(" Exception_Tracebacks := 1;");
1005 if Exception_Tracebacks_Symbolic
then
1006 WBI
(" Exception_Tracebacks_Symbolic := 1;");
1010 Set_String
(" Detect_Blocking := ");
1012 if Detect_Blocking
then
1019 Write_Statement_Buffer
;
1021 Set_String
(" Default_Stack_Size := ");
1022 Set_Int
(Default_Stack_Size
);
1024 Write_Statement_Buffer
;
1026 if Leap_Seconds_Support
then
1027 WBI
(" Leap_Seconds_Support := 1;");
1031 WBI
(" XDR_Stream := 1;");
1034 if Bind_Env_String_Built
then
1035 WBI
(" Bind_Env_Addr := Bind_Env'Address;");
1040 -- Generate default-sized secondary stack pool and set secondary
1043 if Sec_Stack_Used
then
1045 -- Elaborate the body of the binder to initialize the default-
1046 -- sized secondary stack pool.
1048 WBI
(" " & Get_Ada_Main_Name
& "'Elab_Body;");
1050 -- Generate the default-sized secondary stack pool and set the
1051 -- related secondary stack globals.
1053 Set_String
(" Default_Secondary_Stack_Size := ");
1055 if Opt
.Default_Sec_Stack_Size
/= Opt
.No_Stack_Size
then
1056 Set_Int
(Opt
.Default_Sec_Stack_Size
);
1058 Set_String
("System.Parameters.Runtime_Default_Sec_Stack_Size");
1062 Write_Statement_Buffer
;
1064 Set_String
(" Binder_Sec_Stacks_Count := ");
1065 Set_Int
(Num_Sec_Stacks
);
1067 Write_Statement_Buffer
;
1069 Set_String
(" Default_Sized_SS_Pool := ");
1071 if Num_Sec_Stacks
> 0 then
1072 Set_String
("Sec_Default_Sized_Stacks'Address;");
1074 Set_String
("System.Null_Address;");
1077 Write_Statement_Buffer
;
1081 -- Generate call to Runtime_Initialize
1083 WBI
(" Runtime_Initialize (1);");
1086 -- Generate call to set Initialize_Scalar values if active
1088 if Initialize_Scalars_Used
then
1090 Set_String
(" System.Scalar_Values.Initialize ('");
1091 Set_Char
(Initialize_Scalars_Mode1
);
1092 Set_String
("', '");
1093 Set_Char
(Initialize_Scalars_Mode2
);
1095 Write_Statement_Buffer
;
1098 -- Initialize stack limit variable of the environment task if the stack
1099 -- check method is stack limit and stack check is enabled.
1101 if Stack_Check_Limits_On_Target
1102 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
1105 WBI
(" Initialize_Stack_Limit;");
1108 -- On CodePeer, the finalization of library objects is not relevant
1110 if CodePeer_Mode
then
1113 -- If this is the main program case, attach finalize_library to the soft
1114 -- link. Do it only when not using a restricted run time, in which case
1115 -- tasks are non-terminating, so we do not want library-level
1118 elsif not Bind_For_Library
1119 and then not Configurable_Run_Time_On_Target
1120 and then not Suppress_Standard_Library_On_Target
1124 if Lib_Final_Built
then
1125 Set_String
(" Finalize_Library_Objects := ");
1126 Set_String
("finalize_library'access;");
1128 Set_String
(" Finalize_Library_Objects := null;");
1131 Write_Statement_Buffer
;
1134 -- Generate elaboration calls
1136 if not CodePeer_Mode
then
1142 Gen_Elab_Calls
(Elab_Order
);
1144 if not CodePeer_Mode
then
1146 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
1147 -- restriction No_Standard_Allocators_After_Elaboration is active.
1149 if Cumulative_Restrictions
.Set
1150 (No_Standard_Allocators_After_Elaboration
)
1153 (" System.Elaboration_Allocators.Mark_End_Of_Elaboration;");
1156 -- From this point, no new dispatching domain can be created
1158 if Dispatching_Domains_Used
then
1159 WBI
(" Freeze_Dispatching_Domains;");
1162 -- Sequential partition elaboration policy
1164 if Partition_Elaboration_Policy_Specified
= 'S' then
1165 if System_Interrupts_Used
then
1166 WBI
(" Install_Restricted_Handlers_Sequential;");
1169 if System_Tasking_Restricted_Stages_Used
then
1170 WBI
(" Activate_All_Tasks_Sequential;");
1174 if System_BB_CPU_Primitives_Multiprocessors_Used
then
1175 WBI
(" Start_Slave_CPUs;");
1179 WBI
(" end " & Ada_Init_Name
.all & ";");
1183 -------------------------
1184 -- Gen_Bind_Env_String --
1185 -------------------------
1187 procedure Gen_Bind_Env_String
is
1188 procedure Write_Name_With_Len
(Nam
: Name_Id
);
1189 -- Write Nam as a string literal, prefixed with one
1190 -- character encoding Nam's length.
1192 -------------------------
1193 -- Write_Name_With_Len --
1194 -------------------------
1196 procedure Write_Name_With_Len
(Nam
: Name_Id
) is
1198 Get_Name_String
(Nam
);
1199 Write_Str
("Character'Val (");
1200 Write_Int
(Int
(Name_Len
));
1201 Write_Str
(") & """);
1202 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1204 end Write_Name_With_Len
;
1208 First
: Boolean := True;
1209 KN
: Name_Id
:= No_Name
;
1210 VN
: Name_Id
:= No_Name
;
1212 -- Start of processing for Gen_Bind_Env_String
1215 Bind_Environment
.Get_First
(KN
, VN
);
1217 if VN
= No_Name
then
1221 Set_Special_Output
(Write_Bind_Line
'Access);
1223 WBI
(" Bind_Env : aliased constant String :=");
1225 while VN
/= No_Name
loop
1232 Write_Name_With_Len
(KN
);
1234 Write_Name_With_Len
(VN
);
1237 Bind_Environment
.Get_Next
(KN
, VN
);
1241 WBI
(" & ASCII.NUL;");
1243 Cancel_Special_Output
;
1244 Bind_Env_String_Built
:= True;
1245 end Gen_Bind_Env_String
;
1251 procedure Gen_CUDA_Defs
is
1252 Unit_Name
: constant String :=
1253 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1254 Unit
: constant String :=
1255 Unit_Name
(Unit_Name
'First .. Unit_Name
'Last - 2);
1257 if not Enable_CUDA_Expansion
then
1264 WBI
(" procedure CUDA_Register_Function");
1265 WBI
(" (Fat_Binary_Handle : System.Address;");
1266 WBI
(" Func : System.Address;");
1267 WBI
(" Kernel_Name : Interfaces.C.Strings.chars_ptr;");
1268 WBI
(" Kernel_Name_2 : Interfaces.C.Strings.chars_ptr;");
1269 WBI
(" Minus_One : Integer;");
1270 WBI
(" Nullptr1 : System.Address;");
1271 WBI
(" Nullptr2 : System.Address;");
1272 WBI
(" Nullptr3 : System.Address;");
1273 WBI
(" Nullptr4 : System.Address;");
1274 WBI
(" Nullptr5 : System.Address);");
1275 WBI
(" pragma Import");
1276 WBI
(" (Convention => C,");
1277 WBI
(" Entity => CUDA_Register_Function,");
1278 WBI
(" External_Name => ""__cudaRegisterFunction"");");
1280 WBI
(" function CUDA_Register_Fat_Binary");
1281 WBI
(" (Fat_Binary : System.Address)");
1282 WBI
(" return System.Address;");
1283 WBI
(" pragma Import");
1284 WBI
(" (Convention => C,");
1285 WBI
(" Entity => CUDA_Register_Fat_Binary,");
1286 WBI
(" External_Name => ""__cudaRegisterFatBinary"");");
1288 WBI
(" procedure CUDA_Register_Fat_Binary_End");
1289 WBI
(" (Fat_Binary : System.Address);");
1290 WBI
(" pragma Import");
1291 WBI
(" (Convention => C,");
1292 WBI
(" Entity => CUDA_Register_Fat_Binary_End,");
1293 WBI
(" External_Name => ""__cudaRegisterFatBinaryEnd"");");
1295 WBI
(" type Fatbin_Wrapper is record");
1296 WBI
(" Magic : Interfaces.C.int;");
1297 WBI
(" Version : Interfaces.C.int;");
1298 WBI
(" Data : System.Address;");
1299 WBI
(" Filename_Or_Fatbins : System.Address;");
1300 WBI
(" end record;");
1302 WBI
(" Fat_Binary : System.Address;");
1303 WBI
(" pragma Import");
1304 WBI
(" (Convention => C,");
1305 WBI
(" Entity => Fat_Binary,");
1306 WBI
(" External_Name => ""_binary_" & Unit
& "_fatbin_start"");");
1308 WBI
(" Wrapper : Fatbin_Wrapper :=");
1309 WBI
(" (16#466243b1#,");
1311 WBI
(" Fat_Binary'Address,");
1312 WBI
(" System.Null_Address);");
1314 WBI
(" Fat_Binary_Handle : System.Address;");
1317 for K
in CUDA_Kernels
.First
.. CUDA_Kernels
.Last
loop
1319 K_String
: constant String := CUDA_Kernel_Id
'Image (K
);
1320 N
: constant String :=
1321 K_String
(K_String
'First + 1 .. K_String
'Last);
1322 Kernel_Symbol
: constant String := "Kernel_" & N
;
1323 -- K_Symbol is a unique identifier used to derive all symbol names
1324 -- related to kernel K.
1326 Kernel_Proc
: constant String := Kernel_Symbol
& "_Proc";
1327 -- Kernel_Proc is the name of the symbol representing the
1328 -- host-side procedure of the kernel. The address is
1329 -- pragma-imported and then used while registering the kernel with
1330 -- the CUDA runtime.
1331 Kernel_String
: constant String := Kernel_Symbol
& "_String";
1332 -- Kernel_String is the name of the C-string containing the name
1333 -- of the kernel. It is used for registering the kernel with the
1335 Kernel_Name
: constant String :=
1336 Get_Name_String
(CUDA_Kernels
.Table
(K
).Kernel_Name
);
1337 -- Kernel_Name is the name of the kernel, after package expansion.
1340 -- Import host-side kernel address.
1341 WBI
(" procedure " & Kernel_Proc
& ";");
1342 WBI
(" pragma Import");
1343 WBI
(" (Convention => C,");
1344 WBI
(" Entity => " & Kernel_Proc
& ",");
1345 WBI
(" External_Name => """ & Kernel_Name
& """);");
1348 -- Generate C-string containing name of kernel.
1350 (" " & Kernel_String
& " : Interfaces.C.Strings.Chars_Ptr;");
1356 WBI
(" procedure " & Device_Ada_Init_Subp_Name
& ";");
1357 WBI
(" pragma Export (C, " & Device_Ada_Init_Subp_Name
&
1358 ", Link_Name => """ & Device_Ada_Init_Link_Name
& """);");
1360 -- C-string declaration for adainit
1361 WBI
(" " & Adainit_String_Obj_Name
1362 & " : Interfaces.C.Strings.Chars_Ptr;");
1372 procedure Gen_CUDA_Init
is
1373 -- Generate call to register one function
1374 procedure Gen_CUDA_Register_Function_Call
1375 (Kernel_Name
: String;
1376 Kernel_String
: String;
1377 Kernel_Proc
: String);
1379 -------------------------------------
1380 -- Gen_CUDA_Register_Function_Call --
1381 -------------------------------------
1383 procedure Gen_CUDA_Register_Function_Call
1384 (Kernel_Name
: String;
1385 Kernel_String
: String;
1386 Kernel_Proc
: String) is
1388 WBI
(" " & Kernel_String
& " :=");
1389 WBI
(" Interfaces.C.Strings.New_Char_Array ("""
1393 -- Generate call to CUDA runtime to register function.
1394 WBI
(" CUDA_Register_Function (");
1395 WBI
(" Fat_Binary_Handle, ");
1396 WBI
(" " & Kernel_Proc
& "'Address,");
1397 WBI
(" " & Kernel_String
& ",");
1398 WBI
(" " & Kernel_String
& ",");
1400 WBI
(" System.Null_Address,");
1401 WBI
(" System.Null_Address,");
1402 WBI
(" System.Null_Address,");
1403 WBI
(" System.Null_Address,");
1404 WBI
(" System.Null_Address);");
1406 end Gen_CUDA_Register_Function_Call
;
1409 if not Enable_CUDA_Expansion
then
1413 WBI
(" Fat_Binary_Handle :=");
1414 WBI
(" CUDA_Register_Fat_Binary (Wrapper'Address);");
1416 for K
in CUDA_Kernels
.First
.. CUDA_Kernels
.Last
loop
1418 K_String
: constant String := CUDA_Kernel_Id
'Image (K
);
1419 N
: constant String :=
1420 K_String
(K_String
'First + 1 .. K_String
'Last);
1421 Kernel_Symbol
: constant String := "Kernel_" & N
;
1422 -- K_Symbol is a unique identifier used to derive all symbol names
1423 -- related to kernel K.
1425 Kernel_Proc
: constant String := Kernel_Symbol
& "_Proc";
1426 -- Kernel_Proc is the name of the symbol representing the
1427 -- host-side procedure of the kernel. The address is
1428 -- pragma-imported and then used while registering the kernel with
1429 -- the CUDA runtime.
1430 Kernel_String
: constant String := Kernel_Symbol
& "_String";
1431 -- Kernel_String is the name of the C-string containing the name
1432 -- of the kernel. It is used for registering the kernel with the
1434 Kernel_Name
: constant String :=
1435 Get_Name_String
(CUDA_Kernels
.Table
(K
).Kernel_Name
);
1436 -- Kernel_Name is the name of the kernel, after package expansion.
1438 Gen_CUDA_Register_Function_Call
1439 (Kernel_Name
=> Kernel_Name
,
1440 Kernel_String
=> Kernel_String
,
1441 Kernel_Proc
=> Kernel_Proc
);
1445 -- Register device-side Adainit
1446 Gen_CUDA_Register_Function_Call
1447 (Kernel_Name
=> Device_Ada_Init_Link_Name
,
1448 Kernel_String
=> Adainit_String_Obj_Name
,
1449 Kernel_Proc
=> Device_Ada_Init_Subp_Name
);
1451 WBI
(" CUDA_Register_Fat_Binary_End (Fat_Binary_Handle);");
1453 -- perform device (as opposed to host) elaboration
1454 WBI
(" pragma CUDA_Execute (" &
1455 Device_Ada_Init_Subp_Name
& ", 1, 1);");
1458 --------------------------
1459 -- Gen_CodePeer_Wrapper --
1460 --------------------------
1462 procedure Gen_CodePeer_Wrapper
is
1463 Callee_Name
: constant String := "Ada_Main_Program";
1466 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1467 WBI
(" procedure " & CodePeer_Wrapper_Name
& " is ");
1469 WBI
(" " & Callee_Name
& ";");
1472 WBI
(" function " & CodePeer_Wrapper_Name
& " return Integer is");
1474 WBI
(" return " & Callee_Name
& ";");
1477 WBI
(" end " & CodePeer_Wrapper_Name
& ";");
1479 end Gen_CodePeer_Wrapper
;
1481 --------------------
1482 -- Gen_Elab_Calls --
1483 --------------------
1485 procedure Gen_Elab_Calls
(Elab_Order
: Unit_Id_Array
) is
1486 Check_Elab_Flag
: Boolean;
1489 -- Loop through elaboration order entries
1491 for E
in Elab_Order
'Range loop
1493 Unum
: constant Unit_Id
:= Elab_Order
(E
);
1494 U
: Unit_Record
renames Units
.Table
(Unum
);
1496 Unum_Spec
: Unit_Id
;
1497 -- This is the unit number of the spec that corresponds to
1498 -- this entry. It is the same as Unum except when the body
1499 -- and spec are different and we are currently processing
1500 -- the body, in which case it is the spec (Unum + 1).
1503 if U
.Utype
= Is_Body
then
1504 Unum_Spec
:= Unum
+ 1;
1509 -- Nothing to do if predefined unit in no run time mode
1511 if No_Run_Time_Mode
and then Is_Predefined_File_Name
(U
.Sfile
) then
1514 -- Likewise if this is an interface to a stand alone library
1516 elsif U
.SAL_Interface
then
1519 -- Case of no elaboration code
1523 -- In CodePeer mode, we special case subprogram bodies which
1524 -- are handled in the 'else' part below, and lead to a call
1525 -- to <subp>'Elab_Subp_Body.
1527 and then (not CodePeer_Mode
1531 or else U
.Utype
= Is_Spec
1532 or else U
.Utype
= Is_Spec_Only
1533 or else U
.Unit_Kind
/= 's')
1535 -- In the case of a body with a separate spec, where the
1536 -- separate spec has an elaboration entity defined, this is
1537 -- where we increment the elaboration entity if one exists.
1539 -- Likewise for lone specs with an elaboration entity defined
1540 -- despite No_Elaboration_Code, e.g. when requested to preserve
1543 if (U
.Utype
= Is_Body
or else U
.Utype
= Is_Spec_Only
)
1544 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1545 and then not CodePeer_Mode
1548 Set_Unit_Number
(Unum_Spec
);
1549 Set_String
(" := E");
1550 Set_Unit_Number
(Unum_Spec
);
1551 Set_String
(" + 1;");
1552 Write_Statement_Buffer
;
1555 -- Here if elaboration code is present. If binding a library
1556 -- or if there is a non-Ada main subprogram then we generate:
1558 -- if uname_E = 0 then
1559 -- uname'elab_[spec|body];
1561 -- uname_E := uname_E + 1;
1563 -- Otherwise, elaboration routines are called unconditionally:
1565 -- uname'elab_[spec|body];
1566 -- uname_E := uname_E + 1;
1568 -- The uname_E increment is skipped if this is a separate spec,
1569 -- since it will be done when we process the body.
1571 -- In CodePeer mode, we do not generate any reference to xxx_E
1572 -- variables, only calls to 'Elab* subprograms.
1575 -- Check incompatibilities with No_Multiple_Elaboration
1577 if not CodePeer_Mode
1578 and then Cumulative_Restrictions
.Set
(No_Multiple_Elaboration
)
1580 -- Force_Checking_Of_Elaboration_Flags (-F) not allowed
1582 if Force_Checking_Of_Elaboration_Flags
then
1584 ("-F (force elaboration checks) switch not allowed "
1585 & "with restriction No_Multiple_Elaboration active");
1587 -- Interfacing of libraries not allowed
1589 elsif Interface_Library_Unit
then
1591 ("binding of interfaced libraries not allowed "
1592 & "with restriction No_Multiple_Elaboration active");
1594 -- Non-Ada main program not allowed
1596 elsif not Bind_Main_Program
then
1598 ("non-Ada main program not allowed "
1599 & "with restriction No_Multiple_Elaboration active");
1603 -- OK, see if we need to test elaboration flag
1606 Units
.Table
(Unum_Spec
).Set_Elab_Entity
1607 and then Check_Elaboration_Flags
1608 and then not CodePeer_Mode
1609 and then (Force_Checking_Of_Elaboration_Flags
1610 or Interface_Library_Unit
1611 or not Bind_Main_Program
);
1613 if Check_Elab_Flag
then
1614 Set_String
(" if E");
1615 Set_Unit_Number
(Unum_Spec
);
1616 Set_String
(" = 0 then");
1617 Write_Statement_Buffer
;
1622 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
1624 if Name_Buffer
(Name_Len
) = 's' then
1625 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1627 Name_Len
:= Name_Len
+ 8;
1629 -- Special case in CodePeer mode for subprogram bodies
1630 -- which correspond to CodePeer 'Elab_Subp_Body special
1633 elsif U
.Unit_Kind
= 's' and CodePeer_Mode
then
1634 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 13) :=
1636 Name_Len
:= Name_Len
+ 13;
1639 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1641 Name_Len
:= Name_Len
+ 8;
1644 Set_Casing
(U
.Icasing
);
1647 Write_Statement_Buffer
;
1649 if Check_Elab_Flag
then
1653 if U
.Utype
/= Is_Spec
1654 and then not CodePeer_Mode
1655 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1658 Set_Unit_Number
(Unum_Spec
);
1659 Set_String
(" := E");
1660 Set_Unit_Number
(Unum_Spec
);
1661 Set_String
(" + 1;");
1662 Write_Statement_Buffer
;
1669 ------------------------
1670 -- Gen_Elab_Externals --
1671 ------------------------
1673 procedure Gen_Elab_Externals
(Elab_Order
: Unit_Id_Array
) is
1675 if CodePeer_Mode
then
1679 for E
in Elab_Order
'Range loop
1681 Unum
: constant Unit_Id
:= Elab_Order
(E
);
1682 U
: Unit_Record
renames Units
.Table
(Unum
);
1685 -- Check for Elab_Entity to be set for this unit
1687 if U
.Set_Elab_Entity
1689 -- Don't generate reference for stand alone library
1691 and then not U
.SAL_Interface
1693 -- Don't generate reference for predefined file in No_Run_Time
1694 -- mode, since we don't include the object files in this case
1698 and then Is_Predefined_File_Name
(U
.Sfile
))
1700 Get_Name_String
(U
.Sfile
);
1703 Set_Unit_Number
(Unum
);
1704 Set_String
(" : Short_Integer; pragma Import (Ada, E");
1705 Set_Unit_Number
(Unum
);
1706 Set_String
(", """);
1707 Get_Name_String
(U
.Uname
);
1709 Set_String
("_E"");");
1710 Write_Statement_Buffer
;
1716 end Gen_Elab_Externals
;
1718 --------------------
1719 -- Gen_Elab_Order --
1720 --------------------
1722 procedure Gen_Elab_Order
(Elab_Order
: Unit_Id_Array
) is
1725 WBI
(" -- BEGIN ELABORATION ORDER");
1727 for J
in Elab_Order
'Range loop
1728 Set_String
(" -- ");
1729 Get_Name_String
(Units
.Table
(Elab_Order
(J
)).Uname
);
1731 Write_Statement_Buffer
;
1734 WBI
(" -- END ELABORATION ORDER");
1737 --------------------------
1738 -- Gen_Finalize_Library --
1739 --------------------------
1741 procedure Gen_Finalize_Library
(Elab_Order
: Unit_Id_Array
) is
1742 procedure Gen_Header
;
1743 -- Generate the header of the finalization routine
1749 procedure Gen_Header
is
1751 WBI
(" procedure finalize_library is");
1759 Uspec
: Unit_Record
;
1762 -- Start of processing for Gen_Finalize_Library
1765 if CodePeer_Mode
then
1769 for E
in reverse Elab_Order
'Range loop
1770 Unum
:= Elab_Order
(E
);
1771 U
:= Units
.Table
(Unum
);
1773 -- Dealing with package bodies is a little complicated. In such
1774 -- cases we must retrieve the package spec since it contains the
1775 -- spec of the body finalizer.
1777 if U
.Utype
= Is_Body
then
1779 Uspec
:= Units
.Table
(Unum
);
1784 Get_Name_String
(Uspec
.Uname
);
1786 -- We are only interested in non-generic packages
1788 if U
.Unit_Kind
/= 'p' or else U
.Is_Generic
then
1791 -- That aren't an interface to a stand alone library
1793 elsif U
.SAL_Interface
then
1796 -- Case of no finalization
1798 elsif not U
.Has_Finalizer
then
1800 -- The only case in which we have to do something is if this
1801 -- is a body, with a separate spec, where the separate spec
1802 -- has a finalizer. In that case, this is where we decrement
1803 -- the elaboration entity.
1805 if U
.Utype
= Is_Body
and then Uspec
.Has_Finalizer
then
1806 if not Lib_Final_Built
then
1808 Lib_Final_Built
:= True;
1812 Set_Unit_Number
(Unum
);
1813 Set_String
(" := E");
1814 Set_Unit_Number
(Unum
);
1815 Set_String
(" - 1;");
1816 Write_Statement_Buffer
;
1820 if not Lib_Final_Built
then
1822 Lib_Final_Built
:= True;
1827 -- procedure F<Count>;
1829 Set_String
(" declare");
1830 Write_Statement_Buffer
;
1832 Set_String
(" procedure F");
1835 Write_Statement_Buffer
;
1838 -- pragma Import (Ada, F<Count>,
1839 -- "xx__yy__finalize_[body|spec]");
1841 Set_String
(" pragma Import (Ada, F");
1843 Set_String
(", """);
1845 -- Perform name construction
1848 Set_String
("__finalize_");
1850 -- Package spec processing
1852 if U
.Utype
= Is_Spec
1853 or else U
.Utype
= Is_Spec_Only
1855 Set_String
("spec");
1857 -- Package body processing
1860 Set_String
("body");
1863 Set_String
(""");");
1864 Write_Statement_Buffer
;
1866 -- If binding a library or if there is a non-Ada main subprogram
1867 -- then we generate:
1870 -- uname_E := uname_E - 1;
1871 -- if uname_E = 0 then
1876 -- Otherwise, finalization routines are called unconditionally:
1879 -- uname_E := uname_E - 1;
1883 -- The uname_E decrement is skipped if this is a separate spec,
1884 -- since it will be done when we process the body.
1888 if U
.Utype
/= Is_Spec
then
1890 Set_Unit_Number
(Unum
);
1891 Set_String
(" := E");
1892 Set_Unit_Number
(Unum
);
1893 Set_String
(" - 1;");
1894 Write_Statement_Buffer
;
1897 if Interface_Library_Unit
or not Bind_Main_Program
then
1898 Set_String
(" if E");
1899 Set_Unit_Number
(Unum
);
1900 Set_String
(" = 0 then");
1901 Write_Statement_Buffer
;
1908 Write_Statement_Buffer
;
1910 if Interface_Library_Unit
or not Bind_Main_Program
then
1920 if Lib_Final_Built
then
1922 -- It is possible that the finalization of a library-level object
1923 -- raised an exception. In that case import the actual exception
1924 -- and the routine necessary to raise it.
1927 WBI
(" procedure Reraise_Library_Exception_If_Any;");
1929 Set_String
(" pragma Import (Ada, ");
1930 Set_String
("Reraise_Library_Exception_If_Any, ");
1931 Set_String
("""__gnat_reraise_library_exception_if_any"");");
1932 Write_Statement_Buffer
;
1935 WBI
(" Reraise_Library_Exception_If_Any;");
1937 WBI
(" end finalize_library;");
1940 end Gen_Finalize_Library
;
1946 procedure Gen_Main
is
1948 if not No_Main_Subprogram
then
1950 -- To call the main program, we declare it using a pragma Import
1951 -- Ada with the right link name.
1953 -- It might seem more obvious to "with" the main program, and call
1954 -- it in the normal Ada manner. We do not do this for three
1957 -- 1. It is more efficient not to recompile the main program
1958 -- 2. We are not entitled to assume the source is accessible
1959 -- 3. We don't know what options to use to compile it
1961 -- It is really reason 3 that is most critical (indeed we used
1962 -- to generate the "with", but several regression tests failed).
1964 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1965 WBI
(" function Ada_Main_Program return Integer;");
1967 WBI
(" procedure Ada_Main_Program;");
1970 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1971 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1972 Set_Main_Program_Name
;
1973 Set_String
(""");");
1975 Write_Statement_Buffer
;
1978 -- For CodePeer, declare a wrapper for the user-defined main program
1980 if CodePeer_Mode
then
1981 Gen_CodePeer_Wrapper
;
1985 if Exit_Status_Supported_On_Target
then
1986 Set_String
(" function ");
1988 Set_String
(" procedure ");
1991 Set_String
(Get_Main_Name
);
1993 if Command_Line_Args_On_Target
then
1994 Write_Statement_Buffer
;
1995 WBI
(" (argc : Integer;");
1996 WBI
(" argv : System.Address;");
1997 WBI
(" envp : System.Address)");
1999 if Exit_Status_Supported_On_Target
then
2000 WBI
(" return Integer");
2006 if Exit_Status_Supported_On_Target
then
2007 Set_String
(" return Integer is");
2012 Write_Statement_Buffer
;
2015 if Opt
.Default_Exit_Status
/= 0
2016 and then Bind_Main_Program
2017 and then not Configurable_Run_Time_Mode
2019 WBI
(" procedure Set_Exit_Status (Status : Integer);");
2020 WBI
(" pragma Import (C, Set_Exit_Status, " &
2021 """__gnat_set_exit_status"");");
2025 -- Initialize and Finalize
2027 if not CodePeer_Mode
2028 and then not Cumulative_Restrictions
.Set
(No_Finalization
)
2030 WBI
(" procedure Initialize (Addr : System.Address);");
2031 WBI
(" pragma Import (C, Initialize, ""__gnat_initialize"");");
2033 WBI
(" procedure Finalize;");
2034 WBI
(" pragma Import (C, Finalize, ""__gnat_finalize"");");
2037 -- If we want to analyze the stack, we must import corresponding symbols
2039 if Dynamic_Stack_Measurement
then
2041 WBI
(" procedure Output_Results;");
2042 WBI
(" pragma Import (C, Output_Results, " &
2043 """__gnat_stack_usage_output_results"");");
2047 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
2048 WBI
(" pragma Import (C, Initialize_Stack_Analysis, " &
2049 """__gnat_stack_usage_initialize"");");
2052 -- Deal with declarations for main program case
2054 if not No_Main_Subprogram
then
2055 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
2056 WBI
(" Result : Integer;");
2060 if Bind_Main_Program
2061 and not Suppress_Standard_Library_On_Target
2062 and not CodePeer_Mode
2064 WBI
(" SEH : aliased array (1 .. 2) of Integer;");
2069 -- Generate a reference to Ada_Main_Program_Name. This symbol is not
2070 -- referenced elsewhere in the generated program, but is needed by
2071 -- the debugger (that's why it is generated in the first place). The
2072 -- reference stops Ada_Main_Program_Name from being optimized away by
2075 -- Because this variable is unused, we make this variable "aliased"
2076 -- with a pragma Volatile in order to tell the compiler to preserve
2077 -- this variable at any level of optimization.
2079 -- CodePeer and CCG do not need this extra code. The code is also not
2080 -- needed if the binder is in "Minimal Binder" mode.
2082 if Bind_Main_Program
2083 and then not Minimal_Binder
2084 and then not CodePeer_Mode
2085 and then not Generate_C_Code
2087 WBI
(" Ensure_Reference : aliased System.Address := " &
2088 "Ada_Main_Program_Name'Address;");
2089 WBI
(" pragma Volatile (Ensure_Reference);");
2095 -- Acquire command-line arguments if present on target
2097 if CodePeer_Mode
then
2100 elsif Command_Line_Args_On_Target
then
2102 -- Initialize gnat_argc/gnat_argv only if not already initialized,
2103 -- to avoid losing the result of any command-line processing done by
2104 -- earlier GNAT run-time initialization.
2106 WBI
(" if gnat_argc = 0 then");
2107 WBI
(" gnat_argc := argc;");
2108 WBI
(" gnat_argv := argv;");
2110 WBI
(" gnat_envp := envp;");
2113 -- If configurable run-time and no command-line args, then nothing needs
2114 -- to be done since the gnat_argc/argv/envp variables are suppressed in
2117 elsif Configurable_Run_Time_On_Target
then
2120 -- Otherwise set dummy values (to be filled in by some other unit?)
2123 WBI
(" gnat_argc := 0;");
2124 WBI
(" gnat_argv := System.Null_Address;");
2125 WBI
(" gnat_envp := System.Null_Address;");
2128 if Opt
.Default_Exit_Status
/= 0
2129 and then Bind_Main_Program
2130 and then not Configurable_Run_Time_Mode
2132 Set_String
(" Set_Exit_Status (");
2133 Set_Int
(Opt
.Default_Exit_Status
);
2135 Write_Statement_Buffer
;
2138 if Dynamic_Stack_Measurement
then
2139 Set_String
(" Initialize_Stack_Analysis (");
2140 Set_Int
(Dynamic_Stack_Measurement_Array_Size
);
2142 Write_Statement_Buffer
;
2145 if not Cumulative_Restrictions
.Set
(No_Finalization
)
2146 and then not CodePeer_Mode
2148 if not No_Main_Subprogram
2149 and then Bind_Main_Program
2150 and then not Suppress_Standard_Library_On_Target
2152 WBI
(" Initialize (SEH'Address);");
2154 WBI
(" Initialize (System.Null_Address);");
2158 WBI
(" " & Ada_Init_Name
.all & ";");
2160 if not No_Main_Subprogram
then
2161 if CodePeer_Mode
then
2162 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
2163 WBI
(" " & CodePeer_Wrapper_Name
& ";");
2165 WBI
(" Result := " & CodePeer_Wrapper_Name
& ";");
2168 elsif ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
2169 WBI
(" Ada_Main_Program;");
2172 WBI
(" Result := Ada_Main_Program;");
2176 -- Adafinal call is skipped if no finalization
2178 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2182 -- Prints the result of static stack analysis
2184 if Dynamic_Stack_Measurement
then
2185 WBI
(" Output_Results;");
2188 -- Finalize is only called if we have a run time
2190 if not Cumulative_Restrictions
.Set
(No_Finalization
)
2191 and then not CodePeer_Mode
2198 if Exit_Status_Supported_On_Target
then
2199 if No_Main_Subprogram
2200 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
2202 WBI
(" return (gnat_exit_status);");
2204 WBI
(" return (Result);");
2212 ------------------------------
2213 -- Gen_Object_Files_Options --
2214 ------------------------------
2216 procedure Gen_Object_Files_Options
(Elab_Order
: Unit_Id_Array
) is
2218 -- This keeps track of the position in the sorted set of entries in the
2219 -- Linker_Options table of where the first entry from an internal file
2222 Linker_Option_List_Started
: Boolean := False;
2223 -- Set to True when "LINKER OPTION LIST" is displayed
2225 procedure Write_Linker_Option
;
2226 -- Write binder info linker option
2228 -------------------------
2229 -- Write_Linker_Option --
2230 -------------------------
2232 procedure Write_Linker_Option
is
2237 -- Loop through string, breaking at null's
2240 while Start
< Name_Len
loop
2242 -- Find null ending this section
2245 while Name_Buffer
(Stop
) /= ASCII
.NUL
2246 and then Stop
<= Name_Len
loop
2250 -- Process section if non-null
2252 if Stop
> Start
then
2253 if Output_Linker_Option_List
then
2254 if not Zero_Formatting
then
2255 if not Linker_Option_List_Started
then
2256 Linker_Option_List_Started
:= True;
2258 Write_Str
(" LINKER OPTION LIST");
2266 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
2269 WBI
(" -- " & Name_Buffer
(Start
.. Stop
- 1));
2274 end Write_Linker_Option
;
2276 -- Start of processing for Gen_Object_Files_Options
2279 WBI
("-- BEGIN Object file/option list");
2281 if Object_List_Filename
/= null then
2282 Set_List_File
(Object_List_Filename
.all);
2285 for E
in Elab_Order
'Range loop
2287 -- If not spec that has an associated body, then generate a comment
2288 -- giving the name of the corresponding object file.
2290 if not Units
.Table
(Elab_Order
(E
)).SAL_Interface
2291 and then Units
.Table
(Elab_Order
(E
)).Utype
/= Is_Spec
2295 (Units
.Table
(Elab_Order
(E
)).My_ALI
).Ofile_Full_Name
);
2297 -- If the presence of an object file is necessary or if it exists,
2300 if not Hostparm
.Exclude_Missing_Objects
2302 System
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
2304 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
2306 if Output_Object_List
then
2307 Write_Str
(Name_Buffer
(1 .. Name_Len
));
2314 if Object_List_Filename
/= null then
2318 -- Add a "-Ldir" for each directory in the object path
2320 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
2322 Dir
: constant String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
2326 Add_Str_To_Name_Buffer
("-L");
2327 Add_Str_To_Name_Buffer
(Dir
.all);
2328 Write_Linker_Option
;
2332 if not (Opt
.No_Run_Time_Mode
or Opt
.No_Stdlib
) then
2335 if Opt
.Shared_Libgnat
then
2336 Add_Str_To_Name_Buffer
("-shared");
2338 Add_Str_To_Name_Buffer
("-static");
2341 -- Write directly to avoid inclusion in -K output as -static and
2342 -- -shared are not usually specified linker options.
2344 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
2347 -- Sort linker options
2349 -- This sort accomplishes two important purposes:
2351 -- a) All application files are sorted to the front, and all GNAT
2352 -- internal files are sorted to the end. This results in a well
2353 -- defined dividing line between the two sets of files, for the
2354 -- purpose of inserting certain standard library references into
2355 -- the linker arguments list.
2357 -- b) Given two different units, we sort the linker options so that
2358 -- those from a unit earlier in the elaboration order comes later
2359 -- in the list. This is a heuristic designed to create a more
2360 -- friendly order of linker options when the operations appear in
2361 -- separate units. The idea is that if unit A must be elaborated
2362 -- before unit B, then it is more likely that B references
2363 -- libraries included by A, than vice versa, so we want libraries
2364 -- included by A to come after libraries included by B.
2366 -- These two criteria are implemented by function Lt_Linker_Option. Note
2367 -- that a special case of b) is that specs are elaborated before bodies,
2368 -- so linker options from specs come after linker options for bodies,
2369 -- and again, the assumption is that libraries used by the body are more
2370 -- likely to reference libraries used by the spec, than vice versa.
2373 (Linker_Options
.Last
,
2374 Move_Linker_Option
'Access,
2375 Lt_Linker_Option
'Access);
2377 -- Write user linker options, i.e. the set of linker options that come
2378 -- from all files other than GNAT internal files, Lgnat is left set to
2379 -- point to the first entry from a GNAT internal file, or past the end
2380 -- of the entries if there are no internal files.
2382 Lgnat
:= Linker_Options
.Last
+ 1;
2384 for J
in 1 .. Linker_Options
.Last
loop
2385 if not Linker_Options
.Table
(J
).Internal_File
then
2386 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2387 Write_Linker_Option
;
2394 -- Now we insert standard linker options that must appear after the
2395 -- entries from user files, and before the entries from GNAT run-time
2396 -- files. The reason for this decision is that libraries referenced
2397 -- by internal routines may reference these standard library entries.
2399 -- Note that we do not insert anything when pragma No_Run_Time has
2400 -- been specified or when the standard libraries are not to be used,
2401 -- otherwise on some platforms, we may get duplicate symbols when
2402 -- linking (not clear if this is still the case, but it is harmless).
2404 if not (Opt
.No_Run_Time_Mode
or else Opt
.No_Stdlib
) then
2408 if Opt
.Shared_Libgnat
then
2409 Add_Str_To_Name_Buffer
(Shared_Lib
("gnarl"));
2411 Add_Str_To_Name_Buffer
("-lgnarl");
2414 Write_Linker_Option
;
2419 if Opt
.Shared_Libgnat
then
2420 Add_Str_To_Name_Buffer
(Shared_Lib
("gnat"));
2422 Add_Str_To_Name_Buffer
("-lgnat");
2425 Write_Linker_Option
;
2428 -- Write linker options from all internal files
2430 for J
in Lgnat
.. Linker_Options
.Last
loop
2431 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2432 Write_Linker_Option
;
2435 if Output_Linker_Option_List
and then not Zero_Formatting
then
2439 WBI
("-- END Object file/option list ");
2440 end Gen_Object_Files_Options
;
2442 ---------------------
2443 -- Gen_Output_File --
2444 ---------------------
2446 procedure Gen_Output_File
2448 Elab_Order
: Unit_Id_Array
)
2451 -- Acquire settings for Interrupt_State pragmas
2453 Set_IS_Pragma_Table
;
2455 -- Acquire settings for Priority_Specific_Dispatching pragma
2457 Set_PSD_Pragma_Table
;
2459 -- Override time slice value if -T switch is set
2461 if Time_Slice_Set
then
2462 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
2465 -- Count number of elaboration calls
2467 for E
in Elab_Order
'Range loop
2468 if Units
.Table
(Elab_Order
(E
)).No_Elab
then
2471 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
2475 -- Count the number of statically allocated stacks to be generated by
2476 -- the binder. If the user has specified the number of default-sized
2477 -- secondary stacks, use that number. Otherwise start the count at one
2478 -- as the binder is responsible for creating a secondary stack for the
2481 if Opt
.Quantity_Of_Default_Size_Sec_Stacks
/= -1 then
2482 Num_Sec_Stacks
:= Quantity_Of_Default_Size_Sec_Stacks
;
2483 elsif Sec_Stack_Used
then
2484 Num_Sec_Stacks
:= 1;
2487 for J
in Units
.First
.. Units
.Last
loop
2488 Num_Primary_Stacks
:=
2489 Num_Primary_Stacks
+ Units
.Table
(J
).Primary_Stack_Count
;
2492 Num_Sec_Stacks
+ Units
.Table
(J
).Sec_Stack_Count
;
2495 -- Generate output file in appropriate language
2497 Gen_Output_File_Ada
(Filename
, Elab_Order
);
2498 end Gen_Output_File
;
2500 -------------------------
2501 -- Gen_Output_File_Ada --
2502 -------------------------
2504 procedure Gen_Output_File_Ada
2505 (Filename
: String; Elab_Order
: Unit_Id_Array
)
2507 Ada_Main
: constant String := Get_Ada_Main_Name
;
2508 -- Name to be used for generated Ada main program. See the body of
2509 -- function Get_Ada_Main_Name for details on the form of the name.
2511 Needs_Library_Finalization
: constant Boolean :=
2512 not Configurable_Run_Time_On_Target
2513 and then Has_Finalizer
(Elab_Order
);
2514 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2515 -- non-terminating, so we do not want finalization.
2518 -- Name of generated bind file (spec)
2521 -- Name of generated bind file (body)
2524 -- Create spec first
2526 Create_Binder_Output
(Filename
, 's', Bfiles
);
2528 -- We always compile the binder file in Ada 95 mode so that we properly
2529 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2530 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
2532 WBI
("pragma Warnings (Off);");
2533 WBI
("pragma Ada_95;");
2535 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2536 -- then we need to make sure that the binder program is compiled with
2537 -- the same restriction, so that no exception tables are generated.
2539 if Cumulative_Restrictions
.Set
(No_Exception_Handlers
) then
2540 WBI
("pragma Restrictions (No_Exception_Handlers);");
2543 -- Same processing for Restrictions (No_Exception_Propagation)
2545 if Cumulative_Restrictions
.Set
(No_Exception_Propagation
) then
2546 WBI
("pragma Restrictions (No_Exception_Propagation);");
2549 -- Same processing for pragma No_Run_Time
2551 if No_Run_Time_Mode
then
2552 WBI
("pragma No_Run_Time;");
2555 -- Generate with of System so we can reference System.Address
2557 WBI
("with System;");
2559 -- Generate with of System.Initialize_Scalars if active
2561 if Initialize_Scalars_Used
then
2562 WBI
("with System.Scalar_Values;");
2565 -- Generate withs of System.Secondary_Stack and System.Parameters to
2566 -- allow the generation of the default-sized secondary stack pool.
2568 if Sec_Stack_Used
then
2569 WBI
("with System.Parameters;");
2570 WBI
("with System.Secondary_Stack;");
2573 if Enable_CUDA_Expansion
then
2574 WBI
("with Interfaces.C;");
2575 WBI
("with Interfaces.C.Strings;");
2577 -- with of CUDA.Internal needed for CUDA_Execute pragma expansion
2578 WBI
("with CUDA.Internal;");
2581 Resolve_Binder_Options
(Elab_Order
);
2583 -- Generate standard with's
2585 if not Suppress_Standard_Library_On_Target
then
2586 if CodePeer_Mode
then
2587 WBI
("with System.Standard_Library;");
2591 WBI
("package " & Ada_Main
& " is");
2593 -- Main program case
2595 if Bind_Main_Program
then
2596 -- Generate argc/argv stuff unless suppressed
2598 if Command_Line_Args_On_Target
2599 or not Configurable_Run_Time_On_Target
2602 WBI
(" gnat_argc : Integer;");
2603 WBI
(" gnat_argv : System.Address;");
2604 WBI
(" gnat_envp : System.Address;");
2606 -- If the standard library is not suppressed, these variables
2607 -- are in the run-time data area for easy run time access.
2609 if not Suppress_Standard_Library_On_Target
then
2611 WBI
(" pragma Import (C, gnat_argc);");
2612 WBI
(" pragma Import (C, gnat_argv);");
2613 WBI
(" pragma Import (C, gnat_envp);");
2617 -- Define exit status. Again in normal mode, this is in the run-time
2618 -- library, and is initialized there, but in the configurable
2619 -- run-time case, the variable is declared and initialized in this
2624 if Configurable_Run_Time_Mode
then
2625 if Exit_Status_Supported_On_Target
then
2626 WBI
(" gnat_exit_status : Integer := 0;");
2630 WBI
(" gnat_exit_status : Integer;");
2631 WBI
(" pragma Import (C, gnat_exit_status);");
2634 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2635 -- the main program. Otherwise, it can lead under some circumstances
2636 -- to a symbol duplication during the link (for instance when a C
2637 -- program uses two Ada libraries). Also zero terminate the string
2638 -- so that its end can be found reliably at run time.
2640 if not Minimal_Binder
then
2642 WBI
(" GNAT_Version : constant String :=");
2643 WBI
(" """ & Ver_Prefix
&
2644 Gnat_Version_String
&
2646 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2648 WBI
(" GNAT_Version_Address : constant System.Address := " &
2649 "GNAT_Version'Address;");
2650 WBI
(" pragma Export (C, GNAT_Version_Address, " &
2651 """__gnat_version_address"");");
2653 Set_String
(" Ada_Main_Program_Name : constant String := """);
2654 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2656 Set_Main_Program_Name
;
2657 Set_String
(""" & ASCII.NUL;");
2659 Write_Statement_Buffer
;
2662 (" pragma Export (C, Ada_Main_Program_Name, " &
2663 """__gnat_ada_main_program_name"");");
2668 WBI
(" procedure " & Ada_Init_Name
.all & ";");
2669 if Enable_CUDA_Device_Expansion
then
2670 WBI
(" pragma Export (C, " & Ada_Init_Name
.all &
2671 ", Link_Name => """ & Device_Link_Name_Prefix
2672 & Ada_Init_Name
.all & """);");
2673 WBI
(" pragma CUDA_Global (" & Ada_Init_Name
.all & ");");
2675 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
2676 Ada_Init_Name
.all & """);");
2679 -- If -a has been specified use pragma Linker_Constructor for the init
2680 -- procedure and pragma Linker_Destructor for the final procedure.
2682 if Use_Pragma_Linker_Constructor
then
2683 WBI
(" pragma Linker_Constructor (" & Ada_Init_Name
.all & ");");
2686 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2688 WBI
(" procedure " & Ada_Final_Name
.all & ";");
2689 if Enable_CUDA_Device_Expansion
then
2690 WBI
(" pragma Export (C, " & Ada_Final_Name
.all &
2691 ", Link_Name => """ & Device_Link_Name_Prefix
&
2692 Ada_Final_Name
.all & """);");
2693 WBI
(" pragma CUDA_Global (" & Ada_Final_Name
.all & ");");
2695 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
2696 Ada_Final_Name
.all & """);");
2699 if Use_Pragma_Linker_Constructor
then
2700 WBI
(" pragma Linker_Destructor (" & Ada_Final_Name
.all & ");");
2704 if Bind_Main_Program
then
2708 if Exit_Status_Supported_On_Target
then
2709 Set_String
(" function ");
2711 Set_String
(" procedure ");
2714 Set_String
(Get_Main_Name
);
2716 -- Generate argument list if present
2718 if Command_Line_Args_On_Target
then
2719 Write_Statement_Buffer
;
2720 WBI
(" (argc : Integer;");
2721 WBI
(" argv : System.Address;");
2723 (" envp : System.Address)");
2725 if Exit_Status_Supported_On_Target
then
2726 Write_Statement_Buffer
;
2727 WBI
(" return Integer;");
2729 Write_Statement_Buffer
(";");
2733 if Exit_Status_Supported_On_Target
then
2734 Write_Statement_Buffer
(" return Integer;");
2736 Write_Statement_Buffer
(";");
2740 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
2741 Get_Main_Name
& """);");
2746 -- Generate version numbers for units, only if needed. Be very safe on
2749 if not Configurable_Run_Time_On_Target
2750 or else System_Version_Control_Used
2751 or else not Bind_Main_Program
2756 Gen_Elab_Order
(Elab_Order
);
2761 WBI
("end " & Ada_Main
& ";");
2762 Close_Binder_Output
;
2764 -- Prepare to write body
2766 Create_Binder_Output
(Filename
, 'b', Bfileb
);
2768 -- We always compile the binder file in Ada 95 mode so that we properly
2769 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2770 -- of the Ada 2005/2012 constructs are needed by the binder file.
2772 WBI
("pragma Warnings (Off);");
2773 WBI
("pragma Ada_95;");
2775 -- Output Source_File_Name pragmas which look like
2777 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2778 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2780 -- where sss/bbb are the spec/body file names respectively
2782 Get_Name_String
(Bfiles
);
2783 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2785 WBI
("pragma Source_File_Name (" &
2787 ", Spec_File_Name => """ &
2788 Name_Buffer
(1 .. Name_Len
+ 3));
2790 Get_Name_String
(Bfileb
);
2791 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2793 WBI
("pragma Source_File_Name (" &
2795 ", Body_File_Name => """ &
2796 Name_Buffer
(1 .. Name_Len
+ 3));
2798 -- Generate pragma Suppress (Overflow_Check). This is needed for recent
2799 -- versions of the compiler which have overflow checks on by default.
2800 -- We do not want overflow checking enabled for the increments of the
2801 -- elaboration variables (since this can cause an unwanted reference to
2802 -- the last chance exception handler for limited run-times).
2804 WBI
("pragma Suppress (Overflow_Check);");
2806 -- Generate with of System.Restrictions to initialize
2807 -- Run_Time_Restrictions.
2809 if System_Restrictions_Used
then
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 not System_Restrictions_Used
then
2953 WBI
(" System.Restrictions.Run_Time_Restrictions :=");
2959 for J
in Cumulative_Restrictions
.Set
'Range loop
2960 Set_Boolean
(Cumulative_Restrictions
.Set
(J
));
2964 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2965 Write_Statement_Buffer
;
2971 Set_String_Replace
("),");
2972 Write_Statement_Buffer
;
2973 Set_String
(" Value => (");
2975 for J
in Cumulative_Restrictions
.Value
'Range loop
2976 Set_Int
(Int
(Cumulative_Restrictions
.Value
(J
)));
2980 Set_String_Replace
("),");
2981 Write_Statement_Buffer
;
2982 WBI
(" Violated =>");
2986 for J
in Cumulative_Restrictions
.Violated
'Range loop
2987 Set_Boolean
(Cumulative_Restrictions
.Violated
(J
));
2991 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2992 Write_Statement_Buffer
;
2998 Set_String_Replace
("),");
2999 Write_Statement_Buffer
;
3000 Set_String
(" Count => (");
3002 for J
in Cumulative_Restrictions
.Count
'Range loop
3003 Set_Int
(Int
(Cumulative_Restrictions
.Count
(J
)));
3007 Set_String_Replace
("),");
3008 Write_Statement_Buffer
;
3009 Set_String
(" Unknown => (");
3011 for J
in Cumulative_Restrictions
.Unknown
'Range loop
3012 Set_Boolean
(Cumulative_Restrictions
.Unknown
(J
));
3016 Set_String_Replace
("))");
3018 Write_Statement_Buffer
;
3019 end Gen_Restrictions
;
3025 -- This routine generates lines such as:
3027 -- unnnnn : constant Integer := 16#hhhhhhhh#;
3028 -- pragma Export (C, unnnnn, unam);
3030 -- for each unit, where unam is the unit name suffixed by either B or S for
3031 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
3032 -- the version number, and nnnnn is a 5-digits serial number.
3034 procedure Gen_Versions
is
3035 Ubuf
: String (1 .. 6) := "u00000";
3037 procedure Increment_Ubuf
;
3038 -- Little procedure to increment the serial number
3040 --------------------
3041 -- Increment_Ubuf --
3042 --------------------
3044 procedure Increment_Ubuf
is
3046 for J
in reverse Ubuf
'Range loop
3047 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
3048 exit when Ubuf
(J
) <= '9';
3053 -- Start of processing for Gen_Versions
3058 WBI
(" type Version_32 is mod 2 ** 32;");
3059 for U
in Units
.First
.. Units
.Last
loop
3060 if not Units
.Table
(U
).SAL_Interface
3061 and then (not Bind_For_Library
3062 or else Units
.Table
(U
).Directly_Scanned
)
3065 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
3066 Units
.Table
(U
).Version
& "#;");
3067 Set_String
(" pragma Export (C, ");
3069 Set_String
(", """);
3071 Get_Name_String
(Units
.Table
(U
).Uname
);
3073 for K
in 1 .. Name_Len
loop
3074 if Name_Buffer
(K
) = '.' then
3078 elsif Name_Buffer
(K
) = '%' then
3082 Set_Char
(Name_Buffer
(K
));
3086 if Name_Buffer
(Name_Len
) = 's' then
3092 Set_String
(""");");
3093 Write_Statement_Buffer
;
3098 ------------------------
3099 -- Get_Main_Unit_Name --
3100 ------------------------
3102 function Get_Main_Unit_Name
(S
: String) return String is
3103 Result
: String := S
;
3106 for J
in S
'Range loop
3107 if Result
(J
) = '.' then
3113 end Get_Main_Unit_Name
;
3115 -----------------------
3116 -- Get_Ada_Main_Name --
3117 -----------------------
3119 function Get_Ada_Main_Name
return String is
3120 Suffix
: constant String := "_00";
3121 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
3122 Opt
.Ada_Main_Name
.all & Suffix
;
3126 -- For CodePeer, we want reproducible names (independent of other mains
3127 -- that may or may not be present) that don't collide when analyzing
3128 -- multiple mains and which are easily recognizable as "ada_main" names.
3130 if CodePeer_Mode
then
3131 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
3135 Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
- 2));
3138 -- This loop tries the following possibilities in order
3144 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
3145 -- it is set to 'ada_main'.
3147 for J
in 0 .. 99 loop
3149 Nlen
:= Name
'Length - Suffix
'Length;
3151 Nlen
:= Name
'Length;
3152 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
3153 Name
(Name
'Last - 1) :=
3154 Character'Val (J
/ 10 + Character'Pos ('0'));
3157 for K
in ALIs
.First
.. ALIs
.Last
loop
3158 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
3160 -- Get unit name, removing %b or %e at end
3162 Get_Name_String
(Units
.Table
(L
).Uname
);
3163 Name_Len
:= Name_Len
- 2;
3165 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
3171 return Name
(1 .. Nlen
);
3177 -- If we fall through, just use a peculiar unlikely name
3179 return ("Qwertyuiop");
3180 end Get_Ada_Main_Name
;
3186 function Get_Main_Name
return String is
3188 -- Explicit name given with -M switch
3190 if Bind_Alternate_Main_Name
then
3191 return Alternate_Main_Name
.all;
3193 -- Case of main program name to be used directly
3195 elsif Use_Ada_Main_Program_Name_On_Target
then
3197 -- Get main program name
3199 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
3201 -- If this is a child name, return only the name of the child, since
3202 -- we can't have dots in a nested program name. Note that we do not
3203 -- include the %b at the end of the unit name.
3205 for J
in reverse 1 .. Name_Len
- 2 loop
3206 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
3207 return Name_Buffer
(J
.. Name_Len
- 2);
3211 raise Program_Error
; -- impossible exit
3213 -- Case where "main" is to be used as default
3220 ---------------------
3221 -- Get_WC_Encoding --
3222 ---------------------
3224 function Get_WC_Encoding
return Character is
3226 -- If encoding method specified by -W switch, then return it
3228 if Wide_Character_Encoding_Method_Specified
then
3229 return WC_Encoding_Letters
(Wide_Character_Encoding_Method
);
3231 -- If no main program, and not specified, set brackets, we really have
3232 -- no better choice. If some other encoding is required when there is
3233 -- no main, it must be set explicitly using -Wx.
3235 -- Note: if the ALI file always passed the wide character encoding of
3236 -- every file, then we could use the encoding of the initial specified
3237 -- file, but this information is passed only for potential main
3238 -- programs. We could fix this sometime, but it is a very minor point
3239 -- (wide character default encoding for [Wide_[Wide_]]Text_IO when there
3240 -- is no main program).
3242 elsif No_Main_Subprogram
then
3245 -- Otherwise if there is a main program, take encoding from it
3248 return ALIs
.Table
(ALIs
.First
).WC_Encoding
;
3250 end Get_WC_Encoding
;
3256 function Has_Finalizer
(Elab_Order
: Unit_Id_Array
) return Boolean is
3261 for E
in reverse Elab_Order
'Range loop
3262 Unum
:= Elab_Order
(E
);
3263 U
:= Units
.Table
(Unum
);
3265 -- We are only interested in non-generic packages
3267 if U
.Unit_Kind
= 'p'
3268 and then U
.Has_Finalizer
3269 and then not U
.Is_Generic
3270 and then not U
.No_Elab
3283 function Hash
(Nam
: Name_Id
) return Header_Num
is
3285 return Int
(Nam
- Names_Low_Bound
) rem Header_Num
'Last;
3288 ----------------------
3289 -- Lt_Linker_Option --
3290 ----------------------
3292 function Lt_Linker_Option
(Op1
: Natural; Op2
: Natural) return Boolean is
3294 -- Sort internal files last
3296 if Linker_Options
.Table
(Op1
).Internal_File
3298 Linker_Options
.Table
(Op2
).Internal_File
3300 -- Note: following test uses False < True
3302 return Linker_Options
.Table
(Op1
).Internal_File
3304 Linker_Options
.Table
(Op2
).Internal_File
;
3306 -- If both internal or both non-internal, sort according to the
3307 -- elaboration position. A unit that is elaborated later should come
3308 -- earlier in the linker options list.
3311 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
3313 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
3315 end Lt_Linker_Option
;
3317 ------------------------
3318 -- Move_Linker_Option --
3319 ------------------------
3321 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
3323 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
3324 end Move_Linker_Option
;
3326 ----------------------------
3327 -- Resolve_Binder_Options --
3328 ----------------------------
3330 procedure Resolve_Binder_Options
(Elab_Order
: Unit_Id_Array
) is
3331 procedure Check_Package
(Var
: in out Boolean; Name
: String);
3332 -- Set Var to true iff the current identifier in Namet is Name. Do
3333 -- nothing if it doesn't match. This procedure is just a helper to
3334 -- avoid explicitly dealing with length.
3340 procedure Check_Package
(Var
: in out Boolean; Name
: String) is
3342 if Name_Len
= Name
'Length
3343 and then Name_Buffer
(1 .. Name_Len
) = Name
3349 -- Start of processing for Resolve_Binder_Options
3352 for E
in Elab_Order
'Range loop
3353 Get_Name_String
(Units
.Table
(Elab_Order
(E
)).Uname
);
3355 -- This is not a perfect approach, but is the current protocol
3356 -- between the run-time and the binder to indicate that tasking is
3357 -- used: System.OS_Interface should always be used by any tasking
3360 Check_Package
(With_GNARL
, "system.os_interface%s");
3362 -- Ditto for the use of restricted tasking
3365 (System_Tasking_Restricted_Stages_Used
,
3366 "system.tasking.restricted.stages%s");
3368 -- Ditto for the use of interrupts
3370 Check_Package
(System_Interrupts_Used
, "system.interrupts%s");
3372 -- Ditto for the use of dispatching domains
3375 (Dispatching_Domains_Used
,
3376 "system.multiprocessors.dispatching_domains%s");
3378 -- Ditto for the use of restrictions
3380 Check_Package
(System_Restrictions_Used
, "system.restrictions%s");
3382 -- Ditto for use of an SMP bareboard runtime
3384 Check_Package
(System_BB_CPU_Primitives_Multiprocessors_Used
,
3385 "system.bb.cpu_primitives.multiprocessors%s");
3387 -- Ditto for System.Version_Control, which is used for Version and
3388 -- Body_Version attributes.
3390 Check_Package
(System_Version_Control_Used
,
3391 "system.version_control%s");
3393 end Resolve_Binder_Options
;
3399 procedure Set_Bind_Env
(Key
, Value
: String) is
3401 -- The lengths of Key and Value are stored as single bytes
3403 if Key
'Length > 255 then
3404 Osint
.Fail
("bind environment key """ & Key
& """ too long");
3407 if Value
'Length > 255 then
3408 Osint
.Fail
("bind environment value """ & Value
& """ too long");
3411 Bind_Environment
.Set
(Name_Find
(Key
), Name_Find
(Value
));
3418 procedure Set_Boolean
(B
: Boolean) is
3419 False_Str
: constant String := "False";
3420 True_Str
: constant String := "True";
3424 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ True_Str
'Length) :=
3426 Stm_Last
:= Stm_Last
+ True_Str
'Length;
3428 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ False_Str
'Length) :=
3430 Stm_Last
:= Stm_Last
+ False_Str
'Length;
3438 procedure Set_Char
(C
: Character) is
3440 Stm_Last
:= Stm_Last
+ 1;
3441 Statement_Buffer
(Stm_Last
) := C
;
3448 procedure Set_Int
(N
: Int
) is
3459 Stm_Last
:= Stm_Last
+ 1;
3460 Statement_Buffer
(Stm_Last
) :=
3461 Character'Val (N
mod 10 + Character'Pos ('0'));
3465 -------------------------
3466 -- Set_IS_Pragma_Table --
3467 -------------------------
3469 procedure Set_IS_Pragma_Table
is
3471 for F
in ALIs
.First
.. ALIs
.Last
loop
3472 for K
in ALIs
.Table
(F
).First_Interrupt_State
..
3473 ALIs
.Table
(F
).Last_Interrupt_State
3476 Inum
: constant Int
:=
3477 Interrupt_States
.Table
(K
).Interrupt_Id
;
3478 Stat
: constant Character :=
3479 Interrupt_States
.Table
(K
).Interrupt_State
;
3482 while IS_Pragma_Settings
.Last
< Inum
loop
3483 IS_Pragma_Settings
.Append
('n');
3486 IS_Pragma_Settings
.Table
(Inum
) := Stat
;
3490 end Set_IS_Pragma_Table
;
3492 ---------------------------
3493 -- Set_Main_Program_Name --
3494 ---------------------------
3496 procedure Set_Main_Program_Name
is
3498 -- Note that name has %b on the end which we ignore
3500 -- First we output the initial _ada_ since we know that the main program
3501 -- is a library level subprogram.
3503 Set_String
("_ada_");
3505 -- Copy name, changing dots to double underscores
3507 for J
in 1 .. Name_Len
- 2 loop
3508 if Name_Buffer
(J
) = '.' then
3511 Set_Char
(Name_Buffer
(J
));
3514 end Set_Main_Program_Name
;
3516 ---------------------
3517 -- Set_Name_Buffer --
3518 ---------------------
3520 procedure Set_Name_Buffer
is
3522 for J
in 1 .. Name_Len
loop
3523 Set_Char
(Name_Buffer
(J
));
3525 end Set_Name_Buffer
;
3527 -------------------------
3528 -- Set_PSD_Pragma_Table --
3529 -------------------------
3531 procedure Set_PSD_Pragma_Table
is
3533 for F
in ALIs
.First
.. ALIs
.Last
loop
3534 for K
in ALIs
.Table
(F
).First_Specific_Dispatching
..
3535 ALIs
.Table
(F
).Last_Specific_Dispatching
3538 DTK
: Specific_Dispatching_Record
3539 renames Specific_Dispatching
.Table
(K
);
3542 while PSD_Pragma_Settings
.Last
< DTK
.Last_Priority
loop
3543 PSD_Pragma_Settings
.Append
('F');
3546 for Prio
in DTK
.First_Priority
.. DTK
.Last_Priority
loop
3547 PSD_Pragma_Settings
.Table
(Prio
) := DTK
.Dispatching_Policy
;
3552 end Set_PSD_Pragma_Table
;
3558 procedure Set_String
(S
: String) is
3560 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ S
'Length) := S
;
3561 Stm_Last
:= Stm_Last
+ S
'Length;
3564 ------------------------
3565 -- Set_String_Replace --
3566 ------------------------
3568 procedure Set_String_Replace
(S
: String) is
3570 Statement_Buffer
(Stm_Last
- S
'Length + 1 .. Stm_Last
) := S
;
3571 end Set_String_Replace
;
3577 procedure Set_Unit_Name
is
3579 for J
in 1 .. Name_Len
- 2 loop
3580 if Name_Buffer
(J
) = '.' then
3583 Set_Char
(Name_Buffer
(J
));
3588 ---------------------
3589 -- Set_Unit_Number --
3590 ---------------------
3592 procedure Set_Unit_Number
(U
: Unit_Id
) is
3593 Num_Units
: constant Nat
:= Nat
(Units
.Last
) - Nat
(Unit_Id
'First);
3594 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
3597 if Num_Units
>= 10 and then Unum
< 10 then
3601 if Num_Units
>= 100 and then Unum
< 100 then
3606 end Set_Unit_Number
;
3608 ---------------------
3609 -- Write_Bind_Line --
3610 ---------------------
3612 procedure Write_Bind_Line
(S
: String) is
3614 -- Need to strip trailing LF from S
3616 WBI
(S
(S
'First .. S
'Last - 1));
3617 end Write_Bind_Line
;
3619 ----------------------------
3620 -- Write_Statement_Buffer --
3621 ----------------------------
3623 procedure Write_Statement_Buffer
is
3625 WBI
(Statement_Buffer
(1 .. Stm_Last
));
3627 end Write_Statement_Buffer
;
3629 procedure Write_Statement_Buffer
(S
: String) is
3632 Write_Statement_Buffer
;
3633 end Write_Statement_Buffer
;