* gnu/regexp/CharIndexedReader.java: Removed.
[official-gcc.git] / gcc / ada / lib-writ.adb
blob7168e69c9a220115ec9f7d342f192eae0a6cc835
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 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 Munit_Index => 0,
79 Serial_Number => 0,
80 Version => 0,
81 Error_Location => No_Location);
82 end Add_Preprocessing_Dependency;
84 ------------------------------
85 -- Ensure_System_Dependency --
86 ------------------------------
88 procedure Ensure_System_Dependency is
89 System_Uname : Unit_Name_Type;
90 -- Unit name for system spec if needed for dummy entry
92 System_Fname : File_Name_Type;
93 -- File name for system spec if needed for dummy entry
95 begin
96 -- Nothing to do if we already compiled System
98 for Unum in Units.First .. Last_Unit loop
99 if Units.Table (Unum).Source_Index = System_Source_File_Index then
100 return;
101 end if;
102 end loop;
104 -- If no entry for system.ads in the units table, then add a entry
105 -- to the units table for system.ads, which will be referenced when
106 -- the ali file is generated. We need this because every unit depends
107 -- on system as a result of Targparm scanning the system.ads file to
108 -- determine the target dependent parameters for the compilation.
110 Name_Len := 6;
111 Name_Buffer (1 .. 6) := "system";
112 System_Uname := Name_To_Unit_Name (Name_Enter);
113 System_Fname := File_Name (System_Source_File_Index);
115 Units.Increment_Last;
116 Units.Table (Units.Last) := (
117 Unit_File_Name => System_Fname,
118 Unit_Name => System_Uname,
119 Expected_Unit => System_Uname,
120 Source_Index => System_Source_File_Index,
121 Cunit => Empty,
122 Cunit_Entity => Empty,
123 Dependency_Num => 0,
124 Dynamic_Elab => False,
125 Fatal_Error => False,
126 Generate_Code => False,
127 Has_RACW => False,
128 Ident_String => Empty,
129 Loading => False,
130 Main_Priority => -1,
131 Munit_Index => 0,
132 Serial_Number => 0,
133 Version => 0,
134 Error_Location => No_Location);
136 -- Parse system.ads so that the checksum is set right
137 -- Style checks are not applied.
139 declare
140 Save_Mindex : constant Nat := Multiple_Unit_Index;
141 Save_Style : constant Boolean := Style_Check;
142 begin
143 Multiple_Unit_Index := 0;
144 Style_Check := False;
145 Initialize_Scanner (Units.Last, System_Source_File_Index);
146 Discard_List (Par (Configuration_Pragmas => False));
147 Style_Check := Save_Style;
148 Multiple_Unit_Index := Save_Mindex;
149 end;
150 end Ensure_System_Dependency;
152 ---------------
153 -- Write_ALI --
154 ---------------
156 procedure Write_ALI (Object : Boolean) is
158 ----------------
159 -- Local Data --
160 ----------------
162 Last_Unit : constant Unit_Number_Type := Units.Last;
163 -- Record unit number of last unit. We capture this in case we
164 -- have to add a dummy entry to the unit table for package System.
166 With_Flags : array (Units.First .. Last_Unit) of Boolean;
167 -- Array of flags to show which units are with'ed
169 Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
170 -- Array of flags to show which units have pragma Elaborate set
172 Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
173 -- Array of flags to show which units have pragma Elaborate All set
175 Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
176 -- Array of flags to show which units have Elaborate_All_Desirable set
178 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
179 -- Sorted table of source dependencies. One extra entry in case we
180 -- have to add a dummy entry for System.
182 Num_Sdep : Nat := 0;
183 -- Number of active entries in Sdep_Table
185 -----------------------
186 -- Local Subprograms --
187 -----------------------
189 procedure Collect_Withs (Cunit : Node_Id);
190 -- Collect with lines for entries in the context clause of the
191 -- given compilation unit, Cunit.
193 procedure Update_Tables_From_ALI_File;
194 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
195 -- function), update tables from the ALI information, including
196 -- specifically the Compilation_Switches table.
198 function Up_To_Date_ALI_File_Exists return Boolean;
199 -- If there exists an ALI file that is up to date, then this function
200 -- initializes the tables in the ALI spec to contain information on
201 -- this file (using Scan_ALI) and returns True. If no file exists,
202 -- or the file is not up to date, then False is returned.
204 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
205 -- Write out the library information for one unit for which code is
206 -- generated (includes unit line and with lines).
208 procedure Write_With_Lines;
209 -- Write out with lines collected by calls to Collect_Withs
211 -------------------
212 -- Collect_Withs --
213 -------------------
215 procedure Collect_Withs (Cunit : Node_Id) is
216 Item : Node_Id;
217 Unum : Unit_Number_Type;
219 begin
220 Item := First (Context_Items (Cunit));
221 while Present (Item) loop
223 -- Ada0Y (AI-50217): limited with_clauses do not create
224 -- dependencies
226 if Nkind (Item) = N_With_Clause
227 and then not (Limited_Present (Item))
228 then
229 Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
230 With_Flags (Unum) := True;
232 if Elaborate_Present (Item) then
233 Elab_Flags (Unum) := True;
234 end if;
236 if Elaborate_All_Present (Item) then
237 Elab_All_Flags (Unum) := True;
238 end if;
240 if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
241 Elab_Des_Flags (Unum) := True;
242 end if;
243 end if;
245 Next (Item);
246 end loop;
247 end Collect_Withs;
249 --------------------------------
250 -- Up_To_Date_ALI_File_Exists --
251 --------------------------------
253 function Up_To_Date_ALI_File_Exists return Boolean is
254 Name : File_Name_Type;
255 Text : Text_Buffer_Ptr;
256 Id : Sdep_Id;
257 Sind : Source_File_Index;
259 begin
260 Opt.Check_Object_Consistency := True;
261 Read_Library_Info (Name, Text);
263 -- Return if we could not find an ALI file
265 if Text = null then
266 return False;
267 end if;
269 -- Return if ALI file has bad format
271 Initialize_ALI;
273 if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
274 return False;
275 end if;
277 -- If we have an OK ALI file, check if it is up to date
278 -- Note that we assume that the ALI read has all the entries
279 -- we have in our table, plus some additional ones (that can
280 -- come from expansion).
282 Id := First_Sdep_Entry;
283 for J in 1 .. Num_Sdep loop
284 Sind := Units.Table (Sdep_Table (J)).Source_Index;
286 while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
287 if Id = Sdep.Last then
288 return False;
289 else
290 Id := Id + 1;
291 end if;
292 end loop;
294 if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
295 return False;
296 end if;
297 end loop;
299 return True;
300 end Up_To_Date_ALI_File_Exists;
302 ---------------------------------
303 -- Update_Tables_From_ALI_File --
304 ---------------------------------
306 procedure Update_Tables_From_ALI_File is
307 begin
308 -- Build Compilation_Switches table
310 Compilation_Switches.Init;
312 for J in First_Arg_Entry .. Args.Last loop
313 Compilation_Switches.Increment_Last;
314 Compilation_Switches.Table (Compilation_Switches.Last) :=
315 Args.Table (J);
316 end loop;
317 end Update_Tables_From_ALI_File;
319 ----------------------------
320 -- Write_Unit_Information --
321 ----------------------------
323 procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
324 Unode : constant Node_Id := Cunit (Unit_Num);
325 Ukind : constant Node_Kind := Nkind (Unit (Unode));
326 Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
327 Pnode : Node_Id;
329 begin
330 Write_Info_Initiate ('U');
331 Write_Info_Char (' ');
332 Write_Info_Name (Unit_Name (Unit_Num));
333 Write_Info_Tab (25);
334 Write_Info_Name (Unit_File_Name (Unit_Num));
336 Write_Info_Tab (49);
337 Write_Info_Str (Version_Get (Unit_Num));
339 if (Is_Subprogram (Uent)
340 or else Ekind (Uent) = E_Package
341 or else Is_Generic_Unit (Uent))
342 and then Body_Needed_For_SAL (Uent)
343 then
344 Write_Info_Str (" BN");
345 end if;
347 if Dynamic_Elab (Unit_Num) then
348 Write_Info_Str (" DE");
349 end if;
351 -- We set the Elaborate_Body indication if either an explicit pragma
352 -- was present, or if this is an instantiation. RM 12.3(20) requires
353 -- that the body be immediately elaborated after the spec. We would
354 -- normally do that anyway, but the EB we generate here ensures that
355 -- this gets done even when we use the -p gnatbind switch.
357 if Has_Pragma_Elaborate_Body (Uent)
358 or else (Ukind = N_Package_Declaration
359 and then Is_Generic_Instance (Uent)
360 and then Present (Corresponding_Body (Unit (Unode))))
361 then
362 Write_Info_Str (" EB");
363 end if;
365 -- Now see if we should tell the binder that an elaboration entity
366 -- is present, which must be reset to true during elaboration. We
367 -- generate the indication if the following condition is met:
369 -- If this is a spec ...
371 if (Is_Subprogram (Uent)
372 or else
373 Ekind (Uent) = E_Package
374 or else
375 Is_Generic_Unit (Uent))
377 -- and an elaboration entity was declared ...
379 and then Present (Elaboration_Entity (Uent))
381 -- and either the elaboration flag is required ...
383 and then
384 (Elaboration_Entity_Required (Uent)
386 -- or this unit has elaboration code ...
388 or else not Has_No_Elaboration_Code (Unode)
390 -- or this unit has a separate body and this
391 -- body has elaboration code.
393 or else
394 (Ekind (Uent) = E_Package
395 and then Present (Body_Entity (Uent))
396 and then
397 not Has_No_Elaboration_Code
398 (Parent
399 (Declaration_Node
400 (Body_Entity (Uent))))))
401 then
402 Write_Info_Str (" EE");
403 end if;
405 if Has_No_Elaboration_Code (Unode) then
406 Write_Info_Str (" NE");
407 end if;
409 if Is_Preelaborated (Uent) then
410 Write_Info_Str (" PR");
411 end if;
413 if Is_Pure (Uent) then
414 Write_Info_Str (" PU");
415 end if;
417 if Has_RACW (Unit_Num) then
418 Write_Info_Str (" RA");
419 end if;
421 if Is_Remote_Call_Interface (Uent) then
422 Write_Info_Str (" RC");
423 end if;
425 if Is_Remote_Types (Uent) then
426 Write_Info_Str (" RT");
427 end if;
429 if Is_Shared_Passive (Uent) then
430 Write_Info_Str (" SP");
431 end if;
433 if Ukind = N_Subprogram_Declaration
434 or else Ukind = N_Subprogram_Body
435 then
436 Write_Info_Str (" SU");
438 elsif Ukind = N_Package_Declaration
439 or else
440 Ukind = N_Package_Body
441 then
442 -- If this is a wrapper package for a subprogram instantiation,
443 -- the user view is the subprogram. Note that in this case the
444 -- ali file contains both the spec and body of the instance.
446 if Is_Wrapper_Package (Uent) then
447 Write_Info_Str (" SU");
448 else
449 Write_Info_Str (" PK");
450 end if;
452 elsif Ukind = N_Generic_Package_Declaration then
453 Write_Info_Str (" PK");
455 end if;
457 if Ukind in N_Generic_Declaration
458 or else
459 (Present (Library_Unit (Unode))
460 and then
461 Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
462 then
463 Write_Info_Str (" GE");
464 end if;
466 if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
467 case Identifier_Casing (Source_Index (Unit_Num)) is
468 when All_Lower_Case => Write_Info_Str (" IL");
469 when All_Upper_Case => Write_Info_Str (" IU");
470 when others => null;
471 end case;
473 case Keyword_Casing (Source_Index (Unit_Num)) is
474 when Mixed_Case => Write_Info_Str (" KM");
475 when All_Upper_Case => Write_Info_Str (" KU");
476 when others => null;
477 end case;
478 end if;
480 if Initialize_Scalars then
481 Write_Info_Str (" IS");
482 end if;
484 Write_Info_EOL;
486 -- Generate with lines, first those that are directly with'ed
488 for J in With_Flags'Range loop
489 With_Flags (J) := False;
490 Elab_Flags (J) := False;
491 Elab_All_Flags (J) := False;
492 Elab_Des_Flags (J) := False;
493 end loop;
495 Collect_Withs (Unode);
497 -- For a body, we must also check for any subunits which belong to
498 -- it and which have context clauses of their own, since these
499 -- with'ed units are part of its own elaboration dependencies.
501 if Nkind (Unit (Unode)) in N_Unit_Body then
502 for S in Units.First .. Last_Unit loop
504 -- We are only interested in subunits.
505 -- For preproc. data and def. files, Cunit is Empty, so
506 -- we need to test that first.
508 if Cunit (S) /= Empty
509 and then Nkind (Unit (Cunit (S))) = N_Subunit
510 then
511 Pnode := Library_Unit (Cunit (S));
513 -- In gnatc mode, the errors in the subunits will not
514 -- have been recorded, but the analysis of the subunit
515 -- may have failed. There is no information to add to
516 -- ALI file in this case.
518 if No (Pnode) then
519 exit;
520 end if;
522 -- Find ultimate parent of the subunit
524 while Nkind (Unit (Pnode)) = N_Subunit loop
525 Pnode := Library_Unit (Pnode);
526 end loop;
528 -- See if it belongs to current unit, and if so, include
529 -- its with_clauses.
531 if Pnode = Unode then
532 Collect_Withs (Cunit (S));
533 end if;
534 end if;
535 end loop;
536 end if;
538 Write_With_Lines;
540 -- Output linker option lines
542 for J in 1 .. Linker_Option_Lines.Last loop
543 declare
544 S : constant Linker_Option_Entry :=
545 Linker_Option_Lines.Table (J);
546 C : Character;
548 begin
549 if S.Unit = Unit_Num then
550 Write_Info_Initiate ('L');
551 Write_Info_Str (" """);
553 for J in 1 .. String_Length (S.Option) loop
554 C := Get_Character (Get_String_Char (S.Option, J));
556 if C in Character'Val (16#20#) .. Character'Val (16#7E#)
557 and then C /= '{'
558 then
559 Write_Info_Char (C);
561 if C = '"' then
562 Write_Info_Char (C);
563 end if;
565 else
566 declare
567 Hex : constant array (0 .. 15) of Character :=
568 "0123456789ABCDEF";
570 begin
571 Write_Info_Char ('{');
572 Write_Info_Char (Hex (Character'Pos (C) / 16));
573 Write_Info_Char (Hex (Character'Pos (C) mod 16));
574 Write_Info_Char ('}');
575 end;
576 end if;
577 end loop;
579 Write_Info_Char ('"');
580 Write_Info_EOL;
581 end if;
582 end;
583 end loop;
584 end Write_Unit_Information;
586 ----------------------
587 -- Write_With_Lines --
588 ----------------------
590 procedure Write_With_Lines is
591 With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
592 Num_Withs : Int := 0;
593 Unum : Unit_Number_Type;
594 Cunit : Node_Id;
595 Cunite : Entity_Id;
596 Uname : Unit_Name_Type;
597 Fname : File_Name_Type;
598 Pname : constant Unit_Name_Type :=
599 Get_Parent_Spec_Name (Unit_Name (Main_Unit));
600 Body_Fname : File_Name_Type;
601 Body_Index : Nat;
603 begin
604 -- Loop to build the with table. A with on the main unit itself
605 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
606 -- the main unit is a subprogram with no spec, and a subunit of
607 -- it unecessarily withs the parent.
609 for J in Units.First + 1 .. Last_Unit loop
611 -- Add element to with table if it is with'ed or if it is the
612 -- parent spec of the main unit (case of main unit is a child
613 -- unit). The latter with is not needed for semantic purposes,
614 -- but is required by the binder for elaboration purposes.
615 -- For preproc. data and def. files, there is no Unit_Name,
616 -- check for that first.
618 if Unit_Name (J) /= No_Name
619 and then (With_Flags (J) or else Unit_Name (J) = Pname)
620 then
621 Num_Withs := Num_Withs + 1;
622 With_Table (Num_Withs) := J;
623 end if;
624 end loop;
626 -- Sort and output the table
628 Sort (With_Table (1 .. Num_Withs));
630 for J in 1 .. Num_Withs loop
631 Unum := With_Table (J);
632 Cunit := Units.Table (Unum).Cunit;
633 Cunite := Units.Table (Unum).Cunit_Entity;
634 Uname := Units.Table (Unum).Unit_Name;
635 Fname := Units.Table (Unum).Unit_File_Name;
637 Write_Info_Initiate ('W');
638 Write_Info_Char (' ');
639 Write_Info_Name (Uname);
641 -- Now we need to figure out the names of the files that contain
642 -- the with'ed unit. These will usually be the files for the body,
643 -- except in the case of a package that has no body.
645 if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
646 and then
647 Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
648 or else Generic_Separately_Compiled (Cunite)
649 then
650 Write_Info_Tab (25);
652 if Is_Spec_Name (Uname) then
653 Body_Fname :=
654 Get_File_Name
655 (Get_Body_Name (Uname),
656 Subunit => False, May_Fail => True);
658 Body_Index :=
659 Get_Unit_Index
660 (Get_Body_Name (Uname));
662 if Body_Fname = No_File then
663 Body_Fname := Get_File_Name (Uname, Subunit => False);
664 Body_Index := Get_Unit_Index (Uname);
665 end if;
667 else
668 Body_Fname := Get_File_Name (Uname, Subunit => False);
669 Body_Index := Get_Unit_Index (Uname);
670 end if;
672 -- A package is considered to have a body if it requires
673 -- a body or if a body is present in Ada 83 mode.
675 if Body_Required (Cunit)
676 or else (Ada_83
677 and then Full_Source_Name (Body_Fname) /= No_File)
678 then
679 Write_Info_Name (Body_Fname);
680 Write_Info_Tab (49);
681 Write_Info_Name
682 (Lib_File_Name (Body_Fname, Body_Index));
683 else
684 Write_Info_Name (Fname);
685 Write_Info_Tab (49);
686 Write_Info_Name
687 (Lib_File_Name (Fname, Munit_Index (Unum)));
688 end if;
690 if Elab_Flags (Unum) then
691 Write_Info_Str (" E");
692 end if;
694 if Elab_All_Flags (Unum) then
695 Write_Info_Str (" EA");
696 end if;
698 if Elab_Des_Flags (Unum) then
699 Write_Info_Str (" ED");
700 end if;
701 end if;
703 Write_Info_EOL;
704 end loop;
705 end Write_With_Lines;
707 -- Start of processing for Write_ALI
709 begin
710 -- We never write an ALI file if the original operating mode was
711 -- syntax-only (-gnats switch used in compiler invocation line)
713 if Original_Operating_Mode = Check_Syntax then
714 return;
715 end if;
717 -- Build sorted source dependency table. We do this right away,
718 -- because it is referenced by Up_To_Date_ALI_File_Exists.
720 for Unum in Units.First .. Last_Unit loop
721 if Cunit_Entity (Unum) = Empty
722 or else not From_With_Type (Cunit_Entity (Unum))
723 then
724 Num_Sdep := Num_Sdep + 1;
725 Sdep_Table (Num_Sdep) := Unum;
726 end if;
727 end loop;
729 -- Sort the table so that the D lines are in order
731 Lib.Sort (Sdep_Table (1 .. Num_Sdep));
733 -- If we are not generating code, and there is an up to date
734 -- ali file accessible, read it, and acquire the compilation
735 -- arguments from this file.
737 if Operating_Mode /= Generate_Code then
738 if Up_To_Date_ALI_File_Exists then
739 Update_Tables_From_ALI_File;
740 return;
741 end if;
742 end if;
744 -- Otherwise acquire compilation arguments and prepare to write
745 -- out a new ali file.
747 Create_Output_Library_Info;
749 -- Output version line
751 Write_Info_Initiate ('V');
752 Write_Info_Str (" """);
753 Write_Info_Str (Verbose_Library_Version);
754 Write_Info_Char ('"');
756 Write_Info_EOL;
758 -- Output main program line if this is acceptable main program
760 Output_Main_Program_Line : declare
761 U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
762 S : Node_Id;
764 procedure M_Parameters;
765 -- Output parameters for main program line
767 ------------------
768 -- M_Parameters --
769 ------------------
771 procedure M_Parameters is
772 begin
773 if Main_Priority (Main_Unit) /= Default_Main_Priority then
774 Write_Info_Char (' ');
775 Write_Info_Nat (Main_Priority (Main_Unit));
776 end if;
778 if Opt.Time_Slice_Set then
779 Write_Info_Str (" T=");
780 Write_Info_Nat (Opt.Time_Slice_Value);
781 end if;
783 Write_Info_Str (" W=");
784 Write_Info_Char
785 (WC_Encoding_Letters (Wide_Character_Encoding_Method));
787 Write_Info_EOL;
788 end M_Parameters;
790 -- Start of processing for Output_Main_Program_Line
792 begin
793 if Nkind (U) = N_Subprogram_Body
794 or else (Nkind (U) = N_Package_Body
795 and then
796 (Nkind (Original_Node (U)) = N_Function_Instantiation
797 or else
798 Nkind (Original_Node (U)) =
799 N_Procedure_Instantiation))
800 then
801 -- If the unit is a subprogram instance, the entity for the
802 -- subprogram is the alias of the visible entity, which is the
803 -- related instance of the wrapper package. We retrieve the
804 -- subprogram declaration of the desired entity.
806 if Nkind (U) = N_Package_Body then
807 U := Parent (Parent (
808 Alias (Related_Instance (Defining_Unit_Name
809 (Specification (Unit (Library_Unit (Parent (U)))))))));
810 end if;
812 S := Specification (U);
814 if not Present (Parameter_Specifications (S)) then
815 if Nkind (S) = N_Procedure_Specification then
816 Write_Info_Initiate ('M');
817 Write_Info_Str (" P");
818 M_Parameters;
820 else
821 declare
822 Nam : Node_Id := Defining_Unit_Name (S);
824 begin
825 -- If it is a child unit, get its simple name.
827 if Nkind (Nam) = N_Defining_Program_Unit_Name then
828 Nam := Defining_Identifier (Nam);
829 end if;
831 if Is_Integer_Type (Etype (Nam)) then
832 Write_Info_Initiate ('M');
833 Write_Info_Str (" F");
834 M_Parameters;
835 end if;
836 end;
837 end if;
838 end if;
839 end if;
840 end Output_Main_Program_Line;
842 -- Write command argmument ('A') lines
844 for A in 1 .. Compilation_Switches.Last loop
845 Write_Info_Initiate ('A');
846 Write_Info_Char (' ');
847 Write_Info_Str (Compilation_Switches.Table (A).all);
848 Write_Info_Terminate;
849 end loop;
851 -- Output parameters ('P') line
853 Write_Info_Initiate ('P');
855 if Compilation_Errors then
856 Write_Info_Str (" CE");
857 end if;
859 if Opt.Float_Format /= ' ' then
860 Write_Info_Str (" F");
862 if Opt.Float_Format = 'I' then
863 Write_Info_Char ('I');
865 elsif Opt.Float_Format_Long = 'D' then
866 Write_Info_Char ('D');
868 else
869 Write_Info_Char ('G');
870 end if;
871 end if;
873 if Tasking_Used
874 and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
875 then
876 if Locking_Policy /= ' ' then
877 Write_Info_Str (" L");
878 Write_Info_Char (Locking_Policy);
879 end if;
881 if Queuing_Policy /= ' ' then
882 Write_Info_Str (" Q");
883 Write_Info_Char (Queuing_Policy);
884 end if;
886 if Task_Dispatching_Policy /= ' ' then
887 Write_Info_Str (" T");
888 Write_Info_Char (Task_Dispatching_Policy);
889 Write_Info_Char (' ');
890 end if;
891 end if;
893 if not Object then
894 Write_Info_Str (" NO");
895 end if;
897 if No_Run_Time_Mode then
898 Write_Info_Str (" NR");
899 end if;
901 if Normalize_Scalars then
902 Write_Info_Str (" NS");
903 end if;
905 if Sec_Stack_Used then
906 Write_Info_Str (" SS");
907 end if;
909 if Unreserve_All_Interrupts then
910 Write_Info_Str (" UA");
911 end if;
913 if Exception_Mechanism /= Front_End_Setjmp_Longjmp_Exceptions then
914 if Unit_Exception_Table_Present then
915 Write_Info_Str (" UX");
916 end if;
918 Write_Info_Str (" ZX");
919 end if;
921 Write_Info_EOL;
923 -- Before outputting the restrictions line, update the setting of
924 -- the No_Elaboration_Code flag. Violations of this restriction
925 -- cannot be detected until after the backend has been called since
926 -- it is the backend that sets this flag. We have to check all units
927 -- for which we have generated code
929 for Unit in Units.First .. Last_Unit loop
930 if Units.Table (Unit).Generate_Code
931 or else Unit = Main_Unit
932 then
933 if not Has_No_Elaboration_Code (Cunit (Unit)) then
934 Main_Restrictions.Violated (No_Elaboration_Code) := True;
935 end if;
936 end if;
937 end loop;
939 -- Output restrictions line
941 Write_Info_Initiate ('R');
942 Write_Info_Char (' ');
944 -- First the information for the boolean restrictions
946 for R in All_Boolean_Restrictions loop
947 if Main_Restrictions.Set (R) then
948 Write_Info_Char ('r');
949 elsif Main_Restrictions.Violated (R) then
950 Write_Info_Char ('v');
951 else
952 Write_Info_Char ('n');
953 end if;
954 end loop;
956 -- And now the information for the parameter restrictions
958 for RP in All_Parameter_Restrictions loop
959 if Main_Restrictions.Set (RP) then
960 Write_Info_Char ('r');
961 Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
962 else
963 Write_Info_Char ('n');
964 end if;
966 if not Main_Restrictions.Violated (RP)
967 or else RP not in Checked_Parameter_Restrictions
968 then
969 Write_Info_Char ('n');
970 else
971 Write_Info_Char ('v');
972 Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
974 if Main_Restrictions.Unknown (RP) then
975 Write_Info_Char ('+');
976 end if;
977 end if;
978 end loop;
980 Write_Info_EOL;
982 -- Output interrupt state lines
984 for J in Interrupt_States.First .. Interrupt_States.Last loop
985 Write_Info_Initiate ('I');
986 Write_Info_Char (' ');
987 Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
988 Write_Info_Char (' ');
989 Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
990 Write_Info_Char (' ');
991 Write_Info_Nat
992 (Nat (Get_Logical_Line_Number
993 (Interrupt_States.Table (J).Pragma_Loc)));
994 Write_Info_EOL;
995 end loop;
997 -- Loop through file table to output information for all units for which
998 -- we have generated code, as marked by the Generate_Code flag.
1000 for Unit in Units.First .. Last_Unit loop
1001 if Units.Table (Unit).Generate_Code
1002 or else Unit = Main_Unit
1003 then
1004 Write_Info_EOL; -- blank line
1005 Write_Unit_Information (Unit);
1006 end if;
1007 end loop;
1009 Write_Info_EOL; -- blank line
1011 -- Output external version reference lines
1013 for J in 1 .. Version_Ref.Last loop
1014 Write_Info_Initiate ('E');
1015 Write_Info_Char (' ');
1017 for K in 1 .. String_Length (Version_Ref.Table (J)) loop
1018 Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
1019 end loop;
1021 Write_Info_EOL;
1022 end loop;
1024 -- Prepare to output the source dependency lines
1026 declare
1027 Unum : Unit_Number_Type;
1028 -- Number of unit being output
1030 Sind : Source_File_Index;
1031 -- Index of corresponding source file
1033 begin
1034 for J in 1 .. Num_Sdep loop
1035 Unum := Sdep_Table (J);
1036 Units.Table (Unum).Dependency_Num := J;
1037 Sind := Units.Table (Unum).Source_Index;
1039 Write_Info_Initiate ('D');
1040 Write_Info_Char (' ');
1042 -- Normal case of a unit entry with a source index
1044 if Sind /= No_Source_File then
1045 Write_Info_Name (File_Name (Sind));
1046 Write_Info_Tab (25);
1047 Write_Info_Str (String (Time_Stamp (Sind)));
1048 Write_Info_Char (' ');
1049 Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
1051 -- If subunit, add unit name, omitting the %b at the end
1053 if Present (Cunit (Unum))
1054 and then Nkind (Unit (Cunit (Unum))) = N_Subunit
1055 then
1056 Get_Decoded_Name_String (Unit_Name (Unum));
1057 Write_Info_Char (' ');
1058 Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
1059 end if;
1061 -- If Source_Reference pragma used output information
1063 if Num_SRef_Pragmas (Sind) > 0 then
1064 Write_Info_Char (' ');
1066 if Num_SRef_Pragmas (Sind) = 1 then
1067 Write_Info_Nat (Int (First_Mapped_Line (Sind)));
1068 else
1069 Write_Info_Nat (0);
1070 end if;
1072 Write_Info_Char (':');
1073 Write_Info_Name (Reference_Name (Sind));
1074 end if;
1076 -- Case where there is no source index (happens for missing
1077 -- files). In this case we write a dummy time stamp.
1079 else
1080 Write_Info_Name (Unit_File_Name (Unum));
1081 Write_Info_Tab (25);
1082 Write_Info_Str (String (Dummy_Time_Stamp));
1083 Write_Info_Char (' ');
1084 Write_Info_Str (Get_Hex_String (0));
1085 end if;
1087 Write_Info_EOL;
1088 end loop;
1089 end;
1091 Output_References;
1092 Write_Info_Terminate;
1093 Close_Output_Library_Info;
1095 end Write_ALI;
1097 end Lib.Writ;