Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crossbar #2

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: "monthly"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/out/
/.idea/
/.bsp/
.*.sw[a-p]
/.config/
/.vscode/
/.cache/
/build/
/config.json
26 changes: 26 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version = 2.6.4

maxColumn = 120
align = most
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = ScalaDoc
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses = true

align.tokens.add = [
{
code = ":"
}
]

newlines.alwaysBeforeCurlyBraceLambdaParams = false
newlines.alwaysBeforeMultilineDef = false
newlines.implicitParamListModifierForce = [before]

verticalMultiline.atDefnSite = true

optIn.annotationNewlines = true

rewrite.rules = [SortImports, PreferCurlyFors, AvoidInfix]
11 changes: 9 additions & 2 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ object tests extends Module {
override def ivyDeps = T(Seq(
v.mainargs
))
override def mainClass = Some("tests.elaborate.Main")

// TODO: use Cross to support multiple config files for testing.
def config: T[PathRef] = T { PathRef(os.pwd / "config.json") }

// TODO: add config as input to elaborate
def elaborate = T {
Expand All @@ -91,6 +95,7 @@ object tests extends Module {
runClasspath().map(_.path),
Seq(
"--dir", T.dest.toString,
"--json", config().path.toString
),
)
PathRef(T.dest)
Expand All @@ -112,10 +117,9 @@ object tests extends Module {
"-disable-infer-rw",
"-dedup",
"-O=debug",
"--split-verilog",
"--preserve-values=named",
"--output-annotation-file=mfc.anno.json",
s"-o=${T.dest}"
s"-o=${T.dest}/concat.sv"
).call(T.dest)
PathRef(T.dest)
}
Expand All @@ -131,11 +135,13 @@ object tests extends Module {
).filter(p => p.ext == "v" || p.ext == "sv").map(PathRef(_)).toSeq
}


def annotations = T {
os.walk(compile().path).filter(p => p.last.endsWith("mfc.anno.json")).map(PathRef(_))
}
}

/*
object emulator extends Module {

def csrcDir = T.source {
Expand Down Expand Up @@ -234,4 +240,5 @@ object tests extends Module {
PathRef(buildDir().path / "emulator")
}
}
*/
}
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; };

outputs = { self, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
sparta = pkgs.clangStdenv.mkDerivation rec {
pname = "sparta";
version = "v1.1.0";
src = builtins.fetchGit {
url = "https://github.com/sparcians/map.git";
ref = "refs/tags/map_v1.1.0";
rev = "f64923557b79629a1162a83d55f10fe94b0aad59";
# sha256 = "sha256-OiN6+Bfaz0B6uPXi9pRGOUWKfUWDMhuT8lrjjhK1BH8=";
};
patches = [ ./patches/sparta.diff ];
sourceRoot = "source/sparta";
GIT_TAG = version;

buildInputs = [
pkgs.cmake
pkgs.git
pkgs.ninja
pkgs.boost
pkgs.yaml-cpp
pkgs.sqlite
pkgs.hdf5
pkgs.rapidjson
];

cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
];
};
in {
devShell.x86_64-linux = pkgs.mkShell { buildInputs = [
pkgs.verilator
pkgs.cmake
pkgs.clang
pkgs.mill
pkgs.circt
sparta
pkgs.boost
pkgs.yaml-cpp
pkgs.sqlite
pkgs.hdf5
pkgs.rapidjson
]; };
};
}
3 changes: 3 additions & 0 deletions models/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build
/.cache
/.vscode
48 changes: 48 additions & 0 deletions models/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.25)
project(tlmodel)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(./cmake/sparta-config.cmake)

macro(sparta_application build_target)
endmacro(sparta_application)

find_package(nlohmann_json 3.2.0 REQUIRED)
find_package(verilator
HINTS $ENV{VERILATOR_ROOT}
)

