Skip to content

Commit

Permalink
Closs-platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
yatsukha committed Oct 28, 2023
1 parent 90419e2 commit b620619
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
26 changes: 16 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.10)

project(bfjit)

set(CMAKE_CXX_STANDARD 23)
# C++23 triggers a bug in llvm16, fixed in llvm17
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down Expand Up @@ -33,15 +34,20 @@ find_package(fmt REQUIRED)
# -DLLVM_DIR=/opt/homebrew/opt/llvm/lib/cmake/llvm
find_package(LLVM REQUIRED)

llvm_map_components_to_libnames(llvm_libs
core
analysis
scalaropts
instcombine
transformutils
passes
orcjit
native)
set(llvm_libs LLVM)

if(APPLE)
llvm_map_components_to_libnames(llvm_libs
core
analysis
scalaropts
instcombine
transformutils
passes
orcjit
native)
endif()

message(STATUS "LLVM found at: ${LLVM_DIR}")
message(STATUS "LLVM lib list: ${llvm_libs}")

Expand Down
11 changes: 6 additions & 5 deletions include/bfjit/io/file_chunk_iter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ namespace bfjit::io {
}

{
int const enable = 1;
// signal sequential reading on macos
// on linux this would be posix_fadvise but cba
// to make this multiplatform
::fcntl(file, F_RDAHEAD, &enable);
#ifdef __APPLE__
int const enable = 1;
::fcntl(file, F_RDAHEAD, &enable);
#elif __linux__
::posix_fadvise(file, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
}

// initialize the iter
Expand Down
2 changes: 1 addition & 1 deletion src/bfjit/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace bfjit::codegen {
main_type,
// external linkage per convention
llvm::Function::ExternalLinkage,
"jit_main",
"main",
&global_module.mod
);

Expand Down
10 changes: 9 additions & 1 deletion src/bfjit/jit/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ namespace bfjit::jit {

auto jit = llvm::cantFail(llvm::orc::LLJITBuilder().create());

// this one will make sure that symbols in the current process are
// available to the JIT code
// essentially to make sure that libc is available, e.g. getchar and putchar
jit->getMainJITDylib().addGenerator(
llvm::cantFail(
llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
jit->getDataLayout().getGlobalPrefix())));

// fmt::println(
// "architecture: {}",
// jit->getTargetTriple().getArchName().str());
Expand All @@ -33,7 +41,7 @@ namespace bfjit::jit {
std::move(smc.mod_impl),
std::move(smc.ctx_impl))));

auto main_fn = llvm::cantFail(jit->lookup("jit_main"));
auto main_fn = llvm::cantFail(jit->lookup("main"));
auto main_ptr = main_fn.toPtr<int32_t(*)()>();

// for debugging: settings set plugin.jit-loader.gdb.enable on
Expand Down

0 comments on commit b620619

Please sign in to comment.