4
4
import json
5
5
from .utils import temporary_file , try_command , temporary_directory
6
6
from .versions import RUST_VERSION
7
+ from .versions import LLVM_SHORT_VERSION
7
8
8
9
# Needed for cargo operations
9
10
try :
@@ -85,8 +86,19 @@ def smack_lib():
85
86
return os .path .join (smack_root (), 'share' , 'smack' , 'lib' )
86
87
87
88
89
+ def llvm_exact_bin (name ):
90
+ return name + '-' + LLVM_SHORT_VERSION
91
+
92
+
88
93
def default_clang_compile_command (args , lib = False ):
89
- cmd = ['clang' , '-c' , '-emit-llvm' , '-O0' , '-g' , '-gcolumn-info' ]
94
+ cmd = [
95
+ llvm_exact_bin ('clang' ),
96
+ '-c' ,
97
+ '-emit-llvm' ,
98
+ '-O0' ,
99
+ '-g' ,
100
+ '-gcolumn-info'
101
+ ]
90
102
# Starting from LLVM 5.0, we need the following two options
91
103
# in order to enable optimization passes.
92
104
# See: https://stackoverflow.com/a/46753969.
@@ -165,7 +177,7 @@ def fortran_compile_to_bc(input_file, compile_command, args):
165
177
'-i' ,
166
178
's/i32 1, !\" Debug Info Version\" /i32 2, !\" Debug Info Version\" /g' ,
167
179
ll ])
168
- try_command (['llvm-as' , ll ])
180
+ try_command ([llvm_exact_bin ( 'llvm-as' ) , ll ])
169
181
try_command (['rm' , ll ])
170
182
bc = '.' .join (ll .split ('.' )[:- 1 ] + ['bc' ])
171
183
return bc
@@ -189,7 +201,7 @@ def clang_frontend(input_file, args):
189
201
def clang_plusplus_frontend (input_file , args ):
190
202
"""Generate LLVM IR from C++ language source(s)."""
191
203
compile_command = default_clang_compile_command (args )
192
- compile_command [0 ] = 'clang++'
204
+ compile_command [0 ] = llvm_exact_bin ( 'clang++' )
193
205
return compile_to_bc (input_file , compile_command , args )
194
206
195
207
@@ -263,9 +275,17 @@ def json_compilation_database_frontend(input_file, args):
263
275
if 'objects' in cc :
264
276
# TODO what to do when there are multiple linkings?
265
277
bit_codes = [re .sub ('[.]o$' , '.bc' , f ) for f in cc ['objects' ]]
266
- try_command (['llvm-link' , '-o' , args .bc_file ] + bit_codes )
267
- try_command (['llvm-link' , '-o' , args .linked_bc_file ,
268
- args .bc_file ] + default_build_libs (args ))
278
+ try_command ([
279
+ llvm_exact_bin ('llvm-link' ),
280
+ '-o' ,
281
+ args .bc_file
282
+ ] + bit_codes )
283
+ try_command ([
284
+ llvm_exact_bin ('llvm-link' ),
285
+ '-o' ,
286
+ args .linked_bc_file ,
287
+ args .bc_file
288
+ ] + default_build_libs (args ))
269
289
270
290
else :
271
291
command = cc ['command' ]
@@ -316,7 +336,7 @@ def cargo_frontend(input_file, args):
316
336
os .path .basename (input_file ))[0 ],
317
337
'.bc' ,
318
338
args )
319
- try_command (['llvm-link' ] + bcs + ['-o' , bc_file ])
339
+ try_command ([llvm_exact_bin ( 'llvm-link' ) ] + bcs + ['-o' , bc_file ])
320
340
return bc_file
321
341
322
342
@@ -410,7 +430,7 @@ def cplusplus_build_libs(args):
410
430
libs = ['smack.cpp' ]
411
431
412
432
compile_command = default_clang_compile_command (args , True )
413
- compile_command [0 ] = 'clang++'
433
+ compile_command [0 ] = llvm_exact_bin ( 'clang++' )
414
434
415
435
for c in [os .path .join (smack_lib (), c ) for c in libs ]:
416
436
bc = compile_to_bc (c , compile_command , args )
@@ -443,8 +463,8 @@ def link_bc_files(bitcodes, libs, args):
443
463
for build_lib in libs :
444
464
smack_libs += build_lib (args )
445
465
446
- try_command (['llvm-link' , '-o' , args .bc_file ] + bitcodes )
447
- try_command (['llvm-link' , '-o' , args .linked_bc_file ,
466
+ try_command ([llvm_exact_bin ( 'llvm-link' ) , '-o' , args .bc_file ] + bitcodes )
467
+ try_command ([llvm_exact_bin ( 'llvm-link' ) , '-o' , args .linked_bc_file ,
448
468
args .bc_file ] + smack_libs )
449
469
450
470
# import here to avoid a circular import
0 commit comments