OSDN Git Service

* c-tree.h (define_label): Replace filename and lineno arguments
[pf3gnuchains/gcc-fork.git] / gcc / java / jcf-dump.c
index 8e327f7..a87dd40 100644 (file)
@@ -53,6 +53,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "ggc.h"
 
 #include "jcf.h"
 #include "tree.h"
@@ -61,6 +62,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 #include "version.h"
 
 #include <getopt.h>
+#include <math.h>
 
 /* Outout file. */
 FILE *out;
@@ -91,28 +93,27 @@ int class_access_flags = 0;
 /* Print in format similar to javap.  VERY IMCOMPLETE. */
 int flag_javap_compatible = 0;
 
-static void print_access_flags PARAMS ((FILE *, uint16, char));
-static void print_constant_terse PARAMS ((FILE*, JCF*, int, int));
-static void print_constant PARAMS ((FILE *, JCF *, int, int));
-static void print_constant_ref PARAMS ((FILE *, JCF *, int));
-static void disassemble_method PARAMS ((JCF*, const unsigned char *, int));
-static void print_name PARAMS ((FILE*, JCF*, int));
-static void print_signature PARAMS ((FILE*, JCF*, int, int));
-static int utf8_equal_string PARAMS ((struct JCF*, int, const char *));
-static void usage PARAMS ((void)) ATTRIBUTE_NORETURN;
-static void help PARAMS ((void)) ATTRIBUTE_NORETURN;
-static void version PARAMS ((void)) ATTRIBUTE_NORETURN;
-static void process_class PARAMS ((struct JCF *));
-static void print_constant_pool PARAMS ((struct JCF *));
-static void print_exception_table PARAMS ((struct JCF *,
-                                         const unsigned char *entries, int));
+static void print_access_flags (FILE *, uint16, char);
+static void print_constant_terse (FILE*, JCF*, int, int);
+static void print_constant (FILE *, JCF *, int, int);
+static void print_constant_ref (FILE *, JCF *, int);
+static void disassemble_method (JCF*, const unsigned char *, int);
+static void print_name (FILE*, JCF*, int);
+static void print_signature (FILE*, JCF*, int, int);
+static int utf8_equal_string (struct JCF*, int, const char *);
+static void usage (void) ATTRIBUTE_NORETURN;
+static void help (void) ATTRIBUTE_NORETURN;
+static void version (void) ATTRIBUTE_NORETURN;
+static void process_class (struct JCF *);
+static void print_constant_pool (struct JCF *);
+static void print_exception_table (struct JCF *, const unsigned char *entries,
+                                  int);
 
 #define PRINT_SIGNATURE_RESULT_ONLY 1
 #define PRINT_SIGNATURE_ARGS_ONLY 2
 
 static int
