KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > InsnTargetOp


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27
28 import java.io.PrintStream JavaDoc;
29
30 /**
31  * An instruction which requires a single branch offset
32  * as an immediate operand .
33  */

34
35 public class InsnTargetOp extends Insn {
36   /* The branch target */
37   InsnTarget targetOp;
38
39   /* public accessors */
40
41   public int nStackArgs() {
42     return VMOp.ops[opcode()].nStackArgs();
43   }
44
45   public int nStackResults() {
46     return VMOp.ops[opcode()].nStackResults();
47   }
48
49   public String JavaDoc argTypes() {
50     return VMOp.ops[opcode()].argTypes();
51   }
52
53   public String JavaDoc resultTypes() {
54     return VMOp.ops[opcode()].resultTypes();
55   }
56
57   public boolean branches() {
58     return true;
59   }
60
61   /**
62    * Mark possible branch targets
63    */

64   public void markTargets() {
65     targetOp.setBranchTarget();
66   }
67
68   /**
69    * Return the branch target which is the immediate operand
70    */

71   public InsnTarget target() {
72     return targetOp;
73   }
74     
75   /* package local methods */
76
77   void print (PrintStream JavaDoc out, int indent) {
78     ClassPrint.spaces(out, indent);
79     /* print offset in non-relative form for readability */
80     out.println(offset() + " " + opName(opcode()) + " " + //NOI18N
81
targetOp.offset());
82   }
83
84   int store(byte[] buf, int index) {
85     buf[index++] = (byte) opcode();
86     int off = targetOp.offset() - offset();
87     if (opcode() == opc_goto_w || opcode() == opc_jsr_w)
88       return storeInt(buf, index, off);
89     else
90       return storeShort(buf, index, (short)off);
91   }
92
93   int size() {
94     if (opcode() == opc_goto_w || opcode() == opc_jsr_w)
95       return 5;
96     return 3;
97   }
98
99   InsnTargetOp (int theOpcode, InsnTarget theOperand, int pc) {
100     super(theOpcode, pc);
101     targetOp = theOperand;
102   }
103
104   InsnTargetOp (int theOpcode, InsnTarget theOperand) {
105     super(theOpcode, NO_OFFSET);
106
107     targetOp = theOperand;
108
109     switch(theOpcode) {
110     case opc_ifeq:
111     case opc_ifne:
112     case opc_iflt:
113     case opc_ifge:
114     case opc_ifgt:
115     case opc_ifle:
116     case opc_if_icmpeq:
117     case opc_if_icmpne:
118     case opc_if_icmplt:
119     case opc_if_icmpge:
120     case opc_if_icmpgt:
121     case opc_if_icmple:
122     case opc_if_acmpeq:
123     case opc_if_acmpne:
124     case opc_goto:
125     case opc_jsr:
126     case opc_ifnull:
127     case opc_ifnonnull:
128     case opc_goto_w:
129     case opc_jsr_w:
130       /* Target */
131       if (theOperand == null)
132           throw new InsnError ("attempt to create an " + opName(theOpcode) +//NOI18N
133
" with a null Target operand");//NOI18N
134
break;
135
136     default:
137         throw new InsnError ("attempt to create an " + opName(theOpcode) +//NOI18N
138
" with an InsnTarget operand");//NOI18N
139
}
140   }
141 }
142
Popular Tags