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;
}
void* CodeGenerator_macho32_ubu::visit(PrintStatement *stm) {
  CodeReturn *c = (CodeReturn*)stm->exp->accept(this);

  len += sprintf(code+len, "push dword %s\n", c->tmp);
  len += sprintf(code+len, "call putint\n");

  release_reg(c->tmp);

  return new CodeReturn(0, STATEMENT_HUCK_PROD);
}
void* CodeGenerator_macho32_ubu::visit(AssignStatement *stm) {
  CodeReturn *c1 = (CodeReturn*)stm->id->accept(this);
  CodeReturn *c2 = (CodeReturn*)stm->exp->accept(this);

  len += sprintf(code+len, "mov %s,%s\n", c1->tmp, c2->tmp);

  release_reg(c2->tmp);

  return new CodeReturn(0, STATEMENT_ASGN_PROD);
}
Beispiel #4
0
void REG_FREE(reg_t *reg, unsigned long barrier) {
    if (reg && reg->type==REG_ALLOCATED && reg->die->id == barrier) { release_reg(reg->physical); }
}