Skip to content

Commit 75c8aed

Browse files
committed
Autoformat Python and C code
1 parent b44242b commit 75c8aed

File tree

18 files changed

+616
-105
lines changed

18 files changed

+616
-105
lines changed

.clang-format

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
IndentWidth: 4
2+
ColumnLimit: 120
3+
AlignEscapedNewlines: DontAlign
4+
SortIncludes: false
5+
AllowShortFunctionsOnASingleLine: None
6+
AllowShortIfStatementsOnASingleLine: true
7+
AllowShortLoopsOnASingleLine: true

.github/workflows/format.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2022 ETH Zurich and University of Bologna.
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Author: Jannis Schönleber <janniss@iis.ee.ethz.ch>
6+
7+
name: lint-format
8+
9+
on:
10+
workflow_dispatch:
11+
push:
12+
branches:
13+
- '**'
14+
15+
jobs:
16+
lint-python:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check Python with black
20+
uses: rickstaa/action-black@v1
21+
with:
22+
black_args: ". --check"
23+
24+
lint-cxx:
25+
runs-on: ubuntu-latest
26+
steps:
27+
-
28+
name: Checkout
29+
uses: actions/checkout@v4
30+
-
31+
name: Run Clang-format
32+
uses: DoozyX/clang-format-lint-action@v0.18.2
33+
with:
34+
extensions: 'c,h,cpp'
35+
clangFormatVersion: 17

.github/workflows/license.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ jobs:
2222
SPDX-License-Identifier: (SHL-0.51|Apache-2.0)
2323
exclude_paths: |
2424
deps
25-
include/version.h
25+
include/version.h
26+
ihp13
27+
klayout/def2gds.sh
28+
klayout/def2stream.py

Bender.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 ETH Zurich and University of Bologna
1+
# Copyright (c) 2024 ETH Zurich and University of Bologna
22
# Solderpad Hardware License, Version 0.51, see LICENSE for details.
33
# SPDX-License-Identifier: SHL-0.51
44

@@ -18,7 +18,7 @@ dependencies:
1818
timer_unit: { git: "https://github.com/pulp-platform/timer_unit.git", version: 1.0.3 }
1919
obi: { git: "https://github.com/pulp-platform/obi.git", version: 0.1.3 }
2020
apb_uart: { git: "https://github.com/pulp-platform/apb_uart.git", version: 0.2.1 }
21-
cve2: { path: "rtl/cve2" } # a vendor package (no Bender.yml), see below
21+
cve2: { path: "rtl/cve2" } # a vendor package (no Bender.yml), see below
2222

2323

2424
sources:
@@ -53,7 +53,7 @@ sources:
5353
files:
5454
# Level 0
5555
- rtl/croc_chip.sv
56-
56+
5757
# netlist for simulation
5858
- target: netlist_yosys
5959
files:

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ checkout: $(IHP_RCX_FILE)
3434
$(BENDER) checkout
3535
git submodule update --init --recursive
3636

37-
$(IHP_RCX_FILE):
37+
$(IHP_RCX_FILE):
3838
curl -L -o $@ $(IHP_RCX_URL)
3939

4040
## Reset dependencies (without updating Bender.lock)
@@ -151,13 +151,26 @@ help: Makefile
151151

152152
.PHONY: help
153153

154+
###########
155+
# Format #
156+
###########
157+
CLANG_FORMAT_EXECUTABLE ?= clang-format
158+
159+
## Automatically format the code using clang-format and black
160+
format:
161+
@echo -e "\033[1m-> Formatting Python Code...\033[0m"
162+
@black */*.py
163+
@echo -e "\033[1m-> Formatting C Code...\033[0m"
164+
@python scripts/run_clang_format.py -ir sw/ --clang-format-executable=$(CLANG_FORMAT_EXECUTABLE)
165+
166+
.PHONY: format
154167

155168
###########
156169
# Cleanup #
157170
###########
158171

159172
## Delete generated files and directories
160-
clean:
173+
clean:
161174
rm -f $(SV_FLIST)
162175
rm -f klayout/croc_chip.gds
163176
rm -rf verilator/obj_dir/

klayout/def2stream.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
tech.load(tech_file)
1313
layoutOptions = tech.load_layout_options
1414
if len(layer_map) > 0:
15-
layoutOptions.lefdef_config.map_file = layer_map
15+
layoutOptions.lefdef_config.map_file = layer_map
1616

1717
# Load def file
1818
main_layout = pya.Layout()
@@ -21,7 +21,7 @@
2121

2222
print("[INFO] Reporting cells after loading DEF ...")
2323
for i in main_layout.each_cell():
24-
print("[INFO] '{0}'".format(i.name))
24+
print("[INFO] '{0}'".format(i.name))
2525

2626
# Clear cells
2727
top_cell_index = main_layout.cell(design_name).cell_index()
@@ -30,17 +30,17 @@
3030
# - KLayout is prepending VIA_ when reading DEF that instantiates LEF's via
3131
print("[INFO] Clearing cells...")
3232
for i in main_layout.each_cell():
33-
if i.cell_index() != top_cell_index:
34-
if not i.name.startswith("VIA_"):
35-
i.clear()
33+
if i.cell_index() != top_cell_index:
34+
if not i.name.startswith("VIA_"):
35+
i.clear()
3636

3737
# Load in the gds to merge
3838
print("[INFO] Merging GDS/OAS files...")
39-
with open(gds_flist, 'rb') as file:
39+
with open(gds_flist, "rb") as file:
4040
in_files_list = file.read()
4141
for fil in in_files_list.split():
42-
print("\t{0}".format(fil))
43-
main_layout.read(fil)
42+
print("\t{0}".format(fil))
43+
main_layout.read(fil)
4444

4545
# Copy the top level only to a new layout
4646
print("[INFO] Copying toplevel cell '{0}'".format(design_name))
@@ -52,32 +52,38 @@
5252
print("[INFO] Checking for missing cell from GDS/OAS...")
5353
missing_cell = False
5454
regex = None
55-
if 'GDS_ALLOW_EMPTY' in os.environ:
55+
if "GDS_ALLOW_EMPTY" in os.environ:
5656
print("[INFO] Found GDS_ALLOW_EMPTY variable.")
57-
regex = os.getenv('GDS_ALLOW_EMPTY')
57+
regex = os.getenv("GDS_ALLOW_EMPTY")
5858
for i in top_only_layout.each_cell():
59-
if i.is_empty():
60-
missing_cell = True
61-
if regex is not None and re.match(regex, i.name):
62-
print("[WARNING] LEF Cell '{0}' ignored. Matches GDS_ALLOW_EMPTY.".format(i.name))
63-
else:
64-
print("[ERROR] LEF Cell '{0}' has no matching GDS/OAS cell."
65-
" Cell will be empty.".format(i.name))
66-
errors += 1
59+
if i.is_empty():
60+
missing_cell = True
61+
if regex is not None and re.match(regex, i.name):
62+
print(
63+
"[WARNING] LEF Cell '{0}' ignored. Matches GDS_ALLOW_EMPTY.".format(
64+
i.name
65+
)
66+
)
67+
else:
68+
print(
69+
"[ERROR] LEF Cell '{0}' has no matching GDS/OAS cell."
70+
" Cell will be empty.".format(i.name)
71+
)
72+
errors += 1
6773

6874
if not missing_cell:
69-
print("[INFO] All LEF cells have matching GDS/OAS cells")
75+
print("[INFO] All LEF cells have matching GDS/OAS cells")
7076

7177
print("[INFO] Checking for orphan cell in the final layout...")
7278
orphan_cell = False
7379
for i in top_only_layout.each_cell():
74-
if i.name != design_name and i.parent_cells() == 0:
75-
orphan_cell = True
76-
print("[ERROR] Found orphan cell '{0}'".format(i.name))
77-
errors += 1
80+
if i.name != design_name and i.parent_cells() == 0:
81+
orphan_cell = True
82+
print("[ERROR] Found orphan cell '{0}'".format(i.name))
83+
errors += 1
7884

7985
if not orphan_cell:
80-
print("[INFO] No orphan cells")
86+
print("[INFO] No orphan cells")
8187

8288

8389
# Write out the GDS

project.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2025 ETH Zurich and University of Bologna.
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Philip Wiese <wiesep@iis.ee.ethz.ch>
6+
7+
[tool.black]
8+
line-length = 120
9+
target-version = ['py38']
10+
include = '\\.pyi?$'
11+
exclude = ''

rtl/soc_ctrl/soc_ctrl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Copyright 2024 ETH Zurich and University of Bologna
55

66
// Licensing information found in source file:
7-
//
7+
//
88
// SPDX-License-Identifier: SHL-0.51
99

1010
#ifndef _SOC_CTRL_REG_DEFS_
@@ -31,10 +31,10 @@ extern "C" {
3131
#define SOC_CTRL_BOOTMODE_BOOTMODE_MASK 0x3
3232
#define SOC_CTRL_BOOTMODE_BOOTMODE_OFFSET 0
3333
#define SOC_CTRL_BOOTMODE_BOOTMODE_FIELD \
34-
((bitfield_field32_t) { .mask = SOC_CTRL_BOOTMODE_BOOTMODE_MASK, .index = SOC_CTRL_BOOTMODE_BOOTMODE_OFFSET })
34+
((bitfield_field32_t){.mask = SOC_CTRL_BOOTMODE_BOOTMODE_MASK, .index = SOC_CTRL_BOOTMODE_BOOTMODE_OFFSET})
3535

3636
#ifdef __cplusplus
37-
} // extern "C"
37+
} // extern "C"
3838
#endif
39-
#endif // _SOC_CTRL_REG_DEFS_
40-
// End generated register defines for safety_soc_ctrl
39+
#endif // _SOC_CTRL_REG_DEFS_
40+
// End generated register defines for safety_soc_ctrl

0 commit comments

Comments
 (0)