Skip to content

Commit

Permalink
Refactor project structure and CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Dec 18, 2022
1 parent 190418a commit fe5264c
Show file tree
Hide file tree
Showing 219 changed files with 210 additions and 151 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.o
Makefile

CMakeLists.txt.user*


# Qt generated files
moc_*
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.buildDirectory": "C:/Users/Morten/Downloads/build-Ripes-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug"
}
14 changes: 5 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ elseif(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbig-obj") # Allow big object
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

######################################################################
## GUI setup
######################################################################
Expand All @@ -48,11 +50,13 @@ find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5Charts CONFIG REQUIRED)

# Finding Qt includes
# Include Qt includes
# TODO: fix this, it's VSRTL which relies on global includes...
include_directories(${Qt5Widgets_INCLUDE_DIRS})
include_directories(${Qt5Core_INCLUDE_DIRS})
include_directories(${Qt5Charts_INCLUDE_DIRS})


######################################################################
## Resources setup
######################################################################
Expand All @@ -65,14 +69,6 @@ qt5_add_resources(FONTS_SRC ${CMAKE_SOURCE_DIR}/resources/fonts/fonts.qrc)
## Library setup
######################################################################

# Header-only libraries used in the project must be included from top CMakeLists.txt file
include_directories(${RIPES_LIB} SYSTEM PUBLIC external/VSRTL/external/cereal/include)
include_directories(${RIPES_LIB} PUBLIC external/VSRTL/external)
include_directories(SYSTEM external/ELFIO)
include_directories(SYSTEM external/VSRTL/external/Signals)
include_directories(external/libelfin_cmake)
include_directories(external)

option(RIPES_BUILD_VERILATOR_PROCESSORS "Build verilator processors" OFF)
if(RIPES_BUILD_VERILATOR_PROCESSORS)
if(NOT DEFINED ENV{VERILATOR_ROOT})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 60 additions & 0 deletions include/processors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.9)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Allow linking parent libraries with libraries defined in subdirectories
cmake_policy(SET CMP0079 NEW)

