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