Skip to content

Commit 6450800

Browse files
authored
Merge pull request travitch#66 from SRI-CSL/master
Random minor improvements
2 parents 189fab4 + 5e3c682 commit 6450800

File tree

8 files changed

+96
-52
lines changed

8 files changed

+96
-52
lines changed

Makefile

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ all:
44
@echo 'Here are the targets:'
55
@echo ''
66
@echo 'To develop : "make develop"'
7-
@echo 'To test install : "make testinstall"'
87
@echo 'To install : "make install"'
9-
@echo 'To test publish : "make testpublish"'
108
@echo 'To publish : "make publish"'
119

1210
@echo 'To check clang : "make check_clang"'
@@ -17,11 +15,7 @@ all:
1715
@echo ''
1816
@echo 'e.g. on linux: PATH=/usr/lib/llvm-3.3/bin:... make check_dragonegg'
1917
@echo ''
20-
@echo 'To turn md 2 html : "make zippity"'
21-
@echo ''
22-
@echo 'then upload the zip file to https://pypi.python.org/pypi'
23-
@echo ''
24-
@echo 'To pylint : "make lint"'
18+
@echo 'To pylint : "make lint"'
2519
@echo ''
2620

2721

@@ -38,16 +32,8 @@ dist: clean
3832
# INCREASE the version number in wllvm/version.py,
3933
# otherwise the server will give you an error.
4034

41-
testpublish: dist
42-
python setup.py register -r https://testpypi.python.org/pypi
43-
python setup.py sdist upload -r https://testpypi.python.org/pypi
44-
45-
testinstall:
46-
pip install -i https://testpypi.python.org/pypi wllvm
47-
4835
publish: dist
49-
python setup.py register -r https://pypi.python.org/pypi
50-
python setup.py sdist upload -r https://pypi.python.org/pypi
36+
python setup.py sdist upload
5137

5238
install:
5339
pip install
@@ -58,11 +44,6 @@ check_clang:
5844
check_dragonegg:
5945
cd test; python -m unittest -v test_base_driver test_dragonegg_driver
6046

