mirror of
https://github.com/open-goal/jak-project
synced 2026-06-12 13:35:39 -04:00
[decompiler] clean up if/when/cond and recognize define-perm (#472)
* clean up if and when and cond decisions * recognize define perm
This commit is contained in:
@@ -335,24 +335,28 @@ TEST_F(FormRegressionTest, ExprMethod0Thread) {
|
||||
" daddu sp, sp, r0";
|
||||
std::string type = "(function symbol type process symbol int pointer cpu-thread)";
|
||||
std::string expected =
|
||||
"(let ((obj (the-as cpu-thread (if (-> arg2 top-thread)\n"
|
||||
" (&+ arg5 -7164)\n"
|
||||
" (let\n"
|
||||
" ((v1-2\n"
|
||||
" (logand\n"
|
||||
" -16\n"
|
||||
" (the-as int (&+ (-> arg2 heap-cur) 15))\n"
|
||||
"(let ((obj (the-as cpu-thread (cond\n"
|
||||
" ((-> arg2 top-thread)\n"
|
||||
" (&+ arg5 -7164)\n"
|
||||
" )\n"
|
||||
" (else\n"
|
||||
" (let\n"
|
||||
" ((v1-2\n"
|
||||
" (logand\n"
|
||||
" -16\n"
|
||||
" (the-as int (&+ (-> arg2 heap-cur) 15))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (set!\n"
|
||||
" (-> arg2 heap-cur)\n"
|
||||
" (the-as\n"
|
||||
" pointer\n"
|
||||
" (+ (+ v1-2 (the-as int (-> arg1 size))) arg4)\n"
|
||||
" (set!\n"
|
||||
" (-> arg2 heap-cur)\n"
|
||||
" (the-as\n"
|
||||
" pointer\n"
|
||||
" (+ (+ v1-2 (the-as int (-> arg1 size))) arg4)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (+ v1-2 4)\n"
|
||||
" )\n"
|
||||
" (+ v1-2 4)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
@@ -407,10 +411,8 @@ TEST_F(FormRegressionTest, RemoveExit) {
|
||||
" daddu sp, sp, r0";
|
||||
std::string type = "(function stack-frame)";
|
||||
std::string expected =
|
||||
"(if\n"
|
||||
" (-> pp stack-frame-top)\n"
|
||||
" (let\n"
|
||||
" ((v0-0 (-> pp stack-frame-top next)))\n"
|
||||
"(when (-> pp stack-frame-top)\n"
|
||||
" (let ((v0-0 (-> pp stack-frame-top next)))\n"
|
||||
" (set! (-> pp stack-frame-top) v0-0)\n"
|
||||
" v0-0\n"
|
||||
" )\n"
|
||||
@@ -1079,7 +1081,7 @@ TEST_F(FormRegressionTest, ExprMethod14DeadPool) {
|
||||
" (!= arg0 *debug-dead-pool*)\n"
|
||||
" )\n"
|
||||
" (set! s4-0 (get-process *debug-dead-pool* arg1 arg2))\n"
|
||||
" (if (the-as process s4-0)\n"
|
||||
" (when (the-as process s4-0)\n"
|
||||
" (let ((t9-1 format)\n"
|
||||
" (a0-2 0)\n"
|
||||
" (a1-2\n"
|
||||
@@ -1402,26 +1404,30 @@ TEST_F(FormRegressionTest, ExprMethod21DeadPoolHeap) {
|
||||
" daddu sp, sp, r0";
|
||||
std::string type = "(function dead-pool-heap dead-pool-heap-rec int)";
|
||||
std::string expected =
|
||||
"(if (-> arg1 process)\n"
|
||||
" (let\n"
|
||||
" ((v1-3\n"
|
||||
" (&+\n"
|
||||
" (&+ (the-as pointer (-> arg1 process)) (-> process size))\n"
|
||||
" (-> arg1 process allocated-length)\n"
|
||||
"(cond\n"
|
||||
" ((-> arg1 process)\n"
|
||||
" (let\n"
|
||||
" ((v1-3\n"
|
||||
" (&+\n"
|
||||
" (&+ (the-as pointer (-> arg1 process)) (-> process size))\n"
|
||||
" (-> arg1 process allocated-length)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (if (-> arg1 next)\n"
|
||||
" (&- (the-as pointer (-> arg1 next process)) (the-as uint v1-3))\n"
|
||||
" (&- (-> arg0 heap top) (the-as uint (&+ v1-3 4)))\n"
|
||||
" (if (-> arg1 next)\n"
|
||||
" (&- (the-as pointer (-> arg1 next process)) (the-as uint v1-3))\n"
|
||||
" (&- (-> arg0 heap top) (the-as uint (&+ v1-3 4)))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (if (-> arg1 next)\n"
|
||||
" (&-\n"
|
||||
" (the-as pointer (-> arg1 next process))\n"
|
||||
" (the-as uint (&+ (-> arg0 heap base) 4))\n"
|
||||
" (else\n"
|
||||
" (if (-> arg1 next)\n"
|
||||
" (&-\n"
|
||||
" (the-as pointer (-> arg1 next process))\n"
|
||||
" (the-as uint (&+ (-> arg0 heap base) 4))\n"
|
||||
" )\n"
|
||||
" (&- (-> arg0 heap top) (the-as uint (-> arg0 heap base)))\n"
|
||||
" )\n"
|
||||
" (&- (-> arg0 heap top) (the-as uint (-> arg0 heap base)))\n"
|
||||
" )\n"
|
||||
" )";
|
||||
test_with_expr(func, type, expected, false, "", {},
|
||||
@@ -2235,7 +2241,7 @@ TEST_F(FormRegressionTest, ExprMethod15DeadPoolHeap) {
|
||||
" )\n"
|
||||
" (when (= (-> arg0 first-shrink) s5-1)\n"
|
||||
" (set! (-> arg0 first-shrink) (the-as dead-pool-heap-rec (-> s5-1 1)))\n"
|
||||
" (when (not (-> arg0 first-shrink process))\n"
|
||||
" (if (not (-> arg0 first-shrink process))\n"
|
||||
" (set! (-> arg0 first-shrink) #f)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
@@ -2348,38 +2354,33 @@ TEST_F(FormRegressionTest, ExprMethod17DeadPoolHeap) {
|
||||
// NOTE - this has bad types.
|
||||
std::string expected =
|
||||
"(begin\n"
|
||||
" (if arg1 (let ((s5-0 (-> arg1 ppointer)))\n"
|
||||
" (when\n"
|
||||
" (not\n"
|
||||
" (or\n"
|
||||
" (nonzero? (logand (-> arg1 mask) (process-mask heap-shrunk)))\n"
|
||||
" (and (not (-> arg1 next-state)) (not (-> arg1 state)))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (set!\n"
|
||||
" (-> arg1 allocated-length)\n"
|
||||
" (&- (-> arg1 heap-cur) (the-as uint (-> arg1 stack)))\n"
|
||||
" )\n"
|
||||
" (set!\n"
|
||||
" (-> arg1 heap-top)\n"
|
||||
" (&-> arg1 stack (-> arg1 allocated-length))\n"
|
||||
" )\n"
|
||||
" (if\n"
|
||||
" (<\n"
|
||||
" (the-as int arg1)\n"
|
||||
" (the-as int (gap-location arg0 (-> arg0 first-gap)))\n"
|
||||
" )\n"
|
||||
" (set! (-> arg0 first-gap) (find-gap arg0 (the-as dead-pool-heap-rec s5-0)))\n"
|
||||
" )\n"
|
||||
" (set! (-> arg1 mask) (logior (-> arg1 mask) (process-mask heap-shrunk)))\n"
|
||||
" )\n"
|
||||
" (if (= (-> arg0 first-shrink) s5-0)\n"
|
||||
" (set!\n"
|
||||
" (-> arg0 first-shrink)\n"
|
||||
" (the-as dead-pool-heap-rec (-> s5-0 2))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (when arg1\n"
|
||||
" (let ((s5-0 (-> arg1 ppointer)))\n"
|
||||
" (when\n"
|
||||
" (not\n"
|
||||
" (or\n"
|
||||
" (nonzero? (logand (-> arg1 mask) (process-mask heap-shrunk)))\n"
|
||||
" (and (not (-> arg1 next-state)) (not (-> arg1 state)))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (set!\n"
|
||||
" (-> arg1 allocated-length)\n"
|
||||
" (&- (-> arg1 heap-cur) (the-as uint (-> arg1 stack)))\n"
|
||||
" )\n"
|
||||
" (set! (-> arg1 heap-top) (&-> arg1 stack (-> arg1 allocated-length)))\n"
|
||||
" (if\n"
|
||||
" (< (the-as int arg1) (the-as int (gap-location arg0 (-> arg0 first-gap))))\n"
|
||||
" (set!\n"
|
||||
" (-> arg0 first-gap)\n"
|
||||
" (find-gap arg0 (the-as dead-pool-heap-rec s5-0))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (set! (-> arg1 mask) (logior (-> arg1 mask) (process-mask heap-shrunk)))\n"
|
||||
" )\n"
|
||||
" (if (= (-> arg0 first-shrink) s5-0)\n"
|
||||
" (set! (-> arg0 first-shrink) (the-as dead-pool-heap-rec (-> s5-0 2)))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" arg0\n"
|
||||
" )";
|
||||
@@ -2578,46 +2579,49 @@ TEST_F(FormRegressionTest, ExprMethod16DeadPoolHeap) {
|
||||
|
||||
std::string expected =
|
||||
"(begin\n"
|
||||
" (let*\n"
|
||||
" ((s4-0 (memory-free arg0))\n"
|
||||
" (v1-2 (memory-total arg0))\n"
|
||||
" (f0-2 (/ (the float s4-0) (the float v1-2)))\n"
|
||||
" )\n"
|
||||
" (let* ((s4-0 (memory-free arg0))\n"
|
||||
" (v1-2 (memory-total arg0))\n"
|
||||
" (f0-2 (/ (the float s4-0) (the float v1-2)))\n"
|
||||
" )\n"
|
||||
" (cond\n"
|
||||
" ((< f0-2 (l.f L346))\n"
|
||||
" (set! arg1 1000)\n"
|
||||
" (if\n"
|
||||
" (and *debug-segment* (-> *kernel-context* low-memory-message))\n"
|
||||
" (if (and *debug-segment* (-> *kernel-context* low-memory-message))\n"
|
||||
" (format *stdcon* \"~3LLow Actor Memory~%~0L\" a2-0)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" ((< f0-2 (l.f L347)) (set! arg1 (shl arg1 2)))\n"
|
||||
" ((< f0-2 (l.f L348)) (set! arg1 (shl arg1 1)))\n"
|
||||
" ((< f0-2 (l.f L347))\n"
|
||||
" (set! arg1 (shl arg1 2))\n"
|
||||
" )\n"
|
||||
" ((< f0-2 (l.f L348))\n"
|
||||
" (set! arg1 (shl arg1 1))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (set! (-> arg0 compact-count-targ) (the-as uint arg1))\n"
|
||||
" (set! (-> arg0 compact-count) (the-as uint 0))\n"
|
||||
" (while\n"
|
||||
" (nonzero? arg1)\n"
|
||||
" (while (nonzero? arg1)\n"
|
||||
" (+! arg1 -1)\n"
|
||||
" (let\n"
|
||||
" ((v1-13 (-> arg0 first-shrink)))\n"
|
||||
" (when\n"
|
||||
" (not v1-13)\n"
|
||||
" (let ((v1-13 (-> arg0 first-shrink)))\n"
|
||||
" (when (not v1-13)\n"
|
||||
" (set! v1-13 (-> arg0 alive-list next))\n"
|
||||
" (set! (-> arg0 first-shrink) v1-13)\n"
|
||||
" )\n"
|
||||
" (if v1-13 (shrink-heap arg0 (-> v1-13 process)))\n"
|
||||
" (if v1-13\n"
|
||||
" (shrink-heap arg0 (-> v1-13 process))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (let\n"
|
||||
" ((s4-1 (-> arg0 first-gap)))\n"
|
||||
" (if\n"
|
||||
" (-> s4-1 next)\n"
|
||||
" (let\n"
|
||||
" ((s3-0 (-> s4-1 next process)) (s2-0 (gap-size arg0 s4-1)))\n"
|
||||
" (when\n"
|
||||
" (nonzero? s2-0)\n"
|
||||
" (when (< s2-0 0) (break!) (let ((v1-20 0))))\n"
|
||||
" (let ((s4-1 (-> arg0 first-gap)))\n"
|
||||
" (when (-> s4-1 next)\n"
|
||||
" (let ((s3-0 (-> s4-1 next process))\n"
|
||||
" (s2-0 (gap-size arg0 s4-1))\n"
|
||||
" )\n"
|
||||
" (when (nonzero? s2-0)\n"
|
||||
" (when (< s2-0 0)\n"
|
||||
" (break!)\n"
|
||||
" (let ((v1-20 0))\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (shrink-heap arg0 s3-0)\n"
|
||||
" (relocate s3-0 (- s2-0))\n"
|
||||
" (set! (-> arg0 first-gap) (find-gap arg0 s4-1))\n"
|
||||
@@ -2627,7 +2631,8 @@ TEST_F(FormRegressionTest, ExprMethod16DeadPoolHeap) {
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (let ((v0-8 0)))\n"
|
||||
" (let ((v0-8 0))\n"
|
||||
" )\n"
|
||||
" (none)\n"
|
||||
" )";
|
||||
test_with_expr(func, type, expected, false, "", {{"L296", "~3LLow Actor Memory~%~0L"}});
|
||||
@@ -2778,13 +2783,10 @@ TEST_F(FormRegressionTest, ExprMethod18DeadPoolHeap) {
|
||||
std::string type = "(function dead-pool-heap int none)";
|
||||
std::string expected =
|
||||
"(begin\n"
|
||||
" (while\n"
|
||||
" (nonzero? arg1)\n"
|
||||
" (while (nonzero? arg1)\n"
|
||||
" (+! arg1 -1)\n"
|
||||
" (let\n"
|
||||
" ((s4-0 (-> arg0 alive-list next)))\n"
|
||||
" (when\n"
|
||||
" s4-0\n"
|
||||
" (let ((s4-0 (-> arg0 alive-list next)))\n"
|
||||
" (when s4-0\n"
|
||||
" (if\n"
|
||||
" (or\n"
|
||||
" (= (-> arg0 first-gap) s4-0)\n"
|
||||
@@ -2795,27 +2797,24 @@ TEST_F(FormRegressionTest, ExprMethod18DeadPoolHeap) {
|
||||
" )\n"
|
||||
" (set! (-> arg0 first-gap) (-> s4-0 prev))\n"
|
||||
" )\n"
|
||||
" (when\n"
|
||||
" (= (-> arg0 first-shrink) s4-0)\n"
|
||||
" (when (= (-> arg0 first-shrink) s4-0)\n"
|
||||
" (set! (-> arg0 first-shrink) (-> s4-0 prev))\n"
|
||||
" (when\n"
|
||||
" (not (-> arg0 first-shrink process))\n"
|
||||
" (if (not (-> arg0 first-shrink process))\n"
|
||||
" (set! (-> arg0 first-shrink) #f)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (set! (-> s4-0 prev next) (-> s4-0 next))\n"
|
||||
" (if\n"
|
||||
" (-> s4-0 next)\n"
|
||||
" (if (-> s4-0 next)\n"
|
||||
" (set! (-> s4-0 next prev) (-> s4-0 prev))\n"
|
||||
" (set! (-> arg0 alive-list prev) (-> s4-0 prev))\n"
|
||||
" )\n"
|
||||
" (let\n"
|
||||
" ((a1-3 (-> arg0 alive-list prev)))\n"
|
||||
" (let\n"
|
||||
" ((v1-19 (-> a1-3 next)))\n"
|
||||
" (let ((a1-3 (-> arg0 alive-list prev)))\n"
|
||||
" (let ((v1-19 (-> a1-3 next)))\n"
|
||||
" (set! (-> a1-3 next) s4-0)\n"
|
||||
" (set! (-> s4-0 next) v1-19)\n"
|
||||
" (if v1-19 (set! (-> v1-19 prev) s4-0))\n"
|
||||
" (if v1-19\n"
|
||||
" (set! (-> v1-19 prev) s4-0)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (set! (-> s4-0 prev) a1-3)\n"
|
||||
" (set! (-> arg0 alive-list prev) s4-0)\n"
|
||||
@@ -2830,7 +2829,8 @@ TEST_F(FormRegressionTest, ExprMethod18DeadPoolHeap) {
|
||||
" )\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (let ((v0-4 0)))\n"
|
||||
" (let ((v0-4 0))\n"
|
||||
" )\n"
|
||||
" (none)\n"
|
||||
" )";
|
||||
test_with_expr(func, type, expected);
|
||||
|
||||
Reference in New Issue
Block a user