diff options
author | hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-25 12:07:38 +0000 |
---|---|---|
committer | hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-25 12:07:38 +0000 |
commit | 5f8d4adf262a569ffe265df9fe29020259e29bdd (patch) | |
tree | 1b42ff9de53077e317f6573fb7a0e6580fe3254f /gcc/lto-streamer.h | |
parent | 6b88f2fe9d8dd7d78c1c072d0b66835f3620d2b8 (diff) | |
download | gcc-5f8d4adf262a569ffe265df9fe29020259e29bdd.tar.gz |
* lto-streamer-out.c (output_record_start): Use lto_output_enum
(lto_output_tree): Use output_record_start.
* lto-streamer-in.c (input_record_start): Use lto_input_enum
(lto_get_pickled_tree): Use input_record_start.
* lto-section-in.c (lto_section_overrun): Turn into fatal error.
(lto_value_range_error): New function.
* lto-streamer.h (lto_value_range_error): Declare.
(lto_output_int_in_range, lto_input_int_in_range): New functions.
(lto_output_enum, lto_input_enum): New macros.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174186 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/lto-streamer.h')
-rw-r--r-- | gcc/lto-streamer.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h index 3d87e18a825..3389b564374 100644 --- a/gcc/lto-streamer.h +++ b/gcc/lto-streamer.h @@ -771,6 +771,9 @@ extern int lto_eq_in_decl_state (const void *, const void *); extern struct lto_in_decl_state *lto_get_function_in_decl_state ( struct lto_file_decl_data *, tree); extern void lto_section_overrun (struct lto_input_block *) ATTRIBUTE_NORETURN; +extern void lto_value_range_error (const char *, + HOST_WIDE_INT, HOST_WIDE_INT, + HOST_WIDE_INT) ATTRIBUTE_NORETURN; /* In lto-section-out.c */ extern hashval_t lto_hash_decl_slot_node (const void *); @@ -1199,4 +1202,66 @@ lto_input_1_unsigned (struct lto_input_block *ib) return (ib->data[ib->p++]); } +/* Output VAL into OBS and verify it is in range MIN...MAX that is supposed + to be compile time constant. + Be host independent, limit range to 31bits. */ + +static inline void +lto_output_int_in_range (struct lto_output_stream *obs, + HOST_WIDE_INT min, + HOST_WIDE_INT max, + HOST_WIDE_INT val) +{ + HOST_WIDE_INT range = max - min; + + gcc_checking_assert (val >= min && val <= max && range > 0 + && range < 0x7fffffff); + + val -= min; + lto_output_1_stream (obs, val & 255); + if (range >= 0xff) + lto_output_1_stream (obs, (val << 8) & 255); + if (range >= 0xffff) + lto_output_1_stream (obs, (val << 16) & 255); + if (range >= 0xffffff) + lto_output_1_stream (obs, (val << 24) & 255); +} + +/* Input VAL into OBS and verify it is in range MIN...MAX that is supposed + to be compile time constant. PURPOSE is used for error reporting. */ + +static inline HOST_WIDE_INT +lto_input_int_in_range (struct lto_input_block *ib, + const char *purpose, + HOST_WIDE_INT min, + HOST_WIDE_INT max) +{ + HOST_WIDE_INT range = max - min; + HOST_WIDE_INT val = lto_input_1_unsigned (ib); + + gcc_checking_assert (range > 0 && range < 0x7fffffff); + + if (range >= 0xff) + val |= ((HOST_WIDE_INT)lto_input_1_unsigned (ib)) << 8; + if (range >= 0xffff) + val |= ((HOST_WIDE_INT)lto_input_1_unsigned (ib)) << 16; + if (range >= 0xffffff) + val |= ((HOST_WIDE_INT)lto_input_1_unsigned (ib)) << 24; + val += min; + if (val < min || val > max) + lto_value_range_error (purpose, val, min, max); + return val; +} + +/* Output VAL of type "enum enum_name" into OBS. + Assume range 0...ENUM_LAST - 1. */ +#define lto_output_enum(obs,enum_name,enum_last,val) \ + lto_output_int_in_range ((obs), 0, (int)(enum_last) - 1, (int)(val)) + +/* Input enum of type "enum enum_name" from IB. + Assume range 0...ENUM_LAST - 1. */ +#define lto_input_enum(ib,enum_name,enum_last) \ + (enum enum_name)lto_input_int_in_range ((ib), #enum_name, 0, \ + (int)(enum_last) - 1) + #endif /* GCC_LTO_STREAMER_H */ |