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

📄 opexpr.java

📁 用Java实现的编译器。把源代码编译成SPARC汇编程序
💻 JAVA
字号:
// $Id: OpExpr.java,v 1.3 1999/09/29 06:20:44 deberg Exp $package java6035.tools.IR;/** * OpExpr represents an operation expression. The operation is defined as  * an integer opcode, meaningful to the program using this class. */public class OpExpr extends Expression{    protected int opcode;    protected Rhs left_operand;    protected Rhs right_operand;    /**     * Constructs an operation with no operand.     */    public OpExpr(int opcode)    {	this.opcode = opcode;	this.left_operand = null;	this.right_operand = null;    }    /**     * Constructs an unary expression.     */    public OpExpr(int opcode, Rhs operand)    {	this.opcode = opcode;	this.left_operand = operand;	this.right_operand = null;    }    /**     * Constructs a binary expression.     */    public OpExpr(int opcode, Rhs left_operand, Rhs right_operand)    {	this.opcode = opcode;	this.left_operand = left_operand;	this.right_operand = right_operand;    }    protected int expkind()    {	return OP_EXPR;    }    /**     * Returns true if expression is unary.     */    public boolean isUnary()    {	return (left_operand != null && right_operand == null);    }    /**     * Returns the opcode.     */    public int getOpcode()    {	return opcode;    }    /**     * Returns the left operand.     */    public Rhs getLeftOperand()    {	return left_operand;    }    /**     * Sets the left operand.     */    public void setLeftOperand(Rhs l)    {	this.left_operand = l;    }    /**     * Returns the right operand.     */    public Rhs getRightOperand()    {	return right_operand;    }    /**     * Sets the left operand.     */    public void setRightOperand(Rhs r)    {	this.right_operand = r;    }    /**     * Walkable interface: returns the name of the node.     */    public String getNodeName()    {	return "opexpr_"+opcode;    }    /**     * Walkable interface: returns the number of neighbors.     */    public int getNeighborCount()    {	if (isUnary())	    return 1;	else	    return 2;    }    /**     * Walkable interface: returns the specified neighbor: 0, left operand; 1,     * right operand if operation is binary.     */    public Object getNeighbor(int index)    {	if (index == 0)	    return left_operand;	else if (index == 1 && !isUnary())	    return right_operand;	return null;    }    public String PPrint(int indent, boolean recursive)    {        String output = new String();        for(int i=0;i<indent;i++) output += " ";        output += "(op_expr " + opcode + "\n";        if (recursive) {            if (left_operand != null) {                output += this.left_operand.PPrint(indent+2, true);            } else {                for(int i=0;i<indent+2;i++) output += " ";                output += "(no left operand)\n";            }            if (right_operand != null) {                output += this.right_operand.PPrint(indent+2, true);            } else {                for(int i=0;i<indent+2;i++) output += " ";                output += "(no right operand)\n";            }        }        for(int i=0;i<indent;i++) output += " ";        output += ") /* op_expr " + opcode + " */\n";        return output;    }}

⌨️ 快捷键说明

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