OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [java/] [jcf-dump.c] - Diff between revs 287 and 338

Only display areas with differences | Details | Blame | View Log

Rev 287 Rev 338
/* Program to dump out a Java(TM) .class file.
/* Program to dump out a Java(TM) .class file.
   Functionally similar to Sun's javap.
   Functionally similar to Sun's javap.
 
 
   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
the Free Software Foundation; either version 3, or (at your option)
any later version.
any later version.
 
 
GCC is distributed in the hope that it will be useful,
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.
<http://www.gnu.org/licenses/>.
 
 
Java and all Java-based marks are trademarks or registered trademarks
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc.  */
The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 
 
/* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
/* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
 
 
/*
/*
  jcf-dump is a program to print out the contents of class files.
  jcf-dump is a program to print out the contents of class files.
  Usage:  jcf-dump [FLAGS] CLASS
  Usage:  jcf-dump [FLAGS] CLASS
  Each CLASS is either:
  Each CLASS is either:
  + the name of a class in the CLASSPATH (e.g "java.lang.String"), or
  + the name of a class in the CLASSPATH (e.g "java.lang.String"), or
  + the name of a class *file* (e.g. "/home/me/work/package/Foo.class").
  + the name of a class *file* (e.g. "/home/me/work/package/Foo.class").
  + The name of a .zip or .jar file (which prints all the classes in the
  + The name of a .zip or .jar file (which prints all the classes in the
  archive).
  archive).
 
 
  OPTIONS:
  OPTIONS:
  -c
  -c
        Dis-assemble each method.
        Dis-assemble each method.
  -classpath PATH
  -classpath PATH
        Overrides $CLASSPATH.
        Overrides $CLASSPATH.
  --print-main
  --print-main
        Print nothing if there is no valid "main" method;
        Print nothing if there is no valid "main" method;
        otherwise, print only the class name.
        otherwise, print only the class name.
  --javap
  --javap
        Print output in the style of Sun's javap program.  VERY UNFINISHED.
        Print output in the style of Sun's javap program.  VERY UNFINISHED.
 */
 */
 
 
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
#include "ggc.h"
#include "ggc.h"
#include "intl.h"
#include "intl.h"
 
 
#include "jcf.h"
#include "jcf.h"
#include "tree.h"
#include "tree.h"
#include "java-tree.h"
#include "java-tree.h"
 
 
#include "version.h"
#include "version.h"
 
 
#include <getopt.h>
#include <getopt.h>
#include <math.h>
#include <math.h>
 
 
/* Output file. */
/* Output file. */
FILE *out;
FILE *out;
/* Name of output file, if NULL if stdout. */
/* Name of output file, if NULL if stdout. */
char *output_file = NULL;
char *output_file = NULL;
 
 
int verbose = 0;
int verbose = 0;
 
 
int flag_disassemble_methods = 0;
int flag_disassemble_methods = 0;
int flag_print_class_info = 1;
int flag_print_class_info = 1;
int flag_print_constant_pool = 0;
int flag_print_constant_pool = 0;
int flag_print_fields = 1;
int flag_print_fields = 1;
int flag_print_methods = 1;
int flag_print_methods = 1;
int flag_print_attributes = 1;
int flag_print_attributes = 1;
 
 
/* When nonzero, warn when source file is newer than matching class
/* When nonzero, warn when source file is newer than matching class
   file.  */
   file.  */
int flag_newer = 1;
int flag_newer = 1;
 
 
/* Print names of classes that have a "main" method. */
/* Print names of classes that have a "main" method. */
int flag_print_main = 0;
int flag_print_main = 0;
 
 
/* Index in constant pool of this class. */
/* Index in constant pool of this class. */
int this_class_index = 0;
int this_class_index = 0;
 
 
int class_access_flags = 0;
int class_access_flags = 0;
 
 
/* Print in format similar to javap.  VERY INCOMPLETE. */
/* Print in format similar to javap.  VERY INCOMPLETE. */
int flag_javap_compatible = 0;
int flag_javap_compatible = 0;
 
 
static void print_access_flags (FILE *, uint16, char);
static void print_access_flags (FILE *, uint16, char);
static void print_constant_terse (FILE*, JCF*, int, int);
static void print_constant_terse (FILE*, JCF*, int, int);
static void print_constant_terse_with_index (FILE *, JCF *, int, int);
static void print_constant_terse_with_index (FILE *, JCF *, int, int);
static void print_constant (FILE *, JCF *, int, int);
static void print_constant (FILE *, JCF *, int, int);
static void print_constant_ref (FILE *, JCF *, int);
static void print_constant_ref (FILE *, JCF *, int);
static void disassemble_method (JCF*, const unsigned char *, int);
static void disassemble_method (JCF*, const unsigned char *, int);
static void print_name (FILE*, JCF*, int);
static void print_name (FILE*, JCF*, int);
static void print_signature (FILE*, JCF*, int, int);
static void print_signature (FILE*, JCF*, int, int);
static int utf8_equal_string (struct JCF*, int, const char *);
static int utf8_equal_string (struct JCF*, int, const char *);
static void usage (void) ATTRIBUTE_NORETURN;
static void usage (void) ATTRIBUTE_NORETURN;
static void help (void) ATTRIBUTE_NORETURN;
static void help (void) ATTRIBUTE_NORETURN;
static void version (void) ATTRIBUTE_NORETURN;
static void version (void) ATTRIBUTE_NORETURN;
static void process_class (struct JCF *);
static void process_class (struct JCF *);
static void print_constant_pool (struct JCF *);
static void print_constant_pool (struct JCF *);
static void print_exception_table (struct JCF *, const unsigned char *entries,
static void print_exception_table (struct JCF *, const unsigned char *entries,
                                   int);
                                   int);
static void indent (FILE *, int);
static void indent (FILE *, int);
static void print_element_value (FILE *, JCF *, int);
static void print_element_value (FILE *, JCF *, int);
static void print_annotation (FILE *, JCF *, int);
static void print_annotation (FILE *, JCF *, int);
static void print_annotations (FILE *, JCF *, int);
static void print_annotations (FILE *, JCF *, int);
static void print_parameter_annotations (FILE *, JCF *, int);
static void print_parameter_annotations (FILE *, JCF *, int);
 
 
#define PRINT_SIGNATURE_RESULT_ONLY 1
#define PRINT_SIGNATURE_RESULT_ONLY 1
#define PRINT_SIGNATURE_ARGS_ONLY 2
#define PRINT_SIGNATURE_ARGS_ONLY 2
 
 
static int
static int
utf8_equal_string (JCF *jcf, int index, const char * value)
utf8_equal_string (JCF *jcf, int index, const char * value)
{
{
  if (CPOOL_INDEX_IN_RANGE (&jcf->cpool, index)
  if (CPOOL_INDEX_IN_RANGE (&jcf->cpool, index)
      && JPOOL_TAG (jcf, index) == CONSTANT_Utf8)
      && JPOOL_TAG (jcf, index) == CONSTANT_Utf8)
    {
    {
      int len = strlen (value);
      int len = strlen (value);
      if (JPOOL_UTF_LENGTH (jcf, index) == len
      if (JPOOL_UTF_LENGTH (jcf, index) == len
          && memcmp (JPOOL_UTF_DATA (jcf, index), value, len) == 0)
          && memcmp (JPOOL_UTF_DATA (jcf, index), value, len) == 0)
        return 1;
        return 1;
    }
    }
  return 0;
  return 0;
}
}
 
 
#define HANDLE_MAGIC(MAGIC, MINOR, MAJOR) \
#define HANDLE_MAGIC(MAGIC, MINOR, MAJOR) \
  this_class_index = 0; \
  this_class_index = 0; \
  if (flag_print_class_info) \
  if (flag_print_class_info) \
    fprintf (out, \
    fprintf (out, \
             "Magic number: 0x%0lx, minor_version: %ld, major_version: %ld.\n",\
             "Magic number: 0x%0lx, minor_version: %ld, major_version: %ld.\n",\
             (unsigned long) MAGIC, (long) MINOR, (long) MAJOR)
             (unsigned long) MAGIC, (long) MINOR, (long) MAJOR)
 
 
#define HANDLE_START_CONSTANT_POOL(COUNT) \
#define HANDLE_START_CONSTANT_POOL(COUNT) \
  if (flag_print_constant_pool) \
  if (flag_print_constant_pool) \
    fprintf (out, "\nConstant pool (count: %d):\n", COUNT)
    fprintf (out, "\nConstant pool (count: %d):\n", COUNT)
 
 
#define HANDLE_SOURCEFILE(INDEX) \
#define HANDLE_SOURCEFILE(INDEX) \
{ fprintf (out, "Attribute "); \
{ fprintf (out, "Attribute "); \
  print_constant_terse (out, jcf, attribute_name, CONSTANT_Utf8); \
  print_constant_terse (out, jcf, attribute_name, CONSTANT_Utf8); \
  fprintf (out, ", length:%ld, #%d=", (long) attribute_length, INDEX); \
  fprintf (out, ", length:%ld, #%d=", (long) attribute_length, INDEX); \
  print_constant_terse (out, jcf, INDEX, CONSTANT_Utf8); fputc ('\n', out); }
  print_constant_terse (out, jcf, INDEX, CONSTANT_Utf8); fputc ('\n', out); }
 
 
#define HANDLE_CLASS_INFO(ACCESS_FLAGS, THIS, SUPER, INTERFACES_COUNT) \
#define HANDLE_CLASS_INFO(ACCESS_FLAGS, THIS, SUPER, INTERFACES_COUNT) \
  this_class_index = THIS; \
  this_class_index = THIS; \
  class_access_flags = ACCESS_FLAGS; \
  class_access_flags = ACCESS_FLAGS; \
  if (flag_print_class_info) \
  if (flag_print_class_info) \
    { fprintf (out, "\nAccess flags: 0x%x", ACCESS_FLAGS); \
    { fprintf (out, "\nAccess flags: 0x%x", ACCESS_FLAGS); \
      print_access_flags (out, ACCESS_FLAGS, 'c'); \
      print_access_flags (out, ACCESS_FLAGS, 'c'); \
      fputc ('\n', out); \
      fputc ('\n', out); \
      fprintf (out, "This class: "); \
      fprintf (out, "This class: "); \
      print_constant_terse_with_index (out, jcf, THIS, CONSTANT_Class); \
      print_constant_terse_with_index (out, jcf, THIS, CONSTANT_Class); \
      if (flag_print_constant_pool || SUPER != 0) \
      if (flag_print_constant_pool || SUPER != 0) \
        fprintf (out, ", super: "); \
        fprintf (out, ", super: "); \
      if (flag_print_constant_pool) \
      if (flag_print_constant_pool) \
        { \
        { \
          fprintf (out, "%d", SUPER); \
          fprintf (out, "%d", SUPER); \
          if (SUPER != 0) \
          if (SUPER != 0) \
            fputc ('=', out); \
            fputc ('=', out); \
        } \
        } \
      if (SUPER != 0) \
      if (SUPER != 0) \
        print_constant_terse (out, jcf, SUPER, CONSTANT_Class); \
        print_constant_terse (out, jcf, SUPER, CONSTANT_Class); \
      fprintf (out, "\nInterfaces (count: %d):\n", INTERFACES_COUNT); \
      fprintf (out, "\nInterfaces (count: %d):\n", INTERFACES_COUNT); \
    }
    }
 
 
#define IGNORE_ATTRIBUTE(JCF, NAME, NAME_LENGTH) \
#define IGNORE_ATTRIBUTE(JCF, NAME, NAME_LENGTH) \
  (flag_print_attributes <= 0)
  (flag_print_attributes <= 0)
 
 
#define HANDLE_CLASS_INTERFACE(INDEX) \
#define HANDLE_CLASS_INTERFACE(INDEX) \
  if (flag_print_class_info) \
  if (flag_print_class_info) \
    { fprintf (out, "- Implements: "); \
    { fprintf (out, "- Implements: "); \
      print_constant_terse_with_index (out, jcf, INDEX, CONSTANT_Class); \
      print_constant_terse_with_index (out, jcf, INDEX, CONSTANT_Class); \
      fputc ('\n', out); }
      fputc ('\n', out); }
 
 
#define HANDLE_START_FIELDS(FIELDS_COUNT) \
#define HANDLE_START_FIELDS(FIELDS_COUNT) \
  if (flag_print_fields) \
  if (flag_print_fields) \
    fprintf (out, "\nFields (count: %d):\n", FIELDS_COUNT)
    fprintf (out, "\nFields (count: %d):\n", FIELDS_COUNT)
 
 
#define HANDLE_START_FIELD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
#define HANDLE_START_FIELD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
  if (flag_print_fields) \
  if (flag_print_fields) \
    { fprintf (out, "Field name:"); \
    { fprintf (out, "Field name:"); \
      print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
      print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
      print_access_flags (out, ACCESS_FLAGS, 'f'); \
      print_access_flags (out, ACCESS_FLAGS, 'f'); \
      fprintf (out, " Descriptor: "); \
      fprintf (out, " Descriptor: "); \
      if (flag_print_constant_pool) \
      if (flag_print_constant_pool) \
        fprintf (out, "%d=", SIGNATURE); \
        fprintf (out, "%d=", SIGNATURE); \
      print_signature (out, jcf, SIGNATURE, 0); \
      print_signature (out, jcf, SIGNATURE, 0); \
      fputc ('\n', out); } \
      fputc ('\n', out); } \
  else \
  else \
    flag_print_attributes--;
    flag_print_attributes--;
 
 
#define HANDLE_END_FIELD() \
#define HANDLE_END_FIELD() \
  if (! flag_print_fields) \
  if (! flag_print_fields) \
    flag_print_attributes++;
    flag_print_attributes++;
 
 
