package edu.cmu.cs.l3.temp;

import java.util.*;

public class Temp  {

    public static List tempList = new ArrayList();
    private static int count=-1;
    public static int count() { return count; }

    private int num;
    public Temp() { num=++count; tempList.add(this); m_alias = this; }

    public String toString() { return "t" + num; }
    public int num() { return num; }

    public int getSize() {
	return m_size;
    }

    public int hashCode() {
        return num;
    }

    public String getGlobalName() {
        if (m_name == null)
            return toString();
        return m_name;
    }

    public void setGlobalName(String name) {
        m_name = name;
    }

    public boolean isGlobal() {
        return m_global;
    }

    public boolean isGlobalPointer() {
        return m_globalptr;
    }

    public void setGlobal(boolean ptr) {
        m_global = true;
        m_globalptr = ptr;
    }

    public void use() {
        m_uses++;
    }

    public void def() {
        m_defs++;
    }

    public int getNumUses() {
        return m_uses;
    }

    public int getNumDefs() {
        return m_defs;
    }

    public void setSpilled(int offset) {
        m_spilled = true; m_offset=offset;
    }

    public boolean isSpilled() {
        return m_spilled;
    }

    public int getSpillOffset() {
        return m_offset;
    }

    public void resetUsage() {
        m_uses=0; m_defs=0;
    }

    public boolean isMemHelper() {
        return m_memhelper;
    }

    public void setAsMemHelper() {
        m_memhelper = true;
    }

    public boolean hasValue() {
        return m_hasvalue;
    }

    public void setValue(int value) {
        m_hasvalue = true; m_value = value;
    }

    public int getValue() {
        return m_value;
    }

    private int m_uses=0,m_defs=0,m_offset=0,m_value=0;
    private int m_size; // In bytes
    private boolean m_global=false, m_hasvalue=false;
    private boolean m_spilled=false, m_memhelper=false, m_globalptr=false;
    private Temp m_alias;
    private String m_name=null;
}
