Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add intrinsics tests #4567

Merged
merged 2 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sway-ir/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ fn instruction_to_doc<'a>(
} => maybe_constant_to_doc(context, md_namer, namer, number_of_slots).append(
Doc::line(
Doc::text(format!(
"state_load_quad_word {}, key {}, {}",
"{} = state_load_quad_word {}, key {}, {}",
namer.name(context, ins_value),
namer.name(context, load_val),
namer.name(context, key),
namer.name(context, number_of_slots),
Expand All @@ -684,7 +685,8 @@ fn instruction_to_doc<'a>(
} => maybe_constant_to_doc(context, md_namer, namer, number_of_slots).append(
Doc::line(
Doc::text(format!(
"state_store_quad_word {}, key {}, {}",
"{} = state_store_quad_word {}, key {}, {}",
namer.name(context, ins_value),
namer.name(context, stored_val),
namer.name(context, key),
namer.name(context, number_of_slots),
Expand All @@ -695,7 +697,8 @@ fn instruction_to_doc<'a>(
FuelVmInstruction::StateStoreWord { stored_val, key } => {
maybe_constant_to_doc(context, md_namer, namer, stored_val).append(Doc::line(
Doc::text(format!(
"state_store_word {}, key {}",
"{} = state_store_word {}, key {}",
namer.name(context, ins_value),
namer.name(context, stored_val),
namer.name(context, key),
))
Expand Down
15 changes: 15 additions & 0 deletions test/src/ir_generation/tests/addr_of.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

script;

fn main() {
let a: b256 = 0x0000000000000000000000000000000000000000000000000000000000000001;
let _ = __addr_of(a);
}

// check: v0 = get_local ptr b256, a, !2
// check: v1 = const b256 0x0000000000000000000000000000000000000000000000000000000000000001, !3
// check: store v1 to v0, !2
// check: v2 = get_local ptr b256, a, !4
// check: v3 = ptr_to_int v2 to u64, !5
// check: v4 = get_local ptr u64, _, !6
// check: store v3 to v4, !6
9 changes: 9 additions & 0 deletions test/src/ir_generation/tests/eq.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script;

fn main() {
let _ = __eq(1, 2);
}

// check: $(l=$VAL) = const u64 1, $MD
// check: $(r=$VAL) = const u64 2, $MD
// check: $VAL = cmp eq $l $r
9 changes: 9 additions & 0 deletions test/src/ir_generation/tests/gt.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script;

fn main() {
let _ = __gt(1, 2);
}

// check: $(l=$VAL) = const u64 1, $MD
// check: $(r=$VAL) = const u64 2, $MD
// check: cmp gt $l $r
9 changes: 9 additions & 0 deletions test/src/ir_generation/tests/is_reference_type.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script;

fn main() {
let _ = __is_reference_type::<u64>();
let _ = __is_reference_type::<b256>();
}

// check: $VAL = const bool false
// check: $VAL = const bool true
9 changes: 9 additions & 0 deletions test/src/ir_generation/tests/lt.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script;

fn main() {
let _ = __lt(1, 2);
}

// check: $(l=$VAL) = const u64 1, $MD
// check: $(r=$VAL) = const u64 2, $MD
// check: cmp lt $l $r
15 changes: 15 additions & 0 deletions test/src/ir_generation/tests/ptr_add.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
script;

fn main() {
let null = asm(output) { zero: raw_ptr };
let _ = __ptr_add::<u64>(null, 1);
}
// check: $VAL = get_local ptr u64, null, $MD
// check: $(ptr=$VAL) = get_local ptr u64, null, $MD
// check: $(ptr_op=$VAL) = load $ptr
// check: $(size=$VAL) = const u64 8
// check: $(count=$VAL) = const u64 1, $MD
// check: $(mul_res=$VAL) = mul $size, $count
// check: $(add_res=$VAL) = add $ptr_op, $mul_res
// check: $(dst_ptr=$VAL) = get_local ptr u64, _, $(dst_md=$MD)
// check: store $add_res to $dst_ptr, $dst_md
15 changes: 15 additions & 0 deletions test/src/ir_generation/tests/ptr_sub.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
script;

fn main() {
let null = asm(output) { zero: raw_ptr };
let _ = __ptr_sub::<u64>(null, 1);
}
// check: $VAL = get_local ptr u64, null, $MD
// check: $(ptr=$VAL) = get_local ptr u64, null, $MD
// check: $(ptr_op=$VAL) = load $ptr
// check: $(size=$VAL) = const u64 8
// check: $(count=$VAL) = const u64 1, $MD
// check: $(mul_res=$VAL) = mul $size, $count
// check: $(add_res=$VAL) = sub $ptr_op, $mul_res
// check: $(dst_ptr=$VAL) = get_local ptr u64, _, $(dst_md=$MD)
// check: store $add_res to $dst_ptr, $dst_md
8 changes: 8 additions & 0 deletions test/src/ir_generation/tests/size_of.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
script;

fn main() {
let _ = __size_of::<b256>();
}

// check: $VAL = const u64 32

9 changes: 9 additions & 0 deletions test/src/ir_generation/tests/size_of_val.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script;

fn main() {
let _ = __size_of_val(1);
}

// check: v0 = get_local ptr u64, _, !2
// check: v1 = const u64 8
// check: store v1 to v0, !2
13 changes: 13 additions & 0 deletions test/src/ir_generation/tests/state_load_quad.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
script;
fn main() {
let null = asm(output) { zero: raw_ptr };
let res = __state_load_quad(
0x0000000000000000000000000000000000000000000000000000000000000001,
null,
1,
);
}
// check: $(key=$VAL) = get_local ptr b256, key_for_storage, $(meta=$MD)
// check: $(ptr=$VAL) = int_to_ptr $VAL to ptr b256, $meta
// check: $(count=$VAL) = const u64 1, $MD
// check: $VAL = state_load_quad_word $ptr, key $key, $count, $meta
14 changes: 14 additions & 0 deletions test/src/ir_generation/tests/state_load_word.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
script;

fn main() {
let _ = __state_load_word(
0x0000000000000000000000000000000000000000000000000000000000000001,
);
}

// check: v0 = get_local ptr b256, key_for_storage, !2
// check: v1 = const b256 0x0000000000000000000000000000000000000000000000000000000000000001, !3
// check: store v1 to v0, !2
// check: v2 = state_load_word key v0, !2
// check: v3 = get_local ptr u64, _, !4
// check: store v2 to v3, !4
14 changes: 14 additions & 0 deletions test/src/ir_generation/tests/state_store_quad.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
script;

fn main() {
let null = asm(output) { zero: raw_ptr };
let _ = __state_store_quad(
0x0000000000000000000000000000000000000000000000000000000000000001,
null,
1,
);
}
// check: $(key=$VAL) = get_local ptr b256, key_for_storage, $(meta=$MD)
// check: $(ptr=$VAL) = int_to_ptr $VAL to ptr b256, $meta
// check: $(count=$VAL) = const u64 1, $MD
// check: $VAL = state_store_quad_word $ptr, key $key, $count, $meta
11 changes: 11 additions & 0 deletions test/src/ir_generation/tests/state_store_word.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
script;

fn main() {
let _ = __state_store_word(
0x0000000000000000000000000000000000000000000000000000000000000001,
1,
);
}
// check: $(key=$VAL) = get_local ptr b256, key_for_storage, $(meta=$MD)
// check: $(count=$VAL) = const u64 1, $MD
// check: $VAL = state_store_word $count, key $key, $meta
Loading