#define HANDLE_START_METHODS(METHODS_COUNT) \
#define HANDLE_START_METHODS(METHODS_COUNT) \
  if (flag_print_methods) \
  if (flag_print_methods) \
    fprintf (out, "\nMethods (count: %d):\n", METHODS_COUNT); \
    fprintf (out, "\nMethods (count: %d):\n", METHODS_COUNT); \
  else \
  else \
    flag_print_attributes--;
    flag_print_attributes--;
 
 
 
 
#define HANDLE_END_METHODS() \
#define HANDLE_END_METHODS() \
  if (! flag_print_methods) \
  if (! flag_print_methods) \
    flag_print_attributes++;
    flag_print_attributes++;
 
 
#define HANDLE_METHOD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
#define HANDLE_METHOD(ACCESS_FLAGS, NAME, SIGNATURE, ATTRIBUTE_COUNT) \
{ \
{ \
  if (flag_print_methods) \
  if (flag_print_methods) \
    { \
    { \
      if (flag_javap_compatible) \
      if (flag_javap_compatible) \
        { \
        { \
          fprintf (out, "    "); \
          fprintf (out, "    "); \
          print_access_flags (out, ACCESS_FLAGS, 'm'); \
          print_access_flags (out, ACCESS_FLAGS, 'm'); \
          fputc (' ', out); \
          fputc (' ', out); \
          print_signature (out, jcf, SIGNATURE, PRINT_SIGNATURE_RESULT_ONLY); \
          print_signature (out, jcf, SIGNATURE, PRINT_SIGNATURE_RESULT_ONLY); \
          fputc (' ', out); \
          fputc (' ', out); \
          print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
          print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
          print_signature (out, jcf, SIGNATURE, PRINT_SIGNATURE_ARGS_ONLY); \
          print_signature (out, jcf, SIGNATURE, PRINT_SIGNATURE_ARGS_ONLY); \
          fputc ('\n', out); \
          fputc ('\n', out); \
        } \
        } \
      else \
      else \
        { \
        { \
          fprintf (out, "\nMethod name:"); \
          fprintf (out, "\nMethod name:"); \
          print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
          print_constant_terse (out, jcf, NAME, CONSTANT_Utf8); \
          print_access_flags (out, ACCESS_FLAGS, 'm'); \
          print_access_flags (out, ACCESS_FLAGS, 'm'); \
          fprintf (out, " Descriptor: "); \
          fprintf (out, " Descriptor: "); \
          if (flag_print_constant_pool) \
          if (flag_print_constant_pool) \
            fprintf (out, "%d=", SIGNATURE); \
            fprintf (out, "%d=", SIGNATURE); \
          print_signature (out, jcf, SIGNATURE, 0); \
          print_signature (out, jcf, SIGNATURE, 0); \
          fputc ('\n', out); \
          fputc ('\n', out); \
        } \
        } \
    } \
    } \
  if (flag_print_main && ACCESS_FLAGS == (ACC_STATIC|ACC_PUBLIC) \
  if (flag_print_main && ACCESS_FLAGS == (ACC_STATIC|ACC_PUBLIC) \
      && utf8_equal_string (jcf, NAME, "main") \
      && utf8_equal_string (jcf, NAME, "main") \
      && utf8_equal_string (jcf, SIGNATURE, "([Ljava/lang/String;)V") \
      && utf8_equal_string (jcf, SIGNATURE, "([Ljava/lang/String;)V") \
      && this_class_index > 0 \
      && this_class_index > 0 \
      && (class_access_flags & ACC_PUBLIC)) \
      && (class_access_flags & ACC_PUBLIC)) \
    { \
    { \
      print_constant_terse(out, jcf, this_class_index, CONSTANT_Class); \
      print_constant_terse(out, jcf, this_class_index, CONSTANT_Class); \
      fputc  ('\n', out); \
      fputc  ('\n', out); \
   } \
   } \
}
}
 
 
#define COMMON_HANDLE_ATTRIBUTE(JCF, INDEX, LENGTH) \
#define COMMON_HANDLE_ATTRIBUTE(JCF, INDEX, LENGTH) \
( fprintf (out, "Attribute "), \
( fprintf (out, "Attribute "), \
  print_constant_terse (out, jcf, INDEX, CONSTANT_Utf8), \
  print_constant_terse (out, jcf, INDEX, CONSTANT_Utf8), \
  fprintf (out, ", length:%ld", (long) LENGTH) )
  fprintf (out, ", length:%ld", (long) LENGTH) )
 
 
#define HANDLE_CONSTANTVALUE(VALUE_INDEX) \
#define HANDLE_CONSTANTVALUE(VALUE_INDEX) \
( COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length), \
( COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length), \
  fprintf (out, ", value: "), \
  fprintf (out, ", value: "), \
  print_constant_ref (out, jcf, VALUE_INDEX), \
  print_constant_ref (out, jcf, VALUE_INDEX), \
  fprintf (out, "\n") )
  fprintf (out, "\n") )
 
 
#define HANDLE_CODE_ATTRIBUTE(MAX_STACK, MAX_LOCALS, CODE_LENGTH) \
#define HANDLE_CODE_ATTRIBUTE(MAX_STACK, MAX_LOCALS, CODE_LENGTH) \
{ COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length); \
{ COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length); \
  fprintf (out, ", max_stack:%ld, max_locals:%ld, code_length:%ld\n", \
  fprintf (out, ", max_stack:%ld, max_locals:%ld, code_length:%ld\n", \
    (long) MAX_STACK, (long) MAX_LOCALS, (long) CODE_LENGTH); \
    (long) MAX_STACK, (long) MAX_LOCALS, (long) CODE_LENGTH); \
  disassemble_method (jcf, jcf->read_ptr, CODE_LENGTH); }
  disassemble_method (jcf, jcf->read_ptr, CODE_LENGTH); }
 
 
#define HANDLE_EXCEPTION_TABLE(ENTRIES, COUNT) \
#define HANDLE_EXCEPTION_TABLE(ENTRIES, COUNT) \
  print_exception_table (jcf, ENTRIES, COUNT)
  print_exception_table (jcf, ENTRIES, COUNT)
 
 
#define HANDLE_EXCEPTIONS_ATTRIBUTE(COUNT) \
#define HANDLE_EXCEPTIONS_ATTRIBUTE(COUNT) \
{ int n = (COUNT); int i; \
{ int n = (COUNT); int i; \
  COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length); \
  COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length); \
  fprintf (out, ", count: %d\n", n); \
  fprintf (out, ", count: %d\n", n); \
  for (i = 0; i < n; i++) {\
  for (i = 0; i < n; i++) {\
    int ex_index = JCF_readu2 (jcf); \
    int ex_index = JCF_readu2 (jcf); \
    fprintf (out, "%3d: ", i); \
    fprintf (out, "%3d: ", i); \
    print_constant_ref (out, jcf, ex_index); \
    print_constant_ref (out, jcf, ex_index); \
    fputc ('\n', out); } }
    fputc ('\n', out); } }
 
 
#define HANDLE_LOCALVARIABLETABLE_ATTRIBUTE(COUNT) \
#define HANDLE_LOCALVARIABLETABLE_ATTRIBUTE(COUNT) \
{ int n = (COUNT); int i; \
{ int n = (COUNT); int i; \
  COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length); \
  COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length); \
  fprintf (out, ", count: %d\n", n); \
  fprintf (out, ", count: %d\n", n); \
  for (i = 0; i < n; i++) {\
  for (i = 0; i < n; i++) {\
    int start_pc = JCF_readu2 (jcf); \
    int start_pc = JCF_readu2 (jcf); \
    int length = JCF_readu2 (jcf); \
    int length = JCF_readu2 (jcf); \
    int name_index = JCF_readu2 (jcf); \
    int name_index = JCF_readu2 (jcf); \
    int signature_index = JCF_readu2 (jcf); \
    int signature_index = JCF_readu2 (jcf); \
    int slot = JCF_readu2 (jcf); \
    int slot = JCF_readu2 (jcf); \
    fprintf (out, "  slot#%d: name: ", slot); \
    fprintf (out, "  slot#%d: name: ", slot); \
    if (flag_print_constant_pool) \
    if (flag_print_constant_pool) \
      fprintf (out, "%d=", name_index); \
      fprintf (out, "%d=", name_index); \
    print_name (out, jcf, name_index); \
    print_name (out, jcf, name_index); \
    fprintf (out, ", type: "); \
    fprintf (out, ", type: "); \
    if (flag_print_constant_pool) \
    if (flag_print_constant_pool) \
      fprintf (out, "%d=", signature_index); \
      fprintf (out, "%d=", signature_index); \
    print_signature (out, jcf, signature_index, 0); \
    print_signature (out, jcf, signature_index, 0); \
    fprintf (out, " (pc: %d length: %d)\n", start_pc, length); }}
    fprintf (out, " (pc: %d length: %d)\n", start_pc, length); }}
 
 
#define HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE(COUNT)                  \
#define HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE(COUNT)                  \
{ int n = (COUNT); int i;                                               \
{ int n = (COUNT); int i;                                               \
  COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(JCF, attribute_name, attribute_length);       \
  fprintf (out, ", count: %d\n", n);                                    \
  fprintf (out, ", count: %d\n", n);                                    \
  for (i = 0; i < n; i++) {                                              \
  for (i = 0; i < n; i++) {                                              \
    int start_pc = JCF_readu2 (jcf);                                    \
    int start_pc = JCF_readu2 (jcf);                                    \
    int length = JCF_readu2 (jcf);                                      \
    int length = JCF_readu2 (jcf);                                      \
    int name_index = JCF_readu2 (jcf);                                  \
    int name_index = JCF_readu2 (jcf);                                  \
    int signature_index = JCF_readu2 (jcf);                             \
    int signature_index = JCF_readu2 (jcf);                             \
    int slot = JCF_readu2 (jcf);                                        \
    int slot = JCF_readu2 (jcf);                                        \
    fprintf (out, "  slot#%d: name: ", slot);                           \
    fprintf (out, "  slot#%d: name: ", slot);                           \
    if (flag_print_constant_pool)                                       \
    if (flag_print_constant_pool)                                       \
      fprintf (out, "%d=", name_index);                                 \
      fprintf (out, "%d=", name_index);                                 \
    print_name (out, jcf, name_index);                                  \
    print_name (out, jcf, name_index);                                  \
    fprintf (out, ", type: ");                                          \
    fprintf (out, ", type: ");                                          \
    if (flag_print_constant_pool)                                       \
    if (flag_print_constant_pool)                                       \
      fprintf (out, "%d=", signature_index);                            \
      fprintf (out, "%d=", signature_index);                            \
    print_signature (out, jcf, signature_index, 0);                      \
    print_signature (out, jcf, signature_index, 0);                      \
    fprintf (out, " (pc: %d length: %d)\n", start_pc, length); }}
    fprintf (out, " (pc: %d length: %d)\n", start_pc, length); }}
 
 
#define HANDLE_LINENUMBERTABLE_ATTRIBUTE(COUNT) \
#define HANDLE_LINENUMBERTABLE_ATTRIBUTE(COUNT) \
{ int n = (COUNT); int i; \
{ int n = (COUNT); int i; \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
  fprintf (out, ", count: %d\n", n); \
  fprintf (out, ", count: %d\n", n); \
  if (flag_disassemble_methods) \
  if (flag_disassemble_methods) \
    for (i = 0; i < n; i++) {\
    for (i = 0; i < n; i++) {\
      int start_pc = JCF_readu2 (jcf); \
      int start_pc = JCF_readu2 (jcf); \
      int line_number = JCF_readu2 (jcf); \
      int line_number = JCF_readu2 (jcf); \
      fprintf (out, "  line: %d at pc: %d\n", line_number, start_pc); }\
      fprintf (out, "  line: %d at pc: %d\n", line_number, start_pc); }\
  else \
  else \
    JCF_SKIP (jcf, 4 * n); }
    JCF_SKIP (jcf, 4 * n); }
 
 
