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 /** Initialize a ValueType.<br>
023 * Stack transition:<br>
024 * ..., addressOfValueType --> ...
025 * @author Michael Stepp
026 */
027 public class INITOBJ extends Instruction{
028 public static final int INITOBJ = 0x15FE;
029 protected static final int OPCODE_LIST[] = {INITOBJ};
030 private edu.arizona.cs.mbel.mbel.AbstractTypeReference classRef;
031
032 /** Makes a INITOBJ object for the given ValueType
033 * @param ref the type reference of the ValueType to initialize
034 */
035 public INITOBJ(edu.arizona.cs.mbel.mbel.AbstractTypeReference ref) throws InstructionInitException{
036 super(INITOBJ, OPCODE_LIST);
037 classRef = ref;
038 }
039
040 /** Returns the type reference to the ValueType in this instruction
041 */
042 public edu.arizona.cs.mbel.mbel.AbstractTypeReference getType(){
043 return classRef;
044 }
045
046 public String getName(){
047 return "initobj";
048 }
049
050 public int getLength(){
051 return (super.getLength()+4);
052 }
053
054 protected void emit(edu.arizona.cs.mbel.ByteBuffer buffer, edu.arizona.cs.mbel.emit.ClassEmitter emitter){
055 super.emit(buffer, emitter);
056 long token = emitter.getTypeToken(classRef);
057 buffer.putTOKEN(token);
058 }
059
060 public INITOBJ(int opcode, edu.arizona.cs.mbel.mbel.ClassParser parse) throws java.io.IOException, InstructionInitException{
061 super(opcode, OPCODE_LIST);
062 long classToken = parse.getMSILInputStream().readTOKEN();
063 classRef = parse.getClassRef(classToken);
064 }
065
066 public boolean equals(Object o){
067 if (!(super.equals(o) && (o instanceof INITOBJ)))
068 return false;
069 INITOBJ initobj = (INITOBJ)o;
070 return (initobj.classRef==classRef);
071 }
072
073 /*
074 public void output(){
075 System.out.print(getName()+" ");
076 classRef.output();
077 }
078 */
079 }