summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-02-14 01:35:18 -0500
committerKyle Gunger <kgunger12@gmail.com>2024-02-14 01:35:18 -0500
commit8e1237686fb9e03bf3cb9a4289809f2179ff18c7 (patch)
treefcfbc4fec69f01578afa376dcf7ec371e85a4a2e
parent685e0eacd830127188610551e84de88d6d3c79dc (diff)
mul
-rw-r--r--compiler.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/compiler.c b/compiler.c
index 115f445..1e72cd4 100644
--- a/compiler.c
+++ b/compiler.c
@@ -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");
}
}