Loading examples/qsharp/FTQC/qasm3/qs_call_qasm/kernel.qasm +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ OPENQASM 3; include "stdgates.inc"; #pragma { export; } def qasm_x qubit:qb { print("Hello from QASM3!"); x qb; Loading examples/qsharp/FTQC/qasm3/qsharp_lib_integration/kernel.qasm +2 −0 Original line number Diff line number Diff line Loading @@ -3,10 +3,12 @@ OPENQASM 3; include "stdgates.inc"; #pragma { export; } def qasm_x qubit:qb { x qb; } #pragma { export; } def qasm_h qubit:qb { h qb; } No newline at end of file mlir/parsers/qasm3/qasm3_visitor.hpp +16 −1 Original line number Diff line number Diff line Loading @@ -168,6 +168,18 @@ class qasm3_visitor : public qasm3::qasm3BaseVisitor { return 0; } antlrcpp::Any visitPragma(qasm3Parser::PragmaContext *ctx) override { // Handle the #pragma { export; } directive // Mark the export bool flag so that the later sub-routine handler will pick it up. if (ctx->statement().size() == 1 && ctx->statement(0)->getText() == "export;") { // The handler needs to reset this flag after handling the sub-routine. assert(!export_subroutine_as_callable); export_subroutine_as_callable = true; return 0; } else { return visitChildren(ctx); } } protected: // Reference to the MLIR OpBuilder and ModuleOp // this MLIRGen task Loading @@ -188,6 +200,9 @@ class qasm3_visitor : public qasm3::qasm3BaseVisitor { // return statement for subroutines bool subroutine_return_statment_added = false; bool is_return_stmt = false; // Flag to indicate that we should add a callable export // for the next subroutine. bool export_subroutine_as_callable = false; // Keep track of expected subroutine return type mlir::Type current_function_return_type; Loading mlir/parsers/qasm3/visitor_handlers/subroutine_handler.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -168,6 +168,8 @@ void add_callable_gen(mlir::OpBuilder &builder, const std::string &func_name, } // Add a function to create the callable wrapper for this kernel // Naming convention: <Kernel Name>__callable() // Returns a Callable* wrapping the underlying kernel (via the above 4 functors) auto create_callable_func_type = builder.getFunctionType({}, callable_type); const std::string create_callable_fn_name = func_name + "__callable"; auto create_callable_func_proto = Loading Loading @@ -392,8 +394,12 @@ antlrcpp::Any qasm3_visitor::visitSubroutineDefinition( m_module.push_back(interop); // TODO: add a compile switch to enable/disable this export: // There is a #pragma {export;} directive above this kernel // generate the export function. if (export_subroutine_as_callable) { add_callable_gen(builder, subroutine_name, m_module, function); export_subroutine_as_callable = false; } return 0; } Loading tools/driver/qcor.in +1 −1 Original line number Diff line number Diff line Loading @@ -449,7 +449,7 @@ def main(argv=None): # process to single file text = 'OPENQASM 3;\n' + \ '\n'.join([line for line in result.split('\n') if 'OPENQASM' not in line and len(line) > 0 and ('#pragma' not in line and 'no-entrypoint' not in line)]) if 'OPENQASM' not in line and len(line) > 0 and (not ('#pragma' in line and 'no_entrypoint' in line))]) base_name = os.path.splitext(filename)[0].split(os.path.sep)[-1] Loading Loading
examples/qsharp/FTQC/qasm3/qs_call_qasm/kernel.qasm +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ OPENQASM 3; include "stdgates.inc"; #pragma { export; } def qasm_x qubit:qb { print("Hello from QASM3!"); x qb; Loading
examples/qsharp/FTQC/qasm3/qsharp_lib_integration/kernel.qasm +2 −0 Original line number Diff line number Diff line Loading @@ -3,10 +3,12 @@ OPENQASM 3; include "stdgates.inc"; #pragma { export; } def qasm_x qubit:qb { x qb; } #pragma { export; } def qasm_h qubit:qb { h qb; } No newline at end of file
mlir/parsers/qasm3/qasm3_visitor.hpp +16 −1 Original line number Diff line number Diff line Loading @@ -168,6 +168,18 @@ class qasm3_visitor : public qasm3::qasm3BaseVisitor { return 0; } antlrcpp::Any visitPragma(qasm3Parser::PragmaContext *ctx) override { // Handle the #pragma { export; } directive // Mark the export bool flag so that the later sub-routine handler will pick it up. if (ctx->statement().size() == 1 && ctx->statement(0)->getText() == "export;") { // The handler needs to reset this flag after handling the sub-routine. assert(!export_subroutine_as_callable); export_subroutine_as_callable = true; return 0; } else { return visitChildren(ctx); } } protected: // Reference to the MLIR OpBuilder and ModuleOp // this MLIRGen task Loading @@ -188,6 +200,9 @@ class qasm3_visitor : public qasm3::qasm3BaseVisitor { // return statement for subroutines bool subroutine_return_statment_added = false; bool is_return_stmt = false; // Flag to indicate that we should add a callable export // for the next subroutine. bool export_subroutine_as_callable = false; // Keep track of expected subroutine return type mlir::Type current_function_return_type; Loading
mlir/parsers/qasm3/visitor_handlers/subroutine_handler.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -168,6 +168,8 @@ void add_callable_gen(mlir::OpBuilder &builder, const std::string &func_name, } // Add a function to create the callable wrapper for this kernel // Naming convention: <Kernel Name>__callable() // Returns a Callable* wrapping the underlying kernel (via the above 4 functors) auto create_callable_func_type = builder.getFunctionType({}, callable_type); const std::string create_callable_fn_name = func_name + "__callable"; auto create_callable_func_proto = Loading Loading @@ -392,8 +394,12 @@ antlrcpp::Any qasm3_visitor::visitSubroutineDefinition( m_module.push_back(interop); // TODO: add a compile switch to enable/disable this export: // There is a #pragma {export;} directive above this kernel // generate the export function. if (export_subroutine_as_callable) { add_callable_gen(builder, subroutine_name, m_module, function); export_subroutine_as_callable = false; } return 0; } Loading
tools/driver/qcor.in +1 −1 Original line number Diff line number Diff line Loading @@ -449,7 +449,7 @@ def main(argv=None): # process to single file text = 'OPENQASM 3;\n' + \ '\n'.join([line for line in result.split('\n') if 'OPENQASM' not in line and len(line) > 0 and ('#pragma' not in line and 'no-entrypoint' not in line)]) if 'OPENQASM' not in line and len(line) > 0 and (not ('#pragma' in line and 'no_entrypoint' in line))]) base_name = os.path.splitext(filename)[0].split(os.path.sep)[-1] Loading