Skip to content

Commit 125bcb4

Browse files
Xeratecphsauter
authored andcommitted
Autoformat Python and C code
1 parent c8a3b42 commit 125bcb4

File tree

19 files changed

+617
-109
lines changed

19 files changed

+617
-109
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 <[email protected]>
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/[email protected]
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

Makefile

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

36-
$(IHP_RCX_FILE):
36+
$(IHP_RCX_FILE):
3737
curl -L -o $@ $(IHP_RCX_URL)
3838

3939
## Reset dependencies (without updating Bender.lock)
@@ -155,13 +155,26 @@ help: Makefile
155155

156156
.PHONY: help
157157

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

159172
###########
160173
# Cleanup #
161174
###########
162175

163176
## Delete generated files and directories
164-
clean:
177+
clean:
165178
rm -f $(SV_FLIST)
166179
rm -f klayout/croc_chip.gds
167180
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 <[email protected]>
6+
7+
[tool.black]
8+
line-length = 120
9+
target-version = ['py38']
10+
include = '\\.pyi?$'
11+
exclude = ''

0 commit comments

Comments
 (0)