with ALI; use ALI;
with Atree; use Atree;
with Casing; use Casing;
with Einfo; use Einfo;
with Errout; use Errout;
with Fname; use Fname;
with Fname.UF; use Fname.UF;
with Lib.Util; use Lib.Util;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Nlists; use Nlists;
with Gnatvsn; use Gnatvsn;
with Opt; use Opt;
with Osint; use Osint;
with Osint.C; use Osint.C;
with Par;
with Restrict; use Restrict;
with Rident; use Rident;
with Scn; use Scn;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Stringt; use Stringt;
with Tbuild; use Tbuild;
with Uname; use Uname;
with System.WCh_Con; use System.WCh_Con;
package body Lib.Writ is
procedure Write_Unit_Name (N : Node_Id);
procedure Add_Preprocessing_Dependency (S : Source_File_Index) is
begin
Units.Increment_Last;
Units.Table (Units.Last) :=
(Unit_File_Name => File_Name (S),
Unit_Name => No_Name,
Expected_Unit => No_Name,
Source_Index => S,
Cunit => Empty,
Cunit_Entity => Empty,
Dependency_Num => 0,
Dynamic_Elab => False,
Fatal_Error => False,
Generate_Code => False,
Has_RACW => False,
Ident_String => Empty,
Loading => False,
Main_Priority => -1,
Munit_Index => 0,
Serial_Number => 0,
Version => 0,
Error_Location => No_Location);
end Add_Preprocessing_Dependency;
procedure Ensure_System_Dependency is
System_Uname : Unit_Name_Type;
System_Fname : File_Name_Type;
begin
for Unum in Units.First .. Last_Unit loop
if Units.Table (Unum).Source_Index = System_Source_File_Index then
return;
end if;
end loop;
Name_Len := 6;
Name_Buffer (1 .. 6) := "system";
System_Uname := Name_To_Unit_Name (Name_Enter);
System_Fname := File_Name (System_Source_File_Index);
Units.Increment_Last;
Units.Table (Units.Last) := (
Unit_File_Name => System_Fname,
Unit_Name => System_Uname,
Expected_Unit => System_Uname,
Source_Index => System_Source_File_Index,
Cunit => Empty,
Cunit_Entity => Empty,
Dependency_Num => 0,
Dynamic_Elab => False,
Fatal_Error => False,
Generate_Code => False,
Has_RACW => False,
Ident_String => Empty,
Loading => False,
Main_Priority => -1,
Munit_Index => 0,
Serial_Number => 0,
Version => 0,
Error_Location => No_Location);
declare
Save_Mindex : constant Nat := Multiple_Unit_Index;
Save_Style : constant Boolean := Style_Check;
begin
Multiple_Unit_Index := 0;
Style_Check := False;
Initialize_Scanner (Units.Last, System_Source_File_Index);
Discard_List (Par (Configuration_Pragmas => False));
Style_Check := Save_Style;
Multiple_Unit_Index := Save_Mindex;
end;
end Ensure_System_Dependency;
procedure Write_ALI (Object : Boolean) is
Last_Unit : constant Unit_Number_Type := Units.Last;
With_Flags : array (Units.First .. Last_Unit) of Boolean;
Elab_Flags : array (Units.First .. Last_Unit) of Boolean;
Elab_All_Flags : array (Units.First .. Last_Unit) of Boolean;
Elab_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
Num_Sdep : Nat := 0;
procedure Collect_Withs (Cunit : Node_Id);
procedure Update_Tables_From_ALI_File;
function Up_To_Date_ALI_File_Exists return Boolean;
procedure Write_Unit_Information (Unit_Num : Unit_Number_Type);
procedure Write_With_Lines;
procedure Collect_Withs (Cunit : Node_Id) is
Item : Node_Id;
Unum : Unit_Number_Type;
begin
Item := First (Context_Items (Cunit));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not (Limited_Present (Item))
then
Unum := Get_Cunit_Unit_Number (Library_Unit (Item));
With_Flags (Unum) := True;
if Elaborate_Present (Item) then
Elab_Flags (Unum) := True;
end if;
if Elaborate_All_Present (Item) then
Elab_All_Flags (Unum) := True;
end if;
if Elaborate_All_Desirable (Cunit_Entity (Unum)) then
Elab_Des_Flags (Unum) := True;
end if;
end if;
Next (Item);
end loop;
end Collect_Withs;
function Up_To_Date_ALI_File_Exists return Boolean is
Name : File_Name_Type;
Text : Text_Buffer_Ptr;
Id : Sdep_Id;
Sind : Source_File_Index;
begin
Opt.Check_Object_Consistency := True;
Read_Library_Info (Name, Text);
if Text = null then
return False;
end if;
Initialize_ALI;
if Scan_ALI (Name, Text, False, Err => True) = No_ALI_Id then
return False;
end if;
Id := First_Sdep_Entry;
for J in 1 .. Num_Sdep loop
Sind := Units.Table (Sdep_Table (J)).Source_Index;
while Sdep.Table (Id).Sfile /= File_Name (Sind) loop
if Id = Sdep.Last then
return False;
else
Id := Id + 1;
end if;
end loop;
if Sdep.Table (Id).Stamp /= Time_Stamp (Sind) then
return False;
end if;
end loop;
return True;
end Up_To_Date_ALI_File_Exists;
procedure Update_Tables_From_ALI_File is
begin
Compilation_Switches.Init;
for J in First_Arg_Entry .. Args.Last loop
Compilation_Switches.Increment_Last;
Compilation_Switches.Table (Compilation_Switches.Last) :=
Args.Table (J);
end loop;
end Update_Tables_From_ALI_File;
procedure Write_Unit_Information (Unit_Num : Unit_Number_Type) is
Unode : constant Node_Id := Cunit (Unit_Num);
Ukind : constant Node_Kind := Nkind (Unit (Unode));
Uent : constant Entity_Id := Cunit_Entity (Unit_Num);
Pnode : Node_Id;
begin
Write_Info_Initiate ('U');
Write_Info_Char (' ');
Write_Info_Name (Unit_Name (Unit_Num));
Write_Info_Tab (25);
Write_Info_Name (Unit_File_Name (Unit_Num));
Write_Info_Tab (49);
Write_Info_Str (Version_Get (Unit_Num));
if (Is_Subprogram (Uent)
or else Ekind (Uent) = E_Package
or else Is_Generic_Unit (Uent))
and then Body_Needed_For_SAL (Uent)
then
Write_Info_Str (" BN");
end if;
if Dynamic_Elab (Unit_Num) then
Write_Info_Str (" DE");
end if;
if Has_Pragma_Elaborate_Body (Uent)
or else (Ukind = N_Package_Declaration
and then Is_Generic_Instance (Uent)
and then Present (Corresponding_Body (Unit (Unode))))
then
Write_Info_Str (" EB");
end if;
if (Is_Subprogram (Uent)
or else
Ekind (Uent) = E_Package
or else
Is_Generic_Unit (Uent))
and then Present (Elaboration_Entity (Uent))
and then
(Elaboration_Entity_Required (Uent)
or else not Has_No_Elaboration_Code (Unode)
or else
(Ekind (Uent) = E_Package
and then Present (Body_Entity (Uent))
and then
not Has_No_Elaboration_Code
(Parent
(Declaration_Node
(Body_Entity (Uent))))))
then
Write_Info_Str (" EE");
end if;
if Has_No_Elaboration_Code (Unode) then
Write_Info_Str (" NE");
end if;
if Is_Preelaborated (Uent) then
Write_Info_Str (" PR");
end if;
if Is_Pure (Uent) then
Write_Info_Str (" PU");
end if;
if Has_RACW (Unit_Num) then
Write_Info_Str (" RA");
end if;
if Is_Remote_Call_Interface (Uent) then
Write_Info_Str (" RC");
end if;
if Is_Remote_Types (Uent) then
Write_Info_Str (" RT");
end if;
if Is_Shared_Passive (Uent) then
Write_Info_Str (" SP");
end if;
if Ukind = N_Subprogram_Declaration
or else Ukind = N_Subprogram_Body
then
Write_Info_Str (" SU");
elsif Ukind = N_Package_Declaration
or else
Ukind = N_Package_Body
then
if Is_Wrapper_Package (Uent) then
Write_Info_Str (" SU");
else
Write_Info_Str (" PK");
end if;
elsif Ukind = N_Generic_Package_Declaration then
Write_Info_Str (" PK");
end if;
if Ukind in N_Generic_Declaration
or else
(Present (Library_Unit (Unode))
and then
Nkind (Unit (Library_Unit (Unode))) in N_Generic_Declaration)
then
Write_Info_Str (" GE");
end if;
if not Is_Internal_File_Name (Unit_File_Name (Unit_Num), True) then
case Identifier_Casing (Source_Index (Unit_Num)) is
when All_Lower_Case => Write_Info_Str (" IL");
when All_Upper_Case => Write_Info_Str (" IU");
when others => null;
end case;
case Keyword_Casing (Source_Index (Unit_Num)) is
when Mixed_Case => Write_Info_Str (" KM");
when All_Upper_Case => Write_Info_Str (" KU");
when others => null;
end case;
end if;
if Initialize_Scalars then
Write_Info_Str (" IS");
end if;
Write_Info_EOL;
for J in With_Flags'Range loop
With_Flags (J) := False;
Elab_Flags (J) := False;
Elab_All_Flags (J) := False;
Elab_Des_Flags (J) := False;
end loop;
Collect_Withs (Unode);
if Nkind (Unit (Unode)) in N_Unit_Body then
for S in Units.First .. Last_Unit loop
if Cunit (S) /= Empty
and then Nkind (Unit (Cunit (S))) = N_Subunit
then
Pnode := Library_Unit (Cunit (S));
if No (Pnode) then
exit;
end if;
while Nkind (Unit (Pnode)) = N_Subunit loop
Pnode := Library_Unit (Pnode);
end loop;
if Pnode = Unode then
Collect_Withs (Cunit (S));
end if;
end if;
end loop;
end if;
Write_With_Lines;
for J in 1 .. Linker_Option_Lines.Last loop
declare
S : constant Linker_Option_Entry :=
Linker_Option_Lines.Table (J);
C : Character;
begin
if S.Unit = Unit_Num then
Write_Info_Initiate ('L');
Write_Info_Str (" """);
for J in 1 .. String_Length (S.Option) loop
C := Get_Character (Get_String_Char (S.Option, J));
if C in Character'Val (16#20#) .. Character'Val (16#7E#)
and then C /= '{'
then
Write_Info_Char (C);
if C = '"' then
Write_Info_Char (C);
end if;
else
declare
Hex : constant array (0 .. 15) of Character :=
"0123456789ABCDEF";
begin
Write_Info_Char ('{');
Write_Info_Char (Hex (Character'Pos (C) / 16));
Write_Info_Char (Hex (Character'Pos (C) mod 16));
Write_Info_Char ('}');
end;
end if;
end loop;
Write_Info_Char ('"');
Write_Info_EOL;
end if;
end;
end loop;
end Write_Unit_Information;
procedure Write_With_Lines is
With_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 1));
Num_Withs : Int := 0;
Unum : Unit_Number_Type;
Cunit : Node_Id;
Cunite : Entity_Id;
Uname : Unit_Name_Type;
Fname : File_Name_Type;
Pname : constant Unit_Name_Type :=
Get_Parent_Spec_Name (Unit_Name (Main_Unit));
Body_Fname : File_Name_Type;
Body_Index : Nat;
begin
for J in Units.First + 1 .. Last_Unit loop
if Unit_Name (J) /= No_Name
and then (With_Flags (J) or else Unit_Name (J) = Pname)
then
Num_Withs := Num_Withs + 1;
With_Table (Num_Withs) := J;
end if;
end loop;
Sort (With_Table (1 .. Num_Withs));
for J in 1 .. Num_Withs loop
Unum := With_Table (J);
Cunit := Units.Table (Unum).Cunit;
Cunite := Units.Table (Unum).Cunit_Entity;
Uname := Units.Table (Unum).Unit_Name;
Fname := Units.Table (Unum).Unit_File_Name;
Write_Info_Initiate ('W');
Write_Info_Char (' ');
Write_Info_Name (Uname);
if (Nkind (Unit (Cunit)) not in N_Generic_Declaration
and then
Nkind (Unit (Cunit)) not in N_Generic_Renaming_Declaration)
or else Generic_Separately_Compiled (Cunite)
then
Write_Info_Tab (25);
if Is_Spec_Name (Uname) then
Body_Fname :=
Get_File_Name
(Get_Body_Name (Uname),
Subunit => False, May_Fail => True);
Body_Index :=
Get_Unit_Index
(Get_Body_Name (Uname));
if Body_Fname = No_File then
Body_Fname := Get_File_Name (Uname, Subunit => False);
Body_Index := Get_Unit_Index (Uname);
end if;
else
Body_Fname := Get_File_Name (Uname, Subunit => False);
Body_Index := Get_Unit_Index (Uname);
end if;
if Body_Required (Cunit)
or else (Ada_Version = Ada_83
and then Full_Source_Name (Body_Fname) /= No_File)
then
Write_Info_Name (Body_Fname);
Write_Info_Tab (49);
Write_Info_Name
(Lib_File_Name (Body_Fname, Body_Index));
else
Write_Info_Name (Fname);
Write_Info_Tab (49);
Write_Info_Name
(Lib_File_Name (Fname, Munit_Index (Unum)));
end if;
if Elab_Flags (Unum) then
Write_Info_Str (" E");
end if;
if Elab_All_Flags (Unum) then
Write_Info_Str (" EA");
end if;
if Elab_Des_Flags (Unum) then
Write_Info_Str (" ED");
end if;
end if;
Write_Info_EOL;
end loop;
end Write_With_Lines;
begin
if Original_Operating_Mode = Check_Syntax then
return;
end if;
for Unum in Units.First .. Last_Unit loop
if Cunit_Entity (Unum) = Empty
or else not From_With_Type (Cunit_Entity (Unum))
then
Num_Sdep := Num_Sdep + 1;
Sdep_Table (Num_Sdep) := Unum;
end if;
end loop;
Lib.Sort (Sdep_Table (1 .. Num_Sdep));
if Operating_Mode /= Generate_Code then
if Up_To_Date_ALI_File_Exists then
Update_Tables_From_ALI_File;
return;
end if;
end if;
Create_Output_Library_Info;
Write_Info_Initiate ('V');
Write_Info_Str (" """);
Write_Info_Str (Verbose_Library_Version);
Write_Info_Char ('"');
Write_Info_EOL;
Output_Main_Program_Line : declare
U : Node_Id := Unit (Units.Table (Main_Unit).Cunit);
S : Node_Id;
procedure M_Parameters;
procedure M_Parameters is
begin
if Main_Priority (Main_Unit) /= Default_Main_Priority then
Write_Info_Char (' ');
Write_Info_Nat (Main_Priority (Main_Unit));
end if;
if Opt.Time_Slice_Set then
Write_Info_Str (" T=");
Write_Info_Nat (Opt.Time_Slice_Value);
end if;
Write_Info_Str (" W=");
Write_Info_Char
(WC_Encoding_Letters (Wide_Character_Encoding_Method));
Write_Info_EOL;
end M_Parameters;
begin
if Nkind (U) = N_Subprogram_Body
or else (Nkind (U) = N_Package_Body
and then
(Nkind (Original_Node (U)) = N_Function_Instantiation
or else
Nkind (Original_Node (U)) =
N_Procedure_Instantiation))
then
if Nkind (U) = N_Package_Body then
U := Parent (Parent (
Alias (Related_Instance (Defining_Unit_Name
(Specification (Unit (Library_Unit (Parent (U)))))))));
end if;
S := Specification (U);
if not Present (Parameter_Specifications (S)) then
if Nkind (S) = N_Procedure_Specification then
Write_Info_Initiate ('M');
Write_Info_Str (" P");
M_Parameters;
else
declare
Nam : Node_Id := Defining_Unit_Name (S);
begin
if Nkind (Nam) = N_Defining_Program_Unit_Name then
Nam := Defining_Identifier (Nam);
end if;
if Is_Integer_Type (Etype (Nam)) then
Write_Info_Initiate ('M');
Write_Info_Str (" F");
M_Parameters;
end if;
end;
end if;
end if;
end if;
end Output_Main_Program_Line;
for A in 1 .. Compilation_Switches.Last loop
Write_Info_Initiate ('A');
Write_Info_Char (' ');
Write_Info_Str (Compilation_Switches.Table (A).all);
Write_Info_Terminate;
end loop;
Write_Info_Initiate ('P');
if Compilation_Errors then
Write_Info_Str (" CE");
end if;
if Opt.Detect_Blocking then
Write_Info_Str (" DB");
end if;
if Opt.Float_Format /= ' ' then
Write_Info_Str (" F");
if Opt.Float_Format = 'I' then
Write_Info_Char ('I');
elsif Opt.Float_Format_Long = 'D' then
Write_Info_Char ('D');
else
Write_Info_Char ('G');
end if;
end if;
if Tasking_Used
and then not Is_Predefined_File_Name (Unit_File_Name (Main_Unit))
then
if Locking_Policy /= ' ' then
Write_Info_Str (" L");
Write_Info_Char (Locking_Policy);
end if;
if Queuing_Policy /= ' ' then
Write_Info_Str (" Q");
Write_Info_Char (Queuing_Policy);
end if;
if Task_Dispatching_Policy /= ' ' then
Write_Info_Str (" T");
Write_Info_Char (Task_Dispatching_Policy);
Write_Info_Char (' ');
end if;
end if;
if not Object then
Write_Info_Str (" NO");
end if;
if No_Run_Time_Mode then
Write_Info_Str (" NR");
end if;
if Normalize_Scalars then
Write_Info_Str (" NS");
end if;
if Sec_Stack_Used then
Write_Info_Str (" SS");
end if;
if Unreserve_All_Interrupts then
Write_Info_Str (" UA");
end if;
if Exception_Mechanism /= Front_End_Setjmp_Longjmp_Exceptions then
if Unit_Exception_Table_Present then
Write_Info_Str (" UX");
end if;
Write_Info_Str (" ZX");
end if;
Write_Info_EOL;
for Unit in Units.First .. Last_Unit loop
if Units.Table (Unit).Generate_Code
or else Unit = Main_Unit
then
if not Has_No_Elaboration_Code (Cunit (Unit)) then
Main_Restrictions.Violated (No_Elaboration_Code) := True;
end if;
end if;
end loop;
Write_Info_Initiate ('R');
Write_Info_Char (' ');
for R in All_Boolean_Restrictions loop
if Main_Restrictions.Set (R)
and then not Restriction_Warnings (R)
then
Write_Info_Char ('r');
elsif Main_Restrictions.Violated (R) then
Write_Info_Char ('v');
else
Write_Info_Char ('n');
end if;
end loop;
for RP in All_Parameter_Restrictions loop
if Main_Restrictions.Set (RP)
and then not Restriction_Warnings (RP)
then
Write_Info_Char ('r');
Write_Info_Nat (Nat (Main_Restrictions.Value (RP)));
else
Write_Info_Char ('n');
end if;
if not Main_Restrictions.Violated (RP)
or else RP not in Checked_Parameter_Restrictions
then
Write_Info_Char ('n');
else
Write_Info_Char ('v');
Write_Info_Nat (Nat (Main_Restrictions.Count (RP)));
if Main_Restrictions.Unknown (RP) then
Write_Info_Char ('+');
end if;
end if;
end loop;
Write_Info_EOL;
for J in No_Dependence.First .. No_Dependence.Last loop
if In_Extended_Main_Source_Unit (No_Dependence.Table (J).Unit)
and then not No_Dependence.Table (J).Warn
then
Write_Info_Initiate ('R');
Write_Info_Char (' ');
Write_Unit_Name (No_Dependence.Table (J).Unit);
Write_Info_EOL;
end if;
end loop;
for J in Interrupt_States.First .. Interrupt_States.Last loop
Write_Info_Initiate ('I');
Write_Info_Char (' ');
Write_Info_Nat (Interrupt_States.Table (J).Interrupt_Number);
Write_Info_Char (' ');
Write_Info_Char (Interrupt_States.Table (J).Interrupt_State);
Write_Info_Char (' ');
Write_Info_Nat
(Nat (Get_Logical_Line_Number
(Interrupt_States.Table (J).Pragma_Loc)));
Write_Info_EOL;
end loop;
for Unit in Units.First .. Last_Unit loop
if Units.Table (Unit).Generate_Code
or else Unit = Main_Unit
then
Write_Info_EOL; Write_Unit_Information (Unit);
end if;
end loop;
Write_Info_EOL;
for J in 1 .. Version_Ref.Last loop
Write_Info_Initiate ('E');
Write_Info_Char (' ');
for K in 1 .. String_Length (Version_Ref.Table (J)) loop
Write_Info_Char_Code (Get_String_Char (Version_Ref.Table (J), K));
end loop;
Write_Info_EOL;
end loop;
declare
Unum : Unit_Number_Type;
Sind : Source_File_Index;
begin
for J in 1 .. Num_Sdep loop
Unum := Sdep_Table (J);
Units.Table (Unum).Dependency_Num := J;
Sind := Units.Table (Unum).Source_Index;
Write_Info_Initiate ('D');
Write_Info_Char (' ');
if Sind /= No_Source_File then
Write_Info_Name (File_Name (Sind));
Write_Info_Tab (25);
Write_Info_Str (String (Time_Stamp (Sind)));
Write_Info_Char (' ');
Write_Info_Str (Get_Hex_String (Source_Checksum (Sind)));
if Present (Cunit (Unum))
and then Nkind (Unit (Cunit (Unum))) = N_Subunit
then
Get_Decoded_Name_String (Unit_Name (Unum));
Write_Info_Char (' ');
Write_Info_Str (Name_Buffer (1 .. Name_Len - 2));
end if;
if Num_SRef_Pragmas (Sind) > 0 then
Write_Info_Char (' ');
if Num_SRef_Pragmas (Sind) = 1 then
Write_Info_Nat (Int (First_Mapped_Line (Sind)));
else
Write_Info_Nat (0);
end if;
Write_Info_Char (':');
Write_Info_Name (Reference_Name (Sind));
end if;
else
Write_Info_Name (Unit_File_Name (Unum));
Write_Info_Tab (25);
Write_Info_Str (String (Dummy_Time_Stamp));
Write_Info_Char (' ');
Write_Info_Str (Get_Hex_String (0));
end if;
Write_Info_EOL;
end loop;
end;
Output_References;
Write_Info_Terminate;
Close_Output_Library_Info;
end Write_ALI;
procedure Write_Unit_Name (N : Node_Id) is
begin
if Nkind (N) = N_Identifier then
Write_Info_Name (Chars (N));
else
pragma Assert (Nkind (N) = N_Selected_Component);
Write_Unit_Name (Prefix (N));
Write_Info_Char ('.');
Write_Unit_Name (Selector_Name (N));
end if;
end Write_Unit_Name;
end Lib.Writ;