Exemple #1
0
  /**
   * @param ec
   * @see org.jnode.vm.x86.compiler.l1a.Item#release(EmitterContext)
   */
  private void cleanup(EmitterContext ec) {
    // assertCondition(!ec.getVStack().contains(this), "Cannot release while
    // on vstack");
    final X86RegisterPool pool = ec.getGPRPool();

    switch (getKind()) {
      case Kind.GPR:
        pool.release(gpr);
        if (VmUtils.verifyAssertions()) VmUtils._assert(pool.isFree(gpr), "reg is free");
        break;

      case Kind.LOCAL:
        // nothing to do
        break;

      case Kind.CONSTANT:
        // nothing to do
        break;

      case Kind.FPUSTACK:
        // nothing to do
        break;

      case Kind.STACK:
        // nothing to do
        break;

      default:
        throw new IllegalArgumentException("Invalid item kind");
    }

    this.gpr = null;
    setKind((byte) 0);
  }
Exemple #2
0
 /**
  * Load this item into a register that is suitable for BITS8 mode.
  *
  * @param ec
  */
 final void loadToBITS8GPR(EmitterContext ec) {
   if (!isGPR() || !gpr.isSuitableForBits8()) {
     final X86RegisterPool pool = ec.getGPRPool();
     X86Register r = pool.request(JvmType.INT, this, true);
     if (r == null) {
       ec.getVStack().push(ec);
       r = ec.getGPRPool().request(JvmType.INT, this, true);
     }
     if (VmUtils.verifyAssertions()) VmUtils._assert(r != null, "r != null");
     loadTo(ec, (X86Register.GPR) r);
   }
 }
Exemple #3
0
 /** @see org.jnode.vm.x86.compiler.l1a.Item#load(EmitterContext) */
 final void load(EmitterContext ec) {
   if (!isGPR()) {
     final X86RegisterPool pool = ec.getGPRPool();
     X86Register r = pool.request(getType(), this);
     if (r == null) {
       final VirtualStack vstack = ec.getVStack();
       vstack.push(ec);
       r = pool.request(getType(), this);
     }
     if (VmUtils.verifyAssertions()) VmUtils._assert(r != null, "r != null");
     loadTo(ec, (X86Register.GPR) r);
   }
   if (VmUtils.verifyAssertions()) {
     verifyState(ec);
   }
 }
Exemple #4
0
 /**
  * @see org.jnode.vm.x86.compiler.l1a.Item#spill(EmitterContext,
  *     org.jnode.assembler.x86.X86Register)
  */
 final void spill(EmitterContext ec, X86Register reg) {
   if (VmUtils.verifyAssertions()) {
     VmUtils._assert(
         isGPR() && (this.gpr.getNr() == reg.getNr()), "spill1 gpr=" + gpr + ", reg=" + reg);
   }
   final X86RegisterPool pool = ec.getGPRPool();
   X86Register r = pool.request(getType());
   if (r == null) {
     ec.getVStack().push(ec);
     if (getKind() == Kind.STACK) {
       return;
     }
     r = pool.request(getType());
     if (VmUtils.verifyAssertions()) VmUtils._assert(r != null, "r != null");
   }
   loadTo(ec, (X86Register.GPR) r);
   pool.transferOwnerTo(r, this);
   if (VmUtils.verifyAssertions()) {
     verifyState(ec);
   }
 }
Exemple #5
0
 /**
  * enquire whether the item uses a volatile register
  *
  * @return true, when this item uses a volatile register.
  */
 final boolean usesVolatileRegister(X86RegisterPool pool) {
   return (isGPR() && !pool.isCallerSaved(gpr));
 }
Exemple #6
0
  /**
   * load item with register reg. Assumes that reg is properly allocated
   *
   * @param ec current emitter context
   * @param reg register to load the item to
   */
  final void loadTo(EmitterContext ec, X86Register.GPR reg) {
    if (VmUtils.verifyAssertions()) VmUtils._assert(reg != null, "Reg != null");
    final X86Assembler os = ec.getStream();
    final X86RegisterPool pool = ec.getGPRPool();
    final VirtualStack stack = ec.getVStack();
    final X86CompilerHelper helper = ec.getHelper();
    if (VmUtils.verifyAssertions()) {
      VmUtils._assert(!pool.isFree(reg), "reg not free");
    }

    switch (getKind()) {
      case Kind.GPR:
        if (this.gpr != reg) {
          os.writeMOV(reg.getSize(), reg, this.gpr);
          cleanup(ec);
        }
        break;

      case Kind.LOCAL:
        os.writeMOV(reg.getSize(), reg, helper.BP, getOffsetToFP(ec));
        break;

      case Kind.CONSTANT:
        loadToConstant(ec, os, reg);
        break;

      case Kind.FPUSTACK:
        // Make sure this item is on top of the FPU stack
        FPUHelper.fxch(os, stack.fpuStack, this);
        stack.fpuStack.pop(this);
        // Convert & move to new space on normal stack
        os.writeLEA(helper.SP, helper.SP, -helper.SLOTSIZE);
        popFromFPU(os, helper.SP, 0);
        os.writePOP(reg);
        break;

      case Kind.STACK:
        // TODO: make sure 'this' is on top of stack
        // TODO: implemen it for 64 bits
        if (!stack.operandStack.isTos(this)) {

          int stack_loc = stack.operandStack.stackLocation(this);
          if (stack_loc < 0) throw new StackException("Item not found on stack");

          stack.operandStack.makeTop(stack_loc);

          // todo test it
          os.writeMOV(
              org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32,
              reg,
              helper.SP,
              helper.SLOTSIZE);
          os.writeXCHG(
              helper.SP, org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32 * stack_loc, reg);
          os.writeMOV(
              org.jnode.vm.x86.compiler.X86CompilerConstants.BITS32,
              helper.SP,
              helper.SLOTSIZE,
              reg);
        }

        if (VirtualStack.checkOperandStack) {
          stack.operandStack.pop(this);
        }
        os.writePOP(reg);
        break;

      default:
        throw new IllegalArgumentException("Invalid item kind");
    }
    setKind(Kind.GPR);
    this.gpr = reg;
  }