Loading mlir/parsers/qasm3/tests/test_declaration.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,29 @@ for i in [0:22] { EXPECT_TRUE(qcor::execute(src2, "test")); } TEST(qasm3VisitorTester, checkGate) { const std::string gate_def = R"#(OPENQASM 3; gate cphase(x) a, b { U(0, 0, x / 2) a; CX a, b; U(0, 0, -x / 2) b; CX a, b; U(0, 0, x / 2) b; } )#"; auto mlir = qcor::mlir_compile(gate_def, "gate_def", qcor::OutputType::MLIR, false); std::cout << "gate_def MLIR:\n" << mlir << "\n"; qcor::execute(gate_def, "gate_def"); std::cout << "LLVM:\n" << qcor::mlir_compile(gate_def, "gate_def", qcor::OutputType::LLVMIR, false) << "\n"; } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); Loading mlir/parsers/qasm3/visitor_handlers/quantum_types_handler.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,12 @@ antlrcpp::Any qasm3_visitor::visitQuantumGateDefinition( // from this custom gate definition std::vector<mlir::Value> result_qubit_vals; for (auto arg : entryBlock.getArguments()) { // check if argument is a gate param if (arg.getType().isF64()) { result_qubit_vals.push_back(arg); // skip use chain traversal continue; } mlir::Value last_user = arg; auto users = last_user.getUsers(); Loading Loading
mlir/parsers/qasm3/tests/test_declaration.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,29 @@ for i in [0:22] { EXPECT_TRUE(qcor::execute(src2, "test")); } TEST(qasm3VisitorTester, checkGate) { const std::string gate_def = R"#(OPENQASM 3; gate cphase(x) a, b { U(0, 0, x / 2) a; CX a, b; U(0, 0, -x / 2) b; CX a, b; U(0, 0, x / 2) b; } )#"; auto mlir = qcor::mlir_compile(gate_def, "gate_def", qcor::OutputType::MLIR, false); std::cout << "gate_def MLIR:\n" << mlir << "\n"; qcor::execute(gate_def, "gate_def"); std::cout << "LLVM:\n" << qcor::mlir_compile(gate_def, "gate_def", qcor::OutputType::LLVMIR, false) << "\n"; } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); Loading
mlir/parsers/qasm3/visitor_handlers/quantum_types_handler.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,12 @@ antlrcpp::Any qasm3_visitor::visitQuantumGateDefinition( // from this custom gate definition std::vector<mlir::Value> result_qubit_vals; for (auto arg : entryBlock.getArguments()) { // check if argument is a gate param if (arg.getType().isF64()) { result_qubit_vals.push_back(arg); // skip use chain traversal continue; } mlir::Value last_user = arg; auto users = last_user.getUsers(); Loading