Commit d977e41f authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

working on clang fuzzy parsing and qcor xacc compiler implementation

parent 26027617
Loading
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -37,5 +37,16 @@ link_directories(${XACC_LIBRARY_DIR})

message(STATUS "${CLANG_INCLUDE_DIRS}")

macro(qcor_enable_rpath LIBNAME)
  if(APPLE)
    set_target_properties(${LIBNAME} PROPERTIES INSTALL_RPATH "@loader_path/../lib")
    set_target_properties(${LIBNAME}
                          PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
  else()
    set_target_properties(${LIBNAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
    set_target_properties(${LIBNAME} PROPERTIES LINK_FLAGS "-shared")
  endif()
endmacro()

add_subdirectory(compiler)
add_subdirectory(instructions)
+40 −7
Original line number Diff line number Diff line
set(LIBRARY_NAME qcor-ast-plugin) 
add_library(${LIBRARY_NAME} SHARED QCorPluginASTAction.cpp)
target_include_directories(${LIBRARY_NAME} PUBLIC .)
target_include_directories(${LIBRARY_NAME} PUBLIC ${CLANG_INCLUDE_DIRS})
target_include_directories(${LIBRARY_NAME} PUBLIC ${LLVM_INCLUDE_DIRS})
target_include_directories(${LIBRARY_NAME} PUBLIC ${XACC_INCLUDE_DIRS})
target_link_libraries(${LIBRARY_NAME} PUBLIC ${CLANG_LIBS} ${XACC_LIBRARIES})
add_subdirectory(clang)

set(LIBRARY_NAME qcor-compiler)

file(GLOB SRC *.cpp)

usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC)
usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC)

add_library(${LIBRARY_NAME} SHARED ${SRC})

target_include_directories(${LIBRARY_NAME}
                            PUBLIC .
                                ${XACC_INCLUDE_DIRS}
                                )

target_link_libraries(${LIBRARY_NAME} PUBLIC xacc)

set(_bundle_name qcor_compiler)
set_target_properties(${LIBRARY_NAME}
                      PROPERTIES COMPILE_DEFINITIONS
                                 US_BUNDLE_NAME=${_bundle_name}
                                 US_BUNDLE_NAME
                                 ${_bundle_name})

usfunctionembedresources(TARGET
                         ${LIBRARY_NAME}
                         WORKING_DIRECTORY
                         ${CMAKE_CURRENT_SOURCE_DIR}
                         FILES
                         manifest.json)

qcor_enable_rpath(${LIBRARY_NAME})

if(QCOR_BUILD_TESTS)
  #add_subdirectory(tests)
endif()

file(GLOB HEADERS *.hpp)

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
+22 −0
Original line number Diff line number Diff line

#include "QCORCompiler.hpp"

namespace qcor {

std::shared_ptr<IR> QCORCompiler::compile(const std::string &src,
                                            std::shared_ptr<Accelerator> acc) {

  return nullptr;
}

std::shared_ptr<IR> QCORCompiler::compile(const std::string &src) {
  return compile(src, nullptr);
}

const std::string
QCORCompiler::translate(const std::string &bufferVariable,
                          std::shared_ptr<Function> function) {
  return "";
}

}
+104 −0
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2019 UT-Battelle, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompanies this
 * distribution. The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution
 *License is available at https://eclipse.org/org/documents/edl-v10.php
 *
 * Contributors:
 *   Alexander J. McCaskey - initial API and implementation
 *******************************************************************************/
#ifndef COMPILER_QCORCOMPILER_HPP_
#define COMPILER_QCORCOMPILER_HPP_
#include "XACC.hpp"
#include "antlr4-runtime.h"

using namespace xacc;

namespace qcor {

/**
 * An Antlr error listener for handling parsing errors.
 */
class QCORCompilerErrorListener : public antlr4::BaseErrorListener {
public:
  void syntaxError(antlr4::Recognizer *recognizer,
                   antlr4::Token *offendingSymbol, size_t line,
                   size_t charPositionInLine, const std::string &msg,
                   std::exception_ptr e) override {
    std::ostringstream output;
    output << "Invalid QCOR source: ";
    output << "line " << line << ":" << charPositionInLine << " " << msg;
    xacc::error(output.str());
  }
};

/**
 * The PyXACCCompiler is an XACC Compiler that compiles
 * python-like gate instruction source code to produce a
 * XACC IR.
 */
class QCORCompiler : public xacc::Compiler {

public:
  /**
   * The Compiler.
   */
  QCORCompiler() {}

  /**
   * Compile the given kernel code for the
   * given Accelerator.
   *
   * @param src The source code
   * @param acc Reference to the D-Wave Accelerator
   * @return
   */
  virtual std::shared_ptr<xacc::IR> compile(const std::string &src,
                                            std::shared_ptr<Accelerator> acc);

  /**
   * Compile the given kernel code.
   *
   * @param src The source code
   * @return
   */
  virtual std::shared_ptr<xacc::IR> compile(const std::string &src);

  /**
   * Return the command line options for this compiler
   *
   * @return options Description of command line options.
   */
  virtual std::shared_ptr<options_description> getOptions() {
    auto desc =
        std::make_shared<options_description>("QCOR Compiler Options");
    return desc;
  }

  virtual bool handleOptions(variables_map &map) { return false; }

  /**
   * We don't allow translations for the PyXACC Compiler.
   * @param bufferVariable
   * @param function
   * @return
   */
  virtual const std::string translate(const std::string &bufferVariable,
                                      std::shared_ptr<Function> function);

  virtual const std::string name() const { return "qcor"; }

  virtual const std::string description() const { return ""; }

  /**
   * The destructor
   */
  virtual ~QCORCompiler() {}
};

} // namespace xacc

#endif
+35 −0
Original line number Diff line number Diff line
#include "QCORCompiler.hpp"

#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"

#include <memory>
#include <set>

using namespace cppmicroservices;

namespace {

/**
 */
class US_ABI_LOCAL QCORActivator : public BundleActivator {

public:
  QCORActivator() {}

  /**
   */
  void Start(BundleContext context) {

    auto s = std::make_shared<qcor::QCORCompiler>();
    context.RegisterService<xacc::Compiler>(s);
  }

  /**
   */
  void Stop(BundleContext /*context*/) {}
};

} // namespace

CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(QCORActivator)
Loading