Skip to content

Commit 8dc1235

Browse files
committed
Use the logger rather than a DEBUG flag, and fix the recognition of isAssembly.
1 parent eac92f0 commit 8dc1235

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

driver/utils.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
# Internal logger
3333
_logger = logging.getLogger(__name__)
3434

35-
# Flag for debugging
36-
DEBUG = False
35+
# Flag for dumping
36+
DUMPING = False
3737

3838

3939
# This class applies filters to GCC argument lists. It has a few
@@ -282,7 +282,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
282282
_logger.warning('Did not recognize the compiler flag "{0}"'.format(currentItem))
283283
self.compileUnaryCallback(currentItem)
284284

285-
if DEBUG:
285+
if DUMPING:
286286
self.dump()
287287

288288
def _shiftArgs(self, nargs):
@@ -300,7 +300,7 @@ def abortUnaryCallback(self, flag):
300300
def inputFileCallback(self, infile):
301301
_logger.debug('Input file: ' + infile)
302302
self.inputFiles.append(infile)
303-
if re.search('\\.(s|S)', infile):
303+
if re.search('\\.(s|S)$', infile):
304304
self.isAssembly = True
305305

306306
def outputFileCallback(self, flag, filename):
@@ -368,7 +368,7 @@ def getOutputFilename(self):
368368

369369
# iam: returns a pair [objectFilename, bitcodeFilename] i.e .o and .bc.
370370
# the hidden flag determines whether the objectFile is hidden like the
371-
# bitcodeFile is (starts with a '.'), use the DEBUG flag to get a sense
371+
# bitcodeFile is (starts with a '.'), use the logging level & DUMPING flag to get a sense
372372
# of what is being written out.
373373
def getArtifactNames(self, srcFile, hidden=False):
374374
(srcpath, srcbase) = os.path.split(srcFile)
@@ -385,15 +385,15 @@ def getArtifactNames(self, srcFile, hidden=False):
385385

386386
#iam: for printing our partitioning of the args
387387
def dump(self):
388-
print("compileArgs: ", self.compileArgs)
389-
print("inputFiles: ", self.inputFiles)
390-
print("linkArgs: ", self.linkArgs)
391-
print("objectFiles: ", self.objectFiles)
392-
print("outputFilename: ", self.outputFilename)
388+
_logger.debug('compileArgs: {0}'.format(self.compileArgs))
389+
_logger.debug('inputFiles: {0}'.format(self.inputFiles))
390+
_logger.debug('linkArgs: {0}'.format(self.linkArgs))
391+
_logger.debug('objectFiles: {0}'.format(self.objectFiles))
392+
_logger.debug('outputFilename: {0}'.format(self.outputFilename))
393393
for srcFile in self.inputFiles:
394-
print("srcFile: ", srcFile)
394+
_logger.debug('srcFile: {0}'.format(srcFile))
395395
(objFile, bcFile) = self.getArtifactNames(srcFile)
396-
print("{0} ===> ({1}, {2})".format(srcFile, objFile, bcFile))
396+
_logger.debug('{0} ===> ({1}, {2})'.format(srcFile, objFile, bcFile))
397397

398398

399399

@@ -459,8 +459,7 @@ def attachBitcodePathToObject(bcPath, outFileName):
459459
# Don't try to attach a bitcode path to a binary. Unfortunately
460460
# that won't work.
461461
(root, ext) = os.path.splitext(outFileName)
462-
if DEBUG:
463-
print('attachBitcodePathToObject: {0} ===> {1} [ext = {2}]\n'.format(bcPath, outFileName, ext))
462+
_logger.debug('attachBitcodePathToObject: {0} ===> {1} [ext = {2}]\n'.format(bcPath, outFileName, ext))
464463
#iam: this also looks very dodgey; we need a more reliable way to do this:
465464
if ext not in ('.o', '.lo', '.os', '.So', '.po'):
466465
_logger.warning('Cannot attach bitcode path to "{0} of type {1}"'.format(outFileName, FileType.getFileType(outFileName)))
@@ -570,8 +569,7 @@ def getBitcodeCompiler(self):
570569
# When we build LLVM bitcode we do not want to use the GNU assembler,
571570
# instead we want gcc to use our own assembler (see driver/as).
572571
cmd = cc + ['-B', driverDir, '-fplugin={0}'.format(pth), '-fplugin-arg-dragonegg-emit-ir']
573-
if DEBUG:
574-
print(cmd)
572+
_logger.debug(cmd)
575573
return cmd
576574

577575
def getCompiler(self):
@@ -696,8 +694,7 @@ def buildBitcodeFile(builder, srcFile, bcFile):
696694
bcc.extend(af.compileArgs)
697695
bcc.extend(['-c', srcFile])
698696
bcc.extend(['-o', bcFile])
699-
if DEBUG:
700-
print('buildBitcodeFile: {0}\n'.format(bcc))
697+
_logger.debug('buildBitcodeFile: {0}\n'.format(bcc))
701698
proc = Popen(bcc)
702699
rc = proc.wait()
703700
if rc != 0:
@@ -710,8 +707,7 @@ def buildObjectFile(builder, srcFile, objFile):
710707
cc.extend(af.compileArgs)
711708
cc.append(srcFile)
712709
cc.extend(['-c', '-o', objFile])
713-
if DEBUG:
714-
print('buildObjectFile: {0}\n'.format(cc))
710+
_logger.debug('buildObjectFile: {0}\n'.format(cc))
715711
proc = Popen(cc)
716712
rc = proc.wait()
717713
if rc != 0:

0 commit comments

Comments
 (0)