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

adding first pass at xasm and staq clang syntax handlers

parent f0677aad
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -21,9 +21,10 @@ 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)
include_directories(/home/cades/dev/llvm-project-csp/build/xacc_llvm_install/include)
add_subdirectory(handlers)
add_subdirectory(runtime)
add_subdirectory(compiler)
add_subdirectory(ir)
#add_subdirectory(compiler)
#add_subdirectory(ir)

install(PROGRAMS ${CMAKE_BINARY_DIR}/qcor DESTINATION bin)
+2 −0
Original line number Diff line number Diff line
add_subdirectory(xasm)
add_subdirectory(staq)
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
set(LIBRARY_NAME qcor-staq-handler)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
add_library(${LIBRARY_NAME}
            SHARED
            staq_syntax_handler.cpp)

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

target_link_libraries(${LIBRARY_NAME}
                      PRIVATE ${CLANG_LIBS} ${LLVM_LIBS})


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

install(TARGETS ${LIBRARY_NAME} DESTINATION clang-plugins)
+34 −0
Original line number Diff line number Diff line
#include <qalloc>

[[clang::syntax(staq)]] void add_3_5(qreg a, qreg b, qreg c) {
  oracle adder a0,a1,a2,a3,b0,b1,b2,b3,c0,c1,c2,c3 { "add_3_5.v" }
  creg result[4];
  // a = 3
  x a[0];
  x a[1];

  // b = 5
  x b[0];
  x b[2];

  adder a[0],a[1],a[2],a[3],b[0],b[1],b[2],b[3],c[0],c[1],c[2],c[3];

  // measure
  measure c -> result;
}

int main(int argc, char** argv) {

    auto a = qalloc(4);
    auto b = qalloc(4);
    auto c = qalloc(4);

    // Execute on the quantum accelerator
    add_3_5(a, b, c);

    // Get the results and display
    auto counts = c.counts();
    for (const auto & kv: counts) {
        printf("%s: %i\n", kv.first.c_str(), kv.second);
    }
}
+31 −0
Original line number Diff line number Diff line
module top (\a[0],\a[1],\a[2],\a[3],\b[0],\b[1],\b[2],\b[3],\c[0],\c[1],\c[2],\c[3]);
  input \a[0],\a[1],\a[2],\a[3],\b[0],\b[1],\b[2],\b[3];
  output \c[0],\c[1],\c[2],\c[3];
  wire n386,n387,n388,n389,n390,n391,n392,n393,n394,n395,n396,n397,n398,n399,n400,n401,n402,n403,n404,n405,n406,n407,n408,n409,n410 ;
  assign n386 = \a[0]  & ~\b[0] ;
  assign n387 = ~\a[0]  & \b[0] ;
  assign \c[0]  = n386 | n387;
  assign n389 = \a[0]  & \b[0] ;
  assign n390 = ~\a[1]  & ~\b[1] ;
  assign n391 = \a[1]  & \b[1] ;
  assign n392 = ~n390 & ~n391;
  assign n393 = n389 & ~n392;
  assign n394 = ~n389 & n392;
  assign \c[1]  = n393 | n394;
  assign n396 = n389 & ~n390;
  assign n397 = ~n391 & ~n396;
  assign n398 = ~\a[2]  & ~\b[2] ;
  assign n399 = \a[2]  & \b[2] ;
  assign n400 = ~n398 & ~n399;
  assign n401 = n397 & ~n400;
  assign n402 = ~n397 & n400;
  assign \c[2]  = ~n401 & ~n402;
  assign n404 = ~n397 & ~n398;
  assign n405 = ~n399 & ~n404;
  assign n406 = ~\a[3]  & ~\b[3] ;
  assign n407 = \a[3]  & \b[3] ;
  assign n408 = ~n406 & ~n407;
  assign n409 = n405 & ~n408;
  assign n410 = ~n405 & n408;
  assign \c[3]  = ~n409 & ~n410;
endmodule
Loading