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
167 changes: 167 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
Language: Cpp
Standard: Latest
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: Right
AlignOperands: AlignAfterOperator
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeConceptDeclarations: Always
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: false
DerivePointerAlignment: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros: []
IncludeBlocks: Regroup
IncludeCategories:
# Internal project headers
- Regex: '^"'
Priority: 1
# Third-party libraries
- Regex: '^<.*\.(h|hpp)>'
Priority: 2
# Qt
- Regex: '^<Q'
Priority: 3
# C++ standard library
- Regex: '^<'
Priority: 10
IncludeIsMainRegex: ([-_]test|Test)?$
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: NoIndent
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: true
InsertNewlineAtEOF: true
InsertTrailingCommas: Wrapped
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PackConstructorInitializers: Never
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 19
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
# PenaltyIndentedWhitespace: IDK. If you know the appropriate value, create PR.
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
QualifierAlignment: Custom
QualifierOrder: ['friend', 'inline', 'static', 'constexpr', 'const', 'volatile', 'type']
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 0
SortIncludes: CaseSensitive
SortJavaStaticImport: After
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterOverloadedOperator: false
AfterRequiresInClause: true
AfterRequiresInExpression: true
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: 1
SpacesInParentheses: false
SpacesInSquareBrackets: false
StatementAttributeLikeMacros: ['emit']
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
WrapNamespaceBodyWithEmptyLines: Always
17 changes: 8 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ jobs:
- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.14.0
with:
clang-format-version: '19'
clang-format-version: '20'
check-path: '.'

build:
test:
needs: formatting-check
name: Build
name: Test
runs-on: ubuntu-22.04
container:
image: ghcr.io/egorshamshura/protea-build:latest
strategy:
fail-fast: false
matrix:
Expand All @@ -44,11 +46,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4.8'
bundler-cache: true

- name: Build
run: ci-extra/build.sh "$CMAKE_PRESET"

- name: Run tests
run: ci-extra/test.sh "$CMAKE_PRESET"
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

project(protea)

set(TARGET_NAME RISCV)

option(PROTEA_BUILD_TESTS
"Enable tests build (requires riscv gnu toolchain)" OFF)
enable_testing()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set_property(CACHE CMAKE_INSTALL_PREFIX
PROPERTY VALUE "${CMAKE_BINARY_DIR}/install")
endif()

find_package(Ruby 3.4.8 EXACT REQUIRED)
find_package(Python3 3.12 EXACT REQUIRED COMPONENTS Interpreter)
message("Python found: ${Python3_EXECUTABLE}")

include(ExternalProject)
include(cmake/Bundler.cmake)
include(cmake/QEMU.cmake)
include(cmake/CompilerOptions.cmake)
include(cmake/CPM.cmake)
include(cmake/dependencies.cmake)

add_subdirectory(lib)
add_subdirectory(sim_lib)
add_subdirectory(sim_gen)
add_subdirectory(test)
4 changes: 2 additions & 2 deletions ci-extra/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PRESET_NAME=$1

# Configure CMake
cmake -S . \
--preset "${PRESET_NAME}" -G Ninja
--preset "${PRESET_NAME}" -DPROTEA_BUILD_TESTS=true -DQEMU_PATH=qemu-riscv32 -G Ninja

# Build
cmake --build --preset ${PRESET_NAME} --target install --parallel 12
cmake --build --preset ${PRESET_NAME} --target all --parallel 12
4 changes: 4 additions & 0 deletions ci-extra/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PRESET_NAME=$1

# Run tests
cmake --build --preset ${PRESET_NAME} --target c-simtests
3 changes: 3 additions & 0 deletions cmake/QEMU.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (NOT DEFINED QEMU_PATH)
set(QEMU_PATH "qemu")
endif()
65 changes: 65 additions & 0 deletions cmake/toolchain/riscv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# RISC-V Cross Compilation Toolchain File Usage: cmake
# -DCMAKE_TOOLCHAIN_FILE=path/to/this/file.cmake ..

# Base settings
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR riscv)
set(CMAKE_LINKER_TYPE DEFAULT)

# Toolchain prefix (modify this according to your toolchain) Common prefixes:
# riscv64-unknown-elf-, riscv64-unknown-linux-gnu-, riscv32-unknown-elf-
set(RISCV_TOOLCHAIN_PREFIX
"riscv32-unknown-elf-"
CACHE STRING "RISC-V toolchain prefix")