-DEFUN(utf8_equal_string, (jcf, index, value),
-      JCF *jcf AND int index AND const char * value)
+utf8_equal_string (JCF *jcf, int index, const char * value)
 {
   if (CPOOL_INDEX_IN_RANGE (&jcf->cpool, index)
       && JPOOL_TAG (jcf, index) == CONSTANT_Utf8)
@@ -346,8 +347,7 @@ DEFUN(utf8_equal_string, (jcf, index, value),
 #include "javaop.h"
 
 static void
-DEFUN(print_constant_ref, (stream, jcf, index),
-      FILE *stream AND JCF *jcf AND int index)
+print_constant_ref (FILE *stream, JCF *jcf, int index)
 {
   fprintf (stream, "#%d=<", index);
   if (index <= 0 || index >= JPOOL_SIZE(jcf))
@@ -362,8 +362,7 @@ DEFUN(print_constant_ref, (stream, jcf, index),
    or 'm' (method flags). */
 
 static void
-DEFUN (print_access_flags, (stream, flags, context),
-       FILE *stream AND uint16 flags AND char context)
+print_access_flags (FILE *stream, uint16 flags, char context)
 {
   if (flags & ACC_PUBLIC) fprintf (stream, " public");
   if (flags & ACC_PRIVATE) fprintf (stream, " private");
@@ -387,8 +386,7 @@ DEFUN (print_access_flags, (stream, flags, context),
 
 
 static void
-DEFUN(print_name, (stream, jcf, name_index),
-      FILE* stream AND JCF* jcf AND int name_index)
+print_name (FILE* stream, JCF* jcf, int name_index)
 {
   if (JPOOL_TAG (jcf, name_index) != CONSTANT_Utf8)
     fprintf (stream, "<not a UTF8 constant>");
@@ -401,8 +399,7 @@ DEFUN(print_name, (stream, jcf, name_index),
    print it tersely, otherwise more verbosely. */
 
 static void
-DEFUN(print_constant_terse, (out, jcf, index, expected),
-      FILE *out AND JCF *jcf AND int index AND int expected)
+print_constant_terse (FILE *out, JCF *jcf, int index, int expected)
 {
   if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, index))
     fprintf (out, "<constant pool index %d not in range>", index);
@@ -422,8 +419,7 @@ DEFUN(print_constant_terse, (out, jcf, index, expected),
    If verbosity==2, add more descriptive text. */
 
 static void
-DEFUN(print_constant, (out, jcf, index, verbosity),
-      FILE *out AND JCF *jcf AND int index AND int verbosity)
+print_constant (FILE *out, JCF *jcf, int index, int verbosity)
 {
   int j, n;
   jlong num;
@@ -509,24 +505,86 @@ DEFUN(print_constant, (out, jcf, index, verbosity),
       break;
     case CONSTANT_Float:
       {
-       union
-       {
-         jfloat f;
-         int32 i;
-       } pun;
-       
-       pun.f = JPOOL_FLOAT (jcf, index);
-       fprintf (out, "%s%.10g",
-                verbosity > 0 ? "Float " : "", (double) pun.f);
+       jfloat fnum = JPOOL_FLOAT (jcf, index);
+
+       if (verbosity > 0)
+         fputs ("Float ", out);
+
+       if (fnum.negative)
+         putc ('-', out);
+
+       if (JFLOAT_FINITE (fnum))
+         {
+           int dummy;
+           int exponent = fnum.exponent - JFLOAT_EXP_BIAS;
+           double f;
+           uint32 mantissa = fnum.mantissa;
+           if (fnum.exponent == 0)
+             /* Denormal.  */
+             exponent++;
+           else
+             /* Normal; add the implicit bit.  */
+             mantissa |= ((uint32)1 << 23);
+           
+           f = frexp (mantissa, &dummy);
+           f = ldexp (f, exponent + 1);
+           fprintf (out, "%.10g", f);
+         }
+       else
+         {
+           if (fnum.mantissa == 0)
+             fputs ("Inf", out);
+           else if (fnum.mantissa & JFLOAT_QNAN_MASK)
+             fprintf (out, "QNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK));
+           else
+             fprintf (out, "SNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK));
+         }
+
        if (verbosity > 1)
-         fprintf (out, ", bits = 0x%08lx", (long) pun.i);
+         fprintf (out, ", bits = 0x%08lx", JPOOL_UINT (jcf, index));
        
        break;
       }
     case CONSTANT_Double:
       {
        jdouble dnum = JPOOL_DOUBLE (jcf, index);
-       fprintf (out, "%s%.20g", verbosity > 0 ? "Double " : "", dnum);
+
+       if (verbosity > 0)
+         fputs ("Double ", out);
+
+       if (dnum.negative)
+         putc ('-', out);
+
+       if (JDOUBLE_FINITE (dnum))
+         {
+           int dummy;
+           int exponent = dnum.exponent - JDOUBLE_EXP_BIAS;
+           double d;
+           uint64 mantissa = ((((uint64) dnum.mantissa0) << 32)
+                              + dnum.mantissa1);
+           if (dnum.exponent == 0)
+             /* Denormal.  */
+             exponent++;
+           else
+             /* Normal; add the implicit bit.  */
+             mantissa |= ((uint64)1 << 52);
+
+           d = frexp (mantissa, &dummy);
+           d = ldexp (d, exponent + 1);
+           fprintf (out, "%.20g", d);
+         }
+       else
+         {
+           uint64 mantissa = dnum.mantissa0 & ~JDOUBLE_QNAN_MASK;
+           mantissa = (mantissa << 32) + dnum.mantissa1;
+
+           if (dnum.mantissa0 == 0 && dnum.mantissa1 == 0)
+             fputs ("Inf", out);
+           else if (dnum.mantissa0 & JDOUBLE_QNAN_MASK)
+             fprintf (out, "QNaN(%llu)", (unsigned long long)mantissa);
+           else
+             fprintf (out, "SNaN(%llu)", (unsigned long long)mantissa);
+         }
        if (verbosity > 1)
          {
            int32 hi, lo;
@@ -579,8 +637,7 @@ DEFUN(print_constant, (out, jcf, index, verbosity),
 }
 
 static void
-DEFUN(print_constant_pool, (jcf),
-      JCF *jcf)
+print_constant_pool (JCF *jcf)
 {
   int i;
   for (i = 1; i < JPOOL_SIZE(jcf); i++)
@@ -595,8 +652,8 @@ DEFUN(print_constant_pool, (jcf),
 }
 
 static void
-DEFUN(print_signature_type, (stream, ptr, limit),
-     FILE* stream AND const unsigned char **ptr AND const unsigned char *limit)
+print_signature_type (FILE* stream, const unsigned char **ptr,
+                     const unsigned char *limit)
 {
   int array_size;
   if ((*ptr) >= limit)
@@ -657,8 +714,7 @@ DEFUN(print_signature_type, (stream, ptr, limit),
 }
 
 static void
-DEFUN(print_signature, (stream, jcf, signature_index, int options),
-      FILE* stream AND JCF *jcf AND int signature_index AND int options)
+print_signature (FILE* stream, JCF *jcf, int signature_index, int options)
 {
   if (JPOOL_TAG (jcf, signature_index) != CONSTANT_Utf8)
     print_constant_terse (out, jcf, signature_index, CONSTANT_Utf8);
@@ -704,8 +760,7 @@ DEFUN(print_signature, (stream, jcf, signature_index, int options),
 
 
 static void
-DEFUN(print_exception_table, (jcf, entries, count),
-      JCF *jcf AND const unsigned char *entries AND int count)
+print_exception_table (JCF *jcf, const unsigned char *entries, int count)
 {
   /* Print exception table. */
   int i = count;
@@ -736,8 +791,7 @@ DEFUN(print_exception_table, (jcf, entries, count),
 #include "jcf-reader.c"
 
 static void
-DEFUN(process_class, (jcf),
-      JCF *jcf)
+process_class (JCF *jcf)
 {
   int code;
   if (jcf_parse_preamble (jcf) != 0)
@@ -809,14 +863,14 @@ static const struct option options[] =
 };
 
 static void
-usage ()
+usage (void)
 {
   fprintf (stderr, "Try `jcf-dump --help' for more information.\n");
   exit (1);
 }
 
 static void
-help ()
+help (void)
 {
   printf ("Usage: jcf-dump [OPTION]... CLASS...\n\n");
   printf ("Display contents of a class file in readable form.\n\n");
@@ -839,7 +893,7 @@ help ()
 }
 
 static void
-version ()
+version (void)
 {
   printf ("jcf-dump (GCC) %s\n\n", version_string);
   printf ("Copyright (C) 2002 Free Software Foundation, Inc.\n");
@@ -849,8 +903,7 @@ version ()
 }
 
 int
-DEFUN(main, (argc, argv),
-      int argc AND char** argv)
+main (int argc, char** argv)
 {
   JCF jcf[1];
   int argi, opt;
@@ -1069,10 +1122,8 @@ DEFUN(main, (argc, argv),
 \f
 
 static void
-DEFUN(disassemble_method, (jcf, byte_ops, len),
-      JCF* jcf AND const unsigned char *byte_ops AND int len)
+disassemble_method (JCF* jcf, const unsigned char *byte_ops, int len)
 {
-#undef AND /* Causes problems with opcodes for iand and land. */
 #undef PTR
   int PC;
   int i;
@@ -1091,7 +1142,7 @@ DEFUN(disassemble_method, (jcf, byte_ops, len),
 /* This is the actual code emitted for each of opcodes in javaops.def.
    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.
-   Those macros are defiend 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
    else to me printed out just use an empty body. */