[multiple changes]
[gcc.git] / gcc / ada / lib-writ.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . W R I T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
26
27 with ALI; use ALI;
28 with Atree; use Atree;
29 with Casing; use Casing;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Fname; use Fname;
33 with Fname.UF; use Fname.UF;
34 with Lib.Util; use Lib.Util;
35 with Lib.Xref; use Lib.Xref;
36 with Namet; use Namet;
37 with Nlists; use Nlists;
38 with Gnatvsn; use Gnatvsn;
39 with Opt; use Opt;
40 with Osint; use Osint;
41 with Osint.C; use Osint.C;
42 with Par;
43 with Restrict; use Restrict;
44 with Scn; use Scn;
45 with Sinfo; use Sinfo;
46 with Sinput; use Sinput;
47 with Stringt; use Stringt;
48 with Tbuild; use Tbuild;
49 with Uname; use Uname;
50
51 with System.WCh_Con; use System.WCh_Con;
52
53 package body Lib.Writ is
54
55 ----------------------------------
56 -- Add_Preprocessing_Dependency --
57 ----------------------------------
58
59 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
60 begin
61 Units.Increment_Last;
62 Units.Table (Units.Last) :=
63 (Unit_File_Name => File_Name (S),
64 Unit_Name => No_Name,
65 Expected_Unit => No_Name,
66 Source_Index => S,
67 Cunit => Empty,
68 Cunit_Entity => Empty,
69 Dependency_Num => 0,
70 Dependent_Unit => True,
71 Dynamic_Elab => False,
72 Fatal_Error => False,
73 Generate_Code => False,
74 Has_RACW => False,
75 Ident_String => Empty,
76 Loading => False,
77 Main_Priority => -1,
78 Serial_Number => 0,
79 Version => 0,
80 Error_Location => No_Location);
81 end Add_Preprocessing_Dependency;
82
83 ------------------------------
84 -- Ensure_System_Dependency --
85 ------------------------------
86
87 procedure Ensure_System_Dependency is
88 System_Uname : Unit_Name_Type;
89 -- Unit name for system spec if needed for dummy entry
90
91 System_Fname : File_Name_Type;
92 -- File name for system spec if needed for dummy entry
93
94 Save_Style : constant Boolean := Style_Check;
95
96 begin
97 -- Nothing to do if we already compiled System
98
99 for Unum in Units.First .. Last_Unit loop
100 if Units.Table (Unum).Source_Index = System_Source_File_Index then
101 return;
102 end if;
103 end loop;
104
105 -- If no entry for system.ads in the units table, then add a entry
106 -- to the units table for system.ads, which will be referenced when
107 -- the ali file is generated. We need this because every unit depends
108 -- on system as a result of Targparm scanning the system.ads file to
109 -- determine the target dependent parameters for the compilation.
110
111 Name_Len := 6;
112 Name_Buffer (1 .. 6) := "system";
113 System_Uname := Name_To_Unit_Name (Name_Enter);
114 System_Fname := File_Name (System_Source_File_Index);
115
116 Units.Increment_Last;
117 Units.Table (Units.Last) := (
118 Unit_File_Name => System_Fname,
119 Unit_Name => System_Uname,
120 Expected_Unit => System_Uname,
121 Source_Index => System_Source_File_Index,
122 Cunit => Empty,
123 Cunit_Entity => Empty,
124 Dependency_Num => 0,
125 Dependent_Unit => True,
126 Dynamic_Elab => False,
127 Fatal_Error => False,
128 Generate_Code => False,
129 Has_RACW => False,
130 Ident_String => Empty,
131 Loading => False,
132 Main_Priority => -1,
133 Serial_Number => 0,
134 Version => 0,
135 Error_Location => No_Location);
136
137 -- Parse system.ads so that the checksum is set right
138 -- Style checks are not applied.
139
140 Style_Check := False;
141 Initialize_Scanner (Units.Last, System_Source_File_Index);
142 Discard_List (Par (Configuration_Pragmas => False));
143 Style_Check := Save_Style;
144 end Ensure_System_Dependency;
145
146 ---------------
147 -- Write_ALI --
148 ---------------
149
150 procedure Write_ALI (Object : Boolean) is
151
152 ----------------
153 -- Local Data --
154 ----------------
155
156 Last_Unit : constant Unit_Number_Type := Units.Last;
157 -- Record unit number of last unit. We capture this in case we
158 -- have to add a dummy entry to the unit table for package System.
159
160 With_Flags : array (Units.First .. Last_Unit) of Boolean;
161 -- Array of flags to show which units are with'ed
162
163 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
164 -- Array of flags to show which units have pragma Elaborate set
165
166 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
167 -- Array of flags to show which units have pragma Elaborate All set
168
169 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
170 -- Array of flags to show which units have Elaborate_All_Desirable set
171
172 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
173 -- Sorted table of source dependencies. One extra entry in case we
174 -- have to add a dummy entry for System.
175
176 Num_Sdep : Nat := 0;
177 -- Number of active entries in Sdep_Table
178
179 -----------------------
180 -- Local Subprograms --
181 -----------------------
182
183 procedure Collect_Withs (Cunit : Node_Id);
184 -- Collect with lines for entries in the context clause of the
185 -- given compilation unit, Cunit.
186
187 procedure Update_Tables_From_ALI_File;
188 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
189 -- function), update tables from the ALI information, including
190 -- specifically the Compilation_Switches table.
191
192 function Up_To_Date_ALI_File_Exists return Boolean;
193 -- If there exists an ALI file that is up to date, then this function
194 -- initializes the tables in the ALI spec to contain information on
195 -- this file (using Scan_ALI) and returns True. If no file exists,
196 -- or the file is not up to date, then False is returned.
197
198 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
199 -- Write out the library information for one unit for which code is
200 -- generated (includes unit line and with lines).
201
202 procedure Write_With_Lines;
203 -- Write out with lines collected by calls to Collect_Withs
204
205 -------------------
206 -- Collect_Withs --
207 -------------------
208
209 procedure Collect_Withs (Cunit : Node_Id) is
210 Item : Node_Id;
211 Unum : Unit_Number_Type;
212
213 begin
214 Item := First (Context_Items (Cunit));
215 while Present (Item) loop
216
217 -- limited_with_clauses do not create dependencies.
218
219 if Nkind (Item) = N_With_Clause
220 and then not (Limited_Present (Item))
221 then
222 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
223 With_Flags (Unum) := True;
224
225 if Elaborate_Present (Item) then
226 Elab_Flags (Unum) := True;
227 end if;
228
229 if Elaborate_All_Present (Item) then
230 Elab_All_Flags (Unum) := True;
231 end if;
232
233 if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
234 Elab_Des_Flags (Unum) := True;
235 end if;
236 end if;
237
238 Next (Item);
239 end loop;
240 end Collect_Withs;
241
242 --------------------------------
243 -- Up_To_Date_ALI_File_Exists --
244 --------------------------------
245
246 function Up_To_Date_ALI_File_Exists return Boolean is
247 Name : File_Name_Type;
248 Text : Text_Buffer_Ptr;
249 Id : Sdep_Id;
250 Sind : Source_File_Index;
251
252 begin
253 Opt.Check_Object_Consistency := True;
254 Read_Library_Info (Name, Text);
255
256 -- Return if we could not find an ALI file
257
258 if Text = null then
259 return False;
260 end if;
261
262 -- Return if ALI file has bad format
263
264 Initialize_ALI;
265
266 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
267 return False;
268 end if;
269
270 -- If we have an OK ALI file, check if it is up to date
271 -- Note that we assume that the ALI read has all the entries
272 -- we have in our table, plus some additional ones (that can
273 -- come from expansion).
274
275 Id := First_Sdep_Entry;
276 for J in 1 .. Num_Sdep loop
277 Sind := Units.Table (Sdep_Table (J)).Source_Index;
278
279 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
280 if Id = Sdep.Last then
281 return False;
282 else
283 Id := Id + 1;
284 end if;
285 end loop;
286
287 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
288 return False;
289 end if;
290 end loop;
291
292 return True;
293 end Up_To_Date_ALI_File_Exists;
294
295 ---------------------------------
296 -- Update_Tables_From_ALI_File --
297 ---------------------------------
298
299 procedure Update_Tables_From_ALI_File is
300 begin
301 -- Build Compilation_Switches table
302
303 Compilation_Switches.Init;
304
305 for J in First_Arg_Entry .. Args.Last loop
306 Compilation_Switches.Increment_Last;
307 Compilation_Switches.Table (Compilation_Switches.Last) :=
308 Args.Table (J);
309 end loop;
310 end Update_Tables_From_ALI_File;
311
312 ----------------------------
313 -- Write_Unit_Information --
314 ----------------------------
315
316 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
317 Unode : constant Node_Id := Cunit (Unit_Num);
318 Ukind : constant Node_Kind := Nkind (Unit (Unode));
319 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
320 Pnode : Node_Id;
321
322 begin
323 Write_Info_Initiate ('U');
324 Write_Info_Char (' ');
325 Write_Info_Name (Unit_Name (Unit_Num));
326 Write_Info_Tab (25);
327 Write_Info_Name (Unit_File_Name (Unit_Num));
328
329 Write_Info_Tab (49);
330 Write_Info_Str (Version_Get (Unit_Num));
331
332 if (Is_Subprogram (Uent)
333 or else Ekind (Uent) = E_Package
334 or else Is_Generic_Unit (Uent))
335 and then Body_Needed_For_SAL (Uent)
336 then
337 Write_Info_Str (" BN");
338 end if;
339
340 if Dynamic_Elab (Unit_Num) then
341 Write_Info_Str (" DE");
342 end if;
343
344 -- We set the Elaborate_Body indication if either an explicit pragma
345 -- was present, or if this is an instantiation. RM 12.3(20) requires
346 -- that the body be immediately elaborated after the spec. We would
347 -- normally do that anyway, but the EB we generate here ensures that
348 -- this gets done even when we use the -p gnatbind switch.
349
350 if Has_Pragma_Elaborate_Body (Uent)
351 or else (Ukind = N_Package_Declaration
352 and then Is_Generic_Instance (Uent)
353 and then Present (Corresponding_Body (Unit (Unode))))
354 then
355 Write_Info_Str (" EB");
356 end if;
357
358 -- Now see if we should tell the binder that an elaboration entity
359 -- is present, which must be reset to true during elaboration. We
360 -- generate the indication if the following condition is met:
361
362 -- If this is a spec ...
363
364 if (Is_Subprogram (Uent)
365 or else
366 Ekind (Uent) = E_Package
367 or else
368 Is_Generic_Unit (Uent))
369
370 -- and an elaboration entity was declared ...
371
372 and then Present (Elaboration_Entity (Uent))
373
374 -- and either the elaboration flag is required ...
375
376 and then
377 (Elaboration_Entity_Required (Uent)
378
379 -- or this unit has elaboration code ...
380
381 or else not Has_No_Elaboration_Code (Unode)
382
383 -- or this unit has a separate body and this
384 -- body has elaboration code.
385
386 or else
387 (Ekind (Uent) = E_Package
388 and then Present (Body_Entity (Uent))
389 and then
390 not Has_No_Elaboration_Code
391 (Parent
392 (Declaration_Node
393 (Body_Entity (Uent))))))
394 then
395 Write_Info_Str (" EE");
396 end if;
397
398 if Has_No_Elaboration_Code (Unode) then
399 Write_Info_Str (" NE");
400 end if;
401
402 if Is_Preelaborated (Uent) then
403 Write_Info_Str (" PR");
404 end if;
405
406 if Is_Pure (Uent) then
407 Write_Info_Str (" PU");
408 end if;
409
410 if Has_RACW (Unit_Num) then
411 Write_Info_Str (" RA");
412 end if;
413
414 if Is_Remote_Call_Interface (Uent) then
415 Write_Info_Str (" RC");
416 end if;
417
418 if Is_Remote_Types (Uent) then
419 Write_Info_Str (" RT");
420 end if;
421
422 if Is_Shared_Passive (Uent) then
423 Write_Info_Str (" SP");
424 end if;
425
426 if Ukind = N_Subprogram_Declaration
427 or else Ukind = N_Subprogram_Body
428 then
429 Write_Info_Str (" SU");
430
431 elsif Ukind = N_Package_Declaration
432 or else
433 Ukind = N_Package_Body
434 then
435 -- If this is a wrapper package for a subprogram instantiation,
436 -- the user view is the subprogram. Note that in this case the
437 -- ali file contains both the spec and body of the instance.
438
439 if Is_Wrapper_Package (Uent) then
440 Write_Info_Str (" SU");
441 else
442 Write_Info_Str (" PK");
443 end if;
444
445 elsif Ukind = N_Generic_Package_Declaration then
446 Write_Info_Str (" PK");
447
448 end if;
449
450 if Ukind in N_Generic_Declaration
451 or else
452 (Present (Library_Unit (Unode))
453 and then
454 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
455 then
456 Write_Info_Str (" GE");
457 end if;
458
459 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
460 case Identifier_Casing (Source_Index (Unit_Num)) is
461 when All_Lower_Case => Write_Info_Str (" IL");
462 when All_Upper_Case => Write_Info_Str (" IU");
463 when others => null;
464 end case;
465
466 case Keyword_Casing (Source_Index (Unit_Num)) is
467 when Mixed_Case => Write_Info_Str (" KM");
468 when All_Upper_Case => Write_Info_Str (" KU");
469 when others => null;
470 end case;
471 end if;
472
473 if Initialize_Scalars then
474 Write_Info_Str (" IS");
475 end if;
476
477 Write_Info_EOL;
478
479 -- Generate with lines, first those that are directly with'ed
480
481 for J in With_Flags'Range loop
482 With_Flags (J) := False;
483 Elab_Flags (J) := False;
484 Elab_All_Flags (J) := False;
485 Elab_Des_Flags (J) := False;
486 end loop;
487
488 Collect_Withs (Unode);
489
490 -- For a body, we must also check for any subunits which belong to
491 -- it and which have context clauses of their own, since these
492 -- with'ed units are part of its own elaboration dependencies.
493
494 if Nkind (Unit (Unode)) in N_Unit_Body then
495 for S in Units.First .. Last_Unit loop
496
497 -- We are only interested in subunits.
498 -- For preproc. data and def. files, Cunit is Empty, so
499 -- we need to test that first.
500
501 if Cunit (S) /= Empty
502 and then Nkind (Unit (Cunit (S))) = N_Subunit
503 then
504 Pnode := Library_Unit (Cunit (S));
505
506 -- In gnatc mode, the errors in the subunits will not
507 -- have been recorded, but the analysis of the subunit
508 -- may have failed. There is no information to add to
509 -- ALI file in this case.
510
511 if No (Pnode) then
512 exit;
513 end if;
514
515 -- Find ultimate parent of the subunit
516
517 while Nkind (Unit (Pnode)) = N_Subunit loop
518 Pnode := Library_Unit (Pnode);
519 end loop;
520
521 -- See if it belongs to current unit, and if so, include
522 -- its with_clauses.
523
524 if Pnode = Unode then
525 Collect_Withs (Cunit (S));
526 end if;
527 end if;
528 end loop;
529 end if;
530
531 Write_With_Lines;
532
533 -- Output linker option lines
534
535 for J in 1 .. Linker_Option_Lines.Last loop
536 declare
537 S : constant Linker_Option_Entry :=
538 Linker_Option_Lines.Table (J);
539 C : Character;
540
541 begin
542 if S.Unit = Unit_Num then
543 Write_Info_Initiate ('L');
544 Write_Info_Str (" """);
545
546 for J in 1 .. String_Length (S.Option) loop
547 C := Get_Character (Get_String_Char (S.Option, J));
548
549 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
550 and then C /= '{'
551 then
552 Write_Info_Char (C);
553
554 if C = '"' then
555 Write_Info_Char (C);
556 end if;
557
558 else
559 declare
560 Hex : constant array (0 .. 15) of Character :=
561 "0123456789ABCDEF";
562
563 begin
564 Write_Info_Char ('{');
565 Write_Info_Char (Hex (Character'Pos (C) / 16));
566 Write_Info_Char (Hex (Character'Pos (C) mod 16));
567 Write_Info_Char ('}');
568 end;
569 end if;
570 end loop;
571
572 Write_Info_Char ('"');
573 Write_Info_EOL;
574 end if;
575 end;
576 end loop;
577 end Write_Unit_Information;
578
579 ----------------------
580 -- Write_With_Lines --
581 ----------------------
582
583 procedure Write_With_Lines is
584 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
585 Num_Withs : Int := 0;
586 Unum : Unit_Number_Type;
587 Cunit : Node_Id;
588 Cunite : Entity_Id;
589 Uname : Unit_Name_Type;
590 Fname : File_Name_Type;
591 Pname : constant Unit_Name_Type :=
592 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
593 Body_Fname : File_Name_Type;
594
595 begin
596 -- Loop to build the with table. A with on the main unit itself
597 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
598 -- the main unit is a subprogram with no spec, and a subunit of
599 -- it unecessarily withs the parent.
600
601 for J in Units.First + 1 .. Last_Unit loop
602
603 -- Add element to with table if it is with'ed or if it is the
604 -- parent spec of the main unit (case of main unit is a child
605 -- unit). The latter with is not needed for semantic purposes,
606 -- but is required by the binder for elaboration purposes.
607 -- For preproc. data and def. files, there is no Unit_Name,
608 -- check for that first.
609
610 if Unit_Name (J) /= No_Name
611 and then (With_Flags (J) or else Unit_Name (J) = Pname)
612 and then Units.Table (J).Dependent_Unit
613 then
614 Num_Withs := Num_Withs + 1;
615 With_Table (Num_Withs) := J;
616 end if;
617 end loop;
618
619 -- Sort and output the table
620
621 Sort (With_Table (1 .. Num_Withs));
622
623 for J in 1 .. Num_Withs loop
624 Unum := With_Table (J);
625 Cunit := Units.Table (Unum).Cunit;
626 Cunite := Units.Table (Unum).Cunit_Entity;
627 Uname := Units.Table (Unum).Unit_Name;
628 Fname := Units.Table (Unum).Unit_File_Name;
629
630 Write_Info_Initiate ('W');
631 Write_Info_Char (' ');
632 Write_Info_Name (Uname);
633
634 -- Now we need to figure out the names of the files that contain
635 -- the with'ed unit. These will usually be the files for the body,
636 -- except in the case of a package that has no body.
637
638 if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
639 and then
640 Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
641 or else Generic_Separately_Compiled (Cunite)
642 then
643 Write_Info_Tab (25);
644
645 if Is_Spec_Name (Uname) then
646 Body_Fname :=
647 Get_File_Name (Get_Body_Name (Uname), Subunit => False);
648 else
649 Body_Fname := Get_File_Name (Uname, Subunit => False);
650 end if;
651
652 -- A package is considered to have a body if it requires
653 -- a body or if a body is present in Ada 83 mode.
654
655 if Body_Required (Cunit)
656 or else (Ada_83
657 and then Full_Source_Name (Body_Fname) /= No_File)
658 then
659 Write_Info_Name (Body_Fname);
660 Write_Info_Tab (49);
661 Write_Info_Name (Lib_File_Name (Body_Fname));
662 else
663 Write_Info_Name (Fname);
664 Write_Info_Tab (49);
665 Write_Info_Name (Lib_File_Name (Fname));
666 end if;
667
668 if Elab_Flags (Unum) then
669 Write_Info_Str (" E");
670 end if;
671
672 if Elab_All_Flags (Unum) then
673 Write_Info_Str (" EA");
674 end if;
675
676 if Elab_Des_Flags (Unum) then
677 Write_Info_Str (" ED");
678 end if;
679 end if;
680
681 Write_Info_EOL;
682 end loop;
683 end Write_With_Lines;
684
685 -- Start of processing for Writ_ALI
686
687 begin
688 -- We never write an ALI file if the original operating mode was
689 -- syntax-only (-gnats switch used in compiler invocation line)
690
691 if Original_Operating_Mode = Check_Syntax then
692 return;
693 end if;
694
695 -- Build sorted source dependency table. We do this right away,
696 -- because it is referenced by Up_To_Date_ALI_File_Exists.
697
698 for Unum in Units.First .. Last_Unit loop
699 if Cunit_Entity (Unum) = Empty
700 or else not From_With_Type (Cunit_Entity (Unum))
701 then
702 Num_Sdep := Num_Sdep + 1;
703 Sdep_Table (Num_Sdep) := Unum;
704 end if;
705 end loop;
706
707 -- Sort the table so that the D lines are in order
708
709 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
710
711 -- If we are not generating code, and there is an up to date
712 -- ali file accessible, read it, and acquire the compilation
713 -- arguments from this file.
714
715 if Operating_Mode /= Generate_Code then
716 if Up_To_Date_ALI_File_Exists then
717 Update_Tables_From_ALI_File;
718 return;
719 end if;
720 end if;
721
722 -- Otherwise acquire compilation arguments and prepare to write
723 -- out a new ali file.
724
725 Create_Output_Library_Info;
726
727 -- Output version line
728
729 Write_Info_Initiate ('V');
730 Write_Info_Str (" """);
731 Write_Info_Str (Library_Version);
732 Write_Info_Char ('"');
733
734 Write_Info_EOL;
735
736 -- Output main program line if this is acceptable main program
737
738 Output_Main_Program_Line : declare
739 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
740 S : Node_Id;
741
742 procedure M_Parameters;
743 -- Output parameters for main program line
744
745 ------------------
746 -- M_Parameters --
747 ------------------
748
749 procedure M_Parameters is
750 begin
751 if Main_Priority (Main_Unit) /= Default_Main_Priority then
752 Write_Info_Char (' ');
753 Write_Info_Nat (Main_Priority (Main_Unit));
754 end if;
755
756 if Opt.Time_Slice_Set then
757 Write_Info_Str (" T=");
758 Write_Info_Nat (Opt.Time_Slice_Value);
759 end if;
760
761 Write_Info_Str (" W=");
762 Write_Info_Char
763 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
764
765 Write_Info_EOL;
766 end M_Parameters;
767
768 -- Start of processing for Output_Main_Program_Line
769
770 begin
771 if Nkind (U) = N_Subprogram_Body
772 or else (Nkind (U) = N_Package_Body
773 and then
774 (Nkind (Original_Node (U)) = N_Function_Instantiation
775 or else
776 Nkind (Original_Node (U)) =
777 N_Procedure_Instantiation))
778 then
779 -- If the unit is a subprogram instance, the entity for the
780 -- subprogram is the alias of the visible entity, which is the
781 -- related instance of the wrapper package. We retrieve the
782 -- subprogram declaration of the desired entity.
783
784 if Nkind (U) = N_Package_Body then
785 U := Parent (Parent (
786 Alias (Related_Instance (Defining_Unit_Name
787 (Specification (Unit (Library_Unit (Parent (U)))))))));
788 end if;
789
790 S := Specification (U);
791
792 if not Present (Parameter_Specifications (S)) then
793 if Nkind (S) = N_Procedure_Specification then
794 Write_Info_Initiate ('M');
795 Write_Info_Str (" P");
796 M_Parameters;
797
798 else
799 declare
800 Nam : Node_Id := Defining_Unit_Name (S);
801
802 begin
803 -- If it is a child unit, get its simple name.
804
805 if Nkind (Nam) = N_Defining_Program_Unit_Name then
806 Nam := Defining_Identifier (Nam);
807 end if;
808
809 if Is_Integer_Type (Etype (Nam)) then
810 Write_Info_Initiate ('M');
811 Write_Info_Str (" F");
812 M_Parameters;
813 end if;
814 end;
815 end if;
816 end if;
817 end if;
818 end Output_Main_Program_Line;
819
820 -- Write command argmument ('A') lines
821
822 for A in 1 .. Compilation_Switches.Last loop
823 Write_Info_Initiate ('A');
824 Write_Info_Char (' ');
825 Write_Info_Str (Compilation_Switches.Table (A).all);
826 Write_Info_Terminate;
827 end loop;
828
829 -- Output parameters ('P') line
830
831 Write_Info_Initiate ('P');
832
833 if Compilation_Errors then
834 Write_Info_Str (" CE");
835 end if;
836
837 if Opt.Float_Format /= ' ' then
838 Write_Info_Str (" F");
839
840 if Opt.Float_Format = 'I' then
841 Write_Info_Char ('I');
842
843 elsif Opt.Float_Format_Long = 'D' then
844 Write_Info_Char ('D');
845
846 else
847 Write_Info_Char ('G');
848 end if;
849 end if;
850
851 if Tasking_Used
852 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
853 then
854 if Locking_Policy /= ' ' then
855 Write_Info_Str (" L");
856 Write_Info_Char (Locking_Policy);
857 end if;
858
859 if Queuing_Policy /= ' ' then
860 Write_Info_Str (" Q");
861 Write_Info_Char (Queuing_Policy);
862 end if;
863
864 if Task_Dispatching_Policy /= ' ' then
865 Write_Info_Str (" T");
866 Write_Info_Char (Task_Dispatching_Policy);
867 Write_Info_Char (' ');
868 end if;
869 end if;
870
871 if not Object then
872 Write_Info_Str (" NO");
873 end if;
874
875 if No_Run_Time_Mode then
876 Write_Info_Str (" NR");
877 end if;
878
879 if Normalize_Scalars then
880 Write_Info_Str (" NS");
881 end if;
882
883 if Unreserve_All_Interrupts then
884 Write_Info_Str (" UA");
885 end if;
886
887 if Exception_Mechanism /= Front_End_Setjmp_Longjmp_Exceptions then
888 if Unit_Exception_Table_Present then
889 Write_Info_Str (" UX");
890 end if;
891
892 Write_Info_Str (" ZX");
893 end if;
894
895 Write_Info_EOL;
896
897 -- Before outputting the restrictions line, update the setting of
898 -- the No_Elaboration_Code flag. Violations of this restriction
899 -- cannot be detected until after the backend has been called since
900 -- it is the backend that sets this flag. We have to check all units
901 -- for which we have generated code
902
903 for Unit in Units.First .. Last_Unit loop
904 if Units.Table (Unit).Generate_Code
905 or else Unit = Main_Unit
906 then
907 if not Has_No_Elaboration_Code (Cunit (Unit)) then
908 Violations (No_ELaboration_Code) := True;
909 end if;
910 end if;
911 end loop;
912
913 -- Output restrictions line
914
915 Write_Info_Initiate ('R');
916 Write_Info_Char (' ');
917
918 for J in All_Restrictions loop
919 if Main_Restrictions (J) then
920 Write_Info_Char ('r');
921 elsif Violations (J) then
922 Write_Info_Char ('v');
923 else
924 Write_Info_Char ('n');
925 end if;
926 end loop;
927
928 Write_Info_EOL;
929
930 -- Output interrupt state lines
931
932 for J in Interrupt_States.First .. Interrupt_States.Last loop
933 Write_Info_Initiate ('I');
934 Write_Info_Char (' ');
935 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
936 Write_Info_Char (' ');
937 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
938 Write_Info_Char (' ');
939 Write_Info_Nat
940 (Nat (Get_Logical_Line_Number
941 (Interrupt_States.Table (J).Pragma_Loc)));
942 Write_Info_EOL;
943 end loop;
944
945 -- Loop through file table to output information for all units for which
946 -- we have generated code, as marked by the Generate_Code flag.
947
948 for Unit in Units.First .. Last_Unit loop
949 if Units.Table (Unit).Generate_Code
950 or else Unit = Main_Unit
951 then
952 Write_Info_EOL; -- blank line
953 Write_Unit_Information (Unit);
954 end if;
955 end loop;
956
957 Write_Info_EOL; -- blank line
958
959 -- Output external version reference lines
960
961 for J in 1 .. Version_Ref.Last loop
962 Write_Info_Initiate ('E');
963 Write_Info_Char (' ');
964
965 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
966 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
967 end loop;
968
969 Write_Info_EOL;
970 end loop;
971
972 -- Prepare to output the source dependency lines
973
974 declare
975 Unum : Unit_Number_Type;
976 -- Number of unit being output
977
978 Sind : Source_File_Index;
979 -- Index of corresponding source file
980
981 begin
982 for J in 1 .. Num_Sdep loop
983 Unum := Sdep_Table (J);
984 Units.Table (Unum).Dependency_Num := J;
985 Sind := Units.Table (Unum).Source_Index;
986
987 Write_Info_Initiate ('D');
988 Write_Info_Char (' ');
989
990 -- Normal case of a dependent unit entry with a source index
991
992 if Sind /= No_Source_File
993 and then Units.Table (Unum).Dependent_Unit
994 then
995 Write_Info_Name (File_Name (Sind));
996 Write_Info_Tab (25);
997 Write_Info_Str (String (Time_Stamp (Sind)));
998 Write_Info_Char (' ');
999 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1000
1001 -- If subunit, add unit name, omitting the %b at the end
1002
1003 if Present (Cunit (Unum))
1004 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1005 then
1006 Get_Decoded_Name_String (Unit_Name (Unum));
1007 Write_Info_Char (' ');
1008 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1009 end if;
1010
1011 -- If Source_Reference pragma used output information
1012
1013 if Num_SRef_Pragmas (Sind) > 0 then
1014 Write_Info_Char (' ');
1015
1016 if Num_SRef_Pragmas (Sind) = 1 then
1017 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1018 else
1019 Write_Info_Nat (0);
1020 end if;
1021
1022 Write_Info_Char (':');
1023 Write_Info_Name (Reference_Name (Sind));
1024 end if;
1025
1026 -- Case where there is no source index (happens for missing files)
1027 -- Also come here for non-dependent units.
1028
1029 else
1030 Write_Info_Name (Unit_File_Name (Unum));
1031 Write_Info_Tab (25);
1032 Write_Info_Str (String (Dummy_Time_Stamp));
1033 Write_Info_Char (' ');
1034 Write_Info_Str (Get_Hex_String (0));
1035 end if;
1036
1037 Write_Info_EOL;
1038 end loop;
1039 end;
1040
1041 Output_References;
1042 Write_Info_Terminate;
1043 Close_Output_Library_Info;
1044
1045 end Write_ALI;
1046
1047 end Lib.Writ;