diff --git a/crates/mun_codegen/src/snapshots/test__binary_expressions_file_ir.snap b/crates/mun_codegen/src/snapshots/test__binary_expressions.snap similarity index 52% rename from crates/mun_codegen/src/snapshots/test__binary_expressions_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__binary_expressions.snap index b6a85560a..d289bedf5 100644 --- a/crates/mun_codegen/src/snapshots/test__binary_expressions_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__binary_expressions.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn add(a:int, b:int):int {\n a+b\n}\n\nfn subtract(a:int, b:int):int {\n a-b\n}\n\nfn multiply(a:int, b:int):int {\n a*b\n}" +expression: "fn add(a:int, b:int)->int {\n a+b\n}\n\nfn subtract(a:int, b:int)->int {\n a-b\n}\n\nfn multiply(a:int, b:int)->int {\n a*b\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -23,3 +24,8 @@ body: ret i64 %mul } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__binary_expressions_group_ir.snap b/crates/mun_codegen/src/snapshots/test__binary_expressions_group_ir.snap deleted file mode 100644 index cc5524683..000000000 --- a/crates/mun_codegen/src/snapshots/test__binary_expressions_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn add(a:int, b:int):int {\n a+b\n}\n\nfn subtract(a:int, b:int):int {\n a-b\n}\n\nfn multiply(a:int, b:int):int {\n a*b\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__conditional_return_expr_file_ir.snap b/crates/mun_codegen/src/snapshots/test__conditional_return_expr.snap similarity index 61% rename from crates/mun_codegen/src/snapshots/test__conditional_return_expr_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__conditional_return_expr.snap index fe7edca9c..c8eb7e782 100644 --- a/crates/mun_codegen/src/snapshots/test__conditional_return_expr_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__conditional_return_expr.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n if a > 4 {\n return a;\n }\n a - 1\n}" +expression: "fn main(a:int)->int {\n if a > 4 {\n return a;\n }\n a - 1\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -18,3 +19,8 @@ if_merge: ; preds = %body ret i64 %sub } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__conditional_return_expr_group_ir.snap b/crates/mun_codegen/src/snapshots/test__conditional_return_expr_group_ir.snap deleted file mode 100644 index 5de1e82ea..000000000 --- a/crates/mun_codegen/src/snapshots/test__conditional_return_expr_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n if a > 4 {\n return a;\n }\n a - 1\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__equality_operands_file_ir.snap b/crates/mun_codegen/src/snapshots/test__equality_operands.snap similarity index 58% rename from crates/mun_codegen/src/snapshots/test__equality_operands_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__equality_operands.snap index e1df58b00..928669ba5 100644 --- a/crates/mun_codegen/src/snapshots/test__equality_operands_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__equality_operands.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn equals(a:int, b:int):bool { a == b }\nfn not_equals(a:int, b:int):bool { a != b }\nfn less(a:int, b:int):bool { a < b }\nfn less_equal(a:int, b:int):bool { a <= b }\nfn greater(a:int, b:int):bool { a > b }\nfn greater_equal(a:int, b:int):bool { a >= b }\nfn equalsf(a:float, b:float):bool { a == b }\nfn not_equalsf(a:float, b:float):bool { a != b }\nfn lessf(a:float, b:float):bool { a < b }\nfn less_equalf(a:float, b:float):bool { a <= b }\nfn greaterf(a:float, b:float):bool { a > b }\nfn greater_equalf(a:float, b:float):bool { a >= b }" +expression: "fn equals(a:int, b:int)->bool { a == b }\nfn not_equals(a:int, b:int)->bool { a != b }\nfn less(a:int, b:int)->bool { a < b }\nfn less_equal(a:int, b:int)->bool { a <= b }\nfn greater(a:int, b:int)->bool { a > b }\nfn greater_equal(a:int, b:int)->bool { a >= b }\nfn equalsf(a:float, b:float)->bool { a == b }\nfn not_equalsf(a:float, b:float)->bool { a != b }\nfn lessf(a:float, b:float)->bool { a < b }\nfn less_equalf(a:float, b:float)->bool { a <= b }\nfn greaterf(a:float, b:float)->bool { a > b }\nfn greater_equalf(a:float, b:float)->bool { a >= b }" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -77,3 +78,8 @@ body: ret i1 %greatereq } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__equality_operands_group_ir.snap b/crates/mun_codegen/src/snapshots/test__equality_operands_group_ir.snap deleted file mode 100644 index 9e8674043..000000000 --- a/crates/mun_codegen/src/snapshots/test__equality_operands_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn equals(a:int, b:int):bool { a == b }\nfn not_equals(a:int, b:int):bool { a != b }\nfn less(a:int, b:int):bool { a < b }\nfn less_equal(a:int, b:int):bool { a <= b }\nfn greater(a:int, b:int):bool { a > b }\nfn greater_equal(a:int, b:int):bool { a >= b }\nfn equalsf(a:float, b:float):bool { a == b }\nfn not_equalsf(a:float, b:float):bool { a != b }\nfn lessf(a:float, b:float):bool { a < b }\nfn less_equalf(a:float, b:float):bool { a <= b }\nfn greaterf(a:float, b:float):bool { a > b }\nfn greater_equalf(a:float, b:float):bool { a >= b }" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__extern_fn.snap b/crates/mun_codegen/src/snapshots/test__extern_fn.snap new file mode 100644 index 000000000..f1c30f0f2 --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__extern_fn.snap @@ -0,0 +1,34 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "extern fn add(a:int, b:int) -> int;\nfn main() {\n add(3,4);\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +%DispatchTable = type { i64 (i64, i64)* } +%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } + +@dispatchTable = external global %DispatchTable +@global_type_table = external global [1 x %struct.MunTypeInfo addrspace(4)*] + +define void @main() { +body: + %add_ptr = load i64 (i64, i64)*, i64 (i64, i64)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) + %add = call i64 %add_ptr(i64 3, i64 4) + ret void +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + +%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } +%DispatchTable = type { i64 (i64, i64)* } + +@"type_info::::name" = private unnamed_addr constant [10 x i8] c"core::i64\00" +@"type_info::" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::::name", i32 64, i8 8, i8 0 } +@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::"] +@dispatchTable = global %DispatchTable zeroinitializer + diff --git a/crates/mun_codegen/src/snapshots/test__extern_fn_file_ir.snap b/crates/mun_codegen/src/snapshots/test__extern_fn_file_ir.snap deleted file mode 100644 index f5abbe3f1..000000000 --- a/crates/mun_codegen/src/snapshots/test__extern_fn_file_ir.snap +++ /dev/null @@ -1,20 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "extern fn add(a:int, b:int): int;\nfn main() {\n add(3,4);\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -%DispatchTable = type { i64 (i64, i64)* } -%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } - -@dispatchTable = external global %DispatchTable -@global_type_table = external global [1 x %struct.MunTypeInfo addrspace(4)*] - -define void @main() { -body: - %add_ptr = load i64 (i64, i64)*, i64 (i64, i64)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) - %add = call i64 %add_ptr(i64 3, i64 4) - ret void -} - diff --git a/crates/mun_codegen/src/snapshots/test__extern_fn_group_ir.snap b/crates/mun_codegen/src/snapshots/test__extern_fn_group_ir.snap deleted file mode 100644 index cb3729265..000000000 --- a/crates/mun_codegen/src/snapshots/test__extern_fn_group_ir.snap +++ /dev/null @@ -1,15 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "extern fn add(a:int, b:int): int;\nfn main() {\n add(3,4);\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - -%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } -%DispatchTable = type { i64 (i64, i64)* } - -@"type_info::::name" = private unnamed_addr constant [10 x i8] c"core::i64\00" -@"type_info::" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::::name", i32 64, i8 8, i8 0 } -@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::"] -@dispatchTable = global %DispatchTable zeroinitializer - diff --git a/crates/mun_codegen/src/snapshots/test__fibonacci_file_ir.snap b/crates/mun_codegen/src/snapshots/test__fibonacci.snap similarity index 69% rename from crates/mun_codegen/src/snapshots/test__fibonacci_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__fibonacci.snap index 9ec236c1e..125e03f6e 100644 --- a/crates/mun_codegen/src/snapshots/test__fibonacci_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__fibonacci.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn fibonacci(n:int):int {\n if n <= 1 {\n n\n } else {\n fibonacci(n-1) + fibonacci(n-2)\n }\n}" +expression: "fn fibonacci(n:int)->int {\n if n <= 1 {\n n\n } else {\n fibonacci(n-1) + fibonacci(n-2)\n }\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -29,3 +30,14 @@ if_merge: ; preds = %body, %else ret i64 %iftmp } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + +%DispatchTable = type { i64 (i64)* } + +@dispatchTable = global %DispatchTable { i64 (i64)* @fibonacci } + +declare i64 @fibonacci(i64) + diff --git a/crates/mun_codegen/src/snapshots/test__fibonacci_group_ir.snap b/crates/mun_codegen/src/snapshots/test__fibonacci_group_ir.snap deleted file mode 100644 index bb17c0fc0..000000000 --- a/crates/mun_codegen/src/snapshots/test__fibonacci_group_ir.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn fibonacci(n:int):int {\n if n <= 1 {\n n\n } else {\n fibonacci(n-1) + fibonacci(n-2)\n }\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - -%DispatchTable = type { i64 (i64)* } - -@dispatchTable = global %DispatchTable { i64 (i64)* @fibonacci } - -declare i64 @fibonacci(i64) - diff --git a/crates/mun_codegen/src/snapshots/test__fibonacci_loop_file_ir.snap b/crates/mun_codegen/src/snapshots/test__fibonacci_loop.snap similarity index 63% rename from crates/mun_codegen/src/snapshots/test__fibonacci_loop_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__fibonacci_loop.snap index a19d6ece6..afe05faf3 100644 --- a/crates/mun_codegen/src/snapshots/test__fibonacci_loop_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__fibonacci_loop.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn fibonacci(n:int):int {\n let a = 0;\n let b = 1;\n let i = 1;\n loop {\n if i > n {\n return a\n }\n let sum = a + b;\n a = b;\n b = sum;\n i += 1;\n }\n}" +expression: "fn fibonacci(n:int)->int {\n let a = 0;\n let b = 1;\n let i = 1;\n loop {\n if i > n {\n return a\n }\n let sum = a + b;\n a = b;\n b = sum;\n i += 1;\n }\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -25,3 +26,8 @@ if_merge: ; preds = %loop br label %loop } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__fibonacci_loop_group_ir.snap b/crates/mun_codegen/src/snapshots/test__fibonacci_loop_group_ir.snap deleted file mode 100644 index 9e313c346..000000000 --- a/crates/mun_codegen/src/snapshots/test__fibonacci_loop_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn fibonacci(n:int):int {\n let a = 0;\n let b = 1;\n let i = 1;\n loop {\n if i > n {\n return a\n }\n let sum = a + b;\n a = b;\n b = sum;\n i += 1;\n }\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__field_crash_group_ir.snap b/crates/mun_codegen/src/snapshots/test__field_crash.snap similarity index 61% rename from crates/mun_codegen/src/snapshots/test__field_crash_group_ir.snap rename to crates/mun_codegen/src/snapshots/test__field_crash.snap index e6673e721..ed1472963 100644 --- a/crates/mun_codegen/src/snapshots/test__field_crash_group_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__field_crash.snap @@ -1,7 +1,45 @@ --- source: crates/mun_codegen/src/test.rs -expression: "struct(gc) Foo { a: int };\n\nfn main(c:int):int {\n let b = Foo { a: c + 5 }\n b.a\n}" +expression: "struct(gc) Foo { a: int };\n\nfn main(c:int)->int {\n let b = Foo { a: c + 5 }\n b.a\n}" --- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* } +%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } +%Foo = type { i64 } + +@allocatorHandle = external global i8* +@dispatchTable = external global %DispatchTable +@global_type_table = external global [5 x %struct.MunTypeInfo addrspace(4)*] + +define i64 @main(i64) { +body: + %b = alloca %Foo* addrspace(4)* + %c = alloca i64 + store i64 %0, i64* %c + %c1 = load i64, i64* %c + %add = add i64 %c1, 5 + %init = insertvalue %Foo undef, i64 %add, 0 + %new_ptr = load i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i8* addrspace(4)* (i8 addrspace(4)*, i8*)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) + %Foo_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([5 x %struct.MunTypeInfo addrspace(4)*], [5 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 0) + %type_info_ptr_to_i8_ptr = bitcast %struct.MunTypeInfo addrspace(4)* %Foo_ptr to i8 addrspace(4)* + %allocator_handle = load i8*, i8** @allocatorHandle + %new = call i8* addrspace(4)* %new_ptr(i8 addrspace(4)* %type_info_ptr_to_i8_ptr, i8* %allocator_handle) + %Foo_ptr_ptr = bitcast i8* addrspace(4)* %new to %Foo* addrspace(4)* + %Foo_mem_ptr = load %Foo*, %Foo* addrspace(4)* %Foo_ptr_ptr + store %Foo %init, %Foo* %Foo_mem_ptr + store %Foo* addrspace(4)* %Foo_ptr_ptr, %Foo* addrspace(4)** %b + %mem_ptr = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %b + %deref = load %Foo*, %Foo* addrspace(4)* %mem_ptr + %Foo.a = getelementptr inbounds %Foo, %Foo* %deref, i32 0, i32 0 + %a = load i64, i64* %Foo.a + ret i64 %a +} + + +; == GROUP IR ==================================== ; ModuleID = 'group_name' source_filename = "group_name" diff --git a/crates/mun_codegen/src/snapshots/test__field_crash_file_ir.snap b/crates/mun_codegen/src/snapshots/test__field_crash_file_ir.snap deleted file mode 100644 index 225fe0f57..000000000 --- a/crates/mun_codegen/src/snapshots/test__field_crash_file_ir.snap +++ /dev/null @@ -1,39 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "struct(gc) Foo { a: int };\n\nfn main(c:int):int {\n let b = Foo { a: c + 5 }\n b.a\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* } -%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } -%Foo = type { i64 } - -@allocatorHandle = external global i8* -@dispatchTable = external global %DispatchTable -@global_type_table = external global [5 x %struct.MunTypeInfo addrspace(4)*] - -define i64 @main(i64) { -body: - %b = alloca %Foo* addrspace(4)* - %c = alloca i64 - store i64 %0, i64* %c - %c1 = load i64, i64* %c - %add = add i64 %c1, 5 - %init = insertvalue %Foo undef, i64 %add, 0 - %new_ptr = load i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i8* addrspace(4)* (i8 addrspace(4)*, i8*)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) - %Foo_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([5 x %struct.MunTypeInfo addrspace(4)*], [5 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 0) - %type_info_ptr_to_i8_ptr = bitcast %struct.MunTypeInfo addrspace(4)* %Foo_ptr to i8 addrspace(4)* - %allocator_handle = load i8*, i8** @allocatorHandle - %new = call i8* addrspace(4)* %new_ptr(i8 addrspace(4)* %type_info_ptr_to_i8_ptr, i8* %allocator_handle) - %Foo_ptr_ptr = bitcast i8* addrspace(4)* %new to %Foo* addrspace(4)* - %Foo_mem_ptr = load %Foo*, %Foo* addrspace(4)* %Foo_ptr_ptr - store %Foo %init, %Foo* %Foo_mem_ptr - store %Foo* addrspace(4)* %Foo_ptr_ptr, %Foo* addrspace(4)** %b - %mem_ptr = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %b - %deref = load %Foo*, %Foo* addrspace(4)* %mem_ptr - %Foo.a = getelementptr inbounds %Foo, %Foo* %deref, i32 0, i32 0 - %a = load i64, i64* %Foo.a - ret i64 %a -} - diff --git a/crates/mun_codegen/src/snapshots/test__field_expr_group_ir.snap b/crates/mun_codegen/src/snapshots/test__field_expr.snap similarity index 70% rename from crates/mun_codegen/src/snapshots/test__field_expr_group_ir.snap rename to crates/mun_codegen/src/snapshots/test__field_expr.snap index b512ad90c..2e2500b9d 100644 --- a/crates/mun_codegen/src/snapshots/test__field_expr_group_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__field_expr.snap @@ -1,7 +1,63 @@ --- source: crates/mun_codegen/src/test.rs -expression: "struct(value) Bar(float, Foo);\nstruct(value) Foo { a: int };\n\nfn bar_0(bar: Bar): float {\n bar.0\n}\n\nfn bar_1(bar: Bar): Foo {\n bar.1\n}\n\nfn bar_1_a(bar: Bar): int {\n bar.1.a\n}\n\nfn foo_a(foo: Foo): int {\n foo.a\n}\n\nfn bar_1_foo_a(bar: Bar): int {\n foo_a(bar_1(bar))\n}\n\nfn main(): int {\n let a: Foo = Foo { a: 5 };\n let b: Bar = Bar(1.23, a);\n let aa_lhs = a.a + 2;\n let aa_rhs = 2 + a.a;\n aa_lhs + aa_rhs\n}" +expression: "struct(value) Bar(float, Foo);\nstruct(value) Foo { a: int };\n\nfn bar_0(bar: Bar) -> float {\n bar.0\n}\n\nfn bar_1(bar: Bar) -> Foo {\n bar.1\n}\n\nfn bar_1_a(bar: Bar) -> int {\n bar.1.a\n}\n\nfn foo_a(foo: Foo) -> int {\n foo.a\n}\n\nfn bar_1_foo_a(bar: Bar) -> int {\n foo_a(bar_1(bar))\n}\n\nfn main() -> int {\n let a: Foo = Foo { a: 5 };\n let b: Bar = Bar(1.23, a);\n let aa_lhs = a.a + 2;\n let aa_rhs = 2 + a.a;\n aa_lhs + aa_rhs\n}" --- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i64 (%Foo)*, %Foo (%Bar)* } +%Foo = type { i64 } +%Bar = type { double, %Foo } +%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } + +@allocatorHandle = external global i8* +@dispatchTable = external global %DispatchTable +@global_type_table = external global [7 x %struct.MunTypeInfo addrspace(4)*] + +define double @bar_0(%Bar) { +body: + %.fca.0.extract = extractvalue %Bar %0, 0 + ret double %.fca.0.extract +} + +define %Foo @bar_1(%Bar) { +body: + %.fca.1.0.extract = extractvalue %Bar %0, 1, 0 + %"1.fca.0.insert" = insertvalue %Foo undef, i64 %.fca.1.0.extract, 0 + ret %Foo %"1.fca.0.insert" +} + +define i64 @bar_1_a(%Bar) { +body: + %.fca.1.0.extract = extractvalue %Bar %0, 1, 0 + ret i64 %.fca.1.0.extract +} + +define i64 @foo_a(%Foo) { +body: + %.fca.0.extract = extractvalue %Foo %0, 0 + ret i64 %.fca.0.extract +} + +define i64 @bar_1_foo_a(%Bar) { +body: + %.fca.0.extract = extractvalue %Bar %0, 0 + %.fca.1.0.extract = extractvalue %Bar %0, 1, 0 + %bar_1_ptr = load %Foo (%Bar)*, %Foo (%Bar)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 2) + %bar_1 = call %Foo %bar_1_ptr(%Bar %0) + %foo_a_ptr = load i64 (%Foo)*, i64 (%Foo)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 1) + %foo_a = call i64 %foo_a_ptr(%Foo %bar_1) + ret i64 %foo_a +} + +define i64 @main() { +body: + ret i64 14 +} + + +; == GROUP IR ==================================== ; ModuleID = 'group_name' source_filename = "group_name" diff --git a/crates/mun_codegen/src/snapshots/test__field_expr_file_ir.snap b/crates/mun_codegen/src/snapshots/test__field_expr_file_ir.snap deleted file mode 100644 index 65991d1dc..000000000 --- a/crates/mun_codegen/src/snapshots/test__field_expr_file_ir.snap +++ /dev/null @@ -1,57 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "struct(value) Bar(float, Foo);\nstruct(value) Foo { a: int };\n\nfn bar_0(bar: Bar): float {\n bar.0\n}\n\nfn bar_1(bar: Bar): Foo {\n bar.1\n}\n\nfn bar_1_a(bar: Bar): int {\n bar.1.a\n}\n\nfn foo_a(foo: Foo): int {\n foo.a\n}\n\nfn bar_1_foo_a(bar: Bar): int {\n foo_a(bar_1(bar))\n}\n\nfn main(): int {\n let a: Foo = Foo { a: 5 };\n let b: Bar = Bar(1.23, a);\n let aa_lhs = a.a + 2;\n let aa_rhs = 2 + a.a;\n aa_lhs + aa_rhs\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i64 (%Foo)*, %Foo (%Bar)* } -%Foo = type { i64 } -%Bar = type { double, %Foo } -%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } - -@allocatorHandle = external global i8* -@dispatchTable = external global %DispatchTable -@global_type_table = external global [7 x %struct.MunTypeInfo addrspace(4)*] - -define double @bar_0(%Bar) { -body: - %.fca.0.extract = extractvalue %Bar %0, 0 - ret double %.fca.0.extract -} - -define %Foo @bar_1(%Bar) { -body: - %.fca.1.0.extract = extractvalue %Bar %0, 1, 0 - %"1.fca.0.insert" = insertvalue %Foo undef, i64 %.fca.1.0.extract, 0 - ret %Foo %"1.fca.0.insert" -} - -define i64 @bar_1_a(%Bar) { -body: - %.fca.1.0.extract = extractvalue %Bar %0, 1, 0 - ret i64 %.fca.1.0.extract -} - -define i64 @foo_a(%Foo) { -body: - %.fca.0.extract = extractvalue %Foo %0, 0 - ret i64 %.fca.0.extract -} - -define i64 @bar_1_foo_a(%Bar) { -body: - %.fca.0.extract = extractvalue %Bar %0, 0 - %.fca.1.0.extract = extractvalue %Bar %0, 1, 0 - %bar_1_ptr = load %Foo (%Bar)*, %Foo (%Bar)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 2) - %bar_1 = call %Foo %bar_1_ptr(%Bar %0) - %foo_a_ptr = load i64 (%Foo)*, i64 (%Foo)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 1) - %foo_a = call i64 %foo_a_ptr(%Foo %bar_1) - ret i64 %foo_a -} - -define i64 @main() { -body: - ret i64 14 -} - diff --git a/crates/mun_codegen/src/snapshots/test__function_file_ir.snap b/crates/mun_codegen/src/snapshots/test__function.snap similarity index 51% rename from crates/mun_codegen/src/snapshots/test__function_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__function.snap index 28335de17..65896913f 100644 --- a/crates/mun_codegen/src/snapshots/test__function_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__function.snap @@ -2,6 +2,7 @@ source: crates/mun_codegen/src/test.rs expression: "fn main() {\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -10,3 +11,8 @@ body: ret void } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__function_arguments.snap b/crates/mun_codegen/src/snapshots/test__function_arguments.snap new file mode 100644 index 000000000..462337fca --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__function_arguments.snap @@ -0,0 +1,18 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn main(a:int)->int {\n a\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i64 @main(i64) { +body: + ret i64 %0 +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__function_arguments_file_ir.snap b/crates/mun_codegen/src/snapshots/test__function_arguments_file_ir.snap deleted file mode 100644 index 1918d91d5..000000000 --- a/crates/mun_codegen/src/snapshots/test__function_arguments_file_ir.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n a\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i64 @main(i64) { -body: - ret i64 %0 -} - diff --git a/crates/mun_codegen/src/snapshots/test__function_arguments_group_ir.snap b/crates/mun_codegen/src/snapshots/test__function_arguments_group_ir.snap deleted file mode 100644 index 52d4a44eb..000000000 --- a/crates/mun_codegen/src/snapshots/test__function_arguments_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n a\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__function_calls_file_ir.snap b/crates/mun_codegen/src/snapshots/test__function_calls.snap similarity index 67% rename from crates/mun_codegen/src/snapshots/test__function_calls_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__function_calls.snap index 595084dc2..1a3898852 100644 --- a/crates/mun_codegen/src/snapshots/test__function_calls_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__function_calls.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn add_impl(a:int, b:int):int {\n a+b\n}\n\nfn add(a:int, b:int):int {\n add_impl(a,b)\n}\n\nfn test():int {\n add(4,5)\n add_impl(4,5)\n add(4,5)\n}" +expression: "fn add_impl(a:int, b:int)->int {\n a+b\n}\n\nfn add(a:int, b:int)->int {\n add_impl(a,b)\n}\n\nfn test()->int {\n add(4,5)\n add_impl(4,5)\n add(4,5)\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -33,3 +34,16 @@ body: ret i64 %add2 } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + +%DispatchTable = type { i64 (i64, i64)*, i64 (i64, i64)* } + +@dispatchTable = global %DispatchTable { i64 (i64, i64)* @add_impl, i64 (i64, i64)* @add } + +declare i64 @add_impl(i64, i64) + +declare i64 @add(i64, i64) + diff --git a/crates/mun_codegen/src/snapshots/test__function_calls_group_ir.snap b/crates/mun_codegen/src/snapshots/test__function_calls_group_ir.snap deleted file mode 100644 index a2e9dc106..000000000 --- a/crates/mun_codegen/src/snapshots/test__function_calls_group_ir.snap +++ /dev/null @@ -1,15 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn add_impl(a:int, b:int):int {\n a+b\n}\n\nfn add(a:int, b:int):int {\n add_impl(a,b)\n}\n\nfn test():int {\n add(4,5)\n add_impl(4,5)\n add(4,5)\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - -%DispatchTable = type { i64 (i64, i64)*, i64 (i64, i64)* } - -@dispatchTable = global %DispatchTable { i64 (i64, i64)* @add_impl, i64 (i64, i64)* @add } - -declare i64 @add_impl(i64, i64) - -declare i64 @add(i64, i64) - diff --git a/crates/mun_codegen/src/snapshots/test__function_group_ir.snap b/crates/mun_codegen/src/snapshots/test__function_group_ir.snap deleted file mode 100644 index 5588e11fd..000000000 --- a/crates/mun_codegen/src/snapshots/test__function_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main() {\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__gc_struct_group_ir.snap b/crates/mun_codegen/src/snapshots/test__gc_struct.snap similarity index 62% rename from crates/mun_codegen/src/snapshots/test__gc_struct_group_ir.snap rename to crates/mun_codegen/src/snapshots/test__gc_struct.snap index f458f5c05..81005a669 100644 --- a/crates/mun_codegen/src/snapshots/test__gc_struct_group_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__gc_struct.snap @@ -2,6 +2,47 @@ source: crates/mun_codegen/src/test.rs expression: "struct(gc) Foo { a: int, b: int };\n\nfn foo() {\n let a = Foo { a: 3, b: 4 };\n a.b += 3;\n let b = a;\n}" --- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* } +%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } +%Foo = type { i64, i64 } + +@allocatorHandle = external global i8* +@dispatchTable = external global %DispatchTable +@global_type_table = external global [5 x %struct.MunTypeInfo addrspace(4)*] + +define void @foo() { +body: + %b5 = alloca %Foo* addrspace(4)* + %a = alloca %Foo* addrspace(4)* + %new_ptr = load i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i8* addrspace(4)* (i8 addrspace(4)*, i8*)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) + %Foo_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([5 x %struct.MunTypeInfo addrspace(4)*], [5 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 0) + %type_info_ptr_to_i8_ptr = bitcast %struct.MunTypeInfo addrspace(4)* %Foo_ptr to i8 addrspace(4)* + %allocator_handle = load i8*, i8** @allocatorHandle + %new = call i8* addrspace(4)* %new_ptr(i8 addrspace(4)* %type_info_ptr_to_i8_ptr, i8* %allocator_handle) + %Foo_ptr_ptr = bitcast i8* addrspace(4)* %new to %Foo* addrspace(4)* + %Foo_mem_ptr = load %Foo*, %Foo* addrspace(4)* %Foo_ptr_ptr + store %Foo { i64 3, i64 4 }, %Foo* %Foo_mem_ptr + store %Foo* addrspace(4)* %Foo_ptr_ptr, %Foo* addrspace(4)** %a + %mem_ptr = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %a + %deref = load %Foo*, %Foo* addrspace(4)* %mem_ptr + %Foo.b = getelementptr inbounds %Foo, %Foo* %deref, i32 0, i32 1 + %b = load i64, i64* %Foo.b + %add = add i64 %b, 3 + %mem_ptr1 = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %a + %deref2 = load %Foo*, %Foo* addrspace(4)* %mem_ptr1 + %Foo.b3 = getelementptr inbounds %Foo, %Foo* %deref2, i32 0, i32 1 + store i64 %add, i64* %Foo.b3 + %a4 = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %a + store %Foo* addrspace(4)* %a4, %Foo* addrspace(4)** %b5 + ret void +} + + +; == GROUP IR ==================================== ; ModuleID = 'group_name' source_filename = "group_name" diff --git a/crates/mun_codegen/src/snapshots/test__gc_struct_file_ir.snap b/crates/mun_codegen/src/snapshots/test__gc_struct_file_ir.snap deleted file mode 100644 index 82c422fb1..000000000 --- a/crates/mun_codegen/src/snapshots/test__gc_struct_file_ir.snap +++ /dev/null @@ -1,42 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "struct(gc) Foo { a: int, b: int };\n\nfn foo() {\n let a = Foo { a: 3, b: 4 };\n a.b += 3;\n let b = a;\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* } -%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } -%Foo = type { i64, i64 } - -@allocatorHandle = external global i8* -@dispatchTable = external global %DispatchTable -@global_type_table = external global [5 x %struct.MunTypeInfo addrspace(4)*] - -define void @foo() { -body: - %b5 = alloca %Foo* addrspace(4)* - %a = alloca %Foo* addrspace(4)* - %new_ptr = load i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i8* addrspace(4)* (i8 addrspace(4)*, i8*)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) - %Foo_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([5 x %struct.MunTypeInfo addrspace(4)*], [5 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 0) - %type_info_ptr_to_i8_ptr = bitcast %struct.MunTypeInfo addrspace(4)* %Foo_ptr to i8 addrspace(4)* - %allocator_handle = load i8*, i8** @allocatorHandle - %new = call i8* addrspace(4)* %new_ptr(i8 addrspace(4)* %type_info_ptr_to_i8_ptr, i8* %allocator_handle) - %Foo_ptr_ptr = bitcast i8* addrspace(4)* %new to %Foo* addrspace(4)* - %Foo_mem_ptr = load %Foo*, %Foo* addrspace(4)* %Foo_ptr_ptr - store %Foo { i64 3, i64 4 }, %Foo* %Foo_mem_ptr - store %Foo* addrspace(4)* %Foo_ptr_ptr, %Foo* addrspace(4)** %a - %mem_ptr = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %a - %deref = load %Foo*, %Foo* addrspace(4)* %mem_ptr - %Foo.b = getelementptr inbounds %Foo, %Foo* %deref, i32 0, i32 1 - %b = load i64, i64* %Foo.b - %add = add i64 %b, 3 - %mem_ptr1 = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %a - %deref2 = load %Foo*, %Foo* addrspace(4)* %mem_ptr1 - %Foo.b3 = getelementptr inbounds %Foo, %Foo* %deref2, i32 0, i32 1 - store i64 %add, i64* %Foo.b3 - %a4 = load %Foo* addrspace(4)*, %Foo* addrspace(4)** %a - store %Foo* addrspace(4)* %a4, %Foo* addrspace(4)** %b5 - ret void -} - diff --git a/crates/mun_codegen/src/snapshots/test__if_statement_file_ir.snap b/crates/mun_codegen/src/snapshots/test__if_statement.snap similarity index 65% rename from crates/mun_codegen/src/snapshots/test__if_statement_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__if_statement.snap index 701abafb2..359de5c6b 100644 --- a/crates/mun_codegen/src/snapshots/test__if_statement_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__if_statement.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn foo(a:int):int {\n let b = if a > 3 {\n let c = if a > 4 {\n a+1\n } else {\n a+3\n }\n c\n } else {\n a-1\n }\n b\n}" +expression: "fn foo(a:int)->int {\n let b = if a > 3 {\n let c = if a > 4 {\n a+1\n } else {\n a+3\n }\n c\n } else {\n a-1\n }\n b\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -26,3 +27,8 @@ if_merge: ; preds = %else, %then ret i64 %iftmp12 } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__if_statement_group_ir.snap b/crates/mun_codegen/src/snapshots/test__if_statement_group_ir.snap deleted file mode 100644 index 79b237803..000000000 --- a/crates/mun_codegen/src/snapshots/test__if_statement_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn foo(a:int):int {\n let b = if a > 3 {\n let c = if a > 4 {\n a+1\n } else {\n a+3\n }\n c\n } else {\n a-1\n }\n b\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__invalid_binary_ops_file_ir.snap b/crates/mun_codegen/src/snapshots/test__invalid_binary_ops.snap similarity index 61% rename from crates/mun_codegen/src/snapshots/test__invalid_binary_ops_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__invalid_binary_ops.snap index fdac363fb..301964bf0 100644 --- a/crates/mun_codegen/src/snapshots/test__invalid_binary_ops_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__invalid_binary_ops.snap @@ -2,5 +2,9 @@ source: crates/mun_codegen/src/test.rs expression: "fn main() {\n let a = 3+3.0;\n let b = 3.0+3;\n}" --- +; == FILE IR ===================================== error 2:13: mismatched type error 3:15: mismatched type + +; == GROUP IR ==================================== + diff --git a/crates/mun_codegen/src/snapshots/test__invalid_binary_ops_group_ir.snap b/crates/mun_codegen/src/snapshots/test__invalid_binary_ops_group_ir.snap deleted file mode 100644 index fdac363fb..000000000 --- a/crates/mun_codegen/src/snapshots/test__invalid_binary_ops_group_ir.snap +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main() {\n let a = 3+3.0;\n let b = 3.0+3;\n}" ---- -error 2:13: mismatched type -error 3:15: mismatched type diff --git a/crates/mun_codegen/src/snapshots/test__issue_128_file_ir.snap b/crates/mun_codegen/src/snapshots/test__issue_128.snap similarity index 62% rename from crates/mun_codegen/src/snapshots/test__issue_128_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__issue_128.snap index 136b147f4..516df285d 100644 --- a/crates/mun_codegen/src/snapshots/test__issue_128_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__issue_128.snap @@ -2,6 +2,7 @@ source: crates/mun_codegen/src/test.rs expression: "// resources/script.mun\nextern fn thing(n: int);\nextern fn print(n: int) -> int;\n\npub fn main() {\n // 1st\n print(1);\n thing(5);\n\n // 2nd\n print(2);\n thing(78);\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -24,3 +25,16 @@ body: ret void } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + +%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } +%DispatchTable = type { i64 (i64)*, void (i64)* } + +@"type_info::::name" = private unnamed_addr constant [10 x i8] c"core::i64\00" +@"type_info::" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::::name", i32 64, i8 8, i8 0 } +@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::"] +@dispatchTable = global %DispatchTable zeroinitializer + diff --git a/crates/mun_codegen/src/snapshots/test__issue_128_group_ir.snap b/crates/mun_codegen/src/snapshots/test__issue_128_group_ir.snap deleted file mode 100644 index 6831c521f..000000000 --- a/crates/mun_codegen/src/snapshots/test__issue_128_group_ir.snap +++ /dev/null @@ -1,15 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "// resources/script.mun\nextern fn thing(n: int);\nextern fn print(n: int) -> int;\n\npub fn main() {\n // 1st\n print(1);\n thing(5);\n\n // 2nd\n print(2);\n thing(78);\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - -%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } -%DispatchTable = type { i64 (i64)*, void (i64)* } - -@"type_info::::name" = private unnamed_addr constant [10 x i8] c"core::i64\00" -@"type_info::" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::::name", i32 64, i8 8, i8 0 } -@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::"] -@dispatchTable = global %DispatchTable zeroinitializer - diff --git a/crates/mun_codegen/src/snapshots/test__let_statement.snap b/crates/mun_codegen/src/snapshots/test__let_statement.snap new file mode 100644 index 000000000..f13466609 --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__let_statement.snap @@ -0,0 +1,19 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn main(a:int)->int {\n let b = a+1\n b\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i64 @main(i64) { +body: + %add = add i64 %0, 1 + ret i64 %add +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__let_statement_file_ir.snap b/crates/mun_codegen/src/snapshots/test__let_statement_file_ir.snap deleted file mode 100644 index ff5330f63..000000000 --- a/crates/mun_codegen/src/snapshots/test__let_statement_file_ir.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n let b = a+1\n b\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i64 @main(i64) { -body: - %add = add i64 %0, 1 - ret i64 %add -} - diff --git a/crates/mun_codegen/src/snapshots/test__let_statement_group_ir.snap b/crates/mun_codegen/src/snapshots/test__let_statement_group_ir.snap deleted file mode 100644 index 654144d00..000000000 --- a/crates/mun_codegen/src/snapshots/test__let_statement_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n let b = a+1\n b\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__loop_break_expr_file_ir.snap b/crates/mun_codegen/src/snapshots/test__loop_break_expr.snap similarity index 69% rename from crates/mun_codegen/src/snapshots/test__loop_break_expr_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__loop_break_expr.snap index d6e3e9909..d1767097e 100644 --- a/crates/mun_codegen/src/snapshots/test__loop_break_expr_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__loop_break_expr.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn foo(n:int):int {\n loop {\n if n > 5 {\n break n;\n }\n if n > 10 {\n break 10;\n }\n n += 1;\n }\n}" +expression: "fn foo(n:int)->int {\n loop {\n if n > 5 {\n break n;\n }\n if n > 10 {\n break 10;\n }\n n += 1;\n }\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -27,3 +28,8 @@ if_merge6: ; preds = %if_merge br label %loop } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__loop_break_expr_group_ir.snap b/crates/mun_codegen/src/snapshots/test__loop_break_expr_group_ir.snap deleted file mode 100644 index 06e7530ad..000000000 --- a/crates/mun_codegen/src/snapshots/test__loop_break_expr_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn foo(n:int):int {\n loop {\n if n > 5 {\n break n;\n }\n if n > 10 {\n break 10;\n }\n n += 1;\n }\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__loop_expr_file_ir.snap b/crates/mun_codegen/src/snapshots/test__loop_expr.snap similarity index 63% rename from crates/mun_codegen/src/snapshots/test__loop_expr_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__loop_expr.snap index 44f2f7c3a..feda93343 100644 --- a/crates/mun_codegen/src/snapshots/test__loop_expr_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__loop_expr.snap @@ -2,6 +2,7 @@ source: crates/mun_codegen/src/test.rs expression: "fn foo() {\n loop {}\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -13,3 +14,8 @@ loop: ; preds = %loop, %body br label %loop } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__loop_expr_group_ir.snap b/crates/mun_codegen/src/snapshots/test__loop_expr_group_ir.snap deleted file mode 100644 index ebae389cd..000000000 --- a/crates/mun_codegen/src/snapshots/test__loop_expr_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn foo() {\n loop {}\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__never_conditional_return_expr_file_ir.snap b/crates/mun_codegen/src/snapshots/test__never_conditional_return_expr.snap similarity index 58% rename from crates/mun_codegen/src/snapshots/test__never_conditional_return_expr_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__never_conditional_return_expr.snap index 34a8a1f49..e8693872a 100644 --- a/crates/mun_codegen/src/snapshots/test__never_conditional_return_expr_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__never_conditional_return_expr.snap @@ -1,7 +1,8 @@ --- source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n if a > 4 {\n return a;\n } else {\n return a - 1;\n }\n}" +expression: "fn main(a:int)->int {\n if a > 4 {\n return a;\n } else {\n return a - 1;\n }\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -18,3 +19,8 @@ else: ; preds = %body ret i64 %sub } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__never_conditional_return_expr_group_ir.snap b/crates/mun_codegen/src/snapshots/test__never_conditional_return_expr_group_ir.snap deleted file mode 100644 index b629d7bfa..000000000 --- a/crates/mun_codegen/src/snapshots/test__never_conditional_return_expr_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main(a:int):int {\n if a > 4 {\n return a;\n } else {\n return a - 1;\n }\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__primitive_types_file_ir.snap b/crates/mun_codegen/src/snapshots/test__primitive_types.snap similarity index 92% rename from crates/mun_codegen/src/snapshots/test__primitive_types_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__primitive_types.snap index 632441059..3901fcd83 100644 --- a/crates/mun_codegen/src/snapshots/test__primitive_types_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__primitive_types.snap @@ -2,6 +2,7 @@ source: crates/mun_codegen/src/test.rs expression: "fn add(a: u8, b: u8) -> u8 { a+b }\n fn less(a: u16, b: u16) -> bool { a bool { a>b }\n fn equal(a: u64, b: u64) -> bool { a==b }\n fn nequal(a: u128, b: u128) -> bool { a!=b }\n fn greater_equal(a: usize, b: usize) -> bool { a>=b }\n fn less_equal(a: uint, b: uint) -> bool { a<=b }\n\n fn iadd(a: i8, b: i8) -> i8 { a+b }\n fn iless(a: i16, b: i16) -> bool { a bool { a>b }\n fn iequal(a: i64, b: i64) -> bool { a==b }\n fn inequal(a: i128, b: i128) -> bool { a!=b }\n fn igreater_equal(a: isize, b: isize) -> bool { a>=b }\n fn iless_equal(a: int, b: int) -> bool { a<=b }" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -89,3 +90,8 @@ body: ret i1 %lesseq } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__primitive_types_group_ir.snap b/crates/mun_codegen/src/snapshots/test__primitive_types_group_ir.snap deleted file mode 100644 index abc6a41b1..000000000 --- a/crates/mun_codegen/src/snapshots/test__primitive_types_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn add(a: u8, b: u8): u8 { a+b }\n fn less(a: u16, b: u16): bool { ab }\n fn equal(a: u64, b: u64): bool { a==b }\n fn greater_equal(a: usize, b: usize): bool { a>=b }\n fn less_equal(a: uint, b: uint): bool { a<=b }\n\n fn iadd(a: i8, b: i8): i8 { a+b }\n fn iless(a: i16, b: i16): bool { ab }\n fn iequal(a: i64, b: i64): bool { a==b }\n fn igreater_equal(a: isize, b: isize): bool { a>=b }\n fn iless_equal(a: int, b: int): bool { a<=b }" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__return_expr.snap b/crates/mun_codegen/src/snapshots/test__return_expr.snap new file mode 100644 index 000000000..a31cb699b --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__return_expr.snap @@ -0,0 +1,18 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn main()->int {\n return 5;\n let a = 3; // Nothing regarding this statement should be in the IR\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i64 @main() { +body: + ret i64 5 +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__return_expr_file_ir.snap b/crates/mun_codegen/src/snapshots/test__return_expr_file_ir.snap deleted file mode 100644 index 552f2cdec..000000000 --- a/crates/mun_codegen/src/snapshots/test__return_expr_file_ir.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main():int {\n return 5;\n let a = 3; // Nothing regarding this statement should be in the IR\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i64 @main() { -body: - ret i64 5 -} - diff --git a/crates/mun_codegen/src/snapshots/test__return_expr_group_ir.snap b/crates/mun_codegen/src/snapshots/test__return_expr_group_ir.snap deleted file mode 100644 index 4f0975976..000000000 --- a/crates/mun_codegen/src/snapshots/test__return_expr_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main():int {\n return 5;\n let a = 3; // Nothing regarding this statement should be in the IR\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__return_type.snap b/crates/mun_codegen/src/snapshots/test__return_type.snap new file mode 100644 index 000000000..802a6e537 --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__return_type.snap @@ -0,0 +1,18 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn main()->int {\n 0\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i64 @main() { +body: + ret i64 0 +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__return_type_file_ir.snap b/crates/mun_codegen/src/snapshots/test__return_type_file_ir.snap deleted file mode 100644 index 4ce17d4d7..000000000 --- a/crates/mun_codegen/src/snapshots/test__return_type_file_ir.snap +++ /dev/null @@ -1,12 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main():int {\n 0\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i64 @main() { -body: - ret i64 0 -} - diff --git a/crates/mun_codegen/src/snapshots/test__return_type_group_ir.snap b/crates/mun_codegen/src/snapshots/test__return_type_group_ir.snap deleted file mode 100644 index 3a12b5bdd..000000000 --- a/crates/mun_codegen/src/snapshots/test__return_type_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn main():int {\n 0\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__shadowing.snap b/crates/mun_codegen/src/snapshots/test__shadowing.snap new file mode 100644 index 000000000..2c0d59c02 --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__shadowing.snap @@ -0,0 +1,28 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn foo(a:int)->int {\n let a = a+1;\n {\n let a = a+2;\n }\n a+3\n}\n\nfn bar(a:int)->int {\n let a = a+1;\n let a = {\n let a = a+2;\n a\n }\n a+3\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i64 @foo(i64) { +body: + %add = add i64 %0, 1 + %add7 = add i64 %add, 3 + ret i64 %add7 +} + +define i64 @bar(i64) { +body: + %add = add i64 %0, 1 + %add4 = add i64 %add, 2 + %add9 = add i64 %add4, 3 + ret i64 %add9 +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__shadowing_file_ir.snap b/crates/mun_codegen/src/snapshots/test__shadowing_file_ir.snap deleted file mode 100644 index 28bbb04a8..000000000 --- a/crates/mun_codegen/src/snapshots/test__shadowing_file_ir.snap +++ /dev/null @@ -1,22 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn foo(a:int):int {\n let a = a+1;\n {\n let a = a+2;\n }\n a+3\n}\n\nfn bar(a:int):int {\n let a = a+1;\n let a = {\n let a = a+2;\n a\n }\n a+3\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i64 @foo(i64) { -body: - %add = add i64 %0, 1 - %add7 = add i64 %add, 3 - ret i64 %add7 -} - -define i64 @bar(i64) { -body: - %add = add i64 %0, 1 - %add4 = add i64 %add, 2 - %add9 = add i64 %add4, 3 - ret i64 %add9 -} - diff --git a/crates/mun_codegen/src/snapshots/test__shadowing_group_ir.snap b/crates/mun_codegen/src/snapshots/test__shadowing_group_ir.snap deleted file mode 100644 index 9d6e9002d..000000000 --- a/crates/mun_codegen/src/snapshots/test__shadowing_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn foo(a:int):int {\n let a = a+1;\n {\n let a = a+2;\n }\n a+3\n}\n\nfn bar(a:int):int {\n let a = a+1;\n let a = {\n let a = a+2;\n a\n }\n a+3\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__struct_test_group_ir.snap b/crates/mun_codegen/src/snapshots/test__struct_test.snap similarity index 85% rename from crates/mun_codegen/src/snapshots/test__struct_test_group_ir.snap rename to crates/mun_codegen/src/snapshots/test__struct_test.snap index 41cf3a396..72dd45b5d 100644 --- a/crates/mun_codegen/src/snapshots/test__struct_test_group_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__struct_test.snap @@ -2,6 +2,39 @@ source: crates/mun_codegen/src/test.rs expression: "struct(value) Bar(float, int, bool, Foo);\nstruct(value) Foo { a: int };\nstruct(value) Baz;\nfn foo() {\n let a: Foo = Foo { a: 5 };\n let b: Bar = Bar(1.23, a.a, true, a);\n let c: Baz = Baz;\n}" --- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* } +%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } +%Baz = type {} +%Bar = type { double, i64, i1, %Foo } +%Foo = type { i64 } + +@allocatorHandle = external global i8* +@dispatchTable = external global %DispatchTable +@global_type_table = external global [9 x %struct.MunTypeInfo addrspace(4)*] + +define void @foo() { +body: + %c = alloca %Baz + %b = alloca %Bar + %a = alloca %Foo + store %Foo { i64 5 }, %Foo* %a + %Foo.a = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0 + %a1 = load i64, i64* %Foo.a + %a2 = load %Foo, %Foo* %a + %init = insertvalue %Bar { double 1.230000e+00, i64 undef, i1 undef, %Foo undef }, i64 %a1, 1 + %init3 = insertvalue %Bar %init, i1 true, 2 + %init4 = insertvalue %Bar %init3, %Foo %a2, 3 + store %Bar %init4, %Bar* %b + store %Baz undef, %Baz* %c + ret void +} + + +; == GROUP IR ==================================== ; ModuleID = 'group_name' source_filename = "group_name" diff --git a/crates/mun_codegen/src/snapshots/test__struct_test_file_ir.snap b/crates/mun_codegen/src/snapshots/test__struct_test_file_ir.snap deleted file mode 100644 index e16e1e146..000000000 --- a/crates/mun_codegen/src/snapshots/test__struct_test_file_ir.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "struct(value) Bar(float, int, bool, Foo);\nstruct(value) Foo { a: int };\nstruct(value) Baz;\nfn foo() {\n let a: Foo = Foo { a: 5 };\n let b: Bar = Bar(1.23, a.a, true, a);\n let c: Baz = Baz;\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* } -%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 } -%Baz = type {} -%Bar = type { double, i64, i1, %Foo } -%Foo = type { i64 } - -@allocatorHandle = external global i8* -@dispatchTable = external global %DispatchTable -@global_type_table = external global [9 x %struct.MunTypeInfo addrspace(4)*] - -define void @foo() { -body: - %c = alloca %Baz - %b = alloca %Bar - %a = alloca %Foo - store %Foo { i64 5 }, %Foo* %a - %Foo.a = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0 - %a1 = load i64, i64* %Foo.a - %a2 = load %Foo, %Foo* %a - %init = insertvalue %Bar { double 1.230000e+00, i64 undef, i1 undef, %Foo undef }, i64 %a1, 1 - %init3 = insertvalue %Bar %init, i1 true, 2 - %init4 = insertvalue %Bar %init3, %Foo %a2, 3 - store %Bar %init4, %Bar* %b - store %Baz undef, %Baz* %c - ret void -} - diff --git a/crates/mun_codegen/src/snapshots/test__true_is_true.snap b/crates/mun_codegen/src/snapshots/test__true_is_true.snap new file mode 100644 index 000000000..409b7c0ae --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__true_is_true.snap @@ -0,0 +1,23 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn test_true()->bool {\n true\n}\n\nfn test_false()->bool {\n false\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i1 @test_true() { +body: + ret i1 true +} + +define i1 @test_false() { +body: + ret i1 false +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__true_is_true_file_ir.snap b/crates/mun_codegen/src/snapshots/test__true_is_true_file_ir.snap deleted file mode 100644 index 97257103d..000000000 --- a/crates/mun_codegen/src/snapshots/test__true_is_true_file_ir.snap +++ /dev/null @@ -1,17 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn test_true():bool {\n true\n}\n\nfn test_false():bool {\n false\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i1 @test_true() { -body: - ret i1 true -} - -define i1 @test_false() { -body: - ret i1 false -} - diff --git a/crates/mun_codegen/src/snapshots/test__true_is_true_group_ir.snap b/crates/mun_codegen/src/snapshots/test__true_is_true_group_ir.snap deleted file mode 100644 index 1849235c5..000000000 --- a/crates/mun_codegen/src/snapshots/test__true_is_true_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn test_true():bool {\n true\n}\n\nfn test_false():bool {\n false\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__update_operators.snap b/crates/mun_codegen/src/snapshots/test__update_operators.snap new file mode 100644 index 000000000..b3d09a007 --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__update_operators.snap @@ -0,0 +1,37 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn add(a:int, b:int)->int {\n let result = a\n result += b\n result\n}\n\nfn subtract(a:int, b:int)->int {\n let result = a\n result -= b\n result\n}\n\nfn multiply(a:int, b:int)->int {\n let result = a\n result *= b\n result\n}\n\nfn divide(a:int, b:int)->int {\n let result = a\n result /= b\n result\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i64 @add(i64, i64) { +body: + %add = add i64 %0, %1 + ret i64 %add +} + +define i64 @subtract(i64, i64) { +body: + %sub = sub i64 %0, %1 + ret i64 %sub +} + +define i64 @multiply(i64, i64) { +body: + %mul = mul i64 %0, %1 + ret i64 %mul +} + +define i64 @divide(i64, i64) { +body: + %div = sdiv i64 %0, %1 + ret i64 %div +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__update_operators_file_ir.snap b/crates/mun_codegen/src/snapshots/test__update_operators_file_ir.snap deleted file mode 100644 index 5d794f463..000000000 --- a/crates/mun_codegen/src/snapshots/test__update_operators_file_ir.snap +++ /dev/null @@ -1,31 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn add(a:int, b:int):int {\n let result = a\n result += b\n result\n}\n\nfn subtract(a:int, b:int):int {\n let result = a\n result -= b\n result\n}\n\nfn multiply(a:int, b:int):int {\n let result = a\n result *= b\n result\n}\n\nfn divide(a:int, b:int):int {\n let result = a\n result /= b\n result\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i64 @add(i64, i64) { -body: - %add = add i64 %0, %1 - ret i64 %add -} - -define i64 @subtract(i64, i64) { -body: - %sub = sub i64 %0, %1 - ret i64 %sub -} - -define i64 @multiply(i64, i64) { -body: - %mul = mul i64 %0, %1 - ret i64 %mul -} - -define i64 @divide(i64, i64) { -body: - %div = sdiv i64 %0, %1 - ret i64 %div -} - diff --git a/crates/mun_codegen/src/snapshots/test__update_operators_group_ir.snap b/crates/mun_codegen/src/snapshots/test__update_operators_group_ir.snap deleted file mode 100644 index 608dfdf02..000000000 --- a/crates/mun_codegen/src/snapshots/test__update_operators_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn add(a:int, b:int):int {\n let result = a\n result += b\n result\n}\n\nfn subtract(a:int, b:int):int {\n let result = a\n result -= b\n result\n}\n\nfn multiply(a:int, b:int):int {\n let result = a\n result *= b\n result\n}\n\nfn divide(a:int, b:int):int {\n let result = a\n result /= b\n result\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__update_parameter.snap b/crates/mun_codegen/src/snapshots/test__update_parameter.snap new file mode 100644 index 000000000..4ab8612e3 --- /dev/null +++ b/crates/mun_codegen/src/snapshots/test__update_parameter.snap @@ -0,0 +1,19 @@ +--- +source: crates/mun_codegen/src/test.rs +expression: "fn add_three(a:int)->int {\n a += 3;\n a\n}" +--- +; == FILE IR ===================================== +; ModuleID = 'main.mun' +source_filename = "main.mun" + +define i64 @add_three(i64) { +body: + %add = add i64 %0, 3 + ret i64 %add +} + + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__update_parameter_file_ir.snap b/crates/mun_codegen/src/snapshots/test__update_parameter_file_ir.snap deleted file mode 100644 index 8ac10bef7..000000000 --- a/crates/mun_codegen/src/snapshots/test__update_parameter_file_ir.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn add_three(a:int):int {\n a += 3;\n a\n}" ---- -; ModuleID = 'main.mun' -source_filename = "main.mun" - -define i64 @add_three(i64) { -body: - %add = add i64 %0, 3 - ret i64 %add -} - diff --git a/crates/mun_codegen/src/snapshots/test__update_parameter_group_ir.snap b/crates/mun_codegen/src/snapshots/test__update_parameter_group_ir.snap deleted file mode 100644 index 5aabe801e..000000000 --- a/crates/mun_codegen/src/snapshots/test__update_parameter_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn add_three(a:int):int {\n a += 3;\n a\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/snapshots/test__void_return_file_ir.snap b/crates/mun_codegen/src/snapshots/test__void_return.snap similarity index 64% rename from crates/mun_codegen/src/snapshots/test__void_return_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__void_return.snap index 0e4b2327e..50b2fc56e 100644 --- a/crates/mun_codegen/src/snapshots/test__void_return_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__void_return.snap @@ -2,6 +2,7 @@ source: crates/mun_codegen/src/test.rs expression: "fn bar() {\n let a = 3;\n}\nfn foo(a:int) {\n let c = bar()\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -21,3 +22,14 @@ body: ret void } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + +%DispatchTable = type { void ()* } + +@dispatchTable = global %DispatchTable { void ()* @bar } + +declare void @bar() + diff --git a/crates/mun_codegen/src/snapshots/test__void_return_group_ir.snap b/crates/mun_codegen/src/snapshots/test__void_return_group_ir.snap deleted file mode 100644 index ff75282c6..000000000 --- a/crates/mun_codegen/src/snapshots/test__void_return_group_ir.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn bar() {\n let a = 3;\n}\nfn foo(a:int) {\n let c = bar()\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - -%DispatchTable = type { void ()* } - -@dispatchTable = global %DispatchTable { void ()* @bar } - -declare void @bar() - diff --git a/crates/mun_codegen/src/snapshots/test__while_expr_file_ir.snap b/crates/mun_codegen/src/snapshots/test__while_expr.snap similarity index 81% rename from crates/mun_codegen/src/snapshots/test__while_expr_file_ir.snap rename to crates/mun_codegen/src/snapshots/test__while_expr.snap index e56439f69..3d32f4ba5 100644 --- a/crates/mun_codegen/src/snapshots/test__while_expr_file_ir.snap +++ b/crates/mun_codegen/src/snapshots/test__while_expr.snap @@ -2,6 +2,7 @@ source: crates/mun_codegen/src/test.rs expression: "fn foo(n:int) {\n while n<3 {\n n += 1;\n };\n\n // This will be completely optimized out\n while n<4 {\n break;\n };\n}" --- +; == FILE IR ===================================== ; ModuleID = 'main.mun' source_filename = "main.mun" @@ -22,3 +23,8 @@ whilecond3: ; preds = %whilecond ret void } + +; == GROUP IR ==================================== +; ModuleID = 'group_name' +source_filename = "group_name" + diff --git a/crates/mun_codegen/src/snapshots/test__while_expr_group_ir.snap b/crates/mun_codegen/src/snapshots/test__while_expr_group_ir.snap deleted file mode 100644 index bbc3b88f1..000000000 --- a/crates/mun_codegen/src/snapshots/test__while_expr_group_ir.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: crates/mun_codegen/src/test.rs -expression: "fn foo(n:int) {\n while n<3 {\n n += 1;\n };\n\n // This will be completely optimized out\n while n<4 {\n break;\n };\n}" ---- -; ModuleID = 'group_name' -source_filename = "group_name" - diff --git a/crates/mun_codegen/src/test.rs b/crates/mun_codegen/src/test.rs index e3f35fa7e..ba7e16dcc 100644 --- a/crates/mun_codegen/src/test.rs +++ b/crates/mun_codegen/src/test.rs @@ -587,7 +587,7 @@ fn test_snapshot_with_optimization(text: &str, opt: OptimizationLevel) { .replace("test::", ""); let group_ir_value = if !messages.is_empty() { - messages.join("\n") + "".to_owned() } else { format!( "{}", @@ -597,7 +597,7 @@ fn test_snapshot_with_optimization(text: &str, opt: OptimizationLevel) { .to_string() ) }; - insta::assert_snapshot!(format!("{}_group_ir", thread_name), group_ir_value, &text); + let file_ir_value = if !messages.is_empty() { messages.join("\n") } else { @@ -609,5 +609,14 @@ fn test_snapshot_with_optimization(text: &str, opt: OptimizationLevel) { .to_string() ) }; - insta::assert_snapshot!(format!("{}_file_ir", thread_name), file_ir_value, &text); + + let value = format!( + r"; == FILE IR ===================================== +{} + +; == GROUP IR ==================================== +{}", + file_ir_value, group_ir_value + ); + insta::assert_snapshot!(thread_name, value, &text); }