diff options
-rw-r--r-- | compiler.c | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -1057,7 +1057,7 @@ void _var_op_set_ptr(CompData *out, Variable *store, Variable *from) { char *_var_get_store(CompData *out, Variable *store) { if (_var_ptr_type(store) == PTYPE_REF){ vect_push_string(&out->text, "\tmov rdi, "); - vect_push_free_string(&out->text, _op_get_location(store)); + addvect_push_free_string(&out->text, _op_get_location(store)); vect_push_string(&out->text, " ; pre-deref for inbuilt mov (store)\n"); for(size_t i = store->ptr_chain.count - 1; i > 0; i--){ @@ -1489,8 +1489,48 @@ void var_op_mul(CompData *out, Variable *base, Variable *mul) { if(base->type->name[0] == 'i') { // Integer multiplication + if (base->location > 0 && mul->location != LOC_LITL) { + vect_push_string(&out->text, "\timul "); + vect_push_free_string(&out->text, _var_get_store(out, base)); + vect_push_string(&out->text, ", "); + vect_push_free_string(&out->text, _var_get_from(out, base, mul)); + vect_push_string(&out->text, "; complete mul\n\n"); + } else { + // Mov to rax for the multiplication, move back after. + vect_push_string(&out->text, "\tmov "); + vect_push_free_string(&out->text, _op_get_register(1, _var_size(base))); + vect_push_string(&out->text, ", "); + vect_push_free_string(&out->text, _var_get_store(out, base)); + vect_push_string(&out->text, "; pre-mul mov\n"); + + vect_push_string(&out->text, "\timul "); + vect_push_free_string(&out->text, _var_get_from(out, base, mul)); + vect_push_string(&out->text, "; mul\n"); + + // move back after mul + vect_push_string(&out->text, "\tmov "); + vect_push_free_string(&out->text, _var_get_store(out, base)); + vect_push_string(&out->text, ", "); + vect_push_free_string(&out->text, _op_get_register(1, _var_size(base))); + vect_push_string(&out->text, "; post-mul mov\n"); + } } else { + vect_push_string(&out->text, "\tmov "); + vect_push_free_string(&out->text, _op_get_register(1, _var_size(base))); + vect_push_string(&out->text, ", "); + vect_push_free_string(&out->text, _var_get_store(out, base)); + vect_push_string(&out->text, "; pre-mul mov\n"); + vect_push_string(&out->text, "\tmul "); + vect_push_free_string(&out->text, _var_get_from(out, base, mul)); + vect_push_string(&out->text, "; mul\n"); + + // move back after mul + vect_push_string(&out->text, "\tmov "); + vect_push_free_string(&out->text, _var_get_store(out, base)); + vect_push_string(&out->text, ", "); + vect_push_free_string(&out->text, _op_get_register(1, _var_size(base))); + vect_push_string(&out->text, "; post-mul mov\n"); } } |