[Decompiler] Decompile let (#309)

* test

* fix bug

* fix tests for let

* missing formatting fix
This commit is contained in:
water111
2021-03-05 18:48:01 -05:00
committed by GitHub
parent 9168f03289
commit 65ffe83468
20 changed files with 2312 additions and 1655 deletions
+4 -1
View File
@@ -5,6 +5,7 @@
#include "decompiler/analysis/cfg_builder.h"
#include "decompiler/analysis/expression_build.h"
#include "decompiler/analysis/final_output.h"
#include "decompiler/analysis/insert_lets.h"
#include "common/goos/PrettyPrinter.h"
#include "decompiler/IR2/Form.h"
#include "third-party/json.hpp"
@@ -129,7 +130,7 @@ std::unique_ptr<FormRegressionTest::TestData> FormRegressionTest::make_function(
// for now, just test that this can at least be called.
if (test->func.ir2.top_form) {
RegAccessSet vars;
test->func.ir2.top_form->collect_vars(vars);
test->func.ir2.top_form->collect_vars(vars, true);
if (do_expressions) {
bool success = convert_to_expressions(test->func.ir2.top_form, *test->func.ir2.form_pool,
@@ -139,6 +140,8 @@ std::unique_ptr<FormRegressionTest::TestData> FormRegressionTest::make_function(
if (!success) {
return nullptr;
}
insert_lets(test->func, test->func.ir2.env, *test->func.ir2.form_pool,
test->func.ir2.top_form);
}
}
File diff suppressed because it is too large Load Diff
+198 -194
View File
@@ -266,7 +266,7 @@ TEST_F(FormRegressionTest, ExprAbs) {
" jr ra\n"
" daddu sp, sp, r0";
std::string type = "(function int int)";
std::string expected = "(begin (set! v0-0 arg0) (abs v0-0))";
std::string expected = "(let ((v0-0 arg0)) (abs v0-0))";
test_with_expr(func, type, expected);
}
@@ -454,14 +454,11 @@ TEST_F(FormRegressionTest, ExprBasicTypeP) {
std::string type = "(function basic type symbol)";
std::string expected =
"(begin\n"
" (set! v1-0 (-> arg0 type))\n"
" (set! a0-1 object)\n"
" (until\n"
" (begin (set! v1-0 (-> v1-0 parent)) (= v1-0 a0-1))\n" // likely using set! as value. we
// don't plan on supporting this.
" (if\n"
" (= v1-0 arg1)\n"
" (return #t)\n"
" (let\n"
" ((v1-0 (-> arg0 type)) (a0-1 object))\n"
" (until\n"
" (begin (set! v1-0 (-> v1-0 parent)) (= v1-0 a0-1))\n"
" (if (= v1-0 arg1) (return #t))\n"
" )\n"
" )\n"
" #f\n"
@@ -497,17 +494,14 @@ TEST_F(FormRegressionTest, FinalBasicTypeP) {
std::string type = "(function basic type symbol)";
std::string expected =
"(defun test-function ((arg0 basic) (arg1 type))\n"
" (local-vars\n"
" (v1-0 type)\n"
" (a0-1 type)\n"
" )\n"
" (set! v1-0 (-> arg0 type))\n"
" (set! a0-1 object)\n"
" (let\n"
" ((v1-0 (-> arg0 type)) (a0-1 object))\n"
" (until\n"
" (begin (set! v1-0 (-> v1-0 parent)) (= v1-0 a0-1))\n"
" (if (= v1-0 arg1) (return #t))\n"
" )\n"
" #f\n"
" )\n"
" #f\n"
" )";
test_final_function(func, type, expected);
}
@@ -553,13 +547,12 @@ TEST_F(FormRegressionTest, ExprTypeTypep) {
std::string expected =
"(begin\n"
" (set! v1-0 object)\n"
" (until\n"
" (begin\n"
" (set! arg0 (-> arg0 parent))\n"
" (or (= arg0 v1-0) (zero? arg0))\n"
" (let\n"
" ((v1-0 object))\n"
" (until\n"
" (begin (set! arg0 (-> arg0 parent)) (or (= arg0 v1-0) (zero? arg0)))\n"
" (if (= arg0 arg1) (return #t))\n"
" )\n"
" (if (= arg0 arg1) (return #t))\n"
" )\n"
" #f\n"
" )";
@@ -615,13 +608,15 @@ TEST_F(FormRegressionTest, ExprFindParentMethod) {
std::string expected =
"(begin\n"
" (set! v1-2 (-> arg0 method-table arg1))\n"
" (until\n"
" (!= v0-0 v1-2)\n"
" (if (= arg0 object) (return nothing))\n"
" (set! arg0 (-> arg0 parent))\n"
" (set! v0-0 (-> arg0 method-table arg1))\n"
" (if (zero? v0-0) (return nothing))\n"
" (let\n"
" ((v1-2 (-> arg0 method-table arg1)))\n"
" (until\n"
" (!= v0-0 v1-2)\n"
" (if (= arg0 object) (return nothing))\n"
" (set! arg0 (-> arg0 parent))\n"
" (set! v0-0 (-> arg0 method-table arg1))\n"
" (if (zero? v0-0) (return nothing))\n"
" )\n"
" )\n"
" v0-0\n"
" )";
@@ -656,13 +651,9 @@ TEST_F(FormRegressionTest, ExprRef) {
std::string expected =
"(begin\n"
" (set! v1-0 0)\n"
" (while\n"
" (< v1-0 arg1)\n"
" (nop!)\n"
" (nop!)\n"
" (set! arg0 (cdr arg0))\n"
" (+! v1-0 1)\n"
" (let\n"
" ((v1-0 0))\n"
" (while (< v1-0 arg1) (nop!) (nop!) (set! arg0 (cdr arg0)) (+! v1-0 1))\n"
" )\n"
" (car arg0)\n"
" )";
@@ -715,19 +706,20 @@ TEST_F(FormRegressionTest, ExprPairMethod4) {
" daddu sp, sp, r0\n";
std::string type = "(function pair int)";
// multiple return paths merged variable issue.
std::string expected =
"(begin\n"
" (cond\n"
" ((= arg0 '()) (set! v0-0 0))\n"
" ((= arg0 (quote ())) (set! v0-0 0))\n"
" (else\n"
" (set! v1-1 (cdr arg0))\n"
" (set! v0-0 1)\n"
" (while\n"
" (and (!= v1-1 '()) "
" (< (shl (the-as int v1-1) 62) 0)\n"
" (let\n"
" ((v1-1 (cdr arg0)))\n"
" (set! v0-0 1)\n"
" (while\n"
" (and (!= v1-1 (quote ())) (< (shl (the-as int v1-1) 62) 0))\n"
" (+! v0-0 1)\n"
" (set! v1-1 (cdr v1-1))\n"
" )\n"
" (+! v0-0 1)\n"
" (set! v1-1 (cdr v1-1))\n"
" )\n"
" )\n"
" )\n"
@@ -774,12 +766,9 @@ TEST_F(FormRegressionTest, ExprLast) {
std::string type = "(function object object)";
std::string expected =
"(begin\n"
" (set! v0-0 arg0)\n"
" (while (!= (cdr v0-0) '())"
" (nop!)\n"
" (nop!)\n"
" (set! v0-0 (cdr v0-0)))\n"
"(let\n"
" ((v0-0 arg0))\n"
" (while (!= (cdr v0-0) (quote ())) (nop!) (nop!) (set! v0-0 (cdr v0-0)))\n"
" v0-0\n"
" )";
test_with_expr(func, type, expected, true, "");
@@ -826,13 +815,13 @@ TEST_F(FormRegressionTest, ExprMember) {
std::string type = "(function object object object)";
std::string expected =
"(begin\n"
" (set! v1-0 arg1)\n"
"(let\n"
" ((v1-0 arg1))\n"
" (while\n"
" (not (or (= v1-0 '()) (= (car v1-0) arg0)))\n"
" (not (or (= v1-0 (quote ())) (= (car v1-0) arg0)))\n"
" (set! v1-0 (cdr v1-0))\n"
" )\n"
" (if (!= v1-0 '()) v1-0)\n"
" (if (!= v1-0 (quote ())) v1-0)\n"
" )";
test_with_expr(func, type, expected, true, "");
}
@@ -939,13 +928,13 @@ TEST_F(FormRegressionTest, ExprAssoc) {
std::string type = "(function object object object)";
std::string expected =
"(begin\n"
" (set! v1-0 arg1)\n"
"(let\n"
" ((v1-0 arg1))\n"
" (while\n"
" (not (or (= v1-0 '()) (= (car (car v1-0)) arg0)))\n"
" (not (or (= v1-0 (quote ())) (= (car (car v1-0)) arg0)))\n"
" (set! v1-0 (cdr v1-0))\n"
" )\n"
" (if (!= v1-0 '()) (car v1-0))\n"
" (if (!= v1-0 (quote ())) (car v1-0))\n"
" )";
test_with_expr(func, type, expected, true, "");
}
@@ -1001,19 +990,19 @@ TEST_F(FormRegressionTest, ExprAssoce) {
std::string type = "(function object object object)";
std::string expected =
"(begin\n"
" (set! v1-0 arg1)\n"
"(let\n"
" ((v1-0 arg1))\n"
" (while\n"
" (not\n"
" (or\n"
" (= v1-0 '())\n"
" (= v1-0 (quote ()))\n"
" (= (car (car v1-0)) arg0)\n"
" (= (car (car v1-0)) 'else)\n"
" (= (car (car v1-0)) (quote else))\n"
" )\n"
" )\n"
" (set! v1-0 (cdr v1-0))\n"
" )\n"
" (if (!= v1-0 '()) (car v1-0))\n"
" (if (!= v1-0 (quote ())) (car v1-0))\n"
" )";
test_with_expr(func, type, expected, true, "");
}
@@ -1092,13 +1081,13 @@ TEST_F(FormRegressionTest, ExprNassoc) {
" (not\n"
" (or\n"
" (= arg1 (quote ()))\n"
" (begin\n"
" (set! a1-1 (car (car arg1)))\n"
" (if "
" (let\n"
" ((a1-1 (car (car arg1))))\n"
" (if\n"
" (pair? a1-1)\n"
" (nmember (the-as basic arg0) a1-1)\n"
" (name= (the-as basic a1-1) (the-as basic arg0))"
" )\n"
" (name= (the-as basic a1-1) (the-as basic arg0))\n"
" )\n"
" )\n"
" )\n"
" )\n"
@@ -1194,8 +1183,8 @@ TEST_F(FormRegressionTest, ExprNassoce) {
" (not\n"
" (or\n"
" (= arg1 (quote ()))\n"
" (begin\n"
" (set! s4-0 (car (car arg1)))\n"
" (let\n"
" ((s4-0 (car (car arg1))))\n"
" (if\n"
" (pair? s4-0)\n"
" (nmember (the-as basic arg0) s4-0)\n"
@@ -1260,11 +1249,13 @@ TEST_F(FormRegressionTest, ExprAppend) {
std::string expected =
"(cond\n"
" ((= arg0 '()) arg1)\n"
" ((= arg0 (quote ())) arg1)\n"
" (else\n"
" (set! v1-1 arg0)\n"
" (while (!= (cdr v1-1) '()) (nop!) (nop!) (set! v1-1 (cdr v1-1)))\n"
" (if (!= v1-1 '()) (set! (cdr v1-1) arg1))\n"
" (let\n"
" ((v1-1 arg0))\n"
" (while (!= (cdr v1-1) (quote ())) (nop!) (nop!) (set! v1-1 (cdr v1-1)))\n"
" (if (!= v1-1 (quote ())) (set! (cdr v1-1) arg1))\n"
" )\n"
" arg0\n"
" )\n"
" )";
@@ -1332,14 +1323,15 @@ TEST_F(FormRegressionTest, ExprDelete) {
" (cond\n"
" ((= arg0 (car arg1)) (cdr arg1))\n"
" (else\n"
" (set! v1-1 arg1)\n"
" (set! a2-0 (cdr arg1))\n"
" (while\n"
" (not (or (= a2-0 (quote ())) (= (car a2-0) arg0)))\n"
" (set! v1-1 a2-0)\n"
" (set! a2-0 (cdr a2-0))\n"
" (let\n"
" ((v1-1 arg1) (a2-0 (cdr arg1)))\n"
" (while\n"
" (not (or (= a2-0 (quote ())) (= (car a2-0) arg0)))\n"
" (set! v1-1 a2-0)\n"
" (set! a2-0 (cdr a2-0))\n"
" )\n"
" (if (!= a2-0 (quote ())) (set! (cdr v1-1) (cdr a2-0)))\n"
" )\n"
" (if (!= a2-0 (quote ())) (set! (cdr v1-1) (cdr a2-0)))\n"
" arg1\n"
" )\n"
" )\n"
@@ -1410,14 +1402,15 @@ TEST_F(FormRegressionTest, ExprDeleteCar) {
" (cond\n"
" ((= arg0 (car (car arg1))) (cdr arg1))\n"
" (else\n"
" (set! v1-2 arg1)\n"
" (set! a2-0 (cdr arg1))\n"
" (while\n"
" (not (or (= a2-0 (quote ())) (= (car (car a2-0)) arg0)))\n"
" (set! v1-2 a2-0)\n"
" (set! a2-0 (cdr a2-0))\n"
" (let\n"
" ((v1-2 arg1) (a2-0 (cdr arg1)))\n"
" (while\n"
" (not (or (= a2-0 (quote ())) (= (car (car a2-0)) arg0)))\n"
" (set! v1-2 a2-0)\n"
" (set! a2-0 (cdr a2-0))\n"
" )\n"
" (if (!= a2-0 (quote ())) (set! (cdr v1-2) (cdr a2-0)))\n"
" )\n"
" (if (!= a2-0 (quote ())) (set! (cdr v1-2) (cdr a2-0)))\n"
" arg1\n"
" )\n"
" )\n"
@@ -1454,11 +1447,7 @@ TEST_F(FormRegressionTest, ExprInsertCons) {
std::string type = "(function object object pair)";
// NOTE - this appears to _not_ be a nested call.
std::string expected =
"(begin\n"
" (set! a3-0 (delete-car! (car arg0) arg1))\n"
" (cons arg0 a3-0)\n"
" )";
std::string expected = "(let ((a3-0 (delete-car! (car arg0) arg1))) (cons arg0 a3-0))";
test_with_expr(func, type, expected, true, "");
}
@@ -1568,25 +1557,29 @@ TEST_F(FormRegressionTest, ExprSort) {
// TODO - this should probably be tested.
std::string expected =
"(begin\n"
" (set! s4-0 -1)\n"
" (while\n"
" (nonzero? s4-0)\n"
" (set! s4-0 0)\n"
" (set! s3-0 arg0)\n"
" (let\n"
" ((s4-0 -1))\n"
" (while\n"
" (not\n"
" (or (= (cdr s3-0) (quote ())) (>= (shl (the-as int (cdr s3-0)) 62) 0))\n"
" (nonzero? s4-0)\n"
" (set! s4-0 0)\n"
" (let\n"
" ((s3-0 arg0))\n"
" (while\n"
" (not\n"
" (or (= (cdr s3-0) (quote ())) (>= (shl (the-as int (cdr s3-0)) 62) 0))\n"
" )\n"
" (let*\n"
" ((s2-0 (car s3-0)) (s1-0 (car (cdr s3-0))) (v1-1 (arg1 s2-0 s1-0)))\n"
" (when\n"
" (and (or (not v1-1) (> (the-as int v1-1) 0)) (!= v1-1 #t))\n"
" (+! s4-0 1)\n"
" (set! (car s3-0) s1-0)\n"
" (set! (car (cdr s3-0)) s2-0)\n"
" )\n"
" )\n"
" (set! s3-0 (cdr s3-0))\n"
" )\n"
" )\n"
" (set! s2-0 (car s3-0))\n"
" (set! s1-0 (car (cdr s3-0)))\n"
" (set! v1-1 (arg1 s2-0 s1-0))\n"
" (when\n"
" (and (or (not v1-1) (> (the-as int v1-1) 0)) (!= v1-1 #t))\n"
" (+! s4-0 1)\n"
" (set! (car s3-0) s1-0)\n"
" (set! (car (cdr s3-0)) s2-0)\n"
" )\n"
" (set! s3-0 (cdr s3-0))\n"
" )\n"
" )\n"
" arg0\n"
@@ -1627,13 +1620,13 @@ TEST_F(FormRegressionTest, ExprInlineArrayMethod0) {
std::string type = "(function symbol type int inline-array-class)";
std::string expected =
"(begin\n"
" (set!\n"
" v0-0\n"
" (object-new\n"
" arg0\n"
" arg1\n"
" (the-as int (+ (-> arg1 size) (* (the-as uint arg2) (-> arg1 heap-base))))\n"
"(let\n"
" ((v0-0\n"
" (object-new\n"
" arg0\n"
" arg1\n"
" (the-as int (+ (-> arg1 size) (* (the-as uint arg2) (-> arg1 heap-base))))\n"
" )\n"
" )\n"
" )\n"
" (when\n"
@@ -1743,17 +1736,17 @@ TEST_F(FormRegressionTest, ExprArrayMethod0) {
std::string type = "(function symbol type type int array)";
std::string expected =
"(begin\n"
" (set!\n"
" v0-1\n"
" (object-new\n"
" arg0\n"
" arg1\n"
" (the-as\n"
" int\n"
" (+\n"
" (-> arg1 size)\n"
" (the-as uint (* arg3 (if (type-type? arg2 number) (-> arg2 size) 4)))\n"
"(let\n"
" ((v0-1\n"
" (object-new\n"
" arg0\n"
" arg1\n"
" (the-as\n"
" int\n"
" (+\n"
" (-> arg1 size)\n"
" (the-as uint (* arg3 (if (type-type? arg2 number) (-> arg2 size) 4)))\n"
" )\n"
" )\n"
" )\n"
" )\n"
@@ -1867,15 +1860,17 @@ TEST_F(FormRegressionTest, ExprMemCopy) {
std::string type = "(function pointer pointer int pointer)";
std::string expected =
"(begin\n"
" (set! v0-0 arg0)\n"
" (set! v1-0 0)\n"
" (while\n"
" (< v1-0 arg2)\n"
" (set! (-> (the-as (pointer int8) arg0)) (-> (the-as (pointer uint8) arg1)))\n"
" (&+! arg0 1)\n"
" (&+! arg1 1)\n"
" (+! v1-0 1)\n"
"(let\n"
" ((v0-0 arg0))\n"
" (let\n"
" ((v1-0 0))\n"
" (while\n"
" (< v1-0 arg2)\n"
" (set! (-> (the-as (pointer int8) arg0)) (-> (the-as (pointer uint8) arg1)))\n"
" (&+! arg0 1)\n"
" (&+! arg1 1)\n"
" (+! v1-0 1)\n"
" )\n"
" )\n"
" v0-0\n"
" )";
@@ -1908,15 +1903,17 @@ TEST_F(FormRegressionTest, ExprMemSet32) {
std::string type = "(function pointer int int pointer)";
std::string expected =
"(begin\n"
" (set! v0-0 arg0)\n"
" (set! v1-0 0)\n"
" (while\n"
" (< v1-0 arg1)\n"
" (set! (-> (the-as (pointer int32) arg0)) arg2)\n"
" (&+! arg0 4)\n"
" (nop!)\n"
" (+! v1-0 1)\n"
"(let\n"
" ((v0-0 arg0))\n"
" (let\n"
" ((v1-0 0))\n"
" (while\n"
" (< v1-0 arg1)\n"
" (set! (-> (the-as (pointer int32) arg0)) arg2)\n"
" (&+! arg0 4)\n"
" (nop!)\n"
" (+! v1-0 1)\n"
" )\n"
" )\n"
" v0-0\n"
" )";
@@ -1952,21 +1949,23 @@ TEST_F(FormRegressionTest, ExprMemOr) {
std::string type = "(function pointer pointer int pointer)";
std::string expected =
"(begin\n"
" (set! v0-0 arg0)\n"
" (set! v1-0 0)\n"
" (while\n"
" (< v1-0 arg2)\n"
" (set!\n"
" (-> (the-as (pointer int8) arg0))\n"
" (logior\n"
" (-> (the-as (pointer uint8) arg0))\n"
" (-> (the-as (pointer uint8) arg1))\n"
"(let\n"
" ((v0-0 arg0))\n"
" (let\n"
" ((v1-0 0))\n"
" (while\n"
" (< v1-0 arg2)\n"
" (set!\n"
" (-> (the-as (pointer int8) arg0))\n"
" (logior\n"
" (-> (the-as (pointer uint8) arg0))\n"
" (-> (the-as (pointer uint8) arg1))\n"
" )\n"
" )\n"
" (&+! arg0 1)\n"
" (&+! arg1 1)\n"
" (+! v1-0 1)\n"
" )\n"
" (&+! arg0 1)\n"
" (&+! arg1 1)\n"
" (+! v1-0 1)\n"
" )\n"
" v0-0\n"
" )";
@@ -2076,8 +2075,7 @@ TEST_F(FormRegressionTest, ExprPrintl) {
std::string expected =
"(begin\n"
" (set! a0-1 arg0)\n"
" ((method-of-type (rtype-of a0-1) print) a0-1)\n"
" (let ((a0-1 arg0)) ((method-of-type (rtype-of a0-1) print) a0-1))\n"
" (format #t \"~%\")\n"
" arg0\n"
" )";
@@ -2173,16 +2171,14 @@ TEST_F(FormRegressionTest, ExprPrintTreeBitmask) {
std::string expected =
"(begin\n"
" (set! s4-0 0)\n"
" (while\n"
" (< s4-0 arg1)\n"
" (if\n"
" (zero? (logand arg0 1))\n"
" (format #t \" \")\n"
" (format #t \"| \")\n"
" (let\n"
" ((s4-0 0))\n"
" (while\n"
" (< s4-0 arg1)\n"
" (if (zero? (logand arg0 1)) (format #t \" \") (format #t \"| \"))\n"
" (set! arg0 (shr arg0 1))\n"
" (+! s4-0 1)\n"
" )\n"
" (set! arg0 (shr arg0 1))\n"
" (+! s4-0 1)\n"
" )\n"
" #f\n"
" )";
@@ -2351,7 +2347,7 @@ TEST_F(FormRegressionTest, ExprStopwatchElapsedSeconds) {
" daddiu sp, sp, 16";
std::string type = "(function int float)";
std::string expected = "(begin (set! v1-0 (abs arg0)) (* (l.f L20) (the float v1-0)))";
std::string expected = "(let ((v1-0 (abs arg0))) (* (l.f L20) (the float v1-0)))";
test_with_expr(func, type, expected, false, "");
}
@@ -2381,17 +2377,23 @@ TEST_F(FormRegressionTest, ExprCopyStringString) {
" jr ra\n"
" daddu sp, sp, r0";
std::string type = "(function string string string)";
// this is correct, but an example of where let's might look better if nested,
// even if it means making the scope a little bit larger...
std::string expected =
"(begin\n"
" (set! v1-0 (-> arg0 data))\n"
" (set! a1-1 (-> arg1 data))\n"
" (while\n"
" (nonzero? (-> a1-1 0))\n"
" (set! (-> v1-0 0) (-> a1-1 0))\n"
" (set! v1-0 (&-> v1-0 1))\n"
" (set! a1-1 (&-> a1-1 1))\n"
" (let\n"
" ((v1-0 (-> arg0 data)))\n"
" (let\n"
" ((a1-1 (-> arg1 data)))\n"
" (while\n"
" (nonzero? (-> a1-1 0))\n"
" (set! (-> v1-0 0) (-> a1-1 0))\n"
" (set! v1-0 (&-> v1-0 1))\n"
" (set! a1-1 (&-> a1-1 1))\n"
" )\n"
" )\n"
" (set! (-> v1-0 0) 0)\n"
" )\n"
" (set! (-> v1-0 0) 0)\n"
" arg0\n"
" )";
test_with_expr(func, type, expected, false, "");
@@ -2485,21 +2487,23 @@ TEST_F(FormRegressionTest, StringLt) {
std::string type = "(function string string symbol)";
std::string expected =
"(begin\n"
" (set!\n"
" s4-1\n"
" (min\n"
" ((method-of-type string length) arg0)\n"
" ((method-of-type string length) arg1)\n"
" (let\n"
" ((s4-1\n"
" (min\n"
" ((method-of-type string length) arg0)\n"
" ((method-of-type string length) arg1)\n"
" )\n"
" )\n"
" (v1-4 0)\n"
" )\n"
" )\n"
" (set! v1-4 0)\n"
" (while\n"
" (< v1-4 s4-1)\n"
" (cond\n"
" ((< (-> arg0 data v1-4) (-> arg1 data v1-4)) (return #t))\n"
" ((< (-> arg1 data v1-4) (-> arg0 data v1-4)) (return #f))\n"
" (while\n"
" (< v1-4 s4-1)\n"
" (cond\n"
" ((< (-> arg0 data v1-4) (-> arg1 data v1-4)) (return #t))\n"
" ((< (-> arg1 data v1-4) (-> arg0 data v1-4)) (return #f))\n"
" )\n"
" (+! v1-4 1)\n"
" )\n"
" (+! v1-4 1)\n"
" )\n"
" #f\n"
" )";
@@ -2567,8 +2571,8 @@ TEST_F(FormRegressionTest, ExprTerminal2) {
std::string type = "(function float float float float float)";
std::string expected =
"(begin\n"
" (set! f0-4 (sqrt (/ (- (* 0.000000 arg0) arg1) arg2)))\n"
"(let\n"
" ((f0-4 (sqrt (/ (- (* 0.0 arg0) arg1) arg2))))\n"
" (- f0-4 (+ arg1 (* arg2 (* f0-4 f0-4))))\n"
" )";
test_with_expr(func, type, expected, false, "", {{"L17", "A ~A"}});
File diff suppressed because it is too large Load Diff
+382 -345
View File
@@ -62,10 +62,12 @@ TEST_F(FormRegressionTest, ExprLoadPackage) {
std::string expected =
"(when\n"
" (not (nmember arg0 *kernel-packages*))\n"
" (dgo-load arg0 arg1 15 2097152)\n"
" (set! v0-1 (cons arg0 *kernel-packages*))\n"
" (set! *kernel-packages* v0-1)\n"
" v0-1\n"
" (dgo-load arg0 arg1 15 #x200000)\n"
" (let\n"
" ((v0-1 (cons arg0 *kernel-packages*)))\n"
" (set! *kernel-packages* v0-1)\n"
" v0-1\n"
" )\n"
" )";
test_with_expr(func, type, expected);
}
@@ -100,8 +102,10 @@ TEST_F(FormRegressionTest, ExprUnloadPackage) {
std::string type = "(function string pair)";
std::string expected =
"(begin\n"
" (set! v1-0 (nmember arg0 *kernel-packages*))\n"
" (if v1-0 (set! *kernel-packages* (delete! (car v1-0) *kernel-packages*)))\n"
" (let\n"
" ((v1-0 (nmember arg0 *kernel-packages*)))\n"
" (if v1-0 (set! *kernel-packages* (delete! (car v1-0) *kernel-packages*)))\n"
" )\n"
" *kernel-packages*\n"
" )";
test_with_expr(func, type, expected, true);
@@ -128,7 +132,7 @@ TEST_F(FormRegressionTest, ExprMethod1Thread) {
std::string type = "(function thread none)";
std::string expected =
"(begin\n"
" (when (= arg0 (-> arg0 process main-thread)) (break!) (set! v1-3 0))\n"
" (when (= arg0 (-> arg0 process main-thread)) (break!) (let ((v1-3 0))))\n"
" (set! (-> arg0 process top-thread) (-> arg0 previous))\n"
" )";
test_with_expr(func, type, expected, false);
@@ -253,26 +257,28 @@ TEST_F(FormRegressionTest, ExprMethod9Thread) {
std::string type = "(function thread int none)";
std::string expected =
"(begin\n"
" (set! a2-0 (-> arg0 process))\n"
" (cond\n"
" ((!= arg0 (-> a2-0 main-thread)) (format 0 \"1 ~A ~%\" a2-0))\n"
" ((= (-> arg0 stack-size) arg1))\n"
" ((=\n"
" (-> a2-0 heap-cur)\n"
" (+\n"
" (+ (+ (-> arg0 stack-size) -4) (the-as int (-> arg0 type size)))\n"
" (the-as int arg0)\n"
" (let\n"
" ((a2-0 (-> arg0 process)))\n"
" (cond\n"
" ((!= arg0 (-> a2-0 main-thread)) (format 0 \"1 ~A ~%\" a2-0))\n"
" ((= (-> arg0 stack-size) arg1))\n"
" ((=\n"
" (-> a2-0 heap-cur)\n"
" (+\n"
" (+ (+ (-> arg0 stack-size) -4) (the-as int (-> arg0 type size)))\n"
" (the-as int arg0)\n"
" )\n"
" )\n"
" (set!\n"
" (-> a2-0 heap-cur)\n"
" (+ (+ (+ arg1 -4) (the-as int (-> arg0 type size))) (the-as int arg0))\n"
" )\n"
" (set! (-> arg0 stack-size) arg1)\n"
" )\n"
" (set!\n"
" (-> a2-0 heap-cur)\n"
" (+ (+ (+ arg1 -4) (the-as int (-> arg0 type size))) (the-as int arg0))\n"
" )\n"
" (set! (-> arg0 stack-size) arg1)\n"
" (else (format 0 \"2 ~A ~%\" a2-0))\n"
" )\n"
" (else (format 0 \"2 ~A ~%\" a2-0))\n"
" )\n"
" (set! v0-2 0)\n"
" (let ((v0-2 0)))\n"
" )";
test_with_expr(func, type, expected, false, "", {{"L342", "1 ~A ~%"}, {"L341", "2 ~A ~%"}});
}
@@ -319,18 +325,16 @@ TEST_F(FormRegressionTest, ExprMethod0Thread) {
" daddu sp, sp, r0";
std::string type = "(function symbol type process symbol int pointer thread)";
std::string expected =
"(begin\n"
" (set!\n"
" v0-0\n"
" (cond\n"
" ((-> arg2 top-thread) (&+ arg5 -7164))\n"
" (else\n"
" (set!\n"
" v1-2\n"
" (logand -16 (the-as int (&+ (-> arg2 heap-cur) 15)))\n"
"(let\n"
" ((v0-0\n"
" (if\n"
" (-> arg2 top-thread)\n"
" (&+ arg5 -7164)\n"
" (let\n"
" ((v1-2 (logand -16 (the-as int (&+ (-> arg2 heap-cur) 15)))))\n"
" (set! (-> arg2 heap-cur) (+ (+ v1-2 (the-as int (-> arg1 size))) arg4))\n"
" (+ v1-2 4)\n"
" )\n"
" (set! (-> arg2 heap-cur) (+ (+ v1-2 (the-as int (-> arg1 size))) arg4))\n"
" (+ v1-2 4)\n"
" )\n"
" )\n"
" )\n"
@@ -341,7 +345,6 @@ TEST_F(FormRegressionTest, ExprMethod0Thread) {
" (set! (-> v0-0 stack-top) arg5)\n"
" (set! (-> v0-0 previous) (-> arg2 top-thread))\n"
" (set! (-> arg2 top-thread) v0-0)\n"
// TODO - we could make this method access nicer.
" (set! (-> v0-0 suspend-hook) (method-of-object v0-0 thread-suspend))\n"
" (set! (-> v0-0 resume-hook) (method-of-object v0-0 thread-resume))\n"
" (set! (-> v0-0 stack-size) arg4)\n"
@@ -383,11 +386,13 @@ TEST_F(FormRegressionTest, RemoveExit) {
" daddu sp, sp, r0";
std::string type = "(function stack-frame)";
std::string expected =
"(when\n"
"(if\n"
" (-> pp stack-frame-top)\n"
" (set! v0-0 (-> pp stack-frame-top next))\n"
" (set! (-> pp stack-frame-top) v0-0)\n"
" v0-0\n"
" (let\n"
" ((v0-0 (-> pp stack-frame-top next)))\n"
" (set! (-> pp stack-frame-top) v0-0)\n"
" v0-0\n"
" )\n"
" )";
test_with_expr(func, type, expected, false);
}
@@ -423,8 +428,8 @@ TEST_F(FormRegressionTest, RemoveMethod0ProcessTree) {
" daddiu sp, sp, 32";
std::string type = "(function symbol type basic process-tree)";
std::string expected =
"(begin\n"
" (set! v0-0 (object-new arg0 arg1 (the-as int (-> arg1 size))))\n"
"(let\n"
" ((v0-0 (object-new arg0 arg1 (the-as int (-> arg1 size)))))\n"
" (set! (-> v0-0 name) arg2)\n"
" (set! (-> v0-0 mask) 256)\n"
" (set! (-> v0-0 parent) #f)\n"
@@ -525,21 +530,18 @@ TEST_F(FormRegressionTest, RemoveMethod3ProcessTree) {
" (format #t \"[~8x] ~A~%\" arg0 (-> arg0 type))\n"
" (format #t \"~Tname: ~S~%\" (-> arg0 name))\n"
" (format #t \"~Tmask: #x~X~%\" (-> arg0 mask))\n"
" (set! t9-3 format)\n"
" (set! a0-4 #t)\n"
" (set! a1-3 \"~Tparent: ~A~%\")\n"
" (set! v1-0 (-> arg0 parent))\n"
" (t9-3 a0-4 a1-3 (if v1-0 (-> v1-0 0 self)))\n"
" (set! t9-4 format)\n"
" (set! a0-5 #t)\n"
" (set! a1-4 \"~Tbrother: ~A~%\")\n"
" (set! v1-2 (-> arg0 brother))\n"
" (t9-4 a0-5 a1-4 (if v1-2 (-> v1-2 0 self)))\n"
" (set! t9-5 format)\n"
" (set! a0-6 #t)\n"
" (set! a1-5 \"~Tchild: ~A~%\")\n"
" (set! v1-4 (-> arg0 child))\n"
" (t9-5 a0-6 a1-5 (if v1-4 (-> v1-4 0 self)))\n"
" (let\n"
" ((t9-3 format) (a0-4 #t) (a1-3 \"~Tparent: ~A~%\") (v1-0 (-> arg0 parent)))\n"
" (t9-3 a0-4 a1-3 (if v1-0 (-> v1-0 0 self)))\n"
" )\n"
" (let\n"
" ((t9-4 format) (a0-5 #t) (a1-4 \"~Tbrother: ~A~%\") (v1-2 (-> arg0 brother)))\n"
" (t9-4 a0-5 a1-4 (if v1-2 (-> v1-2 0 self)))\n"
" )\n"
" (let\n"
" ((t9-5 format) (a0-6 #t) (a1-5 \"~Tchild: ~A~%\") (v1-4 (-> arg0 child)))\n"
" (t9-5 a0-6 a1-5 (if v1-4 (-> v1-4 0 self)))\n"
" )\n"
" arg0\n"
" )";
test_with_expr(func, type, expected, false, "process-tree",
@@ -619,13 +621,17 @@ TEST_F(FormRegressionTest, ExprMethod0Process) {
" daddiu sp, sp, 48";
std::string type = "(function symbol type basic int process)";
std::string expected =
"(begin\n"
" (set!\n"
" v0-0\n"
" (if\n"
" (= (-> arg0 type) symbol)\n"
" (object-new arg0 arg1 (the-as int (+ (-> process size) (the-as uint arg3))))\n"
" (+ (the-as int arg0) 4)\n"
"(let\n"
" ((v0-0\n"
" (if\n"
" (= (-> arg0 type) symbol)\n"
" (object-new\n"
" arg0\n"
" arg1\n"
" (the-as int (+ (-> process size) (the-as uint arg3)))\n"
" )\n"
" (+ (the-as int arg0) 4)\n"
" )\n"
" )\n"
" )\n"
" (set! (-> (the-as process v0-0) name) arg2)\n"
@@ -635,9 +641,11 @@ TEST_F(FormRegressionTest, ExprMethod0Process) {
" (set! (-> v0-0 allocated-length) arg3)\n"
" (set! (-> v0-0 top-thread) #f)\n"
" (set! (-> v0-0 main-thread) #f)\n"
" (set! v1-5 (-> v0-0 stack))\n"
" (set! (-> v0-0 heap-cur) v1-5)\n"
" (set! (-> v0-0 heap-base) v1-5)\n"
" (let\n"
" ((v1-5 (-> v0-0 stack)))\n"
" (set! (-> v0-0 heap-cur) v1-5)\n"
" (set! (-> v0-0 heap-base) v1-5)\n"
" )\n"
" (set! (-> v0-0 heap-top) (&-> v0-0 stack (-> v0-0 allocated-length)))\n"
" (set! (-> v0-0 stack-frame-top) (-> v0-0 heap-top))\n"
" (set! (-> v0-0 stack-frame-top) #f)\n"
@@ -711,15 +719,16 @@ TEST_F(FormRegressionTest, ExprInspectProcessHeap) {
std::string type = "(function process symbol)";
std::string expected =
"(begin\n"
" (set! s5-0 (&+ (-> arg0 heap-base) 4))\n"
" (while\n"
" (< (the-as int s5-0) (the-as int (-> arg0 heap-cur)))\n"
" (inspect (the-as basic s5-0))\n"
" (+! (the-as int s5-0) (logand -16 (+ (asize-of s5-0) 15)))\n"
" (let\n"
" ((s5-0 (&+ (-> arg0 heap-base) 4)))\n"
" (while\n"
" (< (the-as int s5-0) (the-as int (-> arg0 heap-cur)))\n"
" (inspect (the-as basic s5-0))\n"
" (+! (the-as int s5-0) (logand -16 (+ (asize-of s5-0) 15)))\n"
" )\n"
" )\n"
" #f\n"
" )\n"
"";
" )";
test_with_expr(func, type, expected, false, "", {},
parse_hint_json("[\t\t[4, [\"s5\", \"basic\"]],\n"
"\t\t[17, [\"s5\", \"int\"]]]"));
@@ -914,8 +923,8 @@ TEST_F(FormRegressionTest, ExprMethod0DeadPool) {
" daddiu sp, sp, 112";
std::string type = "(function symbol type int int basic dead-pool)";
std::string expected =
"(begin\n"
" (set! s3-0 (object-new arg0 arg1 (the-as int (-> arg1 size))))\n"
"(let\n"
" ((s3-0 (object-new arg0 arg1 (the-as int (-> arg1 size)))))\n"
" (set! (-> s3-0 name) arg4)\n"
" (set! (-> s3-0 mask) 256)\n"
" (set! (-> s3-0 parent) #f)\n"
@@ -923,18 +932,21 @@ TEST_F(FormRegressionTest, ExprMethod0DeadPool) {
" (set! (-> s3-0 child) #f)\n"
" (set! (-> s3-0 self) s3-0)\n"
" (set! (-> s3-0 ppointer) (&-> s3-0 self))\n"
" (set! s2-1 0)\n"
" (while\n"
" (< s2-1 arg2)\n"
" (set! s1-0 (-> s3-0 child))\n"
" (set! v1-5 ((method-of-type process new) arg0 process (quote dead) arg3))\n"
" (set! a0-3 v1-5)\n"
" (set! (-> s3-0 child) (if a0-3 (-> a0-3 ppointer)))\n"
" (set! a0-4 s3-0)\n"
" (set! (-> v1-5 parent) (if a0-4 (-> a0-4 ppointer)))\n"
" (set! (-> v1-5 pool) s3-0)\n"
" (set! (-> v1-5 brother) s1-0)\n"
" (+! s2-1 1)\n"
" (let\n"
" ((s2-1 0))\n"
" (while\n"
" (< s2-1 arg2)\n"
" (let\n"
" ((s1-0 (-> s3-0 child))\n"
" (v1-5 ((method-of-type process new) arg0 process (quote dead) arg3))\n"
" )\n"
" (let ((a0-3 v1-5)) (set! (-> s3-0 child) (if a0-3 (-> a0-3 ppointer))))\n"
" (let ((a0-4 s3-0)) (set! (-> v1-5 parent) (if a0-4 (-> a0-4 ppointer))))\n"
" (set! (-> v1-5 pool) s3-0)\n"
" (set! (-> v1-5 brother) s1-0)\n"
" )\n"
" (+! s2-1 1)\n"
" )\n"
" )\n"
" s3-0\n"
" )";
@@ -1039,28 +1051,31 @@ TEST_F(FormRegressionTest, ExprMethod14DeadPool) {
" jr ra\n"
" daddiu sp, sp, 64";
std::string type = "(function dead-pool type int process)";
// todo - why does one work but not the other??
std::string expected =
"(begin\n"
" (set! s4-0 (-> arg0 child))\n"
"(let\n"
" ((s4-0 (-> arg0 child)))\n"
" (when\n"
" (and (not s4-0) *debug-segment* (!= arg0 *debug-dead-pool*))\n"
" (set! s4-0 (get-process *debug-dead-pool* arg1 arg2))\n"
" (when\n"
" (if\n"
" s4-0\n"
" (set! t9-1 format)\n"
" (set! a0-2 0)\n"
" (set!\n"
" a1-2\n"
" \"WARNING: ~A ~A had to be allocated from the debug pool, because ~A was empty.~%\"\n"
" )\n"
" (set! a2-1 arg1)\n"
" (set! v1-6 s4-0)\n"
" (t9-1\n"
" a0-2\n"
" a1-2\n"
" a2-1\n"
" (if v1-6 (-> (the-as (pointer process-tree) v1-6) 0 self))\n"
" (-> arg0 name)\n"
" (let\n"
" ((t9-1 format)\n"
" (a0-2 0)\n"
" (a1-2\n"
" \"WARNING: ~A ~A had to be allocated from the debug pool, because ~A was empty.~%\"\n"
" )\n"
" (a2-1 arg1)\n"
" (v1-6 s4-0)\n"
" )\n"
" (t9-1\n"
" a0-2\n"
" a1-2\n"
" a2-1\n"
" (if v1-6 (-> (the-as (pointer process-tree) v1-6) 0 self))\n"
" (-> arg0 name)\n"
" )\n"
" )\n"
" )\n"
" )\n"
@@ -1214,17 +1229,17 @@ TEST_F(FormRegressionTest, ExprMethod0DeadPoolHeap) {
" daddiu sp, sp, 64";
std::string type = "(function symbol type basic int int dead-pool-heap)";
std::string expected =
"(begin\n"
" (set!\n"
" v0-0\n"
" (object-new\n"
" arg0\n"
" arg1\n"
" (the-as\n"
" int\n"
" (+\n"
" (+ (-> arg1 size) (the-as uint (logand -16 (+ (* 12 arg3) 15))))\n"
" (the-as uint arg4)\n"
"(let\n"
" ((v0-0\n"
" (object-new\n"
" arg0\n"
" arg1\n"
" (the-as\n"
" int\n"
" (+\n"
" (+ (-> arg1 size) (the-as uint (logand -16 (+ (* 12 arg3) 15))))\n"
" (the-as uint arg4)\n"
" )\n"
" )\n"
" )\n"
" )\n"
@@ -1237,13 +1252,17 @@ TEST_F(FormRegressionTest, ExprMethod0DeadPoolHeap) {
" (set! (-> v0-0 child) #f)\n"
" (set! (-> v0-0 self) v0-0)\n"
" (set! (-> v0-0 ppointer) (&-> v0-0 self))\n"
" (set! v1-4 arg3)\n"
" (while\n"
" (nonzero? v1-4)\n"
" (+! v1-4 -1)\n"
" (set! a0-4 (-> v0-0 process-list v1-4))\n"
" (set! (-> a0-4 process) *null-process*)\n"
" (set! (-> a0-4 next) (-> v0-0 process-list (+ v1-4 1)))\n"
" (let\n"
" ((v1-4 arg3))\n"
" (while\n"
" (nonzero? v1-4)\n"
" (+! v1-4 -1)\n"
" (let\n"
" ((a0-4 (-> v0-0 process-list v1-4)))\n"
" (set! (-> a0-4 process) *null-process*)\n"
" (set! (-> a0-4 next) (-> v0-0 process-list (+ v1-4 1)))\n"
" )\n"
" )\n"
" )\n"
" (set! (-> v0-0 dead-list next) (-> v0-0 process-list))\n"
" (set! (-> v0-0 alive-list process) #f)\n"
@@ -1255,10 +1274,7 @@ TEST_F(FormRegressionTest, ExprMethod0DeadPoolHeap) {
" (set! (-> v0-0 first-shrink) #f)\n"
" (set!\n"
" (-> v0-0 heap base)\n"
" (logand\n"
" -16\n"
" (the-as int (&+ (+ (the-as int v0-0) 115) (* 12 arg3)))\n"
" )\n"
" (logand -16 (the-as int (&+ (+ (the-as int v0-0) 115) (* 12 arg3))))\n"
" )\n"
" (set! (-> v0-0 heap current) (-> v0-0 heap base))\n"
" (set! (-> v0-0 heap top) (&+ (-> v0-0 heap base) arg4))\n"
@@ -1364,13 +1380,14 @@ TEST_F(FormRegressionTest, ExprMethod21DeadPoolHeap) {
" daddu sp, sp, r0";
std::string type = "(function dead-pool-heap dead-pool-heap-rec int)";
std::string expected =
"(cond\n"
" ((-> arg1 process)\n"
" (set!\n"
" v1-3\n"
" (&+\n"
" (&+ (-> arg1 process) (-> process size))\n"
" (-> arg1 process allocated-length)\n"
"(if\n"
" (-> arg1 process)\n"
" (let\n"
" ((v1-3\n"
" (&+\n"
" (&+ (-> arg1 process) (-> process size))\n"
" (-> arg1 process allocated-length)\n"
" )\n"
" )\n"
" )\n"
" (if\n"
@@ -1379,15 +1396,10 @@ TEST_F(FormRegressionTest, ExprMethod21DeadPoolHeap) {
" (- (-> arg0 heap top) (the-as uint (&+ v1-3 4)))\n"
" )\n"
" )\n"
" (else\n"
" (if\n"
" (-> arg1 next)\n"
" (-\n"
" (-> arg1 next process)\n"
" (the-as uint (&+ (-> arg0 heap base) 4))\n"
" )\n"
" (- (-> arg0 heap top) (the-as uint (-> arg0 heap base)))\n"
" )\n"
" (if\n"
" (-> arg1 next)\n"
" (- (-> arg1 next process) (the-as uint (&+ (-> arg0 heap base) 4)))\n"
" (- (-> arg0 heap top) (the-as uint (-> arg0 heap base)))\n"
" )\n"
" )";
test_with_expr(func, type, expected, false, "", {},
@@ -1524,44 +1536,48 @@ TEST_F(FormRegressionTest, ExprMethod3DeadPoolHeap) {
std::string type = "(function dead-pool-heap dead-pool-heap)";
std::string expected =
"(begin\n"
" (set! s5-0 (- (-> arg0 heap top) (the-as uint (-> arg0 heap base))))\n"
" (set!\n"
" v1-3\n"
" (if (-> arg0 alive-list prev) (gap-size arg0 (-> arg0 alive-list prev)) s5-0)\n"
" (let*\n"
" ((s5-0 (- (-> arg0 heap top) (the-as uint (-> arg0 heap base))))\n"
" (v1-3\n"
" (if\n"
" (-> arg0 alive-list prev)\n"
" (gap-size arg0 (-> arg0 alive-list prev))\n"
" s5-0\n"
" )\n"
" )\n"
" )\n"
" (format\n"
" #t\n"
" \"~Tprocess-list[0] @ #x~X ~D/~D bytes used~%\"\n"
" (-> arg0 process-list)\n"
" (- s5-0 v1-3)\n"
" s5-0\n"
" )\n"
" )\n"
" (format\n"
" #t\n"
" \"~Tprocess-list[0] @ #x~X ~D/~D bytes used~%\"\n"
" (-> arg0 process-list)\n"
" (- s5-0 v1-3)\n"
" s5-0\n"
" )\n"
" (set! s5-1 (-> arg0 alive-list))\n"
" (set! s4-0 0)\n"
" (while\n"
" s5-1\n"
" (if\n"
" (-> s5-1 process)\n"
" (format\n"
" #t\n"
" \"~T [~3D] #<dead-pool-heap-rec @ #x~X> ~A~%\"\n"
" s4-0\n"
" s5-1\n"
" (let\n"
" ((s5-1 (-> arg0 alive-list)) (s4-0 0))\n"
" (while\n"
" s5-1\n"
" (if\n"
" (-> s5-1 process)\n"
" (format\n"
" #t\n"
" \"~T [~3D] #<dead-pool-heap-rec @ #x~X> ~A~%\"\n"
" s4-0\n"
" s5-1\n"
" (-> s5-1 process)\n"
" )\n"
" )\n"
" )\n"
" (set! s3-0 (gap-size arg0 s5-1))\n"
" (if\n"
" (nonzero? s3-0)\n"
" (format\n"
" #t\n"
" \"~T gap: ~D bytes @ #x~X~%\"\n"
" s3-0\n"
" (gap-location arg0 s5-1)\n"
" (let\n"
" ((s3-0 (gap-size arg0 s5-1)))\n"
" (if\n"
" (nonzero? s3-0)\n"
" (format #t \"~T gap: ~D bytes @ #x~X~%\" s3-0 (gap-location arg0 s5-1))\n"
" )\n"
" )\n"
" (set! s5-1 (-> s5-1 next))\n"
" (+! s4-0 1)\n"
" )\n"
" (set! s5-1 (-> s5-1 next))\n"
" (+! s4-0 1)\n"
" )\n"
" arg0\n"
" )";
@@ -1683,8 +1699,8 @@ TEST_F(FormRegressionTest, ExprMethod25DeadPoolHeap) {
" daddiu sp, sp, 16";
std::string type = "(function dead-pool-heap int)";
std::string expected =
"(begin\n"
" (set! v1-0 (-> arg0 heap top))\n"
"(let\n"
" ((v1-0 (-> arg0 heap top)))\n"
" (if\n"
" (-> arg0 alive-list prev)\n"
" (gap-size arg0 (-> arg0 alive-list prev))\n"
@@ -1754,8 +1770,8 @@ TEST_F(FormRegressionTest, ExprMethod24DeadPoolHeap) {
" daddiu sp, sp, 64";
std::string type = "(function dead-pool-heap int dead-pool-heap-rec)";
std::string expected =
"(begin\n"
" (set! gp-0 (-> arg0 first-gap))\n"
"(let\n"
" ((gp-0 (-> arg0 first-gap)))\n"
" (while (and gp-0 (< (gap-size arg0 gp-0) arg1)) (set! gp-0 (-> gp-0 next)))\n"
" gp-0\n"
" )";
@@ -1966,63 +1982,69 @@ TEST_F(FormRegressionTest, ExprMethod14DeadPoolHeap) {
" daddiu sp, sp, 112";
std::string type = "(function dead-pool-heap type int process)";
std::string expected =
"(begin\n"
" (set! s4-0 (-> arg0 dead-list next))\n"
" (set! s3-0 #f)\n"
" (set! s1-0 (find-gap-by-size arg0 (+ (-> process size) (the-as uint arg2))))\n"
" (cond\n"
" ((and s4-0 s1-0)\n"
" (set! (-> arg0 dead-list next) (-> s4-0 next))\n"
" (set! v1-5 (-> s1-0 next))\n"
" (set! (-> s1-0 next) s4-0)\n"
" (set! (-> s4-0 next) v1-5)\n"
" (when v1-5 (set! (-> v1-5 prev) s4-0) (set! v1-6 s4-0))\n"
" (set! (-> s4-0 prev) s1-0)\n"
" (when\n"
" (= s1-0 (-> arg0 alive-list prev))\n"
" (set! (-> arg0 alive-list prev) s4-0)\n"
" (set! v1-9 s4-0)\n"
" )\n"
" (set! a0-4 (gap-location arg0 s1-0))\n"
" (set!\n"
" s3-0\n"
" ((method-of-type process new)\n"
" (the-as symbol a0-4)\n"
" process\n"
" (quote process)\n"
" arg2\n"
"(let\n"
" ((s4-0 (-> arg0 dead-list next)) (s3-0 #f))\n"
" (let\n"
" ((s1-0 (find-gap-by-size arg0 (+ (-> process size) (the-as uint arg2)))))\n"
" (cond\n"
" ((and s4-0 s1-0)\n"
" (set! (-> arg0 dead-list next) (-> s4-0 next))\n"
" (let\n"
" ((v1-5 (-> s1-0 next)))\n"
" (set! (-> s1-0 next) s4-0)\n"
" (set! (-> s4-0 next) v1-5)\n"
" (when v1-5 (set! (-> v1-5 prev) s4-0) (let ((v1-6 s4-0))))\n"
" )\n"
" )\n"
" (set! (-> s4-0 process) s3-0)\n"
" (set! (-> s3-0 ppointer) (&-> s4-0 process))\n"
" (if\n"
" (= (-> arg0 first-gap) s1-0)\n"
" (set! (-> arg0 first-gap) (find-gap arg0 s4-0))\n"
" )\n"
" (when\n"
" (or\n"
" (not (-> arg0 first-shrink))\n"
" (< (the-as int s3-0) (the-as int (-> arg0 first-shrink process)))\n"
" (set! (-> s4-0 prev) s1-0)\n"
" (when\n"
" (= s1-0 (-> arg0 alive-list prev))\n"
" (set! (-> arg0 alive-list prev) s4-0)\n"
" (let ((v1-9 s4-0)))\n"
" )\n"
" (set! (-> arg0 first-shrink) s4-0)\n"
" (set! v1-22 s4-0)\n"
" )\n"
" (set! (-> s3-0 parent) (-> arg0 ppointer))\n"
" (set! (-> s3-0 pool) arg0)\n"
" (set! (-> arg0 child) (&-> s4-0 process))\n"
" )\n"
" (else\n"
" (when\n"
" (and *debug-segment* (!= arg0 *debug-dead-pool*))\n"
" (set! s3-0 (get-process *debug-dead-pool* arg1 arg2))\n"
" (if\n"
" (and s3-0 *vis-boot*)\n"
" (format\n"
" 0\n"
" \"WARNING: ~A ~A had to be allocated from the debug pool, because ~A was empty.~%\"\n"
" arg1\n"
" (let\n"
" ((a0-4 (gap-location arg0 s1-0)))\n"
" (set!\n"
" s3-0\n"
" (-> arg0 name)\n"
" ((method-of-type process new)\n"
" (the-as symbol a0-4)\n"
" process\n"
" (quote process)\n"
" arg2\n"
" )\n"
" )\n"
" )\n"
" (set! (-> s4-0 process) s3-0)\n"
" (set! (-> s3-0 ppointer) (&-> s4-0 process))\n"
" (if\n"
" (= (-> arg0 first-gap) s1-0)\n"
" (set! (-> arg0 first-gap) (find-gap arg0 s4-0))\n"
" )\n"
" (when\n"
" (or\n"
" (not (-> arg0 first-shrink))\n"
" (< (the-as int s3-0) (the-as int (-> arg0 first-shrink process)))\n"
" )\n"
" (set! (-> arg0 first-shrink) s4-0)\n"
" (let ((v1-22 s4-0)))\n"
" )\n"
" (set! (-> s3-0 parent) (-> arg0 ppointer))\n"
" (set! (-> s3-0 pool) arg0)\n"
" (set! (-> arg0 child) (&-> s4-0 process))\n"
" )\n"
" (else\n"
" (when\n"
" (and *debug-segment* (!= arg0 *debug-dead-pool*))\n"
" (set! s3-0 (get-process *debug-dead-pool* arg1 arg2))\n"
" (if\n"
" (and s3-0 *vis-boot*)\n"
" (format\n"
" 0\n"
" \"WARNING: ~A ~A had to be allocated from the debug pool, because ~A was "
"empty.~%\"\n"
" arg1\n"
" s3-0\n"
" (-> arg0 name)\n"
" )\n"
" )\n"
" )\n"
" )\n"
@@ -2180,35 +2202,34 @@ TEST_F(FormRegressionTest, ExprMethod15DeadPoolHeap) {
" )\n"
" (change-parent arg1 arg0)\n"
" (set! (-> arg0 child) #f)\n"
" (set! s5-1 (-> arg1 ppointer))\n"
" (if\n"
" (or\n"
" (= (-> arg0 first-gap) s5-1)\n"
" (<\n"
" (the-as int (gap-location arg0 s5-1))\n"
" (the-as int (gap-location arg0 (-> arg0 first-gap)))\n"
" (let\n"
" ((s5-1 (-> arg1 ppointer)))\n"
" (if\n"
" (or\n"
" (= (-> arg0 first-gap) s5-1)\n"
" (<\n"
" (the-as int (gap-location arg0 s5-1))\n"
" (the-as int (gap-location arg0 (-> arg0 first-gap)))\n"
" )\n"
" )\n"
" (set! (-> arg0 first-gap) (-> s5-1 1))\n"
" )\n"
" (set! (-> arg0 first-gap) (-> s5-1 1))\n"
" )\n"
" (when\n"
" (= (-> arg0 first-shrink) s5-1)\n"
" (set! (-> arg0 first-shrink) (-> s5-1 1))\n"
" (when\n"
" (not (-> arg0 first-shrink process))\n"
" (set! (-> arg0 first-shrink) #f)\n"
" (= (-> arg0 first-shrink) s5-1)\n"
" (set! (-> arg0 first-shrink) (-> s5-1 1))\n"
" (when (not (-> arg0 first-shrink process)) (set! (-> arg0 first-shrink) #f))\n"
" )\n"
" (set! (-> s5-1 1 parent) (-> s5-1 2))\n"
" (if\n"
" (-> s5-1 2)\n"
" (set! (-> s5-1 2 mask) (-> s5-1 1))\n"
" (set! (-> arg0 alive-list prev) (-> s5-1 1))\n"
" )\n"
" (set! (-> s5-1 2) (-> arg0 dead-list next))\n"
" (set! (-> arg0 dead-list next) s5-1)\n"
" (set! (-> s5-1 0) *null-process*)\n"
" )\n"
" (set! (-> s5-1 1 parent) (-> s5-1 2))\n"
" (if\n"
" (-> s5-1 2)\n"
" (set! (-> s5-1 2 mask) (-> s5-1 1))\n"
" (set! (-> arg0 alive-list prev) (-> s5-1 1))\n"
" )\n"
" (set! (-> s5-1 2) (-> arg0 dead-list next))\n"
" (set! (-> arg0 dead-list next) s5-1)\n"
" (set! (-> s5-1 0) *null-process*)\n"
" (set! v0-4 0)\n"
" (let ((v0-4 0)))\n"
" )";
test_with_expr(func, type, expected, false, "",
{{"L297", "ERROR: process ~A does not belong to dead-pool-heap ~A.~%"}});
@@ -2305,30 +2326,32 @@ TEST_F(FormRegressionTest, ExprMethod17DeadPoolHeap) {
std::string expected =
"(begin\n"
" (when\n"
" (if\n"
" arg1\n"
" (set! s5-0 (-> arg1 ppointer))\n"
" (when\n"
" (not\n"
" (or\n"
" (nonzero? (logand (-> arg1 mask) 512))\n"
" (and (not (-> arg1 next-state)) (not (-> arg1 state)))\n"
" (let\n"
" ((s5-0 (-> arg1 ppointer)))\n"
" (when\n"
" (not\n"
" (or\n"
" (nonzero? (logand (-> arg1 mask) 512))\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! (-> arg0 first-gap) (find-gap arg0 s5-0))\n"
" )\n"
" (set! (-> arg1 mask) (logior (-> arg1 mask) 512))\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! (-> arg0 first-gap) (find-gap arg0 s5-0))\n"
" (= (-> arg0 first-shrink) s5-0)\n"
" (set! (-> arg0 first-shrink) (-> s5-0 2))\n"
" )\n"
" (set! (-> arg1 mask) (logior (-> arg1 mask) 512))\n"
" )\n"
" (if\n"
" (= (-> arg0 first-shrink) s5-0)\n"
" (set! (-> arg0 first-shrink) (-> s5-0 2))\n"
" )\n"
" )\n"
" arg0\n"
@@ -2528,49 +2551,57 @@ TEST_F(FormRegressionTest, ExprMethod16DeadPoolHeap) {
std::string expected =
"(begin\n"
" (set! s4-0 (memory-free arg0))\n"
" (set! v1-2 (memory-total arg0))\n"
" (set! f0-2 (/ (the float s4-0) (the float v1-2)))"
" (cond\n"
" ((< f0-2 (l.f L346))\n"
" (set! arg1 1000)\n"
" (if\n"
" (and *debug-segment* (-> *kernel-context* low-memory-message))\n"
" (format *stdcon* \"~3LLow Actor Memory~%~0L\" a2-0)\n" // ~3L tricks it.
" )\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"
" (cond\n"
" ((< f0-2 (l.f L346))\n"
" (set! arg1 1000)\n"
" (if\n"
" (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)) (let ((v1-10 arg1))))\n"
" ((< f0-2 (l.f L348)) (set! arg1 (shl arg1 1)) (let ((v1-12 arg1))))\n"
" )\n"
" ((< f0-2 (l.f L347)) (set! arg1 (shl arg1 2)) (set! v1-10 arg1))\n"
" ((< f0-2 (l.f L348)) (set! arg1 (shl arg1 1)) (set! v1-12 arg1))\n"
" )\n"
" (set! (-> arg0 compact-count-targ) arg1)\n"
" (set! (-> arg0 compact-count) 0)\n"
" (while\n"
" (nonzero? arg1)\n"
" (+! arg1 -1)\n"
" (set! v1-13 (-> arg0 first-shrink))\n"
" (when\n"
" (not v1-13)\n"
" (set! v1-13 (-> arg0 alive-list next))\n"
" (set! (-> arg0 first-shrink) v1-13)\n"
" (set! a0-5 v1-13)\n"
" )\n"
" (if v1-13 (shrink-heap arg0 (-> v1-13 process)))\n"
" (set! s4-1 (-> arg0 first-gap))\n"
" (when\n"
" (-> s4-1 next)\n"
" (set! s3-0 (-> s4-1 next process))\n"
" (set! s2-0 (gap-size arg0 s4-1))\n"
" (let\n"
" ((v1-13 (-> arg0 first-shrink)))\n"
" (when\n"
" (nonzero? s2-0)\n"
" (when (< s2-0 0) (break!) (set! v1-20 0))\n"
" (shrink-heap arg0 s3-0)\n"
" (relocate s3-0 (- s2-0))\n"
" (set! (-> arg0 first-gap) (find-gap arg0 s4-1))\n"
" (set! (-> arg0 compact-count) (+ (-> arg0 compact-count) 1))\n"
" (not v1-13)\n"
" (set! v1-13 (-> arg0 alive-list next))\n"
" (set! (-> arg0 first-shrink) v1-13)\n"
" (let ((a0-5 v1-13)))\n"
" )\n"
" (if v1-13 (shrink-heap arg0 (-> v1-13 process)))\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"
" (shrink-heap arg0 s3-0)\n"
" (relocate s3-0 (- s2-0))\n"
" (set! (-> arg0 first-gap) (find-gap arg0 s4-1))\n"
" (set! (-> arg0 compact-count) (+ (-> arg0 compact-count) 1))\n"
" )\n"
" )\n"
" )\n"
" )\n"
" )\n"
" (set! v0-8 0)\n"
" (let ((v0-8 0)))\n"
" )";
test_with_expr(func, type, expected, false, "", {{"L296", "~3LLow Actor Memory~%~0L"}});
}
@@ -2723,50 +2754,56 @@ TEST_F(FormRegressionTest, ExprMethod18DeadPoolHeap) {
" (while\n"
" (nonzero? arg1)\n"
" (+! arg1 -1)\n"
" (set! s4-0 (-> arg0 alive-list next))\n"
" (when\n"
" s4-0\n"
" (if\n"
" (or\n"
" (= (-> arg0 first-gap) s4-0)\n"
" (<\n"
" (the-as int (gap-location arg0 s4-0))\n"
" (the-as int (gap-location arg0 (-> arg0 first-gap)))\n"
" (let\n"
" ((s4-0 (-> arg0 alive-list next)))\n"
" (when\n"
" s4-0\n"
" (if\n"
" (or\n"
" (= (-> arg0 first-gap) s4-0)\n"
" (<\n"
" (the-as int (gap-location arg0 s4-0))\n"
" (the-as int (gap-location arg0 (-> arg0 first-gap)))\n"
" )\n"
" )\n"
" (set! (-> arg0 first-gap) (-> s4-0 prev))\n"
" )\n"
" (when\n"
" (= (-> arg0 first-shrink) s4-0)\n"
" (set! (-> arg0 first-shrink) (-> s4-0 prev))\n"
" (when\n"
" (not (-> arg0 first-shrink process))\n"
" (set! (-> arg0 first-shrink) #f)\n"
" )\n"
" )\n"
" (set! (-> arg0 first-gap) (-> s4-0 prev))\n"
" )\n"
" (when\n"
" (= (-> arg0 first-shrink) s4-0)\n"
" (set! (-> arg0 first-shrink) (-> s4-0 prev))\n"
" (when\n"
" (not (-> arg0 first-shrink process))\n"
" (set! (-> arg0 first-shrink) #f)\n"
" (set! (-> s4-0 prev next) (-> s4-0 next))\n"
" (if\n"
" (-> s4-0 next)\n"
" (set! (-> s4-0 next prev) (-> s4-0 prev))\n"
" (set! (-> arg0 alive-list prev) (-> s4-0 prev))\n"
" )\n"
" )\n"
" (set! (-> s4-0 prev next) (-> s4-0 next))\n"
" (if\n"
" (-> s4-0 next)\n"
" (set! (-> s4-0 next prev) (-> s4-0 prev))\n"
" (set! (-> arg0 alive-list prev) (-> s4-0 prev))\n"
" )\n"
" (set! a1-3 (-> arg0 alive-list prev))\n"
" (set! v1-19 (-> a1-3 next))\n"
" (set! (-> a1-3 next) s4-0)\n"
" (set! (-> s4-0 next) v1-19)\n"
" (when v1-19 (set! (-> v1-19 prev) s4-0) (set! v1-20 s4-0))\n"
" (set! (-> s4-0 prev) a1-3)\n"
" (set! (-> arg0 alive-list prev) s4-0)\n"
" (set!\n"
" (-> s4-0 process)\n"
" (relocate\n"
" (-> s4-0 process)\n"
" (- (gap-location arg0 a1-3) (the-as uint (&-> (-> s4-0 process) type)))\n"
" (let\n"
" ((a1-3 (-> arg0 alive-list prev)))\n"
" (let\n"
" ((v1-19 (-> a1-3 next)))\n"
" (set! (-> a1-3 next) s4-0)\n"
" (set! (-> s4-0 next) v1-19)\n"
" (when v1-19 (set! (-> v1-19 prev) s4-0) (let ((v1-20 s4-0))))\n"
" )\n"
" (set! (-> s4-0 prev) a1-3)\n"
" (set! (-> arg0 alive-list prev) s4-0)\n"
" (set!\n"
" (-> s4-0 process)\n"
" (relocate\n"
" (-> s4-0 process)\n"
" (- (gap-location arg0 a1-3) (the-as uint (&-> (-> s4-0 process) type)))\n"
" )\n"
" )\n"
" )\n"
" )\n"
" )\n"
" )\n"
" (set! v0-4 0)\n"
" (let ((v0-4 0)))\n"
" )";
test_with_expr(func, type, expected);
}
+3 -3
View File
@@ -94,11 +94,11 @@ TEST_F(FormRegressionTest, ExprSeek) {
" daddu sp, sp, r0";
std::string type = "(function float float float float)";
std::string expected =
"(begin\n"
" (set! f2-0 (- arg1 arg0))\n"
"(let\n"
" ((f2-0 (- arg1 arg0)))\n"
" (cond\n"
" ((>= arg2 (fabs f2-0)) arg1)\n"
" ((>= f2-0 0.000000) (+ arg0 arg2))\n"
" ((>= f2-0 0.0) (+ arg0 arg2))\n"
" (else (- arg0 arg2))\n"
" )\n"
" )";
+16 -1
View File
@@ -40,7 +40,20 @@ const std::unordered_set<std::string> expected_skip_in_decompiler = {
const std::unordered_set<std::string> skip_in_compiling = {
// these functions are not implemented by the compiler in OpenGOAL, but are in GOAL.
"abs", "ash", "min", "max", "lognor", "(method 3 vec4s)", "(method 2 vec4s)"};
"abs", "ash", "min", "max", "lognor",
// these require 128-bit integers. We want these eventually, but disabling for now to focus
// on more important issues.
"(method 3 vec4s)", "(method 2 vec4s)",
// these should pass eventually
"(method 2 array)", "(method 3 array)", "valid?", "mem-copy!", "qmem-copy<-!", "qmem-copy->!",
"mem-or!", "breakpoint-range-set!", "print", "printl", "inspect"};
// The decompiler does not attempt to insert forward definitions, as this would be part of an
// unimplemented full-program type analysis pass. For now, we manually specify all functions
// that should have a forward definition here.
const std::string g_forward_type_defs =
"(define-extern name= (function basic basic symbol))\n"
"(define-extern fact (function int int))";
// default location for the data. It can be changed with a command line argument.
std::string g_iso_data_path = "";
@@ -321,6 +334,8 @@ TEST_F(OfflineDecompilation, Reference) {
TEST_F(OfflineDecompilation, Compile) {
Compiler compiler;
compiler.run_front_end_on_string(g_forward_type_defs);
for (auto& file : g_object_files_to_check_against_reference) {
auto& obj_l = db->obj_files_by_name.at(file);
ASSERT_EQ(obj_l.size(), 1);