001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.jikesrvm.compilers.opt.lir2mir;
014
015import org.jikesrvm.compilers.opt.ir.Operators;
016
017/**
018 * A subclass of BURS_TreeNode for an IntConstantOperand.<p>
019 *
020 * It is very common for us to want to access the value of an
021 * int constant during BURS, so we make it easy to do so by creating
022 * a special kind of node.
023 */
024final class BURS_IntConstantTreeNode extends AbstractBURS_TreeNode {
025
026  /** The int constant value associated with this tree node */
027  final int value;
028
029  /** Where costs and rules are stored */
030  private final AbstractBURS_TreeNode delegate =
031    AbstractBURS_TreeNode.create(Operators.INT_CONSTANT_opcode);
032
033  /**
034   * Constructor for interior node.
035   *
036   * @param val a constant int value
037   */
038  BURS_IntConstantTreeNode(int val) {
039    super(Operators.INT_CONSTANT_opcode);
040    value = val;
041    setNumRegisters(0);
042  }
043
044  @Override
045  public String toString() {
046    return "INT_CONSTANT " + value;
047  }
048
049 /**
050  * Gets the BURS rule number associated with this tree node for a given non-terminal
051  *
052  * @param goalNT the non-terminal we want to know the rule for (e.g. stm_NT)
053  * @return the rule number
054  */
055  @Override
056  public int rule(int goalNT) {
057    return delegate.rule(goalNT);
058  }
059
060  @Override
061  public char getCost(int goalNT) {
062    return delegate.getCost(goalNT);
063  }
064
065  @Override
066  public void setCost(int goalNT, char cost) {
067    delegate.setCost(goalNT, cost);;
068  }
069
070  @Override
071  public void initCost() {
072    delegate.initCost();
073  }
074
075  @Override
076  public void writePacked(int word, int mask, int shiftedValue) {
077    delegate.writePacked(word, mask, shiftedValue);
078  }
079
080  @Override
081  public int readPacked(int word, int shift, int mask) {
082    return readPacked(word, shift, mask);
083  }
084}