macro(create_isa_lib isa)
file(GLOB LIB_SOURCES ${isa}/*.cpp)
file(GLOB LIB_HEADERS
RipesVSRTLProcessor.h
ripesvsrtlprocessor.h
${isa}/*.h)
add_library(${isa}_lib ${LIB_SOURCES} ${LIB_HEADERS})
endmacro()

macro(create_vsrtl_processor isa name)
file(GLOB LIB_SOURCES ${isa}/${name}/*.cpp)
file(GLOB LIB_HEADERS RipesVSRTLProcessor.h ${isa}/${name}/*.h)
add_library(${name} ${LIB_SOURCES} ${LIB_HEADERS})
target_link_libraries(${name} ${VSRTL_CORE_LIB} ${isa}_lib)
target_include_directories(${name} PUBLIC ${isa})
target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${name} PUBLIC ${CMAKE_SOURCE_DIR}/external)
target_compile_features(${name} PRIVATE cxx_std_17)
endmacro()

macro(create_verilator_processor
SUBFOLDER
PROCFOLDER
SOURCES
TOP
ARGS
)
file(GLOB LIB_SOURCES ${SUBFOLDER}/*.cpp)
file(GLOB LIB_HEADERS ${SUBFOLDER}/*.h)

add_library(${SUBFOLDER} ${LIB_SOURCES} ${LIB_HEADERS})
target_compile_features(${SUBFOLDER} PRIVATE cxx_std_17)

# Link processor against Verilator runtime library
target_link_libraries(${SUBFOLDER} PUBLIC ${VERILATOR_LIB})
# Link Ripes lib against the processor library (Verilator processors are not header-only)
target_link_libraries(${RIPES_LIB} PUBLIC ${SUBFOLDER})

verilate(${SUBFOLDER}
TOP_MODULE ${TOP}
SOURCES ${SOURCES}
VERILATOR_ARGS ${ARGS})

endmacro()

# RISC-V Processors
create_isa_lib(RISC-V)
create_vsrtl_processor(RISC-V rvss)
create_vsrtl_processor(RISC-V rv5s)
create_vsrtl_processor(RISC-V rv5s_no_fw_hz)
create_vsrtl_processor(RISC-V rv5s_no_hz)
create_vsrtl_processor(RISC-V rv5s_no_fw)
create_vsrtl_processor(RISC-V rv6s_dual)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "VSRTL/core/vsrtl_logicgate.h"
#include "VSRTL/core/vsrtl_multiplexer.h"

#include "../../ripesvsrtlprocessor.h"
#include "processors/ripesvsrtlprocessor.h"

// Functional units
#include "../riscv.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions include/processors/layouts.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<RCC>
<qresource prefix="/layouts">
<file>RISC-V/rvss/rv_ss_extended_layout.json</file>
<file>RISC-V/rvss/rv_ss_standard_layout.json</file>
<file>RISC-V/rv5s/rv5s_standard_layout.json</file>
<file>RISC-V/rv5s/rv5s_extended_layout.json</file>
<file>RISC-V/rv5s_no_fw_hz/rv5s_no_fw_hz_standard_layout.json</file>
<file>RISC-V/rv5s_no_fw_hz/rv5s_no_fw_hz_extended_layout.json</file>
<file>RISC-V/rv5s_no_hz/rv5s_no_hz_standard_layout.json</file>
<file>RISC-V/rv5s_no_hz/rv5s_no_hz_extended_layout.json</file>
<file>RISC-V/rv5s_no_fw/rv5s_no_fw_standard_layout.json</file>
<file>RISC-V/rv5s_no_fw/rv5s_no_fw_extended_layout.json</file>
<file>RISC-V/rv6s_dual/rv6s_dual_extended_layout.json</file>
</qresource>
</RCC>
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/programviewer.h → include/programviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "assembler/objdump.h"
#include "assembler/program.h"
#include "highlightabletextedit.h"
#include "editor/highlightabletextedit.h"
#include "processorhandler.h"

namespace Ripes {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/savedialog.h → include/savedialog.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "program.h"
#include "assembler/program.h"
#include "ripessettings.h"
#include <QDialog>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions include/version/gen_versionnumber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define RIPES_GIT_VERSION "N/A"
File renamed without changes.
6 changes: 3 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <QTimer>
#include <iostream>

#include "src/cli/clioptions.h"
#include "src/cli/clirunner.h"
#include "src/mainwindow.h"
#include "cli/clioptions.h"
#include "cli/clirunner.h"
#include "mainwindow.h"

using namespace std;

Expand Down
78 changes: 31 additions & 47 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,17 @@ function(check_nonempty_string STR)
endif()
endfunction()

# Function to create sub-libraries for the Ripes library. A library is
# built based on the *.h,*.cpp and *.ui within the immediate directory of
# the CMakeLists.txt file. If LINK_TO_RIPES_LIB is set, the ${RIPES_LIB}
# will be linked to the newly defined library.
function(create_ripes_lib NAME)
cmake_parse_arguments(OPTIONS
"LINK_TO_RIPES_LIB;FIXED_NAME;EXCLUDE_SRC_INC" # options
"" # 1-valued keywords
"" # multi-valued keywords
${ARGN})

file(GLOB LIB_SOURCES *.cpp)
file(GLOB LIB_HEADERS *.h)
file(GLOB LIB_UI *.ui)
if(NOT OPTIONS_FIXED_NAME)
check_nonempty_string(NAME)
set(LIB_NAME ${NAME}_lib)
else()
check_nonempty_string(OPTIONS_FIXED_NAME)
set(LIB_NAME ${NAME})
endif()

add_library(${LIB_NAME} STATIC ${LIB_SOURCES} ${LIB_HEADERS} ${LIB_UI})
target_compile_features(${LIB_NAME} PRIVATE cxx_std_17)
target_include_directories (${LIB_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(${LIB_NAME} PUBLIC Qt5::Gui)
if(NOT OPTIONS_EXCLUDE_SRC_INC)
target_include_directories(${LIB_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/src)
endif()

if(OPTIONS_LINK_TO_RIPES_LIB)
target_link_libraries(${RIPES_LIB} PUBLIC ${LIB_NAME})
endif()
# Appends the .cpp and .ui files to the ripes library.
function(add_ripes_sources NAME)
file(GLOB DIR_SOURCES *.cpp)
file(GLOB DIR_UI *.ui)

# Also pull in the includes from the correspoding directory in
# ${CMAKE_SOURCE_DIR}/include. This is a bit antithetical to CMake
# but is needed for Qt AUTOMOC to run.
file(RELATIVE_PATH CURRENT_DIR_PATH_RELATIVE ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB DIR_INCLUDES ${CMAKE_SOURCE_DIR}/include/${CURRENT_DIR_PATH_RELATIVE}/*.h)
target_sources(${RIPES_LIB} PUBLIC ${DIR_SOURCES} ${DIR_UI} ${DIR_INCLUDES})
endfunction()

# Error flags on everything but MSVC
Expand All @@ -52,10 +27,27 @@ elseif(MINGW)
endif()

# Create the parent library. This will include everything in the current directory.
create_ripes_lib(${RIPES_LIB} FIXED_NAME EXCLUDE_SRC_INC)
add_library(${RIPES_LIB} STATIC)
target_include_directories(${RIPES_LIB} PUBLIC ${CMAKE_SOURCE_DIR}/include)
add_ripes_sources(${RIPES_LIB})

target_link_libraries(${RIPES_LIB} PUBLIC
fancytabbar_lib
${VSRTL_GRAPHICS_LIB}
Qt5::Charts
dwarf++
Qt5::Gui)

# Header-only library includes
target_include_directories(${RIPES_LIB} PUBLIC
${CMAKE_SOURCE_DIR}/external/VSRTL/external/cereal/include
${CMAKE_SOURCE_DIR}/external/VSRTL/external
${CMAKE_SOURCE_DIR}/external/ELFIO
${CMAKE_SOURCE_DIR}/external/VSRTL/external/Signals
${CMAKE_SOURCE_DIR}/external/libelfin_cmake
${CMAKE_SOURCE_DIR}/external
)

# All of the following subdirectories will create separate libraries and link them into
# ripes_lib
add_subdirectory(isa)
add_subdirectory(cachesim)
add_subdirectory(editor)
Expand All @@ -66,11 +58,3 @@ add_subdirectory(utilities)
add_subdirectory(processors)
add_subdirectory(version)
add_subdirectory(cli)

# Also link Qt and VSRTL libraries.
target_link_libraries(${RIPES_LIB} PUBLIC
fancytabbar_lib
${VSRTL_GRAPHICS_LIB}
Qt5::Charts
dwarf++)

2 changes: 1 addition & 1 deletion src/assembler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create_ripes_lib(assembler LINK_TO_RIPES_LIB)
add_ripes_sources(assembler)
5 changes: 2 additions & 3 deletions src/assembler/assemblerbase.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "assemblerbase.h"

#include "parserutilities.h"
#include "assembler/assemblerbase.h"
#include "assembler/parserutilities.h"

namespace Ripes {
namespace Assembler {
Expand Down
8 changes: 4 additions & 4 deletions src/assembler/expreval.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "expreval.h"
#include "assembler/expreval.h"

#include <iostream>
#include <memory>

#include "assembler_defines.h"
#include "assembler/assembler_defines.h"
#include "assembler/parserutilities.h"
#include "binutils.h"
#include "parserutilities.h"

namespace Ripes {
namespace Assembler {
Expand All @@ -22,7 +22,7 @@ const QString s_exprTokens QStringLiteral("()+-*/%@");
struct Expr;

struct Printable {
virtual ~Printable(){};
virtual ~Printable() {}
virtual void print(std::ostream &str) const = 0;
};

Expand Down
4 changes: 2 additions & 2 deletions src/assembler/gnudirectives.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "gnudirectives.h"
#include "assembler.h"
#include "assembler/gnudirectives.h"
#include "assembler/assembler.h"

namespace Ripes {
namespace Assembler {
Expand Down
4 changes: 2 additions & 2 deletions src/assembler/objdump.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "objdump.h"
#include "assembler/objdump.h"

#include "../processorhandler.h"
#include "processorhandler.h"
#include <QDataStream>

namespace Ripes {
Expand Down
3 changes: 1 addition & 2 deletions src/assembler/parserutilities.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "parserutilities.h"

#include "assembler/parserutilities.h"
#include "binutils.h"

namespace Ripes {
Expand Down
2 changes: 1 addition & 1 deletion src/assembler/program.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "program.h"
#include "assembler/program.h"

#include "processorhandler.h"

Expand Down
12 changes: 6 additions & 6 deletions src/assembler/rv32i_assembler.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "rv32i_assembler.h"
#include "gnudirectives.h"
#include "assembler/rv32i_assembler.h"
#include "assembler/gnudirectives.h"
#include "assembler/rvrelocations.h"
#include "ripessettings.h"
#include "rvrelocations.h"

#include <QByteArray>
#include <algorithm>

#include "rv_c_ext.h"
#include "rv_i_ext.h"
#include "rv_m_ext.h"
#include "assembler/rv_c_ext.h"
#include "assembler/rv_i_ext.h"
#include "assembler/rv_m_ext.h"

namespace Ripes {
namespace Assembler {
Expand Down
16 changes: 8 additions & 8 deletions src/assembler/rv64i_assembler.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "rv64i_assembler.h"
#include "gnudirectives.h"
#include "assembler/rv64i_assembler.h"
#include "assembler/gnudirectives.h"
#include "assembler/rv32i_assembler.h"
#include "assembler/rvassembler_common.h"
#include "assembler/rvrelocations.h"
#include "ripessettings.h"
#include "rv32i_assembler.h"
#include "rvassembler_common.h"
#include "rvrelocations.h"

#include <QByteArray>
#include <algorithm>

#include "rv_c_ext.h"
#include "rv_i_ext.h"
#include "rv_m_ext.h"
#include "assembler/rv_c_ext.h"
#include "assembler/rv_i_ext.h"
#include "assembler/rv_m_ext.h"

namespace Ripes {
namespace Assembler {
Expand Down
2 changes: 1 addition & 1 deletion src/assembler/symbolmap.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "symbolmap.h"
#include "assembler/symbolmap.h"

namespace Ripes {
namespace Assembler {
Expand Down
2 changes: 1 addition & 1 deletion src/cachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create_ripes_lib(cachesim LINK_TO_RIPES_LIB)
add_ripes_sources(cachesim)
Loading

0 comments on commit fe5264c

Please sign in to comment.