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 /** Make new array.<br>
023 * Stack transition:<br>
024 * ..., numElems --> ..., array
025 * @author Michael Stepp
026 */
027 public class NEWARR extends Instruction{
028 public static final int NEWARR = 0x8D;
029 protected static final int OPCODE_LIST[] = {NEWARR};
030 private edu.arizona.cs.mbel.mbel.AbstractTypeReference classRef; // element type
031
032 /** Makes a NEWARR object with the given element type.
033 * @param ref the element type of the array
034 */
035 public NEWARR(edu.arizona.cs.mbel.mbel.AbstractTypeReference ref) throws InstructionInitException{
036 super(NEWARR, OPCODE_LIST);
037 classRef = ref;
038 }
039
040 /** Returns the element type for this new array.
041 */
042 public edu.arizona.cs.mbel.mbel.AbstractTypeReference getType(){
043 return classRef;
044 }
045
046 public String getName(){
047 return "newarr";
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 NEWARR(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 NEWARR)))
068 return false;
069 NEWARR newarr = (NEWARR)o;
070 return (classRef==newarr.classRef);
071 }
072
073 /*
074 public void output(){
075 System.out.print(getName()+" ");
076 classRef.output();
077 }
078 */
079 }