1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with Binde; use Binde;
29 with Casing; use Casing;
30 with Fname; use Fname;
31 with Gnatvsn; use Gnatvsn;
33 with Namet; use Namet;
35 with Osint; use Osint;
36 with Osint.B; use Osint.B;
37 with Output; use Output;
38 with Rident; use Rident;
39 with Table; use Table;
40 with Targparm; use Targparm;
41 with Types; use Types;
43 with GNAT.OS_Lib; use GNAT.OS_Lib;
44 with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
46 package body Bindgen is
48 Statement_Buffer : String (1 .. 1000);
49 -- Buffer used for constructing output statements
52 -- Last location in Statement_Buffer currently set
54 With_DECGNAT : Boolean := False;
55 -- Flag which indicates whether the program uses the DECGNAT library
56 -- (presence of the unit DEC).
58 With_GNARL : Boolean := False;
59 -- Flag which indicates whether the program uses the GNARL library
60 -- (presence of the unit System.OS_Interface)
62 Num_Elab_Calls : Nat := 0;
63 -- Number of generated calls to elaboration routines
65 ----------------------------------
66 -- Interface_State Pragma Table --
67 ----------------------------------
69 -- This table assembles the interface state pragma information from
70 -- all the units in the partition. Note that Bcheck has already checked
71 -- that the information is consistent across partitions. The entries
72 -- in this table are n/u/r/s for not set/user/runtime/system.
74 package IS_Pragma_Settings is new Table.Table (
75 Table_Component_Type => Character,
76 Table_Index_Type => Int,
79 Table_Increment => 200,
80 Table_Name => "IS_Pragma_Settings");
82 -- This table assembles the Priority_Specific_Dispatching pragma
83 -- information from all the units in the partition. Note that Bcheck has
84 -- already checked that the information is consistent across partitions.
85 -- The entries in this table are the upper case first character of the
86 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
88 package PSD_Pragma_Settings is new Table.Table (
89 Table_Component_Type => Character,
90 Table_Index_Type => Int,
93 Table_Increment => 200,
94 Table_Name => "PSD_Pragma_Settings");
96 ----------------------
97 -- Run-Time Globals --
98 ----------------------
100 -- This section documents the global variables that set from the
101 -- generated binder file.
103 -- Main_Priority : Integer;
104 -- Time_Slice_Value : Integer;
105 -- WC_Encoding : Character;
106 -- Locking_Policy : Character;
107 -- Queuing_Policy : Character;
108 -- Task_Dispatching_Policy : Character;
109 -- Priority_Specific_Dispatching : System.Address;
110 -- Num_Specific_Dispatching : Integer;
111 -- Restrictions : System.Address;
112 -- Interrupt_States : System.Address;
113 -- Num_Interrupt_States : Integer;
114 -- Unreserve_All_Interrupts : Integer;
115 -- Exception_Tracebacks : Integer;
116 -- Zero_Cost_Exceptions : Integer;
117 -- Detect_Blocking : Integer;
118 -- Default_Stack_Size : Integer;
120 -- Main_Priority is the priority value set by pragma Priority in the
121 -- main program. If no such pragma is present, the value is -1.
123 -- Time_Slice_Value is the time slice value set by pragma Time_Slice
124 -- in the main program, or by the use of a -Tnnn parameter for the
125 -- binder (if both are present, the binder value overrides). The
126 -- value is in milliseconds. A value of zero indicates that time
127 -- slicing should be suppressed. If no pragma is present, and no
128 -- -T switch was used, the value is -1.
130 -- WC_Encoding shows the wide character encoding method used for
131 -- the main program. This is one of the encoding letters defined
132 -- in System.WCh_Con.WC_Encoding_Letters.
134 -- Locking_Policy is a space if no locking policy was specified
135 -- for the partition. If a locking policy was specified, the value
136 -- is the upper case first character of the locking policy name,
137 -- for example, 'C' for Ceiling_Locking.
139 -- Queuing_Policy is a space if no queuing policy was specified
140 -- for the partition. If a queuing policy was specified, the value
141 -- is the upper case first character of the queuing policy name
142 -- for example, 'F' for FIFO_Queuing.
144 -- Task_Dispatching_Policy is a space if no task dispatching policy
145 -- was specified for the partition. If a task dispatching policy
146 -- was specified, the value is the upper case first character of
147 -- the policy name, e.g. 'F' for FIFO_Within_Priorities.
149 -- Priority_Specific_Dispatching is the address of a string used to
150 -- store the task dispatching policy specified for the different priorities
151 -- in the partition. The length of this string is determined by the last
152 -- priority for which such a pragma applies (the string will be a null
153 -- string if no specific dispatching policies were used). If pragma were
154 -- present, the entries apply to the priorities in sequence from the first
155 -- priority. The value stored is the upper case first character of the
156 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
157 -- for those priority ranges not specified.
159 -- Num_Specific_Dispatching is the length of the
160 -- Priority_Specific_Dispatching string. It will be set to zero if no
161 -- Priority_Specific_Dispatching pragmas are present.
163 -- Restrictions is the address of a null-terminated string specifying the
164 -- restrictions information for the partition. The format is identical to
165 -- that of the parameter string found on R lines in ali files (see Lib.Writ
166 -- spec in lib-writ.ads for full details). The difference is that in this
167 -- context the values are the cumulative ones for the entire partition.
169 -- Interrupt_States is the address of a string used to specify the
170 -- cumulative results of Interrupt_State pragmas used in the partition.
171 -- The length of this string is determined by the last interrupt for which
172 -- such a pragma is given (the string will be a null string if no pragmas
173 -- were used). If pragma were present the entries apply to the interrupts
174 -- in sequence from the first interrupt, and are set to one of four
175 -- possible settings: 'n' for not specified, 'u' for user, 'r' for
176 -- run time, 's' for system, see description of Interrupt_State pragma
177 -- for further details.
179 -- Num_Interrupt_States is the length of the Interrupt_States string.
180 -- It will be set to zero if no Interrupt_State pragmas are present.
182 -- Unreserve_All_Interrupts is set to one if at least one unit in the
183 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
185 -- Exception_Tracebacks is set to one if the -E parameter was present
186 -- in the bind and to zero otherwise. Note that on some targets exception
187 -- tracebacks are provided by default, so a value of zero for this
188 -- parameter does not necessarily mean no trace backs are available.
190 -- Zero_Cost_Exceptions is set to one if zero cost exceptions are used for
191 -- this partition, and to zero if longjmp/setjmp exceptions are used.
194 -- Detect_Blocking indicates whether pragma Detect_Blocking is
195 -- active or not. A value of zero indicates that the pragma is not
196 -- present, while a value of 1 signals its presence in the
199 -- Default_Stack_Size is the default stack size used when creating an
200 -- Ada task with no explicit Storize_Size clause.
202 -----------------------
203 -- Local Subprograms --
204 -----------------------
206 procedure WBI (Info : String) renames Osint.B.Write_Binder_Info;
207 -- Convenient shorthand used throughout
209 procedure Gen_Adainit_Ada;
210 -- Generates the Adainit procedure (Ada code case)
212 procedure Gen_Adainit_C;
213 -- Generates the Adainit procedure (C code case)
215 procedure Gen_Adafinal_Ada;
216 -- Generate the Adafinal procedure (Ada code case)
218 procedure Gen_Adafinal_C;
219 -- Generate the Adafinal procedure (C code case)
221 procedure Gen_Elab_Calls_Ada;
222 -- Generate sequence of elaboration calls (Ada code case)
224 procedure Gen_Elab_Calls_C;
225 -- Generate sequence of elaboration calls (C code case)
227 procedure Gen_Elab_Order_Ada;
228 -- Generate comments showing elaboration order chosen (Ada case)
230 procedure Gen_Elab_Order_C;
231 -- Generate comments showing elaboration order chosen (C case)
233 procedure Gen_Elab_Defs_C;
234 -- Generate sequence of definitions for elaboration routines (C code case)
236 procedure Gen_Main_Ada;
237 -- Generate procedure main (Ada code case)
239 procedure Gen_Main_C;
240 -- Generate main() procedure (C code case)
242 procedure Gen_Object_Files_Options;
243 -- Output comments containing a list of the full names of the object
244 -- files to be linked and the list of linker options supplied by
245 -- Linker_Options pragmas in the source. (C and Ada code case)
247 procedure Gen_Output_File_Ada (Filename : String);
248 -- Generate output file (Ada code case)
250 procedure Gen_Output_File_C (Filename : String);
251 -- Generate output file (C code case)
253 procedure Gen_Restrictions_Ada;
254 -- Generate initialization of restrictions variable (Ada code case)
256 procedure Gen_Restrictions_C;
257 -- Generate initialization of restrictions variable (C code case)
259 procedure Gen_Versions_Ada;
260 -- Output series of definitions for unit versions (Ada code case)
262 procedure Gen_Versions_C;
263 -- Output series of definitions for unit versions (C code case)
265 function Get_Ada_Main_Name return String;
266 -- This function is used in the Ada main output case to compute a usable
267 -- name for the generated main program. The normal main program name is
268 -- Ada_Main, but this won't work if the user has a unit with this name.
269 -- This function tries Ada_Main first, and if there is such a clash, then
270 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
272 function Get_Main_Name return String;
273 -- This function is used in the Ada main output case to compute the
274 -- correct external main program. It is "main" by default, unless the
275 -- flag Use_Ada_Main_Program_Name_On_Target is set, in which case it
276 -- is the name of the Ada main name without the "_ada". This default
277 -- can be overridden explicitly using the -Mname binder switch.
279 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean;
280 -- Compare linker options, when sorting, first according to
281 -- Is_Internal_File (internal files come later) and then by
282 -- elaboration order position (latest to earliest).
284 procedure Move_Linker_Option (From : Natural; To : Natural);
285 -- Move routine for sorting linker options
287 procedure Resolve_Binder_Options;
288 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
289 -- since it tests for a package named "dec" which might cause a conflict
290 -- on non-VMS systems.
292 procedure Set_Char (C : Character);
293 -- Set given character in Statement_Buffer at the Last + 1 position
294 -- and increment Last by one to reflect the stored character.
296 procedure Set_Int (N : Int);
297 -- Set given value in decimal in Statement_Buffer with no spaces
298 -- starting at the Last + 1 position, and updating Last past the value.
299 -- A minus sign is output for a negative value.
301 procedure Set_Boolean (B : Boolean);
302 -- Set given boolean value in Statement_Buffer at the Last + 1 position
303 -- and update Last past the value.
305 procedure Set_IS_Pragma_Table;
306 -- Initializes contents of IS_Pragma_Settings table from ALI table
308 procedure Set_Main_Program_Name;
309 -- Given the main program name in Name_Buffer (length in Name_Len)
310 -- generate the name of the routine to be used in the call. The name
311 -- is generated starting at Last + 1, and Last is updated past it.
313 procedure Set_Name_Buffer;
314 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
316 procedure Set_PSD_Pragma_Table;
317 -- Initializes contents of PSD_Pragma_Settings table from ALI table
319 procedure Set_String (S : String);
320 -- Sets characters of given string in Statement_Buffer, starting at the
321 -- Last + 1 position, and updating last past the string value.
323 procedure Set_Unit_Name;
324 -- Given a unit name in the Name_Buffer, copies it to Statement_Buffer,
325 -- starting at the Last + 1 position, and updating last past the value.
326 -- changing periods to double underscores, and updating Last appropriately.
328 procedure Set_Unit_Number (U : Unit_Id);
329 -- Sets unit number (first unit is 1, leading zeroes output to line
330 -- up all output unit numbers nicely as required by the value, and
331 -- by the total number of units.
333 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String);
334 -- For C code case, write C & Common, for Ada case write Ada & Common
335 -- to current binder output file using Write_Binder_Info.
337 procedure Write_Statement_Buffer;
338 -- Write out contents of statement buffer up to Last, and reset Last to 0
340 procedure Write_Statement_Buffer (S : String);
341 -- First writes its argument (using Set_String (S)), then writes out the
342 -- contents of statement buffer up to Last, and reset Last to 0
344 ----------------------
345 -- Gen_Adafinal_Ada --
346 ----------------------
348 procedure Gen_Adafinal_Ada is
351 WBI (" procedure " & Ada_Final_Name.all & " is");
354 -- If compiling for the JVM, we directly call Adafinal because
355 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
357 if Hostparm.Java_VM then
358 WBI (" System.Standard_Library.Adafinal;");
360 -- If there is no finalization, there is nothing to do
362 elsif Cumulative_Restrictions.Set (No_Finalization) then
365 WBI (" Do_Finalize;");
368 WBI (" end " & Ada_Final_Name.all & ";");
369 end Gen_Adafinal_Ada;
375 procedure Gen_Adafinal_C is
377 WBI ("void " & Ada_Final_Name.all & " (void) {");
378 WBI (" system__standard_library__adafinal ();");
383 ---------------------
384 -- Gen_Adainit_Ada --
385 ---------------------
387 procedure Gen_Adainit_Ada is
388 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
391 WBI (" procedure " & Ada_Init_Name.all & " is");
393 -- Generate externals for elaboration entities
395 for E in Elab_Order.First .. Elab_Order.Last loop
397 Unum : constant Unit_Id := Elab_Order.Table (E);
398 U : Unit_Record renames Units.Table (Unum);
401 -- Check for Elab_Entity to be set for this unit
405 -- Don't generate reference for stand alone library
407 and then not U.SAL_Interface
409 -- Don't generate reference for predefined file in No_Run_Time
410 -- mode, since we don't include the object files in this case
414 and then Is_Predefined_File_Name (U.Sfile))
418 Set_Unit_Number (Unum);
419 Set_String (" : Boolean; pragma Import (Ada, ");
421 Set_Unit_Number (Unum);
423 Get_Name_String (U.Uname);
425 -- In the case of JGNAT we need to emit an Import name
426 -- that includes the class name (using '$' separators
427 -- in the case of a child unit name).
429 if Hostparm.Java_VM then
430 for J in 1 .. Name_Len - 2 loop
431 if Name_Buffer (J) /= '.' then
432 Set_Char (Name_Buffer (J));
440 -- If the unit name is very long, then split the
441 -- Import link name across lines using "&" (occurs
442 -- in some C2 tests).
444 if 2 * Name_Len + 60 > Hostparm.Max_Line_Length then
446 Write_Statement_Buffer;
452 Set_String ("_E"");");
453 Write_Statement_Buffer;
458 Write_Statement_Buffer;
460 -- If the standard library is suppressed, then the only global variable
461 -- that might be needed (by the Ravenscar profile) is the priority of
464 if Suppress_Standard_Library_On_Target then
465 if Main_Priority /= No_Main_Priority then
466 WBI (" Main_Priority : Integer;");
467 WBI (" pragma Import (C, Main_Priority," &
468 " ""__gl_main_priority"");");
474 if Main_Priority /= No_Main_Priority then
475 Set_String (" Main_Priority := ");
476 Set_Int (Main_Priority);
478 Write_Statement_Buffer;
484 -- Normal case (standard library not suppressed). Set all global values
485 -- used by the run time.
488 WBI (" Main_Priority : Integer;");
489 WBI (" pragma Import (C, Main_Priority, " &
490 """__gl_main_priority"");");
491 WBI (" Time_Slice_Value : Integer;");
492 WBI (" pragma Import (C, Time_Slice_Value, " &
493 """__gl_time_slice_val"");");
494 WBI (" WC_Encoding : Character;");
495 WBI (" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
496 WBI (" Locking_Policy : Character;");
497 WBI (" pragma Import (C, Locking_Policy, " &
498 """__gl_locking_policy"");");
499 WBI (" Queuing_Policy : Character;");
500 WBI (" pragma Import (C, Queuing_Policy, " &
501 """__gl_queuing_policy"");");
502 WBI (" Task_Dispatching_Policy : Character;");
503 WBI (" pragma Import (C, Task_Dispatching_Policy, " &
504 """__gl_task_dispatching_policy"");");
505 WBI (" Priority_Specific_Dispatching : System.Address;");
506 WBI (" pragma Import (C, Priority_Specific_Dispatching, " &
507 """__gl_priority_specific_dispatching"");");
508 WBI (" Num_Specific_Dispatching : Integer;");
509 WBI (" pragma Import (C, Num_Specific_Dispatching, " &
510 """__gl_num_specific_dispatching"");");
512 WBI (" Interrupt_States : System.Address;");
513 WBI (" pragma Import (C, Interrupt_States, " &
514 """__gl_interrupt_states"");");
515 WBI (" Num_Interrupt_States : Integer;");
516 WBI (" pragma Import (C, Num_Interrupt_States, " &
517 """__gl_num_interrupt_states"");");
518 WBI (" Unreserve_All_Interrupts : Integer;");
519 WBI (" pragma Import (C, Unreserve_All_Interrupts, " &
520 """__gl_unreserve_all_interrupts"");");
522 if Exception_Tracebacks then
523 WBI (" Exception_Tracebacks : Integer;");
524 WBI (" pragma Import (C, Exception_Tracebacks, " &
525 """__gl_exception_tracebacks"");");
528 WBI (" Zero_Cost_Exceptions : Integer;");
529 WBI (" pragma Import (C, Zero_Cost_Exceptions, " &
530 """__gl_zero_cost_exceptions"");");
531 WBI (" Detect_Blocking : Integer;");
532 WBI (" pragma Import (C, Detect_Blocking, " &
533 """__gl_detect_blocking"");");
534 WBI (" Default_Stack_Size : Integer;");
535 WBI (" pragma Import (C, Default_Stack_Size, " &
536 """__gl_default_stack_size"");");
538 -- Import entry point for elaboration time signal handler
539 -- installation, and indication of if it's been called previously.
542 WBI (" procedure Install_Handler;");
543 WBI (" pragma Import (C, Install_Handler, " &
544 """__gnat_install_handler"");");
546 WBI (" Handler_Installed : Integer;");
547 WBI (" pragma Import (C, Handler_Installed, " &
548 """__gnat_handler_installed"");");
551 Set_String (" Main_Priority := ");
552 Set_Int (Main_Priority);
554 Write_Statement_Buffer;
556 Set_String (" Time_Slice_Value := ");
558 if Task_Dispatching_Policy_Specified = 'F'
559 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
563 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
567 Write_Statement_Buffer;
569 Set_String (" WC_Encoding := '");
570 Set_Char (ALIs.Table (ALIs.First).WC_Encoding);
572 Write_Statement_Buffer;
574 Set_String (" Locking_Policy := '");
575 Set_Char (Locking_Policy_Specified);
577 Write_Statement_Buffer;
579 Set_String (" Queuing_Policy := '");
580 Set_Char (Queuing_Policy_Specified);
582 Write_Statement_Buffer;
584 Set_String (" Task_Dispatching_Policy := '");
585 Set_Char (Task_Dispatching_Policy_Specified);
587 Write_Statement_Buffer;
589 Gen_Restrictions_Ada;
591 WBI (" Priority_Specific_Dispatching :=");
592 WBI (" Local_Priority_Specific_Dispatching'Address;");
594 Set_String (" Num_Specific_Dispatching := ");
595 Set_Int (PSD_Pragma_Settings.Last + 1);
597 Write_Statement_Buffer;
599 WBI (" Interrupt_States := Local_Interrupt_States'Address;");
601 Set_String (" Num_Interrupt_States := ");
602 Set_Int (IS_Pragma_Settings.Last + 1);
604 Write_Statement_Buffer;
606 Set_String (" Unreserve_All_Interrupts := ");
608 if Unreserve_All_Interrupts_Specified then
615 Write_Statement_Buffer;
617 if Exception_Tracebacks then
618 WBI (" Exception_Tracebacks := 1;");
621 Set_String (" Zero_Cost_Exceptions := ");
623 if Zero_Cost_Exceptions_Specified then
630 Write_Statement_Buffer;
632 Set_String (" Detect_Blocking := ");
634 if Detect_Blocking then
641 Write_Statement_Buffer;
643 Set_String (" Default_Stack_Size := ");
644 Set_Int (Default_Stack_Size);
646 Write_Statement_Buffer;
648 -- Generate call to Install_Handler
651 WBI (" if Handler_Installed = 0 then");
652 WBI (" Install_Handler;");
656 -- Generate call to set Initialize_Scalar values if active
658 if Initialize_Scalars_Used then
660 Set_String (" System.Scalar_Values.Initialize ('");
661 Set_Char (Initialize_Scalars_Mode1);
663 Set_Char (Initialize_Scalars_Mode2);
665 Write_Statement_Buffer;
668 -- Generate assignment of default secondary stack size if set
670 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
672 Set_String (" System.Secondary_Stack.");
673 Set_String ("Default_Secondary_Stack_Size := ");
674 Set_Int (Opt.Default_Sec_Stack_Size);
676 Write_Statement_Buffer;
679 -- Generate elaboration calls
684 WBI (" end " & Ada_Init_Name.all & ";");
691 procedure Gen_Adainit_C is
692 Main_Priority : Int renames ALIs.Table (ALIs.First).Main_Priority;
695 WBI ("void " & Ada_Init_Name.all & " (void)");
698 -- Generate externals for elaboration entities
700 for E in Elab_Order.First .. Elab_Order.Last loop
702 Unum : constant Unit_Id := Elab_Order.Table (E);
703 U : Unit_Record renames Units.Table (Unum);
706 -- Check for Elab entity to be set for this unit
710 -- Don't generate reference for stand alone library
712 and then not U.SAL_Interface
714 -- Don't generate reference for predefined file in No_Run_Time
715 -- mode, since we don't include the object files in this case
719 and then Is_Predefined_File_Name (U.Sfile))
721 Set_String (" extern char ");
722 Get_Name_String (U.Uname);
725 Write_Statement_Buffer;
730 Write_Statement_Buffer;
732 -- Standard library suppressed
734 if Suppress_Standard_Library_On_Target then
736 -- Case of High_Integrity_Mode mode. Set __gl_main_priority if needed
737 -- for the Ravenscar profile.
739 if Main_Priority /= No_Main_Priority then
740 WBI (" extern int __gl_main_priority;");
741 Set_String (" __gl_main_priority = ");
742 Set_Int (Main_Priority);
744 Write_Statement_Buffer;
747 -- Normal case (standard library not suppressed)
750 -- Generate definition for interrupt states string
752 Set_String (" static const char *local_interrupt_states = """);
754 for J in 0 .. IS_Pragma_Settings.Last loop
755 Set_Char (IS_Pragma_Settings.Table (J));
759 Write_Statement_Buffer;
761 -- Generate definition for priority specific dispatching string
764 (" static const char *local_priority_specific_dispatching = """);
766 for J in 0 .. PSD_Pragma_Settings.Last loop
767 Set_Char (PSD_Pragma_Settings.Table (J));
771 Write_Statement_Buffer;
773 -- Generate declaration for secondary stack default if needed
775 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
776 WBI (" extern int system__secondary_stack__" &
777 "default_secondary_stack_size;");
782 -- Code for normal case (standard library not suppressed)
784 -- We call the routine from inside adainit() because this works for
785 -- both programs with and without binder generated "main" functions.
787 WBI (" extern int __gl_main_priority;");
788 Set_String (" __gl_main_priority = ");
789 Set_Int (Main_Priority);
791 Write_Statement_Buffer;
793 WBI (" extern int __gl_time_slice_val;");
794 Set_String (" __gl_time_slice_val = ");
796 if Task_Dispatching_Policy = 'F'
797 and then ALIs.Table (ALIs.First).Time_Slice_Value = -1
801 Set_Int (ALIs.Table (ALIs.First).Time_Slice_Value);
805 Write_Statement_Buffer;
807 WBI (" extern char __gl_wc_encoding;");
808 Set_String (" __gl_wc_encoding = '");
809 Set_Char (ALIs.Table (ALIs.First).WC_Encoding);
811 Write_Statement_Buffer;
813 WBI (" extern char __gl_locking_policy;");
814 Set_String (" __gl_locking_policy = '");
815 Set_Char (Locking_Policy_Specified);
817 Write_Statement_Buffer;
819 WBI (" extern char __gl_queuing_policy;");
820 Set_String (" __gl_queuing_policy = '");
821 Set_Char (Queuing_Policy_Specified);
823 Write_Statement_Buffer;
825 WBI (" extern char __gl_task_dispatching_policy;");
826 Set_String (" __gl_task_dispatching_policy = '");
827 Set_Char (Task_Dispatching_Policy_Specified);
829 Write_Statement_Buffer;
831 -- Generate definition for restrictions string
835 WBI (" extern const void *__gl_interrupt_states;");
836 WBI (" __gl_interrupt_states = local_interrupt_states;");
838 WBI (" extern int __gl_num_interrupt_states;");
839 Set_String (" __gl_num_interrupt_states = ");
840 Set_Int (IS_Pragma_Settings.Last + 1);
842 Write_Statement_Buffer;
844 WBI (" extern const void *__gl_priority_specific_dispatching;");
845 WBI (" __gl_priority_specific_dispatching =" &
846 " local_priority_specific_dispatching;");
848 WBI (" extern int __gl_num_specific_dispatching;");
849 Set_String (" __gl_num_specific_dispatching = ");
850 Set_Int (PSD_Pragma_Settings.Last + 1);
852 Write_Statement_Buffer;
854 WBI (" extern int __gl_unreserve_all_interrupts;");
855 Set_String (" __gl_unreserve_all_interrupts = ");
856 Set_Int (Boolean'Pos (Unreserve_All_Interrupts_Specified));
858 Write_Statement_Buffer;
860 if Exception_Tracebacks then
861 WBI (" extern int __gl_exception_tracebacks;");
862 WBI (" __gl_exception_tracebacks = 1;");
865 WBI (" extern int __gl_zero_cost_exceptions;");
866 Set_String (" __gl_zero_cost_exceptions = ");
867 Set_Int (Boolean'Pos (Zero_Cost_Exceptions_Specified));
869 Write_Statement_Buffer;
871 WBI (" extern int __gl_detect_blocking;");
872 Set_String (" __gl_detect_blocking = ");
874 if Detect_Blocking then
881 Write_Statement_Buffer;
883 WBI (" extern int __gl_default_stack_size;");
884 Set_String (" __gl_default_stack_size = ");
885 Set_Int (Default_Stack_Size);
887 Write_Statement_Buffer;
891 -- Install elaboration time signal handler
893 WBI (" if (__gnat_handler_installed == 0)");
895 WBI (" __gnat_install_handler ();");
899 -- Generate call to set Initialize_Scalar values if needed
901 if Initialize_Scalars_Used then
903 Set_String (" system__scalar_values__initialize('");
904 Set_Char (Initialize_Scalars_Mode1);
906 Set_Char (Initialize_Scalars_Mode2);
908 Write_Statement_Buffer;
911 -- Generate assignment of default secondary stack size if set
913 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
915 Set_String (" system__secondary_stack__");
916 Set_String ("default_secondary_stack_size = ");
917 Set_Int (Opt.Default_Sec_Stack_Size);
919 Write_Statement_Buffer;
922 -- Generate elaboration calls
929 ------------------------
930 -- Gen_Elab_Calls_Ada --
931 ------------------------
933 procedure Gen_Elab_Calls_Ada is
935 for E in Elab_Order.First .. Elab_Order.Last loop
937 Unum : constant Unit_Id := Elab_Order.Table (E);
938 U : Unit_Record renames Units.Table (Unum);
941 -- This is the unit number of the spec that corresponds to
942 -- this entry. It is the same as Unum except when the body
943 -- and spec are different and we are currently processing
944 -- the body, in which case it is the spec (Unum + 1).
947 if U.Utype = Is_Body then
948 Unum_Spec := Unum + 1;
953 -- Nothing to do if predefined unit in no run time mode
955 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
958 -- Case of no elaboration code
962 -- The only case in which we have to do something is if
963 -- this is a body, with a separate spec, where the separate
964 -- spec has an elaboration entity defined.
966 -- In that case, this is where we set the elaboration entity
967 -- to True, we do not need to test if this has already been
968 -- done, since it is quicker to set the flag than to test it.
970 if not U.SAL_Interface and then U.Utype = Is_Body
971 and then Units.Table (Unum_Spec).Set_Elab_Entity
974 Set_Unit_Number (Unum_Spec);
975 Set_String (" := True;");
976 Write_Statement_Buffer;
979 -- Here if elaboration code is present. If binding a library
980 -- or if there is a non-Ada main subprogram then we generate:
982 -- if not uname_E then
983 -- uname'elab_[spec|body];
987 -- Otherwise, elaboration routines are called unconditionally:
989 -- uname'elab_[spec|body];
992 -- The uname_E assignment is skipped if this is a separate spec,
993 -- since the assignment will be done when we process the body.
995 elsif not U.SAL_Interface then
996 if Force_Checking_Of_Elaboration_Flags or
997 Interface_Library_Unit or
998 (not Bind_Main_Program)
1000 Set_String (" if not E");
1001 Set_Unit_Number (Unum_Spec);
1002 Set_String (" then");
1003 Write_Statement_Buffer;
1008 Get_Decoded_Name_String_With_Brackets (U.Uname);
1010 if Name_Buffer (Name_Len) = 's' then
1011 Name_Buffer (Name_Len - 1 .. Name_Len + 8) := "'elab_spec";
1013 Name_Buffer (Name_Len - 1 .. Name_Len + 8) := "'elab_body";
1016 Name_Len := Name_Len + 8;
1017 Set_Casing (U.Icasing);
1020 Write_Statement_Buffer;
1022 if U.Utype /= Is_Spec then
1023 if Force_Checking_Of_Elaboration_Flags or
1024 Interface_Library_Unit or
1025 (not Bind_Main_Program)
1031 Set_Unit_Number (Unum_Spec);
1032 Set_String (" := True;");
1033 Write_Statement_Buffer;
1036 if Force_Checking_Of_Elaboration_Flags or
1037 Interface_Library_Unit or
1038 (not Bind_Main_Program)
1045 end Gen_Elab_Calls_Ada;
1047 ----------------------
1048 -- Gen_Elab_Calls_C --
1049 ----------------------
1051 procedure Gen_Elab_Calls_C is
1053 for E in Elab_Order.First .. Elab_Order.Last loop
1055 Unum : constant Unit_Id := Elab_Order.Table (E);
1056 U : Unit_Record renames Units.Table (Unum);
1058 Unum_Spec : Unit_Id;
1059 -- This is the unit number of the spec that corresponds to
1060 -- this entry. It is the same as Unum except when the body
1061 -- and spec are different and we are currently processing
1062 -- the body, in which case it is the spec (Unum + 1).
1065 if U.Utype = Is_Body then
1066 Unum_Spec := Unum + 1;
1071 -- Nothing to do if predefined unit in no run time mode
1073 if No_Run_Time_Mode and then Is_Predefined_File_Name (U.Sfile) then
1076 -- Case of no elaboration code
1078 elsif U.No_Elab then
1080 -- The only case in which we have to do something is if
1081 -- this is a body, with a separate spec, where the separate
1082 -- spec has an elaboration entity defined.
1084 -- In that case, this is where we set the elaboration entity
1085 -- to True, we do not need to test if this has already been
1086 -- done, since it is quicker to set the flag than to test it.
1088 if not U.SAL_Interface and then U.Utype = Is_Body
1089 and then Units.Table (Unum_Spec).Set_Elab_Entity
1092 Get_Name_String (U.Uname);
1094 Set_String ("_E = 1;");
1095 Write_Statement_Buffer;
1098 -- Here if elaboration code is present. If binding a library
1099 -- or if there is a non-Ada main subprogram then we generate:
1101 -- if (uname_E == 0) {
1102 -- uname__elab[s|b] ();
1106 -- The uname_E assignment is skipped if this is a separate spec,
1107 -- since the assignment will be done when we process the body.
1109 elsif not U.SAL_Interface then
1110 Get_Name_String (U.Uname);
1112 if Force_Checking_Of_Elaboration_Flags or
1113 Interface_Library_Unit or
1114 (not Bind_Main_Program)
1116 Set_String (" if (");
1118 Set_String ("_E == 0) {");
1119 Write_Statement_Buffer;
1125 Set_String ("___elab");
1126 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1127 Set_String (" ();");
1128 Write_Statement_Buffer;
1130 if U.Utype /= Is_Spec then
1131 if Force_Checking_Of_Elaboration_Flags or
1132 Interface_Library_Unit or
1133 (not Bind_Main_Program)
1140 Set_String ("_E++;");
1141 Write_Statement_Buffer;
1144 if Force_Checking_Of_Elaboration_Flags or
1145 Interface_Library_Unit or
1146 (not Bind_Main_Program)
1154 end Gen_Elab_Calls_C;
1156 ----------------------
1157 -- Gen_Elab_Defs_C --
1158 ----------------------
1160 procedure Gen_Elab_Defs_C is
1162 for E in Elab_Order.First .. Elab_Order.Last loop
1164 -- Generate declaration of elaboration procedure if elaboration
1165 -- needed. Note that passive units are always excluded.
1167 if not Units.Table (Elab_Order.Table (E)).No_Elab then
1168 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
1169 Set_String ("extern void ");
1171 Set_String ("___elab");
1172 Set_Char (Name_Buffer (Name_Len)); -- 's' or 'b' for spec/body
1173 Set_String (" (void);");
1174 Write_Statement_Buffer;
1180 end Gen_Elab_Defs_C;
1182 ------------------------
1183 -- Gen_Elab_Order_Ada --
1184 ------------------------
1186 procedure Gen_Elab_Order_Ada is
1189 WBI (" -- BEGIN ELABORATION ORDER");
1191 for J in Elab_Order.First .. Elab_Order.Last loop
1192 Set_String (" -- ");
1193 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1195 Write_Statement_Buffer;
1198 WBI (" -- END ELABORATION ORDER");
1199 end Gen_Elab_Order_Ada;
1201 ----------------------
1202 -- Gen_Elab_Order_C --
1203 ----------------------
1205 procedure Gen_Elab_Order_C is
1208 WBI ("/* BEGIN ELABORATION ORDER");
1210 for J in Elab_Order.First .. Elab_Order.Last loop
1211 Get_Name_String (Units.Table (Elab_Order.Table (J)).Uname);
1213 Write_Statement_Buffer;
1216 WBI (" END ELABORATION ORDER */");
1217 end Gen_Elab_Order_C;
1223 procedure Gen_Main_Ada is
1227 if Exit_Status_Supported_On_Target then
1228 Set_String (" function ");
1230 Set_String (" procedure ");
1233 Set_String (Get_Main_Name);
1235 if Command_Line_Args_On_Target then
1236 Write_Statement_Buffer;
1237 WBI (" (argc : Integer;");
1238 WBI (" argv : System.Address;");
1239 WBI (" envp : System.Address)");
1241 if Exit_Status_Supported_On_Target then
1242 WBI (" return Integer");
1248 if Exit_Status_Supported_On_Target then
1249 Set_String (" return Integer is");
1254 Write_Statement_Buffer;
1257 if Opt.Default_Exit_Status /= 0
1258 and then Bind_Main_Program
1259 and then not Configurable_Run_Time_Mode
1261 WBI (" procedure Set_Exit_Status (Status : Integer);");
1262 WBI (" pragma Import (C, Set_Exit_Status, " &
1263 """__gnat_set_exit_status"");");
1267 -- Initialize and Finalize
1269 if not Cumulative_Restrictions.Set (No_Finalization) then
1270 WBI (" procedure initialize (Addr : System.Address);");
1271 WBI (" pragma Import (C, initialize, ""__gnat_initialize"");");
1273 WBI (" procedure finalize;");
1274 WBI (" pragma Import (C, finalize, ""__gnat_finalize"");");
1277 -- If we want to analyze the stack, we have to import corresponding
1280 if Dynamic_Stack_Measurement then
1282 WBI (" procedure Output_Results;");
1283 WBI (" pragma Import (C, Output_Results, " &
1284 """__gnat_stack_usage_output_results"");");
1288 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1289 WBI (" pragma Import (C, Initialize_Stack_Analysis, " &
1290 """__gnat_stack_usage_initialize"");");
1293 -- Deal with declarations for main program case
1295 if not No_Main_Subprogram then
1297 -- To call the main program, we declare it using a pragma Import
1298 -- Ada with the right link name.
1300 -- It might seem more obvious to "with" the main program, and call
1301 -- it in the normal Ada manner. We do not do this for three reasons:
1303 -- 1. It is more efficient not to recompile the main program
1304 -- 2. We are not entitled to assume the source is accessible
1305 -- 3. We don't know what options to use to compile it
1307 -- It is really reason 3 that is most critical (indeed we used
1308 -- to generate the "with", but several regression tests failed).
1312 if ALIs.Table (ALIs.First).Main_Program = Func then
1313 WBI (" Result : Integer;");
1315 WBI (" function Ada_Main_Program return Integer;");
1318 WBI (" procedure Ada_Main_Program;");
1321 Set_String (" pragma Import (Ada, Ada_Main_Program, """);
1322 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1323 Set_Main_Program_Name;
1324 Set_String (""");");
1326 Write_Statement_Buffer;
1329 if Bind_Main_Program
1330 and then not Suppress_Standard_Library_On_Target
1332 WBI (" SEH : aliased array (1 .. 2) of Integer;");
1337 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1338 -- not referenced elsewhere in the generated program, but is needed
1339 -- by the debugger (that's why it is generated in the first place).
1340 -- The reference stops Ada_Main_Program_Name from being optimized
1341 -- away by smart linkers, such as the AiX linker.
1343 -- Because this variable is unused, we make this variable "aliased"
1344 -- with a pragma Volatile in order to tell the compiler to preserve
1345 -- this variable at any level of optimization.
1347 if Bind_Main_Program then
1349 (" Ensure_Reference : aliased System.Address := " &
1350 "Ada_Main_Program_Name'Address;");
1351 WBI (" pragma Volatile (Ensure_Reference);");
1357 -- Acquire command line arguments if present on target
1359 if Command_Line_Args_On_Target then
1360 WBI (" gnat_argc := argc;");
1361 WBI (" gnat_argv := argv;");
1362 WBI (" gnat_envp := envp;");
1365 -- If configurable run time and no command line args, then nothing
1366 -- needs to be done since the gnat_argc/argv/envp variables are
1367 -- suppressed in this case.
1369 elsif Configurable_Run_Time_On_Target then
1372 -- Otherwise set dummy values (to be filled in by some other unit?)
1375 WBI (" gnat_argc := 0;");
1376 WBI (" gnat_argv := System.Null_Address;");
1377 WBI (" gnat_envp := System.Null_Address;");
1380 if Opt.Default_Exit_Status /= 0
1381 and then Bind_Main_Program
1382 and then not Configurable_Run_Time_Mode
1384 Set_String (" Set_Exit_Status (");
1385 Set_Int (Opt.Default_Exit_Status);
1387 Write_Statement_Buffer;
1390 if Dynamic_Stack_Measurement then
1391 Set_String (" Initialize_Stack_Analysis (");
1392 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1394 Write_Statement_Buffer;
1397 if not Cumulative_Restrictions.Set (No_Finalization) then
1399 if not No_Main_Subprogram
1400 and then Bind_Main_Program
1401 and then not Suppress_Standard_Library_On_Target
1403 WBI (" Initialize (SEH'Address);");
1405 WBI (" Initialize (System.Null_Address);");
1409 WBI (" " & Ada_Init_Name.all & ";");
1411 if not No_Main_Subprogram then
1412 WBI (" Break_Start;");
1414 if ALIs.Table (ALIs.First).Main_Program = Proc then
1415 WBI (" Ada_Main_Program;");
1417 WBI (" Result := Ada_Main_Program;");
1421 -- Adafinal call is skipped if no finalization
1423 if not Cumulative_Restrictions.Set (No_Finalization) then
1425 -- If compiling for the JVM, we directly call Adafinal because
1426 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1428 if Hostparm.Java_VM then
1429 WBI (" System.Standard_Library.Adafinal;");
1431 WBI (" Do_Finalize;");
1435 -- Prints the result of static stack analysis
1437 if Dynamic_Stack_Measurement then
1438 WBI (" Output_Results;");
1441 -- Finalize is only called if we have a run time
1443 if not Cumulative_Restrictions.Set (No_Finalization) then
1449 if Exit_Status_Supported_On_Target then
1450 if No_Main_Subprogram
1451 or else ALIs.Table (ALIs.First).Main_Program = Proc
1453 WBI (" return (gnat_exit_status);");
1455 WBI (" return (Result);");
1466 procedure Gen_Main_C is
1468 if Exit_Status_Supported_On_Target then
1469 WBI ("#include <stdlib.h>");
1470 Set_String ("int ");
1472 Set_String ("void ");
1475 Set_String (Get_Main_Name);
1477 -- Generate command line args in prototype if present on target
1479 if Command_Line_Args_On_Target then
1480 Write_Statement_Buffer (" (int argc, char **argv, char **envp)");
1482 -- Case of no command line arguments on target
1485 Write_Statement_Buffer (" (void)");
1490 -- Generate a reference to __gnat_ada_main_program_name. This symbol
1491 -- is not referenced elsewhere in the generated program, but is
1492 -- needed by the debugger (that's why it is generated in the first
1493 -- place). The reference stops Ada_Main_Program_Name from being
1494 -- optimized away by smart linkers, such as the AiX linker.
1496 -- Because this variable is unused, we declare this variable as
1497 -- volatile in order to tell the compiler to preserve it at any
1498 -- level of optimization.
1500 if Bind_Main_Program then
1501 WBI (" char * volatile ensure_reference " &
1502 "__attribute__ ((__unused__)) = " &
1503 "__gnat_ada_main_program_name;");
1506 if not Suppress_Standard_Library_On_Target
1507 and then not No_Main_Subprogram
1509 WBI (" int SEH [2];");
1514 -- If main program is a function, generate result variable
1516 if ALIs.Table (ALIs.First).Main_Program = Func then
1517 WBI (" int result;");
1520 -- Set command line argument values from parameters if command line
1521 -- arguments are present on target
1523 if Command_Line_Args_On_Target then
1524 WBI (" gnat_argc = argc;");
1525 WBI (" gnat_argv = argv;");
1526 WBI (" gnat_envp = envp;");
1529 -- If configurable run-time, then nothing to do, since in this case
1530 -- the gnat_argc/argv/envp variables are entirely suppressed.
1532 elsif Configurable_Run_Time_On_Target then
1535 -- if no command line arguments on target, set dummy values
1538 WBI (" int result;");
1539 WBI (" gnat_argc = 0;");
1540 WBI (" gnat_argv = 0;");
1541 WBI (" gnat_envp = 0;");
1544 if Opt.Default_Exit_Status /= 0
1545 and then Bind_Main_Program
1546 and then not Configurable_Run_Time_Mode
1548 Set_String (" __gnat_set_exit_status (");
1549 Set_Int (Opt.Default_Exit_Status);
1551 Write_Statement_Buffer;
1554 -- Initializes dynamic stack measurement if needed
1556 if Dynamic_Stack_Measurement then
1557 Set_String (" __gnat_stack_usage_initialize (");
1558 Set_Int (Dynamic_Stack_Measurement_Array_Size);
1560 Write_Statement_Buffer;
1563 -- The __gnat_initialize routine is used only if we have a run-time
1565 if not Suppress_Standard_Library_On_Target then
1566 if not No_Main_Subprogram and then Bind_Main_Program then
1567 WBI (" __gnat_initialize ((void *)SEH);");
1569 WBI (" __gnat_initialize ((void *)0);");
1573 WBI (" " & Ada_Init_Name.all & " ();");
1575 if not No_Main_Subprogram then
1576 WBI (" __gnat_break_start ();");
1579 -- Output main program name
1581 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
1583 -- Main program is procedure case
1585 if ALIs.Table (ALIs.First).Main_Program = Proc then
1587 Set_Main_Program_Name;
1588 Set_String (" ();");
1589 Write_Statement_Buffer;
1591 -- Main program is function case
1593 else -- ALIs.Table (ALIs_First).Main_Program = Func
1594 Set_String (" result = ");
1595 Set_Main_Program_Name;
1596 Set_String (" ();");
1597 Write_Statement_Buffer;
1602 -- Call adafinal if finalization active
1604 if not Cumulative_Restrictions.Set (No_Finalization) then
1606 WBI (" system__standard_library__adafinal ();");
1609 -- Outputs the dynamic stack measurement if needed
1611 if Dynamic_Stack_Measurement then
1612 WBI (" __gnat_stack_usage_output_results ();");
1615 -- The finalize routine is used only if we have a run-time
1617 if not Suppress_Standard_Library_On_Target then
1618 WBI (" __gnat_finalize ();");
1621 -- Case of main program is a function, so the value it returns
1622 -- is the exit status in this case.
1624 if ALIs.Table (ALIs.First).Main_Program = Func then
1625 if Exit_Status_Supported_On_Target then
1627 -- VMS must use Posix exit routine in order to get the effect
1628 -- of a Unix compatible setting of the program exit status.
1629 -- For all other systems, we use the standard exit routine.
1631 if OpenVMS_On_Target then
1632 WBI (" decc$__posix_exit (result);");
1634 WBI (" exit (result);");
1638 -- Case of main program is a procedure, in which case the exit
1639 -- status is whatever was set by a Set_Exit call most recently
1642 if Exit_Status_Supported_On_Target then
1644 -- VMS must use Posix exit routine in order to get the effect
1645 -- of a Unix compatible setting of the program exit status.
1646 -- For all other systems, we use the standard exit routine.
1648 if OpenVMS_On_Target then
1649 WBI (" decc$__posix_exit (gnat_exit_status);");
1651 WBI (" exit (gnat_exit_status);");
1659 ------------------------------
1660 -- Gen_Object_Files_Options --
1661 ------------------------------
1663 procedure Gen_Object_Files_Options is
1665 -- This keeps track of the position in the sorted set of entries
1666 -- in the Linker_Options table of where the first entry from an
1667 -- internal file appears.
1669 procedure Write_Linker_Option;
1670 -- Write binder info linker option
1672 -------------------------
1673 -- Write_Linker_Option --
1674 -------------------------
1676 procedure Write_Linker_Option is
1681 -- Loop through string, breaking at null's
1684 while Start < Name_Len loop
1686 -- Find null ending this section
1689 while Name_Buffer (Stop) /= ASCII.NUL
1690 and then Stop <= Name_Len loop
1694 -- Process section if non-null
1696 if Stop > Start then
1697 if Output_Linker_Option_List then
1698 Write_Str (Name_Buffer (Start .. Stop - 1));
1702 (" -- ", "", Name_Buffer (Start .. Stop - 1));
1707 end Write_Linker_Option;
1709 -- Start of processing for Gen_Object_Files_Options
1713 Write_Info_Ada_C ("-- ", "/* ", " BEGIN Object file/option list");
1715 for E in Elab_Order.First .. Elab_Order.Last loop
1717 -- If not spec that has an associated body, then generate a
1718 -- comment giving the name of the corresponding object file.
1720 if (not Units.Table (Elab_Order.Table (E)).SAL_Interface)
1721 and then Units.Table (Elab_Order.Table (E)).Utype /= Is_Spec
1725 (Units.Table (Elab_Order.Table (E)).My_ALI).Ofile_Full_Name);
1727 -- If the presence of an object file is necessary or if it
1728 -- exists, then use it.
1730 if not Hostparm.Exclude_Missing_Objects
1731 or else GNAT.OS_Lib.Is_Regular_File (Name_Buffer (1 .. Name_Len))
1733 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
1735 if Output_Object_List then
1736 Write_Str (Name_Buffer (1 .. Name_Len));
1740 -- Don't link with the shared library on VMS if an internal
1741 -- filename object is seen. Multiply defined symbols will
1744 if OpenVMS_On_Target
1745 and then Is_Internal_File_Name
1747 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile)
1749 -- Special case for g-trasym.obj, which is not included
1752 Get_Name_String (ALIs.Table
1753 (Units.Table (Elab_Order.Table (E)).My_ALI).Sfile);
1755 if Name_Buffer (1 .. 8) /= "g-trasym" then
1756 Opt.Shared_Libgnat := False;
1763 -- Add a "-Ldir" for each directory in the object path
1765 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1767 Dir : constant String_Ptr := Dir_In_Obj_Search_Path (J);
1770 Add_Str_To_Name_Buffer ("-L");
1771 Add_Str_To_Name_Buffer (Dir.all);
1772 Write_Linker_Option;
1776 -- Sort linker options
1778 -- This sort accomplishes two important purposes:
1780 -- a) All application files are sorted to the front, and all
1781 -- GNAT internal files are sorted to the end. This results
1782 -- in a well defined dividing line between the two sets of
1783 -- files, for the purpose of inserting certain standard
1784 -- library references into the linker arguments list.
1786 -- b) Given two different units, we sort the linker options so
1787 -- that those from a unit earlier in the elaboration order
1788 -- comes later in the list. This is a heuristic designed
1789 -- to create a more friendly order of linker options when
1790 -- the operations appear in separate units. The idea is that
1791 -- if unit A must be elaborated before unit B, then it is
1792 -- more likely that B references libraries included by A,
1793 -- than vice versa, so we want the libraries included by
1794 -- A to come after the libraries included by B.
1796 -- These two criteria are implemented by function Lt_Linker_Option.
1797 -- Note that a special case of b) is that specs are elaborated before
1798 -- bodies, so linker options from specs come after linker options
1799 -- for bodies, and again, the assumption is that libraries used by
1800 -- the body are more likely to reference libraries used by the spec,
1804 (Linker_Options.Last,
1805 Move_Linker_Option'Access,
1806 Lt_Linker_Option'Access);
1808 -- Write user linker options, i.e. the set of linker options that
1809 -- come from all files other than GNAT internal files, Lgnat is
1810 -- left set to point to the first entry from a GNAT internal file,
1811 -- or past the end of the entriers if there are no internal files.
1813 Lgnat := Linker_Options.Last + 1;
1815 for J in 1 .. Linker_Options.Last loop
1816 if not Linker_Options.Table (J).Internal_File then
1817 Get_Name_String (Linker_Options.Table (J).Name);
1818 Write_Linker_Option;
1825 -- Now we insert standard linker options that must appear after the
1826 -- entries from user files, and before the entries from GNAT run-time
1827 -- files. The reason for this decision is that libraries referenced
1828 -- by internal routines may reference these standard library entries.
1830 -- Note that we do not insert anything when pragma No_Run_Time has been
1831 -- specified or when the standard libraries are not to be used,
1832 -- otherwise on some platforms, such as VMS, we may get duplicate
1833 -- symbols when linking.
1835 if not (Opt.No_Run_Time_Mode or else Opt.No_Stdlib) then
1838 if Opt.Shared_Libgnat then
1839 Add_Str_To_Name_Buffer ("-shared");
1841 Add_Str_To_Name_Buffer ("-static");
1844 -- Write directly to avoid -K output (why???)
1846 Write_Info_Ada_C (" -- ", "", Name_Buffer (1 .. Name_Len));
1848 if With_DECGNAT then
1851 if Opt.Shared_Libgnat then
1852 Add_Str_To_Name_Buffer (Shared_Lib ("decgnat"));
1854 Add_Str_To_Name_Buffer ("-ldecgnat");
1857 Write_Linker_Option;
1863 if Opt.Shared_Libgnat then
1864 Add_Str_To_Name_Buffer (Shared_Lib ("gnarl"));
1866 Add_Str_To_Name_Buffer ("-lgnarl");
1869 Write_Linker_Option;
1874 if Opt.Shared_Libgnat then
1875 Add_Str_To_Name_Buffer (Shared_Lib ("gnat"));
1877 Add_Str_To_Name_Buffer ("-lgnat");
1880 Write_Linker_Option;
1883 -- Write linker options from all internal files
1885 for J in Lgnat .. Linker_Options.Last loop
1886 Get_Name_String (Linker_Options.Table (J).Name);
1887 Write_Linker_Option;
1890 if Ada_Bind_File then
1891 WBI ("-- END Object file/option list ");
1893 WBI (" END Object file/option list */");
1895 end Gen_Object_Files_Options;
1897 ---------------------
1898 -- Gen_Output_File --
1899 ---------------------
1901 procedure Gen_Output_File (Filename : String) is
1903 -- Acquire settings for Interrupt_State pragmas
1905 Set_IS_Pragma_Table;
1907 -- Acquire settings for Priority_Specific_Dispatching pragma
1909 Set_PSD_Pragma_Table;
1911 -- Override Ada_Bind_File and Bind_Main_Program for Java since
1912 -- JGNAT only supports Ada code, and the main program is already
1913 -- generated by the compiler.
1915 if Hostparm.Java_VM then
1916 Ada_Bind_File := True;
1917 Bind_Main_Program := False;
1920 -- Override time slice value if -T switch is set
1922 if Time_Slice_Set then
1923 ALIs.Table (ALIs.First).Time_Slice_Value := Opt.Time_Slice_Value;
1926 -- Count number of elaboration calls
1928 for E in Elab_Order.First .. Elab_Order.Last loop
1929 if Units.Table (Elab_Order.Table (E)).No_Elab then
1932 Num_Elab_Calls := Num_Elab_Calls + 1;
1936 -- Generate output file in appropriate language
1938 if Ada_Bind_File then
1939 Gen_Output_File_Ada (Filename);
1941 Gen_Output_File_C (Filename);
1944 end Gen_Output_File;
1946 -------------------------
1947 -- Gen_Output_File_Ada --
1948 -------------------------
1950 procedure Gen_Output_File_Ada (Filename : String) is
1953 -- Name of generated bind file (spec)
1956 -- Name of generated bind file (body)
1958 Ada_Main : constant String := Get_Ada_Main_Name;
1959 -- Name to be used for generated Ada main program. See the body of
1960 -- function Get_Ada_Main_Name for details on the form of the name.
1963 -- Create spec first
1965 Create_Binder_Output (Filename, 's', Bfiles);
1967 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
1968 -- then we need to make sure that the binder program is compiled with
1969 -- the same restriction, so that no exception tables are generated.
1971 if Cumulative_Restrictions.Set (No_Exception_Handlers) then
1972 WBI ("pragma Restrictions (No_Exception_Handlers);");
1975 -- Generate with of System so we can reference System.Address
1977 WBI ("with System;");
1979 -- Generate with of System.Initialize_Scalars if active
1981 if Initialize_Scalars_Used then
1982 WBI ("with System.Scalar_Values;");
1985 -- Generate with of System.Secondary_Stack if active
1987 if Sec_Stack_Used and then Default_Sec_Stack_Size /= -1 then
1988 WBI ("with System.Secondary_Stack;");
1991 Resolve_Binder_Options;
1993 if not Suppress_Standard_Library_On_Target then
1994 -- Usually, adafinal is called using a pragma Import C. Since
1995 -- Import C doesn't have the same semantics for JGNAT, we use
1998 if Hostparm.Java_VM then
1999 WBI ("with System.Standard_Library;");
2003 WBI ("package " & Ada_Main & " is");
2004 WBI (" pragma Warnings (Off);");
2006 -- Main program case
2008 if Bind_Main_Program then
2010 -- Generate argc/argv stuff unless suppressed
2012 if Command_Line_Args_On_Target
2013 or not Configurable_Run_Time_On_Target
2016 WBI (" gnat_argc : Integer;");
2017 WBI (" gnat_argv : System.Address;");
2018 WBI (" gnat_envp : System.Address;");
2020 -- If the standard library is not suppressed, these variables are
2021 -- in the runtime data area for easy access from the runtime
2023 if not Suppress_Standard_Library_On_Target then
2025 WBI (" pragma Import (C, gnat_argc);");
2026 WBI (" pragma Import (C, gnat_argv);");
2027 WBI (" pragma Import (C, gnat_envp);");
2031 -- Define exit status. Again in normal mode, this is in the
2032 -- run-time library, and is initialized there, but in the
2033 -- configurable runtime case, the variable is declared and
2034 -- initialized in this file.
2038 if Configurable_Run_Time_Mode then
2039 if Exit_Status_Supported_On_Target then
2040 WBI (" gnat_exit_status : Integer := 0;");
2043 WBI (" gnat_exit_status : Integer;");
2044 WBI (" pragma Import (C, gnat_exit_status);");
2048 -- Generate the GNAT_Version and Ada_Main_Program_Name info only for
2049 -- the main program. Otherwise, it can lead under some circumstances
2050 -- to a symbol duplication during the link (for instance when a
2051 -- C program uses 2 Ada libraries)
2053 if Bind_Main_Program then
2055 WBI (" GNAT_Version : constant String :=");
2056 WBI (" ""GNAT Version: " &
2057 Gnat_Version_String & """;");
2058 WBI (" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2061 Set_String (" Ada_Main_Program_Name : constant String := """);
2062 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2063 Set_Main_Program_Name;
2064 Set_String (""" & Ascii.NUL;");
2065 Write_Statement_Buffer;
2068 (" pragma Export (C, Ada_Main_Program_Name, " &
2069 """__gnat_ada_main_program_name"");");
2073 WBI (" procedure " & Ada_Final_Name.all & ";");
2074 WBI (" pragma Export (C, " & Ada_Final_Name.all & ", """ &
2075 Ada_Final_Name.all & """);");
2077 if Use_Pragma_Linker_Constructor then
2078 WBI (" pragma Linker_Destructor (" & Ada_Final_Name.all & ");");
2082 WBI (" procedure " & Ada_Init_Name.all & ";");
2083 WBI (" pragma Export (C, " & Ada_Init_Name.all & ", """ &
2084 Ada_Init_Name.all & """);");
2086 if Use_Pragma_Linker_Constructor then
2087 WBI (" pragma Linker_Constructor (" & Ada_Init_Name.all & ");");
2090 if Bind_Main_Program then
2092 -- If we have the standard library, then Break_Start is defined
2093 -- there, but when the standard library is suppressed, Break_Start
2097 WBI (" procedure Break_Start;");
2099 if Suppress_Standard_Library_On_Target then
2100 WBI (" pragma Export (C, Break_Start, ""__gnat_break_start"");");
2102 WBI (" pragma Import (C, Break_Start, ""__gnat_break_start"");");
2107 if Exit_Status_Supported_On_Target then
2108 Set_String (" function ");
2110 Set_String (" procedure ");
2113 Set_String (Get_Main_Name);
2115 -- Generate argument list if present
2117 if Command_Line_Args_On_Target then
2118 Write_Statement_Buffer;
2119 WBI (" (argc : Integer;");
2120 WBI (" argv : System.Address;");
2122 (" envp : System.Address)");
2124 if Exit_Status_Supported_On_Target then
2125 Write_Statement_Buffer;
2126 WBI (" return Integer;");
2128 Write_Statement_Buffer (";");
2132 if Exit_Status_Supported_On_Target then
2133 Write_Statement_Buffer (" return Integer;");
2135 Write_Statement_Buffer (";");
2139 WBI (" pragma Export (C, " & Get_Main_Name & ", """ &
2140 Get_Main_Name & """);");
2149 WBI ("end " & Ada_Main & ";");
2150 Close_Binder_Output;
2152 -- Prepare to write body
2154 Create_Binder_Output (Filename, 'b', Bfileb);
2156 -- Output Source_File_Name pragmas which look like
2158 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2159 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2161 -- where sss/bbb are the spec/body file names respectively
2163 Get_Name_String (Bfiles);
2164 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2166 WBI ("pragma Source_File_Name (" &
2168 ", Spec_File_Name => """ &
2169 Name_Buffer (1 .. Name_Len + 3));
2171 Get_Name_String (Bfileb);
2172 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := """);";
2174 WBI ("pragma Source_File_Name (" &
2176 ", Body_File_Name => """ &
2177 Name_Buffer (1 .. Name_Len + 3));
2179 -- Generate with of System.Restrictions to initialize
2180 -- Run_Time_Restrictions.
2182 if not Suppress_Standard_Library_On_Target then
2184 WBI ("with System.Restrictions;");
2188 WBI ("package body " & Ada_Main & " is");
2189 WBI (" pragma Warnings (Off);");
2191 -- Import the finalization procedure only if finalization active
2193 if not Cumulative_Restrictions.Set (No_Finalization) then
2195 -- In the Java case, pragma Import C cannot be used, so the
2196 -- standard Ada constructs will be used instead.
2198 if not Hostparm.Java_VM then
2200 WBI (" procedure Do_Finalize;");
2202 (" pragma Import (C, Do_Finalize, " &
2203 """system__standard_library__adafinal"");");
2208 if not Suppress_Standard_Library_On_Target then
2210 -- Generate Priority_Specific_Dispatching pragma string
2213 (" Local_Priority_Specific_Dispatching : constant String := """);
2215 for J in 0 .. PSD_Pragma_Settings.Last loop
2216 Set_Char (PSD_Pragma_Settings.Table (J));
2220 Write_Statement_Buffer;
2222 -- Generate Interrupt_State pragma string
2224 Set_String (" Local_Interrupt_States : constant String := """);
2226 for J in 0 .. IS_Pragma_Settings.Last loop
2227 Set_Char (IS_Pragma_Settings.Table (J));
2231 Write_Statement_Buffer;
2239 if Bind_Main_Program then
2241 -- When suppressing the standard library then generate dummy body
2244 if Suppress_Standard_Library_On_Target then
2246 WBI (" procedure Break_Start is");
2255 -- Output object file list and the Ada body is complete
2257 Gen_Object_Files_Options;
2260 WBI ("end " & Ada_Main & ";");
2262 Close_Binder_Output;
2263 end Gen_Output_File_Ada;
2265 -----------------------
2266 -- Gen_Output_File_C --
2267 -----------------------
2269 procedure Gen_Output_File_C (Filename : String) is
2272 -- Name of generated bind file
2275 Create_Binder_Output (Filename, 'c', Bfile);
2277 Resolve_Binder_Options;
2279 if Use_Pragma_Linker_Constructor then
2280 WBI ("extern void " & Ada_Final_Name.all &
2281 " (void) __attribute__((destructor));");
2282 WBI ("extern void " & Ada_Init_Name.all &
2283 " (void) __attribute__((constructor));");
2286 WBI ("extern void " & Ada_Final_Name.all & " (void);");
2287 WBI ("extern void " & Ada_Init_Name.all & " (void);");
2290 WBI ("extern void system__standard_library__adafinal (void);");
2292 if not No_Main_Subprogram then
2293 Set_String ("extern ");
2295 if Exit_Status_Supported_On_Target then
2298 Set_String ("void");
2301 Set_String (" main ");
2303 if Command_Line_Args_On_Target then
2304 Write_Statement_Buffer ("(int, char **, char **);");
2306 Write_Statement_Buffer ("(void);");
2309 if OpenVMS_On_Target then
2310 WBI ("extern void decc$__posix_exit (int);");
2312 WBI ("extern void exit (int);");
2315 WBI ("extern void __gnat_break_start (void);");
2316 Set_String ("extern ");
2318 if ALIs.Table (ALIs.First).Main_Program = Proc then
2319 Set_String ("void ");
2321 Set_String ("int ");
2324 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2325 Set_Main_Program_Name;
2326 Set_String (" (void);");
2327 Write_Statement_Buffer;
2330 if not Suppress_Standard_Library_On_Target then
2331 WBI ("extern void __gnat_initialize (void *);");
2332 WBI ("extern void __gnat_finalize (void);");
2333 WBI ("extern void __gnat_install_handler (void);");
2336 if Dynamic_Stack_Measurement then
2338 WBI ("extern void __gnat_stack_usage_output_results (void);");
2339 WBI ("extern void __gnat_stack_usage_initialize (int size);");
2346 -- Imported variable used to track elaboration/finalization phase.
2347 -- Used only when we have a runtime.
2349 if not Suppress_Standard_Library_On_Target then
2350 WBI ("extern int __gnat_handler_installed;");
2354 -- Write argv/argc exit status stuff if main program case
2356 if Bind_Main_Program then
2358 -- First deal with argc/argv/envp. In the normal case they
2359 -- are in the run-time library.
2361 if not Configurable_Run_Time_On_Target then
2362 WBI ("extern int gnat_argc;");
2363 WBI ("extern char **gnat_argv;");
2364 WBI ("extern char **gnat_envp;");
2366 -- If configurable run time and no command line args, then the
2367 -- generation of these variables is entirely suppressed.
2369 elsif not Command_Line_Args_On_Target then
2372 -- Otherwise, in the configurable run-time case they are right in
2376 WBI ("int gnat_argc;");
2377 WBI ("char **gnat_argv;");
2378 WBI ("char **gnat_envp;");
2381 -- Similarly deal with exit status
2382 -- are in the run-time library.
2384 if not Configurable_Run_Time_On_Target then
2385 WBI ("extern int gnat_exit_status;");
2387 -- If configurable run time and no exit status on target, then
2388 -- the generation of this variables is entirely suppressed.
2390 elsif not Exit_Status_Supported_On_Target then
2393 -- Otherwise, in the configurable run-time case this variable is
2394 -- right in the binder file, and initialized to zero there.
2397 WBI ("int gnat_exit_status = 0;");
2403 -- When suppressing the standard library, the __gnat_break_start
2404 -- routine (for the debugger to get initial control) is defined in
2407 if Suppress_Standard_Library_On_Target then
2409 WBI ("void __gnat_break_start (void) {}");
2412 -- Generate the __gnat_version and __gnat_ada_main_program_name info
2413 -- only for the main program. Otherwise, it can lead under some
2414 -- circumstances to a symbol duplication during the link (for instance
2415 -- when a C program uses 2 Ada libraries)
2417 if Bind_Main_Program then
2419 WBI ("char __gnat_version[] = ""GNAT Version: " &
2420 Gnat_Version_String & """;");
2422 Set_String ("char __gnat_ada_main_program_name[] = """);
2423 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2424 Set_Main_Program_Name;
2426 Write_Statement_Buffer;
2429 -- Generate the adafinal routine. In no runtime mode, this is
2430 -- not needed, since there is no finalization to do.
2432 if not Cumulative_Restrictions.Set (No_Finalization) then
2438 -- Main is only present for Ada main case
2440 if Bind_Main_Program then
2444 -- Generate versions, elaboration order, list of object files
2448 Gen_Object_Files_Options;
2450 -- C binder output is complete
2452 Close_Binder_Output;
2453 end Gen_Output_File_C;
2455 --------------------------
2456 -- Gen_Restrictions_Ada --
2457 --------------------------
2459 procedure Gen_Restrictions_Ada is
2462 if Suppress_Standard_Library_On_Target then
2466 WBI (" System.Restrictions.Run_Time_Restrictions :=");
2472 for J in Cumulative_Restrictions.Set'First ..
2473 Restriction_Id'Pred (Cumulative_Restrictions.Set'Last)
2475 Set_Boolean (Cumulative_Restrictions.Set (J));
2480 Write_Statement_Buffer;
2487 (Cumulative_Restrictions.Set (Cumulative_Restrictions.Set'Last));
2489 Write_Statement_Buffer;
2490 Set_String (" Value => (");
2492 for J in Cumulative_Restrictions.Value'First ..
2493 Restriction_Id'Pred (Cumulative_Restrictions.Value'Last)
2495 Set_Int (Int (Cumulative_Restrictions.Value (J)));
2499 Set_Int (Int (Cumulative_Restrictions.Value
2500 (Cumulative_Restrictions.Value'Last)));
2502 Write_Statement_Buffer;
2503 WBI (" Violated =>");
2507 for J in Cumulative_Restrictions.Violated'First ..
2508 Restriction_Id'Pred (Cumulative_Restrictions.Violated'Last)
2510 Set_Boolean (Cumulative_Restrictions.Violated (J));
2515 Write_Statement_Buffer;
2521 Set_Boolean (Cumulative_Restrictions.Violated
2522 (Cumulative_Restrictions.Violated'Last));
2524 Write_Statement_Buffer;
2525 Set_String (" Count => (");
2527 for J in Cumulative_Restrictions.Count'First ..
2528 Restriction_Id'Pred (Cumulative_Restrictions.Count'Last)
2530 Set_Int (Int (Cumulative_Restrictions.Count (J)));
2534 Set_Int (Int (Cumulative_Restrictions.Count
2535 (Cumulative_Restrictions.Count'Last)));
2537 Write_Statement_Buffer;
2538 Set_String (" Unknown => (");
2540 for J in Cumulative_Restrictions.Unknown'First ..
2541 Restriction_Id'Pred (Cumulative_Restrictions.Unknown'Last)
2543 Set_Boolean (Cumulative_Restrictions.Unknown (J));
2548 (Cumulative_Restrictions.Unknown
2549 (Cumulative_Restrictions.Unknown'Last));
2551 Write_Statement_Buffer;
2552 end Gen_Restrictions_Ada;
2554 ------------------------
2555 -- Gen_Restrictions_C --
2556 ------------------------
2558 procedure Gen_Restrictions_C is
2560 if Suppress_Standard_Library_On_Target then
2564 WBI (" typedef struct {");
2565 Set_String (" char set [");
2566 Set_Int (Cumulative_Restrictions.Set'Length);
2568 Write_Statement_Buffer;
2570 Set_String (" int value [");
2571 Set_Int (Cumulative_Restrictions.Value'Length);
2573 Write_Statement_Buffer;
2575 Set_String (" char violated [");
2576 Set_Int (Cumulative_Restrictions.Violated'Length);
2578 Write_Statement_Buffer;
2580 Set_String (" int count [");
2581 Set_Int (Cumulative_Restrictions.Count'Length);
2583 Write_Statement_Buffer;
2585 Set_String (" char unknown [");
2586 Set_Int (Cumulative_Restrictions.Unknown'Length);
2588 Write_Statement_Buffer;
2589 WBI (" } restrictions;");
2590 WBI (" extern restrictions " &
2591 "system__restrictions__run_time_restrictions;");
2592 WBI (" restrictions r = {");
2595 for J in Cumulative_Restrictions.Set'First ..
2596 Restriction_Id'Pred (Cumulative_Restrictions.Set'Last)
2598 Set_Int (Boolean'Pos (Cumulative_Restrictions.Set (J)));
2602 Set_Int (Boolean'Pos
2603 (Cumulative_Restrictions.Set (Cumulative_Restrictions.Set'Last)));
2605 Write_Statement_Buffer;
2608 for J in Cumulative_Restrictions.Value'First ..
2609 Restriction_Id'Pred (Cumulative_Restrictions.Value'Last)
2611 Set_Int (Int (Cumulative_Restrictions.Value (J)));
2615 Set_Int (Int (Cumulative_Restrictions.Value
2616 (Cumulative_Restrictions.Value'Last)));
2618 Write_Statement_Buffer;
2621 for J in Cumulative_Restrictions.Violated'First ..
2622 Restriction_Id'Pred (Cumulative_Restrictions.Violated'Last)
2624 Set_Int (Boolean'Pos (Cumulative_Restrictions.Violated (J)));
2628 Set_Int (Boolean'Pos (Cumulative_Restrictions.Violated
2629 (Cumulative_Restrictions.Violated'Last)));
2631 Write_Statement_Buffer;
2634 for J in Cumulative_Restrictions.Count'First ..
2635 Restriction_Id'Pred (Cumulative_Restrictions.Count'Last)
2637 Set_Int (Int (Cumulative_Restrictions.Count (J)));
2641 Set_Int (Int (Cumulative_Restrictions.Count
2642 (Cumulative_Restrictions.Count'Last)));
2644 Write_Statement_Buffer;
2647 for J in Cumulative_Restrictions.Unknown'First ..
2648 Restriction_Id'Pred (Cumulative_Restrictions.Unknown'Last)
2650 Set_Int (Boolean'Pos (Cumulative_Restrictions.Unknown (J)));
2654 Set_Int (Boolean'Pos (Cumulative_Restrictions.Unknown
2655 (Cumulative_Restrictions.Unknown'Last)));
2657 Write_Statement_Buffer;
2658 WBI (" system__restrictions__run_time_restrictions = r;");
2659 end Gen_Restrictions_C;
2661 ----------------------
2662 -- Gen_Versions_Ada --
2663 ----------------------
2665 -- This routine generates two sets of lines. The first set has the form:
2667 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2669 -- The second set has the form
2671 -- pragma Export (C, unnnnn, unam);
2673 -- for each unit, where unam is the unit name suffixed by either B or
2674 -- S for body or spec, with dots replaced by double underscores, and
2675 -- hhhhhhhh is the version number, and nnnnn is a 5-digits serial number.
2677 procedure Gen_Versions_Ada is
2678 Ubuf : String (1 .. 6) := "u00000";
2680 procedure Increment_Ubuf;
2681 -- Little procedure to increment the serial number
2683 procedure Increment_Ubuf is
2685 for J in reverse Ubuf'Range loop
2686 Ubuf (J) := Character'Succ (Ubuf (J));
2687 exit when Ubuf (J) <= '9';
2692 -- Start of processing for Gen_Versions_Ada
2695 if Bind_For_Library then
2697 -- When building libraries, the version number of each unit can
2698 -- not be computed, since the binder does not know the full list
2699 -- of units. Therefore, the 'Version and 'Body_Version
2700 -- attributes cannot supported in this case.
2707 WBI (" type Version_32 is mod 2 ** 32;");
2708 for U in Units.First .. Units.Last loop
2710 WBI (" " & Ubuf & " : constant Version_32 := 16#" &
2711 Units.Table (U).Version & "#;");
2717 for U in Units.First .. Units.Last loop
2719 Set_String (" pragma Export (C, ");
2721 Set_String (", """);
2723 Get_Name_String (Units.Table (U).Uname);
2725 for K in 1 .. Name_Len loop
2726 if Name_Buffer (K) = '.' then
2730 elsif Name_Buffer (K) = '%' then
2734 Set_Char (Name_Buffer (K));
2738 if Name_Buffer (Name_Len) = 's' then
2744 Set_String (""");");
2745 Write_Statement_Buffer;
2748 end Gen_Versions_Ada;
2750 --------------------
2751 -- Gen_Versions_C --
2752 --------------------
2754 -- This routine generates a line of the form:
2756 -- unsigned unam = 0xhhhhhhhh;
2758 -- for each unit, where unam is the unit name suffixed by either B or
2759 -- S for body or spec, with dots replaced by double underscores.
2761 procedure Gen_Versions_C is
2763 if Bind_For_Library then
2765 -- When building libraries, the version number of each unit can
2766 -- not be computed, since the binder does not know the full list
2767 -- of units. Therefore, the 'Version and 'Body_Version
2768 -- attributes cannot supported.
2773 for U in Units.First .. Units.Last loop
2774 Set_String ("unsigned ");
2776 Get_Name_String (Units.Table (U).Uname);
2778 for K in 1 .. Name_Len loop
2779 if Name_Buffer (K) = '.' then
2782 elsif Name_Buffer (K) = '%' then
2786 Set_Char (Name_Buffer (K));
2790 if Name_Buffer (Name_Len) = 's' then
2796 Set_String (" = 0x");
2797 Set_String (Units.Table (U).Version);
2799 Write_Statement_Buffer;
2804 -----------------------
2805 -- Get_Ada_Main_Name --
2806 -----------------------
2808 function Get_Ada_Main_Name return String is
2809 Suffix : constant String := "_00";
2810 Name : String (1 .. Opt.Ada_Main_Name.all'Length + Suffix'Length) :=
2811 Opt.Ada_Main_Name.all & Suffix;
2815 -- The main program generated by JGNAT expects a package called
2816 -- ada_<main procedure>.
2818 if Hostparm.Java_VM then
2819 -- Get main program name
2821 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2825 return "ada_" & Name_Buffer (1 .. Name_Len - 2);
2828 -- This loop tries the following possibilities in order
2834 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
2835 -- it is set to 'ada_main'.
2837 for J in 0 .. 99 loop
2839 Nlen := Name'Length - Suffix'Length;
2841 Nlen := Name'Length;
2842 Name (Name'Last) := Character'Val (J mod 10 + Character'Pos ('0'));
2843 Name (Name'Last - 1) :=
2844 Character'Val (J / 10 + Character'Pos ('0'));
2847 for K in ALIs.First .. ALIs.Last loop
2848 for L in ALIs.Table (K).First_Unit .. ALIs.Table (K).Last_Unit loop
2850 -- Get unit name, removing %b or %e at end
2852 Get_Name_String (Units.Table (L).Uname);
2853 Name_Len := Name_Len - 2;
2855 if Name_Buffer (1 .. Name_Len) = Name (1 .. Nlen) then
2861 return Name (1 .. Nlen);
2867 -- If we fall through, just use a peculiar unlikely name
2869 return ("Qwertyuiop");
2870 end Get_Ada_Main_Name;
2876 function Get_Main_Name return String is
2878 -- Explicit name given with -M switch
2880 if Bind_Alternate_Main_Name then
2881 return Alternate_Main_Name.all;
2883 -- Case of main program name to be used directly
2885 elsif Use_Ada_Main_Program_Name_On_Target then
2887 -- Get main program name
2889 Get_Name_String (Units.Table (First_Unit_Entry).Uname);
2891 -- If this is a child name, return only the name of the child,
2892 -- since we can't have dots in a nested program name. Note that
2893 -- we do not include the %b at the end of the unit name.
2895 for J in reverse 1 .. Name_Len - 2 loop
2896 if J = 1 or else Name_Buffer (J - 1) = '.' then
2897 return Name_Buffer (J .. Name_Len - 2);
2901 raise Program_Error; -- impossible exit
2903 -- Case where "main" is to be used as default
2910 ----------------------
2911 -- Lt_Linker_Option --
2912 ----------------------
2914 function Lt_Linker_Option (Op1, Op2 : Natural) return Boolean is
2916 -- Sort internal files last
2918 if Linker_Options.Table (Op1).Internal_File
2920 Linker_Options.Table (Op2).Internal_File
2922 -- Note: following test uses False < True
2924 return Linker_Options.Table (Op1).Internal_File
2926 Linker_Options.Table (Op2).Internal_File;
2928 -- If both internal or both non-internal, sort according to the
2929 -- elaboration position. A unit that is elaborated later should
2930 -- come earlier in the linker options list.
2933 return Units.Table (Linker_Options.Table (Op1).Unit).Elab_Position
2935 Units.Table (Linker_Options.Table (Op2).Unit).Elab_Position;
2938 end Lt_Linker_Option;
2940 ------------------------
2941 -- Move_Linker_Option --
2942 ------------------------
2944 procedure Move_Linker_Option (From : Natural; To : Natural) is
2946 Linker_Options.Table (To) := Linker_Options.Table (From);
2947 end Move_Linker_Option;
2949 ----------------------------
2950 -- Resolve_Binder_Options --
2951 ----------------------------
2953 procedure Resolve_Binder_Options is
2955 for E in Elab_Order.First .. Elab_Order.Last loop
2956 Get_Name_String (Units.Table (Elab_Order.Table (E)).Uname);
2958 -- The procedure of looking for specific packages and setting
2959 -- flags is somewhat dubious, but there isn't a good alternative
2960 -- at the current time ???
2962 if Name_Buffer (1 .. 19) = "system.os_interface" then
2966 if OpenVMS_On_Target and then Name_Buffer (1 .. 5) = "dec%s" then
2967 With_DECGNAT := True;
2970 end Resolve_Binder_Options;
2976 procedure Set_Boolean (B : Boolean) is
2977 True_Str : constant String := "True";
2978 False_Str : constant String := "False";
2981 Statement_Buffer (Last + 1 .. Last + True_Str'Length) := True_Str;
2982 Last := Last + True_Str'Length;
2984 Statement_Buffer (Last + 1 .. Last + False_Str'Length) := False_Str;
2985 Last := Last + False_Str'Length;
2993 procedure Set_Char (C : Character) is
2996 Statement_Buffer (Last) := C;
3003 procedure Set_Int (N : Int) is
3015 Statement_Buffer (Last) :=
3016 Character'Val (N mod 10 + Character'Pos ('0'));
3020 -------------------------
3021 -- Set_IS_Pragma_Table --
3022 -------------------------
3024 procedure Set_IS_Pragma_Table is
3026 for F in ALIs.First .. ALIs.Last loop
3027 for K in ALIs.Table (F).First_Interrupt_State ..
3028 ALIs.Table (F).Last_Interrupt_State
3031 Inum : constant Int :=
3032 Interrupt_States.Table (K).Interrupt_Id;
3033 Stat : constant Character :=
3034 Interrupt_States.Table (K).Interrupt_State;
3037 while IS_Pragma_Settings.Last < Inum loop
3038 IS_Pragma_Settings.Append ('n');
3041 IS_Pragma_Settings.Table (Inum) := Stat;
3045 end Set_IS_Pragma_Table;
3047 ---------------------------
3048 -- Set_Main_Program_Name --
3049 ---------------------------
3051 procedure Set_Main_Program_Name is
3053 -- Note that name has %b on the end which we ignore
3055 -- First we output the initial _ada_ since we know that the main
3056 -- program is a library level subprogram.
3058 Set_String ("_ada_");
3060 -- Copy name, changing dots to double underscores
3062 for J in 1 .. Name_Len - 2 loop
3063 if Name_Buffer (J) = '.' then
3066 Set_Char (Name_Buffer (J));
3069 end Set_Main_Program_Name;
3071 ---------------------
3072 -- Set_Name_Buffer --
3073 ---------------------
3075 procedure Set_Name_Buffer is
3077 for J in 1 .. Name_Len loop
3078 Set_Char (Name_Buffer (J));
3080 end Set_Name_Buffer;
3082 -------------------------
3083 -- Set_PSD_Pragma_Table --
3084 -------------------------
3086 procedure Set_PSD_Pragma_Table is
3088 for F in ALIs.First .. ALIs.Last loop
3089 for K in ALIs.Table (F).First_Specific_Dispatching ..
3090 ALIs.Table (F).Last_Specific_Dispatching
3093 DTK : Specific_Dispatching_Record
3094 renames Specific_Dispatching.Table (K);
3097 while PSD_Pragma_Settings.Last < DTK.Last_Priority loop
3098 PSD_Pragma_Settings.Append ('F');
3101 for Prio in DTK.First_Priority .. DTK.Last_Priority loop
3102 PSD_Pragma_Settings.Table (Prio) := DTK.Dispatching_Policy;
3107 end Set_PSD_Pragma_Table;
3113 procedure Set_String (S : String) is
3115 Statement_Buffer (Last + 1 .. Last + S'Length) := S;
3116 Last := Last + S'Length;
3123 procedure Set_Unit_Name is
3125 for J in 1 .. Name_Len - 2 loop
3126 if Name_Buffer (J) /= '.' then
3127 Set_Char (Name_Buffer (J));
3134 ---------------------
3135 -- Set_Unit_Number --
3136 ---------------------
3138 procedure Set_Unit_Number (U : Unit_Id) is
3139 Num_Units : constant Nat := Nat (Units.Last) - Nat (Unit_Id'First);
3140 Unum : constant Nat := Nat (U) - Nat (Unit_Id'First);
3143 if Num_Units >= 10 and then Unum < 10 then
3147 if Num_Units >= 100 and then Unum < 100 then
3152 end Set_Unit_Number;
3154 ----------------------
3155 -- Write_Info_Ada_C --
3156 ----------------------
3158 procedure Write_Info_Ada_C (Ada : String; C : String; Common : String) is
3160 if Ada_Bind_File then
3162 S : String (1 .. Ada'Length + Common'Length);
3164 S (1 .. Ada'Length) := Ada;
3165 S (Ada'Length + 1 .. S'Length) := Common;
3171 S : String (1 .. C'Length + Common'Length);
3173 S (1 .. C'Length) := C;
3174 S (C'Length + 1 .. S'Length) := Common;
3178 end Write_Info_Ada_C;
3180 ----------------------------
3181 -- Write_Statement_Buffer --
3182 ----------------------------
3184 procedure Write_Statement_Buffer is
3186 WBI (Statement_Buffer (1 .. Last));
3188 end Write_Statement_Buffer;
3190 procedure Write_Statement_Buffer (S : String) is
3193 Write_Statement_Buffer;
3194 end Write_Statement_Buffer;