#define HANDLE_INNERCLASSES_ATTRIBUTE(COUNT)                                \
#define HANDLE_INNERCLASSES_ATTRIBUTE(COUNT)                                \
{ int n = (COUNT);                                                          \
{ int n = (COUNT);                                                          \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);           \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);           \
  while (n--)                                                               \
  while (n--)                                                               \
    {                                                                       \
    {                                                                       \
      uint16 inner_class_info_index = JCF_readu2 (jcf);                     \
      uint16 inner_class_info_index = JCF_readu2 (jcf);                     \
      uint16 outer_class_info_index = JCF_readu2 (jcf);                     \
      uint16 outer_class_info_index = JCF_readu2 (jcf);                     \
      uint16 inner_name_index = JCF_readu2 (jcf);                           \
      uint16 inner_name_index = JCF_readu2 (jcf);                           \
      uint16 inner_class_access_flags = JCF_readu2 (jcf);                   \
      uint16 inner_class_access_flags = JCF_readu2 (jcf);                   \
                                                                            \
                                                                            \
      if (flag_print_class_info)                                            \
      if (flag_print_class_info)                                            \
        {                                                                   \
        {                                                                   \
          fprintf (out, "\n  inner: ");                                     \
          fprintf (out, "\n  inner: ");                                     \
          if (inner_class_info_index == 0)                                   \
          if (inner_class_info_index == 0)                                   \
            fprintf (out, " (no inner info index)");                        \
            fprintf (out, " (no inner info index)");                        \
          else                                                              \
          else                                                              \
            print_constant_terse_with_index (out, jcf,                      \
            print_constant_terse_with_index (out, jcf,                      \
                                             inner_class_info_index,        \
                                             inner_class_info_index,        \
                                             CONSTANT_Class);               \
                                             CONSTANT_Class);               \
          if (inner_name_index == 0)                                         \
          if (inner_name_index == 0)                                         \
            fprintf (out, " (anonymous)");                                  \
            fprintf (out, " (anonymous)");                                  \
          else if (verbose || flag_print_constant_pool)                     \
          else if (verbose || flag_print_constant_pool)                     \
            {                                                               \
            {                                                               \
              fprintf (out, " (");                                          \
              fprintf (out, " (");                                          \
              print_constant_terse_with_index (out, jcf, inner_name_index,  \
              print_constant_terse_with_index (out, jcf, inner_name_index,  \
                                               CONSTANT_Utf8);              \
                                               CONSTANT_Utf8);              \
              fputc (')', out);                                             \
              fputc (')', out);                                             \
            }                                                               \
            }                                                               \
          fprintf (out, ", access flags: 0x%x", inner_class_access_flags);  \
          fprintf (out, ", access flags: 0x%x", inner_class_access_flags);  \
          print_access_flags (out, inner_class_access_flags, 'c');          \
          print_access_flags (out, inner_class_access_flags, 'c');          \
          fprintf (out, ", outer class: ");                                 \
          fprintf (out, ", outer class: ");                                 \
          if (outer_class_info_index == 0)                                   \
          if (outer_class_info_index == 0)                                   \
            fprintf (out, "(not a member)");                                \
            fprintf (out, "(not a member)");                                \
          else                                                              \
          else                                                              \
            print_constant_terse_with_index (out, jcf,                      \
            print_constant_terse_with_index (out, jcf,                      \
                                             outer_class_info_index,        \
                                             outer_class_info_index,        \
                                             CONSTANT_Class);               \
                                             CONSTANT_Class);               \
        }                                                                   \
        }                                                                   \
    }                                                                       \
    }                                                                       \
  if (flag_print_class_info)                                                \
  if (flag_print_class_info)                                                \
    fputc ('\n', out);                                                      \
    fputc ('\n', out);                                                      \
}
}
 
 
#define HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE(LENGTH) \
#define HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE(LENGTH) \
{ int i, n = (LENGTH), c = 0;                                      \
{ int i, n = (LENGTH), c = 0;                                      \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length); \
  fputc ('\n', out); \
  fputc ('\n', out); \
  for (i = 0;  i < n;  i++) { c = JCF_readu(jcf); fputc(c, out); } \
  for (i = 0;  i < n;  i++) { c = JCF_readu(jcf); fputc(c, out); } \
  if (c != '\r' && c != '\n') fputc('\n', out); }
  if (c != '\r' && c != '\n') fputc('\n', out); }
 
 
#define HANDLE_ENCLOSINGMETHOD_ATTRIBUTE()                              \
#define HANDLE_ENCLOSINGMETHOD_ATTRIBUTE()                              \
  { uint16 class_index, method_index;                                   \
  { uint16 class_index, method_index;                                   \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  class_index = JCF_readu2 (jcf);                                       \
  class_index = JCF_readu2 (jcf);                                       \
  method_index = JCF_readu2 (jcf);                                      \
  method_index = JCF_readu2 (jcf);                                      \
  fprintf (out, "\n  Class: ");                                         \
  fprintf (out, "\n  Class: ");                                         \
  print_constant_terse_with_index (out, jcf, class_index, CONSTANT_Class); \
  print_constant_terse_with_index (out, jcf, class_index, CONSTANT_Class); \
  fprintf (out, "\n  Method: ");                                        \
  fprintf (out, "\n  Method: ");                                        \
  print_constant_terse_with_index (out, jcf, method_index,              \
  print_constant_terse_with_index (out, jcf, method_index,              \
                                   CONSTANT_NameAndType);               \
                                   CONSTANT_NameAndType);               \
  fputc ('\n', out);                                                    \
  fputc ('\n', out);                                                    \
}
}
 
 
#define HANDLE_SIGNATURE_ATTRIBUTE()                                    \
#define HANDLE_SIGNATURE_ATTRIBUTE()                                    \
{                                                                       \
{                                                                       \
  uint16 signature;                                                     \
  uint16 signature;                                                     \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  signature = JCF_readu2 (jcf);                                         \
  signature = JCF_readu2 (jcf);                                         \
  fprintf (out, "\n  Value: ");                                         \
  fprintf (out, "\n  Value: ");                                         \
  print_constant_terse_with_index (out, jcf, signature, CONSTANT_Utf8); \
  print_constant_terse_with_index (out, jcf, signature, CONSTANT_Utf8); \
  fputc ('\n', out);                                                    \
  fputc ('\n', out);                                                    \
}
}
 
 
#define HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE()                    \
#define HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE()                    \
{                                                                       \
{                                                                       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  print_annotations (out, jcf, 1);                                      \
  print_annotations (out, jcf, 1);                                      \
}
}
 
 
#define HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE()                  \
#define HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE()                  \
{                                                                       \
{                                                                       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  print_annotations (out, jcf, 1);                                      \
  print_annotations (out, jcf, 1);                                      \
}
}
 
 
#define HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE()           \
#define HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE()           \
{                                                                       \
{                                                                       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  print_parameter_annotations (out, jcf, 1);                            \
  print_parameter_annotations (out, jcf, 1);                            \
}
}
 
 
#define HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE()         \
#define HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE()         \
{                                                                       \
{                                                                       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  print_parameter_annotations (out, jcf, 1);                            \
  print_parameter_annotations (out, jcf, 1);                            \
}
}
 
 
#define HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE()                            \
#define HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE()                            \
{                                                                       \
{                                                                       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);       \
  print_element_value (out, jcf, 1);                                    \
  print_element_value (out, jcf, 1);                                    \
}
}
 
 
 
 
#define PROCESS_OTHER_ATTRIBUTE(JCF, INDEX, LENGTH) \
#define PROCESS_OTHER_ATTRIBUTE(JCF, INDEX, LENGTH) \
{ COMMON_HANDLE_ATTRIBUTE(JCF, INDEX, LENGTH); \
{ COMMON_HANDLE_ATTRIBUTE(JCF, INDEX, LENGTH); \
  fputc ('\n', out); JCF_SKIP (JCF, LENGTH); }
  fputc ('\n', out); JCF_SKIP (JCF, LENGTH); }
 
 
#define START_FINAL_ATTRIBUTES(ATTRIBUTES_COUNT) \
#define START_FINAL_ATTRIBUTES(ATTRIBUTES_COUNT) \
  if (flag_print_attributes > 0) \
  if (flag_print_attributes > 0) \
    fprintf (out, "\nAttributes (count: %d):\n", attributes_count);
    fprintf (out, "\nAttributes (count: %d):\n", attributes_count);
 
 
#include "javaop.h"
#include "javaop.h"
 
 


 
 
static void
static void
indent (FILE *stream, int level)
indent (FILE *stream, int level)
{
{
  int i;
  int i;
  for (i = 0; i < level; ++i)
  for (i = 0; i < level; ++i)
    fprintf (stream, "  ");
    fprintf (stream, "  ");
}
}
 
 
static void
static void
print_element_value (FILE *stream, JCF *jcf, int level)
print_element_value (FILE *stream, JCF *jcf, int level)
{
{
  uint8 tag = JCF_readu (jcf);
  uint8 tag = JCF_readu (jcf);
  indent (stream, level);
  indent (stream, level);
  switch (tag)
  switch (tag)
    {
    {
    case 'B':
    case 'B':
    case 'C':
    case 'C':
    case 'S':
    case 'S':
    case 'Z':
    case 'Z':
    case 'I':
    case 'I':
      {
      {
        uint16 cindex = JCF_readu2 (jcf);
        uint16 cindex = JCF_readu2 (jcf);
        print_constant_terse_with_index (stream, jcf, cindex,
        print_constant_terse_with_index (stream, jcf, cindex,
                                         CONSTANT_Integer);
                                         CONSTANT_Integer);
      }
      }
      break;
      break;
    case 'D':
    case 'D':
      {
      {
        uint16 cindex = JCF_readu2 (jcf);
        uint16 cindex = JCF_readu2 (jcf);
        print_constant_terse_with_index (stream, jcf, cindex,
        print_constant_terse_with_index (stream, jcf, cindex,
                                         CONSTANT_Double);
                                         CONSTANT_Double);
      }
      }
      break;
      break;
    case 'F':
    case 'F':
      {
      {
        uint16 cindex = JCF_readu2 (jcf);
        uint16 cindex = JCF_readu2 (jcf);
        print_constant_terse_with_index (stream, jcf, cindex,
        print_constant_terse_with_index (stream, jcf, cindex,
                                         CONSTANT_Float);
                                         CONSTANT_Float);
      }
      }
      break;
      break;
    case 'J':
    case 'J':
      {
      {
        uint16 cindex = JCF_readu2 (jcf);
        uint16 cindex = JCF_readu2 (jcf);
        print_constant_terse_with_index (stream, jcf, cindex,
        print_constant_terse_with_index (stream, jcf, cindex,
                                         CONSTANT_Long);
                                         CONSTANT_Long);
      }
      }
      break;
      break;
    case 's':
    case 's':
      {
      {
        uint16 cindex = JCF_readu2 (jcf);
        uint16 cindex = JCF_readu2 (jcf);
        /* Despite what the JVM spec says, compilers generate a Utf8
        /* Despite what the JVM spec says, compilers generate a Utf8
           constant here, not a String.  */
           constant here, not a String.  */
        print_constant_terse_with_index (stream, jcf, cindex,
        print_constant_terse_with_index (stream, jcf, cindex,
                                         CONSTANT_Utf8);
                                         CONSTANT_Utf8);
      }
      }
      break;
      break;
 
 
    case 'e':
    case 'e':
      {
      {
        uint16 type_name_index = JCF_readu2 (jcf);
        uint16 type_name_index = JCF_readu2 (jcf);
        uint16 const_name_index = JCF_readu2 (jcf);
        uint16 const_name_index = JCF_readu2 (jcf);
        fprintf (stream, "enum class: ");
        fprintf (stream, "enum class: ");
        print_constant_terse_with_index (stream, jcf, type_name_index,
        print_constant_terse_with_index (stream, jcf, type_name_index,
                                         CONSTANT_Utf8);
                                         CONSTANT_Utf8);
        fprintf (stream, "\n");
        fprintf (stream, "\n");
        indent (stream, level);
        indent (stream, level);
        fprintf (stream, "Field: ");
        fprintf (stream, "Field: ");
        print_constant_terse_with_index (stream, jcf, const_name_index,
        print_constant_terse_with_index (stream, jcf, const_name_index,
                                         CONSTANT_Utf8);
                                         CONSTANT_Utf8);
      }
      }
      break;
      break;
    case 'c':
    case 'c':
      {
      {
        uint16 class_info_index = JCF_readu2 (jcf);
        uint16 class_info_index = JCF_readu2 (jcf);
        print_constant_terse_with_index (stream, jcf, class_info_index,
        print_constant_terse_with_index (stream, jcf, class_info_index,
                                         CONSTANT_Utf8);
                                         CONSTANT_Utf8);
      }
      }
      break;
      break;
    case '@':
    case '@':
      {
      {
        fprintf (stream, "Annotation:\n");
        fprintf (stream, "Annotation:\n");
        print_annotation (stream, jcf, level + 1);
        print_annotation (stream, jcf, level + 1);
      }
      }
      break;
      break;
    case '[':
    case '[':
      {
      {
        uint16 n_array_elts = JCF_readu2 (jcf);
        uint16 n_array_elts = JCF_readu2 (jcf);
        fprintf (stream, "array[%d]: [\n", (int) n_array_elts);
        fprintf (stream, "array[%d]: [\n", (int) n_array_elts);
        while (n_array_elts--)
        while (n_array_elts--)
          print_element_value (stream, jcf, level + 1);
          print_element_value (stream, jcf, level + 1);
        indent (stream, level);
        indent (stream, level);
        fprintf (stream, "]");
        fprintf (stream, "]");
      }
      }
      break;
      break;
    default:
    default:
      fprintf (stream, "Unexpected tag value: %d", (int) tag);
      fprintf (stream, "Unexpected tag value: %d", (int) tag);
      break;
      break;
    }
    }
  fputc ('\n', stream);
  fputc ('\n', stream);
}
}
 
 
static void
static void
print_annotation (FILE *stream, JCF *jcf, int level)
print_annotation (FILE *stream, JCF *jcf, int level)
{
{
  uint16 type_index = JCF_readu2 (jcf);
  uint16 type_index = JCF_readu2 (jcf);
  uint16 npairs = JCF_readu2 (jcf);
  uint16 npairs = JCF_readu2 (jcf);
  fprintf (stream, "\n");
  fprintf (stream, "\n");
  indent (stream, level);
  indent (stream, level);
  fprintf (stream, "Annotation name: ");
  fprintf (stream, "Annotation name: ");
  print_constant_terse_with_index (stream, jcf, type_index,
  print_constant_terse_with_index (stream, jcf, type_index,
                                   CONSTANT_Utf8);
                                   CONSTANT_Utf8);
  if (npairs)
  if (npairs)
    {
    {
      fprintf (stream, "\n");
      fprintf (stream, "\n");
      while (npairs--)
      while (npairs--)
        {
        {
          uint16 name_index = JCF_readu2 (jcf);
          uint16 name_index = JCF_readu2 (jcf);
          indent (stream, level + 1);
          indent (stream, level + 1);
          fprintf (stream, "Name: ");
          fprintf (stream, "Name: ");
          print_constant_terse_with_index (stream, jcf, name_index,
          print_constant_terse_with_index (stream, jcf, name_index,
                                           CONSTANT_Utf8);
                                           CONSTANT_Utf8);
          fprintf (stream, "\n");
          fprintf (stream, "\n");
          print_element_value (stream, jcf, level + 2);
          print_element_value (stream, jcf, level + 2);
        }
        }
    }
    }
}
}
 
 
static void
static void
print_annotations (FILE *stream, JCF *jcf, int level)
print_annotations (FILE *stream, JCF *jcf, int level)
{
{
  uint16 num = JCF_readu2 (jcf);
  uint16 num = JCF_readu2 (jcf);
  while (num--)
  while (num--)
    print_annotation (stream, jcf, level);
    print_annotation (stream, jcf, level);
}
}
 
 
static void
static void
print_parameter_annotations (FILE *stream, JCF *jcf, int level)
print_parameter_annotations (FILE *stream, JCF *jcf, int level)
{
{
  uint8 nparams = JCF_readu (jcf);
  uint8 nparams = JCF_readu (jcf);
  uint8 i;
  uint8 i;
  for (i = 0; i < nparams; ++i)
  for (i = 0; i < nparams; ++i)
    {
    {
      indent (stream, level);
      indent (stream, level);
      fprintf (stream, "Parameter annotations (%d):\n", (int) i);
      fprintf (stream, "Parameter annotations (%d):\n", (int) i);
      print_annotations (stream, jcf, level + 1);
      print_annotations (stream, jcf, level + 1);
    }
    }
}
}
 
 


 
 
