Skip to content

Commit

Permalink
Refulang now compiles and runs on Macosx
Browse files Browse the repository at this point in the history
  • Loading branch information
LefterisJP committed Feb 21, 2017
1 parent 14c6d2a commit fd61bbf
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 11 deletions.
5 changes: 4 additions & 1 deletion cmake/FindGperf.cmake
Expand Up @@ -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()

Expand Down
4 changes: 1 addition & 3 deletions cmake/RFRefuConfig.cmake
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion cmake/RFUseLLVM.cmake
Expand Up @@ -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}")
Expand Down
4 changes: 2 additions & 2 deletions src/ast/iterable.c
Expand Up @@ -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;
}

Expand Down
15 changes: 12 additions & 3 deletions src/backend/llvm.c
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions test.sh
Expand Up @@ -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:"
Expand Down

0 comments on commit fd61bbf

Please sign in to comment.