Skip to content

Commit 4bb0970

Browse files
committed
pylint driven code clean up.
1 parent 2bef076 commit 4bb0970

14 files changed

+721
-314
lines changed

.pylintrc

Lines changed: 407 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ all:
2727

2828

2929
#local editable install for developing
30-
develop:
30+
develop:
3131
pip install -e .
3232

3333

@@ -36,7 +36,7 @@ dist: clean
3636

3737
# If you need to push this project again,
3838
# INCREASE the version number in wllvm/version.py,
39-
# otherwise the server will give you an error.
39+
# otherwise the server will give you an error.
4040

4141
testpublish: dist
4242
python setup.py register -r https://testpypi.python.org/pypi
@@ -50,7 +50,7 @@ publish: dist
5050
python setup.py sdist upload -r https://pypi.python.org/pypi
5151

5252
install:
53-
pip install
53+
pip install
5454

5555
check_clang:
5656
cd test; python -m unittest -v test_base_driver test_clang_driver
@@ -74,4 +74,6 @@ lint:
7474
ifeq ($(PYLINT),)
7575
$(error lint target requires pylint)
7676
endif
77-
@ $(PYLINT) -E wllvm/*.py
77+
# @ $(PYLINT) -E wllvm/*.py
78+
# for detecting more than just errors:
79+
@ $(PYLINT) --rcfile=.pylintrc wllvm/*.py

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
# use the in house version number so we stay in synch with ourselves.
1515
from wllvm.version import wllvm_version
16-
16+
1717
setup(
1818
name='wllvm',
19-
version=wllvm_version,
19+
version=wllvm_version,
2020
description='Whole Program LLVM',
2121
long_description=long_description,
2222
url='https://github.com/SRI-CSL/whole-program-llvm',
@@ -25,9 +25,9 @@
2525

2626

2727
include_package_data=True,
28-
28+
2929
packages=find_packages(),
30-
30+
3131
entry_points = {
3232
'console_scripts': [
3333
'wllvm-as = wllvm.as:main',
@@ -39,7 +39,7 @@
3939
},
4040

4141
license='MIT',
42-
42+
4343
classifiers=[
4444
'Development Status :: 4 - Beta',
4545
'Natural Language :: English',

wllvm/arglistfilter.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import logging, collections, os, re, sys
1+
import logging
2+
import collections
3+
import os
4+
import re
5+
import sys
26

37
# Internal logger
48
_logger = logging.getLogger(__name__)
@@ -123,8 +127,8 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
123127
# Debug
124128
'-g' : (0, ArgumentListFilter.compileUnaryCallback),
125129
'-g0' : (0, ArgumentListFilter.compileUnaryCallback), #iam: clang not gcc
126-
'-ggdb' : (0, ArgumentListFilter.compileUnaryCallback),
127-
'-ggdb3' : (0, ArgumentListFilter.compileUnaryCallback),
130+
'-ggdb' : (0, ArgumentListFilter.compileUnaryCallback),
131+
'-ggdb3' : (0, ArgumentListFilter.compileUnaryCallback),
128132
'-gdwarf-2' : (0, ArgumentListFilter.compileUnaryCallback),
129133
'-gdwarf-3' : (0, ArgumentListFilter.compileUnaryCallback),
130134
'-gline-tables-only' : (0, ArgumentListFilter.compileUnaryCallback),
@@ -185,7 +189,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
185189
# (the Darwin ld is a bit single minded)
186190
#
187191
# 1) compilation with -fvisibility=hidden causes trouble when we try to
188-
# attach bitcode filenames to an object file. The global symbols in object
192+
# attach bitcode filenames to an object file. The global symbols in object
189193
# files get turned into local symbols when we invoke 'ld -r'
190194
#
191195
# 2) all stripping commands (e.g., -dead_strip) remove the __LLVM segment after
@@ -195,8 +199,8 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
195199
# calling ld -r.
196200
#
197201
'-Wl,-dead_strip' : (0, ArgumentListFilter.darwinWarningLinkUnaryCallback),
198-
199-
}
202+
203+
}
200204

201205
#
202206
# Patterns for other command-line arguments:
@@ -227,15 +231,15 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
227231
r'^--sysroot=.+$' : (0, ArgumentListFilter.compileUnaryCallback),
228232
r'^-print-prog-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
229233
r'^-print-file-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
230-
234+
231235
}
232236

233237
#iam: try and keep track of the files, input object, and output
234238
self.inputList = inputList
235239
self.inputFiles = []
236240
self.objectFiles = []
237241
self.outputFilename = None
238-
242+
239243
#iam: try and split the args into linker and compiler switches
240244
self.compileArgs = []
241245
self.linkArgs = []
@@ -256,10 +260,10 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
256260
self._inputArgs = collections.deque(inputList)
257261

258262
#iam: parse the cmd line, bailing if we discover that there will be no second phase.
259-
while ( len(self._inputArgs) > 0 and
260-
not (self.isAssembly or
261-
self.isAssembleOnly or
262-
self.isPreprocessOnly ) ):
263+
while (len(self._inputArgs) > 0 and
264+
not (self.isAssembly or
265+
self.isAssembleOnly or
266+
self.isPreprocessOnly)):
263267
# Get the next argument
264268
currentItem = self._inputArgs.popleft()
265269
_logger.debug('Trying to match item ' + currentItem)
@@ -281,7 +285,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
281285
# If no action has been specified, this is a zero-argument
282286
# flag that we should just keep.
283287
if not matched:
284-
_logger.warning('Did not recognize the compiler flag "{0}"'.format(currentItem))
288+
_logger.warning('Did not recognize the compiler flag "%s"', currentItem)
285289
self.compileUnaryCallback(currentItem)
286290

287291
if DUMPING:
@@ -296,11 +300,11 @@ def _shiftArgs(self, nargs):
296300
return ret
297301

298302
def abortUnaryCallback(self, flag):
299-
_logger.warning('Out of context experience: "{0}"'.format(str(self.inputList)))
303+
_logger.warning('Out of context experience: "%s"', str(self.inputList))
300304
sys.exit(1)
301305

302306
def inputFileCallback(self, infile):
303-
_logger.debug('Input file: ' + infile)
307+
_logger.debug('Input file: %s', infile)
304308
self.inputFiles.append(infile)
305309
if re.search('\\.(s|S)$', infile):
306310
self.isAssembly = True
@@ -335,13 +339,13 @@ def compileUnaryCallback(self, flag):
335339

336340
def darwinWarningLinkUnaryCallback(self, flag):
337341
if sys.platform.startswith('darwin'):
338-
_logger.warning('The flag "{0}" cannot be used with this tool'.format(flag))
342+
_logger.warning('The flag "%s" cannot be used with this tool', flag)
339343
sys.exit(1)
340344
else:
341345
self.linkArgs.append(flag)
342346

343347
def defaultBinaryCallback(self, flag, arg):
344-
_logger.warning('Ignoring compiler arg pair: "{0} {1}"'.format(flag, arg))
348+
_logger.warning('Ignoring compiler arg pair: "%s %s"', flag, arg)
345349

346350
def dependencyBinaryCallback(self, flag, arg):
347351
self.isDependencyOnly = True
@@ -392,15 +396,11 @@ def getArtifactNames(self, srcFile, hidden=False):
392396

393397
#iam: for printing our partitioning of the args
394398
def dump(self):
395-
_logger.debug('compileArgs: {0}'.format(self.compileArgs))
396-
_logger.debug('inputFiles: {0}'.format(self.inputFiles))
397-
_logger.debug('linkArgs: {0}'.format(self.linkArgs))
398-
_logger.debug('objectFiles: {0}'.format(self.objectFiles))
399-
_logger.debug('outputFilename: {0}'.format(self.outputFilename))
399+
_logger.debug('compileArgs: %s\ninputFiles: %s\nlinkArgs: %s',
400+
self.compileArgs, self.inputFiles, self.linkArgs)
401+
_logger.debug('objectFiles: %s\noutputFilename: %s',
402+
self.objectFiles, self.outputFilename)
400403
for srcFile in self.inputFiles:
401-
_logger.debug('srcFile: {0}'.format(srcFile))
404+
_logger.debug('srcFile: %s', srcFile)
402405
(objFile, bcFile) = self.getArtifactNames(srcFile)
403-
_logger.debug('{0} ===> ({1}, {2})'.format(srcFile, objFile, bcFile))
404-
405-
406-
406+
_logger.debug('%s ===> (%s, %s)', srcFile, objFile, bcFile)

wllvm/as.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
"""This is the (dragonegg) assembler phase.
2+
"""This is the (dragonegg) assembler phase.
33
44
This variant is only invoked during the second compilation where we
55
are building bitcode. The compiler has already been instructed to
@@ -53,7 +53,7 @@ def outFileCallback(self, flag, name):
5353
self.outFileName = name
5454

5555
def main():
56-
56+
5757
argFilter = BCFilter(sys.argv[1:])
5858
# Since this is just the assembler, there should only ever be one file
5959
try:
@@ -72,7 +72,7 @@ def main():
7272
if not argFilter.outFileName:
7373
logging.error('Output file argument not found.')
7474
sys.exit(1)
75-
75+
7676
fakeAssembler = [llvmAssembler, infile, '-o', argFilter.outFileName]
7777

7878
asmProc = Popen(fakeAssembler)
@@ -84,6 +84,6 @@ def main():
8484

8585
sys.exit(realRet)
8686

87-
87+
8888
if __name__ == '__main__':
8989
sys.exit(main())

0 commit comments

Comments
 (0)