Debian Codegraph @

gcc/ada/doc/gnat_ugn/example_of_binder_output.rst

raw
1 .. _Example_of_Binder_Output_File:
2
3 *****************************
4 Example of Binder Output File
5 *****************************
6
7 .. index:: Binder output (example)
8
9 This Appendix displays the source code for the output file
10 generated by ``gnatbind`` for a simple 'Hello World' program.
11 Comments have been added for clarification purposes.
12
13
14 .. code-block:: ada
15
16 -- The package is called Ada_Main unless this name is actually used
17 -- as a unit name in the partition, in which case some other unique
18 -- name is used.
19
20 pragma Ada_95;
21 with System;
22 package ada_main is
23 pragma Warnings (Off);
24
25 -- The main program saves the parameters (argument count,
26 -- argument values, environment pointer) in global variables
27 -- for later access by other units including Ada.Command_Line.
28
29 gnat_argc : Integer;
30 gnat_argv : System.Address;
31 gnat_envp : System.Address;
32
33 -- The actual variables are stored in a library routine. This
34 -- is useful for some shared library situations, where there
35 -- are problems if variables are not in the library.
36
37 pragma Import (C, gnat_argc);
38 pragma Import (C, gnat_argv);
39 pragma Import (C, gnat_envp);
40
41 -- The exit status is similarly an external location
42
43 gnat_exit_status : Integer;
44 pragma Import (C, gnat_exit_status);
45
46 GNAT_Version : constant String :=
47 "GNAT Version: Pro 7.4.0w (20141119-49)" & ASCII.NUL;
48 pragma Export (C, GNAT_Version, "__gnat_version");
49
50 Ada_Main_Program_Name : constant String := "_ada_hello" & ASCII.NUL;
51 pragma Export (C, Ada_Main_Program_Name, "__gnat_ada_main_program_name");
52
53 -- This is the generated adainit routine that performs
54 -- initialization at the start of execution. In the case
55 -- where Ada is the main program, this main program makes
56 -- a call to adainit at program startup.
57
58 procedure adainit;
59 pragma Export (C, adainit, "adainit");
60
61 -- This is the generated adafinal routine that performs
62 -- finalization at the end of execution. In the case where
63 -- Ada is the main program, this main program makes a call
64 -- to adafinal at program termination.
65
66 procedure adafinal;
67 pragma Export (C, adafinal, "adafinal");
68
69 -- This routine is called at the start of execution. It is
70 -- a dummy routine that is used by the debugger to breakpoint
71 -- at the start of execution.
72
73 -- This is the actual generated main program (it would be
74 -- suppressed if the no main program switch were used). As
75 -- required by standard system conventions, this program has
76 -- the external name main.
77
78 function main
79 (argc : Integer;
80 argv : System.Address;
81 envp : System.Address)
82 return Integer;
83 pragma Export (C, main, "main");
84
85 -- The following set of constants give the version
86 -- identification values for every unit in the bound
87 -- partition. This identification is computed from all
88 -- dependent semantic units, and corresponds to the
89 -- string that would be returned by use of the
90 -- Body_Version or Version attributes.
91
92 -- The following Export pragmas export the version numbers
93 -- with symbolic names ending in B (for body) or S
94 -- (for spec) so that they can be located in a link. The
95 -- information provided here is sufficient to track down
96 -- the exact versions of units used in a given build.
97
98 type Version_32 is mod 2 ** 32;
99 u00001 : constant Version_32 := 16#8ad6e54a#;
100 pragma Export (C, u00001, "helloB");
101 u00002 : constant Version_32 := 16#fbff4c67#;
102 pragma Export (C, u00002, "system__standard_libraryB");
103 u00003 : constant Version_32 := 16#1ec6fd90#;
104 pragma Export (C, u00003, "system__standard_libraryS");
105 u00004 : constant Version_32 := 16#3ffc8e18#;
106 pragma Export (C, u00004, "adaS");
107 u00005 : constant Version_32 := 16#28f088c2#;
108 pragma Export (C, u00005, "ada__text_ioB");
109 u00006 : constant Version_32 := 16#f372c8ac#;
110 pragma Export (C, u00006, "ada__text_ioS");
111 u00007 : constant Version_32 := 16#2c143749#;
112 pragma Export (C, u00007, "ada__exceptionsB");
113 u00008 : constant Version_32 := 16#f4f0cce8#;
114 pragma Export (C, u00008, "ada__exceptionsS");
115 u00009 : constant Version_32 := 16#a46739c0#;
116 pragma Export (C, u00009, "ada__exceptions__last_chance_handlerB");
117 u00010 : constant Version_32 := 16#3aac8c92#;
118 pragma Export (C, u00010, "ada__exceptions__last_chance_handlerS");
119 u00011 : constant Version_32 := 16#1d274481#;
120 pragma Export (C, u00011, "systemS");
121 u00012 : constant Version_32 := 16#a207fefe#;
122 pragma Export (C, u00012, "system__soft_linksB");
123 u00013 : constant Version_32 := 16#467d9556#;
124 pragma Export (C, u00013, "system__soft_linksS");
125 u00014 : constant Version_32 := 16#b01dad17#;
126 pragma Export (C, u00014, "system__parametersB");
127 u00015 : constant Version_32 := 16#630d49fe#;
128 pragma Export (C, u00015, "system__parametersS");
129 u00016 : constant Version_32 := 16#b19b6653#;
130 pragma Export (C, u00016, "system__secondary_stackB");
131 u00017 : constant Version_32 := 16#b6468be8#;
132 pragma Export (C, u00017, "system__secondary_stackS");
133 u00018 : constant Version_32 := 16#39a03df9#;
134 pragma Export (C, u00018, "system__storage_elementsB");
135 u00019 : constant Version_32 := 16#30e40e85#;
136 pragma Export (C, u00019, "system__storage_elementsS");
137 u00020 : constant Version_32 := 16#41837d1e#;
138 pragma Export (C, u00020, "system__stack_checkingB");
139 u00021 : constant Version_32 := 16#93982f69#;
140 pragma Export (C, u00021, "system__stack_checkingS");
141 u00022 : constant Version_32 := 16#393398c1#;
142 pragma Export (C, u00022, "system__exception_tableB");
143 u00023 : constant Version_32 := 16#b33e2294#;
144 pragma Export (C, u00023, "system__exception_tableS");
145 u00024 : constant Version_32 := 16#ce4af020#;
146 pragma Export (C, u00024, "system__exceptionsB");
147 u00025 : constant Version_32 := 16#75442977#;
148 pragma Export (C, u00025, "system__exceptionsS");
149 u00026 : constant Version_32 := 16#37d758f1#;
150 pragma Export (C, u00026, "system__exceptions__machineS");
151 u00027 : constant Version_32 := 16#b895431d#;
152 pragma Export (C, u00027, "system__exceptions_debugB");
153 u00028 : constant Version_32 := 16#aec55d3f#;
154 pragma Export (C, u00028, "system__exceptions_debugS");
155 u00029 : constant Version_32 := 16#570325c8#;
156 pragma Export (C, u00029, "system__img_intB");
157 u00030 : constant Version_32 := 16#1ffca443#;
158 pragma Export (C, u00030, "system__img_intS");
159 u00031 : constant Version_32 := 16#b98c3e16#;
160 pragma Export (C, u00031, "system__tracebackB");
161 u00032 : constant Version_32 := 16#831a9d5a#;
162 pragma Export (C, u00032, "system__tracebackS");
163 u00033 : constant Version_32 := 16#9ed49525#;
164 pragma Export (C, u00033, "system__traceback_entriesB");
165 u00034 : constant Version_32 := 16#1d7cb2f1#;
166 pragma Export (C, u00034, "system__traceback_entriesS");
167 u00035 : constant Version_32 := 16#8c33a517#;
168 pragma Export (C, u00035, "system__wch_conB");
169 u00036 : constant Version_32 := 16#065a6653#;
170 pragma Export (C, u00036, "system__wch_conS");
171 u00037 : constant Version_32 := 16#9721e840#;
172 pragma Export (C, u00037, "system__wch_stwB");
173 u00038 : constant Version_32 := 16#2b4b4a52#;
174 pragma Export (C, u00038, "system__wch_stwS");
175 u00039 : constant Version_32 := 16#92b797cb#;
176 pragma Export (C, u00039, "system__wch_cnvB");
177 u00040 : constant Version_32 := 16#09eddca0#;
178 pragma Export (C, u00040, "system__wch_cnvS");
179 u00041 : constant Version_32 := 16#6033a23f#;
180 pragma Export (C, u00041, "interfacesS");
181 u00042 : constant Version_32 := 16#ece6fdb6#;
182 pragma Export (C, u00042, "system__wch_jisB");
183 u00043 : constant Version_32 := 16#899dc581#;
184 pragma Export (C, u00043, "system__wch_jisS");
185 u00044 : constant Version_32 := 16#10558b11#;
186 pragma Export (C, u00044, "ada__streamsB");
187 u00045 : constant Version_32 := 16#2e6701ab#;
188 pragma Export (C, u00045, "ada__streamsS");
189 u00046 : constant Version_32 := 16#db5c917c#;
190 pragma Export (C, u00046, "ada__io_exceptionsS");
191 u00047 : constant Version_32 := 16#12c8cd7d#;
192 pragma Export (C, u00047, "ada__tagsB");
193 u00048 : constant Version_32 := 16#ce72c228#;
194 pragma Export (C, u00048, "ada__tagsS");
195 u00049 : constant Version_32 := 16#c3335bfd#;
196 pragma Export (C, u00049, "system__htableB");
197 u00050 : constant Version_32 := 16#99e5f76b#;
198 pragma Export (C, u00050, "system__htableS");
199 u00051 : constant Version_32 := 16#089f5cd0#;
200 pragma Export (C, u00051, "system__string_hashB");
201 u00052 : constant Version_32 := 16#3bbb9c15#;
202 pragma Export (C, u00052, "system__string_hashS");
203 u00053 : constant Version_32 := 16#807fe041#;
204 pragma Export (C, u00053, "system__unsigned_typesS");
205 u00054 : constant Version_32 := 16#d27be59e#;
206 pragma Export (C, u00054, "system__val_lluB");
207 u00055 : constant Version_32 := 16#fa8db733#;
208 pragma Export (C, u00055, "system__val_lluS");
209 u00056 : constant Version_32 := 16#27b600b2#;
210 pragma Export (C, u00056, "system__val_utilB");
211 u00057 : constant Version_32 := 16#b187f27f#;
212 pragma Export (C, u00057, "system__val_utilS");
213 u00058 : constant Version_32 := 16#d1060688#;
214 pragma Export (C, u00058, "system__case_utilB");
215 u00059 : constant Version_32 := 16#392e2d56#;
216 pragma Export (C, u00059, "system__case_utilS");
217 u00060 : constant Version_32 := 16#84a27f0d#;
218 pragma Export (C, u00060, "interfaces__c_streamsB");
219 u00061 : constant Version_32 := 16#8bb5f2c0#;
220 pragma Export (C, u00061, "interfaces__c_streamsS");
221 u00062 : constant Version_32 := 16#6db6928f#;
222 pragma Export (C, u00062, "system__crtlS");
223 u00063 : constant Version_32 := 16#4e6a342b#;
224 pragma Export (C, u00063, "system__file_ioB");
225 u00064 : constant Version_32 := 16#ba56a5e4#;
226 pragma Export (C, u00064, "system__file_ioS");
227 u00065 : constant Version_32 := 16#b7ab275c#;
228 pragma Export (C, u00065, "ada__finalizationB");
229 u00066 : constant Version_32 := 16#19f764ca#;
230 pragma Export (C, u00066, "ada__finalizationS");
231 u00067 : constant Version_32 := 16#95817ed8#;
232 pragma Export (C, u00067, "system__finalization_rootB");
233 u00068 : constant Version_32 := 16#52d53711#;
234 pragma Export (C, u00068, "system__finalization_rootS");
235 u00069 : constant Version_32 := 16#769e25e6#;
236 pragma Export (C, u00069, "interfaces__cB");
237 u00070 : constant Version_32 := 16#4a38bedb#;
238 pragma Export (C, u00070, "interfaces__cS");
239 u00071 : constant Version_32 := 16#07e6ee66#;
240 pragma Export (C, u00071, "system__os_libB");
241 u00072 : constant Version_32 := 16#d7b69782#;
242 pragma Export (C, u00072, "system__os_libS");
243 u00073 : constant Version_32 := 16#1a817b8e#;
244 pragma Export (C, u00073, "system__stringsB");
245 u00074 : constant Version_32 := 16#639855e7#;
246 pragma Export (C, u00074, "system__stringsS");
247 u00075 : constant Version_32 := 16#e0b8de29#;
248 pragma Export (C, u00075, "system__file_control_blockS");
249 u00076 : constant Version_32 := 16#b5b2aca1#;
250 pragma Export (C, u00076, "system__finalization_mastersB");
251 u00077 : constant Version_32 := 16#69316dc1#;
252 pragma Export (C, u00077, "system__finalization_mastersS");
253 u00078 : constant Version_32 := 16#57a37a42#;
254 pragma Export (C, u00078, "system__address_imageB");
255 u00079 : constant Version_32 := 16#bccbd9bb#;
256 pragma Export (C, u00079, "system__address_imageS");
257 u00080 : constant Version_32 := 16#7268f812#;
258 pragma Export (C, u00080, "system__img_boolB");
259 u00081 : constant Version_32 := 16#e8fe356a#;
260 pragma Export (C, u00081, "system__img_boolS");
261 u00082 : constant Version_32 := 16#d7aac20c#;
262 pragma Export (C, u00082, "system__ioB");
263 u00083 : constant Version_32 := 16#8365b3ce#;
264 pragma Export (C, u00083, "system__ioS");
265 u00084 : constant Version_32 := 16#6d4d969a#;
266 pragma Export (C, u00084, "system__storage_poolsB");
267 u00085 : constant Version_32 := 16#e87cc305#;
268 pragma Export (C, u00085, "system__storage_poolsS");
269 u00086 : constant Version_32 := 16#e34550ca#;
270 pragma Export (C, u00086, "system__pool_globalB");
271 u00087 : constant Version_32 := 16#c88d2d16#;
272 pragma Export (C, u00087, "system__pool_globalS");
273 u00088 : constant Version_32 := 16#9d39c675#;
274 pragma Export (C, u00088, "system__memoryB");
275 u00089 : constant Version_32 := 16#445a22b5#;
276 pragma Export (C, u00089, "system__memoryS");
277 u00090 : constant Version_32 := 16#6a859064#;
278 pragma Export (C, u00090, "system__storage_pools__subpoolsB");
279 u00091 : constant Version_32 := 16#e3b008dc#;
280 pragma Export (C, u00091, "system__storage_pools__subpoolsS");
281 u00092 : constant Version_32 := 16#63f11652#;
282 pragma Export (C, u00092, "system__storage_pools__subpools__finalizationB");
283 u00093 : constant Version_32 := 16#fe2f4b3a#;
284 pragma Export (C, u00093, "system__storage_pools__subpools__finalizationS");
285
286 -- BEGIN ELABORATION ORDER
287 -- ada%s
288 -- interfaces%s
289 -- system%s
290 -- system.case_util%s
291 -- system.case_util%b
292 -- system.htable%s
293 -- system.img_bool%s
294 -- system.img_bool%b
295 -- system.img_int%s
296 -- system.img_int%b
297 -- system.io%s
298 -- system.io%b
299 -- system.parameters%s
300 -- system.parameters%b
301 -- system.crtl%s
302 -- interfaces.c_streams%s
303 -- interfaces.c_streams%b
304 -- system.standard_library%s
305 -- system.exceptions_debug%s
306 -- system.exceptions_debug%b
307 -- system.storage_elements%s
308 -- system.storage_elements%b
309 -- system.stack_checking%s
310 -- system.stack_checking%b
311 -- system.string_hash%s
312 -- system.string_hash%b
313 -- system.htable%b
314 -- system.strings%s
315 -- system.strings%b
316 -- system.os_lib%s
317 -- system.traceback_entries%s
318 -- system.traceback_entries%b
319 -- ada.exceptions%s
320 -- system.soft_links%s
321 -- system.unsigned_types%s
322 -- system.val_llu%s
323 -- system.val_util%s
324 -- system.val_util%b
325 -- system.val_llu%b
326 -- system.wch_con%s
327 -- system.wch_con%b
328 -- system.wch_cnv%s
329 -- system.wch_jis%s
330 -- system.wch_jis%b
331 -- system.wch_cnv%b
332 -- system.wch_stw%s
333 -- system.wch_stw%b
334 -- ada.exceptions.last_chance_handler%s
335 -- ada.exceptions.last_chance_handler%b
336 -- system.address_image%s
337 -- system.exception_table%s
338 -- system.exception_table%b
339 -- ada.io_exceptions%s
340 -- ada.tags%s
341 -- ada.streams%s
342 -- ada.streams%b
343 -- interfaces.c%s
344 -- system.exceptions%s
345 -- system.exceptions%b
346 -- system.exceptions.machine%s
347 -- system.finalization_root%s
348 -- system.finalization_root%b
349 -- ada.finalization%s
350 -- ada.finalization%b
351 -- system.storage_pools%s
352 -- system.storage_pools%b
353 -- system.finalization_masters%s
354 -- system.storage_pools.subpools%s
355 -- system.storage_pools.subpools.finalization%s
356 -- system.storage_pools.subpools.finalization%b
357 -- system.memory%s
358 -- system.memory%b
359 -- system.standard_library%b
360 -- system.pool_global%s
361 -- system.pool_global%b
362 -- system.file_control_block%s
363 -- system.file_io%s
364 -- system.secondary_stack%s
365 -- system.file_io%b
366 -- system.storage_pools.subpools%b
367 -- system.finalization_masters%b
368 -- interfaces.c%b
369 -- ada.tags%b
370 -- system.soft_links%b
371 -- system.os_lib%b
372 -- system.secondary_stack%b
373 -- system.address_image%b
374 -- system.traceback%s
375 -- ada.exceptions%b
376 -- system.traceback%b
377 -- ada.text_io%s
378 -- ada.text_io%b
379 -- hello%b
380 -- END ELABORATION ORDER
381
382 end ada_main;
383
384 .. code-block:: ada
385
386 pragma Ada_95;
387 -- The following source file name pragmas allow the generated file
388 -- names to be unique for different main programs. They are needed
389 -- since the package name will always be Ada_Main.
390
391 pragma Source_File_Name (ada_main, Spec_File_Name => "b~hello.ads");
392 pragma Source_File_Name (ada_main, Body_File_Name => "b~hello.adb");
393
394 pragma Suppress (Overflow_Check);
395 with Ada.Exceptions;
396
397 -- Generated package body for Ada_Main starts here
398
399 package body ada_main is
400 pragma Warnings (Off);
401
402 -- These values are reference counters associated with units that have
403 -- been elaborated. They are used to avoid elaborating the
404 -- same unit twice.
405
406 E72 : Short_Integer; pragma Import (Ada, E72, "system__os_lib_E");
407 E13 : Short_Integer; pragma Import (Ada, E13, "system__soft_links_E");
408 E23 : Short_Integer; pragma Import (Ada, E23, "system__exception_table_E");
409 E46 : Short_Integer; pragma Import (Ada, E46, "ada__io_exceptions_E");
410 E48 : Short_Integer; pragma Import (Ada, E48, "ada__tags_E");
411 E45 : Short_Integer; pragma Import (Ada, E45, "ada__streams_E");
412 E70 : Short_Integer; pragma Import (Ada, E70, "interfaces__c_E");
413 E25 : Short_Integer; pragma Import (Ada, E25, "system__exceptions_E");
414 E68 : Short_Integer; pragma Import (Ada, E68, "system__finalization_root_E");
415 E66 : Short_Integer; pragma Import (Ada, E66, "ada__finalization_E");
416 E85 : Short_Integer; pragma Import (Ada, E85, "system__storage_pools_E");
417 E77 : Short_Integer; pragma Import (Ada, E77, "system__finalization_masters_E");
418 E91 : Short_Integer; pragma Import (Ada, E91, "system__storage_pools__subpools_E");
419 E87 : Short_Integer; pragma Import (Ada, E87, "system__pool_global_E");
420 E75 : Short_Integer; pragma Import (Ada, E75, "system__file_control_block_E");
421 E64 : Short_Integer; pragma Import (Ada, E64, "system__file_io_E");
422 E17 : Short_Integer; pragma Import (Ada, E17, "system__secondary_stack_E");
423 E06 : Short_Integer; pragma Import (Ada, E06, "ada__text_io_E");
424
425 Local_Priority_Specific_Dispatching : constant String := "";
426 Local_Interrupt_States : constant String := "";
427
428 Is_Elaborated : Boolean := False;
429
430 procedure finalize_library is
431 begin
432 E06 := E06 - 1;
433 declare
434 procedure F1;
435 pragma Import (Ada, F1, "ada__text_io__finalize_spec");
436 begin
437 F1;
438 end;
439 E77 := E77 - 1;
440 E91 := E91 - 1;
441 declare
442 procedure F2;
443 pragma Import (Ada, F2, "system__file_io__finalize_body");
444 begin
445 E64 := E64 - 1;
446 F2;
447 end;
448 declare
449 procedure F3;
450 pragma Import (Ada, F3, "system__file_control_block__finalize_spec");
451 begin
452 E75 := E75 - 1;
453 F3;
454 end;
455 E87 := E87 - 1;
456 declare
457 procedure F4;
458 pragma Import (Ada, F4, "system__pool_global__finalize_spec");
459 begin
460 F4;
461 end;
462 declare
463 procedure F5;
464 pragma Import (Ada, F5, "system__storage_pools__subpools__finalize_spec");
465 begin
466 F5;
467 end;
468 declare
469 procedure F6;
470 pragma Import (Ada, F6, "system__finalization_masters__finalize_spec");
471 begin
472 F6;
473 end;
474 declare
475 procedure Reraise_Library_Exception_If_Any;
476 pragma Import (Ada, Reraise_Library_Exception_If_Any, "__gnat_reraise_library_exception_if_any");
477 begin
478 Reraise_Library_Exception_If_Any;
479 end;
480 end finalize_library;
481
482 -------------
483 -- adainit --
484 -------------
485
486 procedure adainit is
487
488 Main_Priority : Integer;
489 pragma Import (C, Main_Priority, "__gl_main_priority");
490 Time_Slice_Value : Integer;
491 pragma Import (C, Time_Slice_Value, "__gl_time_slice_val");
492 WC_Encoding : Character;
493 pragma Import (C, WC_Encoding, "__gl_wc_encoding");
494 Locking_Policy : Character;
495 pragma Import (C, Locking_Policy, "__gl_locking_policy");
496 Queuing_Policy : Character;
497 pragma Import (C, Queuing_Policy, "__gl_queuing_policy");
498 Task_Dispatching_Policy : Character;
499 pragma Import (C, Task_Dispatching_Policy, "__gl_task_dispatching_policy");
500 Priority_Specific_Dispatching : System.Address;
501 pragma Import (C, Priority_Specific_Dispatching, "__gl_priority_specific_dispatching");
502 Num_Specific_Dispatching : Integer;
503 pragma Import (C, Num_Specific_Dispatching, "__gl_num_specific_dispatching");
504 Main_CPU : Integer;
505 pragma Import (C, Main_CPU, "__gl_main_cpu");
506 Interrupt_States : System.Address;
507 pragma Import (C, Interrupt_States, "__gl_interrupt_states");
508 Num_Interrupt_States : Integer;
509 pragma Import (C, Num_Interrupt_States, "__gl_num_interrupt_states");
510 Unreserve_All_Interrupts : Integer;
511 pragma Import (C, Unreserve_All_Interrupts, "__gl_unreserve_all_interrupts");
512 Detect_Blocking : Integer;
513 pragma Import (C, Detect_Blocking, "__gl_detect_blocking");
514 Default_Stack_Size : Integer;
515 pragma Import (C, Default_Stack_Size, "__gl_default_stack_size");
516 Leap_Seconds_Support : Integer;
517 pragma Import (C, Leap_Seconds_Support, "__gl_leap_seconds_support");
518
519 procedure Runtime_Initialize;
520 pragma Import (C, Runtime_Initialize, "__gnat_runtime_initialize");
521
522 Finalize_Library_Objects : No_Param_Proc;
523 pragma Import (C, Finalize_Library_Objects, "__gnat_finalize_library_objects");
524
525 -- Start of processing for adainit
526
527 begin
528
529 -- Record various information for this partition. The values
530 -- are derived by the binder from information stored in the ali
531 -- files by the compiler.
532
533 if Is_Elaborated then
534 return;
535 end if;
536 Is_Elaborated := True;
537 Main_Priority := -1;
538 Time_Slice_Value := -1;
539 WC_Encoding := 'b';
540 Locking_Policy := ' ';
541 Queuing_Policy := ' ';
542 Task_Dispatching_Policy := ' ';
543 Priority_Specific_Dispatching :=
544 Local_Priority_Specific_Dispatching'Address;
545 Num_Specific_Dispatching := 0;
546 Main_CPU := -1;
547 Interrupt_States := Local_Interrupt_States'Address;
548 Num_Interrupt_States := 0;
549 Unreserve_All_Interrupts := 0;
550 Detect_Blocking := 0;
551 Default_Stack_Size := -1;
552 Leap_Seconds_Support := 0;
553
554 Runtime_Initialize;
555
556 Finalize_Library_Objects := finalize_library'access;
557
558 -- Now we have the elaboration calls for all units in the partition.
559 -- The Elab_Spec and Elab_Body attributes generate references to the
560 -- implicit elaboration procedures generated by the compiler for
561 -- each unit that requires elaboration. Also increment a reference
562 -- counter for each unit.
563
564 System.Soft_Links'Elab_Spec;
565 System.Exception_Table'Elab_Body;
566 E23 := E23 + 1;
567 Ada.Io_Exceptions'Elab_Spec;
568 E46 := E46 + 1;
569 Ada.Tags'Elab_Spec;
570 Ada.Streams'Elab_Spec;
571 E45 := E45 + 1;
572 Interfaces.C'Elab_Spec;
573 System.Exceptions'Elab_Spec;
574 E25 := E25 + 1;
575 System.Finalization_Root'Elab_Spec;
576 E68 := E68 + 1;
577 Ada.Finalization'Elab_Spec;
578 E66 := E66 + 1;
579 System.Storage_Pools'Elab_Spec;
580 E85 := E85 + 1;
581 System.Finalization_Masters'Elab_Spec;
582 System.Storage_Pools.Subpools'Elab_Spec;
583 System.Pool_Global'Elab_Spec;
584 E87 := E87 + 1;
585 System.File_Control_Block'Elab_Spec;
586 E75 := E75 + 1;
587 System.File_Io'Elab_Body;
588 E64 := E64 + 1;
589 E91 := E91 + 1;
590 System.Finalization_Masters'Elab_Body;
591 E77 := E77 + 1;
592 E70 := E70 + 1;
593 Ada.Tags'Elab_Body;
594 E48 := E48 + 1;
595 System.Soft_Links'Elab_Body;
596 E13 := E13 + 1;
597 System.Os_Lib'Elab_Body;
598 E72 := E72 + 1;
599 System.Secondary_Stack'Elab_Body;
600 E17 := E17 + 1;
601 Ada.Text_Io'Elab_Spec;
602 Ada.Text_Io'Elab_Body;
603 E06 := E06 + 1;
604 end adainit;
605
606 --------------
607 -- adafinal --
608 --------------
609
610 procedure adafinal is
611 procedure s_stalib_adafinal;
612 pragma Import (C, s_stalib_adafinal, "system__standard_library__adafinal");
613
614 procedure Runtime_Finalize;
615 pragma Import (C, Runtime_Finalize, "__gnat_runtime_finalize");
616
617 begin
618 if not Is_Elaborated then
619 return;
620 end if;
621 Is_Elaborated := False;
622 Runtime_Finalize;
623 s_stalib_adafinal;
624 end adafinal;
625
626 -- We get to the main program of the partition by using
627 -- pragma Import because if we try to 'with' the unit and
628 -- call it in Ada style, not only do we waste time recompiling it,
629 -- but we don't know the right switches (e.g.@: identifier
630 -- character set) to be used to compile it.
631
632 procedure Ada_Main_Program;
633 pragma Import (Ada, Ada_Main_Program, "_ada_hello");
634
635 ----------
636 -- main --
637 ----------
638
639 -- main is actually a function, as in the ANSI C standard,
640 -- defined to return the exit status. The three parameters
641 -- are the argument count, argument values and environment
642 -- pointer.
643
644 function main
645 (argc : Integer;
646 argv : System.Address;
647 envp : System.Address)
648 return Integer
649 is
650 -- The initialize routine performs low level system
651 -- initialization using a standard library routine which
652 -- sets up signal handling and performs any other
653 -- required setup. The routine can be found in file
654 -- a-init.c.
655
656 procedure initialize;
657 pragma Import (C, initialize, "__gnat_initialize");
658
659 -- The finalize routine performs low level system
660 -- finalization using a standard library routine. The
661 -- routine is found in file a-final.c and in the standard
662 -- distribution is a dummy routine that does nothing, so
663 -- really this is a hook for special user finalization.
664
665 procedure finalize;
666 pragma Import (C, finalize, "__gnat_finalize");
667
668 -- The following is to initialize the SEH exceptions
669
670 SEH : aliased array (1 .. 2) of Integer;
671
672 Ensure_Reference : aliased System.Address := Ada_Main_Program_Name'Address;
673 pragma Volatile (Ensure_Reference);
674
675 -- Start of processing for main
676
677 begin
678 -- Save global variables
679
680 gnat_argc := argc;
681 gnat_argv := argv;
682 gnat_envp := envp;
683
684 -- Call low level system initialization
685
686 Initialize (SEH'Address);
687
688 -- Call our generated Ada initialization routine
689
690 adainit;
691
692 -- Now we call the main program of the partition
693
694 Ada_Main_Program;
695
696 -- Perform Ada finalization
697
698 adafinal;
699
700 -- Perform low level system finalization
701
702 Finalize;
703
704 -- Return the proper exit status
705 return (gnat_exit_status);
706 end;
707
708 -- This section is entirely comments, so it has no effect on the
709 -- compilation of the Ada_Main package. It provides the list of
710 -- object files and linker options, as well as some standard
711 -- libraries needed for the link. The gnatlink utility parses
712 -- this b~hello.adb file to read these comment lines to generate
713 -- the appropriate command line arguments for the call to the
714 -- system linker. The BEGIN/END lines are used for sentinels for
715 -- this parsing operation.
716
717 -- The exact file names will of course depend on the environment,
718 -- host/target and location of files on the host system.
719
720 -- BEGIN Object file/option list
721 -- ./hello.o
722 -- -L./
723 -- -L/usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/
724 -- /usr/local/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/libgnat.a
725 -- END Object file/option list
726
727 end ada_main;
728
729
730 The Ada code in the above example is exactly what is generated by the
731 binder. We have added comments to more clearly indicate the function
732 of each part of the generated ``Ada_Main`` package.
733
734 The code is standard Ada in all respects, and can be processed by any
735 tools that handle Ada. In particular, you can use the debugger
736 in Ada mode to debug the generated ``Ada_Main`` package. For example,
737 suppose that for reasons you don't understand, your program is crashing
738 during elaboration of the body of ``Ada.Text_IO``. To locate this bug,
739 you can place a breakpoint on the call:
740
741 .. code-block:: ada
742
743 Ada.Text_Io'Elab_Body;
744
745 and trace the elaboration routine for this package to find out where
746 the problem might be (more usually, of course, you would be debugging
747 elaboration code in your own application).