microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/pipeline-issue-debugging

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/compiler/qsc_codegen/src/qir/instruction_tests/phi.rs

69lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::qir::ToQir;
5use expect_test::expect;
6use qsc_rir::rir;
7
8#[test]
9#[should_panic(expected = "phi instruction should have at least one argument")]
10fn phi_with_empty_args() {
11 let args = [];
12 let inst = rir::Instruction::Phi(
13 args.to_vec(),
14 rir::Variable {
15 variable_id: rir::VariableId(0),
16 ty: rir::Ty::Integer,
17 },
18 );
19 let _ = &inst.to_qir(&rir::Program::default());
20}
21
22#[test]
23fn phi_with_single_arg() {
24 let args = [(
25 rir::Operand::Variable(rir::Variable {
26 variable_id: rir::VariableId(13),
27 ty: rir::Ty::Integer,
28 }),
29 rir::BlockId(3),
30 )];
31 let inst = rir::Instruction::Phi(
32 args.to_vec(),
33 rir::Variable {
34 variable_id: rir::VariableId(0),
35 ty: rir::Ty::Integer,
36 },
37 );
38 expect![" %var_0 = phi i64 [%var_13, %block_3]"]
39 .assert_eq(&inst.to_qir(&rir::Program::default()));
40}
41
42#[test]
43fn phi_with_multiple_args() {
44 let args = [
45 (
46 rir::Operand::Variable(rir::Variable {
47 variable_id: rir::VariableId(13),
48 ty: rir::Ty::Integer,
49 }),
50 rir::BlockId(3),
51 ),
52 (
53 rir::Operand::Variable(rir::Variable {
54 variable_id: rir::VariableId(2),
55 ty: rir::Ty::Integer,
56 }),
57 rir::BlockId(7),
58 ),
59 ];
60 let inst = rir::Instruction::Phi(
61 args.to_vec(),
62 rir::Variable {
63 variable_id: rir::VariableId(0),
64 ty: rir::Ty::Integer,
65 },
66 );
67 expect![" %var_0 = phi i64 [%var_13, %block_3], [%var_2, %block_7]"]
68 .assert_eq(&inst.to_qir(&rir::Program::default()));
69}
70