001 /* MBEL: The Microsoft Bytecode Engineering Library
002 * Copyright (C) 2003 The University of Arizona
003 * http://www.cs.arizona.edu/mbel/license.html
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either
008 * version 2.1 of the License, or (at your option) any later version.
009 *
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013 * Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public
016 * License along with this library; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018 */
019
020 package edu.arizona.cs.mbel.instructions;
021
022 /** Indirect method call. Calls method on stack with given signature.<br>
023 * Stack transition:<br>
024 * ...arg1, ... argN, ftn --> ..., retVal (maybe)
025 * @author Michael Stepp
026 */
027 public class CALLI extends TailPrefixInstruction{
028 // CALLI callsitedescr
029 public static final int CALLI = 0x29;
030 protected static final int OPCODE_LIST[] = {CALLI};
031 private edu.arizona.cs.mbel.signature.MethodSignature signature;
032
033 /** Makes a new CALLI object with the given method callsite signature (with no tail prefix)
034 * @param sig the method callsite signature
035 */
036 public CALLI(edu.arizona.cs.mbel.signature.MethodSignature sig) throws InstructionInitException{
037 this(false, sig);
038 }
039
040 /** Makes a new CALLI object with the given method callsite signature, possibly with a tail prefix.
041 * @param has true iff this CALLI has a tail prefix
042 * @param sig the method callsite signature
043 */
044 public CALLI(boolean has, edu.arizona.cs.mbel.signature.MethodSignature sig) throws InstructionInitException{
045 super(has, CALLI, OPCODE_LIST);
046 signature = sig;
047 }
048
049 /** Returns the method callsite signature for this CALLI
050 */
051 public edu.arizona.cs.mbel.signature.MethodSignature getMethodSignature(){
052 return signature;
053 }
054
055 public String getName(){
056 return "calli";
057 }
058
059 public int getLength(){
060 return (super.getLength()+4);
061 }
062
063 protected void emit(edu.arizona.cs.mbel.ByteBuffer buffer, edu.arizona.cs.mbel.emit.ClassEmitter emitter){
064 super.emit(buffer, emitter);
065 long token = emitter.getStandAloneSigToken(signature);
066 buffer.putTOKEN(token);
067 }
068
069 public CALLI(int opcode, edu.arizona.cs.mbel.mbel.ClassParser parse) throws java.io.IOException, InstructionInitException{
070 super(opcode, OPCODE_LIST);
071 long callsiteDescriptor = parse.getMSILInputStream().readTOKEN();
072 signature = parse.getStandAloneSignature(callsiteDescriptor);
073 }
074
075 public boolean equals(Object o){
076 if (!(super.equals(o) && (o instanceof CALLI)))
077 return false;
078 CALLI calli = (CALLI)o;
079 return (signature==calli.signature);
080 }
081
082 /*
083 public void output(){
084 System.out.print(getName()+" ");
085 signature.output();
086 }
087 */
088 }