KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > coffi > Instruction_branch


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

63 abstract class Instruction_branch extends Instruction {
64    public int arg_i;
65    public Instruction target; // pointer to target instruction
66
public Instruction_branch(byte c) { super(c); branches = true; }
67
68    public String JavaDoc toString(cp_info constant_pool[]) {
69       return super.toString(constant_pool) + argsep
70       + "[label_" + Integer.toString(target.label) + "]";
71    }
72
73    public void offsetToPointer(ByteCode bc) {
74       target = bc.locateInst(arg_i+label);
75       if (target==null) {
76          G.v().out.println("Warning: can't locate target of instruction");
77          G.v().out.println(" which should be at byte address " + (label+arg_i));
78       } else
79          target.labelled = true;
80    }
81    // returns the array of instructions which might be the target of a
82
// branch with this instruction, assuming the next instruction is next
83
public Instruction[] branchpoints(Instruction next) {
84       Instruction i[] = new Instruction[2];
85       i[0] = target; i[1] = next;
86       return i;
87    }
88
89     public String JavaDoc toString()
90     {
91     return super.toString()+ "\t"+target.label;
92     }
93 }
94
Popular Tags