Skip to content

Commit

Permalink
add snapshot test for mux call with strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mhasel committed Mar 7, 2024
1 parent 062b894 commit b83be8c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/codegen/tests/expression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,21 @@ fn builtin_function_call_mux() {
VAR
a,b,c,d,e : DINT;
END_VAR
a := MUX(3, b,c,d,e); //3 = d
a := MUX(3, b,c,d,e); // 3 = e
END_PROGRAM",
);

insta::assert_snapshot!(result);
}

#[test]
fn builtin_function_call_mux_with_aggregate_type() {
let result = codegen(
"PROGRAM main
VAR
str1 : STRING;
END_VAR
str1 := MUX(3, 'lorem', 'ipsum', 'dolor', 'sit'); // 3 = sit
END_PROGRAM",
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: src/codegen/tests/expression_tests.rs
expression: result
---
; ModuleID = 'main'
source_filename = "main"

%main = type { [81 x i8] }

@main_instance = global %main zeroinitializer
@utf08_literal_0 = private unnamed_addr constant [6 x i8] c"dolor\00"
@utf08_literal_1 = private unnamed_addr constant [6 x i8] c"ipsum\00"
@utf08_literal_2 = private unnamed_addr constant [6 x i8] c"lorem\00"
@utf08_literal_3 = private unnamed_addr constant [4 x i8] c"sit\00"

define void @main(%main* %0) {
entry:
%str1 = getelementptr inbounds %main, %main* %0, i32 0, i32 0
%1 = alloca [81 x i8], align 1
switch i32 3, label %continue_block [
i32 0, label %2
i32 1, label %4
i32 2, label %6
i32 3, label %8
]

2: ; preds = %entry
%3 = bitcast [81 x i8]* %1 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %3, i8* align 1 getelementptr inbounds ([6 x i8], [6 x i8]* @utf08_literal_2, i32 0, i32 0), i32 6, i1 false)
br label %continue_block

4: ; preds = %entry
%5 = bitcast [81 x i8]* %1 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %5, i8* align 1 getelementptr inbounds ([6 x i8], [6 x i8]* @utf08_literal_1, i32 0, i32 0), i32 6, i1 false)
br label %continue_block

6: ; preds = %entry
%7 = bitcast [81 x i8]* %1 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %7, i8* align 1 getelementptr inbounds ([6 x i8], [6 x i8]* @utf08_literal_0, i32 0, i32 0), i32 6, i1 false)
br label %continue_block

8: ; preds = %entry
%9 = bitcast [81 x i8]* %1 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %9, i8* align 1 getelementptr inbounds ([4 x i8], [4 x i8]* @utf08_literal_3, i32 0, i32 0), i32 4, i1 false)
br label %continue_block

continue_block: ; preds = %entry, %8, %6, %4, %2
%10 = bitcast [81 x i8]* %str1 to i8*
%11 = bitcast [81 x i8]* %1 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %10, i8* align 1 %11, i32 80, i1 false)
ret void
}

; Function Attrs: argmemonly nofree nounwind willreturn
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i32, i1 immarg) #0

attributes #0 = { argmemonly nofree nounwind willreturn }

0 comments on commit b83be8c

Please sign in to comment.