1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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 Binde
; use Binde
;
28 with Casing
; use Casing
;
29 with Fname
; use Fname
;
30 with Gnatvsn
; use Gnatvsn
;
32 with Namet
; use Namet
;
34 with Osint
; use Osint
;
35 with Osint
.B
; use Osint
.B
;
36 with Output
; use Output
;
37 with Rident
; use Rident
;
38 with Table
; use Table
;
39 with Targparm
; use Targparm
;
40 with Types
; use Types
;
42 with System
.OS_Lib
; use System
.OS_Lib
;
43 with System
.WCh_Con
; use System
.WCh_Con
;
45 with GNAT
.Heap_Sort_A
; use GNAT
.Heap_Sort_A
;
47 package body Bindgen
is
49 Statement_Buffer
: String (1 .. 1000);
50 -- Buffer used for constructing output statements
53 -- Last location in Statement_Buffer currently set
55 With_DECGNAT
: Boolean := False;
56 -- Flag which indicates whether the program uses the DECGNAT library
57 -- (presence of the unit DEC).
59 With_GNARL
: Boolean := False;
60 -- Flag which indicates whether the program uses the GNARL library
61 -- (presence of the unit System.OS_Interface)
63 Num_Elab_Calls
: Nat
:= 0;
64 -- Number of generated calls to elaboration routines
66 System_Restrictions_Used
: Boolean;
67 -- Flag indicating whether the unit System.Restrictions is in the closure
68 -- of the partition. This is set by Check_System_Restrictions_Used, and
69 -- is used to determine whether or not to initialize the restrictions
70 -- information in the body of the binder generated file (we do not want
71 -- to do this unconditionally, since it drags in the System.Restrictions
72 -- unit unconditionally, which is unpleasand, especially for ZFP etc.)
74 Dispatching_Domains_Used
: Boolean;
75 -- Flag indicating whether multiprocessor dispatching domains are used in
76 -- the closure of the partition. This is set by
77 -- Check_Dispatching_Domains_Used, and is used to call the routine to
78 -- disallow the creation of new dispatching domains just before calling
79 -- the main procedure from the environment task.
81 Lib_Final_Built
: Boolean := False;
82 -- Flag indicating whether the finalize_library rountine has been built
84 CodePeer_Wrapper_Name
: constant String := "call_main_subprogram";
85 -- For CodePeer, introduce a wrapper subprogram which calls the
86 -- user-defined main subprogram.
88 ----------------------------------
89 -- Interface_State Pragma Table --
90 ----------------------------------
92 -- This table assembles the interface state pragma information from
93 -- all the units in the partition. Note that Bcheck has already checked
94 -- that the information is consistent across units. The entries
95 -- in this table are n/u/r/s for not set/user/runtime/system.
97 package IS_Pragma_Settings
is new Table
.Table
(
98 Table_Component_Type
=> Character,
99 Table_Index_Type
=> Int
,
100 Table_Low_Bound
=> 0,
101 Table_Initial
=> 100,
102 Table_Increment
=> 200,
103 Table_Name
=> "IS_Pragma_Settings");
105 -- This table assembles the Priority_Specific_Dispatching pragma
106 -- information from all the units in the partition. Note that Bcheck has
107 -- already checked that the information is consistent across units.
108 -- The entries in this table are the upper case first character of the
109 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
111 package PSD_Pragma_Settings
is new Table
.Table
(
112 Table_Component_Type
=> Character,
113 Table_Index_Type
=> Int
,
114 Table_Low_Bound
=> 0,
115 Table_Initial
=> 100,
116 Table_Increment
=> 200,
117 Table_Name
=> "PSD_Pragma_Settings");
119 ----------------------
120 -- Run-Time Globals --
121 ----------------------
123 -- This section documents the global variables that set from the
124 -- generated binder file.
126 -- Main_Priority : Integer;
127 -- Time_Slice_Value : Integer;
128 -- Heap_Size : Natural;
129 -- WC_Encoding : Character;
130 -- Locking_Policy : Character;
131 -- Queuing_Policy : Character;
132 -- Task_Dispatching_Policy : Character;
133 -- Priority_Specific_Dispatching : System.Address;
134 -- Num_Specific_Dispatching : Integer;
135 -- Restrictions : System.Address;
136 -- Interrupt_States : System.Address;
137 -- Num_Interrupt_States : Integer;
138 -- Unreserve_All_Interrupts : Integer;
139 -- Exception_Tracebacks : Integer;
140 -- Detect_Blocking : Integer;
141 -- Default_Stack_Size : Integer;
142 -- Leap_Seconds_Support : Integer;
143 -- Main_CPU : Integer;
145 -- Main_Priority is the priority value set by pragma Priority in the main
146 -- program. If no such pragma is present, the value is -1.
148 -- Time_Slice_Value is the time slice value set by pragma Time_Slice in the
149 -- main program, or by the use of a -Tnnn parameter for the binder (if both
150 -- are present, the binder value overrides). The value is in milliseconds.
151 -- A value of zero indicates that time slicing should be suppressed. If no
152 -- pragma is present, and no -T switch was used, the value is -1.
154 -- Heap_Size is the heap to use for memory allocations set by use of a
155 -- -Hnn parameter for the binder or by the GNAT$NO_MALLOC_64 logical.
156 -- Valid values are 32 and 64. This switch is only effective on VMS.
158 -- WC_Encoding shows the wide character encoding method used for the main
159 -- program. This is one of the encoding letters defined in
160 -- System.WCh_Con.WC_Encoding_Letters.
162 -- Locking_Policy is a space if no locking policy was specified for the
163 -- partition. If a locking policy was specified, the value is the upper
164 -- case first character of the locking policy name, for example, 'C' for
167 -- Queuing_Policy is a space if no queuing policy was specified for the
168 -- partition. If a queuing policy was specified, the value is the upper
169 -- case first character of the queuing policy name for example, 'F' for
172 -- Task_Dispatching_Policy is a space if no task dispatching policy was
173 -- specified for the partition. If a task dispatching policy was specified,
174 -- the value is the upper case first character of the policy name, e.g. 'F'
175 -- for FIFO_Within_Priorities.
177 -- Priority_Specific_Dispatching is the address of a string used to store
178 -- the task dispatching policy specified for the different priorities in
179 -- the partition. The length of this string is determined by the last
180 -- priority for which such a pragma applies (the string will be a null
181 -- string if no specific dispatching policies were used). If pragma were
182 -- present, the entries apply to the priorities in sequence from the first
183 -- priority. The value stored is the upper case first character of the
184 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
185 -- for those priority ranges not specified.
187 -- Num_Specific_Dispatching is length of the Priority_Specific_Dispatching
188 -- string. It will be set to zero if no Priority_Specific_Dispatching
189 -- pragmas are present.
191 -- Restrictions is the address of a null-terminated string specifying the
192 -- restrictions information for the partition. The format is identical to
193 -- that of the parameter string found on R lines in ali files (see Lib.Writ
194 -- spec in lib-writ.ads for full details). The difference is that in this
195 -- context the values are the cumulative ones for the entire partition.
197 -- Interrupt_States is the address of a string used to specify the
198 -- cumulative results of Interrupt_State pragmas used in the partition.
199 -- The length of this string is determined by the last interrupt for which
200 -- such a pragma is given (the string will be a null string if no pragmas
201 -- were used). If pragma were present the entries apply to the interrupts
202 -- in sequence from the first interrupt, and are set to one of four
203 -- possible settings: 'n' for not specified, 'u' for user, 'r' for run
204 -- time, 's' for system, see description of Interrupt_State pragma for
207 -- Num_Interrupt_States is the length of the Interrupt_States string. It
208 -- will be set to zero if no Interrupt_State pragmas are present.
210 -- Unreserve_All_Interrupts is set to one if at least one unit in the
211 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
213 -- Exception_Tracebacks is set to one if the -E parameter was present
214 -- in the bind and to zero otherwise. Note that on some targets exception
215 -- tracebacks are provided by default, so a value of zero for this
216 -- parameter does not necessarily mean no trace backs are available.
218 -- Detect_Blocking indicates whether pragma Detect_Blocking is active or
219 -- not. A value of zero indicates that the pragma is not present, while a
220 -- value of 1 signals its presence in the partition.
222 -- Default_Stack_Size is the default stack size used when creating an Ada
223 -- task with no explicit Storage_Size clause.
225 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
226 -- disabled. A value of zero indicates that leap seconds are turned "off",
227 -- while a value of one signifies "on" status.
229 -- Main_CPU is the processor set by pragma CPU in the main program. If no
230 -- such pragma is present, the value is -1.
232 procedure WBI
(Info
: String) renames Osint
.B
.Write_Binder_Info
;
233 -- Convenient shorthand used throughout
235 -----------------------
236 -- Local Subprograms --
237 -----------------------
239 procedure Check_File_In_Partition
242 -- If the file indicated by File_Name is in the partition the Flag is set
243 -- to True, False otherwise.
245 procedure Check_System_Restrictions_Used
;
246 -- Sets flag System_Restrictions_Used (Set to True if and only if the unit
247 -- System.Restrictions is present in the partition, otherwise False).
249 procedure Check_Dispatching_Domains_Used
;
250 -- Sets flag Dispatching_Domains_Used to True when using the unit
251 -- System.Multiprocessors.Dispatching_Domains is present in the partition,
252 -- otherwise set to False.
254 procedure Gen_Adainit
;
255 -- Generates the Adainit procedure
257 procedure Gen_Adafinal
;
258 -- Generate the Adafinal procedure
260 procedure Gen_CodePeer_Wrapper
;
261 -- For CodePeer, generate wrapper which calls user-defined main subprogram
263 procedure Gen_Elab_Calls
;
264 -- Generate sequence of elaboration calls
266 procedure Gen_Elab_Externals
;
267 -- Generate sequence of external declarations for elaboration
269 procedure Gen_Elab_Order
;
270 -- Generate comments showing elaboration order chosen
272 procedure Gen_Finalize_Library
;
273 -- Generate a sequence of finalization calls to elaborated packages
276 -- Generate procedure main
278 procedure Gen_Object_Files_Options
;
279 -- Output comments containing a list of the full names of the object
280 -- files to be linked and the list of linker options supplied by
281 -- Linker_Options pragmas in the source.
283 procedure Gen_Output_File_Ada
(Filename
: String);
284 -- Generate Ada output file
286 procedure Gen_Restrictions
;
287 -- Generate initialization of restrictions variable
289 procedure Gen_Versions
;
290 -- Output series of definitions for unit versions
292 function Get_Ada_Main_Name
return String;
293 -- This function is used for the Ada main output to compute a usable name
294 -- for the generated main program. The normal main program name is
295 -- Ada_Main, but this won't work if the user has a unit with this name.
296 -- This function tries Ada_Main first, and if there is such a clash, then
297 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
299 function Get_Main_Unit_Name
(S
: String) return String;
300 -- Return the main unit name corresponding to S by replacing '.' with '_'
302 function Get_Main_Name
return String;
303 -- This function is used in the main output case to compute the correct
304 -- external main program. It is "main" by default, unless the flag
305 -- Use_Ada_Main_Program_Name_On_Target is set, in which case it is the name
306 -- of the Ada main name without the "_ada". This default can be overridden
307 -- explicitly using the -Mname binder switch.
309 function Get_WC_Encoding
return Character;
310 -- Return wide character encoding method to set as WC_Encoding in output.
311 -- If -W has been used, returns the specified encoding, otherwise returns
312 -- the encoding method used for the main program source. If there is no
313 -- main program source (-z switch used), returns brackets ('b').
315 function Has_Finalizer
return Boolean;
316 -- Determine whether the current unit has at least one library-level
319 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean;
320 -- Compare linker options, when sorting, first according to
321 -- Is_Internal_File (internal files come later) and then by
322 -- elaboration order position (latest to earliest).
324 procedure Move_Linker_Option
(From
: Natural; To
: Natural);
325 -- Move routine for sorting linker options
327 procedure Resolve_Binder_Options
;
328 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
329 -- since it tests for a package named "dec" which might cause a conflict
330 -- on non-VMS systems.
332 procedure Set_Char
(C
: Character);
333 -- Set given character in Statement_Buffer at the Last + 1 position
334 -- and increment Last by one to reflect the stored character.
336 procedure Set_Int
(N
: Int
);
337 -- Set given value in decimal in Statement_Buffer with no spaces
338 -- starting at the Last + 1 position, and updating Last past the value.
339 -- A minus sign is output for a negative value.
341 procedure Set_Boolean
(B
: Boolean);
342 -- Set given boolean value in Statement_Buffer at the Last + 1 position
343 -- and update Last past the value.
345 procedure Set_IS_Pragma_Table
;
346 -- Initializes contents of IS_Pragma_Settings table from ALI table
348 procedure Set_Main_Program_Name
;
349 -- Given the main program name in Name_Buffer (length in Name_Len)
350 -- generate the name of the routine to be used in the call. The name
351 -- is generated starting at Last + 1, and Last is updated past it.
353 procedure Set_Name_Buffer
;
354 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
356 procedure Set_PSD_Pragma_Table
;
357 -- Initializes contents of PSD_Pragma_Settings table from ALI table
359 procedure Set_String
(S
: String);
360 -- Sets characters of given string in Statement_Buffer, starting at the
361 -- Last + 1 position, and updating last past the string value.
363 procedure Set_String_Replace
(S
: String);
364 -- Replaces the last S'Length characters in the Statement_Buffer with
365 -- the characters of S. The caller must ensure that these characters do
366 -- in fact exist in the Statement_Buffer.
368 type Qualification_Mode
is (Dollar_Sign
, Dot
, Double_Underscores
);
370 procedure Set_Unit_Name
(Mode
: Qualification_Mode
:= Double_Underscores
);
371 -- Given a unit name in the Name_Buffer, copy it into Statement_Buffer,
372 -- starting at the Last + 1 position and update Last past the value.
373 -- Depending on parameter Mode, a dot (.) can be qualified into double
374 -- underscores (__), a dollar sign ($) or left as is.
376 procedure Set_Unit_Number
(U
: Unit_Id
);
377 -- Sets unit number (first unit is 1, leading zeroes output to line
378 -- up all output unit numbers nicely as required by the value, and
379 -- by the total number of units.
381 procedure Write_Statement_Buffer
;
382 -- Write out contents of statement buffer up to Last, and reset Last to 0
384 procedure Write_Statement_Buffer
(S
: String);
385 -- First writes its argument (using Set_String (S)), then writes out the
386 -- contents of statement buffer up to Last, and reset Last to 0
388 ------------------------------------
389 -- Check_Dispatching_Domains_Used --
390 ------------------------------------
392 procedure Check_Dispatching_Domains_Used
is
394 Check_File_In_Partition
("s-mudido.ads", Dispatching_Domains_Used
);
395 end Check_Dispatching_Domains_Used
;
397 -----------------------------
398 -- Check_File_In_Partition --
399 -----------------------------
401 procedure Check_File_In_Partition
406 for J
in Units
.First
.. Units
.Last
loop
407 if Get_Name_String
(Units
.Table
(J
).Sfile
) = File_Name
then
414 end Check_File_In_Partition
;
416 ------------------------------------
417 -- Check_System_Restrictions_Used --
418 ------------------------------------
420 procedure Check_System_Restrictions_Used
is
422 Check_File_In_Partition
("s-restri.ads", System_Restrictions_Used
);
423 end Check_System_Restrictions_Used
;
429 procedure Gen_Adafinal
is
431 WBI
(" procedure " & Ada_Final_Name
.all & " is");
434 and Bind_Main_Program
435 and not CodePeer_Mode
437 WBI
(" procedure s_stalib_adafinal;");
438 Set_String
(" pragma Import (C, s_stalib_adafinal, ");
439 Set_String
("""system__standard_library__adafinal"");");
440 Write_Statement_Buffer
;
445 if not CodePeer_Mode
then
446 WBI
(" if not Is_Elaborated then");
449 WBI
(" Is_Elaborated := False;");
452 -- On non-virtual machine targets, finalization is done differently
453 -- depending on whether this is the main program or a library.
455 if VM_Target
= No_VM
and then not CodePeer_Mode
then
456 if Bind_Main_Program
then
457 WBI
(" s_stalib_adafinal;");
458 elsif Lib_Final_Built
then
459 WBI
(" finalize_library;");
464 -- Pragma Import C cannot be used on virtual machine targets, therefore
465 -- call the runtime finalization routine directly. Similarly in CodePeer
466 -- mode, where imported functions are ignored.
469 WBI
(" System.Standard_Library.Adafinal;");
472 WBI
(" end " & Ada_Final_Name
.all & ";");
480 procedure Gen_Adainit
is
481 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
482 Main_CPU
: Int
renames ALIs
.Table
(ALIs
.First
).Main_CPU
;
485 -- Declare the access-to-subprogram type used for initialization of
486 -- of __gnat_finalize_library_objects. This is declared at library
487 -- level for compatibility with the type used in System.Soft_Links.
488 -- The import of the soft link which performs library-level object
489 -- finalization is not needed for VM targets; regular Ada is used in
490 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
491 -- tasks are non-terminating, so we do not want finalization.
493 if not Suppress_Standard_Library_On_Target
494 and then VM_Target
= No_VM
495 and then not CodePeer_Mode
496 and then not Configurable_Run_Time_On_Target
498 WBI
(" type No_Param_Proc is access procedure;");
502 WBI
(" procedure " & Ada_Init_Name
.all & " is");
504 -- In CodePeer mode, simplify adainit procedure by only calling
505 -- elaboration procedures.
507 if CodePeer_Mode
then
510 -- When compiling for the AAMP small library, where the standard library
511 -- is no longer suppressed, we still want to exclude the setting of the
512 -- various imported globals, which aren't present for that library.
514 elsif AAMP_On_Target
and then Configurable_Run_Time_On_Target
then
518 -- If the standard library is suppressed, then the only global variables
519 -- that might be needed (by the Ravenscar profile) are the priority and
520 -- the processor for the environment task.
522 elsif Suppress_Standard_Library_On_Target
then
523 if Main_Priority
/= No_Main_Priority
then
524 WBI
(" Main_Priority : Integer;");
525 WBI
(" pragma Import (C, Main_Priority," &
526 " ""__gl_main_priority"");");
530 if Main_CPU
/= No_Main_CPU
then
531 WBI
(" Main_CPU : Integer;");
532 WBI
(" pragma Import (C, Main_CPU," &
533 " ""__gl_main_cpu"");");
539 if Main_Priority
/= No_Main_Priority
then
540 Set_String
(" Main_Priority := ");
541 Set_Int
(Main_Priority
);
543 Write_Statement_Buffer
;
546 if Main_CPU
/= No_Main_CPU
then
547 Set_String
(" Main_CPU := ");
550 Write_Statement_Buffer
;
553 if Main_Priority
= No_Main_Priority
554 and then Main_CPU
= No_Main_CPU
559 -- Normal case (standard library not suppressed). Set all global values
560 -- used by the run time.
563 WBI
(" Main_Priority : Integer;");
564 WBI
(" pragma Import (C, Main_Priority, " &
565 """__gl_main_priority"");");
566 WBI
(" Time_Slice_Value : Integer;");
567 WBI
(" pragma Import (C, Time_Slice_Value, " &
568 """__gl_time_slice_val"");");
569 WBI
(" WC_Encoding : Character;");
570 WBI
(" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
571 WBI
(" Locking_Policy : Character;");
572 WBI
(" pragma Import (C, Locking_Policy, " &
573 """__gl_locking_policy"");");
574 WBI
(" Queuing_Policy : Character;");
575 WBI
(" pragma Import (C, Queuing_Policy, " &
576 """__gl_queuing_policy"");");
577 WBI
(" Task_Dispatching_Policy : Character;");
578 WBI
(" pragma Import (C, Task_Dispatching_Policy, " &
579 """__gl_task_dispatching_policy"");");
580 WBI
(" Priority_Specific_Dispatching : System.Address;");
581 WBI
(" pragma Import (C, Priority_Specific_Dispatching, " &
582 """__gl_priority_specific_dispatching"");");
583 WBI
(" Num_Specific_Dispatching : Integer;");
584 WBI
(" pragma Import (C, Num_Specific_Dispatching, " &
585 """__gl_num_specific_dispatching"");");
586 WBI
(" Main_CPU : Integer;");
587 WBI
(" pragma Import (C, Main_CPU, " &
588 """__gl_main_cpu"");");
590 WBI
(" Interrupt_States : System.Address;");
591 WBI
(" pragma Import (C, Interrupt_States, " &
592 """__gl_interrupt_states"");");
593 WBI
(" Num_Interrupt_States : Integer;");
594 WBI
(" pragma Import (C, Num_Interrupt_States, " &
595 """__gl_num_interrupt_states"");");
596 WBI
(" Unreserve_All_Interrupts : Integer;");
597 WBI
(" pragma Import (C, Unreserve_All_Interrupts, " &
598 """__gl_unreserve_all_interrupts"");");
600 if Exception_Tracebacks
then
601 WBI
(" Exception_Tracebacks : Integer;");
602 WBI
(" pragma Import (C, Exception_Tracebacks, " &
603 """__gl_exception_tracebacks"");");
606 WBI
(" Detect_Blocking : Integer;");
607 WBI
(" pragma Import (C, Detect_Blocking, " &
608 """__gl_detect_blocking"");");
609 WBI
(" Default_Stack_Size : Integer;");
610 WBI
(" pragma Import (C, Default_Stack_Size, " &
611 """__gl_default_stack_size"");");
612 WBI
(" Leap_Seconds_Support : Integer;");
613 WBI
(" pragma Import (C, Leap_Seconds_Support, " &
614 """__gl_leap_seconds_support"");");
616 -- Import entry point for elaboration time signal handler
617 -- installation, and indication of if it's been called previously.
620 WBI
(" procedure Install_Handler;");
621 WBI
(" pragma Import (C, Install_Handler, " &
622 """__gnat_install_handler"");");
624 WBI
(" Handler_Installed : Integer;");
625 WBI
(" pragma Import (C, Handler_Installed, " &
626 """__gnat_handler_installed"");");
628 -- The import of the soft link which performs library-level object
629 -- finalization is not needed for VM targets; regular Ada is used in
630 -- that case. For restricted run-time libraries (ZFP and Ravenscar)
631 -- tasks are non-terminating, so we do not want finalization.
633 if VM_Target
= No_VM
and then not Configurable_Run_Time_On_Target
then
635 WBI
(" Finalize_Library_Objects : No_Param_Proc;");
636 WBI
(" pragma Import (C, Finalize_Library_Objects, " &
637 """__gnat_finalize_library_objects"");");
640 -- Import entry point for environment feature enable/disable
641 -- routine, and indication that it's been called previously.
643 if OpenVMS_On_Target
then
645 WBI
(" procedure Set_Features;");
646 WBI
(" pragma Import (C, Set_Features, " &
647 """__gnat_set_features"");");
649 WBI
(" Features_Set : Integer;");
650 WBI
(" pragma Import (C, Features_Set, " &
651 """__gnat_features_set"");");
653 if Opt
.Heap_Size
/= 0 then
655 WBI
(" Heap_Size : Integer;");
656 WBI
(" pragma Import (C, Heap_Size, " &
657 """__gl_heap_size"");");
659 Write_Statement_Buffer
;
663 -- Initialize stack limit variable of the environment task if the
664 -- stack check method is stack limit and stack check is enabled.
666 if Stack_Check_Limits_On_Target
667 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
670 WBI
(" procedure Initialize_Stack_Limit;");
671 WBI
(" pragma Import (C, Initialize_Stack_Limit, " &
672 """__gnat_initialize_stack_limit"");");
675 -- Special processing when main program is CIL function/procedure
677 if VM_Target
= CLI_Target
678 and then Bind_Main_Program
679 and then not No_Main_Subprogram
683 -- Function case, use Set_Exit_Status to report the returned
684 -- status code, since that is the only mechanism available.
686 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
687 WBI
(" Result : Integer;");
688 WBI
(" procedure Set_Exit_Status (Code : Integer);");
689 WBI
(" pragma Import (C, Set_Exit_Status, " &
690 """__gnat_set_exit_status"");");
692 WBI
(" function Ada_Main_Program return Integer;");
697 WBI
(" procedure Ada_Main_Program;");
700 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
701 Name_Len
:= Name_Len
- 2;
702 WBI
(" pragma Import (CIL, Ada_Main_Program, """
703 & Name_Buffer
(1 .. Name_Len
) & "."
704 & Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
)) & """);");
707 -- When dispatching domains are used then we need to signal it
708 -- before calling the main procedure.
710 if Dispatching_Domains_Used
then
711 WBI
(" procedure Freeze_Dispatching_Domains;");
712 WBI
(" pragma Import");
713 WBI
(" (Ada, Freeze_Dispatching_Domains, " &
714 """__gnat_freeze_dispatching_domains"");");
718 WBI
(" if Is_Elaborated then");
721 WBI
(" Is_Elaborated := True;");
723 Set_String
(" Main_Priority := ");
724 Set_Int
(Main_Priority
);
726 Write_Statement_Buffer
;
728 Set_String
(" Time_Slice_Value := ");
730 if Task_Dispatching_Policy_Specified
= 'F'
731 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
735 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
739 Write_Statement_Buffer
;
741 Set_String
(" WC_Encoding := '");
742 Set_Char
(Get_WC_Encoding
);
745 Write_Statement_Buffer
;
747 Set_String
(" Locking_Policy := '");
748 Set_Char
(Locking_Policy_Specified
);
750 Write_Statement_Buffer
;
752 Set_String
(" Queuing_Policy := '");
753 Set_Char
(Queuing_Policy_Specified
);
755 Write_Statement_Buffer
;
757 Set_String
(" Task_Dispatching_Policy := '");
758 Set_Char
(Task_Dispatching_Policy_Specified
);
760 Write_Statement_Buffer
;
764 WBI
(" Priority_Specific_Dispatching :=");
765 WBI
(" Local_Priority_Specific_Dispatching'Address;");
767 Set_String
(" Num_Specific_Dispatching := ");
768 Set_Int
(PSD_Pragma_Settings
.Last
+ 1);
770 Write_Statement_Buffer
;
772 Set_String
(" Main_CPU := ");
775 Write_Statement_Buffer
;
777 WBI
(" Interrupt_States := Local_Interrupt_States'Address;");
779 Set_String
(" Num_Interrupt_States := ");
780 Set_Int
(IS_Pragma_Settings
.Last
+ 1);
782 Write_Statement_Buffer
;
784 Set_String
(" Unreserve_All_Interrupts := ");
786 if Unreserve_All_Interrupts_Specified
then
793 Write_Statement_Buffer
;
795 if Exception_Tracebacks
then
796 WBI
(" Exception_Tracebacks := 1;");
799 Set_String
(" Detect_Blocking := ");
801 if Detect_Blocking
then
808 Write_Statement_Buffer
;
810 Set_String
(" Default_Stack_Size := ");
811 Set_Int
(Default_Stack_Size
);
813 Write_Statement_Buffer
;
815 Set_String
(" Leap_Seconds_Support := ");
817 if Leap_Seconds_Support
then
824 Write_Statement_Buffer
;
826 -- Generate call to Install_Handler
828 -- In .NET, when binding with -z, we don't install the signal handler
829 -- to let the caller handle the last exception handler.
831 if VM_Target
/= CLI_Target
832 or else Bind_Main_Program
835 WBI
(" if Handler_Installed = 0 then");
836 WBI
(" Install_Handler;");
840 -- Generate call to Set_Features
842 if OpenVMS_On_Target
then
844 WBI
(" if Features_Set = 0 then");
845 WBI
(" Set_Features;");
848 -- Features_Set may twiddle the heap size according to a logical
849 -- name, but the binder switch must override.
851 if Opt
.Heap_Size
/= 0 then
852 Set_String
(" Heap_Size := ");
853 Set_Int
(Opt
.Heap_Size
);
855 Write_Statement_Buffer
;
860 -- Generate call to set Initialize_Scalar values if active
862 if Initialize_Scalars_Used
then
864 Set_String
(" System.Scalar_Values.Initialize ('");
865 Set_Char
(Initialize_Scalars_Mode1
);
867 Set_Char
(Initialize_Scalars_Mode2
);
869 Write_Statement_Buffer
;
872 -- Generate assignment of default secondary stack size if set
874 if Sec_Stack_Used
and then Default_Sec_Stack_Size
/= -1 then
876 Set_String
(" System.Secondary_Stack.");
877 Set_String
("Default_Secondary_Stack_Size := ");
878 Set_Int
(Opt
.Default_Sec_Stack_Size
);
880 Write_Statement_Buffer
;
883 -- Initialize stack limit variable of the environment task if the
884 -- stack check method is stack limit and stack check is enabled.
886 if Stack_Check_Limits_On_Target
887 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
890 WBI
(" Initialize_Stack_Limit;");
893 -- On CodePeer, the finalization of library objects is not relevant
895 if CodePeer_Mode
then
898 -- On virtual machine targets, or on non-virtual machine ones if this
899 -- is the main program case, attach finalize_library to the soft link.
900 -- Do it only when not using a restricted run time, in which case tasks
901 -- are non-terminating, so we do not want library-level finalization.
903 elsif (VM_Target
/= No_VM
or else Bind_Main_Program
)
904 and then not Configurable_Run_Time_On_Target
905 and then not Suppress_Standard_Library_On_Target
909 if VM_Target
= No_VM
then
910 if Lib_Final_Built
then
911 Set_String
(" Finalize_Library_Objects := ");
912 Set_String
("finalize_library'access;");
914 Set_String
(" Finalize_Library_Objects := null;");
917 -- On VM targets use regular Ada to set the soft link
920 if Lib_Final_Built
then
922 (" System.Soft_Links.Finalize_Library_Objects");
923 Set_String
(" := finalize_library'access;");
926 (" System.Soft_Links.Finalize_Library_Objects");
927 Set_String
(" := null;");
931 Write_Statement_Buffer
;
934 -- Generate elaboration calls
936 if not CodePeer_Mode
then
942 -- From this point, no new dispatching domain can be created.
944 if Dispatching_Domains_Used
then
945 WBI
(" Freeze_Dispatching_Domains;");
948 -- Case of main program is CIL function or procedure
950 if VM_Target
= CLI_Target
951 and then Bind_Main_Program
952 and then not No_Main_Subprogram
954 -- For function case, use Set_Exit_Status to set result
956 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
957 WBI
(" Result := Ada_Main_Program;");
958 WBI
(" Set_Exit_Status (Result);");
963 WBI
(" Ada_Main_Program;");
967 WBI
(" end " & Ada_Init_Name
.all & ";");
971 --------------------------
972 -- Gen_CodePeer_Wrapper --
973 --------------------------
975 procedure Gen_CodePeer_Wrapper
is
976 Callee_Name
: constant String := "Ada_Main_Program";
979 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
980 WBI
(" procedure " & CodePeer_Wrapper_Name
& " is ");
982 WBI
(" " & Callee_Name
& ";");
985 WBI
(" function " & CodePeer_Wrapper_Name
& " return Integer is");
987 WBI
(" return " & Callee_Name
& ";");
990 WBI
(" end " & CodePeer_Wrapper_Name
& ";");
992 end Gen_CodePeer_Wrapper
;
998 procedure Gen_Elab_Calls
is
999 Check_Elab_Flag
: Boolean;
1002 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1004 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
1005 U
: Unit_Record
renames Units
.Table
(Unum
);
1007 Unum_Spec
: Unit_Id
;
1008 -- This is the unit number of the spec that corresponds to
1009 -- this entry. It is the same as Unum except when the body
1010 -- and spec are different and we are currently processing
1011 -- the body, in which case it is the spec (Unum + 1).
1014 if U
.Utype
= Is_Body
then
1015 Unum_Spec
:= Unum
+ 1;
1020 -- Nothing to do if predefined unit in no run time mode
1022 if No_Run_Time_Mode
and then Is_Predefined_File_Name
(U
.Sfile
) then
1025 -- Likewise if this is an interface to a stand alone library
1027 elsif U
.SAL_Interface
then
1030 -- Case of no elaboration code
1032 -- In CodePeer mode, we special case subprogram bodies which
1033 -- are handled in the 'else' part below, and lead to a call to
1034 -- <subp>'Elab_Subp_Body.
1037 and then (not CodePeer_Mode
1038 or else U
.Utype
= Is_Spec
1039 or else U
.Utype
= Is_Spec_Only
1040 or else U
.Unit_Kind
/= 's')
1043 -- In the case of a body with a separate spec, where the
1044 -- separate spec has an elaboration entity defined, this is
1045 -- where we increment the elaboration entity.
1047 if U
.Utype
= Is_Body
1048 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1049 and then not CodePeer_Mode
1052 Set_Unit_Number
(Unum_Spec
);
1054 -- The AAMP target has no notion of shared libraries, and
1055 -- there's no possibility of reelaboration, so we treat the
1056 -- the elaboration var as a flag instead of a counter and
1059 if AAMP_On_Target
then
1060 Set_String
(" := 1;");
1062 -- Otherwise (normal case), increment elaboration counter
1065 Set_String
(" := E");
1066 Set_Unit_Number
(Unum_Spec
);
1067 Set_String
(" + 1;");
1070 Write_Statement_Buffer
;
1072 -- In the special case where the target is AAMP and the unit is
1073 -- a spec with a body, the elaboration entity is initialized
1074 -- here. This is done because it's the only way to accomplish
1075 -- initialization of such entities, as there is no mechanism
1076 -- provided for initializing global variables at load time on
1079 elsif AAMP_On_Target
1080 and then U
.Utype
= Is_Spec
1081 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1084 Set_Unit_Number
(Unum_Spec
);
1085 Set_String
(" := 0;");
1086 Write_Statement_Buffer
;
1089 -- Here if elaboration code is present. If binding a library
1090 -- or if there is a non-Ada main subprogram then we generate:
1092 -- if uname_E = 0 then
1093 -- uname'elab_[spec|body];
1095 -- uname_E := uname_E + 1;
1097 -- Otherwise, elaboration routines are called unconditionally:
1099 -- uname'elab_[spec|body];
1100 -- uname_E := uname_E + 1;
1102 -- The uname_E increment is skipped if this is a separate spec,
1103 -- since it will be done when we process the body.
1105 -- In CodePeer mode, we do not generate any reference to xxx_E
1106 -- variables, only calls to 'Elab* subprograms.
1109 -- In the special case where the target is AAMP and the unit is
1110 -- a spec with a body, the elaboration entity is initialized
1111 -- here. This is done because it's the only way to accomplish
1112 -- initialization of such entities, as there is no mechanism
1113 -- provided for initializing global variables at load time on
1117 and then U
.Utype
= Is_Spec
1118 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1121 Set_Unit_Number
(Unum_Spec
);
1122 Set_String
(" := 0;");
1123 Write_Statement_Buffer
;
1128 and then (Force_Checking_Of_Elaboration_Flags
1129 or Interface_Library_Unit
1130 or not Bind_Main_Program
);
1132 if Check_Elab_Flag
then
1133 Set_String
(" if E");
1134 Set_Unit_Number
(Unum_Spec
);
1135 Set_String
(" = 0 then");
1136 Write_Statement_Buffer
;
1141 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
1143 if VM_Target
= CLI_Target
and then U
.Unit_Kind
/= 's' then
1144 if Name_Buffer
(Name_Len
) = 's' then
1145 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 12) :=
1148 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 12) :=
1152 Name_Len
:= Name_Len
+ 12;
1155 if Name_Buffer
(Name_Len
) = 's' then
1156 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1158 Name_Len
:= Name_Len
+ 8;
1160 -- Special case in CodePeer mode for subprogram bodies
1161 -- which correspond to CodePeer 'Elab_Subp_Body special
1164 elsif U
.Unit_Kind
= 's' and CodePeer_Mode
then
1165 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 13) :=
1167 Name_Len
:= Name_Len
+ 13;
1170 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1172 Name_Len
:= Name_Len
+ 8;
1176 Set_Casing
(U
.Icasing
);
1179 Write_Statement_Buffer
;
1181 if Check_Elab_Flag
then
1185 if U
.Utype
/= Is_Spec
1186 and then not CodePeer_Mode
1189 Set_Unit_Number
(Unum_Spec
);
1191 -- The AAMP target has no notion of shared libraries, and
1192 -- there's no possibility of reelaboration, so we treat the
1193 -- the elaboration var as a flag instead of a counter and
1196 if AAMP_On_Target
then
1197 Set_String
(" := 1;");
1199 -- Otherwise (normal case), increment elaboration counter
1202 Set_String
(" := E");
1203 Set_Unit_Number
(Unum_Spec
);
1204 Set_String
(" + 1;");
1207 Write_Statement_Buffer
;
1214 ------------------------
1215 -- Gen_Elab_Externals --
1216 ------------------------
1218 procedure Gen_Elab_Externals
is
1220 if CodePeer_Mode
then
1224 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1226 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
1227 U
: Unit_Record
renames Units
.Table
(Unum
);
1230 -- Check for Elab_Entity to be set for this unit
1232 if U
.Set_Elab_Entity
1234 -- Don't generate reference for stand alone library
1236 and then not U
.SAL_Interface
1238 -- Don't generate reference for predefined file in No_Run_Time
1239 -- mode, since we don't include the object files in this case
1243 and then Is_Predefined_File_Name
(U
.Sfile
))
1247 Set_Unit_Number
(Unum
);
1250 when No_VM | JVM_Target
=>
1251 Set_String
(" : Short_Integer; pragma Import (Ada, ");
1253 Set_String
(" : Short_Integer; pragma Import (CIL, ");
1257 Set_Unit_Number
(Unum
);
1258 Set_String
(", """);
1259 Get_Name_String
(U
.Uname
);
1261 -- In the case of JGNAT we need to emit an Import name that
1262 -- includes the class name (using '$' separators in the case
1263 -- of a child unit name).
1265 if VM_Target
/= No_VM
then
1266 for J
in 1 .. Name_Len
- 2 loop
1267 if VM_Target
= CLI_Target
1268 or else Name_Buffer
(J
) /= '.'
1270 Set_Char
(Name_Buffer
(J
));
1276 if VM_Target
/= CLI_Target
or else U
.Unit_Kind
= 's' then
1279 Set_String
("_pkg.");
1282 -- If the unit name is very long, then split the
1283 -- Import link name across lines using "&" (occurs
1284 -- in some C2 tests).
1286 if 2 * Name_Len
+ 60 > Hostparm
.Max_Line_Length
then
1287 Set_String
(""" &");
1288 Write_Statement_Buffer
;
1294 Set_String
("_E"");");
1295 Write_Statement_Buffer
;
1301 end Gen_Elab_Externals
;
1303 --------------------
1304 -- Gen_Elab_Order --
1305 --------------------
1307 procedure Gen_Elab_Order
is
1309 WBI
(" -- BEGIN ELABORATION ORDER");
1311 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
1312 Set_String
(" -- ");
1313 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
1315 Write_Statement_Buffer
;
1318 WBI
(" -- END ELABORATION ORDER");
1322 --------------------------
1323 -- Gen_Finalize_Library --
1324 --------------------------
1326 procedure Gen_Finalize_Library
is
1329 Uspec
: Unit_Record
;
1332 procedure Gen_Header
;
1333 -- Generate the header of the finalization routine
1339 procedure Gen_Header
is
1341 WBI
(" procedure finalize_library is");
1345 -- Start of processing for Gen_Finalize_Library
1348 if CodePeer_Mode
then
1352 for E
in reverse Elab_Order
.First
.. Elab_Order
.Last
loop
1353 Unum
:= Elab_Order
.Table
(E
);
1354 U
:= Units
.Table
(Unum
);
1356 -- Dealing with package bodies is a little complicated. In such
1357 -- cases we must retrieve the package spec since it contains the
1358 -- spec of the body finalizer.
1360 if U
.Utype
= Is_Body
then
1362 Uspec
:= Units
.Table
(Unum
);
1367 Get_Name_String
(Uspec
.Uname
);
1369 -- We are only interested in non-generic packages
1371 if U
.Unit_Kind
/= 'p' or else U
.Is_Generic
then
1374 -- That aren't an interface to a stand alone library
1376 elsif U
.SAL_Interface
then
1379 -- Case of no finalization
1381 elsif not U
.Has_Finalizer
then
1383 -- The only case in which we have to do something is if this
1384 -- is a body, with a separate spec, where the separate spec
1385 -- has a finalizer. In that case, this is where we decrement
1386 -- the elaboration entity.
1388 if U
.Utype
= Is_Body
and then Uspec
.Has_Finalizer
then
1389 if not Lib_Final_Built
then
1391 Lib_Final_Built
:= True;
1395 Set_Unit_Number
(Unum
);
1396 Set_String
(" := E");
1397 Set_Unit_Number
(Unum
);
1398 Set_String
(" - 1;");
1399 Write_Statement_Buffer
;
1403 if not Lib_Final_Built
then
1405 Lib_Final_Built
:= True;
1410 -- procedure F<Count>;
1412 Set_String
(" declare");
1413 Write_Statement_Buffer
;
1415 Set_String
(" procedure F");
1418 Write_Statement_Buffer
;
1421 -- pragma Import (CIL, F<Count>,
1422 -- "xx.yy_pkg.xx__yy__finalize_[body|spec]");
1423 -- -- for .NET targets
1425 -- pragma Import (Java, F<Count>,
1426 -- "xx$yy.xx__yy__finalize_[body|spec]");
1427 -- -- for JVM targets
1429 -- pragma Import (Ada, F<Count>,
1430 -- "xx__yy__finalize_[body|spec]");
1431 -- -- for default targets
1433 if VM_Target
= CLI_Target
then
1434 Set_String
(" pragma Import (CIL, F");
1435 elsif VM_Target
= JVM_Target
then
1436 Set_String
(" pragma Import (Java, F");
1438 Set_String
(" pragma Import (Ada, F");
1442 Set_String
(", """);
1444 -- Perform name construction
1446 -- .NET xx.yy_pkg.xx__yy__finalize
1448 if VM_Target
= CLI_Target
then
1449 Set_Unit_Name
(Mode
=> Dot
);
1450 Set_String
("_pkg.");
1452 -- JVM xx$yy.xx__yy__finalize
1454 elsif VM_Target
= JVM_Target
then
1455 Set_Unit_Name
(Mode
=> Dollar_Sign
);
1459 -- Default xx__yy__finalize
1462 Set_String
("__finalize_");
1464 -- Package spec processing
1466 if U
.Utype
= Is_Spec
1467 or else U
.Utype
= Is_Spec_Only
1469 Set_String
("spec");
1471 -- Package body processing
1474 Set_String
("body");
1477 Set_String
(""");");
1478 Write_Statement_Buffer
;
1480 -- If binding a library or if there is a non-Ada main subprogram
1481 -- then we generate:
1484 -- uname_E := uname_E - 1;
1485 -- if uname_E = 0 then
1490 -- Otherwise, finalization routines are called unconditionally:
1493 -- uname_E := uname_E - 1;
1497 -- The uname_E decrement is skipped if this is a separate spec,
1498 -- since it will be done when we process the body.
1502 if U
.Utype
/= Is_Spec
then
1504 Set_Unit_Number
(Unum
);
1505 Set_String
(" := E");
1506 Set_Unit_Number
(Unum
);
1507 Set_String
(" - 1;");
1508 Write_Statement_Buffer
;
1511 if Interface_Library_Unit
or not Bind_Main_Program
then
1512 Set_String
(" if E");
1513 Set_Unit_Number
(Unum
);
1514 Set_String
(" = 0 then");
1515 Write_Statement_Buffer
;
1522 Write_Statement_Buffer
;
1524 if Interface_Library_Unit
or not Bind_Main_Program
then
1534 if Lib_Final_Built
then
1536 -- It is possible that the finalization of a library-level object
1537 -- raised an exception. In that case import the actual exception
1538 -- and the routine necessary to raise it.
1540 if VM_Target
= No_VM
then
1542 WBI
(" procedure Reraise_Library_Exception_If_Any;");
1544 Set_String
(" pragma Import (Ada, ");
1545 Set_String
("Reraise_Library_Exception_If_Any, ");
1546 Set_String
("""__gnat_reraise_library_exception_if_any"");");
1547 Write_Statement_Buffer
;
1550 WBI
(" Reraise_Library_Exception_If_Any;");
1553 -- VM-specific code, use regular Ada to produce the desired behavior
1556 WBI
(" if System.Soft_Links.Library_Exception_Set then");
1558 Set_String
(" Ada.Exceptions.Reraise_Occurrence (");
1559 Set_String
("System.Soft_Links.Library_Exception);");
1560 Write_Statement_Buffer
;
1565 WBI
(" end finalize_library;");
1568 end Gen_Finalize_Library
;
1574 procedure Gen_Main
is
1576 if not No_Main_Subprogram
then
1578 -- To call the main program, we declare it using a pragma Import
1579 -- Ada with the right link name.
1581 -- It might seem more obvious to "with" the main program, and call
1582 -- it in the normal Ada manner. We do not do this for three
1585 -- 1. It is more efficient not to recompile the main program
1586 -- 2. We are not entitled to assume the source is accessible
1587 -- 3. We don't know what options to use to compile it
1589 -- It is really reason 3 that is most critical (indeed we used
1590 -- to generate the "with", but several regression tests failed).
1592 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1593 WBI
(" function Ada_Main_Program return Integer;");
1595 WBI
(" procedure Ada_Main_Program;");
1598 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1599 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1600 Set_Main_Program_Name
;
1601 Set_String
(""");");
1603 Write_Statement_Buffer
;
1606 -- For CodePeer, declare a wrapper for the user-defined main program
1608 if CodePeer_Mode
then
1609 Gen_CodePeer_Wrapper
;
1613 if Exit_Status_Supported_On_Target
then
1614 Set_String
(" function ");
1616 Set_String
(" procedure ");
1619 Set_String
(Get_Main_Name
);
1621 if Command_Line_Args_On_Target
then
1622 Write_Statement_Buffer
;
1623 WBI
(" (argc : Integer;");
1624 WBI
(" argv : System.Address;");
1625 WBI
(" envp : System.Address)");
1627 if Exit_Status_Supported_On_Target
then
1628 WBI
(" return Integer");
1634 if Exit_Status_Supported_On_Target
then
1635 Set_String
(" return Integer is");
1640 Write_Statement_Buffer
;
1643 if Opt
.Default_Exit_Status
/= 0
1644 and then Bind_Main_Program
1645 and then not Configurable_Run_Time_Mode
1647 WBI
(" procedure Set_Exit_Status (Status : Integer);");
1648 WBI
(" pragma Import (C, Set_Exit_Status, " &
1649 """__gnat_set_exit_status"");");
1653 -- Initialize and Finalize
1655 if not CodePeer_Mode
1656 and then not Cumulative_Restrictions
.Set
(No_Finalization
)
1658 WBI
(" procedure Initialize (Addr : System.Address);");
1659 WBI
(" pragma Import (C, Initialize, ""__gnat_initialize"");");
1661 WBI
(" procedure Finalize;");
1662 WBI
(" pragma Import (C, Finalize, ""__gnat_finalize"");");
1665 -- If we want to analyze the stack, we must import corresponding symbols
1667 if Dynamic_Stack_Measurement
then
1669 WBI
(" procedure Output_Results;");
1670 WBI
(" pragma Import (C, Output_Results, " &
1671 """__gnat_stack_usage_output_results"");");
1675 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1676 WBI
(" pragma Import (C, Initialize_Stack_Analysis, " &
1677 """__gnat_stack_usage_initialize"");");
1680 -- Deal with declarations for main program case
1682 if not No_Main_Subprogram
then
1683 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1684 WBI
(" Result : Integer;");
1688 if Bind_Main_Program
1689 and not Suppress_Standard_Library_On_Target
1690 and not CodePeer_Mode
1692 WBI
(" SEH : aliased array (1 .. 2) of Integer;");
1697 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1698 -- not referenced elsewhere in the generated program, but is needed
1699 -- by the debugger (that's why it is generated in the first place).
1700 -- The reference stops Ada_Main_Program_Name from being optimized
1701 -- away by smart linkers, such as the AiX linker.
1703 -- Because this variable is unused, we make this variable "aliased"
1704 -- with a pragma Volatile in order to tell the compiler to preserve
1705 -- this variable at any level of optimization.
1707 if Bind_Main_Program
and not CodePeer_Mode
then
1708 WBI
(" Ensure_Reference : aliased System.Address := " &
1709 "Ada_Main_Program_Name'Address;");
1710 WBI
(" pragma Volatile (Ensure_Reference);");
1716 -- Acquire command line arguments if present on target
1718 if CodePeer_Mode
then
1721 elsif Command_Line_Args_On_Target
then
1722 WBI
(" gnat_argc := argc;");
1723 WBI
(" gnat_argv := argv;");
1724 WBI
(" gnat_envp := envp;");
1727 -- If configurable run time and no command line args, then nothing
1728 -- needs to be done since the gnat_argc/argv/envp variables are
1729 -- suppressed in this case.
1731 elsif Configurable_Run_Time_On_Target
then
1734 -- Otherwise set dummy values (to be filled in by some other unit?)
1737 WBI
(" gnat_argc := 0;");
1738 WBI
(" gnat_argv := System.Null_Address;");
1739 WBI
(" gnat_envp := System.Null_Address;");
1742 if Opt
.Default_Exit_Status
/= 0
1743 and then Bind_Main_Program
1744 and then not Configurable_Run_Time_Mode
1746 Set_String
(" Set_Exit_Status (");
1747 Set_Int
(Opt
.Default_Exit_Status
);
1749 Write_Statement_Buffer
;
1752 if Dynamic_Stack_Measurement
then
1753 Set_String
(" Initialize_Stack_Analysis (");
1754 Set_Int
(Dynamic_Stack_Measurement_Array_Size
);
1756 Write_Statement_Buffer
;
1759 if not Cumulative_Restrictions
.Set
(No_Finalization
)
1760 and then not CodePeer_Mode
1762 if not No_Main_Subprogram
1763 and then Bind_Main_Program
1764 and then not Suppress_Standard_Library_On_Target
1766 WBI
(" Initialize (SEH'Address);");
1768 WBI
(" Initialize (System.Null_Address);");
1772 WBI
(" " & Ada_Init_Name
.all & ";");
1774 if not No_Main_Subprogram
then
1775 if CodePeer_Mode
then
1776 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1777 WBI
(" " & CodePeer_Wrapper_Name
& ";");
1779 WBI
(" Result := " & CodePeer_Wrapper_Name
& ";");
1782 elsif ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1783 WBI
(" Ada_Main_Program;");
1786 WBI
(" Result := Ada_Main_Program;");
1790 -- Adafinal call is skipped if no finalization
1792 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
1796 -- Prints the result of static stack analysis
1798 if Dynamic_Stack_Measurement
then
1799 WBI
(" Output_Results;");
1802 -- Finalize is only called if we have a run time
1804 if not Cumulative_Restrictions
.Set
(No_Finalization
)
1805 and then not CodePeer_Mode
1812 if Exit_Status_Supported_On_Target
then
1813 if No_Main_Subprogram
1814 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
1816 WBI
(" return (gnat_exit_status);");
1818 WBI
(" return (Result);");
1826 ------------------------------
1827 -- Gen_Object_Files_Options --
1828 ------------------------------
1830 procedure Gen_Object_Files_Options
is
1832 -- This keeps track of the position in the sorted set of entries
1833 -- in the Linker_Options table of where the first entry from an
1834 -- internal file appears.
1836 Linker_Option_List_Started
: Boolean := False;
1837 -- Set to True when "LINKER OPTION LIST" is displayed
1839 procedure Write_Linker_Option
;
1840 -- Write binder info linker option
1842 -------------------------
1843 -- Write_Linker_Option --
1844 -------------------------
1846 procedure Write_Linker_Option
is
1851 -- Loop through string, breaking at null's
1854 while Start
< Name_Len
loop
1856 -- Find null ending this section
1859 while Name_Buffer
(Stop
) /= ASCII
.NUL
1860 and then Stop
<= Name_Len
loop
1864 -- Process section if non-null
1866 if Stop
> Start
then
1867 if Output_Linker_Option_List
then
1868 if not Zero_Formatting
then
1869 if not Linker_Option_List_Started
then
1870 Linker_Option_List_Started
:= True;
1872 Write_Str
(" LINKER OPTION LIST");
1880 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
1883 WBI
(" -- " & Name_Buffer
(Start
.. Stop
- 1));
1888 end Write_Linker_Option
;
1890 -- Start of processing for Gen_Object_Files_Options
1893 WBI
("-- BEGIN Object file/option list");
1895 if Object_List_Filename
/= null then
1896 Set_List_File
(Object_List_Filename
.all);
1899 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1901 -- If not spec that has an associated body, then generate a comment
1902 -- giving the name of the corresponding object file.
1904 if not Units
.Table
(Elab_Order
.Table
(E
)).SAL_Interface
1905 and then Units
.Table
(Elab_Order
.Table
(E
)).Utype
/= Is_Spec
1909 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Ofile_Full_Name
);
1911 -- If the presence of an object file is necessary or if it exists,
1914 if not Hostparm
.Exclude_Missing_Objects
1916 System
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
1918 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
1920 if Output_Object_List
then
1921 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1928 if Object_List_Filename
/= null then
1932 -- Add a "-Ldir" for each directory in the object path
1933 if VM_Target
/= CLI_Target
then
1934 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
1936 Dir
: constant String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
1939 Add_Str_To_Name_Buffer
("-L");
1940 Add_Str_To_Name_Buffer
(Dir
.all);
1941 Write_Linker_Option
;
1946 -- Sort linker options
1948 -- This sort accomplishes two important purposes:
1950 -- a) All application files are sorted to the front, and all GNAT
1951 -- internal files are sorted to the end. This results in a well
1952 -- defined dividing line between the two sets of files, for the
1953 -- purpose of inserting certain standard library references into
1954 -- the linker arguments list.
1956 -- b) Given two different units, we sort the linker options so that
1957 -- those from a unit earlier in the elaboration order comes later
1958 -- in the list. This is a heuristic designed to create a more
1959 -- friendly order of linker options when the operations appear in
1960 -- separate units. The idea is that if unit A must be elaborated
1961 -- before unit B, then it is more likely that B references
1962 -- libraries included by A, than vice versa, so we want libraries
1963 -- included by A to come after libraries included by B.
1965 -- These two criteria are implemented by function Lt_Linker_Option. Note
1966 -- that a special case of b) is that specs are elaborated before bodies,
1967 -- so linker options from specs come after linker options for bodies,
1968 -- and again, the assumption is that libraries used by the body are more
1969 -- likely to reference libraries used by the spec, than vice versa.
1972 (Linker_Options
.Last
,
1973 Move_Linker_Option
'Access,
1974 Lt_Linker_Option
'Access);
1976 -- Write user linker options, i.e. the set of linker options that come
1977 -- from all files other than GNAT internal files, Lgnat is left set to
1978 -- point to the first entry from a GNAT internal file, or past the end
1979 -- of the entries if there are no internal files.
1981 Lgnat
:= Linker_Options
.Last
+ 1;
1983 for J
in 1 .. Linker_Options
.Last
loop
1984 if not Linker_Options
.Table
(J
).Internal_File
then
1985 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
1986 Write_Linker_Option
;
1993 -- Now we insert standard linker options that must appear after the
1994 -- entries from user files, and before the entries from GNAT run-time
1995 -- files. The reason for this decision is that libraries referenced
1996 -- by internal routines may reference these standard library entries.
1998 -- Note that we do not insert anything when pragma No_Run_Time has been
1999 -- specified or when the standard libraries are not to be used,
2000 -- otherwise on some platforms, such as VMS, we may get duplicate
2001 -- symbols when linking.
2003 if not (Opt
.No_Run_Time_Mode
or else Opt
.No_Stdlib
) then
2006 if Opt
.Shared_Libgnat
then
2007 Add_Str_To_Name_Buffer
("-shared");
2009 Add_Str_To_Name_Buffer
("-static");
2012 -- Write directly to avoid -K output (why???)
2014 WBI
(" -- " & Name_Buffer
(1 .. Name_Len
));
2016 if With_DECGNAT
then
2019 if Opt
.Shared_Libgnat
then
2020 Add_Str_To_Name_Buffer
(Shared_Lib
("decgnat"));
2022 Add_Str_To_Name_Buffer
("-ldecgnat");
2025 Write_Linker_Option
;
2031 if Opt
.Shared_Libgnat
then
2032 Add_Str_To_Name_Buffer
(Shared_Lib
("gnarl"));
2034 Add_Str_To_Name_Buffer
("-lgnarl");
2037 Write_Linker_Option
;
2042 if Opt
.Shared_Libgnat
then
2043 Add_Str_To_Name_Buffer
(Shared_Lib
("gnat"));
2045 Add_Str_To_Name_Buffer
("-lgnat");
2048 Write_Linker_Option
;
2051 -- Write linker options from all internal files
2053 for J
in Lgnat
.. Linker_Options
.Last
loop
2054 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2055 Write_Linker_Option
;
2058 if Output_Linker_Option_List
and then not Zero_Formatting
then
2062 WBI
("-- END Object file/option list ");
2063 end Gen_Object_Files_Options
;
2065 ---------------------
2066 -- Gen_Output_File --
2067 ---------------------
2069 procedure Gen_Output_File
(Filename
: String) is
2071 -- Acquire settings for Interrupt_State pragmas
2073 Set_IS_Pragma_Table
;
2075 -- Acquire settings for Priority_Specific_Dispatching pragma
2077 Set_PSD_Pragma_Table
;
2079 -- For JGNAT the main program is already generated by the compiler
2081 if VM_Target
= JVM_Target
then
2082 Bind_Main_Program
:= False;
2085 -- Override time slice value if -T switch is set
2087 if Time_Slice_Set
then
2088 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
2091 -- Count number of elaboration calls
2093 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
2094 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
2097 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
2101 -- Generate output file in appropriate language
2103 Check_System_Restrictions_Used
;
2104 Check_Dispatching_Domains_Used
;
2106 Gen_Output_File_Ada
(Filename
);
2107 end Gen_Output_File
;
2109 -------------------------
2110 -- Gen_Output_File_Ada --
2111 -------------------------
2113 procedure Gen_Output_File_Ada
(Filename
: String) is
2115 Ada_Main
: constant String := Get_Ada_Main_Name
;
2116 -- Name to be used for generated Ada main program. See the body of
2117 -- function Get_Ada_Main_Name for details on the form of the name.
2119 Needs_Library_Finalization
: constant Boolean :=
2120 not Configurable_Run_Time_On_Target
and then Has_Finalizer
;
2121 -- For restricted run-time libraries (ZFP and Ravenscar) tasks are
2122 -- non-terminating, so we do not want finalization.
2125 -- Name of generated bind file (spec)
2128 -- Name of generated bind file (body)
2131 -- Create spec first
2133 Create_Binder_Output
(Filename
, 's', Bfiles
);
2135 -- We always compile the binder file in Ada 95 mode so that we properly
2136 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2137 -- of the Ada 2005 or Ada 2012 constructs are needed by the binder file.
2139 WBI
("pragma Ada_95;");
2141 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2142 -- then we need to make sure that the binder program is compiled with
2143 -- the same restriction, so that no exception tables are generated.
2145 if Cumulative_Restrictions
.Set
(No_Exception_Handlers
) then
2146 WBI
("pragma Restrictions (No_Exception_Handlers);");
2149 -- Same processing for Restrictions (No_Exception_Propagation)
2151 if Cumulative_Restrictions
.Set
(No_Exception_Propagation
) then
2152 WBI
("pragma Restrictions (No_Exception_Propagation);");
2155 -- Same processing for pragma No_Run_Time
2157 if No_Run_Time_Mode
then
2158 WBI
("pragma No_Run_Time;");
2161 -- Generate with of System so we can reference System.Address
2163 WBI
("with System;");
2165 -- Generate with of System.Initialize_Scalars if active
2167 if Initialize_Scalars_Used
then
2168 WBI
("with System.Scalar_Values;");
2171 -- Generate with of System.Secondary_Stack if active
2173 if Sec_Stack_Used
and then Default_Sec_Stack_Size
/= -1 then
2174 WBI
("with System.Secondary_Stack;");
2177 Resolve_Binder_Options
;
2179 -- Usually, adafinal is called using a pragma Import C. Since Import C
2180 -- doesn't have the same semantics for VMs or CodePeer use standard Ada.
2182 if not Suppress_Standard_Library_On_Target
then
2183 if CodePeer_Mode
then
2184 WBI
("with System.Standard_Library;");
2185 elsif VM_Target
/= No_VM
then
2186 WBI
("with System.Soft_Links;");
2187 WBI
("with System.Standard_Library;");
2191 WBI
("package " & Ada_Main
& " is");
2192 WBI
(" pragma Warnings (Off);");
2194 -- Main program case
2196 if Bind_Main_Program
then
2197 if VM_Target
= No_VM
then
2199 -- Generate argc/argv stuff unless suppressed
2201 if Command_Line_Args_On_Target
2202 or not Configurable_Run_Time_On_Target
2205 WBI
(" gnat_argc : Integer;");
2206 WBI
(" gnat_argv : System.Address;");
2207 WBI
(" gnat_envp : System.Address;");
2209 -- If the standard library is not suppressed, these variables
2210 -- are in the run-time data area for easy run time access.
2212 if not Suppress_Standard_Library_On_Target
then
2214 WBI
(" pragma Import (C, gnat_argc);");
2215 WBI
(" pragma Import (C, gnat_argv);");
2216 WBI
(" pragma Import (C, gnat_envp);");
2220 -- Define exit status. Again in normal mode, this is in the
2221 -- run-time library, and is initialized there, but in the
2222 -- configurable runtime case, the variable is declared and
2223 -- initialized in this file.
2227 if Configurable_Run_Time_Mode
then
2228 if Exit_Status_Supported_On_Target
then
2229 WBI
(" gnat_exit_status : Integer := 0;");
2233 WBI
(" gnat_exit_status : Integer;");
2234 WBI
(" pragma Import (C, gnat_exit_status);");
2238 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2239 -- the main program. Otherwise, it can lead under some circumstances
2240 -- to a symbol duplication during the link (for instance when a C
2241 -- program uses two Ada libraries). Also zero terminate the string
2242 -- so that its end can be found reliably at run time.
2245 WBI
(" GNAT_Version : constant String :=");
2246 WBI
(" """ & Ver_Prefix
&
2247 Gnat_Version_String
&
2249 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2252 Set_String
(" Ada_Main_Program_Name : constant String := """);
2253 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2255 if VM_Target
= No_VM
then
2256 Set_Main_Program_Name
;
2257 Set_String
(""" & ASCII.NUL;");
2259 Set_String
(Name_Buffer
(1 .. Name_Len
- 2) & """;");
2262 Write_Statement_Buffer
;
2265 (" pragma Export (C, Ada_Main_Program_Name, " &
2266 """__gnat_ada_main_program_name"");");
2270 WBI
(" procedure " & Ada_Init_Name
.all & ";");
2271 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
2272 Ada_Init_Name
.all & """);");
2274 -- If -a has been specified use pragma Linker_Constructor for the init
2275 -- procedure and pragma Linker_Destructor for the final procedure.
2277 if Use_Pragma_Linker_Constructor
then
2278 WBI
(" pragma Linker_Constructor (" & Ada_Init_Name
.all & ");");
2281 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2283 WBI
(" procedure " & Ada_Final_Name
.all & ";");
2284 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
2285 Ada_Final_Name
.all & """);");
2287 if Use_Pragma_Linker_Constructor
then
2288 WBI
(" pragma Linker_Destructor (" & Ada_Final_Name
.all & ");");
2292 if Bind_Main_Program
and then VM_Target
= No_VM
then
2296 if Exit_Status_Supported_On_Target
then
2297 Set_String
(" function ");
2299 Set_String
(" procedure ");
2302 Set_String
(Get_Main_Name
);
2304 -- Generate argument list if present
2306 if Command_Line_Args_On_Target
then
2307 Write_Statement_Buffer
;
2308 WBI
(" (argc : Integer;");
2309 WBI
(" argv : System.Address;");
2311 (" envp : System.Address)");
2313 if Exit_Status_Supported_On_Target
then
2314 Write_Statement_Buffer
;
2315 WBI
(" return Integer;");
2317 Write_Statement_Buffer
(";");
2321 if Exit_Status_Supported_On_Target
then
2322 Write_Statement_Buffer
(" return Integer;");
2324 Write_Statement_Buffer
(";");
2328 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
2329 Get_Main_Name
& """);");
2338 WBI
("end " & Ada_Main
& ";");
2339 Close_Binder_Output
;
2341 -- Prepare to write body
2343 Create_Binder_Output
(Filename
, 'b', Bfileb
);
2345 -- We always compile the binder file in Ada 95 mode so that we properly
2346 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2347 -- of the Ada 2005/2012 constructs are needed by the binder file.
2349 WBI
("pragma Ada_95;");
2351 -- Output Source_File_Name pragmas which look like
2353 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2354 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2356 -- where sss/bbb are the spec/body file names respectively
2358 Get_Name_String
(Bfiles
);
2359 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2361 WBI
("pragma Source_File_Name (" &
2363 ", Spec_File_Name => """ &
2364 Name_Buffer
(1 .. Name_Len
+ 3));
2366 Get_Name_String
(Bfileb
);
2367 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2369 WBI
("pragma Source_File_Name (" &
2371 ", Body_File_Name => """ &
2372 Name_Buffer
(1 .. Name_Len
+ 3));
2374 -- Generate with of System.Restrictions to initialize
2375 -- Run_Time_Restrictions.
2377 if System_Restrictions_Used
2378 and not Suppress_Standard_Library_On_Target
2381 WBI
("with System.Restrictions;");
2384 if Needs_Library_Finalization
then
2385 WBI
("with Ada.Exceptions;");
2389 WBI
("package body " & Ada_Main
& " is");
2390 WBI
(" pragma Warnings (Off);");
2393 -- Generate externals for elaboration entities
2397 if not CodePeer_Mode
then
2398 if not Suppress_Standard_Library_On_Target
then
2400 -- Generate Priority_Specific_Dispatching pragma string
2403 (" Local_Priority_Specific_Dispatching : " &
2404 "constant String := """);
2406 for J
in 0 .. PSD_Pragma_Settings
.Last
loop
2407 Set_Char
(PSD_Pragma_Settings
.Table
(J
));
2411 Write_Statement_Buffer
;
2413 -- Generate Interrupt_State pragma string
2415 Set_String
(" Local_Interrupt_States : constant String := """);
2417 for J
in 0 .. IS_Pragma_Settings
.Last
loop
2418 Set_Char
(IS_Pragma_Settings
.Table
(J
));
2422 Write_Statement_Buffer
;
2426 -- The B.1 (39) implementation advice says that the adainit/adafinal
2427 -- routines should be idempotent. Generate a flag to ensure that.
2429 WBI
(" Is_Elaborated : Boolean := False;");
2433 -- Generate the adafinal routine unless there is no finalization to do
2435 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2436 if Needs_Library_Finalization
then
2437 Gen_Finalize_Library
;
2445 if Bind_Main_Program
and then VM_Target
= No_VM
then
2449 -- Output object file list and the Ada body is complete
2451 Gen_Object_Files_Options
;
2454 WBI
("end " & Ada_Main
& ";");
2456 Close_Binder_Output
;
2457 end Gen_Output_File_Ada
;
2459 ----------------------
2460 -- Gen_Restrictions --
2461 ----------------------
2463 procedure Gen_Restrictions
is
2467 if Suppress_Standard_Library_On_Target
2468 or not System_Restrictions_Used
2473 WBI
(" System.Restrictions.Run_Time_Restrictions :=");
2479 for J
in Cumulative_Restrictions
.Set
'Range loop
2480 Set_Boolean
(Cumulative_Restrictions
.Set
(J
));
2484 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2485 Write_Statement_Buffer
;
2491 Set_String_Replace
("),");
2492 Write_Statement_Buffer
;
2493 Set_String
(" Value => (");
2495 for J
in Cumulative_Restrictions
.Value
'Range loop
2496 Set_Int
(Int
(Cumulative_Restrictions
.Value
(J
)));
2500 Set_String_Replace
("),");
2501 Write_Statement_Buffer
;
2502 WBI
(" Violated =>");
2506 for J
in Cumulative_Restrictions
.Violated
'Range loop
2507 Set_Boolean
(Cumulative_Restrictions
.Violated
(J
));
2511 if J
/= Cumulative_Restrictions
.Set
'Last and then Count
= 8 then
2512 Write_Statement_Buffer
;
2518 Set_String_Replace
("),");
2519 Write_Statement_Buffer
;
2520 Set_String
(" Count => (");
2522 for J
in Cumulative_Restrictions
.Count
'Range loop
2523 Set_Int
(Int
(Cumulative_Restrictions
.Count
(J
)));
2527 Set_String_Replace
("),");
2528 Write_Statement_Buffer
;
2529 Set_String
(" Unknown => (");
2531 for J
in Cumulative_Restrictions
.Unknown
'Range loop
2532 Set_Boolean
(Cumulative_Restrictions
.Unknown
(J
));
2536 Set_String_Replace
("))");
2538 Write_Statement_Buffer
;
2539 end Gen_Restrictions
;
2545 -- This routine generates lines such as:
2547 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2548 -- pragma Export (C, unnnnn, unam);
2550 -- for each unit, where unam is the unit name suffixed by either B or S for
2551 -- body or spec, with dots replaced by double underscores, and hhhhhhhh is
2552 -- the version number, and nnnnn is a 5-digits serial number.
2554 procedure Gen_Versions
is
2555 Ubuf
: String (1 .. 6) := "u00000";
2557 procedure Increment_Ubuf
;
2558 -- Little procedure to increment the serial number
2560 --------------------
2561 -- Increment_Ubuf --
2562 --------------------
2564 procedure Increment_Ubuf
is
2566 for J
in reverse Ubuf
'Range loop
2567 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
2568 exit when Ubuf
(J
) <= '9';
2573 -- Start of processing for Gen_Versions
2578 WBI
(" type Version_32 is mod 2 ** 32;");
2579 for U
in Units
.First
.. Units
.Last
loop
2580 if not Units
.Table
(U
).SAL_Interface
2582 (not Bind_For_Library
or else Units
.Table
(U
).Directly_Scanned
)
2585 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
2586 Units
.Table
(U
).Version
& "#;");
2587 Set_String
(" pragma Export (C, ");
2589 Set_String
(", """);
2591 Get_Name_String
(Units
.Table
(U
).Uname
);
2593 for K
in 1 .. Name_Len
loop
2594 if Name_Buffer
(K
) = '.' then
2598 elsif Name_Buffer
(K
) = '%' then
2602 Set_Char
(Name_Buffer
(K
));
2606 if Name_Buffer
(Name_Len
) = 's' then
2612 Set_String
(""");");
2613 Write_Statement_Buffer
;
2618 ------------------------
2619 -- Get_Main_Unit_Name --
2620 ------------------------
2622 function Get_Main_Unit_Name
(S
: String) return String is
2623 Result
: String := S
;
2626 for J
in S
'Range loop
2627 if Result
(J
) = '.' then
2633 end Get_Main_Unit_Name
;
2635 -----------------------
2636 -- Get_Ada_Main_Name --
2637 -----------------------
2639 function Get_Ada_Main_Name
return String is
2640 Suffix
: constant String := "_00";
2641 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
2642 Opt
.Ada_Main_Name
.all & Suffix
;
2646 -- The main program generated by JGNAT expects a package called
2647 -- ada_<main procedure>.
2648 if VM_Target
/= No_VM
then
2649 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2650 return "ada_" & Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
- 2));
2653 -- For CodePeer, we want reproducible names (independent of other
2654 -- mains that may or may not be present) that don't collide
2655 -- when analyzing multiple mains and which are easily recognizable
2656 -- as "ada_main" names.
2657 if CodePeer_Mode
then
2658 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2659 return "ada_main_for_" &
2660 Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
- 2));
2663 -- This loop tries the following possibilities in order
2669 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2670 -- it is set to 'ada_main'.
2672 for J
in 0 .. 99 loop
2674 Nlen
:= Name
'Length - Suffix
'Length;
2676 Nlen
:= Name
'Length;
2677 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
2678 Name
(Name
'Last - 1) :=
2679 Character'Val (J
/ 10 + Character'Pos ('0'));
2682 for K
in ALIs
.First
.. ALIs
.Last
loop
2683 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
2685 -- Get unit name, removing %b or %e at end
2687 Get_Name_String
(Units
.Table
(L
).Uname
);
2688 Name_Len
:= Name_Len
- 2;
2690 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
2696 return Name
(1 .. Nlen
);
2702 -- If we fall through, just use a peculiar unlikely name
2704 return ("Qwertyuiop");
2705 end Get_Ada_Main_Name
;
2711 function Get_Main_Name
return String is
2713 -- Explicit name given with -M switch
2715 if Bind_Alternate_Main_Name
then
2716 return Alternate_Main_Name
.all;
2718 -- Case of main program name to be used directly
2720 elsif Use_Ada_Main_Program_Name_On_Target
then
2722 -- Get main program name
2724 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2726 -- If this is a child name, return only the name of the child, since
2727 -- we can't have dots in a nested program name. Note that we do not
2728 -- include the %b at the end of the unit name.
2730 for J
in reverse 1 .. Name_Len
- 2 loop
2731 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
2732 return Name_Buffer
(J
.. Name_Len
- 2);
2736 raise Program_Error
; -- impossible exit
2738 -- Case where "main" is to be used as default
2745 ---------------------
2746 -- Get_WC_Encoding --
2747 ---------------------
2749 function Get_WC_Encoding
return Character is
2751 -- If encoding method specified by -W switch, then return it
2753 if Wide_Character_Encoding_Method_Specified
then
2754 return WC_Encoding_Letters
(Wide_Character_Encoding_Method
);
2756 -- If no main program, and not specified, set brackets, we really have
2757 -- no better choice. If some other encoding is required when there is
2758 -- no main, it must be set explicitly using -Wx.
2760 -- Note: if the ALI file always passed the wide character encoding of
2761 -- every file, then we could use the encoding of the initial specified
2762 -- file, but this information is passed only for potential main
2763 -- programs. We could fix this sometime, but it is a very minor point
2764 -- (wide character default encoding for [Wide_[Wide_]Text_IO when there
2765 -- is no main program).
2767 elsif No_Main_Subprogram
then
2770 -- Otherwise if there is a main program, take encoding from it
2773 return ALIs
.Table
(ALIs
.First
).WC_Encoding
;
2775 end Get_WC_Encoding
;
2781 function Has_Finalizer
return Boolean is
2786 for E
in reverse Elab_Order
.First
.. Elab_Order
.Last
loop
2787 Unum
:= Elab_Order
.Table
(E
);
2788 U
:= Units
.Table
(Unum
);
2790 -- We are only interested in non-generic packages
2792 if U
.Unit_Kind
= 'p'
2793 and then U
.Has_Finalizer
2794 and then not U
.Is_Generic
2795 and then not U
.No_Elab
2804 ----------------------
2805 -- Lt_Linker_Option --
2806 ----------------------
2808 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean is
2810 -- Sort internal files last
2812 if Linker_Options
.Table
(Op1
).Internal_File
2814 Linker_Options
.Table
(Op2
).Internal_File
2816 -- Note: following test uses False < True
2818 return Linker_Options
.Table
(Op1
).Internal_File
2820 Linker_Options
.Table
(Op2
).Internal_File
;
2822 -- If both internal or both non-internal, sort according to the
2823 -- elaboration position. A unit that is elaborated later should come
2824 -- earlier in the linker options list.
2827 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
2829 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
2832 end Lt_Linker_Option
;
2834 ------------------------
2835 -- Move_Linker_Option --
2836 ------------------------
2838 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
2840 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
2841 end Move_Linker_Option
;
2843 ----------------------------
2844 -- Resolve_Binder_Options --
2845 ----------------------------
2847 procedure Resolve_Binder_Options
is
2849 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
2850 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
2852 -- This is not a perfect approach, but is the current protocol
2853 -- between the run-time and the binder to indicate that tasking is
2854 -- used: system.os_interface should always be used by any tasking
2857 if Name_Buffer
(1 .. 19) = "system.os_interface" then
2861 -- Ditto for declib and the "dec" package
2863 if OpenVMS_On_Target
and then Name_Buffer
(1 .. 5) = "dec%s" then
2864 With_DECGNAT
:= True;
2867 end Resolve_Binder_Options
;
2873 procedure Set_Boolean
(B
: Boolean) is
2874 True_Str
: constant String := "True";
2875 False_Str
: constant String := "False";
2878 Statement_Buffer
(Last
+ 1 .. Last
+ True_Str
'Length) := True_Str
;
2879 Last
:= Last
+ True_Str
'Length;
2881 Statement_Buffer
(Last
+ 1 .. Last
+ False_Str
'Length) := False_Str
;
2882 Last
:= Last
+ False_Str
'Length;
2890 procedure Set_Char
(C
: Character) is
2893 Statement_Buffer
(Last
) := C
;
2900 procedure Set_Int
(N
: Int
) is
2912 Statement_Buffer
(Last
) :=
2913 Character'Val (N
mod 10 + Character'Pos ('0'));
2917 -------------------------
2918 -- Set_IS_Pragma_Table --
2919 -------------------------
2921 procedure Set_IS_Pragma_Table
is
2923 for F
in ALIs
.First
.. ALIs
.Last
loop
2924 for K
in ALIs
.Table
(F
).First_Interrupt_State
..
2925 ALIs
.Table
(F
).Last_Interrupt_State
2928 Inum
: constant Int
:=
2929 Interrupt_States
.Table
(K
).Interrupt_Id
;
2930 Stat
: constant Character :=
2931 Interrupt_States
.Table
(K
).Interrupt_State
;
2934 while IS_Pragma_Settings
.Last
< Inum
loop
2935 IS_Pragma_Settings
.Append
('n');
2938 IS_Pragma_Settings
.Table
(Inum
) := Stat
;
2942 end Set_IS_Pragma_Table
;
2944 ---------------------------
2945 -- Set_Main_Program_Name --
2946 ---------------------------
2948 procedure Set_Main_Program_Name
is
2950 -- Note that name has %b on the end which we ignore
2952 -- First we output the initial _ada_ since we know that the main
2953 -- program is a library level subprogram.
2955 Set_String
("_ada_");
2957 -- Copy name, changing dots to double underscores
2959 for J
in 1 .. Name_Len
- 2 loop
2960 if Name_Buffer
(J
) = '.' then
2963 Set_Char
(Name_Buffer
(J
));
2966 end Set_Main_Program_Name
;
2968 ---------------------
2969 -- Set_Name_Buffer --
2970 ---------------------
2972 procedure Set_Name_Buffer
is
2974 for J
in 1 .. Name_Len
loop
2975 Set_Char
(Name_Buffer
(J
));
2977 end Set_Name_Buffer
;
2979 -------------------------
2980 -- Set_PSD_Pragma_Table --
2981 -------------------------
2983 procedure Set_PSD_Pragma_Table
is
2985 for F
in ALIs
.First
.. ALIs
.Last
loop
2986 for K
in ALIs
.Table
(F
).First_Specific_Dispatching
..
2987 ALIs
.Table
(F
).Last_Specific_Dispatching
2990 DTK
: Specific_Dispatching_Record
2991 renames Specific_Dispatching
.Table
(K
);
2994 while PSD_Pragma_Settings
.Last
< DTK
.Last_Priority
loop
2995 PSD_Pragma_Settings
.Append
('F');
2998 for Prio
in DTK
.First_Priority
.. DTK
.Last_Priority
loop
2999 PSD_Pragma_Settings
.Table
(Prio
) := DTK
.Dispatching_Policy
;
3004 end Set_PSD_Pragma_Table
;
3010 procedure Set_String
(S
: String) is
3012 Statement_Buffer
(Last
+ 1 .. Last
+ S
'Length) := S
;
3013 Last
:= Last
+ S
'Length;
3016 ------------------------
3017 -- Set_String_Replace --
3018 ------------------------
3020 procedure Set_String_Replace
(S
: String) is
3022 Statement_Buffer
(Last
- S
'Length + 1 .. Last
) := S
;
3023 end Set_String_Replace
;
3029 procedure Set_Unit_Name
(Mode
: Qualification_Mode
:= Double_Underscores
) is
3031 for J
in 1 .. Name_Len
- 2 loop
3032 if Name_Buffer
(J
) = '.' then
3033 if Mode
= Double_Underscores
then
3035 elsif Mode
= Dot
then
3041 Set_Char
(Name_Buffer
(J
));
3046 ---------------------
3047 -- Set_Unit_Number --
3048 ---------------------
3050 procedure Set_Unit_Number
(U
: Unit_Id
) is
3051 Num_Units
: constant Nat
:= Nat
(Units
.Last
) - Nat
(Unit_Id
'First);
3052 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
3055 if Num_Units
>= 10 and then Unum
< 10 then
3059 if Num_Units
>= 100 and then Unum
< 100 then
3064 end Set_Unit_Number
;
3066 ----------------------------
3067 -- Write_Statement_Buffer --
3068 ----------------------------
3070 procedure Write_Statement_Buffer
is
3072 WBI
(Statement_Buffer
(1 .. Last
));
3074 end Write_Statement_Buffer
;
3076 procedure Write_Statement_Buffer
(S
: String) is
3079 Write_Statement_Buffer
;
3080 end Write_Statement_Buffer
;