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