From: Tom Tromey Date: Sun, 13 Dec 1998 13:29:08 +0000 (+0000) Subject: jcf-reader.c (jcf_parse_one_method): Recognize HANDLE_END_METHOD. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=92c068d1dc9b2bf77a9154e9cbaac97687ae9818;p=gcc.git jcf-reader.c (jcf_parse_one_method): Recognize HANDLE_END_METHOD. * jcf-reader.c (jcf_parse_one_method): Recognize HANDLE_END_METHOD. * gjavah.c (HANDLE_END_METHOD): New macro. (HANDLE_CODE_ATTRIBUTE): New macro. (decompile_method): New function. (print_method_info): Don't print `;\n' at end of function decl. Include java-opcodes.h. (decompiled): New global. From-SVN: r24295 --- diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index ff6829bfa51..adf8787c9b4 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,14 @@ +1998-12-13 Tom Tromey + + * jcf-reader.c (jcf_parse_one_method): Recognize + HANDLE_END_METHOD. + * gjavah.c (HANDLE_END_METHOD): New macro. + (HANDLE_CODE_ATTRIBUTE): New macro. + (decompile_method): New function. + (print_method_info): Don't print `;\n' at end of function decl. + Include java-opcodes.h. + (decompiled): New global. + Sat Dec 12 20:13:19 1998 Per Bothner * class.c (build_class_ref): Handle PRIMTYPE.class if diff --git a/gcc/java/gjavah.c b/gcc/java/gjavah.c index ed8e9e95622..eec27b3dc34 100644 --- a/gcc/java/gjavah.c +++ b/gcc/java/gjavah.c @@ -33,6 +33,8 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include +#include "java-opcodes.h" + /* The output file. */ FILE *out = NULL; @@ -99,6 +101,7 @@ static struct method_name *method_name_list; static void print_field_info PROTO ((FILE *, JCF*, int, int, JCF_u2)); static void print_method_info PROTO ((FILE *, JCF*, int, int, JCF_u2)); static void print_c_decl PROTO ((FILE*, JCF*, int, int, JCF_u2, int, char *)); +static void decompile_method PROTO ((FILE *, JCF *, int)); JCF_u2 current_field_name; JCF_u2 current_field_value; @@ -122,7 +125,16 @@ static int field_pass; #define HANDLE_CONSTANTVALUE(VALUEINDEX) current_field_value = (VALUEINDEX) #define HANDLE_METHOD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \ - if (out) print_method_info (out, jcf, NAME, SIGNATURE, ACCESS_FLAGS) + if (out) { decompiled = 0; \ + print_method_info (out, jcf, NAME, SIGNATURE, ACCESS_FLAGS); \ + } + +#define HANDLE_CODE_ATTRIBUTE(MAX_STACK, MAX_LOCALS, CODE_LENGTH) \ + if (out) decompile_method (out, jcf, CODE_LENGTH); + +static int decompiled = 0; +#define HANDLE_END_METHOD() \ + if (out) fputs (decompiled ? "\n" : ";\n", out); #include "jcf-reader.c" @@ -439,11 +451,37 @@ DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags), fputs ("virtual ", out); } print_c_decl (out, jcf, name_index, sig_index, flags, is_init, override); +} - /* FIXME: it would be nice to decompile small methods here. That - would allow for inlining. */ - - fprintf(out, ";\n"); +/* Try to decompile a method body. Right now we just try to handle a + simple case that we can do. Expand as desired. */ +static void +decompile_method (out, jcf, code_len) + FILE *out; + JCF *jcf; + int code_len; +{ + unsigned char *codes = jcf->read_ptr; + int index; + uint16 name_and_type, name; + + if (code_len == 5 + && codes[0] == OPCODE_aload_0 + && codes[1] == OPCODE_getfield + && codes[4] == OPCODE_areturn) + { + /* Found something useful to decompile. */ + fputs (" { return ", out); + index = (codes[2] << 8) | codes[3]; + /* FIXME: ensure that tag is CONSTANT_Fieldref. */ + /* FIXME: ensure that the field's class is this class. */ + name_and_type = JPOOL_USHORT2 (jcf, index); + /* FIXME: ensure that tag is CONSTANT_NameAndType. */ + name = JPOOL_USHORT1 (jcf, name_and_type); + print_name (out, jcf, name); + fputs ("; }", out); + decompiled = 1; + } } /* Print one piece of a signature. Returns pointer to next parseable diff --git a/gcc/java/jcf-reader.c b/gcc/java/jcf-reader.c index 9816ce329c8..f3c860f6a9e 100644 --- a/gcc/java/jcf-reader.c +++ b/gcc/java/jcf-reader.c @@ -308,6 +308,9 @@ DEFUN(jcf_parse_one_method, (jcf), if (code != 0) return code; } +#ifdef HANDLE_END_METHOD + HANDLE_END_METHOD (); +#endif return 0; }