Skip to content

Commit 0574afe

Browse files
committed
Initial implementation of idea to handle -emit-llvm.
1 parent d5640a1 commit 0574afe

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

test/test_files/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ zero_e:
99
${CXX} hello.bc -o hello
1010

1111

12+
e:
13+
${CC} -emit-llvm foo.c -c
14+
${CC} -emit-llvm bar.c -c
15+
${CC} -emit-llvm baz.c -c
16+
${CC} -emit-llvm main.c -c
17+
${CC} foo.bc bar.bc baz.bc main.bc -o main
18+
1219

1320
one:
1421
${CC} foo.c bar.c baz.c main.c -o main
@@ -59,4 +66,3 @@ mystery:
5966
otool -X -s __WLLVM __llvm_bc main > main.otool
6067
xxd -r main.otool
6168
xxd -r main.otool main.xxd
62-

wllvm/arglistfilter.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
5050

5151

5252
#iam: if this happens, then we need to stop and think.
53-
'-emit-llvm' : (0, ArgumentListFilter.abortUnaryCallback),
53+
'-emit-llvm' : (0, ArgumentListFilter.emitLLVMCallback),
5454

5555
#iam: buildworld and buildkernel use these flags
5656
'-pipe' : (0, ArgumentListFilter.compileUnaryCallback),
@@ -212,7 +212,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
212212
# - optimiziation and other flags: -f...
213213
#
214214
defaultArgPatterns = {
215-
r'^.+\.(c|cc|cpp|C|cxx|i|s|S)$' : (0, ArgumentListFilter.inputFileCallback),
215+
r'^.+\.(c|cc|cpp|C|cxx|i|s|S|bc)$' : (0, ArgumentListFilter.inputFileCallback),
216216
#iam: the object file recogition is not really very robust, object files
217217
# should be determined by their existance and contents...
218218
r'^.+\.(o|lo|So|so|po|a|dylib)$' : (0, ArgumentListFilter.objectFileCallback),
@@ -252,6 +252,8 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
252252
self.isAssembleOnly = False
253253
self.isAssembly = False
254254
self.isCompileOnly = False
255+
self.isEmitLLVM = False
256+
255257

256258
argExactMatches = dict(defaultArgExactMatches)
257259
argExactMatches.update(exactMatches)
@@ -339,6 +341,11 @@ def compileOnlyCallback(self, flag):
339341
_logger.debug('compileOnlyCallback: %s', flag)
340342
self.isCompileOnly = True
341343

344+
def emitLLVMCallback(self, flag):
345+
_logger.debug('emitLLVMCallback: %s', flag)
346+
self.isEmitLLVM = True
347+
self.isCompileOnly = True
348+
342349
def linkUnaryCallback(self, flag):
343350
_logger.debug('linkUnaryCallback: %s', flag)
344351
self.linkArgs.append(flag)

wllvm/compilers.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ def wcompile(isCXX):
2828
builder = getBuilder(cmd, isCXX)
2929
rc = buildObject(builder)
3030

31-
3231
if rc == 0 and not os.environ.get('WLLVM_CONFIGURE_ONLY', False):
3332
buildAndAttachBitcode(builder)
3433
except Exception as e:
35-
_logger.debug('wllvm++: exception case: %s', str(e))
34+
_logger.debug('%s: exception case: %s', "wllvm++" if isCXX else "wllvm", str(e))
3635

3736
return rc
3837

@@ -252,7 +251,7 @@ def buildAndAttachBitcode(builder):
252251

253252
af = builder.getBitcodeArglistFilter()
254253

255-
if len(af.inputFiles) == 0 or af.isAssembly or af.isAssembleOnly or (af.isDependencyOnly and not af.isCompileOnly) or af.isPreprocessOnly:
254+
if len(af.inputFiles) == 0 or af.isEmitLLVM or af.isAssembly or af.isAssembleOnly or (af.isDependencyOnly and not af.isCompileOnly) or af.isPreprocessOnly:
256255
_logger.debug('No work to do')
257256
_logger.debug(af.__dict__)
258257
return
@@ -281,12 +280,19 @@ def buildAndAttachBitcode(builder):
281280
else:
282281

283282
for srcFile in af.inputFiles:
283+
_logger.debug('Not compile only case: %s', srcFile)
284284
(objFile, bcFile) = af.getArtifactNames(srcFile, hidden)
285285
if hidden:
286286
buildObjectFile(builder, srcFile, objFile)
287287
newObjectFiles.append(objFile)
288-
buildBitcodeFile(builder, srcFile, bcFile)
289-
attachBitcodePathToObject(bcFile, objFile)
288+
289+
if srcFile.endswith('.bc'):
290+
_logger.debug('attaching %s to %s', srcFile, objFile)
291+
attachBitcodePathToObject(srcFile, objFile)
292+
else:
293+
_logger.debug('building and attaching %s to %s', bcFile, objFile)
294+
buildBitcodeFile(builder, srcFile, bcFile)
295+
attachBitcodePathToObject(bcFile, objFile)
290296

291297

292298
if not af.isCompileOnly:

0 commit comments

Comments
 (0)