This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: register classes
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 07 Mar 2005 17:42:56 -0700
- Subject: [gcjx] Patch: FYI: register classes
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
Now we call cgraph_finalize_compilation_unit and we arrange to
register the created Class objects at runtime. Some of this code is
taken directly from gcj; a big chunk is commented out, to be
resurrected later.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* driver.cc (parse_file): Finalize compilation unit.
* treegen.cc (generate): Update class_list.
* hooks.hh (class_list): Declare.
* decl.cc (class_list): New global.
Index: decl.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/decl.cc,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 decl.cc
--- decl.cc 8 Mar 2005 00:22:45 -0000 1.1.2.10
+++ decl.cc 8 Mar 2005 00:44:30 -0000
@@ -140,6 +140,10 @@
// Version number.
tree gcj_abi_version;
+// This holds the Class objects for all the classes we've compiled, as
+// a TREE_LIST.
+tree class_list;
+
static void
Index: driver.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/driver.cc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 driver.cc
--- driver.cc 31 Jan 2005 02:26:01 -0000 1.1.2.3
+++ driver.cc 8 Mar 2005 00:44:30 -0000
@@ -442,6 +442,71 @@
our_compiler = NULL;
}
+// Write out code to register classes we defined.
+// The preferred mechanism is through the .jcr section, which contain
+// a list of pointers to classes which get registered during constructor
+// invocation time.
+static void
+register_classes (tree classes)
+{
+ if (TARGET_USE_JCR_SECTION)
+ {
+#ifdef JCR_SECTION_NAME
+ int len = list_length (classes) + 1;
+ tree type = build_array_type (type_class_ptr,
+ build_index_type (build_int_cst (type_jint,
+ len)));
+ tree result = build_decl (VAR_DECL, get_identifier ("_jcr_list"), type);
+ DECL_SECTION_NAME (result) = build_string (strlen (JCR_SECTION_NAME),
+ JCR_SECTION_NAME);
+
+ tree cons = NULL_TREE;
+ int i = 0;
+ for (tree iter = classes; iter != NULL_TREE; iter = TREE_CHAIN (iter))
+ {
+ // Destructively modify the purpose field.
+ TREE_PURPOSE (iter) = build_int_cst (type_jint, i);
+ ++i;
+ }
+
+ classes = chainon (classes,
+ tree_cons (build_int_cst (type_jint, i),
+ null_pointer_node,
+ NULL_TREE));
+
+ DECL_INITIAL (result) = build_constructor (type, classes);
+ TREE_STATIC (result) = 1;
+ DECL_ARTIFICIAL (result) = 1;
+ DECL_IGNORED_P (result) = 1;
+
+ rest_of_decl_compilation (result, 1, 0);
+#else
+ // A target has defined TARGET_USE_JCR_SECTION, but doesn't have
+ // a JCR_SECTION_NAME.
+ abort ();
+#endif
+ }
+ else
+ {
+ abort ();
+// tree klass, t, register_class_fn;
+
+// t = build_function_type_list (void_type_node, class_ptr_type, NULL);
+// t = build_decl (FUNCTION_DECL, get_identifier ("_Jv_RegisterClass"), t);
+// TREE_PUBLIC (t) = 1;
+// DECL_EXTERNAL (t) = 1;
+// register_class_fn = t;
+
+// for (klass = registered_class; klass; klass = TREE_CHAIN (klass))
+// {
+// t = build_fold_addr_expr (klass);
+// t = tree_cons (NULL, t, NULL);
+// t = build_function_call_expr (register_class_fn, t);
+// append_to_statement_list (t, list_p);
+// }
+ }
+}
+
// This handles the processing for a single file. It feeds the
// contents of the file to the compiler as appropriate. For instance,
// ".java" files are parsed and marked for code generation.
@@ -483,4 +548,9 @@
// Compile, then generate code if everything went ok.
if (our_compiler->semantic_analysis ())
our_compiler->generate_code ();
+
+ register_classes (class_list);
+
+ cgraph_finalize_compilation_unit ();
+ cgraph_optimize ();
}
Index: hooks.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/hooks.hh,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 hooks.hh
--- hooks.hh 8 Mar 2005 00:22:45 -0000 1.1.2.5
+++ hooks.hh 8 Mar 2005 00:44:30 -0000
@@ -98,6 +98,7 @@
extern GTY (()) tree field_slot_d;
extern GTY (()) tree field_slot_o;
extern GTY (()) tree gcj_abi_version;
+extern GTY (()) tree class_list;
extern tree build_address_of (tree);
Index: treegen.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/treegen.cc,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 treegen.cc
--- treegen.cc 13 Feb 2005 03:59:51 -0000 1.1.2.6
+++ treegen.cc 8 Mar 2005 00:44:30 -0000
@@ -90,5 +90,5 @@
class_object_creator creator (builtins, wrapper, TREE_TYPE (class_tree));
tree class_obj = creator.get_class ();
- // FIXME: do something with the class now.
+ class_list = tree_cons (NULL_TREE, class_obj, class_list);
}