static void
static void
print_constant_ref (FILE *stream, JCF *jcf, int index)
print_constant_ref (FILE *stream, JCF *jcf, int index)
{
{
  if (index <= 0 || index >= JPOOL_SIZE(jcf))
  if (index <= 0 || index >= JPOOL_SIZE(jcf))
    fprintf (stream, "<out of range>");
    fprintf (stream, "<out of range>");
  else
  else
    {
    {
      if (flag_print_constant_pool)
      if (flag_print_constant_pool)
        fprintf (stream, "#%d=", index);
        fprintf (stream, "#%d=", index);
      fputc ('<', stream);
      fputc ('<', stream);
      print_constant (stream, jcf, index, 1);
      print_constant (stream, jcf, index, 1);
      fputc ('>', stream);
      fputc ('>', stream);
    }
    }
}
}
 
 
/* Print the access flags given by FLAGS.
/* Print the access flags given by FLAGS.
   The CONTEXT is one of 'c' (class flags), 'f' (field flags),
   The CONTEXT is one of 'c' (class flags), 'f' (field flags),
   or 'm' (method flags). */
   or 'm' (method flags). */
 
 
static void
static void
print_access_flags (FILE *stream, uint16 flags, char context)
print_access_flags (FILE *stream, uint16 flags, char context)
{
{
  if (flags & ACC_PUBLIC) fprintf (stream, " public");
  if (flags & ACC_PUBLIC) fprintf (stream, " public");
  if (flags & ACC_PRIVATE) fprintf (stream, " private");
  if (flags & ACC_PRIVATE) fprintf (stream, " private");
  if (flags & ACC_PROTECTED) fprintf (stream, " protected");
  if (flags & ACC_PROTECTED) fprintf (stream, " protected");
  if (flags & ACC_ABSTRACT) fprintf (stream, " abstract");
  if (flags & ACC_ABSTRACT) fprintf (stream, " abstract");
  if (flags & ACC_STATIC) fprintf (stream, " static");
  if (flags & ACC_STATIC) fprintf (stream, " static");
  if (flags & ACC_FINAL) fprintf (stream, " final");
  if (flags & ACC_FINAL) fprintf (stream, " final");
  if (flags & ACC_TRANSIENT)
  if (flags & ACC_TRANSIENT)
    fprintf (stream, context == 'm' ? " varargs" : " transient");
    fprintf (stream, context == 'm' ? " varargs" : " transient");
  if (flags & ACC_VOLATILE)
  if (flags & ACC_VOLATILE)
    fprintf (stream, context == 'm' ? " bridge" : " volatile");
    fprintf (stream, context == 'm' ? " bridge" : " volatile");
  if (flags & ACC_NATIVE) fprintf (stream, " native");
  if (flags & ACC_NATIVE) fprintf (stream, " native");
  if (flags & ACC_SYNCHRONIZED)
  if (flags & ACC_SYNCHRONIZED)
    {
    {
      if (context == 'c')
      if (context == 'c')
        fprintf (stream, " super");
        fprintf (stream, " super");
      else
      else
        fprintf (stream, " synchronized");
        fprintf (stream, " synchronized");
    }
    }
  if (flags & ACC_INTERFACE)
  if (flags & ACC_INTERFACE)
    fprintf (stream, (flags & ACC_ANNOTATION) ? " @interface" : " interface");
    fprintf (stream, (flags & ACC_ANNOTATION) ? " @interface" : " interface");
  if (flags & ACC_ENUM) fprintf (stream, " enum");
  if (flags & ACC_ENUM) fprintf (stream, " enum");
  if (flags & ACC_STRICT) fprintf (stream, " strictfp");
  if (flags & ACC_STRICT) fprintf (stream, " strictfp");
  if (flags & ACC_SYNTHETIC) fprintf (stream, " synthetic");
  if (flags & ACC_SYNTHETIC) fprintf (stream, " synthetic");
}
}
 
 
 
 
static void
static void
print_name (FILE* stream, JCF* jcf, int name_index)
print_name (FILE* stream, JCF* jcf, int name_index)
{
{
  if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
  if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
    fprintf (stream, "<not a UTF8 constant>");
    fprintf (stream, "<not a UTF8 constant>");
  else
  else
    jcf_print_utf8 (stream, JPOOL_UTF_DATA (jcf,name_index),
    jcf_print_utf8 (stream, JPOOL_UTF_DATA (jcf,name_index),
                    JPOOL_UTF_LENGTH (jcf, name_index));
                    JPOOL_UTF_LENGTH (jcf, name_index));
}
}
 
 
/* If the type of the constant at INDEX matches EXPECTED,
/* If the type of the constant at INDEX matches EXPECTED,
   print it tersely, otherwise more verbosely. */
   print it tersely, otherwise more verbosely. */
 
 
static void
static void
print_constant_terse (FILE *out, JCF *jcf, int index, int expected)
print_constant_terse (FILE *out, JCF *jcf, int index, int expected)
{
{
  if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, index))
  if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, index))
    fprintf (out, "<constant pool index %d not in range>", index);
    fprintf (out, "<constant pool index %d not in range>", index);
  else if (JPOOL_TAG (jcf, index) != expected)
  else if (JPOOL_TAG (jcf, index) != expected)
    {
    {
      fprintf (out, "<Unexpected constant type ");
      fprintf (out, "<Unexpected constant type ");
      print_constant (out, jcf, index, 1);
      print_constant (out, jcf, index, 1);
      fprintf (out, ">");
      fprintf (out, ">");
    }
    }
  else
  else
    print_constant (out, jcf, index, 0);
    print_constant (out, jcf, index, 0);
}
}
 
 
static void
static void
print_constant_terse_with_index (FILE *out, JCF *jcf, int index, int expected)
print_constant_terse_with_index (FILE *out, JCF *jcf, int index, int expected)
{
{
  if (flag_print_constant_pool)
  if (flag_print_constant_pool)
    fprintf (out, "%d=", index);
    fprintf (out, "%d=", index);
  print_constant_terse (out, jcf, index, expected);
  print_constant_terse (out, jcf, index, expected);
}
}
 
 
/* Print the constant at INDEX in JCF's constant pool.
/* Print the constant at INDEX in JCF's constant pool.
   If verbosity==0, print very tersely (no extraneous text).
   If verbosity==0, print very tersely (no extraneous text).
   If verbosity==1, prefix the type of the constant.
   If verbosity==1, prefix the type of the constant.
   If verbosity==2, add more descriptive text. */
   If verbosity==2, add more descriptive text. */
 
 
