From 10797a473d6193cefe5a0f4495d89d33fa0095a1 Mon Sep 17 00:00:00 2001 From: eyck Date: Sat, 30 May 2020 13:57:01 +0200 Subject: [PATCH] modernize build system and cleanup dependencies --- CMakeLists.txt | 156 ++++++++---------- .../templates/interp/src-CORENAME.cpp.gtl | 10 -- gen_input/templates/llvm/src-CORENAME.cpp.gtl | 10 -- gen_input/templates/tcc/src-CORENAME.cpp.gtl | 10 -- softfloat/CMakeLists.txt | 59 +++---- src/iss/mnrv32.cpp | 8 - src/iss/rv32gc.cpp | 8 - src/iss/rv32imac.cpp | 8 - src/iss/rv64gc.cpp | 8 - src/iss/rv64i.cpp | 8 - src/main.cpp | 22 ++- src/sysc/core_complex.cpp | 2 +- 12 files changed, 104 insertions(+), 205 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0e72ad..cf6ceba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,42 +1,28 @@ cmake_minimum_required(VERSION 3.12) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) # main (top) cmake dir -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # project specific cmake dir -# CMake useful variables -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") +project("riscv" VERSION 1.0.0) -# Set the name of your project here -project("riscv") - -include(Common) +include(GNUInstallDirs) conan_basic_setup() find_package(Boost COMPONENTS program_options system thread filesystem REQUIRED) +if(WITH_LLVM) + if(DEFINED ENV{LLVM_HOME}) + find_path (LLVM_DIR LLVM-Config.cmake $ENV{LLVM_HOME}/lib/cmake/llvm) + endif(DEFINED ENV{LLVM_HOME}) + find_package(LLVM REQUIRED CONFIG) + message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") + message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") + llvm_map_components_to_libnames(llvm_libs support core mcjit x86codegen x86asmparser) +endif() -# This sets the include directory for the reference project. This is the -I flag in gcc. -include_directories( - ${PROJECT_SOURCE_DIR}/incl - ${SOFTFLOAT_INCLUDE_DIRS} - ${LLVM_INCLUDE_DIRS} -) -add_dependent_subproject(dbt-core) -include_directories( - ${PROJECT_SOURCE_DIR}/incl - ${PROJECT_SOURCE_DIR}/../external/elfio - ${PROJECT_SOURCE_DIR}/../external/libGIS - ${Boost_INCLUDE_DIRS} -) - - -# Mac needed variables (adapt for your needs - http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH) -set(CMAKE_MACOSX_RPATH ON) -set(CMAKE_SKIP_BUILD_RPATH FALSE) -set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) -set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +#Mac needed variables (adapt for your needs - http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH) +#set(CMAKE_MACOSX_RPATH ON) +#set(CMAKE_SKIP_BUILD_RPATH FALSE) +#set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) +#set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") +#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) add_subdirectory(softfloat) @@ -50,12 +36,6 @@ set(LIB_SOURCES src/iss/rv64gc.cpp src/iss/mnrv32.cpp src/vm/fp_functions.cpp - src/vm/llvm/fp_impl.cpp - src/vm/llvm/vm_mnrv32.cpp - src/vm/llvm/vm_rv32gc.cpp - src/vm/llvm/vm_rv32imac.cpp - src/vm/llvm/vm_rv64i.cpp - src/vm/llvm/vm_rv64gc.cpp src/vm/tcc/vm_mnrv32.cpp src/vm/tcc/vm_rv32gc.cpp src/vm/tcc/vm_rv32imac.cpp @@ -67,78 +47,78 @@ set(LIB_SOURCES src/vm/interp/vm_rv64i.cpp src/vm/interp/vm_rv64gc.cpp src/plugin/instruction_count.cpp - src/plugin/cycle_estimate.cpp) - -# Define two variables in order not to repeat ourselves. -set(LIBRARY_NAME riscv) + src/plugin/cycle_estimate.cpp +) +if(WITH_LLVM) +set(LIB_SOURCES ${LIB_SOURCES} + src/vm/llvm/fp_impl.cpp + src/vm/llvm/vm_mnrv32.cpp + src/vm/llvm/vm_rv32gc.cpp + src/vm/llvm/vm_rv32imac.cpp + src/vm/llvm/vm_rv64i.cpp + src/vm/llvm/vm_rv64gc.cpp +) +endif() # Define the library -add_library(${LIBRARY_NAME} ${LIB_SOURCES}) -SET(${LIBRARY_NAME} -Wl,-whole-archive -l${LIBRARY_NAME} -Wl,-no-whole-archive) -target_link_libraries(${LIBRARY_NAME} softfloat dbt-core scc-util) -set_target_properties(${LIBRARY_NAME} PROPERTIES - VERSION ${VERSION} # ${VERSION} was defined in the main CMakeLists. +add_library(riscv ${LIB_SOURCES}) +SET(riscv -Wl,-whole-archive -lriscv -Wl,-no-whole-archive) +target_compile_options(riscv PRIVATE -Wno-shift-count-overflow) +target_include_directories(riscv PUBLIC incl ../external/elfio) +target_link_libraries(riscv PUBLIC softfloat dbt-core scc-util) +set_target_properties(riscv PROPERTIES + VERSION ${PROJECT_VERSION} FRAMEWORK FALSE PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers ) if(SystemC_FOUND) - set(SC_LIBRARY_NAME riscv_sc) - add_library(${SC_LIBRARY_NAME} src/sysc/core_complex.cpp) - add_definitions(-DWITH_SYSTEMC) - include_directories(${SystemC_INCLUDE_DIRS}) - - include_directories(${CCI_INCLUDE_DIRS}) + add_library(riscv_sc src/sysc/core_complex.cpp) + target_compile_definitions(riscv_sc PUBLIC WITH_SYSTEMC) + target_include_directories(riscv_sc PUBLIC ../incl ${SystemC_INCLUDE_DIRS} ${CCI_INCLUDE_DIRS}) if(SCV_FOUND) - add_definitions(-DWITH_SCV) - include_directories(${SCV_INCLUDE_DIRS}) + target_compile_definitions(riscv_sc PUBLIC WITH_SCV) + target_include_directories(riscv_sc PUBLIC ${SCV_INCLUDE_DIRS}) endif() - target_link_libraries(${SC_LIBRARY_NAME} ${LIBRARY_NAME}) - target_link_libraries(${SC_LIBRARY_NAME} dbt-core) - target_link_libraries(${SC_LIBRARY_NAME} softfloat) - target_link_libraries(${SC_LIBRARY_NAME} scc) - target_link_libraries(${SC_LIBRARY_NAME} external) - target_link_libraries(${SC_LIBRARY_NAME} ${llvm_libs}) - target_link_libraries(${SC_LIBRARY_NAME} ${Boost_LIBRARIES} ) - set_target_properties(${SC_LIBRARY_NAME} PROPERTIES - VERSION ${VERSION} # ${VERSION} was defined in the main CMakeLists. + target_link_libraries(riscv_sc PUBLIC riscv scc ) + if(WITH_LLVM) + target_link_libraries(riscv_sc PUBLIC ${llvm_libs}) + endif() + target_link_libraries(riscv_sc PUBLIC ${Boost_LIBRARIES} ) + set_target_properties(riscv_sc PROPERTIES + VERSION ${PROJECT_VERSION} FRAMEWORK FALSE PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers ) endif() project("riscv-sim") - -# This is a make target, so you can do a "make riscv-sc" -set(APPLICATION_NAME riscv-sim) - -add_executable(${APPLICATION_NAME} src/main.cpp) - +add_executable(riscv-sim src/main.cpp) +# This sets the include directory for the reference project. This is the -I flag in gcc. +target_include_directories(riscv-sim PRIVATE ../external/libGIS) +if(WITH_LLVM) + target_compile_definitions(riscv-sim PRIVATE WITH_LLVM) + target_link_libraries(riscv-sim PUBLIC ${llvm_libs}) +endif() # Links the target exe against the libraries -target_link_libraries(${APPLICATION_NAME} ${LIBRARY_NAME}) -target_link_libraries(${APPLICATION_NAME} jsoncpp) -target_link_libraries(${APPLICATION_NAME} dbt-core) -target_link_libraries(${APPLICATION_NAME} external) -target_link_libraries(${APPLICATION_NAME} ${llvm_libs}) -target_link_libraries(${APPLICATION_NAME} ${Boost_LIBRARIES} ) +target_link_libraries(riscv-sim riscv) +target_link_libraries(riscv-sim jsoncpp) +target_link_libraries(riscv-sim dbt-core) +target_link_libraries(riscv-sim external) +target_link_libraries(riscv-sim ${Boost_LIBRARIES} ) if (Tcmalloc_FOUND) - target_link_libraries(${APPLICATION_NAME} ${Tcmalloc_LIBRARIES}) + target_link_libraries(riscv-sim ${Tcmalloc_LIBRARIES}) endif(Tcmalloc_FOUND) -# Says how and where to install software -# Targets: -# * /lib/ -# * header location after install: /include//*.h -# * headers can be included by C++ code `#/Bar.hpp>` -install(TARGETS ${LIBRARY_NAME} ${APPLICATION_NAME} +install(TARGETS riscv riscv-sim EXPORT ${PROJECT_NAME}Targets # for downstream dependencies - ARCHIVE DESTINATION lib COMPONENT libs # static lib - RUNTIME DESTINATION bin COMPONENT libs # binaries - LIBRARY DESTINATION lib COMPONENT libs # shared lib - FRAMEWORK DESTINATION bin COMPONENT libs # for mac - PUBLIC_HEADER DESTINATION incl/${PROJECT_NAME} COMPONENT devel # headers for mac (note the different component -> different package) - INCLUDES DESTINATION incl # headers + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # static lib + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # binaries + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # shared lib + FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # for mac + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} COMPONENT devel # headers for mac (note the different component -> different package) + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # headers ) diff --git a/gen_input/templates/interp/src-CORENAME.cpp.gtl b/gen_input/templates/interp/src-CORENAME.cpp.gtl index 6dee5fc..8ed478f 100644 --- a/gen_input/templates/interp/src-CORENAME.cpp.gtl +++ b/gen_input/templates/interp/src-CORENAME.cpp.gtl @@ -70,17 +70,7 @@ def getRegisterAliasNames(){ %> #include "util/ities.h" #include - -#include #include - -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/gen_input/templates/llvm/src-CORENAME.cpp.gtl b/gen_input/templates/llvm/src-CORENAME.cpp.gtl index 6dee5fc..8ed478f 100644 --- a/gen_input/templates/llvm/src-CORENAME.cpp.gtl +++ b/gen_input/templates/llvm/src-CORENAME.cpp.gtl @@ -70,17 +70,7 @@ def getRegisterAliasNames(){ %> #include "util/ities.h" #include - -#include #include - -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/gen_input/templates/tcc/src-CORENAME.cpp.gtl b/gen_input/templates/tcc/src-CORENAME.cpp.gtl index 6dee5fc..8ed478f 100644 --- a/gen_input/templates/tcc/src-CORENAME.cpp.gtl +++ b/gen_input/templates/tcc/src-CORENAME.cpp.gtl @@ -70,17 +70,7 @@ def getRegisterAliasNames(){ %> #include "util/ities.h" #include - -#include #include - -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/softfloat/CMakeLists.txt b/softfloat/CMakeLists.txt index db9892e..c4ea4bd 100644 --- a/softfloat/CMakeLists.txt +++ b/softfloat/CMakeLists.txt @@ -2,31 +2,17 @@ cmake_minimum_required(VERSION 3.12) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) # main (top) cmake dir set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # project specific cmake dir -# CMake useful variables -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") - # Set the name of your project here -project("sotfloat") +project("sotfloat" VERSION 3.0.0) # Set the version number of your project here (format is MAJOR.MINOR.PATCHLEVEL - e.g. 1.0.0) set(VERSION "3e") include(Common) +include(GNUInstallDirs) set(SPECIALIZATION RISCV) -add_definitions( - -DSOFTFLOAT_ROUND_ODD - -DINLINE_LEVEL=5 - -DSOFTFLOAT_FAST_DIV32TO16 - -DSOFTFLOAT_FAST_DIV64TO32 - -DSOFTFLOAT_FAST_INT64 -# -DTHREAD_LOCAL=__thread -) - - set(LIB_HEADERS source/include/softfloat.h source/include/softfloat_types.h) set(PRIMITIVES source/s_eq128.c @@ -341,32 +327,29 @@ set(OTHERS set(LIB_SOURCES ${PRIMITIVES} ${SPECIALIZE} ${OTHERS}) -# Define two variables in order not to repeat ourselves. -set(LIBRARY_NAME softfloat) - -# Define the library -add_library(${LIBRARY_NAME} ${LIB_SOURCES}) -set_property(TARGET ${LIBRARY_NAME} PROPERTY C_STANDARD 99) -target_include_directories(${LIBRARY_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/build/Linux-x86_64-GCC) -target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/source/include ${CMAKE_CURRENT_SOURCE_DIR}/source/${SPECIALIZATION}) -# Set the build version. It will be used in the name of the lib, with corresponding -# symlinks created. SOVERSION could also be specified for api version. -set_target_properties(${LIBRARY_NAME} PROPERTIES +add_library(softfloat ${LIB_SOURCES}) +set_property(TARGET softfloat PROPERTY C_STANDARD 99) +target_compile_definitions(softfloat PRIVATE + SOFTFLOAT_ROUND_ODD + INLINE_LEVEL=5 + SOFTFLOAT_FAST_DIV32TO16 + SOFTFLOAT_FAST_DIV64TO32 + SOFTFLOAT_FAST_INT64 +# THREAD_LOCAL=__thread +) +target_include_directories(softfloat PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/build/Linux-x86_64-GCC) +target_include_directories(softfloat PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/source/include ${CMAKE_CURRENT_SOURCE_DIR}/source/${SPECIALIZATION}) +set_target_properties(softfloat PROPERTIES VERSION ${VERSION} FRAMEWORK FALSE PUBLIC_HEADER "${LIB_HEADERS}" ) -# Says how and where to install software -# Targets: -# * /lib/ -# * header location after install: /include//*.h -# * headers can be included by C++ code `#/Bar.hpp>` -install(TARGETS ${LIBRARY_NAME} +install(TARGETS softfloat EXPORT ${PROJECT_NAME}Targets # for downstream dependencies - ARCHIVE DESTINATION lib COMPONENT libs # static lib - LIBRARY DESTINATION lib COMPONENT libs # shared lib - FRAMEWORK DESTINATION bin COMPONENT libs # for mac - PUBLIC_HEADER DESTINATION include COMPONENT devel # headers for mac (note the different component -> different package) - INCLUDES DESTINATION include # headers + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # static lib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # shared lib + FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # for mac + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT devel # headers for mac (note the different component -> different package) + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # headers ) diff --git a/src/iss/mnrv32.cpp b/src/iss/mnrv32.cpp index 414fdff..613bbf1 100644 --- a/src/iss/mnrv32.cpp +++ b/src/iss/mnrv32.cpp @@ -33,16 +33,8 @@ #include "util/ities.h" #include -#include #include -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/src/iss/rv32gc.cpp b/src/iss/rv32gc.cpp index 4149503..c3756f9 100644 --- a/src/iss/rv32gc.cpp +++ b/src/iss/rv32gc.cpp @@ -33,16 +33,8 @@ #include "util/ities.h" #include -#include #include -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/src/iss/rv32imac.cpp b/src/iss/rv32imac.cpp index b9e4dd7..2d8a56e 100644 --- a/src/iss/rv32imac.cpp +++ b/src/iss/rv32imac.cpp @@ -33,16 +33,8 @@ #include "util/ities.h" #include -#include #include -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/src/iss/rv64gc.cpp b/src/iss/rv64gc.cpp index 7353643..17d8dc1 100644 --- a/src/iss/rv64gc.cpp +++ b/src/iss/rv64gc.cpp @@ -35,16 +35,8 @@ #include "util/ities.h" #include -#include #include -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/src/iss/rv64i.cpp b/src/iss/rv64i.cpp index b3b875c..83070d5 100644 --- a/src/iss/rv64i.cpp +++ b/src/iss/rv64i.cpp @@ -33,16 +33,8 @@ #include "util/ities.h" #include -#include #include -#ifdef __cplusplus -extern "C" { -#endif -#include -#ifdef __cplusplus -} -#endif #include #include #include diff --git a/src/main.cpp b/src/main.cpp index c122f8f..7eb0737 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,7 +41,9 @@ #include #include #include +#ifdef WITH_LLVM #include +#endif #include #include #include @@ -56,8 +58,10 @@ std::tuple create_cpu(std::string const& backend, unsigned gdb_ CORE* lcpu = new iss::arch::riscv_hart_msu_vp(); if(backend == "interp") return {cpu_ptr{lcpu}, vm_ptr{iss::interp::create(lcpu, gdb_port)}}; +#ifdef WITH_LLVM if(backend == "llvm") return {cpu_ptr{lcpu}, vm_ptr{iss::llvm::create(lcpu, gdb_port)}}; +#endif if(backend == "tcc") return {cpu_ptr{lcpu}, vm_ptr{iss::tcc::create(lcpu, gdb_port)}}; return {nullptr, nullptr}; @@ -119,8 +123,10 @@ int main(int argc, char *argv[]) { std::vector plugin_list; auto res = 0; try { +#ifdef WITH_LLVM // application code comes here // iss::init_jit_debug(argc, argv); +#endif bool dump = clim.count("dump-ir"); // instantiate the simulator vm_ptr vm{nullptr}; @@ -130,19 +136,19 @@ int main(int argc, char *argv[]) { std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); } else if (isa_opt=="rv64i") { std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); -// } else if (isa_opt=="rv64gc") { -// std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); -// } else if (isa_opt=="rv32imac") { -// std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); -// } else if (isa_opt=="rv32gc") { -// std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); + } else if (isa_opt=="rv64gc") { + std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); + } else if (isa_opt=="rv32imac") { + std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); + } else if (isa_opt=="rv32gc") { + std::tie(cpu, vm) = create_cpu(clim["backend"].as(), clim["gdb-port"].as()); } else { LOG(ERROR) << "Illegal argument value for '--isa': " << clim["isa"].as() << std::endl; return 127; } if (clim.count("plugin")) { - for (std::string opt_val : clim["plugin"].as>()) { - std::string plugin_name{opt_val}; + for (std::string const& opt_val : clim["plugin"].as>()) { + std::string plugin_name=opt_val; std::string filename{"cycles.txt"}; std::size_t found = opt_val.find('='); if (found != std::string::npos) { diff --git a/src/sysc/core_complex.cpp b/src/sysc/core_complex.cpp index 7061dc9..1c54719 100644 --- a/src/sysc/core_complex.cpp +++ b/src/sysc/core_complex.cpp @@ -286,7 +286,7 @@ void core_complex::trace(sc_trace_file *trf) const {} void core_complex::before_end_of_elaboration() { cpu = scc::make_unique(this); - vm = llvm::create(cpu.get(), gdb_server_port.get_value(), dump_ir.get_value()); + vm = tcc::create(cpu.get(), gdb_server_port.get_value(), dump_ir.get_value()); #ifdef WITH_SCV vm->setDisassEnabled(enable_disass.get_value() || m_db != nullptr); #else