@@ -242,6 +242,164 @@ pph_register_shared_data (pph_stream *stream, void *data, unsigned ix)
}
+/* Given a type index TYPE_IDX and TYPE_KIND specifying the kind of type,
+ return a type from integer_types or global_trees. */
+
+static tree
+pth_get_type_from_index (unsigned type_idx, unsigned type_kind)
+{
+ if (type_kind == CPP_N_INTEGER)
+ return integer_types[type_idx];
+ else if (type_kind == CPP_N_FLOATING || type_kind == CPP_N_FRACT)
+ return global_trees[type_idx];
+ else if (type_kind == CPP_N_IMAGINARY)
+ {
+ /* We don't need a type for the complex number. The type is
+ associated with the real and imaginary parts. */
+ return NULL_TREE;
+ }
+ else
+ gcc_unreachable ();
+}
+
+
+/* Load a numeric value from file F. Return the corresponding tree. */
+
+static tree
+pth_load_number (pph_stream *f)
+{
+ unsigned type_idx, type_kind;
+ tree type, val;
+
+ type_idx = pph_in_uint (f);
+ type_kind = pph_in_uint (f);
+
+ type = pth_get_type_from_index (type_idx, type_kind);
+
+ if (type_kind == CPP_N_INTEGER)
+ {
+ HOST_WIDE_INT v[2];
+ pph_in_bytes (f, v, 2 * sizeof (HOST_WIDE_INT));
+ val = build_int_cst_wide (type, v[0], v[1]);
+ }
+ else if (type_kind == CPP_N_FLOATING)
+ {
+ REAL_VALUE_TYPE r;
+ pph_in_bytes (f, &r, sizeof (REAL_VALUE_TYPE));
+ val = build_real (type, r);
+ }
+ else if (type_kind == CPP_N_FRACT)
+ {
+ FIXED_VALUE_TYPE fv;
+ pph_in_bytes (f, &fv, sizeof (FIXED_VALUE_TYPE));
+ val = build_fixed (type, fv);
+ }
+ else if (type_kind == CPP_N_IMAGINARY)
+ {
+ tree r = pth_load_number (f);
+ tree i = pth_load_number (f);
+ val = build_complex (NULL_TREE, r, i);
+ }
+ else
+ gcc_unreachable ();
+
+ return val;
+}
+
+
+/* Load the tree value associated with TOKEN to file F. */
+
+static void
+pth_load_token_value (cp_token *token, pph_stream *f)
+{
+ const char *str;
+
+ switch (token->type)
+ {
+ case CPP_TEMPLATE_ID:
+ case CPP_NESTED_NAME_SPECIFIER:
+ break;
+
+ case CPP_NAME:
+ str = pph_in_string (f);
+ token->u.value = get_identifier (str);
+ break;
+
+ case CPP_KEYWORD:
+ token->u.value = ridpointers[token->keyword];
+ break;
+
+ case CPP_CHAR:
+ case CPP_WCHAR:
+ case CPP_CHAR16:
+ case CPP_CHAR32:
+ case CPP_NUMBER:
+ token->u.value = pth_load_number (f);
+ break;
+
+ case CPP_STRING:
+ case CPP_WSTRING:
+ case CPP_STRING16:
+ case CPP_STRING32:
+ str = pph_in_string (f);
+ token->u.value = build_string (strlen (str), str);
+ break;
+
+ case CPP_PRAGMA:
+ /* Nothing to do. Field pragma_kind has already been loaded. */
+ break;
+
+ default:
+ pph_in_bytes (f, &token->u.value, sizeof (token->u.value));
+ gcc_assert (token->u.value == NULL);
+ }
+}
+
+
+/* Read and return a token from STREAM. */
+
+static cp_token *
+pth_load_token (pph_stream *stream)
+{
+ cp_token *token = ggc_alloc_cleared_cp_token ();
+
+ /* Do not read the whole structure, the token value has
+ dynamic size as it contains swizzled pointers.
+ FIXME pph, restructure to allow bulk reads of the whole
+ section. */
+ pph_in_bytes (stream, token, sizeof (cp_token) - sizeof (void *));
+
+ /* FIXME pph. Use an arbitrary (but valid) location to avoid
+ confusing the rest of the compiler for now. */
+ token->location = input_location;
+
+ /* FIXME pph: verify that pth_load_token_value works with no tokens. */
+ pth_load_token_value (token, stream);
+
+ return token;
+}
+
+
+/* Read and return a cp_token_cache instance from STREAM. */
+
+static cp_token_cache *
+pth_load_token_cache (pph_stream *stream)
+{
+ unsigned i, num;
+ cp_token *first, *last;
+
+ num = pph_in_uint (stream);
+ for (last = first = NULL, i = 0; i < num; i++)
+ {
+ last = pth_load_token (stream);
+ if (first == NULL)
+ first = last;
+ }
+
+ return cp_token_cache_new (first, last);
+}
+
+
/* Read all fields in lang_decl_base instance LDB from STREAM. */
static void
@@ -231,6 +231,207 @@ pph_out_start_record (pph_stream *stream, void *data)
}
+/* Compute an index value for TYPE suitable for restoring it later
+ from global_trees[] or integer_types. The index is saved
+ in TYPE_IX_P and the number category (one of CPP_N_INTEGER,
+ CPP_N_FLOATING, etc) is saved in CATEGORY_P. */
+
+static void
+pth_get_index_from_type (tree type, unsigned *type_ix_p, unsigned *category_p)
+{
+ void **val_p;
+ static struct pointer_map_t *type_cache = NULL;
+
+ /* For complex types we will just use the type of the components. */
+ if (TREE_CODE (type) == COMPLEX_TYPE)
+ {
+ *type_ix_p = 0;
+ *category_p = CPP_N_IMAGINARY;
+ return;
+ }
+
+ if (type_cache == NULL)
+ type_cache = pointer_map_create ();
+
+ val_p = pointer_map_contains (type_cache, type);
+ if (val_p)
+ *type_ix_p = *((unsigned *) val_p);
+ else
+ {
+ if (CP_INTEGRAL_TYPE_P (type))
+ {
+ unsigned i;
+ for (i = itk_char; i < itk_none; i++)
+ if (type == integer_types[i])
+ {
+ *type_ix_p = (unsigned) i;
+ break;
+ }
+
+ gcc_assert (i != itk_none);
+ }
+ else if (FLOAT_TYPE_P (type) || FIXED_POINT_TYPE_P (type))
+ {
+ unsigned i;
+
+ for (i = TI_ERROR_MARK; i < TI_MAX; i++)
+ if (global_trees[i] == type)
+ {
+ *type_ix_p = (unsigned) i;
+ break;
+ }
+
+ gcc_assert (i != TI_MAX);
+ }
+ else
+ gcc_unreachable ();
+ }
+
+ if (CP_INTEGRAL_TYPE_P (type))
+ *category_p = CPP_N_INTEGER;
+ else if (FLOAT_TYPE_P (type))
+ *category_p = CPP_N_FLOATING;
+ else if (FIXED_POINT_TYPE_P (type))
+ *category_p = CPP_N_FRACT;
+ else
+ gcc_unreachable ();
+}
+
+
+/* Save the number VAL to file F. */
+
+static void
+pth_write_number (pph_stream *f, tree val)
+{
+ unsigned type_idx, type_kind;
+
+ pth_get_index_from_type (TREE_TYPE (val), &type_idx, &type_kind);
+
+ pph_out_uint (f, type_idx);
+ pph_out_uint (f, type_kind);
+
+ if (type_kind == CPP_N_INTEGER)
+ {
+ HOST_WIDE_INT v[2];
+
+ v[0] = TREE_INT_CST_LOW (val);
+ v[1] = TREE_INT_CST_HIGH (val);
+ pph_out_bytes (f, v, 2 * sizeof (HOST_WIDE_INT));
+ }
+ else if (type_kind == CPP_N_FLOATING)
+ {
+ REAL_VALUE_TYPE r = TREE_REAL_CST (val);
+ pph_out_bytes (f, &r, sizeof (REAL_VALUE_TYPE));
+ }
+ else if (type_kind == CPP_N_FRACT)
+ {
+ FIXED_VALUE_TYPE fv = TREE_FIXED_CST (val);
+ pph_out_bytes (f, &fv, sizeof (FIXED_VALUE_TYPE));
+ }
+ else if (type_kind == CPP_N_IMAGINARY)
+ {
+ pth_write_number (f, TREE_REALPART (val));
+ pth_write_number (f, TREE_IMAGPART (val));
+ }
+ else
+ gcc_unreachable ();
+}
+
+
+/* Save the tree associated with TOKEN to file F. */
+
+static void
+pth_save_token_value (pph_stream *f, cp_token *token)
+{
+ const char *str;
+ unsigned len;
+ tree val;
+
+ val = token->u.value;
+ switch (token->type)
+ {
+ case CPP_TEMPLATE_ID:
+ case CPP_NESTED_NAME_SPECIFIER:
+ break;
+
+ case CPP_NAME:
+ /* FIXME pph. Hash the strings and emit a string table. */
+ str = IDENTIFIER_POINTER (val);
+ len = IDENTIFIER_LENGTH (val);
+ pph_out_string_with_length (f, str, len);
+ break;
+
+ case CPP_KEYWORD:
+ /* Nothing to do. We will reconstruct the keyword from
+ ridpointers[token->keyword] at load time. */
+ break;
+
+ case CPP_CHAR:
+ case CPP_WCHAR:
+ case CPP_CHAR16:
+ case CPP_CHAR32:
+ case CPP_NUMBER:
+ pth_write_number (f, val);
+ break;
+
+ case CPP_STRING:
+ case CPP_WSTRING:
+ case CPP_STRING16:
+ case CPP_STRING32:
+ /* FIXME pph. Need to represent the type. */
+ str = TREE_STRING_POINTER (val);
+ len = TREE_STRING_LENGTH (val);
+ pph_out_string_with_length (f, str, len);
+ break;
+
+ case CPP_PRAGMA:
+ /* Nothing to do. Field pragma_kind has already been written. */
+ break;
+
+ default:
+ gcc_assert (token->u.value == NULL);
+ pph_out_bytes (f, &token->u.value, sizeof (token->u.value));
+ }
+}
+
+
+/* Save TOKEN on file F. Return the number of bytes written on F. */
+
+static void
+pth_save_token (cp_token *token, pph_stream *f)
+{
+ /* Do not write out the final field in TOKEN. It contains
+ pointers that need to be pickled separately.
+
+ FIXME pph - Need to also emit the location_t table so we can
+ reconstruct it when reading the PTH state. */
+ pph_out_bytes (f, token, sizeof (cp_token) - sizeof (void *));
+ pth_save_token_value (f, token);
+}
+
+
+/* Save all the tokens in CACHE to PPH stream F. */
+
+static void
+pth_save_token_cache (cp_token_cache *cache, pph_stream *f)
+{
+ unsigned i, num;
+ cp_token *tok;
+
+ if (cache == NULL)
+ {
+ pph_out_uint (f, 0);
+ return;
+ }
+
+ for (num = 0, tok = cache->first; tok != cache->last; tok++)
+ num++;
+
+ pph_out_uint (f, num);
+ for (i = 0, tok = cache->first; i < num; tok++, i++)
+ pth_save_token (tok, f);
+}
+
/* Write all the fields in lang_decl_base instance LDB to OB. */
static void
@@ -157,11 +157,6 @@ tree pph_alloc_tree (enum tree_code, struct lto_input_block *,
struct data_in *);
void pph_read_file (const char *filename);
-/* In pph.c. FIXME pph move these to pph-streamer.c. */
-struct cp_token_cache;
-void pth_save_token_cache (struct cp_token_cache *, pph_stream *);
-struct cp_token_cache *pth_load_token_cache (pph_stream *);
-
/* Inline functions. */
/* Output AST T to STREAM. If REF_P is true, output all the leaves of T
@@ -42,365 +42,6 @@ along with GCC; see the file COPYING3. If not see
-fpph_logfile. If this flag is not given, stdout is used. */
FILE *pph_logfile = NULL;
-/* Compute an index value for TYPE suitable for restoring it later
- from global_trees[] or integer_types. The index is saved
- in TYPE_IX_P and the number category (one of CPP_N_INTEGER,
- CPP_N_FLOATING, etc) is saved in CATEGORY_P. */
-
-static void
-pth_get_index_from_type (tree type, unsigned *type_ix_p, unsigned *category_p)
-{
- void **val_p;
- static struct pointer_map_t *type_cache = NULL;
-
- /* For complex types we will just use the type of the components. */
- if (TREE_CODE (type) == COMPLEX_TYPE)
- {
- *type_ix_p = 0;
- *category_p = CPP_N_IMAGINARY;
- return;
- }
-
- if (type_cache == NULL)
- type_cache = pointer_map_create ();
-
- val_p = pointer_map_contains (type_cache, type);
- if (val_p)
- *type_ix_p = *((unsigned *) val_p);
- else
- {
- if (CP_INTEGRAL_TYPE_P (type))
- {
- unsigned i;
- for (i = itk_char; i < itk_none; i++)
- if (type == integer_types[i])
- {
- *type_ix_p = (unsigned) i;
- break;
- }
-
- gcc_assert (i != itk_none);
- }
- else if (FLOAT_TYPE_P (type) || FIXED_POINT_TYPE_P (type))
- {
- unsigned i;
-
- for (i = TI_ERROR_MARK; i < TI_MAX; i++)
- if (global_trees[i] == type)
- {
- *type_ix_p = (unsigned) i;
- break;
- }
-
- gcc_assert (i != TI_MAX);
- }
- else
- gcc_unreachable ();
- }
-
- if (CP_INTEGRAL_TYPE_P (type))
- *category_p = CPP_N_INTEGER;
- else if (FLOAT_TYPE_P (type))
- *category_p = CPP_N_FLOATING;
- else if (FIXED_POINT_TYPE_P (type))
- *category_p = CPP_N_FRACT;
- else
- gcc_unreachable ();
-}
-
-
-/* Save the number VAL to file F. */
-
-static void
-pth_write_number (pph_stream *f, tree val)
-{
- unsigned type_idx, type_kind;
-
- pth_get_index_from_type (TREE_TYPE (val), &type_idx, &type_kind);
-
- pph_out_uint (f, type_idx);
- pph_out_uint (f, type_kind);
-
- if (type_kind == CPP_N_INTEGER)
- {
- HOST_WIDE_INT v[2];
-
- v[0] = TREE_INT_CST_LOW (val);
- v[1] = TREE_INT_CST_HIGH (val);
- pph_out_bytes (f, v, 2 * sizeof (HOST_WIDE_INT));
- }
- else if (type_kind == CPP_N_FLOATING)
- {
- REAL_VALUE_TYPE r = TREE_REAL_CST (val);
- pph_out_bytes (f, &r, sizeof (REAL_VALUE_TYPE));
- }
- else if (type_kind == CPP_N_FRACT)
- {
- FIXED_VALUE_TYPE fv = TREE_FIXED_CST (val);
- pph_out_bytes (f, &fv, sizeof (FIXED_VALUE_TYPE));
- }
- else if (type_kind == CPP_N_IMAGINARY)
- {
- pth_write_number (f, TREE_REALPART (val));
- pth_write_number (f, TREE_IMAGPART (val));
- }
- else
- gcc_unreachable ();
-}
-
-
-/* Save the tree associated with TOKEN to file F. */
-
-static void
-pth_save_token_value (pph_stream *f, cp_token *token)
-{
- const char *str;
- unsigned len;
- tree val;
-
- val = token->u.value;
- switch (token->type)
- {
- case CPP_TEMPLATE_ID:
- case CPP_NESTED_NAME_SPECIFIER:
- break;
-
- case CPP_NAME:
- /* FIXME pph. Hash the strings and emit a string table. */
- str = IDENTIFIER_POINTER (val);
- len = IDENTIFIER_LENGTH (val);
- pph_out_string_with_length (f, str, len);
- break;
-
- case CPP_KEYWORD:
- /* Nothing to do. We will reconstruct the keyword from
- ridpointers[token->keyword] at load time. */
- break;
-
- case CPP_CHAR:
- case CPP_WCHAR:
- case CPP_CHAR16:
- case CPP_CHAR32:
- case CPP_NUMBER:
- pth_write_number (f, val);
- break;
-
- case CPP_STRING:
- case CPP_WSTRING:
- case CPP_STRING16:
- case CPP_STRING32:
- /* FIXME pph. Need to represent the type. */
- str = TREE_STRING_POINTER (val);
- len = TREE_STRING_LENGTH (val);
- pph_out_string_with_length (f, str, len);
- break;
-
- case CPP_PRAGMA:
- /* Nothing to do. Field pragma_kind has already been written. */
- break;
-
- default:
- gcc_assert (token->u.value == NULL);
- pph_out_bytes (f, &token->u.value, sizeof (token->u.value));
- }
-}
-
-
-/* Save TOKEN on file F. Return the number of bytes written on F. */
-
-static void
-pth_save_token (cp_token *token, pph_stream *f)
-{
- /* Do not write out the final field in TOKEN. It contains
- pointers that need to be pickled separately.
-
- FIXME pph - Need to also emit the location_t table so we can
- reconstruct it when reading the PTH state. */
- pph_out_bytes (f, token, sizeof (cp_token) - sizeof (void *));
- pth_save_token_value (f, token);
-}
-
-
-/* Save all the tokens in CACHE to PPH stream F. */
-
-void
-pth_save_token_cache (cp_token_cache *cache, pph_stream *f)
-{
- unsigned i, num;
- cp_token *tok;
-
- if (cache == NULL)
- {
- pph_out_uint (f, 0);
- return;
- }
-
- for (num = 0, tok = cache->first; tok != cache->last; tok++)
- num++;
-
- pph_out_uint (f, num);
- for (i = 0, tok = cache->first; i < num; tok++, i++)
- pth_save_token (tok, f);
-}
-
-
-/* Given a type index TYPE_IDX and TYPE_KIND specifying the kind of type,
- return a type from integer_types or global_trees. */
-
-static tree
-pth_get_type_from_index (unsigned type_idx, unsigned type_kind)
-{
- if (type_kind == CPP_N_INTEGER)
- return integer_types[type_idx];
- else if (type_kind == CPP_N_FLOATING || type_kind == CPP_N_FRACT)
- return global_trees[type_idx];
- else if (type_kind == CPP_N_IMAGINARY)
- {
- /* We don't need a type for the complex number. The type is
- associated with the real and imaginary parts. */
- return NULL_TREE;
- }
- else
- gcc_unreachable ();
-}
-
-
-/* Load a numeric value from file F. Return the corresponding tree. */
-
-static tree
-pth_load_number (pph_stream *f)
-{
- unsigned type_idx, type_kind;
- tree type, val;
-
- type_idx = pph_in_uint (f);
- type_kind = pph_in_uint (f);
-
- type = pth_get_type_from_index (type_idx, type_kind);
-
- if (type_kind == CPP_N_INTEGER)
- {
- HOST_WIDE_INT v[2];
- pph_in_bytes (f, v, 2 * sizeof (HOST_WIDE_INT));
- val = build_int_cst_wide (type, v[0], v[1]);
- }
- else if (type_kind == CPP_N_FLOATING)
- {
- REAL_VALUE_TYPE r;
- pph_in_bytes (f, &r, sizeof (REAL_VALUE_TYPE));
- val = build_real (type, r);
- }
- else if (type_kind == CPP_N_FRACT)
- {
- FIXED_VALUE_TYPE fv;
- pph_in_bytes (f, &fv, sizeof (FIXED_VALUE_TYPE));
- val = build_fixed (type, fv);
- }
- else if (type_kind == CPP_N_IMAGINARY)
- {
- tree r = pth_load_number (f);
- tree i = pth_load_number (f);
- val = build_complex (NULL_TREE, r, i);
- }
- else
- gcc_unreachable ();
-
- return val;
-}
-
-
-/* Load the tree value associated with TOKEN to file F. */
-
-static void
-pth_load_token_value (cp_token *token, pph_stream *f)
-{
- const char *str;
-
- switch (token->type)
- {
- case CPP_TEMPLATE_ID:
- case CPP_NESTED_NAME_SPECIFIER:
- break;
-
- case CPP_NAME:
- str = pph_in_string (f);
- token->u.value = get_identifier (str);
- break;
-
- case CPP_KEYWORD:
- token->u.value = ridpointers[token->keyword];
- break;
-
- case CPP_CHAR:
- case CPP_WCHAR:
- case CPP_CHAR16:
- case CPP_CHAR32:
- case CPP_NUMBER:
- token->u.value = pth_load_number (f);
- break;
-
- case CPP_STRING:
- case CPP_WSTRING:
- case CPP_STRING16:
- case CPP_STRING32:
- str = pph_in_string (f);
- token->u.value = build_string (strlen (str), str);
- break;
-
- case CPP_PRAGMA:
- /* Nothing to do. Field pragma_kind has already been loaded. */
- break;
-
- default:
- pph_in_bytes (f, &token->u.value, sizeof (token->u.value));
- gcc_assert (token->u.value == NULL);
- }
-}
-
-
-/* Read and return a token from STREAM. */
-
-static cp_token *
-pth_load_token (pph_stream *stream)
-{
- cp_token *token = ggc_alloc_cleared_cp_token ();
-
- /* Do not read the whole structure, the token value has
- dynamic size as it contains swizzled pointers.
- FIXME pph, restructure to allow bulk reads of the whole
- section. */
- pph_in_bytes (stream, token, sizeof (cp_token) - sizeof (void *));
-
- /* FIXME pph. Use an arbitrary (but valid) location to avoid
- confusing the rest of the compiler for now. */
- token->location = input_location;
-
- /* FIXME pph: verify that pth_load_token_value works with no tokens. */
- pth_load_token_value (token, stream);
-
- return token;
-}
-
-
-/* Read and return a cp_token_cache instance from STREAM. */
-
-cp_token_cache *
-pth_load_token_cache (pph_stream *stream)
-{
- unsigned i, num;
- cp_token *first, *last;
-
- num = pph_in_uint (stream);
- for (last = first = NULL, i = 0; i < num; i++)
- {
- last = pth_load_token (stream);
- if (first == NULL)
- first = last;
- }
-
- return cp_token_cache_new (first, last);
-}
-
/* Dump a complicated name for tree T to FILE using FLAGS.
See TDF_* in tree-pass.h for flags. */