jdk/src/share/classes/sun/reflect/ClassFileAssembler.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
class ClassFileAssembler implements ClassFileConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
    private ByteVector vec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
    private short cpIdx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    public ClassFileAssembler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        this(ByteVectorFactory.create());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public ClassFileAssembler(ByteVector vec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        this.vec = vec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public ByteVector getData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        return vec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /** Length in bytes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public short getLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        return (short) vec.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public void emitMagicAndVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        emitInt(0xCAFEBABE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        emitShort((short) 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        emitShort((short) 49);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public void emitInt(int val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        emitByte((byte) (val >> 24));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        emitByte((byte) ((val >> 16) & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        emitByte((byte) ((val >> 8) & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        emitByte((byte) (val & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public void emitShort(short val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        emitByte((byte) ((val >> 8) & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        emitByte((byte) (val & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // Support for labels; package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    void emitShort(short bci, short val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        vec.put(bci,     (byte) ((val >> 8) & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        vec.put(bci + 1, (byte) (val & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public void emitByte(byte val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        vec.add(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public void append(ClassFileAssembler asm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        append(asm.vec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void append(ByteVector vec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        for (int i = 0; i < vec.getLength(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            emitByte(vec.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** Keeps track of the current (one-based) constant pool index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        incremented after emitting one of the following constant pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        entries. Can fetch the current constant pool index for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        later entries.  Index points at the last valid constant pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        entry; initially invalid. It is illegal to fetch the constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        pool index before emitting at least one constant pool entry. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public short cpi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (cpIdx == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new RuntimeException("Illegal use of ClassFileAssembler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return cpIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void emitConstantPoolUTF8(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // NOTE: can not use str.getBytes("UTF-8") here because of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // bootstrapping issues with the character set converters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        byte[] bytes = UTF8.encode(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        emitByte(CONSTANT_Utf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        emitShort((short) bytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        for (int i = 0; i < bytes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            emitByte(bytes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        cpIdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public void emitConstantPoolClass(short index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        emitByte(CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        emitShort(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        cpIdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void emitConstantPoolNameAndType(short nameIndex, short typeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        emitByte(CONSTANT_NameAndType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        emitShort(nameIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        emitShort(typeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        cpIdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public void emitConstantPoolFieldref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        (short classIndex, short nameAndTypeIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        emitByte(CONSTANT_Fieldref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        emitShort(classIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        emitShort(nameAndTypeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        cpIdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void emitConstantPoolMethodref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        (short classIndex, short nameAndTypeIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        emitByte(CONSTANT_Methodref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        emitShort(classIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        emitShort(nameAndTypeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        cpIdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void emitConstantPoolInterfaceMethodref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        (short classIndex, short nameAndTypeIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        emitByte(CONSTANT_InterfaceMethodref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        emitShort(classIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        emitShort(nameAndTypeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        cpIdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void emitConstantPoolString(short utf8Index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        emitByte(CONSTANT_String);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        emitShort(utf8Index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        cpIdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // Opcodes. Keeps track of maximum stack and locals. Make a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    // assembler for each piece of assembled code, then append the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // result to the previous assembler's class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private int stack     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private int maxStack  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private int maxLocals = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private void incStack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        setStack(stack + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private void decStack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        --stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public short getMaxStack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return (short) maxStack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public short getMaxLocals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return (short) maxLocals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /** It's necessary to be able to specify the number of arguments at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        the beginning of the method (which translates to the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        value of max locals) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public void setMaxLocals(int maxLocals) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        this.maxLocals = maxLocals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /** Needed to do flow control. Returns current stack depth. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public int getStack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /** Needed to do flow control. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void setStack(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        stack = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (stack > maxStack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            maxStack = stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    ///////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    // Constants //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    ///////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public void opc_aconst_null() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        emitByte(opc_aconst_null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void opc_sipush(short constant) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        emitByte(opc_sipush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        emitShort(constant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void opc_ldc(byte cpIdx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        emitByte(opc_ldc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        emitByte(cpIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    // Local variable loads and stores //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public void opc_iload_0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        emitByte(opc_iload_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (maxLocals < 1) maxLocals = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void opc_iload_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        emitByte(opc_iload_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (maxLocals < 2) maxLocals = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public void opc_iload_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        emitByte(opc_iload_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (maxLocals < 3) maxLocals = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public void opc_iload_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        emitByte(opc_iload_3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (maxLocals < 4) maxLocals = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void opc_lload_0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        emitByte(opc_lload_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (maxLocals < 2) maxLocals = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void opc_lload_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        emitByte(opc_lload_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (maxLocals < 3) maxLocals = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void opc_lload_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        emitByte(opc_lload_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (maxLocals < 4) maxLocals = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public void opc_lload_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        emitByte(opc_lload_3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (maxLocals < 5) maxLocals = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void opc_fload_0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        emitByte(opc_fload_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (maxLocals < 1) maxLocals = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public void opc_fload_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        emitByte(opc_fload_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (maxLocals < 2) maxLocals = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public void opc_fload_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        emitByte(opc_fload_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (maxLocals < 3) maxLocals = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public void opc_fload_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        emitByte(opc_fload_3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (maxLocals < 4) maxLocals = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public void opc_dload_0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        emitByte(opc_dload_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (maxLocals < 2) maxLocals = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public void opc_dload_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        emitByte(opc_dload_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (maxLocals < 3) maxLocals = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void opc_dload_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        emitByte(opc_dload_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (maxLocals < 4) maxLocals = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public void opc_dload_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        emitByte(opc_dload_3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (maxLocals < 5) maxLocals = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public void opc_aload_0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        emitByte(opc_aload_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (maxLocals < 1) maxLocals = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public void opc_aload_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        emitByte(opc_aload_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (maxLocals < 2) maxLocals = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public void opc_aload_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        emitByte(opc_aload_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (maxLocals < 3) maxLocals = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public void opc_aload_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        emitByte(opc_aload_3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (maxLocals < 4) maxLocals = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public void opc_aaload() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        emitByte(opc_aaload);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public void opc_astore_0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        emitByte(opc_astore_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (maxLocals < 1) maxLocals = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public void opc_astore_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        emitByte(opc_astore_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (maxLocals < 2) maxLocals = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public void opc_astore_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        emitByte(opc_astore_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (maxLocals < 3) maxLocals = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public void opc_astore_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        emitByte(opc_astore_3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (maxLocals < 4) maxLocals = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    ////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    // Stack manipulation //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    ////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public void opc_pop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        emitByte(opc_pop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public void opc_dup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        emitByte(opc_dup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public void opc_dup_x1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        emitByte(opc_dup_x1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public void opc_swap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        emitByte(opc_swap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    ///////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    // Widening conversions only //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    ///////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void opc_i2l() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        emitByte(opc_i2l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public void opc_i2f() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        emitByte(opc_i2f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public void opc_i2d() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        emitByte(opc_i2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public void opc_l2f() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        emitByte(opc_l2f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public void opc_l2d() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        emitByte(opc_l2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public void opc_f2d() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        emitByte(opc_f2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    //////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    // Control flow //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    //////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public void opc_ifeq(short bciOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        emitByte(opc_ifeq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        emitShort(bciOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /** Control flow with forward-reference BCI. Stack assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        straight-through control flow. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public void opc_ifeq(Label l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        short instrBCI = getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        emitByte(opc_ifeq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        l.add(this, instrBCI, getLength(), getStack() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        emitShort((short) -1); // Must be patched later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public void opc_if_icmpeq(short bciOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        emitByte(opc_if_icmpeq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        emitShort(bciOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        setStack(getStack() - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /** Control flow with forward-reference BCI. Stack assumes straight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        control flow. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public void opc_if_icmpeq(Label l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        short instrBCI = getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        emitByte(opc_if_icmpeq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        l.add(this, instrBCI, getLength(), getStack() - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        emitShort((short) -1); // Must be patched later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public void opc_goto(short bciOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        emitByte(opc_goto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        emitShort(bciOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /** Control flow with forward-reference BCI. Stack assumes straight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        control flow. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public void opc_goto(Label l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        short instrBCI = getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        emitByte(opc_goto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        l.add(this, instrBCI, getLength(), getStack());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        emitShort((short) -1); // Must be patched later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public void opc_ifnull(short bciOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        emitByte(opc_ifnull);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        emitShort(bciOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /** Control flow with forward-reference BCI. Stack assumes straight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        control flow. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public void opc_ifnull(Label l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        short instrBCI = getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        emitByte(opc_ifnull);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        l.add(this, instrBCI, getLength(), getStack() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        emitShort((short) -1); // Must be patched later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public void opc_ifnonnull(short bciOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        emitByte(opc_ifnonnull);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        emitShort(bciOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /** Control flow with forward-reference BCI. Stack assumes straight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        control flow. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public void opc_ifnonnull(Label l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        short instrBCI = getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        emitByte(opc_ifnonnull);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        l.add(this, instrBCI, getLength(), getStack() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        emitShort((short) -1); // Must be patched later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        decStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    // Return instructions //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    /////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public void opc_ireturn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        emitByte(opc_ireturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        setStack(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    public void opc_lreturn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        emitByte(opc_lreturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        setStack(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public void opc_freturn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        emitByte(opc_freturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        setStack(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public void opc_dreturn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        emitByte(opc_dreturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        setStack(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public void opc_areturn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        emitByte(opc_areturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        setStack(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public void opc_return() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        emitByte(opc_return);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        setStack(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    //////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    // Field operations //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    //////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    public void opc_getstatic(short fieldIndex, int fieldSizeInStackSlots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        emitByte(opc_getstatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        emitShort(fieldIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        setStack(getStack() + fieldSizeInStackSlots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    public void opc_putstatic(short fieldIndex, int fieldSizeInStackSlots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        emitByte(opc_putstatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        emitShort(fieldIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        setStack(getStack() - fieldSizeInStackSlots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public void opc_getfield(short fieldIndex, int fieldSizeInStackSlots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        emitByte(opc_getfield);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        emitShort(fieldIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        setStack(getStack() + fieldSizeInStackSlots - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public void opc_putfield(short fieldIndex, int fieldSizeInStackSlots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        emitByte(opc_putfield);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        emitShort(fieldIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        setStack(getStack() - fieldSizeInStackSlots - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    ////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    // Method invocations //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    ////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /** Long and double arguments and return types count as 2 arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        other values count as 1. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public void opc_invokevirtual(short methodIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                  int numArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                  int numReturnValues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        emitByte(opc_invokevirtual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        emitShort(methodIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        setStack(getStack() - numArgs - 1 + numReturnValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /** Long and double arguments and return types count as 2 arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        other values count as 1. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public void opc_invokespecial(short methodIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                  int numArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                                  int numReturnValues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        emitByte(opc_invokespecial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        emitShort(methodIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        setStack(getStack() - numArgs - 1 + numReturnValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /** Long and double arguments and return types count as 2 arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        other values count as 1. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public void opc_invokestatic(short methodIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                                 int numArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                                 int numReturnValues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        emitByte(opc_invokestatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        emitShort(methodIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        setStack(getStack() - numArgs + numReturnValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /** Long and double arguments and return types count as 2 arguments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        other values count as 1. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public void opc_invokeinterface(short methodIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                    int numArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                    byte count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                                    int numReturnValues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        emitByte(opc_invokeinterface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        emitShort(methodIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        emitByte(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        emitByte((byte) 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        setStack(getStack() - numArgs - 1 + numReturnValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    //////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    // Array length //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    //////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    public void opc_arraylength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        emitByte(opc_arraylength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    /////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    // New //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public void opc_new(short classIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        emitByte(opc_new);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        emitShort(classIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        incStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    ////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    // Athrow //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    ////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    public void opc_athrow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        emitByte(opc_athrow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        setStack(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    //////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    // Checkcast and instanceof //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    //////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /** Assumes the checkcast succeeds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    public void opc_checkcast(short classIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        emitByte(opc_checkcast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        emitShort(classIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    public void opc_instanceof(short classIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        emitByte(opc_instanceof);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        emitShort(classIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
}