Package compiler.frames

Examples of compiler.frames.Temp


    }
    /** NAME */
    else if (expr instanceof ImcNAME)
    {
      // Name as an expression, load label
      Temp val = new Temp();
     
      LinkedList<Temp> defs = new LinkedList<Temp>();
      defs.add(val);
     
      LinkedList<Label> lbls = new LinkedList<Label>();
      lbls.add(((ImcNAME)expr).label);
     
      instructions.add(new AsmOPER("ldr `d0, =" + lbls.get(0).name(), defs, new LinkedList<Temp>(), lbls));
     
      return val;
    }
    else
    {
      System.err.println(" -- " + expr.getClass().toString());
    }
   
    return new Temp();
  };
View Full Code Here


        instructions.add(new AsmOPER("ldr `d0, =" + constValue, def, new LinkedList<Temp>()));
      }
    }
    else if (move.dst instanceof ImcTEMP && move.src instanceof ImcExpr)
    {
      Temp val = munch(move.src);
      instructions.add(new AsmMOVE("mov `d0, [`s0]", ((ImcTEMP)move.dst).temp, val));
    }
    // STR
    else if (move.dst instanceof ImcMEM)
    {
      Temp value = munch((ImcExpr)move.src);
      ImcMEM mem = (ImcMEM)move.dst;
     
      // Check if it's a label or a register with offset
     
      // NAME
      if (mem.expr instanceof ImcNAME)
      {
        LinkedList<Temp> src = new LinkedList<Temp>();
        src.add(value);
       
        instructions.add(new AsmOPER("str `s0, =" + ((ImcNAME)mem.expr).label.name(), new LinkedList<Temp>(), src));
      }
      else if (mem.expr instanceof ImcBINOP && ((ImcBINOP)mem.expr).rimc instanceof ImcCONST)
      {
        LinkedList<Temp> src = new LinkedList<Temp>();
        src.add(value);
        src.add(munch(((ImcBINOP)mem.expr).limc));
       
        int offset = ((ImcCONST)((ImcBINOP)mem.expr).rimc).value;
       
        instructions.add(new AsmOPER("str `s0, [`s1, #" + offset + "]", new LinkedList<Temp>(), src));
      }
      // Address that evaluates
      else if (((ImcBINOP)mem.expr).rimc instanceof ImcCONST)
      {
        Temp addr = munch((ImcExpr)mem.expr);
       
        LinkedList<Temp> src = new LinkedList<Temp>();
        src.add(addr);
        src.add(munch(((ImcBINOP)mem.expr).limc));
       
View Full Code Here

  /**
   * Munch CJUMP
   */
  private void munch(ImcCJUMP jump)
  {
    Temp conditionResult = munch(jump.cond);
   
    LinkedList<Temp> src = new LinkedList<Temp>();
    src.add(conditionResult);
   
    // Test if condition is true
View Full Code Here

    instructions.add(new AsmOPER("str `s0, [sp]", new LinkedList<Temp>(), uses));
    addComment("Store arguments");
    int offset = 4;
    for (ImcExpr arg : call.args)
    {
      Temp val = munch(arg);
     
      // Store on stack (r14 is stack pointer) and increment it (!)
      LinkedList<Temp> src = new LinkedList<Temp>();
      src.add(val);

      instructions.add(new AsmOPER("str `s0, [sp, #" + offset + "]", new LinkedList<Temp>(), src));
     
      offset += 4;
    }
   
    // JUMP
    LinkedList<Label> lbls = new LinkedList<Label>();
    lbls.add(call.label);
   
    // Store registers
    instructions.add(new AsmOPER("b " + call.label.name(), new LinkedList<Temp>(), new LinkedList<Temp>(), lbls));
   
    return new Temp();
  }
View Full Code Here

      case ImcBINOP.OR:
        return munchLogical(binop);
   
      default:
        System.err.println("Unimplemented BINOP operation " + binop.op);
        return new Temp();
    }
  }