static void
static void
print_constant (FILE *out, JCF *jcf, int index, int verbosity)
print_constant (FILE *out, JCF *jcf, int index, int verbosity)
{
{
  int j, n;
  int j, n;
  jlong num;
  jlong num;
  const char *str;
  const char *str;
  int kind = JPOOL_TAG (jcf, index);
  int kind = JPOOL_TAG (jcf, index);
  switch (kind)
  switch (kind)
    {
    {
    case CONSTANT_Class:
    case CONSTANT_Class:
      n = JPOOL_USHORT1 (jcf, index);
      n = JPOOL_USHORT1 (jcf, index);
      if (verbosity > 0)
      if (verbosity > 0)
        {
        {
          if (verbosity > 1)
          if (verbosity > 1)
            fprintf (out, "Class name: %d=", n);
            fprintf (out, "Class name: %d=", n);
          else
          else
            fprintf (out, "Class ");
            fprintf (out, "Class ");
        }
        }
      if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, n))
      if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, n))
        fprintf (out, "<out of range>");
        fprintf (out, "<out of range>");
      else if (verbosity < 2 && JPOOL_TAG (jcf, n) == CONSTANT_Utf8)
      else if (verbosity < 2 && JPOOL_TAG (jcf, n) == CONSTANT_Utf8)
        {
        {
          int len = JPOOL_UTF_LENGTH (jcf, n);
          int len = JPOOL_UTF_LENGTH (jcf, n);
          jcf_print_utf8_replace (out, JPOOL_UTF_DATA(jcf,n), len, '/', '.');
          jcf_print_utf8_replace (out, JPOOL_UTF_DATA(jcf,n), len, '/', '.');
        }
        }
      else
      else
        print_constant_terse (out, jcf, n, CONSTANT_Utf8);
        print_constant_terse (out, jcf, n, CONSTANT_Utf8);
      break;
      break;
    case CONSTANT_Fieldref:
    case CONSTANT_Fieldref:
      str = "Field"; goto field_or_method;
      str = "Field"; goto field_or_method;
    case CONSTANT_Methodref:
    case CONSTANT_Methodref:
      str = "Method"; goto field_or_method;
      str = "Method"; goto field_or_method;
    case CONSTANT_InterfaceMethodref:
    case CONSTANT_InterfaceMethodref:
      str = "InterfaceMethod"; goto field_or_method;
      str = "InterfaceMethod"; goto field_or_method;
    field_or_method:
    field_or_method:
      {
      {
        uint16 tclass = JPOOL_USHORT1 (jcf, index);
        uint16 tclass = JPOOL_USHORT1 (jcf, index);
        uint16 name_and_type = JPOOL_USHORT2 (jcf, index);
        uint16 name_and_type = JPOOL_USHORT2 (jcf, index);
        if (verbosity == 2)
        if (verbosity == 2)
          fprintf (out, "%sref class: %d=", str, tclass);
          fprintf (out, "%sref class: %d=", str, tclass);
        else if (verbosity > 0)
        else if (verbosity > 0)
            fprintf (out, "%s ", str);
            fprintf (out, "%s ", str);
        print_constant_terse (out, jcf, tclass, CONSTANT_Class);
        print_constant_terse (out, jcf, tclass, CONSTANT_Class);
        if (verbosity < 2)
        if (verbosity < 2)
          fprintf (out, ".");
          fprintf (out, ".");
        else
        else
          fprintf (out, " name_and_type: %d=<", name_and_type);
          fprintf (out, " name_and_type: %d=<", name_and_type);
        print_constant_terse (out, jcf, name_and_type, CONSTANT_NameAndType);
        print_constant_terse (out, jcf, name_and_type, CONSTANT_NameAndType);
        if (verbosity == 2)
        if (verbosity == 2)
          fputc ('>', out);
          fputc ('>', out);
      }
      }
      break;
      break;
    case CONSTANT_String:
    case CONSTANT_String:
      j = JPOOL_USHORT1 (jcf, index);
      j = JPOOL_USHORT1 (jcf, index);
      if (verbosity > 0)
      if (verbosity > 0)
        {
        {
          if (verbosity > 1)
          if (verbosity > 1)
            fprintf (out, "String %d=", j);
            fprintf (out, "String %d=", j);
          else
          else
            fprintf (out, "String ");
            fprintf (out, "String ");
        }
        }
      print_constant_terse (out, jcf, j, CONSTANT_Utf8);
      print_constant_terse (out, jcf, j, CONSTANT_Utf8);
      break;
      break;
    case CONSTANT_Integer:
    case CONSTANT_Integer:
      if (verbosity > 0)
      if (verbosity > 0)
        fprintf (out, "Integer ");
        fprintf (out, "Integer ");
      num = JPOOL_INT (jcf, index);
      num = JPOOL_INT (jcf, index);
      goto integer;
      goto integer;
    case CONSTANT_Long:
    case CONSTANT_Long:
      if (verbosity > 0)
      if (verbosity > 0)
        fprintf (out, "Long ");
        fprintf (out, "Long ");
      num = JPOOL_LONG (jcf, index);
      num = JPOOL_LONG (jcf, index);
      goto integer;
      goto integer;
    integer:
    integer:
      {
      {
        char buffer[25];
        char buffer[25];
        format_int (buffer, num, 10);
        format_int (buffer, num, 10);
        fprintf (out, "%s", buffer);
        fprintf (out, "%s", buffer);
        if (verbosity > 1)
        if (verbosity > 1)
          {
          {
            format_uint (buffer, (uint64)num, 16);
            format_uint (buffer, (uint64)num, 16);
            fprintf (out, "=0x%s", buffer);
            fprintf (out, "=0x%s", buffer);
          }
          }
      }
      }
      break;
      break;
    case CONSTANT_Float:
    case CONSTANT_Float:
      {
      {
        jfloat fnum = JPOOL_FLOAT (jcf, index);
        jfloat fnum = JPOOL_FLOAT (jcf, index);
 
 
        if (verbosity > 0)
        if (verbosity > 0)
          fputs ("Float ", out);
          fputs ("Float ", out);
 
 
        if (fnum.negative)
        if (fnum.negative)
          putc ('-', out);
          putc ('-', out);
 
 
        if (JFLOAT_FINITE (fnum))
        if (JFLOAT_FINITE (fnum))
          {
          {
            int dummy;
            int dummy;
            int exponent = fnum.exponent - JFLOAT_EXP_BIAS;
            int exponent = fnum.exponent - JFLOAT_EXP_BIAS;
            double f;
            double f;
            uint32 mantissa = fnum.mantissa;
            uint32 mantissa = fnum.mantissa;
            if (fnum.exponent == 0)
            if (fnum.exponent == 0)
              /* Denormal.  */
              /* Denormal.  */
              exponent++;
              exponent++;
            else
            else
              /* Normal; add the implicit bit.  */
              /* Normal; add the implicit bit.  */
              mantissa |= ((uint32)1 << 23);
              mantissa |= ((uint32)1 << 23);
 
 
            f = frexp (mantissa, &dummy);
            f = frexp (mantissa, &dummy);
            f = ldexp (f, exponent + 1);
            f = ldexp (f, exponent + 1);
            fprintf (out, "%.10g", f);
            fprintf (out, "%.10g", f);
          }
          }
        else
        else
          {
          {
            if (fnum.mantissa == 0)
            if (fnum.mantissa == 0)
              fputs ("Inf", out);
              fputs ("Inf", out);
            else if (fnum.mantissa & JFLOAT_QNAN_MASK)
            else if (fnum.mantissa & JFLOAT_QNAN_MASK)
              fprintf (out, "QNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK));
              fprintf (out, "QNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK));
            else
            else
              fprintf (out, "SNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK));
              fprintf (out, "SNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK));
          }
          }
 
 
        if (verbosity > 1)
        if (verbosity > 1)
          fprintf (out, ", bits = 0x%08lx", (unsigned long) JPOOL_UINT (jcf, index));
          fprintf (out, ", bits = 0x%08lx", (unsigned long) JPOOL_UINT (jcf, index));
 
 
        break;
        break;
      }
      }
    case CONSTANT_Double:
    case CONSTANT_Double:
      {
      {
        jdouble dnum = JPOOL_DOUBLE (jcf, index);
        jdouble dnum = JPOOL_DOUBLE (jcf, index);
 
 
        if (verbosity > 0)
        if (verbosity > 0)
          fputs ("Double ", out);
          fputs ("Double ", out);
 
 
        if (dnum.negative)
        if (dnum.negative)
          putc ('-', out);
          putc ('-', out);
 
 
        if (JDOUBLE_FINITE (dnum))
        if (JDOUBLE_FINITE (dnum))
          {
          {
            int dummy;
            int dummy;
            int exponent = dnum.exponent - JDOUBLE_EXP_BIAS;
            int exponent = dnum.exponent - JDOUBLE_EXP_BIAS;
            double d;
            double d;
            uint64 mantissa = ((((uint64) dnum.mantissa0) << 32)
            uint64 mantissa = ((((uint64) dnum.mantissa0) << 32)
                               + dnum.mantissa1);
                               + dnum.mantissa1);
            if (dnum.exponent == 0)
            if (dnum.exponent == 0)
              /* Denormal.  */
              /* Denormal.  */
              exponent++;
              exponent++;
            else
            else
              /* Normal; add the implicit bit.  */
              /* Normal; add the implicit bit.  */
              mantissa |= ((uint64)1 << 52);
              mantissa |= ((uint64)1 << 52);
 
 
            d = frexp (mantissa, &dummy);
            d = frexp (mantissa, &dummy);
            d = ldexp (d, exponent + 1);
            d = ldexp (d, exponent + 1);
            fprintf (out, "%.20g", d);
            fprintf (out, "%.20g", d);
          }
          }
        else
        else
          {
          {
            uint64 mantissa = dnum.mantissa0 & ~JDOUBLE_QNAN_MASK;
            uint64 mantissa = dnum.mantissa0 & ~JDOUBLE_QNAN_MASK;
            mantissa = (mantissa << 32) + dnum.mantissa1;
            mantissa = (mantissa << 32) + dnum.mantissa1;
 
 
            if (dnum.mantissa0 == 0 && dnum.mantissa1 == 0)
            if (dnum.mantissa0 == 0 && dnum.mantissa1 == 0)
              fputs ("Inf", out);
              fputs ("Inf", out);
            else if (dnum.mantissa0 & JDOUBLE_QNAN_MASK)
            else if (dnum.mantissa0 & JDOUBLE_QNAN_MASK)
              fprintf (out, "QNaN(%" HOST_LONG_LONG_FORMAT "u)",
              fprintf (out, "QNaN(%" HOST_LONG_LONG_FORMAT "u)",
                (unsigned long long)mantissa);
                (unsigned long long)mantissa);
            else
            else
              fprintf (out, "SNaN(%" HOST_LONG_LONG_FORMAT "u)",
              fprintf (out, "SNaN(%" HOST_LONG_LONG_FORMAT "u)",
                (unsigned long long)mantissa);
                (unsigned long long)mantissa);
          }
          }
        if (verbosity > 1)
        if (verbosity > 1)
          {
          {
            int32 hi, lo;
            int32 hi, lo;
            hi = JPOOL_UINT (jcf, index);
            hi = JPOOL_UINT (jcf, index);
            lo = JPOOL_UINT (jcf, index + 1);
            lo = JPOOL_UINT (jcf, index + 1);
            fprintf (out, ", bits = 0x%08lx%08lx", (unsigned long) hi,
            fprintf (out, ", bits = 0x%08lx%08lx", (unsigned long) hi,
                     (unsigned long) lo);
                     (unsigned long) lo);
          }
          }
        break;
        break;
      }
      }
    case CONSTANT_NameAndType:
    case CONSTANT_NameAndType:
      {
      {
        uint16 name = JPOOL_USHORT1 (jcf, index);
        uint16 name = JPOOL_USHORT1 (jcf, index);
        uint16 sig = JPOOL_USHORT2 (jcf, index);
        uint16 sig = JPOOL_USHORT2 (jcf, index);
        if (verbosity > 0)
        if (verbosity > 0)
          {
          {
            if (verbosity > 1)
            if (verbosity > 1)
              fprintf (out, "NameAndType name: %d=", name);
              fprintf (out, "NameAndType name: %d=", name);
            else
            else
              fprintf (out, "NameAndType ");
              fprintf (out, "NameAndType ");
          }
          }
        print_name (out, jcf, name);
        print_name (out, jcf, name);
        if (verbosity <= 1)
        if (verbosity <= 1)
          fputc (' ', out);
          fputc (' ', out);
        else
        else
          fprintf (out, ", signature: %d=", sig);
          fprintf (out, ", signature: %d=", sig);
        print_signature (out, jcf, sig, 0);
        print_signature (out, jcf, sig, 0);
      }
      }
      break;
      break;
    case CONSTANT_Utf8:
    case CONSTANT_Utf8:
      {
      {
        const unsigned char *str = JPOOL_UTF_DATA (jcf, index);
        const unsigned char *str = JPOOL_UTF_DATA (jcf, index);
        int length = JPOOL_UTF_LENGTH (jcf, index);
        int length = JPOOL_UTF_LENGTH (jcf, index);
        if (verbosity > 0)
        if (verbosity > 0)
          { /* Print as 8-bit bytes. */
          { /* Print as 8-bit bytes. */
            fputs ("Utf8: \"", out);
            fputs ("Utf8: \"", out);
            while (--length >= 0)
            while (--length >= 0)
              jcf_print_char (out, *str++);
              jcf_print_char (out, *str++);
          }
          }
        else
        else
          { /* Print as Unicode. */
          { /* Print as Unicode. */
            fputc ('\"', out);
            fputc ('\"', out);
            jcf_print_utf8 (out, str, length);
            jcf_print_utf8 (out, str, length);
          }
          }
        fputc ('\"', out);
        fputc ('\"', out);
      }
      }
      break;
      break;
    default:
    default:
      fprintf (out, "(Unknown constant type %d)", kind);
      fprintf (out, "(Unknown constant type %d)", kind);
    }
    }
}
}
 
 
static void
static void
print_constant_pool (JCF *jcf)
print_constant_pool (JCF *jcf)
{
{
  int i;
  int i;
  for (i = 1; i < JPOOL_SIZE(jcf); i++)
  for (i = 1; i < JPOOL_SIZE(jcf); i++)
    {
    {
      int kind = JPOOL_TAG (jcf, i);
      int kind = JPOOL_TAG (jcf, i);
      fprintf (out, "#%d: ", i);
      fprintf (out, "#%d: ", i);
      print_constant (out, jcf, i, 2);
      print_constant (out, jcf, i, 2);
      fprintf (out, "\n");
      fprintf (out, "\n");
      if (kind == CONSTANT_Double || kind == CONSTANT_Long)
      if (kind == CONSTANT_Double || kind == CONSTANT_Long)
        i++; /* These take up two slots in the constant table */
        i++; /* These take up two slots in the constant table */
    }
    }
}
}
 
 
static void
static void
print_signature_type (FILE* stream, const unsigned char **ptr,
print_signature_type (FILE* stream, const unsigned char **ptr,
                      const unsigned char *limit)
                      const unsigned char *limit)
{
{
  int array_size;
  int array_size;
  if ((*ptr) >= limit)
  if ((*ptr) >= limit)
    return;
    return;
  switch (*(*ptr))
  switch (*(*ptr))
    {
    {
    case '[':
    case '[':
      array_size = -1;
      array_size = -1;
      for ((*ptr)++; (*ptr) < limit && ISDIGIT (**ptr); (*ptr)++)
      for ((*ptr)++; (*ptr) < limit && ISDIGIT (**ptr); (*ptr)++)
        {
        {
          array_size = (array_size < 0 ? 0 : 10 * array_size) + *(*ptr) - '0';
          array_size = (array_size < 0 ? 0 : 10 * array_size) + *(*ptr) - '0';
        }
        }
      print_signature_type (stream, ptr, limit);
      print_signature_type (stream, ptr, limit);
      if (array_size == -1)
      if (array_size == -1)
        fprintf (stream, "[]");
        fprintf (stream, "[]");
      else
      else
        fprintf (stream, "[%d]", array_size);
        fprintf (stream, "[%d]", array_size);
      break;
      break;
    case '(':
    case '(':
      {
      {
        int nargs = 0;
        int nargs = 0;
        fputc (*(*ptr)++, stream);
        fputc (*(*ptr)++, stream);
        for (; **ptr != ')' && *ptr < limit; nargs++)
        for (; **ptr != ')' && *ptr < limit; nargs++)
          {
          {
            if (nargs > 0)
            if (nargs > 0)
              fputc (',', stream);
              fputc (',', stream);
            print_signature_type (stream, ptr, limit);
            print_signature_type (stream, ptr, limit);
          }
          }
        if (*ptr < limit)
        if (*ptr < limit)
          {
          {
            fputc (*(*ptr)++, stream);
            fputc (*(*ptr)++, stream);
            print_signature_type (stream, ptr, limit);
            print_signature_type (stream, ptr, limit);
          }
          }
        else
        else
          fprintf (stream, "???");
          fprintf (stream, "???");
      }
      }
    break;
    break;
 
 
    case 'B':  fprintf (stream, "byte");  (*ptr)++;  break;
    case 'B':  fprintf (stream, "byte");  (*ptr)++;  break;
    case 'C':  fprintf (stream, "char");  (*ptr)++;  break;
    case 'C':  fprintf (stream, "char");  (*ptr)++;  break;
    case 'D':  fprintf (stream, "double");  (*ptr)++;  break;
    case 'D':  fprintf (stream, "double");  (*ptr)++;  break;
    case 'F':  fprintf (stream, "float");  (*ptr)++;  break;
    case 'F':  fprintf (stream, "float");  (*ptr)++;  break;
    case 'S':  fprintf (stream, "short");  (*ptr)++;  break;
    case 'S':  fprintf (stream, "short");  (*ptr)++;  break;
    case 'I':  fprintf (stream, "int");  (*ptr)++;  break;
    case 'I':  fprintf (stream, "int");  (*ptr)++;  break;
    case 'J':  fprintf (stream, "long");  (*ptr)++;  break;
    case 'J':  fprintf (stream, "long");  (*ptr)++;  break;
    case 'Z':  fprintf (stream, "boolean");  (*ptr)++;  break;
    case 'Z':  fprintf (stream, "boolean");  (*ptr)++;  break;
    case 'V':  fprintf (stream, "void");  (*ptr)++;  break;
    case 'V':  fprintf (stream, "void");  (*ptr)++;  break;
 
 
    case 'L':
    case 'L':
      for ((*ptr)++; (*ptr)<limit && *(*ptr) != ';'; (*ptr)++)
      for ((*ptr)++; (*ptr)<limit && *(*ptr) != ';'; (*ptr)++)
        jcf_print_char (stream, *(*ptr) == '/' ? '.' : *(*ptr));
        jcf_print_char (stream, *(*ptr) == '/' ? '.' : *(*ptr));
      if (*(*ptr) == ';')
      if (*(*ptr) == ';')
        (*ptr)++;
        (*ptr)++;
      break;
      break;
    default:
    default:
      jcf_print_char (stream, *(*ptr)++);
      jcf_print_char (stream, *(*ptr)++);
    }
    }
}
}
 
 
static void
static void
print_signature (FILE* stream, JCF *jcf, int signature_index, int options)
print_signature (FILE* stream, JCF *jcf, int signature_index, int options)
{
{
  if (JPOOL_TAG (jcf, signature_index) != CONSTANT_Utf8)
  if (JPOOL_TAG (jcf, signature_index) != CONSTANT_Utf8)
    print_constant_terse (out, jcf, signature_index, CONSTANT_Utf8);
    print_constant_terse (out, jcf, signature_index, CONSTANT_Utf8);
  else
  else
    {
    {
      const unsigned char *str = JPOOL_UTF_DATA (jcf, signature_index);
      const unsigned char *str = JPOOL_UTF_DATA (jcf, signature_index);
      int length = JPOOL_UTF_LENGTH (jcf, signature_index);
      int length = JPOOL_UTF_LENGTH (jcf, signature_index);
      const unsigned char *limit;
      const unsigned char *limit;
      limit = str + length;
      limit = str + length;
      if (str >= limit)
      if (str >= limit)
        fprintf (stream, "<empty signature string>");
        fprintf (stream, "<empty signature string>");
      else
      else
        {
        {
          if (options & PRINT_SIGNATURE_RESULT_ONLY)
          if (options & PRINT_SIGNATURE_RESULT_ONLY)
            {
            {
              while (str < limit && *str++ != ')') ;
              while (str < limit && *str++ != ')') ;
            }
            }
          if (options & PRINT_SIGNATURE_ARGS_ONLY)
          if (options & PRINT_SIGNATURE_ARGS_ONLY)
            {
            {
              str++;
              str++;
              fputc ('(', stream);
              fputc ('(', stream);
              while (str < limit && *str != ')')
              while (str < limit && *str != ')')
                {
                {
                  print_signature_type (stream, &str, limit);
                  print_signature_type (stream, &str, limit);
                  if (*str != ')')
                  if (*str != ')')
                    fputs (", ", stream);
                    fputs (", ", stream);
                }
                }
              fputc (')', stream);
              fputc (')', stream);
            }
            }
          else
          else
            {
            {
              print_signature_type (stream, &str, limit);
              print_signature_type (stream, &str, limit);
              if (str < limit)
              if (str < limit)
                {
                {
                  fprintf (stream, "<junk:");
                  fprintf (stream, "<junk:");
                  jcf_print_utf8 (stream, str, limit - str);
                  jcf_print_utf8 (stream, str, limit - str);
                  fputc ('>', stream);
                  fputc ('>', stream);
                }
                }
            }
            }
        }
        }
    }
    }
}
}
 
 
 
 
static void
static void
print_exception_table (JCF *jcf, const unsigned char *entries, int count)
print_exception_table (JCF *jcf, const unsigned char *entries, int count)
{
{
  /* Print exception table. */
  /* Print exception table. */
  int i = count;
  int i = count;
  if (i > 0)
  if (i > 0)
    {
    {
      const unsigned char *ptr = entries;
      const unsigned char *ptr = entries;
      fprintf (out, "Exceptions (count: %d):\n", i);
      fprintf (out, "Exceptions (count: %d):\n", i);
      for (; --i >= 0;  ptr+= 8)
      for (; --i >= 0;  ptr+= 8)
        {
        {
          int start_pc = GET_u2 (ptr);
          int start_pc = GET_u2 (ptr);
          int end_pc = GET_u2 (ptr+2);
          int end_pc = GET_u2 (ptr+2);
          int handler_pc = GET_u2 (ptr+4);
          int handler_pc = GET_u2 (ptr+4);
          int catch_type = GET_u2 (ptr+6);
          int catch_type = GET_u2 (ptr+6);
          fprintf (out, "  start: %d, end: %d, handler: %d, type: ",
          fprintf (out, "  start: %d, end: %d, handler: %d, type: ",
                   start_pc, end_pc, handler_pc);
                   start_pc, end_pc, handler_pc);
          if (catch_type == 0)
          if (catch_type == 0)
            fputs ("0 /* finally */", out);
            fputs ("0 /* finally */", out);
          else
          else
            print_constant_terse_with_index (out, jcf,
            print_constant_terse_with_index (out, jcf,
                                             catch_type, CONSTANT_Class);
                                             catch_type, CONSTANT_Class);
          fputc ('\n', out);
          fputc ('\n', out);
        }
        }
    }
    }
}
}
 
 
#include "jcf-reader.c"
#include "jcf-reader.c"
 
 
static void
static void
process_class (JCF *jcf)
process_class (JCF *jcf)
{
{
  int code;
  int code;
  if (jcf_parse_preamble (jcf) != 0)
  if (jcf_parse_preamble (jcf) != 0)
    fprintf (stderr, _("Not a valid Java .class file.\n"));
    fprintf (stderr, _("Not a valid Java .class file.\n"));
 
 
  /* Parse and possibly print constant pool */
  /* Parse and possibly print constant pool */
  code = jcf_parse_constant_pool (jcf);
  code = jcf_parse_constant_pool (jcf);
  if (code != 0)
  if (code != 0)
    {
    {
      fprintf (stderr, _("error while parsing constant pool\n"));
      fprintf (stderr, _("error while parsing constant pool\n"));
      exit (FATAL_EXIT_CODE);
      exit (FATAL_EXIT_CODE);
    }
    }
  code = verify_constant_pool (jcf);
  code = verify_constant_pool (jcf);
  if (code > 0)
  if (code > 0)
    {
    {
      fprintf (stderr, _("error in constant pool entry #%d\n"), code);
      fprintf (stderr, _("error in constant pool entry #%d\n"), code);
      exit (FATAL_EXIT_CODE);
      exit (FATAL_EXIT_CODE);
    }
    }
  if (flag_print_constant_pool)
  if (flag_print_constant_pool)
    print_constant_pool (jcf);
    print_constant_pool (jcf);
 
 
  jcf_parse_class (jcf);
  jcf_parse_class (jcf);
  code = jcf_parse_fields (jcf);
  code = jcf_parse_fields (jcf);
  if (code != 0)
  if (code != 0)
    {
    {
      fprintf (stderr, _("error while parsing fields\n"));
      fprintf (stderr, _("error while parsing fields\n"));
      exit (FATAL_EXIT_CODE);
      exit (FATAL_EXIT_CODE);
    }
    }
  code = jcf_parse_methods (jcf);
  code = jcf_parse_methods (jcf);
  if (code != 0)
  if (code != 0)
    {
    {
      fprintf (stderr, _("error while parsing methods\n"));
      fprintf (stderr, _("error while parsing methods\n"));
      exit (FATAL_EXIT_CODE);
      exit (FATAL_EXIT_CODE);
    }
    }
  code = jcf_parse_final_attributes (jcf);
  code = jcf_parse_final_attributes (jcf);
  if (code != 0)
  if (code != 0)
    {
    {
      fprintf (stderr, _("error while parsing final attributes\n"));
      fprintf (stderr, _("error while parsing final attributes\n"));
      exit (FATAL_EXIT_CODE);
      exit (FATAL_EXIT_CODE);
    }
    }
  jcf->filename = NULL;
  jcf->filename = NULL;
}
}
 
 


 
 