# Target architecture (modify these according to your needs)
set(RISCV_ARCH
"rv32i"
CACHE STRING "RISC-V architecture")
set(RISCV_ABI
"ilp32"
CACHE STRING "RISC-V ABI")

# Cross-compilation tools
if(DEFINED RISCV_TOOLCHAIN_DIR)
set(CMAKE_C_COMPILER "${RISCV_TOOLCHAIN_DIR}/${RISCV_TOOLCHAIN_PREFIX}gcc")
set(CMAKE_CXX_COMPILER "${RISCV_TOOLCHAIN_DIR}/${RISCV_TOOLCHAIN_PREFIX}g++")
set(CMAKE_ASM_COMPILER "${RISCV_TOOLCHAIN_DIR}/${RISCV_TOOLCHAIN_PREFIX}gcc")
set(CMAKE_AR "${RISCV_TOOLCHAIN_DIR}/${RISCV_TOOLCHAIN_PREFIX}ar")
set(CMAKE_RANLIB "${RISCV_TOOLCHAIN_DIR}/${RISCV_TOOLCHAIN_PREFIX}ranlib")
else()
set(CMAKE_C_COMPILER "${RISCV_TOOLCHAIN_PREFIX}gcc")
set(CMAKE_CXX_COMPILER "${RISCV_TOOLCHAIN_PREFIX}g++")
set(CMAKE_ASM_COMPILER "${RISCV_TOOLCHAIN_PREFIX}gcc")
set(CMAKE_AR "${RISCV_TOOLCHAIN_PREFIX}ar")
set(CMAKE_RANLIB "${RISCV_TOOLCHAIN_PREFIX}ranlib")
endif()

# Compiler flags Search settings
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# Optional: Specify sysroot if needed set(CMAKE_SYSROOT
# "/path/to/riscv/sysroot")

# Optional: Additional flags for specific use cases
set(COMMON_FLAGS
"-march=${RISCV_ARCH} -mabi=${RISCV_ABI} -Wall -Wextra -nostdlib -nodefaultlibs -nostartfiles -static -fno-builtin"
)
set(CMAKE_C_FLAGS
"${COMMON_FLAGS}"
CACHE STRING "C compiler flags")
set(CMAKE_ASM_FLAGS
"${COMMON_FLAGS}"
CACHE STRING "ASM compiler flags")

set(CMAKE_EXE_LINKER_FLAGS_INIT
"-nostdlib -nodefaultlibs -nostartfiles -fno-builtin -static"
CACHE STRING "Linker flags")

# Test compiler
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.6)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
endif()
2 changes: 1 addition & 1 deletion code_gen/cpp_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def generate_statement(operation)
@emitter.emit_line("#{dst} = #{src};")
when :new_var
var_name = operation[:oprnds][0][:name]
var_type = Utility::HelperCpp.gen_type(operation[:oprnds][0][:type])
var_type = Utility::HelperCpp.gen_small_type(operation[:oprnds][0][:type])
@emitter.emit_line("#{var_type} #{var_name};")
when :cast
dst = @mapping[operation[:oprnds][0][:name]] || operation[:oprnds][0][:name]
Expand Down
2 changes: 2 additions & 0 deletions lib/ADL/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def self.serialize(msg= nil)
yaml_data = YAML.dump(
{
regfiles: @@regfiles.map(&:to_h),
interface_functions: @@interface_functions.map(&:to_h),
instructions: @@instructions.map(&:to_h),
}
)
Expand All @@ -19,6 +20,7 @@ def self.state
yaml_data = YAML.dump(
{
regfiles: @@regfiles.map(&:to_h),
interface_functions: @@interface_functions.map(&:to_h),
instructions: @@instructions.map(&:to_h),
}
)
Expand Down
2 changes: 1 addition & 1 deletion lib/ADL/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def Instruction(name, &block)
class InterfaceBuilder
include SimInfra

def function(name, output_types = [], input_types = [])
def Function(name, output_types = [], input_types = [])
@@interface_functions << {:name => name, :return_types => output_types, :argument_types => input_types}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/RISC-V/32I.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module RV32I
extend SimInfra

Interface {
function :sysCall
Function(:sysCall)
}

RegisterFile(:XRegs) {
Expand Down
Loading
Loading