forked from github/verilator
Cleanup python code style issues. No functional change intended.
This commit is contained in:
parent
81ef8fb201
commit
de774ac4d8
@ -504,8 +504,12 @@ FLAKE8_FLAGS = \
|
||||
--extend-exclude=fastcov.py \
|
||||
--ignore=E123,E129,E251,E501,W503,W504,E701
|
||||
|
||||
PYLINT = pylint
|
||||
PYLINT_FLAGS = --disable=R0801
|
||||
|
||||
lint-py:
|
||||
$(FLAKE8) $(FLAKE8_FLAGS) $(PY_PROGRAMS)
|
||||
$(PYLINT) $(PYLINT_FLAGS) $(PY_PROGRAMS)
|
||||
|
||||
format-pl-exec:
|
||||
-chmod a+x test_regress/t/*.pl
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- Python -*- See copyright, etc below
|
||||
# pylint: disable=C0114,C0115,R0903
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -26,15 +27,15 @@ class VlFileCopy:
|
||||
|
||||
xml_temp = tempfile.NamedTemporaryFile()
|
||||
|
||||
args = [
|
||||
vargs = [
|
||||
'--xml-output',
|
||||
xml_temp.name,
|
||||
'--bbox-sys', # Parse some stuff can't translate
|
||||
'--bbox-unsup',
|
||||
'--prefix vlxml'
|
||||
] # So we know name of .xml output
|
||||
args += verilator_args
|
||||
self.run_verilator(args)
|
||||
vargs += verilator_args
|
||||
self.run_verilator(vargs)
|
||||
self.tree = ET.parse(xml_temp.name)
|
||||
|
||||
os.makedirs(output_dir, 0o777, True)
|
||||
@ -49,13 +50,13 @@ class VlFileCopy:
|
||||
print("\tcp %s %s" % (filename, output_dir))
|
||||
copy2(filename, output_dir)
|
||||
|
||||
def run_verilator(self, args):
|
||||
def run_verilator(self, vargs):
|
||||
"""Run Verilator command, check errors"""
|
||||
if os.getenv("VERILATOR_ROOT"):
|
||||
command = os.getenv("VERILATOR_ROOT") + "/bin/verilator"
|
||||
else:
|
||||
command = "verilator"
|
||||
command += ' ' + ' '.join(args)
|
||||
command += ' ' + ' '.join(vargs)
|
||||
if self.debug:
|
||||
print("\t%s " % command)
|
||||
status = subprocess.call(command, shell=True)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- Python -*- See copyright, etc below
|
||||
# pylint: disable=C0103,C0114,C0115,C0115,C0116,R0914
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -25,15 +26,15 @@ class VlHierGraph:
|
||||
|
||||
xml_temp = tempfile.NamedTemporaryFile()
|
||||
|
||||
args = [
|
||||
vargs = [
|
||||
'--xml-output',
|
||||
xml_temp.name,
|
||||
'--bbox-sys', # Parse some stuff can't translate
|
||||
'--bbox-unsup',
|
||||
'--prefix vlxml'
|
||||
] # So we know name of .xml output
|
||||
args += verilator_args
|
||||
self.run_verilator(args)
|
||||
vargs += verilator_args
|
||||
self.run_verilator(vargs)
|
||||
self.tree = ET.parse(xml_temp.name)
|
||||
|
||||
with open(output_filename, "w") as fh:
|
||||
@ -72,13 +73,13 @@ class VlHierGraph:
|
||||
self.name_to_number[name] = self.next_vertex_number
|
||||
return self.name_to_number[name]
|
||||
|
||||
def run_verilator(self, args):
|
||||
def run_verilator(self, vargs):
|
||||
"""Run Verilator command, check errors"""
|
||||
if os.getenv("VERILATOR_ROOT"):
|
||||
command = os.getenv("VERILATOR_ROOT") + "/bin/verilator"
|
||||
else:
|
||||
command = "verilator"
|
||||
command += ' ' + ' '.join(args)
|
||||
command += ' ' + ' '.join(vargs)
|
||||
if self.debug:
|
||||
print("\t%s " % command)
|
||||
status = subprocess.call(command, shell=True)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,R0912,R0914,R0915,W0125,W0621,exec-used
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -398,7 +399,7 @@ if True:
|
||||
elif match_from:
|
||||
start = int(match_from.group(1))
|
||||
else:
|
||||
os.exit("%Error: --stages not understood: " + Args.stages)
|
||||
sys.exit("%Error: --stages not understood: " + Args.stages)
|
||||
for n in range(0, 100):
|
||||
Args.stage_enabled[n] = False
|
||||
for n in range(start, end + 1):
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,C0301
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,C0321,R0911
|
||||
######################################################################
|
||||
# DESCRIPTION: Fuzzer result checker
|
||||
#
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,C0321
|
||||
######################################################################
|
||||
# DESCRIPTION: Fuzzer dictionary generator
|
||||
#
|
||||
@ -50,7 +51,7 @@ def write_file(filename, contents):
|
||||
|
||||
def parse_line(s):
|
||||
# str->maybe str
|
||||
if len(s) == 0: return
|
||||
if len(s) == 0: return None
|
||||
part = skip_while(lambda x: x != '"', s)
|
||||
if len(part) == 0 or part[0] != '"': return None
|
||||
literal_part = take_while(lambda x: x != '"', part[1:])
|
||||
@ -67,7 +68,7 @@ def main():
|
||||
|
||||
dirname = 'dictionary'
|
||||
r = system('mkdir -p ' + dirname)
|
||||
assert (r == 0)
|
||||
assert r == 0
|
||||
for i, token in enumerate(tokens):
|
||||
write_file(dirname + '/' + str(i), token)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,R0801,R0915
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -52,43 +53,43 @@ def test():
|
||||
# run a test using just the path
|
||||
if Args.stage <= 2:
|
||||
print("== stage 2")
|
||||
dir = testdirp
|
||||
run("/bin/rm -rf " + dir)
|
||||
run("/bin/mkdir -p " + dir)
|
||||
odir = testdirp
|
||||
run("/bin/rm -rf " + odir)
|
||||
run("/bin/mkdir -p " + odir)
|
||||
path = prefix + "/bin" + ":" + prefix + "/share/bin"
|
||||
write_verilog(dir)
|
||||
run("cd " + dir + " && PATH=" + path +
|
||||
write_verilog(odir)
|
||||
run("cd " + odir + " && PATH=" + path +
|
||||
":$PATH verilator --cc top.v --exe sim_main.cpp")
|
||||
run("cd " + dir + "/obj_dir && PATH=" + path +
|
||||
run("cd " + odir + "/obj_dir && PATH=" + path +
|
||||
":$PATH make -f Vtop.mk")
|
||||
run("cd " + dir + " && PATH=" + path + ":$PATH obj_dir/Vtop")
|
||||
run("cd " + odir + " && PATH=" + path + ":$PATH obj_dir/Vtop")
|
||||
|
||||
# run a test using exact path to binary
|
||||
if Args.stage <= 3:
|
||||
print("== stage 3")
|
||||
dir = testdirn
|
||||
run("/bin/rm -rf " + dir)
|
||||
run("/bin/mkdir -p " + dir)
|
||||
write_verilog(dir)
|
||||
odir = testdirn
|
||||
run("/bin/rm -rf " + odir)
|
||||
run("/bin/mkdir -p " + odir)
|
||||
write_verilog(odir)
|
||||
bin1 = prefix + "/bin"
|
||||
run("cd " + dir + " && " + bin1 +
|
||||
run("cd " + odir + " && " + bin1 +
|
||||
"/verilator --cc top.v --exe sim_main.cpp")
|
||||
run("cd " + dir + "/obj_dir && make -f Vtop.mk")
|
||||
run("cd " + dir + "/obj_dir && ./Vtop")
|
||||
run("cd " + odir + "/obj_dir && make -f Vtop.mk")
|
||||
run("cd " + odir + "/obj_dir && ./Vtop")
|
||||
|
||||
if Args.stage <= 9:
|
||||
print("*-* All Finished *-*")
|
||||
|
||||
|
||||
def write_verilog(dir):
|
||||
shutil.copy2("examples/make_hello_c/top.v", dir + "/top.v")
|
||||
shutil.copy2("examples/make_hello_c/sim_main.cpp", dir + "/sim_main.cpp")
|
||||
def write_verilog(odir):
|
||||
shutil.copy2("examples/make_hello_c/top.v", odir + "/top.v")
|
||||
shutil.copy2("examples/make_hello_c/sim_main.cpp", odir + "/sim_main.cpp")
|
||||
|
||||
|
||||
def cleanenv():
|
||||
for var in os.environ:
|
||||
if (var == "VERILATOR_ROOT" or var == "VERILATOR_INCLUDE"
|
||||
or var == "VERILATOR_NO_OPT_BUILD"):
|
||||
if var in ('VERILATOR_ROOT', 'VERILATOR_INCLUDE',
|
||||
'VERILATOR_NO_OPT_BUILD'):
|
||||
print("unset %s # Was '%s'" % (var, os.environ[var]))
|
||||
del os.environ[var]
|
||||
|
||||
|
24
src/astgen
24
src/astgen
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,C0123,C0301,R0902,R0913,R0914,R0912,R0915,W0621
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -17,10 +18,13 @@ Stages = {}
|
||||
class Cpt:
|
||||
def __init__(self):
|
||||
self.did_out_tree = False
|
||||
self.out_lines = []
|
||||
self.in_filename = ""
|
||||
self.in_linenum = 1
|
||||
self.out_filename = ""
|
||||
self.out_linenum = 1
|
||||
self.treeop = {}
|
||||
self.out_lines = []
|
||||
self.tree_skip_visit = {}
|
||||
self.treeop = {}
|
||||
self._exec_nsyms = 0
|
||||
self._exec_syms = {}
|
||||
|
||||
@ -169,9 +173,9 @@ class Cpt:
|
||||
self.error("Unknown astgen op: " + func)
|
||||
|
||||
@staticmethod
|
||||
def add_nodep(str):
|
||||
str = re.sub(r'\$([a-zA-Z0-9]+)', r'nodep->\1()', str)
|
||||
return str
|
||||
def add_nodep(strg):
|
||||
strg = re.sub(r'\$([a-zA-Z0-9]+)', r'nodep->\1()', strg)
|
||||
return strg
|
||||
|
||||
def _exec_syms_recurse(self, aref):
|
||||
for sym in aref:
|
||||
@ -213,9 +217,9 @@ class Cpt:
|
||||
argtext = func + "\000" # EOF character
|
||||
for tok in argtext:
|
||||
if tok == "\000":
|
||||
None
|
||||
None # pylint: disable=pointless-statement
|
||||
elif re.match(r'\s+', tok):
|
||||
None
|
||||
None # pylint: disable=pointless-statement
|
||||
elif tok == "{":
|
||||
newref = [forming]
|
||||
if not aref:
|
||||
@ -258,7 +262,7 @@ class Cpt:
|
||||
elif func == "NEVER":
|
||||
out += "nodep->v3fatalSrc(\"Executing transform that was NEVERed\");"
|
||||
elif func == "DONE":
|
||||
None
|
||||
None # pylint: disable=pointless-statement
|
||||
else:
|
||||
self.error("Unknown execution function format: " + func + "\n")
|
||||
return out
|
||||
@ -305,7 +309,7 @@ class Cpt:
|
||||
" if (" + typefunc['match_func'] +
|
||||
"(nodep)) return;\n"
|
||||
]
|
||||
if (typefunc['short_circuit']): # short-circuit match fn
|
||||
if typefunc['short_circuit']: # short-circuit match fn
|
||||
out_for_type_sc.extend(lines)
|
||||
else: # Standard match fn
|
||||
if typefunc[
|
||||
@ -471,7 +475,7 @@ def write_report(filename):
|
||||
if subclass != 'Node':
|
||||
fh.write("Ast%-12s " % subclass)
|
||||
fh.write("\n")
|
||||
if ("Ast" + typen) in ClassRefs:
|
||||
if ("Ast" + typen) in ClassRefs: # pylint: disable=superfluous-parens
|
||||
refs = ClassRefs["Ast" + typen]
|
||||
fh.write(" newed: ")
|
||||
for stage in sorted(refs['newed'].keys(),
|
||||
|
26
src/bisonpre
26
src/bisonpre
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,R0912,R0914,R0915,R1702,W0125
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -55,8 +56,7 @@ def output_prefix():
|
||||
if Args.output:
|
||||
o = re.sub(r'\.[^.]*$', '', Args.output)
|
||||
return o
|
||||
else:
|
||||
return Args.file_prefix + ".tab"
|
||||
return Args.file_prefix + ".tab"
|
||||
|
||||
|
||||
def unlink_ok(filename):
|
||||
@ -90,7 +90,7 @@ def bison_version_check():
|
||||
if v < 1.875:
|
||||
sys.exit("bisonpre: %Error: '" + Args.yacc + "' is version " + v +
|
||||
"; version 1.875 or newer is required\n")
|
||||
global Bison_Version
|
||||
global Bison_Version # pylint: disable=global-variable-undefined
|
||||
Bison_Version = v
|
||||
return
|
||||
|
||||
@ -182,7 +182,7 @@ def warning_check(filename):
|
||||
def clean_input(filename, outname):
|
||||
print(" edit " + filename + " " + outname)
|
||||
|
||||
global Filename
|
||||
global Filename # pylint: disable=global-variable-undefined
|
||||
Filename = filename
|
||||
|
||||
with open(filename) as fh:
|
||||
@ -190,7 +190,7 @@ def clean_input(filename, outname):
|
||||
|
||||
# Find "%tokens<type>:"
|
||||
# Find "rule<type>:" and replace with just "rule:"
|
||||
global Rules
|
||||
global Rules # pylint: disable=global-variable-undefined
|
||||
Rules = {}
|
||||
|
||||
types = {}
|
||||
@ -240,7 +240,7 @@ def clean_input(filename, outname):
|
||||
last_rule = name
|
||||
elif matchb:
|
||||
name = matchb.group(1)
|
||||
if name != 'public' and name != 'private':
|
||||
if name not in ('public', 'private'):
|
||||
if name in Rules:
|
||||
sys.exit("%Error: " + filename + ":" + str(lineno) +
|
||||
": Redeclaring '" + name + "': " + line)
|
||||
@ -332,7 +332,7 @@ def clean_input(filename, outname):
|
||||
": Can't find definition for token: " + etok +
|
||||
"\n")
|
||||
# Push it all onto one line to avoid error messages changing
|
||||
bar = ""
|
||||
pipe = ""
|
||||
for tok in sorted(tokens.keys()):
|
||||
hit = False
|
||||
for etok in endtoks:
|
||||
@ -340,8 +340,8 @@ def clean_input(filename, outname):
|
||||
hit = True
|
||||
break
|
||||
if not hit and endtok != tok:
|
||||
line += "\t" + bar + " " + tok + " " + action
|
||||
bar = "|"
|
||||
line += "\t" + pipe + " " + tok + " " + action
|
||||
pipe = "|"
|
||||
line += "\n"
|
||||
lines.append(line)
|
||||
|
||||
@ -376,11 +376,11 @@ def clean_input(filename, outname):
|
||||
lineno += 1
|
||||
if _enaline(line) and re.search(r'//BISONPRE_TYPES', line):
|
||||
lines.append(line)
|
||||
for type in sorted(types.keys()):
|
||||
if not type:
|
||||
for typen in sorted(types.keys()):
|
||||
if not typen:
|
||||
continue
|
||||
line = "%type<" + type + ">\t"
|
||||
for rule in sorted(types[type].keys()):
|
||||
line = "%type<" + typen + ">\t"
|
||||
for rule in sorted(types[typen].keys()):
|
||||
line += " " + rule
|
||||
line += "\n"
|
||||
lines.append(line)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114
|
||||
######################################################################
|
||||
#
|
||||
# Copyright 2005-2021 by Wilson Snyder. This program is free software; you
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0115,C0116,R0911,R0912,R0915,W0621
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -88,8 +89,8 @@ def process(cppcheck_args):
|
||||
file = match.group(1)
|
||||
linenum = match.group(2)
|
||||
match = re.search(r' id="([^"]+)"', last_error)
|
||||
id = match.group(1) if match else '?'
|
||||
if _suppress(file, linenum, id):
|
||||
eid = match.group(1) if match else '?'
|
||||
if _suppress(file, linenum, eid):
|
||||
suppress = True
|
||||
if file == "*":
|
||||
suppress = True
|
||||
@ -109,9 +110,9 @@ def process(cppcheck_args):
|
||||
######################################################################
|
||||
|
||||
|
||||
def _suppress(filename, linenum, id):
|
||||
def _suppress(filename, linenum, eid):
|
||||
if Args.debug:
|
||||
print("-Suppression search %s %s %s" % (filename, linenum, id))
|
||||
print("-Suppression search %s %s %s" % (filename, linenum, eid))
|
||||
|
||||
if filename == "*":
|
||||
return False
|
||||
@ -120,17 +121,17 @@ def _suppress(filename, linenum, id):
|
||||
filename = re.sub(r'^\.\./(.*)', r'src/\1', filename)
|
||||
|
||||
# Specific suppressions
|
||||
if id == 'missingInclude' and re.search(r'systemc.h', filename):
|
||||
if eid == 'missingInclude' and re.search(r'systemc.h', filename):
|
||||
return True
|
||||
if id == 'missingInclude' and re.search(r'svdpi.h', filename):
|
||||
if eid == 'missingInclude' and re.search(r'svdpi.h', filename):
|
||||
return True
|
||||
if id == 'unusedFunction' and re.search(r'verilated_dpi.cpp', filename):
|
||||
if eid == 'unusedFunction' and re.search(r'verilated_dpi.cpp', filename):
|
||||
return True
|
||||
if id == 'unusedFunction' and re.search(r'verilated_vpi.cpp', filename):
|
||||
if eid == 'unusedFunction' and re.search(r'verilated_vpi.cpp', filename):
|
||||
return True
|
||||
if id == 'unreachableCode' and re.search(r'V3ParseBison.c', filename):
|
||||
if eid == 'unreachableCode' and re.search(r'V3ParseBison.c', filename):
|
||||
return True
|
||||
if id == 'variableScope' and re.search(r'fstapi.c', filename):
|
||||
if eid == 'variableScope' and re.search(r'fstapi.c', filename):
|
||||
return True
|
||||
|
||||
if not os.path.exists(filename):
|
||||
@ -142,12 +143,12 @@ def _suppress(filename, linenum, id):
|
||||
lineno = 0
|
||||
for line in fh:
|
||||
lineno += 1
|
||||
if (lineno + 1 == linenum):
|
||||
if lineno + 1 == linenum:
|
||||
match = re.search(r'cppcheck-suppress((\s+\S+)+)', line)
|
||||
if match:
|
||||
for supid in match.group(1).split():
|
||||
if (supid == id or
|
||||
(id in SuppressMap and supid == SuppressMap[id])):
|
||||
if (supid == eid or (eid in SuppressMap
|
||||
and supid == SuppressMap[eid])):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0114,C0301
|
||||
######################################################################
|
||||
#
|
||||
# Copyright 2002-2021 by Wilson Snyder. This program is free software; you
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,C0114,C0116,eval-used
|
||||
######################################################################
|
||||
|
||||
import argparse
|
||||
@ -64,9 +65,7 @@ def write_keys(filename):
|
||||
elif re.search(r'VLCOVGEN_.*AUTO_EDIT_END', line):
|
||||
deleting = False
|
||||
out.append(line)
|
||||
elif deleting:
|
||||
None
|
||||
else:
|
||||
elif not deleting:
|
||||
out.append(line)
|
||||
|
||||
ok = "".join(out) == "".join(orig)
|
||||
|
Loading…
Reference in New Issue
Block a user