Beispiel #1
0
/*
 *   Allocate a temporary register.    Returns the next register
 *   that will be allocated.
 */
static REG allocate_register P2 (REG, reg, REGTYPE, kind)
{
    if (reg_in_use[reg] != UNUSED) {
        /*
         *   The next available register is already in use.
         *   It (and any associated registers) must be pushed.
         */
        REG     r;
        REGMASK rmask = associated_regs[reg];

        for (r = 0; r < NUM_REGS; r++) {
            if (rmask & REGBIT (r)) {
                g_push (r, reg_in_use[r]);
                reg_in_use[r] = UNUSED;
            }
        }
    }
    reg_in_use[reg] = alloc_depth;
    associated_regs[reg] = REGBIT (reg);
    reg_alloc[alloc_depth].reg = reg;
    reg_alloc[alloc_depth].pushed = FALSE;

    if (alloc_depth++ == MAX_REG_STACK) {
        FATAL ((__FILE__, "allocate_register", "register stack overflow"));
    }
    return next_reg (reg, kind);
}
Beispiel #2
0
/*
 *   This routine should be called before each expression is
 *   evaluated to make sure the stack is balanced and all of
 *   the registers are marked free.
 *
 *   This is also a good place to free all 'pseudo' registers
 *   in the stack frame by setting act_scratch to zero.
 */
void initstack P0 (void)
{
    REG     reg;

    start_data = next_data = next_reg (D7, D_REG);
    start_addr = next_addr = next_reg (A7, A_REG);
#ifdef FLOAT_IEEE
    start_float = next_float = next_reg (FP7, F_REG);
#endif /* FLOAT_IEEE */
    for (reg = D0; reg <= MAX_REG; reg++) {
        reg_in_use[reg] = UNUSED;
        associated_regs[reg] = (REGMASK) 0;
    }
    stack_depth = EMPTY;
    alloc_depth = EMPTY;
    act_scratch = 0L;
}
void* CodeGenerator_macho32_ubu::visit(StrExpression *exp) {
  const char *reg = next_reg();
  len += sprintf(code+len, "mov %s,%d\n", reg, 911);

  CodeReturn *c = new CodeReturn(0, EXPRESSION_STR_PROD);
  strcpy(c->tmp, reg);
  return c;
}
void* CodeGenerator_macho32_ubu::visit(OperationExpression *exp) {
  CodeReturn *c1 = (CodeReturn*)exp->exp1->accept(this);
  CodeReturn *c2 = (CodeReturn*)exp->op->accept(this);
  CodeReturn *c3 = (CodeReturn*)exp->exp2->accept(this);

  const char *reg = next_reg();

  if(c2->type == OPERATION_PLUS_PROD) {
    len += sprintf(code+len, "mov %s,%s\n"
                             "add %s,%s\n", reg, c1->tmp, reg, c3->tmp);
  }
  else if(c2->type == OPERATION_MINUS_PROD) {
    len += sprintf(code+len, "mov %s,%s\n"
                             "sub %s,%s\n", reg, c1->tmp, reg, c3->tmp);
  }
  else if(c2->type == OPERATION_DIV_PROD) {
    len += sprintf(code+len, "push eax\n"
                             "push edx\n"
                             "mov eax,%s\n"
                             "div dword %s\n"
                             "push %s\n"
                             "add esp,4\n"
                             "pop edx\n"
                             "pop eax\n"
                             "mov %s,[esp-12]\n", c1->tmp, c3->tmp, c1->tmp, reg);
  }
  else if (c2->type == OPERATION_MULT_PROD) {
    len += sprintf(code+len, "push eax\n"
                             "push edx\n"
                             "mov eax,%s\n"
                             "mul dword %s\n"
                             "push %s\n"
                             "add esp,4\n"
                             "pop edx\n"
                             "pop eax\n"
                             "mov %s,[esp-12]\n", c1->tmp, c3->tmp, c1->tmp, reg);
  }

  release_reg(c1->tmp);
  release_reg(c3->tmp);

  CodeReturn *c = new CodeReturn(0, EXPRESSION_OPR_PROD);
  strcpy(c->tmp, reg);
  return c;
}