Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / lib-writ.adb
blob9c0b4ad250e5c0d78cb2a04d386986b384bf50be
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . W R I T --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 -- --
26 ------------------------------------------------------------------------------
28 with ALI; use ALI;
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Fname; use Fname;
34 with Fname.UF; use Fname.UF;
35 with Lib.Util; use Lib.Util;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Nlists; use Nlists;
39 with Gnatvsn; use Gnatvsn;
40 with Opt; use Opt;
41 with Osint; use Osint;
42 with Osint.C; use Osint.C;
43 with Par;
44 with Restrict; use Restrict;
45 with Scn; use Scn;
46 with Sinfo; use Sinfo;
47 with Sinput; use Sinput;
48 with Stringt; use Stringt;
49 with Uname; use Uname;
51 with System.WCh_Con; use System.WCh_Con;
53 package body Lib.Writ is
55 ------------------------------
56 -- Ensure_System_Dependency --
57 ------------------------------
59 procedure Ensure_System_Dependency is
60 Discard : List_Id;
62 System_Uname : Unit_Name_Type;
63 -- Unit name for system spec if needed for dummy entry
65 System_Fname : File_Name_Type;
66 -- File name for system spec if needed for dummy entry
68 begin
69 -- Nothing to do if we already compiled System
71 for Unum in Units.First .. Last_Unit loop
72 if Units.Table (Unum).Source_Index = System_Source_File_Index then
73 return;
74 end if;
75 end loop;
77 -- If no entry for system.ads in the units table, then add a entry
78 -- to the units table for system.ads, which will be referenced when
79 -- the ali file is generated. We need this because every unit depends
80 -- on system as a result of Targparm scanning the system.ads file to
81 -- determine the target dependent parameters for the compilation.
83 Name_Len := 6;
84 Name_Buffer (1 .. 6) := "system";
85 System_Uname := Name_To_Unit_Name (Name_Enter);
86 System_Fname := File_Name (System_Source_File_Index);
88 Units.Increment_Last;
89 Units.Table (Units.Last) := (
90 Unit_File_Name => System_Fname,
91 Unit_Name => System_Uname,
92 Expected_Unit => System_Uname,
93 Source_Index => System_Source_File_Index,
94 Cunit => Empty,
95 Cunit_Entity => Empty,
96 Dependency_Num => 0,
97 Dependent_Unit => True,
98 Dynamic_Elab => False,
99 Fatal_Error => False,
100 Generate_Code => False,
101 Has_RACW => False,
102 Ident_String => Empty,
103 Loading => False,
104 Main_Priority => -1,
105 Serial_Number => 0,
106 Version => 0,
107 Error_Location => No_Location);
109 -- Parse system.ads so that the checksum is set right
111 Initialize_Scanner (Units.Last, System_Source_File_Index);
112 Discard := Par (Configuration_Pragmas => False);
113 end Ensure_System_Dependency;
115 ---------------
116 -- Write_ALI --
117 ---------------
119 procedure Write_ALI (Object : Boolean) is
121 ----------------
122 -- Local Data --
123 ----------------
125 Last_Unit : constant Unit_Number_Type := Units.Last;
126 -- Record unit number of last unit. We capture this in case we
127 -- have to add a dummy entry to the unit table for package System.
129 With_Flags : array (Units.First .. Last_Unit) of Boolean;
130 -- Array of flags to show which units are with'ed
132 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
133 -- Array of flags to show which units have pragma Elaborate set
135 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
136 -- Array of flags to show which units have pragma Elaborate All set
138 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
139 -- Array of flags to show which units have Elaborate_All_Desirable set
141 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
142 -- Sorted table of source dependencies. One extra entry in case we
143 -- have to add a dummy entry for System.
145 Num_Sdep : Nat := 0;
146 -- Number of active entries in Sdep_Table
148 -----------------------
149 -- Local Subprograms --
150 -----------------------
152 procedure Collect_Withs (Cunit : Node_Id);
153 -- Collect with lines for entries in the context clause of the
154 -- given compilation unit, Cunit.
156 procedure Update_Tables_From_ALI_File;
157 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
158 -- function), update tables from the ALI information, including
159 -- specifically the Compilation_Switches table.
161 function Up_To_Date_ALI_File_Exists return Boolean;
162 -- If there exists an ALI file that is up to date, then this function
163 -- initializes the tables in the ALI spec to contain information on
164 -- this file (using Scan_ALI) and returns True. If no file exists,
165 -- or the file is not up to date, then False is returned.
167 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
168 -- Write out the library information for one unit for which code is
169 -- generated (includes unit line and with lines).
171 procedure Write_With_Lines;
172 -- Write out with lines collected by calls to Collect_Withs
174 -------------------
175 -- Collect_Withs --
176 -------------------
178 procedure Collect_Withs (Cunit : Node_Id) is
179 Item : Node_Id;
180 Unum : Unit_Number_Type;
182 begin
183 Item := First (Context_Items (Cunit));
184 while Present (Item) loop
186 if Nkind (Item) = N_With_Clause then
187 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
188 With_Flags (Unum) := True;
190 if Elaborate_Present (Item) then
191 Elab_Flags (Unum) := True;
192 end if;
194 if Elaborate_All_Present (Item) then
195 Elab_All_Flags (Unum) := True;
196 end if;
198 if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
199 Elab_Des_Flags (Unum) := True;
200 end if;
201 end if;
203 Next (Item);
204 end loop;
205 end Collect_Withs;
207 --------------------------------
208 -- Up_To_Date_ALI_File_Exists --
209 --------------------------------
211 function Up_To_Date_ALI_File_Exists return Boolean is
212 Name : File_Name_Type;
213 Text : Text_Buffer_Ptr;
214 Id : Sdep_Id;
215 Sind : Source_File_Index;
217 begin
218 Opt.Check_Object_Consistency := True;
219 Read_Library_Info (Name, Text);
221 -- Return if we could not find an ALI file
223 if Text = null then
224 return False;
225 end if;
227 -- Return if ALI file has bad format
229 Initialize_ALI;
231 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
232 return False;
233 end if;
235 -- If we have an OK ALI file, check if it is up to date
236 -- Note that we assume that the ALI read has all the entries
237 -- we have in our table, plus some additional ones (that can
238 -- come from expansion).
240 Id := First_Sdep_Entry;
241 for J in 1 .. Num_Sdep loop
242 Sind := Units.Table (Sdep_Table (J)).Source_Index;
244 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
245 if Id = Sdep.Last then
246 return False;
247 else
248 Id := Id + 1;
249 end if;
250 end loop;
252 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
253 return False;
254 end if;
255 end loop;
257 return True;
258 end Up_To_Date_ALI_File_Exists;
260 ---------------------------------
261 -- Update_Tables_From_ALI_File --
262 ---------------------------------
264 procedure Update_Tables_From_ALI_File is
265 begin
266 -- Build Compilation_Switches table
268 Compilation_Switches.Init;
270 for J in First_Arg_Entry .. Args.Last loop
271 Compilation_Switches.Increment_Last;
272 Compilation_Switches.Table (Compilation_Switches.Last) :=
273 Args.Table (J);
274 end loop;
275 end Update_Tables_From_ALI_File;
277 ----------------------------
278 -- Write_Unit_Information --
279 ----------------------------
281 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
282 Unode : constant Node_Id := Cunit (Unit_Num);
283 Ukind : constant Node_Kind := Nkind (Unit (Unode));
284 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
285 Pnode : Node_Id;
287 begin
288 Write_Info_Initiate ('U');
289 Write_Info_Char (' ');
290 Write_Info_Name (Unit_Name (Unit_Num));
291 Write_Info_Tab (25);
292 Write_Info_Name (Unit_File_Name (Unit_Num));
294 Write_Info_Tab (49);
295 Write_Info_Str (Version_Get (Unit_Num));
297 if Dynamic_Elab (Unit_Num) then
298 Write_Info_Str (" DE");
299 end if;
301 -- We set the Elaborate_Body indication if either an explicit pragma
302 -- was present, or if this is an instantiation. RM 12.3(20) requires
303 -- that the body be immediately elaborated after the spec. We would
304 -- normally do that anyway, but the EB we generate here ensures that
305 -- this gets done even when we use the -p gnatbind switch.
307 if Has_Pragma_Elaborate_Body (Uent)
308 or else (Ukind = N_Package_Declaration
309 and then Is_Generic_Instance (Uent)
310 and then Present (Corresponding_Body (Unit (Unode))))
311 then
312 Write_Info_Str (" EB");
313 end if;
315 -- Now see if we should tell the binder that an elaboration entity
316 -- is present, which must be reset to true during elaboration. We
317 -- generate the indication if the following condition is met:
319 -- If this is a spec ...
321 if (Is_Subprogram (Uent)
322 or else
323 Ekind (Uent) = E_Package
324 or else
325 Is_Generic_Unit (Uent))
327 -- and an elaboration entity was declared ...
329 and then Present (Elaboration_Entity (Uent))
331 -- and either the elaboration flag is required ...
333 and then
334 (Elaboration_Entity_Required (Uent)
336 -- or this unit has elaboration code ...
338 or else not Has_No_Elaboration_Code (Unode)
340 -- or this unit has a separate body and this
341 -- body has elaboration code.
343 or else
344 (Ekind (Uent) = E_Package
345 and then Present (Body_Entity (Uent))
346 and then
347 not Has_No_Elaboration_Code
348 (Parent
349 (Declaration_Node
350 (Body_Entity (Uent))))))
351 then
352 Write_Info_Str (" EE");
353 end if;
355 if Has_No_Elaboration_Code (Unode) then
356 Write_Info_Str (" NE");
357 end if;
359 if Is_Preelaborated (Uent) then
360 Write_Info_Str (" PR");
361 end if;
363 if Is_Pure (Uent) then
364 Write_Info_Str (" PU");
365 end if;
367 if Has_RACW (Unit_Num) then
368 Write_Info_Str (" RA");
369 end if;
371 if Is_Remote_Call_Interface (Uent) then
372 Write_Info_Str (" RC");
373 end if;
375 if Is_Remote_Types (Uent) then
376 Write_Info_Str (" RT");
377 end if;
379 if Is_Shared_Passive (Uent) then
380 Write_Info_Str (" SP");
381 end if;
383 if Ukind = N_Subprogram_Declaration
384 or else Ukind = N_Subprogram_Body
385 then
386 Write_Info_Str (" SU");
388 elsif Ukind = N_Package_Declaration
389 or else
390 Ukind = N_Package_Body
391 then
392 -- If this is a wrapper package for a subprogram instantiation,
393 -- the user view is the subprogram. Note that in this case the
394 -- ali file contains both the spec and body of the instance.
396 if Is_Wrapper_Package (Uent) then
397 Write_Info_Str (" SU");
398 else
399 Write_Info_Str (" PK");
400 end if;
402 elsif Ukind = N_Generic_Package_Declaration then
403 Write_Info_Str (" PK");
405 end if;
407 if Ukind in N_Generic_Declaration
408 or else
409 (Present (Library_Unit (Unode))
410 and then
411 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
412 then
413 Write_Info_Str (" GE");
414 end if;
416 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
417 case Identifier_Casing (Source_Index (Unit_Num)) is
418 when All_Lower_Case => Write_Info_Str (" IL");
419 when All_Upper_Case => Write_Info_Str (" IU");
420 when others => null;
421 end case;
423 case Keyword_Casing (Source_Index (Unit_Num)) is
424 when Mixed_Case => Write_Info_Str (" KM");
425 when All_Upper_Case => Write_Info_Str (" KU");
426 when others => null;
427 end case;
428 end if;
430 if Initialize_Scalars then
431 Write_Info_Str (" IS");
432 end if;
434 Write_Info_EOL;
436 -- Generate with lines, first those that are directly with'ed
438 for J in With_Flags'Range loop
439 With_Flags (J) := False;
440 Elab_Flags (J) := False;
441 Elab_All_Flags (J) := False;
442 Elab_Des_Flags (J) := False;
443 end loop;
445 Collect_Withs (Unode);
447 -- For a body, we must also check for any subunits which belong to
448 -- it and which have context clauses of their own, since these
449 -- with'ed units are part of its own elaboration dependencies.
451 if Nkind (Unit (Unode)) in N_Unit_Body then
452 for S in Units.First .. Last_Unit loop
454 -- We are only interested in subunits
456 if Nkind (Unit (Cunit (S))) = N_Subunit then
457 Pnode := Library_Unit (Cunit (S));
459 -- In gnatc mode, the errors in the subunits will not
460 -- have been recorded, but the analysis of the subunit
461 -- may have failed. There is no information to add to
462 -- ALI file in this case.
464 if No (Pnode) then
465 exit;
466 end if;
468 -- Find ultimate parent of the subunit
470 while Nkind (Unit (Pnode)) = N_Subunit loop
471 Pnode := Library_Unit (Pnode);
472 end loop;
474 -- See if it belongs to current unit, and if so, include
475 -- its with_clauses.
477 if Pnode = Unode then
478 Collect_Withs (Cunit (S));
479 end if;
480 end if;
481 end loop;
482 end if;
484 Write_With_Lines;
486 -- Output linker option lines
488 for J in 1 .. Linker_Option_Lines.Last loop
489 declare
490 S : constant Linker_Option_Entry :=
491 Linker_Option_Lines.Table (J);
492 C : Character;
494 begin
495 if S.Unit = Unit_Num then
496 Write_Info_Initiate ('L');
497 Write_Info_Str (" """);
499 for J in 1 .. String_Length (S.Option) loop
500 C := Get_Character (Get_String_Char (S.Option, J));
502 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
503 and then C /= '{'
504 then
505 Write_Info_Char (C);
507 if C = '"' then
508 Write_Info_Char (C);
509 end if;
511 else
512 declare
513 Hex : array (0 .. 15) of Character :=
514 "0123456789ABCDEF";
516 begin
517 Write_Info_Char ('{');
518 Write_Info_Char (Hex (Character'Pos (C) / 16));
519 Write_Info_Char (Hex (Character'Pos (C) mod 16));
520 Write_Info_Char ('}');
521 end;
522 end if;
523 end loop;
525 Write_Info_Char ('"');
526 Write_Info_EOL;
527 end if;
528 end;
529 end loop;
530 end Write_Unit_Information;
532 ----------------------
533 -- Write_With_Lines --
534 ----------------------
536 procedure Write_With_Lines is
537 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
538 Num_Withs : Int := 0;
539 Unum : Unit_Number_Type;
540 Cunit : Node_Id;
541 Cunite : Entity_Id;
542 Uname : Unit_Name_Type;
543 Fname : File_Name_Type;
544 Pname : constant Unit_Name_Type :=
545 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
546 Body_Fname : File_Name_Type;
548 begin
549 -- Loop to build the with table. A with on the main unit itself
550 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
551 -- the main unit is a subprogram with no spec, and a subunit of
552 -- it unecessarily withs the parent.
554 for J in Units.First + 1 .. Last_Unit loop
556 -- Add element to with table if it is with'ed or if it is the
557 -- parent spec of the main unit (case of main unit is a child
558 -- unit). The latter with is not needed for semantic purposes,
559 -- but is required by the binder for elaboration purposes.
561 if (With_Flags (J) or else Unit_Name (J) = Pname)
562 and then Units.Table (J).Dependent_Unit
563 then
564 Num_Withs := Num_Withs + 1;
565 With_Table (Num_Withs) := J;
566 end if;
567 end loop;
569 -- Sort and output the table
571 Sort (With_Table (1 .. Num_Withs));
573 for J in 1 .. Num_Withs loop
574 Unum := With_Table (J);
575 Cunit := Units.Table (Unum).Cunit;
576 Cunite := Units.Table (Unum).Cunit_Entity;
577 Uname := Units.Table (Unum).Unit_Name;
578 Fname := Units.Table (Unum).Unit_File_Name;
580 Write_Info_Initiate ('W');
581 Write_Info_Char (' ');
582 Write_Info_Name (Uname);
584 -- Now we need to figure out the names of the files that contain
585 -- the with'ed unit. These will usually be the files for the body,
586 -- except in the case of a package that has no body.
588 if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
589 and then
590 Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
591 or else Generic_Separately_Compiled (Cunite)
592 then
593 Write_Info_Tab (25);
595 if Is_Spec_Name (Uname) then
596 Body_Fname :=
597 Get_File_Name (Get_Body_Name (Uname), Subunit => False);
598 else
599 Body_Fname := Get_File_Name (Uname, Subunit => False);
600 end if;
602 -- A package is considered to have a body if it requires
603 -- a body or if a body is present in Ada 83 mode.
605 if Body_Required (Cunit)
606 or else (Ada_83
607 and then Full_Source_Name (Body_Fname) /= No_File)
608 then
609 Write_Info_Name (Body_Fname);
610 Write_Info_Tab (49);
611 Write_Info_Name (Lib_File_Name (Body_Fname));
612 else
613 Write_Info_Name (Fname);
614 Write_Info_Tab (49);
615 Write_Info_Name (Lib_File_Name (Fname));
616 end if;
618 if Elab_Flags (Unum) then
619 Write_Info_Str (" E");
620 end if;
622 if Elab_All_Flags (Unum) then
623 Write_Info_Str (" EA");
624 end if;
626 if Elab_Des_Flags (Unum) then
627 Write_Info_Str (" ED");
628 end if;
629 end if;
631 Write_Info_EOL;
632 end loop;
633 end Write_With_Lines;
635 -- Start of processing for Writ_ALI
637 begin
638 -- Build sorted source dependency table. We do this right away,
639 -- because it is referenced by Up_To_Date_ALI_File_Exists.
641 for Unum in Units.First .. Last_Unit loop
642 Num_Sdep := Num_Sdep + 1;
643 Sdep_Table (Num_Sdep) := Unum;
644 end loop;
646 -- Sort the table so that the D lines are in order
648 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
650 -- If we are not generating code, and there is an up to date
651 -- ali file accessible, read it, and acquire the compilation
652 -- arguments from this file.
654 if Operating_Mode /= Generate_Code then
655 if Up_To_Date_ALI_File_Exists then
656 Update_Tables_From_ALI_File;
657 return;
658 end if;
659 end if;
661 -- Otherwise acquire compilation arguments and prepare to write
662 -- out a new ali file.
664 Create_Output_Library_Info;
666 -- Output version line
668 Write_Info_Initiate ('V');
669 Write_Info_Str (" """);
670 Write_Info_Str (Library_Version);
671 Write_Info_Char ('"');
673 Write_Info_EOL;
675 -- Output main program line if this is acceptable main program
677 declare
678 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
679 S : Node_Id;
681 procedure M_Parameters;
682 -- Output parameters for main program line
684 procedure M_Parameters is
685 begin
686 if Main_Priority (Main_Unit) /= Default_Main_Priority then
687 Write_Info_Char (' ');
688 Write_Info_Nat (Main_Priority (Main_Unit));
689 end if;
691 if Opt.Time_Slice_Set then
692 Write_Info_Str (" T=");
693 Write_Info_Nat (Opt.Time_Slice_Value);
694 end if;
696 Write_Info_Str (" W=");
697 Write_Info_Char
698 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
700 Write_Info_EOL;
701 end M_Parameters;
703 begin
704 if Nkind (U) = N_Subprogram_Body
705 or else (Nkind (U) = N_Package_Body
706 and then
707 (Nkind (Original_Node (U)) = N_Function_Instantiation
708 or else
709 Nkind (Original_Node (U)) =
710 N_Procedure_Instantiation))
711 then
712 -- If the unit is a subprogram instance, the entity for the
713 -- subprogram is the alias of the visible entity, which is the
714 -- related instance of the wrapper package. We retrieve the
715 -- subprogram declaration of the desired entity.
717 if Nkind (U) = N_Package_Body then
718 U := Parent (Parent (
719 Alias (Related_Instance (Defining_Unit_Name
720 (Specification (Unit (Library_Unit (Parent (U)))))))));
721 end if;
723 S := Specification (U);
725 if not Present (Parameter_Specifications (S)) then
726 if Nkind (S) = N_Procedure_Specification then
727 Write_Info_Initiate ('M');
728 Write_Info_Str (" P");
729 M_Parameters;
731 else
732 declare
733 Nam : Node_Id := Defining_Unit_Name (S);
735 begin
736 -- If it is a child unit, get its simple name.
738 if Nkind (Nam) = N_Defining_Program_Unit_Name then
739 Nam := Defining_Identifier (Nam);
740 end if;
742 if Is_Integer_Type (Etype (Nam)) then
743 Write_Info_Initiate ('M');
744 Write_Info_Str (" F");
745 M_Parameters;
746 end if;
747 end;
748 end if;
749 end if;
750 end if;
751 end;
753 -- Write command argmument ('A') lines
755 for A in 1 .. Compilation_Switches.Last loop
756 Write_Info_Initiate ('A');
757 Write_Info_Char (' ');
758 Write_Info_Str (Compilation_Switches.Table (A).all);
759 Write_Info_Terminate;
760 end loop;
762 -- Output parameters ('P') line
764 Write_Info_Initiate ('P');
766 if Compilation_Errors then
767 Write_Info_Str (" CE");
768 end if;
770 if Opt.Float_Format /= ' ' then
771 Write_Info_Str (" F");
773 if Opt.Float_Format = 'I' then
774 Write_Info_Char ('I');
776 elsif Opt.Float_Format_Long = 'D' then
777 Write_Info_Char ('D');
779 else
780 Write_Info_Char ('G');
781 end if;
782 end if;
784 if Tasking_Used
785 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
786 then
787 if Locking_Policy /= ' ' then
788 Write_Info_Str (" L");
789 Write_Info_Char (Locking_Policy);
790 end if;
792 if Queuing_Policy /= ' ' then
793 Write_Info_Str (" Q");
794 Write_Info_Char (Queuing_Policy);
795 end if;
797 if Task_Dispatching_Policy /= ' ' then
798 Write_Info_Str (" T");
799 Write_Info_Char (Task_Dispatching_Policy);
800 Write_Info_Char (' ');
801 end if;
802 end if;
804 if not Object then
805 Write_Info_Str (" NO");
806 end if;
808 if No_Run_Time then
809 Write_Info_Str (" NR");
810 end if;
812 if Normalize_Scalars then
813 Write_Info_Str (" NS");
814 end if;
816 if Unreserve_All_Interrupts then
817 Write_Info_Str (" UA");
818 end if;
820 if Exception_Mechanism /= Setjmp_Longjmp then
821 if Unit_Exception_Table_Present then
822 Write_Info_Str (" UX");
823 end if;
825 Write_Info_Str (" ZX");
826 end if;
828 Write_Info_EOL;
830 -- Output restrictions line
832 Write_Info_Initiate ('R');
833 Write_Info_Char (' ');
835 for J in All_Restrictions loop
836 if Main_Restrictions (J) then
837 Write_Info_Char ('r');
838 elsif Violations (J) then
839 Write_Info_Char ('v');
840 else
841 Write_Info_Char ('n');
842 end if;
843 end loop;
845 Write_Info_EOL;
847 -- Loop through file table to output information for all units for which
848 -- we have generated code, as marked by the Generate_Code flag.
850 for Unit in Units.First .. Last_Unit loop
851 if Units.Table (Unit).Generate_Code
852 or else Unit = Main_Unit
853 then
854 Write_Info_EOL; -- blank line
855 Write_Unit_Information (Unit);
856 end if;
857 end loop;
859 Write_Info_EOL; -- blank line
861 -- Output external version reference lines
863 for J in 1 .. Version_Ref.Last loop
864 Write_Info_Initiate ('E');
865 Write_Info_Char (' ');
867 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
868 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
869 end loop;
871 Write_Info_EOL;
872 end loop;
874 -- Prepare to output the source dependency lines
876 declare
877 Unum : Unit_Number_Type;
878 -- Number of unit being output
880 Sind : Source_File_Index;
881 -- Index of corresponding source file
883 begin
884 for J in 1 .. Num_Sdep loop
885 Unum := Sdep_Table (J);
886 Units.Table (Unum).Dependency_Num := J;
887 Sind := Units.Table (Unum).Source_Index;
889 Write_Info_Initiate ('D');
890 Write_Info_Char (' ');
892 -- Normal case of a dependent unit entry with a source index
894 if Sind /= No_Source_File
895 and then Units.Table (Unum).Dependent_Unit
896 then
897 Write_Info_Name (File_Name (Sind));
898 Write_Info_Tab (25);
899 Write_Info_Str (String (Time_Stamp (Sind)));
900 Write_Info_Char (' ');
901 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
903 -- If subunit, add unit name, omitting the %b at the end
905 if Present (Cunit (Unum))
906 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
907 then
908 Get_Decoded_Name_String (Unit_Name (Unum));
909 Write_Info_Char (' ');
910 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
911 end if;
913 -- If Source_Reference pragma used output information
915 if Num_SRef_Pragmas (Sind) > 0 then
916 Write_Info_Char (' ');
918 if Num_SRef_Pragmas (Sind) = 1 then
919 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
920 else
921 Write_Info_Nat (0);
922 end if;
924 Write_Info_Char (':');
925 Write_Info_Name (Reference_Name (Sind));
926 end if;
928 -- Case where there is no source index (happens for missing files)
929 -- Also come here for non-dependent units.
931 else
932 Write_Info_Name (Unit_File_Name (Unum));
933 Write_Info_Tab (25);
934 Write_Info_Str (String (Dummy_Time_Stamp));
935 Write_Info_Char (' ');
936 Write_Info_Str (Get_Hex_String (0));
937 end if;
939 Write_Info_EOL;
940 end loop;
941 end;
943 Output_References;
944 Write_Info_Terminate;
945 Close_Output_Library_Info;
947 end Write_ALI;
949 end Lib.Writ;