Skip to content

Commit ad86263

Browse files
committed
Merge pull request #6 from delcypher/fixes
Mostly fixes for "as"
2 parents e2f5a7b + 4d604b6 commit ad86263

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

driver/as

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import sys
1515
from utils import *
1616
from subprocess import *
1717
from popenwrapper import Popen
18+
import logconfig
1819

1920

2021
class BCFilter(ArgumentListFilter):
@@ -31,18 +32,30 @@ argFilter = BCFilter(sys.argv[1:])
3132
try:
3233
[infile] = argFilter.inputFiles
3334
except ValueError:
35+
logging.debug('Input file argument not detected, assuming stdin.')
3436
infile = "-"
3537

38+
# set llvm-as
39+
llvmAssembler='llvm-as'
40+
if os.getenv(llvmCompilerPathEnv):
41+
llvmAssembler = os.path.join(os.getenv(llvmCompilerPathEnv), llvmAssembler)
42+
3643
# Now compile this llvm assembly file into a bitcode file. The output
3744
# filename is the same as the object with a .bc appended
38-
(dirs, filename) = os.path.split(argFilter.outFileName)
45+
try:
46+
(dirs, filename) = os.path.split(argFilter.outFileName)
47+
except AttributeError as e:
48+
logging.error('Output file argument not found.\nException message: ' + str(e))
49+
sys.exit(1)
50+
3951
bcfilename = '.{0}.bc'.format(filename)
4052
bcPath = os.path.join(dirs, bcfilename)
41-
fakeAssembler = ['llvm-as', infile, '-o', bcPath]
42-
asmProc = subprocess.Popen(fakeAssembler)
53+
fakeAssembler = [llvmAssembler, infile, '-o', bcPath]
54+
asmProc = Popen(fakeAssembler)
4355
realRet = asmProc.wait()
4456

4557
if realRet != 0:
58+
logging.error('llvm-as failed')
4659
sys.exit(realRet)
4760

4861
attachBitcodePathToObject(bcPath, argFilter.outFileName)

driver/utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,27 @@
77
import re
88
import sys
99
import tempfile
10-
from driver.popenwrapper import Popen
1110

1211
fullSelfPath = os.path.realpath(__file__)
1312
prefix = os.path.dirname(fullSelfPath)
1413
driverDir = prefix
1514

15+
# This is a bit hacky.
16+
# We cannot do
17+
# from .popenwrapper import Popen
18+
# OR
19+
# from driver.popenwrapper import Popen
20+
# because then 'as' will not succesfully import us (wllvm/wllvm++ can
21+
# successfully import however).
22+
#
23+
# Using
24+
# from popenwrapper import Popen
25+
# will allow 'as' to import us but then wllvm/wllvm++ will not be able to.
26+
#
27+
# The work around is to put this directory in the search path for modules.
28+
sys.path.insert(0,driverDir)
29+
from popenwrapper import Popen
30+
1631
# Environmental variable for path to compiler tools (clang/llvm-link etc..)
1732
llvmCompilerPathEnv = 'LLVM_COMPILER_PATH'
1833

@@ -229,6 +244,7 @@ def attachBitcodePathToObject(bcPath, outFileName):
229244
# that won't work.
230245
(root, ext) = os.path.splitext(outFileName)
231246
if ext not in ('.o', '.lo', '.os'):
247+
_logger.warning('Cannot attach bitcode path to "{0}"'.format(outFileName))
232248
return
233249

234250
# Now just build a temporary text file with the full path to the
@@ -327,6 +343,9 @@ def __init__(self, cmd, isCxx, prefixPath=None):
327343
def getBitcodeCompiler(self):
328344
pth = os.getenv('LLVM_DRAGONEGG_PLUGIN')
329345
cc = self.getCompiler()
346+
# We use '-B' to tell gcc where to look for an assembler.
347+
# When we build LLVM bitcode we do not want to use the GNU assembler,
348+
# instead we want gcc to use our own assembler (see driver/as).
330349
return cc + ['-B', driverDir, '-fplugin={0}'.format(pth),
331350
'-fplugin-arg-dragonegg-emit-ir']
332351

0 commit comments

Comments
 (0)