* target.h (struct gcc_target): Add new field to struct cxx: import_export_class.
[official-gcc.git] / gcc / cp / cp-mudflap.c
bloba9703a76ec2d0bbb32e8f599f363a47dcf50a234
1 /* Mudflap: narrow-pointer bounds-checking by tree rewriting:
2 C++ front-end interface.
4 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
5 Contributed by Frank Ch. Eigler <fche@redhat.com>
6 and Graydon Hoare <graydon@redhat.com>
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 02111-1307, USA. */
26 #include "config.h"
27 #include "errors.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "tree.h"
32 #include "tree-inline.h"
33 #include "cp-tree.h"
34 #include "c-common.h"
35 #include "diagnostic.h"
36 #include "output.h"
37 #include "varray.h"
38 #include "tree-mudflap.h"
39 #include "target.h"
40 #include "flags.h"
41 #include "rtl.h"
42 #include "toplev.h"
45 /* Initialize the global tree nodes that correspond to mf-runtime.h
46 declarations. */
47 tree
48 mflang_lookup_decl (const char* name)
50 tree decl = lookup_name (get_identifier (name), 1);
51 if (decl == NULL_TREE)
52 internal_error ("mudflap: cannot find declaration of `%s' from mf-runtime.h",
53 name);
55 return decl;
59 /* Emit a synthetic CTOR function for the current file. Populate it from
60 the enqueued __mf_register calls. Register it with the constructors. */
62 void
63 mflang_flush_calls (tree enqueued_call_stmt_chain)
65 tree fnname, fndecl, body;
66 tree type;
68 /* Short-circuit! */
69 if (enqueued_call_stmt_chain == NULL_TREE)
70 return;
72 /* Create a ctor function declaration. */
73 fnname = get_identifier ("__static_initialization_and_destruction_mudflap");
74 type = build_function_type (void_type_node, void_list_node);
75 fndecl = build_lang_decl (FUNCTION_DECL, fnname, type);
77 TREE_PUBLIC (fndecl) = 0;
78 TREE_USED (fndecl) = 1;
79 DECL_ARTIFICIAL (fndecl) = 1;
80 mf_mark (fndecl);
82 /* Generate the body, one statement at a time. */
83 start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
84 body = begin_compound_stmt (BCS_FN_BODY);
86 while (enqueued_call_stmt_chain)
88 tree next = TREE_CHAIN (enqueued_call_stmt_chain);
89 finish_expr_stmt (enqueued_call_stmt_chain);
90 enqueued_call_stmt_chain = next;
93 finish_compound_stmt (body);
94 fndecl = finish_function (0);
96 /* NB: We cannot call expand_or_defer_fn here, since that goes through
97 the callgraph queue. This queue will have already been processed by the
98 time this function is running. */
99 expand_body (fndecl);
100 if (targetm.have_ctors_dtors)
101 (* targetm.asm_out.constructor) (XEXP (DECL_RTL (fndecl), 0),
102 DEFAULT_INIT_PRIORITY);
103 else
104 /* By this time, it's too late to do this:
105 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors); */
106 abort ();