Skip to content

Commit bf7e57f

Browse files
Merge pull request #200 from zjcurtis/master
pre-commit with ruff initial set up
2 parents d9a6d92 + a465697 commit bf7e57f

23 files changed

+2732
-1584
lines changed

CONTRIBUTING.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ But nothing was ever good enough for anyone (including myself) it seems. And now
4444

4545
See the [How does the compiler work?](https://github.com/JulianKemmerer/PipelineC/wiki/How-does-the-compiler-work%3F) page.
4646

47-
# Tests
47+
# Pre-Commit
4848

49-
We use hypothesis (property testing) mutmut (mutation testing) and pytest (general unit tests).
50-
Please add tests when you submit a PR.
51-
To ensure that your PR doesn't break anything, use the command `poetry run pytest`
49+
We use ruff for formatting and linting (currently most lint rules are disabled, we are enabling them incrementally as the codebase is cleaned up). To ensure this is done, we use a pre-commit hook.
5250

53-
# Formatting/Style Guide
51+
You can install Poetry (for dev dependency management) via https://python-poetry.org/docs/#installation. Once you have poetry installed, you can run 'poetry install' to get the dev dependencies installed. From there, you must run 'poetry run pre-commit install' once before making a commit. This will ensure that the pre-commit hook gets run when you make any commit. If the lint fails, follow the guidance given by Ruff (you can look up the name of the error, such as E721, online, if necessary to understand) to fix the lint error.
5452

55-
We use black for formatting. Before you submit a PR do `poetry run black src`
53+
Cheers!
5654

5755
# Future Goals
5856

pyproject.toml

+3-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ readme = "README.md"
1010
python = "^3.10"
1111

1212
[tool.poetry.group.dev.dependencies]
13-
black = ">=22.12.0"
14-
pytest = ">=7.2.1"
15-
hypothesis = ">=6.65.2"
16-
py-spy = ">=0.3.14"
17-
ruff = ">=0.0.237"
18-
refurb = ">=1.10.0"
19-
pytest-cov = "^4.0.0"
20-
cosmic-ray = "^8.3.5"
13+
ruff = "^0.5.0"
14+
pre-commit = "^3.7.1"
15+
2116

2217
[build-system]
2318
requires = ["poetry-core"]

src/C_TO_FSM.py

+596-222
Large diffs are not rendered by default.

src/C_TO_LOGIC.py

+395-366
Large diffs are not rendered by default.

src/DEVICE_MODELS.py

+72-55
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,87 @@
77
# https://github.com/JulianKemmerer/PipelineC/issues/48
88
# https://github.com/JulianKemmerer/PipelineC/issues/64
99

10-
#(C) 2022 Victor Surez Rovere <[email protected]>
11-
#NOTE: only for integer operations (not floats)
10+
# (C) 2022 Victor Surez Rovere <[email protected]>
11+
# NOTE: only for integer operations (not floats)
1212

1313
import os, re, math
1414

1515
ops = {}
1616

17+
1718
def part_supported(part_str):
18-
return part_str=="xc7a35ticsg324-1l"
19+
return part_str == "xc7a35ticsg324-1l"
20+
1921

2022
def estimate_int_timing(integer_op, widths_vector):
21-
timing_model= { #category, origin, slope
22-
"arith": (1.92, .04),
23-
"comp": (2.49, .0),
24-
"equal": (1.72, .04),
25-
"logical": (1.28, .0),
26-
"shift": (3.42, .0),
27-
}
28-
29-
categ = ""
30-
if integer_op in ["PLUS", "MINUS", "NEGATE"]: categ = "arith"
31-
if integer_op in ["GT", "GTE", "LT", "LTE"]: categ = "comp"
32-
if integer_op in ["EQ", "NEQ"]: categ = "equal"
33-
if integer_op in ["AND", "OR", "XOR", "NOT"]: categ = "logical"
34-
if integer_op in ["SL", "SR"]: categ = "shift"
35-
if categ not in timing_model:
36-
return None #unknown operation
37-
38-
bits = max(widths_vector)
39-
origin, slope = timing_model[categ]
40-
return origin + bits*slope
23+
timing_model = { # category, origin, slope
24+
"arith": (1.92, 0.04),
25+
"comp": (2.49, 0.0),
26+
"equal": (1.72, 0.04),
27+
"logical": (1.28, 0.0),
28+
"shift": (3.42, 0.0),
29+
}
30+
31+
categ = ""
32+
if integer_op in ["PLUS", "MINUS", "NEGATE"]:
33+
categ = "arith"
34+
if integer_op in ["GT", "GTE", "LT", "LTE"]:
35+
categ = "comp"
36+
if integer_op in ["EQ", "NEQ"]:
37+
categ = "equal"
38+
if integer_op in ["AND", "OR", "XOR", "NOT"]:
39+
categ = "logical"
40+
if integer_op in ["SL", "SR"]:
41+
categ = "shift"
42+
if categ not in timing_model:
43+
return None # unknown operation
44+
45+
bits = max(widths_vector)
46+
origin, slope = timing_model[categ]
47+
return origin + bits * slope
48+
4149

4250
def func_name_to_op_and_widths(func_name):
43-
p = func_name.find("_OP_")
44-
if p >= 0:
45-
optyp = func_name[:p]
46-
_ = func_name.find("_", p+4)
47-
op = func_name[p+4:_]
48-
widths = re.findall(r'int[0-9]+', func_name[4:])
49-
if not len(widths):
50-
return None
51-
widths = [int(w[3:]) for w in widths] #cut 'int'
52-
return op, widths
53-
return None
51+
p = func_name.find("_OP_")
52+
if p >= 0:
53+
optyp = func_name[:p]
54+
_ = func_name.find("_", p + 4)
55+
op = func_name[p + 4 : _]
56+
widths = re.findall(r"int[0-9]+", func_name[4:])
57+
if not len(widths):
58+
return None
59+
widths = [int(w[3:]) for w in widths] # cut 'int'
60+
return op, widths
61+
return None
62+
5463

5564
def process_delays(dir_path):
56-
print("real\top\testimation\twidths")
57-
mindelay = 1e6
58-
total = count = 0
59-
for path in os.listdir(dir_path):
60-
full = os.path.join(dir_path, path)
61-
if os.path.isfile(full):
62-
op_and_widths = func_name_to_op_and_widths(path)
63-
if op_and_widths is not None:
64-
op, widths = op_and_widths
65-
estim_ns = estimate_int_timing(op, widths)
66-
with open(full, 'r') as file:
67-
time_ns = float(file.read())
68-
69-
if estim_ns is not None:
70-
if time_ns < mindelay: mindelay = time_ns
71-
total += (time_ns - estim_ns)**2
72-
count += 1
73-
print(str(time_ns) + "\t" + op + "\t" + str(estim_ns) + "\t".join([str(w) for w in widths]))
74-
75-
rms = math.sqrt(total/count)
76-
print("Count:", count, ", minimum delay (ns):", mindelay, ", RMS error (ns):", rms)
65+
print("real\top\testimation\twidths")
66+
mindelay = 1e6
67+
total = count = 0
68+
for path in os.listdir(dir_path):
69+
full = os.path.join(dir_path, path)
70+
if os.path.isfile(full):
71+
op_and_widths = func_name_to_op_and_widths(path)
72+
if op_and_widths is not None:
73+
op, widths = op_and_widths
74+
estim_ns = estimate_int_timing(op, widths)
75+
with open(full, "r") as file:
76+
time_ns = float(file.read())
77+
78+
if estim_ns is not None:
79+
if time_ns < mindelay:
80+
mindelay = time_ns
81+
total += (time_ns - estim_ns) ** 2
82+
count += 1
83+
print(
84+
str(time_ns)
85+
+ "\t"
86+
+ op
87+
+ "\t"
88+
+ str(estim_ns)
89+
+ "\t".join([str(w) for w in widths])
90+
)
91+
92+
rms = math.sqrt(total / count)
93+
print("Count:", count, ", minimum delay (ns):", mindelay, ", RMS error (ns):", rms)

src/DIAMOND.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def SYN_AND_REPORT_TIMING_NEW(
9191
log_text = f.read()
9292
f.close()
9393
else:
94-
9594
# Write top level vhdl for this module/multimain
9695
if inst_name:
9796
VHDL.WRITE_LOGIC_ENTITY(
@@ -221,7 +220,7 @@ def init_synplify(self, syn_output):
221220
# WTF is system clock that shows up with zero delay?
222221
# Skip it?
223222
if path_report.path_delay_ns == 0.0:
224-
continue
223+
continue
225224
# Only save the worst delay per path group
226225
do_add = False
227226
if path_report.path_group in self.path_reports:
@@ -317,7 +316,7 @@ def init_synplify(self, path_report_text):
317316
toks = list(filter(None, line.split(" ")))
318317
tok = toks[6].strip()
319318
self.path_group = tok
320-
#print("path_group",self.path_group)
319+
# print("path_group",self.path_group)
321320
tok1 = "The end point is clocked by"
322321
if tok1 in line:
323322
toks = list(filter(None, line.split(" ")))
@@ -351,7 +350,7 @@ def init_synplify(self, path_report_text):
351350
prev_line = line
352351

353352
self.path_delay_ns = self.source_ns_per_clock - self.slack_ns
354-
#print("path_delay_ns",self.path_delay_ns)
353+
# print("path_delay_ns",self.path_delay_ns)
355354

356355
def init_lse(self, path_report_text):
357356
# print("path_report_text",path_report_text)
@@ -366,7 +365,6 @@ def init_lse(self, path_report_text):
366365

367366
prev_line = None
368367
for line in path_report_text.split("\n"):
369-
370368
# DELAY
371369
tok1 = "Delay:"
372370
if tok1 in line:
@@ -453,5 +451,8 @@ def init_lse(self, path_report_text):
453451
def FUNC_IS_PRIMITIVE(func_name):
454452
return OPEN_TOOLS.FUNC_IS_PRIMITIVE(func_name)
455453

454+
456455
def GET_PRIMITIVE_MODULE_TEXT(inst_name, Logic, parser_state, TimingParamsLookupTable):
457-
return OPEN_TOOLS.GET_PRIMITIVE_MODULE_TEXT(inst_name, Logic, parser_state, TimingParamsLookupTable)
456+
return OPEN_TOOLS.GET_PRIMITIVE_MODULE_TEXT(
457+
inst_name, Logic, parser_state, TimingParamsLookupTable
458+
)

0 commit comments

Comments
 (0)