1*38fd1498Szrj /* Streamer hooks.  Support for adding streamer-specific callbacks to
2*38fd1498Szrj    generic streaming routines.
3*38fd1498Szrj 
4*38fd1498Szrj    Copyright (C) 2011-2018 Free Software Foundation, Inc.
5*38fd1498Szrj    Contributed by Diego Novillo <dnovillo@google.com>
6*38fd1498Szrj 
7*38fd1498Szrj This file is part of GCC.
8*38fd1498Szrj 
9*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
10*38fd1498Szrj the terms of the GNU General Public License as published by the Free
11*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
12*38fd1498Szrj version.
13*38fd1498Szrj 
14*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
16*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17*38fd1498Szrj for more details.
18*38fd1498Szrj 
19*38fd1498Szrj You should have received a copy of the GNU General Public License
20*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
21*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
22*38fd1498Szrj 
23*38fd1498Szrj #ifndef GCC_STREAMER_HOOKS_H
24*38fd1498Szrj #define GCC_STREAMER_HOOKS_H
25*38fd1498Szrj 
26*38fd1498Szrj /* Forward declarations to avoid including unnecessary headers.  */
27*38fd1498Szrj struct output_block;
28*38fd1498Szrj struct lto_input_block;
29*38fd1498Szrj struct data_in;
30*38fd1498Szrj 
31*38fd1498Szrj /* Streamer hooks.  These functions do additional processing as
32*38fd1498Szrj    needed by the module.  There are two types of callbacks, those that
33*38fd1498Szrj    replace the default behavior and those that supplement it.
34*38fd1498Szrj 
35*38fd1498Szrj    Hooks marked [REQ] are required to be set.  Those marked [OPT] may
36*38fd1498Szrj    be NULL, if the streamer does not need to implement them.  */
37*38fd1498Szrj struct streamer_hooks {
38*38fd1498Szrj   /* [REQ] Called by every tree streaming routine that needs to write
39*38fd1498Szrj      a tree node.  The arguments are: output_block where to write the
40*38fd1498Szrj      node, the tree node to write and a boolean flag that should be true
41*38fd1498Szrj      if the caller wants to write a reference to the tree, instead of the
42*38fd1498Szrj      tree itself.  The second boolean parameter specifies this for
43*38fd1498Szrj      the tree itself, the first for all siblings that are streamed.
44*38fd1498Szrj      The referencing mechanism is up to each streamer to implement.  */
45*38fd1498Szrj   void (*write_tree) (struct output_block *, tree, bool, bool);
46*38fd1498Szrj 
47*38fd1498Szrj   /* [REQ] Called by every tree streaming routine that needs to read
48*38fd1498Szrj      a tree node.  It takes two arguments: an lto_input_block pointing
49*38fd1498Szrj      to the buffer where to read from and a data_in instance with tables
50*38fd1498Szrj      and descriptors needed by the unpickling routines.  It returns the
51*38fd1498Szrj      tree instantiated from the stream.  */
52*38fd1498Szrj   tree (*read_tree) (struct lto_input_block *, struct data_in *);
53*38fd1498Szrj 
54*38fd1498Szrj   /* [REQ] Called by every streaming routine that needs to read a location.  */
55*38fd1498Szrj   void (*input_location) (location_t *, struct bitpack_d *, struct data_in *);
56*38fd1498Szrj 
57*38fd1498Szrj   /* [REQ] Called by every streaming routine that needs to write a location.  */
58*38fd1498Szrj   void (*output_location) (struct output_block *, struct bitpack_d *, location_t);
59*38fd1498Szrj };
60*38fd1498Szrj 
61*38fd1498Szrj #define stream_write_tree(OB, EXPR, REF_P) \
62*38fd1498Szrj     streamer_hooks.write_tree (OB, EXPR, REF_P, REF_P)
63*38fd1498Szrj 
64*38fd1498Szrj #define stream_write_tree_shallow_non_ref(OB, EXPR, REF_P) \
65*38fd1498Szrj     streamer_hooks.write_tree (OB, EXPR, REF_P, false)
66*38fd1498Szrj 
67*38fd1498Szrj #define stream_read_tree(IB, DATA_IN) \
68*38fd1498Szrj     streamer_hooks.read_tree (IB, DATA_IN)
69*38fd1498Szrj 
70*38fd1498Szrj #define stream_input_location(LOCPTR, BP, DATA_IN) \
71*38fd1498Szrj     streamer_hooks.input_location (LOCPTR, BP, DATA_IN)
72*38fd1498Szrj 
73*38fd1498Szrj #define stream_output_location(OB, BP, LOC) \
74*38fd1498Szrj     streamer_hooks.output_location (OB, BP, LOC)
75*38fd1498Szrj 
76*38fd1498Szrj /* Streamer hooks.  */
77*38fd1498Szrj extern struct streamer_hooks streamer_hooks;
78*38fd1498Szrj 
79*38fd1498Szrj /* In streamer-hooks.c.  */
80*38fd1498Szrj void streamer_hooks_init (void);
81*38fd1498Szrj 
82*38fd1498Szrj #endif  /* GCC_STREAMER_HOOKS_H  */
83