View Javadoc

1   /*
2    * @(#) IF_ICMPGE.java Jan 8, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.interpreter.operations;
11  
12  import java.io.DataInput;
13  import java.io.IOException;
14  
15  import nl.tudelft.simulation.dsol.interpreter.LocalVariable;
16  import nl.tudelft.simulation.dsol.interpreter.OperandStack;
17  import nl.tudelft.simulation.dsol.interpreter.classfile.Constant;
18  import nl.tudelft.simulation.language.primitives.Primitive;
19  
20  /***
21   * The IF_ICMPGE operation as defined in <a
22   * href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc6.html">
23   * http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc6.html
24   * </a>.
25   * <p>
26   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
27   * University of Technology </a>, the Netherlands. <br>
28   * See for project information <a
29   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
30   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
31   * License (GPL) </a>, no warranty <br>
32   * 
33   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
34   *         Jacobs </a><a
35   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
36   *         Verbraeck </a>
37   * @version 1.3 Apr 6, 2004
38   * @since 1.4
39   */
40  public class IF_ICMPGE extends JumpOperation
41  {
42  	/*** OP refers to the operand code */
43  	public static final int OP = 162;
44  
45  	/*** the index to load */
46  	private int offset = -1;
47  
48  	/***
49  	 * constructs a new IF_ICMPGE
50  	 * 
51  	 * @param dataInput the dataInput
52  	 * @throws IOException on IOfailure
53  	 */
54  	public IF_ICMPGE(final DataInput dataInput) throws IOException
55  	{
56  		super();
57  		this.offset = dataInput.readShort();
58  	}
59  
60  	/***
61  	 * @see nl.tudelft.simulation.dsol.interpreter.operations.JumpOperation
62  	 *      #execute(nl.tudelft.simulation.dsol.interpreter.OperandStack,
63  	 *      nl.tudelft.simulation.dsol.interpreter.classfile.Constant[],
64  	 *      nl.tudelft.simulation.dsol.interpreter.LocalVariable[])
65  	 */
66  	public int execute(final OperandStack stack, final Constant[] constantPool,
67  			final LocalVariable[] localVariables)
68  	{
69  		Comparable obj2 = Primitive.toInteger(stack.pop());
70  		Comparable obj1 = Primitive.toInteger(stack.pop());
71  		if (obj1.compareTo(obj2) >= 0)
72  		{
73  			return this.offset;
74  		}
75  		return this.getByteLength();
76  	}
77  
78  	/***
79  	 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getByteLength()
80  	 */
81  	public int getByteLength()
82  	{
83  		return OPCODE_BYTE_LENGTH + 2;
84  	}
85  
86  	/***
87  	 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getOpcode()
88  	 */
89  	public int getOpcode()
90  	{
91  		return IF_ICMPGE.OP;
92  	}
93  }