1 /* Data and functions related to line maps and input files.
2 Copyright (C) 2004, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 /* Current position in real source file. */
29 location_t input_location;
31 struct line_maps *line_table;
34 expand_location (source_location loc)
36 expanded_location xloc;
37 if (loc <= BUILTINS_LOCATION)
39 xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>");
45 xloc = linemap_expand_location_full (line_table, loc,
46 LRK_SPELLING_LOCATION);
51 #define ONE_M (ONE_K * ONE_K)
53 /* Display a number as an integer multiple of either:
54 - 1024, if said integer is >= to 10 K (in base 2)
55 - 1024 * 1024, if said integer is >= 10 M in (base 2)
57 #define SCALE(x) ((unsigned long) ((x) < 10 * ONE_K \
63 /* For a given integer, display either:
64 - the character 'k', if the number is higher than 10 K (in base 2)
65 but strictly lower than 10 M (in base 2)
66 - the character 'M' if the number is higher than 10 M (in base2)
67 - the charcter ' ' if the number is strictly lower than 10 K */
68 #define STAT_LABEL(x) ((x) < 10 * ONE_K ? ' ' : ((x) < 10 * ONE_M ? 'k' : 'M'))
70 /* Display an integer amount as multiple of 1K or 1M (in base 2).
71 Display the correct unit (either k, M, or ' ') after the amout, as
73 #define FORMAT_AMOUNT(size) SCALE (size), STAT_LABEL (size)
75 /* Dump statistics to stderr about the memory usage of the line_table
76 set of line maps. This also displays some statistics about macro
80 dump_line_table_statistics (void)
82 struct linemap_stats s;
83 size_t total_used_map_size,
85 total_allocated_map_size;
87 memset (&s, 0, sizeof (s));
89 linemap_get_statistics (line_table, &s);
91 macro_maps_size = s.macro_maps_used_size
92 + s.macro_maps_locations_size;
94 total_allocated_map_size = s.ordinary_maps_allocated_size
95 + s.macro_maps_allocated_size
96 + s.macro_maps_locations_size;
98 total_used_map_size = s.ordinary_maps_used_size
99 + s.macro_maps_used_size
100 + s.macro_maps_locations_size;
102 fprintf (stderr, "Number of expanded macros: %5lu\n",
103 s.num_expanded_macros);
104 if (s.num_expanded_macros != 0)
105 fprintf (stderr, "Average number of tokens per macro expansion: %5lu\n",
106 s.num_macro_tokens / s.num_expanded_macros);
108 "\nLine Table allocations during the "
109 "compilation process\n");
110 fprintf (stderr, "Number of ordinary maps used: %5lu%c\n",
111 SCALE (s.num_ordinary_maps_used),
112 STAT_LABEL (s.num_ordinary_maps_used));
113 fprintf (stderr, "Ordinary map used size: %5lu%c\n",
114 SCALE (s.ordinary_maps_used_size),
115 STAT_LABEL (s.ordinary_maps_used_size));
116 fprintf (stderr, "Number of ordinary maps allocated: %5lu%c\n",
117 SCALE (s.num_ordinary_maps_allocated),
118 STAT_LABEL (s.num_ordinary_maps_allocated));
119 fprintf (stderr, "Ordinary maps allocated size: %5lu%c\n",
120 SCALE (s.ordinary_maps_allocated_size),
121 STAT_LABEL (s.ordinary_maps_allocated_size));
122 fprintf (stderr, "Number of macro maps used: %5lu%c\n",
123 SCALE (s.num_macro_maps_used),
124 STAT_LABEL (s.num_macro_maps_used));
125 fprintf (stderr, "Macro maps used size: %5lu%c\n",
126 SCALE (s.macro_maps_used_size),
127 STAT_LABEL (s.macro_maps_used_size));
128 fprintf (stderr, "Macro maps locations size: %5lu%c\n",
129 SCALE (s.macro_maps_locations_size),
130 STAT_LABEL (s.macro_maps_locations_size));
131 fprintf (stderr, "Macro maps size: %5lu%c\n",
132 SCALE (macro_maps_size),
133 STAT_LABEL (macro_maps_size));
134 fprintf (stderr, "Duplicated maps locations size: %5lu%c\n",
135 SCALE (s.duplicated_macro_maps_locations_size),
136 STAT_LABEL (s.duplicated_macro_maps_locations_size));
137 fprintf (stderr, "Total allocated maps size: %5lu%c\n",
138 SCALE (total_allocated_map_size),
139 STAT_LABEL (total_allocated_map_size));
140 fprintf (stderr, "Total used maps size: %5lu%c\n",
141 SCALE (total_used_map_size),
142 STAT_LABEL (total_used_map_size));
143 fprintf (stderr, "\n");