001: /*
002: This library is free software; you can redistribute it and/or
003: modify it under the terms of the GNU General Public
004: License as published by the Free Software Foundation; either
005: version 2 of the license, or (at your option) any later version.
006: */
007:
008: package org.gjt.jclasslib.bytecode;
009:
010: import org.gjt.jclasslib.io.ByteCodeInput;
011: import org.gjt.jclasslib.io.ByteCodeOutput;
012:
013: import java.io.IOException;
014:
015: /**
016: Describes an instruction that is followed by an immediate unsigned byte.
017:
018: @author <a href="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
019: @version $Revision: 1.5 $ $Date: 2003/08/18 07:58:35 $
020: */
021: public class ImmediateByteInstruction extends AbstractInstruction {
022:
023: /** Indicates whether the instuction is subject to a wide instruction or not. */
024: protected boolean wide;
025:
026: private int immediateByte;
027:
028: /**
029: Constructor.
030: @param opcode the opcode
031: @param wide whether the instruction is a wide instruction.
032: */
033: public ImmediateByteInstruction(int opcode, boolean wide) {
034: super (opcode);
035: this .wide = wide;
036: }
037:
038: /**
039: Constructor.
040: @param opcode the opcode
041: @param wide whether the instruction is a wide instruction.
042: @param immediateByte the immediate byte value.
043: */
044: public ImmediateByteInstruction(int opcode, boolean wide,
045: int immediateByte) {
046: this (opcode, wide);
047: this .immediateByte = immediateByte;
048: }
049:
050: public int getSize() {
051: return super .getSize() + (wide ? 2 : 1);
052: }
053:
054: /**
055: Get the immediate unsigned byte of this instruction.
056: @return the byte
057: */
058: public int getImmediateByte() {
059: return immediateByte;
060: }
061:
062: /**
063: Set the immediate unsigned byte of this instruction.
064: @param immediateByte the byte
065: */
066: public void setImmediateByte(int immediateByte) {
067: this .immediateByte = immediateByte;
068: }
069:
070: /**
071: Check whether the instuction is subject to a wide instruction or not.
072: @return wide or not
073: */
074: public boolean isWide() {
075: return wide;
076: }
077:
078: /**
079: Set whether the instuction is subject to a wide instruction or not.
080: @param wide wide or not
081: */
082: public void setWide(boolean wide) {
083: this .wide = wide;
084: }
085:
086: public void read(ByteCodeInput in) throws IOException {
087: super .read(in);
088:
089: if (wide) {
090: immediateByte = in.readUnsignedShort();
091: } else {
092: immediateByte = in.readUnsignedByte();
093: }
094: }
095:
096: public void write(ByteCodeOutput out) throws IOException {
097: super.write(out);
098:
099: if (wide) {
100: out.writeShort(immediateByte);
101: } else {
102: out.writeByte(immediateByte);
103: }
104: }
105:
106: }
|