annotate gcc/ada/sinput-d.adb @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S I N P U T . D --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2002-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Debug; use Debug;
kono
parents:
diff changeset
27 with Osint; use Osint;
kono
parents:
diff changeset
28 with Osint.C; use Osint.C;
kono
parents:
diff changeset
29 with Output; use Output;
kono
parents:
diff changeset
30 with System.OS_Lib; use System.OS_Lib;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 package body Sinput.D is
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 Dfile : Source_File_Index;
kono
parents:
diff changeset
35 -- Index of currently active debug source file
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 ------------------------
kono
parents:
diff changeset
38 -- Close_Debug_Source --
kono
parents:
diff changeset
39 ------------------------
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 procedure Close_Debug_Source is
kono
parents:
diff changeset
42 FD : File_Descriptor;
kono
parents:
diff changeset
43 SFR : Source_File_Record renames Source_File.Table (Dfile);
kono
parents:
diff changeset
44 Src : Source_Buffer_Ptr;
kono
parents:
diff changeset
45 begin
kono
parents:
diff changeset
46 Trim_Lines_Table (Dfile);
kono
parents:
diff changeset
47 Close_Debug_File;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 -- Now we need to read the file that we wrote and store it in memory for
kono
parents:
diff changeset
50 -- subsequent access.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Read_Source_File
kono
parents:
diff changeset
53 (SFR.Full_Debug_Name, SFR.Source_First, SFR.Source_Last, Src, FD);
kono
parents:
diff changeset
54 SFR.Source_Text := Src;
kono
parents:
diff changeset
55 pragma Assert (SFR.Source_Text'First = SFR.Source_First);
kono
parents:
diff changeset
56 pragma Assert (SFR.Source_Text'Last = SFR.Source_Last);
kono
parents:
diff changeset
57 end Close_Debug_Source;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -------------------------
kono
parents:
diff changeset
60 -- Create_Debug_Source --
kono
parents:
diff changeset
61 -------------------------
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 procedure Create_Debug_Source
kono
parents:
diff changeset
64 (Source : Source_File_Index;
kono
parents:
diff changeset
65 Loc : out Source_Ptr)
kono
parents:
diff changeset
66 is
kono
parents:
diff changeset
67 begin
kono
parents:
diff changeset
68 Loc :=
kono
parents:
diff changeset
69 ((Source_File.Table (Source_File.Last).Source_Last + Source_Align) /
kono
parents:
diff changeset
70 Source_Align) * Source_Align;
kono
parents:
diff changeset
71 Source_File.Append (Source_File.Table (Source));
kono
parents:
diff changeset
72 Dfile := Source_File.Last;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 declare
kono
parents:
diff changeset
75 S : Source_File_Record renames Source_File.Table (Dfile);
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 begin
kono
parents:
diff changeset
78 S.Index := Dfile;
kono
parents:
diff changeset
79 S.Full_Debug_Name := Create_Debug_File (S.File_Name);
kono
parents:
diff changeset
80 S.Debug_Source_Name := Strip_Directory (S.Full_Debug_Name);
kono
parents:
diff changeset
81 S.Source_Text := null;
kono
parents:
diff changeset
82 S.Source_First := Loc;
kono
parents:
diff changeset
83 S.Source_Last := Loc;
kono
parents:
diff changeset
84 S.Lines_Table := null;
kono
parents:
diff changeset
85 S.Last_Source_Line := 1;
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 -- Allocate lines table, guess that it needs to be three times bigger
kono
parents:
diff changeset
88 -- than the original source (in number of lines).
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 Alloc_Line_Tables
kono
parents:
diff changeset
91 (S, Int (Source_File.Table (Source).Last_Source_Line * 3));
kono
parents:
diff changeset
92 S.Lines_Table (1) := Loc;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 if Debug_Flag_L then
kono
parents:
diff changeset
95 Write_Str ("Sinput.D.Create_Debug_Source: created source ");
kono
parents:
diff changeset
96 Write_Int (Int (Dfile));
kono
parents:
diff changeset
97 Write_Str (" for ");
kono
parents:
diff changeset
98 Write_Str (Get_Name_String (S.Full_Debug_Name));
kono
parents:
diff changeset
99 Write_Line ("");
kono
parents:
diff changeset
100 end if;
kono
parents:
diff changeset
101 end;
kono
parents:
diff changeset
102 end Create_Debug_Source;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 ----------------------
kono
parents:
diff changeset
105 -- Write_Debug_Line --
kono
parents:
diff changeset
106 ----------------------
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 procedure Write_Debug_Line (Str : String; Loc : in out Source_Ptr) is
kono
parents:
diff changeset
109 S : Source_File_Record renames Source_File.Table (Dfile);
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 begin
kono
parents:
diff changeset
112 -- Ignore write request if null line at start of file
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 if Str'Length = 0 and then Loc = S.Source_First then
kono
parents:
diff changeset
115 return;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 -- Here we write the line, compute the source location for the following
kono
parents:
diff changeset
118 -- line, allocate its table entry, and update the source record entry.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 else
kono
parents:
diff changeset
121 Write_Debug_Info (Str (Str'First .. Str'Last - 1));
kono
parents:
diff changeset
122 Loc := Loc - 1 + Source_Ptr (Str'Length + Debug_File_Eol_Length);
kono
parents:
diff changeset
123 Add_Line_Tables_Entry (S, Loc);
kono
parents:
diff changeset
124 S.Source_Last := Loc;
kono
parents:
diff changeset
125 Set_Source_File_Index_Table (Dfile);
kono
parents:
diff changeset
126 end if;
kono
parents:
diff changeset
127 end Write_Debug_Line;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 end Sinput.D;