KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > coffi > Instruction_bytevar


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997 Clark Verbrugge
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30
31
32 package soot.coffi;
33 import java.io.*;
34 /** Instruction subclasses are used to represent parsed bytecode; each
35  * bytecode operation has a corresponding subclass of Instruction.
36  * <p>
37  * Each subclass is derived from one of
38  * <ul><li>Instruction</li>
39  * <li>Instruction_noargs (an Instruction with no embedded arguments)</li>
40  * <li>Instruction_byte (an Instruction with a single byte data argument)</li>
41  * <li>Instruction_bytevar (a byte argument specifying a local variable)</li>
42  * <li>Instruction_byteindex (a byte argument specifying a constant pool index)</li>
43  * <li>Instruction_int (an Instruction with a single short data argument)</li>
44  * <li>Instruction_intvar (a short argument specifying a local variable)</li>
45  * <li>Instruction_intindex (a short argument specifying a constant pool index)</li>
46  * <li>Instruction_intbranch (a short argument specifying a code offset)</li>
47  * <li>Instruction_longbranch (an int argument specifying a code offset)</li>
48  * </ul>
49  * @author Clark Verbrugge
50  * @see Instruction
51  * @see Instruction_noargs
52  * @see Instruction_byte
53  * @see Instruction_bytevar
54  * @see Instruction_byteindex
55  * @see Instruction_int
56  * @see Instruction_intvar
57  * @see Instruction_intindex
58  * @see Instruction_intbranch
59  * @see Instruction_longbranch
60  * @see Instruction_Unknown
61  */

62 class Instruction_bytevar extends Instruction implements Interface_OneIntArg
63 {
64     /**
65      * arg_b needs to be short in order to contain all the possible values for an unsigned byte
66      */

67     public int arg_b;
68     public boolean isWide;
69
70     public Instruction_bytevar(byte c) { super(c); }
71     public String JavaDoc toString(cp_info constant_pool[]) {
72     return super.toString(constant_pool) + argsep + LOCALPREFIX + arg_b;
73     }
74
75     public int nextOffset(int curr) { return curr + 1 + ((isWide) ? 3 : 1); }
76
77     public int parse(byte bc[],int index)
78     {
79         int indexbyte1 = ((int) bc[index]) & 0xff;
80
81         if(isWide)
82         {
83             int indexbyte2 = ((int) bc[index+1]) & 0xff;
84
85             arg_b = (indexbyte1 << 8) | indexbyte2;
86
87             return index+2;
88         }
89         else
90         {
91             arg_b = indexbyte1;
92             return index+1;
93         }
94     }
95
96     public int compile(byte bc[],int index) { bc[index++] = code; bc[index++] = (byte) arg_b; return index; }
97
98     public int getIntArg()
99     {
100     return arg_b;
101     }
102 }
103
Popular Tags