1 /* Generic plugin context
2 Copyright (C) 2020 Free Software Foundation, Inc.
4 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
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef CC1_PLUGIN_CONTEXT_HH
21 #define CC1_PLUGIN_CONTEXT_HH
24 #include "coretypes.h"
27 #include "connection.hh"
31 static inline unsigned long long
34 return (unsigned long long) (uintptr_t) t
;
38 convert_in (unsigned long long v
)
40 return (tree
) (uintptr_t) v
;
43 struct decl_addr_value
49 struct decl_addr_hasher
: free_ptr_hash
<decl_addr_value
>
51 static hashval_t
hash (const decl_addr_value
*e
)
53 return DECL_UID (e
->decl
);
56 static bool equal (const decl_addr_value
*p1
,
57 const decl_addr_value
*p2
)
59 return p1
->decl
== p2
->decl
;
63 struct string_hasher
: nofree_ptr_hash
<const char>
65 static inline hashval_t
hash (const char *s
)
67 return htab_hash_string (s
);
70 static inline bool equal (const char *p1
, const char *p2
)
72 return strcmp (p1
, p2
) == 0;
76 struct plugin_context
: public cc1_plugin::connection
78 plugin_context (int fd
)
79 : cc1_plugin::connection (fd
),
86 // Map decls to addresses.
87 hash_table
<decl_addr_hasher
> address_map
;
89 // A collection of trees that are preserved for the GC.
90 hash_table
< nofree_ptr_hash
<tree_node
> > preserved
;
93 hash_table
<string_hasher
> file_names
;
95 // Perform GC marking.
98 // Preserve a tree during the plugin's operation.
99 tree
preserve (tree t
)
101 tree_node
**slot
= preserved
.find_slot (t
, INSERT
);
106 location_t
get_location_t (const char *filename
,
107 unsigned int line_number
);
111 // Add a file name to FILE_NAMES and return the canonical copy.
112 const char *intern_filename (const char *filename
);
115 extern plugin_context
*current_context
;
117 void generic_plugin_init (struct plugin_name_args
*plugin_info
,
118 unsigned int version
);
121 #endif // CC1_PLUGIN_CONTEXT_HH