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 /** Branch on false.<br>
023 * Stack transition:<br>
024 * ..., value --> ...
025 * @author Michael Stepp
026 */
027 public class BRFALSE extends BranchInstruction{
028 // BRFALSE <int32>
029 // BRFALSE.S <int8>
030 // aliases: BRZERO, BRNULL
031 public static final int BRFALSE = 0x39;
032 public static final int BRFALSE_S = 0x2C;
033 protected static final int OPCODE_LIST[] = {BRFALSE, BRFALSE_S};
034
035 /** Makes a new BRFALSE object with the given branch target, possibly in short form
036 * @param shortF true iff this is a short form instruction
037 * @param ih the baranch target handle
038 */
039 public BRFALSE(boolean shortF, InstructionHandle ih) throws InstructionInitException{
040 super((shortF ? BRFALSE_S : BRFALSE), OPCODE_LIST, ih);
041 }
042
043 public boolean isShort(){
044 return (getOpcode()==BRFALSE_S);
045 }
046
047 public String getName(){
048 return (isShort() ? "brfalse.s" : "brfalse");
049 }
050
051 public int getLength(){
052 return (super.getLength() + (isShort() ? 1 : 4));
053 }
054
055 protected void emit(edu.arizona.cs.mbel.ByteBuffer buffer, edu.arizona.cs.mbel.emit.ClassEmitter emitter){
056 super.emit(buffer, emitter);
057 if (isShort())
058 buffer.put(getTarget());
059 else
060 buffer.putINT32(getTarget());
061 }
062
063 public BRFALSE(int opcode, edu.arizona.cs.mbel.mbel.ClassParser parse) throws java.io.IOException, InstructionInitException{
064 super(opcode, OPCODE_LIST);
065 setTarget((isShort() ? parse.getMSILInputStream().readINT8() : parse.getMSILInputStream().readINT32()));
066 }
067
068 public boolean equals(Object o){
069 return (super.equals(o) && (o instanceof BRFALSE));
070 }
071 }