This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[BC] Patch: FYI: make type map in new verifer


I'm checking this in on the BC branch.

This adds code to the new verifier to create the type map that is
used by the rest of the compiler.  As the new verifier isn't wired in
yet, this has not been tested.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* verify-impl.c (vfr): Fixed comment formatting.
	(collapse_type): New function.
	(verify_instructions): Notify compiler about type map.
	* verify.h (vfy_note_stack_depth): Updated.
	(vfy_note_stack_type): Likewise.
	(vfy_note_local_type): Likewise.
	(vfy_unsuitable_type, vfy_return_address_type, vfy_null_type):
	Declare.
	* verify-glue.c (vfy_note_stack_depth): Correctly size type
	state.  Added `method' argument.
	(vfy_note_stack_type): Renamed from vfy_note_type.  Added `method'
	argument.
	(vfy_note_local_type): New function.
	(vfy_unsuitable_type): Likewise.
	(vfy_return_address_type): Likewise.
	(vfy_null_type): Likewise.

Index: verify-glue.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/verify-glue.c,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 verify-glue.c
--- verify-glue.c 6 Oct 2004 23:29:25 -0000 1.1.2.2
+++ verify-glue.c 15 Oct 2004 17:18:58 -0000
@@ -1,5 +1,5 @@
 /* Glue to interface gcj with bytecode verifier.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -334,6 +334,24 @@
   return k;
 }
 
+vfy_jclass
+vfy_unsuitable_type (void)
+{
+  return TYPE_SECOND;
+}
+
+vfy_jclass
+vfy_return_address_type (void)
+{
+  return TYPE_RETURN_ADDR;
+}
+
+vfy_jclass
+vfy_null_type (void)
+{
+  return TYPE_NULL;
+}
+
 int
 vfy_fail (const char *message, int pc, vfy_jclass ignore1 ATTRIBUTE_UNUSED,
 	  vfy_method *ignore2 ATTRIBUTE_UNUSED)
@@ -361,14 +379,24 @@
 }
 
 void
-vfy_note_stack_depth (int pc, int depth)
+vfy_note_stack_depth (vfy_method *method, int pc, int depth)
+{
+  tree label = lookup_label (pc);
+  LABEL_TYPE_STATE (label) = make_tree_vec (method->max_locals + depth);
+}
+
+void
+vfy_note_stack_type (vfy_method *method, int pc, int slot, vfy_jclass type)
 {
+  slot += method->max_locals;
+
   tree label = lookup_label (pc);
-  LABEL_TYPE_STATE (label) = make_tree_vec (depth);
+  tree vec = LABEL_TYPE_STATE (label);
+  TREE_VEC_ELT (vec, slot) = type;
 }
 
 void
-vfy_note_type (int pc, int slot, vfy_jclass type)
+vfy_note_local_type (vfy_method *method, int pc, int slot, vfy_jclass type)
 {
   tree label = lookup_label (pc);
   tree vec = LABEL_TYPE_STATE (label);
Index: verify-impl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/verify-impl.c,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 verify-impl.c
--- verify-impl.c 15 Oct 2004 16:32:46 -0000 1.1.2.4
+++ verify-impl.c 15 Oct 2004 17:18:59 -0000
@@ -210,8 +210,8 @@
 } verifier_context;
 
 /* The current verifier's state data. This is maintained by
-{push/pop}_verifier_context to provide a shorthand form to access the
-verification state. */
+   {push/pop}_verifier_context to provide a shorthand form to access
+   the verification state. */
 static GTY(()) verifier_context *vfr;
 
 /* Local function declarations.  */
@@ -3258,10 +3258,73 @@
     }
 }
 
-static void verify_instructions (void)
+/* This turns a `type' into something suitable for use by the type map
+   in the other parts of the compiler.  In particular, reference types
+   are mapped to Object, primitive types are unchanged, and other
+   types are mapped using special functions declared in verify.h.  */
+static vfy_jclass
+collapse_type (type *t)
+{
+  switch (t->key)
+    {
+    case void_type:
+    case boolean_type:
+    case char_type:
+    case float_type:
+    case double_type:
+    case byte_type:
+    case short_type:
+    case int_type:
+    case long_type:
+      return vfy_get_primitive_type (t->key);
+
+    case unsuitable_type:
+    case continuation_type:
+      return vfy_unsuitable_type ();
+
+    case return_address_type:
+      return vfy_return_address_type ();
+
+    case null_type:
+      return vfy_null_type ();
+
+    case reference_type:
+    case uninitialized_reference_type:
+      return vfy_object_type ();
+    }
+
+  abort ();
+}
+
+static void
+verify_instructions (void)
 {
+  int i;
+
   branch_prepass ();
   verify_instructions_0 ();
+
+  /* Now tell the rest of the compiler about the types we've found.  */
+  for (i = 0; i < vfr->current_method->code_length; ++i)
+    {
+      int j;
+      struct state *curr;
+
+      if (! vfr->states[i])
+	continue;
+
+      curr = vfr->states[i]->val;
+      vfy_note_stack_depth (vfr->current_method, i, curr->stackdepth);
+
+      /* Tell the compiler about each local variable.  */
+      for (j = 0; j < vfr->current_method->max_locals; ++j)
+	vfy_note_stack_type (vfr->current_method, i, j,
+			     collapse_type (&curr->locals[j]));
+      /* Tell the compiler about each stack slot.  */
+      for (j = 0; j < curr->stackdepth; ++j)
+	vfy_note_stack_type (vfr->current_method, i, j,
+			     collapse_type (&curr->stack[j]));
+    }
 }
 
 #if 0
Index: verify.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/verify.h,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 verify.h
--- verify.h 15 Oct 2004 16:32:46 -0000 1.1.2.3
+++ verify.h 15 Oct 2004 17:18:59 -0000
@@ -113,11 +113,17 @@
 vfy_jclass vfy_object_type (void);
 vfy_jclass vfy_string_type (void);
 vfy_jclass vfy_throwable_type (void);
+vfy_jclass vfy_unsuitable_type (void);
+vfy_jclass vfy_return_address_type (void);
+vfy_jclass vfy_null_type (void);
 int vfy_fail (const char *message, int pc, vfy_jclass ignore1, vfy_method *method);
 void vfy_notify_verified (int pc);
 vfy_jclass vfy_get_primitive_type (int type);
-void vfy_note_stack_depth (int pc, int depth);
-void vfy_note_type (int pc, int slot, vfy_jclass type);
+void vfy_note_stack_depth (vfy_method *method, int pc, int depth);
+void vfy_note_stack_type (vfy_method *method, int pc, int slot,
+			  vfy_jclass type);
+void vfy_note_local_type (vfy_method *method, int pc, int slot,
+			  vfy_jclass type);
 
 #define GLOM(name, stuff) name ## stuff
 #define VFY_PRIMITIVE_CLASS(name) \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]