1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 ------------------------------------------------------------------------------
27 with Casing
; use Casing
;
28 with Fname
; use Fname
;
29 with Gnatvsn
; use Gnatvsn
;
31 with Namet
; use Namet
;
33 with Osint
; use Osint
;
34 with Osint
.B
; use Osint
.B
;
35 with Output
; use Output
;
36 with Rident
; use Rident
;
37 with Stringt
; use Stringt
;
39 with Targparm
; use Targparm
;
40 with Types
; use Types
;
43 with System
.WCh_Con
; use System
.WCh_Con
;
45 with GNAT
.Heap_Sort_A
; use GNAT
.Heap_Sort_A
;
48 package body Bindgen
is
49 Statement_Buffer
: String (1 .. 1000);
50 -- Buffer used for constructing output statements
52 Stm_Last
: Natural := 0;
53 -- Stm_Last location in Statement_Buffer currently set
55 With_GNARL
: Boolean := False;
56 -- Flag which indicates whether the program uses the GNARL library
57 -- (presence of the unit System.OS_Interface)
59 Num_Elab_Calls
: Nat
:= 0;
60 -- Number of generated calls to elaboration routines
62 Num_Primary_Stacks
: Int
:= 0;
63 -- Number of default-sized primary stacks the binder needs to allocate for
64 -- task objects declared in the program.
66 Num_Sec_Stacks
: Int
:= 0;
67 -- Number of default-sized primary stacks the binder needs to allocate for
68 -- task objects declared in the program.
70 System_Restrictions_Used
: Boolean := False;
71 -- Flag indicating whether the unit System.Restrictions is in the closure
72 -- of the partition. This is set by Resolve_Binder_Options, and is used
73 -- to determine whether or not to initialize the restrictions information
74 -- in the body of the binder generated file (we do not want to do this
75 -- unconditionally, since it drags in the System.Restrictions unit
76 -- unconditionally, which is unpleasand, especially for ZFP etc.)
78 Dispatching_Domains_Used
: Boolean := False;
79 -- Flag indicating whether multiprocessor dispatching domains are used in
80 -- the closure of the partition. This is set by Resolve_Binder_Options, and
81 -- is used to call the routine to disallow the creation of new dispatching
82 -- domains just before calling the main procedure from the environment
85 System_Secondary_Stack_Used
: Boolean := False;
86 -- Flag indicating whether the unit System.Secondary_Stack is in the
87 -- closure of the partition. This is set by Resolve_Binder_Options, and
88 -- is used to initialize the package in cases where the run-time brings
89 -- in package but the secondary stack is not used.
91 System_Tasking_Restricted_Stages_Used
: Boolean := False;
92 -- Flag indicating whether the unit System.Tasking.Restricted.Stages is in
93 -- the closure of the partition. This is set by Resolve_Binder_Options,
94 -- and it used to call a routine to active all the tasks at the end of
95 -- the elaboration when partition elaboration policy is sequential.
97 System_Interrupts_Used
: Boolean := False;
98 -- Flag indicating whether the unit System.Interrups is in the closure of
99 -- the partition. This is set by Resolve_Binder_Options, and it used to
100 -- attach interrupt handlers at the end of the elaboration when partition
101 -- elaboration policy is sequential.
103 System_BB_CPU_Primitives_Multiprocessors_Used
: Boolean := False;
104 -- Flag indicating whether unit System.BB.CPU_Primitives.Multiprocessors
105 -- is in the closure of the partition. This is set by procedure
106 -- Resolve_Binder_Options, and it is used to call a procedure that starts
109 System_Version_Control_Used
: Boolean := False;
110 -- Flag indicating whether unit System.Version_Control is in the closure.
111 -- This unit is implicitly withed by the compiler when Version or
112 -- Body_Version attributes are used. If the package is not in the closure,
113 -- the version definitions can be removed.
115 Lib_Final_Built
: Boolean := False;
116 -- Flag indicating whether the finalize_library rountine has been built
118 Bind_Env_String_Built
: Boolean := False;
119 -- Flag indicating whether a bind environment string has been built
121 CodePeer_Wrapper_Name
: constant String := "call_main_subprogram";
122 -- For CodePeer, introduce a wrapper subprogram which calls the
123 -- user-defined main subprogram.
125 ----------------------------------
126 -- Interface_State Pragma Table --
127 ----------------------------------
129 -- This table assembles the interface state pragma information from
130 -- all the units in the partition. Note that Bcheck has already checked
131 -- that the information is consistent across units. The entries
132 -- in this table are n/u/r/s for not set/user/runtime/system.
134 package IS_Pragma_Settings
is new Table
.Table
135 (Table_Component_Type
=> Character,
136 Table_Index_Type
=> Int
,
137 Table_Low_Bound
=> 0,
138 Table_Initial
=> 100,
139 Table_Increment
=> 200,
140 Table_Name
=> "IS_Pragma_Settings");
142 -- This table assembles the Priority_Specific_Dispatching pragma
143 -- information from all the units in the partition. Note that Bcheck has
144 -- already checked that the information is consistent across units.
145 -- The entries in this table are the upper case first character of the
146 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
148 package PSD_Pragma_Settings
is new Table
.Table
149 (Table_Component_Type
=> Character,
150 Table_Index_Type
=> Int
,
151 Table_Low_Bound
=> 0,
152 Table_Initial
=> 100,
153 Table_Increment
=> 200,
154 Table_Name
=> "PSD_Pragma_Settings");
156 ----------------------------
157 -- Bind_Environment Table --
158 ----------------------------
160 subtype Header_Num
is Int
range 0 .. 36;
162 function Hash
(Nam
: Name_Id
) return Header_Num
;
164 package Bind_Environment
is new GNAT
.HTable
.Simple_HTable
165 (Header_Num
=> Header_Num
,
167 No_Element
=> No_Name
,
172 ----------------------
173 -- Run-Time Globals --
174 ----------------------
176 -- This section documents the global variables that are set from the
177 -- generated binder file.
179 -- Main_Priority : Integer;
180 -- Time_Slice_Value : Integer;
181 -- Heap_Size : Natural;
182 -- WC_Encoding : Character;
183 -- Locking_Policy : Character;
184 -- Queuing_Policy : Character;
185 -- Task_Dispatching_Policy : Character;
186 -- Priority_Specific_Dispatching : System.Address;
187 -- Num_Specific_Dispatching : Integer;
188 -- Restrictions : System.Address;
189 -- Interrupt_States : System.Address;
190 -- Num_Interrupt_States : Integer;
191 -- Unreserve_All_Interrupts : Integer;
192 -- Exception_Tracebacks : Integer;
193 -- Exception_Tracebacks_Symbolic : Integer;
194 -- Detect_Blocking : Integer;
195 -- Default_Stack_Size : Integer;
196 -- Default_Secondary_Stack_Size : System.Parameters.Size_Type;
197 -- Leap_Seconds_Support : Integer;
198 -- Main_CPU : Integer;
199 -- Default_Sized_SS_Pool : System.Address;
200 -- Binder_Sec_Stacks_Count : Natural;
202 -- Main_Priority is the priority value set by pragma Priority in the main
203 -- program. If no such pragma is present, the value is -1.
205 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
206 -- main program, or by the use of a -Tnnn parameter for the binder (if both
207 -- are present, the binder value overrides). The value is in milliseconds.
208 -- A value of zero indicates that time slicing should be suppressed. If no
209 -- pragma is present, and no -T switch was used, the value is -1.
211 -- WC_Encoding shows the wide character encoding method used for the main
212 -- program. This is one of the encoding letters defined in
213 -- System.WCh_Con.WC_Encoding_Letters.
215 -- Locking_Policy is a space if no locking policy was specified for the
216 -- partition. If a locking policy was specified, the value is the upper
217 -- case first character of the locking policy name, for example, 'C' for
220 -- Queuing_Policy is a space if no queuing policy was specified for the
221 -- partition. If a queuing policy was specified, the value is the upper
222 -- case first character of the queuing policy name for example, 'F' for
225 -- Task_Dispatching_Policy is a space if no task dispatching policy was
226 -- specified for the partition. If a task dispatching policy was specified,
227 -- the value is the upper case first character of the policy name, e.g. 'F'
228 -- for FIFO_Within_Priorities.
230 -- Priority_Specific_Dispatching is the address of a string used to store
231 -- the task dispatching policy specified for the different priorities in
232 -- the partition. The length of this string is determined by the last
233 -- priority for which such a pragma applies (the string will be a null
234 -- string if no specific dispatching policies were used). If pragma were
235 -- present, the entries apply to the priorities in sequence from the first
236 -- priority. The value stored is the upper case first character of the
237 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
238 -- for those priority ranges not specified.
240 -- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
241 -- string. It will be set to zero if no Priority_Specific_Dispatching
242 -- pragmas are present.
244 -- Restrictions is the address of a null-terminated string specifying the
245 -- restrictions information for the partition. The format is identical to
246 -- that of the parameter string found on R lines in ali files (see Lib.Writ
247 -- spec in lib-writ.ads for full details). The difference is that in this
248 -- context the values are the cumulative ones for the entire partition.
250 -- Interrupt_States is the address of a string used to specify the
251 -- cumulative results of Interrupt_State pragmas used in the partition.
252 -- The length of this string is determined by the last interrupt for which
253 -- such a pragma is given (the string will be a null string if no pragmas
254 -- were used). If pragma were present the entries apply to the interrupts
255 -- in sequence from the first interrupt, and are set to one of four
256 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
257 -- time, 's' for system, see description of Interrupt_State pragma for
260 -- Num_Interrupt_States is the length of the Interrupt_States string. It
261 -- will be set to zero if no Interrupt_State pragmas are present.
263 -- Unreserve_All_Interrupts is set to one if at least one unit in the
264 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
266 -- Exception_Tracebacks is set to one if the -Ea or -E parameter was
267 -- present in the bind and to zero otherwise. Note that on some targets
268 -- exception tracebacks are provided by default, so a value of zero for
269 -- this parameter does not necessarily mean no trace backs are available.
271 -- Exception_Tracebacks_Symbolic is set to one if the -Es parameter was
272 -- present in the bind and to zero otherwise.
274 -- Detect_Blocking indicates whether pragma Detect_Blocking is active or
275 -- not. A value of zero indicates that the pragma is not present, while a
276 -- value of 1 signals its presence in the partition.
278 -- Default_Stack_Size is the default stack size used when creating an Ada
279 -- task with no explicit Storage_Size clause.
281 -- Default_Secondary_Stack_Size is the default secondary stack size used
282 -- when creating an Ada task with no explicit Secondary_Stack_Size clause.
284 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
285 -- disabled. A value of zero indicates that leap seconds are turned "off",
286 -- while a value of one signifies "on" status.
288 -- Main_CPU is the processor set by pragma CPU in the main program. If no
289 -- such pragma is present, the value is -1.
291 -- Default_Sized_SS_Pool is set to the address of the default-sized
292 -- secondary stacks array generated by the binder. This pool of stacks is
293 -- generated when either the restriction No_Implicit_Heap_Allocations
294 -- or No_Implicit_Task_Allocations is active.
296 -- Binder_Sec_Stacks_Count is the number of generated secondary stacks in
297 -- the Default_Sized_SS_Pool.
299 procedure WBI
(Info
: String) renames Osint
.B
.Write_Binder_Info
;
300 -- Convenient shorthand used throughout
302 -----------------------
303 -- Local Subprograms --
304 -----------------------
306 procedure Gen_Adainit
(Elab_Order
: Unit_Id_Array
);
307 -- Generates the Adainit procedure
309 procedure Gen_Adafinal
;
310 -- Generate the Adafinal procedure
312 procedure Gen_Bind_Env_String
;
313 -- Generate the bind environment buffer
315 procedure Gen_CodePeer_Wrapper
;
316 -- For CodePeer, generate wrapper which calls user-defined main subprogram
318 procedure Gen_Elab_Calls
(Elab_Order
: Unit_Id_Array
);
319 -- Generate sequence of elaboration calls
321 procedure Gen_Elab_Externals
(Elab_Order
: Unit_Id_Array
);
322 -- Generate sequence of external declarations for elaboration
324 procedure Gen_Elab_Order
(Elab_Order
: Unit_Id_Array
);
325 -- Generate comments showing elaboration order chosen
327 procedure Gen_Finalize_Library
(Elab_Order
: Unit_Id_Array
);
328 -- Generate a sequence of finalization calls to elaborated packages
331 -- Generate procedure main
333 procedure Gen_Object_Files_Options
(Elab_Order
: Unit_Id_Array
);
334 -- Output comments containing a list of the full names of the object
335 -- files to be linked and the list of linker options supplied by
336 -- Linker_Options pragmas in the source.
338 procedure Gen_Output_File_Ada
340 Elab_Order
: Unit_Id_Array
);
341 -- Generate Ada output file
343 procedure Gen_Restrictions
;
344 -- Generate initialization of restrictions variable
346 procedure Gen_Versions
;
347 -- Output series of definitions for unit versions
349 function Get_Ada_Main_Name
return String;
350 -- This function is used for the Ada main output to compute a usable name
351 -- for the generated main program. The normal main program name is
352 -- Ada_Main, but this won't work if the user has a unit with this name.
353 -- This function tries Ada_Main first, and if there is such a clash, then
354 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
356 function Get_Main_Unit_Name
(S
: String) return String;
357 -- Return the main unit name corresponding to S by replacing '.' with '_'
359 function Get_Main_Name
return String;
360 -- This function is used in the main output case to compute the correct
361 -- external main program. It is "main" by default, unless the flag
362 -- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
363 -- of the Ada main name without the "_ada". This default can be overridden
364 -- explicitly using the -Mname binder switch.
366 function Get_WC_Encoding
return Character;
367 -- Return wide character encoding method to set as WC_Encoding in output.
368 -- If -W has been used, returns the specified encoding, otherwise returns
369 -- the encoding method used for the main program source. If there is no
370 -- main program source (-z switch used), returns brackets ('b').
372 function Has_Finalizer
(Elab_Order
: Unit_Id_Array
) return Boolean;
373 -- Determine whether the current unit has at least one library-level
376 function Lt_Linker_Option
(Op1
: Natural; Op2
: Natural) return Boolean;
377 -- Compare linker options, when sorting, first according to
378 -- Is_Internal_File (internal files come later) and then by
379 -- elaboration order position (latest to earliest).
381 procedure Move_Linker_Option
(From
: Natural; To
: Natural);
382 -- Move routine for sorting linker options
384 procedure Resolve_Binder_Options
(Elab_Order
: Unit_Id_Array
);
385 -- Set the value of With_GNARL
387 procedure Set_Char
(C
: Character);
388 -- Set given character in Statement_Buffer at the Stm_Last + 1 position
389 -- and increment Stm_Last by one to reflect the stored character.
391 procedure Set_Int
(N
: Int
);
392 -- Set given value in decimal in Statement_Buffer with no spaces starting
393 -- at the Stm_Last + 1 position, and updating Stm_Last past the value. A
394 -- minus sign is output for a negative value.
396 procedure Set_Boolean
(B
: Boolean);
397 -- Set given boolean value in Statement_Buffer at the Stm_Last + 1 position
398 -- and update Stm_Last past the value.
400 procedure Set_IS_Pragma_Table
;
401 -- Initializes contents of IS_Pragma_Settings table from ALI table
403 procedure Set_Main_Program_Name
;
404 -- Given the main program name in Name_Buffer (length in Name_Len) generate
405 -- the name of the routine to be used in the call. The name is generated
406 -- starting at Stm_Last + 1, and Stm_Last is updated past it.
408 procedure Set_Name_Buffer
;
409 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
411 procedure Set_PSD_Pragma_Table
;
412 -- Initializes contents of PSD_Pragma_Settings table from ALI table
414 procedure Set_String
(S
: String);
415 -- Sets characters of given string in Statement_Buffer, starting at the
416 -- Stm_Last + 1 position, and updating last past the string value.
418 procedure Set_String_Replace
(S
: String);
419 -- Replaces the last S'Length characters in the Statement_Buffer with the
420 -- characters of S. The caller must ensure that these characters do in fact
421 -- exist in the Statement_Buffer.
423 procedure Set_Unit_Name
;
424 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
425 -- starting at the Stm_Last + 1 position and update Stm_Last past the
426 -- value. Each dot (.) will be qualified into double underscores (__).
428 procedure Set_Unit_Number
(U
: Unit_Id
);
429 -- Sets unit number (first unit is 1, leading zeroes output to line up all
430 -- output unit numbers nicely as required by the value, and by the total
433 procedure Write_Statement_Buffer
;
434 -- Write out contents of statement buffer up to Stm_Last, and reset
437 procedure Write_Statement_Buffer
(S
: String);
438 -- First writes its argument (using Set_String (S)), then writes out the
439 -- contents of statement buffer up to Stm_Last, and resets Stm_Last to 0.
441 procedure Write_Bind_Line
(S
: String);
442 -- Write S (an LF-terminated string) to the binder file (for use with
443 -- Set_Special_Output).
449 procedure Gen_Adafinal
is
451 WBI
(" procedure " & Ada_Final_Name
.all & " is");
453 -- If task termination is not allowed, as is the case in restricted
454 -- runtimes, such as Ravenscar or ZFP, but may not be the case for all
455 -- configurable runtimes, we do not need program-level finalization.
457 if Cumulative_Restrictions
.Set
(No_Task_Termination
) then
460 WBI
(" end " & Ada_Final_Name
.all & ";");
465 -- Call s_stalib_adafinal to await termination of tasks and so on. We
466 -- want to do this if there is a main program, either in Ada or in some
467 -- other language. (Note that Bind_Main_Program is True for Ada mains,
468 -- but False for mains in other languages.) We do not want to do this if
469 -- we're binding a library.
471 if not Bind_For_Library
and not CodePeer_Mode
then
472 WBI
(" procedure s_stalib_adafinal;");
473 Set_String
(" pragma Import (C, s_stalib_adafinal, ");
474 Set_String
("""system__standard_library__adafinal"");");
475 Write_Statement_Buffer
;
479 WBI
(" procedure Runtime_Finalize;");
480 WBI
(" pragma Import (C, Runtime_Finalize, " &
481 """__gnat_runtime_finalize"");");
485 if not CodePeer_Mode
then
486 WBI
(" if not Is_Elaborated then");
489 WBI
(" Is_Elaborated := False;");
492 WBI
(" Runtime_Finalize;");
494 -- By default (real targets), finalization is done differently depending
495 -- on whether this is the main program or a library.
497 if not CodePeer_Mode
then
498 if not Bind_For_Library
then
499 WBI
(" s_stalib_adafinal;");
500 elsif Lib_Final_Built
then
501 WBI
(" finalize_library;");
506 -- Pragma Import C cannot be used on virtual targets, therefore call the
507 -- runtime finalization routine directly in CodePeer mode, where
508 -- imported functions are ignored.
511 WBI
(" System.Standard_Library.Adafinal;");
514 WBI
(" end " & Ada_Final_Name
.all & ";");
522 procedure Gen_Adainit
(Elab_Order
: Unit_Id_Array
) is
523 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
524 Main_CPU
: Int
renames ALIs
.Table
(ALIs
.First
).Main_CPU
;
527 -- Declare the access-to-subprogram type used for initialization of
528 -- of __gnat_finalize_library_objects. This is declared at library
529 -- level for compatibility with the type used in System.Soft_Links.
530 -- The import of the soft link which performs library-level object
531 -- finalization does not work for CodePeer, so regular Ada is used in
532 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
533 -- tasks are non-terminating, so we do not want finalization.
535 if not Suppress_Standard_Library_On_Target
536 and then not CodePeer_Mode
537 and then not Configurable_Run_Time_On_Target
539 WBI
(" type No_Param_Proc is access procedure;");
543 WBI
(" procedure " & Ada_Init_Name
.all & " is");
545 -- In CodePeer mode, simplify adainit procedure by only calling
546 -- elaboration procedures.
548 if CodePeer_Mode
then
551 -- If the standard library is suppressed, then the only global variables
552 -- that might be needed (by the Ravenscar profile) are the priority and
553 -- the processor for the environment task.
555 elsif Suppress_Standard_Library_On_Target
then
556 if Main_Priority
/= No_Main_Priority
then
557 WBI
(" Main_Priority : Integer;");
558 WBI
(" pragma Import (C, Main_Priority," &
559 " ""__gl_main_priority"");");
563 if Main_CPU
/= No_Main_CPU
then
564 WBI
(" Main_CPU : Integer;");
565 WBI
(" pragma Import (C, Main_CPU," &
566 " ""__gl_main_cpu"");");
570 if System_Interrupts_Used
571 and then Partition_Elaboration_Policy_Specified
= 'S'
573 WBI
(" procedure Install_Restricted_Handlers_Sequential;");
574 WBI
(" pragma Import (C," &
575 "Install_Restricted_Handlers_Sequential," &
576 " ""__gnat_attach_all_handlers"");");
580 if System_Tasking_Restricted_Stages_Used
581 and then Partition_Elaboration_Policy_Specified
= 'S'
583 WBI
(" Partition_Elaboration_Policy : Character;");
584 WBI
(" pragma Import (C, Partition_Elaboration_Policy," &
585 " ""__gnat_partition_elaboration_policy"");");
587 WBI
(" procedure Activate_All_Tasks_Sequential;");
588 WBI
(" pragma Import (C, Activate_All_Tasks_Sequential," &
589 " ""__gnat_activate_all_tasks"");");
593 if System_BB_CPU_Primitives_Multiprocessors_Used
then
594 WBI
(" procedure Start_Slave_CPUs;");
595 WBI
(" pragma Import (C, Start_Slave_CPUs," &
596 " ""__gnat_start_slave_cpus"");");
600 -- A restricted run-time may attempt to initialize the main task's
601 -- secondary stack even if the stack is not used. Consequently,
602 -- the binder needs to initialize Binder_Sec_Stacks_Count anytime
603 -- System.Secondary_Stack is in the enclosure of the partition.
605 if System_Secondary_Stack_Used
then
606 WBI
(" Binder_Sec_Stacks_Count : Natural;");
607 WBI
(" pragma Import (Ada, Binder_Sec_Stacks_Count, " &
608 """__gnat_binder_ss_count"");");
612 if Sec_Stack_Used
then
613 WBI
(" Default_Secondary_Stack_Size : " &
614 "System.Parameters.Size_Type;");
615 WBI
(" pragma Import (C, Default_Secondary_Stack_Size, " &
616 """__gnat_default_ss_size"");");
618 WBI
(" Default_Sized_SS_Pool : System.Address;");
619 WBI
(" pragma Import (Ada, Default_Sized_SS_Pool, " &
620 """__gnat_default_ss_pool"");");
627 if Main_Priority
/= No_Main_Priority
then
628 Set_String
(" Main_Priority := ");
629 Set_Int
(Main_Priority
);
631 Write_Statement_Buffer
;
634 if Main_CPU
/= No_Main_CPU
then
635 Set_String
(" Main_CPU := ");
638 Write_Statement_Buffer
;
641 if System_Tasking_Restricted_Stages_Used
642 and then Partition_Elaboration_Policy_Specified
= 'S'
644 Set_String
(" Partition_Elaboration_Policy := '");
645 Set_Char
(Partition_Elaboration_Policy_Specified
);
647 Write_Statement_Buffer
;
650 if Main_Priority
= No_Main_Priority
651 and then Main_CPU
= No_Main_CPU
652 and then not System_Tasking_Restricted_Stages_Used
657 -- Generate default-sized secondary stack pool and set secondary
660 if Sec_Stack_Used
then
662 -- Elaborate the body of the binder to initialize the default-
663 -- sized secondary stack pool.
666 WBI
(" " & Get_Ada_Main_Name
& "'Elab_Body;");
668 -- Generate the default-sized secondary stack pool and set the
669 -- related secondary stack globals.
671 Set_String
(" Default_Secondary_Stack_Size := ");
673 if Opt
.Default_Sec_Stack_Size
/= Opt
.No_Stack_Size
then
674 Set_Int
(Opt
.Default_Sec_Stack_Size
);
676 Set_String
("System.Parameters.Runtime_Default_Sec_Stack_Size");
680 Write_Statement_Buffer
;
682 Set_String
(" Binder_Sec_Stacks_Count := ");
683 Set_Int
(Num_Sec_Stacks
);
685 Write_Statement_Buffer
;
687 WBI
(" Default_Sized_SS_Pool := " &
688 "Sec_Default_Sized_Stacks'Address;");
691 -- When a restricted run-time initializes the main task's secondary
692 -- stack but the program does not use it, no secondary stack is
693 -- generated. Binder_Sec_Stacks_Count is set to zero so the run-time
694 -- is aware that the lack of pre-allocated secondary stack is
697 elsif System_Secondary_Stack_Used
then
698 WBI
(" Binder_Sec_Stacks_Count := 0;");
701 -- Normal case (standard library not suppressed). Set all global values
702 -- used by the run time.
705 WBI
(" Main_Priority : Integer;");
706 WBI
(" pragma Import (C, Main_Priority, " &
707 """__gl_main_priority"");");
708 WBI
(" Time_Slice_Value : Integer;");
709 WBI
(" pragma Import (C, Time_Slice_Value, " &
710 """__gl_time_slice_val"");");
711 WBI
(" WC_Encoding : Character;");
712 WBI
(" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
713 WBI
(" Locking_Policy : Character;");
714 WBI
(" pragma Import (C, Locking_Policy, " &
715 """__gl_locking_policy"");");
716 WBI
(" Queuing_Policy : Character;");
717 WBI
(" pragma Import (C, Queuing_Policy, " &
718 """__gl_queuing_policy"");");
719 WBI
(" Task_Dispatching_Policy : Character;");
720 WBI
(" pragma Import (C, Task_Dispatching_Policy, " &
721 """__gl_task_dispatching_policy"");");
722 WBI
(" Priority_Specific_Dispatching : System.Address;");
723 WBI
(" pragma Import (C, Priority_Specific_Dispatching, " &
724 """__gl_priority_specific_dispatching"");");
725 WBI
(" Num_Specific_Dispatching : Integer;");
726 WBI
(" pragma Import (C, Num_Specific_Dispatching, " &
727 """__gl_num_specific_dispatching"");");
728 WBI
(" Main_CPU : Integer;");
729 WBI
(" pragma Import (C, Main_CPU, " &
730 """__gl_main_cpu"");");
732 WBI
(" Interrupt_States : System.Address;");
733 WBI
(" pragma Import (C, Interrupt_States, " &
734 """__gl_interrupt_states"");");
735 WBI
(" Num_Interrupt_States : Integer;");
736 WBI
(" pragma Import (C, Num_Interrupt_States, " &
737 """__gl_num_interrupt_states"");");
738 WBI
(" Unreserve_All_Interrupts : Integer;");
739 WBI
(" pragma Import (C, Unreserve_All_Interrupts, " &
740 """__gl_unreserve_all_interrupts"");");
742 if Exception_Tracebacks
or Exception_Tracebacks_Symbolic
then
743 WBI
(" Exception_Tracebacks : Integer;");
744 WBI
(" pragma Import (C, Exception_Tracebacks, " &
745 """__gl_exception_tracebacks"");");
747 if Exception_Tracebacks_Symbolic
then
748 WBI
(" Exception_Tracebacks_Symbolic : Integer;");
749 WBI
(" pragma Import (C, Exception_Tracebacks_Symbolic, " &
750 """__gl_exception_tracebacks_symbolic"");");
754 WBI
(" Detect_Blocking : Integer;");
755 WBI
(" pragma Import (C, Detect_Blocking, " &
756 """__gl_detect_blocking"");");
757 WBI
(" Default_Stack_Size : Integer;");
758 WBI
(" pragma Import (C, Default_Stack_Size, " &
759 """__gl_default_stack_size"");");
760 WBI
(" Default_Secondary_Stack_Size : " &
761 "System.Parameters.Size_Type;");
762 WBI
(" pragma Import (C, Default_Secondary_Stack_Size, " &
763 """__gnat_default_ss_size"");");
764 WBI
(" Leap_Seconds_Support : Integer;");
765 WBI
(" pragma Import (C, Leap_Seconds_Support, " &
766 """__gl_leap_seconds_support"");");
767 WBI
(" Bind_Env_Addr : System.Address;");
768 WBI
(" pragma Import (C, Bind_Env_Addr, " &
769 """__gl_bind_env_addr"");");
771 -- Import entry point for elaboration time signal handler
772 -- installation, and indication of if it's been called previously.
775 WBI
(" procedure Runtime_Initialize " &
776 "(Install_Handler : Integer);");
777 WBI
(" pragma Import (C, Runtime_Initialize, " &
778 """__gnat_runtime_initialize"");");
780 -- Import handlers attach procedure for sequential elaboration policy
782 if System_Interrupts_Used
783 and then Partition_Elaboration_Policy_Specified
= 'S'
785 WBI
(" procedure Install_Restricted_Handlers_Sequential;");
786 WBI
(" pragma Import (C," &
787 "Install_Restricted_Handlers_Sequential," &
788 " ""__gnat_attach_all_handlers"");");
792 -- Import task activation procedure for sequential elaboration
795 if System_Tasking_Restricted_Stages_Used
796 and then Partition_Elaboration_Policy_Specified
= 'S'
798 WBI
(" Partition_Elaboration_Policy : Character;");
799 WBI
(" pragma Import (C, Partition_Elaboration_Policy," &
800 " ""__gnat_partition_elaboration_policy"");");
802 WBI
(" procedure Activate_All_Tasks_Sequential;");
803 WBI
(" pragma Import (C, Activate_All_Tasks_Sequential," &
804 " ""__gnat_activate_all_tasks"");");
807 -- Import procedure to start slave cpus for bareboard runtime
809 if System_BB_CPU_Primitives_Multiprocessors_Used
then
810 WBI
(" procedure Start_Slave_CPUs;");
811 WBI
(" pragma Import (C, Start_Slave_CPUs," &
812 " ""__gnat_start_slave_cpus"");");
815 -- For restricted run-time libraries (ZFP and Ravenscar)
816 -- tasks are non-terminating, so we do not want finalization.
818 if not Configurable_Run_Time_On_Target
then
820 WBI
(" Finalize_Library_Objects : No_Param_Proc;");
821 WBI
(" pragma Import (C, Finalize_Library_Objects, " &
822 """__gnat_finalize_library_objects"");");
825 -- Initialize stack limit variable of the environment task if the
826 -- stack check method is stack limit and stack check is enabled.
828 if Stack_Check_Limits_On_Target
829 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
832 WBI
(" procedure Initialize_Stack_Limit;");
833 WBI
(" pragma Import (C, Initialize_Stack_Limit, " &
834 """__gnat_initialize_stack_limit"");");
837 -- When dispatching domains are used then we need to signal it
838 -- before calling the main procedure.
840 if Dispatching_Domains_Used
then
841 WBI
(" procedure Freeze_Dispatching_Domains;");
842 WBI
(" pragma Import");
843 WBI
(" (Ada, Freeze_Dispatching_Domains, "
844 & """__gnat_freeze_dispatching_domains"");");
847 -- Secondary stack global variables
849 WBI
(" Binder_Sec_Stacks_Count : Natural;");
850 WBI
(" pragma Import (Ada, Binder_Sec_Stacks_Count, " &
851 """__gnat_binder_ss_count"");");
853 WBI
(" Default_Sized_SS_Pool : System.Address;");
854 WBI
(" pragma Import (Ada, Default_Sized_SS_Pool, " &
855 """__gnat_default_ss_pool"");");
859 -- Start of processing for Adainit
862 WBI
(" if Is_Elaborated then");
865 WBI
(" Is_Elaborated := True;");
867 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
868 -- restriction No_Standard_Allocators_After_Elaboration is active.
870 if Cumulative_Restrictions
.Set
871 (No_Standard_Allocators_After_Elaboration
)
873 WBI
(" System.Elaboration_Allocators."
874 & "Mark_Start_Of_Elaboration;");
877 -- Generate assignments to initialize globals
879 Set_String
(" Main_Priority := ");
880 Set_Int
(Main_Priority
);
882 Write_Statement_Buffer
;
884 Set_String
(" Time_Slice_Value := ");
886 if Task_Dispatching_Policy_Specified
= 'F'
887 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
891 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
895 Write_Statement_Buffer
;
897 Set_String
(" WC_Encoding := '");
898 Set_Char
(Get_WC_Encoding
);
901 Write_Statement_Buffer
;
903 Set_String
(" Locking_Policy := '");
904 Set_Char
(Locking_Policy_Specified
);
906 Write_Statement_Buffer
;
908 Set_String
(" Queuing_Policy := '");
909 Set_Char
(Queuing_Policy_Specified
);
911 Write_Statement_Buffer
;
913 Set_String
(" Task_Dispatching_Policy := '");
914 Set_Char
(Task_Dispatching_Policy_Specified
);
916 Write_Statement_Buffer
;
918 if System_Tasking_Restricted_Stages_Used
919 and then Partition_Elaboration_Policy_Specified
= 'S'
921 Set_String
(" Partition_Elaboration_Policy := '");
922 Set_Char
(Partition_Elaboration_Policy_Specified
);
924 Write_Statement_Buffer
;
929 WBI
(" Priority_Specific_Dispatching :=");
930 WBI
(" Local_Priority_Specific_Dispatching'Address;");
932 Set_String
(" Num_Specific_Dispatching := ");
933 Set_Int
(PSD_Pragma_Settings
.Last
+ 1);
935 Write_Statement_Buffer
;
937 Set_String
(" Main_CPU := ");
940 Write_Statement_Buffer
;
942 WBI
(" Interrupt_States := Local_Interrupt_States'Address;");
944 Set_String
(" Num_Interrupt_States := ");
945 Set_Int
(IS_Pragma_Settings
.Last
+ 1);
947 Write_Statement_Buffer
;
949 Set_String
(" Unreserve_All_Interrupts := ");
951 if Unreserve_All_Interrupts_Specified
then
958 Write_Statement_Buffer
;
960 if Exception_Tracebacks
or Exception_Tracebacks_Symbolic
then
961 WBI
(" Exception_Tracebacks := 1;");
963 if Exception_Tracebacks_Symbolic
then
964 WBI
(" Exception_Tracebacks_Symbolic := 1;");
968 Set_String
(" Detect_Blocking := ");
970 if Detect_Blocking
then
977 Write_Statement_Buffer
;
979 Set_String
(" Default_Stack_Size := ");
980 Set_Int
(Default_Stack_Size
);
982 Write_Statement_Buffer
;
984 Set_String
(" Leap_Seconds_Support := ");
986 if Leap_Seconds_Support
then
993 Write_Statement_Buffer
;
995 if Bind_Env_String_Built
then
996 WBI
(" Bind_Env_Addr := Bind_Env'Address;");
1001 -- Generate default-sized secondary stack pool and set secondary
1004 if Sec_Stack_Used
then
1006 -- Elaborate the body of the binder to initialize the default-
1007 -- sized secondary stack pool.
1009 WBI
(" " & Get_Ada_Main_Name
& "'Elab_Body;");
1011 -- Generate the default-sized secondary stack pool and set the
1012 -- related secondary stack globals.
1014 Set_String
(" Default_Secondary_Stack_Size := ");
1016 if Opt
.Default_Sec_Stack_Size
/= Opt
.No_Stack_Size
then
1017 Set_Int
(Opt
.Default_Sec_Stack_Size
);
1019 Set_String
("System.Parameters.Runtime_Default_Sec_Stack_Size");
1023 Write_Statement_Buffer
;
1025 Set_String
(" Binder_Sec_Stacks_Count := ");
1026 Set_Int
(Num_Sec_Stacks
);
1028 Write_Statement_Buffer
;
1030 Set_String
(" Default_Sized_SS_Pool := ");
1032 if Num_Sec_Stacks
> 0 then
1033 Set_String
("Sec_Default_Sized_Stacks'Address;");
1035 Set_String
("System.Null_Address;");
1038 Write_Statement_Buffer
;
1042 -- Generate call to Runtime_Initialize
1044 WBI
(" Runtime_Initialize (1);");
1047 -- Generate call to set Initialize_Scalar values if active
1049 if Initialize_Scalars_Used
then
1051 Set_String
(" System.Scalar_Values.Initialize ('");
1052 Set_Char
(Initialize_Scalars_Mode1
);
1053 Set_String
("', '");
1054 Set_Char
(Initialize_Scalars_Mode2
);
1056 Write_Statement_Buffer
;
1059 -- Initialize stack limit variable of the environment task if the stack
1060 -- check method is stack limit and stack check is enabled.
1062 if Stack_Check_Limits_On_Target
1063 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
1066 WBI
(" Initialize_Stack_Limit;");
1069 -- On CodePeer, the finalization of library objects is not relevant
1071 if CodePeer_Mode
then
1074 -- If this is the main program case, attach finalize_library to the soft
1075 -- link. Do it only when not using a restricted run time, in which case
1076 -- tasks are non-terminating, so we do not want library-level
1079 elsif not Bind_For_Library
1080 and then not Configurable_Run_Time_On_Target
1081 and then not Suppress_Standard_Library_On_Target
1085 if Lib_Final_Built
then
1086 Set_String
(" Finalize_Library_Objects := ");
1087 Set_String
("finalize_library'access;");
1089 Set_String
(" Finalize_Library_Objects := null;");
1092 Write_Statement_Buffer
;
1095 -- Generate elaboration calls
1097 if not CodePeer_Mode
then
1101 Gen_Elab_Calls
(Elab_Order
);
1103 if not CodePeer_Mode
then
1105 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
1106 -- restriction No_Standard_Allocators_After_Elaboration is active.
1108 if Cumulative_Restrictions
.Set
1109 (No_Standard_Allocators_After_Elaboration
)
1112 (" System.Elaboration_Allocators.Mark_End_Of_Elaboration;");
1115 -- From this point, no new dispatching domain can be created
1117 if Dispatching_Domains_Used
then
1118 WBI
(" Freeze_Dispatching_Domains;");
1121 -- Sequential partition elaboration policy
1123 if Partition_Elaboration_Policy_Specified
= 'S' then
1124 if System_Interrupts_Used
then
1125 WBI
(" Install_Restricted_Handlers_Sequential;");
1128 if System_Tasking_Restricted_Stages_Used
then
1129 WBI
(" Activate_All_Tasks_Sequential;");
1133 if System_BB_CPU_Primitives_Multiprocessors_Used
then
1134 WBI
(" Start_Slave_CPUs;");
1138 WBI
(" end " & Ada_Init_Name
.all & ";");
1142 -------------------------
1143 -- Gen_Bind_Env_String --
1144 -------------------------
1146 procedure Gen_Bind_Env_String
is
1147 procedure Write_Name_With_Len
(Nam
: Name_Id
);
1148 -- Write Nam as a string literal, prefixed with one
1149 -- character encoding Nam's length.
1151 -------------------------
1152 -- Write_Name_With_Len --
1153 -------------------------
1155 procedure Write_Name_With_Len
(Nam
: Name_Id
) is
1157 Get_Name_String
(Nam
);
1160 Store_String_Char
(Character'Val (Name_Len
));
1161 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
1163 Write_String_Table_Entry
(End_String
);
1164 end Write_Name_With_Len
;
1169 KN
: Name_Id
:= No_Name
;
1170 VN
: Name_Id
:= No_Name
;
1172 -- Start of processing for Gen_Bind_Env_String
1175 Bind_Environment
.Get_First
(KN
, VN
);
1177 if VN
= No_Name
then
1181 Set_Special_Output
(Write_Bind_Line
'Access);
1183 WBI
(" Bind_Env : aliased constant String :=");
1185 while VN
/= No_Name
loop
1186 Write_Str
(" " & Amp
& ' ');
1187 Write_Name_With_Len
(KN
);
1189 Write_Name_With_Len
(VN
);
1192 Bind_Environment
.Get_Next
(KN
, VN
);
1195 WBI
(" & ASCII.NUL;");
1197 Set_Special_Output
(null);
1199 Bind_Env_String_Built
:= True;
1200 end Gen_Bind_Env_String
;
1202 --------------------------
1203 -- Gen_CodePeer_Wrapper --
1204 --------------------------
1206 procedure Gen_CodePeer_Wrapper
is
1207 Callee_Name
: constant String := "Ada_Main_Program";
1210 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1211 WBI
(" procedure " & CodePeer_Wrapper_Name
& " is ");
1213 WBI
(" " & Callee_Name
& ";");
1216 WBI
(" function " & CodePeer_Wrapper_Name
& " return Integer is");
1218 WBI
(" return " & Callee_Name
& ";");
1221 WBI
(" end " & CodePeer_Wrapper_Name
& ";");
1223 end Gen_CodePeer_Wrapper
;
1225 --------------------
1226 -- Gen_Elab_Calls --
1227 --------------------
1229 procedure Gen_Elab_Calls
(Elab_Order
: Unit_Id_Array
) is
1230 Check_Elab_Flag
: Boolean;
1233 -- Loop through elaboration order entries
1235 for E
in Elab_Order
'Range loop
1237 Unum
: constant Unit_Id
:= Elab_Order
(E
);
1238 U
: Unit_Record
renames Units
.Table
(Unum
);
1240 Unum_Spec
: Unit_Id
;
1241 -- This is the unit number of the spec that corresponds to
1242 -- this entry. It is the same as Unum except when the body
1243 -- and spec are different and we are currently processing
1244 -- the body, in which case it is the spec (Unum + 1).
1247 if U
.Utype
= Is_Body
then
1248 Unum_Spec
:= Unum
+ 1;
1253 -- Nothing to do if predefined unit in no run time mode
1255 if No_Run_Time_Mode
and then Is_Predefined_File_Name
(U
.Sfile
) then
1258 -- Likewise if this is an interface to a stand alone library
1260 elsif U
.SAL_Interface
then
1263 -- Case of no elaboration code
1267 -- In CodePeer mode, we special case subprogram bodies which
1268 -- are handled in the 'else' part below, and lead to a call
1269 -- to <subp>'Elab_Subp_Body.
1271 and then (not CodePeer_Mode
1275 or else U
.Utype
= Is_Spec
1276 or else U
.Utype
= Is_Spec_Only
1277 or else U
.Unit_Kind
/= 's')
1279 -- In the case of a body with a separate spec, where the
1280 -- separate spec has an elaboration entity defined, this is
1281 -- where we increment the elaboration entity if one exists.
1283 -- Likewise for lone specs with an elaboration entity defined
1284 -- despite No_Elaboration_Code, e.g. when requested to preserve
1287 if (U
.Utype
= Is_Body
or else U
.Utype
= Is_Spec_Only
)
1288 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1289 and then not CodePeer_Mode
1292 Set_Unit_Number
(Unum_Spec
);
1293 Set_String
(" := E");
1294 Set_Unit_Number
(Unum_Spec
);
1295 Set_String
(" + 1;");
1296 Write_Statement_Buffer
;
1299 -- Here if elaboration code is present. If binding a library
1300 -- or if there is a non-Ada main subprogram then we generate:
1302 -- if uname_E = 0 then
1303 -- uname'elab_[spec|body];
1305 -- uname_E := uname_E + 1;
1307 -- Otherwise, elaboration routines are called unconditionally:
1309 -- uname'elab_[spec|body];
1310 -- uname_E := uname_E + 1;
1312 -- The uname_E increment is skipped if this is a separate spec,
1313 -- since it will be done when we process the body.
1315 -- In CodePeer mode, we do not generate any reference to xxx_E
1316 -- variables, only calls to 'Elab* subprograms.
1319 -- Check incompatibilities with No_Multiple_Elaboration
1321 if not CodePeer_Mode
1322 and then Cumulative_Restrictions
.Set
(No_Multiple_Elaboration
)
1324 -- Force_Checking_Of_Elaboration_Flags (-F) not allowed
1326 if Force_Checking_Of_Elaboration_Flags
then
1328 ("-F (force elaboration checks) switch not allowed "
1329 & "with restriction No_Multiple_Elaboration active");
1331 -- Interfacing of libraries not allowed
1333 elsif Interface_Library_Unit
then
1335 ("binding of interfaced libraries not allowed "
1336 & "with restriction No_Multiple_Elaboration active");
1338 -- Non-Ada main program not allowed
1340 elsif not Bind_Main_Program
then
1342 ("non-Ada main program not allowed "
1343 & "with restriction No_Multiple_Elaboration active");
1347 -- OK, see if we need to test elaboration flag
1350 Units
.Table
(Unum_Spec
).Set_Elab_Entity
1351 and then not CodePeer_Mode
1352 and then (Force_Checking_Of_Elaboration_Flags
1353 or Interface_Library_Unit
1354 or not Bind_Main_Program
);
1356 if Check_Elab_Flag
then
1357 Set_String
(" if E");
1358 Set_Unit_Number
(Unum_Spec
);
1359 Set_String
(" = 0 then");
1360 Write_Statement_Buffer
;
1365 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
1367 if Name_Buffer
(Name_Len
) = 's' then
1368 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1370 Name_Len
:= Name_Len
+ 8;
1372 -- Special case in CodePeer mode for subprogram bodies
1373 -- which correspond to CodePeer 'Elab_Subp_Body special
1376 elsif U
.Unit_Kind
= 's' and CodePeer_Mode
then
1377 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 13) :=
1379 Name_Len
:= Name_Len
+ 13;
1382 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1384 Name_Len
:= Name_Len
+ 8;
1387 Set_Casing
(U
.Icasing
);
1390 Write_Statement_Buffer
;
1392 if Check_Elab_Flag
then
1396 if U
.Utype
/= Is_Spec
1397 and then not CodePeer_Mode
1398 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1401 Set_Unit_Number
(Unum_Spec
);
1402 Set_String
(" := E");
1403 Set_Unit_Number
(Unum_Spec
);
1404 Set_String
(" + 1;");
1405 Write_Statement_Buffer
;
1412 ------------------------
1413 -- Gen_Elab_Externals --
1414 ------------------------
1416 procedure Gen_Elab_Externals
(Elab_Order
: Unit_Id_Array
) is
1418 if CodePeer_Mode
then
1422 for E
in Elab_Order
'Range loop
1424 Unum
: constant Unit_Id
:= Elab_Order
(E
);
1425 U
: Unit_Record
renames Units
.Table
(Unum
);
1428 -- Check for Elab_Entity to be set for this unit
1430 if U
.Set_Elab_Entity
1432 -- Don't generate reference for stand alone library
1434 and then not U
.SAL_Interface
1436 -- Don't generate reference for predefined file in No_Run_Time
1437 -- mode, since we don't include the object files in this case
1441 and then Is_Predefined_File_Name
(U
.Sfile
))
1443 Get_Name_String
(U
.Sfile
);
1446 Set_Unit_Number
(Unum
);
1447 Set_String
(" : Short_Integer; pragma Import (Ada, E");
1448 Set_Unit_Number
(Unum
);
1449 Set_String
(", """);
1450 Get_Name_String
(U
.Uname
);
1452 Set_String
("_E"");");
1453 Write_Statement_Buffer
;
1459 end Gen_Elab_Externals
;
1461 --------------------
1462 -- Gen_Elab_Order --
1463 --------------------
1465 procedure Gen_Elab_Order
(Elab_Order
: Unit_Id_Array
) is
1468 WBI
(" -- BEGIN ELABORATION ORDER");
1470 for J
in Elab_Order
'Range loop
1471 Set_String
(" -- ");
1472 Get_Name_String
(Units
.Table
(Elab_Order
(J
)).Uname
);
1474 Write_Statement_Buffer
;
1477 WBI
(" -- END ELABORATION ORDER");
1480 --------------------------
1481 -- Gen_Finalize_Library --
1482 --------------------------
1484 procedure Gen_Finalize_Library
(Elab_Order
: Unit_Id_Array
) is
1485 procedure Gen_Header
;
1486 -- Generate the header of the finalization routine
1492 procedure Gen_Header
is
1494 WBI
(" procedure finalize_library is");
1502 Uspec
: Unit_Record
;
1505 -- Start of processing for Gen_Finalize_Library
1508 if CodePeer_Mode
then
1512 for E
in reverse Elab_Order
'Range loop
1513 Unum
:= Elab_Order
(E
);
1514 U
:= Units
.Table
(Unum
);
1516 -- Dealing with package bodies is a little complicated. In such
1517 -- cases we must retrieve the package spec since it contains the
1518 -- spec of the body finalizer.
1520 if U
.Utype
= Is_Body
then
1522 Uspec
:= Units
.Table
(Unum
);
1527 Get_Name_String
(Uspec
.Uname
);
1529 -- We are only interested in non-generic packages
1531 if U
.Unit_Kind
/= 'p' or else U
.Is_Generic
then
1534 -- That aren't an interface to a stand alone library
1536 elsif U
.SAL_Interface
then
1539 -- Case of no finalization
1541 elsif not U
.Has_Finalizer
then
1543 -- The only case in which we have to do something is if this
1544 -- is a body, with a separate spec, where the separate spec
1545 -- has a finalizer. In that case, this is where we decrement
1546 -- the elaboration entity.
1548 if U
.Utype
= Is_Body
and then Uspec
.Has_Finalizer
then
1549 if not Lib_Final_Built
then
1551 Lib_Final_Built
:= True;
1555 Set_Unit_Number
(Unum
);
1556 Set_String
(" := E");
1557 Set_Unit_Number
(Unum
);
1558 Set_String
(" - 1;");
1559 Write_Statement_Buffer
;
1563 if not Lib_Final_Built
then
1565 Lib_Final_Built
:= True;
1570 -- procedure F<Count>;
1572 Set_String
(" declare");
1573 Write_Statement_Buffer
;
1575 Set_String
(" procedure F");
1578 Write_Statement_Buffer
;
1581 -- pragma Import (Ada, F<Count>,
1582 -- "xx__yy__finalize_[body|spec]");
1584 Set_String
(" pragma Import (Ada, F");
1586 Set_String
(", """);
1588 -- Perform name construction
1591 Set_String
("__finalize_");
1593 -- Package spec processing
1595 if U
.Utype
= Is_Spec
1596 or else U
.Utype
= Is_Spec_Only
1598 Set_String
("spec");
1600 -- Package body processing
1603 Set_String
("body");
1606 Set_String
(""");");
1607 Write_Statement_Buffer
;
1609 -- If binding a library or if there is a non-Ada main subprogram
1610 -- then we generate:
1613 -- uname_E := uname_E - 1;
1614 -- if uname_E = 0 then
1619 -- Otherwise, finalization routines are called unconditionally:
1622 -- uname_E := uname_E - 1;
1626 -- The uname_E decrement is skipped if this is a separate spec,
1627 -- since it will be done when we process the body.
1631 if U
.Utype
/= Is_Spec
then
1633 Set_Unit_Number
(Unum
);
1634 Set_String
(" := E");
1635 Set_Unit_Number
(Unum
);
1636 Set_String
(" - 1;");
1637 Write_Statement_Buffer
;
1640 if Interface_Library_Unit
or not Bind_Main_Program
then
1641 Set_String
(" if E");
1642 Set_Unit_Number
(Unum
);
1643 Set_String
(" = 0 then");
1644 Write_Statement_Buffer
;
1651 Write_Statement_Buffer
;
1653 if Interface_Library_Unit
or not Bind_Main_Program
then
1663 if Lib_Final_Built
then
1665 -- It is possible that the finalization of a library-level object
1666 -- raised an exception. In that case import the actual exception
1667 -- and the routine necessary to raise it.
1670 WBI
(" procedure Reraise_Library_Exception_If_Any;");
1672 Set_String
(" pragma Import (Ada, ");
1673 Set_String
("Reraise_Library_Exception_If_Any, ");
1674 Set_String
("""__gnat_reraise_library_exception_if_any"");");
1675 Write_Statement_Buffer
;
1678 WBI
(" Reraise_Library_Exception_If_Any;");
1680 WBI
(" end finalize_library;");
1683 end Gen_Finalize_Library
;
1689 procedure Gen_Main
is
1691 if not No_Main_Subprogram
then
1693 -- To call the main program, we declare it using a pragma Import
1694 -- Ada with the right link name.
1696 -- It might seem more obvious to "with" the main program, and call
1697 -- it in the normal Ada manner. We do not do this for three
1700 -- 1. It is more efficient not to recompile the main program
1701 -- 2. We are not entitled to assume the source is accessible
1702 -- 3. We don't know what options to use to compile it
1704 -- It is really reason 3 that is most critical (indeed we used
1705 -- to generate the "with", but several regression tests failed).
1707 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1708 WBI
(" function Ada_Main_Program return Integer;");
1710 WBI
(" procedure Ada_Main_Program;");
1713 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1714 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1715 Set_Main_Program_Name
;
1716 Set_String
(""");");
1718 Write_Statement_Buffer
;
1721 -- For CodePeer, declare a wrapper for the user-defined main program
1723 if CodePeer_Mode
then
1724 Gen_CodePeer_Wrapper
;
1728 if Exit_Status_Supported_On_Target
then
1729 Set_String
(" function ");
1731 Set_String
(" procedure ");
1734 Set_String
(Get_Main_Name
);
1736 if Command_Line_Args_On_Target
then
1737 Write_Statement_Buffer
;
1738 WBI
(" (argc : Integer;");
1739 WBI
(" argv : System.Address;");
1740 WBI
(" envp : System.Address)");
1742 if Exit_Status_Supported_On_Target
then
1743 WBI
(" return Integer");
1749 if Exit_Status_Supported_On_Target
then
1750 Set_String
(" return Integer is");
1755 Write_Statement_Buffer
;
1758 if Opt
.Default_Exit_Status
/= 0
1759 and then Bind_Main_Program
1760 and then not Configurable_Run_Time_Mode
1762 WBI
(" procedure Set_Exit_Status (Status : Integer);");
1763 WBI
(" pragma Import (C, Set_Exit_Status, " &
1764 """__gnat_set_exit_status"");");
1768 -- Initialize and Finalize
1770 if not CodePeer_Mode
1771 and then not Cumulative_Restrictions
.Set
(No_Finalization
)
1773 WBI
(" procedure Initialize (Addr : System.Address);");
1774 WBI
(" pragma Import (C, Initialize, ""__gnat_initialize"");");
1776 WBI
(" procedure Finalize;");
1777 WBI
(" pragma Import (C, Finalize, ""__gnat_finalize"");");
1780 -- If we want to analyze the stack, we must import corresponding symbols
1782 if Dynamic_Stack_Measurement
then
1784 WBI
(" procedure Output_Results;");
1785 WBI
(" pragma Import (C, Output_Results, " &
1786 """__gnat_stack_usage_output_results"");");
1790 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1791 WBI
(" pragma Import (C, Initialize_Stack_Analysis, " &
1792 """__gnat_stack_usage_initialize"");");
1795 -- Deal with declarations for main program case
1797 if not No_Main_Subprogram
then
1798 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1799 WBI
(" Result : Integer;");
1803 if Bind_Main_Program
1804 and not Suppress_Standard_Library_On_Target
1805 and not CodePeer_Mode
1807 WBI
(" SEH : aliased array (1 .. 2) of Integer;");
1812 -- Generate a reference to Ada_Main_Program_Name. This symbol is not
1813 -- referenced elsewhere in the generated program, but is needed by
1814 -- the debugger (that's why it is generated in the first place). The
1815 -- reference stops Ada_Main_Program_Name from being optimized away by
1816 -- smart linkers, such as the AiX linker.
1818 -- Because this variable is unused, we make this variable "aliased"
1819 -- with a pragma Volatile in order to tell the compiler to preserve
1820 -- this variable at any level of optimization.
1822 if Bind_Main_Program
and not CodePeer_Mode
then
1823 WBI
(" Ensure_Reference : aliased System.Address := " &
1824 "Ada_Main_Program_Name'Address;");
1825 WBI
(" pragma Volatile (Ensure_Reference);");
1831 -- Acquire command line arguments if present on target
1833 if CodePeer_Mode
then
1836 elsif Command_Line_Args_On_Target
then
1837 WBI
(" gnat_argc := argc;");
1838 WBI
(" gnat_argv := argv;");
1839 WBI
(" gnat_envp := envp;");
1842 -- If configurable run time and no command line args, then nothing needs
1843 -- to be done since the gnat_argc/argv/envp variables are suppressed in
1846 elsif Configurable_Run_Time_On_Target
then
1849 -- Otherwise set dummy values (to be filled in by some other unit?)
1852 WBI
(" gnat_argc := 0;");
1853 WBI
(" gnat_argv := System.Null_Address;");
1854 WBI
(" gnat_envp := System.Null_Address;");
1857 if Opt
.Default_Exit_Status
/= 0
1858 and then Bind_Main_Program
1859 and then not Configurable_Run_Time_Mode
1861 Set_String
(" Set_Exit_Status (");
1862 Set_Int
(Opt
.Default_Exit_Status
);
1864 Write_Statement_Buffer
;
1867 if Dynamic_Stack_Measurement
then
1868 Set_String
(" Initialize_Stack_Analysis (");
1869 Set_Int
(Dynamic_Stack_Measurement_Array_Size
);
1871 Write_Statement_Buffer
;
1874 if not Cumulative_Restrictions
.Set
(No_Finalization
)
1875 and then not CodePeer_Mode
1877 if not No_Main_Subprogram
1878 and then Bind_Main_Program
1879 and then not Suppress_Standard_Library_On_Target
1881 WBI
(" Initialize (SEH'Address);");
1883 WBI
(" Initialize (System.Null_Address);");
1887 WBI
(" " & Ada_Init_Name
.all & ";");
1889 if not No_Main_Subprogram
then
1890 if CodePeer_Mode
then
1891 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1892 WBI
(" " & CodePeer_Wrapper_Name
& ";");
1894 WBI
(" Result := " & CodePeer_Wrapper_Name
& ";");
1897 elsif ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1898 WBI
(" Ada_Main_Program;");
1901 WBI
(" Result := Ada_Main_Program;");
1905 -- Adafinal call is skipped if no finalization
1907 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
1911 -- Prints the result of static stack analysis
1913 if Dynamic_Stack_Measurement
then
1914 WBI
(" Output_Results;");
1917 -- Finalize is only called if we have a run time
1919 if not Cumulative_Restrictions
.Set
(No_Finalization
)
1920 and then not CodePeer_Mode
1927 if Exit_Status_Supported_On_Target
then
1928 if No_Main_Subprogram
1929 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
1931 WBI
(" return (gnat_exit_status);");
1933 WBI
(" return (Result);");
1941 ------------------------------
1942 -- Gen_Object_Files_Options --
1943 ------------------------------
1945 procedure Gen_Object_Files_Options
(Elab_Order
: Unit_Id_Array
) is
1947 -- This keeps track of the position in the sorted set of entries in the
1948 -- Linker_Options table of where the first entry from an internal file
1951 Linker_Option_List_Started
: Boolean := False;
1952 -- Set to True when "LINKER OPTION LIST" is displayed
1954 procedure Write_Linker_Option
;
1955 -- Write binder info linker option
1957 -------------------------
1958 -- Write_Linker_Option --
1959 -------------------------
1961 procedure Write_Linker_Option
is
1966 -- Loop through string, breaking at null's
1969 while Start
< Name_Len
loop
1971 -- Find null ending this section
1974 while Name_Buffer
(Stop
) /= ASCII
.NUL
1975 and then Stop
<= Name_Len
loop
1979 -- Process section if non-null
1981 if Stop
> Start
then
1982 if Output_Linker_Option_List
then
1983 if not Zero_Formatting
then
1984 if not Linker_Option_List_Started
then
1985 Linker_Option_List_Started
:= True;
1987 Write_Str
(" LINKER OPTION LIST");
1995 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
1998 WBI
(" -- " & Name_Buffer
(Start
.. Stop
- 1));
2003 end Write_Linker_Option
;
2005 -- Start of processing for Gen_Object_Files_Options
2008 WBI
("-- BEGIN Object file/option list");
2010 if Object_List_Filename
/= null then
2011 Set_List_File
(Object_List_Filename
.all);
2014 for E
in Elab_Order
'Range loop
2016 -- If not spec that has an associated body, then generate a comment
2017 -- giving the name of the corresponding object file.
2019 if not Units
.Table
(Elab_Order
(E
)).SAL_Interface
2020 and then Units
.Table
(Elab_Order
(E
)).Utype
/= Is_Spec
2024 (Units
.Table
(Elab_Order
(E
)).My_ALI
).Ofile_Full_Name
);
2026 -- If the presence of an object file is necessary or if it exists,
2029 if not Hostparm
.Exclude_Missing_Objects
2031 System
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
2033 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
2035 if Output_Object_List
then
2036 Write_Str
(Name_Buffer
(1 .. Name_Len
));
2043 if Object_List_Filename
/= null then
2047 -- Add a "-Ldir" for each directory in the object path
2049 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
2051 Dir
: constant String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
2055 Add_Str_To_Name_Buffer
("-L");
2056 Add_Str_To_Name_Buffer
(Dir
.all);
2057 Write_Linker_Option
;
2061 if not (Opt
.No_Run_Time_Mode
or Opt
.No_Stdlib
) then
2064 if Opt
.Shared_Libgnat
then
2065 Add_Str_To_Name_Buffer
("-shared");
2067 Add_Str_To_Name_Buffer
("-static");
2070 -- Write directly to avoid inclusion in -K output as -static and
2071 -- -shared are not usually specified linker options.
2073 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
2076 -- Sort linker options
2078 -- This sort accomplishes two important purposes:
2080 -- a) All application files are sorted to the front, and all GNAT
2081 -- internal files are sorted to the end. This results in a well
2082 -- defined dividing line between the two sets of files, for the
2083 -- purpose of inserting certain standard library references into
2084 -- the linker arguments list.
2086 -- b) Given two different units, we sort the linker options so that
2087 -- those from a unit earlier in the elaboration order comes later
2088 -- in the list. This is a heuristic designed to create a more
2089 -- friendly order of linker options when the operations appear in
2090 -- separate units. The idea is that if unit A must be elaborated
2091 -- before unit B, then it is more likely that B references
2092 -- libraries included by A, than vice versa, so we want libraries
2093 -- included by A to come after libraries included by B.
2095 -- These two criteria are implemented by function Lt_Linker_Option. Note
2096 -- that a special case of b) is that specs are elaborated before bodies,
2097 -- so linker options from specs come after linker options for bodies,
2098 -- and again, the assumption is that libraries used by the body are more
2099 -- likely to reference libraries used by the spec, than vice versa.
2102 (Linker_Options
.Last
,
2103 Move_Linker_Option
'Access,
2104 Lt_Linker_Option
'Access);
2106 -- Write user linker options, i.e. the set of linker options that come
2107 -- from all files other than GNAT internal files, Lgnat is left set to
2108 -- point to the first entry from a GNAT internal file, or past the end
2109 -- of the entries if there are no internal files.
2111 Lgnat
:= Linker_Options
.Last
+ 1;
2113 for J
in 1 .. Linker_Options
.Last
loop
2114 if not Linker_Options
.Table
(J
).Internal_File
then
2115 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2116 Write_Linker_Option
;
2123 -- Now we insert standard linker options that must appear after the
2124 -- entries from user files, and before the entries from GNAT run-time
2125 -- files. The reason for this decision is that libraries referenced
2126 -- by internal routines may reference these standard library entries.
2128 -- Note that we do not insert anything when pragma No_Run_Time has
2129 -- been specified or when the standard libraries are not to be used,
2130 -- otherwise on some platforms, we may get duplicate symbols when
2131 -- linking (not clear if this is still the case, but it is harmless).
2133 if not (Opt
.No_Run_Time_Mode
or else Opt
.No_Stdlib
) then
2137 if Opt
.Shared_Libgnat
then
2138 Add_Str_To_Name_Buffer
(Shared_Lib
("gnarl"));
2140 Add_Str_To_Name_Buffer
("-lgnarl");
2143 Write_Linker_Option
;
2148 if Opt
.Shared_Libgnat
then
2149 Add_Str_To_Name_Buffer
(Shared_Lib
("gnat"));
2151 Add_Str_To_Name_Buffer
("-lgnat");
2154 Write_Linker_Option
;
2157 -- Write linker options from all internal files
2159 for J
in Lgnat
.. Linker_Options
.Last
loop
2160 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2161 Write_Linker_Option
;
2164 if Output_Linker_Option_List
and then not Zero_Formatting
then
2168 WBI
("-- END Object file/option list ");
2169 end Gen_Object_Files_Options
;
2171 ---------------------
2172 -- Gen_Output_File --
2173 ---------------------
2175 procedure Gen_Output_File
2177 Elab_Order
: Unit_Id_Array
)
2180 -- Acquire settings for Interrupt_State pragmas
2182 Set_IS_Pragma_Table
;
2184 -- Acquire settings for Priority_Specific_Dispatching pragma
2186 Set_PSD_Pragma_Table
;
2188 -- Override time slice value if -T switch is set
2190 if Time_Slice_Set
then
2191 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
2194 -- Count number of elaboration calls
2196 for E
in Elab_Order
'Range loop
2197 if Units
.Table
(Elab_Order
(E
)).No_Elab
then
2200 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
2204 -- Count the number of statically allocated stacks to be generated by
2205 -- the binder. If the user has specified the number of default-sized
2206 -- secondary stacks, use that number. Otherwise start the count at one
2207 -- as the binder is responsible for creating a secondary stack for the
2210 if Opt
.Quantity_Of_Default_Size_Sec_Stacks
/= -1 then
2211 Num_Sec_Stacks
:= Quantity_Of_Default_Size_Sec_Stacks
;
2212 elsif Sec_Stack_Used
then
2213 Num_Sec_Stacks
:= 1;
2216 for J
in Units
.First
.. Units
.Last
loop
2217 Num_Primary_Stacks
:=
2218 Num_Primary_Stacks
+ Units
.Table
(J
).Primary_Stack_Count
;
2221 Num_Sec_Stacks
+ Units
.Table
(J
).Sec_Stack_Count
;
2224 -- Generate output file in appropriate language
2226 Gen_Output_File_Ada
(Filename
, Elab_Order
);
2227 end Gen_Output_File
;
2229 -------------------------
2230 -- Gen_Output_File_Ada --
2231 -------------------------
2233 procedure Gen_Output_File_Ada
2234 (Filename
: String; Elab_Order
: Unit_Id_Array
)
2236 Ada_Main
: constant String := Get_Ada_Main_Name
;
2237 -- Name to be used for generated Ada main program. See the body of
2238 -- function Get_Ada_Main_Name for details on the form of the name.
2240 Needs_Library_Finalization
: constant Boolean :=
2241 not Configurable_Run_Time_On_Target
2242 and then Has_Finalizer
(Elab_Order
);
2243 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2244 -- non-terminating, so we do not want finalization.
2247 -- Name of generated bind file (spec)
2250 -- Name of generated bind file (body)
2253 -- Create spec first
2255 Create_Binder_Output
(Filename
, 's', Bfiles
);
2257 -- We always compile the binder file in Ada 95 mode so that we properly
2258 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2259 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
2261 WBI
("pragma Warnings (Off);");
2262 WBI
("pragma Ada_95;");
2264 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2265 -- then we need to make sure that the binder program is compiled with
2266 -- the same restriction, so that no exception tables are generated.
2268 if Cumulative_Restrictions
.Set
(No_Exception_Handlers
) then
2269 WBI
("pragma Restrictions (No_Exception_Handlers);");
2272 -- Same processing for Restrictions (No_Exception_Propagation)
2274 if Cumulative_Restrictions
.Set
(No_Exception_Propagation
) then
2275 WBI
("pragma Restrictions (No_Exception_Propagation);");
2278 -- Same processing for pragma No_Run_Time
2280 if No_Run_Time_Mode
then
2281 WBI
("pragma No_Run_Time;");
2284 -- Generate with of System so we can reference System.Address
2286 WBI
("with System;");
2288 -- Generate with of System.Initialize_Scalars if active
2290 if Initialize_Scalars_Used
then
2291 WBI
("with System.Scalar_Values;");
2294 -- Generate withs of System.Secondary_Stack and System.Parameters to
2295 -- allow the generation of the default-sized secondary stack pool.
2297 if Sec_Stack_Used
then
2298 WBI
("with System.Parameters;");
2299 WBI
("with System.Secondary_Stack;");
2302 Resolve_Binder_Options
(Elab_Order
);
2304 -- Generate standard with's
2306 if not Suppress_Standard_Library_On_Target
then
2307 if CodePeer_Mode
then
2308 WBI
("with System.Standard_Library;");
2312 WBI
("package " & Ada_Main
& " is");
2314 -- Main program case
2316 if Bind_Main_Program
then
2317 -- Generate argc/argv stuff unless suppressed
2319 if Command_Line_Args_On_Target
2320 or not Configurable_Run_Time_On_Target
2323 WBI
(" gnat_argc : Integer;");
2324 WBI
(" gnat_argv : System.Address;");
2325 WBI
(" gnat_envp : System.Address;");
2327 -- If the standard library is not suppressed, these variables
2328 -- are in the run-time data area for easy run time access.
2330 if not Suppress_Standard_Library_On_Target
then
2332 WBI
(" pragma Import (C, gnat_argc);");
2333 WBI
(" pragma Import (C, gnat_argv);");
2334 WBI
(" pragma Import (C, gnat_envp);");
2338 -- Define exit status. Again in normal mode, this is in the run-time
2339 -- library, and is initialized there, but in the configurable
2340 -- run-time case, the variable is declared and initialized in this
2345 if Configurable_Run_Time_Mode
then
2346 if Exit_Status_Supported_On_Target
then
2347 WBI
(" gnat_exit_status : Integer := 0;");
2351 WBI
(" gnat_exit_status : Integer;");
2352 WBI
(" pragma Import (C, gnat_exit_status);");
2355 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2356 -- the main program. Otherwise, it can lead under some circumstances
2357 -- to a symbol duplication during the link (for instance when a C
2358 -- program uses two Ada libraries). Also zero terminate the string
2359 -- so that its end can be found reliably at run time.
2362 WBI
(" GNAT_Version : constant String :=");
2363 WBI
(" """ & Ver_Prefix
&
2364 Gnat_Version_String
&
2366 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2369 Set_String
(" Ada_Main_Program_Name : constant String := """);
2370 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2372 Set_Main_Program_Name
;
2373 Set_String
(""" & ASCII.NUL;");
2375 Write_Statement_Buffer
;
2378 (" pragma Export (C, Ada_Main_Program_Name, " &
2379 """__gnat_ada_main_program_name"");");
2383 WBI
(" procedure " & Ada_Init_Name
.all & ";");
2384 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
2385 Ada_Init_Name
.all & """);");
2387 -- If -a has been specified use pragma Linker_Constructor for the init
2388 -- procedure and pragma Linker_Destructor for the final procedure.
2390 if Use_Pragma_Linker_Constructor
then
2391 WBI
(" pragma Linker_Constructor (" & Ada_Init_Name
.all & ");");
2394 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2396 WBI
(" procedure " & Ada_Final_Name
.all & ";");
2397 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
2398 Ada_Final_Name
.all & """);");
2400 if Use_Pragma_Linker_Constructor
then
2401 WBI
(" pragma Linker_Destructor (" & Ada_Final_Name
.all & ");");
2405 if Bind_Main_Program
then
2409 if Exit_Status_Supported_On_Target
then
2410 Set_String
(" function ");
2412 Set_String
(" procedure ");
2415 Set_String
(Get_Main_Name
);
2417 -- Generate argument list if present
2419 if Command_Line_Args_On_Target
then
2420 Write_Statement_Buffer
;
2421 WBI
(" (argc : Integer;");
2422 WBI
(" argv : System.Address;");
2424 (" envp : System.Address)");
2426 if Exit_Status_Supported_On_Target
then
2427 Write_Statement_Buffer
;
2428 WBI
(" return Integer;");
2430 Write_Statement_Buffer
(";");
2434 if Exit_Status_Supported_On_Target
then
2435 Write_Statement_Buffer
(" return Integer;");
2437 Write_Statement_Buffer
(";");
2441 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
2442 Get_Main_Name
& """);");
2445 -- Generate version numbers for units, only if needed. Be very safe on
2448 if not Configurable_Run_Time_On_Target
2449 or else System_Version_Control_Used
2450 or else not Bind_Main_Program
2455 Gen_Elab_Order
(Elab_Order
);
2460 WBI
("end " & Ada_Main
& ";");
2461 Close_Binder_Output
;
2463 -- Prepare to write body
2465 Create_Binder_Output
(Filename
, 'b', Bfileb
);
2467 -- We always compile the binder file in Ada 95 mode so that we properly
2468 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2469 -- of the Ada 2005/2012 constructs are needed by the binder file.
2471 WBI
("pragma Warnings (Off);");
2472 WBI
("pragma Ada_95;");
2474 -- Output Source_File_Name pragmas which look like
2476 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2477 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2479 -- where sss/bbb are the spec/body file names respectively
2481 Get_Name_String
(Bfiles
);
2482 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2484 WBI
("pragma Source_File_Name (" &
2486 ", Spec_File_Name => """ &
2487 Name_Buffer
(1 .. Name_Len
+ 3));
2489 Get_Name_String
(Bfileb
);
2490 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2492 WBI
("pragma Source_File_Name (" &
2494 ", Body_File_Name => """ &
2495 Name_Buffer
(1 .. Name_Len
+ 3));
2497 -- Generate pragma Suppress (Overflow_Check). This is needed for recent
2498 -- versions of the compiler which have overflow checks on by default.
2499 -- We do not want overflow checking enabled for the increments of the
2500 -- elaboration variables (since this can cause an unwanted reference to
2501 -- the last chance exception handler for limited run-times).
2503 WBI
("pragma Suppress (Overflow_Check);");
2505 -- Generate with of System.Restrictions to initialize
2506 -- Run_Time_Restrictions.
2508 if System_Restrictions_Used
2509 and not Suppress_Standard_Library_On_Target
2512 WBI
("with System.Restrictions;");
2515 -- Generate with of Ada.Exceptions if needs library finalization
2517 if Needs_Library_Finalization
then
2518 WBI
("with Ada.Exceptions;");
2521 -- Generate with of System.Elaboration_Allocators if the restriction
2522 -- No_Standard_Allocators_After_Elaboration was present.
2524 if Cumulative_Restrictions
.Set
2525 (No_Standard_Allocators_After_Elaboration
)
2527 WBI
("with System.Elaboration_Allocators;");
2530 -- Generate start of package body
2533 WBI
("package body " & Ada_Main
& " is");
2536 -- Generate externals for elaboration entities
2538 Gen_Elab_Externals
(Elab_Order
);
2540 -- Generate default-sized secondary stacks pool. At least one stack is
2541 -- created and assigned to the environment task if secondary stacks are
2542 -- used by the program.
2544 if Sec_Stack_Used
then
2545 Set_String
(" Sec_Default_Sized_Stacks");
2546 Set_String
(" : array (1 .. ");
2547 Set_Int
(Num_Sec_Stacks
);
2548 Set_String
(") of aliased System.Secondary_Stack.SS_Stack (");
2550 if Opt
.Default_Sec_Stack_Size
/= No_Stack_Size
then
2551 Set_Int
(Opt
.Default_Sec_Stack_Size
);
2553 Set_String
("System.Parameters.Runtime_Default_Sec_Stack_Size");
2557 Write_Statement_Buffer
;
2561 -- Generate reference
2563 if not CodePeer_Mode
then
2564 if not Suppress_Standard_Library_On_Target
then
2566 -- Generate Priority_Specific_Dispatching pragma string
2569 (" Local_Priority_Specific_Dispatching : " &
2570 "constant String := """);
2572 for J
in 0 .. PSD_Pragma_Settings
.Last
loop
2573 Set_Char
(PSD_Pragma_Settings
.Table
(J
));
2577 Write_Statement_Buffer
;
2579 -- Generate Interrupt_State pragma string
2581 Set_String
(" Local_Interrupt_States : constant String := """);
2583 for J
in 0 .. IS_Pragma_Settings
.Last
loop
2584 Set_Char
(IS_Pragma_Settings
.Table
(J
));
2588 Write_Statement_Buffer
;
2592 if not Suppress_Standard_Library_On_Target
then
2594 -- The B.1(39) implementation advice says that the adainit and
2595 -- adafinal routines should be idempotent. Generate a flag to
2596 -- ensure that. This is not needed if we are suppressing the
2597 -- standard library since it would never be referenced.
2599 WBI
(" Is_Elaborated : Boolean := False;");
2601 -- Generate bind environment string
2603 Gen_Bind_Env_String
;
2609 -- Generate the adafinal routine unless there is no finalization to do
2611 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2612 if Needs_Library_Finalization
then
2613 Gen_Finalize_Library
(Elab_Order
);
2619 Gen_Adainit
(Elab_Order
);
2621 if Bind_Main_Program
then
2625 -- Output object file list and the Ada body is complete
2627 Gen_Object_Files_Options
(Elab_Order
);
2630 WBI
("end " & Ada_Main
& ";");
2632 Close_Binder_Output
;
2633 end Gen_Output_File_Ada
;
2635 ----------------------
2636 -- Gen_Restrictions --
2637 ----------------------
2639 procedure Gen_Restrictions
is
2643 if Suppress_Standard_Library_On_Target
2644 or not System_Restrictions_Used
2649 WBI
(" System.Restrictions.Run_Time_Restrictions :=");
2655 for J
in Cumulative_Restrictions
.Set
'Range loop
2656 Set_Boolean
(Cumulative_Restrictions
.Set
(J
));
2660 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2661 Write_Statement_Buffer
;
2667 Set_String_Replace
("),");
2668 Write_Statement_Buffer
;
2669 Set_String
(" Value => (");
2671 for J
in Cumulative_Restrictions
.Value
'Range loop
2672 Set_Int
(Int
(Cumulative_Restrictions
.Value
(J
)));
2676 Set_String_Replace
("),");
2677 Write_Statement_Buffer
;
2678 WBI
(" Violated =>");
2682 for J
in Cumulative_Restrictions
.Violated
'Range loop
2683 Set_Boolean
(Cumulative_Restrictions
.Violated
(J
));
2687 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2688 Write_Statement_Buffer
;
2694 Set_String_Replace
("),");
2695 Write_Statement_Buffer
;
2696 Set_String
(" Count => (");
2698 for J
in Cumulative_Restrictions
.Count
'Range loop
2699 Set_Int
(Int
(Cumulative_Restrictions
.Count
(J
)));
2703 Set_String_Replace
("),");
2704 Write_Statement_Buffer
;
2705 Set_String
(" Unknown => (");
2707 for J
in Cumulative_Restrictions
.Unknown
'Range loop
2708 Set_Boolean
(Cumulative_Restrictions
.Unknown
(J
));
2712 Set_String_Replace
("))");
2714 Write_Statement_Buffer
;
2715 end Gen_Restrictions
;
2721 -- This routine generates lines such as:
2723 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2724 -- pragma Export (C, unnnnn, unam);
2726 -- for each unit, where unam is the unit name suffixed by either B or S for
2727 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
2728 -- the version number, and nnnnn is a 5-digits serial number.
2730 procedure Gen_Versions
is
2731 Ubuf
: String (1 .. 6) := "u00000";
2733 procedure Increment_Ubuf
;
2734 -- Little procedure to increment the serial number
2736 --------------------
2737 -- Increment_Ubuf --
2738 --------------------
2740 procedure Increment_Ubuf
is
2742 for J
in reverse Ubuf
'Range loop
2743 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
2744 exit when Ubuf
(J
) <= '9';
2749 -- Start of processing for Gen_Versions
2754 WBI
(" type Version_32 is mod 2 ** 32;");
2755 for U
in Units
.First
.. Units
.Last
loop
2756 if not Units
.Table
(U
).SAL_Interface
2757 and then (not Bind_For_Library
2758 or else Units
.Table
(U
).Directly_Scanned
)
2761 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
2762 Units
.Table
(U
).Version
& "#;");
2763 Set_String
(" pragma Export (C, ");
2765 Set_String
(", """);
2767 Get_Name_String
(Units
.Table
(U
).Uname
);
2769 for K
in 1 .. Name_Len
loop
2770 if Name_Buffer
(K
) = '.' then
2774 elsif Name_Buffer
(K
) = '%' then
2778 Set_Char
(Name_Buffer
(K
));
2782 if Name_Buffer
(Name_Len
) = 's' then
2788 Set_String
(""");");
2789 Write_Statement_Buffer
;
2794 ------------------------
2795 -- Get_Main_Unit_Name --
2796 ------------------------
2798 function Get_Main_Unit_Name
(S
: String) return String is
2799 Result
: String := S
;
2802 for J
in S
'Range loop
2803 if Result
(J
) = '.' then
2809 end Get_Main_Unit_Name
;
2811 -----------------------
2812 -- Get_Ada_Main_Name --
2813 -----------------------
2815 function Get_Ada_Main_Name
return String is
2816 Suffix
: constant String := "_00";
2817 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
2818 Opt
.Ada_Main_Name
.all & Suffix
;
2822 -- For CodePeer, we want reproducible names (independent of other mains
2823 -- that may or may not be present) that don't collide when analyzing
2824 -- multiple mains and which are easily recognizable as "ada_main" names.
2826 if CodePeer_Mode
then
2827 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2831 Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
- 2));
2834 -- This loop tries the following possibilities in order
2840 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2841 -- it is set to 'ada_main'.
2843 for J
in 0 .. 99 loop
2845 Nlen
:= Name
'Length - Suffix
'Length;
2847 Nlen
:= Name
'Length;
2848 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
2849 Name
(Name
'Last - 1) :=
2850 Character'Val (J
/ 10 + Character'Pos ('0'));
2853 for K
in ALIs
.First
.. ALIs
.Last
loop
2854 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
2856 -- Get unit name, removing %b or %e at end
2858 Get_Name_String
(Units
.Table
(L
).Uname
);
2859 Name_Len
:= Name_Len
- 2;
2861 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
2867 return Name
(1 .. Nlen
);
2873 -- If we fall through, just use a peculiar unlikely name
2875 return ("Qwertyuiop");
2876 end Get_Ada_Main_Name
;
2882 function Get_Main_Name
return String is
2884 -- Explicit name given with -M switch
2886 if Bind_Alternate_Main_Name
then
2887 return Alternate_Main_Name
.all;
2889 -- Case of main program name to be used directly
2891 elsif Use_Ada_Main_Program_Name_On_Target
then
2893 -- Get main program name
2895 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2897 -- If this is a child name, return only the name of the child, since
2898 -- we can't have dots in a nested program name. Note that we do not
2899 -- include the %b at the end of the unit name.
2901 for J
in reverse 1 .. Name_Len
- 2 loop
2902 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
2903 return Name_Buffer
(J
.. Name_Len
- 2);
2907 raise Program_Error
; -- impossible exit
2909 -- Case where "main" is to be used as default
2916 ---------------------
2917 -- Get_WC_Encoding --
2918 ---------------------
2920 function Get_WC_Encoding
return Character is
2922 -- If encoding method specified by -W switch, then return it
2924 if Wide_Character_Encoding_Method_Specified
then
2925 return WC_Encoding_Letters
(Wide_Character_Encoding_Method
);
2927 -- If no main program, and not specified, set brackets, we really have
2928 -- no better choice. If some other encoding is required when there is
2929 -- no main, it must be set explicitly using -Wx.
2931 -- Note: if the ALI file always passed the wide character encoding of
2932 -- every file, then we could use the encoding of the initial specified
2933 -- file, but this information is passed only for potential main
2934 -- programs. We could fix this sometime, but it is a very minor point
2935 -- (wide character default encoding for [Wide_[Wide_]]Text_IO when there
2936 -- is no main program).
2938 elsif No_Main_Subprogram
then
2941 -- Otherwise if there is a main program, take encoding from it
2944 return ALIs
.Table
(ALIs
.First
).WC_Encoding
;
2946 end Get_WC_Encoding
;
2952 function Has_Finalizer
(Elab_Order
: Unit_Id_Array
) return Boolean is
2957 for E
in reverse Elab_Order
'Range loop
2958 Unum
:= Elab_Order
(E
);
2959 U
:= Units
.Table
(Unum
);
2961 -- We are only interested in non-generic packages
2963 if U
.Unit_Kind
= 'p'
2964 and then U
.Has_Finalizer
2965 and then not U
.Is_Generic
2966 and then not U
.No_Elab
2979 function Hash
(Nam
: Name_Id
) return Header_Num
is
2981 return Int
(Nam
- Names_Low_Bound
) rem Header_Num
'Last;
2984 ----------------------
2985 -- Lt_Linker_Option --
2986 ----------------------
2988 function Lt_Linker_Option
(Op1
: Natural; Op2
: Natural) return Boolean is
2990 -- Sort internal files last
2992 if Linker_Options
.Table
(Op1
).Internal_File
2994 Linker_Options
.Table
(Op2
).Internal_File
2996 -- Note: following test uses False < True
2998 return Linker_Options
.Table
(Op1
).Internal_File
3000 Linker_Options
.Table
(Op2
).Internal_File
;
3002 -- If both internal or both non-internal, sort according to the
3003 -- elaboration position. A unit that is elaborated later should come
3004 -- earlier in the linker options list.
3007 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
3009 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
3011 end Lt_Linker_Option
;
3013 ------------------------
3014 -- Move_Linker_Option --
3015 ------------------------
3017 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
3019 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
3020 end Move_Linker_Option
;
3022 ----------------------------
3023 -- Resolve_Binder_Options --
3024 ----------------------------
3026 procedure Resolve_Binder_Options
(Elab_Order
: Unit_Id_Array
) is
3027 procedure Check_Package
(Var
: in out Boolean; Name
: String);
3028 -- Set Var to true iff the current identifier in Namet is Name. Do
3029 -- nothing if it doesn't match. This procedure is just a helper to
3030 -- avoid explicitly dealing with length.
3036 procedure Check_Package
(Var
: in out Boolean; Name
: String) is
3038 if Name_Len
= Name
'Length
3039 and then Name_Buffer
(1 .. Name_Len
) = Name
3045 -- Start of processing for Resolve_Binder_Options
3048 for E
in Elab_Order
'Range loop
3049 Get_Name_String
(Units
.Table
(Elab_Order
(E
)).Uname
);
3051 -- This is not a perfect approach, but is the current protocol
3052 -- between the run-time and the binder to indicate that tasking is
3053 -- used: System.OS_Interface should always be used by any tasking
3056 Check_Package
(With_GNARL
, "system.os_interface%s");
3058 -- Ditto for the use of restricted tasking
3061 (System_Tasking_Restricted_Stages_Used
,
3062 "system.tasking.restricted.stages%s");
3064 -- Ditto for the use of interrupts
3066 Check_Package
(System_Interrupts_Used
, "system.interrupts%s");
3068 -- Ditto for the use of dispatching domains
3071 (Dispatching_Domains_Used
,
3072 "system.multiprocessors.dispatching_domains%s");
3074 -- Ditto for the use of restrictions
3076 Check_Package
(System_Restrictions_Used
, "system.restrictions%s");
3078 -- Ditto for the use of System.Secondary_Stack
3081 (System_Secondary_Stack_Used
, "system.secondary_stack%s");
3083 -- Ditto for use of an SMP bareboard runtime
3085 Check_Package
(System_BB_CPU_Primitives_Multiprocessors_Used
,
3086 "system.bb.cpu_primitives.multiprocessors%s");
3088 -- Ditto for System.Version_Control, which is used for Version and
3089 -- Body_Version attributes.
3091 Check_Package
(System_Version_Control_Used
,
3092 "system.version_control%s");
3094 end Resolve_Binder_Options
;
3100 procedure Set_Bind_Env
(Key
, Value
: String) is
3102 -- The lengths of Key and Value are stored as single bytes
3104 if Key
'Length > 255 then
3105 Osint
.Fail
("bind environment key """ & Key
& """ too long");
3108 if Value
'Length > 255 then
3109 Osint
.Fail
("bind environment value """ & Value
& """ too long");
3112 Bind_Environment
.Set
(Name_Find
(Key
), Name_Find
(Value
));
3119 procedure Set_Boolean
(B
: Boolean) is
3120 False_Str
: constant String := "False";
3121 True_Str
: constant String := "True";
3125 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ True_Str
'Length) :=
3127 Stm_Last
:= Stm_Last
+ True_Str
'Length;
3129 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ False_Str
'Length) :=
3131 Stm_Last
:= Stm_Last
+ False_Str
'Length;
3139 procedure Set_Char
(C
: Character) is
3141 Stm_Last
:= Stm_Last
+ 1;
3142 Statement_Buffer
(Stm_Last
) := C
;
3149 procedure Set_Int
(N
: Int
) is
3160 Stm_Last
:= Stm_Last
+ 1;
3161 Statement_Buffer
(Stm_Last
) :=
3162 Character'Val (N
mod 10 + Character'Pos ('0'));
3166 -------------------------
3167 -- Set_IS_Pragma_Table --
3168 -------------------------
3170 procedure Set_IS_Pragma_Table
is
3172 for F
in ALIs
.First
.. ALIs
.Last
loop
3173 for K
in ALIs
.Table
(F
).First_Interrupt_State
..
3174 ALIs
.Table
(F
).Last_Interrupt_State
3177 Inum
: constant Int
:=
3178 Interrupt_States
.Table
(K
).Interrupt_Id
;
3179 Stat
: constant Character :=
3180 Interrupt_States
.Table
(K
).Interrupt_State
;
3183 while IS_Pragma_Settings
.Last
< Inum
loop
3184 IS_Pragma_Settings
.Append
('n');
3187 IS_Pragma_Settings
.Table
(Inum
) := Stat
;
3191 end Set_IS_Pragma_Table
;
3193 ---------------------------
3194 -- Set_Main_Program_Name --
3195 ---------------------------
3197 procedure Set_Main_Program_Name
is
3199 -- Note that name has %b on the end which we ignore
3201 -- First we output the initial _ada_ since we know that the main program
3202 -- is a library level subprogram.
3204 Set_String
("_ada_");
3206 -- Copy name, changing dots to double underscores
3208 for J
in 1 .. Name_Len
- 2 loop
3209 if Name_Buffer
(J
) = '.' then
3212 Set_Char
(Name_Buffer
(J
));
3215 end Set_Main_Program_Name
;
3217 ---------------------
3218 -- Set_Name_Buffer --
3219 ---------------------
3221 procedure Set_Name_Buffer
is
3223 for J
in 1 .. Name_Len
loop
3224 Set_Char
(Name_Buffer
(J
));
3226 end Set_Name_Buffer
;
3228 -------------------------
3229 -- Set_PSD_Pragma_Table --
3230 -------------------------
3232 procedure Set_PSD_Pragma_Table
is
3234 for F
in ALIs
.First
.. ALIs
.Last
loop
3235 for K
in ALIs
.Table
(F
).First_Specific_Dispatching
..
3236 ALIs
.Table
(F
).Last_Specific_Dispatching
3239 DTK
: Specific_Dispatching_Record
3240 renames Specific_Dispatching
.Table
(K
);
3243 while PSD_Pragma_Settings
.Last
< DTK
.Last_Priority
loop
3244 PSD_Pragma_Settings
.Append
('F');
3247 for Prio
in DTK
.First_Priority
.. DTK
.Last_Priority
loop
3248 PSD_Pragma_Settings
.Table
(Prio
) := DTK
.Dispatching_Policy
;
3253 end Set_PSD_Pragma_Table
;
3259 procedure Set_String
(S
: String) is
3261 Statement_Buffer
(Stm_Last
+ 1 .. Stm_Last
+ S
'Length) := S
;
3262 Stm_Last
:= Stm_Last
+ S
'Length;
3265 ------------------------
3266 -- Set_String_Replace --
3267 ------------------------
3269 procedure Set_String_Replace
(S
: String) is
3271 Statement_Buffer
(Stm_Last
- S
'Length + 1 .. Stm_Last
) := S
;
3272 end Set_String_Replace
;
3278 procedure Set_Unit_Name
is
3280 for J
in 1 .. Name_Len
- 2 loop
3281 if Name_Buffer
(J
) = '.' then
3284 Set_Char
(Name_Buffer
(J
));
3289 ---------------------
3290 -- Set_Unit_Number --
3291 ---------------------
3293 procedure Set_Unit_Number
(U
: Unit_Id
) is
3294 Num_Units
: constant Nat
:= Nat
(Units
.Last
) - Nat
(Unit_Id
'First);
3295 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
3298 if Num_Units
>= 10 and then Unum
< 10 then
3302 if Num_Units
>= 100 and then Unum
< 100 then
3307 end Set_Unit_Number
;
3309 ---------------------
3310 -- Write_Bind_Line --
3311 ---------------------
3313 procedure Write_Bind_Line
(S
: String) is
3315 -- Need to strip trailing LF from S
3317 WBI
(S
(S
'First .. S
'Last - 1));
3318 end Write_Bind_Line
;
3320 ----------------------------
3321 -- Write_Statement_Buffer --
3322 ----------------------------
3324 procedure Write_Statement_Buffer
is
3326 WBI
(Statement_Buffer
(1 .. Stm_Last
));
3328 end Write_Statement_Buffer
;
3330 procedure Write_Statement_Buffer
(S
: String) is
3333 Write_Statement_Buffer
;
3334 end Write_Statement_Buffer
;