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