Commit 57688f0b authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Improved fuzzy parsing, got test working with c++14

parent 6207f596
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ find_package(XACC REQUIRED)

configure_file(${CMAKE_SOURCE_DIR}/scripts/qcor.in
               ${CMAKE_BINARY_DIR}/qcor)

include_directories(/home/cades/dev/llvm-project/clang/include)
add_subdirectory(runtime)
add_subdirectory(compiler)
add_subdirectory(ir)
+19 −33
Original line number Diff line number Diff line
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})
set(LIBRARY_NAME qcor-ast-plugin)
add_library(${LIBRARY_NAME}
            SHARED
            fuzzy_parsing.cpp
            qcor_ast_visitor.cpp
            qcor_ast_consumer.cpp)

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

target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc qcor-ast-plugin ${CLANG_LIBS} ${LLVM_LIBS})

set(_bundle_name qcor_compiler)
set_target_properties(${LIBRARY_NAME}
                      PROPERTIES COMPILE_DEFINITIONS
                                 US_BUNDLE_NAME=${_bundle_name}
                                 US_BUNDLE_NAME
                                 ${_bundle_name})
target_link_libraries(${LIBRARY_NAME}
                      PUBLIC ${CLANG_LIBS} ${LLVM_LIBS} tinfo xacc::xacc)

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

xacc_configure_plugin_rpath(${LIBRARY_NAME})
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)

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

file(GLOB HEADERS *.hpp)

install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
configure_file(qcor-driver.in.cpp
               ${CMAKE_BINARY_DIR}/compiler/qcor-driver.cpp)
#add_executable(qcor-driver ${CMAKE_BINARY_DIR}/compiler/qcor-driver.cpp)
#target_link_libraries(qcor-driver PRIVATE qcor-ast-plugin qcor)
#install(PROGRAMS ${CMAKE_BINARY_DIR}/compiler/qcor-driver DESTINATION bin)

compiler/QCORCompiler.cpp

deleted100644 → 0
+0 −46
Original line number Diff line number Diff line

#include "QCORCompiler.hpp"
#include "IRProvider.hpp"
#include "xacc_service.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::shared_ptr<Function>
QCORCompiler::compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) {

   auto provider = xacc::getService<xacc::IRProvider>("quantum");
   auto ir = provider->createIR();
   ir->addKernel(f);

   // FIXME Hardware Independent Transformation

   // Hardware Dependent Transformations
   if (acc) {
       auto ts = acc->getIRTransformations();
       for (auto& t : ts) {
           ir = t->transform(ir);
       }
   }

   // FIXME Program Verification???

   return f;
}

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

}

compiler/QCORCompiler.hpp

deleted100644 → 0
+0 −78
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"

using namespace xacc;

namespace qcor {

/**
 * 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);

  const std::shared_ptr<Function>
  compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) override;
  

  /**
   * 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
+0 −40
Original line number Diff line number Diff line
#include "QCORCompiler.hpp"

#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"
#include "clang/FuzzyParsingExternalSemaSource.hpp"
#include "clang/QCORExternalSemaSource.hpp"

#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);

    auto es = std::make_shared<qcor::compiler::FuzzyParsingExternalSemaSource>();
    context.RegisterService<qcor::compiler::QCORExternalSemaSource>(es);
  }

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

} // namespace

CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(QCORActivator)
Loading