⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sparcregister.java

📁 用Java实现的编译器。把源代码编译成SPARC汇编程序
💻 JAVA
字号:
// $Id: SPARCRegister.java,v 1.5 2000/10/21 23:18:10 mdeeds Exp $package java6035.tools.ASM;/** * SPARC Register represents a register in SPARC. * Only the user accessable registers may be created and used. * System registers will cause problems. *  * Valid register numbers are from 0 to 31 inclusive **/public class SPARCRegister extends SPARCOperand{    protected int sparc_op_kind() { return SPARCREGISTER; }    public int status;	/**     * Returns true if @param o represents the same register     * as this.     **/    public boolean equals(Object o)    {	if (o instanceof SPARCRegister &&	    this.w == ((SPARCRegister)o).w)	    return true;	return false;    }    /**     * Returns a hash code which is the same for any two SPARCRegisters     * which are equal to each other.  (i.e. the same register)     **/    public int hashCode() {	return this.w;    }    /**     * Returns true if this object represents the register identified by     * the symbolic constant given.     */	     public boolean equals(int r)    {	return w == r;    }    /**     * Returns which register this object represents.     */	     public int which()    {	return w;    }    /**     * Returns the string representation of the register.     */	     public String toString()    {	return stringrep[w];    }    SPARCRegister(int which)    {	this.w = which;    }    private int w;    private static String stringrep[] =     	{"%g0","%g1","%g2","%g3","%g4","%g5","%g6","%g7",         "%o0","%o1","%o2","%o3","%o4","%o5","%sp","%o7",	 	 "%l0","%l1","%l2","%l3","%l4","%l5","%l6","%l7",	 	 "%i0","%i1","%i2","%i3","%i4","%i5","%fp","%i7"};    /** Global register g0: mapped to constant 0 */    public static final int G0 = 0;    /** register 0: mapped to constant 0 */    public static final SPARCRegister g0 = new SPARCRegister(G0);    /** Global register 1 */    public static final int G1 = 1;    /** Global register 1 */    public static final SPARCRegister g1 = new SPARCRegister(G1);    /** Global register 2 */    public static final int G2 = 2;    /** Global register 2 */    public static final SPARCRegister g2 = new SPARCRegister(G2);        /** Global register 3 */    public static final int G3 = 3;    /** Global register 3 */    public static final SPARCRegister g3 = new SPARCRegister(G3);        /** Global register 4 */    public static final int G4 = 4;    /** Global register 4 */    public static final SPARCRegister g4 = new SPARCRegister(G4);        /** Global register 5 */    public static final int G5 = 5;    /** Global register 5 */    public static final SPARCRegister g5 = new SPARCRegister(G5);        /** Global register 6 */    public static final int G6 = 6;    /** Global register 6 */    public static final SPARCRegister g6 = new SPARCRegister(G6);        /** Global register 7 */    public static final int G7 = 7;    /** Global register 7 */    public static final SPARCRegister g7 = new SPARCRegister(G7);        /** Output register 0 */    public static final int O0 = 8;    /** Output register 0 */    public static final SPARCRegister o0 = new SPARCRegister(O0);        /** Output register 1 */    public static final int O1 = 9;    /** Output register 1 */    public static final SPARCRegister o1 = new SPARCRegister(O1);        /** Output register 2 */    public static final int O2 = 10;    /** Output register 2 */    public static final SPARCRegister o2 = new SPARCRegister(O2);        /** Output register 3 */    public static final int O3 = 11;    /** Output register 3 */    public static final SPARCRegister o3 = new SPARCRegister(O3);        /** Output register 4 */    public static final int O4 = 12;    /** Output register 4 */    public static final SPARCRegister o4 = new SPARCRegister(O4);    	/** Output register 5 */    public static final int O5 = 13;	/** Output register 5 */    public static final SPARCRegister o5 = new SPARCRegister(O5);    	/** Stack Pointer register synonym of out register 6 */    public static final int SP = 14;	/** Stack Pointer register synonym of out register 6 */    public static final SPARCRegister sp = new SPARCRegister(SP);    	/** Output register 7 */    public static final int O7 = 15;	/** Output register 7 */    public static final SPARCRegister o7 = new SPARCRegister(O7);    	/** Local register 0 */    public static final int L0 = 16;	/** Local register 0 */    public static final SPARCRegister l0 = new SPARCRegister(L0);    	/** Local register 1 */    public static final int L1 = 17;	/** Local register 1 */    public static final SPARCRegister l1 = new SPARCRegister(L1);		/** Local register 2 */    public static final int L2 = 18;	/** Local register 2 */    public static final SPARCRegister l2 = new SPARCRegister(L2);		/** Local register 3 */    public static final int L3 = 19;	/** Local register 3 */    public static final SPARCRegister l3 = new SPARCRegister(L3);		/** Local register 4 */    public static final int L4 = 20;	/** Local register 4 */    public static final SPARCRegister l4 = new SPARCRegister(L4);    	/** Local register 5 */    public static final int L5 = 21;	/** Local register 5 */    public static final SPARCRegister l5 = new SPARCRegister(L5);    	/** Local register 6 */    public static final int L6 = 22;	/** Local register 6 */    public static final SPARCRegister l6 = new SPARCRegister(L6);    	/** Local register 7 */    public static final int L7 = 23;	/** Local register 7 */    public static final SPARCRegister l7 = new SPARCRegister(L7);    	/** Input register 0 */    public static final int I0 = 24;	/** Input register 0 */    public static final SPARCRegister i0 = new SPARCRegister(I0);    	/** Input register 1 */    public static final int I1 = 25;	/** Input register 1 */    public static final SPARCRegister i1 = new SPARCRegister(I1);    	/** Input register 2 */    public static final int I2 = 26;	/** Input register 2 */    public static final SPARCRegister i2 = new SPARCRegister(I2);    	/** Input register 3 */    public static final int I3 = 27;	/** Input register 3 */    public static final SPARCRegister i3 = new SPARCRegister(I3);    	/** Input register 4 */    public static final int I4 = 28;	/** Input register 4 */    public static final SPARCRegister i4 = new SPARCRegister(I4);    	/** Input register 5 */    public static final int I5 = 29;	/** Input register 5 */    public static final SPARCRegister i5 = new SPARCRegister(I5);        /** frame pointer */    public static final int FP = 30;    /** frame pointer */    public static final SPARCRegister fp = new SPARCRegister(FP);    	/** Input register 7 */    public static final int I7 = 31;	/** Input register 7*/    public static final SPARCRegister i7 = new SPARCRegister(I7);    private static SPARCRegister regs[] =     	{g0,g1,g2,g3,g4,g5,g6,g7,	 	 o0,o1,o2,o3,o4,o5,sp,o7,	     l0,l1,l2,l3,l4,l5,l6,l7,	     i0,i1,i2,i3,i4,i5,fp,i7};    /** return register the given register number points to **/    public static SPARCRegister getRegister(int reg)    {		if (reg < 0 || reg > 31 || reg == 1 || reg == 26 || reg == 27)		    throw new ASMException("Illegal register "+reg);		return regs[reg];    }	public static void releaseRegister(SPARCRegister reg){		reg.status = 0;	}	public static void setRegister(SPARCRegister reg){		reg.status = 1;	}	public static SPARCRegister getNextRegInput(){		for(int j=24 ; j<=31; j++){			if( (regs[j].which() != 30) && (regs[j].status != 1)){				return regs[j];			}		}		return null;	}		public static SPARCRegister getNextRegOutput(){		for(int j=8 ; j<=15; j++){			if( (regs[j].which() != 14) && (regs[j].status != 1)){				return regs[j];			}		}		return null;	}		public static SPARCRegister getNextRegLocal(){		for(int j=16 ; j<=23; j++){			if( regs[j].status != 1 ){				return regs[j];			}		}		return null;	}	public static int getLocalAvailable(){		int cnt = 0;		for(int j=16 ; j<=23; j++){			if( regs[j].status != 1 ){				cnt++;			}		}		return cnt;	}		public static void releaseAllRegisters(){		for(int j=0; j<=31; j++){			if( (regs[j].which() != 14) && (regs[j].which() != 30) ){				regs[j].status = 0;			}		}	}	public static void releaseAllOutputRegisters(){		for(int j=8; j<=15; j++){			if( regs[j].which() != 14 ){				regs[j].status = 0;			}		}	}	public static int noOfOutputRegistersUsed(){		int cnt = 0;		for(int j=8; j<=15; j++){			if( (regs[j].which() != 14)  && (regs[j].status == 1)){				cnt++;			}		}		return cnt;	}}

⌨️ 快捷键说明

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