summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2024-02-07 19:05:20 -0500
committerKyle Gunger <kgunger12@gmail.com>2024-02-07 19:05:20 -0500
commitf6d8a2ca424714560000317af4d59302fdb404e0 (patch)
treeb2d8a90d180e57e271afa5d35de0f552dd28d64d
parent56c9e4b84fd91502d63748d435230a4be889fd3c (diff)
finish inbuilt mov
-rw-r--r--compiler.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/compiler.c b/compiler.c
index 73a881c..7e7d1e4 100644
--- a/compiler.c
+++ b/compiler.c
@@ -1013,12 +1013,12 @@ void _var_op_set_inbuilt(CompData *out, Variable *store, Variable *from) {
if (_var_ptr_type(store) == PTYPE_REF){
vect_push_string(&out->text, "\tmov rdi, ");
vect_push_free_string(&out->text, _op_get_location(store));
- vect_push_string(&out->text, " ; pre-deref for inbuilt mov\n");
+ vect_push_string(&out->text, " ; pre-deref for inbuilt mov (store)\n");
for(size_t i = store->ptr_chain.count - 1; i > 0; i--){
int *cur = vect_get(&store->ptr_chain, i);
if (cur == PTYPE_REF) {
- vect_push_string(&out->text, "\tmov rsi, [rsi] ; deref for mov\n");
+ vect_push_string(&out->text, "\tmov rdi, [rdi] ; deref for mov\n");
} else
break; // Should not happen
}
@@ -1033,10 +1033,49 @@ void _var_op_set_inbuilt(CompData *out, Variable *store, Variable *from) {
}
// TODO: Get mov_from for this func
+ if (_var_ptr_type(from) == PTYPE_REF) {
+ vect_push_string(&out->text, "\tmov rsi, ");
+ vect_push_free_string(&out->text, _op_get_location(from));
+ vect_push_string(&out->text, " ; pre-deref for inbuilt mov (from)\n");
+ for(size_t i = store->ptr_chain.count - 1; i > 0; i--){
+ int *cur = vect_get(&store->ptr_chain, i);
+ if (cur == PTYPE_REF) {
+ vect_push_string(&out->text, "\tmov rsi, [rsi] ; deref for mov\n");
+ } else
+ break; // Should not happen
+ }
+ // Final deref (store actual value in rsi)
+ vect_push_string(&out->text, "\tmov ");
+ vect_push_free_string(&out->text, _op_get_register(5, _var_size(from)));
+ vect_push_string(&out->text, ", ");
+ vect_push_string(&out->text, PREFIXES[_var_size(from)]);
+ vect_push_string(&out->text, "[rsi] ; pre-deref for inbuilt mov (from)\n");
+
+ mov_from = _op_get_register(5, _var_size(from));
+
+ } else if (from->location > 0) {
+ mov_from = _op_get_register(from->location, _var_size(from));
+
+ } else if (store->location < 1 || _var_ptr_type(store) == PTYPE_REF) {
+ vect_push_string(&out->text, "\tmov ");
+ vect_push_free_string(&out->text, _op_get_register(5, _var_size(from)));
+ vect_push_string(&out->text, ", ");
+ vect_push_string(&out->text, _op_get_location(from));
+ vect_push_string(&out->text, " ; pre-load for mov (from)\n");
+
+ mov_from = _op_get_register(5, _var_size(from));
+ } else if (from->location == 0) {
+ // from in data sec
+ mov_from = _gen_address(PREFIXES[_var_size(from) - 1], from->name, "", 0, 0);
+ } else {
+ // from on stack
+ mov_from = _gen_address(PREFIXES[_var_size(from) - 1], "rsp", "", 0, -(from->location + 1));
+ }
// Match sign of data if required.
if (_var_size(from) < _var_size(store)) {
+ // Store larger than from (extend sign)
if(from->type->name[0] == 'i' && store->type->name[0] == 'i') {
if (_var_size(from) < 4)
vect_push_string(&out->text, "\tmovsx rsi, ");
@@ -1051,6 +1090,13 @@ void _var_op_set_inbuilt(CompData *out, Variable *store, Variable *from) {
vect_push_free_string(&out->text, mov_from);
vect_push_string(&out->text, " ; Sign extension for mov\n");
mov_from = _op_get_register(5, _var_size(store));
+ } else if (_var_size(from) > _var_size(store)) {
+ // Store smaller than from (recompute mov_from)
+ if (_var_ptr_type(from) == PTYPE_REF) {
+ } else if (from->location > 0) {
+ free(mov_from);
+ mov_from = _op_get_register(from->location, _var_size(store));
+ }
}
vect_push_string(&out->text, "\tmov ");