decl.c (value_annotation_hasher::handle_cache_entry): Delete.
[gcc.git] / gcc / data-streamer-in.c
1 /* Routines for restoring various data types from a file stream. This deals
2 with various data types like strings, integers, enums, etc.
3
4 Copyright (C) 2011-2015 Free Software Foundation, Inc.
5 Contributed by Diego Novillo <dnovillo@google.com>
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "diagnostic.h"
27 #include "alias.h"
28 #include "symtab.h"
29 #include "options.h"
30 #include "tree.h"
31 #include "fold-const.h"
32 #include "predict.h"
33 #include "tm.h"
34 #include "hard-reg-set.h"
35 #include "function.h"
36 #include "basic-block.h"
37 #include "tree-ssa-alias.h"
38 #include "internal-fn.h"
39 #include "gimple-expr.h"
40 #include "gimple.h"
41 #include "plugin-api.h"
42 #include "ipa-ref.h"
43 #include "cgraph.h"
44 #include "data-streamer.h"
45
46 /* Read a string from the string table in DATA_IN using input block
47 IB. Write the length to RLEN. */
48
49 static const char *
50 string_for_index (struct data_in *data_in, unsigned int loc, unsigned int *rlen)
51 {
52 unsigned int len;
53 const char *result;
54
55 if (!loc)
56 {
57 *rlen = 0;
58 return NULL;
59 }
60
61 /* Get the string stored at location LOC in DATA_IN->STRINGS. */
62 lto_input_block str_tab (data_in->strings, loc - 1, data_in->strings_len, NULL);
63 len = streamer_read_uhwi (&str_tab);
64 *rlen = len;
65
66 if (str_tab.p + len > data_in->strings_len)
67 internal_error ("bytecode stream: string too long for the string table");
68
69 result = (const char *)(data_in->strings + str_tab.p);
70
71 return result;
72 }
73
74
75 /* Read a string from the string table in DATA_IN using input block
76 IB. Write the length to RLEN. */
77
78 const char *
79 streamer_read_indexed_string (struct data_in *data_in,
80 struct lto_input_block *ib, unsigned int *rlen)
81 {
82 return string_for_index (data_in, streamer_read_uhwi (ib), rlen);
83 }
84
85
86 /* Read a NULL terminated string from the string table in DATA_IN. */
87
88 const char *
89 streamer_read_string (struct data_in *data_in, struct lto_input_block *ib)
90 {
91 unsigned int len;
92 const char *ptr;
93
94 ptr = streamer_read_indexed_string (data_in, ib, &len);
95 if (!ptr)
96 return NULL;
97 if (ptr[len - 1] != '\0')
98 internal_error ("bytecode stream: found non-null terminated string");
99
100 return ptr;
101 }
102
103
104 /* Read a string from the string table in DATA_IN using the bitpack BP.
105 Write the length to RLEN. */
106
107 const char *
108 bp_unpack_indexed_string (struct data_in *data_in,
109 struct bitpack_d *bp, unsigned int *rlen)
110 {
111 return string_for_index (data_in, bp_unpack_var_len_unsigned (bp), rlen);
112 }
113
114
115 /* Read a NULL terminated string from the string table in DATA_IN. */
116
117 const char *
118 bp_unpack_string (struct data_in *data_in, struct bitpack_d *bp)
119 {
120 unsigned int len;
121 const char *ptr;
122
123 ptr = bp_unpack_indexed_string (data_in, bp, &len);
124 if (!ptr)
125 return NULL;
126 if (ptr[len - 1] != '\0')
127 internal_error ("bytecode stream: found non-null terminated string");
128
129 return ptr;
130 }
131
132
133 /* Read an unsigned HOST_WIDE_INT number from IB. */
134
135 unsigned HOST_WIDE_INT
136 streamer_read_uhwi (struct lto_input_block *ib)
137 {
138 unsigned HOST_WIDE_INT result;
139 int shift;
140 unsigned HOST_WIDE_INT byte;
141 unsigned int p = ib->p;
142 unsigned int len = ib->len;
143
144 const char *data = ib->data;
145 result = data[p++];
146 if ((result & 0x80) != 0)
147 {
148 result &= 0x7f;
149 shift = 7;
150 do
151 {
152 byte = data[p++];
153 result |= (byte & 0x7f) << shift;
154 shift += 7;
155 }
156 while ((byte & 0x80) != 0);
157 }
158
159 /* We check for section overrun after the fact for performance reason. */
160 if (p > len)
161 lto_section_overrun (ib);
162
163 ib->p = p;
164 return result;
165 }
166
167
168 /* Read a HOST_WIDE_INT number from IB. */
169
170 HOST_WIDE_INT
171 streamer_read_hwi (struct lto_input_block *ib)
172 {
173 HOST_WIDE_INT result = 0;
174 int shift = 0;
175 unsigned HOST_WIDE_INT byte;
176
177 while (true)
178 {
179 byte = streamer_read_uchar (ib);
180 result |= (byte & 0x7f) << shift;
181 shift += 7;
182 if ((byte & 0x80) == 0)
183 {
184 if ((shift < HOST_BITS_PER_WIDE_INT) && (byte & 0x40))
185 result |= - (HOST_WIDE_INT_1U << shift);
186
187 return result;
188 }
189 }
190 }
191
192 /* Read gcov_type value from IB. */
193
194 gcov_type
195 streamer_read_gcov_count (struct lto_input_block *ib)
196 {
197 gcov_type ret = streamer_read_hwi (ib);
198 gcc_assert (ret >= 0);
199 return ret;
200 }