* pt.c (lookup_template_class_1): Splice out abi_tag attribute if
[official-gcc.git] / gcc / data-streamer-in.c
blobea1628c30dcf962b2fddbbebcb024545d0403fca
1 /* Routines for restoring various data types from a file stream. This deals
2 with various data types like strings, integers, enums, etc.
4 Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 Contributed by Diego Novillo <dnovillo@google.com>
7 This file is part of GCC.
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.
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.
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/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "diagnostic.h"
27 #include "tree.h"
28 #include "basic-block.h"
29 #include "tree-ssa-alias.h"
30 #include "internal-fn.h"
31 #include "gimple-expr.h"
32 #include "is-a.h"
33 #include "gimple.h"
34 #include "data-streamer.h"
36 /* Read a string from the string table in DATA_IN using input block
37 IB. Write the length to RLEN. */
39 static const char *
40 string_for_index (struct data_in *data_in, unsigned int loc, unsigned int *rlen)
42 unsigned int len;
43 const char *result;
45 if (!loc)
47 *rlen = 0;
48 return NULL;
51 /* Get the string stored at location LOC in DATA_IN->STRINGS. */
52 lto_input_block str_tab (data_in->strings, loc - 1, data_in->strings_len);
53 len = streamer_read_uhwi (&str_tab);
54 *rlen = len;
56 if (str_tab.p + len > data_in->strings_len)
57 internal_error ("bytecode stream: string too long for the string table");
59 result = (const char *)(data_in->strings + str_tab.p);
61 return result;
65 /* Read a string from the string table in DATA_IN using input block
66 IB. Write the length to RLEN. */
68 const char *
69 streamer_read_indexed_string (struct data_in *data_in,
70 struct lto_input_block *ib, unsigned int *rlen)
72 return string_for_index (data_in, streamer_read_uhwi (ib), rlen);
76 /* Read a NULL terminated string from the string table in DATA_IN. */
78 const char *
79 streamer_read_string (struct data_in *data_in, struct lto_input_block *ib)
81 unsigned int len;
82 const char *ptr;
84 ptr = streamer_read_indexed_string (data_in, ib, &len);
85 if (!ptr)
86 return NULL;
87 if (ptr[len - 1] != '\0')
88 internal_error ("bytecode stream: found non-null terminated string");
90 return ptr;
94 /* Read a string from the string table in DATA_IN using the bitpack BP.
95 Write the length to RLEN. */
97 const char *
98 bp_unpack_indexed_string (struct data_in *data_in,
99 struct bitpack_d *bp, unsigned int *rlen)
101 return string_for_index (data_in, bp_unpack_var_len_unsigned (bp), rlen);
105 /* Read a NULL terminated string from the string table in DATA_IN. */
107 const char *
108 bp_unpack_string (struct data_in *data_in, struct bitpack_d *bp)
110 unsigned int len;
111 const char *ptr;
113 ptr = bp_unpack_indexed_string (data_in, bp, &len);
114 if (!ptr)
115 return NULL;
116 if (ptr[len - 1] != '\0')
117 internal_error ("bytecode stream: found non-null terminated string");
119 return ptr;
123 /* Read an unsigned HOST_WIDE_INT number from IB. */
125 unsigned HOST_WIDE_INT
126 streamer_read_uhwi (struct lto_input_block *ib)
128 unsigned HOST_WIDE_INT result;
129 int shift;
130 unsigned HOST_WIDE_INT byte;
131 unsigned int p = ib->p;
132 unsigned int len = ib->len;
134 const char *data = ib->data;
135 result = data[p++];
136 if ((result & 0x80) != 0)
138 result &= 0x7f;
139 shift = 7;
142 byte = data[p++];
143 result |= (byte & 0x7f) << shift;
144 shift += 7;
146 while ((byte & 0x80) != 0);
149 /* We check for section overrun after the fact for performance reason. */
150 if (p > len)
151 lto_section_overrun (ib);
153 ib->p = p;
154 return result;
158 /* Read a HOST_WIDE_INT number from IB. */
160 HOST_WIDE_INT
161 streamer_read_hwi (struct lto_input_block *ib)
163 HOST_WIDE_INT result = 0;
164 int shift = 0;
165 unsigned HOST_WIDE_INT byte;
167 while (true)
169 byte = streamer_read_uchar (ib);
170 result |= (byte & 0x7f) << shift;
171 shift += 7;
172 if ((byte & 0x80) == 0)
174 if ((shift < HOST_BITS_PER_WIDE_INT) && (byte & 0x40))
175 result |= - (HOST_WIDE_INT_1U << shift);
177 return result;
182 /* Read gcov_type value from IB. */
184 gcov_type
185 streamer_read_gcov_count (struct lto_input_block *ib)
187 gcov_type ret = streamer_read_hwi (ib);
188 gcc_assert (ret >= 0);
189 return ret;