2016-06-16 Hristian Kirtchev <kirtchev@adacore.com>
[official-gcc.git] / gcc / ada / bindgen.adb
blob079ebb40cbc25e05adac88d857fbd70e23d37fee
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- B I N D G E N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with ALI; use ALI;
27 with Binde; use Binde;
28 with Casing; use Casing;
29 with Fname; use Fname;
30 with Gnatvsn; use Gnatvsn;
31 with Hostparm;
32 with Namet; use Namet;
33 with Opt; use Opt;
34 with Osint; use Osint;
35 with Osint.B; use Osint.B;
36 with Output; use Output;
37 with Rident; use Rident;
38 with Stringt; use Stringt;
39 with Table; use Table;
40 with Targparm; use Targparm;
41 with Types; use Types;
43 with System.OS_Lib; use System.OS_Lib;
44 with System.WCh_Con; use System.WCh_Con;
46 with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
47 with GNAT.HTable;
49 package body Bindgen is
51 Statement_Buffer : String (1 .. 1000);
52 -- Buffer used for constructing output statements
54 Last : Natural := 0;
55 -- Last location in Statement_Buffer currently set
57 With_GNARL : Boolean := False;
58 -- Flag which indicates whether the program uses the GNARL library
59 -- (presence of the unit System.OS_Interface)
61 Num_Elab_Calls : Nat := 0;
62 -- Number of generated calls to elaboration routines
64 System_Restrictions_Used : Boolean := False;
65 -- Flag indicating whether the unit System.Restrictions is in the closure
66 -- of the partition. This is set by Resolve_Binder_Options, and is used
67 -- to determine whether or not to initialize the restrictions information
68 -- in the body of the binder generated file (we do not want to do this
69 -- unconditionally, since it drags in the System.Restrictions unit
70 -- unconditionally, which is unpleasand, especially for ZFP etc.)
72 Dispatching_Domains_Used : Boolean := False;
73 -- Flag indicating whether multiprocessor dispatching domains are used in
74 -- the closure of the partition. This is set by Resolve_Binder_Options, and
75 -- is used to call the routine to disallow the creation of new dispatching
76 -- domains just before calling the main procedure from the environment
77 -- task.
79 System_Tasking_Restricted_Stages_Used : Boolean := False;
80 -- Flag indicating whether the unit System.Tasking.Restricted.Stages is in
81 -- the closure of the partition. This is set by Resolve_Binder_Options,
82 -- and it used to call a routine to active all the tasks at the end of
83 -- the elaboration when partition elaboration policy is sequential.
85 System_Interrupts_Used : Boolean := False;
86 -- Flag indicating whether the unit System.Interrups is in the closure of
87 -- the partition. This is set by Resolve_Binder_Options, and it used to
88 -- attach interrupt handlers at the end of the elaboration when partition
89 -- elaboration policy is sequential.
91 System_BB_CPU_Primitives_Multiprocessors_Used : Boolean := False;
92 -- Flag indicating whether unit System.BB.CPU_Primitives.Multiprocessors
93 -- is in the closure of the partition. This is set by procedure
94 -- Resolve_Binder_Options, and it is used to call a procedure that starts
95 -- slave processors.
97 Lib_Final_Built : Boolean := False;
98 -- Flag indicating whether the finalize_library rountine has been built
100 Bind_Env_String_Built : Boolean := False;
101 -- Flag indicating whether a bind environment string has been built
103 CodePeer_Wrapper_Name : constant String := "call_main_subprogram";
104 -- For CodePeer, introduce a wrapper subprogram which calls the
105 -- user-defined main subprogram.
107 ----------------------------------
108 -- Interface_State Pragma Table --
109 ----------------------------------
111 -- This table assembles the interface state pragma information from
112 -- all the units in the partition. Note that Bcheck has already checked
113 -- that the information is consistent across units. The entries
114 -- in this table are n/u/r/s for not set/user/runtime/system.
116 package IS_Pragma_Settings is new Table.Table (
117 Table_Component_Type => Character,
118 Table_Index_Type => Int,
119 Table_Low_Bound => 0,
120 Table_Initial => 100,
121 Table_Increment => 200,
122 Table_Name => "IS_Pragma_Settings");
124 -- This table assembles the Priority_Specific_Dispatching pragma
125 -- information from all the units in the partition. Note that Bcheck has
126 -- already checked that the information is consistent across units.
127 -- The entries in this table are the upper case first character of the
128 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
130 package PSD_Pragma_Settings is new Table.Table (
131 Table_Component_Type => Character,
132 Table_Index_Type => Int,
133 Table_Low_Bound => 0,
134 Table_Initial => 100,
135 Table_Increment => 200,
136 Table_Name => "PSD_Pragma_Settings");
138 ----------------------------
139 -- Bind_Environment Table --
140 ----------------------------
142 subtype Header_Num is Int range 0 .. 36;
144 function Hash (Nam : Name_Id) return Header_Num;
146 package Bind_Environment is new GNAT.HTable.Simple_HTable
147 (Header_Num => Header_Num,
148 Element => Name_Id,
149 No_Element => No_Name,
150 Key => Name_Id,
151 Hash => Hash,
152 Equal => "=");
154 ----------------------
155 -- Run-Time Globals --
156 ----------------------
158 -- This section documents the global variables that are set from the
159 -- generated binder file.
161 -- Main_Priority : Integer;
162 -- Time_Slice_Value : Integer;
163 -- Heap_Size : Natural;
164 -- WC_Encoding : Character;
165 -- Locking_Policy : Character;
166 -- Queuing_Policy : Character;
167 -- Task_Dispatching_Policy : Character;
168 -- Priority_Specific_Dispatching : System.Address;
169 -- Num_Specific_Dispatching : Integer;
170 -- Restrictions : System.Address;
171 -- Interrupt_States : System.Address;
172 -- Num_Interrupt_States : Integer;
173 -- Unreserve_All_Interrupts : Integer;
174 -- Exception_Tracebacks : Integer;
175 -- Exception_Tracebacks_Symbolic : Integer;
176 -- Detect_Blocking : Integer;
177 -- Default_Stack_Size : Integer;
178 -- Leap_Seconds_Support : Integer;
179 -- Main_CPU : Integer;
181 -- Main_Priority is the priority value set by pragma Priority in the main
182 -- program. If no such pragma is present, the value is -1.
184 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
185 -- main program, or by the use of a -Tnnn parameter for the binder (if both
186 -- are present, the binder value overrides). The value is in milliseconds.
187 -- A value of zero indicates that time slicing should be suppressed. If no
188 -- pragma is present, and no -T switch was used, the value is -1.
190 -- WC_Encoding shows the wide character encoding method used for the main
191 -- program. This is one of the encoding letters defined in
192 -- System.WCh_Con.WC_Encoding_Letters.
194 -- Locking_Policy is a space if no locking policy was specified for the
195 -- partition. If a locking policy was specified, the value is the upper
196 -- case first character of the locking policy name, for example, 'C' for
197 -- Ceiling_Locking.
199 -- Queuing_Policy is a space if no queuing policy was specified for the
200 -- partition. If a queuing policy was specified, the value is the upper
201 -- case first character of the queuing policy name for example, 'F' for
202 -- FIFO_Queuing.
204 -- Task_Dispatching_Policy is a space if no task dispatching policy was
205 -- specified for the partition. If a task dispatching policy was specified,
206 -- the value is the upper case first character of the policy name, e.g. 'F'
207 -- for FIFO_Within_Priorities.
209 -- Priority_Specific_Dispatching is the address of a string used to store
210 -- the task dispatching policy specified for the different priorities in
211 -- the partition. The length of this string is determined by the last
212 -- priority for which such a pragma applies (the string will be a null
213 -- string if no specific dispatching policies were used). If pragma were
214 -- present, the entries apply to the priorities in sequence from the first
215 -- priority. The value stored is the upper case first character of the
216 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
217 -- for those priority ranges not specified.
219 -- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
220 -- string. It will be set to zero if no Priority_Specific_Dispatching
221 -- pragmas are present.
223 -- Restrictions is the address of a null-terminated string specifying the
224 -- restrictions information for the partition. The format is identical to
225 -- that of the parameter string found on R lines in ali files (see Lib.Writ
226 -- spec in lib-writ.ads for full details). The difference is that in this
227 -- context the values are the cumulative ones for the entire partition.
229 -- Interrupt_States is the address of a string used to specify the
230 -- cumulative results of Interrupt_State pragmas used in the partition.
231 -- The length of this string is determined by the last interrupt for which
232 -- such a pragma is given (the string will be a null string if no pragmas
233 -- were used). If pragma were present the entries apply to the interrupts
234 -- in sequence from the first interrupt, and are set to one of four
235 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
236 -- time, 's' for system, see description of Interrupt_State pragma for
237 -- further details.
239 -- Num_Interrupt_States is the length of the Interrupt_States string. It
240 -- will be set to zero if no Interrupt_State pragmas are present.
242 -- Unreserve_All_Interrupts is set to one if at least one unit in the
243 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
245 -- Exception_Tracebacks is set to one if the -Ea or -E parameter was
246 -- present in the bind and to zero otherwise. Note that on some targets
247 -- exception tracebacks are provided by default, so a value of zero for
248 -- this parameter does not necessarily mean no trace backs are available.
250 -- Exception_Tracebacks_Symbolic is set to one if the -Es parameter was
251 -- present in the bind and to zero otherwise.
253 -- Detect_Blocking indicates whether pragma Detect_Blocking is active or
254 -- not. A value of zero indicates that the pragma is not present, while a
255 -- value of 1 signals its presence in the partition.
257 -- Default_Stack_Size is the default stack size used when creating an Ada
258 -- task with no explicit Storage_Size clause.
260 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
261 -- disabled. A value of zero indicates that leap seconds are turned "off",
262 -- while a value of one signifies "on" status.
264 -- Main_CPU is the processor set by pragma CPU in the main program. If no
265 -- such pragma is present, the value is -1.
267 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
268 -- Convenient shorthand used throughout
270 -----------------------
271 -- Local Subprograms --
272 -----------------------
274 procedure Gen_Adainit;
275 -- Generates the Adainit procedure
277 procedure Gen_Adafinal;
278 -- Generate the Adafinal procedure
280 procedure Gen_Bind_Env_String;
281 -- Generate the bind environment buffer
283 procedure Gen_CodePeer_Wrapper;
284 -- For CodePeer, generate wrapper which calls user-defined main subprogram
286 procedure Gen_Elab_Calls;
287 -- Generate sequence of elaboration calls
289 procedure Gen_Elab_Externals;
290 -- Generate sequence of external declarations for elaboration
292 procedure Gen_Elab_Order;
293 -- Generate comments showing elaboration order chosen
295 procedure Gen_Finalize_Library;
296 -- Generate a sequence of finalization calls to elaborated packages
298 procedure Gen_Main;
299 -- Generate procedure main
301 procedure Gen_Object_Files_Options;
302 -- Output comments containing a list of the full names of the object
303 -- files to be linked and the list of linker options supplied by
304 -- Linker_Options pragmas in the source.
306 procedure Gen_Output_File_Ada (Filename : String);
307 -- Generate Ada output file
309 procedure Gen_Restrictions;
310 -- Generate initialization of restrictions variable
312 procedure Gen_Versions;
313 -- Output series of definitions for unit versions
315 function Get_Ada_Main_Name return String;
316 -- This function is used for the Ada main output to compute a usable name
317 -- for the generated main program. The normal main program name is
318 -- Ada_Main, but this won't work if the user has a unit with this name.
319 -- This function tries Ada_Main first, and if there is such a clash, then
320 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
322 function Get_Main_Unit_Name (S : String) return String;
323 -- Return the main unit name corresponding to S by replacing '.' with '_'
325 function Get_Main_Name return String;
326 -- This function is used in the main output case to compute the correct
327 -- external main program. It is "main" by default, unless the flag
328 -- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
329 -- of the Ada main name without the "_ada". This default can be overridden
330 -- explicitly using the -Mname binder switch.
332 function Get_WC_Encoding return Character;
333 -- Return wide character encoding method to set as WC_Encoding in output.
334 -- If -W has been used, returns the specified encoding, otherwise returns
335 -- the encoding method used for the main program source. If there is no
336 -- main program source (-z switch used), returns brackets ('b').
338 function Has_Finalizer return Boolean;
339 -- Determine whether the current unit has at least one library-level
340 -- finalizer.
342 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
343 -- Compare linker options, when sorting, first according to
344 -- Is_Internal_File (internal files come later) and then by
345 -- elaboration order position (latest to earliest).
347 procedure Move_Linker_Option (From : Natural; To : Natural);
348 -- Move routine for sorting linker options
350 procedure Resolve_Binder_Options;
351 -- Set the value of With_GNARL
353 procedure Set_Char (C : Character);
354 -- Set given character in Statement_Buffer at the Last + 1 position
355 -- and increment Last by one to reflect the stored character.
357 procedure Set_Int (N : Int);
358 -- Set given value in decimal in Statement_Buffer with no spaces starting
359 -- at the Last + 1 position, and updating Last past the value. A minus sign
360 -- is output for a negative value.
362 procedure Set_Boolean (B : Boolean);
363 -- Set given boolean value in Statement_Buffer at the Last + 1 position
364 -- and update Last past the value.
366 procedure Set_IS_Pragma_Table;
367 -- Initializes contents of IS_Pragma_Settings table from ALI table
369 procedure Set_Main_Program_Name;
370 -- Given the main program name in Name_Buffer (length in Name_Len) generate
371 -- the name of the routine to be used in the call. The name is generated
372 -- starting at Last + 1, and Last is updated past it.
374 procedure Set_Name_Buffer;
375 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
377 procedure Set_PSD_Pragma_Table;
378 -- Initializes contents of PSD_Pragma_Settings table from ALI table
380 procedure Set_String (S : String);
381 -- Sets characters of given string in Statement_Buffer, starting at the
382 -- Last + 1 position, and updating last past the string value.
384 procedure Set_String_Replace (S : String);
385 -- Replaces the last S'Length characters in the Statement_Buffer with the
386 -- characters of S. The caller must ensure that these characters do in fact
387 -- exist in the Statement_Buffer.
389 procedure Set_Unit_Name;
390 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
391 -- starting at the Last + 1 position and update Last past the value.
392 -- Each dot (.) will be qualified into double underscores (__).
394 procedure Set_Unit_Number (U : Unit_Id);
395 -- Sets unit number (first unit is 1, leading zeroes output to line up all
396 -- output unit numbers nicely as required by the value, and by the total
397 -- number of units.
399 procedure Write_Statement_Buffer;
400 -- Write out contents of statement buffer up to Last, and reset Last to 0
402 procedure Write_Statement_Buffer (S : String);
403 -- First writes its argument (using Set_String (S)), then writes out the
404 -- contents of statement buffer up to Last, and reset Last to 0
406 procedure Write_Bind_Line (S : String);
407 -- Write S (an LF-terminated string) to the binder file (for use with
408 -- Set_Special_Output).
410 ------------------
411 -- Gen_Adafinal --
412 ------------------
414 procedure Gen_Adafinal is
415 begin
416 WBI (" procedure " & Ada_Final_Name.all & " is");
418 if Bind_Main_Program and not CodePeer_Mode then
419 WBI (" procedure s_stalib_adafinal;");
420 Set_String (" pragma Import (C, s_stalib_adafinal, ");
421 Set_String ("""system__standard_library__adafinal"");");
422 Write_Statement_Buffer;
423 end if;
425 WBI ("");
426 WBI (" procedure Runtime_Finalize;");
427 WBI (" pragma Import (C, Runtime_Finalize, " &
428 """__gnat_runtime_finalize"");");
429 WBI ("");
430 WBI (" begin");
432 if not CodePeer_Mode then
433 WBI (" if not Is_Elaborated then");
434 WBI (" return;");
435 WBI (" end if;");
436 WBI (" Is_Elaborated := False;");
437 end if;
439 WBI (" Runtime_Finalize;");
441 -- By default (real targets), finalization is done differently depending
442 -- on whether this is the main program or a library.
444 if not CodePeer_Mode then
445 if Bind_Main_Program then
446 WBI (" s_stalib_adafinal;");
447 elsif Lib_Final_Built then
448 WBI (" finalize_library;");
449 else
450 WBI (" null;");
451 end if;
453 -- Pragma Import C cannot be used on virtual targets, therefore call the
454 -- runtime finalization routine directly in CodePeer mode, where
455 -- imported functions are ignored.
457 else
458 WBI (" System.Standard_Library.Adafinal;");
459 end if;
461 WBI (" end " & Ada_Final_Name.all & ";");
462 WBI ("");
463 end Gen_Adafinal;
465 -----------------
466 -- Gen_Adainit --
467 -----------------
469 procedure Gen_Adainit is
470 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
471 Main_CPU : Int renames ALIs.Table (ALIs.First).Main_CPU;
473 begin
474 -- Declare the access-to-subprogram type used for initialization of
475 -- of __gnat_finalize_library_objects. This is declared at library
476 -- level for compatibility with the type used in System.Soft_Links.
477 -- The import of the soft link which performs library-level object
478 -- finalization does not work for CodePeer, so regular Ada is used in
479 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
480 -- tasks are non-terminating, so we do not want finalization.
482 if not Suppress_Standard_Library_On_Target
483 and then not CodePeer_Mode
484 and then not Configurable_Run_Time_On_Target
485 then
486 WBI (" type No_Param_Proc is access procedure;");
487 WBI ("");
488 end if;
490 WBI (" procedure " & Ada_Init_Name.all & " is");
492 -- In CodePeer mode, simplify adainit procedure by only calling
493 -- elaboration procedures.
495 if CodePeer_Mode then
496 WBI (" begin");
498 -- If the standard library is suppressed, then the only global variables
499 -- that might be needed (by the Ravenscar profile) are the priority and
500 -- the processor for the environment task.
502 elsif Suppress_Standard_Library_On_Target then
503 if Main_Priority /= No_Main_Priority then
504 WBI (" Main_Priority : Integer;");
505 WBI (" pragma Import (C, Main_Priority," &
506 " ""__gl_main_priority"");");
507 WBI ("");
508 end if;
510 if Main_CPU /= No_Main_CPU then
511 WBI (" Main_CPU : Integer;");
512 WBI (" pragma Import (C, Main_CPU," &
513 " ""__gl_main_cpu"");");
514 WBI ("");
515 end if;
517 if System_Interrupts_Used
518 and then Partition_Elaboration_Policy_Specified = 'S'
519 then
520 WBI (" procedure Install_Restricted_Handlers_Sequential;");
521 WBI (" pragma Import (C," &
522 "Install_Restricted_Handlers_Sequential," &
523 " ""__gnat_attach_all_handlers"");");
524 WBI ("");
525 end if;
527 if System_Tasking_Restricted_Stages_Used
528 and then Partition_Elaboration_Policy_Specified = 'S'
529 then
530 WBI (" Partition_Elaboration_Policy : Character;");
531 WBI (" pragma Import (C, Partition_Elaboration_Policy," &
532 " ""__gnat_partition_elaboration_policy"");");
533 WBI ("");
534 WBI (" procedure Activate_All_Tasks_Sequential;");
535 WBI (" pragma Import (C, Activate_All_Tasks_Sequential," &
536 " ""__gnat_activate_all_tasks"");");
537 WBI ("");
538 end if;
540 if System_BB_CPU_Primitives_Multiprocessors_Used then
541 WBI (" procedure Start_Slave_CPUs;");
542 WBI (" pragma Import (C, Start_Slave_CPUs," &
543 " ""__gnat_start_slave_cpus"");");
544 end if;
546 WBI (" begin");
548 if Main_Priority /= No_Main_Priority then
549 Set_String (" Main_Priority := ");
550 Set_Int (Main_Priority);
551 Set_Char (';');
552 Write_Statement_Buffer;
553 end if;
555 if Main_CPU /= No_Main_CPU then
556 Set_String (" Main_CPU := ");
557 Set_Int (Main_CPU);
558 Set_Char (';');
559 Write_Statement_Buffer;
560 end if;
562 if System_Tasking_Restricted_Stages_Used
563 and then Partition_Elaboration_Policy_Specified = 'S'
564 then
565 Set_String (" Partition_Elaboration_Policy := '");
566 Set_Char (Partition_Elaboration_Policy_Specified);
567 Set_String ("';");
568 Write_Statement_Buffer;
569 end if;
571 if Main_Priority = No_Main_Priority
572 and then Main_CPU = No_Main_CPU
573 and then not System_Tasking_Restricted_Stages_Used
574 then
575 WBI (" null;");
576 end if;
578 -- Normal case (standard library not suppressed). Set all global values
579 -- used by the run time.
581 else
582 WBI (" Main_Priority : Integer;");
583 WBI (" pragma Import (C, Main_Priority, " &
584 """__gl_main_priority"");");
585 WBI (" Time_Slice_Value : Integer;");
586 WBI (" pragma Import (C, Time_Slice_Value, " &
587 """__gl_time_slice_val"");");
588 WBI (" WC_Encoding : Character;");
589 WBI (" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
590 WBI (" Locking_Policy : Character;");
591 WBI (" pragma Import (C, Locking_Policy, " &
592 """__gl_locking_policy"");");
593 WBI (" Queuing_Policy : Character;");
594 WBI (" pragma Import (C, Queuing_Policy, " &
595 """__gl_queuing_policy"");");
596 WBI (" Task_Dispatching_Policy : Character;");
597 WBI (" pragma Import (C, Task_Dispatching_Policy, " &
598 """__gl_task_dispatching_policy"");");
599 WBI (" Priority_Specific_Dispatching : System.Address;");
600 WBI (" pragma Import (C, Priority_Specific_Dispatching, " &
601 """__gl_priority_specific_dispatching"");");
602 WBI (" Num_Specific_Dispatching : Integer;");
603 WBI (" pragma Import (C, Num_Specific_Dispatching, " &
604 """__gl_num_specific_dispatching"");");
605 WBI (" Main_CPU : Integer;");
606 WBI (" pragma Import (C, Main_CPU, " &
607 """__gl_main_cpu"");");
609 WBI (" Interrupt_States : System.Address;");
610 WBI (" pragma Import (C, Interrupt_States, " &
611 """__gl_interrupt_states"");");
612 WBI (" Num_Interrupt_States : Integer;");
613 WBI (" pragma Import (C, Num_Interrupt_States, " &
614 """__gl_num_interrupt_states"");");
615 WBI (" Unreserve_All_Interrupts : Integer;");
616 WBI (" pragma Import (C, Unreserve_All_Interrupts, " &
617 """__gl_unreserve_all_interrupts"");");
619 if Exception_Tracebacks or Exception_Tracebacks_Symbolic then
620 WBI (" Exception_Tracebacks : Integer;");
621 WBI (" pragma Import (C, Exception_Tracebacks, " &
622 """__gl_exception_tracebacks"");");
624 if Exception_Tracebacks_Symbolic then
625 WBI (" Exception_Tracebacks_Symbolic : Integer;");
626 WBI (" pragma Import (C, Exception_Tracebacks_Symbolic, " &
627 """__gl_exception_tracebacks_symbolic"");");
628 end if;
629 end if;
631 WBI (" Detect_Blocking : Integer;");
632 WBI (" pragma Import (C, Detect_Blocking, " &
633 """__gl_detect_blocking"");");
634 WBI (" Default_Stack_Size : Integer;");
635 WBI (" pragma Import (C, Default_Stack_Size, " &
636 """__gl_default_stack_size"");");
637 WBI (" Leap_Seconds_Support : Integer;");
638 WBI (" pragma Import (C, Leap_Seconds_Support, " &
639 """__gl_leap_seconds_support"");");
640 WBI (" Bind_Env_Addr : System.Address;");
641 WBI (" pragma Import (C, Bind_Env_Addr, " &
642 """__gl_bind_env_addr"");");
644 -- Import entry point for elaboration time signal handler
645 -- installation, and indication of if it's been called previously.
647 WBI ("");
648 WBI (" procedure Runtime_Initialize " &
649 "(Install_Handler : Integer);");
650 WBI (" pragma Import (C, Runtime_Initialize, " &
651 """__gnat_runtime_initialize"");");
653 -- Import handlers attach procedure for sequential elaboration policy
655 if System_Interrupts_Used
656 and then Partition_Elaboration_Policy_Specified = 'S'
657 then
658 WBI (" procedure Install_Restricted_Handlers_Sequential;");
659 WBI (" pragma Import (C," &
660 "Install_Restricted_Handlers_Sequential," &
661 " ""__gnat_attach_all_handlers"");");
662 WBI ("");
663 end if;
665 -- Import task activation procedure for sequential elaboration
666 -- policy.
668 if System_Tasking_Restricted_Stages_Used
669 and then Partition_Elaboration_Policy_Specified = 'S'
670 then
671 WBI (" Partition_Elaboration_Policy : Character;");
672 WBI (" pragma Import (C, Partition_Elaboration_Policy," &
673 " ""__gnat_partition_elaboration_policy"");");
674 WBI ("");
675 WBI (" procedure Activate_All_Tasks_Sequential;");
676 WBI (" pragma Import (C, Activate_All_Tasks_Sequential," &
677 " ""__gnat_activate_all_tasks"");");
678 end if;
680 -- Import procedure to start slave cpus for bareboard runtime
682 if System_BB_CPU_Primitives_Multiprocessors_Used then
683 WBI (" procedure Start_Slave_CPUs;");
684 WBI (" pragma Import (C, Start_Slave_CPUs," &
685 " ""__gnat_start_slave_cpus"");");
686 end if;
688 -- For restricted run-time libraries (ZFP and Ravenscar)
689 -- tasks are non-terminating, so we do not want finalization.
691 if not Configurable_Run_Time_On_Target then
692 WBI ("");
693 WBI (" Finalize_Library_Objects : No_Param_Proc;");
694 WBI (" pragma Import (C, Finalize_Library_Objects, " &
695 """__gnat_finalize_library_objects"");");
696 end if;
698 -- Initialize stack limit variable of the environment task if the
699 -- stack check method is stack limit and stack check is enabled.
701 if Stack_Check_Limits_On_Target
702 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
703 then
704 WBI ("");
705 WBI (" procedure Initialize_Stack_Limit;");
706 WBI (" pragma Import (C, Initialize_Stack_Limit, " &
707 """__gnat_initialize_stack_limit"");");
708 end if;
710 -- When dispatching domains are used then we need to signal it
711 -- before calling the main procedure.
713 if Dispatching_Domains_Used then
714 WBI (" procedure Freeze_Dispatching_Domains;");
715 WBI (" pragma Import");
716 WBI (" (Ada, Freeze_Dispatching_Domains, "
717 & """__gnat_freeze_dispatching_domains"");");
718 end if;
720 -- Start of processing for Adainit
722 WBI (" begin");
723 WBI (" if Is_Elaborated then");
724 WBI (" return;");
725 WBI (" end if;");
726 WBI (" Is_Elaborated := True;");
728 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
729 -- restriction No_Standard_Allocators_After_Elaboration is active.
731 if Cumulative_Restrictions.Set
732 (No_Standard_Allocators_After_Elaboration)
733 then
734 WBI (" System.Elaboration_Allocators."
735 & "Mark_Start_Of_Elaboration;");
736 end if;
738 -- Generate assignments to initialize globals
740 Set_String (" Main_Priority := ");
741 Set_Int (Main_Priority);
742 Set_Char (';');
743 Write_Statement_Buffer;
745 Set_String (" Time_Slice_Value := ");
747 if Task_Dispatching_Policy_Specified = 'F'
748 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
749 then
750 Set_Int (0);
751 else
752 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
753 end if;
755 Set_Char (';');
756 Write_Statement_Buffer;
758 Set_String (" WC_Encoding := '");
759 Set_Char (Get_WC_Encoding);
761 Set_String ("';");
762 Write_Statement_Buffer;
764 Set_String (" Locking_Policy := '");
765 Set_Char (Locking_Policy_Specified);
766 Set_String ("';");
767 Write_Statement_Buffer;
769 Set_String (" Queuing_Policy := '");
770 Set_Char (Queuing_Policy_Specified);
771 Set_String ("';");
772 Write_Statement_Buffer;
774 Set_String (" Task_Dispatching_Policy := '");
775 Set_Char (Task_Dispatching_Policy_Specified);
776 Set_String ("';");
777 Write_Statement_Buffer;
779 if System_Tasking_Restricted_Stages_Used
780 and then Partition_Elaboration_Policy_Specified = 'S'
781 then
782 Set_String (" Partition_Elaboration_Policy := '");
783 Set_Char (Partition_Elaboration_Policy_Specified);
784 Set_String ("';");
785 Write_Statement_Buffer;
786 end if;
788 Gen_Restrictions;
790 WBI (" Priority_Specific_Dispatching :=");
791 WBI (" Local_Priority_Specific_Dispatching'Address;");
793 Set_String (" Num_Specific_Dispatching := ");
794 Set_Int (PSD_Pragma_Settings.Last + 1);
795 Set_Char (';');
796 Write_Statement_Buffer;
798 Set_String (" Main_CPU := ");
799 Set_Int (Main_CPU);
800 Set_Char (';');
801 Write_Statement_Buffer;
803 WBI (" Interrupt_States := Local_Interrupt_States'Address;");
805 Set_String (" Num_Interrupt_States := ");
806 Set_Int (IS_Pragma_Settings.Last + 1);
807 Set_Char (';');
808 Write_Statement_Buffer;
810 Set_String (" Unreserve_All_Interrupts := ");
812 if Unreserve_All_Interrupts_Specified then
813 Set_String ("1");
814 else
815 Set_String ("0");
816 end if;
818 Set_Char (';');
819 Write_Statement_Buffer;
821 if Exception_Tracebacks or Exception_Tracebacks_Symbolic then
822 WBI (" Exception_Tracebacks := 1;");
824 if Exception_Tracebacks_Symbolic then
825 WBI (" Exception_Tracebacks_Symbolic := 1;");
826 end if;
827 end if;
829 Set_String (" Detect_Blocking := ");
831 if Detect_Blocking then
832 Set_Int (1);
833 else
834 Set_Int (0);
835 end if;
837 Set_String (";");
838 Write_Statement_Buffer;
840 Set_String (" Default_Stack_Size := ");
841 Set_Int (Default_Stack_Size);
842 Set_String (";");
843 Write_Statement_Buffer;
845 Set_String (" Leap_Seconds_Support := ");
847 if Leap_Seconds_Support then
848 Set_Int (1);
849 else
850 Set_Int (0);
851 end if;
853 Set_String (";");
854 Write_Statement_Buffer;
856 if Bind_Env_String_Built then
857 WBI (" Bind_Env_Addr := Bind_Env'Address;");
858 end if;
860 -- Generate call to Install_Handler
862 WBI ("");
863 WBI (" Runtime_Initialize (1);");
864 end if;
866 -- Generate call to set Initialize_Scalar values if active
868 if Initialize_Scalars_Used then
869 WBI ("");
870 Set_String (" System.Scalar_Values.Initialize ('");
871 Set_Char (Initialize_Scalars_Mode1);
872 Set_String ("', '");
873 Set_Char (Initialize_Scalars_Mode2);
874 Set_String ("');");
875 Write_Statement_Buffer;
876 end if;
878 -- Generate assignment of default secondary stack size if set
880 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
881 WBI ("");
882 Set_String (" System.Secondary_Stack.");
883 Set_String ("Default_Secondary_Stack_Size := ");
884 Set_Int (Opt.Default_Sec_Stack_Size);
885 Set_Char (';');
886 Write_Statement_Buffer;
887 end if;
889 -- Initialize stack limit variable of the environment task if the
890 -- stack check method is stack limit and stack check is enabled.
892 if Stack_Check_Limits_On_Target
893 and then (Stack_Check_Default_On_Target or Stack_Check_Switch_Set)
894 then
895 WBI ("");
896 WBI (" Initialize_Stack_Limit;");
897 end if;
899 -- On CodePeer, the finalization of library objects is not relevant
901 if CodePeer_Mode then
902 null;
904 -- If this is the main program case, attach finalize_library to the soft
905 -- link. Do it only when not using a restricted run time, in which case
906 -- tasks are non-terminating, so we do not want library-level
907 -- finalization.
909 elsif Bind_Main_Program
910 and then not Configurable_Run_Time_On_Target
911 and then not Suppress_Standard_Library_On_Target
912 then
913 WBI ("");
915 if Lib_Final_Built then
916 Set_String (" Finalize_Library_Objects := ");
917 Set_String ("finalize_library'access;");
918 else
919 Set_String (" Finalize_Library_Objects := null;");
920 end if;
922 Write_Statement_Buffer;
923 end if;
925 -- Generate elaboration calls
927 if not CodePeer_Mode then
928 WBI ("");
929 end if;
931 Gen_Elab_Calls;
933 if not CodePeer_Mode then
934 -- Call System.Elaboration_Allocators.Mark_Start_Of_Elaboration if
935 -- restriction No_Standard_Allocators_After_Elaboration is active.
937 if Cumulative_Restrictions.Set
938 (No_Standard_Allocators_After_Elaboration)
939 then
941 (" System.Elaboration_Allocators.Mark_End_Of_Elaboration;");
942 end if;
944 -- From this point, no new dispatching domain can be created
946 if Dispatching_Domains_Used then
947 WBI (" Freeze_Dispatching_Domains;");
948 end if;
950 -- Sequential partition elaboration policy
952 if Partition_Elaboration_Policy_Specified = 'S' then
953 if System_Interrupts_Used then
954 WBI (" Install_Restricted_Handlers_Sequential;");
955 end if;
957 if System_Tasking_Restricted_Stages_Used then
958 WBI (" Activate_All_Tasks_Sequential;");
959 end if;
960 end if;
962 if System_BB_CPU_Primitives_Multiprocessors_Used then
963 WBI (" Start_Slave_CPUs;");
964 end if;
965 end if;
967 WBI (" end " & Ada_Init_Name.all & ";");
968 WBI ("");
969 end Gen_Adainit;
971 -------------------------
972 -- Gen_Bind_Env_String --
973 -------------------------
975 procedure Gen_Bind_Env_String is
976 KN, VN : Name_Id := No_Name;
977 Amp : Character;
979 procedure Write_Name_With_Len (Nam : Name_Id);
980 -- Write Nam as a string literal, prefixed with one
981 -- character encoding Nam's length.
983 -------------------------
984 -- Write_Name_With_Len --
985 -------------------------
987 procedure Write_Name_With_Len (Nam : Name_Id) is
988 begin
989 Get_Name_String (Nam);
991 Start_String;
992 Store_String_Char (Character'Val (Name_Len));
993 Store_String_Chars (Name_Buffer (1 .. Name_Len));
995 Write_String_Table_Entry (End_String);
996 end Write_Name_With_Len;
998 -- Start of processing for Gen_Bind_Env_String
1000 begin
1001 Bind_Environment.Get_First (KN, VN);
1002 if VN = No_Name then
1003 return;
1004 end if;
1006 Set_Special_Output (Write_Bind_Line'Access);
1008 WBI (" Bind_Env : aliased constant String :=");
1009 Amp := ' ';
1010 while VN /= No_Name loop
1011 Write_Str (" " & Amp & ' ');
1012 Write_Name_With_Len (KN);
1013 Write_Str (" & ");
1014 Write_Name_With_Len (VN);
1015 Write_Eol;
1017 Bind_Environment.Get_Next (KN, VN);
1018 Amp := '&';
1019 end loop;
1020 WBI (" & ASCII.NUL;");
1022 Set_Special_Output (null);
1024 Bind_Env_String_Built := True;
1025 end Gen_Bind_Env_String;
1027 --------------------------
1028 -- Gen_CodePeer_Wrapper --
1029 --------------------------
1031 procedure Gen_CodePeer_Wrapper is
1032 Callee_Name : constant String := "Ada_Main_Program";
1034 begin
1035 if ALIs.Table (ALIs.First).Main_Program = Proc then
1036 WBI (" procedure " & CodePeer_Wrapper_Name & " is ");
1037 WBI (" begin");
1038 WBI (" " & Callee_Name & ";");
1040 else
1041 WBI (" function " & CodePeer_Wrapper_Name & " return Integer is");
1042 WBI (" begin");
1043 WBI (" return " & Callee_Name & ";");
1044 end if;
1046 WBI (" end " & CodePeer_Wrapper_Name & ";");
1047 WBI ("");
1048 end Gen_CodePeer_Wrapper;
1050 --------------------
1051 -- Gen_Elab_Calls --
1052 --------------------
1054 procedure Gen_Elab_Calls is
1055 Check_Elab_Flag : Boolean;
1057 begin
1058 -- Loop through elaboration order entries
1060 for E in Elab_Order.First .. Elab_Order.Last loop
1061 declare
1062 Unum : constant Unit_Id := Elab_Order.Table (E);
1063 U : Unit_Record renames Units.Table (Unum);
1065 Unum_Spec : Unit_Id;
1066 -- This is the unit number of the spec that corresponds to
1067 -- this entry. It is the same as Unum except when the body
1068 -- and spec are different and we are currently processing
1069 -- the body, in which case it is the spec (Unum + 1).
1071 begin
1072 if U.Utype = Is_Body then
1073 Unum_Spec := Unum + 1;
1074 else
1075 Unum_Spec := Unum;
1076 end if;
1078 -- Nothing to do if predefined unit in no run time mode
1080 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1081 null;
1083 -- Likewise if this is an interface to a stand alone library
1085 elsif U.SAL_Interface then
1086 null;
1088 -- Case of no elaboration code
1090 elsif U.No_Elab
1092 -- In CodePeer mode, we special case subprogram bodies which
1093 -- are handled in the 'else' part below, and lead to a call
1094 -- to <subp>'Elab_Subp_Body.
1096 and then (not CodePeer_Mode
1098 -- Test for spec
1100 or else U.Utype = Is_Spec
1101 or else U.Utype = Is_Spec_Only
1102 or else U.Unit_Kind /= 's')
1103 then
1104 -- In the case of a body with a separate spec, where the
1105 -- separate spec has an elaboration entity defined, this is
1106 -- where we increment the elaboration entity if one exists
1108 if U.Utype = Is_Body
1109 and then Units.Table (Unum_Spec).Set_Elab_Entity
1110 and then not CodePeer_Mode
1111 then
1112 Set_String (" E");
1113 Set_Unit_Number (Unum_Spec);
1114 Set_String (" := E");
1115 Set_Unit_Number (Unum_Spec);
1116 Set_String (" + 1;");
1117 Write_Statement_Buffer;
1118 end if;
1120 -- Here if elaboration code is present. If binding a library
1121 -- or if there is a non-Ada main subprogram then we generate:
1123 -- if uname_E = 0 then
1124 -- uname'elab_[spec|body];
1125 -- end if;
1126 -- uname_E := uname_E + 1;
1128 -- Otherwise, elaboration routines are called unconditionally:
1130 -- uname'elab_[spec|body];
1131 -- uname_E := uname_E + 1;
1133 -- The uname_E increment is skipped if this is a separate spec,
1134 -- since it will be done when we process the body.
1136 -- In CodePeer mode, we do not generate any reference to xxx_E
1137 -- variables, only calls to 'Elab* subprograms.
1139 else
1140 -- Check incompatibilities with No_Multiple_Elaboration
1142 if not CodePeer_Mode
1143 and then Cumulative_Restrictions.Set (No_Multiple_Elaboration)
1144 then
1145 -- Force_Checking_Of_Elaboration_Flags (-F) not allowed
1147 if Force_Checking_Of_Elaboration_Flags then
1148 Osint.Fail
1149 ("-F (force elaboration checks) switch not allowed "
1150 & "with restriction No_Multiple_Elaboration active");
1152 -- Interfacing of libraries not allowed
1154 elsif Interface_Library_Unit then
1155 Osint.Fail
1156 ("binding of interfaced libraries not allowed "
1157 & "with restriction No_Multiple_Elaboration active");
1159 -- Non-Ada main program not allowed
1161 elsif not Bind_Main_Program then
1162 Osint.Fail
1163 ("non-Ada main program not allowed "
1164 & "with restriction No_Multiple_Elaboration active");
1165 end if;
1166 end if;
1168 -- OK, see if we need to test elaboration flag
1170 Check_Elab_Flag :=
1171 Units.Table (Unum_Spec).Set_Elab_Entity
1172 and then not CodePeer_Mode
1173 and then (Force_Checking_Of_Elaboration_Flags
1174 or Interface_Library_Unit
1175 or not Bind_Main_Program);
1177 if Check_Elab_Flag then
1178 Set_String (" if E");
1179 Set_Unit_Number (Unum_Spec);
1180 Set_String (" = 0 then");
1181 Write_Statement_Buffer;
1182 Set_String (" ");
1183 end if;
1185 Set_String (" ");
1186 Get_Decoded_Name_String_With_Brackets (U.Uname);
1188 if Name_Buffer (Name_Len) = 's' then
1189 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1190 "'elab_spec";
1191 Name_Len := Name_Len + 8;
1193 -- Special case in CodePeer mode for subprogram bodies
1194 -- which correspond to CodePeer 'Elab_Subp_Body special
1195 -- init procedure.
1197 elsif U.Unit_Kind = 's' and CodePeer_Mode then
1198 Name_Buffer (Name_Len - 1 .. Name_Len + 13) :=
1199 "'elab_subp_body";
1200 Name_Len := Name_Len + 13;
1202 else
1203 Name_Buffer (Name_Len - 1 .. Name_Len + 8) :=
1204 "'elab_body";
1205 Name_Len := Name_Len + 8;
1206 end if;
1208 Set_Casing (U.Icasing);
1209 Set_Name_Buffer;
1210 Set_Char (';');
1211 Write_Statement_Buffer;
1213 if Check_Elab_Flag then
1214 WBI (" end if;");
1215 end if;
1217 if U.Utype /= Is_Spec
1218 and then not CodePeer_Mode
1219 and then Units.Table (Unum_Spec).Set_Elab_Entity
1220 then
1221 Set_String (" E");
1222 Set_Unit_Number (Unum_Spec);
1223 Set_String (" := E");
1224 Set_Unit_Number (Unum_Spec);
1225 Set_String (" + 1;");
1226 Write_Statement_Buffer;
1227 end if;
1228 end if;
1229 end;
1230 end loop;
1231 end Gen_Elab_Calls;
1233 ------------------------
1234 -- Gen_Elab_Externals --
1235 ------------------------
1237 procedure Gen_Elab_Externals is
1238 begin
1239 if CodePeer_Mode then
1240 return;
1241 end if;
1243 for E in Elab_Order.First .. Elab_Order.Last loop
1244 declare
1245 Unum : constant Unit_Id := Elab_Order.Table (E);
1246 U : Unit_Record renames Units.Table (Unum);
1248 begin
1249 -- Check for Elab_Entity to be set for this unit
1251 if U.Set_Elab_Entity
1253 -- Don't generate reference for stand alone library
1255 and then not U.SAL_Interface
1257 -- Don't generate reference for predefined file in No_Run_Time
1258 -- mode, since we don't include the object files in this case
1260 and then not
1261 (No_Run_Time_Mode
1262 and then Is_Predefined_File_Name (U.Sfile))
1263 then
1264 Set_String (" ");
1265 Set_String ("E");
1266 Set_Unit_Number (Unum);
1267 Set_String (" : Short_Integer; pragma Import (Ada, E");
1268 Set_Unit_Number (Unum);
1269 Set_String (", """);
1270 Get_Name_String (U.Uname);
1271 Set_Unit_Name;
1272 Set_String ("_E"");");
1273 Write_Statement_Buffer;
1274 end if;
1275 end;
1276 end loop;
1278 WBI ("");
1279 end Gen_Elab_Externals;
1281 --------------------
1282 -- Gen_Elab_Order --
1283 --------------------
1285 procedure Gen_Elab_Order is
1286 begin
1287 WBI (" -- BEGIN ELABORATION ORDER");
1289 for J in Elab_Order.First .. Elab_Order.Last loop
1290 Set_String (" -- ");
1291 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1292 Set_Name_Buffer;
1293 Write_Statement_Buffer;
1294 end loop;
1296 WBI (" -- END ELABORATION ORDER");
1297 WBI ("");
1298 end Gen_Elab_Order;
1300 --------------------------
1301 -- Gen_Finalize_Library --
1302 --------------------------
1304 procedure Gen_Finalize_Library is
1305 Count : Int := 1;
1306 U : Unit_Record;
1307 Uspec : Unit_Record;
1308 Unum : Unit_Id;
1310 procedure Gen_Header;
1311 -- Generate the header of the finalization routine
1313 ----------------
1314 -- Gen_Header --
1315 ----------------
1317 procedure Gen_Header is
1318 begin
1319 WBI (" procedure finalize_library is");
1320 WBI (" begin");
1321 end Gen_Header;
1323 -- Start of processing for Gen_Finalize_Library
1325 begin
1326 if CodePeer_Mode then
1327 return;
1328 end if;
1330 for E in reverse Elab_Order.First .. Elab_Order.Last loop
1331 Unum := Elab_Order.Table (E);
1332 U := Units.Table (Unum);
1334 -- Dealing with package bodies is a little complicated. In such
1335 -- cases we must retrieve the package spec since it contains the
1336 -- spec of the body finalizer.
1338 if U.Utype = Is_Body then
1339 Unum := Unum + 1;
1340 Uspec := Units.Table (Unum);
1341 else
1342 Uspec := U;
1343 end if;
1345 Get_Name_String (Uspec.Uname);
1347 -- We are only interested in non-generic packages
1349 if U.Unit_Kind /= 'p' or else U.Is_Generic then
1350 null;
1352 -- That aren't an interface to a stand alone library
1354 elsif U.SAL_Interface then
1355 null;
1357 -- Case of no finalization
1359 elsif not U.Has_Finalizer then
1361 -- The only case in which we have to do something is if this
1362 -- is a body, with a separate spec, where the separate spec
1363 -- has a finalizer. In that case, this is where we decrement
1364 -- the elaboration entity.
1366 if U.Utype = Is_Body and then Uspec.Has_Finalizer then
1367 if not Lib_Final_Built then
1368 Gen_Header;
1369 Lib_Final_Built := True;
1370 end if;
1372 Set_String (" E");
1373 Set_Unit_Number (Unum);
1374 Set_String (" := E");
1375 Set_Unit_Number (Unum);
1376 Set_String (" - 1;");
1377 Write_Statement_Buffer;
1378 end if;
1380 else
1381 if not Lib_Final_Built then
1382 Gen_Header;
1383 Lib_Final_Built := True;
1384 end if;
1386 -- Generate:
1387 -- declare
1388 -- procedure F<Count>;
1390 Set_String (" declare");
1391 Write_Statement_Buffer;
1393 Set_String (" procedure F");
1394 Set_Int (Count);
1395 Set_Char (';');
1396 Write_Statement_Buffer;
1398 -- Generate:
1399 -- pragma Import (Ada, F<Count>,
1400 -- "xx__yy__finalize_[body|spec]");
1402 Set_String (" pragma Import (Ada, F");
1403 Set_Int (Count);
1404 Set_String (", """);
1406 -- Perform name construction
1408 Set_Unit_Name;
1409 Set_String ("__finalize_");
1411 -- Package spec processing
1413 if U.Utype = Is_Spec
1414 or else U.Utype = Is_Spec_Only
1415 then
1416 Set_String ("spec");
1418 -- Package body processing
1420 else
1421 Set_String ("body");
1422 end if;
1424 Set_String (""");");
1425 Write_Statement_Buffer;
1427 -- If binding a library or if there is a non-Ada main subprogram
1428 -- then we generate:
1430 -- begin
1431 -- uname_E := uname_E - 1;
1432 -- if uname_E = 0 then
1433 -- F<Count>;
1434 -- end if;
1435 -- end;
1437 -- Otherwise, finalization routines are called unconditionally:
1439 -- begin
1440 -- uname_E := uname_E - 1;
1441 -- F<Count>;
1442 -- end;
1444 -- The uname_E decrement is skipped if this is a separate spec,
1445 -- since it will be done when we process the body.
1447 WBI (" begin");
1449 if U.Utype /= Is_Spec then
1450 Set_String (" E");
1451 Set_Unit_Number (Unum);
1452 Set_String (" := E");
1453 Set_Unit_Number (Unum);
1454 Set_String (" - 1;");
1455 Write_Statement_Buffer;
1456 end if;
1458 if Interface_Library_Unit or not Bind_Main_Program then
1459 Set_String (" if E");
1460 Set_Unit_Number (Unum);
1461 Set_String (" = 0 then");
1462 Write_Statement_Buffer;
1463 Set_String (" ");
1464 end if;
1466 Set_String (" F");
1467 Set_Int (Count);
1468 Set_Char (';');
1469 Write_Statement_Buffer;
1471 if Interface_Library_Unit or not Bind_Main_Program then
1472 WBI (" end if;");
1473 end if;
1475 WBI (" end;");
1477 Count := Count + 1;
1478 end if;
1479 end loop;
1481 if Lib_Final_Built then
1483 -- It is possible that the finalization of a library-level object
1484 -- raised an exception. In that case import the actual exception
1485 -- and the routine necessary to raise it.
1487 WBI (" declare");
1488 WBI (" procedure Reraise_Library_Exception_If_Any;");
1490 Set_String (" pragma Import (Ada, ");
1491 Set_String ("Reraise_Library_Exception_If_Any, ");
1492 Set_String ("""__gnat_reraise_library_exception_if_any"");");
1493 Write_Statement_Buffer;
1495 WBI (" begin");
1496 WBI (" Reraise_Library_Exception_If_Any;");
1497 WBI (" end;");
1498 WBI (" end finalize_library;");
1499 WBI ("");
1500 end if;
1501 end Gen_Finalize_Library;
1503 --------------
1504 -- Gen_Main --
1505 --------------
1507 procedure Gen_Main is
1508 begin
1509 if not No_Main_Subprogram then
1511 -- To call the main program, we declare it using a pragma Import
1512 -- Ada with the right link name.
1514 -- It might seem more obvious to "with" the main program, and call
1515 -- it in the normal Ada manner. We do not do this for three
1516 -- reasons:
1518 -- 1. It is more efficient not to recompile the main program
1519 -- 2. We are not entitled to assume the source is accessible
1520 -- 3. We don't know what options to use to compile it
1522 -- It is really reason 3 that is most critical (indeed we used
1523 -- to generate the "with", but several regression tests failed).
1525 if ALIs.Table (ALIs.First).Main_Program = Func then
1526 WBI (" function Ada_Main_Program return Integer;");
1527 else
1528 WBI (" procedure Ada_Main_Program;");
1529 end if;
1531 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1532 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1533 Set_Main_Program_Name;
1534 Set_String (""");");
1536 Write_Statement_Buffer;
1537 WBI ("");
1539 -- For CodePeer, declare a wrapper for the user-defined main program
1541 if CodePeer_Mode then
1542 Gen_CodePeer_Wrapper;
1543 end if;
1544 end if;
1546 if Exit_Status_Supported_On_Target then
1547 Set_String (" function ");
1548 else
1549 Set_String (" procedure ");
1550 end if;
1552 Set_String (Get_Main_Name);
1554 if Command_Line_Args_On_Target then
1555 Write_Statement_Buffer;
1556 WBI (" (argc : Integer;");
1557 WBI (" argv : System.Address;");
1558 WBI (" envp : System.Address)");
1560 if Exit_Status_Supported_On_Target then
1561 WBI (" return Integer");
1562 end if;
1564 WBI (" is");
1566 else
1567 if Exit_Status_Supported_On_Target then
1568 Set_String (" return Integer is");
1569 else
1570 Set_String (" is");
1571 end if;
1573 Write_Statement_Buffer;
1574 end if;
1576 if Opt.Default_Exit_Status /= 0
1577 and then Bind_Main_Program
1578 and then not Configurable_Run_Time_Mode
1579 then
1580 WBI (" procedure Set_Exit_Status (Status : Integer);");
1581 WBI (" pragma Import (C, Set_Exit_Status, " &
1582 """__gnat_set_exit_status"");");
1583 WBI ("");
1584 end if;
1586 -- Initialize and Finalize
1588 if not CodePeer_Mode
1589 and then not Cumulative_Restrictions.Set (No_Finalization)
1590 then
1591 WBI (" procedure Initialize (Addr : System.Address);");
1592 WBI (" pragma Import (C, Initialize, ""__gnat_initialize"");");
1593 WBI ("");
1594 WBI (" procedure Finalize;");
1595 WBI (" pragma Import (C, Finalize, ""__gnat_finalize"");");
1596 end if;
1598 -- If we want to analyze the stack, we must import corresponding symbols
1600 if Dynamic_Stack_Measurement then
1601 WBI ("");
1602 WBI (" procedure Output_Results;");
1603 WBI (" pragma Import (C, Output_Results, " &
1604 """__gnat_stack_usage_output_results"");");
1606 WBI ("");
1607 WBI (" " &
1608 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1609 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1610 """__gnat_stack_usage_initialize"");");
1611 end if;
1613 -- Deal with declarations for main program case
1615 if not No_Main_Subprogram then
1616 if ALIs.Table (ALIs.First).Main_Program = Func then
1617 WBI (" Result : Integer;");
1618 WBI ("");
1619 end if;
1621 if Bind_Main_Program
1622 and not Suppress_Standard_Library_On_Target
1623 and not CodePeer_Mode
1624 then
1625 WBI (" SEH : aliased array (1 .. 2) of Integer;");
1626 WBI ("");
1627 end if;
1628 end if;
1630 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1631 -- not referenced elsewhere in the generated program, but is needed
1632 -- by the debugger (that's why it is generated in the first place).
1633 -- The reference stops Ada_Main_Program_Name from being optimized
1634 -- away by smart linkers, such as the AiX linker.
1636 -- Because this variable is unused, we make this variable "aliased"
1637 -- with a pragma Volatile in order to tell the compiler to preserve
1638 -- this variable at any level of optimization.
1640 if Bind_Main_Program and not CodePeer_Mode then
1641 WBI (" Ensure_Reference : aliased System.Address := " &
1642 "Ada_Main_Program_Name'Address;");
1643 WBI (" pragma Volatile (Ensure_Reference);");
1644 WBI ("");
1645 end if;
1647 WBI (" begin");
1649 -- Acquire command line arguments if present on target
1651 if CodePeer_Mode then
1652 null;
1654 elsif Command_Line_Args_On_Target then
1655 WBI (" gnat_argc := argc;");
1656 WBI (" gnat_argv := argv;");
1657 WBI (" gnat_envp := envp;");
1658 WBI ("");
1660 -- If configurable run time and no command line args, then nothing
1661 -- needs to be done since the gnat_argc/argv/envp variables are
1662 -- suppressed in this case.
1664 elsif Configurable_Run_Time_On_Target then
1665 null;
1667 -- Otherwise set dummy values (to be filled in by some other unit?)
1669 else
1670 WBI (" gnat_argc := 0;");
1671 WBI (" gnat_argv := System.Null_Address;");
1672 WBI (" gnat_envp := System.Null_Address;");
1673 end if;
1675 if Opt.Default_Exit_Status /= 0
1676 and then Bind_Main_Program
1677 and then not Configurable_Run_Time_Mode
1678 then
1679 Set_String (" Set_Exit_Status (");
1680 Set_Int (Opt.Default_Exit_Status);
1681 Set_String (");");
1682 Write_Statement_Buffer;
1683 end if;
1685 if Dynamic_Stack_Measurement then
1686 Set_String (" Initialize_Stack_Analysis (");
1687 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1688 Set_String (");");
1689 Write_Statement_Buffer;
1690 end if;
1692 if not Cumulative_Restrictions.Set (No_Finalization)
1693 and then not CodePeer_Mode
1694 then
1695 if not No_Main_Subprogram
1696 and then Bind_Main_Program
1697 and then not Suppress_Standard_Library_On_Target
1698 then
1699 WBI (" Initialize (SEH'Address);");
1700 else
1701 WBI (" Initialize (System.Null_Address);");
1702 end if;
1703 end if;
1705 WBI (" " & Ada_Init_Name.all & ";");
1707 if not No_Main_Subprogram then
1708 if CodePeer_Mode then
1709 if ALIs.Table (ALIs.First).Main_Program = Proc then
1710 WBI (" " & CodePeer_Wrapper_Name & ";");
1711 else
1712 WBI (" Result := " & CodePeer_Wrapper_Name & ";");
1713 end if;
1715 elsif ALIs.Table (ALIs.First).Main_Program = Proc then
1716 WBI (" Ada_Main_Program;");
1718 else
1719 WBI (" Result := Ada_Main_Program;");
1720 end if;
1721 end if;
1723 -- Adafinal call is skipped if no finalization
1725 if not Cumulative_Restrictions.Set (No_Finalization) then
1726 WBI (" adafinal;");
1727 end if;
1729 -- Prints the result of static stack analysis
1731 if Dynamic_Stack_Measurement then
1732 WBI (" Output_Results;");
1733 end if;
1735 -- Finalize is only called if we have a run time
1737 if not Cumulative_Restrictions.Set (No_Finalization)
1738 and then not CodePeer_Mode
1739 then
1740 WBI (" Finalize;");
1741 end if;
1743 -- Return result
1745 if Exit_Status_Supported_On_Target then
1746 if No_Main_Subprogram
1747 or else ALIs.Table (ALIs.First).Main_Program = Proc
1748 then
1749 WBI (" return (gnat_exit_status);");
1750 else
1751 WBI (" return (Result);");
1752 end if;
1753 end if;
1755 WBI (" end;");
1756 WBI ("");
1757 end Gen_Main;
1759 ------------------------------
1760 -- Gen_Object_Files_Options --
1761 ------------------------------
1763 procedure Gen_Object_Files_Options is
1764 Lgnat : Natural;
1765 -- This keeps track of the position in the sorted set of entries
1766 -- in the Linker_Options table of where the first entry from an
1767 -- internal file appears.
1769 Linker_Option_List_Started : Boolean := False;
1770 -- Set to True when "LINKER OPTION LIST" is displayed
1772 procedure Write_Linker_Option;
1773 -- Write binder info linker option
1775 -------------------------
1776 -- Write_Linker_Option --
1777 -------------------------
1779 procedure Write_Linker_Option is
1780 Start : Natural;
1781 Stop : Natural;
1783 begin
1784 -- Loop through string, breaking at null's
1786 Start := 1;
1787 while Start < Name_Len loop
1789 -- Find null ending this section
1791 Stop := Start + 1;
1792 while Name_Buffer (Stop) /= ASCII.NUL
1793 and then Stop <= Name_Len loop
1794 Stop := Stop + 1;
1795 end loop;
1797 -- Process section if non-null
1799 if Stop > Start then
1800 if Output_Linker_Option_List then
1801 if not Zero_Formatting then
1802 if not Linker_Option_List_Started then
1803 Linker_Option_List_Started := True;
1804 Write_Eol;
1805 Write_Str (" LINKER OPTION LIST");
1806 Write_Eol;
1807 Write_Eol;
1808 end if;
1810 Write_Str (" ");
1811 end if;
1813 Write_Str (Name_Buffer (Start .. Stop - 1));
1814 Write_Eol;
1815 end if;
1816 WBI (" -- " & Name_Buffer (Start .. Stop - 1));
1817 end if;
1819 Start := Stop + 1;
1820 end loop;
1821 end Write_Linker_Option;
1823 -- Start of processing for Gen_Object_Files_Options
1825 begin
1826 WBI ("-- BEGIN Object file/option list");
1828 if Object_List_Filename /= null then
1829 Set_List_File (Object_List_Filename.all);
1830 end if;
1832 for E in Elab_Order.First .. Elab_Order.Last loop
1834 -- If not spec that has an associated body, then generate a comment
1835 -- giving the name of the corresponding object file.
1837 if not Units.Table (Elab_Order.Table (E)).SAL_Interface
1838 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
1839 then
1840 Get_Name_String
1841 (ALIs.Table
1842 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
1844 -- If the presence of an object file is necessary or if it exists,
1845 -- then use it.
1847 if not Hostparm.Exclude_Missing_Objects
1848 or else
1849 System.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
1850 then
1851 WBI (" -- " & Name_Buffer (1 .. Name_Len));
1853 if Output_Object_List then
1854 Write_Str (Name_Buffer (1 .. Name_Len));
1855 Write_Eol;
1856 end if;
1857 end if;
1858 end if;
1859 end loop;
1861 if Object_List_Filename /= null then
1862 Close_List_File;
1863 end if;
1865 -- Add a "-Ldir" for each directory in the object path
1867 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1868 declare
1869 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
1870 begin
1871 Name_Len := 0;
1872 Add_Str_To_Name_Buffer ("-L");
1873 Add_Str_To_Name_Buffer (Dir.all);
1874 Write_Linker_Option;
1875 end;
1876 end loop;
1878 if not (Opt.No_Run_Time_Mode or Opt.No_Stdlib) then
1879 Name_Len := 0;
1881 if Opt.Shared_Libgnat then
1882 Add_Str_To_Name_Buffer ("-shared");
1883 else
1884 Add_Str_To_Name_Buffer ("-static");
1885 end if;
1887 -- Write directly to avoid inclusion in -K output as -static and
1888 -- -shared are not usually specified linker options.
1890 WBI (" -- " & Name_Buffer (1 .. Name_Len));
1891 end if;
1893 -- Sort linker options
1895 -- This sort accomplishes two important purposes:
1897 -- a) All application files are sorted to the front, and all GNAT
1898 -- internal files are sorted to the end. This results in a well
1899 -- defined dividing line between the two sets of files, for the
1900 -- purpose of inserting certain standard library references into
1901 -- the linker arguments list.
1903 -- b) Given two different units, we sort the linker options so that
1904 -- those from a unit earlier in the elaboration order comes later
1905 -- in the list. This is a heuristic designed to create a more
1906 -- friendly order of linker options when the operations appear in
1907 -- separate units. The idea is that if unit A must be elaborated
1908 -- before unit B, then it is more likely that B references
1909 -- libraries included by A, than vice versa, so we want libraries
1910 -- included by A to come after libraries included by B.
1912 -- These two criteria are implemented by function Lt_Linker_Option. Note
1913 -- that a special case of b) is that specs are elaborated before bodies,
1914 -- so linker options from specs come after linker options for bodies,
1915 -- and again, the assumption is that libraries used by the body are more
1916 -- likely to reference libraries used by the spec, than vice versa.
1918 Sort
1919 (Linker_Options.Last,
1920 Move_Linker_Option'Access,
1921 Lt_Linker_Option'Access);
1923 -- Write user linker options, i.e. the set of linker options that come
1924 -- from all files other than GNAT internal files, Lgnat is left set to
1925 -- point to the first entry from a GNAT internal file, or past the end
1926 -- of the entries if there are no internal files.
1928 Lgnat := Linker_Options.Last + 1;
1930 for J in 1 .. Linker_Options.Last loop
1931 if not Linker_Options.Table (J).Internal_File then
1932 Get_Name_String (Linker_Options.Table (J).Name);
1933 Write_Linker_Option;
1934 else
1935 Lgnat := J;
1936 exit;
1937 end if;
1938 end loop;
1940 -- Now we insert standard linker options that must appear after the
1941 -- entries from user files, and before the entries from GNAT run-time
1942 -- files. The reason for this decision is that libraries referenced
1943 -- by internal routines may reference these standard library entries.
1945 -- Note that we do not insert anything when pragma No_Run_Time has
1946 -- been specified or when the standard libraries are not to be used,
1947 -- otherwise on some platforms, we may get duplicate symbols when
1948 -- linking (not clear if this is still the case, but it is harmless).
1950 if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
1951 if With_GNARL then
1952 Name_Len := 0;
1954 if Opt.Shared_Libgnat then
1955 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
1956 else
1957 Add_Str_To_Name_Buffer ("-lgnarl");
1958 end if;
1960 Write_Linker_Option;
1961 end if;
1963 Name_Len := 0;
1965 if Opt.Shared_Libgnat then
1966 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
1967 else
1968 Add_Str_To_Name_Buffer ("-lgnat");
1969 end if;
1971 Write_Linker_Option;
1972 end if;
1974 -- Write linker options from all internal files
1976 for J in Lgnat .. Linker_Options.Last loop
1977 Get_Name_String (Linker_Options.Table (J).Name);
1978 Write_Linker_Option;
1979 end loop;
1981 if Output_Linker_Option_List and then not Zero_Formatting then
1982 Write_Eol;
1983 end if;
1985 WBI ("-- END Object file/option list ");
1986 end Gen_Object_Files_Options;
1988 ---------------------
1989 -- Gen_Output_File --
1990 ---------------------
1992 procedure Gen_Output_File (Filename : String) is
1993 begin
1994 -- Acquire settings for Interrupt_State pragmas
1996 Set_IS_Pragma_Table;
1998 -- Acquire settings for Priority_Specific_Dispatching pragma
2000 Set_PSD_Pragma_Table;
2002 -- Override time slice value if -T switch is set
2004 if Time_Slice_Set then
2005 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
2006 end if;
2008 -- Count number of elaboration calls
2010 for E in Elab_Order.First .. Elab_Order.Last loop
2011 if Units.Table (Elab_Order.Table (E)).No_Elab then
2012 null;
2013 else
2014 Num_Elab_Calls := Num_Elab_Calls + 1;
2015 end if;
2016 end loop;
2018 -- Generate output file in appropriate language
2020 Gen_Output_File_Ada (Filename);
2021 end Gen_Output_File;
2023 -------------------------
2024 -- Gen_Output_File_Ada --
2025 -------------------------
2027 procedure Gen_Output_File_Ada (Filename : String) is
2029 Ada_Main : constant String := Get_Ada_Main_Name;
2030 -- Name to be used for generated Ada main program. See the body of
2031 -- function Get_Ada_Main_Name for details on the form of the name.
2033 Needs_Library_Finalization : constant Boolean :=
2034 not Configurable_Run_Time_On_Target and then Has_Finalizer;
2035 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2036 -- non-terminating, so we do not want finalization.
2038 Bfiles : Name_Id;
2039 -- Name of generated bind file (spec)
2041 Bfileb : Name_Id;
2042 -- Name of generated bind file (body)
2044 begin
2045 -- Create spec first
2047 Create_Binder_Output (Filename, 's', Bfiles);
2049 -- We always compile the binder file in Ada 95 mode so that we properly
2050 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2051 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
2053 WBI ("pragma Ada_95;");
2054 WBI ("pragma Warnings (Off);");
2056 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2057 -- then we need to make sure that the binder program is compiled with
2058 -- the same restriction, so that no exception tables are generated.
2060 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
2061 WBI ("pragma Restrictions (No_Exception_Handlers);");
2062 end if;
2064 -- Same processing for Restrictions (No_Exception_Propagation)
2066 if Cumulative_Restrictions.Set (No_Exception_Propagation) then
2067 WBI ("pragma Restrictions (No_Exception_Propagation);");
2068 end if;
2070 -- Same processing for pragma No_Run_Time
2072 if No_Run_Time_Mode then
2073 WBI ("pragma No_Run_Time;");
2074 end if;
2076 -- Generate with of System so we can reference System.Address
2078 WBI ("with System;");
2080 -- Generate with of System.Initialize_Scalars if active
2082 if Initialize_Scalars_Used then
2083 WBI ("with System.Scalar_Values;");
2084 end if;
2086 -- Generate with of System.Secondary_Stack if active
2088 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
2089 WBI ("with System.Secondary_Stack;");
2090 end if;
2092 Resolve_Binder_Options;
2094 -- Generate standard with's
2096 if not Suppress_Standard_Library_On_Target then
2097 if CodePeer_Mode then
2098 WBI ("with System.Standard_Library;");
2099 end if;
2100 end if;
2102 WBI ("package " & Ada_Main & " is");
2104 -- Main program case
2106 if Bind_Main_Program then
2107 -- Generate argc/argv stuff unless suppressed
2109 if Command_Line_Args_On_Target
2110 or not Configurable_Run_Time_On_Target
2111 then
2112 WBI ("");
2113 WBI (" gnat_argc : Integer;");
2114 WBI (" gnat_argv : System.Address;");
2115 WBI (" gnat_envp : System.Address;");
2117 -- If the standard library is not suppressed, these variables
2118 -- are in the run-time data area for easy run time access.
2120 if not Suppress_Standard_Library_On_Target then
2121 WBI ("");
2122 WBI (" pragma Import (C, gnat_argc);");
2123 WBI (" pragma Import (C, gnat_argv);");
2124 WBI (" pragma Import (C, gnat_envp);");
2125 end if;
2126 end if;
2128 -- Define exit status. Again in normal mode, this is in the
2129 -- run-time library, and is initialized there, but in the
2130 -- configurable runtime case, the variable is declared and
2131 -- initialized in this file.
2133 WBI ("");
2135 if Configurable_Run_Time_Mode then
2136 if Exit_Status_Supported_On_Target then
2137 WBI (" gnat_exit_status : Integer := 0;");
2138 end if;
2140 else
2141 WBI (" gnat_exit_status : Integer;");
2142 WBI (" pragma Import (C, gnat_exit_status);");
2143 end if;
2145 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2146 -- the main program. Otherwise, it can lead under some circumstances
2147 -- to a symbol duplication during the link (for instance when a C
2148 -- program uses two Ada libraries). Also zero terminate the string
2149 -- so that its end can be found reliably at run time.
2151 WBI ("");
2152 WBI (" GNAT_Version : constant String :=");
2153 WBI (" """ & Ver_Prefix &
2154 Gnat_Version_String &
2155 """ & ASCII.NUL;");
2156 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2158 WBI ("");
2159 Set_String (" Ada_Main_Program_Name : constant String := """);
2160 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2162 Set_Main_Program_Name;
2163 Set_String (""" & ASCII.NUL;");
2165 Write_Statement_Buffer;
2168 (" pragma Export (C, Ada_Main_Program_Name, " &
2169 """__gnat_ada_main_program_name"");");
2170 end if;
2172 WBI ("");
2173 WBI (" procedure " & Ada_Init_Name.all & ";");
2174 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2175 Ada_Init_Name.all & """);");
2177 -- If -a has been specified use pragma Linker_Constructor for the init
2178 -- procedure and pragma Linker_Destructor for the final procedure.
2180 if Use_Pragma_Linker_Constructor then
2181 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2182 end if;
2184 if not Cumulative_Restrictions.Set (No_Finalization) then
2185 WBI ("");
2186 WBI (" procedure " & Ada_Final_Name.all & ";");
2187 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2188 Ada_Final_Name.all & """);");
2190 if Use_Pragma_Linker_Constructor then
2191 WBI (" pragma Linker_Destructor (" & Ada_Final_Name.all & ");");
2192 end if;
2193 end if;
2195 if Bind_Main_Program then
2197 WBI ("");
2199 if Exit_Status_Supported_On_Target then
2200 Set_String (" function ");
2201 else
2202 Set_String (" procedure ");
2203 end if;
2205 Set_String (Get_Main_Name);
2207 -- Generate argument list if present
2209 if Command_Line_Args_On_Target then
2210 Write_Statement_Buffer;
2211 WBI (" (argc : Integer;");
2212 WBI (" argv : System.Address;");
2213 Set_String
2214 (" envp : System.Address)");
2216 if Exit_Status_Supported_On_Target then
2217 Write_Statement_Buffer;
2218 WBI (" return Integer;");
2219 else
2220 Write_Statement_Buffer (";");
2221 end if;
2223 else
2224 if Exit_Status_Supported_On_Target then
2225 Write_Statement_Buffer (" return Integer;");
2226 else
2227 Write_Statement_Buffer (";");
2228 end if;
2229 end if;
2231 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2232 Get_Main_Name & """);");
2233 end if;
2235 Gen_Versions;
2236 Gen_Elab_Order;
2238 -- Spec is complete
2240 WBI ("");
2241 WBI ("end " & Ada_Main & ";");
2242 Close_Binder_Output;
2244 -- Prepare to write body
2246 Create_Binder_Output (Filename, 'b', Bfileb);
2248 -- We always compile the binder file in Ada 95 mode so that we properly
2249 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2250 -- of the Ada 2005/2012 constructs are needed by the binder file.
2252 WBI ("pragma Ada_95;");
2253 WBI ("pragma Warnings (Off);");
2255 -- Output Source_File_Name pragmas which look like
2257 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2258 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2260 -- where sss/bbb are the spec/body file names respectively
2262 Get_Name_String (Bfiles);
2263 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2265 WBI ("pragma Source_File_Name (" &
2266 Ada_Main &
2267 ", Spec_File_Name => """ &
2268 Name_Buffer (1 .. Name_Len + 3));
2270 Get_Name_String (Bfileb);
2271 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2273 WBI ("pragma Source_File_Name (" &
2274 Ada_Main &
2275 ", Body_File_Name => """ &
2276 Name_Buffer (1 .. Name_Len + 3));
2278 -- Generate pragma Suppress (Overflow_Check). This is needed for recent
2279 -- versions of the compiler which have overflow checks on by default.
2280 -- We do not want overflow checking enabled for the increments of the
2281 -- elaboration variables (since this can cause an unwanted reference to
2282 -- the last chance exception handler for limited run-times).
2284 WBI ("pragma Suppress (Overflow_Check);");
2286 -- Generate with of System.Restrictions to initialize
2287 -- Run_Time_Restrictions.
2289 if System_Restrictions_Used
2290 and not Suppress_Standard_Library_On_Target
2291 then
2292 WBI ("");
2293 WBI ("with System.Restrictions;");
2294 end if;
2296 -- Generate with of Ada.Exceptions if needs library finalization
2298 if Needs_Library_Finalization then
2299 WBI ("with Ada.Exceptions;");
2300 end if;
2302 -- Generate with of System.Elaboration_Allocators if the restriction
2303 -- No_Standard_Allocators_After_Elaboration was present.
2305 if Cumulative_Restrictions.Set
2306 (No_Standard_Allocators_After_Elaboration)
2307 then
2308 WBI ("with System.Elaboration_Allocators;");
2309 end if;
2311 -- Generate start of package body
2313 WBI ("");
2314 WBI ("package body " & Ada_Main & " is");
2315 WBI ("");
2317 -- Generate externals for elaboration entities
2319 Gen_Elab_Externals;
2321 if not CodePeer_Mode then
2322 if not Suppress_Standard_Library_On_Target then
2324 -- Generate Priority_Specific_Dispatching pragma string
2326 Set_String
2327 (" Local_Priority_Specific_Dispatching : " &
2328 "constant String := """);
2330 for J in 0 .. PSD_Pragma_Settings.Last loop
2331 Set_Char (PSD_Pragma_Settings.Table (J));
2332 end loop;
2334 Set_String (""";");
2335 Write_Statement_Buffer;
2337 -- Generate Interrupt_State pragma string
2339 Set_String (" Local_Interrupt_States : constant String := """);
2341 for J in 0 .. IS_Pragma_Settings.Last loop
2342 Set_Char (IS_Pragma_Settings.Table (J));
2343 end loop;
2345 Set_String (""";");
2346 Write_Statement_Buffer;
2347 WBI ("");
2348 end if;
2350 if not Suppress_Standard_Library_On_Target then
2352 -- The B.1(39) implementation advice says that the adainit
2353 -- and adafinal routines should be idempotent. Generate a flag to
2354 -- ensure that. This is not needed if we are suppressing the
2355 -- standard library since it would never be referenced.
2357 WBI (" Is_Elaborated : Boolean := False;");
2359 -- Generate bind environment string
2361 Gen_Bind_Env_String;
2362 end if;
2364 WBI ("");
2365 end if;
2367 -- Generate the adafinal routine unless there is no finalization to do
2369 if not Cumulative_Restrictions.Set (No_Finalization) then
2370 if Needs_Library_Finalization then
2371 Gen_Finalize_Library;
2372 end if;
2374 Gen_Adafinal;
2375 end if;
2377 Gen_Adainit;
2379 if Bind_Main_Program then
2380 Gen_Main;
2381 end if;
2383 -- Output object file list and the Ada body is complete
2385 Gen_Object_Files_Options;
2387 WBI ("");
2388 WBI ("end " & Ada_Main & ";");
2390 Close_Binder_Output;
2391 end Gen_Output_File_Ada;
2393 ----------------------
2394 -- Gen_Restrictions --
2395 ----------------------
2397 procedure Gen_Restrictions is
2398 Count : Integer;
2400 begin
2401 if Suppress_Standard_Library_On_Target
2402 or not System_Restrictions_Used
2403 then
2404 return;
2405 end if;
2407 WBI (" System.Restrictions.Run_Time_Restrictions :=");
2408 WBI (" (Set =>");
2409 Set_String (" (");
2411 Count := 0;
2413 for J in Cumulative_Restrictions.Set'Range loop
2414 Set_Boolean (Cumulative_Restrictions.Set (J));
2415 Set_String (", ");
2416 Count := Count + 1;
2418 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2419 Write_Statement_Buffer;
2420 Set_String (" ");
2421 Count := 0;
2422 end if;
2423 end loop;
2425 Set_String_Replace ("),");
2426 Write_Statement_Buffer;
2427 Set_String (" Value => (");
2429 for J in Cumulative_Restrictions.Value'Range loop
2430 Set_Int (Int (Cumulative_Restrictions.Value (J)));
2431 Set_String (", ");
2432 end loop;
2434 Set_String_Replace ("),");
2435 Write_Statement_Buffer;
2436 WBI (" Violated =>");
2437 Set_String (" (");
2438 Count := 0;
2440 for J in Cumulative_Restrictions.Violated'Range loop
2441 Set_Boolean (Cumulative_Restrictions.Violated (J));
2442 Set_String (", ");
2443 Count := Count + 1;
2445 if J /= Cumulative_Restrictions.Set'Last and then Count = 8 then
2446 Write_Statement_Buffer;
2447 Set_String (" ");
2448 Count := 0;
2449 end if;
2450 end loop;
2452 Set_String_Replace ("),");
2453 Write_Statement_Buffer;
2454 Set_String (" Count => (");
2456 for J in Cumulative_Restrictions.Count'Range loop
2457 Set_Int (Int (Cumulative_Restrictions.Count (J)));
2458 Set_String (", ");
2459 end loop;
2461 Set_String_Replace ("),");
2462 Write_Statement_Buffer;
2463 Set_String (" Unknown => (");
2465 for J in Cumulative_Restrictions.Unknown'Range loop
2466 Set_Boolean (Cumulative_Restrictions.Unknown (J));
2467 Set_String (", ");
2468 end loop;
2470 Set_String_Replace ("))");
2471 Set_String (";");
2472 Write_Statement_Buffer;
2473 end Gen_Restrictions;
2475 ------------------
2476 -- Gen_Versions --
2477 ------------------
2479 -- This routine generates lines such as:
2481 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2482 -- pragma Export (C, unnnnn, unam);
2484 -- for each unit, where unam is the unit name suffixed by either B or S for
2485 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
2486 -- the version number, and nnnnn is a 5-digits serial number.
2488 procedure Gen_Versions is
2489 Ubuf : String (1 .. 6) := "u00000";
2491 procedure Increment_Ubuf;
2492 -- Little procedure to increment the serial number
2494 --------------------
2495 -- Increment_Ubuf --
2496 --------------------
2498 procedure Increment_Ubuf is
2499 begin
2500 for J in reverse Ubuf'Range loop
2501 Ubuf (J) := Character'Succ (Ubuf (J));
2502 exit when Ubuf (J) <= '9';
2503 Ubuf (J) := '0';
2504 end loop;
2505 end Increment_Ubuf;
2507 -- Start of processing for Gen_Versions
2509 begin
2510 WBI ("");
2512 WBI (" type Version_32 is mod 2 ** 32;");
2513 for U in Units.First .. Units.Last loop
2514 if not Units.Table (U).SAL_Interface
2515 and then
2516 (not Bind_For_Library or else Units.Table (U).Directly_Scanned)
2517 then
2518 Increment_Ubuf;
2519 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
2520 Units.Table (U).Version & "#;");
2521 Set_String (" pragma Export (C, ");
2522 Set_String (Ubuf);
2523 Set_String (", """);
2525 Get_Name_String (Units.Table (U).Uname);
2527 for K in 1 .. Name_Len loop
2528 if Name_Buffer (K) = '.' then
2529 Set_Char ('_');
2530 Set_Char ('_');
2532 elsif Name_Buffer (K) = '%' then
2533 exit;
2535 else
2536 Set_Char (Name_Buffer (K));
2537 end if;
2538 end loop;
2540 if Name_Buffer (Name_Len) = 's' then
2541 Set_Char ('S');
2542 else
2543 Set_Char ('B');
2544 end if;
2546 Set_String (""");");
2547 Write_Statement_Buffer;
2548 end if;
2549 end loop;
2550 end Gen_Versions;
2552 ------------------------
2553 -- Get_Main_Unit_Name --
2554 ------------------------
2556 function Get_Main_Unit_Name (S : String) return String is
2557 Result : String := S;
2559 begin
2560 for J in S'Range loop
2561 if Result (J) = '.' then
2562 Result (J) := '_';
2563 end if;
2564 end loop;
2566 return Result;
2567 end Get_Main_Unit_Name;
2569 -----------------------
2570 -- Get_Ada_Main_Name --
2571 -----------------------
2573 function Get_Ada_Main_Name return String is
2574 Suffix : constant String := "_00";
2575 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
2576 Opt.Ada_Main_Name.all & Suffix;
2577 Nlen : Natural;
2579 begin
2580 -- For CodePeer, we want reproducible names (independent of other
2581 -- mains that may or may not be present) that don't collide
2582 -- when analyzing multiple mains and which are easily recognizable
2583 -- as "ada_main" names.
2585 if CodePeer_Mode then
2586 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2587 return "ada_main_for_" &
2588 Get_Main_Unit_Name (Name_Buffer (1 .. Name_Len - 2));
2589 end if;
2591 -- This loop tries the following possibilities in order
2592 -- <Ada_Main>
2593 -- <Ada_Main>_01
2594 -- <Ada_Main>_02
2595 -- ..
2596 -- <Ada_Main>_99
2597 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2598 -- it is set to 'ada_main'.
2600 for J in 0 .. 99 loop
2601 if J = 0 then
2602 Nlen := Name'Length - Suffix'Length;
2603 else
2604 Nlen := Name'Length;
2605 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
2606 Name (Name'Last - 1) :=
2607 Character'Val (J / 10 + Character'Pos ('0'));
2608 end if;
2610 for K in ALIs.First .. ALIs.Last loop
2611 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
2613 -- Get unit name, removing %b or %e at end
2615 Get_Name_String (Units.Table (L).Uname);
2616 Name_Len := Name_Len - 2;
2618 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
2619 goto Continue;
2620 end if;
2621 end loop;
2622 end loop;
2624 return Name (1 .. Nlen);
2626 <<Continue>>
2627 null;
2628 end loop;
2630 -- If we fall through, just use a peculiar unlikely name
2632 return ("Qwertyuiop");
2633 end Get_Ada_Main_Name;
2635 -------------------
2636 -- Get_Main_Name --
2637 -------------------
2639 function Get_Main_Name return String is
2640 begin
2641 -- Explicit name given with -M switch
2643 if Bind_Alternate_Main_Name then
2644 return Alternate_Main_Name.all;
2646 -- Case of main program name to be used directly
2648 elsif Use_Ada_Main_Program_Name_On_Target then
2650 -- Get main program name
2652 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2654 -- If this is a child name, return only the name of the child, since
2655 -- we can't have dots in a nested program name. Note that we do not
2656 -- include the %b at the end of the unit name.
2658 for J in reverse 1 .. Name_Len - 2 loop
2659 if J = 1 or else Name_Buffer (J - 1) = '.' then
2660 return Name_Buffer (J .. Name_Len - 2);
2661 end if;
2662 end loop;
2664 raise Program_Error; -- impossible exit
2666 -- Case where "main" is to be used as default
2668 else
2669 return "main";
2670 end if;
2671 end Get_Main_Name;
2673 ---------------------
2674 -- Get_WC_Encoding --
2675 ---------------------
2677 function Get_WC_Encoding return Character is
2678 begin
2679 -- If encoding method specified by -W switch, then return it
2681 if Wide_Character_Encoding_Method_Specified then
2682 return WC_Encoding_Letters (Wide_Character_Encoding_Method);
2684 -- If no main program, and not specified, set brackets, we really have
2685 -- no better choice. If some other encoding is required when there is
2686 -- no main, it must be set explicitly using -Wx.
2688 -- Note: if the ALI file always passed the wide character encoding of
2689 -- every file, then we could use the encoding of the initial specified
2690 -- file, but this information is passed only for potential main
2691 -- programs. We could fix this sometime, but it is a very minor point
2692 -- (wide character default encoding for [Wide_[Wide_]Text_IO when there
2693 -- is no main program).
2695 elsif No_Main_Subprogram then
2696 return 'b';
2698 -- Otherwise if there is a main program, take encoding from it
2700 else
2701 return ALIs.Table (ALIs.First).WC_Encoding;
2702 end if;
2703 end Get_WC_Encoding;
2705 -------------------
2706 -- Has_Finalizer --
2707 -------------------
2709 function Has_Finalizer return Boolean is
2710 U : Unit_Record;
2711 Unum : Unit_Id;
2713 begin
2714 for E in reverse Elab_Order.First .. Elab_Order.Last loop
2715 Unum := Elab_Order.Table (E);
2716 U := Units.Table (Unum);
2718 -- We are only interested in non-generic packages
2720 if U.Unit_Kind = 'p'
2721 and then U.Has_Finalizer
2722 and then not U.Is_Generic
2723 and then not U.No_Elab
2724 then
2725 return True;
2726 end if;
2727 end loop;
2729 return False;
2730 end Has_Finalizer;
2732 ----------
2733 -- Hash --
2734 ----------
2736 function Hash (Nam : Name_Id) return Header_Num is
2737 begin
2738 return Int (Nam - Names_Low_Bound) rem Header_Num'Last;
2739 end Hash;
2741 ----------------------
2742 -- Lt_Linker_Option --
2743 ----------------------
2745 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
2746 begin
2747 -- Sort internal files last
2749 if Linker_Options.Table (Op1).Internal_File
2751 Linker_Options.Table (Op2).Internal_File
2752 then
2753 -- Note: following test uses False < True
2755 return Linker_Options.Table (Op1).Internal_File
2757 Linker_Options.Table (Op2).Internal_File;
2759 -- If both internal or both non-internal, sort according to the
2760 -- elaboration position. A unit that is elaborated later should come
2761 -- earlier in the linker options list.
2763 else
2764 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
2766 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
2768 end if;
2769 end Lt_Linker_Option;
2771 ------------------------
2772 -- Move_Linker_Option --
2773 ------------------------
2775 procedure Move_Linker_Option (From : Natural; To : Natural) is
2776 begin
2777 Linker_Options.Table (To) := Linker_Options.Table (From);
2778 end Move_Linker_Option;
2780 ----------------------------
2781 -- Resolve_Binder_Options --
2782 ----------------------------
2784 procedure Resolve_Binder_Options is
2786 procedure Check_Package (Var : in out Boolean; Name : String);
2787 -- Set Var to true iff the current identifier in Namet is Name. Do
2788 -- nothing if it doesn't match. This procedure is just a helper to
2789 -- avoid explicitly dealing with length.
2791 -------------------
2792 -- Check_Package --
2793 -------------------
2795 procedure Check_Package (Var : in out Boolean; Name : String) is
2796 begin
2797 if Name_Len = Name'Length
2798 and then Name_Buffer (1 .. Name_Len) = Name
2799 then
2800 Var := True;
2801 end if;
2802 end Check_Package;
2804 -- Start of processing for Resolve_Binder_Options
2806 begin
2807 for E in Elab_Order.First .. Elab_Order.Last loop
2808 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
2810 -- This is not a perfect approach, but is the current protocol
2811 -- between the run-time and the binder to indicate that tasking is
2812 -- used: System.OS_Interface should always be used by any tasking
2813 -- application.
2815 Check_Package (With_GNARL, "system.os_interface%s");
2817 -- Ditto for the use of restricted tasking
2819 Check_Package
2820 (System_Tasking_Restricted_Stages_Used,
2821 "system.tasking.restricted.stages%s");
2823 -- Ditto for the use of interrupts
2825 Check_Package (System_Interrupts_Used, "system.interrupts%s");
2827 -- Ditto for the use of dispatching domains
2829 Check_Package
2830 (Dispatching_Domains_Used,
2831 "system.multiprocessors.dispatching_domains%s");
2833 -- Ditto for the use of restrictions
2835 Check_Package (System_Restrictions_Used, "system.restrictions%s");
2837 -- Ditto for use of an SMP bareboard runtime
2839 Check_Package (System_BB_CPU_Primitives_Multiprocessors_Used,
2840 "system.bb.cpu_primitives.multiprocessors%s");
2842 end loop;
2843 end Resolve_Binder_Options;
2845 ------------------
2846 -- Set_Bind_Env --
2847 ------------------
2849 procedure Set_Bind_Env (Key, Value : String) is
2850 begin
2851 -- The lengths of Key and Value are stored as single bytes
2853 if Key'Length > 255 then
2854 Osint.Fail ("bind environment key """ & Key & """ too long");
2855 end if;
2857 if Value'Length > 255 then
2858 Osint.Fail ("bind environment value """ & Value & """ too long");
2859 end if;
2861 Bind_Environment.Set (Name_Find (Key), Name_Find (Value));
2862 end Set_Bind_Env;
2864 -----------------
2865 -- Set_Boolean --
2866 -----------------
2868 procedure Set_Boolean (B : Boolean) is
2869 True_Str : constant String := "True";
2870 False_Str : constant String := "False";
2871 begin
2872 if B then
2873 Statement_Buffer (Last + 1 .. Last + True_Str'Length) := True_Str;
2874 Last := Last + True_Str'Length;
2875 else
2876 Statement_Buffer (Last + 1 .. Last + False_Str'Length) := False_Str;
2877 Last := Last + False_Str'Length;
2878 end if;
2879 end Set_Boolean;
2881 --------------
2882 -- Set_Char --
2883 --------------
2885 procedure Set_Char (C : Character) is
2886 begin
2887 Last := Last + 1;
2888 Statement_Buffer (Last) := C;
2889 end Set_Char;
2891 -------------
2892 -- Set_Int --
2893 -------------
2895 procedure Set_Int (N : Int) is
2896 begin
2897 if N < 0 then
2898 Set_String ("-");
2899 Set_Int (-N);
2901 else
2902 if N > 9 then
2903 Set_Int (N / 10);
2904 end if;
2906 Last := Last + 1;
2907 Statement_Buffer (Last) :=
2908 Character'Val (N mod 10 + Character'Pos ('0'));
2909 end if;
2910 end Set_Int;
2912 -------------------------
2913 -- Set_IS_Pragma_Table --
2914 -------------------------
2916 procedure Set_IS_Pragma_Table is
2917 begin
2918 for F in ALIs.First .. ALIs.Last loop
2919 for K in ALIs.Table (F).First_Interrupt_State ..
2920 ALIs.Table (F).Last_Interrupt_State
2921 loop
2922 declare
2923 Inum : constant Int :=
2924 Interrupt_States.Table (K).Interrupt_Id;
2925 Stat : constant Character :=
2926 Interrupt_States.Table (K).Interrupt_State;
2928 begin
2929 while IS_Pragma_Settings.Last < Inum loop
2930 IS_Pragma_Settings.Append ('n');
2931 end loop;
2933 IS_Pragma_Settings.Table (Inum) := Stat;
2934 end;
2935 end loop;
2936 end loop;
2937 end Set_IS_Pragma_Table;
2939 ---------------------------
2940 -- Set_Main_Program_Name --
2941 ---------------------------
2943 procedure Set_Main_Program_Name is
2944 begin
2945 -- Note that name has %b on the end which we ignore
2947 -- First we output the initial _ada_ since we know that the main
2948 -- program is a library level subprogram.
2950 Set_String ("_ada_");
2952 -- Copy name, changing dots to double underscores
2954 for J in 1 .. Name_Len - 2 loop
2955 if Name_Buffer (J) = '.' then
2956 Set_String ("__");
2957 else
2958 Set_Char (Name_Buffer (J));
2959 end if;
2960 end loop;
2961 end Set_Main_Program_Name;
2963 ---------------------
2964 -- Set_Name_Buffer --
2965 ---------------------
2967 procedure Set_Name_Buffer is
2968 begin
2969 for J in 1 .. Name_Len loop
2970 Set_Char (Name_Buffer (J));
2971 end loop;
2972 end Set_Name_Buffer;
2974 -------------------------
2975 -- Set_PSD_Pragma_Table --
2976 -------------------------
2978 procedure Set_PSD_Pragma_Table is
2979 begin
2980 for F in ALIs.First .. ALIs.Last loop
2981 for K in ALIs.Table (F).First_Specific_Dispatching ..
2982 ALIs.Table (F).Last_Specific_Dispatching
2983 loop
2984 declare
2985 DTK : Specific_Dispatching_Record
2986 renames Specific_Dispatching.Table (K);
2988 begin
2989 while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
2990 PSD_Pragma_Settings.Append ('F');
2991 end loop;
2993 for Prio in DTK.First_Priority .. DTK.Last_Priority loop
2994 PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
2995 end loop;
2996 end;
2997 end loop;
2998 end loop;
2999 end Set_PSD_Pragma_Table;
3001 ----------------
3002 -- Set_String --
3003 ----------------
3005 procedure Set_String (S : String) is
3006 begin
3007 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
3008 Last := Last + S'Length;
3009 end Set_String;
3011 ------------------------
3012 -- Set_String_Replace --
3013 ------------------------
3015 procedure Set_String_Replace (S : String) is
3016 begin
3017 Statement_Buffer (Last - S'Length + 1 .. Last) := S;
3018 end Set_String_Replace;
3020 -------------------
3021 -- Set_Unit_Name --
3022 -------------------
3024 procedure Set_Unit_Name is
3025 begin
3026 for J in 1 .. Name_Len - 2 loop
3027 if Name_Buffer (J) = '.' then
3028 Set_String ("__");
3029 else
3030 Set_Char (Name_Buffer (J));
3031 end if;
3032 end loop;
3033 end Set_Unit_Name;
3035 ---------------------
3036 -- Set_Unit_Number --
3037 ---------------------
3039 procedure Set_Unit_Number (U : Unit_Id) is
3040 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
3041 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
3043 begin
3044 if Num_Units >= 10 and then Unum < 10 then
3045 Set_Char ('0');
3046 end if;
3048 if Num_Units >= 100 and then Unum < 100 then
3049 Set_Char ('0');
3050 end if;
3052 Set_Int (Unum);
3053 end Set_Unit_Number;
3055 ---------------------
3056 -- Write_Bind_Line --
3057 ---------------------
3059 procedure Write_Bind_Line (S : String) is
3060 begin
3061 -- Need to strip trailing LF from S
3063 WBI (S (S'First .. S'Last - 1));
3064 end Write_Bind_Line;
3066 ----------------------------
3067 -- Write_Statement_Buffer --
3068 ----------------------------
3070 procedure Write_Statement_Buffer is
3071 begin
3072 WBI (Statement_Buffer (1 .. Last));
3073 Last := 0;
3074 end Write_Statement_Buffer;
3076 procedure Write_Statement_Buffer (S : String) is
3077 begin
3078 Set_String (S);
3079 Write_Statement_Buffer;
3080 end Write_Statement_Buffer;
3082 end Bindgen;