variable.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 158 行

JAVA
158
字号
/*
 * $Id: Variable.java,v 1.10 2004/02/16 14:15:10 msiddalingaiah Exp $
 *
 * mailto:madhu@madhu.com
 */
package org.jnode.vm.compiler.ir;

import org.jnode.vm.compiler.ir.quad.AssignQuad;
import org.jnode.vm.compiler.ir.quad.VariableRefAssignQuad;

/**
 * @author Madhu Siddalingaiah
 *
 */
public abstract class Variable extends Operand implements Cloneable {
	private int index;
	private int ssaValue;
	private Location location;

	/*
	 * The operation where this variable is assigned
	 */
	private AssignQuad assignQuad;

	/*
	 * The address where this variable is last used
	 */
	private int lastUseAddress;

	public Variable(int type, int index, int ssaValue) {
		super(type);
		this.index = index;
		this.ssaValue = ssaValue;
	}

	/**
	 * @param type
	 */
	public Variable(int type, int index) {
		this(type, index, 1000*index);
	}

	public void doSSA() {
		ssaValue += 1;
	}

	public boolean equals(Object other) {
		if (other == null) {
			return false;
		}
		return hashCode() == other.hashCode();
	}

	public int hashCode() {
		return ssaValue;
	}

	/**
	 * @return
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * @return
	 */
	public int getSSAValue() {
		return ssaValue;
	}
	
	public abstract Object clone();

	/**
	 * Returns the AssignQuad where this variable was last assigned.
	 * 
	 * @return
	 */
	public AssignQuad getAssignQuad() {
		return assignQuad;
	}

	/**
	 * @return
	 */
	public int getLastUseAddress() {
		return lastUseAddress;
	}

	/**
	 * @param assignQuad
	 */
	public void setAssignQuad(AssignQuad assignQuad) {
		this.assignQuad = assignQuad;
	}

	public int getAssignAddress() {
		if (assignQuad == null) {
			return 0;
		}
		// Add one so this live range starts just after this operation.
		// This way live range interference computation is simplified.
		return this.assignQuad.getLHSLiveAddress();
	}

	/**
	 * @param address
	 */
	public void setLastUseAddress(int address) {
		if (address > lastUseAddress) {
			lastUseAddress = address;
		}
	}

	public Operand simplify() {
		return assignQuad.propagate(this);
	}
	
	public Variable simplifyCopy() {
		if (assignQuad instanceof VariableRefAssignQuad) {
			VariableRefAssignQuad va = (VariableRefAssignQuad) assignQuad;
			Operand rhs = va.getRHS();
			if (rhs instanceof Variable) {
				return (Variable) rhs;
			}
		}
		assignQuad.setDeadCode(false);
		return this;
	}

	/**
	 * @return
	 */
	public Location getLocation() {
		return this.location;
	}

	/**
	 * @param loc
	 */
	public void setLocation(Location loc) {
		this.location = loc;
	}

	/* (non-Javadoc)
	 * @see org.jnode.vm.compiler.ir.Operand#getAddressingMode()
	 */
	public int getAddressingMode() {
		if (location instanceof StackLocation) {
			return Operand.MODE_STACK;
		} else if (location instanceof RegisterLocation) {
			return Operand.MODE_REGISTER;
		} else {
			throw new IllegalArgumentException("Undefined location");
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?