QCORPluginAction.cpp 1.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "QCORPluginAction.hpp"
#include "QCORASTConsumer.hpp"

#include "XACC.hpp"

namespace qcor {
namespace compiler {
std::unique_ptr<ASTConsumer>
QCORPluginAction::CreateASTConsumer(CompilerInstance &ci, llvm::StringRef) {
  return llvm::make_unique<QCORASTConsumer>(ci);
}

bool QCORPluginAction::ParseArgs(const CompilerInstance &ci,
Mccaskey, Alex's avatar
Mccaskey, Alex committed
14
                                 const std::vector<std::string> &args) {
15
  if (!xacc::isInitialized()) {
Mccaskey, Alex's avatar
Mccaskey, Alex committed
16
17
18
19
20
    std::vector<std::string> local;
    local.push_back("--logger-name");
    local.push_back("qcor");

    xacc::Initialize(local);
21
  }
Mccaskey, Alex's avatar
Mccaskey, Alex committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

  auto it = std::find(args.begin(), args.end(), "accelerator");
  if (it != args.end()) {
    int index = std::distance(args.begin(), it);
    auto acc = args[index + 1];
    xacc::setAccelerator(acc);
  }

  std::vector<std::string> transformations;
  it = args.begin();
  std::for_each(args.begin(), args.end(), [&](const std::string &value) {
    if (value == "transform") {
      int index = std::distance(args.begin(), it);
      auto transformationName = args[index + 1];
      transformations.push_back(transformationName);
    }
    ++it;
  });

  if (!transformations.empty()) {
    std::string transformNames = transformations[0];
    for (int i = 1; i < transformations.size(); ++i) {
      transformNames += "," + transformations[i];
    }
46
    xacc::setOption("qcor-transforms", transformNames);
Mccaskey, Alex's avatar
Mccaskey, Alex committed
47
  }
48
49
50
  return true;
}

51
52
53
// PluginASTAction::ActionType QCORPluginAction::getActionType() {
//   return PluginASTAction::AddBeforeMainAction;
// }
Mccaskey, Alex's avatar
Mccaskey, Alex committed
54
} // namespace compiler
55
56
57
58
} // namespace qcor

static FrontendPluginRegistry::Add<qcor::compiler::QCORPluginAction>
    X("enable-quantum", "Enable quantum language extension via XACC.");