61-
zippity:
62-
rm -rf doczip*; mkdir doczip;
63-
cat README.md | pandoc -f markdown_github > doczip/index.html
64-
zip -r -j doczip.zip doczip
65-
6647
clean:
6748
rm -f wllvm/*.pyc wllvm/*~
6849

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ presence of static libraries in builds. WLLVM's approach has the
3131
distinct advantage of generating working binaries, in case some part
3232
of a build process requires that.
3333

34-
WLLVM works with either clang or the gcc dragonegg plugin.
34+
WLLVM works with either clang or the gcc dragonegg plugin. If you are not interested in dragonegg support,
35+
and speed is an issue for you, you may want to try out [gllvm.](https://github.com/SRI-CSL/gllvm)
3536

3637
Installation
3738
------------
@@ -241,17 +242,25 @@ Debugging
241242
---------
242243

243244
The WLLVM tools can show various levels of output to aid with debugging.
244-
To show this output set WLLVM_OUTPUT to one of the following levels:
245+
To show this output set the `WLLVM_OUTPUT_LEVEL` environment
246+
variable to one of the following levels:
245247

246-
* `CRITICAL`
247248
* `ERROR`
248249
* `WARNING`
249250
* `INFO`
250251
* `DEBUG`
251252

252-
For example
253+
For example:
254+
```
255+
export WLLVM_OUTPUT_LEVEL=DEBUG
256+
```
257+
Output will be directed to the standard error stream, unless you specify the
258+
path of a logfile via the `WLLVM_OUTPUT_FILE` environment variable.
253259

254-
export WLLVM_OUTPUT=DEBUG
260+
For example:
261+
```
262+
export WLLVM_OUTPUT_FILE=/tmp/wllvm.log
263+
```
255264

256265

257266
Sanity Checking

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
description='Whole Program LLVM',
2121
long_description=long_description,
2222
url='https://github.com/SRI-CSL/whole-program-llvm',
23-
author='Ian A. Mason, Tristan Ravitch, Dan Liew, Bruno Dutertre, Benjamin Schubert, Berkeley Churchill, Marko Dimjasevic, Will Dietz, Fabian Mager, Ben Liblit, Andrew Santosa, Tomas Kalibera, Loic Gelle.',
23+
author='Ian A. Mason, Tristan Ravitch, Dan Liew, Bruno Dutertre, Benjamin Schubert, Berkeley Churchill, Marko Dimjasevic, Will Dietz, Fabian Mager, Ben Liblit, Andrew Santosa, Tomas Kalibera, Loic Gelle, Joshua Cranmer.',
2424
author_email='iam@csl.sri.com',
2525

2626

wllvm/arglistfilter.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class ArgumentListFilter(object):
3131
def __init__(self, inputList, exactMatches={}, patternMatches={}):
3232
defaultArgExactMatches = {
3333

34+
'-' : (0, ArgumentListFilter.standardInCallback),
35+
3436
'-o' : (1, ArgumentListFilter.outputFileCallback),
3537
'-c' : (0, ArgumentListFilter.compileOnlyCallback),
3638
'-E' : (0, ArgumentListFilter.preprocessOnlyCallback),
@@ -122,6 +124,14 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
122124
# Language
123125
'-ansi' : (0, ArgumentListFilter.compileUnaryCallback),
124126
'-pedantic' : (0, ArgumentListFilter.compileUnaryCallback),
127+
#iam: i notice that yices configure passes -xc so
128+
# we should have a fall back pattern that captures the case
129+
# when there is no space between the x and the langauge.
130+
# for what its worth: the manual says the language can be one of
131+
# c objective-c c++ c-header cpp-output c++-cpp-output
132+
# assembler assembler-with-cpp
133+
# BD: care to comment on your configure?
134+
125135
'-x' : (1, ArgumentListFilter.compileBinaryCallback),
126136

127137
# Debug
@@ -235,6 +245,8 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
235245
r'^--sysroot=.+$' : (0, ArgumentListFilter.compileUnaryCallback),
236246
r'^-print-prog-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
237247
r'^-print-file-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
248+
#iam: -xc from yices. why BD?
249+
r'^-x.+$' : (0, ArgumentListFilter.compileUnaryCallback),
238250

239251
}
240252

@@ -256,7 +268,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
256268
self.isAssembly = False
257269
self.isCompileOnly = False
258270
self.isEmitLLVM = False
259-
271+
self.isStandardIn = False
260272

261273
argExactMatches = dict(defaultArgExactMatches)
262274
argExactMatches.update(exactMatches)
@@ -297,6 +309,16 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
297309
if DUMPING:
298310
self.dump()
299311

312+
313+
def skipBitcodeGeneration(self):
314+
if os.environ.get('WLLVM_CONFIGURE_ONLY', False):
315+
return True
316+
if not self.inputFiles or self.isEmitLLVM or self.isAssembly or self.isAssembleOnly:
317+
return True
318+
if self.isPreprocessOnly or self.isStandardIn or (self.isDependencyOnly and not self.isCompileOnly):
319+
return True
320+
return False
321+
300322
def _shiftArgs(self, nargs):
301323
ret = []
302324
while nargs > 0:
@@ -305,6 +327,11 @@ def _shiftArgs(self, nargs):
305327
nargs = nargs - 1
306328
return ret
307329

330+
331+
def standardInCallback(self, flag):
332+
_logger.debug('standardInCallback: %s', flag)
333+
self.isStandardIn = True
334+
308335
def abortUnaryCallback(self, flag):
309336
_logger.warning('Out of context experience: "%s" "%s"', str(self.inputList), flag)
310337
sys.exit(1)

wllvm/compilers.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# Internal logger
1818
_logger = logConfig(__name__)
1919

20-
2120
def wcompile(mode):
2221
""" The workhorse, called from wllvm and wllvm++.
2322
"""
@@ -28,13 +27,29 @@ def wcompile(mode):
2827
cmd = list(sys.argv)
2928
cmd = cmd[1:]
3029
builder = getBuilder(cmd, mode)
30+
31+
af = builder.getBitcodeArglistFilter()
32+
3133
rc = buildObject(builder)
3234

33-
if rc == 0 and not os.environ.get('WLLVM_CONFIGURE_ONLY', False):
34-
buildAndAttachBitcode(builder)
35+
# phase one compile failed. no point continuing
36+
if rc != 0:
37+
_logger.info('phase one failed: %s', str(sys.argv))
38+
return rc
39+
40+
# no need to generate bitcode (e.g. configure only, assembly, ....)
41+
if af.skipBitcodeGeneration():
42+
_logger.info('No work to do')
43+
_logger.debug(af.__dict__)
44+
return rc
45+
46+
# phase two
47+
buildAndAttachBitcode(builder, af)
48+
3549
except Exception as e:
36-
_logger.debug('%s: exception case: %s', mode, str(e))
50+
_logger.warning('%s: exception case: %s', mode, str(e))
3751

52+
_logger.info('Calling %s returned %d', list(sys.argv), rc)
3853
return rc
3954

4055

@@ -134,6 +149,7 @@ def attachBitcodePathToObject(bcPath, outFileName):
134149

135150
class BuilderBase(object):
136151
def __init__(self, cmd, mode, prefixPath=None):
152+
self.af = None #memoize the arglist filter
137153
self.cmd = cmd
138154
self.mode = mode
139155

@@ -169,7 +185,9 @@ def getCompiler(self):
169185
return ['{0}{1}'.format(self.prefixPath, os.getenv(env) or prog)]
170186

171187
def getBitcodeArglistFilter(self):
172-
return ClangBitcodeArgumentListFilter(self.cmd)
188+
if self.af is None:
189+
self.af = ClangBitcodeArgumentListFilter(self.cmd)
190+
return self.af
173191

174192
class DragoneggBuilder(BuilderBase):
175193
def getBitcodeCompiler(self):
@@ -198,15 +216,17 @@ def getCompiler(self):
198216
return ['{0}{1}{2}'.format(self.prefixPath, pfx, mode)]
199217

200218
def getBitcodeArglistFilter(self):
201-
return ArgumentListFilter(self.cmd)
219+
if self.af is None:
220+
self.af = ArgumentListFilter(self.cmd)
221+
return self.af
202222

203223
def getBuilder(cmd, mode):
204224
compilerEnv = 'LLVM_COMPILER'
205225
cstring = os.getenv(compilerEnv)
206226
pathPrefix = os.getenv(llvmCompilerPathEnv) # Optional
207-
_logger.info('WLLVM compiler using %s', cstring)
227+
_logger.debug('WLLVM compiler using %s', cstring)
208228
if pathPrefix:
209-
_logger.info('WLLVM compiler path prefix "%s"', pathPrefix)
229+
_logger.debug('WLLVM compiler path prefix "%s"', pathPrefix)
210230

211231
if cstring == 'clang':
212232
return ClangBuilder(cmd, mode, pathPrefix)
@@ -231,14 +251,7 @@ def buildObject(builder):
231251

232252

233253
# This command does not have the executable with it
234-
def buildAndAttachBitcode(builder):
235-
236-
af = builder.getBitcodeArglistFilter()
237-
238-
if not af.inputFiles or af.isEmitLLVM or af.isAssembly or af.isAssembleOnly or (af.isDependencyOnly and not af.isCompileOnly) or af.isPreprocessOnly:
239-
_logger.debug('No work to do')
240-
_logger.debug(af.__dict__)
241-
return
254+
def buildAndAttachBitcode(builder, af):
242255

243256
#iam: when we have multiple input files we'll have to keep track of their object files.
244257
newObjectFiles = []

wllvm/extraction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import tempfile
99
import shutil
1010
import argparse
11-
import hashlib
1211

1312
from .popenwrapper import Popen
1413

wllvm/logconfig.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,33 @@
77
import os
88
import sys
99

10-
_loggingEnv = 'WLLVM_OUTPUT'
10+
# iam: 6/30/2017 decided to move to a gllvm style where we can set the level and the output file
11+
_loggingEnvLevel_old = 'WLLVM_OUTPUT'
12+
_loggingEnvLevel_new = 'WLLVM_OUTPUT_LEVEL'
1113

12-
_validLogLevels = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']
14+
_loggingDestination = 'WLLVM_OUTPUT_FILE'
15+
16+
_validLogLevels = ['ERROR', 'WARNING', 'INFO', 'DEBUG']
1317

1418
def logConfig(name):
1519

16-
logging.basicConfig(level=logging.WARNING, format='%(levelname)s:%(message)s')
20+
destination = os.getenv(_loggingDestination)
21+
22+
if destination:
23+
logging.basicConfig(filename=destination, level=logging.WARNING, format='%(levelname)s:%(message)s')
24+
else:
25+
logging.basicConfig(level=logging.WARNING, format='%(levelname)s:%(message)s')
1726

1827
retval = logging.getLogger(name)
1928

20-
level = os.getenv(_loggingEnv)
29+
# ignore old setting
30+
level = os.getenv(_loggingEnvLevel_new)
2131

2232
if level:
2333
level = level.upper()
2434
if not level in _validLogLevels:
25-
logging.error('"%s" is not a valid value for %s. Valid values are %s',
26-
level, _loggingEnv, _validLogLevels)
35+
logging.error('"%s" is not a valid value for %s or %s. Valid values are %s',
36+
level, _loggingEnvLevel_old, _loggingEnvLevel_new, _validLogLevels)
2737
sys.exit(1)
2838
else:
2939
retval.setLevel(getattr(logging, level))

wllvm/version.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
5555
1.1.2 - 4/26/2017 encoding issues with hashlib in the python 3 swarm.
5656
57+
1.1.3 - 5/20/2017 fortran support via flang (pull #60 over at travitch's place)
58+
59+
1.1.4 - 7/24/2017 improvements motivated by gllvm and logic.
60+
61+
5762
"""
5863

59-
wllvm_version = '1.1.2'
64+
wllvm_version = '1.1.4'

0 commit comments

Comments
 (0)