Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: false
ColumnLimit: 80
ColumnLimit: 120
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 8
Expand Down
26 changes: 6 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,20 @@ set(PROJECT_VERSION 3.0.0-alpha.3)
set(PROJECT_DESCRIPTION "The ROOT-Sim C Compiler")
set(CMAKE_VERBOSE_MAKEFILE ON)

include(ExternalProject)

add_definitions(-DROOTSIM_VERSION=${PROJECT_VERSION})
add_compile_options(-Wall -Wextra -pedantic)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(LLVM REQUIRED CONFIG)
find_package(CLANG REQUIRED CONFIG)

include_directories(src)

# Build the compiler, the plugins, the userspace libraries
add_executable(rootsimcc
src/compiler/rootsimcc.c
src/datatypes/dynstr.c
)

add_library(rsmeminstr SHARED
src/plugins/rootsim-cc_llvm.cpp
)
find_package(MPI REQUIRED)

add_library(rsmodel STATIC
src/lib/config/jsmn.c
src/lib/config/reflect.c
src/datatypes/vector.c
src/lib/argparse/argparse.c
)
add_subdirectory(src)

# Run the tests
enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(DOXYGEN_FOUND)
set(DOXYGEN_PROJECT_LOGO img/rs.png)
set(DOXYGEN_HTML_EXTRA_STYLESHEET flatdoc.css inline-params.css)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ../README.md)
doxygen_add_docs(doc
doxygen_add_docs(rootsimcc-doc
"../src"
"../README.md"
ALL
Expand Down
31 changes: 31 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build the compiler, the plugins, the userspace libraries

add_executable(compiler compiler/compiler.cpp)

string (REPLACE ";" " -I" MPI_INCLUDES "${MPI_C_INCLUDE_DIRS}")
string (REPLACE ";" " -l" MPI_LIBS "${MPI_C_LIBRARIES}")
string (REPLACE ";" " " MPI_COMPILE_DEFINITIONS "${MPI_C_COMPILE_DEFINITIONS}")

target_compile_definitions(compiler PRIVATE
ROOTSIM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/lib"
ROOTSIM_INC_DIR="${CMAKE_INSTALL_PREFIX}/include"
MPI_LIBS="${MPI_LIBS}"
MPI_INCLUDES_FLAGS="-I${MPI_INCLUDES}")

add_library(rsllvmwrap SHARED plugin/wrap.cpp)
target_include_directories(rsllvmwrap PRIVATE . ${LLVM_INCLUDE_DIRS})
# Disable the warning for unused function parameters: LLVM codebase is riddled with those
target_compile_options(rsllvmwrap PRIVATE -Wno-unused-parameter)

if(${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "14")
target_compile_definitions(compiler PRIVATE LLVM_USE_NEW_PASS_MANAGER)
target_compile_definitions(rsllvmwrap PRIVATE LLVM_USE_NEW_PASS_MANAGER)
endif()

add_library(rsmodel STATIC model_lib/argparse.c model_lib/init.c model_lib/model_main.c)
target_include_directories(rsmodel PRIVATE . ${CMAKE_SOURCE_DIR}/subprojects/core/src)

install(TARGETS compiler rsllvmwrap rsmodel
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
109 changes: 109 additions & 0 deletions src/compiler/compiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* @file compiler/compiler.cpp
*
* @brief The ROOT-Sim compiler
*
* This is the ROOT-Sim compiler, a compiler wrapper which allows to setup all necessary includes and configurations to
* run with a parallel or distributed simulation. This is targeting low level C models.
*
* SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com>
* SPDX-License-Identifier: GPL-3.0-only
*/
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

#ifndef ROOTSIM_OPTIMIZATION_OPTIONS
/// The optimization options to be used when compiling models
/** This macro is filled in at build time */
#define ROOTSIM_OPTIMIZATION_OPTIONS "-g"
#endif

#ifndef ROOTSIM_CC
/// The path of the C compiler to use when compiling models
/** This macro is filled in at build time */
#define ROOTSIM_CC "clang"
#endif

#ifndef MPI_INCLUDES_FLAGS
/// The path of the C compiler to use when compiling models
/** This macro is filled in at build time */
#define MPI_INCLUDES_FLAGS ""
#endif

#ifndef MPI_LIBS
/// The path of the C compiler to use when compiling models
/** This macro is filled in at build time */
#define MPI_LIBS ""
#endif

#ifndef ROOTSIM_LIB_DIR
/// The path of the installed ROOT-Sim libraries
/** This macro is filled in at build time */
#define ROOTSIM_LIB_DIR ""
#endif

#ifndef ROOTSIM_INC_DIR
/// The path of the installed ROOT-Sim headers
/** This macro is filled in at build time */
#define ROOTSIM_INC_DIR ""
#endif

static const char *options[] = {"-rsinc", "-rslib"};

static int extract_options(const char *const *args, const char **parsed_options, std::string &remaining)
{
if(*args == nullptr) {
std::cerr << "No input files\n";
return -1;
}

do {
for(unsigned i = 0; i < sizeof(options) / sizeof(*options); ++i) {
if(std::strcmp(*args, options[i]) == 0) {
parsed_options[i] = *(++args);
if(parsed_options[i] == nullptr) {
std::cerr << "Option " + std::string(options[i]) + " is missing its argument\n";
return -1;
}
}
}
remaining.append(" ");
remaining.append(*args);
++args;
} while(*args);
return 0;
}

/**
* @brief The main entry point of the custom compiler
* @param argc The count of command line arguments, as per ISO C standard
* @param argv The list of command line arguments, as per ISO C standard
*/
int main(int argc, char *argv[])
{
(void)argc;
const char *parsed_options[sizeof(options) / sizeof(*options)] = {ROOTSIM_INC_DIR, ROOTSIM_LIB_DIR};

std::string command_line(ROOTSIM_CC);
if(extract_options(&argv[1], parsed_options, command_line) < 0)
return EXIT_FAILURE;

command_line.append(" " MPI_INCLUDES_FLAGS " " ROOTSIM_OPTIMIZATION_OPTIONS);

command_line.append(" -I");
command_line.append(parsed_options[0]);

command_line.append(" -L");
command_line.append(parsed_options[1]);
#ifdef LLVM_USE_NEW_PASS_MANAGER
command_line.append(" -fpass-plugin=");
#else
command_line.append(" -flegacy-pass-manager -Xclang -load -Xclang ");
#endif
command_line.append(parsed_options[1]);
command_line.append("/librsllvmwrap.so -Wl,--as-needed -lrscore -lrsmodel -lm -lpthread " MPI_LIBS);

return std::system(command_line.c_str());
}
111 changes: 0 additions & 111 deletions src/compiler/rootsimcc.c

This file was deleted.

Loading