This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: little endian bytecode fix
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 14 Oct 2005 13:11:08 -0600
- Subject: [gcjx] Patch: FYI: little endian bytecode fix
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
This fixes a buglet when parsing class files on little-endian
machines. This only really shows up when running the gcc front end on
a class file.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* bytecode/cpool.hh (constant_pool::get_indices): Declare.
* bytecode/cpool.cc (get_indices): New method.
(get_name_and_type): Use it.
(get_fieldref): Likewise.
(get_methodref): Likewise.
Index: bytecode/cpool.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/cpool.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 cpool.cc
--- bytecode/cpool.cc 4 Apr 2005 00:52:40 -0000 1.1.2.2
+++ bytecode/cpool.cc 14 Oct 2005 19:14:47 -0000
@@ -49,6 +49,21 @@
}
void
+constant_pool::get_indices (uint16 index, uint16 &first, uint16 &second)
+{
+ jword whole = value (index);
+ // FIXME: we should have a more general unpacker than this.
+ // There is more code like this in the gcc front end.
+#ifdef WORDS_BIGENDIAN
+ first = whole & 0xffff;
+ second = (whole >> 16) & 0xffff;
+#else
+ second = whole & 0xffff;
+ first = (whole >> 16) & 0xffff;
+#endif
+}
+
+void
constant_pool::get_name_and_type (uint16 index,
std::string &name,
std::string &type)
@@ -57,8 +72,10 @@
throw class_file_error (where,
"expected CONSTANT_NameAndType tag at index %1")
% int (index);
- name = get_utf8 (value (index) & 0xffff);
- type = get_utf8 ((value (index) >> 16) & 0xffff);
+ uint16 n, t;
+ get_indices (index, n, t);
+ name = get_utf8 (n);
+ type = get_utf8 (t);
}
void
@@ -70,8 +87,10 @@
throw class_file_error (where, "expected CONSTANT_Fieldref tag "
"at index %1")
% int (index);
- class_name = get_class (value (index) & 0xffff);
- get_name_and_type ((value (index) >> 16) & 0xffff, field_name, descriptor);
+ uint16 n, t;
+ get_indices (index, n, t);
+ class_name = get_class (n);
+ get_name_and_type (t, field_name, descriptor);
}
void
@@ -83,6 +102,8 @@
throw class_file_error (where, "expected CONSTANT_Methodref tag "
"at index %1")
% int (index);
- class_name = get_class (value (index) & 0xffff);
- get_name_and_type ((value (index) >> 16) & 0xffff, method_name, descriptor);
+ uint16 n, t;
+ get_indices (index, n, t);
+ class_name = get_class (n);
+ get_name_and_type (t, method_name, descriptor);
}
Index: bytecode/cpool.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/cpool.hh,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 cpool.hh
--- bytecode/cpool.hh 4 Apr 2005 00:52:40 -0000 1.1.2.2
+++ bytecode/cpool.hh 14 Oct 2005 19:14:47 -0000
@@ -46,6 +46,7 @@
void get_name_and_type (uint16, std::string &, std::string &);
+ void get_indices (uint16, uint16 &, uint16 &);
public: