Skip to content

Commit 75f3ed4

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

31 files changed

+638
-125
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ name: lint-license
88

99
on:
1010
workflow_dispatch:
11+
push:
12+
branches:
13+
- '**'
1114

1215
jobs:
1316
lint-license:
@@ -22,4 +25,7 @@ jobs:
2225
SPDX-License-Identifier: (SHL-0.51|Apache-2.0)
2326
exclude_paths: |
2427
deps
25-
include/version.h
28+
include/version.h
29+
ihp13
30+
klayout/def2gds.sh
31+
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: 14 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,25 @@ help: Makefile
151151

152152
.PHONY: help
153153

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

155167
###########
156168
# Cleanup #
157169
###########
158170

159171
## Delete generated files and directories
160-
clean:
172+
clean:
161173
rm -f $(SV_FLIST)
162174
rm -f klayout/croc_chip.gds
163175
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

openroad/openroad.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 ETH Zurich and University of Bologna.
1+
# Copyright (c) 2023 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
#

openroad/scripts/checkpoint.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 ETH Zurich and University of Bologna.
1+
# Copyright (c) 2023 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

@@ -48,7 +48,7 @@ proc load_checkpoint_def { checkpoint_name } {
4848
global save_dir
4949
utl::report "Loading checkpoint $checkpoint_name"
5050
set checkpoint ${save_dir}/${checkpoint_name}
51-
51+
5252
exec unzip ${checkpoint}.zip -d ${save_dir}
5353
read_verilog ${checkpoint}/$checkpoint_name.v
5454
read_def ${checkpoint}/$checkpoint_name.def

openroad/scripts/chip.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 ETH Zurich and University of Bologna.
1+
# Copyright (c) 2023 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

openroad/scripts/floorplan.tcl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 ETH Zurich and University of Bologna.
1+
# Copyright (c) 2023 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

@@ -27,7 +27,7 @@ foreach inst $insts {
2727
}
2828

2929
##########################################################################
30-
# Pads/IOs
30+
# Pads/IOs
3131
##########################################################################
3232
utl::report "Create Padring"
3333
source src/padring.tcl
@@ -53,9 +53,9 @@ set core_topY [lindex $coreArea 3]
5353

5454

5555
##########################################################################
56-
# Tracks
56+
# Tracks
5757
##########################################################################
58-
# We need to define the metal tracks
58+
# We need to define the metal tracks
5959
# (where the wires on each metal should go)
6060
# this function is defined in init_tech.tcl
6161
makeTracks
@@ -71,7 +71,7 @@ utl::report "Macro Names"
7171
source src/instances.tcl
7272

7373
##########################################################################
74-
# Placing
74+
# Placing
7575
##########################################################################
7676
# use these for macro placement
7777
set floorPaddingX 20.0

0 commit comments

Comments
 (0)