/* This is used to mark options with no short value.  */
/* This is used to mark options with no short value.  */
#define LONG_OPT(Num)  ((Num) + 128)
#define LONG_OPT(Num)  ((Num) + 128)
 
 
#define OPT_classpath     LONG_OPT (0)
#define OPT_classpath     LONG_OPT (0)
#define OPT_CLASSPATH     OPT_classpath
#define OPT_CLASSPATH     OPT_classpath
#define OPT_bootclasspath LONG_OPT (1)
#define OPT_bootclasspath LONG_OPT (1)
#define OPT_extdirs       LONG_OPT (2)
#define OPT_extdirs       LONG_OPT (2)
#define OPT_HELP          LONG_OPT (3)
#define OPT_HELP          LONG_OPT (3)
#define OPT_VERSION       LONG_OPT (4)
#define OPT_VERSION       LONG_OPT (4)
#define OPT_JAVAP         LONG_OPT (5)
#define OPT_JAVAP         LONG_OPT (5)
 
 
static const struct option options[] =
static const struct option options[] =
{
{
  { "classpath",     required_argument, NULL, OPT_classpath },
  { "classpath",     required_argument, NULL, OPT_classpath },
  { "bootclasspath", required_argument, NULL, OPT_bootclasspath },
  { "bootclasspath", required_argument, NULL, OPT_bootclasspath },
  { "extdirs",       required_argument, NULL, OPT_extdirs },
  { "extdirs",       required_argument, NULL, OPT_extdirs },
  { "CLASSPATH",     required_argument, NULL, OPT_CLASSPATH },
  { "CLASSPATH",     required_argument, NULL, OPT_CLASSPATH },
  { "help",          no_argument,       NULL, OPT_HELP },
  { "help",          no_argument,       NULL, OPT_HELP },
  { "verbose",       no_argument,       NULL, 'v' },
  { "verbose",       no_argument,       NULL, 'v' },
  { "version",       no_argument,       NULL, OPT_VERSION },
  { "version",       no_argument,       NULL, OPT_VERSION },
  { "javap",         no_argument,       NULL, OPT_JAVAP },
  { "javap",         no_argument,       NULL, OPT_JAVAP },
  { "print-main",    no_argument,       &flag_print_main, 1 },
  { "print-main",    no_argument,       &flag_print_main, 1 },
  { "print-constants", no_argument,     &flag_print_constant_pool, 1 },
  { "print-constants", no_argument,     &flag_print_constant_pool, 1 },
  { NULL,            no_argument,       NULL, 0 }
  { NULL,            no_argument,       NULL, 0 }
};
};
 
 
static void
static void
usage (void)
usage (void)
{
{
  fprintf (stderr, _("Try 'jcf-dump --help' for more information.\n"));
  fprintf (stderr, _("Try 'jcf-dump --help' for more information.\n"));
  exit (1);
  exit (1);
}
}
 
 
static void
static void
help (void)
help (void)
{
{
  printf (_("Usage: jcf-dump [OPTION]... CLASS...\n\n"));
  printf (_("Usage: jcf-dump [OPTION]... CLASS...\n\n"));
  printf (_("Display contents of a class file in readable form.\n\n"));
  printf (_("Display contents of a class file in readable form.\n\n"));
  printf (_("  -c                      Disassemble method bodies\n"));
  printf (_("  -c                      Disassemble method bodies\n"));
  printf (_("  --javap                 Generate output in 'javap' format\n"));
  printf (_("  --javap                 Generate output in 'javap' format\n"));
  printf ("\n");
  printf ("\n");
  printf (_("  --classpath PATH        Set path to find .class files\n"));
  printf (_("  --classpath PATH        Set path to find .class files\n"));
  printf (_("  -IDIR                   Append directory to class path\n"));
  printf (_("  -IDIR                   Append directory to class path\n"));
  printf (_("  --bootclasspath PATH    Override built-in class path\n"));
  printf (_("  --bootclasspath PATH    Override built-in class path\n"));
  printf (_("  --extdirs PATH          Set extensions directory path\n"));
  printf (_("  --extdirs PATH          Set extensions directory path\n"));
  printf (_("  -o FILE                 Set output file name\n"));
  printf (_("  -o FILE                 Set output file name\n"));
  printf ("\n");
  printf ("\n");
  printf (_("  --help                  Print this help, then exit\n"));
  printf (_("  --help                  Print this help, then exit\n"));
  printf (_("  --version               Print version number, then exit\n"));
  printf (_("  --version               Print version number, then exit\n"));
  printf (_("  -v, --verbose           Print extra information while running\n"));
  printf (_("  -v, --verbose           Print extra information while running\n"));
  printf ("\n");
  printf ("\n");
  printf (_("For bug reporting instructions, please see:\n"
  printf (_("For bug reporting instructions, please see:\n"
            "%s.\n"), bug_report_url);
            "%s.\n"), bug_report_url);
  exit (0);
  exit (0);
}
}
 
 
static void
static void
version (void)
version (void)
{
{
  printf ("jcf-dump %s%s\n\n", pkgversion_string, version_string);
  printf ("jcf-dump %s%s\n\n", pkgversion_string, version_string);
  printf ("Copyright %s 2010 Free Software Foundation, Inc.\n", _("(C)"));
  printf ("Copyright %s 2010 Free Software Foundation, Inc.\n", _("(C)"));
  printf (_("This is free software; see the source for copying conditions.  There is NO\n"
  printf (_("This is free software; see the source for copying conditions.  There is NO\n"
            "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"));
            "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"));
  exit (0);
  exit (0);
}
}
 
 
int
int
main (int argc, char** argv)
main (int argc, char** argv)
{
{
  JCF jcf[1];
  JCF jcf[1];
  int argi, opt;
  int argi, opt;
 
 
  /* Unlock the stdio streams.  */
  /* Unlock the stdio streams.  */
  unlock_std_streams ();
  unlock_std_streams ();
 
 
  gcc_init_libintl ();
  gcc_init_libintl ();
 
 
  if (argc <= 1)
  if (argc <= 1)
    {
    {
      fprintf (stderr, _("jcf-dump: no classes specified\n"));
      fprintf (stderr, _("jcf-dump: no classes specified\n"));
      usage ();
      usage ();
    }
    }
 
 
  jcf_path_init ();
  jcf_path_init ();
 
 
  /* We use getopt_long_only to allow single `-' long options.  For
  /* We use getopt_long_only to allow single `-' long options.  For
     some of our options this is more natural.  */
     some of our options this is more natural.  */
  while ((opt = getopt_long_only (argc, argv, "o:I:vc", options, NULL)) != -1)
  while ((opt = getopt_long_only (argc, argv, "o:I:vc", options, NULL)) != -1)
    {
    {
      switch (opt)
      switch (opt)
        {
        {
        case 0:
        case 0:
          /* Already handled.  */
          /* Already handled.  */
          break;
          break;
 
 
        case 'o':
        case 'o':
          output_file = optarg;
          output_file = optarg;
          break;
          break;
 
 
        case 'I':
        case 'I':
          jcf_path_include_arg (optarg);
          jcf_path_include_arg (optarg);
          break;
          break;
 
 
        case 'v':
        case 'v':
          verbose++;
          verbose++;
          break;
          break;
 
 
        case 'c':
        case 'c':
          flag_disassemble_methods = 1;
          flag_disassemble_methods = 1;
          break;
          break;
 
 
        case OPT_classpath:
        case OPT_classpath:
          jcf_path_classpath_arg (optarg);
          jcf_path_classpath_arg (optarg);
          break;
          break;
 
 
        case OPT_bootclasspath:
        case OPT_bootclasspath:
          jcf_path_bootclasspath_arg (optarg);
          jcf_path_bootclasspath_arg (optarg);
          break;
          break;
 
 
        case OPT_extdirs:
        case OPT_extdirs:
          jcf_path_extdirs_arg (optarg);
          jcf_path_extdirs_arg (optarg);
          break;
          break;
 
 
        case OPT_HELP:
        case OPT_HELP:
          help ();
          help ();
          break;
          break;
 
 
        case OPT_VERSION:
        case OPT_VERSION:
          version ();
          version ();
          break;
          break;
 
 
        case OPT_JAVAP:
        case OPT_JAVAP:
          flag_javap_compatible++;
          flag_javap_compatible++;
          flag_print_constant_pool = 0;
          flag_print_constant_pool = 0;
          flag_print_attributes = 0;
          flag_print_attributes = 0;
          break;
          break;
 
 
        default:
        default:
          usage ();
          usage ();
        }
        }
    }
    }
 
 
  if (verbose && ! flag_javap_compatible)
  if (verbose && ! flag_javap_compatible)
    flag_print_constant_pool = 1;
    flag_print_constant_pool = 1;
 
 
  if (optind == argc)
  if (optind == argc)
    {
    {
      fprintf (stderr, _("jcf-dump: no classes specified\n"));
      fprintf (stderr, _("jcf-dump: no classes specified\n"));
      usage ();
      usage ();
    }
    }
 
 
  jcf_path_seal (verbose);
  jcf_path_seal (verbose);
 
 
  if (flag_print_main)
  if (flag_print_main)
    {
    {
      flag_print_fields = 0;
      flag_print_fields = 0;
      flag_print_methods = 0;
      flag_print_methods = 0;
      flag_print_constant_pool = 0;
      flag_print_constant_pool = 0;
      flag_print_attributes = 0;
      flag_print_attributes = 0;
      flag_print_class_info = 0;
      flag_print_class_info = 0;
    }
    }
 
 
  if (output_file)
  if (output_file)
    {
    {
      out = fopen (output_file, "w");
      out = fopen (output_file, "w");
      if (! out)
      if (! out)
        {
        {
          fprintf (stderr, _("Cannot open '%s' for output.\n"), output_file);
          fprintf (stderr, _("Cannot open '%s' for output.\n"), output_file);
          return FATAL_EXIT_CODE;
          return FATAL_EXIT_CODE;
        }
        }
    }
    }
  else
  else
    out = stdout;
    out = stdout;
 
 
  if (optind >= argc)
  if (optind >= argc)
    {
    {
      fprintf (out, "Reading .class from <standard input>.\n");
      fprintf (out, "Reading .class from <standard input>.\n");
      open_class ("<stdio>", jcf, 0, NULL);
      open_class ("<stdio>", jcf, 0, NULL);
      process_class (jcf);
      process_class (jcf);
    }
    }
  else
  else
    {
    {
      for (argi = optind; argi < argc; argi++)
      for (argi = optind; argi < argc; argi++)
        {
        {
          char *arg = argv[argi];
          char *arg = argv[argi];
          const char *class_filename = find_class (arg, strlen (arg), jcf);
          const char *class_filename = find_class (arg, strlen (arg), jcf);
          if (class_filename == NULL)
          if (class_filename == NULL)
            class_filename = find_classfile (arg, jcf, NULL);
            class_filename = find_classfile (arg, jcf, NULL);
          if (class_filename == NULL)
          if (class_filename == NULL)
            {
            {
              perror ("Could not find class");
              perror ("Could not find class");
              return FATAL_EXIT_CODE;
              return FATAL_EXIT_CODE;
            }
            }
          JCF_FILL (jcf, 4);
          JCF_FILL (jcf, 4);
          if (GET_u4 (jcf->read_ptr) == ZIPMAGIC)
          if (GET_u4 (jcf->read_ptr) == ZIPMAGIC)
            {
            {
              long compressed_size, member_size;
              long compressed_size, member_size;
              int compression_method, filename_length, extra_length;
              int compression_method, filename_length, extra_length;
              const char *filename;
              const char *filename;
              int total_length;
              int total_length;
              if (flag_print_class_info)
              if (flag_print_class_info)
                fprintf (out, "Reading classes from archive %s.\n",
                fprintf (out, "Reading classes from archive %s.\n",
                         class_filename);
                         class_filename);
              for (;;)
              for (;;)
                {
                {
                  int skip = 0;
                  int skip = 0;
                  jcf_filbuf_t save_filbuf = jcf->filbuf;
                  jcf_filbuf_t save_filbuf = jcf->filbuf;
                  long magic = JCF_readu4_le (jcf);
                  long magic = JCF_readu4_le (jcf);
                  if (magic == 0x02014b50 || magic == 0x06054b50)
                  if (magic == 0x02014b50 || magic == 0x06054b50)
                    break;  /* got to central directory */
                    break;  /* got to central directory */
                  if (magic != 0x04034b50) /* ZIPMAGIC (little-endian) */
                  if (magic != 0x04034b50) /* ZIPMAGIC (little-endian) */
                    {
                    {
                      fprintf (stderr, _("bad format of .zip/.jar archive\n"));
                      fprintf (stderr, _("bad format of .zip/.jar archive\n"));
                      return FATAL_EXIT_CODE;
                      return FATAL_EXIT_CODE;
                    }
                    }
                  JCF_FILL (jcf, 26);
                  JCF_FILL (jcf, 26);
                  JCF_SKIP (jcf, 2);
                  JCF_SKIP (jcf, 2);
                  (void) /* general_purpose_bits = */ JCF_readu2_le (jcf);
                  (void) /* general_purpose_bits = */ JCF_readu2_le (jcf);
                  compression_method = JCF_readu2_le (jcf);
                  compression_method = JCF_readu2_le (jcf);
                  JCF_SKIP (jcf, 8);
                  JCF_SKIP (jcf, 8);
                  compressed_size = JCF_readu4_le (jcf);
                  compressed_size = JCF_readu4_le (jcf);
                  member_size = JCF_readu4_le (jcf);
                  member_size = JCF_readu4_le (jcf);
                  filename_length = JCF_readu2_le (jcf);
                  filename_length = JCF_readu2_le (jcf);
                  extra_length = JCF_readu2_le (jcf);
                  extra_length = JCF_readu2_le (jcf);
                  total_length = filename_length + extra_length
                  total_length = filename_length + extra_length
                    + compressed_size;
                    + compressed_size;
                  if (jcf->read_end - jcf->read_ptr < total_length)
                  if (jcf->read_end - jcf->read_ptr < total_length)
                    jcf_trim_old_input (jcf);
                    jcf_trim_old_input (jcf);
                  JCF_FILL (jcf, total_length);
                  JCF_FILL (jcf, total_length);
                  filename = (const char *) jcf->read_ptr;
                  filename = (const char *) jcf->read_ptr;
                  JCF_SKIP (jcf, filename_length);
                  JCF_SKIP (jcf, filename_length);
                  JCF_SKIP (jcf, extra_length);
                  JCF_SKIP (jcf, extra_length);
                  if (filename_length > 0
                  if (filename_length > 0
                      && filename[filename_length-1] == '/')
                      && filename[filename_length-1] == '/')
                    {
                    {
                      if (flag_print_class_info)
                      if (flag_print_class_info)
                        fprintf (out, "[Skipping directory %.*s]\n",
                        fprintf (out, "[Skipping directory %.*s]\n",
                                 filename_length, filename);
                                 filename_length, filename);
                      skip = 1;
                      skip = 1;
                    }
                    }
                  else if (compression_method != 0)
                  else if (compression_method != 0)
                    {
                    {
                      if (flag_print_class_info)
                      if (flag_print_class_info)
                        fprintf (out, "[Skipping compressed file %.*s]\n",
                        fprintf (out, "[Skipping compressed file %.*s]\n",
                                 filename_length, filename);
                                 filename_length, filename);
                      skip = 1;
                      skip = 1;
                    }
                    }
                  else if (member_size < 4
                  else if (member_size < 4
                           || GET_u4 (jcf->read_ptr) != 0xcafebabe)
                           || GET_u4 (jcf->read_ptr) != 0xcafebabe)
                    {
                    {
                      if (flag_print_class_info)
                      if (flag_print_class_info)
                        fprintf (out, "[Skipping non-.class member %.*s]\n",
                        fprintf (out, "[Skipping non-.class member %.*s]\n",
                                 filename_length, filename);
                                 filename_length, filename);
                      skip = 1;
                      skip = 1;
                    }
                    }
                  else
                  else
                    {
                    {
                      if (flag_print_class_info)
                      if (flag_print_class_info)
                        fprintf (out, "Reading class member: %.*s.\n",
                        fprintf (out, "Reading class member: %.*s.\n",
                                 filename_length, filename);
                                 filename_length, filename);
                    }
                    }
                  if (skip)
                  if (skip)
                    {
                    {
                      JCF_SKIP (jcf, compressed_size);
                      JCF_SKIP (jcf, compressed_size);
                    }
                    }
                  else
                  else
                    {
                    {
                      unsigned char *save_end;
                      unsigned char *save_end;
                      jcf->filbuf = jcf_unexpected_eof;
                      jcf->filbuf = jcf_unexpected_eof;
                      save_end = jcf->read_end;
                      save_end = jcf->read_end;
                      jcf->read_end = jcf->read_ptr + compressed_size;
                      jcf->read_end = jcf->read_ptr + compressed_size;
                      process_class (jcf);
                      process_class (jcf);
                      jcf->filbuf = save_filbuf;
                      jcf->filbuf = save_filbuf;
                      jcf->read_end = save_end;
                      jcf->read_end = save_end;
                    }
                    }
                }
                }
            }
            }
          else
          else
            {
            {
              if (flag_print_class_info)
              if (flag_print_class_info)
                fprintf (out, "Reading .class from %s.\n", class_filename);
                fprintf (out, "Reading .class from %s.\n", class_filename);
              process_class (jcf);
              process_class (jcf);
            }
            }
          JCF_FINISH(jcf);
          JCF_FINISH(jcf);
        }
        }
    }
    }
 
 
  return SUCCESS_EXIT_CODE;
  return SUCCESS_EXIT_CODE;
}
}
 
 


 
 
