|
|
1.1 root 1: /* Garbage collection primitives for GNU C++.
2: Copyright (C) 1992 Free Software Foundation, Inc.
3: Contributed by Michael Tiemann ([email protected])
4:
5: This file is part of GNU CC.
6:
7: GNU CC is free software; you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation; either version 2, or (at your option)
10: any later version.
11:
12: GNU CC is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with GNU CC; see the file COPYING. If not, write to
19: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20:
21:
22: #include "config.h"
23: #include "tree.h"
24: #include "cp-tree.h"
25: #include "flags.h"
26: #include "assert.h"
1.1.1.2 ! root 27:
1.1 root 28: #define NULL 0
29:
30: extern tree build_t_desc_overload ();
31:
32: /* This is the function decl for the (pseudo-builtin) __gc_protect
33: function. Args are (class *value, int index); Returns value. */
34: tree gc_protect_fndecl;
35:
36: /* This is the function decl for the (pseudo-builtin) __gc_unprotect
37: function. Args are (int index); void return. */
38: tree gc_unprotect_fndecl;
39:
40: /* This is the function decl for the (pseudo-builtin) __gc_push
41: function. Args are (int length); void return. */
42: tree gc_push_fndecl;
43:
44: /* This is the function decl for the (pseudo-builtin) __gc_pop
45: function. Args are void; void return. */
46: tree gc_pop_fndecl;
47:
48: /* Special integers that are used to represent bits in gc-safe objects. */
49: tree gc_nonobject;
50: tree gc_visible;
51: tree gc_white;
52: tree gc_offwhite;
53: tree gc_grey;
54: tree gc_black;
55:
56: /* Predicate that returns non-zero if TYPE needs some kind of
57: entry for the GC. Returns zero otherwise. */
58: int
59: type_needs_gc_entry (type)
60: tree type;
61: {
62: tree ttype = type;
63:
64: if (! flag_gc || type == error_mark_node)
65: return 0;
66:
67: /* Aggregate types need gc entries if any of their members
68: need gc entries. */
69: if (IS_AGGR_TYPE (type))
70: {
71: tree binfos;
72: tree fields = TYPE_FIELDS (type);
73: int i;
74:
75: /* We don't care about certain pointers. Pointers
76: to virtual baseclasses are always up front. We also
77: cull out virtual function table pointers because it's
78: easy, and it simplifies the logic.*/
79: while (fields
80: && (DECL_NAME (fields) == NULL_TREE
81: || VFIELD_NAME_P (DECL_NAME (fields))
82: || VBASE_NAME_P (DECL_NAME (fields))
83: || !strcmp (IDENTIFIER_POINTER (DECL_NAME (fields)), "__bits")))
84: fields = TREE_CHAIN (fields);
85:
86: while (fields)
87: {
88: if (type_needs_gc_entry (TREE_TYPE (fields)))
89: return 1;
90: fields = TREE_CHAIN (fields);
91: }
92:
93: binfos = TYPE_BINFO_BASETYPES (type);
94: if (binfos)
95: for (i = TREE_VEC_LENGTH (binfos)-1; i >= 0; i--)
96: if (type_needs_gc_entry (BINFO_TYPE (TREE_VEC_ELT (binfos, i))))
97: return 1;
98:
99: return 0;
100: }
101:
102: while (TREE_CODE (ttype) == ARRAY_TYPE
103: && TREE_CODE (TREE_TYPE (ttype)) == ARRAY_TYPE)
104: ttype = TREE_TYPE (ttype);
105: if ((TREE_CODE (ttype) == POINTER_TYPE
106: || TREE_CODE (ttype) == ARRAY_TYPE
107: || TREE_CODE (ttype) == REFERENCE_TYPE)
108: && IS_AGGR_TYPE (TREE_TYPE (ttype))
109: && CLASSTYPE_DOSSIER (TREE_TYPE (ttype)))
110: return 1;
111:
112: return 0;
113: }
114:
115: /* Predicate that returns non-zero iff FROM is safe from the GC.
116:
117: If TO is nonzero, it means we know that FROM is being stored
118: in TO, which make make it safe. */
119: int
120: value_safe_from_gc (to, from)
121: tree to, from;
122: {
123: /* First, return non-zero for easy cases: parameters,
124: static variables. */
125: if (TREE_CODE (from) == PARM_DECL
126: || (TREE_CODE (from) == VAR_DECL
127: && TREE_STATIC (from)))
128: return 1;
129:
130: /* If something has its address taken, it cannot be
131: in the heap, so it doesn't need to be protected. */
132: if (TREE_CODE (from) == ADDR_EXPR || TREE_REFERENCE_EXPR (from))
133: return 1;
134:
135: /* If we are storing into a static variable, then what
136: we store will be safe from the gc. */
137: if (to && TREE_CODE (to) == VAR_DECL
138: && TREE_STATIC (to))
139: return 1;
140:
141: /* Now recurse on structure of FROM. */
142: switch (TREE_CODE (from))
143: {
144: case COMPONENT_REF:
145: /* These guys are special, and safe. */
146: if (TREE_CODE (TREE_OPERAND (from, 1)) == FIELD_DECL
147: && (VFIELD_NAME_P (DECL_NAME (TREE_OPERAND (from, 1)))
148: || VBASE_NAME_P (DECL_NAME (TREE_OPERAND (from, 1)))))
149: return 1;
150: /* fall through... */
151: case NOP_EXPR:
152: case CONVERT_EXPR:
153: case NON_LVALUE_EXPR:
154: case WITH_CLEANUP_EXPR:
155: case SAVE_EXPR:
156: case PREDECREMENT_EXPR:
157: case PREINCREMENT_EXPR:
158: case POSTDECREMENT_EXPR:
159: case POSTINCREMENT_EXPR:
160: if (value_safe_from_gc (to, TREE_OPERAND (from, 0)))
161: return 1;
162: break;
163:
164: case VAR_DECL:
165: case PARM_DECL:
166: /* We can safely pass these things as parameters to functions. */
167: if (to == 0)
168: return 1;
169:
170: case ARRAY_REF:
171: case INDIRECT_REF:
172: case RESULT_DECL:
173: case OFFSET_REF:
174: case CALL_EXPR:
175: case METHOD_CALL_EXPR:
176: break;
177:
178: case COMPOUND_EXPR:
179: case TARGET_EXPR:
180: if (value_safe_from_gc (to, TREE_OPERAND (from, 1)))
181: return 1;
182: break;
183:
184: case COND_EXPR:
185: if (value_safe_from_gc (to, TREE_OPERAND (from, 1))
186: && value_safe_from_gc (to, TREE_OPERAND (from, 2)))
187: return 1;
188: break;
189:
190: case PLUS_EXPR:
191: case MINUS_EXPR:
192: if ((type_needs_gc_entry (TREE_TYPE (TREE_OPERAND (from, 0)))
193: || value_safe_from_gc (to, TREE_OPERAND (from, 0)))
194: && (type_needs_gc_entry (TREE_TYPE (TREE_OPERAND (from, 1))) == 0
195: || value_safe_from_gc (to, TREE_OPERAND (from, 1))))
196: return 1;
197: break;
198:
199: case RTL_EXPR:
200: /* Every time we build an RTL_EXPR in the front-end, we must
201: ensure that everything in it is safe from the garbage collector.
202: ??? This has only been done for `build_new'. */
203: return 1;
204:
205: default:
206: abort ();
207: }
208:
209: if (to == 0)
210: return 0;
211:
212: /* FROM wasn't safe. But other properties of TO might make it safe. */
213: switch (TREE_CODE (to))
214: {
215: case VAR_DECL:
216: case PARM_DECL:
217: /* We already culled out static VAR_DECLs above. */
218: return 0;
219:
220: case COMPONENT_REF:
221: /* These guys are special, and safe. */
222: if (TREE_CODE (TREE_OPERAND (to, 1)) == FIELD_DECL
223: && (VFIELD_NAME_P (DECL_NAME (TREE_OPERAND (to, 1)))
224: || VBASE_NAME_P (DECL_NAME (TREE_OPERAND (to, 1)))))
225: return 1;
226: /* fall through... */
227:
228: case NOP_EXPR:
229: case NON_LVALUE_EXPR:
230: case WITH_CLEANUP_EXPR:
231: case SAVE_EXPR:
232: case PREDECREMENT_EXPR:
233: case PREINCREMENT_EXPR:
234: case POSTDECREMENT_EXPR:
235: case POSTINCREMENT_EXPR:
236: return value_safe_from_gc (TREE_OPERAND (to, 0), from);
237:
238: case COMPOUND_EXPR:
239: case TARGET_EXPR:
240: return value_safe_from_gc (TREE_OPERAND (to, 1), from);
241:
242: case COND_EXPR:
243: return (value_safe_from_gc (TREE_OPERAND (to, 1), from)
244: && value_safe_from_gc (TREE_OPERAND (to, 2), from));
245:
246: case INDIRECT_REF:
247: case ARRAY_REF:
248: /* This used to be 0, but our current restricted model
249: allows this to be 1. We'll never get arrays this way. */
250: return 1;
251:
252: default:
253: abort ();
254: }
255:
256: /* Catch-all case is that TO/FROM is not safe. */
257: return 0;
258: }
259:
260: /* Function to build a static GC entry for DECL. TYPE is DECL's type.
261:
262: For objects of type `class *', this is just an entry in the
263: static vector __PTR_LIST__.
264:
265: For objects of type `class[]', this requires building an entry
266: in the static vector __ARR_LIST__.
267:
268: For aggregates, this records all fields of type `class *'
269: and `class[]' in the respective lists above. */
270: void
271: build_static_gc_entry (decl, type)
272: tree decl;
273: tree type;
274: {
275: /* Now, figure out what sort of entry to build. */
276: if (TREE_CODE (type) == POINTER_TYPE
277: || TREE_CODE (type) == REFERENCE_TYPE)
278: assemble_gc_entry (IDENTIFIER_POINTER (DECL_NAME (decl)));
279: else if (TREE_CODE (type) == RECORD_TYPE)
280: {
281: tree ref = get_temp_name (build_reference_type (type), 1);
282: DECL_INITIAL (ref) = build1 (ADDR_EXPR, TREE_TYPE (ref), decl);
283: TREE_CONSTANT (DECL_INITIAL (ref)) = 1;
284: finish_decl (ref, DECL_INITIAL (ref), 0, 0);
285: }
286: else
287: {
288: /* Not yet implemented.
289:
290: Cons up a static variable that holds address and length info
291: and add that to ___ARR_LIST__. */
292: abort ();
293: }
294: }
295:
296: /* Protect FROM from the GC, assuming FROM is going to be
297: stored into TO. We handle three cases for TO here:
298:
299: case 1: TO is a stack variable.
300: case 2: TO is zero (which means it is a parameter).
301: case 3: TO is a return value. */
302:
303: tree
304: protect_value_from_gc (to, from)
305: tree to, from;
306: {
307: if (to == 0)
308: {
309: tree cleanup;
310:
311: to = get_temp_regvar (TREE_TYPE (from), from);
312:
313: /* Convert from integer to list form since we'll use it twice. */
314: DECL_GC_OFFSET (to) = build_tree_list (NULL_TREE, DECL_GC_OFFSET (to));
315: cleanup = build_function_call (gc_unprotect_fndecl,
316: DECL_GC_OFFSET (to));
317:
318: if (! expand_decl_cleanup (to, cleanup))
319: {
320: compiler_error ("cannot unprotect parameter in this scope");
321: return error_mark_node;
322: }
323: }
324:
325: /* Should never need to protect a value that's headed for static storage. */
326: if (TREE_STATIC (to))
327: abort ();
328:
329: switch (TREE_CODE (to))
330: {
331: case COMPONENT_REF:
332: case INDIRECT_REF:
333: return protect_value_from_gc (TREE_OPERAND (to, 0), from);
334:
335: case VAR_DECL:
336: case PARM_DECL:
337: {
338: tree rval;
339: if (DECL_GC_OFFSET (to) == NULL_TREE)
340: {
341: /* Because of a cast or a conversion, we might stick
342: a value into a variable that would not normally
343: have a GC entry. */
344: DECL_GC_OFFSET (to) = size_int (++current_function_obstack_index);
345: }
346:
347: if (TREE_CODE (DECL_GC_OFFSET (to)) != TREE_LIST)
348: {
349: DECL_GC_OFFSET (to)
350: = build_tree_list (NULL_TREE, DECL_GC_OFFSET (to));
351: }
352:
353: current_function_obstack_usage = 1;
354: rval = build_function_call (gc_protect_fndecl,
355: tree_cons (NULL_TREE, from,
356: DECL_GC_OFFSET (to)));
357: TREE_TYPE (rval) = TREE_TYPE (from);
358: return rval;
359: }
360: }
361:
362: /* If we fall through the switch, assume we lost. */
363: abort ();
364: /* NOTREACHED */
365: return NULL_TREE;
366: }
367:
368: /* Given the expression EXP of type `class *', return the head
369: of the object pointed to by EXP. */
370: tree
371: build_headof (exp)
372: tree exp;
373: {
374: tree type = TREE_TYPE (exp);
375: tree vptr, offset;
376:
377: if (TREE_CODE (type) != POINTER_TYPE)
378: {
379: error ("`headof' applied to non-pointer type");
380: return error_mark_node;
381: }
382:
383: vptr = build1 (INDIRECT_REF, TYPE_POINTER_TO (vtable_entry_type), exp);
384: offset = build_component_ref (build_array_ref (vptr, integer_one_node),
385: get_identifier (VTABLE_DELTA_NAME),
386: NULL_TREE, 0);
387: return build (PLUS_EXPR, class_star_type_node, exp,
388: convert (integer_type_node, offset));
389: }
390:
391: /* Given the expression EXP of type `class *', return the
392: type descriptor for the object pointed to by EXP. */
393: tree
394: build_classof (exp)
395: tree exp;
396: {
397: tree type = TREE_TYPE (exp);
398: tree vptr;
399: tree t_desc_entry;
400:
401: if (TREE_CODE (type) != POINTER_TYPE)
402: {
403: error ("`classof' applied to non-pointer type");
404: return error_mark_node;
405: }
406:
407: vptr = build1 (INDIRECT_REF, TYPE_POINTER_TO (vtable_entry_type), exp);
408: t_desc_entry = build_component_ref (build_array_ref (vptr, integer_one_node),
409: get_identifier (VTABLE_PFN_NAME),
410: NULL_TREE, 0);
411: TREE_TYPE (t_desc_entry) = TYPE_POINTER_TO (__t_desc_type_node);
412: return t_desc_entry;
413: }
414:
415: /* Build and initialize various sorts of descriptors. Every descriptor
416: node has a name associated with it (the name created by mangling).
417: For this reason, we use the identifier as our access to the __*_desc
418: nodes, instead of sticking them directly in the types. Otherwise we
419: would burden all built-in types (and pointer types) with slots that
420: we don't necessarily want to use.
421:
422: For each descriptor we build, we build a variable that contains
423: the descriptor's information. When we need this info at runtime,
424: all we need is access to these variables.
425:
426: Note: these constructors always return the address of the descriptor
427: info, since that is simplest for their mutual interaction. */
428:
429: static tree
430: build_generic_desc (decl, elems)
431: tree decl;
432: tree elems;
433: {
434: tree init = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, elems);
435: TREE_CONSTANT (init) = 1;
436: TREE_STATIC (init) = 1;
437: TREE_READONLY (init) = 1;
438:
439: DECL_INITIAL (decl) = init;
440: TREE_STATIC (decl) = 1;
441: layout_decl (decl, 0);
442: finish_decl (decl, init, 0, 0);
443:
444: return IDENTIFIER_AS_DESC (DECL_NAME (decl));
445: }
446:
447: /* Build an initializer for a __t_desc node. So that we can take advantage
448: of recursion, we accept NULL for TYPE.
449: DEFINITION is greater than zero iff we must define the type descriptor
450: (as opposed to merely referencing it). 1 means treat according to
451: #pragma interface/#pragma implementation rules. 2 means define as
452: global and public, no matter what. */
453: tree
454: build_t_desc (type, definition)
455: tree type;
456: int definition;
457: {
458: tree tdecl;
459: tree tname, name_string;
460: tree elems, fields;
461: tree parents, vbases, offsets, ivars, methods, target_type;
462: int method_count = 0, field_count = 0;
463:
464: if (type == NULL_TREE)
465: return NULL_TREE;
466:
467: tname = build_t_desc_overload (type);
468: if (IDENTIFIER_AS_DESC (tname)
469: && (!definition || TREE_ASM_WRITTEN (IDENTIFIER_AS_DESC (tname))))
470: return IDENTIFIER_AS_DESC (tname);
471:
472: tdecl = lookup_name (tname, 0);
473: if (tdecl == NULL_TREE)
474: {
475: tdecl = build_decl (VAR_DECL, tname, __t_desc_type_node);
476: TREE_EXTERNAL (tdecl) = 1;
477: TREE_PUBLIC (tdecl) = 1;
478: tdecl = pushdecl_top_level (tdecl);
479: }
480: /* If we previously defined it, return the defined result. */
481: else if (definition && DECL_INITIAL (tdecl))
482: return IDENTIFIER_AS_DESC (tname);
483:
484: if (definition)
485: {
486: tree taggr = type;
487: /* Let T* and T& be written only when T is written (if T is an aggr).
488: We do this for const, but not for volatile, since volatile
489: is rare and const is not. */
490: if (!TYPE_VOLATILE (taggr)
491: && (TREE_CODE (taggr) == POINTER_TYPE
492: || TREE_CODE (taggr) == REFERENCE_TYPE)
493: && IS_AGGR_TYPE (TREE_TYPE (taggr)))
494: taggr = TREE_TYPE (taggr);
495:
496: /* If we know that we don't need to write out this type's
497: vtable, then don't write out it's dossier. Somebody
498: else will take care of that. */
499: if (IS_AGGR_TYPE (taggr) && CLASSTYPE_VFIELD (taggr))
500: {
501: if (CLASSTYPE_VTABLE_NEEDS_WRITING (taggr))
502: {
503: TREE_PUBLIC (tdecl) = !(CLASSTYPE_INTERFACE_ONLY (taggr)
504: || CLASSTYPE_INTERFACE_UNKNOWN (taggr));
505: TREE_STATIC (tdecl) = 1;
506: TREE_EXTERNAL (tdecl) = 0;
507: }
508: else
509: {
510: if (write_virtuals != 0)
511: TREE_PUBLIC (tdecl) = 1;
512: }
513: }
514: else
515: {
516: TREE_EXTERNAL (tdecl) = 0;
517: TREE_STATIC (tdecl) = 1;
518: TREE_PUBLIC (tdecl) = (definition > 1);
519: }
520: }
521: SET_IDENTIFIER_AS_DESC (tname, build_unary_op (ADDR_EXPR, tdecl, 0));
522: if (!definition || TREE_EXTERNAL (tdecl))
523: {
524: /* That's it! */
525: finish_decl (tdecl, 0, 0, 0);
526: return IDENTIFIER_AS_DESC (tname);
527: }
528:
529: /* Show that we are defining the t_desc for this type. */
530: DECL_INITIAL (tdecl) = error_mark_node;
531:
532: parents = build_tree_list (NULL_TREE, integer_zero_node);
533: vbases = build_tree_list (NULL_TREE, integer_zero_node);
534: offsets = build_tree_list (NULL_TREE, integer_zero_node);
535: methods = NULL_TREE;
536: ivars = NULL_TREE;
537:
538: if (TYPE_LANG_SPECIFIC (type))
539: {
540: int i = CLASSTYPE_N_BASECLASSES (type);
541: tree method_vec = CLASSTYPE_METHOD_VEC (type);
542: tree *meth, *end;
543: tree binfos = TYPE_BINFO_BASETYPES (type);
544: tree vb = CLASSTYPE_VBASECLASSES (type);
545:
546: while (--i >= 0)
547: parents = tree_cons (NULL_TREE, build_t_desc (BINFO_TYPE (TREE_VEC_ELT (binfos, i)), 0), parents);
548:
549: while (vb)
550: {
551: vbases = tree_cons (NULL_TREE, build_t_desc (BINFO_TYPE (vb), 0), vbases);
552: offsets = tree_cons (NULL_TREE, BINFO_OFFSET (vb), offsets);
553: vb = TREE_CHAIN (vb);
554: }
555:
556: if (method_vec)
557: for (meth = TREE_VEC_END (method_vec),
558: end = &TREE_VEC_ELT (method_vec, 0); meth-- != end; )
559: if (*meth)
560: {
561: methods = tree_cons (NULL_TREE, build_m_desc (*meth), methods);
562: method_count++;
563: }
564: }
565:
566: if (IS_AGGR_TYPE (type))
567: {
568: for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
569: if (TREE_CODE (fields) == FIELD_DECL
570: || TREE_CODE (fields) == VAR_DECL)
571: {
572: ivars = tree_cons (NULL_TREE, build_i_desc (fields), ivars);
573: field_count++;
574: }
575: ivars = nreverse (ivars);
576: }
577:
578: parents = finish_table (0, TYPE_POINTER_TO (__t_desc_type_node), parents, 0);
579: vbases = finish_table (0, TYPE_POINTER_TO (__t_desc_type_node), vbases, 0);
580: offsets = finish_table (0, integer_type_node, offsets, 0);
581: methods = finish_table (0, __m_desc_type_node, methods, 0);
582: ivars = finish_table (0, __i_desc_type_node, ivars, 0);
583: if (TREE_TYPE (type))
584: target_type = build_t_desc (TREE_TYPE (type), definition);
585: else
586: target_type = integer_zero_node;
587:
588: name_string = combine_strings (build_string (IDENTIFIER_LENGTH (tname)+1, IDENTIFIER_POINTER (tname)));
589:
590: elems = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, name_string, 0),
591: tree_cons (NULL_TREE,
592: TYPE_SIZE(type)? size_in_bytes(type) : integer_zero_node,
593: /* really should use bitfield initialization here. */
594: tree_cons (NULL_TREE, integer_zero_node,
595: tree_cons (NULL_TREE, target_type,
596: tree_cons (NULL_TREE, build_int_2 (field_count, 2),
597: tree_cons (NULL_TREE, build_int_2 (method_count, 2),
598: tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, ivars, 0),
599: tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, methods, 0),
600: tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, parents, 0),
601: tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, vbases, 0),
602: build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, offsets, 0))))))))))));
603: return build_generic_desc (tdecl, elems);
604: }
605:
606: /* Build an initializer for a __i_desc node. */
607: tree
608: build_i_desc (decl)
609: tree decl;
610: {
611: tree elems, name_string;
612: tree taggr;
613:
614: name_string = DECL_NAME (decl);
615: name_string = combine_strings (build_string (IDENTIFIER_LENGTH (name_string)+1, IDENTIFIER_POINTER (name_string)));
616:
617: /* Now decide whether this ivar should cause it's type to get
618: def'd or ref'd in this file. If the type we are looking at
619: has a proxy definition, we look at the proxy (i.e., a
620: `foo *' is equivalent to a `foo'). */
621: taggr = TREE_TYPE (decl);
622:
623: if ((TREE_CODE (taggr) == POINTER_TYPE
624: || TREE_CODE (taggr) == REFERENCE_TYPE)
625: && TYPE_VOLATILE (taggr) == 0)
626: taggr = TREE_TYPE (taggr);
627:
628: elems = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, name_string, 0),
629: tree_cons (NULL_TREE, DECL_FIELD_BITPOS (decl),
630: build_tree_list (NULL_TREE, build_t_desc (TREE_TYPE (decl),
631: ! IS_AGGR_TYPE (taggr)))));
632: taggr = build (CONSTRUCTOR, __i_desc_type_node, NULL_TREE, elems);
633: TREE_CONSTANT (taggr) = 1;
634: TREE_STATIC (taggr) = 1;
635: TREE_READONLY (taggr) = 1;
636: return taggr;
637: }
638:
639: /* Build an initializer for a __m_desc node. */
640: tree
641: build_m_desc (decl)
642: tree decl;
643: {
644: tree taggr, elems, name_string;
645: tree parm_count, req_count, vindex, vcontext;
646: tree parms;
647: int p_count, r_count;
648: tree parm_types = NULL_TREE;
649:
650: for (parms = TYPE_ARG_TYPES (TREE_TYPE (decl)), p_count = 0, r_count = 0;
651: parms != NULL_TREE; parms = TREE_CHAIN (parms), p_count++)
652: {
653: taggr = TREE_VALUE (parms);
654: if ((TREE_CODE (taggr) == POINTER_TYPE
655: || TREE_CODE (taggr) == REFERENCE_TYPE)
656: && TYPE_VOLATILE (taggr) == 0)
657: taggr = TREE_TYPE (taggr);
658:
659: parm_types = tree_cons (NULL_TREE, build_t_desc (TREE_VALUE (parms),
660: ! IS_AGGR_TYPE (taggr)),
661: parm_types);
662: if (TREE_PURPOSE (parms) == NULL_TREE)
663: r_count++;
664: }
665:
666: parm_types = finish_table (0, TYPE_POINTER_TO (__t_desc_type_node),
667: nreverse (parm_types), 0);
668: parm_count = build_int_2 (p_count, 0);
669: req_count = build_int_2 (r_count, 0);
670:
671: if (DECL_VINDEX (decl))
672: vindex = DECL_VINDEX (decl);
673: else
674: vindex = integer_zero_node;
675: if (DECL_CONTEXT (decl))
676: vcontext = build_t_desc (DECL_CONTEXT (decl), 0);
677: else
678: vcontext = integer_zero_node;
679: name_string = DECL_NAME (decl);
680: if (name_string == NULL)
681: name_string = DECL_ASSEMBLER_NAME (decl);
682: name_string = combine_strings (build_string (IDENTIFIER_LENGTH (name_string)+1, IDENTIFIER_POINTER (name_string)));
683:
684: /* Now decide whether the return type of this mvar
685: should cause it's type to get def'd or ref'd in this file.
686: If the type we are looking at has a proxy definition,
687: we look at the proxy (i.e., a `foo *' is equivalent to a `foo'). */
688: taggr = TREE_TYPE (TREE_TYPE (decl));
689:
690: if ((TREE_CODE (taggr) == POINTER_TYPE
691: || TREE_CODE (taggr) == REFERENCE_TYPE)
692: && TYPE_VOLATILE (taggr) == 0)
693: taggr = TREE_TYPE (taggr);
694:
695: elems = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, name_string, 0),
696: tree_cons (NULL_TREE, vindex,
697: tree_cons (NULL_TREE, vcontext,
698: tree_cons (NULL_TREE, build_t_desc (TREE_TYPE (TREE_TYPE (decl)),
699: ! IS_AGGR_TYPE (taggr)),
700: tree_cons (NULL_TREE, build_c_cast (TYPE_POINTER_TO (default_function_type), build_unary_op (ADDR_EXPR, decl, 0)),
701: tree_cons (NULL_TREE, parm_count,
702: tree_cons (NULL_TREE, req_count,
703: build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, parm_types, 0)))))))));
704:
705: taggr = build (CONSTRUCTOR, __m_desc_type_node, NULL_TREE, elems);
706: TREE_CONSTANT (taggr) = 1;
707: TREE_STATIC (taggr) = 1;
708: TREE_READONLY (taggr) = 1;
709: return taggr;
710: }
711:
712: /* Conditionally emit code to set up an unwind-protect for the
713: garbage collector. If this function doesn't do anything that involves
714: the garbage collector, then do nothing. Otherwise, call __gc_push
715: at the beginning and __gc_pop at the end.
716:
717: NOTE! The __gc_pop function must operate transparently, since
718: it comes where the logical return label lies. This means that
719: at runtime *it* must preserve any return value registers. */
720:
721: void
722: expand_gc_prologue_and_epilogue ()
723: {
724: extern tree maybe_gc_cleanup;
725: struct rtx_def *last_parm_insn, *mark;
726: extern struct rtx_def *get_last_insn ();
727: extern struct rtx_def *get_first_nonparm_insn ();
728: extern struct rtx_def *previous_insn ();
729: tree action;
730:
731: /* If we didn't need the obstack, don't cons any space. */
732: if (current_function_obstack_index == 0
733: || current_function_obstack_usage == 0)
734: return;
735:
736: mark = get_last_insn ();
737: last_parm_insn = get_first_nonparm_insn ();
738: if (last_parm_insn == 0) last_parm_insn = mark;
739: else last_parm_insn = previous_insn (last_parm_insn);
740:
741: action = build_function_call (gc_push_fndecl,
742: build_tree_list (NULL_TREE, size_int (++current_function_obstack_index)));
743: expand_expr_stmt (action);
744:
745: reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
746:
747: /* This will be expanded as a cleanup. */
748: TREE_VALUE (maybe_gc_cleanup)
749: = build_function_call (gc_pop_fndecl, NULL_TREE);
750: }
751:
752: /* Some day we'll use this function as a call-back and clean
753: up all the unnecessary gc dribble that we otherwise create. */
754: void
755: lang_expand_end_bindings (first, last)
756: struct rtx_def *first, *last;
757: {
758: }
759:
760: void
761: init_gc_processing ()
762: {
763: tree parmtypes = hash_tree_chain (class_star_type_node,
764: hash_tree_chain (integer_type_node, NULL_TREE));
765: gc_protect_fndecl = define_function ("__gc_protect",
766: build_function_type (class_star_type_node, parmtypes),
767: NOT_BUILT_IN, 0, 0);
768:
769: parmtypes = hash_tree_chain (integer_type_node, NULL_TREE);
770: gc_unprotect_fndecl = define_function ("__gc_unprotect",
771: build_function_type (void_type_node, parmtypes),
772: NOT_BUILT_IN, 0, 0);
773:
774: gc_push_fndecl = define_function ("__gc_push",
775: TREE_TYPE (gc_unprotect_fndecl),
776: NOT_BUILT_IN, 0, 0);
777:
778: gc_pop_fndecl = define_function ("__gc_pop",
779: build_function_type (void_type_node,
780: void_list_node),
781: NOT_BUILT_IN, 0, 0);
782: gc_nonobject = build_int_2 (0x80000000, 0);
783: gc_visible = build_int_2 (0x40000000, 0);
784: gc_white = integer_zero_node;
785: gc_offwhite = build_int_2 (0x10000000, 0);
786: gc_grey = build_int_2 (0x20000000, 0);
787: gc_black = build_int_2 (0x30000000, 0);
788: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.