LambdaVisitor.hpp 1.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef COMPILER_QCORASTVISITOR_HPP_
#define COMPILER_QCORASTVISITOR_HPP_

#include "clang/AST/Expr.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/Frontend/CompilerInstance.h"

#include "XACC.hpp"

using namespace xacc;
using namespace clang;

namespace xacc {
class IRProvider;
}
namespace qcor {
namespace compiler {

class LambdaVisitor : public RecursiveASTVisitor<LambdaVisitor> {

protected:
Mccaskey, Alex's avatar
Mccaskey, Alex committed
23
24
25
26
27
28
29
30
31
32
33
34
35
  class IsQuantumKernelVisitor
      : public RecursiveASTVisitor<IsQuantumKernelVisitor> {
  protected:
    ASTContext &context;
    bool _isQuantumKernel = false;
    std::vector<std::string> validInstructions;

  public:
    IsQuantumKernelVisitor(ASTContext &c);
    bool VisitDeclRefExpr(DeclRefExpr *expr);
    bool isQuantumKernel() { return _isQuantumKernel; }
  };

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  class CppToXACCIRVisitor : public RecursiveASTVisitor<CppToXACCIRVisitor> {
  protected:
    ASTContext &context;

    std::shared_ptr<Function> function;
    std::shared_ptr<xacc::IRProvider> provider;

    std::string gateName = "";
    std::vector<int> bits;
    std::vector<InstructionParameter> parameters;

  public:
    CppToXACCIRVisitor(ASTContext &c);
    bool VisitCallExpr(CallExpr *expr);
    bool VisitDeclRefExpr(DeclRefExpr *expr);
    bool VisitIntegerLiteral(IntegerLiteral *literal);
    bool VisitFloatingLiteral(FloatingLiteral *literal);
    std::shared_ptr<Function> getFunction();
  };

public:
  LambdaVisitor(CompilerInstance &c);

  bool VisitLambdaExpr(LambdaExpr *LE);

private:
  CompilerInstance &ci;
};
} // namespace compiler
} // namespace qcor
#endif