Commit dcb36804 by Per Bothner Committed by Per Bothner

class.c: Change vtable to be more compatible with g++ v3 abi.


	*  class.c:  Change vtable to be more compatible with g++ v3 abi.
	(get_dispatch_table):  Prepend offset-to-top (always 0) and
	type_info pointer (currently unimplemented hence NULL) to vtable.
	Specifically, prepend offset-to-top and typeinfo ptr (currently null).
	(make_class_data):  Variable dtable_start_offset is sizeof 2 pointers.
	Adjust vtable pointers by dtable_start_offse - i.e. skip new words.
	(build_dtable_decl):  Add declarations for new fields.

From-SVN: r49978
parent 9aa43698
2002-02-22 Per Bothner <per@bothner.com>
* class.c: Change vtable to be more compatible with g++ v3 abi.
(get_dispatch_table): Prepend offset-to-top (always 0) and
type_info pointer (currently unimplemented hence NULL) to vtable.
Specifically, prepend offset-to-top and typeinfo ptr (currently null).
(make_class_data): Variable dtable_start_offset is sizeof 2 pointers.
Adjust vtable pointers by dtable_start_offse - i.e. skip new words.
(build_dtable_decl): Add declarations for new fields.
2002-02-20 Per Bothner <per@bothner.com> 2002-02-20 Per Bothner <per@bothner.com>
* parse.y (patch_method_invocation): Set CAN_COMPLETE_NORMALLY on call * parse.y (patch_method_invocation): Set CAN_COMPLETE_NORMALLY on call
......
...@@ -1470,11 +1470,17 @@ get_dispatch_table (type, this_class_addr) ...@@ -1470,11 +1470,17 @@ get_dispatch_table (type, this_class_addr)
list = tree_cons (NULL_TREE, gc_descr, list); list = tree_cons (NULL_TREE, gc_descr, list);
for (j = 1; j < TARGET_VTABLE_USES_DESCRIPTORS-1; ++j) for (j = 1; j < TARGET_VTABLE_USES_DESCRIPTORS-1; ++j)
list = tree_cons (NULL_TREE, gc_descr, list); list = tree_cons (NULL_TREE, gc_descr, list);
list = tree_cons (integer_zero_node, this_class_addr, list); list = tree_cons (NULL_TREE, this_class_addr, list);
/** Pointer to type_info object (to be implemented), according to g++ ABI. */
list = tree_cons (NULL_TREE, null_pointer_node, list);
/** Offset to start of whole object. Always (ptrdiff_t)0 for Java. */
list = tree_cons (integer_zero_node, null_pointer_node, list);
arraysize = (TARGET_VTABLE_USES_DESCRIPTORS? nvirtuals + 1 : nvirtuals + 2); arraysize = (TARGET_VTABLE_USES_DESCRIPTORS? nvirtuals + 1 : nvirtuals + 2);
if (TARGET_VTABLE_USES_DESCRIPTORS) if (TARGET_VTABLE_USES_DESCRIPTORS)
arraysize *= TARGET_VTABLE_USES_DESCRIPTORS; arraysize *= TARGET_VTABLE_USES_DESCRIPTORS;
arraysize += 2;
return build (CONSTRUCTOR, return build (CONSTRUCTOR,
build_prim_array_type (nativecode_ptr_type_node, arraysize), build_prim_array_type (nativecode_ptr_type_node, arraysize),
NULL_TREE, list); NULL_TREE, list);
...@@ -1504,6 +1510,9 @@ make_class_data (type) ...@@ -1504,6 +1510,9 @@ make_class_data (type)
tree interfaces = null_pointer_node; tree interfaces = null_pointer_node;
int interface_len = 0; int interface_len = 0;
tree type_decl = TYPE_NAME (type); tree type_decl = TYPE_NAME (type);
/** Offset from start of virtual function table declaration
to where objects actually point at, following new g++ ABI. */
tree dtable_start_offset = build_int_2 (2 * POINTER_SIZE / BITS_PER_UNIT, 0);
this_class_addr = build_class_ref (type); this_class_addr = build_class_ref (type);
decl = TREE_OPERAND (this_class_addr, 0); decl = TREE_OPERAND (this_class_addr, 0);
...@@ -1657,7 +1666,9 @@ make_class_data (type) ...@@ -1657,7 +1666,9 @@ make_class_data (type)
START_RECORD_CONSTRUCTOR (temp, object_type_node); START_RECORD_CONSTRUCTOR (temp, object_type_node);
PUSH_FIELD_VALUE (temp, "vtable", PUSH_FIELD_VALUE (temp, "vtable",
build1 (ADDR_EXPR, dtable_ptr_type, class_dtable_decl)); build (PLUS_EXPR, dtable_ptr_type,
build1 (ADDR_EXPR, dtable_ptr_type, class_dtable_decl),
dtable_start_offset));
if (! flag_hash_synchronization) if (! flag_hash_synchronization)
PUSH_FIELD_VALUE (temp, "sync_info", null_pointer_node); PUSH_FIELD_VALUE (temp, "sync_info", null_pointer_node);
FINISH_RECORD_CONSTRUCTOR (temp); FINISH_RECORD_CONSTRUCTOR (temp);
...@@ -1693,7 +1704,9 @@ make_class_data (type) ...@@ -1693,7 +1704,9 @@ make_class_data (type)
else else
PUSH_FIELD_VALUE (cons, "vtable", PUSH_FIELD_VALUE (cons, "vtable",
dtable_decl == NULL_TREE ? null_pointer_node dtable_decl == NULL_TREE ? null_pointer_node
: build1 (ADDR_EXPR, dtable_ptr_type, dtable_decl)); : build (PLUS_EXPR, dtable_ptr_type,
build1 (ADDR_EXPR, dtable_ptr_type, dtable_decl),
dtable_start_offset));
if (otable_methods == NULL_TREE) if (otable_methods == NULL_TREE)
{ {
...@@ -1826,7 +1839,7 @@ build_dtable_decl (type) ...@@ -1826,7 +1839,7 @@ build_dtable_decl (type)
/* We need to build a new dtable type so that its size is uniquely /* We need to build a new dtable type so that its size is uniquely
computed when we're dealing with the class for real and not just computed when we're dealing with the class for real and not just
faking it (like java.lang.Class during the initialization of the faking it (like java.lang.Class during the initialization of the
compiler.) We now we're not faking a class when CURRENT_CLASS is compiler.) We know we're not faking a class when CURRENT_CLASS is
TYPE. */ TYPE. */
if (current_class == type) if (current_class == type)
{ {
...@@ -1835,6 +1848,9 @@ build_dtable_decl (type) ...@@ -1835,6 +1848,9 @@ build_dtable_decl (type)
dtype = make_node (RECORD_TYPE); dtype = make_node (RECORD_TYPE);
PUSH_FIELD (dtype, dummy, "top_offset", ptr_type_node);
PUSH_FIELD (dtype, dummy, "type_info", ptr_type_node);
PUSH_FIELD (dtype, dummy, "class", class_ptr_type); PUSH_FIELD (dtype, dummy, "class", class_ptr_type);
for (n = 1; n < TARGET_VTABLE_USES_DESCRIPTORS; ++n) for (n = 1; n < TARGET_VTABLE_USES_DESCRIPTORS; ++n)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment