From fd61bbf8348484dac8b15ec52eb6e2a4b91c681b Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 21 Feb 2017 23:44:38 +0100 Subject: [PATCH] Refulang now compiles and runs on Macosx --- cmake/FindGperf.cmake | 5 ++++- cmake/RFRefuConfig.cmake | 4 +--- cmake/RFUseLLVM.cmake | 8 +++++++- rfbase | 2 +- src/ast/iterable.c | 4 ++-- src/backend/llvm.c | 15 ++++++++++++--- test.sh | 28 ++++++++++++++++++++++++++++ 7 files changed, 55 insertions(+), 11 deletions(-) diff --git a/cmake/FindGperf.cmake b/cmake/FindGperf.cmake index d542e0c3..f8ec8551 100644 --- a/cmake/FindGperf.cmake +++ b/cmake/FindGperf.cmake @@ -29,7 +29,10 @@ function(rf_use_gperf TARGET) GPERF_VERSION_STRING ${GPERF_VERSION_OUTPUT} ) - if(NOT CMAKE_MATCH_1 OR NOT CMAKE_MATCH_2) + + # Assert that both major and minor version are parsed. + if((NOT CMAKE_MATCH_1 AND NOT CMAKE_MATCH_1 STREQUAL "0") + OR (NOT CMAKE_MATCH_2 AND NOT CMAKE_MATCH_2 STREQUAL "0")) message(AUTHOR_WARNING "Error during check for gperf version.") endif() diff --git a/cmake/RFRefuConfig.cmake b/cmake/RFRefuConfig.cmake index 7e20fcc1..c6fad6f6 100644 --- a/cmake/RFRefuConfig.cmake +++ b/cmake/RFRefuConfig.cmake @@ -56,11 +56,9 @@ buffer used by the compiler to store all messages" rf_use_gperf(${TARGET}) # Deal with LLVM - find_package(LLVM REQUIRED CONFIG) + rf_use_llvm(${TARGET}) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - rf_use_llvm(${TARGET}) - # link with rfbase target_link_libraries(${TARGET} PUBLIC rfbase) diff --git a/cmake/RFUseLLVM.cmake b/cmake/RFUseLLVM.cmake index b98f99c2..ec849774 100644 --- a/cmake/RFUseLLVM.cmake +++ b/cmake/RFUseLLVM.cmake @@ -3,7 +3,13 @@ # TARGET -- The target for which to configure LLVM function(rf_use_llvm TARGET) - find_package(LLVM REQUIRED CONFIG) + if (APPLE) + set(PATHS_TO_SEARCH "/usr/local/opt/llvm") + endif() + find_package( + LLVM REQUIRED CONFIG + PATHS ${PATHS_TO_SEARCH} + ) message("LLVM INCLUDES: ${LLVM_INCLUDE_DIRS}") target_include_directories(${TARGET} PUBLIC ${LLVM_INCLUDE_DIRS}) message("LLVM DEFS: ${LLVM_DEFINITIONS}") diff --git a/rfbase b/rfbase index 239105dd..b0f05f59 160000 --- a/rfbase +++ b/rfbase @@ -1 +1 @@ -Subproject commit 239105dd9c4be54e29221e6c83302b4bbcec707a +Subproject commit b0f05f592abb9a682d0d2a1fc2ce67ed501cfd23 diff --git a/src/ast/iterable.c b/src/ast/iterable.c index 5c57378e..e5c9cd14 100644 --- a/src/ast/iterable.c +++ b/src/ast/iterable.c @@ -138,8 +138,8 @@ int64_t ast_iterable_range_number_of_loops(const struct ast_node *n) return -1; } - int64_t breadth = abs(end - start); - int64_t abs_step = abs(step); + int64_t breadth = llabs(end - start); + int64_t abs_step = llabs(step); return abs_step == 0 ? breadth : breadth / abs_step; } diff --git a/src/backend/llvm.c b/src/backend/llvm.c index c1ba576c..60bb149a 100644 --- a/src/backend/llvm.c +++ b/src/backend/llvm.c @@ -194,11 +194,20 @@ static bool bllvm_ir_to_asm(struct compiler_args *args) static bool backend_asm_to_exec(struct compiler_args *args) { static const struct RFstring compiler_exec = RF_STRING_STATIC_INIT("gcc"); + + return transformation_step_do( + args, + &compiler_exec, + "s", + "exe", + "-L"RF_LANG_CORE_ROOT"/build/rfbase/ -lrfbase" #ifdef COVERAGE - return transformation_step_do(args, &compiler_exec, "s", "exe", "-L"RF_LANG_CORE_ROOT"/build/rfbase/ -lrfbase -lgcov -static"); -#else - return transformation_step_do(args, &compiler_exec, "s", "exe", "-L"RF_LANG_CORE_ROOT"/build/rfbase/ -lrfbase -static"); + " -lgcov" +#endif +#ifndef __APPLE__ + " -static" #endif + ); } bool bllvm_generate(struct modules_arr *modules, struct compiler_args *args) diff --git a/test.sh b/test.sh index e53a5de6..dd279c8f 100755 --- a/test.sh +++ b/test.sh @@ -21,6 +21,34 @@ IN_TRAVIS=0 TRAVIS_JOB_ID=0 REQUESTED_ARG="" +exists () { + local __result=$2 + if type "$1" >/dev/null 2>/dev/null; then + local myresult=1 + else + local myresult=0 + fi + eval $__result="'$myresult'" +} + +exists "llvm-config" LLVM_CONFIG_EXISTS +# Assert that llvm binaries are accessible in the path +if [[ $LLVM_CONFIG_EXISTS -eq 0 ]]; then + if [[ "$OSTYPE" == "darwin"* ]]; then + export PATH="$PATH:/usr/local/opt/llvm/bin/" + exists "llvm-config" LLVM_CONFIG_EXISTS + if [[ $LLVM_CONFIG_EXISTS -eq 0 ]]; then + echo "test.sh - ERROR: llvm-config not found in the path. Have you installed llvm?" + echo " If you have, then have you added the proper directory in the path?" + exit 1 + fi + else + echo "test.sh - ERROR: llvm-config not found in the path. Have you installed llvm?" + echo " If you have, then have you added the proper directory in the path?" + exit 1 + fi +fi + function print_help { echo "Usage: test.sh [extra-options]" echo "Arguments:"