Skip to content

Commit 2275513

Browse files
committed
Linting.
1 parent b97f9e7 commit 2275513

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

wllvm/arglistfilter.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
201201
'--coverage' : (0, ArgumentListFilter.compileLinkUnaryCallback),
202202

203203
# ian's additions while building the linux kernel
204-
'/dev/null' : (0, ArgumentListFilter.inputFileCallback),
204+
'/dev/null' : (0, ArgumentListFilter.inputFileCallback),
205205
'-mno-80387': (0, ArgumentListFilter.compileUnaryCallback), #gcc Don't generate output containing 80387 instructions for floating point.
206206

207207

@@ -256,8 +256,6 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
256256
r'^-stdlib=.+$' : (0, ArgumentListFilter.compileLinkUnaryCallback),
257257
r'^-mtune=.+$' : (0, ArgumentListFilter.compileUnaryCallback),
258258
r'^-mstack-alignment=.+$': (0, ArgumentListFilter.compileUnaryCallback), #iam: linux kernel stuff
259-
r'^-march=.+$': (0, ArgumentListFilter.compileUnaryCallback), #iam: linux kernel stuff
260-
r'^-mregparm=.+$': (0, ArgumentListFilter.compileUnaryCallback), #iam: linux kernel stuff
261259
r'^-mcmodel=.+$': (0, ArgumentListFilter.compileUnaryCallback), #iam: linux kernel stuff
262260
r'^-mpreferred-stack-boundary=.+$': (0, ArgumentListFilter.compileUnaryCallback), #iam: linux kernel stuff
263261
r'^-mindirect-branch=.+$': (0, ArgumentListFilter.compileUnaryCallback), #iam: linux kernel stuff
@@ -338,21 +336,22 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
338336

339337

340338
def skipBitcodeGeneration(self):
339+
retval = (False, "")
341340
if os.environ.get('WLLVM_CONFIGURE_ONLY', False):
342-
return (True, "CFG Only")
343-
if not self.inputFiles:
344-
return (True, "No input files")
345-
if self.isEmitLLVM:
346-
return (True, "Emit LLVM")
347-
if self.isAssembly or self.isAssembleOnly:
348-
return (True, "Assembly")
349-
if self.isPreprocessOnly:
350-
return (True, "Preprocess Only")
351-
if self.isStandardIn:
352-
return (True, "Standard In")
353-
if (self.isDependencyOnly and not self.isCompileOnly):
354-
return (True, "Dependency Only")
355-
return (False, "")
341+
retval = (True, "CFG Only")
342+
elif not self.inputFiles:
343+
retval = (True, "No input files")
344+
elif self.isEmitLLVM:
345+
retval = (True, "Emit LLVM")
346+
elif self.isAssembly or self.isAssembleOnly:
347+
retval = (True, "Assembly")
348+
elif self.isPreprocessOnly:
349+
retval = (True, "Preprocess Only")
350+
elif self.isStandardIn:
351+
retval = (True, "Standard In")
352+
elif (self.isDependencyOnly and not self.isCompileOnly):
353+
retval = (True, "Dependency Only")
354+
return retval
356355

357356
def _shiftArgs(self, nargs):
358357
ret = []

wllvm/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def checkLogging(self):
120120
(destination, level) = loggingConfiguration()
121121
print('Logging output to {0}.'.format(destination if destination else 'standard error'))
122122
if not level:
123-
print('Logging level not set, defaulting to WARNING\n'.format(destination if destination else 'standard error'))
123+
print('Logging level not set, defaulting to WARNING\n')
124124
else:
125125
print('Logging level set to {0}.\n'.format(level))
126126

wllvm/compilers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def attachBitcodePathToObject(bcPath, outFileName):
108108
fileType = FileType.getFileType(outFileName)
109109
if fileType not in (FileType.MACH_OBJECT, FileType.ELF_OBJECT):
110110
#if fileType not in (FileType.MACH_OBJECT, FileType.MACH_SHARED, FileType.ELF_OBJECT, FileType.ELF_SHARED):
111-
_logger.warning('Cannot attach bitcode path to "%s of type %s"', outFileName, FileType.getReadableFileType(fileType))
111+
_logger.warning('Cannot attach bitcode path to "%s of type %s"', outFileName, FileType.getFileTypeString(fileType))
112112
return
113113

114114
#iam: this also looks very dodgey; we need a more reliable way to do this:

wllvm/extraction.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ def extract_from_thin_archive(inputFile):
248248
arOutput = arProc.communicate()[0]
249249
if arProc.returncode != 0:
250250
_logger.error('ar failed on %s', inputFile)
251-
sys.exit(-1)
252-
253-
lines = arOutput.splitlines()
254-
return lines
251+
else:
252+
retval = arOutput.splitlines()
253+
return retval
255254

256255

257256

@@ -280,17 +279,17 @@ def handleThinArchive(pArgs):
280279

281280
bcFiles = []
282281
for p in objectPaths:
283-
_logger.info('handleThinArchive: processing {0}'.format(p))
282+
_logger.info('handleThinArchive: processing %s', p)
284283
contents = pArgs.extractor(p)
285284
for c in contents:
286-
if len(c) > 0:
287-
_logger.info('\t including {0}'.format(c))
285+
if c:
286+
_logger.info('\t including %s', c)
288287
bcFiles.append(str(c))
289288

290289
return buildArchive(pArgs, bcFiles)
291290

