KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > coffi > Instruction_byteindex


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_byteindex extends Instruction {
63     /**
64     * arg_b needs to be short in order to contain all the possible values for an unsigned byte
65     */

66    public short arg_b;
67    public Instruction_byteindex(byte c) { super(c); }
68    public String JavaDoc toString(cp_info constant_pool[]) {
69       int i = ((int)arg_b)&0xff;
70       return super.toString(constant_pool) + argsep + "[" +
71          constant_pool[i].toString(constant_pool) + "]";
72    }
73    public int nextOffset(int curr) { return curr+2; }
74    public void markCPRefs(boolean[] refs) { refs[((int)arg_b)&0xff] = true; }
75    public void redirectCPRefs(short redirect[]) { arg_b = (byte)(redirect[((int)arg_b)&0xff]); }
76    public int parse(byte bc[],int index) {
77       arg_b = bc[index];
78
79       arg_b = (arg_b >= 0) ? arg_b : (short) (256 + arg_b);
80
81       return index+1;
82    }
83    public int compile(byte bc[],int index) { bc[index++] = code; bc[index++] = (byte) arg_b; return index; }
84 }
85
Popular Tags