1 /* Streamer hooks. Support for adding streamer-specific callbacks to
2 generic streaming routines.
4 Copyright 2011 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
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
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 #ifndef GCC_STREAMER_HOOKS_H
24 #define GCC_STREAMER_HOOKS_H
28 /* Forward declarations to avoid including unnecessary headers. */
30 struct lto_input_block
;
33 struct lto_streamer_cache_d
;
35 /* Streamer hooks. These functions do additional processing as
36 needed by the module. There are two types of callbacks, those that
37 replace the default behavior and those that supplement it.
39 Hooks marked [REQ] are required to be set. Those marked [OPT] may
40 be NULL, if the streamer does not need to implement them. */
41 struct streamer_hooks
{
42 /* [REQ] A string identifying this streamer. */
45 /* [REQ] Called by lto_streamer_cache_create to instantiate a cache of
46 well-known nodes. These are tree nodes that are always
47 instantiated by the compiler on startup. Additionally, these
48 nodes need to be shared. This function should call
49 lto_streamer_cache_append on every tree node that it wishes to
50 preload in the streamer cache. This way, the writer will only
51 write out a reference to the tree and the reader will instantiate
52 the tree out of this pre-populated cache. */
53 void (*preload_common_nodes
) (struct lto_streamer_cache_d
*);
55 /* [REQ] Return true if the given tree is supported by this streamer. */
56 bool (*is_streamable
) (tree
);
58 /* [OPT] Called by lto_write_tree after writing all the common parts of
59 a tree. If defined, the callback is in charge of writing all
60 the fields that lto_write_tree did not write out. Arguments
61 are as in lto_write_tree.
63 The following tree fields are not handled by common code:
69 Callbacks may choose to ignore or handle them. If handled,
70 the reader should read them in the exact same sequence written
72 void (*write_tree
) (struct output_block
*, tree
, bool);
74 /* [OPT] Called by lto_read_tree after reading all the common parts of
75 a tree. If defined, the callback is in charge of reading all
76 the fields that lto_read_tree did not read in. Arguments
77 are as in lto_read_tree. */
78 void (*read_tree
) (struct lto_input_block
*, struct data_in
*, tree
);
80 /* [OPT] Called by lto_output_tree_ref to determine if the given tree node
81 should be emitted as a reference to the table of declarations
82 (the same table that holds global declarations). */
83 bool (*indexable_with_decls_p
) (tree
);
85 /* [OPT] Called by pack_value_fields to store any non-pointer fields
86 in the tree structure. The arguments are as in pack_value_fields. */
87 void (*pack_value_fields
) (struct bitpack_d
*, tree
);
89 /* [OPT] Called by unpack_value_fields to retrieve any non-pointer fields
90 in the tree structure. The arguments are as in unpack_value_fields. */
91 void (*unpack_value_fields
) (struct bitpack_d
*, tree
);
93 /* [OPT] Called by lto_materialize_tree for tree nodes that it does not
94 know how to allocate memory for. If defined, this hook should
95 return a new tree node of the given code. The data_in and
96 input_block arguments are passed in case the hook needs to
97 read more data from the stream to allocate the node.
98 If this hook returns NULL, then lto_materialize_tree will attempt
99 to allocate the tree by calling make_node directly. */
100 tree (*alloc_tree
) (enum tree_code
, struct lto_input_block
*,
103 /* [OPT] Called by lto_output_tree_header to write any streamer-specific
104 information needed to allocate the tree. This hook may assume
105 that the basic header data (tree code, etc) has already been
106 written. It should only write any extra data needed to allocate
107 the node (e.g., in the case of CALL_EXPR, this hook would write
108 the number of arguments to the CALL_EXPR). */
109 void (*output_tree_header
) (struct output_block
*, tree
);
112 /* Streamer hooks. */
113 extern struct streamer_hooks streamer_hooks
;
115 /* In streamer-hooks.c. */
116 void streamer_hooks_init (void);
118 #endif /* GCC_STREAMER_HOOKS_H */