sparcaddress.java

来自「用Java实现的编译器。把源代码编译成SPARC汇编程序」· Java 代码 · 共 215 行

JAVA
215
字号
// $Id: SPARCAddress.java,v 1.4 1999/11/04 16:53:41 deberg Exp $package java6035.tools.ASM;/** * SPARCAddress * * represents an address in SPARC. There are four formats of address: * (register), imm, imm(register), symbol */public class SPARCAddress extends SPARCOperand{    protected int sparc_op_kind() { return SPARCADDRESS; } 	/**      *  the address label (usually for branch instructions)	 *	null if address in other formats	 *     */    protected String symbol;    /**      * base address register 1, null if address is simm13 or label format	 *     */    protected SPARCRegister r1;    /**      * base address register 2, null if address is simm13 or label format     */    protected SPARCRegister r2;    /**      * 	immediate offset or address (depending on format)	 *	; disregarded or arbitrary if the address is label format     */	     protected int imm;    public final boolean isImmed()     { 	return false;     }       public final boolean isRegister()     { 	return false;     }    public final boolean isAddress()    {	return true;    }    /**      * returns the first base register  of the address, null if address is     * pure simm13 format      */    public SPARCRegister getRegister1()    {		return r1;    }    /**      * returns the      */    public String getSymbol()    {		return symbol;    }		/**      * returns the second base register  of the address, null if address is     * pure simm13 format      */    public SPARCRegister getRegister2()    {		return r2;    }    /**      * returns the immed offset of the address, 	 * which is disregarded or arbitrary if	 * address format is (reg+reg)     */    public int getImmed()    {		return imm;    }    /**     * Constructor for address of the form reg.only     */    public SPARCAddress (SPARCRegister r)    {		if (r == null) throw new ASMException		    ("SPARCAddress: in constructor: register r must not be null");		this.imm = 0;		this.r1 = r;		this.r2 = null;					symbol = null;	}	/**     * Constructor for label form of address     */    public SPARCAddress (String s)    {		if (s == null) throw new ASMException		    ("SPARCAddress: in constructor: label must not be null");		this.imm = 0;		this.r1 = null;		this.r2 = null;					symbol = s;	}    /**     * Constructor for address of the form simm13     */    public SPARCAddress (int i)    {		this.imm = i;		this.r1 = SPARCRegister.g0;		this.r2 = null;		symbol = null;    }	    /**     * Constructor for address of the form simm13 (+-) reg     */    public SPARCAddress (SPARCRegister r, int i)    {		if (r == null) throw new ASMException		    ("SPARCAddress: in constructor: register r must not be null");		this.imm = i;		this.r1 = r;		this.r2 = null;		symbol = null;		    }    /**     * Constructor for address of the form reg + reg     */    public SPARCAddress (SPARCRegister r1, SPARCRegister r2)    {		if (r1 == null) throw new ASMException		    ("SPARCAddress: in constructor: register must not be null");		if (r2 == null) throw new ASMException		    ("SPARCAddress: in constructor: register must not be null");					this.r1 = r1;		this.r2 = r2;		this.imm = 0;		symbol = null;    }    /**     * Returns the string representation of the operand.     */    public String toString()    {		if(symbol != null) return symbol;		if(imm !=0 )		{			if(imm > 0)			{				return "["+r1.toString()+"+"+imm+"]";			}			else			{				imm = -imm;				return "["+r1.toString()+"-"+imm+"]";						}		}		else		{			if(r1 != null && r2 != null)			{				return "["+r1.toString()+"+"+r2.toString()+"]";			}				else			{				return "["+r1.toString()+"]";			}		}    }    /**     * Returns true if two address are the same.     */    public boolean equals(Object o)    {		if (o instanceof SPARCAddress)		{		    SPARCAddress a = (SPARCAddress) o;		    if(symbol != null)				return symbol.equals(a.symbol);			else				return (a.r1.equals(r1) &&						a.r2.equals(r2) &&						a.imm == imm);		}		return false;    }}

⌨️ 快捷键说明

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