static void
static void
disassemble_method (JCF* jcf, const unsigned char *byte_ops, int len)
disassemble_method (JCF* jcf, const unsigned char *byte_ops, int len)
{
{
#undef PTR
#undef PTR
  int PC;
  int PC;
  int i;
  int i;
  int saw_wide = 0;
  int saw_wide = 0;
  if (flag_disassemble_methods == 0)
  if (flag_disassemble_methods == 0)
    return;
    return;
#define BCODE byte_ops
#define BCODE byte_ops
  for (PC = 0; PC < len;)
  for (PC = 0; PC < len;)
    {
    {
      int oldpc = PC;
      int oldpc = PC;
      int saw_index;
      int saw_index;
      jint INT_temp;
      jint INT_temp;
      switch (byte_ops[PC++])
      switch (byte_ops[PC++])
        {
        {
 
 
/* This is the actual code emitted for each of opcodes in javaops.def.
/* This is the actual code emitted for each of opcodes in javaops.def.
   The actual opcode-specific stuff is handled by the OPKIND macro.
   The actual opcode-specific stuff is handled by the OPKIND macro.
   I.e. for an opcode whose OPKIND is BINOP, the BINOP will be called.
   I.e. for an opcode whose OPKIND is BINOP, the BINOP will be called.
   Those macros are defined below.  The OPKINDs that do not have any
   Those macros are defined below.  The OPKINDs that do not have any
   inline parameters (such as BINOP) and therefore do mot need anything
   inline parameters (such as BINOP) and therefore do mot need anything
   else to me printed out just use an empty body. */
   else to me printed out just use an empty body. */
 
 
#define JAVAOP(OPNAME, OPCODE, OPKIND, OPERAND_TYPE, OPERAND_VALUE) \
#define JAVAOP(OPNAME, OPCODE, OPKIND, OPERAND_TYPE, OPERAND_VALUE) \
        case OPCODE: \
        case OPCODE: \
          fprintf (out, "%3d: %s", oldpc, #OPNAME); \
          fprintf (out, "%3d: %s", oldpc, #OPNAME); \
          OPKIND(OPERAND_TYPE, OPERAND_VALUE); \
          OPKIND(OPERAND_TYPE, OPERAND_VALUE); \
          fputc ('\n', out); \
          fputc ('\n', out); \
          break;
          break;
 
 
#define CONST_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
#define CONST_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
#define CONST_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
#define CONST_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
#define VAR_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
#define VAR_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
#define VAR_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
#define VAR_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
 
 
#define CHECK_PC_IN_RANGE(PC) (PC < 0 || PC > len ? \
#define CHECK_PC_IN_RANGE(PC) (PC < 0 || PC > len ? \
  (fprintf(stderr, _("Bad byte codes.\n")), exit(-1), 0) : 1)
  (fprintf(stderr, _("Bad byte codes.\n")), exit(-1), 0) : 1)
 
 
/* Print out operand (if not implied by the opcode) for PUSCH opcodes.
/* Print out operand (if not implied by the opcode) for PUSCH opcodes.
   These all push a constant onto the opcode stack. */
   These all push a constant onto the opcode stack. */
#define PUSHC(OPERAND_TYPE, OPERAND_VALUE) \
#define PUSHC(OPERAND_TYPE, OPERAND_VALUE) \
  saw_index = 0, i = (OPERAND_VALUE); \
  saw_index = 0, i = (OPERAND_VALUE); \
  if (oldpc+1 == PC) /* nothing */; \
  if (oldpc+1 == PC) /* nothing */; \
  else if (saw_index) fprintf (out, " "), print_constant_ref (out, jcf, i); \
  else if (saw_index) fprintf (out, " "), print_constant_ref (out, jcf, i); \
  else fprintf (out, " %d", i);
  else fprintf (out, " %d", i);
 
 
/* Print out operand (a local variable index) for LOAD opcodes.
/* Print out operand (a local variable index) for LOAD opcodes.
   These all push local variable onto the opcode stack. */
   These all push local variable onto the opcode stack. */
#define LOAD(OPERAND_TYPE, OPERAND_VALUE) \
#define LOAD(OPERAND_TYPE, OPERAND_VALUE) \
  INT_temp = saw_wide ? IMMEDIATE_u2 : (OPERAND_VALUE); goto load_store;
  INT_temp = saw_wide ? IMMEDIATE_u2 : (OPERAND_VALUE); goto load_store;
 
 
/* Handle STORE opcodes same as LOAD opcodes.
/* Handle STORE opcodes same as LOAD opcodes.
   These all store a value from the opcode stack in a local variable. */
   These all store a value from the opcode stack in a local variable. */
#define STORE LOAD
#define STORE LOAD
 
 
/* Handle more kind of opcodes. */
/* Handle more kind of opcodes. */
#define STACK(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define STACK(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define UNOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define UNOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define BINOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define BINOP(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define CONVERT(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define CONVERT(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define CONVERT2(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define CONVERT2(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define RETURN(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define RETURN(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define UNKNOWN(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#define UNKNOWN(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
 
 
/* Handle putfield and getfield opcodes, with static versions. */
/* Handle putfield and getfield opcodes, with static versions. */
#define FIELD(MAYBE_STATIC, PUT_OR_GET) \
#define FIELD(MAYBE_STATIC, PUT_OR_GET) \
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2)
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2)
 
 
/* Print operand for invoke opcodes. */
/* Print operand for invoke opcodes. */
#define INVOKE(OPERAND_TYPE, OPERAND_VALUE) \
#define INVOKE(OPERAND_TYPE, OPERAND_VALUE) \
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);\
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);\
  if (OPERAND_VALUE) /* for invokeinterface */ \
  if (OPERAND_VALUE) /* for invokeinterface */ \
  { int nargs = IMMEDIATE_u1;  PC++; \
  { int nargs = IMMEDIATE_u1;  PC++; \
    fprintf (out, " nargs:%d", nargs); }
    fprintf (out, " nargs:%d", nargs); }
 
 
#define OBJECT(OPERAND_TYPE, OPERAND_VALUE) \
#define OBJECT(OPERAND_TYPE, OPERAND_VALUE) \
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);
 
 
#define ARRAY(OPERAND_TYPE, SUBOP) \
#define ARRAY(OPERAND_TYPE, SUBOP) \
  ARRAY_##SUBOP(OPERAND_TYPE)
  ARRAY_##SUBOP(OPERAND_TYPE)
/* Handle sub-categories of ARRAY opcodes. */
/* Handle sub-categories of ARRAY opcodes. */
#define ARRAY_LOAD(TYPE) /* nothing */
#define ARRAY_LOAD(TYPE) /* nothing */
#define ARRAY_STORE(TYPE) /* nothing */
#define ARRAY_STORE(TYPE) /* nothing */
#define ARRAY_LENGTH(TYPE) /* nothing */
#define ARRAY_LENGTH(TYPE) /* nothing */
#define ARRAY_NEW(TYPE) ARRAY_NEW_##TYPE
#define ARRAY_NEW(TYPE) ARRAY_NEW_##TYPE
#define ARRAY_NEW_NUM \
#define ARRAY_NEW_NUM \
 INT_temp = IMMEDIATE_u1; \
 INT_temp = IMMEDIATE_u1; \
 { switch ((int) INT_temp) {  \
 { switch ((int) INT_temp) {  \
    case  4: fputs (" boolean", out); break; \
    case  4: fputs (" boolean", out); break; \
    case  5: fputs (" char", out); break; \
    case  5: fputs (" char", out); break; \
    case  6: fputs (" float", out); break; \
    case  6: fputs (" float", out); break; \
    case  7: fputs (" double", out); break; \
    case  7: fputs (" double", out); break; \
    case  8: fputs (" byte", out); break; \
    case  8: fputs (" byte", out); break; \
    case  9: fputs (" short", out); break; \
    case  9: fputs (" short", out); break; \
    case 10: fputs (" int", out); break; \
    case 10: fputs (" int", out); break; \
    case 11: fputs (" long", out); break; \
    case 11: fputs (" long", out); break; \
    default: fprintf (out, " <unknown type code %ld>", (long)INT_temp); break;\
    default: fprintf (out, " <unknown type code %ld>", (long)INT_temp); break;\
  } }
  } }
 
 
#define ARRAY_NEW_PTR  \
#define ARRAY_NEW_PTR  \
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2);
 
 
#define ARRAY_NEW_MULTI \
#define ARRAY_NEW_MULTI \
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2); \
  fputc (' ', out); print_constant_ref (out, jcf, IMMEDIATE_u2); \
  fprintf (out, " %d", IMMEDIATE_u1); /* number of dimensions */
  fprintf (out, " %d", IMMEDIATE_u1); /* number of dimensions */
 
 
