]>
Commit | Line | Data |
---|---|---|
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 | ||
3aea1f79 | 4 | Copyright (C) 2011-2014 Free Software Foundation, Inc. |
2541503d | 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" | |
41a8aa41 | 27 | #include "tree.h" |
94ea8568 | 28 | #include "predict.h" |
29 | #include "vec.h" | |
30 | #include "hashtab.h" | |
31 | #include "hash-set.h" | |
32 | #include "machmode.h" | |
33 | #include "tm.h" | |
34 | #include "hard-reg-set.h" | |
35 | #include "input.h" | |
36 | #include "function.h" | |
bc61cadb | 37 | #include "basic-block.h" |
38 | #include "tree-ssa-alias.h" | |
39 | #include "internal-fn.h" | |
40 | #include "gimple-expr.h" | |
41 | #include "is-a.h" | |
b23fb4cb | 42 | #include "gimple.h" |
2541503d | 43 | #include "data-streamer.h" |
44 | ||
45 | /* Read a string from the string table in DATA_IN using input block | |
46 | IB. Write the length to RLEN. */ | |
47 | ||
b5054e4c | 48 | static const char * |
2541503d | 49 | string_for_index (struct data_in *data_in, unsigned int loc, unsigned int *rlen) |
50 | { | |
2541503d | 51 | unsigned int len; |
52 | const char *result; | |
53 | ||
54 | if (!loc) | |
55 | { | |
56 | *rlen = 0; | |
57 | return NULL; | |
58 | } | |
59 | ||
60 | /* Get the string stored at location LOC in DATA_IN->STRINGS. */ | |
472ca566 | 61 | lto_input_block str_tab (data_in->strings, loc - 1, data_in->strings_len); |
7f385784 | 62 | len = streamer_read_uhwi (&str_tab); |
2541503d | 63 | *rlen = len; |
64 | ||
65 | if (str_tab.p + len > data_in->strings_len) | |
66 | internal_error ("bytecode stream: string too long for the string table"); | |
67 | ||
68 | result = (const char *)(data_in->strings + str_tab.p); | |
69 | ||
70 | return result; | |
71 | } | |
72 | ||
73 | ||
74 | /* Read a string from the string table in DATA_IN using input block | |
75 | IB. Write the length to RLEN. */ | |
76 | ||
77 | const char * | |
7f385784 | 78 | streamer_read_indexed_string (struct data_in *data_in, |
79 | struct lto_input_block *ib, unsigned int *rlen) | |
2541503d | 80 | { |
7f385784 | 81 | return string_for_index (data_in, streamer_read_uhwi (ib), rlen); |
2541503d | 82 | } |
83 | ||
84 | ||
85 | /* Read a NULL terminated string from the string table in DATA_IN. */ | |
86 | ||
87 | const char * | |
7f385784 | 88 | streamer_read_string (struct data_in *data_in, struct lto_input_block *ib) |
2541503d | 89 | { |
90 | unsigned int len; | |
91 | const char *ptr; | |
92 | ||
7f385784 | 93 | ptr = streamer_read_indexed_string (data_in, ib, &len); |
2541503d | 94 | if (!ptr) |
95 | return NULL; | |
96 | if (ptr[len - 1] != '\0') | |
97 | internal_error ("bytecode stream: found non-null terminated string"); | |
98 | ||
99 | return ptr; | |
100 | } | |
101 | ||
102 | ||
07de37ab | 103 | /* Read a string from the string table in DATA_IN using the bitpack BP. |
104 | Write the length to RLEN. */ | |
105 | ||
106 | const char * | |
107 | bp_unpack_indexed_string (struct data_in *data_in, | |
108 | struct bitpack_d *bp, unsigned int *rlen) | |
109 | { | |
110 | return string_for_index (data_in, bp_unpack_var_len_unsigned (bp), rlen); | |
111 | } | |
112 | ||
113 | ||
114 | /* Read a NULL terminated string from the string table in DATA_IN. */ | |
115 | ||
116 | const char * | |
117 | bp_unpack_string (struct data_in *data_in, struct bitpack_d *bp) | |
118 | { | |
119 | unsigned int len; | |
120 | const char *ptr; | |
121 | ||
122 | ptr = bp_unpack_indexed_string (data_in, bp, &len); | |
123 | if (!ptr) | |
124 | return NULL; | |
125 | if (ptr[len - 1] != '\0') | |
126 | internal_error ("bytecode stream: found non-null terminated string"); | |
127 | ||
128 | return ptr; | |
129 | } | |
130 | ||
131 | ||
7f385784 | 132 | /* Read an unsigned HOST_WIDE_INT number from IB. */ |
2541503d | 133 | |
134 | unsigned HOST_WIDE_INT | |
7f385784 | 135 | streamer_read_uhwi (struct lto_input_block *ib) |
2541503d | 136 | { |
ab4542eb | 137 | unsigned HOST_WIDE_INT result; |
138 | int shift; | |
2541503d | 139 | unsigned HOST_WIDE_INT byte; |
ab4542eb | 140 | unsigned int p = ib->p; |
141 | unsigned int len = ib->len; | |
2541503d | 142 | |
ab4542eb | 143 | const char *data = ib->data; |
144 | result = data[p++]; | |
145 | if ((result & 0x80) != 0) | |
2541503d | 146 | { |
ab4542eb | 147 | result &= 0x7f; |
148 | shift = 7; | |
149 | do | |
150 | { | |
151 | byte = data[p++]; | |
152 | result |= (byte & 0x7f) << shift; | |
153 | shift += 7; | |
154 | } | |
155 | while ((byte & 0x80) != 0); | |
2541503d | 156 | } |
ab4542eb | 157 | |
158 | /* We check for section overrun after the fact for performance reason. */ | |
159 | if (p > len) | |
160 | lto_section_overrun (ib); | |
161 | ||
162 | ib->p = p; | |
163 | return result; | |
2541503d | 164 | } |
165 | ||
166 | ||
7f385784 | 167 | /* Read a HOST_WIDE_INT number from IB. */ |
2541503d | 168 | |
169 | HOST_WIDE_INT | |
7f385784 | 170 | streamer_read_hwi (struct lto_input_block *ib) |
2541503d | 171 | { |
172 | HOST_WIDE_INT result = 0; | |
173 | int shift = 0; | |
174 | unsigned HOST_WIDE_INT byte; | |
175 | ||
176 | while (true) | |
177 | { | |
7f385784 | 178 | byte = streamer_read_uchar (ib); |
2541503d | 179 | result |= (byte & 0x7f) << shift; |
180 | shift += 7; | |
181 | if ((byte & 0x80) == 0) | |
182 | { | |
183 | if ((shift < HOST_BITS_PER_WIDE_INT) && (byte & 0x40)) | |
d69521d8 | 184 | result |= - (HOST_WIDE_INT_1U << shift); |
2541503d | 185 | |
186 | return result; | |
187 | } | |
188 | } | |
189 | } | |
fc44a215 | 190 | |
191 | /* Read gcov_type value from IB. */ | |
192 | ||
193 | gcov_type | |
194 | streamer_read_gcov_count (struct lto_input_block *ib) | |
195 | { | |
196 | gcov_type ret = streamer_read_hwi (ib); | |
197 | gcc_assert (ret >= 0); | |
198 | return ret; | |
199 | } |