add_executable(tlmodel
${CMAKE_SOURCE_DIR}/src/Crossbar.cpp
${CMAKE_SOURCE_DIR}/src/GlobalLogger.cpp
${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/Master.cpp
${CMAKE_SOURCE_DIR}/src/Simulator.cpp
${CMAKE_SOURCE_DIR}/src/Slave.cpp
)
set_property(TARGET tlmodel PROPERTY CXX_STANDARD 23)
target_include_directories(tlmodel PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(tlmodel SYSTEM PUBLIC /usr/local/include)
target_link_libraries(tlmodel PRIVATE ${Sparta_LIBS})
target_link_libraries(tlmodel PRIVATE nlohmann_json::nlohmann_json)

add_executable(rtlsim
${CMAKE_SOURCE_DIR}/src/rtl.cpp
)
set_property(TARGET rtlsim PROPERTY CXX_STANDARD 23)
target_include_directories(rtlsim PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(rtlsim SYSTEM PUBLIC /usr/local/include)
target_link_libraries(rtlsim PRIVATE nlohmann_json::nlohmann_json)

set(RTL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../out/tests/mfccompile/compile.dest/concat.sv)

verilate(
rtlsim
SOURCES ${RTL_SRC}
PREFIX rtl
TRACE_FST
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/verilated
VERILATOR_ARGS --trace-params --trace-structs --top-module TLCrossBar
)
target_include_directories(rtlsim PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/verilated)
150 changes: 150 additions & 0 deletions models/cmake/modules/FindCppcheck.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Locate cppcheck and add a cppcheck-analysis target
#
# This module defines
# CPPCHECK_BIN, where to find cppcheck
#
# To help find the binary you can set CPPCHECK_ROOT_DIR to search a custom path
# Exported argumets include
# CPPCHECK_FOUND, if false, do not try to link to cppcheck --- if (CPPCHECK_FOUND)
#
# CPPCHECK_THREADS_ARG - Number of threads to use (default -j2)
# CPPCHECK_PROJECT_ARG - The project to use (compile_comands.json)
# CPPCHECK_BUILD_DIR_ARG - The build output directory (default - ${PROJECT_BINARY_DIR}/analysis/cppcheck)
# CPPCHECK_ERROR_EXITCODE_ARG - The exit code if an error is found (default --error-exitcode=1)
# CPPCHECK_SUPPRESSIONS - A suppressiosn file to use (defaults to .cppcheck_suppressions)
# CPPCHECK_EXITCODE_SUPPRESSIONS - An exitcode suppressions file to use (defaults to .cppcheck_exitcode_suppressions)
# CPPCHECK_CHECKS_ARGS - The checks to run (defaults to --enable=warning)
# CPPCHECK_OTHER_ARGS - Any other arguments (defaults to --inline-suppr)
# CPPCHECK_COMMAND - The full command to run the default cppcheck configuration
# CPPCHECK_EXCLUDES - A list of files or folders to exclude from the scan. Must be the full path
#
# if CPPCHECK_XML_OUTPUT is set to an output file name before calling this. CppCheck will create an xml file with that name
# find the cppcheck binary

# if custom path check there first
if (CPPCHECK_ROOT_DIR)
find_program (CPPCHECK_BIN
NAMES
cppcheck
PATHS
"${CPPCHECK_ROOT_DIR}"
NO_DEFAULT_PATH)
find_program (CPPCHECK_HTMLREPORT_BIN
NAMES
cppcheck-htmlreport
PATHS
"${CPPCHECK_ROOT_DIR}"
NO_DEFAULT_PATH)
endif ()

find_program (CPPCHECK_BIN NAMES cppcheck)
find_program (CPPCHECK_HTMLREPORT_BIN NAMES cppcheck-htmlreport)

if (CPPCHECK_BIN)
message ("-- Adding support for cppcheck")
execute_process (COMMAND ${CPPCHECK_BIN} --version
OUTPUT_VARIABLE CPPCHECK_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)

set (CPPCHECK_THREADS_ARG "-j1" CACHE STRING "The number of threads to use")
set (CPPCHECK_PROJECT_ARG "--project=${PROJECT_BINARY_DIR}/compile_commands.json")
set (CPPCHECK_BUILD_DIR_ARG "--cppcheck-build-dir=${PROJECT_BINARY_DIR}/analysis/cppcheck" CACHE STRING "The build directory to use")
# Don't show thise errors
if (EXISTS "${CMAKE_SOURCE_DIR}/.cppcheck_suppressions")
set (CPPCHECK_SUPPRESSIONS "--suppressions-list=${CMAKE_SOURCE_DIR}/.cppcheck_suppressions" CACHE STRING "The suppressions file to use")
else ()
set (CPPCHECK_SUPPRESSIONS "" CACHE STRING "The suppressions file to use")
endif ()

# Show these errors but don't fail the build
# These are mainly going to be from the "warning" category that is enabled by default later
if (EXISTS "${CMAKE_SOURCE_DIR}/.cppcheck_exitcode_suppressions")
set (CPPCHECK_EXITCODE_SUPPRESSIONS "--exitcode-suppressions=${CMAKE_SOURCE_DIR}/.cppcheck_exitcode_suppressions" CACHE STRING "The exitcode suppressions file to use")
else ()
set (CPPCHECK_EXITCODE_SUPPRESSIONS "" CACHE STRING "The exitcode suppressions file to use")
endif ()

set (CPPCHECK_ERROR_EXITCODE_ARG "--error-exitcode=0" CACHE STRING "The exitcode to use if an error is found")
set (CPPCHECK_CHECKS_ARGS "--enable=all" CACHE STRING "Arguments for the checks to run")
set (CPPCHECK_OTHER_ARGS "--inline-suppr" CACHE STRING "Other arguments")
set (_CPPCHECK_EXCLUDES)

## set exclude files and folders
foreach (ex ${CPPCHECK_EXCLUDES})
list (APPEND _CPPCHECK_EXCLUDES "-i${ex}")
endforeach (ex)

set (CPPCHECK_ALL_ARGS
${CPPCHECK_THREADS_ARG}
${CPPCHECK_PROJECT_ARG}
${CPPCHECK_BUILD_DIR_ARG}
${CPPCHECK_ERROR_EXITCODE_ARG}
${CPPCHECK_SUPPRESSIONS}
${CPPCHECK_EXITCODE_SUPPRESSIONS}
${CPPCHECK_CHECKS_ARGS}
${CPPCHECK_OTHER_ARGS}
${_CPPCHECK_EXCLUDES}
)

# run cppcheck command with optional xml output for CI system
if (NOT CPPCHECK_XML_OUTPUT)
set (CPPCHECK_COMMAND
${CPPCHECK_BIN}
${CPPCHECK_ALL_ARGS}
)
else ()
set (CPPCHECK_COMMAND
${CPPCHECK_BIN}
${CPPCHECK_ALL_ARGS}
--xml
--xml-version=2
2> ${CPPCHECK_XML_OUTPUT}
)
set (CPPCHECK_HTMLREPORT_COMMAND
${CPPCHECK_HTMLREPORT_BIN}
--source-dir ${CMAKE_SOURCE_DIR}
--title "CppCheck"
--file ${CPPCHECK_XML_OUTPUT}
--report-dir ${CPPCHECK_XML_OUTPUT}_html
)
endif ()

else ()
add_custom_target (cppcheck-analysis COMMAND echo cppcheck is not installed. Install and re-run cmake)
endif ()

# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE
include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS (
CPPCHECK
DEFAULT_MSG
CPPCHECK_BIN)

mark_as_advanced (
CPPCHECK_BIN
CPPCHECK_THREADS_ARG
CPPCHECK_PROJECT_ARG
CPPCHECK_BUILD_DIR_ARG
CPPCHECK_ERROR_EXITCODE_ARG
CPPCHECK_SUPPRESSIONS
CPPCHECK_EXITCODE_SUPPRESSIONS
CPPCHECK_CHECKS_ARGS
CPPCHECK_EXCLUDES
CPPCHECK_OTHER_ARGS)

# If found add a cppcheck-analysis target
if (CPPCHECK_FOUND)
message ("-- Using ${CPPCHECK_VERSION}. Use cppcheck-analysis targets to run it")
file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/analysis/cppcheck)
add_custom_target (cppcheck-analysis
COMMAND ${CPPCHECK_COMMAND})
if (CPPCHECK_XML_OUTPUT)
add_custom_command (TARGET cppcheck-analysis POST_BUILD VERBATIM
COMMAND ${CPPCHECK_HTMLREPORT_COMMAND}
COMMENT "Generating HTML REPORT")
# message ("-- HTML Report CMD: ${CPPCHECK_HTMLREPORT_COMMAND}")
endif ()
else ()
message ("-- cppcheck not found")
endif ()
Loading