1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 ----------------------------------
75 -- Interface_State Pragma Table --
76 ----------------------------------
78 -- This table assembles the interface state pragma information from
79 -- all the units in the partition. Note that Bcheck has already checked
80 -- that the information is consistent across units. The entries
81 -- in this table are n/u/r/s for not set/user/runtime/system.
83 package IS_Pragma_Settings
is new Table
.Table
(
84 Table_Component_Type
=> Character,
85 Table_Index_Type
=> Int
,
88 Table_Increment
=> 200,
89 Table_Name
=> "IS_Pragma_Settings");
91 -- This table assembles the Priority_Specific_Dispatching pragma
92 -- information from all the units in the partition. Note that Bcheck has
93 -- already checked that the information is consistent across units.
94 -- The entries in this table are the upper case first character of the
95 -- policy name, e.g. 'F' for FIFO_Within_Priorities.
97 package PSD_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
=> "PSD_Pragma_Settings");
105 ----------------------
106 -- Run-Time Globals --
107 ----------------------
109 -- This section documents the global variables that set from the
110 -- generated binder file.
112 -- Main_Priority : Integer;
113 -- Time_Slice_Value : Integer;
114 -- WC_Encoding : Character;
115 -- Locking_Policy : Character;
116 -- Queuing_Policy : Character;
117 -- Task_Dispatching_Policy : Character;
118 -- Priority_Specific_Dispatching : System.Address;
119 -- Num_Specific_Dispatching : Integer;
120 -- Restrictions : System.Address;
121 -- Interrupt_States : System.Address;
122 -- Num_Interrupt_States : Integer;
123 -- Unreserve_All_Interrupts : Integer;
124 -- Exception_Tracebacks : Integer;
125 -- Zero_Cost_Exceptions : Integer;
126 -- Detect_Blocking : Integer;
127 -- Default_Stack_Size : Integer;
128 -- Leap_Seconds_Support : Integer;
130 -- Main_Priority is the priority value set by pragma Priority in the
131 -- main program. If no such pragma is present, the value is -1.
133 -- Time_Slice_Value is the time slice value set by pragma Time_Slice
134 -- in the main program, or by the use of a -Tnnn parameter for the
135 -- binder (if both are present, the binder value overrides). The
136 -- value is in milliseconds. A value of zero indicates that time
137 -- slicing should be suppressed. If no pragma is present, and no
138 -- -T switch was used, the value is -1.
140 -- WC_Encoding shows the wide character encoding method used for
141 -- the main program. This is one of the encoding letters defined
142 -- in System.WCh_Con.WC_Encoding_Letters.
144 -- Locking_Policy is a space if no locking policy was specified
145 -- for the partition. If a locking policy was specified, the value
146 -- is the upper case first character of the locking policy name,
147 -- for example, 'C' for Ceiling_Locking.
149 -- Queuing_Policy is a space if no queuing policy was specified
150 -- for the partition. If a queuing policy was specified, the value
151 -- is the upper case first character of the queuing policy name
152 -- for example, 'F' for FIFO_Queuing.
154 -- Task_Dispatching_Policy is a space if no task dispatching policy
155 -- was specified for the partition. If a task dispatching policy
156 -- was specified, the value is the upper case first character of
157 -- the policy name, e.g. 'F' for FIFO_Within_Priorities.
159 -- Priority_Specific_Dispatching is the address of a string used to
160 -- store the task dispatching policy specified for the different priorities
161 -- in the partition. The length of this string is determined by the last
162 -- priority for which such a pragma applies (the string will be a null
163 -- string if no specific dispatching policies were used). If pragma were
164 -- present, the entries apply to the priorities in sequence from the first
165 -- priority. The value stored is the upper case first character of the
166 -- policy name, or 'F' (for FIFO_Within_Priorities) as the default value
167 -- for those priority ranges not specified.
169 -- Num_Specific_Dispatching is the length of the
170 -- Priority_Specific_Dispatching string. It will be set to zero if no
171 -- Priority_Specific_Dispatching pragmas are present.
173 -- Restrictions is the address of a null-terminated string specifying the
174 -- restrictions information for the partition. The format is identical to
175 -- that of the parameter string found on R lines in ali files (see Lib.Writ
176 -- spec in lib-writ.ads for full details). The difference is that in this
177 -- context the values are the cumulative ones for the entire partition.
179 -- Interrupt_States is the address of a string used to specify the
180 -- cumulative results of Interrupt_State pragmas used in the partition.
181 -- The length of this string is determined by the last interrupt for which
182 -- such a pragma is given (the string will be a null string if no pragmas
183 -- were used). If pragma were present the entries apply to the interrupts
184 -- in sequence from the first interrupt, and are set to one of four
185 -- possible settings: 'n' for not specified, 'u' for user, 'r' for
186 -- run time, 's' for system, see description of Interrupt_State pragma
187 -- for further details.
189 -- Num_Interrupt_States is the length of the Interrupt_States string.
190 -- It will be set to zero if no Interrupt_State pragmas are present.
192 -- Unreserve_All_Interrupts is set to one if at least one unit in the
193 -- partition had a pragma Unreserve_All_Interrupts, and zero otherwise.
195 -- Exception_Tracebacks is set to one if the -E parameter was present
196 -- in the bind and to zero otherwise. Note that on some targets exception
197 -- tracebacks are provided by default, so a value of zero for this
198 -- parameter does not necessarily mean no trace backs are available.
200 -- Zero_Cost_Exceptions is set to one if zero cost exceptions are used for
201 -- this partition, and to zero if longjmp/setjmp exceptions are used.
204 -- Detect_Blocking indicates whether pragma Detect_Blocking is
205 -- active or not. A value of zero indicates that the pragma is not
206 -- present, while a value of 1 signals its presence in the
209 -- Default_Stack_Size is the default stack size used when creating an
210 -- Ada task with no explicit Storize_Size clause.
212 -- Leap_Seconds_Support denotes whether leap seconds have been enabled or
213 -- disabled. A value of zero indicates that leap seconds are turned "off",
214 -- while a value of one signifies "on" status.
216 -----------------------
217 -- Local Subprograms --
218 -----------------------
220 procedure WBI
(Info
: String) renames Osint
.B
.Write_Binder_Info
;
221 -- Convenient shorthand used throughout
223 procedure Check_System_Restrictions_Used
;
224 -- Sets flag System_Restrictions_Used (Set to True if and only if the unit
225 -- System.Restrictions is present in the partition, otherwise False).
227 procedure Gen_Adainit_Ada
;
228 -- Generates the Adainit procedure (Ada code case)
230 procedure Gen_Adainit_C
;
231 -- Generates the Adainit procedure (C code case)
233 procedure Gen_Adafinal_Ada
;
234 -- Generate the Adafinal procedure (Ada code case)
236 procedure Gen_Adafinal_C
;
237 -- Generate the Adafinal procedure (C code case)
239 procedure Gen_Elab_Calls_Ada
;
240 -- Generate sequence of elaboration calls (Ada code case)
242 procedure Gen_Elab_Calls_C
;
243 -- Generate sequence of elaboration calls (C code case)
245 procedure Gen_Elab_Order_Ada
;
246 -- Generate comments showing elaboration order chosen (Ada case)
248 procedure Gen_Elab_Order_C
;
249 -- Generate comments showing elaboration order chosen (C case)
251 procedure Gen_Elab_Defs_C
;
252 -- Generate sequence of definitions for elaboration routines (C code case)
254 procedure Gen_Main_Ada
;
255 -- Generate procedure main (Ada code case)
257 procedure Gen_Main_C
;
258 -- Generate main() procedure (C code case)
260 procedure Gen_Object_Files_Options
;
261 -- Output comments containing a list of the full names of the object
262 -- files to be linked and the list of linker options supplied by
263 -- Linker_Options pragmas in the source. (C and Ada code case)
265 procedure Gen_Output_File_Ada
(Filename
: String);
266 -- Generate output file (Ada code case)
268 procedure Gen_Output_File_C
(Filename
: String);
269 -- Generate output file (C code case)
271 procedure Gen_Restrictions_Ada
;
272 -- Generate initialization of restrictions variable (Ada code case)
274 procedure Gen_Restrictions_C
;
275 -- Generate initialization of restrictions variable (C code case)
277 procedure Gen_Versions_Ada
;
278 -- Output series of definitions for unit versions (Ada code case)
280 procedure Gen_Versions_C
;
281 -- Output series of definitions for unit versions (C code case)
283 function Get_Ada_Main_Name
return String;
284 -- This function is used in the Ada main output case to compute a usable
285 -- name for the generated main program. The normal main program name is
286 -- Ada_Main, but this won't work if the user has a unit with this name.
287 -- This function tries Ada_Main first, and if there is such a clash, then
288 -- it tries Ada_Name_01, Ada_Name_02 ... Ada_Name_99 in sequence.
290 function Get_Main_Unit_Name
(S
: String) return String;
291 -- Return the main unit name corresponding to S by replacing '.' with '_'
293 function Get_Main_Name
return String;
294 -- This function is used in the Ada main output case to compute the
295 -- correct external main program. It is "main" by default, unless the
296 -- flag Use_Ada_Main_Program_Name_On_Target is set, in which case it
297 -- is the name of the Ada main name without the "_ada". This default
298 -- can be overridden explicitly using the -Mname binder switch.
300 function Get_WC_Encoding
return Character;
301 -- Return wide character encoding method to set as WC_Encoding in output.
302 -- If -W has been used, returns the specified encoding, otherwise returns
303 -- the encoding method used for the main program source. If there is no
304 -- main program source (-z switch used), returns brackets ('b').
306 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean;
307 -- Compare linker options, when sorting, first according to
308 -- Is_Internal_File (internal files come later) and then by
309 -- elaboration order position (latest to earliest).
311 procedure Move_Linker_Option
(From
: Natural; To
: Natural);
312 -- Move routine for sorting linker options
314 procedure Resolve_Binder_Options
;
315 -- Set the value of With_GNARL and With_DECGNAT. The latter only on VMS
316 -- since it tests for a package named "dec" which might cause a conflict
317 -- on non-VMS systems.
319 procedure Set_Char
(C
: Character);
320 -- Set given character in Statement_Buffer at the Last + 1 position
321 -- and increment Last by one to reflect the stored character.
323 procedure Set_Int
(N
: Int
);
324 -- Set given value in decimal in Statement_Buffer with no spaces
325 -- starting at the Last + 1 position, and updating Last past the value.
326 -- A minus sign is output for a negative value.
328 procedure Set_Boolean
(B
: Boolean);
329 -- Set given boolean value in Statement_Buffer at the Last + 1 position
330 -- and update Last past the value.
332 procedure Set_IS_Pragma_Table
;
333 -- Initializes contents of IS_Pragma_Settings table from ALI table
335 procedure Set_Main_Program_Name
;
336 -- Given the main program name in Name_Buffer (length in Name_Len)
337 -- generate the name of the routine to be used in the call. The name
338 -- is generated starting at Last + 1, and Last is updated past it.
340 procedure Set_Name_Buffer
;
341 -- Set the value stored in positions 1 .. Name_Len of the Name_Buffer
343 procedure Set_PSD_Pragma_Table
;
344 -- Initializes contents of PSD_Pragma_Settings table from ALI table
346 procedure Set_String
(S
: String);
347 -- Sets characters of given string in Statement_Buffer, starting at the
348 -- Last + 1 position, and updating last past the string value.
350 procedure Set_Unit_Name
;
351 -- Given a unit name in the Name_Buffer, copies it to Statement_Buffer,
352 -- starting at the Last + 1 position, and updating last past the value.
353 -- changing periods to double underscores, and updating Last appropriately.
355 procedure Set_Unit_Number
(U
: Unit_Id
);
356 -- Sets unit number (first unit is 1, leading zeroes output to line
357 -- up all output unit numbers nicely as required by the value, and
358 -- by the total number of units.
360 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String);
361 -- For C code case, write C & Common, for Ada case write Ada & Common
362 -- to current binder output file using Write_Binder_Info.
364 procedure Write_Statement_Buffer
;
365 -- Write out contents of statement buffer up to Last, and reset Last to 0
367 procedure Write_Statement_Buffer
(S
: String);
368 -- First writes its argument (using Set_String (S)), then writes out the
369 -- contents of statement buffer up to Last, and reset Last to 0
371 ------------------------------------
372 -- Check_System_Restrictions_Used --
373 ------------------------------------
375 procedure Check_System_Restrictions_Used
is
377 for J
in Units
.First
.. Units
.Last
loop
378 if Get_Name_String
(Units
.Table
(J
).Sfile
) = "s-restri.ads" then
379 System_Restrictions_Used
:= True;
384 System_Restrictions_Used
:= False;
385 end Check_System_Restrictions_Used
;
387 ----------------------
388 -- Gen_Adafinal_Ada --
389 ----------------------
391 procedure Gen_Adafinal_Ada
is
394 WBI
(" procedure " & Ada_Final_Name
.all & " is");
397 -- If compiling for the JVM, we directly call Adafinal because
398 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
400 if VM_Target
/= No_VM
then
401 WBI
(" System.Standard_Library.Adafinal;");
403 -- If there is no finalization, there is nothing to do
405 elsif Cumulative_Restrictions
.Set
(No_Finalization
) then
408 WBI
(" Do_Finalize;");
411 WBI
(" end " & Ada_Final_Name
.all & ";");
412 end Gen_Adafinal_Ada
;
418 procedure Gen_Adafinal_C
is
420 WBI
("void " & Ada_Final_Name
.all & " (void) {");
421 WBI
(" system__standard_library__adafinal ();");
426 ---------------------
427 -- Gen_Adainit_Ada --
428 ---------------------
430 procedure Gen_Adainit_Ada
is
431 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
434 WBI
(" procedure " & Ada_Init_Name
.all & " is");
436 -- Generate externals for elaboration entities
438 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
440 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
441 U
: Unit_Record
renames Units
.Table
(Unum
);
444 -- Check for Elab_Entity to be set for this unit
448 -- Don't generate reference for stand alone library
450 and then not U
.SAL_Interface
452 -- Don't generate reference for predefined file in No_Run_Time
453 -- mode, since we don't include the object files in this case
457 and then Is_Predefined_File_Name
(U
.Sfile
))
461 Set_Unit_Number
(Unum
);
464 when No_VM | JVM_Target
=>
465 Set_String
(" : Boolean; pragma Import (Ada, ");
467 Set_String
(" : Boolean; pragma Import (CIL, ");
471 Set_Unit_Number
(Unum
);
473 Get_Name_String
(U
.Uname
);
475 -- In the case of JGNAT we need to emit an Import name
476 -- that includes the class name (using '$' separators
477 -- in the case of a child unit name).
479 if VM_Target
/= No_VM
then
480 for J
in 1 .. Name_Len
- 2 loop
481 if VM_Target
= CLI_Target
482 or else Name_Buffer
(J
) /= '.'
484 Set_Char
(Name_Buffer
(J
));
490 if VM_Target
/= CLI_Target
or else U
.Unit_Kind
= 's' then
493 Set_String
("_pkg.");
496 -- If the unit name is very long, then split the
497 -- Import link name across lines using "&" (occurs
498 -- in some C2 tests).
500 if 2 * Name_Len
+ 60 > Hostparm
.Max_Line_Length
then
502 Write_Statement_Buffer
;
508 Set_String
("_E"");");
509 Write_Statement_Buffer
;
514 Write_Statement_Buffer
;
516 -- If the standard library is suppressed, then the only global variable
517 -- that might be needed (by the Ravenscar profile) is the priority of
520 if Suppress_Standard_Library_On_Target
then
521 if Main_Priority
/= No_Main_Priority
then
522 WBI
(" Main_Priority : Integer;");
523 WBI
(" pragma Import (C, Main_Priority," &
524 " ""__gl_main_priority"");");
530 if Main_Priority
/= No_Main_Priority
then
531 Set_String
(" Main_Priority := ");
532 Set_Int
(Main_Priority
);
534 Write_Statement_Buffer
;
540 -- Normal case (standard library not suppressed). Set all global values
541 -- used by the run time.
544 WBI
(" Main_Priority : Integer;");
545 WBI
(" pragma Import (C, Main_Priority, " &
546 """__gl_main_priority"");");
547 WBI
(" Time_Slice_Value : Integer;");
548 WBI
(" pragma Import (C, Time_Slice_Value, " &
549 """__gl_time_slice_val"");");
550 WBI
(" WC_Encoding : Character;");
551 WBI
(" pragma Import (C, WC_Encoding, ""__gl_wc_encoding"");");
552 WBI
(" Locking_Policy : Character;");
553 WBI
(" pragma Import (C, Locking_Policy, " &
554 """__gl_locking_policy"");");
555 WBI
(" Queuing_Policy : Character;");
556 WBI
(" pragma Import (C, Queuing_Policy, " &
557 """__gl_queuing_policy"");");
558 WBI
(" Task_Dispatching_Policy : Character;");
559 WBI
(" pragma Import (C, Task_Dispatching_Policy, " &
560 """__gl_task_dispatching_policy"");");
561 WBI
(" Priority_Specific_Dispatching : System.Address;");
562 WBI
(" pragma Import (C, Priority_Specific_Dispatching, " &
563 """__gl_priority_specific_dispatching"");");
564 WBI
(" Num_Specific_Dispatching : Integer;");
565 WBI
(" pragma Import (C, Num_Specific_Dispatching, " &
566 """__gl_num_specific_dispatching"");");
568 WBI
(" Interrupt_States : System.Address;");
569 WBI
(" pragma Import (C, Interrupt_States, " &
570 """__gl_interrupt_states"");");
571 WBI
(" Num_Interrupt_States : Integer;");
572 WBI
(" pragma Import (C, Num_Interrupt_States, " &
573 """__gl_num_interrupt_states"");");
574 WBI
(" Unreserve_All_Interrupts : Integer;");
575 WBI
(" pragma Import (C, Unreserve_All_Interrupts, " &
576 """__gl_unreserve_all_interrupts"");");
578 if Exception_Tracebacks
then
579 WBI
(" Exception_Tracebacks : Integer;");
580 WBI
(" pragma Import (C, Exception_Tracebacks, " &
581 """__gl_exception_tracebacks"");");
584 WBI
(" Zero_Cost_Exceptions : Integer;");
585 WBI
(" pragma Import (C, Zero_Cost_Exceptions, " &
586 """__gl_zero_cost_exceptions"");");
587 WBI
(" Detect_Blocking : Integer;");
588 WBI
(" pragma Import (C, Detect_Blocking, " &
589 """__gl_detect_blocking"");");
590 WBI
(" Default_Stack_Size : Integer;");
591 WBI
(" pragma Import (C, Default_Stack_Size, " &
592 """__gl_default_stack_size"");");
593 WBI
(" Leap_Seconds_Support : Integer;");
594 WBI
(" pragma Import (C, Leap_Seconds_Support, " &
595 """__gl_leap_seconds_support"");");
597 -- Import entry point for elaboration time signal handler
598 -- installation, and indication of if it's been called previously.
601 WBI
(" procedure Install_Handler;");
602 WBI
(" pragma Import (C, Install_Handler, " &
603 """__gnat_install_handler"");");
605 WBI
(" Handler_Installed : Integer;");
606 WBI
(" pragma Import (C, Handler_Installed, " &
607 """__gnat_handler_installed"");");
609 -- Initialize stack limit variable of the environment task if the
610 -- stack check method is stack limit and stack check is enabled.
612 if Stack_Check_Limits_On_Target
613 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
616 WBI
(" procedure Initialize_Stack_Limit;");
617 WBI
(" pragma Import (C, Initialize_Stack_Limit, " &
618 """__gnat_initialize_stack_limit"");");
621 -- Special processing when main program is CIL function/procedure
623 if VM_Target
= CLI_Target
624 and then Bind_Main_Program
625 and then not No_Main_Subprogram
629 -- Function case, use Set_Exit_Status to report the returned
630 -- status code, since that is the only mechanism available.
632 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
633 WBI
(" Result : Integer;");
634 WBI
(" procedure Set_Exit_Status (Code : Integer);");
635 WBI
(" pragma Import (C, Set_Exit_Status, " &
636 """__gnat_set_exit_status"");");
638 WBI
(" function Ada_Main_Program return Integer;");
643 WBI
(" procedure Ada_Main_Program;");
646 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
647 Name_Len
:= Name_Len
- 2;
648 WBI
(" pragma Import (CIL, Ada_Main_Program, """
649 & Name_Buffer
(1 .. Name_Len
) & "."
650 & Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
)) & """);");
655 Set_String
(" Main_Priority := ");
656 Set_Int
(Main_Priority
);
658 Write_Statement_Buffer
;
660 Set_String
(" Time_Slice_Value := ");
662 if Task_Dispatching_Policy_Specified
= 'F'
663 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
667 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
671 Write_Statement_Buffer
;
673 Set_String
(" WC_Encoding := '");
674 Set_Char
(Get_WC_Encoding
);
677 Write_Statement_Buffer
;
679 Set_String
(" Locking_Policy := '");
680 Set_Char
(Locking_Policy_Specified
);
682 Write_Statement_Buffer
;
684 Set_String
(" Queuing_Policy := '");
685 Set_Char
(Queuing_Policy_Specified
);
687 Write_Statement_Buffer
;
689 Set_String
(" Task_Dispatching_Policy := '");
690 Set_Char
(Task_Dispatching_Policy_Specified
);
692 Write_Statement_Buffer
;
694 Gen_Restrictions_Ada
;
696 WBI
(" Priority_Specific_Dispatching :=");
697 WBI
(" Local_Priority_Specific_Dispatching'Address;");
699 Set_String
(" Num_Specific_Dispatching := ");
700 Set_Int
(PSD_Pragma_Settings
.Last
+ 1);
702 Write_Statement_Buffer
;
704 WBI
(" Interrupt_States := Local_Interrupt_States'Address;");
706 Set_String
(" Num_Interrupt_States := ");
707 Set_Int
(IS_Pragma_Settings
.Last
+ 1);
709 Write_Statement_Buffer
;
711 Set_String
(" Unreserve_All_Interrupts := ");
713 if Unreserve_All_Interrupts_Specified
then
720 Write_Statement_Buffer
;
722 if Exception_Tracebacks
then
723 WBI
(" Exception_Tracebacks := 1;");
726 Set_String
(" Zero_Cost_Exceptions := ");
728 if Zero_Cost_Exceptions_Specified
then
735 Write_Statement_Buffer
;
737 Set_String
(" Detect_Blocking := ");
739 if Detect_Blocking
then
746 Write_Statement_Buffer
;
748 Set_String
(" Default_Stack_Size := ");
749 Set_Int
(Default_Stack_Size
);
751 Write_Statement_Buffer
;
753 Set_String
(" Leap_Seconds_Support := ");
755 if Leap_Seconds_Support
then
762 Write_Statement_Buffer
;
764 -- Generate call to Install_Handler
767 WBI
(" if Handler_Installed = 0 then");
768 WBI
(" Install_Handler;");
772 -- Generate call to set Initialize_Scalar values if active
774 if Initialize_Scalars_Used
then
776 Set_String
(" System.Scalar_Values.Initialize ('");
777 Set_Char
(Initialize_Scalars_Mode1
);
779 Set_Char
(Initialize_Scalars_Mode2
);
781 Write_Statement_Buffer
;
784 -- Generate assignment of default secondary stack size if set
786 if Sec_Stack_Used
and then Default_Sec_Stack_Size
/= -1 then
788 Set_String
(" System.Secondary_Stack.");
789 Set_String
("Default_Secondary_Stack_Size := ");
790 Set_Int
(Opt
.Default_Sec_Stack_Size
);
792 Write_Statement_Buffer
;
795 -- Initialize stack limit variable of the environment task if the
796 -- stack check method is stack limit and stack check is enabled.
798 if Stack_Check_Limits_On_Target
799 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
802 WBI
(" Initialize_Stack_Limit;");
805 -- Generate elaboration calls
810 -- Case of main program is CIL function or procedure
812 if VM_Target
= CLI_Target
813 and then Bind_Main_Program
814 and then not No_Main_Subprogram
816 -- For function case, use Set_Exit_Status to set result
818 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
819 WBI
(" Result := Ada_Main_Program;");
820 WBI
(" Set_Exit_Status (Result);");
825 WBI
(" Ada_Main_Program;");
829 WBI
(" end " & Ada_Init_Name
.all & ";");
836 procedure Gen_Adainit_C
is
837 Main_Priority
: Int
renames ALIs
.Table
(ALIs
.First
).Main_Priority
;
840 WBI
("void " & Ada_Init_Name
.all & " (void)");
843 -- Generate externals for elaboration entities
845 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
847 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
848 U
: Unit_Record
renames Units
.Table
(Unum
);
851 -- Check for Elab entity to be set for this unit
855 -- Don't generate reference for stand alone library
857 and then not U
.SAL_Interface
859 -- Don't generate reference for predefined file in No_Run_Time
860 -- mode, since we don't include the object files in this case
864 and then Is_Predefined_File_Name
(U
.Sfile
))
866 Set_String
(" extern char ");
867 Get_Name_String
(U
.Uname
);
870 Write_Statement_Buffer
;
875 Write_Statement_Buffer
;
877 -- Standard library suppressed
879 if Suppress_Standard_Library_On_Target
then
881 -- Case of High_Integrity_Mode mode. Set __gl_main_priority if needed
882 -- for the Ravenscar profile.
884 if Main_Priority
/= No_Main_Priority
then
885 WBI
(" extern int __gl_main_priority;");
886 Set_String
(" __gl_main_priority = ");
887 Set_Int
(Main_Priority
);
889 Write_Statement_Buffer
;
892 -- Normal case (standard library not suppressed)
895 -- Generate definition for interrupt states string
897 Set_String
(" static const char *local_interrupt_states = """);
899 for J
in 0 .. IS_Pragma_Settings
.Last
loop
900 Set_Char
(IS_Pragma_Settings
.Table
(J
));
904 Write_Statement_Buffer
;
906 -- Generate definition for priority specific dispatching string
909 (" static const char *local_priority_specific_dispatching = """);
911 for J
in 0 .. PSD_Pragma_Settings
.Last
loop
912 Set_Char
(PSD_Pragma_Settings
.Table
(J
));
916 Write_Statement_Buffer
;
918 -- Generate declaration for secondary stack default if needed
920 if Sec_Stack_Used
and then Default_Sec_Stack_Size
/= -1 then
921 WBI
(" extern int system__secondary_stack__" &
922 "default_secondary_stack_size;");
927 -- Code for normal case (standard library not suppressed)
929 -- We call the routine from inside adainit() because this works for
930 -- both programs with and without binder generated "main" functions.
932 WBI
(" extern int __gl_main_priority;");
933 Set_String
(" __gl_main_priority = ");
934 Set_Int
(Main_Priority
);
936 Write_Statement_Buffer
;
938 WBI
(" extern int __gl_time_slice_val;");
939 Set_String
(" __gl_time_slice_val = ");
941 if Task_Dispatching_Policy
= 'F'
942 and then ALIs
.Table
(ALIs
.First
).Time_Slice_Value
= -1
946 Set_Int
(ALIs
.Table
(ALIs
.First
).Time_Slice_Value
);
950 Write_Statement_Buffer
;
952 WBI
(" extern char __gl_wc_encoding;");
953 Set_String
(" __gl_wc_encoding = '");
954 Set_Char
(Get_WC_Encoding
);
957 Write_Statement_Buffer
;
959 WBI
(" extern char __gl_locking_policy;");
960 Set_String
(" __gl_locking_policy = '");
961 Set_Char
(Locking_Policy_Specified
);
963 Write_Statement_Buffer
;
965 WBI
(" extern char __gl_queuing_policy;");
966 Set_String
(" __gl_queuing_policy = '");
967 Set_Char
(Queuing_Policy_Specified
);
969 Write_Statement_Buffer
;
971 WBI
(" extern char __gl_task_dispatching_policy;");
972 Set_String
(" __gl_task_dispatching_policy = '");
973 Set_Char
(Task_Dispatching_Policy_Specified
);
975 Write_Statement_Buffer
;
979 WBI
(" extern const void *__gl_interrupt_states;");
980 WBI
(" __gl_interrupt_states = local_interrupt_states;");
982 WBI
(" extern int __gl_num_interrupt_states;");
983 Set_String
(" __gl_num_interrupt_states = ");
984 Set_Int
(IS_Pragma_Settings
.Last
+ 1);
986 Write_Statement_Buffer
;
988 WBI
(" extern const void *__gl_priority_specific_dispatching;");
989 WBI
(" __gl_priority_specific_dispatching =" &
990 " local_priority_specific_dispatching;");
992 WBI
(" extern int __gl_num_specific_dispatching;");
993 Set_String
(" __gl_num_specific_dispatching = ");
994 Set_Int
(PSD_Pragma_Settings
.Last
+ 1);
996 Write_Statement_Buffer
;
998 WBI
(" extern int __gl_unreserve_all_interrupts;");
999 Set_String
(" __gl_unreserve_all_interrupts = ");
1000 Set_Int
(Boolean'Pos (Unreserve_All_Interrupts_Specified
));
1002 Write_Statement_Buffer
;
1004 if Exception_Tracebacks
then
1005 WBI
(" extern int __gl_exception_tracebacks;");
1006 WBI
(" __gl_exception_tracebacks = 1;");
1009 WBI
(" extern int __gl_zero_cost_exceptions;");
1010 Set_String
(" __gl_zero_cost_exceptions = ");
1011 Set_Int
(Boolean'Pos (Zero_Cost_Exceptions_Specified
));
1013 Write_Statement_Buffer
;
1015 WBI
(" extern int __gl_detect_blocking;");
1016 Set_String
(" __gl_detect_blocking = ");
1018 if Detect_Blocking
then
1025 Write_Statement_Buffer
;
1027 WBI
(" extern int __gl_default_stack_size;");
1028 Set_String
(" __gl_default_stack_size = ");
1029 Set_Int
(Default_Stack_Size
);
1031 Write_Statement_Buffer
;
1033 WBI
(" extern int __gl_leap_seconds_support;");
1034 Set_String
(" __gl_leap_seconds_support = ");
1036 if Leap_Seconds_Support
then
1043 Write_Statement_Buffer
;
1047 -- Install elaboration time signal handler
1049 WBI
(" if (__gnat_handler_installed == 0)");
1051 WBI
(" __gnat_install_handler ();");
1055 -- Initialize stack limit for the environment task if the stack
1056 -- check method is stack limit and stack check is enabled.
1058 if Stack_Check_Limits_On_Target
1059 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
1062 WBI
(" __gnat_initialize_stack_limit ();");
1065 -- Generate call to set Initialize_Scalar values if needed
1067 if Initialize_Scalars_Used
then
1069 Set_String
(" system__scalar_values__initialize('");
1070 Set_Char
(Initialize_Scalars_Mode1
);
1071 Set_String
("', '");
1072 Set_Char
(Initialize_Scalars_Mode2
);
1074 Write_Statement_Buffer
;
1077 -- Generate assignment of default secondary stack size if set
1079 if Sec_Stack_Used
and then Default_Sec_Stack_Size
/= -1 then
1081 Set_String
(" system__secondary_stack__");
1082 Set_String
("default_secondary_stack_size = ");
1083 Set_Int
(Opt
.Default_Sec_Stack_Size
);
1085 Write_Statement_Buffer
;
1088 -- Generate elaboration calls
1095 ------------------------
1096 -- Gen_Elab_Calls_Ada --
1097 ------------------------
1099 procedure Gen_Elab_Calls_Ada
is
1101 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1103 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
1104 U
: Unit_Record
renames Units
.Table
(Unum
);
1106 Unum_Spec
: Unit_Id
;
1107 -- This is the unit number of the spec that corresponds to
1108 -- this entry. It is the same as Unum except when the body
1109 -- and spec are different and we are currently processing
1110 -- the body, in which case it is the spec (Unum + 1).
1113 if U
.Utype
= Is_Body
then
1114 Unum_Spec
:= Unum
+ 1;
1119 -- Nothing to do if predefined unit in no run time mode
1121 if No_Run_Time_Mode
and then Is_Predefined_File_Name
(U
.Sfile
) then
1124 -- Case of no elaboration code
1126 elsif U
.No_Elab
then
1128 -- The only case in which we have to do something is if
1129 -- this is a body, with a separate spec, where the separate
1130 -- spec has an elaboration entity defined.
1132 -- In that case, this is where we set the elaboration entity
1133 -- to True, we do not need to test if this has already been
1134 -- done, since it is quicker to set the flag than to test it.
1136 if not U
.SAL_Interface
and then U
.Utype
= Is_Body
1137 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1140 Set_Unit_Number
(Unum_Spec
);
1141 Set_String
(" := True;");
1142 Write_Statement_Buffer
;
1145 -- Here if elaboration code is present. If binding a library
1146 -- or if there is a non-Ada main subprogram then we generate:
1148 -- if not uname_E then
1149 -- uname'elab_[spec|body];
1153 -- Otherwise, elaboration routines are called unconditionally:
1155 -- uname'elab_[spec|body];
1158 -- The uname_E assignment is skipped if this is a separate spec,
1159 -- since the assignment will be done when we process the body.
1161 elsif not U
.SAL_Interface
then
1162 if Force_Checking_Of_Elaboration_Flags
or
1163 Interface_Library_Unit
or
1164 (not Bind_Main_Program
)
1166 Set_String
(" if not E");
1167 Set_Unit_Number
(Unum_Spec
);
1168 Set_String
(" then");
1169 Write_Statement_Buffer
;
1174 Get_Decoded_Name_String_With_Brackets
(U
.Uname
);
1176 if VM_Target
= CLI_Target
and then U
.Unit_Kind
/= 's' then
1177 if Name_Buffer
(Name_Len
) = 's' then
1178 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 12) :=
1181 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 12) :=
1185 Name_Len
:= Name_Len
+ 12;
1188 if Name_Buffer
(Name_Len
) = 's' then
1189 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1192 Name_Buffer
(Name_Len
- 1 .. Name_Len
+ 8) :=
1196 Name_Len
:= Name_Len
+ 8;
1199 Set_Casing
(U
.Icasing
);
1202 Write_Statement_Buffer
;
1204 if U
.Utype
/= Is_Spec
then
1205 if Force_Checking_Of_Elaboration_Flags
or
1206 Interface_Library_Unit
or
1207 (not Bind_Main_Program
)
1213 Set_Unit_Number
(Unum_Spec
);
1214 Set_String
(" := True;");
1215 Write_Statement_Buffer
;
1218 if Force_Checking_Of_Elaboration_Flags
or
1219 Interface_Library_Unit
or
1220 (not Bind_Main_Program
)
1227 end Gen_Elab_Calls_Ada
;
1229 ----------------------
1230 -- Gen_Elab_Calls_C --
1231 ----------------------
1233 procedure Gen_Elab_Calls_C
is
1235 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1237 Unum
: constant Unit_Id
:= Elab_Order
.Table
(E
);
1238 U
: Unit_Record
renames Units
.Table
(Unum
);
1240 Unum_Spec
: Unit_Id
;
1241 -- This is the unit number of the spec that corresponds to
1242 -- this entry. It is the same as Unum except when the body
1243 -- and spec are different and we are currently processing
1244 -- the body, in which case it is the spec (Unum + 1).
1247 if U
.Utype
= Is_Body
then
1248 Unum_Spec
:= Unum
+ 1;
1253 -- Nothing to do if predefined unit in no run time mode
1255 if No_Run_Time_Mode
and then Is_Predefined_File_Name
(U
.Sfile
) then
1258 -- Case of no elaboration code
1260 elsif U
.No_Elab
then
1262 -- The only case in which we have to do something is if
1263 -- this is a body, with a separate spec, where the separate
1264 -- spec has an elaboration entity defined.
1266 -- In that case, this is where we set the elaboration entity
1267 -- to True, we do not need to test if this has already been
1268 -- done, since it is quicker to set the flag than to test it.
1270 if not U
.SAL_Interface
and then U
.Utype
= Is_Body
1271 and then Units
.Table
(Unum_Spec
).Set_Elab_Entity
1274 Get_Name_String
(U
.Uname
);
1276 Set_String
("_E = 1;");
1277 Write_Statement_Buffer
;
1280 -- Here if elaboration code is present. If binding a library
1281 -- or if there is a non-Ada main subprogram then we generate:
1283 -- if (uname_E == 0) {
1284 -- uname__elab[s|b] ();
1288 -- The uname_E assignment is skipped if this is a separate spec,
1289 -- since the assignment will be done when we process the body.
1291 elsif not U
.SAL_Interface
then
1292 Get_Name_String
(U
.Uname
);
1294 if Force_Checking_Of_Elaboration_Flags
or
1295 Interface_Library_Unit
or
1296 (not Bind_Main_Program
)
1298 Set_String
(" if (");
1300 Set_String
("_E == 0) {");
1301 Write_Statement_Buffer
;
1307 Set_String
("___elab");
1308 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1309 Set_String
(" ();");
1310 Write_Statement_Buffer
;
1312 if U
.Utype
/= Is_Spec
then
1313 if Force_Checking_Of_Elaboration_Flags
or
1314 Interface_Library_Unit
or
1315 (not Bind_Main_Program
)
1322 Set_String
("_E++;");
1323 Write_Statement_Buffer
;
1326 if Force_Checking_Of_Elaboration_Flags
or
1327 Interface_Library_Unit
or
1328 (not Bind_Main_Program
)
1336 end Gen_Elab_Calls_C
;
1338 ----------------------
1339 -- Gen_Elab_Defs_C --
1340 ----------------------
1342 procedure Gen_Elab_Defs_C
is
1344 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1346 -- Generate declaration of elaboration procedure if elaboration
1347 -- needed. Note that passive units are always excluded.
1349 if not Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
1350 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
1351 Set_String
("extern void ");
1353 Set_String
("___elab");
1354 Set_Char
(Name_Buffer
(Name_Len
)); -- 's' or 'b' for spec/body
1355 Set_String
(" (void);");
1356 Write_Statement_Buffer
;
1362 end Gen_Elab_Defs_C
;
1364 ------------------------
1365 -- Gen_Elab_Order_Ada --
1366 ------------------------
1368 procedure Gen_Elab_Order_Ada
is
1371 WBI
(" -- BEGIN ELABORATION ORDER");
1373 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
1374 Set_String
(" -- ");
1375 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
1377 Write_Statement_Buffer
;
1380 WBI
(" -- END ELABORATION ORDER");
1381 end Gen_Elab_Order_Ada
;
1383 ----------------------
1384 -- Gen_Elab_Order_C --
1385 ----------------------
1387 procedure Gen_Elab_Order_C
is
1390 WBI
("/* BEGIN ELABORATION ORDER");
1392 for J
in Elab_Order
.First
.. Elab_Order
.Last
loop
1393 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(J
)).Uname
);
1395 Write_Statement_Buffer
;
1398 WBI
(" END ELABORATION ORDER */");
1399 end Gen_Elab_Order_C
;
1405 procedure Gen_Main_Ada
is
1409 if Exit_Status_Supported_On_Target
then
1410 Set_String
(" function ");
1412 Set_String
(" procedure ");
1415 Set_String
(Get_Main_Name
);
1417 if Command_Line_Args_On_Target
then
1418 Write_Statement_Buffer
;
1419 WBI
(" (argc : Integer;");
1420 WBI
(" argv : System.Address;");
1421 WBI
(" envp : System.Address)");
1423 if Exit_Status_Supported_On_Target
then
1424 WBI
(" return Integer");
1430 if Exit_Status_Supported_On_Target
then
1431 Set_String
(" return Integer is");
1436 Write_Statement_Buffer
;
1439 if Opt
.Default_Exit_Status
/= 0
1440 and then Bind_Main_Program
1441 and then not Configurable_Run_Time_Mode
1443 WBI
(" procedure Set_Exit_Status (Status : Integer);");
1444 WBI
(" pragma Import (C, Set_Exit_Status, " &
1445 """__gnat_set_exit_status"");");
1449 -- Initialize and Finalize
1451 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
1452 WBI
(" procedure initialize (Addr : System.Address);");
1453 WBI
(" pragma Import (C, initialize, ""__gnat_initialize"");");
1455 WBI
(" procedure finalize;");
1456 WBI
(" pragma Import (C, finalize, ""__gnat_finalize"");");
1459 -- If we want to analyze the stack, we have to import corresponding
1462 if Dynamic_Stack_Measurement
then
1464 WBI
(" procedure Output_Results;");
1465 WBI
(" pragma Import (C, Output_Results, " &
1466 """__gnat_stack_usage_output_results"");");
1470 "procedure Initialize_Stack_Analysis (Buffer_Size : Natural);");
1471 WBI
(" pragma Import (C, Initialize_Stack_Analysis, " &
1472 """__gnat_stack_usage_initialize"");");
1475 -- Deal with declarations for main program case
1477 if not No_Main_Subprogram
then
1479 -- To call the main program, we declare it using a pragma Import
1480 -- Ada with the right link name.
1482 -- It might seem more obvious to "with" the main program, and call
1483 -- it in the normal Ada manner. We do not do this for three reasons:
1485 -- 1. It is more efficient not to recompile the main program
1486 -- 2. We are not entitled to assume the source is accessible
1487 -- 3. We don't know what options to use to compile it
1489 -- It is really reason 3 that is most critical (indeed we used
1490 -- to generate the "with", but several regression tests failed).
1494 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1495 WBI
(" Result : Integer;");
1497 WBI
(" function Ada_Main_Program return Integer;");
1500 WBI
(" procedure Ada_Main_Program;");
1503 Set_String
(" pragma Import (Ada, Ada_Main_Program, """);
1504 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1505 Set_Main_Program_Name
;
1506 Set_String
(""");");
1508 Write_Statement_Buffer
;
1511 if Bind_Main_Program
1512 and then not Suppress_Standard_Library_On_Target
1514 WBI
(" SEH : aliased array (1 .. 2) of Integer;");
1519 -- Generate a reference to Ada_Main_Program_Name. This symbol is
1520 -- not referenced elsewhere in the generated program, but is needed
1521 -- by the debugger (that's why it is generated in the first place).
1522 -- The reference stops Ada_Main_Program_Name from being optimized
1523 -- away by smart linkers, such as the AiX linker.
1525 -- Because this variable is unused, we make this variable "aliased"
1526 -- with a pragma Volatile in order to tell the compiler to preserve
1527 -- this variable at any level of optimization.
1529 if Bind_Main_Program
then
1531 (" Ensure_Reference : aliased System.Address := " &
1532 "Ada_Main_Program_Name'Address;");
1533 WBI
(" pragma Volatile (Ensure_Reference);");
1539 -- Acquire command line arguments if present on target
1541 if Command_Line_Args_On_Target
then
1542 WBI
(" gnat_argc := argc;");
1543 WBI
(" gnat_argv := argv;");
1544 WBI
(" gnat_envp := envp;");
1547 -- If configurable run time and no command line args, then nothing
1548 -- needs to be done since the gnat_argc/argv/envp variables are
1549 -- suppressed in this case.
1551 elsif Configurable_Run_Time_On_Target
then
1554 -- Otherwise set dummy values (to be filled in by some other unit?)
1557 WBI
(" gnat_argc := 0;");
1558 WBI
(" gnat_argv := System.Null_Address;");
1559 WBI
(" gnat_envp := System.Null_Address;");
1562 if Opt
.Default_Exit_Status
/= 0
1563 and then Bind_Main_Program
1564 and then not Configurable_Run_Time_Mode
1566 Set_String
(" Set_Exit_Status (");
1567 Set_Int
(Opt
.Default_Exit_Status
);
1569 Write_Statement_Buffer
;
1572 if Dynamic_Stack_Measurement
then
1573 Set_String
(" Initialize_Stack_Analysis (");
1574 Set_Int
(Dynamic_Stack_Measurement_Array_Size
);
1576 Write_Statement_Buffer
;
1579 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
1580 if not No_Main_Subprogram
1581 and then Bind_Main_Program
1582 and then not Suppress_Standard_Library_On_Target
1584 WBI
(" Initialize (SEH'Address);");
1586 WBI
(" Initialize (System.Null_Address);");
1590 WBI
(" " & Ada_Init_Name
.all & ";");
1592 if not No_Main_Subprogram
then
1593 WBI
(" Break_Start;");
1595 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1596 WBI
(" Ada_Main_Program;");
1598 WBI
(" Result := Ada_Main_Program;");
1602 -- Adafinal call is skipped if no finalization
1604 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
1606 -- If compiling for the JVM, we directly call Adafinal because
1607 -- we don't import it via Do_Finalize (see Gen_Output_File_Ada).
1609 if VM_Target
= No_VM
then
1610 WBI
(" Do_Finalize;");
1612 WBI
(" System.Standard_Library.Adafinal;");
1616 -- Prints the result of static stack analysis
1618 if Dynamic_Stack_Measurement
then
1619 WBI
(" Output_Results;");
1622 -- Finalize is only called if we have a run time
1624 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
1630 if Exit_Status_Supported_On_Target
then
1631 if No_Main_Subprogram
1632 or else ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
1634 WBI
(" return (gnat_exit_status);");
1636 WBI
(" return (Result);");
1647 procedure Gen_Main_C
is
1649 if Exit_Status_Supported_On_Target
then
1650 WBI
("#include <stdlib.h>");
1651 Set_String
("int ");
1653 Set_String
("void ");
1656 Set_String
(Get_Main_Name
);
1658 -- Generate command line args in prototype if present on target
1660 if Command_Line_Args_On_Target
then
1661 Write_Statement_Buffer
(" (int argc, char **argv, char **envp)");
1663 -- Case of no command line arguments on target
1666 Write_Statement_Buffer
(" (void)");
1671 -- Generate a reference to __gnat_ada_main_program_name. This symbol
1672 -- is not referenced elsewhere in the generated program, but is
1673 -- needed by the debugger (that's why it is generated in the first
1674 -- place). The reference stops Ada_Main_Program_Name from being
1675 -- optimized away by smart linkers, such as the AiX linker.
1677 -- Because this variable is unused, we declare this variable as
1678 -- volatile in order to tell the compiler to preserve it at any
1679 -- level of optimization.
1681 if Bind_Main_Program
then
1682 WBI
(" char * volatile ensure_reference " &
1683 "__attribute__ ((__unused__)) = " &
1684 "__gnat_ada_main_program_name;");
1687 if not Suppress_Standard_Library_On_Target
1688 and then not No_Main_Subprogram
1690 WBI
(" int SEH [2];");
1695 -- If main program is a function, generate result variable
1697 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1698 WBI
(" int result;");
1701 -- Set command line argument values from parameters if command line
1702 -- arguments are present on target
1704 if Command_Line_Args_On_Target
then
1705 WBI
(" gnat_argc = argc;");
1706 WBI
(" gnat_argv = argv;");
1707 WBI
(" gnat_envp = envp;");
1710 -- If configurable run-time, then nothing to do, since in this case
1711 -- the gnat_argc/argv/envp variables are entirely suppressed.
1713 elsif Configurable_Run_Time_On_Target
then
1716 -- if no command line arguments on target, set dummy values
1719 WBI
(" gnat_argc = 0;");
1720 WBI
(" gnat_argv = 0;");
1721 WBI
(" gnat_envp = 0;");
1724 if Opt
.Default_Exit_Status
/= 0
1725 and then Bind_Main_Program
1726 and then not Configurable_Run_Time_Mode
1728 Set_String
(" __gnat_set_exit_status (");
1729 Set_Int
(Opt
.Default_Exit_Status
);
1731 Write_Statement_Buffer
;
1734 -- Initializes dynamic stack measurement if needed
1736 if Dynamic_Stack_Measurement
then
1737 Set_String
(" __gnat_stack_usage_initialize (");
1738 Set_Int
(Dynamic_Stack_Measurement_Array_Size
);
1740 Write_Statement_Buffer
;
1743 -- The __gnat_initialize routine is used only if we have a run-time
1745 if not Suppress_Standard_Library_On_Target
then
1746 if not No_Main_Subprogram
and then Bind_Main_Program
then
1747 WBI
(" __gnat_initialize ((void *)SEH);");
1749 WBI
(" __gnat_initialize ((void *)0);");
1753 WBI
(" " & Ada_Init_Name
.all & " ();");
1755 if not No_Main_Subprogram
then
1756 WBI
(" __gnat_break_start ();");
1759 -- Output main program name
1761 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
1763 -- Main program is procedure case
1765 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
1767 Set_Main_Program_Name
;
1768 Set_String
(" ();");
1769 Write_Statement_Buffer
;
1771 -- Main program is function case
1773 else -- ALIs.Table (ALIs_First).Main_Program = Func
1774 Set_String
(" result = ");
1775 Set_Main_Program_Name
;
1776 Set_String
(" ();");
1777 Write_Statement_Buffer
;
1782 -- Call adafinal if finalization active
1784 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
1786 WBI
(" system__standard_library__adafinal ();");
1789 -- Outputs the dynamic stack measurement if needed
1791 if Dynamic_Stack_Measurement
then
1792 WBI
(" __gnat_stack_usage_output_results ();");
1795 -- The finalize routine is used only if we have a run-time
1797 if not Suppress_Standard_Library_On_Target
then
1798 WBI
(" __gnat_finalize ();");
1801 -- Case of main program is a function, so the value it returns
1802 -- is the exit status in this case.
1804 if ALIs
.Table
(ALIs
.First
).Main_Program
= Func
then
1805 if Exit_Status_Supported_On_Target
then
1807 -- VMS must use Posix exit routine in order to get the effect
1808 -- of a Unix compatible setting of the program exit status.
1809 -- For all other systems, we use the standard exit routine.
1811 if OpenVMS_On_Target
then
1812 WBI
(" decc$__posix_exit (result);");
1814 WBI
(" exit (result);");
1818 -- Case of main program is a procedure, in which case the exit
1819 -- status is whatever was set by a Set_Exit call most recently
1822 if Exit_Status_Supported_On_Target
then
1824 -- VMS must use Posix exit routine in order to get the effect
1825 -- of a Unix compatible setting of the program exit status.
1826 -- For all other systems, we use the standard exit routine.
1828 if OpenVMS_On_Target
then
1829 WBI
(" decc$__posix_exit (gnat_exit_status);");
1831 WBI
(" exit (gnat_exit_status);");
1839 ------------------------------
1840 -- Gen_Object_Files_Options --
1841 ------------------------------
1843 procedure Gen_Object_Files_Options
is
1845 -- This keeps track of the position in the sorted set of entries
1846 -- in the Linker_Options table of where the first entry from an
1847 -- internal file appears.
1849 Linker_Option_List_Started
: Boolean := False;
1850 -- Set to True when "LINKER OPTION LIST" is displayed
1852 procedure Write_Linker_Option
;
1853 -- Write binder info linker option
1855 -------------------------
1856 -- Write_Linker_Option --
1857 -------------------------
1859 procedure Write_Linker_Option
is
1864 -- Loop through string, breaking at null's
1867 while Start
< Name_Len
loop
1869 -- Find null ending this section
1872 while Name_Buffer
(Stop
) /= ASCII
.NUL
1873 and then Stop
<= Name_Len
loop
1877 -- Process section if non-null
1879 if Stop
> Start
then
1880 if Output_Linker_Option_List
then
1881 if not Zero_Formatting
then
1882 if not Linker_Option_List_Started
then
1883 Linker_Option_List_Started
:= True;
1885 Write_Str
(" LINKER OPTION LIST");
1893 Write_Str
(Name_Buffer
(Start
.. Stop
- 1));
1897 (" -- ", "", Name_Buffer
(Start
.. Stop
- 1));
1902 end Write_Linker_Option
;
1904 -- Start of processing for Gen_Object_Files_Options
1908 Write_Info_Ada_C
("-- ", "/* ", " BEGIN Object file/option list");
1910 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
1912 -- If not spec that has an associated body, then generate a
1913 -- comment giving the name of the corresponding object file.
1915 if (not Units
.Table
(Elab_Order
.Table
(E
)).SAL_Interface
)
1916 and then Units
.Table
(Elab_Order
.Table
(E
)).Utype
/= Is_Spec
1920 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Ofile_Full_Name
);
1922 -- If the presence of an object file is necessary or if it
1923 -- exists, then use it.
1925 if not Hostparm
.Exclude_Missing_Objects
1927 System
.OS_Lib
.Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
1929 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
1931 if Output_Object_List
then
1932 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1936 -- Don't link with the shared library on VMS if an internal
1937 -- filename object is seen. Multiply defined symbols will
1940 if OpenVMS_On_Target
1941 and then Is_Internal_File_Name
1943 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Sfile
)
1945 -- Special case for g-trasym.obj, which is not included
1948 Get_Name_String
(ALIs
.Table
1949 (Units
.Table
(Elab_Order
.Table
(E
)).My_ALI
).Sfile
);
1951 if Name_Buffer
(1 .. 8) /= "g-trasym" then
1952 Opt
.Shared_Libgnat
:= False;
1959 -- Add a "-Ldir" for each directory in the object path
1961 for J
in 1 .. Nb_Dir_In_Obj_Search_Path
loop
1963 Dir
: constant String_Ptr
:= Dir_In_Obj_Search_Path
(J
);
1966 Add_Str_To_Name_Buffer
("-L");
1967 Add_Str_To_Name_Buffer
(Dir
.all);
1968 Write_Linker_Option
;
1972 -- Sort linker options
1974 -- This sort accomplishes two important purposes:
1976 -- a) All application files are sorted to the front, and all
1977 -- GNAT internal files are sorted to the end. This results
1978 -- in a well defined dividing line between the two sets of
1979 -- files, for the purpose of inserting certain standard
1980 -- library references into the linker arguments list.
1982 -- b) Given two different units, we sort the linker options so
1983 -- that those from a unit earlier in the elaboration order
1984 -- comes later in the list. This is a heuristic designed
1985 -- to create a more friendly order of linker options when
1986 -- the operations appear in separate units. The idea is that
1987 -- if unit A must be elaborated before unit B, then it is
1988 -- more likely that B references libraries included by A,
1989 -- than vice versa, so we want the libraries included by
1990 -- A to come after the libraries included by B.
1992 -- These two criteria are implemented by function Lt_Linker_Option.
1993 -- Note that a special case of b) is that specs are elaborated before
1994 -- bodies, so linker options from specs come after linker options
1995 -- for bodies, and again, the assumption is that libraries used by
1996 -- the body are more likely to reference libraries used by the spec,
2000 (Linker_Options
.Last
,
2001 Move_Linker_Option
'Access,
2002 Lt_Linker_Option
'Access);
2004 -- Write user linker options, i.e. the set of linker options that
2005 -- come from all files other than GNAT internal files, Lgnat is
2006 -- left set to point to the first entry from a GNAT internal file,
2007 -- or past the end of the entriers if there are no internal files.
2009 Lgnat
:= Linker_Options
.Last
+ 1;
2011 for J
in 1 .. Linker_Options
.Last
loop
2012 if not Linker_Options
.Table
(J
).Internal_File
then
2013 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2014 Write_Linker_Option
;
2021 -- Now we insert standard linker options that must appear after the
2022 -- entries from user files, and before the entries from GNAT run-time
2023 -- files. The reason for this decision is that libraries referenced
2024 -- by internal routines may reference these standard library entries.
2026 -- Note that we do not insert anything when pragma No_Run_Time has been
2027 -- specified or when the standard libraries are not to be used,
2028 -- otherwise on some platforms, such as VMS, we may get duplicate
2029 -- symbols when linking.
2031 if not (Opt
.No_Run_Time_Mode
or else Opt
.No_Stdlib
) then
2034 if Opt
.Shared_Libgnat
then
2035 Add_Str_To_Name_Buffer
("-shared");
2037 Add_Str_To_Name_Buffer
("-static");
2040 -- Write directly to avoid -K output (why???)
2042 Write_Info_Ada_C
(" -- ", "", Name_Buffer
(1 .. Name_Len
));
2044 if With_DECGNAT
then
2047 if Opt
.Shared_Libgnat
then
2048 Add_Str_To_Name_Buffer
(Shared_Lib
("decgnat"));
2050 Add_Str_To_Name_Buffer
("-ldecgnat");
2053 Write_Linker_Option
;
2059 if Opt
.Shared_Libgnat
then
2060 Add_Str_To_Name_Buffer
(Shared_Lib
("gnarl"));
2062 Add_Str_To_Name_Buffer
("-lgnarl");
2065 Write_Linker_Option
;
2070 if Opt
.Shared_Libgnat
then
2071 Add_Str_To_Name_Buffer
(Shared_Lib
("gnat"));
2073 Add_Str_To_Name_Buffer
("-lgnat");
2076 Write_Linker_Option
;
2079 -- Write linker options from all internal files
2081 for J
in Lgnat
.. Linker_Options
.Last
loop
2082 Get_Name_String
(Linker_Options
.Table
(J
).Name
);
2083 Write_Linker_Option
;
2086 if Output_Linker_Option_List
and then not Zero_Formatting
then
2090 if Ada_Bind_File
then
2091 WBI
("-- END Object file/option list ");
2093 WBI
(" END Object file/option list */");
2095 end Gen_Object_Files_Options
;
2097 ---------------------
2098 -- Gen_Output_File --
2099 ---------------------
2101 procedure Gen_Output_File
(Filename
: String) is
2103 -- Acquire settings for Interrupt_State pragmas
2105 Set_IS_Pragma_Table
;
2107 -- Acquire settings for Priority_Specific_Dispatching pragma
2109 Set_PSD_Pragma_Table
;
2111 -- Override Ada_Bind_File and Bind_Main_Program for VMs since
2112 -- JGNAT only supports Ada code, and the main program is already
2113 -- generated by the compiler.
2115 if VM_Target
/= No_VM
then
2116 Ada_Bind_File
:= True;
2118 if VM_Target
= JVM_Target
then
2119 Bind_Main_Program
:= False;
2123 -- Override time slice value if -T switch is set
2125 if Time_Slice_Set
then
2126 ALIs
.Table
(ALIs
.First
).Time_Slice_Value
:= Opt
.Time_Slice_Value
;
2129 -- Count number of elaboration calls
2131 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
2132 if Units
.Table
(Elab_Order
.Table
(E
)).No_Elab
then
2135 Num_Elab_Calls
:= Num_Elab_Calls
+ 1;
2139 -- Generate output file in appropriate language
2141 Check_System_Restrictions_Used
;
2143 if Ada_Bind_File
then
2144 Gen_Output_File_Ada
(Filename
);
2146 Gen_Output_File_C
(Filename
);
2148 end Gen_Output_File
;
2150 -------------------------
2151 -- Gen_Output_File_Ada --
2152 -------------------------
2154 procedure Gen_Output_File_Ada
(Filename
: String) is
2157 -- Name of generated bind file (spec)
2160 -- Name of generated bind file (body)
2162 Ada_Main
: constant String := Get_Ada_Main_Name
;
2163 -- Name to be used for generated Ada main program. See the body of
2164 -- function Get_Ada_Main_Name for details on the form of the name.
2167 -- Create spec first
2169 Create_Binder_Output
(Filename
, 's', Bfiles
);
2171 -- We always compile the binder file in Ada 95 mode so that we properly
2172 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2173 -- of the Ada 2005 constructs are needed by the binder file.
2175 WBI
("pragma Ada_95;");
2177 -- If we are operating in Restrictions (No_Exception_Handlers) mode,
2178 -- then we need to make sure that the binder program is compiled with
2179 -- the same restriction, so that no exception tables are generated.
2181 if Cumulative_Restrictions
.Set
(No_Exception_Handlers
) then
2182 WBI
("pragma Restrictions (No_Exception_Handlers);");
2185 -- Same processing for Restrictions (No_Exception_Propagation)
2187 if Cumulative_Restrictions
.Set
(No_Exception_Propagation
) then
2188 WBI
("pragma Restrictions (No_Exception_Propagation);");
2191 -- Same processing for pragma No_Run_Time
2193 if No_Run_Time_Mode
then
2194 WBI
("pragma No_Run_Time;");
2197 -- Generate with of System so we can reference System.Address
2199 WBI
("with System;");
2201 -- Generate with of System.Initialize_Scalars if active
2203 if Initialize_Scalars_Used
then
2204 WBI
("with System.Scalar_Values;");
2207 -- Generate with of System.Secondary_Stack if active
2209 if Sec_Stack_Used
and then Default_Sec_Stack_Size
/= -1 then
2210 WBI
("with System.Secondary_Stack;");
2213 Resolve_Binder_Options
;
2215 if VM_Target
/= No_VM
then
2216 if not Suppress_Standard_Library_On_Target
then
2218 -- Usually, adafinal is called using a pragma Import C. Since
2219 -- Import C doesn't have the same semantics for JGNAT, we use
2222 WBI
("with System.Standard_Library;");
2226 WBI
("package " & Ada_Main
& " is");
2227 WBI
(" pragma Warnings (Off);");
2229 -- Main program case
2231 if Bind_Main_Program
then
2232 if VM_Target
= No_VM
then
2234 -- Generate argc/argv stuff unless suppressed
2236 if Command_Line_Args_On_Target
2237 or not Configurable_Run_Time_On_Target
2240 WBI
(" gnat_argc : Integer;");
2241 WBI
(" gnat_argv : System.Address;");
2242 WBI
(" gnat_envp : System.Address;");
2244 -- If the standard library is not suppressed, these variables
2245 -- are in the runtime data area for easy access from the
2248 if not Suppress_Standard_Library_On_Target
then
2250 WBI
(" pragma Import (C, gnat_argc);");
2251 WBI
(" pragma Import (C, gnat_argv);");
2252 WBI
(" pragma Import (C, gnat_envp);");
2256 -- Define exit status. Again in normal mode, this is in the
2257 -- run-time library, and is initialized there, but in the
2258 -- configurable runtime case, the variable is declared and
2259 -- initialized in this file.
2263 if Configurable_Run_Time_Mode
then
2264 if Exit_Status_Supported_On_Target
then
2265 WBI
(" gnat_exit_status : Integer := 0;");
2269 WBI
(" gnat_exit_status : Integer;");
2270 WBI
(" pragma Import (C, gnat_exit_status);");
2273 -- Generate the GNAT_Version and Ada_Main_Program_Name info only
2274 -- for the main program. Otherwise, it can lead under some
2275 -- circumstances to a symbol duplication during the link (for
2276 -- instance when a C program uses 2 Ada libraries)
2280 WBI
(" GNAT_Version : constant String :=");
2281 WBI
(" ""GNAT Version: " &
2282 Gnat_Version_String
& """;");
2283 WBI
(" pragma Export (C, GNAT_Version, ""__gnat_version"");");
2286 Set_String
(" Ada_Main_Program_Name : constant String := """);
2287 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2289 if VM_Target
= No_VM
then
2290 Set_Main_Program_Name
;
2291 Set_String
(""" & ASCII.NUL;");
2293 Set_String
(Name_Buffer
(1 .. Name_Len
- 2) & """;");
2296 Write_Statement_Buffer
;
2299 (" pragma Export (C, Ada_Main_Program_Name, " &
2300 """__gnat_ada_main_program_name"");");
2304 WBI
(" procedure " & Ada_Final_Name
.all & ";");
2305 WBI
(" pragma Export (C, " & Ada_Final_Name
.all & ", """ &
2306 Ada_Final_Name
.all & """);");
2308 WBI
(" procedure " & Ada_Init_Name
.all & ";");
2309 WBI
(" pragma Export (C, " & Ada_Init_Name
.all & ", """ &
2310 Ada_Init_Name
.all & """);");
2312 -- If -a has been specified use pragma Linker_Constructor for the init
2313 -- procedure. No need to use a similar pragma for the final procedure as
2314 -- global finalization will occur when the executable finishes execution
2315 -- and for plugins (shared stand-alone libraries that can be
2316 -- "unloaded"), finalization should not occur automatically, otherwise
2317 -- the main executable may not continue to work properly.
2319 if Use_Pragma_Linker_Constructor
then
2320 WBI
(" pragma Linker_Constructor (" & Ada_Init_Name
.all & ");");
2323 if Bind_Main_Program
and then VM_Target
= No_VM
then
2325 -- If we have the standard library, then Break_Start is defined
2326 -- there, but when the standard library is suppressed, Break_Start
2330 WBI
(" procedure Break_Start;");
2332 if Suppress_Standard_Library_On_Target
then
2333 WBI
(" pragma Export (C, Break_Start, ""__gnat_break_start"");");
2335 WBI
(" pragma Import (C, Break_Start, ""__gnat_break_start"");");
2340 if Exit_Status_Supported_On_Target
then
2341 Set_String
(" function ");
2343 Set_String
(" procedure ");
2346 Set_String
(Get_Main_Name
);
2348 -- Generate argument list if present
2350 if Command_Line_Args_On_Target
then
2351 Write_Statement_Buffer
;
2352 WBI
(" (argc : Integer;");
2353 WBI
(" argv : System.Address;");
2355 (" envp : System.Address)");
2357 if Exit_Status_Supported_On_Target
then
2358 Write_Statement_Buffer
;
2359 WBI
(" return Integer;");
2361 Write_Statement_Buffer
(";");
2365 if Exit_Status_Supported_On_Target
then
2366 Write_Statement_Buffer
(" return Integer;");
2368 Write_Statement_Buffer
(";");
2372 WBI
(" pragma Export (C, " & Get_Main_Name
& ", """ &
2373 Get_Main_Name
& """);");
2382 WBI
("end " & Ada_Main
& ";");
2383 Close_Binder_Output
;
2385 -- Prepare to write body
2387 Create_Binder_Output
(Filename
, 'b', Bfileb
);
2389 -- We always compile the binder file in Ada 95 mode so that we properly
2390 -- handle use of Ada 2005 keywords as identifiers in Ada 95 mode. None
2391 -- of the Ada 2005 constructs are needed by the binder file.
2393 WBI
("pragma Ada_95;");
2395 -- Output Source_File_Name pragmas which look like
2397 -- pragma Source_File_Name (Ada_Main, Spec_File_Name => "sss");
2398 -- pragma Source_File_Name (Ada_Main, Body_File_Name => "bbb");
2400 -- where sss/bbb are the spec/body file names respectively
2402 Get_Name_String
(Bfiles
);
2403 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2405 WBI
("pragma Source_File_Name (" &
2407 ", Spec_File_Name => """ &
2408 Name_Buffer
(1 .. Name_Len
+ 3));
2410 Get_Name_String
(Bfileb
);
2411 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 3) := """);";
2413 WBI
("pragma Source_File_Name (" &
2415 ", Body_File_Name => """ &
2416 Name_Buffer
(1 .. Name_Len
+ 3));
2418 -- Generate with of System.Restrictions to initialize
2419 -- Run_Time_Restrictions.
2421 if System_Restrictions_Used
2422 and not Suppress_Standard_Library_On_Target
2425 WBI
("with System.Restrictions;");
2429 WBI
("package body " & Ada_Main
& " is");
2430 WBI
(" pragma Warnings (Off);");
2432 -- Import the finalization procedure only if finalization active
2434 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2436 -- In the Java case, pragma Import C cannot be used, so the
2437 -- standard Ada constructs will be used instead.
2439 if VM_Target
= No_VM
then
2441 WBI
(" procedure Do_Finalize;");
2443 (" pragma Import (C, Do_Finalize, " &
2444 """system__standard_library__adafinal"");");
2449 if not Suppress_Standard_Library_On_Target
then
2451 -- Generate Priority_Specific_Dispatching pragma string
2454 (" Local_Priority_Specific_Dispatching : constant String := """);
2456 for J
in 0 .. PSD_Pragma_Settings
.Last
loop
2457 Set_Char
(PSD_Pragma_Settings
.Table
(J
));
2461 Write_Statement_Buffer
;
2463 -- Generate Interrupt_State pragma string
2465 Set_String
(" Local_Interrupt_States : constant String := """);
2467 for J
in 0 .. IS_Pragma_Settings
.Last
loop
2468 Set_Char
(IS_Pragma_Settings
.Table
(J
));
2472 Write_Statement_Buffer
;
2480 if Bind_Main_Program
and then VM_Target
= No_VM
then
2482 -- When suppressing the standard library then generate dummy body
2485 if Suppress_Standard_Library_On_Target
then
2487 WBI
(" procedure Break_Start is");
2496 -- Output object file list and the Ada body is complete
2498 Gen_Object_Files_Options
;
2501 WBI
("end " & Ada_Main
& ";");
2503 Close_Binder_Output
;
2504 end Gen_Output_File_Ada
;
2506 -----------------------
2507 -- Gen_Output_File_C --
2508 -----------------------
2510 procedure Gen_Output_File_C
(Filename
: String) is
2512 pragma Warnings
(Off
, Bfile
);
2513 -- Name of generated bind file (not referenced)
2516 Create_Binder_Output
(Filename
, 'c', Bfile
);
2518 Resolve_Binder_Options
;
2520 WBI
("extern void " & Ada_Final_Name
.all & " (void);");
2522 -- If -a has been specified use __attribute__((constructor)) for the
2523 -- init procedure. No need to use a similar featute for the final
2524 -- procedure as global finalization will occur when the executable
2525 -- finishes execution and for plugins (shared stand-alone libraries that
2526 -- can be "unloaded"), finalization should not occur automatically,
2527 -- otherwise the main executable may not continue to work properly.
2529 if Use_Pragma_Linker_Constructor
then
2530 WBI
("extern void " & Ada_Init_Name
.all &
2531 " (void) __attribute__((constructor));");
2533 WBI
("extern void " & Ada_Init_Name
.all & " (void);");
2536 WBI
("extern void system__standard_library__adafinal (void);");
2538 if not No_Main_Subprogram
then
2539 Set_String
("extern ");
2541 if Exit_Status_Supported_On_Target
then
2544 Set_String
("void");
2547 Set_String
(" main ");
2549 if Command_Line_Args_On_Target
then
2550 Write_Statement_Buffer
("(int, char **, char **);");
2552 Write_Statement_Buffer
("(void);");
2555 if OpenVMS_On_Target
then
2556 WBI
("extern void decc$__posix_exit (int);");
2558 WBI
("extern void exit (int);");
2561 WBI
("extern void __gnat_break_start (void);");
2562 Set_String
("extern ");
2564 if ALIs
.Table
(ALIs
.First
).Main_Program
= Proc
then
2565 Set_String
("void ");
2567 Set_String
("int ");
2570 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2571 Set_Main_Program_Name
;
2572 Set_String
(" (void);");
2573 Write_Statement_Buffer
;
2576 if not Suppress_Standard_Library_On_Target
then
2577 WBI
("extern void __gnat_initialize (void *);");
2578 WBI
("extern void __gnat_finalize (void);");
2579 WBI
("extern void __gnat_install_handler (void);");
2582 if Dynamic_Stack_Measurement
then
2584 WBI
("extern void __gnat_stack_usage_output_results (void);");
2585 WBI
("extern void __gnat_stack_usage_initialize (int size);");
2588 -- Initialize stack limit for the environment task if the stack
2589 -- check method is stack limit and stack check is enabled.
2591 if Stack_Check_Limits_On_Target
2592 and then (Stack_Check_Default_On_Target
or Stack_Check_Switch_Set
)
2595 WBI
("extern void __gnat_initialize_stack_limit (void);");
2602 -- Imported variable used to track elaboration/finalization phase.
2603 -- Used only when we have a runtime.
2605 if not Suppress_Standard_Library_On_Target
then
2606 WBI
("extern int __gnat_handler_installed;");
2610 -- Write argv/argc exit status stuff if main program case
2612 if Bind_Main_Program
then
2614 -- First deal with argc/argv/envp. In the normal case they
2615 -- are in the run-time library.
2617 if not Configurable_Run_Time_On_Target
then
2618 WBI
("extern int gnat_argc;");
2619 WBI
("extern char **gnat_argv;");
2620 WBI
("extern char **gnat_envp;");
2622 -- If configurable run time and no command line args, then the
2623 -- generation of these variables is entirely suppressed.
2625 elsif not Command_Line_Args_On_Target
then
2628 -- Otherwise, in the configurable run-time case they are right in
2632 WBI
("int gnat_argc;");
2633 WBI
("char **gnat_argv;");
2634 WBI
("char **gnat_envp;");
2637 -- Similarly deal with exit status
2638 -- are in the run-time library.
2640 if not Configurable_Run_Time_On_Target
then
2641 WBI
("extern int gnat_exit_status;");
2643 -- If configurable run time and no exit status on target, then
2644 -- the generation of this variables is entirely suppressed.
2646 elsif not Exit_Status_Supported_On_Target
then
2649 -- Otherwise, in the configurable run-time case this variable is
2650 -- right in the binder file, and initialized to zero there.
2653 WBI
("int gnat_exit_status = 0;");
2659 -- When suppressing the standard library, the __gnat_break_start
2660 -- routine (for the debugger to get initial control) is defined in
2663 if Suppress_Standard_Library_On_Target
then
2665 WBI
("void __gnat_break_start (void) {}");
2668 -- Generate the __gnat_version and __gnat_ada_main_program_name info
2669 -- only for the main program. Otherwise, it can lead under some
2670 -- circumstances to a symbol duplication during the link (for instance
2671 -- when a C program uses 2 Ada libraries)
2673 if Bind_Main_Program
then
2675 WBI
("char __gnat_version[] = ""GNAT Version: " &
2676 Gnat_Version_String
& """;");
2678 Set_String
("char __gnat_ada_main_program_name[] = """);
2679 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
2680 Set_Main_Program_Name
;
2682 Write_Statement_Buffer
;
2685 -- Generate the adafinal routine. In no runtime mode, this is
2686 -- not needed, since there is no finalization to do.
2688 if not Cumulative_Restrictions
.Set
(No_Finalization
) then
2694 -- Main is only present for Ada main case
2696 if Bind_Main_Program
then
2700 -- Generate versions, elaboration order, list of object files
2704 Gen_Object_Files_Options
;
2706 -- C binder output is complete
2708 Close_Binder_Output
;
2709 end Gen_Output_File_C
;
2711 --------------------------
2712 -- Gen_Restrictions_Ada --
2713 --------------------------
2715 procedure Gen_Restrictions_Ada
is
2719 if Suppress_Standard_Library_On_Target
2720 or not System_Restrictions_Used
2725 WBI
(" System.Restrictions.Run_Time_Restrictions :=");
2731 for J
in Cumulative_Restrictions
.Set
'First ..
2732 Restriction_Id
'Pred (Cumulative_Restrictions
.Set
'Last)
2734 Set_Boolean
(Cumulative_Restrictions
.Set
(J
));
2739 Write_Statement_Buffer
;
2746 (Cumulative_Restrictions
.Set
(Cumulative_Restrictions
.Set
'Last));
2748 Write_Statement_Buffer
;
2749 Set_String
(" Value => (");
2751 for J
in Cumulative_Restrictions
.Value
'First ..
2752 Restriction_Id
'Pred (Cumulative_Restrictions
.Value
'Last)
2754 Set_Int
(Int
(Cumulative_Restrictions
.Value
(J
)));
2758 Set_Int
(Int
(Cumulative_Restrictions
.Value
2759 (Cumulative_Restrictions
.Value
'Last)));
2761 Write_Statement_Buffer
;
2762 WBI
(" Violated =>");
2766 for J
in Cumulative_Restrictions
.Violated
'First ..
2767 Restriction_Id
'Pred (Cumulative_Restrictions
.Violated
'Last)
2769 Set_Boolean
(Cumulative_Restrictions
.Violated
(J
));
2774 Write_Statement_Buffer
;
2780 Set_Boolean
(Cumulative_Restrictions
.Violated
2781 (Cumulative_Restrictions
.Violated
'Last));
2783 Write_Statement_Buffer
;
2784 Set_String
(" Count => (");
2786 for J
in Cumulative_Restrictions
.Count
'First ..
2787 Restriction_Id
'Pred (Cumulative_Restrictions
.Count
'Last)
2789 Set_Int
(Int
(Cumulative_Restrictions
.Count
(J
)));
2793 Set_Int
(Int
(Cumulative_Restrictions
.Count
2794 (Cumulative_Restrictions
.Count
'Last)));
2796 Write_Statement_Buffer
;
2797 Set_String
(" Unknown => (");
2799 for J
in Cumulative_Restrictions
.Unknown
'First ..
2800 Restriction_Id
'Pred (Cumulative_Restrictions
.Unknown
'Last)
2802 Set_Boolean
(Cumulative_Restrictions
.Unknown
(J
));
2807 (Cumulative_Restrictions
.Unknown
2808 (Cumulative_Restrictions
.Unknown
'Last));
2810 Write_Statement_Buffer
;
2811 end Gen_Restrictions_Ada
;
2813 ------------------------
2814 -- Gen_Restrictions_C --
2815 ------------------------
2817 procedure Gen_Restrictions_C
is
2819 if Suppress_Standard_Library_On_Target
2820 or not System_Restrictions_Used
2825 WBI
(" typedef struct {");
2826 Set_String
(" char set [");
2827 Set_Int
(Cumulative_Restrictions
.Set
'Length);
2829 Write_Statement_Buffer
;
2831 Set_String
(" int value [");
2832 Set_Int
(Cumulative_Restrictions
.Value
'Length);
2834 Write_Statement_Buffer
;
2836 Set_String
(" char violated [");
2837 Set_Int
(Cumulative_Restrictions
.Violated
'Length);
2839 Write_Statement_Buffer
;
2841 Set_String
(" int count [");
2842 Set_Int
(Cumulative_Restrictions
.Count
'Length);
2844 Write_Statement_Buffer
;
2846 Set_String
(" char unknown [");
2847 Set_Int
(Cumulative_Restrictions
.Unknown
'Length);
2849 Write_Statement_Buffer
;
2850 WBI
(" } restrictions;");
2851 WBI
(" extern restrictions " &
2852 "system__restrictions__run_time_restrictions;");
2853 WBI
(" restrictions r = {");
2856 for J
in Cumulative_Restrictions
.Set
'First ..
2857 Restriction_Id
'Pred (Cumulative_Restrictions
.Set
'Last)
2859 Set_Int
(Boolean'Pos (Cumulative_Restrictions
.Set
(J
)));
2863 Set_Int
(Boolean'Pos
2864 (Cumulative_Restrictions
.Set
(Cumulative_Restrictions
.Set
'Last)));
2866 Write_Statement_Buffer
;
2869 for J
in Cumulative_Restrictions
.Value
'First ..
2870 Restriction_Id
'Pred (Cumulative_Restrictions
.Value
'Last)
2872 Set_Int
(Int
(Cumulative_Restrictions
.Value
(J
)));
2876 Set_Int
(Int
(Cumulative_Restrictions
.Value
2877 (Cumulative_Restrictions
.Value
'Last)));
2879 Write_Statement_Buffer
;
2882 for J
in Cumulative_Restrictions
.Violated
'First ..
2883 Restriction_Id
'Pred (Cumulative_Restrictions
.Violated
'Last)
2885 Set_Int
(Boolean'Pos (Cumulative_Restrictions
.Violated
(J
)));
2889 Set_Int
(Boolean'Pos (Cumulative_Restrictions
.Violated
2890 (Cumulative_Restrictions
.Violated
'Last)));
2892 Write_Statement_Buffer
;
2895 for J
in Cumulative_Restrictions
.Count
'First ..
2896 Restriction_Id
'Pred (Cumulative_Restrictions
.Count
'Last)
2898 Set_Int
(Int
(Cumulative_Restrictions
.Count
(J
)));
2902 Set_Int
(Int
(Cumulative_Restrictions
.Count
2903 (Cumulative_Restrictions
.Count
'Last)));
2905 Write_Statement_Buffer
;
2908 for J
in Cumulative_Restrictions
.Unknown
'First ..
2909 Restriction_Id
'Pred (Cumulative_Restrictions
.Unknown
'Last)
2911 Set_Int
(Boolean'Pos (Cumulative_Restrictions
.Unknown
(J
)));
2915 Set_Int
(Boolean'Pos (Cumulative_Restrictions
.Unknown
2916 (Cumulative_Restrictions
.Unknown
'Last)));
2918 Write_Statement_Buffer
;
2919 WBI
(" system__restrictions__run_time_restrictions = r;");
2920 end Gen_Restrictions_C
;
2922 ----------------------
2923 -- Gen_Versions_Ada --
2924 ----------------------
2926 -- This routine generates two sets of lines. The first set has the form:
2928 -- unnnnn : constant Integer := 16#hhhhhhhh#;
2930 -- The second set has the form
2932 -- pragma Export (C, unnnnn, unam);
2934 -- for each unit, where unam is the unit name suffixed by either B or
2935 -- S for body or spec, with dots replaced by double underscores, and
2936 -- hhhhhhhh is the version number, and nnnnn is a 5-digits serial number.
2938 procedure Gen_Versions_Ada
is
2939 Ubuf
: String (1 .. 6) := "u00000";
2941 procedure Increment_Ubuf
;
2942 -- Little procedure to increment the serial number
2944 procedure Increment_Ubuf
is
2946 for J
in reverse Ubuf
'Range loop
2947 Ubuf
(J
) := Character'Succ (Ubuf
(J
));
2948 exit when Ubuf
(J
) <= '9';
2953 -- Start of processing for Gen_Versions_Ada
2956 if Bind_For_Library
then
2958 -- When building libraries, the version number of each unit can
2959 -- not be computed, since the binder does not know the full list
2960 -- of units. Therefore, the 'Version and 'Body_Version
2961 -- attributes cannot supported in this case.
2968 WBI
(" type Version_32 is mod 2 ** 32;");
2969 for U
in Units
.First
.. Units
.Last
loop
2971 WBI
(" " & Ubuf
& " : constant Version_32 := 16#" &
2972 Units
.Table
(U
).Version
& "#;");
2978 for U
in Units
.First
.. Units
.Last
loop
2980 Set_String
(" pragma Export (C, ");
2982 Set_String
(", """);
2984 Get_Name_String
(Units
.Table
(U
).Uname
);
2986 for K
in 1 .. Name_Len
loop
2987 if Name_Buffer
(K
) = '.' then
2991 elsif Name_Buffer
(K
) = '%' then
2995 Set_Char
(Name_Buffer
(K
));
2999 if Name_Buffer
(Name_Len
) = 's' then
3005 Set_String
(""");");
3006 Write_Statement_Buffer
;
3009 end Gen_Versions_Ada
;
3011 --------------------
3012 -- Gen_Versions_C --
3013 --------------------
3015 -- This routine generates a line of the form:
3017 -- unsigned unam = 0xhhhhhhhh;
3019 -- for each unit, where unam is the unit name suffixed by either B or
3020 -- S for body or spec, with dots replaced by double underscores.
3022 procedure Gen_Versions_C
is
3024 if Bind_For_Library
then
3026 -- When building libraries, the version number of each unit can
3027 -- not be computed, since the binder does not know the full list
3028 -- of units. Therefore, the 'Version and 'Body_Version
3029 -- attributes cannot supported.
3034 for U
in Units
.First
.. Units
.Last
loop
3035 Set_String
("unsigned ");
3037 Get_Name_String
(Units
.Table
(U
).Uname
);
3039 for K
in 1 .. Name_Len
loop
3040 if Name_Buffer
(K
) = '.' then
3043 elsif Name_Buffer
(K
) = '%' then
3047 Set_Char
(Name_Buffer
(K
));
3051 if Name_Buffer
(Name_Len
) = 's' then
3057 Set_String
(" = 0x");
3058 Set_String
(Units
.Table
(U
).Version
);
3060 Write_Statement_Buffer
;
3065 ------------------------
3066 -- Get_Main_Unit_Name --
3067 ------------------------
3069 function Get_Main_Unit_Name
(S
: String) return String is
3070 Result
: String := S
;
3073 for J
in S
'Range loop
3074 if Result
(J
) = '.' then
3080 end Get_Main_Unit_Name
;
3082 -----------------------
3083 -- Get_Ada_Main_Name --
3084 -----------------------
3086 function Get_Ada_Main_Name
return String is
3087 Suffix
: constant String := "_00";
3088 Name
: String (1 .. Opt
.Ada_Main_Name
.all'Length + Suffix
'Length) :=
3089 Opt
.Ada_Main_Name
.all & Suffix
;
3093 -- The main program generated by JGNAT expects a package called
3094 -- ada_<main procedure>.
3096 if VM_Target
/= No_VM
then
3097 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
3098 return "ada_" & Get_Main_Unit_Name
(Name_Buffer
(1 .. Name_Len
- 2));
3101 -- This loop tries the following possibilities in order
3107 -- where <Ada_Main> is equal to Opt.Ada_Main_Name. By default,
3108 -- it is set to 'ada_main'.
3110 for J
in 0 .. 99 loop
3112 Nlen
:= Name
'Length - Suffix
'Length;
3114 Nlen
:= Name
'Length;
3115 Name
(Name
'Last) := Character'Val (J
mod 10 + Character'Pos ('0'));
3116 Name
(Name
'Last - 1) :=
3117 Character'Val (J
/ 10 + Character'Pos ('0'));
3120 for K
in ALIs
.First
.. ALIs
.Last
loop
3121 for L
in ALIs
.Table
(K
).First_Unit
.. ALIs
.Table
(K
).Last_Unit
loop
3123 -- Get unit name, removing %b or %e at end
3125 Get_Name_String
(Units
.Table
(L
).Uname
);
3126 Name_Len
:= Name_Len
- 2;
3128 if Name_Buffer
(1 .. Name_Len
) = Name
(1 .. Nlen
) then
3134 return Name
(1 .. Nlen
);
3140 -- If we fall through, just use a peculiar unlikely name
3142 return ("Qwertyuiop");
3143 end Get_Ada_Main_Name
;
3149 function Get_Main_Name
return String is
3151 -- Explicit name given with -M switch
3153 if Bind_Alternate_Main_Name
then
3154 return Alternate_Main_Name
.all;
3156 -- Case of main program name to be used directly
3158 elsif Use_Ada_Main_Program_Name_On_Target
then
3160 -- Get main program name
3162 Get_Name_String
(Units
.Table
(First_Unit_Entry
).Uname
);
3164 -- If this is a child name, return only the name of the child,
3165 -- since we can't have dots in a nested program name. Note that
3166 -- we do not include the %b at the end of the unit name.
3168 for J
in reverse 1 .. Name_Len
- 2 loop
3169 if J
= 1 or else Name_Buffer
(J
- 1) = '.' then
3170 return Name_Buffer
(J
.. Name_Len
- 2);
3174 raise Program_Error
; -- impossible exit
3176 -- Case where "main" is to be used as default
3183 ---------------------
3184 -- Get_WC_Encoding --
3185 ---------------------
3187 function Get_WC_Encoding
return Character is
3189 -- If encoding method specified by -W switch, then return it
3191 if Wide_Character_Encoding_Method_Specified
then
3192 return WC_Encoding_Letters
(Wide_Character_Encoding_Method
);
3194 -- If no main program, and not specified, set brackets, we really have
3195 -- no better choice. If some other encoding is required when there is
3196 -- no main, it must be set explicitly using -Wx.
3198 -- Note: if the ALI file always passed the wide character encoding
3199 -- of every file, then we could use the encoding of the initial
3200 -- specified file, but this information is passed only for potential
3201 -- main programs. We could fix this sometime, but it is a very minor
3202 -- point (wide character default encoding for [Wide_[Wide_]Text_IO
3203 -- when there is no main program).
3205 elsif No_Main_Subprogram
then
3208 -- Otherwise if there is a main program, take encoding from it
3211 return ALIs
.Table
(ALIs
.First
).WC_Encoding
;
3213 end Get_WC_Encoding
;
3215 ----------------------
3216 -- Lt_Linker_Option --
3217 ----------------------
3219 function Lt_Linker_Option
(Op1
, Op2
: Natural) return Boolean is
3221 -- Sort internal files last
3223 if Linker_Options
.Table
(Op1
).Internal_File
3225 Linker_Options
.Table
(Op2
).Internal_File
3227 -- Note: following test uses False < True
3229 return Linker_Options
.Table
(Op1
).Internal_File
3231 Linker_Options
.Table
(Op2
).Internal_File
;
3233 -- If both internal or both non-internal, sort according to the
3234 -- elaboration position. A unit that is elaborated later should
3235 -- come earlier in the linker options list.
3238 return Units
.Table
(Linker_Options
.Table
(Op1
).Unit
).Elab_Position
3240 Units
.Table
(Linker_Options
.Table
(Op2
).Unit
).Elab_Position
;
3243 end Lt_Linker_Option
;
3245 ------------------------
3246 -- Move_Linker_Option --
3247 ------------------------
3249 procedure Move_Linker_Option
(From
: Natural; To
: Natural) is
3251 Linker_Options
.Table
(To
) := Linker_Options
.Table
(From
);
3252 end Move_Linker_Option
;
3254 ----------------------------
3255 -- Resolve_Binder_Options --
3256 ----------------------------
3258 procedure Resolve_Binder_Options
is
3260 for E
in Elab_Order
.First
.. Elab_Order
.Last
loop
3261 Get_Name_String
(Units
.Table
(Elab_Order
.Table
(E
)).Uname
);
3263 -- This is not a perfect approach, but is the current protocol
3264 -- between the run-time and the binder to indicate that tasking
3265 -- is used: system.os_interface should always be used by any
3266 -- tasking application.
3268 if Name_Buffer
(1 .. 19) = "system.os_interface" then
3272 -- Ditto for declib and the "dec" package
3274 if OpenVMS_On_Target
and then Name_Buffer
(1 .. 5) = "dec%s" then
3275 With_DECGNAT
:= True;
3278 end Resolve_Binder_Options
;
3284 procedure Set_Boolean
(B
: Boolean) is
3285 True_Str
: constant String := "True";
3286 False_Str
: constant String := "False";
3289 Statement_Buffer
(Last
+ 1 .. Last
+ True_Str
'Length) := True_Str
;
3290 Last
:= Last
+ True_Str
'Length;
3292 Statement_Buffer
(Last
+ 1 .. Last
+ False_Str
'Length) := False_Str
;
3293 Last
:= Last
+ False_Str
'Length;
3301 procedure Set_Char
(C
: Character) is
3304 Statement_Buffer
(Last
) := C
;
3311 procedure Set_Int
(N
: Int
) is
3323 Statement_Buffer
(Last
) :=
3324 Character'Val (N
mod 10 + Character'Pos ('0'));
3328 -------------------------
3329 -- Set_IS_Pragma_Table --
3330 -------------------------
3332 procedure Set_IS_Pragma_Table
is
3334 for F
in ALIs
.First
.. ALIs
.Last
loop
3335 for K
in ALIs
.Table
(F
).First_Interrupt_State
..
3336 ALIs
.Table
(F
).Last_Interrupt_State
3339 Inum
: constant Int
:=
3340 Interrupt_States
.Table
(K
).Interrupt_Id
;
3341 Stat
: constant Character :=
3342 Interrupt_States
.Table
(K
).Interrupt_State
;
3345 while IS_Pragma_Settings
.Last
< Inum
loop
3346 IS_Pragma_Settings
.Append
('n');
3349 IS_Pragma_Settings
.Table
(Inum
) := Stat
;
3353 end Set_IS_Pragma_Table
;
3355 ---------------------------
3356 -- Set_Main_Program_Name --
3357 ---------------------------
3359 procedure Set_Main_Program_Name
is
3361 -- Note that name has %b on the end which we ignore
3363 -- First we output the initial _ada_ since we know that the main
3364 -- program is a library level subprogram.
3366 Set_String
("_ada_");
3368 -- Copy name, changing dots to double underscores
3370 for J
in 1 .. Name_Len
- 2 loop
3371 if Name_Buffer
(J
) = '.' then
3374 Set_Char
(Name_Buffer
(J
));
3377 end Set_Main_Program_Name
;
3379 ---------------------
3380 -- Set_Name_Buffer --
3381 ---------------------
3383 procedure Set_Name_Buffer
is
3385 for J
in 1 .. Name_Len
loop
3386 Set_Char
(Name_Buffer
(J
));
3388 end Set_Name_Buffer
;
3390 -------------------------
3391 -- Set_PSD_Pragma_Table --
3392 -------------------------
3394 procedure Set_PSD_Pragma_Table
is
3396 for F
in ALIs
.First
.. ALIs
.Last
loop
3397 for K
in ALIs
.Table
(F
).First_Specific_Dispatching
..
3398 ALIs
.Table
(F
).Last_Specific_Dispatching
3401 DTK
: Specific_Dispatching_Record
3402 renames Specific_Dispatching
.Table
(K
);
3405 while PSD_Pragma_Settings
.Last
< DTK
.Last_Priority
loop
3406 PSD_Pragma_Settings
.Append
('F');
3409 for Prio
in DTK
.First_Priority
.. DTK
.Last_Priority
loop
3410 PSD_Pragma_Settings
.Table
(Prio
) := DTK
.Dispatching_Policy
;
3415 end Set_PSD_Pragma_Table
;
3421 procedure Set_String
(S
: String) is
3423 Statement_Buffer
(Last
+ 1 .. Last
+ S
'Length) := S
;
3424 Last
:= Last
+ S
'Length;
3431 procedure Set_Unit_Name
is
3433 for J
in 1 .. Name_Len
- 2 loop
3434 if Name_Buffer
(J
) /= '.' then
3435 Set_Char
(Name_Buffer
(J
));
3442 ---------------------
3443 -- Set_Unit_Number --
3444 ---------------------
3446 procedure Set_Unit_Number
(U
: Unit_Id
) is
3447 Num_Units
: constant Nat
:= Nat
(Units
.Last
) - Nat
(Unit_Id
'First);
3448 Unum
: constant Nat
:= Nat
(U
) - Nat
(Unit_Id
'First);
3451 if Num_Units
>= 10 and then Unum
< 10 then
3455 if Num_Units
>= 100 and then Unum
< 100 then
3460 end Set_Unit_Number
;
3462 ----------------------
3463 -- Write_Info_Ada_C --
3464 ----------------------
3466 procedure Write_Info_Ada_C
(Ada
: String; C
: String; Common
: String) is
3468 if Ada_Bind_File
then
3470 S
: String (1 .. Ada
'Length + Common
'Length);
3472 S
(1 .. Ada
'Length) := Ada
;
3473 S
(Ada
'Length + 1 .. S
'Length) := Common
;
3479 S
: String (1 .. C
'Length + Common
'Length);
3481 S
(1 .. C
'Length) := C
;
3482 S
(C
'Length + 1 .. S
'Length) := Common
;
3486 end Write_Info_Ada_C
;
3488 ----------------------------
3489 -- Write_Statement_Buffer --
3490 ----------------------------
3492 procedure Write_Statement_Buffer
is
3494 WBI
(Statement_Buffer
(1 .. Last
));
3496 end Write_Statement_Buffer
;
3498 procedure Write_Statement_Buffer
(S
: String) is
3501 Write_Statement_Buffer
;
3502 end Write_Statement_Buffer
;