View Full Code Here

   * Munch CONST
   */
  private Temp munch(ImcCONST constant)
  {
    // Load constant to a register and return it
    Temp constreg = new Temp();
    int val = constant.value;
   
    LinkedList<Temp> dst = new LinkedList<Temp>();
    dst.add(constreg);
   
View Full Code Here

   * Munch MEM
   */
  private Temp munch(ImcMEM mem)
  {
    // Create LDR command depending on the parameters
    Temp dest = new Temp();
   
    LinkedList<Temp> defs = new LinkedList<Temp>();
    defs.add(dest);
   
    if (mem.expr instanceof ImcNAME)
    {
      Label label = ((ImcNAME)mem.expr).label;
     
      LinkedList<Label> lbls = new LinkedList<Label>();
      lbls.add(label);
     
      instructions.add(new AsmOPER("ldr `d0, =" + label.name(), defs, new LinkedList<Temp>(), lbls));
    }
    else if (mem.expr instanceof ImcBINOP && ((ImcBINOP)mem.expr).rimc instanceof ImcCONST)
    {
      Temp left = munch(((ImcBINOP)mem.expr).limc);
      LinkedList<Temp> src = new LinkedList<Temp>();
      src.add(left);
     
      int offset = ((ImcCONST)((ImcBINOP)mem.expr).rimc).value;
     
      instructions.add(new AsmOPER("ldr `d0, [`s0, #" + offset + "]", defs, src));
    }
    else
    {
      Temp addr = munch(mem.expr);
     
      LinkedList<Temp> src = new LinkedList<Temp>();
      src.add(addr);
     
      instructions.add(new AsmOPER("ldr, `d0, [`s0]", defs, src));
View Full Code Here

          result = val1 / val2;
          break;
      }
     
      LinkedList<Temp> def = new LinkedList<Temp>();
      def.add(new Temp());
     
      if (result < 4096)
      {
        instructions.add(new AsmOPER("mov `d0, #" + result, def, new LinkedList<Temp>()));
      }
      else
      {
        instructions.add(new AsmOPER("ldr `d0, =" + result, def, new LinkedList<Temp>()));
      }
     
      return def.getFirst();
    }
    // Check for immediate values
    else
    {
      String command = "";
     
      // Evaulate left and right sides
      Temp val1 = munch((ImcExpr)binop.limc);
      Temp val2 = munch((ImcExpr)binop.rimc);
     
      switch(binop.op)
      {
        case ImcBINOP.ADD:
          command = "add";
          break;
        case ImcBINOP.SUB:
          command = "sub";
          break;
        case ImcBINOP.MUL:
          command = "mul";
          break;
        case ImcBINOP.DIV:
          return inlineDivAlgorithm(val1, val2);         
      }
     
      Temp result = new Temp();
     
      LinkedList<Temp> defs = new LinkedList<Temp>();
      defs.add(result);
     
      LinkedList<Temp> srcs = new LinkedList<Temp>();
View Full Code Here

  private Temp inlineDivAlgorithm(Temp val1, Temp val2)
  {
    LinkedList<Temp> uses = new LinkedList<Temp>();
    LinkedList<Temp> defs = new LinkedList<Temp>();
   
    Temp result = new Temp();
    defs.add(result);
   
    Temp tmp = new Temp();
   
    // Clear result register for accumulation
    // MOV R0, #0
    instructions.add(new AsmOPER("mov `d0, #0", defs, new LinkedList<Temp>()));
   
View Full Code Here

    return result;
  }
 
  private Temp munchLogical(ImcBINOP binop)
  {
    Temp result = new Temp();
    LinkedList<Temp> dst = new LinkedList<Temp>();
    dst.add(result);
   
    Temp left = munch(binop.limc);
    Temp right = munch(binop.rimc);
   
    LinkedList<Temp> src = new LinkedList<Temp>();
    src.add(left);
    src.add(right);
   
View Full Code Here

TOP

Related Classes of compiler.frames.Temp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.