]>
Commit | Line | Data |
---|---|---|
0a25f1f5 | 1 | /* Garbage collection for the GNU compiler. |
a611912f | 2 | Copyright (C) 1998, 1999 Free Software Foundation, Inc. |
0a25f1f5 RH |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "gansidecl.h" | |
22 | ||
23 | /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with | |
24 | an external gc library that might be linked in. */ | |
25 | ||
a3770a81 RH |
26 | /* Language-specific code defines this variable to be either one (if |
27 | it wants garbage collection), or zero (if it does not). */ | |
28 | extern int ggc_p; | |
29 | ||
87ff9c8e RH |
30 | /* These structures are defined in various headers throughout the |
31 | compiler. However, rather than force everyone who includes this | |
32 | header to include all the headers in which they are declared, we | |
33 | just forward-declare them here. */ | |
87ff9c8e RH |
34 | struct eh_status; |
35 | struct emit_status; | |
fa51b01b | 36 | struct expr_status; |
b49a6a90 AS |
37 | struct hash_table; |
38 | struct label_node; | |
39 | struct rtvec_def; | |
87ff9c8e | 40 | struct stmt_status; |
b49a6a90 | 41 | union tree_node; |
87ff9c8e | 42 | struct varasm_status; |
a3770a81 | 43 | struct varray_head_tag; |
87ff9c8e | 44 | |
b49a6a90 AS |
45 | /* Manipulate global roots that are needed between calls to gc. */ |
46 | void ggc_add_root PROTO ((void *base, int nelt, int size, void (*)(void *))); | |
47 | void ggc_add_rtx_root PROTO ((struct rtx_def **, int nelt)); | |
48 | void ggc_add_tree_root PROTO ((union tree_node **, int nelt)); | |
49 | void ggc_add_string_root PROTO ((char **, int nelt)); | |
50 | void ggc_add_tree_varray_root PROTO ((struct varray_head_tag **, int nelt)); | |
51 | void ggc_add_tree_hash_table_root PROTO ((struct hash_table **, int nelt)); | |
52 | void ggc_del_root PROTO ((void *base)); | |
0a25f1f5 | 53 | |
b49a6a90 AS |
54 | /* Mark nodes from the gc_add_root callback. These functions follow |
55 | pointers to mark other objects too. */ | |
96df4529 AS |
56 | extern void ggc_mark_rtvec PROTO ((struct rtvec_def *)); |
57 | extern void ggc_mark_tree_varray PROTO ((struct varray_head_tag *)); | |
58 | extern void ggc_mark_tree_hash_table PROTO ((struct hash_table *)); | |
59 | extern void ggc_mark_string PROTO ((char *)); | |
60 | extern void ggc_mark PROTO ((void *)); | |
61 | extern void ggc_mark_roots PROTO((void)); | |
62 | ||
63 | extern void ggc_mark_rtx_children PROTO ((struct rtx_def *)); | |
64 | extern void ggc_mark_tree_children PROTO ((union tree_node *)); | |
65 | ||
66 | #define ggc_mark_rtx(RTX_EXPR) \ | |
67 | do { \ | |
68 | rtx r__ = (RTX_EXPR); \ | |
69 | if (r__ != NULL && ! ggc_set_mark_rtx (r__)) \ | |
70 | ggc_mark_rtx_children (r__); \ | |
71 | } while (0) | |
72 | ||
73 | #define ggc_mark_tree(TREE_EXPR) \ | |
74 | do { \ | |
75 | tree t__ = (TREE_EXPR); \ | |
76 | if (t__ != NULL && ! ggc_set_mark_tree (t__)) \ | |
77 | ggc_mark_tree_children (t__); \ | |
78 | } while (0) | |
b49a6a90 AS |
79 | |
80 | /* A GC implementation must provide these functions. */ | |
81 | ||
82 | /* Initialize the garbage collector. */ | |
0a25f1f5 RH |
83 | extern void init_ggc PROTO ((void)); |
84 | ||
21cd906e MM |
85 | /* Start a new GGC context. Memory allocated in previous contexts |
86 | will not be collected while the new context is active. */ | |
87 | extern void ggc_pop_context PROTO ((void)); | |
b49a6a90 | 88 | |
21cd906e MM |
89 | /* Finish a GC context. Any uncollected memory in the new context |
90 | will be merged with the old context. */ | |
91 | extern void ggc_push_context PROTO ((void)); | |
92 | ||
0a25f1f5 | 93 | /* Allocation. */ |
0a25f1f5 RH |
94 | struct rtx_def *ggc_alloc_rtx PROTO ((int nslots)); |
95 | struct rtvec_def *ggc_alloc_rtvec PROTO ((int nelt)); | |
96 | union tree_node *ggc_alloc_tree PROTO ((int length)); | |
97 | char *ggc_alloc_string PROTO ((const char *contents, int length)); | |
37b31aef | 98 | void *ggc_alloc PROTO ((size_t)); |
0a25f1f5 RH |
99 | |
100 | /* Invoke the collector. This is really just a hint, but in the case of | |
101 | the simple collector, the only time it will happen. */ | |
0a25f1f5 RH |
102 | void ggc_collect PROTO ((void)); |
103 | ||
b49a6a90 AS |
104 | /* Actually set the mark on a particular region of memory, but don't |
105 | follow pointers. These functions are called by ggc_mark_*. They | |
106 | return zero if the object was not previously marked; they return | |
107 | non-zero if the object was already marked, or if, for any other | |
108 | reason, pointers in this data structure should not be traversed. */ | |
109 | int ggc_set_mark_rtx PROTO ((struct rtx_def *)); | |
110 | int ggc_set_mark_rtvec PROTO ((struct rtvec_def *)); | |
111 | int ggc_set_mark_tree PROTO ((union tree_node *)); | |
0a25f1f5 | 112 | |
0a25f1f5 RH |
113 | |
114 | /* Callbacks to the languages. */ | |
115 | ||
116 | /* This is the language's opportunity to mark nodes held through | |
117 | the lang_specific hooks in the tree. */ | |
118 | void lang_mark_tree PROTO ((union tree_node *)); | |
119 | ||
87ff9c8e RH |
120 | /* The FALSE_LABEL_STACK, declared in except.h, has |
121 | language-dependent semantics. Each front-end should define this | |
122 | function appropriately. */ | |
123 | void lang_mark_false_label_stack PROTO ((struct label_node *)); | |
124 | ||
0a25f1f5 RH |
125 | /* Mark functions for various structs scattered about. */ |
126 | ||
fa51b01b RH |
127 | void mark_eh_status PROTO ((struct eh_status *)); |
128 | void mark_emit_status PROTO ((struct emit_status *)); | |
129 | void mark_expr_status PROTO ((struct expr_status *)); | |
130 | void mark_stmt_status PROTO ((struct stmt_status *)); | |
131 | void mark_varasm_status PROTO ((struct varasm_status *)); | |
0a25f1f5 | 132 | void mark_optab PROTO ((void *)); |