Commit 746a9965 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Robust handling of PyXASM token collector



PyXASM needs information about the kernel signature to to token collector.

Using the last item in the list of cached kernel names is not reliable, hence the token collector to propagate this information downward.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent eca3f7b7
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ namespace qcor {
void PyXasmTokenCollector::collect(clang::Preprocessor &PP,
                                   clang::CachedTokens &Toks,
                                   std::vector<std::string> bufferNames,
                                   std::stringstream &ss) {
                                   std::stringstream &ss, const std::string &kernel_name) {
  // NEW STRATEGY
  // Loop over tokens, get source file info like line number and
  // indentation. Construct vector of lines, and for each line
@@ -105,10 +105,11 @@ void PyXasmTokenCollector::collect(clang::Preprocessor &PP,
    if (::quantum::kernels_in_translation_unit.empty()) {
      return {};
    }
    const std::string kernel_name =
        ::quantum::kernels_in_translation_unit.back();
    const std::string this_kernel_name =
        kernel_name.empty() ? ::quantum::kernels_in_translation_unit.back()
                            : kernel_name;
    const auto &[arg_types, arg_names] =
        ::quantum::kernel_signatures_in_translation_unit[kernel_name];
        ::quantum::kernel_signatures_in_translation_unit[this_kernel_name];
    return arg_names;
  }();
  // Tracking the Python scopes by the indent of code blocks
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ class PyXasmTokenCollector : public TokenCollector {
public:
  void collect(clang::Preprocessor &PP, clang::CachedTokens &Toks,
               std::vector<std::string> bufferNames,
               std::stringstream &ss) override;
               std::stringstream &ss, const std::string &kernel_name) override;
  const std::string name() const override { return "pyxasm"; }
  const std::string description() const override { return ""; }
};
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ namespace qcor {

void QuilTokenCollector::collect(clang::Preprocessor &PP,
                                 clang::CachedTokens &Toks,
                                 std::stringstream &ss) {
                                 std::stringstream &ss, const std::string &kernel_name) {
  bool inForLoop = false;
  for (int i = 0; i < Toks.size() - 1; i++) {

+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ namespace qcor {
class QuilTokenCollector : public TokenCollector {
public:
  void collect(clang::Preprocessor &PP, clang::CachedTokens &Toks,
               std::stringstream &ss) override;
               std::stringstream &ss, const std::string &kernel_name) override;
  const std::string name() const override { return "quil"; }
  const std::string description() const override { return ""; }
};
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ static const std::map<std::string, std::string> gates{
void StaqTokenCollector::collect(clang::Preprocessor &PP,
                                 clang::CachedTokens &Toks,
                                 std::vector<std::string> bufferNames,
                                 std::stringstream &ss) {
                                 std::stringstream &ss, const std::string &kernel_name) {

  // I need to know of any allocated buffers.
  std::stringstream sss, xx, put_this_after;
Loading