QCORPluginAction.cpp 1.74 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
  for (auto a : args) {
23
    xacc::info("qcor argument: " + a);
Mccaskey, Alex's avatar
Mccaskey, Alex committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  }

  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];
    }
    xacc::setOption("qcor-transforms",transformNames);
  }
51
52
53
54
55
56
  return true;
}

PluginASTAction::ActionType QCORPluginAction::getActionType() {
  return PluginASTAction::AddBeforeMainAction;
}
Mccaskey, Alex's avatar
Mccaskey, Alex committed
57
} // namespace compiler
58
59
60
61
} // namespace qcor

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