Skip to content

Commit 7e04d58

Browse files
committed
add error checking for qe-qem
1 parent 6ac0c76 commit 7e04d58

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/API/api.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ static llvm::cl::opt<enum Action> emitAction(
143143
llvm::cl::values(clEnumValN(GenQEM, "qem",
144144
"generate a quantum executable module (qem) "
145145
"for execution on hardware")),
146-
llvm::cl::values(
147-
clEnumValN(GenQEQEM, "qe-qem",
148-
"generate a target-specific quantum executable module (qem) "
149-
"for execution on hardware")));
146+
llvm::cl::values(clEnumValN(
147+
GenQEQEM, "qe-qem",
148+
"generate a target-specific quantum executable module (qeqem) "
149+
"for execution on hardware")));
150150

151151
namespace qss {
152152
enum FileExtension { None, AST, ASTPRETTY, QASM, QOBJ, MLIR, WMEM, QEM, QEQEM };
@@ -555,13 +555,21 @@ compile_(int argc, char const **argv, std::string *outputString,
555555
auto outputFile = mlir::openOutputFile(outputFilename, &errorMessage);
556556
std::unique_ptr<qssc::payload::Payload> payload = nullptr;
557557

558+
if (emitAction == Action::GenQEQEM && !config.targetName.has_value())
559+
return llvm::createStringError(
560+
llvm::inconvertibleErrorCode(),
561+
"Unsupported target-specific payload: no target");
558562
if (emitAction == Action::GenQEM || emitAction == Action::GenQEQEM) {
559563
const std::filesystem::path payloadPath(outputFilename.c_str());
560564
const std::string fNamePrefix = payloadPath.stem();
561565
const auto payloadName =
562-
(emitAction == Action::GenQEM) ? "ZIP" : config.targetName.value_or("");
566+
(emitAction == Action::GenQEM) ? "ZIP" : config.targetName.value();
563567
auto payloadInfo =
564568
qssc::payload::registry::PayloadRegistry::lookupPluginInfo(payloadName);
569+
if (payloadInfo == llvm::None)
570+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
571+
"Unsupported target-specific payload: " +
572+
payloadName);
565573
if (outputFilename == "-") {
566574
payload = std::move(
567575
payloadInfo.getValue()->createPluginInstance(llvm::None).get());

0 commit comments

Comments
 (0)