From 6d120c1ac8b90a2041700930eca81fee71468d76 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Wed, 1 Sep 2021 16:42:24 -0400 Subject: [PATCH] fix self issue (#808) --- decompiler/IR2/FormExpressionAnalysis.cpp | 32 +------- decompiler/util/data_decompile.cpp | 6 +- goal_src/levels/beach/beach-rocks.gc | 64 +++------------ goal_src/levels/common/nav-enemy.gc | 15 ++-- .../reference/engine/load/loader_REF.gc | 80 +++---------------- .../reference/levels/beach/beach-rocks_REF.gc | 62 +++----------- .../reference/levels/common/nav-enemy_REF.gc | 15 ++-- 7 files changed, 54 insertions(+), 220 deletions(-) diff --git a/decompiler/IR2/FormExpressionAnalysis.cpp b/decompiler/IR2/FormExpressionAnalysis.cpp index 6e683a2eee..5e8824a2dc 100644 --- a/decompiler/IR2/FormExpressionAnalysis.cpp +++ b/decompiler/IR2/FormExpressionAnalysis.cpp @@ -2146,13 +2146,6 @@ void SetVarElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta return; } - // bool skip = false; - // auto dst_type = env.get_variable_type(m_dst, false); - // auto as_bitfield = dynamic_cast(env.dts->ts.lookup_type(dst_type)); - // if (as_bitfield && as_bitfield->get_load_size() == 16) { - // skip = true; - // } - // if we are a reg-reg move that consumes the original, push it without popping from stack. // it is the Stack's responsibility to untangle these later on. if (m_src->is_single_element()) { @@ -2168,7 +2161,8 @@ void SetVarElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta auto var = src_as_se->expr().get_arg(0).var(); auto& info = env.reg_use().op.at(var.idx()); - if (info.consumes.find(var.reg()) != info.consumes.end()) { + if (var.reg() == Register(Reg::GPR, Reg::S6) || + info.consumes.find(var.reg()) != info.consumes.end()) { stack.push_non_seq_reg_to_reg(m_dst, src_as_se->expr().get_arg(0).var(), m_src, m_src_type, m_var_info); return; @@ -2180,28 +2174,6 @@ void SetVarElement::push_to_stack(const Env& env, FormPool& pool, FormStack& sta // we aren't a reg-reg move, so update our source m_src->update_children_from_stack(env, pool, stack, true); - /* - auto src_as_bf_set = dynamic_cast(m_src->try_as_single_element()); - if (src_as_bf_set && !src_as_bf_set->from_pcpyud() && src_as_bf_set->mods().size() == 1) { - auto dst_form = m_dst.to_form(env, RegisterAccess::Print::AS_VARIABLE_NO_CAST); - auto src_form = src_as_bf_set->base()->to_form(env); - if (dst_form == src_form) { - // success! - auto value = src_as_bf_set->mods().at(0).value; - value->parent_element = this; - - // make the (-> thing bitfield) - auto field_token = DerefToken::make_field_name(src_as_bf_set->mods().at(0).field_name); - auto dst_dform = pool.alloc_single_element_form(nullptr, - SimpleAtom::make_var(m_dst)); auto loc_elt = pool.alloc_element(dst_dform, false, - field_token); loc_elt->inline_nested(); auto loc = pool.alloc_single_form(nullptr, loc_elt); auto - new_form_el = pool.alloc_element(loc, value); - stack.push_form_element(new_form_el, true); - return; - } - } - */ - for (auto x : m_src->elts()) { assert(x->parent_form == m_src); } diff --git a/decompiler/util/data_decompile.cpp b/decompiler/util/data_decompile.cpp index 05a1492420..a041ea7f5b 100644 --- a/decompiler/util/data_decompile.cpp +++ b/decompiler/util/data_decompile.cpp @@ -330,7 +330,7 @@ goos::Object decomp_ref_to_inline_array_guess_size( const LinkedObjectFile* file, const TypeSpec& array_elt_type, int stride) { - fmt::print("Decomp decomp_ref_to_inline_array_guess_size {}\n", array_elt_type.print()); + // fmt::print("Decomp decomp_ref_to_inline_array_guess_size {}\n", array_elt_type.print()); // verify that the field is the right type. assert(data_field.type() == TypeSpec("inline-array", {array_elt_type})); @@ -353,13 +353,13 @@ goos::Object decomp_ref_to_inline_array_guess_size( index_of_closest_following_label_in_segment(start_label.offset, my_seg, labels); assert(end_label_idx >= 0); const auto& end_label = labels.at(end_label_idx); - fmt::print("Data is from {} to {}\n", start_label.name, end_label.name); + // fmt::print("Data is from {} to {}\n", start_label.name, end_label.name); // now we can figure out the size int size_bytes = end_label.offset - start_label.offset; int size_elts = size_bytes / stride; // 32 bytes per ocean-near-index int leftover_bytes = size_bytes % stride; - fmt::print("Size is {} bytes: {} elts, {} left over\n", size_bytes, size_elts, leftover_bytes); + // fmt::print("Size is {} bytes: {} elts, {} left over\n", size_bytes, size_elts, leftover_bytes); // if we have leftover, should verify that its all zeros, or that it's the type pointer // of the next basic in the data section. diff --git a/goal_src/levels/beach/beach-rocks.gc b/goal_src/levels/beach/beach-rocks.gc index 1ac92f7ff4..a13be9f0af 100644 --- a/goal_src/levels/beach/beach-rocks.gc +++ b/goal_src/levels/beach/beach-rocks.gc @@ -1241,14 +1241,7 @@ :code (behavior () (while #t - (let* ((a0-0 *art-control*) - (t9-0 (method-of-object a0-0 spool-push)) - (a1-0 "lrocklrg-falling") - (a2-0 0) - (t0-0 -1.0) - ) - (t9-0 a0-0 a1-0 a2-0 self t0-0) - ) + (spool-push *art-control* "lrocklrg-falling" 0 self -1.0) (suspend) ) (none) @@ -1309,14 +1302,7 @@ (behavior () (local-vars (v1-3 symbol) (v1-49 symbol)) (until v1-3 - (let* ((a0-0 *art-control*) - (t9-0 (method-of-object a0-0 spool-push)) - (a1-0 "lrocklrg-falling") - (a2-0 0) - (t0-0 -1.0) - ) - (t9-0 a0-0 a1-0 a2-0 self t0-0) - ) + (spool-push *art-control* "lrocklrg-falling" 0 self -1.0) (suspend) (set! v1-3 (or (not *target*) (process-grab? *target*))) ) @@ -1333,16 +1319,12 @@ (let* ((gp-1 (get-process *default-dead-pool* othercam #x4000)) (gp-2 (ppointer->handle (when gp-1 (let - ((t9-5 (method-of-type othercam activate)) - (a0-8 gp-1) - (a2-3 'othercam) - (a3-1 #x70004000) - ) + ((t9-5 (method-of-type othercam activate))) (t9-5 - (the-as othercam a0-8) + (the-as othercam gp-1) self - a2-3 - (the-as pointer a3-1) + 'othercam + (the-as pointer #x70004000) ) ) (let @@ -1373,16 +1355,12 @@ (s5-0 (get-process *default-dead-pool* fuel-cell #x4000)) (s5-1 (ppointer->handle (when s5-0 (let - ((t9-8 (method-of-type fuel-cell activate)) - (a0-14 s5-0) - (a2-6 'fuel-cell) - (a3-3 #x70004000) - ) + ((t9-8 (method-of-type fuel-cell activate))) (t9-8 - (the-as fuel-cell a0-14) + (the-as fuel-cell s5-0) self - a2-6 - (the-as pointer a3-3) + 'fuel-cell + (the-as pointer #x70004000) ) ) ((the-as @@ -1404,14 +1382,7 @@ (task-status need-reminder) ) (set! (-> self movie-start) (the-as uint (-> *display* base-frame-counter))) - (let* ((a0-20 *art-control*) - (t9-11 (method-of-object a0-20 spool-push)) - (a1-9 "lrocklrg-falling") - (a2-11 0) - (t0-2 -1.0) - ) - (t9-11 a0-20 a1-9 a2-11 self t0-2) - ) + (spool-push *art-control* "lrocklrg-falling" 0 self -1.0) (ja-play-spooled-anim (new 'static 'spool-anim :name "lrocklrg-falling" @@ -1430,12 +1401,7 @@ (the-as art-joint-anim (-> self draw art-group data 3)) (the-as (function process-drawable symbol) false-func) ) - (let ((t9-13 process-entity-status!) - (a1-11 64) - (a2-13 #t) - ) - (t9-13 self (the-as entity-perm-status a1-11) a2-13) - ) + (process-entity-status! self (entity-perm-status complete) #t) (cond ((handle->process gp-2) (deactivate (-> gp-2 process 0)) @@ -1601,8 +1567,4 @@ (dummy-14 obj *lrocklrg-sg* '()) ((method-of-type beach-rock copy-defaults!) obj arg0) (none) - ) - - - - + ) \ No newline at end of file diff --git a/goal_src/levels/common/nav-enemy.gc b/goal_src/levels/common/nav-enemy.gc index 99d8fd6a47..6e957a783c 100644 --- a/goal_src/levels/common/nav-enemy.gc +++ b/goal_src/levels/common/nav-enemy.gc @@ -2381,14 +2381,13 @@ nav-enemy-default-event-handler (process-entity-status! self (entity-perm-status complete) #t) (when (not (task-complete? *game-info* (-> self entity extra perm task))) (label cfg-1) - (let ((t9-5 birth-pickup-at-point) - (a0-4 (-> self collide-info trans)) - (a1-2 6) - (a2-1 (the float (the-as int (-> self entity extra perm task)))) - (a3-0 #f) - (t1-0 #f) - ) - (t9-5 a0-4 a1-2 a2-1 a3-0 self t1-0) + (birth-pickup-at-point + (-> self collide-info trans) + 6 + (the float (the-as int (-> self entity extra perm task))) + #f + self + #f ) (when (not (-> self child)) (suspend) diff --git a/test/decompiler/reference/engine/load/loader_REF.gc b/test/decompiler/reference/engine/load/loader_REF.gc index 275df28c9e..355954d0f9 100644 --- a/test/decompiler/reference/engine/load/loader_REF.gc +++ b/test/decompiler/reference/engine/load/loader_REF.gc @@ -1124,14 +1124,7 @@ (if (arg3 self) (goto cfg-88) ) - (let* ((a0-16 *art-control*) - (t9-11 (method-of-object a0-16 spool-push)) - (a1-8 (-> arg0 name)) - (a2-4 spool-part) - (t0-1 -9.0) - ) - (t9-11 a0-16 a1-8 a2-4 self t0-1) - ) + (spool-push *art-control* (-> arg0 name) spool-part self -9.0) (suspend) (when arg1 (let ((a0-17 (-> self skel root-channel 0))) @@ -1156,23 +1149,9 @@ ) (set! sv-48 (-> *display* base-frame-counter)) (while (< spool-part (-> arg0 parts)) - (let* ((a0-27 *art-control*) - (t9-13 (method-of-object a0-27 spool-push)) - (a1-11 (-> arg0 name)) - (a2-6 spool-part) - (t0-2 -20.0) - ) - (t9-13 a0-27 a1-11 a2-6 self t0-2) - ) + (spool-push *art-control* (-> arg0 name) spool-part self -20.0) (update *art-control* #f) - (let* ((a0-29 *art-control*) - (t9-15 (method-of-object a0-29 spool-push)) - (a1-13 (-> arg0 name)) - (a2-7 spool-part) - (t0-3 -20.0) - ) - (t9-15 a0-29 a1-13 a2-7 self t0-3) - ) + (spool-push *art-control* (-> arg0 name) spool-part self -20.0) (when (!= (file-status *art-control* (-> arg0 name) spool-part) 'active) (cond (arg1 @@ -1196,14 +1175,7 @@ (if (arg3 self) (goto cfg-88) ) - (let* ((a0-35 *art-control*) - (t9-21 (method-of-object a0-35 spool-push)) - (a1-16 (-> arg0 name)) - (a2-10 spool-part) - (t0-4 -20.0) - ) - (t9-21 a0-35 a1-16 a2-10 self t0-4) - ) + (spool-push *art-control* (-> arg0 name) spool-part self -20.0) (format #t "WARNING: ---------------------> loader stall on art ~S ~D~%" @@ -1223,14 +1195,7 @@ ) ) ) - (let* ((a0-39 *art-control*) - (t9-25 (method-of-object a0-39 spool-push)) - (a1-20 (-> arg0 name)) - (a2-14 spool-part) - (t0-5 -20.0) - ) - (t9-25 a0-39 a1-20 a2-14 self t0-5) - ) + (spool-push *art-control* (-> arg0 name) spool-part self -20.0) (let ((s2-4 (the-as @@ -1275,28 +1240,10 @@ ) (goto cfg-88) ) - (let* ((a0-55 *art-control*) - (t9-32 (method-of-object a0-55 spool-push)) - (a1-24 (-> arg0 name)) - (a2-17 spool-part) - (t0-6 -20.0) - ) - (t9-32 a0-55 a1-24 a2-17 self t0-6) - ) - (cond - ((< (+ spool-part 1) (-> arg0 parts)) - (let* ((a0-57 *art-control*) - (t9-33 (method-of-object a0-57 spool-push)) - (a1-25 (-> arg0 name)) - (a2-18 (+ spool-part 1)) - (t0-7 -10.0) - ) - (t9-33 a0-57 a1-25 a2-18 self t0-7) - ) - ) - (else - (set! (-> self skel status) (logand -5 (-> self skel status))) - ) + (spool-push *art-control* (-> arg0 name) spool-part self -20.0) + (if (< (+ spool-part 1) (-> arg0 parts)) + (spool-push *art-control* (-> arg0 name) (+ spool-part 1) self -10.0) + (set! (-> self skel status) (logand -5 (-> self skel status))) ) (dummy-16 *load-state* (ja-aframe-num 0)) (cond @@ -1380,14 +1327,7 @@ (ja-channel-push! 1 30) (set! (-> self skel root-channel 0 frame-group) arg1) (while (!= (-> self skel root-channel 0) (-> self skel channel)) - (let* ((a0-11 *art-control*) - (t9-4 (method-of-object a0-11 spool-push)) - (a1-3 (-> arg0 name)) - (a2-2 arg2) - (t0-0 -20.0) - ) - (t9-4 a0-11 a1-3 a2-2 self t0-0) - ) + (spool-push *art-control* (-> arg0 name) arg2 self -20.0) (suspend) (let ((a0-12 (-> self skel root-channel 0))) (set! diff --git a/test/decompiler/reference/levels/beach/beach-rocks_REF.gc b/test/decompiler/reference/levels/beach/beach-rocks_REF.gc index 3719562cdd..9f6b788eb4 100644 --- a/test/decompiler/reference/levels/beach/beach-rocks_REF.gc +++ b/test/decompiler/reference/levels/beach/beach-rocks_REF.gc @@ -1235,14 +1235,7 @@ :code (behavior () (while #t - (let* ((a0-0 *art-control*) - (t9-0 (method-of-object a0-0 spool-push)) - (a1-0 "lrocklrg-falling") - (a2-0 0) - (t0-0 -1.0) - ) - (t9-0 a0-0 a1-0 a2-0 self t0-0) - ) + (spool-push *art-control* "lrocklrg-falling" 0 self -1.0) (suspend) ) (none) @@ -1303,14 +1296,7 @@ (behavior () (local-vars (v1-3 symbol) (v1-49 symbol)) (until v1-3 - (let* ((a0-0 *art-control*) - (t9-0 (method-of-object a0-0 spool-push)) - (a1-0 "lrocklrg-falling") - (a2-0 0) - (t0-0 -1.0) - ) - (t9-0 a0-0 a1-0 a2-0 self t0-0) - ) + (spool-push *art-control* "lrocklrg-falling" 0 self -1.0) (suspend) (set! v1-3 (or (not *target*) (process-grab? *target*))) ) @@ -1327,16 +1313,12 @@ (let* ((gp-1 (get-process *default-dead-pool* othercam #x4000)) (gp-2 (ppointer->handle (when gp-1 (let - ((t9-5 (method-of-type othercam activate)) - (a0-8 gp-1) - (a2-3 'othercam) - (a3-1 #x70004000) - ) + ((t9-5 (method-of-type othercam activate))) (t9-5 - (the-as othercam a0-8) + (the-as othercam gp-1) self - a2-3 - (the-as pointer a3-1) + 'othercam + (the-as pointer #x70004000) ) ) (let @@ -1367,16 +1349,12 @@ (s5-0 (get-process *default-dead-pool* fuel-cell #x4000)) (s5-1 (ppointer->handle (when s5-0 (let - ((t9-8 (method-of-type fuel-cell activate)) - (a0-14 s5-0) - (a2-6 'fuel-cell) - (a3-3 #x70004000) - ) + ((t9-8 (method-of-type fuel-cell activate))) (t9-8 - (the-as fuel-cell a0-14) + (the-as fuel-cell s5-0) self - a2-6 - (the-as pointer a3-3) + 'fuel-cell + (the-as pointer #x70004000) ) ) ((the-as @@ -1398,14 +1376,7 @@ (task-status need-reminder) ) (set! (-> self movie-start) (the-as uint (-> *display* base-frame-counter))) - (let* ((a0-20 *art-control*) - (t9-11 (method-of-object a0-20 spool-push)) - (a1-9 "lrocklrg-falling") - (a2-11 0) - (t0-2 -1.0) - ) - (t9-11 a0-20 a1-9 a2-11 self t0-2) - ) + (spool-push *art-control* "lrocklrg-falling" 0 self -1.0) (ja-play-spooled-anim (new 'static 'spool-anim :name "lrocklrg-falling" @@ -1424,12 +1395,7 @@ (the-as art-joint-anim (-> self draw art-group data 3)) (the-as (function process-drawable symbol) false-func) ) - (let ((t9-13 process-entity-status!) - (a1-11 64) - (a2-13 #t) - ) - (t9-13 self (the-as entity-perm-status a1-11) a2-13) - ) + (process-entity-status! self (entity-perm-status complete) #t) (cond ((handle->process gp-2) (deactivate (-> gp-2 process 0)) @@ -1596,7 +1562,3 @@ ((method-of-type beach-rock copy-defaults!) obj arg0) (none) ) - - - - diff --git a/test/decompiler/reference/levels/common/nav-enemy_REF.gc b/test/decompiler/reference/levels/common/nav-enemy_REF.gc index e9c56837ea..e5952be641 100644 --- a/test/decompiler/reference/levels/common/nav-enemy_REF.gc +++ b/test/decompiler/reference/levels/common/nav-enemy_REF.gc @@ -2377,14 +2377,13 @@ nav-enemy-default-event-handler (process-entity-status! self (entity-perm-status complete) #t) (when (not (task-complete? *game-info* (-> self entity extra perm task))) (label cfg-1) - (let ((t9-5 birth-pickup-at-point) - (a0-4 (-> self collide-info trans)) - (a1-2 6) - (a2-1 (the float (the-as int (-> self entity extra perm task)))) - (a3-0 #f) - (t1-0 #f) - ) - (t9-5 a0-4 a1-2 a2-1 a3-0 self t1-0) + (birth-pickup-at-point + (-> self collide-info trans) + 6 + (the float (the-as int (-> self entity extra perm task))) + #f + self + #f ) (when (not (-> self child)) (suspend)