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     */
013    package org.jikesrvm.compilers.opt.liveness;
014    
015    import org.jikesrvm.VM;
016    import org.jikesrvm.classloader.TypeReference;
017    import org.jikesrvm.compilers.opt.ir.Register;
018    import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand;
019    
020    /**
021     * A simple class that holds an element in a LiveSet.
022     */
023    final class LiveSetElement {
024    
025      /**
026       * The register operand, i.e., the data
027       */
028      private RegisterOperand regOp;
029    
030      /**
031       * The next field
032       */
033      private LiveSetElement next;
034    
035      /**
036       * Construct an {@link LiveSetElement}.
037       *
038       * @param register    An {@link RegisterOperand}
039       */
040      LiveSetElement(RegisterOperand register) {
041        regOp = register;
042      }
043    
044      /**
045       * Returns the register operand associated with this element
046       * @return the register operand associated with this element
047       */
048      public RegisterOperand getRegisterOperand() {
049        return regOp;
050      }
051    
052      /**
053       * Change the register operand.  New operand must represent the same register
054       * This is done to promote something of WordType to ReferenceType for the purposes of GC mapping.
055       */
056      public void setRegisterOperand(RegisterOperand newRegOp) {
057        if (VM.VerifyAssertions) VM._assert(regOp.getRegister().number == newRegOp.getRegister().number);
058        regOp = newRegOp;
059      }
060    
061      /**
062       * Returns the register associated with this element
063       * @return the register associated with this element
064       */
065      public Register getRegister() {
066        return regOp.getRegister();
067      }
068    
069      /**
070       * Returns the register type associated with this element
071       * @return the register type associated with this element
072       */
073      public TypeReference getRegisterType() {
074        return regOp.getType();
075      }
076    
077      /**
078       * Returns the next element on this list
079       * @return the next element on this list
080       */
081      public LiveSetElement getNext() {
082        return next;
083      }
084    
085      /**
086       * Sets the next element field
087       * @param newNext the next element field
088       */
089      public void setNext(LiveSetElement newNext) {
090        next = newNext;
091      }
092    
093      /**
094       * Returns a string version of this element
095       * @return a string version of this element
096       */
097      @Override
098      public String toString() {
099        StringBuilder buf = new StringBuilder("");
100        buf.append(regOp);
101        return buf.toString();
102      }
103    }