2005-01-13 Michael Koch <konqueror@gmx.de>
[official-gcc.git] / gcc / c-mudflap.c
blob78523e960a07df5ab9193a60d848a9b2cf23a836
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 "c-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"
43 #include "function.h"
47 /* ------------------------------------------------------------------------ */
50 /* Initialize the global tree nodes that correspond to mf-runtime.h
51 declarations. */
52 tree
53 mflang_lookup_decl (const char* name)
55 tree decl = lookup_name (get_identifier (name));
56 if (decl == NULL_TREE)
57 internal_error ("mudflap: cannot find declaration of `%s' from mf-runtime.h",
58 name);
60 return decl;
64 /* Emit a synthetic CTOR function for the current file. Populate it from
65 the enqueued __mf_register calls. Compile the function. */
67 void
68 mflang_flush_calls (tree enqueued_call_stmt_chain)
70 tree fnname, t1, t2, cs;
72 /* Short-circuit! */
73 if (enqueued_call_stmt_chain == NULL_TREE)
74 return;
76 fnname = get_identifier ("__mudflap_static_initializer");
77 t1 = build_tree_list (NULL_TREE, void_type_node);
78 t2 = tree_cons (NULL, NULL, t1);
79 start_function (t1, build_nt (CALL_EXPR, fnname, t2, NULL), NULL);
80 store_parm_decls ();
82 DECL_STATIC_CONSTRUCTOR (current_function_decl) = 1;
83 TREE_PUBLIC (current_function_decl) = 0;
84 TREE_USED (current_function_decl) = 1;
85 mf_mark (current_function_decl);
87 cs = c_begin_compound_stmt (true);
88 c_expand_expr_stmt (enqueued_call_stmt_chain);
89 add_stmt (c_end_compound_stmt (cs, true));
91 finish_function ();