langtools/src/share/classes/sun/tools/javap/Tables.java
author jjg
Thu, 22 May 2008 16:06:00 -0700
changeset 656 4718b910737c
parent 10 06bc494ca11e
child 735 372aa565a221
permissions -rw-r--r--
6657909: javap has unchecked compilation warnings Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
package sun.tools.javap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Hashtable;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.Vector;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
public class Tables implements Constants {
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
     * Define mnemocodes table.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
     */
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    37
  static  Hashtable<String,Integer> mnemocodes = new Hashtable<String,Integer>(301, 0.5f);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
  static  String opcExtNamesTab[]=new String[128];
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
  static  String opcPrivExtNamesTab[]=new String[128];
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
  static  void defineNonPriv(int opc, String mnem) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    41
        mnemocodes.put(opcExtNamesTab[opc]=mnem, opc_nonpriv*256+opc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
  static  void definePriv(int opc, String mnem) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    44
        mnemocodes.put(opcPrivExtNamesTab[opc]="priv_"+mnem, opc_priv*256+opc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
  static  void defineExt(int opc, String mnem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        defineNonPriv(opc, mnem);
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
        definePriv(opc, mnem);
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
  static { int k;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
        for (k=0; k<opc_wide; k++) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    52
                mnemocodes.put(opcNamesTab[k], k);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        for (k=opc_wide+1; k<opcNamesTab.length; k++) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    55
                mnemocodes.put(opcNamesTab[k], k);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        }
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    57
        mnemocodes.put("invokenonvirtual", opc_invokespecial);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    59
        mnemocodes.put("iload_w", opc_iload_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    60
        mnemocodes.put("lload_w", opc_lload_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    61
        mnemocodes.put("fload_w", opc_fload_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    62
        mnemocodes.put("dload_w", opc_dload_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    63
        mnemocodes.put("aload_w", opc_aload_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    64
        mnemocodes.put("istore_w", opc_istore_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    65
        mnemocodes.put("lstore_w", opc_lstore_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    66
        mnemocodes.put("fstore_w", opc_fstore_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    67
        mnemocodes.put("dstore_w", opc_dstore_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    68
        mnemocodes.put("astore_w", opc_astore_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    69
        mnemocodes.put("ret_w", opc_ret_w);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    70
        mnemocodes.put("iinc_w", opc_iinc_w);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    72
        mnemocodes.put("nonpriv", opc_nonpriv);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
    73
        mnemocodes.put("priv", opc_priv);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        defineExt(0, "load_ubyte");
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        defineExt(1, "load_byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        defineExt(2, "load_char");
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        defineExt(3, "load_short");
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        defineExt(4, "load_word");
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        defineExt(10, "load_char_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        defineExt(11, "load_short_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        defineExt(12, "load_word_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        defineExt(16, "ncload_ubyte");
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        defineExt(17, "ncload_byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        defineExt(18, "ncload_char");
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        defineExt(19, "ncload_short");
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        defineExt(20, "ncload_word");
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        defineExt(26, "ncload_char_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        defineExt(27, "ncload_short_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        defineExt(28, "ncload_word_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        defineExt(30, "cache_flush");
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        defineExt(32, "store_byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        defineExt(34, "store_short");
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        defineExt(36, "store_word");
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        defineExt(42, "store_short_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        defineExt(44, "store_word_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        defineExt(48, "ncstore_byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        defineExt(50, "ncstore_short");
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        defineExt(52, "ncstore_word");
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        defineExt(58, "ncstore_short_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        defineExt(60, "ncstore_word_oe");
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        defineExt(62, "zero_line");
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        defineNonPriv(5, "ret_from_sub");
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        defineNonPriv(63, "enter_sync_method");
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        definePriv(5, "ret_from_trap");
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        definePriv(6, "read_dcache_tag");
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        definePriv(7, "read_dcache_data");
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        definePriv(14, "read_icache_tag");
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        definePriv(15, "read_icache_data");
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        definePriv(22, "powerdown");
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        definePriv(23, "read_scache_data");
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        definePriv(31, "cache_index_flush");
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        definePriv(38, "write_dcache_tag");
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        definePriv(39, "write_dcache_data");
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        definePriv(46, "write_icache_tag");
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        definePriv(47, "write_icache_data");
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        definePriv(54, "reset");
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        definePriv(55, "write_scache_data");
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        for (k=0; k<32; k++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
                definePriv(k+64, "read_reg_"+k);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        for (k=0; k<32; k++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                definePriv(k+96, "write_reg_"+k);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
 }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
  public static int opcLength(int opc) throws ArrayIndexOutOfBoundsException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        switch (opc>>8) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
          case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                return opcLengthsTab[opc];
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
          case opc_wide:
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                switch (opc&0xFF) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                  case opc_aload: case opc_astore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                  case opc_fload: case opc_fstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                  case opc_iload: case opc_istore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                  case opc_lload: case opc_lstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                  case opc_dload: case opc_dstore:
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                  case opc_ret:
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                        return  4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                  case opc_iinc:
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                        return  6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                  default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                        throw new ArrayIndexOutOfBoundsException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
          case opc_nonpriv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
          case opc_priv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
          default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                throw new ArrayIndexOutOfBoundsException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
  public static String opcName(int opc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                switch (opc>>8) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                  case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                        return opcNamesTab[opc];
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                  case opc_wide: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                        String mnem=opcNamesTab[opc&0xFF]+"_w";
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                        if (mnemocodes.get(mnem) == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                                return null; // non-existent opcode
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                        return mnem;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                  case opc_nonpriv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                        return opcExtNamesTab[opc&0xFF];
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
                  case opc_priv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                        return opcPrivExtNamesTab[opc&0xFF];
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                  default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        } catch (ArrayIndexOutOfBoundsException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                switch (opc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                  case opc_nonpriv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                        return "nonpriv";
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                  case opc_priv:
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                        return "priv";
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                  default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
  public static int opcode(String mnem) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   184
        Integer Val=mnemocodes.get(mnem);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        if (Val == null) return -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        return Val.intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * Initialized keyword and token Hashtables
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     */
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   192
  static Vector<String> keywordNames = new Vector<String>(40);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
  private static void defineKeywordName(String id, int token) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        if (token>=keywordNames.size()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
                keywordNames.setSize(token+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        keywordNames.setElementAt(id, token);
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
  public static String keywordName(int token) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        if (token==-1) return "EOF";
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        if (token>=keywordNames.size()) return null;
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   203
        return keywordNames.elementAt(token);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
  static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        defineKeywordName("ident", IDENT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        defineKeywordName("STRINGVAL", STRINGVAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        defineKeywordName("intVal", INTVAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        defineKeywordName("longVal", LONGVAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        defineKeywordName("floatVal", FLOATVAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        defineKeywordName("doubleVal", DOUBLEVAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        defineKeywordName("SEMICOLON", SEMICOLON);
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        defineKeywordName("COLON", COLON);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        defineKeywordName("LBRACE", LBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        defineKeywordName("RBRACE", RBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   218
  static Hashtable<String,Integer> keywords = new Hashtable<String,Integer>(40);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
  public static int keyword(String idValue) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   220
        Integer val=keywords.get(idValue);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   221
        if (val == null) return IDENT;
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   222
        return val.intValue();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
  private static void defineKeyword(String id, int token) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   226
        keywords.put(id, token);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        defineKeywordName(id, token);
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
  static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        // Modifier keywords
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        defineKeyword("private", PRIVATE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        defineKeyword("public", PUBLIC);
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        defineKeyword("protected",      PROTECTED);
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        defineKeyword("static", STATIC);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        defineKeyword("transient",      TRANSIENT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        defineKeyword("synchronized",   SYNCHRONIZED);
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        defineKeyword("super",  SUPER);
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        defineKeyword("native", NATIVE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        defineKeyword("abstract",       ABSTRACT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        defineKeyword("volatile", VOLATILE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        defineKeyword("final",  FINAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        defineKeyword("interface",INTERFACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        defineKeyword("synthetic",SYNTHETIC);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        defineKeyword("strict",STRICT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        // Declaration keywords
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        defineKeyword("package",PACKAGE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        defineKeyword("class",CLASS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        defineKeyword("extends",EXTENDS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        defineKeyword("implements",IMPLEMENTS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        defineKeyword("const",  CONST);
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        defineKeyword("throws",THROWS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        defineKeyword("interface",INTERFACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        defineKeyword("Method",METHODREF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        defineKeyword("Field",FIELDREF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        defineKeyword("stack",STACK);
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        defineKeyword("locals",LOCAL);
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        // used in switchtables
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        defineKeyword("default",        DEFAULT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        // used in inner class declarations
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        defineKeyword("InnerClass",     INNERCLASS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        defineKeyword("of",     OF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        // misc
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        defineKeyword("bits",BITS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        defineKeyword("Infinity",INF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        defineKeyword("Inf",INF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        defineKeyword("NaN",NAN);
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
   /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     * Define tag table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   276
  private static Vector<String> tagNames = new Vector<String>(10);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   277
  private static Hashtable<String,Integer> Tags = new Hashtable<String,Integer>(10);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
  static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        defineTag("Asciz",CONSTANT_UTF8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        defineTag("int",CONSTANT_INTEGER);
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        defineTag("float",CONSTANT_FLOAT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        defineTag("long",CONSTANT_LONG);
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        defineTag("double",CONSTANT_DOUBLE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        defineTag("class",CONSTANT_CLASS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        defineTag("String",CONSTANT_STRING);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        defineTag("Field",CONSTANT_FIELD);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        defineTag("Method",CONSTANT_METHOD);
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        defineTag("InterfaceMethod",CONSTANT_INTERFACEMETHOD);
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        defineTag("NameAndType",CONSTANT_NAMEANDTYPE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
  private static void defineTag(String id, int val) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   292
        Tags.put(id, val);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        if (val>=tagNames.size()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                tagNames.setSize(val+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        tagNames.setElementAt(id, val);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
  public static String tagName(int tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        if (tag>=tagNames.size()) return null;
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   300
        return tagNames.elementAt(tag);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
  public static int tagValue(String idValue) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   303
        Integer Val=Tags.get(idValue);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        if (Val == null) return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        return Val.intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
   /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     * Define type table. These types used in "newarray" instruction only.
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
     */
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   311
  private static Vector<String> typeNames = new Vector<String>(10);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   312
  private static Hashtable<String,Integer> Types = new Hashtable<String,Integer>(10);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
  static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        defineType("int",T_INT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        defineType("long",T_LONG);
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        defineType("float",T_FLOAT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        defineType("double",T_DOUBLE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        defineType("class",T_CLASS);
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        defineType("boolean",T_BOOLEAN);
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
        defineType("char",T_CHAR);
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        defineType("byte",T_BYTE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        defineType("short",T_SHORT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
  private static void defineType(String id, int val) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   325
        Types.put(id, val);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        if (val>=typeNames.size()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                typeNames.setSize(val+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        typeNames.setElementAt(id, val);
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
  public static int typeValue(String idValue) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   332
        Integer Val=Types.get(idValue);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        if (Val == null) return -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        return Val.intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
  public static String typeName(int type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        if (type>=typeNames.size()) return null;
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   338
        return typeNames.elementAt(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
   /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     * Define MapTypes table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
     * These constants used in stackmap tables only.
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     */
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   345
  private static Vector<String> mapTypeNames = new Vector<String>(10);
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   346
  private static Hashtable<String,Integer> MapTypes = new Hashtable<String,Integer>(10);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
  static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        defineMapType("bogus",             ITEM_Bogus);
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        defineMapType("int",               ITEM_Integer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        defineMapType("float",             ITEM_Float);
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        defineMapType("double",            ITEM_Double);
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        defineMapType("long",              ITEM_Long);
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        defineMapType("null",              ITEM_Null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        defineMapType("this",              ITEM_InitObject);
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        defineMapType("CP",                ITEM_Object);
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        defineMapType("uninitialized",     ITEM_NewObject);
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
  private static void defineMapType(String id, int val) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   359
        MapTypes.put(id, val);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        if (val>=mapTypeNames.size()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                mapTypeNames.setSize(val+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        mapTypeNames.setElementAt(id, val);
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
  public static int mapTypeValue(String idValue) {
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   366
        Integer Val=MapTypes.get(idValue);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        if (Val == null) return -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        return Val.intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
  public static String mapTypeName(int type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        if (type>=mapTypeNames.size()) return null;
656
4718b910737c 6657909: javap has unchecked compilation warnings
jjg
parents: 10
diff changeset
   372
        return mapTypeNames.elementAt(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
  }
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
}