GetInstr.java

  1. package org.jruby.ir.instructions;

  2. import org.jruby.ir.Operation;
  3. import org.jruby.ir.operands.Operand;
  4. import org.jruby.ir.operands.StringLiteral;
  5. import org.jruby.ir.operands.Variable;

  6. import java.util.Map;

  7. // Represents result = source.ref or result = source where source is not a stack variable
  8. public abstract class GetInstr extends Instr implements ResultInstr, FixedArityInstr {
  9.     private Operand source;
  10.     private final String  ref;
  11.     private Variable result;

  12.     public GetInstr(Operation op, Variable result, Operand source, String ref) {
  13.         super(op);

  14.         assert result != null: "" + getClass().getSimpleName() + " result is null";

  15.         this.source = source;
  16.         this.ref = ref;
  17.         this.result = result;
  18.     }

  19.     public String getRef() {
  20.         return ref;
  21.     }

  22.     @Override
  23.     public Variable getResult() {
  24.         return result;
  25.     }

  26.     @Override
  27.     public void updateResult(Variable v) {
  28.         this.result = v;
  29.     }

  30.     @Override
  31.     public Operand[] getOperands() {
  32.         return new Operand[] { source, new StringLiteral(ref) };
  33.     }

  34.     public Operand getSource() {
  35.         return source;
  36.     }

  37.     @Override
  38.     public String toString() {
  39.         return super.toString() + "(" + source + (ref == null ? "" : ", " + ref) + ")";
  40.     }

  41.     @Override
  42.     public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
  43.         source = source.getSimplifiedOperand(valueMap, force);
  44.     }
  45. }