From 30826876223d379bf0e028f049aeb9c5bc24574f Mon Sep 17 00:00:00 2001 From: Kenneth Moon Date: Wed, 6 Nov 2024 11:44:22 -0500 Subject: [PATCH] Update tests to include ir --- .../test_capture_nested_quote.txt | 6 ++ .../test_captured_closure.txt | 13 ++++ .../test_metaprogramming/test_conditional.txt | 8 +++ .../test_constant_lifting.txt | 4 ++ .../test_local_externs.txt | 4 ++ .../test_proc_shadowing.txt | 28 ++++++++ .../test_quote_complex_expr.txt | 4 ++ .../test_quote_elision.txt | 4 ++ .../test_scope_collision1.txt | 6 ++ .../test_scope_collision2.txt | 4 ++ .../test_scope_nesting.txt | 4 ++ .../test_metaprogramming/test_scoping.txt | 4 ++ .../test_statement_assignment.txt | 7 ++ .../test_metaprogramming/test_type_params.txt | 16 +++++ .../test_type_quote_elision.txt | 5 ++ .../test_metaprogramming/test_unary_ops.txt | 4 ++ .../test_unquote_elision.txt | 4 ++ .../test_unquote_in_slice.txt | 7 ++ .../test_unquote_index_tuple.txt | 8 +++ .../test_unquote_slice_object1.txt | 11 +++ .../test_metaprogramming/test_unrolling.txt | 15 +++++ tests/test_metaprogramming.py | 67 ++++++++++++------- 22 files changed, 207 insertions(+), 26 deletions(-) create mode 100644 tests/golden/test_metaprogramming/test_proc_shadowing.txt diff --git a/tests/golden/test_metaprogramming/test_capture_nested_quote.txt b/tests/golden/test_metaprogramming/test_capture_nested_quote.txt index ca9b81a5..56a54d49 100644 --- a/tests/golden/test_metaprogramming/test_capture_nested_quote.txt +++ b/tests/golden/test_metaprogramming/test_capture_nested_quote.txt @@ -1,3 +1,9 @@ +EXO IR: +def foo(a: i32 @ DRAM): + a = 2 + a = 2 + a = 2 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_captured_closure.txt b/tests/golden/test_metaprogramming/test_captured_closure.txt index 20390796..569653d3 100644 --- a/tests/golden/test_metaprogramming/test_captured_closure.txt +++ b/tests/golden/test_metaprogramming/test_captured_closure.txt @@ -1,3 +1,16 @@ +EXO IR: +def bar(a: i32 @ DRAM): + a += 1 + a += 2 + a += 3 + a += 4 + a += 5 + a += 6 + a += 7 + a += 8 + a += 9 + a += 10 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_conditional.txt b/tests/golden/test_metaprogramming/test_conditional.txt index 8f2b476b..7e3473e5 100644 --- a/tests/golden/test_metaprogramming/test_conditional.txt +++ b/tests/golden/test_metaprogramming/test_conditional.txt @@ -1,3 +1,11 @@ +EXO IR: +def bar1(a: i8 @ DRAM): + b: i8 @ DRAM + b += 1 +def bar2(a: i8 @ DRAM): + b: i8 @ DRAM + b = 0 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_constant_lifting.txt b/tests/golden/test_metaprogramming/test_constant_lifting.txt index 0f25fad1..5ac001ad 100644 --- a/tests/golden/test_metaprogramming/test_constant_lifting.txt +++ b/tests/golden/test_metaprogramming/test_constant_lifting.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: f64 @ DRAM): + a = 2.0818897486445276 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_local_externs.txt b/tests/golden/test_metaprogramming/test_local_externs.txt index 1c9d31d3..504175e7 100644 --- a/tests/golden/test_metaprogramming/test_local_externs.txt +++ b/tests/golden/test_metaprogramming/test_local_externs.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: f64 @ DRAM): + a = sin(a) +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_proc_shadowing.txt b/tests/golden/test_metaprogramming/test_proc_shadowing.txt new file mode 100644 index 00000000..5a3d3670 --- /dev/null +++ b/tests/golden/test_metaprogramming/test_proc_shadowing.txt @@ -0,0 +1,28 @@ +EXO IR: +def foo(a: f32 @ DRAM): + sin(a) +C: +#include "test.h" + +#include +#include + +// sin( +// a : f32 @DRAM +// ) +static void sin( void *ctxt, float* a ); + +// foo( +// a : f32 @DRAM +// ) +void foo( void *ctxt, float* a ) { +sin(ctxt,a); +} + +// sin( +// a : f32 @DRAM +// ) +static void sin( void *ctxt, float* a ) { +*a = 0.0f; +} + diff --git a/tests/golden/test_metaprogramming/test_quote_complex_expr.txt b/tests/golden/test_metaprogramming/test_quote_complex_expr.txt index 3f3c8626..b111df4f 100644 --- a/tests/golden/test_metaprogramming/test_quote_complex_expr.txt +++ b/tests/golden/test_metaprogramming/test_quote_complex_expr.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: i32 @ DRAM): + a = a + 1 + 1 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_quote_elision.txt b/tests/golden/test_metaprogramming/test_quote_elision.txt index da671d39..a22821c7 100644 --- a/tests/golden/test_metaprogramming/test_quote_elision.txt +++ b/tests/golden/test_metaprogramming/test_quote_elision.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: i32 @ DRAM, b: i32 @ DRAM): + b = a +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_scope_collision1.txt b/tests/golden/test_metaprogramming/test_scope_collision1.txt index 89ba4b00..c2d6b20c 100644 --- a/tests/golden/test_metaprogramming/test_scope_collision1.txt +++ b/tests/golden/test_metaprogramming/test_scope_collision1.txt @@ -1,3 +1,9 @@ +EXO IR: +def foo(a: i32 @ DRAM): + b: i32 @ DRAM + b = 2 + a = 1 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_scope_collision2.txt b/tests/golden/test_metaprogramming/test_scope_collision2.txt index da671d39..a22821c7 100644 --- a/tests/golden/test_metaprogramming/test_scope_collision2.txt +++ b/tests/golden/test_metaprogramming/test_scope_collision2.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: i32 @ DRAM, b: i32 @ DRAM): + b = a +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_scope_nesting.txt b/tests/golden/test_metaprogramming/test_scope_nesting.txt index db2f5260..0ae39ca1 100644 --- a/tests/golden/test_metaprogramming/test_scope_nesting.txt +++ b/tests/golden/test_metaprogramming/test_scope_nesting.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: i8 @ DRAM, b: i8 @ DRAM): + a = b +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_scoping.txt b/tests/golden/test_metaprogramming/test_scoping.txt index 8679fce5..331db00a 100644 --- a/tests/golden/test_metaprogramming/test_scoping.txt +++ b/tests/golden/test_metaprogramming/test_scoping.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: i8 @ DRAM): + a = 3 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_statement_assignment.txt b/tests/golden/test_metaprogramming/test_statement_assignment.txt index 71f64950..a8ea5b1a 100644 --- a/tests/golden/test_metaprogramming/test_statement_assignment.txt +++ b/tests/golden/test_metaprogramming/test_statement_assignment.txt @@ -1,3 +1,10 @@ +EXO IR: +def foo(a: i32 @ DRAM): + a += 1 + a += 2 + a += 1 + a += 2 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_type_params.txt b/tests/golden/test_metaprogramming/test_type_params.txt index 23b4b196..98c6282a 100644 --- a/tests/golden/test_metaprogramming/test_type_params.txt +++ b/tests/golden/test_metaprogramming/test_type_params.txt @@ -1,3 +1,19 @@ +EXO IR: +def bar1(a: i32 @ DRAM, b: i8 @ DRAM): + c: i32[4] @ DRAM + for i in seq(0, 3): + d: i32 @ DRAM + d = b + c[i + 1] = a + c[i] * d + a = c[3] +def bar2(a: f64 @ DRAM, b: f64 @ DRAM): + c: f64[4] @ DRAM + for i in seq(0, 3): + d: f64 @ DRAM + d = b + c[i + 1] = a + c[i] * d + a = c[3] +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_type_quote_elision.txt b/tests/golden/test_metaprogramming/test_type_quote_elision.txt index 5db02aca..d9173f3d 100644 --- a/tests/golden/test_metaprogramming/test_type_quote_elision.txt +++ b/tests/golden/test_metaprogramming/test_type_quote_elision.txt @@ -1,3 +1,8 @@ +EXO IR: +def foo(a: i8 @ DRAM, x: i8[2] @ DRAM): + a += x[0] + a += x[1] +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_unary_ops.txt b/tests/golden/test_metaprogramming/test_unary_ops.txt index 456b67fc..028ac6f3 100644 --- a/tests/golden/test_metaprogramming/test_unary_ops.txt +++ b/tests/golden/test_metaprogramming/test_unary_ops.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: i32 @ DRAM): + a = -2 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_unquote_elision.txt b/tests/golden/test_metaprogramming/test_unquote_elision.txt index da220cec..71079913 100644 --- a/tests/golden/test_metaprogramming/test_unquote_elision.txt +++ b/tests/golden/test_metaprogramming/test_unquote_elision.txt @@ -1,3 +1,7 @@ +EXO IR: +def foo(a: i32 @ DRAM): + a = a * 2 +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_unquote_in_slice.txt b/tests/golden/test_metaprogramming/test_unquote_in_slice.txt index bc7554eb..de0fc0e9 100644 --- a/tests/golden/test_metaprogramming/test_unquote_in_slice.txt +++ b/tests/golden/test_metaprogramming/test_unquote_in_slice.txt @@ -1,3 +1,10 @@ +EXO IR: +def foo(a: [i8][2] @ DRAM): + a[0] += a[1] +def bar(a: i8[10, 10] @ DRAM): + for i in seq(0, 5): + foo(a[i, 2:4]) +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_unquote_index_tuple.txt b/tests/golden/test_metaprogramming/test_unquote_index_tuple.txt index ead0c0db..49abf306 100644 --- a/tests/golden/test_metaprogramming/test_unquote_index_tuple.txt +++ b/tests/golden/test_metaprogramming/test_unquote_index_tuple.txt @@ -1,3 +1,11 @@ +EXO IR: +def foo(a: [i8][2, 2] @ DRAM): + a[0, 0] += a[0, 1] + a[1, 0] += a[1, 1] +def bar(a: i8[10, 10, 10] @ DRAM): + for i in seq(0, 7): + foo(a[i, i:i + 2, i + 1:i + 3]) +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_unquote_slice_object1.txt b/tests/golden/test_metaprogramming/test_unquote_slice_object1.txt index 37da11d2..ea4f9798 100644 --- a/tests/golden/test_metaprogramming/test_unquote_slice_object1.txt +++ b/tests/golden/test_metaprogramming/test_unquote_slice_object1.txt @@ -1,3 +1,14 @@ +EXO IR: +def foo(a: [i8][2] @ DRAM): + a[0] += a[1] +def bar(a: i8[10, 10] @ DRAM): + for i in seq(0, 10): + foo(a[i, 1:3]) + for i in seq(0, 10): + foo(a[i, 5:7]) + for i in seq(0, 10): + foo(a[i, 2:4]) +C: #include "test.h" #include diff --git a/tests/golden/test_metaprogramming/test_unrolling.txt b/tests/golden/test_metaprogramming/test_unrolling.txt index f556b8d5..136c770c 100644 --- a/tests/golden/test_metaprogramming/test_unrolling.txt +++ b/tests/golden/test_metaprogramming/test_unrolling.txt @@ -1,3 +1,18 @@ +EXO IR: +def foo(a: i8 @ DRAM): + b: i8 @ DRAM + b = 0 + b += a + b += a + b += a + b += a + b += a + b += a + b += a + b += a + b += a + b += a +C: #include "test.h" #include diff --git a/tests/test_metaprogramming.py b/tests/test_metaprogramming.py index 2f98796e..d869480e 100644 --- a/tests/test_metaprogramming.py +++ b/tests/test_metaprogramming.py @@ -19,7 +19,7 @@ def foo(a: i8): c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_conditional(golden): @@ -37,10 +37,11 @@ def bar(a: i8): return bar - c_file, _ = compile_procs_to_strings( - [rename(foo(False), "bar1"), rename(foo(True), "bar2")], "test.h" - ) - assert c_file == golden + bar1 = rename(foo(False), "bar1") + bar2 = rename(foo(True), "bar2") + + c_file, _ = compile_procs_to_strings([bar1, bar2], "test.h") + assert f"EXO IR:\n{str(bar1)}\n{str(bar2)}\nC:\n{c_file}" == golden def test_scoping(golden): @@ -51,7 +52,7 @@ def foo(a: i8): a = {a} c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_scope_nesting(golden): @@ -65,7 +66,7 @@ def foo(a: i8, b: i8): a = {~{b} if x == 3 and y == 2 else ~{a}} c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_global_scope(): @@ -92,7 +93,7 @@ def foo(a: f64): a = {(x**x + x) / x} c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_type_params(golden): @@ -108,10 +109,11 @@ def bar(a: {T}, b: {U}): return bar - c_file, _ = compile_procs_to_strings( - [rename(foo("i32", "i8"), "bar1"), rename(foo("f64", "f64"), "bar2")], "test.h" - ) - assert c_file == golden + bar1 = rename(foo("i32", "i8"), "bar1") + bar2 = rename(foo("f64", "f64"), "bar2") + + c_file, _ = compile_procs_to_strings([bar1, bar2], "test.h") + assert f"EXO IR:\n{str(bar1)}\n{str(bar2)}\nC:\n{c_file}" == golden def test_captured_closure(golden): @@ -129,7 +131,7 @@ def bar(a: i32): a += {cell[0]} c_file, _ = compile_procs_to_strings([bar], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(bar)}\nC:\n{c_file}" == golden def test_capture_nested_quote(golden): @@ -143,7 +145,7 @@ def foo(a: i32): a = {a} c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_quote_elision(golden): @@ -158,7 +160,7 @@ def bar(): b = {bar()} c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_unquote_elision(golden): @@ -170,7 +172,7 @@ def foo(a: i32): a = a * x c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_scope_collision1(golden): @@ -187,7 +189,7 @@ def foo(a: i32): a = c c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_scope_collision2(golden): @@ -199,7 +201,7 @@ def foo(a: i32, b: i32): b = a c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_scope_collision3(): @@ -225,7 +227,7 @@ def foo(a: T, x: T[2]): a += x[1] c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_unquote_in_slice(golden): @@ -242,7 +244,7 @@ def bar(a: i8[10, 10]): foo(a[i, {x} : {2 * x}]) c_file, _ = compile_procs_to_strings([foo, bar], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\n{str(bar)}\nC:\n{c_file}" == golden def test_unquote_slice_object1(golden): @@ -259,7 +261,7 @@ def bar(a: i8[10, 10]): foo(a[i, s]) c_file, _ = compile_procs_to_strings([foo, bar], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\n{str(bar)}\nC:\n{c_file}" == golden def test_unquote_slice_object2(): @@ -294,7 +296,7 @@ def get_index(i): foo(a[i, {get_index(i)}]) c_file, _ = compile_procs_to_strings([foo, bar], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\n{str(bar)}\nC:\n{c_file}" == golden def test_unquote_err(): @@ -320,7 +322,7 @@ def bar(x): a = {bar(~{a + 1})} c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_statement_assignment(golden): @@ -339,7 +341,7 @@ def foo(a: i32): {s} c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_statement_in_expr(): @@ -403,7 +405,7 @@ def foo(a: i32): a = x c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_return_in_async(): @@ -425,7 +427,7 @@ def foo(a: f64): a = my_sin(a) c_file, _ = compile_procs_to_strings([foo], "test.h") - assert c_file == golden + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden def test_unquote_multiple_exprs(): @@ -498,3 +500,16 @@ def foo(a: i32[20]): x = "0" with exo: a[x] = 0 + + +def test_proc_shadowing(golden): + @proc + def sin(a: f32): + a = 0 + + @proc + def foo(a: f32): + sin(a) + + c_file, _ = compile_procs_to_strings([foo], "test.h") + assert f"EXO IR:\n{str(foo)}\nC:\n{c_file}" == golden