// Mike Maxim
// IRTree rep for Move

package edu.cmu.cs.l3.tree;

public class IRMove extends IRStatement {

    public IRMove(IRExpression d, IRExpression s) {
	m_dst=d; m_src=s;

	m_classname = "IRMove";
    }

    public IRExpression getDestination() {
	return m_dst;
    }

    public IRExpression getSource() {
	return m_src;
    }

    public void setDestination(IRExpression exp) {
	m_dst = exp;
    }

    public void setSource(IRExpression exp) {
	m_src = exp;
    }

    public boolean isDestTemp() {
	return m_dst.getClassName().equals("IRTemp");
    }

    public IRExpressionList getComponents() {
	IRExpressionList comps = new IRExpressionList();
	if (m_dst.getClassName().equals("IRMem")) {
	    return comps.prepend(m_src).prepend(((IRMem)m_dst).getExpression());
	}
	else {
	    return comps.prepend(m_src);
	}
    }

    public IRStatement build(IRExpressionList comps) {
	if (m_dst.getClassName().equals("IRMem")) {
	    return new IRMove(new IRMem(comps.getExpression(0)),comps.getExpression(1));
	}
	else {
	    return new IRMove(m_dst,comps.getExpression(0));
	}
    }

    public String toString() {
	return (super.toString() + " " + m_dst.toString() + " " + m_src.toString());
    }

    private IRExpression m_dst;
    private IRExpression m_src;
}


