* gcc.dg/vect/pr63605.c (dg-final): Cleanup vect tree dump.
[official-gcc.git] / libcc1 / plugin.cc
blob7b5df1d24fa551da1db99bf74ce79e0527511e20
1 /* Library interface to C front end
2 Copyright (C) 2014 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
9 version.
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
14 for more details.
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>
22 #undef PACKAGE_NAME
23 #undef PACKAGE_STRING
24 #undef PACKAGE_TARNAME
25 #undef PACKAGE_VERSION
27 #include "../gcc/config.h"
29 #undef PACKAGE_NAME
30 #undef PACKAGE_STRING
31 #undef PACKAGE_TARNAME
32 #undef PACKAGE_VERSION
34 #include "gcc-plugin.h"
35 #include "system.h"
36 #include "coretypes.h"
37 #include "stringpool.h"
39 #include "gcc-interface.h"
40 #include "tree-core.h"
41 #include "wide-int.h"
42 #include "stor-layout.h"
43 #include "c-tree.h"
44 #include "toplev.h"
45 #include "timevar.h"
46 #include "hash-table.h"
47 #include "tm.h"
48 #include "c-family/c-pragma.h"
49 #include "c-lang.h"
50 #include "diagnostic.h"
51 #include "langhooks.h"
52 #include "langhooks-def.h"
54 #include "callbacks.hh"
55 #include "connection.hh"
56 #include "rpc.hh"
58 #ifdef __GNUC__
59 #pragma GCC visibility push(default)
60 #endif
61 int plugin_is_GPL_compatible;
62 #ifdef __GNUC__
63 #pragma GCC visibility pop
64 #endif
68 // This is put into the lang hooks when the plugin starts.
70 static void
71 plugin_print_error_function (diagnostic_context *context, const char *file,
72 diagnostic_info *diagnostic)
74 if (current_function_decl != NULL_TREE
75 && DECL_NAME (current_function_decl) != NULL_TREE
76 && strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
77 GCC_FE_WRAPPER_FUNCTION) == 0)
78 return;
79 lhd_print_error_function (context, file, diagnostic);
84 static unsigned long long
85 convert_out (tree t)
87 return (unsigned long long) (uintptr_t) t;
90 static tree
91 convert_in (unsigned long long v)
93 return (tree) (uintptr_t) v;
98 struct decl_addr_value
100 tree decl;
101 tree address;
104 struct decl_addr_hasher : typed_free_remove<decl_addr_value>
106 typedef decl_addr_value value_type;
107 typedef decl_addr_value compare_type;
109 static inline hashval_t hash (const value_type *);
110 static inline bool equal (const value_type *, const compare_type *);
113 inline hashval_t
114 decl_addr_hasher::hash (const value_type *e)
116 return IDENTIFIER_HASH_VALUE (DECL_NAME (e->decl));
119 inline bool
120 decl_addr_hasher::equal (const value_type *p1, const compare_type *p2)
122 return p1->decl == p2->decl;
127 struct string_hasher : typed_noop_remove<char>
129 typedef char value_type;
130 typedef char compare_type;
132 static inline hashval_t hash (const value_type *s)
134 return htab_hash_string (s);
137 static inline bool equal (const value_type *p1, const value_type *p2)
139 return strcmp (p1, p2) == 0;
145 // A wrapper for pushdecl that doesn't let gdb have a chance to
146 // instantiate a symbol.
148 static void
149 pushdecl_safe (tree decl)
151 void (*save) (enum c_oracle_request, tree identifier);
153 save = c_binding_oracle;
154 c_binding_oracle = NULL;
155 pushdecl (decl);
156 c_binding_oracle = save;
161 struct plugin_context : public cc1_plugin::connection
163 plugin_context (int fd);
165 // Map decls to addresses.
166 hash_table<decl_addr_hasher> address_map;
168 // A collection of trees that are preserved for the GC.
169 hash_table< pointer_hash<tree_node> > preserved;
171 // File name cache.
172 hash_table<string_hasher> file_names;
174 // Perform GC marking.
175 void mark ();
177 // Preserve a tree during the plugin's operation.
178 tree preserve (tree t)
180 tree_node **slot = preserved.find_slot (t, INSERT);
181 *slot = t;
182 return t;
185 source_location get_source_location (const char *filename,
186 unsigned int line_number)
188 if (filename == NULL)
189 return UNKNOWN_LOCATION;
191 filename = intern_filename (filename);
192 linemap_add (line_table, LC_ENTER, false, filename, line_number);
193 source_location loc = linemap_line_start (line_table, line_number, 0);
194 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
195 return loc;
198 private:
200 // Add a file name to FILE_NAMES and return the canonical copy.
201 const char *intern_filename (const char *filename)
203 char **slot = file_names.find_slot (filename, INSERT);
204 if (*slot == NULL)
206 /* The file name must live as long as the line map, which
207 effectively means as long as this compilation. So, we copy
208 the string here but never free it. */
209 *slot = xstrdup (filename);
211 return *slot;
215 static plugin_context *current_context;
219 plugin_context::plugin_context (int fd)
220 : cc1_plugin::connection (fd),
221 address_map (30),
222 preserved (30),
223 file_names (30)
227 void
228 plugin_context::mark ()
230 for (hash_table<decl_addr_hasher>::iterator it = address_map.begin ();
231 it != address_map.end ();
232 ++it)
234 ggc_mark ((*it)->decl);
235 ggc_mark ((*it)->address);
238 for (hash_table< pointer_hash<tree_node> >::iterator it = preserved.begin ();
239 it != preserved.end ();
240 ++it)
241 ggc_mark (&*it);
244 static void
245 plugin_binding_oracle (enum c_oracle_request kind, tree identifier)
247 enum gcc_c_oracle_request request;
249 gcc_assert (current_context != NULL);
251 switch (kind)
253 case C_ORACLE_SYMBOL:
254 request = GCC_C_ORACLE_SYMBOL;
255 break;
256 case C_ORACLE_TAG:
257 request = GCC_C_ORACLE_TAG;
258 break;
259 case C_ORACLE_LABEL:
260 request = GCC_C_ORACLE_LABEL;
261 break;
262 default:
263 abort ();
266 int ignore;
267 cc1_plugin::call (current_context, "binding_oracle", &ignore,
268 request, IDENTIFIER_POINTER (identifier));
271 static void
272 plugin_pragma_user_expression (cpp_reader *)
274 c_binding_oracle = plugin_binding_oracle;
277 static void
278 plugin_init_extra_pragmas (void *, void *)
280 c_register_pragma ("GCC", "user_expression", plugin_pragma_user_expression);
285 // Maybe rewrite a decl to its address.
286 static tree
287 address_rewriter (tree *in, int *walk_subtrees, void *arg)
289 plugin_context *ctx = (plugin_context *) arg;
291 if (!DECL_P (*in) || DECL_NAME (*in) == NULL_TREE)
292 return NULL_TREE;
294 decl_addr_value value;
295 value.decl = *in;
296 decl_addr_value *found_value = ctx->address_map.find (&value);
297 if (found_value != NULL)
299 // At this point we don't need VLA sizes for gdb-supplied
300 // variables, and having them here confuses later passes, so we
301 // drop them.
302 if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (*in)))
304 TREE_TYPE (*in)
305 = build_array_type_nelts (TREE_TYPE (TREE_TYPE (*in)), 1);
306 DECL_SIZE (*in) = TYPE_SIZE (TREE_TYPE (*in));
307 DECL_SIZE_UNIT (*in) = TYPE_SIZE_UNIT (TREE_TYPE (*in));
310 else if (DECL_IS_BUILTIN (*in))
312 gcc_address address;
314 if (!cc1_plugin::call (ctx, "address_oracle", &address,
315 IDENTIFIER_POINTER (DECL_NAME (*in))))
316 return NULL_TREE;
317 if (address == 0)
318 return NULL_TREE;
320 // Insert the decl into the address map in case it is referenced
321 // again.
322 value.address = build_int_cst_type (ptr_type_node, address);
323 decl_addr_value **slot = ctx->address_map.find_slot (&value, INSERT);
324 gcc_assert (*slot == NULL);
325 *slot
326 = static_cast<decl_addr_value *> (xmalloc (sizeof (decl_addr_value)));
327 **slot = value;
328 found_value = *slot;
330 else
331 return NULL_TREE;
333 if (found_value->address != error_mark_node)
335 // We have an address for the decl, so rewrite the tree.
336 tree ptr_type = build_pointer_type (TREE_TYPE (*in));
337 *in = fold_build1 (INDIRECT_REF, TREE_TYPE (*in),
338 fold_build1 (CONVERT_EXPR, ptr_type,
339 found_value->address));
342 *walk_subtrees = 0;
344 return NULL_TREE;
347 // When generating code for gdb, we want to be able to use absolute
348 // addresses to refer to otherwise external objects that gdb knows
349 // about. gdb passes in these addresses when building decls, and then
350 // before gimplification we go through the trees, rewriting uses to
351 // the equivalent of "*(TYPE *) ADDR".
352 static void
353 rewrite_decls_to_addresses (void *function_in, void *)
355 tree function = (tree) function_in;
357 // Do nothing if we're not in gdb.
358 if (current_context == NULL)
359 return;
361 walk_tree (&DECL_SAVED_TREE (function), address_rewriter, current_context,
362 NULL);
367 gcc_decl
368 plugin_build_decl (cc1_plugin::connection *self,
369 const char *name,
370 enum gcc_c_symbol_kind sym_kind,
371 gcc_type sym_type_in,
372 const char *substitution_name,
373 gcc_address address,
374 const char *filename,
375 unsigned int line_number)
377 plugin_context *ctx = static_cast<plugin_context *> (self);
378 tree identifier = get_identifier (name);
379 enum tree_code code;
380 tree decl;
381 tree sym_type = convert_in (sym_type_in);
383 switch (sym_kind)
385 case GCC_C_SYMBOL_FUNCTION:
386 code = FUNCTION_DECL;
387 break;
389 case GCC_C_SYMBOL_VARIABLE:
390 code = VAR_DECL;
391 break;
393 case GCC_C_SYMBOL_TYPEDEF:
394 code = TYPE_DECL;
395 break;
397 case GCC_C_SYMBOL_LABEL:
398 // FIXME: we aren't ready to handle labels yet.
399 // It isn't clear how to translate them properly
400 // and in any case a "goto" isn't likely to work.
401 return convert_out (error_mark_node);
403 default:
404 abort ();
407 source_location loc = ctx->get_source_location (filename, line_number);
409 decl = build_decl (loc, code, identifier, sym_type);
410 TREE_USED (decl) = 1;
411 TREE_ADDRESSABLE (decl) = 1;
413 if (sym_kind != GCC_C_SYMBOL_TYPEDEF)
415 decl_addr_value value;
417 value.decl = decl;
418 if (substitution_name != NULL)
420 // If the translator gave us a name without a binding,
421 // we can just substitute error_mark_node, since we know the
422 // translator will be reporting an error anyhow.
423 value.address
424 = lookup_name (get_identifier (substitution_name));
425 if (value.address == NULL_TREE)
426 value.address = error_mark_node;
428 else
429 value.address = build_int_cst_type (ptr_type_node, address);
430 decl_addr_value **slot = ctx->address_map.find_slot (&value, INSERT);
431 gcc_assert (*slot == NULL);
432 *slot
433 = static_cast<decl_addr_value *> (xmalloc (sizeof (decl_addr_value)));
434 **slot = value;
437 return convert_out (ctx->preserve (decl));
441 plugin_bind (cc1_plugin::connection *,
442 gcc_decl decl_in, int is_global)
444 tree decl = convert_in (decl_in);
445 c_bind (DECL_SOURCE_LOCATION (decl), decl, is_global);
446 rest_of_decl_compilation (decl, is_global, 0);
447 return 1;
451 plugin_tagbind (cc1_plugin::connection *self,
452 const char *name, gcc_type tagged_type,
453 const char *filename, unsigned int line_number)
455 plugin_context *ctx = static_cast<plugin_context *> (self);
456 c_pushtag (ctx->get_source_location (filename, line_number),
457 get_identifier (name), convert_in (tagged_type));
458 return 1;
461 gcc_type
462 plugin_build_pointer_type (cc1_plugin::connection *,
463 gcc_type base_type)
465 // No need to preserve a pointer type as the base type is preserved.
466 return convert_out (build_pointer_type (convert_in (base_type)));
469 gcc_type
470 plugin_build_record_type (cc1_plugin::connection *self)
472 plugin_context *ctx = static_cast<plugin_context *> (self);
473 return convert_out (ctx->preserve (make_node (RECORD_TYPE)));
476 gcc_type
477 plugin_build_union_type (cc1_plugin::connection *self)
479 plugin_context *ctx = static_cast<plugin_context *> (self);
480 return convert_out (ctx->preserve (make_node (UNION_TYPE)));
484 plugin_build_add_field (cc1_plugin::connection *,
485 gcc_type record_or_union_type_in,
486 const char *field_name,
487 gcc_type field_type_in,
488 unsigned long bitsize,
489 unsigned long bitpos)
491 tree record_or_union_type = convert_in (record_or_union_type_in);
492 tree field_type = convert_in (field_type_in);
494 gcc_assert (TREE_CODE (record_or_union_type) == RECORD_TYPE
495 || TREE_CODE (record_or_union_type) == UNION_TYPE);
497 /* Note that gdb does not preserve the location of field decls, so
498 we can't provide a decent location here. */
499 tree decl = build_decl (BUILTINS_LOCATION, FIELD_DECL,
500 get_identifier (field_name), field_type);
501 DECL_FIELD_CONTEXT (decl) = record_or_union_type;
503 if (TREE_CODE (field_type) == INTEGER_TYPE
504 && TYPE_PRECISION (field_type) != bitsize)
506 DECL_BIT_FIELD_TYPE (decl) = field_type;
507 TREE_TYPE (decl)
508 = c_build_bitfield_integer_type (bitsize, TYPE_UNSIGNED (field_type));
511 DECL_MODE (decl) = TYPE_MODE (TREE_TYPE (decl));
513 // There's no way to recover this from DWARF.
514 SET_DECL_OFFSET_ALIGN (decl, TYPE_PRECISION (pointer_sized_int_node));
516 tree pos = bitsize_int (bitpos);
517 pos_from_bit (&DECL_FIELD_OFFSET (decl), &DECL_FIELD_BIT_OFFSET (decl),
518 DECL_OFFSET_ALIGN (decl), pos);
520 DECL_SIZE (decl) = bitsize_int (bitsize);
521 DECL_SIZE_UNIT (decl) = size_int ((bitsize + BITS_PER_UNIT - 1)
522 / BITS_PER_UNIT);
524 DECL_CHAIN (decl) = TYPE_FIELDS (record_or_union_type);
525 TYPE_FIELDS (record_or_union_type) = decl;
527 return 1;
531 plugin_finish_record_or_union (cc1_plugin::connection *,
532 gcc_type record_or_union_type_in,
533 unsigned long size_in_bytes)
535 tree record_or_union_type = convert_in (record_or_union_type_in);
537 gcc_assert (TREE_CODE (record_or_union_type) == RECORD_TYPE
538 || TREE_CODE (record_or_union_type) == UNION_TYPE);
540 /* We built the field list in reverse order, so fix it now. */
541 TYPE_FIELDS (record_or_union_type)
542 = nreverse (TYPE_FIELDS (record_or_union_type));
544 if (TREE_CODE (record_or_union_type) == UNION_TYPE)
546 /* Unions can just be handled by the generic code. */
547 layout_type (record_or_union_type);
549 else
551 // FIXME there's no way to get this from DWARF,
552 // or even, it seems, a particularly good way to deduce it.
553 TYPE_ALIGN (record_or_union_type)
554 = TYPE_PRECISION (pointer_sized_int_node);
556 TYPE_SIZE (record_or_union_type) = bitsize_int (size_in_bytes
557 * BITS_PER_UNIT);
558 TYPE_SIZE_UNIT (record_or_union_type) = size_int (size_in_bytes);
560 compute_record_mode (record_or_union_type);
561 finish_bitfield_layout (record_or_union_type);
562 // FIXME we have no idea about TYPE_PACKED
565 return 1;
568 gcc_type
569 plugin_build_enum_type (cc1_plugin::connection *self,
570 gcc_type underlying_int_type_in)
572 tree underlying_int_type = convert_in (underlying_int_type_in);
574 if (underlying_int_type == error_mark_node)
575 return convert_out (error_mark_node);
577 tree result = make_node (ENUMERAL_TYPE);
579 TYPE_PRECISION (result) = TYPE_PRECISION (underlying_int_type);
580 TYPE_UNSIGNED (result) = TYPE_UNSIGNED (underlying_int_type);
582 plugin_context *ctx = static_cast<plugin_context *> (self);
583 return convert_out (ctx->preserve (result));
587 plugin_build_add_enum_constant (cc1_plugin::connection *,
588 gcc_type enum_type_in,
589 const char *name,
590 unsigned long value)
592 tree cst, decl, cons;
593 tree enum_type = convert_in (enum_type_in);
595 gcc_assert (TREE_CODE (enum_type) == ENUMERAL_TYPE);
597 cst = build_int_cst (enum_type, value);
598 /* Note that gdb does not preserve the location of enum constants,
599 so we can't provide a decent location here. */
600 decl = build_decl (BUILTINS_LOCATION, CONST_DECL,
601 get_identifier (name), enum_type);
602 DECL_INITIAL (decl) = cst;
603 pushdecl_safe (decl);
605 cons = tree_cons (DECL_NAME (decl), cst, TYPE_VALUES (enum_type));
606 TYPE_VALUES (enum_type) = cons;
608 return 1;
612 plugin_finish_enum_type (cc1_plugin::connection *,
613 gcc_type enum_type_in)
615 tree enum_type = convert_in (enum_type_in);
616 tree minnode, maxnode, iter;
618 iter = TYPE_VALUES (enum_type);
619 minnode = maxnode = TREE_VALUE (iter);
620 for (iter = TREE_CHAIN (iter);
621 iter != NULL_TREE;
622 iter = TREE_CHAIN (iter))
624 tree value = TREE_VALUE (iter);
625 if (tree_int_cst_lt (maxnode, value))
626 maxnode = value;
627 if (tree_int_cst_lt (value, minnode))
628 minnode = value;
630 TYPE_MIN_VALUE (enum_type) = minnode;
631 TYPE_MAX_VALUE (enum_type) = maxnode;
633 layout_type (enum_type);
635 return 1;
638 gcc_type
639 plugin_build_function_type (cc1_plugin::connection *self,
640 gcc_type return_type_in,
641 const struct gcc_type_array *argument_types_in,
642 int is_varargs)
644 tree *argument_types;
645 tree return_type = convert_in (return_type_in);
646 tree result;
648 argument_types = new tree[argument_types_in->n_elements];
649 for (int i = 0; i < argument_types_in->n_elements; ++i)
650 argument_types[i] = convert_in (argument_types_in->elements[i]);
652 if (is_varargs)
653 result = build_varargs_function_type_array (return_type,
654 argument_types_in->n_elements,
655 argument_types);
656 else
657 result = build_function_type_array (return_type,
658 argument_types_in->n_elements,
659 argument_types);
661 delete[] argument_types;
663 plugin_context *ctx = static_cast<plugin_context *> (self);
664 return convert_out (ctx->preserve (result));
667 gcc_type
668 plugin_int_type (cc1_plugin::connection *self,
669 int is_unsigned, unsigned long size_in_bytes)
671 tree result = c_common_type_for_size (BITS_PER_UNIT * size_in_bytes,
672 is_unsigned);
673 if (result == NULL_TREE)
674 result = error_mark_node;
675 else
677 plugin_context *ctx = static_cast<plugin_context *> (self);
678 ctx->preserve (result);
680 return convert_out (result);
683 gcc_type
684 plugin_float_type (cc1_plugin::connection *,
685 unsigned long size_in_bytes)
687 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (float_type_node))
688 return convert_out (float_type_node);
689 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (double_type_node))
690 return convert_out (double_type_node);
691 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (long_double_type_node))
692 return convert_out (long_double_type_node);
693 return convert_out (error_mark_node);
696 gcc_type
697 plugin_void_type (cc1_plugin::connection *)
699 return convert_out (void_type_node);
702 gcc_type
703 plugin_bool_type (cc1_plugin::connection *)
705 return convert_out (boolean_type_node);
708 gcc_type
709 plugin_build_array_type (cc1_plugin::connection *self,
710 gcc_type element_type_in, int num_elements)
712 tree element_type = convert_in (element_type_in);
713 tree result;
715 if (num_elements == -1)
716 result = build_array_type (element_type, NULL_TREE);
717 else
718 result = build_array_type_nelts (element_type, num_elements);
720 plugin_context *ctx = static_cast<plugin_context *> (self);
721 return convert_out (ctx->preserve (result));
724 gcc_type
725 plugin_build_vla_array_type (cc1_plugin::connection *self,
726 gcc_type element_type_in,
727 const char *upper_bound_name)
729 tree element_type = convert_in (element_type_in);
730 tree upper_bound = lookup_name (get_identifier (upper_bound_name));
731 tree range = build_index_type (upper_bound);
733 tree result = build_array_type (element_type, range);
734 C_TYPE_VARIABLE_SIZE (result) = 1;
736 plugin_context *ctx = static_cast<plugin_context *> (self);
737 return convert_out (ctx->preserve (result));
740 gcc_type
741 plugin_build_qualified_type (cc1_plugin::connection *,
742 gcc_type unqualified_type_in,
743 enum gcc_qualifiers qualifiers)
745 tree unqualified_type = convert_in (unqualified_type_in);
746 int quals = 0;
748 if ((qualifiers & GCC_QUALIFIER_CONST) != 0)
749 quals |= TYPE_QUAL_CONST;
750 if ((qualifiers & GCC_QUALIFIER_VOLATILE) != 0)
751 quals |= TYPE_QUAL_VOLATILE;
752 if ((qualifiers & GCC_QUALIFIER_RESTRICT) != 0)
753 quals |= TYPE_QUAL_RESTRICT;
755 return convert_out (build_qualified_type (unqualified_type, quals));
758 gcc_type
759 plugin_build_complex_type (cc1_plugin::connection *self,
760 gcc_type base_type)
762 plugin_context *ctx = static_cast<plugin_context *> (self);
763 return convert_out (ctx->preserve (build_complex_type (convert_in (base_type))));
766 gcc_type
767 plugin_build_vector_type (cc1_plugin::connection *self,
768 gcc_type base_type, int nunits)
770 plugin_context *ctx = static_cast<plugin_context *> (self);
771 return convert_out (ctx->preserve (build_vector_type (convert_in (base_type),
772 nunits)));
776 plugin_build_constant (cc1_plugin::connection *self, gcc_type type_in,
777 const char *name, unsigned long value,
778 const char *filename, unsigned int line_number)
780 plugin_context *ctx = static_cast<plugin_context *> (self);
781 tree cst, decl;
782 tree type = convert_in (type_in);
784 cst = build_int_cst (type, value);
785 decl = build_decl (ctx->get_source_location (filename, line_number),
786 CONST_DECL, get_identifier (name), type);
787 DECL_INITIAL (decl) = cst;
788 pushdecl_safe (decl);
790 return 1;
793 gcc_type
794 plugin_error (cc1_plugin::connection *,
795 const char *message)
797 error ("%s", message);
798 return convert_out (error_mark_node);
803 // Perform GC marking.
805 static void
806 gc_mark (void *, void *)
808 if (current_context != NULL)
809 current_context->mark ();
812 #ifdef __GNUC__
813 #pragma GCC visibility push(default)
814 #endif
817 plugin_init (struct plugin_name_args *plugin_info,
818 struct plugin_gcc_version *)
820 long fd = -1;
821 for (int i = 0; i < plugin_info->argc; ++i)
823 if (strcmp (plugin_info->argv[i].key, "fd") == 0)
825 char *tail;
826 errno = 0;
827 fd = strtol (plugin_info->argv[i].value, &tail, 0);
828 if (*tail != '\0' || errno != 0)
829 fatal_error ("%s: invalid file descriptor argument to plugin",
830 plugin_info->base_name);
831 break;
834 if (fd == -1)
835 fatal_error ("%s: required plugin argument %<fd%> is missing",
836 plugin_info->base_name);
838 current_context = new plugin_context (fd);
840 // Handshake.
841 cc1_plugin::protocol_int version;
842 if (!current_context->require ('H')
843 || ! ::cc1_plugin::unmarshall (current_context, &version))
844 fatal_error ("%s: handshake failed", plugin_info->base_name);
845 if (version != GCC_C_FE_VERSION_0)
846 fatal_error ("%s: unknown version in handshake", plugin_info->base_name);
848 register_callback (plugin_info->base_name, PLUGIN_PRAGMAS,
849 plugin_init_extra_pragmas, NULL);
850 register_callback (plugin_info->base_name, PLUGIN_PRE_GENERICIZE,
851 rewrite_decls_to_addresses, NULL);
852 register_callback (plugin_info->base_name, PLUGIN_GGC_MARKING,
853 gc_mark, NULL);
855 lang_hooks.print_error_function = plugin_print_error_function;
857 #define GCC_METHOD0(R, N) \
859 cc1_plugin::callback_ftype *fun \
860 = cc1_plugin::callback<R, plugin_ ## N>; \
861 current_context->add_callback (# N, fun); \
863 #define GCC_METHOD1(R, N, A) \
865 cc1_plugin::callback_ftype *fun \
866 = cc1_plugin::callback<R, A, plugin_ ## N>; \
867 current_context->add_callback (# N, fun); \
869 #define GCC_METHOD2(R, N, A, B) \
871 cc1_plugin::callback_ftype *fun \
872 = cc1_plugin::callback<R, A, B, plugin_ ## N>; \
873 current_context->add_callback (# N, fun); \
875 #define GCC_METHOD3(R, N, A, B, C) \
877 cc1_plugin::callback_ftype *fun \
878 = cc1_plugin::callback<R, A, B, C, plugin_ ## N>; \
879 current_context->add_callback (# N, fun); \
881 #define GCC_METHOD4(R, N, A, B, C, D) \
883 cc1_plugin::callback_ftype *fun \
884 = cc1_plugin::callback<R, A, B, C, D, \
885 plugin_ ## N>; \
886 current_context->add_callback (# N, fun); \
888 #define GCC_METHOD5(R, N, A, B, C, D, E) \
890 cc1_plugin::callback_ftype *fun \
891 = cc1_plugin::callback<R, A, B, C, D, E, \
892 plugin_ ## N>; \
893 current_context->add_callback (# N, fun); \
895 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
897 cc1_plugin::callback_ftype *fun \
898 = cc1_plugin::callback<R, A, B, C, D, E, F, G, \
899 plugin_ ## N>; \
900 current_context->add_callback (# N, fun); \
903 #include "gcc-c-fe.def"
905 #undef GCC_METHOD0
906 #undef GCC_METHOD1
907 #undef GCC_METHOD2
908 #undef GCC_METHOD3
909 #undef GCC_METHOD4
910 #undef GCC_METHOD5
911 #undef GCC_METHOD7
913 return 0;