1 /* Library interface to C front end
2 Copyright (C) 2014-2021 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 #include <cc1plugin-config.h>
24 #undef PACKAGE_TARNAME
25 #undef PACKAGE_VERSION
27 #include "../gcc/config.h"
31 #undef PACKAGE_TARNAME
32 #undef PACKAGE_VERSION
34 #include "gcc-plugin.h"
36 #include "coretypes.h"
37 #include "stringpool.h"
39 #include "gcc-interface.h"
43 #include "double-int.h"
51 #include "fold-const.h"
52 #include "stor-layout.h"
56 #include "hash-table.h"
58 #include "c-family/c-pragma.h"
60 #include "diagnostic.h"
61 #include "langhooks.h"
62 #include "langhooks-def.h"
64 #include "callbacks.hh"
65 #include "connection.hh"
66 #include "marshall.hh"
68 #include "gcc-c-interface.h"
73 #pragma GCC visibility push(default)
75 int plugin_is_GPL_compatible
;
77 #pragma GCC visibility pop
82 // This is put into the lang hooks when the plugin starts.
85 plugin_print_error_function (diagnostic_context
*context
, const char *file
,
86 diagnostic_info
*diagnostic
)
88 if (current_function_decl
!= NULL_TREE
89 && DECL_NAME (current_function_decl
) != NULL_TREE
90 && strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl
)),
91 GCC_FE_WRAPPER_FUNCTION
) == 0)
93 lhd_print_error_function (context
, file
, diagnostic
);
98 static unsigned long long
101 return (unsigned long long) (uintptr_t) t
;
105 convert_in (unsigned long long v
)
107 return (tree
) (uintptr_t) v
;
112 struct decl_addr_value
118 struct decl_addr_hasher
: free_ptr_hash
<decl_addr_value
>
120 static inline hashval_t
hash (const decl_addr_value
*);
121 static inline bool equal (const decl_addr_value
*, const decl_addr_value
*);
125 decl_addr_hasher::hash (const decl_addr_value
*e
)
127 return IDENTIFIER_HASH_VALUE (DECL_NAME (e
->decl
));
131 decl_addr_hasher::equal (const decl_addr_value
*p1
, const decl_addr_value
*p2
)
133 return p1
->decl
== p2
->decl
;
138 struct string_hasher
: nofree_ptr_hash
<const char>
140 static inline hashval_t
hash (const char *s
)
142 return htab_hash_string (s
);
145 static inline bool equal (const char *p1
, const char *p2
)
147 return strcmp (p1
, p2
) == 0;
153 // A wrapper for pushdecl that doesn't let gdb have a chance to
154 // instantiate a symbol.
157 pushdecl_safe (tree decl
)
159 void (*save
) (enum c_oracle_request
, tree identifier
);
161 save
= c_binding_oracle
;
162 c_binding_oracle
= NULL
;
164 c_binding_oracle
= save
;
169 struct plugin_context
: public cc1_plugin::connection
171 plugin_context (int fd
);
173 // Map decls to addresses.
174 hash_table
<decl_addr_hasher
> address_map
;
176 // A collection of trees that are preserved for the GC.
177 hash_table
< nofree_ptr_hash
<tree_node
> > preserved
;
180 hash_table
<string_hasher
> file_names
;
182 // Perform GC marking.
185 // Preserve a tree during the plugin's operation.
186 tree
preserve (tree t
)
188 tree_node
**slot
= preserved
.find_slot (t
, INSERT
);
193 location_t
get_location_t (const char *filename
,
194 unsigned int line_number
)
196 if (filename
== NULL
)
197 return UNKNOWN_LOCATION
;
199 filename
= intern_filename (filename
);
200 linemap_add (line_table
, LC_ENTER
, false, filename
, line_number
);
201 location_t loc
= linemap_line_start (line_table
, line_number
, 0);
202 linemap_add (line_table
, LC_LEAVE
, false, NULL
, 0);
208 // Add a file name to FILE_NAMES and return the canonical copy.
209 const char *intern_filename (const char *filename
)
211 const char **slot
= file_names
.find_slot (filename
, INSERT
);
214 /* The file name must live as long as the line map, which
215 effectively means as long as this compilation. So, we copy
216 the string here but never free it. */
217 *slot
= xstrdup (filename
);
223 static plugin_context
*current_context
;
227 plugin_context::plugin_context (int fd
)
228 : cc1_plugin::connection (fd
),
236 plugin_context::mark ()
238 for (hash_table
<decl_addr_hasher
>::iterator it
= address_map
.begin ();
239 it
!= address_map
.end ();
242 ggc_mark ((*it
)->decl
);
243 ggc_mark ((*it
)->address
);
246 for (hash_table
< nofree_ptr_hash
<tree_node
> >::iterator
247 it
= preserved
.begin (); it
!= preserved
.end (); ++it
)
252 plugin_binding_oracle (enum c_oracle_request kind
, tree identifier
)
254 enum gcc_c_oracle_request request
;
256 gcc_assert (current_context
!= NULL
);
260 case C_ORACLE_SYMBOL
:
261 request
= GCC_C_ORACLE_SYMBOL
;
264 request
= GCC_C_ORACLE_TAG
;
267 request
= GCC_C_ORACLE_LABEL
;
274 cc1_plugin::call (current_context
, "binding_oracle", &ignore
,
275 request
, IDENTIFIER_POINTER (identifier
));
279 plugin_pragma_user_expression (cpp_reader
*)
281 c_binding_oracle
= plugin_binding_oracle
;
285 plugin_init_extra_pragmas (void *, void *)
287 c_register_pragma ("GCC", "user_expression", plugin_pragma_user_expression
);
292 // Maybe rewrite a decl to its address.
294 address_rewriter (tree
*in
, int *walk_subtrees
, void *arg
)
296 plugin_context
*ctx
= (plugin_context
*) arg
;
298 if (!DECL_P (*in
) || DECL_NAME (*in
) == NULL_TREE
)
301 decl_addr_value value
;
303 decl_addr_value
*found_value
= ctx
->address_map
.find (&value
);
304 if (found_value
!= NULL
)
306 else if (DECL_IS_UNDECLARED_BUILTIN (*in
))
310 if (!cc1_plugin::call (ctx
, "address_oracle", &address
,
311 IDENTIFIER_POINTER (DECL_NAME (*in
))))
316 // Insert the decl into the address map in case it is referenced
318 value
.address
= build_int_cst_type (ptr_type_node
, address
);
319 decl_addr_value
**slot
= ctx
->address_map
.find_slot (&value
, INSERT
);
320 gcc_assert (*slot
== NULL
);
322 = static_cast<decl_addr_value
*> (xmalloc (sizeof (decl_addr_value
)));
329 if (found_value
->address
!= error_mark_node
)
331 // We have an address for the decl, so rewrite the tree.
332 tree ptr_type
= build_pointer_type (TREE_TYPE (*in
));
333 *in
= fold_build1 (INDIRECT_REF
, TREE_TYPE (*in
),
334 fold_build1 (CONVERT_EXPR
, ptr_type
,
335 found_value
->address
));
343 // When generating code for gdb, we want to be able to use absolute
344 // addresses to refer to otherwise external objects that gdb knows
345 // about. gdb passes in these addresses when building decls, and then
346 // before gimplification we go through the trees, rewriting uses to
347 // the equivalent of "*(TYPE *) ADDR".
349 rewrite_decls_to_addresses (void *function_in
, void *)
351 tree function
= (tree
) function_in
;
353 // Do nothing if we're not in gdb.
354 if (current_context
== NULL
)
357 walk_tree (&DECL_SAVED_TREE (function
), address_rewriter
, current_context
,
364 plugin_build_decl (cc1_plugin::connection
*self
,
366 enum gcc_c_symbol_kind sym_kind
,
367 gcc_type sym_type_in
,
368 const char *substitution_name
,
370 const char *filename
,
371 unsigned int line_number
)
373 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
374 tree identifier
= get_identifier (name
);
377 tree sym_type
= convert_in (sym_type_in
);
381 case GCC_C_SYMBOL_FUNCTION
:
382 code
= FUNCTION_DECL
;
385 case GCC_C_SYMBOL_VARIABLE
:
389 case GCC_C_SYMBOL_TYPEDEF
:
393 case GCC_C_SYMBOL_LABEL
:
394 // FIXME: we aren't ready to handle labels yet.
395 // It isn't clear how to translate them properly
396 // and in any case a "goto" isn't likely to work.
397 return convert_out (error_mark_node
);
403 location_t loc
= ctx
->get_location_t (filename
, line_number
);
405 decl
= build_decl (loc
, code
, identifier
, sym_type
);
406 TREE_USED (decl
) = 1;
407 TREE_ADDRESSABLE (decl
) = 1;
409 if (sym_kind
!= GCC_C_SYMBOL_TYPEDEF
)
411 decl_addr_value value
;
413 DECL_EXTERNAL (decl
) = 1;
415 if (substitution_name
!= NULL
)
417 // If the translator gave us a name without a binding,
418 // we can just substitute error_mark_node, since we know the
419 // translator will be reporting an error anyhow.
421 = lookup_name (get_identifier (substitution_name
));
422 if (value
.address
== NULL_TREE
)
423 value
.address
= error_mark_node
;
426 value
.address
= build_int_cst_type (ptr_type_node
, address
);
427 decl_addr_value
**slot
= ctx
->address_map
.find_slot (&value
, INSERT
);
428 gcc_assert (*slot
== NULL
);
430 = static_cast<decl_addr_value
*> (xmalloc (sizeof (decl_addr_value
)));
434 return convert_out (ctx
->preserve (decl
));
438 plugin_bind (cc1_plugin::connection
*,
439 gcc_decl decl_in
, int is_global
)
441 tree decl
= convert_in (decl_in
);
442 c_bind (DECL_SOURCE_LOCATION (decl
), decl
, is_global
);
443 rest_of_decl_compilation (decl
, is_global
, 0);
448 plugin_tagbind (cc1_plugin::connection
*self
,
449 const char *name
, gcc_type tagged_type
,
450 const char *filename
, unsigned int line_number
)
452 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
453 tree t
= convert_in (tagged_type
), x
;
454 c_pushtag (ctx
->get_location_t (filename
, line_number
),
455 get_identifier (name
), t
);
457 /* Propagate the newly-added type name so that previously-created
458 variant types are not disconnected from their main variants. */
459 for (x
= TYPE_MAIN_VARIANT (t
); x
; x
= TYPE_NEXT_VARIANT (x
))
460 TYPE_NAME (x
) = TYPE_NAME (t
);
466 plugin_build_pointer_type (cc1_plugin::connection
*,
469 // No need to preserve a pointer type as the base type is preserved.
470 return convert_out (build_pointer_type (convert_in (base_type
)));
473 // TYPE_NAME needs to be a valid pointer, even if there is no name available.
476 build_anonymous_node (enum tree_code code
)
478 tree node
= make_node (code
);
479 tree type_decl
= build_decl (input_location
, TYPE_DECL
, NULL_TREE
, node
);
480 TYPE_NAME (node
) = type_decl
;
481 TYPE_STUB_DECL (node
) = type_decl
;
486 plugin_build_record_type (cc1_plugin::connection
*self
)
488 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
489 return convert_out (ctx
->preserve (build_anonymous_node (RECORD_TYPE
)));
493 plugin_build_union_type (cc1_plugin::connection
*self
)
495 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
496 return convert_out (ctx
->preserve (build_anonymous_node (UNION_TYPE
)));
500 plugin_build_add_field (cc1_plugin::connection
*,
501 gcc_type record_or_union_type_in
,
502 const char *field_name
,
503 gcc_type field_type_in
,
504 unsigned long bitsize
,
505 unsigned long bitpos
)
507 tree record_or_union_type
= convert_in (record_or_union_type_in
);
508 tree field_type
= convert_in (field_type_in
);
510 gcc_assert (TREE_CODE (record_or_union_type
) == RECORD_TYPE
511 || TREE_CODE (record_or_union_type
) == UNION_TYPE
);
513 /* Note that gdb does not preserve the location of field decls, so
514 we can't provide a decent location here. */
515 tree decl
= build_decl (BUILTINS_LOCATION
, FIELD_DECL
,
516 get_identifier (field_name
), field_type
);
517 DECL_FIELD_CONTEXT (decl
) = record_or_union_type
;
519 if (TREE_CODE (field_type
) == INTEGER_TYPE
520 && TYPE_PRECISION (field_type
) != bitsize
)
522 DECL_BIT_FIELD_TYPE (decl
) = field_type
;
524 = c_build_bitfield_integer_type (bitsize
, TYPE_UNSIGNED (field_type
));
527 SET_DECL_MODE (decl
, TYPE_MODE (TREE_TYPE (decl
)));
529 // There's no way to recover this from DWARF.
530 SET_DECL_OFFSET_ALIGN (decl
, TYPE_PRECISION (pointer_sized_int_node
));
532 tree pos
= bitsize_int (bitpos
);
533 pos_from_bit (&DECL_FIELD_OFFSET (decl
), &DECL_FIELD_BIT_OFFSET (decl
),
534 DECL_OFFSET_ALIGN (decl
), pos
);
536 DECL_SIZE (decl
) = bitsize_int (bitsize
);
537 DECL_SIZE_UNIT (decl
) = size_int ((bitsize
+ BITS_PER_UNIT
- 1)
540 DECL_CHAIN (decl
) = TYPE_FIELDS (record_or_union_type
);
541 TYPE_FIELDS (record_or_union_type
) = decl
;
547 plugin_finish_record_or_union (cc1_plugin::connection
*,
548 gcc_type record_or_union_type_in
,
549 unsigned long size_in_bytes
)
551 tree record_or_union_type
= convert_in (record_or_union_type_in
);
553 gcc_assert (TREE_CODE (record_or_union_type
) == RECORD_TYPE
554 || TREE_CODE (record_or_union_type
) == UNION_TYPE
);
556 /* We built the field list in reverse order, so fix it now. */
557 TYPE_FIELDS (record_or_union_type
)
558 = nreverse (TYPE_FIELDS (record_or_union_type
));
560 if (TREE_CODE (record_or_union_type
) == UNION_TYPE
)
562 /* Unions can just be handled by the generic code. */
563 layout_type (record_or_union_type
);
567 // FIXME there's no way to get this from DWARF,
568 // or even, it seems, a particularly good way to deduce it.
569 SET_TYPE_ALIGN (record_or_union_type
,
570 TYPE_PRECISION (pointer_sized_int_node
));
572 TYPE_SIZE (record_or_union_type
) = bitsize_int (size_in_bytes
574 TYPE_SIZE_UNIT (record_or_union_type
) = size_int (size_in_bytes
);
576 compute_record_mode (record_or_union_type
);
577 finish_bitfield_layout (record_or_union_type
);
578 // FIXME we have no idea about TYPE_PACKED
581 tree t
= record_or_union_type
, x
;
582 for (x
= TYPE_MAIN_VARIANT (t
); x
; x
= TYPE_NEXT_VARIANT (x
))
584 /* Like finish_struct, update the qualified variant types. */
585 TYPE_FIELDS (x
) = TYPE_FIELDS (t
);
586 TYPE_LANG_SPECIFIC (x
) = TYPE_LANG_SPECIFIC (t
);
587 C_TYPE_FIELDS_READONLY (x
) = C_TYPE_FIELDS_READONLY (t
);
588 C_TYPE_FIELDS_VOLATILE (x
) = C_TYPE_FIELDS_VOLATILE (t
);
589 C_TYPE_VARIABLE_SIZE (x
) = C_TYPE_VARIABLE_SIZE (t
);
590 /* We copy these fields too. */
591 SET_TYPE_ALIGN (x
, TYPE_ALIGN (t
));
592 TYPE_SIZE (x
) = TYPE_SIZE (t
);
593 TYPE_SIZE_UNIT (x
) = TYPE_SIZE_UNIT (t
);
594 if (x
!= record_or_union_type
)
595 compute_record_mode (x
);
602 plugin_build_enum_type (cc1_plugin::connection
*self
,
603 gcc_type underlying_int_type_in
)
605 tree underlying_int_type
= convert_in (underlying_int_type_in
);
607 if (underlying_int_type
== error_mark_node
)
608 return convert_out (error_mark_node
);
610 tree result
= build_anonymous_node (ENUMERAL_TYPE
);
612 TYPE_PRECISION (result
) = TYPE_PRECISION (underlying_int_type
);
613 TYPE_UNSIGNED (result
) = TYPE_UNSIGNED (underlying_int_type
);
615 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
616 return convert_out (ctx
->preserve (result
));
620 plugin_build_add_enum_constant (cc1_plugin::connection
*,
621 gcc_type enum_type_in
,
625 tree cst
, decl
, cons
;
626 tree enum_type
= convert_in (enum_type_in
);
628 gcc_assert (TREE_CODE (enum_type
) == ENUMERAL_TYPE
);
630 cst
= build_int_cst (enum_type
, value
);
631 /* Note that gdb does not preserve the location of enum constants,
632 so we can't provide a decent location here. */
633 decl
= build_decl (BUILTINS_LOCATION
, CONST_DECL
,
634 get_identifier (name
), enum_type
);
635 DECL_INITIAL (decl
) = cst
;
636 pushdecl_safe (decl
);
638 cons
= tree_cons (DECL_NAME (decl
), cst
, TYPE_VALUES (enum_type
));
639 TYPE_VALUES (enum_type
) = cons
;
645 plugin_finish_enum_type (cc1_plugin::connection
*,
646 gcc_type enum_type_in
)
648 tree enum_type
= convert_in (enum_type_in
);
649 tree minnode
, maxnode
, iter
;
651 iter
= TYPE_VALUES (enum_type
);
652 minnode
= maxnode
= TREE_VALUE (iter
);
653 for (iter
= TREE_CHAIN (iter
);
655 iter
= TREE_CHAIN (iter
))
657 tree value
= TREE_VALUE (iter
);
658 if (tree_int_cst_lt (maxnode
, value
))
660 if (tree_int_cst_lt (value
, minnode
))
663 TYPE_MIN_VALUE (enum_type
) = minnode
;
664 TYPE_MAX_VALUE (enum_type
) = maxnode
;
666 layout_type (enum_type
);
672 plugin_build_function_type (cc1_plugin::connection
*self
,
673 gcc_type return_type_in
,
674 const struct gcc_type_array
*argument_types_in
,
677 tree return_type
= convert_in (return_type_in
);
680 std::vector
<tree
> argument_types (argument_types_in
->n_elements
);
681 for (int i
= 0; i
< argument_types_in
->n_elements
; ++i
)
682 argument_types
[i
] = convert_in (argument_types_in
->elements
[i
]);
685 result
= build_varargs_function_type_array (return_type
,
686 argument_types_in
->n_elements
,
687 argument_types
.data ());
689 result
= build_function_type_array (return_type
,
690 argument_types_in
->n_elements
,
691 argument_types
.data ());
693 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
694 return convert_out (ctx
->preserve (result
));
697 /* Return a builtin type associated with BUILTIN_NAME. */
700 safe_lookup_builtin_type (const char *builtin_name
)
702 tree result
= NULL_TREE
;
707 result
= identifier_global_value (get_identifier (builtin_name
));
712 gcc_assert (TREE_CODE (result
) == TYPE_DECL
);
713 result
= TREE_TYPE (result
);
718 plugin_int_check (cc1_plugin::connection
*self
,
719 int is_unsigned
, unsigned long size_in_bytes
,
722 if (result
== NULL_TREE
)
723 result
= error_mark_node
;
726 gcc_assert (!TYPE_UNSIGNED (result
) == !is_unsigned
);
727 gcc_assert (TREE_CODE (TYPE_SIZE (result
)) == INTEGER_CST
);
728 gcc_assert (TYPE_PRECISION (result
) == BITS_PER_UNIT
* size_in_bytes
);
730 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
731 ctx
->preserve (result
);
733 return convert_out (result
);
737 plugin_int_type_v0 (cc1_plugin::connection
*self
,
738 int is_unsigned
, unsigned long size_in_bytes
)
740 tree result
= c_common_type_for_size (BITS_PER_UNIT
* size_in_bytes
,
743 return plugin_int_check (self
, is_unsigned
, size_in_bytes
, result
);
747 plugin_int_type (cc1_plugin::connection
*self
,
748 int is_unsigned
, unsigned long size_in_bytes
,
749 const char *builtin_name
)
752 return plugin_int_type_v0 (self
, is_unsigned
, size_in_bytes
);
754 tree result
= safe_lookup_builtin_type (builtin_name
);
755 gcc_assert (!result
|| TREE_CODE (result
) == INTEGER_TYPE
);
757 return plugin_int_check (self
, is_unsigned
, size_in_bytes
, result
);
761 plugin_char_type (cc1_plugin::connection
*)
763 return convert_out (char_type_node
);
767 plugin_float_type_v0 (cc1_plugin::connection
*,
768 unsigned long size_in_bytes
)
770 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (float_type_node
))
771 return convert_out (float_type_node
);
772 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (double_type_node
))
773 return convert_out (double_type_node
);
774 if (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (long_double_type_node
))
775 return convert_out (long_double_type_node
);
776 return convert_out (error_mark_node
);
780 plugin_float_type (cc1_plugin::connection
*self
,
781 unsigned long size_in_bytes
,
782 const char *builtin_name
)
785 return plugin_float_type_v0 (self
, size_in_bytes
);
787 tree result
= safe_lookup_builtin_type (builtin_name
);
790 return convert_out (error_mark_node
);
792 gcc_assert (TREE_CODE (result
) == REAL_TYPE
);
793 gcc_assert (BITS_PER_UNIT
* size_in_bytes
== TYPE_PRECISION (result
));
795 return convert_out (result
);
799 plugin_void_type (cc1_plugin::connection
*)
801 return convert_out (void_type_node
);
805 plugin_bool_type (cc1_plugin::connection
*)
807 return convert_out (boolean_type_node
);
811 plugin_build_array_type (cc1_plugin::connection
*self
,
812 gcc_type element_type_in
, int num_elements
)
814 tree element_type
= convert_in (element_type_in
);
817 if (num_elements
== -1)
818 result
= build_array_type (element_type
, NULL_TREE
);
820 result
= build_array_type_nelts (element_type
, num_elements
);
822 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
823 return convert_out (ctx
->preserve (result
));
827 plugin_build_vla_array_type (cc1_plugin::connection
*self
,
828 gcc_type element_type_in
,
829 const char *upper_bound_name
)
831 tree element_type
= convert_in (element_type_in
);
832 tree upper_bound
= lookup_name (get_identifier (upper_bound_name
));
833 tree range
= build_index_type (upper_bound
);
835 tree result
= build_array_type (element_type
, range
);
836 C_TYPE_VARIABLE_SIZE (result
) = 1;
838 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
839 return convert_out (ctx
->preserve (result
));
843 plugin_build_qualified_type (cc1_plugin::connection
*,
844 gcc_type unqualified_type_in
,
845 enum gcc_qualifiers qualifiers
)
847 tree unqualified_type
= convert_in (unqualified_type_in
);
850 if ((qualifiers
& GCC_QUALIFIER_CONST
) != 0)
851 quals
|= TYPE_QUAL_CONST
;
852 if ((qualifiers
& GCC_QUALIFIER_VOLATILE
) != 0)
853 quals
|= TYPE_QUAL_VOLATILE
;
854 if ((qualifiers
& GCC_QUALIFIER_RESTRICT
) != 0)
855 quals
|= TYPE_QUAL_RESTRICT
;
857 return convert_out (build_qualified_type (unqualified_type
, quals
));
861 plugin_build_complex_type (cc1_plugin::connection
*self
,
864 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
865 return convert_out (ctx
->preserve (build_complex_type (convert_in (base_type
))));
869 plugin_build_vector_type (cc1_plugin::connection
*self
,
870 gcc_type base_type
, int nunits
)
872 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
873 return convert_out (ctx
->preserve (build_vector_type (convert_in (base_type
),
878 plugin_build_constant (cc1_plugin::connection
*self
, gcc_type type_in
,
879 const char *name
, unsigned long value
,
880 const char *filename
, unsigned int line_number
)
882 plugin_context
*ctx
= static_cast<plugin_context
*> (self
);
884 tree type
= convert_in (type_in
);
886 cst
= build_int_cst (type
, value
);
887 decl
= build_decl (ctx
->get_location_t (filename
, line_number
),
888 CONST_DECL
, get_identifier (name
), type
);
889 DECL_INITIAL (decl
) = cst
;
890 pushdecl_safe (decl
);
896 plugin_error (cc1_plugin::connection
*,
899 error ("%s", message
);
900 return convert_out (error_mark_node
);
905 // Perform GC marking.
908 gc_mark (void *, void *)
910 if (current_context
!= NULL
)
911 current_context
->mark ();
915 #pragma GCC visibility push(default)
919 plugin_init (struct plugin_name_args
*plugin_info
,
920 struct plugin_gcc_version
*)
923 for (int i
= 0; i
< plugin_info
->argc
; ++i
)
925 if (strcmp (plugin_info
->argv
[i
].key
, "fd") == 0)
929 fd
= strtol (plugin_info
->argv
[i
].value
, &tail
, 0);
930 if (*tail
!= '\0' || errno
!= 0)
931 fatal_error (input_location
,
932 "%s: invalid file descriptor argument to plugin",
933 plugin_info
->base_name
);
938 fatal_error (input_location
,
939 "%s: required plugin argument %<fd%> is missing",
940 plugin_info
->base_name
);
942 current_context
= new plugin_context (fd
);
945 cc1_plugin::protocol_int version
;
946 if (!current_context
->require ('H')
947 || ! ::cc1_plugin::unmarshall (current_context
, &version
))
948 fatal_error (input_location
,
949 "%s: handshake failed", plugin_info
->base_name
);
950 if (version
!= GCC_C_FE_VERSION_1
)
951 fatal_error (input_location
,
952 "%s: unknown version in handshake", plugin_info
->base_name
);
954 register_callback (plugin_info
->base_name
, PLUGIN_PRAGMAS
,
955 plugin_init_extra_pragmas
, NULL
);
956 register_callback (plugin_info
->base_name
, PLUGIN_PRE_GENERICIZE
,
957 rewrite_decls_to_addresses
, NULL
);
958 register_callback (plugin_info
->base_name
, PLUGIN_GGC_MARKING
,
961 lang_hooks
.print_error_function
= plugin_print_error_function
;
963 #define GCC_METHOD0(R, N) \
965 cc1_plugin::callback_ftype *fun \
966 = cc1_plugin::callback<R, plugin_ ## N>; \
967 current_context->add_callback (# N, fun); \
969 #define GCC_METHOD1(R, N, A) \
971 cc1_plugin::callback_ftype *fun \
972 = cc1_plugin::callback<R, A, plugin_ ## N>; \
973 current_context->add_callback (# N, fun); \
975 #define GCC_METHOD2(R, N, A, B) \
977 cc1_plugin::callback_ftype *fun \
978 = cc1_plugin::callback<R, A, B, plugin_ ## N>; \
979 current_context->add_callback (# N, fun); \
981 #define GCC_METHOD3(R, N, A, B, C) \
983 cc1_plugin::callback_ftype *fun \
984 = cc1_plugin::callback<R, A, B, C, plugin_ ## N>; \
985 current_context->add_callback (# N, fun); \
987 #define GCC_METHOD4(R, N, A, B, C, D) \
989 cc1_plugin::callback_ftype *fun \
990 = cc1_plugin::callback<R, A, B, C, D, \
992 current_context->add_callback (# N, fun); \
994 #define GCC_METHOD5(R, N, A, B, C, D, E) \
996 cc1_plugin::callback_ftype *fun \
997 = cc1_plugin::callback<R, A, B, C, D, E, \
999 current_context->add_callback (# N, fun); \
1001 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
1003 cc1_plugin::callback_ftype *fun \
1004 = cc1_plugin::callback<R, A, B, C, D, E, F, G, \
1006 current_context->add_callback (# N, fun); \
1009 #include "gcc-c-fe.def"