* toplev.h (floor_log2): If GCC_VERSION >= 3004, declare as static
[official-gcc.git] / gcc / ada / lib-writ.adb
blobf248c05cedc1cf2fbbca0c38512d1d49cc723e44
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-2008, 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 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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with ALI; use ALI;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Fname; use Fname;
32 with Fname.UF; use Fname.UF;
33 with Lib.Util; use Lib.Util;
34 with Lib.Xref; use Lib.Xref;
35 with Nlists; use Nlists;
36 with Gnatvsn; use Gnatvsn;
37 with Opt; use Opt;
38 with Osint; use Osint;
39 with Osint.C; use Osint.C;
40 with Par;
41 with Restrict; use Restrict;
42 with Rident; use Rident;
43 with Scn; use Scn;
44 with Sinfo; use Sinfo;
45 with Sinput; use Sinput;
46 with Snames; use Snames;
47 with Stringt; use Stringt;
48 with Tbuild; use Tbuild;
49 with Uname; use Uname;
51 with System.Case_Util; use System.Case_Util;
52 with System.WCh_Con; use System.WCh_Con;
54 package body Lib.Writ is
56 -----------------------
57 -- Local Subprograms --
58 -----------------------
60 procedure Write_Unit_Name (N : Node_Id);
61 -- Used to write out the unit name for R (pragma Restriction) lines
62 -- for uses of Restriction (No_Dependence => unit-name).
64 ----------------------------------
65 -- Add_Preprocessing_Dependency --
66 ----------------------------------
68 procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
69 begin
70 Units.Increment_Last;
71 Units.Table (Units.Last) :=
72 (Unit_File_Name => File_Name (S),
73 Unit_Name => No_Unit_Name,
74 Expected_Unit => No_Unit_Name,
75 Source_Index => S,
76 Cunit => Empty,
77 Cunit_Entity => Empty,
78 Dependency_Num => 0,
79 Dynamic_Elab => False,
80 Fatal_Error => False,
81 Generate_Code => False,
82 Has_RACW => False,
83 Is_Compiler_Unit => False,
84 Ident_String => Empty,
85 Loading => False,
86 Main_Priority => -1,
87 Munit_Index => 0,
88 Serial_Number => 0,
89 Version => 0,
90 Error_Location => No_Location,
91 OA_Setting => 'O');
92 end Add_Preprocessing_Dependency;
94 ------------------------------
95 -- Ensure_System_Dependency --
96 ------------------------------
98 procedure Ensure_System_Dependency is
99 System_Uname : Unit_Name_Type;
100 -- Unit name for system spec if needed for dummy entry
102 System_Fname : File_Name_Type;
103 -- File name for system spec if needed for dummy entry
105 begin
106 -- Nothing to do if we already compiled System
108 for Unum in Units.First .. Last_Unit loop
109 if Units.Table (Unum).Source_Index = System_Source_File_Index then
110 return;
111 end if;
112 end loop;
114 -- If no entry for system.ads in the units table, then add a entry
115 -- to the units table for system.ads, which will be referenced when
116 -- the ali file is generated. We need this because every unit depends
117 -- on system as a result of Targparm scanning the system.ads file to
118 -- determine the target dependent parameters for the compilation.
120 Name_Len := 6;
121 Name_Buffer (1 .. 6) := "system";
122 System_Uname := Name_To_Unit_Name (Name_Enter);
123 System_Fname := File_Name (System_Source_File_Index);
125 Units.Increment_Last;
126 Units.Table (Units.Last) := (
127 Unit_File_Name => System_Fname,
128 Unit_Name => System_Uname,
129 Expected_Unit => System_Uname,
130 Source_Index => System_Source_File_Index,
131 Cunit => Empty,
132 Cunit_Entity => Empty,
133 Dependency_Num => 0,
134 Dynamic_Elab => False,
135 Fatal_Error => False,
136 Generate_Code => False,
137 Has_RACW => False,
138 Is_Compiler_Unit => False,
139 Ident_String => Empty,
140 Loading => False,
141 Main_Priority => -1,
142 Munit_Index => 0,
143 Serial_Number => 0,
144 Version => 0,
145 Error_Location => No_Location,
146 OA_Setting => 'O');
148 -- Parse system.ads so that the checksum is set right
149 -- Style checks are not applied.
151 declare
152 Save_Mindex : constant Nat := Multiple_Unit_Index;
153 Save_Style : constant Boolean := Style_Check;
154 begin
155 Multiple_Unit_Index := 0;
156 Style_Check := False;
157 Initialize_Scanner (Units.Last, System_Source_File_Index);
158 Discard_List (Par (Configuration_Pragmas => False));
159 Style_Check := Save_Style;
160 Multiple_Unit_Index := Save_Mindex;
161 end;
162 end Ensure_System_Dependency;
164 ---------------
165 -- Write_ALI --
166 ---------------
168 procedure Write_ALI (Object : Boolean) is
170 ----------------
171 -- Local Data --
172 ----------------
174 Last_Unit : constant Unit_Number_Type := Units.Last;
175 -- Record unit number of last unit. We capture this in case we
176 -- have to add a dummy entry to the unit table for package System.
178 With_Flags : array (Units.First .. Last_Unit) of Boolean;
179 -- Array of flags to show which units are with'ed
181 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
182 -- Array of flags to show which units have pragma Elaborate set
184 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
185 -- Array of flags to show which units have pragma Elaborate All set
187 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
188 -- Array of flags to show which units have Elaborate_Desirable set
190 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
191 -- Array of flags to show which units have Elaborate_All_Desirable set
193 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
194 -- Sorted table of source dependencies. One extra entry in case we
195 -- have to add a dummy entry for System.
197 Num_Sdep : Nat := 0;
198 -- Number of active entries in Sdep_Table
200 flag_compare_debug : Int;
201 pragma Import (C, flag_compare_debug);
202 -- Import from toplev.c
204 -----------------------
205 -- Local Subprograms --
206 -----------------------
208 procedure Collect_Withs (Cunit : Node_Id);
209 -- Collect with lines for entries in the context clause of the
210 -- given compilation unit, Cunit.
212 procedure Update_Tables_From_ALI_File;
213 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
214 -- function), update tables from the ALI information, including
215 -- specifically the Compilation_Switches table.
217 function Up_To_Date_ALI_File_Exists return Boolean;
218 -- If there exists an ALI file that is up to date, then this function
219 -- initializes the tables in the ALI spec to contain information on
220 -- this file (using Scan_ALI) and returns True. If no file exists,
221 -- or the file is not up to date, then False is returned.
223 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
224 -- Write out the library information for one unit for which code is
225 -- generated (includes unit line and with lines).
227 procedure Write_With_Lines;
228 -- Write out with lines collected by calls to Collect_Withs
230 -------------------
231 -- Collect_Withs --
232 -------------------
234 procedure Collect_Withs (Cunit : Node_Id) is
235 Item : Node_Id;
236 Unum : Unit_Number_Type;
238 begin
239 Item := First (Context_Items (Cunit));
240 while Present (Item) loop
242 -- Process with clause
244 -- Ada 2005 (AI-50217): limited with_clauses do not create
245 -- dependencies, but must be recorded as components of the
246 -- partition, in case there is no regular with_clause for
247 -- the unit anywhere else.
249 if Nkind (Item) = N_With_Clause then
250 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
251 With_Flags (Unum) := True;
253 if not Limited_Present (Item) then
254 if Elaborate_Present (Item) then
255 Elab_Flags (Unum) := True;
256 end if;
258 if Elaborate_All_Present (Item) then
259 Elab_All_Flags (Unum) := True;
260 end if;
262 if Elaborate_All_Desirable (Item) then
263 Elab_All_Des_Flags (Unum) := True;
264 end if;
266 if Elaborate_Desirable (Item) then
267 Elab_Des_Flags (Unum) := True;
268 end if;
270 else
271 Set_From_With_Type (Cunit_Entity (Unum));
272 end if;
273 end if;
275 Next (Item);
276 end loop;
277 end Collect_Withs;
279 --------------------------------
280 -- Up_To_Date_ALI_File_Exists --
281 --------------------------------
283 function Up_To_Date_ALI_File_Exists return Boolean is
284 Name : File_Name_Type;
285 Text : Text_Buffer_Ptr;
286 Id : Sdep_Id;
287 Sind : Source_File_Index;
289 begin
290 Opt.Check_Object_Consistency := True;
291 Read_Library_Info (Name, Text);
293 -- Return if we could not find an ALI file
295 if Text = null then
296 return False;
297 end if;
299 -- Return if ALI file has bad format
301 Initialize_ALI;
303 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
304 return False;
305 end if;
307 -- If we have an OK ALI file, check if it is up to date
308 -- Note that we assume that the ALI read has all the entries
309 -- we have in our table, plus some additional ones (that can
310 -- come from expansion).
312 Id := First_Sdep_Entry;
313 for J in 1 .. Num_Sdep loop
314 Sind := Units.Table (Sdep_Table (J)).Source_Index;
316 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
317 if Id = Sdep.Last then
318 return False;
319 else
320 Id := Id + 1;
321 end if;
322 end loop;
324 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
325 return False;
326 end if;
327 end loop;
329 return True;
330 end Up_To_Date_ALI_File_Exists;
332 ---------------------------------
333 -- Update_Tables_From_ALI_File --
334 ---------------------------------
336 procedure Update_Tables_From_ALI_File is
337 begin
338 -- Build Compilation_Switches table
340 Compilation_Switches.Init;
342 for J in First_Arg_Entry .. Args.Last loop
343 Compilation_Switches.Increment_Last;
344 Compilation_Switches.Table (Compilation_Switches.Last) :=
345 Args.Table (J);
346 end loop;
347 end Update_Tables_From_ALI_File;
349 ----------------------------
350 -- Write_Unit_Information --
351 ----------------------------
353 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
354 Unode : constant Node_Id := Cunit (Unit_Num);
355 Ukind : constant Node_Kind := Nkind (Unit (Unode));
356 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
357 Pnode : Node_Id;
359 begin
360 Write_Info_Initiate ('U');
361 Write_Info_Char (' ');
362 Write_Info_Name (Unit_Name (Unit_Num));
363 Write_Info_Tab (25);
364 Write_Info_Name (Unit_File_Name (Unit_Num));
366 Write_Info_Tab (49);
367 Write_Info_Str (Version_Get (Unit_Num));
369 -- Add BD parameter if Elaborate_Body pragma desirable
371 if Ekind (Uent) = E_Package
372 and then Elaborate_Body_Desirable (Uent)
373 then
374 Write_Info_Str (" BD");
375 end if;
377 -- Add BN parameter if body needed for SAL
379 if (Is_Subprogram (Uent)
380 or else Ekind (Uent) = E_Package
381 or else Is_Generic_Unit (Uent))
382 and then Body_Needed_For_SAL (Uent)
383 then
384 Write_Info_Str (" BN");
385 end if;
387 if Dynamic_Elab (Unit_Num) then
388 Write_Info_Str (" DE");
389 end if;
391 -- Set the Elaborate_Body indication if either an explicit pragma
392 -- was present, or if this is an instantiation.
394 if Has_Pragma_Elaborate_Body (Uent)
395 or else (Ukind = N_Package_Declaration
396 and then Is_Generic_Instance (Uent)
397 and then Present (Corresponding_Body (Unit (Unode))))
398 then
399 Write_Info_Str (" EB");
400 end if;
402 -- Now see if we should tell the binder that an elaboration entity
403 -- is present, which must be set to true during elaboration.
404 -- We generate the indication if the following condition is met:
406 -- If this is a spec ...
408 if (Is_Subprogram (Uent)
409 or else
410 Ekind (Uent) = E_Package
411 or else
412 Is_Generic_Unit (Uent))
414 -- and an elaboration entity was declared ...
416 and then Present (Elaboration_Entity (Uent))
418 -- and either the elaboration flag is required ...
420 and then
421 (Elaboration_Entity_Required (Uent)
423 -- or this unit has elaboration code ...
425 or else not Has_No_Elaboration_Code (Unode)
427 -- or this unit has a separate body and this
428 -- body has elaboration code.
430 or else
431 (Ekind (Uent) = E_Package
432 and then Present (Body_Entity (Uent))
433 and then
434 not Has_No_Elaboration_Code
435 (Parent
436 (Declaration_Node
437 (Body_Entity (Uent))))))
438 then
439 if Convention (Uent) = Convention_CIL then
441 -- Special case for generic CIL packages which never have
442 -- elaboration code
444 Write_Info_Str (" NE");
446 else
447 Write_Info_Str (" EE");
448 end if;
449 end if;
451 if Has_No_Elaboration_Code (Unode) then
452 Write_Info_Str (" NE");
453 end if;
455 Write_Info_Str (" O");
456 Write_Info_Char (OA_Setting (Unit_Num));
458 if Is_Preelaborated (Uent) then
459 Write_Info_Str (" PR");
460 end if;
462 if Is_Pure (Uent) then
463 Write_Info_Str (" PU");
464 end if;
466 if Has_RACW (Unit_Num) then
467 Write_Info_Str (" RA");
468 end if;
470 if Is_Remote_Call_Interface (Uent) then
471 Write_Info_Str (" RC");
472 end if;
474 if Is_Remote_Types (Uent) then
475 Write_Info_Str (" RT");
476 end if;
478 if Is_Shared_Passive (Uent) then
479 Write_Info_Str (" SP");
480 end if;
482 if Ukind = N_Subprogram_Declaration
483 or else Ukind = N_Subprogram_Body
484 then
485 Write_Info_Str (" SU");
487 elsif Ukind = N_Package_Declaration
488 or else
489 Ukind = N_Package_Body
490 then
491 -- If this is a wrapper package for a subprogram instantiation,
492 -- the user view is the subprogram. Note that in this case the
493 -- ali file contains both the spec and body of the instance.
495 if Is_Wrapper_Package (Uent) then
496 Write_Info_Str (" SU");
497 else
498 Write_Info_Str (" PK");
499 end if;
501 elsif Ukind = N_Generic_Package_Declaration then
502 Write_Info_Str (" PK");
504 end if;
506 if Ukind in N_Generic_Declaration
507 or else
508 (Present (Library_Unit (Unode))
509 and then
510 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
511 then
512 Write_Info_Str (" GE");
513 end if;
515 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
516 case Identifier_Casing (Source_Index (Unit_Num)) is
517 when All_Lower_Case => Write_Info_Str (" IL");
518 when All_Upper_Case => Write_Info_Str (" IU");
519 when others => null;
520 end case;
522 case Keyword_Casing (Source_Index (Unit_Num)) is
523 when Mixed_Case => Write_Info_Str (" KM");
524 when All_Upper_Case => Write_Info_Str (" KU");
525 when others => null;
526 end case;
527 end if;
529 if Initialize_Scalars or else Invalid_Value_Used then
530 Write_Info_Str (" IS");
531 end if;
533 Write_Info_EOL;
535 -- Generate with lines, first those that are directly with'ed
537 for J in With_Flags'Range loop
538 With_Flags (J) := False;
539 Elab_Flags (J) := False;
540 Elab_All_Flags (J) := False;
541 Elab_Des_Flags (J) := False;
542 Elab_All_Des_Flags (J) := False;
543 end loop;
545 Collect_Withs (Unode);
547 -- For a body, we must also check for any subunits which belong to
548 -- it and which have context clauses of their own, since these
549 -- with'ed units are part of its own elaboration dependencies.
551 if Nkind (Unit (Unode)) in N_Unit_Body then
552 for S in Units.First .. Last_Unit loop
554 -- We are only interested in subunits.
555 -- For preproc. data and def. files, Cunit is Empty, so
556 -- we need to test that first.
558 if Cunit (S) /= Empty
559 and then Nkind (Unit (Cunit (S))) = N_Subunit
560 then
561 Pnode := Library_Unit (Cunit (S));
563 -- In gnatc mode, the errors in the subunits will not
564 -- have been recorded, but the analysis of the subunit
565 -- may have failed. There is no information to add to
566 -- ALI file in this case.
568 if No (Pnode) then
569 exit;
570 end if;
572 -- Find ultimate parent of the subunit
574 while Nkind (Unit (Pnode)) = N_Subunit loop
575 Pnode := Library_Unit (Pnode);
576 end loop;
578 -- See if it belongs to current unit, and if so, include
579 -- its with_clauses.
581 if Pnode = Unode then
582 Collect_Withs (Cunit (S));
583 end if;
584 end if;
585 end loop;
586 end if;
588 Write_With_Lines;
590 -- Output linker option lines
592 for J in 1 .. Linker_Option_Lines.Last loop
593 declare
594 S : constant Linker_Option_Entry :=
595 Linker_Option_Lines.Table (J);
596 C : Character;
598 begin
599 if S.Unit = Unit_Num then
600 Write_Info_Initiate ('L');
601 Write_Info_Str (" """);
603 for J in 1 .. String_Length (S.Option) loop
604 C := Get_Character (Get_String_Char (S.Option, J));
606 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
607 and then C /= '{'
608 then
609 Write_Info_Char (C);
611 if C = '"' then
612 Write_Info_Char (C);
613 end if;
615 else
616 declare
617 Hex : constant array (0 .. 15) of Character :=
618 "0123456789ABCDEF";
620 begin
621 Write_Info_Char ('{');
622 Write_Info_Char (Hex (Character'Pos (C) / 16));
623 Write_Info_Char (Hex (Character'Pos (C) mod 16));
624 Write_Info_Char ('}');
625 end;
626 end if;
627 end loop;
629 Write_Info_Char ('"');
630 Write_Info_EOL;
631 end if;
632 end;
633 end loop;
634 end Write_Unit_Information;
636 ----------------------
637 -- Write_With_Lines --
638 ----------------------
640 procedure Write_With_Lines is
641 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
642 Num_Withs : Int := 0;
643 Unum : Unit_Number_Type;
644 Cunit : Node_Id;
645 Uname : Unit_Name_Type;
646 Fname : File_Name_Type;
647 Pname : constant Unit_Name_Type :=
648 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
649 Body_Fname : File_Name_Type;
650 Body_Index : Nat;
652 procedure Write_With_File_Names
653 (Nam : in out File_Name_Type;
654 Idx : Nat);
655 -- Write source file name Nam and ALI file name for unit index Idx.
656 -- Possibly change Nam to lowercase (generating a new file name).
658 --------------------------
659 -- Write_With_File_Name --
660 --------------------------
662 procedure Write_With_File_Names
663 (Nam : in out File_Name_Type;
664 Idx : Nat)
666 begin
667 if not File_Names_Case_Sensitive then
668 Get_Name_String (Nam);
669 To_Lower (Name_Buffer (1 .. Name_Len));
670 Nam := Name_Find;
671 end if;
673 Write_Info_Name (Nam);
674 Write_Info_Tab (49);
675 Write_Info_Name (Lib_File_Name (Nam, Idx));
676 end Write_With_File_Names;
678 -- Start of processing for Write_With_Lines
680 begin
681 -- Loop to build the with table. A with on the main unit itself
682 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
683 -- the main unit is a subprogram with no spec, and a subunit of
684 -- it unnecessarily withs the parent.
686 for J in Units.First + 1 .. Last_Unit loop
688 -- Add element to with table if it is with'ed or if it is the
689 -- parent spec of the main unit (case of main unit is a child
690 -- unit). The latter with is not needed for semantic purposes,
691 -- but is required by the binder for elaboration purposes.
692 -- For preproc. data and def. files, there is no Unit_Name,
693 -- check for that first.
695 if Unit_Name (J) /= No_Unit_Name
696 and then (With_Flags (J) or else Unit_Name (J) = Pname)
697 then
698 Num_Withs := Num_Withs + 1;
699 With_Table (Num_Withs) := J;
700 end if;
701 end loop;
703 -- Sort and output the table
705 Sort (With_Table (1 .. Num_Withs));
707 for J in 1 .. Num_Withs loop
708 Unum := With_Table (J);
709 Cunit := Units.Table (Unum).Cunit;
710 Uname := Units.Table (Unum).Unit_Name;
711 Fname := Units.Table (Unum).Unit_File_Name;
713 if Ekind (Cunit_Entity (Unum)) = E_Package
714 and then From_With_Type (Cunit_Entity (Unum))
715 then
716 Write_Info_Initiate ('Y');
717 else
718 Write_Info_Initiate ('W');
719 end if;
721 Write_Info_Char (' ');
722 Write_Info_Name (Uname);
724 -- Now we need to figure out the names of the files that contain
725 -- the with'ed unit. These will usually be the files for the body,
726 -- except in the case of a package that has no body. Note that we
727 -- have a specific exemption here for predefined library generics
728 -- (see comments for Generic_May_Lack_ALI). We do not generate
729 -- dependency upon the ALI file for such units. Older compilers
730 -- used to not support generating code (and ALI) for generics, and
731 -- we want to avoid having different processing (namely, different
732 -- lists of files to be compiled) for different stages of the
733 -- bootstrap.
735 if not ((Nkind (Unit (Cunit)) in N_Generic_Declaration
736 or else
737 Nkind (Unit (Cunit)) in N_Generic_Renaming_Declaration)
738 and then Generic_May_Lack_ALI (Fname))
739 then
740 Write_Info_Tab (25);
742 if Is_Spec_Name (Uname) then
743 Body_Fname :=
744 Get_File_Name
745 (Get_Body_Name (Uname),
746 Subunit => False, May_Fail => True);
748 Body_Index :=
749 Get_Unit_Index
750 (Get_Body_Name (Uname));
752 if Body_Fname = No_File then
753 Body_Fname := Get_File_Name (Uname, Subunit => False);
754 Body_Index := Get_Unit_Index (Uname);
755 end if;
757 else
758 Body_Fname := Get_File_Name (Uname, Subunit => False);
759 Body_Index := Get_Unit_Index (Uname);
760 end if;
762 -- A package is considered to have a body if it requires
763 -- a body or if a body is present in Ada 83 mode.
765 if Body_Required (Cunit)
766 or else (Ada_Version = Ada_83
767 and then Full_Source_Name (Body_Fname) /= No_File)
768 then
769 Write_With_File_Names (Body_Fname, Body_Index);
770 else
771 Write_With_File_Names (Fname, Munit_Index (Unum));
772 end if;
774 if Ekind (Cunit_Entity (Unum)) = E_Package
775 and then From_With_Type (Cunit_Entity (Unum))
776 then
777 null;
778 else
779 if Elab_Flags (Unum) then
780 Write_Info_Str (" E");
781 end if;
783 if Elab_All_Flags (Unum) then
784 Write_Info_Str (" EA");
785 end if;
787 if Elab_Des_Flags (Unum) then
788 Write_Info_Str (" ED");
789 end if;
791 if Elab_All_Des_Flags (Unum) then
792 Write_Info_Str (" AD");
793 end if;
794 end if;
795 end if;
797 Write_Info_EOL;
798 end loop;
799 end Write_With_Lines;
801 -- Start of processing for Write_ALI
803 begin
804 -- We never write an ALI file if the original operating mode was
805 -- syntax-only (-gnats switch used in compiler invocation line)
807 if Original_Operating_Mode = Check_Syntax
808 or flag_compare_debug /= 0
809 then
810 return;
811 end if;
813 -- Build sorted source dependency table. We do this right away,
814 -- because it is referenced by Up_To_Date_ALI_File_Exists.
816 for Unum in Units.First .. Last_Unit loop
817 if Cunit_Entity (Unum) = Empty
818 or else not From_With_Type (Cunit_Entity (Unum))
819 then
820 Num_Sdep := Num_Sdep + 1;
821 Sdep_Table (Num_Sdep) := Unum;
822 end if;
823 end loop;
825 -- Sort the table so that the D lines are in order
827 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
829 -- If we are not generating code, and there is an up to date
830 -- ali file accessible, read it, and acquire the compilation
831 -- arguments from this file.
833 if Operating_Mode /= Generate_Code then
834 if Up_To_Date_ALI_File_Exists then
835 Update_Tables_From_ALI_File;
836 return;
837 end if;
838 end if;
840 -- Otherwise acquire compilation arguments and prepare to write
841 -- out a new ali file.
843 Create_Output_Library_Info;
845 -- Output version line
847 Write_Info_Initiate ('V');
848 Write_Info_Str (" """);
849 Write_Info_Str (Verbose_Library_Version);
850 Write_Info_Char ('"');
852 Write_Info_EOL;
854 -- Output main program line if this is acceptable main program
856 Output_Main_Program_Line : declare
857 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
858 S : Node_Id;
860 procedure M_Parameters;
861 -- Output parameters for main program line
863 ------------------
864 -- M_Parameters --
865 ------------------
867 procedure M_Parameters is
868 begin
869 if Main_Priority (Main_Unit) /= Default_Main_Priority then
870 Write_Info_Char (' ');
871 Write_Info_Nat (Main_Priority (Main_Unit));
872 end if;
874 if Opt.Time_Slice_Set then
875 Write_Info_Str (" T=");
876 Write_Info_Nat (Opt.Time_Slice_Value);
877 end if;
879 Write_Info_Str (" W=");
880 Write_Info_Char
881 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
883 Write_Info_EOL;
884 end M_Parameters;
886 -- Start of processing for Output_Main_Program_Line
888 begin
889 if Nkind (U) = N_Subprogram_Body
890 or else
891 (Nkind (U) = N_Package_Body
892 and then
893 Nkind (Original_Node (U)) in N_Subprogram_Instantiation)
894 then
895 -- If the unit is a subprogram instance, the entity for the
896 -- subprogram is the alias of the visible entity, which is the
897 -- related instance of the wrapper package. We retrieve the
898 -- subprogram declaration of the desired entity.
900 if Nkind (U) = N_Package_Body then
901 U := Parent (Parent (
902 Alias (Related_Instance (Defining_Unit_Name
903 (Specification (Unit (Library_Unit (Parent (U)))))))));
904 end if;
906 S := Specification (U);
908 if No (Parameter_Specifications (S)) then
909 if Nkind (S) = N_Procedure_Specification then
910 Write_Info_Initiate ('M');
911 Write_Info_Str (" P");
912 M_Parameters;
914 else
915 declare
916 Nam : Node_Id := Defining_Unit_Name (S);
918 begin
919 -- If it is a child unit, get its simple name
921 if Nkind (Nam) = N_Defining_Program_Unit_Name then
922 Nam := Defining_Identifier (Nam);
923 end if;
925 if Is_Integer_Type (Etype (Nam)) then
926 Write_Info_Initiate ('M');
927 Write_Info_Str (" F");
928 M_Parameters;
929 end if;
930 end;
931 end if;
932 end if;
933 end if;
934 end Output_Main_Program_Line;
936 -- Write command argument ('A') lines
938 for A in 1 .. Compilation_Switches.Last loop
939 Write_Info_Initiate ('A');
940 Write_Info_Char (' ');
941 Write_Info_Str (Compilation_Switches.Table (A).all);
942 Write_Info_Terminate;
943 end loop;
945 -- Output parameters ('P') line
947 Write_Info_Initiate ('P');
949 if Compilation_Errors then
950 Write_Info_Str (" CE");
951 end if;
953 if Opt.Detect_Blocking then
954 Write_Info_Str (" DB");
955 end if;
957 if Opt.Float_Format /= ' ' then
958 Write_Info_Str (" F");
960 if Opt.Float_Format = 'I' then
961 Write_Info_Char ('I');
963 elsif Opt.Float_Format_Long = 'D' then
964 Write_Info_Char ('D');
966 else
967 Write_Info_Char ('G');
968 end if;
969 end if;
971 if Tasking_Used
972 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
973 then
974 if Locking_Policy /= ' ' then
975 Write_Info_Str (" L");
976 Write_Info_Char (Locking_Policy);
977 end if;
979 if Queuing_Policy /= ' ' then
980 Write_Info_Str (" Q");
981 Write_Info_Char (Queuing_Policy);
982 end if;
984 if Task_Dispatching_Policy /= ' ' then
985 Write_Info_Str (" T");
986 Write_Info_Char (Task_Dispatching_Policy);
987 Write_Info_Char (' ');
988 end if;
989 end if;
991 if not Object then
992 Write_Info_Str (" NO");
993 end if;
995 if No_Run_Time_Mode then
996 Write_Info_Str (" NR");
997 end if;
999 if Normalize_Scalars then
1000 Write_Info_Str (" NS");
1001 end if;
1003 if Sec_Stack_Used then
1004 Write_Info_Str (" SS");
1005 end if;
1007 if Unreserve_All_Interrupts then
1008 Write_Info_Str (" UA");
1009 end if;
1011 if Exception_Mechanism = Back_End_Exceptions then
1012 Write_Info_Str (" ZX");
1013 end if;
1015 Write_Info_EOL;
1017 -- Before outputting the restrictions line, update the setting of
1018 -- the No_Elaboration_Code flag. Violations of this restriction
1019 -- cannot be detected until after the backend has been called since
1020 -- it is the backend that sets this flag. We have to check all units
1021 -- for which we have generated code
1023 for Unit in Units.First .. Last_Unit loop
1024 if Units.Table (Unit).Generate_Code
1025 or else Unit = Main_Unit
1026 then
1027 if not Has_No_Elaboration_Code (Cunit (Unit)) then
1028 Main_Restrictions.Violated (No_Elaboration_Code) := True;
1029 end if;
1030 end if;
1031 end loop;
1033 -- Output first restrictions line
1035 Write_Info_Initiate ('R');
1036 Write_Info_Char (' ');
1038 -- First the information for the boolean restrictions
1040 for R in All_Boolean_Restrictions loop
1041 if Main_Restrictions.Set (R)
1042 and then not Restriction_Warnings (R)
1043 then
1044 Write_Info_Char ('r');
1045 elsif Main_Restrictions.Violated (R) then
1046 Write_Info_Char ('v');
1047 else
1048 Write_Info_Char ('n');
1049 end if;
1050 end loop;
1052 -- And now the information for the parameter restrictions
1054 for RP in All_Parameter_Restrictions loop
1055 if Main_Restrictions.Set (RP)
1056 and then not Restriction_Warnings (RP)
1057 then
1058 Write_Info_Char ('r');
1059 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
1060 else
1061 Write_Info_Char ('n');
1062 end if;
1064 if not Main_Restrictions.Violated (RP)
1065 or else RP not in Checked_Parameter_Restrictions
1066 then
1067 Write_Info_Char ('n');
1068 else
1069 Write_Info_Char ('v');
1070 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
1072 if Main_Restrictions.Unknown (RP) then
1073 Write_Info_Char ('+');
1074 end if;
1075 end if;
1076 end loop;
1078 Write_Info_EOL;
1080 -- Output R lines for No_Dependence entries
1082 for J in No_Dependence.First .. No_Dependence.Last loop
1083 if In_Extended_Main_Source_Unit (No_Dependence.Table (J).Unit)
1084 and then not No_Dependence.Table (J).Warn
1085 then
1086 Write_Info_Initiate ('R');
1087 Write_Info_Char (' ');
1088 Write_Unit_Name (No_Dependence.Table (J).Unit);
1089 Write_Info_EOL;
1090 end if;
1091 end loop;
1093 -- Output interrupt state lines
1095 for J in Interrupt_States.First .. Interrupt_States.Last loop
1096 Write_Info_Initiate ('I');
1097 Write_Info_Char (' ');
1098 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
1099 Write_Info_Char (' ');
1100 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
1101 Write_Info_Char (' ');
1102 Write_Info_Nat
1103 (Nat (Get_Logical_Line_Number
1104 (Interrupt_States.Table (J).Pragma_Loc)));
1105 Write_Info_EOL;
1106 end loop;
1108 -- Output priority specific dispatching lines
1110 for J in Specific_Dispatching.First .. Specific_Dispatching.Last loop
1111 Write_Info_Initiate ('S');
1112 Write_Info_Char (' ');
1113 Write_Info_Char (Specific_Dispatching.Table (J).Dispatching_Policy);
1114 Write_Info_Char (' ');
1115 Write_Info_Nat (Specific_Dispatching.Table (J).First_Priority);
1116 Write_Info_Char (' ');
1117 Write_Info_Nat (Specific_Dispatching.Table (J).Last_Priority);
1118 Write_Info_Char (' ');
1119 Write_Info_Nat
1120 (Nat (Get_Logical_Line_Number
1121 (Specific_Dispatching.Table (J).Pragma_Loc)));
1122 Write_Info_EOL;
1123 end loop;
1125 -- Loop through file table to output information for all units for which
1126 -- we have generated code, as marked by the Generate_Code flag.
1128 for Unit in Units.First .. Last_Unit loop
1129 if Units.Table (Unit).Generate_Code
1130 or else Unit = Main_Unit
1131 then
1132 Write_Info_EOL; -- blank line
1133 Write_Unit_Information (Unit);
1134 end if;
1135 end loop;
1137 Write_Info_EOL; -- blank line
1139 -- Output external version reference lines
1141 for J in 1 .. Version_Ref.Last loop
1142 Write_Info_Initiate ('E');
1143 Write_Info_Char (' ');
1145 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1146 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1147 end loop;
1149 Write_Info_EOL;
1150 end loop;
1152 -- Prepare to output the source dependency lines
1154 declare
1155 Unum : Unit_Number_Type;
1156 -- Number of unit being output
1158 Sind : Source_File_Index;
1159 -- Index of corresponding source file
1161 Fname : File_Name_Type;
1163 begin
1164 for J in 1 .. Num_Sdep loop
1165 Unum := Sdep_Table (J);
1166 Units.Table (Unum).Dependency_Num := J;
1167 Sind := Units.Table (Unum).Source_Index;
1169 Write_Info_Initiate ('D');
1170 Write_Info_Char (' ');
1172 -- Normal case of a unit entry with a source index
1174 if Sind /= No_Source_File then
1175 Fname := File_Name (Sind);
1177 -- Ensure that on platforms where the file names are not
1178 -- case sensitive, the recorded file name is in lower case.
1180 if not File_Names_Case_Sensitive then
1181 Get_Name_String (Fname);
1182 To_Lower (Name_Buffer (1 .. Name_Len));
1183 Fname := Name_Find;
1184 end if;
1186 Write_Info_Name (Fname);
1187 Write_Info_Tab (25);
1188 Write_Info_Str (String (Time_Stamp (Sind)));
1189 Write_Info_Char (' ');
1190 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1192 -- If subunit, add unit name, omitting the %b at the end
1194 if Present (Cunit (Unum))
1195 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1196 then
1197 Get_Decoded_Name_String (Unit_Name (Unum));
1198 Write_Info_Char (' ');
1199 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1200 end if;
1202 -- If Source_Reference pragma used output information
1204 if Num_SRef_Pragmas (Sind) > 0 then
1205 Write_Info_Char (' ');
1207 if Num_SRef_Pragmas (Sind) = 1 then
1208 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1209 else
1210 Write_Info_Nat (0);
1211 end if;
1213 Write_Info_Char (':');
1214 Write_Info_Name (Reference_Name (Sind));
1215 end if;
1217 -- Case where there is no source index (happens for missing
1218 -- files). In this case we write a dummy time stamp.
1220 else
1221 Write_Info_Name (Unit_File_Name (Unum));
1222 Write_Info_Tab (25);
1223 Write_Info_Str (String (Dummy_Time_Stamp));
1224 Write_Info_Char (' ');
1225 Write_Info_Str (Get_Hex_String (0));
1226 end if;
1228 Write_Info_EOL;
1229 end loop;
1230 end;
1232 Output_References;
1233 Write_Info_Terminate;
1234 Close_Output_Library_Info;
1235 end Write_ALI;
1237 ---------------------
1238 -- Write_Unit_Name --
1239 ---------------------
1241 procedure Write_Unit_Name (N : Node_Id) is
1242 begin
1243 if Nkind (N) = N_Identifier then
1244 Write_Info_Name (Chars (N));
1246 else
1247 pragma Assert (Nkind (N) = N_Selected_Component);
1248 Write_Unit_Name (Prefix (N));
1249 Write_Info_Char ('.');
1250 Write_Unit_Name (Selector_Name (N));
1251 end if;
1252 end Write_Unit_Name;
1254 end Lib.Writ;