Skip to content
Merged
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
38 changes: 12 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
Information and guidelines for people contributing code back to TCE.
Information and guidelines for people contributing code back to OpenASIP.

TCE coding style
Coding Style
================

There used to be a huge coding style manual all TCE developers slavishly and humbly followed :P Nowadays, as there is plenty of code, the easiest way is to just match the style of the existing code.
The coding style is roughly defined by `openasip/.clang-format`. The all-important indentation style is 4 spaces, no tabs.

If in doubt, look around. Good references are the oldest pieces of code (from the times when we had stricter code review process) inside src/base. Take a look at some of the files there to get the feeling.

The basic guidelines:

* the indentations should be 4 spaces (no tabs)
* maximum of 78 characters per line

In case of emacs, you should use the stroustrup style.

Example .emacs:
Note that large parts of the codebase were written before semi-formal style checking, so you may want to run the formatter on only your changes and leave the rest of the file alone to minimize unnecessary noise in your commits. For example, you could run the below from within `openasip/` before committing:

```shell
./tools/scripts/format-diff.sh
```
(defun my-c-mode-common-hook ()
(c-set-style "stroustrup")
;; other customizations can go here
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(setq default-tab-width 4)
(setq-default indent-tabs-mode nil)
Alternatively, to format a whole branch at a time:

(add-to-list 'auto-mode-alist '("\\.icc$" . c++-mode))
```shell
./tools/scripts/format-branch.sh
```

This setups the "stroustrup" style for C/C++ code and makes emacs detect the .icc files (inline C++ definitions in TCE) as C++ files.

TCE Test Suite
Test Suite
==============

The TCE test suite includes both fine grained unit tests and "systemtests"
that test the command line interfaces of the tools using test scripts. In case you want to contribute code for TCE, you should ensure your modifications pass the test suite before submitting the patch/committing. In addition, if you add a new feature, you should include a system test (actually an integration test), some unit tests, or preferably both, with your merge request.
The test suite includes both fine grained unit tests and "systemtests"
that test the command line interfaces of the tools using test scripts. In case you want to contribute code for OpenASIP, you should ensure your modifications pass the test suite before submitting the patch/committing. In addition, if you add a new feature, you should include a system test (actually an integration test), some unit tests, or preferably both, with your merge request.

The system tests are under 'testsuite' directory. '''Note:''' The test system currently works only with a source tree build.

Expand Down
72 changes: 72 additions & 0 deletions openasip/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: false
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowAllArgumentsOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
ColumnLimit: 78
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 0
PointerAlignment: Left
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
FixNamespaceComments: true
InsertNewlineAtEOF: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: true
AtStartOfFile: false
MacroBlockBegin: "^(INIT_STATE|OPERATION_WITH_STATE|OPERATION|TRIGGER)"
MacroBlockEnd: "(END_INIT_STATE|END_OPERATION_WITH_STATE|END_OPERATION|END_TRIGGER)"
AlignEscapedNewlines: Right
...

35 changes: 3 additions & 32 deletions openasip/tools/scripts/format-branch.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
#!/bin/bash

if [ ! -d .git ]; then
if [ -d src ]; then
cd ..
if [ ! -d .git ]; then
echo "must be run in TCE repository root or the source root"
exit 1
fi
else
echo "must be run in TCE repository root or the source root"
exit 1
fi
fi

REF_BRANCH=${1:-origin/main}
SCRIPTDIR=openasip/tools/scripts

echo "Diffing against ${REF_BRANCH}..."

PATCHY=/tmp/p.patch

rm -f $PATCHY
git diff main -U0 --no-color >$PATCHY

$SCRIPTDIR/clang-format-diff.py \
-regex '(.*(\.hh$|\.cc$|\.c$|\.h$))' \
-i -p1 -style \
"{BasedOnStyle: Google, IndentWidth: 4, \
AlwaysBreakAfterReturnType: AllDefinitions, AccessModifierOffset: -4, \
AlignAfterOpenBracket: AlwaysBreak, ColumnLimit: 78}" \
-v <$PATCHY
#!/usr/bin/env bash
RELPATH=$(dirname "$(realpath "$0")")
$RELPATH/format-diff.sh main "$@"
49 changes: 49 additions & 0 deletions openasip/tools/scripts/format-diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# USAGE:
#
# 1) format-diff.sh
# 2) format-diff.sh <commit>
#
# 1) formats current unstaged changes and 2) formats changes since the
# commit or changes between commit range (XREF..YREF).

GITROOT=$(git rev-parse --show-toplevel 2>/dev/null)
if [ $? -ne 0 ]; then
>&2 echo "must be run in git repo"
exit 1
fi

SCRIPTPATH=$( realpath "$0" )
RELPATH=$(dirname "$SCRIPTPATH")

# cd to root directory of the git repo
cd "${GITROOT}" || exit 1

if [ $# -ne 0 ]; then
if git status --porcelain=1 -uno | grep '^.[MTDRC] '; then
>&2 echo "There are unstaged changes - aborting."
exit 1
fi
fi

PATCHY=$(mktemp /tmp/pocl.XXXXXXXX.patch)
trap 'rm -f $PATCHY' EXIT

git diff "$@" -U0 --no-color >"$PATCHY"

if [ -z "${CLANG_FORMAT_BIN}" ]; then
CLANG_FORMAT_BIN=clang-format
# clang-format v15 is the lowest version that supports the custom
# style files ahead.
for i in {25..15}; do
cand_bin=$(command -v "clang-format-$i") || continue
CLANG_FORMAT_BIN=$cand_bin
break;
done
fi

echo "Using: $CLANG_FORMAT_BIN"

"$RELPATH"/clang-format-diff.py -v -binary "$CLANG_FORMAT_BIN" \
-regex 'openasip/.*(\.hpp$|\.hh$|\.cc$|\.cpp$)' \
-i -p1 -style=file:"openasip/.clang-format" <"$PATCHY"
Loading