summaryrefslogtreecommitdiff
path: root/compiler.c
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-02-14 01:42:47 -0500
committerKyle Gunger <kgunger12@gmail.com>2024-02-14 01:42:47 -0500
commit34d333e387216b38ed00b23ee9560426ac66534a (patch)
treecbab8be424d87eba41624674fa4f645d75e0838e /compiler.c
parent8e1237686fb9e03bf3cb9a4289809f2179ff18c7 (diff)
mul fix literal
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/compiler.c b/compiler.c
index 1e72cd4..3535ba1 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, ");
- addvect_push_free_string(&out->text, _op_get_location(store));
+ vect_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--){
@@ -1495,6 +1495,16 @@ void var_op_mul(CompData *out, Variable *base, Variable *mul) {
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 if (base->location > 0) {
+ vect_push_string(&out->text, "\tmov rcx, ");
+ vect_push_free_string(&out->text, int_to_str(mul->offset));
+ vect_push_string(&out->text, "; literal load\n");
+
+ 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, _op_get_register(3, _var_size(base)));
+ 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 ");
@@ -1503,9 +1513,19 @@ void var_op_mul(CompData *out, Variable *base, Variable *mul) {
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");
+ if (mul->location == LOC_LITL) {
+ vect_push_string(&out->text, "\tmov rcx, ");
+ vect_push_free_string(&out->text, int_to_str(mul->offset));
+ vect_push_string(&out->text, "; literal load\n");
+
+ vect_push_string(&out->text, "\timul ");
+ vect_push_free_string(&out->text, _op_get_register(3, _var_size(base)));
+ vect_push_string(&out->text, "; mul\n");
+ } else {
+ 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 ");
@@ -1521,9 +1541,19 @@ void var_op_mul(CompData *out, Variable *base, Variable *mul) {
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");
+ if (mul->location == LOC_LITL) {
+ vect_push_string(&out->text, "\tmov rcx, ");
+ vect_push_free_string(&out->text, int_to_str(mul->offset));
+ vect_push_string(&out->text, "; literal load\n");
+
+ vect_push_string(&out->text, "\tmul ");
+ vect_push_free_string(&out->text, _op_get_register(3, _var_size(base)));
+ vect_push_string(&out->text, "; mul\n");
+ } else {
+ 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 ");