diff --git a/python_lib/qss_compiler/lib.cpp b/python_lib/qss_compiler/lib.cpp index 865a112ae..63f1f09ef 100644 --- a/python_lib/qss_compiler/lib.cpp +++ b/python_lib/qss_compiler/lib.cpp @@ -222,19 +222,40 @@ py::tuple py_compile_file(const std::string &inputFile, std::move(onDiagnostic)); } +qssc::config::EmitAction parseEmitAction(const std::string &name) { + if (name == "ast") + return qssc::config::EmitAction::AST; + if (name == "ast-pretty") + return qssc::config::EmitAction::ASTPretty; + if (name == "mlir") + return qssc::config::EmitAction::MLIR; + if (name == "bytecode") + return qssc::config::EmitAction::Bytecode; + if (name == "wmem") + return qssc::config::EmitAction::WaveMem; + if (name == "qem") + return qssc::config::EmitAction::QEM; + if (name == "qeqem") + return qssc::config::EmitAction::QEQEM; + + return qssc::config::EmitAction::None; +} + py::tuple py_link_file(const std::string &input, const bool enableInMemoryInput, const std::string &outputPath, const std::string &target, + const std::string &emitActionString, const std::string &configPath, const std::unordered_map &arguments, bool treatWarningsAsErrors, qssc::DiagnosticCallback onDiagnostic) { std::string inMemoryOutput(""); + auto emitAction = parseEmitAction(emitActionString); - int const status = qssc::bindArguments( - target, qssc::config::EmitAction::QEM, configPath, input, outputPath, - arguments, treatWarningsAsErrors, enableInMemoryInput, &inMemoryOutput, - std::move(onDiagnostic)); + int const status = + qssc::bindArguments(target, emitAction, configPath, input, outputPath, + arguments, treatWarningsAsErrors, enableInMemoryInput, + &inMemoryOutput, std::move(onDiagnostic)); bool const success = status == 0; #ifndef NDEBUG diff --git a/python_lib/qss_compiler/link.py b/python_lib/qss_compiler/link.py index 7244614e1..1ced6b7f6 100644 --- a/python_lib/qss_compiler/link.py +++ b/python_lib/qss_compiler/link.py @@ -20,6 +20,7 @@ """ from dataclasses import dataclass, field +from enum import Enum from importlib import resources as importlib_resources from os import environ as os_environ from typing import Mapping, Any, Optional, Callable, Union @@ -31,6 +32,16 @@ from . import exceptions +class InputType(Enum): + """Enumeration of input types supported by the link""" + + QEM = "qem" + QEQEM = "qe-qem" + + def __str__(self): + return self.value + + @dataclass class LinkOptions: """Options to the linker tool.""" @@ -42,6 +53,8 @@ class LinkOptions: output_file: Union[str, None] = None """Output file, if not supplied raw bytes will be returned.""" target: str = None + """Input source type.""" + input_type: InputType = InputType.QEM """Hardware target to select.""" arguments: Mapping[str, Any] = field(default_factory=lambda: {}) """Set the specific execution arguments of a pre-compiled program @@ -75,6 +88,8 @@ def link_file( output_file: Path to write the output payload to. target: Compiler target to invoke for binding arguments (must match with the target that created the module). + input_type: Input file type to invoke for binding arguments (must match + with the output type that created the module). arguments: Circuit arguments as name/value map. Returns: Produces a payload in a file. @@ -129,6 +144,7 @@ def on_diagnostic(diag): enable_in_memory, output_file, link_options.target, + str(link_options.input_type), config_path, link_options.arguments, link_options.treat_warnings_as_errors, diff --git a/releasenotes/notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml b/releasenotes/notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml new file mode 100644 index 000000000..b8ddb080c --- /dev/null +++ b/releasenotes/notes/add_emit_option_to_link_file-8901fd3d6ed51d98.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--emit`` option to ``link_file`` function to specify a file format + of target file to be linked.