Skip to content

Commit 6ac0c76

Browse files
committed
added a new emit option qe-qem to generate target-specific payload
1 parent a7dbcdf commit 6ac0c76

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

lib/API/api.cpp

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ static llvm::cl::opt<enum InputType> inputType(
121121
"load the input file as a QOBJ file")));
122122

123123
namespace {
124-
enum Action { None, DumpAST, DumpASTPretty, DumpMLIR, DumpWaveMem, GenQEM };
124+
enum Action {
125+
None,
126+
DumpAST,
127+
DumpASTPretty,
128+
DumpMLIR,
129+
DumpWaveMem,
130+
GenQEM,
131+
GenQEQEM
132+
};
125133
} // anonymous namespace
126134
static llvm::cl::opt<enum Action> emitAction(
127135
"emit", llvm::cl::init(Action::None),
@@ -134,14 +142,14 @@ static llvm::cl::opt<enum Action> emitAction(
134142
"output the waveform memory")),
135143
llvm::cl::values(clEnumValN(GenQEM, "qem",
136144
"generate a quantum executable module (qem) "
137-
"for execution on hardware")));
138-
139-
static llvm::cl::opt<bool>
140-
emitTargetQem("emit-target-qem", llvm::cl::desc("Emit target-specific qem"),
141-
llvm::cl::cat(qssc::config::getQSSCCategory()));
145+
"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")));
142150

143151
namespace qss {
144-
enum FileExtension { None, AST, ASTPRETTY, QASM, QOBJ, MLIR, WMEM, QEM };
152+
enum FileExtension { None, AST, ASTPRETTY, QASM, QOBJ, MLIR, WMEM, QEM, QEQEM };
145153
} // namespace qss
146154

147155
auto fileExtensionToStr(const qss::FileExtension &inExt) -> std::string {
@@ -167,6 +175,9 @@ auto fileExtensionToStr(const qss::FileExtension &inExt) -> std::string {
167175
case qss::FileExtension::QEM:
168176
return "qem";
169177
break;
178+
case qss::FileExtension::QEQEM:
179+
return "qeqem";
180+
break;
170181
default:
171182
return "none";
172183
break;
@@ -208,6 +219,9 @@ auto fileExtensionToAction(const qss::FileExtension &inExt) -> Action {
208219
case qss::FileExtension::QEM:
209220
return Action::GenQEM;
210221
break;
222+
case qss::FileExtension::QEQEM:
223+
return Action::GenQEQEM;
224+
break;
211225
default:
212226
break;
213227
}
@@ -229,6 +243,8 @@ auto strToFileExtension(const std::string &extStr) -> qss::FileExtension {
229243
return qss::FileExtension::WMEM;
230244
if (extStr == "qem" || extStr == "QEM")
231245
return qss::FileExtension::QEM;
246+
if (extStr == "qeqem" || extStr == "QEQEM")
247+
return qss::FileExtension::QEQEM;
232248
return qss::FileExtension::None;
233249
}
234250

@@ -539,27 +555,21 @@ compile_(int argc, char const **argv, std::string *outputString,
539555
auto outputFile = mlir::openOutputFile(outputFilename, &errorMessage);
540556
std::unique_ptr<qssc::payload::Payload> payload = nullptr;
541557

542-
if (emitAction == Action::GenQEM) {
558+
if (emitAction == Action::GenQEM || emitAction == Action::GenQEQEM) {
559+
const std::filesystem::path payloadPath(outputFilename.c_str());
560+
const std::string fNamePrefix = payloadPath.stem();
561+
const auto payloadName =
562+
(emitAction == Action::GenQEM) ? "ZIP" : config.targetName.value_or("");
563+
auto payloadInfo =
564+
qssc::payload::registry::PayloadRegistry::lookupPluginInfo(payloadName);
543565
if (outputFilename == "-") {
544-
auto payloadInfo =
545-
qssc::payload::registry::PayloadRegistry::lookupPluginInfo("ZIP");
546566
payload = std::move(
547567
payloadInfo.getValue()->createPluginInstance(llvm::None).get());
548568
} else {
549-
const auto targetName = config.targetName.value_or("");
550-
const auto pluginName =
551-
(emitTargetQem &&
552-
qssc::payload::registry::PayloadRegistry::pluginExists(targetName))
553-
? targetName
554-
: "ZIP";
555-
const std::filesystem::path payloadPath(outputFilename.c_str());
556-
const std::string fNamePrefix = payloadPath.stem();
557-
const qssc::payload::PayloadConfig config{fNamePrefix, fNamePrefix};
558-
auto payloadInfo =
559-
qssc::payload::registry::PayloadRegistry::lookupPluginInfo(
560-
pluginName);
561-
payload =
562-
std::move(payloadInfo.getValue()->createPluginInstance(config).get());
569+
const qssc::payload::PayloadConfig payloadConfig{fNamePrefix,
570+
fNamePrefix};
571+
payload = std::move(
572+
payloadInfo.getValue()->createPluginInstance(payloadConfig).get());
563573
}
564574
}
565575

0 commit comments

Comments
 (0)