summaryrefslogtreecommitdiff
path: root/CodingStyle
blob: e076cbd891fef080140ed9f5ba035433882c43b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Section 0: Notes on the existing codebase
-----------------------------------------

Not all parts of Yosys adhere to this coding styles for historical
reasons. When adding code to existing parts of the system, adhere
to this guide for the new code instead of trying to mimic to style
of the surrounding code.



Section 1: Formatting of code
-----------------------------

- Yosys code is using tabs for indentation. Tabs are 8 characters.

- A continuation of a statement in the following line is indented by
  two additional tabs.

- Lines are as long as you want them to be. A good rule of thumb is
  to break lines at about column 150.

- Opening braces can be put on the same or next line as the statement
  opening the block (if, switch, for, while, do). Put the opening brace
  on its own line for larger blocks.

- Otherwise stick to the Linux Kernel Coding Stlye:
    https://www.kernel.org/doc/Documentation/CodingStyle


Section 2: C++ Langugage
------------------------

Yosys is written in C++11. At the moment only constructs supported by
gcc 4.6 is allowed in Yosys code. This will change in future releases.

In general Yosys uses "int" instead of "size_t". To avoid compiler
warnings for implicit type casts, always use "SIZE(foobar)" instead
of "foobar.size()". (the macro SIZE() is defined by kernel/yosys.h)

Use range-based for loops whenever applicable.