streamer-hooks.h 3.3 KB

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