package edu.cmu.cs.l3.flowgraph;

import edu.cmu.cs.l3.graph.*;
import edu.cmu.cs.l3.assem.*;
import java.util.*;
import edu.cmu.cs.l3.temp.*;

public class FlowVertex extends Vertex {

    public FlowVertex(Instruction instr) {
        m_instr = instr;
    }

    public BitSet getDefines() {
        return makeBitVector(m_instr.destTemps());
    }

    public BitSet getUses() {
        return makeBitVector(m_instr.sourceTemps());
    }

    private BitSet makeBitVector(List temps) {
        int i;
        BitSet def = new BitSet(Temp.count());

        if (temps != null) {
            for (i = 0; i < temps.size(); i++) {
                def.set(((Temp)temps.get(i)).num());
            }
        }

        return def;
    }

    public boolean isMove() {
        return (m_instr instanceof MoveInstruction);
    }

    public Instruction getInstruction() {
        return m_instr;
    }

    public String toString() {
        return "V:(" + m_instr.getInstruction().substring(0,m_instr.getInstruction().length()-1)+")";
    }

    private Instruction m_instr;
}