* config/rs6000/rs6000.md: Document why a pattern is not
[official-gcc.git] / gcc / ada / lib-writ.adb
blobbc6bfe54bf92b9024730e994878aca05dca4de2f
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-2004 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 ------------------------------------------------------------------------------
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 Rident; use Rident;
45 with Scn; use Scn;
46 with Sinfo; use Sinfo;
47 with Sinput; use Sinput;
48 with Stringt; use Stringt;
49 with Tbuild; use Tbuild;
50 with Uname; use Uname;
52 with System.WCh_Con; use System.WCh_Con;
54 package body Lib.Writ is
56 ----------------------------------
57 -- Add_Preprocessing_Dependency --
58 ----------------------------------
60 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
61 begin
62 Units.Increment_Last;
63 Units.Table (Units.Last) :=
64 (Unit_File_Name => File_Name (S),
65 Unit_Name => No_Name,
66 Expected_Unit => No_Name,
67 Source_Index => S,
68 Cunit => Empty,
69 Cunit_Entity => Empty,
70 Dependency_Num => 0,
71 Dependent_Unit => True,
72 Dynamic_Elab => False,
73 Fatal_Error => False,
74 Generate_Code => False,
75 Has_RACW => False,
76 Ident_String => Empty,
77 Loading => False,
78 Main_Priority => -1,
79 Munit_Index => 0,
80 Serial_Number => 0,
81 Version => 0,
82 Error_Location => No_Location);
83 end Add_Preprocessing_Dependency;
85 ------------------------------
86 -- Ensure_System_Dependency --
87 ------------------------------
89 procedure Ensure_System_Dependency is
90 System_Uname : Unit_Name_Type;
91 -- Unit name for system spec if needed for dummy entry
93 System_Fname : File_Name_Type;
94 -- File name for system spec if needed for dummy entry
96 begin
97 -- Nothing to do if we already compiled System
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;
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.
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);
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 Munit_Index => 0,
134 Serial_Number => 0,
135 Version => 0,
136 Error_Location => No_Location);
138 -- Parse system.ads so that the checksum is set right
139 -- Style checks are not applied.
141 declare
142 Save_Mindex : constant Nat := Multiple_Unit_Index;
143 Save_Style : constant Boolean := Style_Check;
144 begin
145 Multiple_Unit_Index := 0;
146 Style_Check := False;
147 Initialize_Scanner (Units.Last, System_Source_File_Index);
148 Discard_List (Par (Configuration_Pragmas => False));
149 Style_Check := Save_Style;
150 Multiple_Unit_Index := Save_Mindex;
151 end;
152 end Ensure_System_Dependency;
154 ---------------
155 -- Write_ALI --
156 ---------------
158 procedure Write_ALI (Object : Boolean) is
160 ----------------
161 -- Local Data --
162 ----------------
164 Last_Unit : constant Unit_Number_Type := Units.Last;
165 -- Record unit number of last unit. We capture this in case we
166 -- have to add a dummy entry to the unit table for package System.
168 With_Flags : array (Units.First .. Last_Unit) of Boolean;
169 -- Array of flags to show which units are with'ed
171 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
172 -- Array of flags to show which units have pragma Elaborate set
174 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
175 -- Array of flags to show which units have pragma Elaborate All set
177 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
178 -- Array of flags to show which units have Elaborate_All_Desirable set
180 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
181 -- Sorted table of source dependencies. One extra entry in case we
182 -- have to add a dummy entry for System.
184 Num_Sdep : Nat := 0;
185 -- Number of active entries in Sdep_Table
187 -----------------------
188 -- Local Subprograms --
189 -----------------------
191 procedure Collect_Withs (Cunit : Node_Id);
192 -- Collect with lines for entries in the context clause of the
193 -- given compilation unit, Cunit.
195 procedure Update_Tables_From_ALI_File;
196 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
197 -- function), update tables from the ALI information, including
198 -- specifically the Compilation_Switches table.
200 function Up_To_Date_ALI_File_Exists return Boolean;
201 -- If there exists an ALI file that is up to date, then this function
202 -- initializes the tables in the ALI spec to contain information on
203 -- this file (using Scan_ALI) and returns True. If no file exists,
204 -- or the file is not up to date, then False is returned.
206 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
207 -- Write out the library information for one unit for which code is
208 -- generated (includes unit line and with lines).
210 procedure Write_With_Lines;
211 -- Write out with lines collected by calls to Collect_Withs
213 -------------------
214 -- Collect_Withs --
215 -------------------
217 procedure Collect_Withs (Cunit : Node_Id) is
218 Item : Node_Id;
219 Unum : Unit_Number_Type;
221 begin
222 Item := First (Context_Items (Cunit));
223 while Present (Item) loop
225 -- Ada0Y (AI-50217): limited with_clauses do not create
226 -- dependencies
228 if Nkind (Item) = N_With_Clause
229 and then not (Limited_Present (Item))
230 then
231 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
232 With_Flags (Unum) := True;
234 if Elaborate_Present (Item) then
235 Elab_Flags (Unum) := True;
236 end if;
238 if Elaborate_All_Present (Item) then
239 Elab_All_Flags (Unum) := True;
240 end if;
242 if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
243 Elab_Des_Flags (Unum) := True;
244 end if;
245 end if;
247 Next (Item);
248 end loop;
249 end Collect_Withs;
251 --------------------------------
252 -- Up_To_Date_ALI_File_Exists --
253 --------------------------------
255 function Up_To_Date_ALI_File_Exists return Boolean is
256 Name : File_Name_Type;
257 Text : Text_Buffer_Ptr;
258 Id : Sdep_Id;
259 Sind : Source_File_Index;
261 begin
262 Opt.Check_Object_Consistency := True;
263 Read_Library_Info (Name, Text);
265 -- Return if we could not find an ALI file
267 if Text = null then
268 return False;
269 end if;
271 -- Return if ALI file has bad format
273 Initialize_ALI;
275 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
276 return False;
277 end if;
279 -- If we have an OK ALI file, check if it is up to date
280 -- Note that we assume that the ALI read has all the entries
281 -- we have in our table, plus some additional ones (that can
282 -- come from expansion).
284 Id := First_Sdep_Entry;
285 for J in 1 .. Num_Sdep loop
286 Sind := Units.Table (Sdep_Table (J)).Source_Index;
288 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
289 if Id = Sdep.Last then
290 return False;
291 else
292 Id := Id + 1;
293 end if;
294 end loop;
296 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
297 return False;
298 end if;
299 end loop;
301 return True;
302 end Up_To_Date_ALI_File_Exists;
304 ---------------------------------
305 -- Update_Tables_From_ALI_File --
306 ---------------------------------
308 procedure Update_Tables_From_ALI_File is
309 begin
310 -- Build Compilation_Switches table
312 Compilation_Switches.Init;
314 for J in First_Arg_Entry .. Args.Last loop
315 Compilation_Switches.Increment_Last;
316 Compilation_Switches.Table (Compilation_Switches.Last) :=
317 Args.Table (J);
318 end loop;
319 end Update_Tables_From_ALI_File;
321 ----------------------------
322 -- Write_Unit_Information --
323 ----------------------------
325 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
326 Unode : constant Node_Id := Cunit (Unit_Num);
327 Ukind : constant Node_Kind := Nkind (Unit (Unode));
328 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
329 Pnode : Node_Id;
331 begin
332 Write_Info_Initiate ('U');
333 Write_Info_Char (' ');
334 Write_Info_Name (Unit_Name (Unit_Num));
335 Write_Info_Tab (25);
336 Write_Info_Name (Unit_File_Name (Unit_Num));
338 Write_Info_Tab (49);
339 Write_Info_Str (Version_Get (Unit_Num));
341 if (Is_Subprogram (Uent)
342 or else Ekind (Uent) = E_Package
343 or else Is_Generic_Unit (Uent))
344 and then Body_Needed_For_SAL (Uent)
345 then
346 Write_Info_Str (" BN");
347 end if;
349 if Dynamic_Elab (Unit_Num) then
350 Write_Info_Str (" DE");
351 end if;
353 -- We set the Elaborate_Body indication if either an explicit pragma
354 -- was present, or if this is an instantiation. RM 12.3(20) requires
355 -- that the body be immediately elaborated after the spec. We would
356 -- normally do that anyway, but the EB we generate here ensures that
357 -- this gets done even when we use the -p gnatbind switch.
359 if Has_Pragma_Elaborate_Body (Uent)
360 or else (Ukind = N_Package_Declaration
361 and then Is_Generic_Instance (Uent)
362 and then Present (Corresponding_Body (Unit (Unode))))
363 then
364 Write_Info_Str (" EB");
365 end if;
367 -- Now see if we should tell the binder that an elaboration entity
368 -- is present, which must be reset to true during elaboration. We
369 -- generate the indication if the following condition is met:
371 -- If this is a spec ...
373 if (Is_Subprogram (Uent)
374 or else
375 Ekind (Uent) = E_Package
376 or else
377 Is_Generic_Unit (Uent))
379 -- and an elaboration entity was declared ...
381 and then Present (Elaboration_Entity (Uent))
383 -- and either the elaboration flag is required ...
385 and then
386 (Elaboration_Entity_Required (Uent)
388 -- or this unit has elaboration code ...
390 or else not Has_No_Elaboration_Code (Unode)
392 -- or this unit has a separate body and this
393 -- body has elaboration code.
395 or else
396 (Ekind (Uent) = E_Package
397 and then Present (Body_Entity (Uent))
398 and then
399 not Has_No_Elaboration_Code
400 (Parent
401 (Declaration_Node
402 (Body_Entity (Uent))))))
403 then
404 Write_Info_Str (" EE");
405 end if;
407 if Has_No_Elaboration_Code (Unode) then
408 Write_Info_Str (" NE");
409 end if;
411 if Is_Preelaborated (Uent) then
412 Write_Info_Str (" PR");
413 end if;
415 if Is_Pure (Uent) then
416 Write_Info_Str (" PU");
417 end if;
419 if Has_RACW (Unit_Num) then
420 Write_Info_Str (" RA");
421 end if;
423 if Is_Remote_Call_Interface (Uent) then
424 Write_Info_Str (" RC");
425 end if;
427 if Is_Remote_Types (Uent) then
428 Write_Info_Str (" RT");
429 end if;
431 if Is_Shared_Passive (Uent) then
432 Write_Info_Str (" SP");
433 end if;
435 if Ukind = N_Subprogram_Declaration
436 or else Ukind = N_Subprogram_Body
437 then
438 Write_Info_Str (" SU");
440 elsif Ukind = N_Package_Declaration
441 or else
442 Ukind = N_Package_Body
443 then
444 -- If this is a wrapper package for a subprogram instantiation,
445 -- the user view is the subprogram. Note that in this case the
446 -- ali file contains both the spec and body of the instance.
448 if Is_Wrapper_Package (Uent) then
449 Write_Info_Str (" SU");
450 else
451 Write_Info_Str (" PK");
452 end if;
454 elsif Ukind = N_Generic_Package_Declaration then
455 Write_Info_Str (" PK");
457 end if;
459 if Ukind in N_Generic_Declaration
460 or else
461 (Present (Library_Unit (Unode))
462 and then
463 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
464 then
465 Write_Info_Str (" GE");
466 end if;
468 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
469 case Identifier_Casing (Source_Index (Unit_Num)) is
470 when All_Lower_Case => Write_Info_Str (" IL");
471 when All_Upper_Case => Write_Info_Str (" IU");
472 when others => null;
473 end case;
475 case Keyword_Casing (Source_Index (Unit_Num)) is
476 when Mixed_Case => Write_Info_Str (" KM");
477 when All_Upper_Case => Write_Info_Str (" KU");
478 when others => null;
479 end case;
480 end if;
482 if Initialize_Scalars then
483 Write_Info_Str (" IS");
484 end if;
486 Write_Info_EOL;
488 -- Generate with lines, first those that are directly with'ed
490 for J in With_Flags'Range loop
491 With_Flags (J) := False;
492 Elab_Flags (J) := False;
493 Elab_All_Flags (J) := False;
494 Elab_Des_Flags (J) := False;
495 end loop;
497 Collect_Withs (Unode);
499 -- For a body, we must also check for any subunits which belong to
500 -- it and which have context clauses of their own, since these
501 -- with'ed units are part of its own elaboration dependencies.
503 if Nkind (Unit (Unode)) in N_Unit_Body then
504 for S in Units.First .. Last_Unit loop
506 -- We are only interested in subunits.
507 -- For preproc. data and def. files, Cunit is Empty, so
508 -- we need to test that first.
510 if Cunit (S) /= Empty
511 and then Nkind (Unit (Cunit (S))) = N_Subunit
512 then
513 Pnode := Library_Unit (Cunit (S));
515 -- In gnatc mode, the errors in the subunits will not
516 -- have been recorded, but the analysis of the subunit
517 -- may have failed. There is no information to add to
518 -- ALI file in this case.
520 if No (Pnode) then
521 exit;
522 end if;
524 -- Find ultimate parent of the subunit
526 while Nkind (Unit (Pnode)) = N_Subunit loop
527 Pnode := Library_Unit (Pnode);
528 end loop;
530 -- See if it belongs to current unit, and if so, include
531 -- its with_clauses.
533 if Pnode = Unode then
534 Collect_Withs (Cunit (S));
535 end if;
536 end if;
537 end loop;
538 end if;
540 Write_With_Lines;
542 -- Output linker option lines
544 for J in 1 .. Linker_Option_Lines.Last loop
545 declare
546 S : constant Linker_Option_Entry :=
547 Linker_Option_Lines.Table (J);
548 C : Character;
550 begin
551 if S.Unit = Unit_Num then
552 Write_Info_Initiate ('L');
553 Write_Info_Str (" """);
555 for J in 1 .. String_Length (S.Option) loop
556 C := Get_Character (Get_String_Char (S.Option, J));
558 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
559 and then C /= '{'
560 then
561 Write_Info_Char (C);
563 if C = '"' then
564 Write_Info_Char (C);
565 end if;
567 else
568 declare
569 Hex : constant array (0 .. 15) of Character :=
570 "0123456789ABCDEF";
572 begin
573 Write_Info_Char ('{');
574 Write_Info_Char (Hex (Character'Pos (C) / 16));
575 Write_Info_Char (Hex (Character'Pos (C) mod 16));
576 Write_Info_Char ('}');
577 end;
578 end if;
579 end loop;
581 Write_Info_Char ('"');
582 Write_Info_EOL;
583 end if;
584 end;
585 end loop;
586 end Write_Unit_Information;
588 ----------------------
589 -- Write_With_Lines --
590 ----------------------
592 procedure Write_With_Lines is
593 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
594 Num_Withs : Int := 0;
595 Unum : Unit_Number_Type;
596 Cunit : Node_Id;
597 Cunite : Entity_Id;
598 Uname : Unit_Name_Type;
599 Fname : File_Name_Type;
600 Pname : constant Unit_Name_Type :=
601 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
602 Body_Fname : File_Name_Type;
604 begin
605 -- Loop to build the with table. A with on the main unit itself
606 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
607 -- the main unit is a subprogram with no spec, and a subunit of
608 -- it unecessarily withs the parent.
610 for J in Units.First + 1 .. Last_Unit loop
612 -- Add element to with table if it is with'ed or if it is the
613 -- parent spec of the main unit (case of main unit is a child
614 -- unit). The latter with is not needed for semantic purposes,
615 -- but is required by the binder for elaboration purposes.
616 -- For preproc. data and def. files, there is no Unit_Name,
617 -- check for that first.
619 if Unit_Name (J) /= No_Name
620 and then (With_Flags (J) or else Unit_Name (J) = Pname)
621 and then Units.Table (J).Dependent_Unit
622 then
623 Num_Withs := Num_Withs + 1;
624 With_Table (Num_Withs) := J;
625 end if;
626 end loop;
628 -- Sort and output the table
630 Sort (With_Table (1 .. Num_Withs));
632 for J in 1 .. Num_Withs loop
633 Unum := With_Table (J);
634 Cunit := Units.Table (Unum).Cunit;
635 Cunite := Units.Table (Unum).Cunit_Entity;
636 Uname := Units.Table (Unum).Unit_Name;
637 Fname := Units.Table (Unum).Unit_File_Name;
639 Write_Info_Initiate ('W');
640 Write_Info_Char (' ');
641 Write_Info_Name (Uname);
643 -- Now we need to figure out the names of the files that contain
644 -- the with'ed unit. These will usually be the files for the body,
645 -- except in the case of a package that has no body.
647 if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
648 and then
649 Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
650 or else Generic_Separately_Compiled (Cunite)
651 then
652 Write_Info_Tab (25);
654 if Is_Spec_Name (Uname) then
655 Body_Fname :=
656 Get_File_Name
657 (Get_Body_Name (Uname),
658 Subunit => False, May_Fail => True);
660 if Body_Fname = No_File then
661 Body_Fname := Get_File_Name (Uname, Subunit => False);
662 end if;
664 else
665 Body_Fname := Get_File_Name (Uname, Subunit => False);
666 end if;
668 -- A package is considered to have a body if it requires
669 -- a body or if a body is present in Ada 83 mode.
671 if Body_Required (Cunit)
672 or else (Ada_83
673 and then Full_Source_Name (Body_Fname) /= No_File)
674 then
675 Write_Info_Name (Body_Fname);
676 Write_Info_Tab (49);
677 Write_Info_Name
678 (Lib_File_Name (Body_Fname, Munit_Index (Unum)));
679 else
680 Write_Info_Name (Fname);
681 Write_Info_Tab (49);
682 Write_Info_Name
683 (Lib_File_Name (Fname, Munit_Index (Unum)));
684 end if;
686 if Elab_Flags (Unum) then
687 Write_Info_Str (" E");
688 end if;
690 if Elab_All_Flags (Unum) then
691 Write_Info_Str (" EA");
692 end if;
694 if Elab_Des_Flags (Unum) then
695 Write_Info_Str (" ED");
696 end if;
697 end if;
699 Write_Info_EOL;
700 end loop;
701 end Write_With_Lines;
703 -- Start of processing for Write_ALI
705 begin
706 -- We never write an ALI file if the original operating mode was
707 -- syntax-only (-gnats switch used in compiler invocation line)
709 if Original_Operating_Mode = Check_Syntax then
710 return;
711 end if;
713 -- Build sorted source dependency table. We do this right away,
714 -- because it is referenced by Up_To_Date_ALI_File_Exists.
716 for Unum in Units.First .. Last_Unit loop
717 if Cunit_Entity (Unum) = Empty
718 or else not From_With_Type (Cunit_Entity (Unum))
719 then
720 Num_Sdep := Num_Sdep + 1;
721 Sdep_Table (Num_Sdep) := Unum;
722 end if;
723 end loop;
725 -- Sort the table so that the D lines are in order
727 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
729 -- If we are not generating code, and there is an up to date
730 -- ali file accessible, read it, and acquire the compilation
731 -- arguments from this file.
733 if Operating_Mode /= Generate_Code then
734 if Up_To_Date_ALI_File_Exists then
735 Update_Tables_From_ALI_File;
736 return;
737 end if;
738 end if;
740 -- Otherwise acquire compilation arguments and prepare to write
741 -- out a new ali file.
743 Create_Output_Library_Info;
745 -- Output version line
747 Write_Info_Initiate ('V');
748 Write_Info_Str (" """);
749 Write_Info_Str (Verbose_Library_Version);
750 Write_Info_Char ('"');
752 Write_Info_EOL;
754 -- Output main program line if this is acceptable main program
756 Output_Main_Program_Line : declare
757 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
758 S : Node_Id;
760 procedure M_Parameters;
761 -- Output parameters for main program line
763 ------------------
764 -- M_Parameters --
765 ------------------
767 procedure M_Parameters is
768 begin
769 if Main_Priority (Main_Unit) /= Default_Main_Priority then
770 Write_Info_Char (' ');
771 Write_Info_Nat (Main_Priority (Main_Unit));
772 end if;
774 if Opt.Time_Slice_Set then
775 Write_Info_Str (" T=");
776 Write_Info_Nat (Opt.Time_Slice_Value);
777 end if;
779 Write_Info_Str (" W=");
780 Write_Info_Char
781 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
783 Write_Info_EOL;
784 end M_Parameters;
786 -- Start of processing for Output_Main_Program_Line
788 begin
789 if Nkind (U) = N_Subprogram_Body
790 or else (Nkind (U) = N_Package_Body
791 and then
792 (Nkind (Original_Node (U)) = N_Function_Instantiation
793 or else
794 Nkind (Original_Node (U)) =
795 N_Procedure_Instantiation))
796 then
797 -- If the unit is a subprogram instance, the entity for the
798 -- subprogram is the alias of the visible entity, which is the
799 -- related instance of the wrapper package. We retrieve the
800 -- subprogram declaration of the desired entity.
802 if Nkind (U) = N_Package_Body then
803 U := Parent (Parent (
804 Alias (Related_Instance (Defining_Unit_Name
805 (Specification (Unit (Library_Unit (Parent (U)))))))));
806 end if;
808 S := Specification (U);
810 if not Present (Parameter_Specifications (S)) then
811 if Nkind (S) = N_Procedure_Specification then
812 Write_Info_Initiate ('M');
813 Write_Info_Str (" P");
814 M_Parameters;
816 else
817 declare
818 Nam : Node_Id := Defining_Unit_Name (S);
820 begin
821 -- If it is a child unit, get its simple name.
823 if Nkind (Nam) = N_Defining_Program_Unit_Name then
824 Nam := Defining_Identifier (Nam);
825 end if;
827 if Is_Integer_Type (Etype (Nam)) then
828 Write_Info_Initiate ('M');
829 Write_Info_Str (" F");
830 M_Parameters;
831 end if;
832 end;
833 end if;
834 end if;
835 end if;
836 end Output_Main_Program_Line;
838 -- Write command argmument ('A') lines
840 for A in 1 .. Compilation_Switches.Last loop
841 Write_Info_Initiate ('A');
842 Write_Info_Char (' ');
843 Write_Info_Str (Compilation_Switches.Table (A).all);
844 Write_Info_Terminate;
845 end loop;
847 -- Output parameters ('P') line
849 Write_Info_Initiate ('P');
851 if Compilation_Errors then
852 Write_Info_Str (" CE");
853 end if;
855 if Opt.Float_Format /= ' ' then
856 Write_Info_Str (" F");
858 if Opt.Float_Format = 'I' then
859 Write_Info_Char ('I');
861 elsif Opt.Float_Format_Long = 'D' then
862 Write_Info_Char ('D');
864 else
865 Write_Info_Char ('G');
866 end if;
867 end if;
869 if Tasking_Used
870 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
871 then
872 if Locking_Policy /= ' ' then
873 Write_Info_Str (" L");
874 Write_Info_Char (Locking_Policy);
875 end if;
877 if Queuing_Policy /= ' ' then
878 Write_Info_Str (" Q");
879 Write_Info_Char (Queuing_Policy);
880 end if;
882 if Task_Dispatching_Policy /= ' ' then
883 Write_Info_Str (" T");
884 Write_Info_Char (Task_Dispatching_Policy);
885 Write_Info_Char (' ');
886 end if;
887 end if;
889 if not Object then
890 Write_Info_Str (" NO");
891 end if;
893 if No_Run_Time_Mode then
894 Write_Info_Str (" NR");
895 end if;
897 if Normalize_Scalars then
898 Write_Info_Str (" NS");
899 end if;
901 if Sec_Stack_Used then
902 Write_Info_Str (" SS");
903 end if;
905 if Unreserve_All_Interrupts then
906 Write_Info_Str (" UA");
907 end if;
909 if Exception_Mechanism /= Front_End_Setjmp_Longjmp_Exceptions then
910 if Unit_Exception_Table_Present then
911 Write_Info_Str (" UX");
912 end if;
914 Write_Info_Str (" ZX");
915 end if;
917 Write_Info_EOL;
919 -- Before outputting the restrictions line, update the setting of
920 -- the No_Elaboration_Code flag. Violations of this restriction
921 -- cannot be detected until after the backend has been called since
922 -- it is the backend that sets this flag. We have to check all units
923 -- for which we have generated code
925 for Unit in Units.First .. Last_Unit loop
926 if Units.Table (Unit).Generate_Code
927 or else Unit = Main_Unit
928 then
929 if not Has_No_Elaboration_Code (Cunit (Unit)) then
930 Main_Restrictions.Violated (No_Elaboration_Code) := True;
931 end if;
932 end if;
933 end loop;
935 -- Output restrictions line
937 Write_Info_Initiate ('R');
938 Write_Info_Char (' ');
940 -- First the information for the boolean restrictions
942 for R in All_Boolean_Restrictions loop
943 if Main_Restrictions.Set (R) then
944 Write_Info_Char ('r');
945 elsif Main_Restrictions.Violated (R) then
946 Write_Info_Char ('v');
947 else
948 Write_Info_Char ('n');
949 end if;
950 end loop;
952 -- And now the information for the parameter restrictions
954 for RP in All_Parameter_Restrictions loop
955 if Main_Restrictions.Set (RP) then
956 Write_Info_Char ('r');
957 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
958 else
959 Write_Info_Char ('n');
960 end if;
962 if not Main_Restrictions.Violated (RP)
963 or else RP not in Checked_Parameter_Restrictions
964 then
965 Write_Info_Char ('n');
966 else
967 Write_Info_Char ('v');
968 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
970 if Main_Restrictions.Unknown (RP) then
971 Write_Info_Char ('+');
972 end if;
973 end if;
974 end loop;
976 Write_Info_EOL;
978 -- Output interrupt state lines
980 for J in Interrupt_States.First .. Interrupt_States.Last loop
981 Write_Info_Initiate ('I');
982 Write_Info_Char (' ');
983 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
984 Write_Info_Char (' ');
985 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
986 Write_Info_Char (' ');
987 Write_Info_Nat
988 (Nat (Get_Logical_Line_Number
989 (Interrupt_States.Table (J).Pragma_Loc)));
990 Write_Info_EOL;
991 end loop;
993 -- Loop through file table to output information for all units for which
994 -- we have generated code, as marked by the Generate_Code flag.
996 for Unit in Units.First .. Last_Unit loop
997 if Units.Table (Unit).Generate_Code
998 or else Unit = Main_Unit
999 then
1000 Write_Info_EOL; -- blank line
1001 Write_Unit_Information (Unit);
1002 end if;
1003 end loop;
1005 Write_Info_EOL; -- blank line
1007 -- Output external version reference lines
1009 for J in 1 .. Version_Ref.Last loop
1010 Write_Info_Initiate ('E');
1011 Write_Info_Char (' ');
1013 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1014 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1015 end loop;
1017 Write_Info_EOL;
1018 end loop;
1020 -- Prepare to output the source dependency lines
1022 declare
1023 Unum : Unit_Number_Type;
1024 -- Number of unit being output
1026 Sind : Source_File_Index;
1027 -- Index of corresponding source file
1029 begin
1030 for J in 1 .. Num_Sdep loop
1031 Unum := Sdep_Table (J);
1032 Units.Table (Unum).Dependency_Num := J;
1033 Sind := Units.Table (Unum).Source_Index;
1035 Write_Info_Initiate ('D');
1036 Write_Info_Char (' ');
1038 -- Normal case of a dependent unit entry with a source index
1040 if Sind /= No_Source_File
1041 and then Units.Table (Unum).Dependent_Unit
1042 then
1043 Write_Info_Name (File_Name (Sind));
1044 Write_Info_Tab (25);
1045 Write_Info_Str (String (Time_Stamp (Sind)));
1046 Write_Info_Char (' ');
1047 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1049 -- If subunit, add unit name, omitting the %b at the end
1051 if Present (Cunit (Unum))
1052 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1053 then
1054 Get_Decoded_Name_String (Unit_Name (Unum));
1055 Write_Info_Char (' ');
1056 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1057 end if;
1059 -- If Source_Reference pragma used output information
1061 if Num_SRef_Pragmas (Sind) > 0 then
1062 Write_Info_Char (' ');
1064 if Num_SRef_Pragmas (Sind) = 1 then
1065 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1066 else
1067 Write_Info_Nat (0);
1068 end if;
1070 Write_Info_Char (':');
1071 Write_Info_Name (Reference_Name (Sind));
1072 end if;
1074 -- Case where there is no source index (happens for missing files)
1075 -- Also come here for non-dependent units.
1077 else
1078 Write_Info_Name (Unit_File_Name (Unum));
1079 Write_Info_Tab (25);
1080 Write_Info_Str (String (Dummy_Time_Stamp));
1081 Write_Info_Char (' ');
1082 Write_Info_Str (Get_Hex_String (0));
1083 end if;
1085 Write_Info_EOL;
1086 end loop;
1087 end;
1089 Output_References;
1090 Write_Info_Terminate;
1091 Close_Output_Library_Info;
1093 end Write_ALI;
1095 end Lib.Writ;