* c-c++-common/ubsan/float-cast-overflow-6.c: Add i?86-*-* target.
[official-gcc.git] / libcc1 / plugin.cc
blob5cdd19d78ceb3155bf6d818ebcb6a194e99cddca
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 #include <string>
60 #ifdef __GNUC__
61 #pragma GCC visibility push(default)
62 #endif
63 int plugin_is_GPL_compatible;
64 #ifdef __GNUC__
65 #pragma GCC visibility pop
66 #endif
70 // This is put into the lang hooks when the plugin starts.
72 static void
73 plugin_print_error_function (diagnostic_context *context, const char *file,
74 diagnostic_info *diagnostic)
76 if (current_function_decl != NULL_TREE
77 && DECL_NAME (current_function_decl) != NULL_TREE
78 && strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
79 GCC_FE_WRAPPER_FUNCTION) == 0)
80 return;
81 lhd_print_error_function (context, file, diagnostic);
86 static unsigned long long
87 convert_out (tree t)
89 return (unsigned long long) (uintptr_t) t;
92 static tree
93 convert_in (unsigned long long v)
95 return (tree) (uintptr_t) v;
100 struct decl_addr_value
102 tree decl;
103 tree address;
106 struct decl_addr_hasher : typed_free_remove<decl_addr_value>
108 typedef decl_addr_value value_type;
109 typedef decl_addr_value compare_type;
111 static inline hashval_t hash (const value_type *);
112 static inline bool equal (const value_type *, const compare_type *);
115 inline hashval_t
116 decl_addr_hasher::hash (const value_type *e)
118 return IDENTIFIER_HASH_VALUE (DECL_NAME (e->decl));
121 inline bool
122 decl_addr_hasher::equal (const value_type *p1, const compare_type *p2)
124 return p1->decl == p2->decl;
129 struct string_hasher : typed_noop_remove<char>
131 typedef char value_type;
132 typedef char compare_type;
134 static inline hashval_t hash (const value_type *s)
136 return htab_hash_string (s);
139 static inline bool equal (const value_type *p1, const value_type *p2)
141 return strcmp (p1, p2) == 0;
147 // A wrapper for pushdecl that doesn't let gdb have a chance to
148 // instantiate a symbol.
150 static void
151 pushdecl_safe (tree decl)
153 void (*save) (enum c_oracle_request, tree identifier);
155 save = c_binding_oracle;
156 c_binding_oracle = NULL;
157 pushdecl (decl);
158 c_binding_oracle = save;
163 struct plugin_context : public cc1_plugin::connection
165 plugin_context (int fd);
167 // Map decls to addresses.
168 hash_table<decl_addr_hasher> address_map;
170 // A collection of trees that are preserved for the GC.
171 hash_table< pointer_hash<tree_node> > preserved;
173 // File name cache.
174 hash_table<string_hasher> file_names;
176 // Perform GC marking.
177 void mark ();
179 // Preserve a tree during the plugin's operation.
180 tree preserve (tree t)
182 tree_node **slot = preserved.find_slot (t, INSERT);
183 *slot = t;
184 return t;
187 source_location get_source_location (const char *filename,
188 unsigned int line_number)
190 if (filename == NULL)
191 return UNKNOWN_LOCATION;
193 filename = intern_filename (filename);
194 linemap_add (line_table, LC_ENTER, false, filename, line_number);
195 source_location loc = linemap_line_start (line_table, line_number, 0);
196 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
197 return loc;
200 private:
202 // Add a file name to FILE_NAMES and return the canonical copy.
203 const char *intern_filename (const char *filename)
205 char **slot = file_names.find_slot (filename, INSERT);
206 if (*slot == NULL)
208 /* The file name must live as long as the line map, which
209 effectively means as long as this compilation. So, we copy
210 the string here but never free it. */
211 *slot = xstrdup (filename);
213 return *slot;
217 static plugin_context *current_context;
221 plugin_context::plugin_context (int fd)
222 : cc1_plugin::connection (fd),
223 address_map (30),
224 preserved (30),
225 file_names (30)
229 void
230 plugin_context::mark ()
232 for (hash_table<decl_addr_hasher>::iterator it = address_map.begin ();
233 it != address_map.end ();
234 ++it)
236 ggc_mark ((*it)->decl);
237 ggc_mark ((*it)->address);
240 for (hash_table< pointer_hash<tree_node> >::iterator it = preserved.begin ();
241 it != preserved.end ();
242 ++it)
243 ggc_mark (&*it);
246 static void
247 plugin_binding_oracle (enum c_oracle_request kind, tree identifier)
249 enum gcc_c_oracle_request request;
251 gcc_assert (current_context != NULL);
253 switch (kind)
255 case C_ORACLE_SYMBOL:
256 request = GCC_C_ORACLE_SYMBOL;
257 break;
258 case C_ORACLE_TAG:
259 request = GCC_C_ORACLE_TAG;
260 break;
261 case C_ORACLE_LABEL:
262 request = GCC_C_ORACLE_LABEL;
263 break;
264 default:
265 abort ();
268 int ignore;
269 cc1_plugin::call (current_context, "binding_oracle", &ignore,
270 request, IDENTIFIER_POINTER (identifier));
273 static void
274 plugin_pragma_user_expression (cpp_reader *)
276 c_binding_oracle = plugin_binding_oracle;
279 static void
280 plugin_init_extra_pragmas (void *, void *)
282 c_register_pragma ("GCC", "user_expression", plugin_pragma_user_expression);
287 // Maybe rewrite a decl to its address.
288 static tree
289 address_rewriter (tree *in, int *walk_subtrees, void *arg)
291 plugin_context *ctx = (plugin_context *) arg;
293 if (!DECL_P (*in) || DECL_NAME (*in) == NULL_TREE)
294 return NULL_TREE;
296 decl_addr_value value;
297 value.decl = *in;
298 decl_addr_value *found_value = ctx->address_map.find (&value);
299 if (found_value != NULL)
301 // At this point we don't need VLA sizes for gdb-supplied
302 // variables, and having them here confuses later passes, so we
303 // drop them.
304 if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (*in)))
306 TREE_TYPE (*in)
307 = build_array_type_nelts (TREE_TYPE (TREE_TYPE (*in)), 1);
308 DECL_SIZE (*in) = TYPE_SIZE (TREE_TYPE (*in));
309 DECL_SIZE_UNIT (*in) = TYPE_SIZE_UNIT (TREE_TYPE (*in));
312 else if (DECL_IS_BUILTIN (*in))
314 gcc_address address;
316 if (!cc1_plugin::call (ctx, "address_oracle", &address,
317 IDENTIFIER_POINTER (DECL_NAME (*in))))
318 return NULL_TREE;
319 if (address == 0)
320 return NULL_TREE;
322 // Insert the decl into the address map in case it is referenced
323 // again.
324 value.address = build_int_cst_type (ptr_type_node, address);
325 decl_addr_value **slot = ctx->address_map.find_slot (&value, INSERT);
326 gcc_assert (*slot == NULL);
327 *slot
328 = static_cast<decl_addr_value *> (xmalloc (sizeof (decl_addr_value)));
329 **slot = value;
330 found_value = *slot;
332 else
333 return NULL_TREE;
335 if (found_value->address != error_mark_node)
337 // We have an address for the decl, so rewrite the tree.
338 tree ptr_type = build_pointer_type (TREE_TYPE (*in));
339 *in = fold_build1 (INDIRECT_REF, TREE_TYPE (*in),
340 fold_build1 (CONVERT_EXPR, ptr_type,
341 found_value->address));
344 *walk_subtrees = 0;
346 return NULL_TREE;
349 // When generating code for gdb, we want to be able to use absolute
350 // addresses to refer to otherwise external objects that gdb knows
351 // about. gdb passes in these addresses when building decls, and then
352 // before gimplification we go through the trees, rewriting uses to
353 // the equivalent of "*(TYPE *) ADDR".
354 static void
355 rewrite_decls_to_addresses (void *function_in, void *)
357 tree function = (tree) function_in;
359 // Do nothing if we're not in gdb.
360 if (current_context == NULL)
361 return;
363 walk_tree (&DECL_SAVED_TREE (function), address_rewriter, current_context,
364 NULL);
369 gcc_decl
370 plugin_build_decl (cc1_plugin::connection *self,
371 const char *name,
372 enum gcc_c_symbol_kind sym_kind,
373 gcc_type sym_type_in,
374 const char *substitution_name,
375 gcc_address address,
376 const char *filename,
377 unsigned int line_number)
379 plugin_context *ctx = static_cast<plugin_context *> (self);
380 tree identifier = get_identifier (name);
381 enum tree_code code;
382 tree decl;
383 tree sym_type = convert_in (sym_type_in);
385 switch (sym_kind)
387 case GCC_C_SYMBOL_FUNCTION:
388 code = FUNCTION_DECL;
389 break;
391 case GCC_C_SYMBOL_VARIABLE:
392 code = VAR_DECL;
393 break;
395 case GCC_C_SYMBOL_TYPEDEF:
396 code = TYPE_DECL;
397 break;
399 case GCC_C_SYMBOL_LABEL:
400 // FIXME: we aren't ready to handle labels yet.
401 // It isn't clear how to translate them properly
402 // and in any case a "goto" isn't likely to work.
403 return convert_out (error_mark_node);
405 default:
406 abort ();
409 source_location loc = ctx->get_source_location (filename, line_number);
411 decl = build_decl (loc, code, identifier, sym_type);
412 TREE_USED (decl) = 1;
413 TREE_ADDRESSABLE (decl) = 1;
415 if (sym_kind != GCC_C_SYMBOL_TYPEDEF)
417 decl_addr_value value;
419 value.decl = decl;
420 if (substitution_name != NULL)
422 // If the translator gave us a name without a binding,
423 // we can just substitute error_mark_node, since we know the
424 // translator will be reporting an error anyhow.
425 value.address
426 = lookup_name (get_identifier (substitution_name));
427 if (value.address == NULL_TREE)
428 value.address = error_mark_node;
430 else
431 value.address = build_int_cst_type (ptr_type_node, address);
432 decl_addr_value **slot = ctx->address_map.find_slot (&value, INSERT);
433 gcc_assert (*slot == NULL);
434 *slot
435 = static_cast<decl_addr_value *> (xmalloc (sizeof (decl_addr_value)));
436 **slot = value;
439 return convert_out (ctx->preserve (decl));
443 plugin_bind (cc1_plugin::connection *,
444 gcc_decl decl_in, int is_global)
446 tree decl = convert_in (decl_in);
447 c_bind (DECL_SOURCE_LOCATION (decl), decl, is_global);
448 rest_of_decl_compilation (decl, is_global, 0);
449 return 1;
453 plugin_tagbind (cc1_plugin::connection *self,
454 const char *name, gcc_type tagged_type,
455 const char *filename, unsigned int line_number)
457 plugin_context *ctx = static_cast<plugin_context *> (self);
458 c_pushtag (ctx->get_source_location (filename, line_number),
459 get_identifier (name), convert_in (tagged_type));
460 return 1;
463 gcc_type
464 plugin_build_pointer_type (cc1_plugin::connection *,
465 gcc_type base_type)
467 // No need to preserve a pointer type as the base type is preserved.
468 return convert_out (build_pointer_type (convert_in (base_type)));
471 gcc_type
472 plugin_build_record_type (cc1_plugin::connection *self)
474 plugin_context *ctx = static_cast<plugin_context *> (self);
475 return convert_out (ctx->preserve (make_node (RECORD_TYPE)));
478 gcc_type
479 plugin_build_union_type (cc1_plugin::connection *self)
481 plugin_context *ctx = static_cast<plugin_context *> (self);
482 return convert_out (ctx->preserve (make_node (UNION_TYPE)));
486 plugin_build_add_field (cc1_plugin::connection *,
487 gcc_type record_or_union_type_in,
488 const char *field_name,
489 gcc_type field_type_in,
490 unsigned long bitsize,
491 unsigned long bitpos)
493 tree record_or_union_type = convert_in (record_or_union_type_in);
494 tree field_type = convert_in (field_type_in);
496 gcc_assert (TREE_CODE (record_or_union_type) == RECORD_TYPE
497 || TREE_CODE (record_or_union_type) == UNION_TYPE);
499 /* Note that gdb does not preserve the location of field decls, so
500 we can't provide a decent location here. */
501 tree decl = build_decl (BUILTINS_LOCATION, FIELD_DECL,
502 get_identifier (field_name), field_type);
503 DECL_FIELD_CONTEXT (decl) = record_or_union_type;
505 if (TREE_CODE (field_type) == INTEGER_TYPE
506 && TYPE_PRECISION (field_type) != bitsize)
508 DECL_BIT_FIELD_TYPE (decl) = field_type;
509 TREE_TYPE (decl)
510 = c_build_bitfield_integer_type (bitsize, TYPE_UNSIGNED (field_type));
513 DECL_MODE (decl) = TYPE_MODE (TREE_TYPE (decl));
515 // There's no way to recover this from DWARF.
516 SET_DECL_OFFSET_ALIGN (decl, TYPE_PRECISION (pointer_sized_int_node));
518 tree pos = bitsize_int (bitpos);
519 pos_from_bit (&DECL_FIELD_OFFSET (decl), &DECL_FIELD_BIT_OFFSET (decl),
520 DECL_OFFSET_ALIGN (decl), pos);
522 DECL_SIZE (decl) = bitsize_int (bitsize);
523 DECL_SIZE_UNIT (decl) = size_int ((bitsize + BITS_PER_UNIT - 1)
524 / BITS_PER_UNIT);
526 DECL_CHAIN (decl) = TYPE_FIELDS (record_or_union_type);
527 TYPE_FIELDS (record_or_union_type) = decl;
529 return 1;
533 plugin_finish_record_or_union (cc1_plugin::connection *,
534 gcc_type record_or_union_type_in,
535 unsigned long size_in_bytes)
537 tree record_or_union_type = convert_in (record_or_union_type_in);
539 gcc_assert (TREE_CODE (record_or_union_type) == RECORD_TYPE
540 || TREE_CODE (record_or_union_type) == UNION_TYPE);
542 /* We built the field list in reverse order, so fix it now. */
543 TYPE_FIELDS (record_or_union_type)
544 = nreverse (TYPE_FIELDS (record_or_union_type));
546 if (TREE_CODE (record_or_union_type) == UNION_TYPE)
548 /* Unions can just be handled by the generic code. */
549 layout_type (record_or_union_type);
551 else
553 // FIXME there's no way to get this from DWARF,
554 // or even, it seems, a particularly good way to deduce it.
555 TYPE_ALIGN (record_or_union_type)
556 = TYPE_PRECISION (pointer_sized_int_node);
558 TYPE_SIZE (record_or_union_type) = bitsize_int (size_in_bytes
559 * BITS_PER_UNIT);
560 TYPE_SIZE_UNIT (record_or_union_type) = size_int (size_in_bytes);
562 compute_record_mode (record_or_union_type);
563 finish_bitfield_layout (record_or_union_type);
564 // FIXME we have no idea about TYPE_PACKED
567 return 1;
570 gcc_type
571 plugin_build_enum_type (cc1_plugin::connection *self,
572 gcc_type underlying_int_type_in)
574 tree underlying_int_type = convert_in (underlying_int_type_in);
576 if (underlying_int_type == error_mark_node)
577 return convert_out (error_mark_node);
579 tree result = make_node (ENUMERAL_TYPE);
581 TYPE_PRECISION (result) = TYPE_PRECISION (underlying_int_type);
582 TYPE_UNSIGNED (result) = TYPE_UNSIGNED (underlying_int_type);
584 plugin_context *ctx = static_cast<plugin_context *> (self);
585 return convert_out (ctx->preserve (result));
589 plugin_build_add_enum_constant (cc1_plugin::connection *,
590 gcc_type enum_type_in,
591 const char *name,
592 unsigned long value)
594 tree cst, decl, cons;
595 tree enum_type = convert_in (enum_type_in);
597 gcc_assert (TREE_CODE (enum_type) == ENUMERAL_TYPE);
599 cst = build_int_cst (enum_type, value);
600 /* Note that gdb does not preserve the location of enum constants,
601 so we can't provide a decent location here. */
602 decl = build_decl (BUILTINS_LOCATION, CONST_DECL,
603 get_identifier (name), enum_type);
604 DECL_INITIAL (decl) = cst;
605 pushdecl_safe (decl);
607 cons = tree_cons (DECL_NAME (decl), cst, TYPE_VALUES (enum_type));
608 TYPE_VALUES (enum_type) = cons;
610 return 1;
614 plugin_finish_enum_type (cc1_plugin::connection *,
615 gcc_type enum_type_in)
617 tree enum_type = convert_in (enum_type_in);
618 tree minnode, maxnode, iter;
620 iter = TYPE_VALUES (enum_type);
621 minnode = maxnode = TREE_VALUE (iter);
622 for (iter = TREE_CHAIN (iter);
623 iter != NULL_TREE;
624 iter = TREE_CHAIN (iter))
626 tree value = TREE_VALUE (iter);
627 if (tree_int_cst_lt (maxnode, value))
628 maxnode = value;
629 if (tree_int_cst_lt (value, minnode))
630 minnode = value;
632 TYPE_MIN_VALUE (enum_type) = minnode;
633 TYPE_MAX_VALUE (enum_type) = maxnode;
635 layout_type (enum_type);
637 return 1;
640 gcc_type
641 plugin_build_function_type (cc1_plugin::connection *self,
642 gcc_type return_type_in,
643 const struct gcc_type_array *argument_types_in,
644 int is_varargs)
646 tree *argument_types;
647 tree return_type = convert_in (return_type_in);
648 tree result;
650 argument_types = new tree[argument_types_in->n_elements];
651 for (int i = 0; i < argument_types_in->n_elements; ++i)
652 argument_types[i] = convert_in (argument_types_in->elements[i]);
654 if (is_varargs)
655 result = build_varargs_function_type_array (return_type,
656 argument_types_in->n_elements,
657 argument_types);
658 else
659 result = build_function_type_array (return_type,
660 argument_types_in->n_elements,
661 argument_types);
663 delete[] argument_types;
665 plugin_context *ctx = static_cast<plugin_context *> (self);
666 return convert_out (ctx->preserve (result));
669 gcc_type
670 plugin_int_type (cc1_plugin::connection *self,
671 int is_unsigned, unsigned long size_in_bytes)
673 tree result = c_common_type_for_size (BITS_PER_UNIT * size_in_bytes,
674 is_unsigned);
675 if (result == NULL_TREE)
676 result = error_mark_node;
677 else
679 plugin_context *ctx = static_cast<plugin_context *> (self);
680 ctx->preserve (result);
682 return convert_out (result);
685 gcc_type
686 plugin_float_type (cc1_plugin::connection *,
687 unsigned long size_in_bytes)
689 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (float_type_node))
690 return convert_out (float_type_node);
691 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (double_type_node))
692 return convert_out (double_type_node);
693 if (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (long_double_type_node))
694 return convert_out (long_double_type_node);
695 return convert_out (error_mark_node);
698 gcc_type
699 plugin_void_type (cc1_plugin::connection *)
701 return convert_out (void_type_node);
704 gcc_type
705 plugin_bool_type (cc1_plugin::connection *)
707 return convert_out (boolean_type_node);
710 gcc_type
711 plugin_build_array_type (cc1_plugin::connection *self,
712 gcc_type element_type_in, int num_elements)
714 tree element_type = convert_in (element_type_in);
715 tree result;
717 if (num_elements == -1)
718 result = build_array_type (element_type, NULL_TREE);
719 else
720 result = build_array_type_nelts (element_type, num_elements);
722 plugin_context *ctx = static_cast<plugin_context *> (self);
723 return convert_out (ctx->preserve (result));
726 gcc_type
727 plugin_build_vla_array_type (cc1_plugin::connection *self,
728 gcc_type element_type_in,
729 const char *upper_bound_name)
731 tree element_type = convert_in (element_type_in);
732 tree upper_bound = lookup_name (get_identifier (upper_bound_name));
733 tree range = build_index_type (upper_bound);
735 tree result = build_array_type (element_type, range);
736 C_TYPE_VARIABLE_SIZE (result) = 1;
738 plugin_context *ctx = static_cast<plugin_context *> (self);
739 return convert_out (ctx->preserve (result));
742 gcc_type
743 plugin_build_qualified_type (cc1_plugin::connection *,
744 gcc_type unqualified_type_in,
745 enum gcc_qualifiers qualifiers)
747 tree unqualified_type = convert_in (unqualified_type_in);
748 int quals = 0;
750 if ((qualifiers & GCC_QUALIFIER_CONST) != 0)
751 quals |= TYPE_QUAL_CONST;
752 if ((qualifiers & GCC_QUALIFIER_VOLATILE) != 0)
753 quals |= TYPE_QUAL_VOLATILE;
754 if ((qualifiers & GCC_QUALIFIER_RESTRICT) != 0)
755 quals |= TYPE_QUAL_RESTRICT;
757 return convert_out (build_qualified_type (unqualified_type, quals));
760 gcc_type
761 plugin_build_complex_type (cc1_plugin::connection *self,
762 gcc_type base_type)
764 plugin_context *ctx = static_cast<plugin_context *> (self);
765 return convert_out (ctx->preserve (build_complex_type (convert_in (base_type))));
768 gcc_type
769 plugin_build_vector_type (cc1_plugin::connection *self,
770 gcc_type base_type, int nunits)
772 plugin_context *ctx = static_cast<plugin_context *> (self);
773 return convert_out (ctx->preserve (build_vector_type (convert_in (base_type),
774 nunits)));
778 plugin_build_constant (cc1_plugin::connection *self, gcc_type type_in,
779 const char *name, unsigned long value,
780 const char *filename, unsigned int line_number)
782 plugin_context *ctx = static_cast<plugin_context *> (self);
783 tree cst, decl;
784 tree type = convert_in (type_in);
786 cst = build_int_cst (type, value);
787 decl = build_decl (ctx->get_source_location (filename, line_number),
788 CONST_DECL, get_identifier (name), type);
789 DECL_INITIAL (decl) = cst;
790 pushdecl_safe (decl);
792 return 1;
795 gcc_type
796 plugin_error (cc1_plugin::connection *,
797 const char *message)
799 error ("%s", message);
800 return convert_out (error_mark_node);
805 // Perform GC marking.
807 static void
808 gc_mark (void *, void *)
810 if (current_context != NULL)
811 current_context->mark ();
814 #ifdef __GNUC__
815 #pragma GCC visibility push(default)
816 #endif
819 plugin_init (struct plugin_name_args *plugin_info,
820 struct plugin_gcc_version *)
822 long fd = -1;
823 for (int i = 0; i < plugin_info->argc; ++i)
825 if (strcmp (plugin_info->argv[i].key, "fd") == 0)
827 char *tail;
828 errno = 0;
829 fd = strtol (plugin_info->argv[i].value, &tail, 0);
830 if (*tail != '\0' || errno != 0)
831 fatal_error ("%s: invalid file descriptor argument to plugin",
832 plugin_info->base_name);
833 break;
836 if (fd == -1)
837 fatal_error ("%s: required plugin argument %<fd%> is missing",
838 plugin_info->base_name);
840 current_context = new plugin_context (fd);
842 // Handshake.
843 cc1_plugin::protocol_int version;
844 if (!current_context->require ('H')
845 || ! ::cc1_plugin::unmarshall (current_context, &version))
846 fatal_error ("%s: handshake failed", plugin_info->base_name);
847 if (version != GCC_C_FE_VERSION_0)
848 fatal_error ("%s: unknown version in handshake", plugin_info->base_name);
850 register_callback (plugin_info->base_name, PLUGIN_PRAGMAS,
851 plugin_init_extra_pragmas, NULL);
852 register_callback (plugin_info->base_name, PLUGIN_PRE_GENERICIZE,
853 rewrite_decls_to_addresses, NULL);
854 register_callback (plugin_info->base_name, PLUGIN_GGC_MARKING,
855 gc_mark, NULL);
857 lang_hooks.print_error_function = plugin_print_error_function;
859 #define GCC_METHOD0(R, N) \
861 cc1_plugin::callback_ftype *fun \
862 = cc1_plugin::callback<R, plugin_ ## N>; \
863 current_context->add_callback (# N, fun); \
865 #define GCC_METHOD1(R, N, A) \
867 cc1_plugin::callback_ftype *fun \
868 = cc1_plugin::callback<R, A, plugin_ ## N>; \
869 current_context->add_callback (# N, fun); \
871 #define GCC_METHOD2(R, N, A, B) \
873 cc1_plugin::callback_ftype *fun \
874 = cc1_plugin::callback<R, A, B, plugin_ ## N>; \
875 current_context->add_callback (# N, fun); \
877 #define GCC_METHOD3(R, N, A, B, C) \
879 cc1_plugin::callback_ftype *fun \
880 = cc1_plugin::callback<R, A, B, C, plugin_ ## N>; \
881 current_context->add_callback (# N, fun); \
883 #define GCC_METHOD4(R, N, A, B, C, D) \
885 cc1_plugin::callback_ftype *fun \
886 = cc1_plugin::callback<R, A, B, C, D, \
887 plugin_ ## N>; \
888 current_context->add_callback (# N, fun); \
890 #define GCC_METHOD5(R, N, A, B, C, D, E) \
892 cc1_plugin::callback_ftype *fun \
893 = cc1_plugin::callback<R, A, B, C, D, E, \
894 plugin_ ## N>; \
895 current_context->add_callback (# N, fun); \
897 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
899 cc1_plugin::callback_ftype *fun \
900 = cc1_plugin::callback<R, A, B, C, D, E, F, G, \
901 plugin_ ## N>; \
902 current_context->add_callback (# N, fun); \
905 #include "gcc-c-fe.def"
907 #undef GCC_METHOD0
908 #undef GCC_METHOD1
909 #undef GCC_METHOD2
910 #undef GCC_METHOD3
911 #undef GCC_METHOD4
912 #undef GCC_METHOD5
913 #undef GCC_METHOD7
915 return 0;