1 /* Mudflap: narrow-pointer bounds-checking by tree rewriting:
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
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
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
29 #include "coretypes.h"
32 #include "tree-inline.h"
35 #include "diagnostic.h"
38 #include "tree-mudflap.h"
47 /* ------------------------------------------------------------------------ */
50 /* Initialize the global tree nodes that correspond to mf-runtime.h
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",
64 /* Emit a synthetic CTOR function for the current file. Populate it from
65 the enqueued __mf_register calls. Compile the function. */
68 mflang_flush_calls (tree enqueued_call_stmt_chain)
70 tree fnname, t1, t2, body, block, scope;
73 if (enqueued_call_stmt_chain == NULL_TREE)
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);
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 body = c_begin_compound_stmt ();
90 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
92 c_expand_expr_stmt (enqueued_call_stmt_chain);
94 scope = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
96 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope)) = block;
97 SCOPE_STMT_BLOCK (TREE_VALUE (scope)) = block;
98 RECHAIN_STMTS (body, COMPOUND_BODY (body));