Skip to content
Open
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
# IDE files
.vscode

# Clangd cache files
.cache/

# Temporaries
*~

Expand Down
7 changes: 6 additions & 1 deletion ArchImpl/RV32IMACFD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
PROJECT(RV32IMACFD)

SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../../include/jit/etiss/jit")
IF(APPLE)
# macOS uses @loader_path instead of $ORIGIN
SET(CMAKE_INSTALL_RPATH "@loader_path/../../include/jit/etiss/jit")
ELSE()
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../../include/jit/etiss/jit")
ENDIF()

ADD_LIBRARY(${PROJECT_NAME} SHARED
RV32IMACFDArch.cpp
Expand Down
4 changes: 1 addition & 3 deletions ArchImpl/RV32IMACFD/RV32IMACFDFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ extern "C"

void leave(etiss_int32 priv_lvl);

void wait(etiss_int32 flag);

etiss_uint8 RV32IMACFD_extension_enabled(ETISS_CPU * const cpu, ETISS_System * const system, void * const * const plugin_pointers, etiss_int8 extension);

etiss_uint32 fadd_s(etiss_uint32, etiss_uint32, etiss_uint8);
Expand Down Expand Up @@ -119,4 +117,4 @@ etiss_int64 etiss_semihost(ETISS_CPU * const cpu, ETISS_System * const system, v
}
#endif

#endif
#endif
7 changes: 6 additions & 1 deletion ArchImpl/RV64IMACFD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
PROJECT(RV64IMACFD)

SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../../include/jit/etiss/jit")
IF(APPLE)
# macOS uses @loader_path instead of $ORIGIN
SET(CMAKE_INSTALL_RPATH "@loader_path/../../include/jit/etiss/jit")
ELSE()
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../../include/jit/etiss/jit")
ENDIF()

ADD_LIBRARY(${PROJECT_NAME} SHARED
RV64IMACFDArch.cpp
Expand Down
4 changes: 1 addition & 3 deletions ArchImpl/RV64IMACFD/RV64IMACFDFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ extern "C"

void leave(etiss_int32 priv_lvl);

void wait(etiss_int32 flag);

etiss_uint8 RV64IMACFD_extension_enabled(ETISS_CPU * const cpu, ETISS_System * const system, void * const * const plugin_pointers, etiss_int8 extension);

etiss_uint32 fadd_s(etiss_uint32, etiss_uint32, etiss_uint8);
Expand Down Expand Up @@ -125,4 +123,4 @@ etiss_int64 etiss_semihost(ETISS_CPU * const cpu, ETISS_System * const system, v
}
#endif

#endif
#endif
32 changes: 29 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ option(ETISS_BUILD_MANUAL_DOC "If enabled then the documentation will not be bui
option(ETISS_BUILD_DEFAULTSUB "If enabled then the ArchImpl,JITImpl,PluginImpl and projects folder will be added as subfolders. Please have a look at the CMakeLists.txt files of those folders for further information" ON)
option(ETISS_USE_PROFILEFLAGS "Enable or disable the -pg compiler and linker flags." OFF)
option(ETISS_USE_COREDSL_COVERAGE "Enable the CoreDSL coverage analyzer" OFF)
option(ETISS_TRANSLATOR_STAT "Enable translator statistics (cache hits/misses)" ON)
option(ETISS_TRANSLATOR_STAT_WITH_EXECUTION_STAT "Enable translator statistics (cache hits/misses)" OFF)
option(ETISS_NEW_DECODER "Use hierarchical map-based instruction decoder instead of chunk-based decoder" OFF)

# Global configuration
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down Expand Up @@ -64,7 +67,13 @@ ELSE()

# Set relative rpath to mimic runtime link behavior of windows (libs loadable from current dir)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "\$ORIGIN")
IF(APPLE)
# macOS uses @loader_path instead of $ORIGIN
SET(CMAKE_INSTALL_RPATH "@loader_path")
SET(CMAKE_MACOSX_RPATH TRUE)
ELSE()
SET(CMAKE_INSTALL_RPATH "\$ORIGIN")
ENDIF()


ENDIF()
Expand All @@ -86,6 +95,18 @@ IF(ETISS_USE_COREDSL_COVERAGE)
ADD_DEFINITIONS(-DETISS_USE_COREDSL_COVERAGE)
ENDIF()

IF(ETISS_TRANSLATOR_STAT)
ADD_DEFINITIONS(-DETISS_TRANSLATOR_STAT)
ENDIF()

IF(ETISS_TRANSLATOR_STAT_WITH_EXECUTION_STAT)
ADD_DEFINITIONS(-DETISS_TRANSLATOR_STAT_WITH_EXECUTION_STAT)
ENDIF()

IF(ETISS_NEW_DECODER)
ADD_DEFINITIONS(-DETISS_NEW_DECODER)
ENDIF()

# Include modules.
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${ETISS_ROOT}/cmake"
Expand All @@ -101,7 +122,9 @@ INCLUDE(ETISSPlugin)

# Find packages
FIND_PACKAGE(Threads REQUIRED)
FIND_PACKAGE(Boost COMPONENTS filesystem system program_options REQUIRED)
# boost::system is header-only in recent Boost releases, so no compiled library is
# required; drop it from the component list for macOS/Homebrew.
FIND_PACKAGE(Boost COMPONENTS filesystem program_options REQUIRED)
FIND_PACKAGE(Doxygen)
IF(ETISS_USE_PYTHON)
SET(Boost_VERBOSE ON)
Expand Down Expand Up @@ -309,7 +332,7 @@ set_target_properties(ETISS PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/
)
IF(UNIX)
TARGET_LINK_LIBRARIES(ETISS PUBLIC Boost::filesystem Boost::system Boost::program_options)
TARGET_LINK_LIBRARIES(ETISS PUBLIC Boost::filesystem Boost::program_options)
ELSE(UNIX)
TARGET_LINK_LIBRARIES(ETISS PUBLIC Boost::boost Threads::Threads)
ENDIF()
Expand Down Expand Up @@ -388,5 +411,8 @@ message(STATUS "ETISS_VERSION_FULL: ${ETISS_VERSION_FULL}")
message(STATUS "ETISS_USE_PYTHON: ${ETISS_USE_PYTHON}")
message(STATUS "ETISS_USE_PROFILEFLAGS: ${ETISS_USE_PROFILEFLAGS}")
message(STATUS "ETISS_USE_COREDSL_COVERAGE: ${ETISS_USE_COREDSL_COVERAGE}")
message(STATUS "ETISS_TRANSLATOR_STAT: ${ETISS_TRANSLATOR_STAT}")
message(STATUS "ETISS_TRANSLATOR_STAT_WITH_EXECUTION_STAT: ${ETISS_TRANSLATOR_STAT_WITH_EXECUTION_STAT}")
message(STATUS "ETISS_NEW_DECODER: ${ETISS_NEW_DECODER}")
message(STATUS "ETISS_USE_DLSYM: ${ETISS_USE_DLSYM}")
message(STATUS "ETISS_BUILD_MANUAL_DOC: ${ETISS_BUILD_MANUAL_DOC}")
3 changes: 3 additions & 0 deletions JITImpl/GCC/GCCJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ void *GCCJIT::translate(std::string code, std::set<std::string> headerpaths, std
ss.str("");

ss << "gcc -shared ";
#ifdef __APPLE__
ss << "-undefined dynamic_lookup ";
#endif
/*
if (debug)
ss <<"-g -dl ";
Expand Down
2 changes: 1 addition & 1 deletion JITImpl/GCC/GCCJITLIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C"
{
etiss::Configuration cfg;
cfg.config() = options;
return new GCCJIT(cfg.get<bool>("jit.gcc.cleanup", true), cfg.get<std::string>("jit.gcc.opt_level", "fast"),
return new GCCJIT(cfg.get<bool>("jit.gcc.cleanup", true), cfg.get<std::string>("jit.gcc.opt_level", "3"),
cfg.get<bool>("jit.gcc.quiet", false));
}

Expand Down
10 changes: 9 additions & 1 deletion JITImpl/LLVM/LLVMJITLIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LLVMJIT.h"

#include <iostream>
#include "etiss/Misc.h"

// implement etiss library interface
extern "C"
Expand Down Expand Up @@ -42,7 +43,14 @@ extern "C"
switch (index)
{
case 0:
return new etiss::LLVMJIT();
{
etiss::Configuration cfg;
cfg.config() = options;
return new etiss::LLVMJIT(
cfg.get<std::string>("jit.llvm.opt_level", "3"),
cfg.get<bool>("jit.llvm.quiet", true)
);
}
default:
return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion JITImpl/LLVM/include/LLVMJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace etiss
class LLVMJIT : public etiss::JIT
{
public:
LLVMJIT();
LLVMJIT(const std::string &opt_level = "3", bool quiet = false);
virtual ~LLVMJIT();
virtual void *translate(std::string code, std::set<std::string> headerpaths, std::set<std::string> librarypaths,
std::set<std::string> libraries, std::string &error, bool debug = false);
Expand All @@ -29,6 +29,8 @@ class LLVMJIT : public etiss::JIT
private:
std::unique_ptr<OrcJit> orcJit_;
std::unordered_set<std::string> loadedLibs_;
std::string opt_level_;
bool quiet_;
};

} // namespace etiss
21 changes: 17 additions & 4 deletions JITImpl/LLVM/src/LLVMJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ class OrcJit
for (const auto &libPath : libPaths)
{
SmallString<128> fullPath;
sys::path::append(fullPath, libPath, "lib" + libName + ".so");
sys::path::append(fullPath, libPath, "lib" + libName +
#ifdef __APPLE__
".dylib"
#else
".so"
#endif
);
if (sys::fs::exists(fullPath))
{
MainJITDylib.addGenerator(llvm::cantFail(
Expand Down Expand Up @@ -114,7 +120,7 @@ class OrcJit
llvm::orc::JITDylib &MainJITDylib;
};

LLVMJIT::LLVMJIT() : JIT("LLVMJIT")
LLVMJIT::LLVMJIT(const std::string &opt_level, bool quiet) : JIT("LLVMJIT"), opt_level_(opt_level), quiet_(quiet)
{

// init environment once
Expand All @@ -138,6 +144,7 @@ void *LLVMJIT::translate(std::string code, std::set<std::string> headerpaths, st
{
clang::CompilerInstance CI;
compat::createDiagnostics(CI);
CI.getDiagnostics().setIgnoreAllWarnings(quiet_);
auto pto = std::make_shared<clang::TargetOptions>();
pto->Triple = llvm::sys::getDefaultTargetTriple();
TargetInfo *pti = TargetInfo::CreateTargetInfo(CI.getDiagnostics(), pto);
Expand All @@ -154,17 +161,23 @@ void *LLVMJIT::translate(std::string code, std::set<std::string> headerpaths, st
}
else
{
args.push_back("-O3");
args.push_back("-O" + opt_level_); // Use configurable opt level
}
args.push_back("-std=c99");
args.push_back("-isystem" + etiss::jitFiles() + "/clang_stdlib");
#ifdef __APPLE__
// macOS: system headers are in the SDK, not /usr/include
args.push_back("-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include");
#else
// Linux: system headers are in /usr/include
args.push_back("-isystem/usr/include");
args.push_back("-isystem/usr/include/x86_64-linux-gnu");
#endif
for (const auto &headerPath : headerpaths)
{
args.push_back("-isystem" + headerPath);
}
args.push_back("/etiss_llvm_clang_memory_mapped_file.c");
args.push_back("-isystem/usr/include/x86_64-linux-gnu");

for (const auto &lib : libraries)
{
Expand Down
Loading