292291
#iam: do we want to preserve the order in the archive? if so we need to return both the list and the dict.
293-
def fetchTOC(pArgs, inputFile):
292+
def fetchTOC(inputFile):
294293
toc = {}
295294

296295
arCmd = ['ar', '-t', inputFile] #iam: check if this might be os dependent
@@ -333,11 +332,11 @@ def handleArchive(pArgs):
333332

334333
originalDir = os.getcwd() # We want to end up back where we started.
335334

336-
toc = fetchTOC(pArgs, inputFile)
335+
toc = fetchTOC(inputFile)
337336

338337
if not toc:
339338
_logger.warning('No files found, so nothing to be done.')
340-
return
339+
return 0
341340

342341
bitCodeFiles = []
343342

@@ -353,31 +352,31 @@ def handleArchive(pArgs):
353352
arP = Popen(arCmd)
354353
except Exception as e:
355354
_logger.error(e)
356-
return
355+
return 1
357356

358357
arPE = arP.wait()
359358

360359
if arPE != 0:
361360
errorMsg = 'Failed to execute archiver with command {0}'.format(arCmd)
362361
_logger.error(errorMsg)
363-
return
362+
return 1
364363

365364
# Extract bitcode locations from object
366365
contents = pArgs.extractor(filename)
367-
_logger.debug('From instance {0} of {1} in {2} we extracted\n\t{3}\n'.format(i, filename, inputFile, contents))
366+
_logger.debug('From instance %s of %s in %s we extracted\n\t%s\n', i, filename, inputFile, contents)
368367
if contents:
369368
for path in contents:
370369
if path:
371370
bitCodeFiles.append(path)
372371
else:
373-
_logger.debug('From instance {0} of {1} in {2} we extracted NOTHING\n'.format(i, filename, inputFile))
372+
_logger.debug('From instance %s of %s in %s we extracted NOTHING\n', i, filename, inputFile)
374373

375374
finally:
376375
# Delete the temporary folder
377376
_logger.debug('Deleting temporary folder "%s"', tempDir)
378377
shutil.rmtree(tempDir)
379378

380-
_logger.debug('From instance {0} we extracted\n\t{1}\n'.format(inputFile, bitCodeFiles))
379+
_logger.debug('From instance %s we extracted\n\t%s\n', inputFile, bitCodeFiles)
381380

382381
# Build bitcode archive
383382
os.chdir(originalDir)
@@ -599,7 +598,7 @@ def extract_bc_args():
599598

600599

601600
def process_file_unix(pArgs):
602-
601+
retval = 1
603602
ft = FileType.getFileType(pArgs.inputFile)
604603
_logger.debug('Detected file type is %s', FileType.revMap[ft])
605604

@@ -609,19 +608,19 @@ def process_file_unix(pArgs):
609608

610609
if ft == FileType.ELF_EXECUTABLE or ft == FileType.ELF_SHARED or ft == FileType.ELF_OBJECT:
611610
_logger.info('Generating LLVM Bitcode module')
612-
return handleExecutable(pArgs)
611+
retval = handleExecutable(pArgs)
613612
elif ft == FileType.ARCHIVE:
614-
return handleArchive(pArgs)
613+
retval = handleArchive(pArgs)
615614
elif ft == FileType.THIN_ARCHIVE:
616-
return handleThinArchive(pArgs)
615+
retval = handleThinArchive(pArgs)
617616
else:
618617
_logger.error('File "%s" of type %s cannot be used', pArgs.inputFile, FileType.revMap[ft])
619-
return 1
618+
return retval
620619

621620

622621

623622
def process_file_darwin(pArgs):
624-
623+
retval = 1
625624
ft = FileType.getFileType(pArgs.inputFile)
626625
_logger.debug('Detected file type is %s', FileType.revMap[ft])
627626

@@ -631,9 +630,9 @@ def process_file_darwin(pArgs):
631630

632631
if ft == FileType.MACH_EXECUTABLE or ft == FileType.MACH_SHARED or ft == FileType.MACH_OBJECT:
633632
_logger.info('Generating LLVM Bitcode module')
634-
return handleExecutable(pArgs)
633+
retval = handleExecutable(pArgs)
635634
elif ft == FileType.ARCHIVE:
636-
return handleArchive(pArgs)
635+
retval = handleArchive(pArgs)
637636
else:
638637
_logger.error('File "%s" of type %s cannot be used', pArgs.inputFile, FileType.revMap[ft])
639-
return 1
638+
return retval

wllvm/filetype.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class FileType(object):
1919
MACH_OBJECT = None
2020
MACH_SHARED = None
2121
ARCHIVE = None
22+
THIN_ARCHIVE = None
2223

2324

2425
# Provides int -> str map
@@ -66,8 +67,7 @@ def getFileTypeString(cls, fti):
6667
"""
6768
if fti in cls.revMap:
6869
return cls.revMap[fti]
69-
else:
70-
'UNKNOWN'
70+
return 'UNKNOWN'
7171

7272
@classmethod
7373
def init(cls):
@@ -81,8 +81,7 @@ def init(cls):
8181
'MACH_OBJECT',
8282
'MACH_SHARED',
8383
'ARCHIVE',
84-
'THIN_ARCHIVE',
85-
)):
84+
'THIN_ARCHIVE')):
8685
setattr(cls, name, index)
8786
cls.revMap[index] = name
8887

0 commit comments

Comments
 (0)