#define TEST(OPERAND_TYPE, OPERAND_VALUE) \
#define TEST(OPERAND_TYPE, OPERAND_VALUE) \
  fprintf (out, " %d", oldpc + IMMEDIATE_s2)
  fprintf (out, " %d", oldpc + IMMEDIATE_s2)
 
 
#define BRANCH(OPERAND_TYPE, OPERAND_VALUE) \
#define BRANCH(OPERAND_TYPE, OPERAND_VALUE) \
  saw_index = 0, INT_temp = (OPERAND_VALUE); \
  saw_index = 0, INT_temp = (OPERAND_VALUE); \
  fprintf (out, " %ld", (long) (saw_index ? INT_temp : oldpc + INT_temp))
  fprintf (out, " %ld", (long) (saw_index ? INT_temp : oldpc + INT_temp))
 
 
#define JSR(OPERAND_TYPE, OPERAND_VALUE) \
#define JSR(OPERAND_TYPE, OPERAND_VALUE) \
  saw_index = 0, INT_temp = (OPERAND_VALUE); \
  saw_index = 0, INT_temp = (OPERAND_VALUE); \
  fprintf (out, " %ld", (long) (saw_index ? INT_temp : oldpc + INT_temp))
  fprintf (out, " %ld", (long) (saw_index ? INT_temp : oldpc + INT_temp))
 
 
#undef RET /* Defined by config/i386/i386.h */
#undef RET /* Defined by config/i386/i386.h */
#define RET(OPERAND_TYPE, OPERAND_VALUE) \
#define RET(OPERAND_TYPE, OPERAND_VALUE) \
  INT_temp = saw_wide ? IMMEDIATE_u2 : (OPERAND_VALUE); \
  INT_temp = saw_wide ? IMMEDIATE_u2 : (OPERAND_VALUE); \
  saw_wide = 0; \
  saw_wide = 0; \
  fprintf (out, " %ld", (long) INT_temp);
  fprintf (out, " %ld", (long) INT_temp);
 
 
#define SWITCH(OPERAND_TYPE, TABLE_OR_LOOKUP) \
#define SWITCH(OPERAND_TYPE, TABLE_OR_LOOKUP) \
  PC = (PC + 3) / 4 * 4; TABLE_OR_LOOKUP##_SWITCH
  PC = (PC + 3) / 4 * 4; TABLE_OR_LOOKUP##_SWITCH
 
 
#define LOOKUP_SWITCH \
#define LOOKUP_SWITCH \
  { jint default_offset = IMMEDIATE_s4;  jint npairs = IMMEDIATE_s4; \
  { jint default_offset = IMMEDIATE_s4;  jint npairs = IMMEDIATE_s4; \
    fprintf (out, " npairs=%ld, default=%ld", (long) npairs, (long) default_offset+oldpc); \
    fprintf (out, " npairs=%ld, default=%ld", (long) npairs, (long) default_offset+oldpc); \
    while (--npairs >= 0) { \
    while (--npairs >= 0) { \
     jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \
     jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \
     fprintf (out, "\n%10ld: %ld", (long)match, (long)(offset+oldpc)); } \
     fprintf (out, "\n%10ld: %ld", (long)match, (long)(offset+oldpc)); } \
  }
  }
 
 
#define TABLE_SWITCH \
#define TABLE_SWITCH \
  { jint default_offset = IMMEDIATE_s4; \
  { jint default_offset = IMMEDIATE_s4; \
    jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \
    jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \
    fprintf (out, " low=%ld, high=%ld, default=%ld", \
    fprintf (out, " low=%ld, high=%ld, default=%ld", \
      (long) low, (long) high, (long) default_offset+oldpc); \
      (long) low, (long) high, (long) default_offset+oldpc); \
    for (; low <= high; low++) { \
    for (; low <= high; low++) { \
     jint offset = IMMEDIATE_s4; \
     jint offset = IMMEDIATE_s4; \
     fprintf (out, "\n%10ld: %ld", (long)low, (long)(offset+oldpc)); } \
     fprintf (out, "\n%10ld: %ld", (long)low, (long)(offset+oldpc)); } \
  }
  }
 
 
#define SPECIAL(OPERAND_TYPE, OPERAND_VALUE) \
#define SPECIAL(OPERAND_TYPE, OPERAND_VALUE) \
  SPECIAL_##OPERAND_VALUE(OPERAND_TYPE)
  SPECIAL_##OPERAND_VALUE(OPERAND_TYPE)
 
 
#define SPECIAL_IINC(OPERAND_TYPE) \
#define SPECIAL_IINC(OPERAND_TYPE) \
  i = saw_wide ? IMMEDIATE_u2 : IMMEDIATE_u1; \
  i = saw_wide ? IMMEDIATE_u2 : IMMEDIATE_u1; \
  fprintf (out, " %d", i); \
  fprintf (out, " %d", i); \
  i = saw_wide ? IMMEDIATE_s2 : IMMEDIATE_s1; \
  i = saw_wide ? IMMEDIATE_s2 : IMMEDIATE_s1; \
  saw_wide = 0; \
  saw_wide = 0; \
  fprintf (out, " %d", i)
  fprintf (out, " %d", i)
 
 
#define SPECIAL_WIDE(OPERAND_TYPE) \
#define SPECIAL_WIDE(OPERAND_TYPE) \
  saw_wide = 1;
  saw_wide = 1;
 
 
#define SPECIAL_EXIT(OPERAND_TYPE) /* nothing */
#define SPECIAL_EXIT(OPERAND_TYPE) /* nothing */
#define SPECIAL_ENTER(OPERAND_TYPE) /* nothing */
#define SPECIAL_ENTER(OPERAND_TYPE) /* nothing */
#define SPECIAL_BREAK(OPERAND_TYPE) /* nothing */
#define SPECIAL_BREAK(OPERAND_TYPE) /* nothing */
#define SPECIAL_THROW(OPERAND_TYPE) /* nothing */
#define SPECIAL_THROW(OPERAND_TYPE) /* nothing */
 
 
#define IMPL(OPERAND_TYPE, OPERAND_VALUE) \
#define IMPL(OPERAND_TYPE, OPERAND_VALUE) \
  fprintf (out, " %d", IMMEDIATE_u##OPERAND_VALUE)
  fprintf (out, " %d", IMMEDIATE_u##OPERAND_VALUE)
 
 
#define COND(OPERAND_TYPE, OPERAND_VALUE) \
#define COND(OPERAND_TYPE, OPERAND_VALUE) \
   TEST(OPERAND_TYPE, OPERAND_VALUE)
   TEST(OPERAND_TYPE, OPERAND_VALUE)
 
 
#include "javaop.def"
#include "javaop.def"
 
 
        load_store:
        load_store:
          if (oldpc+1 == PC) /* nothing - local index implied by opcode */;
          if (oldpc+1 == PC) /* nothing - local index implied by opcode */;
          else
          else
            {
            {
              saw_wide = 0;
              saw_wide = 0;
              fprintf (out, " %ld", (long) INT_temp);
              fprintf (out, " %ld", (long) INT_temp);
            }
            }
          fputc ('\n', out);
          fputc ('\n', out);
          break;
          break;
 
 
        default:
        default:
          fprintf (out, "%3d: unknown(%3d)\n", oldpc, byte_ops[PC]);
          fprintf (out, "%3d: unknown(%3d)\n", oldpc, byte_ops[PC]);
        }
        }
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.