@@ -139,18 +139,18 @@ def extract_section_linux(inputFile):
139
139
return contents
140
140
141
141
142
- def handleExecutable (inputFile , outputFile , extractor , llvmLinker ):
142
+ def handleExecutable (inputFile , outputFile , extractor , llvmLinker , manifestFlag ):
143
143
144
144
fileNames = extractor (inputFile )
145
145
146
146
if not fileNames :
147
147
return 1
148
-
149
- manifestFile = '{0}.occcam.manifest' .format (inputFile )
150
148
151
- with open (manifestFile , 'w' ) as output :
152
- for f in fileNames :
153
- output .write ('{0}\n ' .format (f ))
149
+ if manifestFlag :
150
+ manifestFile = '{0}.occcam.manifest' .format (inputFile )
151
+ with open (manifestFile , 'w' ) as output :
152
+ for f in fileNames :
153
+ output .write ('{0}\n ' .format (f ))
154
154
155
155
if outputFile == None :
156
156
outputFile = inputFile + '.' + moduleExtension
@@ -179,7 +179,7 @@ def handleExecutable(inputFile, outputFile, extractor, llvmLinker):
179
179
180
180
181
181
182
- def handleArchive (inputFile , outputFile , arCmd , fileType , extractor , llvmArchiver ):
182
+ def handleArchive (inputFile , outputFile , arCmd , fileType , extractor , llvmArchiver , manifestFlag ):
183
183
inputFile = os .path .abspath (inputFile )
184
184
originalDir = os .getcwd () # This will be the destination
185
185
@@ -237,6 +237,13 @@ def handleArchive(inputFile, outputFile, arCmd, fileType, extractor, llvmArchive
237
237
# Delete the temporary folder
238
238
logging .debug ('Deleting temporary folder "{0}"' .format (tempDir ))
239
239
shutil .rmtree (tempDir )
240
+
241
+ #write the manifest file if asked for
242
+ if manifestFlag :
243
+ manifestFile = '{0}.occcam.manifest' .format (inputFile )
244
+ with open (manifestFile , 'w' ) as output :
245
+ for f in bitCodeFiles :
246
+ output .write ('{0}\n ' .format (f ))
240
247
241
248
# Build bitcode archive
242
249
os .chdir (originalDir )
@@ -325,6 +332,9 @@ def extract_bc_args(args):
325
332
parser .add_argument ("--verbose" ,"-v" ,
326
333
help = 'Call the external procedures in verbose mode.' ,
327
334
action = "store_true" )
335
+ parser .add_argument ("--manifest" ,"-m" ,
336
+ help = 'Write a manifest file listing all the .bc files used.' ,
337
+ action = "store_true" )
328
338
parser .add_argument ("--output" ,"-o" ,
329
339
help = 'The output file. Defaults to a file in the same directory ' +
330
340
'as the input with the same name as the input but with an ' +
@@ -337,11 +347,12 @@ def extract_bc_args(args):
337
347
llvmLinker = parsedArgs .linker
338
348
llvmArchiver = parsedArgs .archiver
339
349
verboseFlag = parsedArgs .verbose
340
-
350
+ manifestFlag = parsedArgs .manifest
351
+
341
352
# Check file exists
342
353
if not os .path .exists (inputFile ):
343
354
logging .error ('File "{0}" does not exist.' .format (inputFile ))
344
- return (False , inputFile , '' , llvmLinker , llvmArchiver )
355
+ return (False , inputFile , '' , llvmLinker , llvmArchiver , manifestFlag )
345
356
346
357
# Check output destitionation if set
347
358
outputFile = parsedArgs .output
@@ -351,34 +362,34 @@ def extract_bc_args(args):
351
362
if not os .path .exists (os .path .dirname (outputFile )):
352
363
logging .error ('Output directory "{0}" does not exist.' .format (
353
364
os .path .dirname (outputFile )))
354
- return (False , inputFile , '' , llvmLinker , llvmArchiver )
365
+ return (False , inputFile , '' , llvmLinker , llvmArchiver , manifestFlag )
355
366
356
- return (True , inputFile , outputFile , llvmLinker , llvmArchiver )
367
+ return (True , inputFile , outputFile , llvmLinker , llvmArchiver , manifestFlag )
357
368
358
369
359
370
def main (args ):
360
371
361
- (success , inputFile , outputFile , llvmLinker , llvmArchiver ) = extract_bc_args (args )
372
+ (success , inputFile , outputFile , llvmLinker , llvmArchiver , manifestFlag ) = extract_bc_args (args )
362
373
363
374
if not success :
364
375
return 1
365
376
366
377
if ( sys .platform .startswith ('freebsd' ) or
367
378
sys .platform .startswith ('linux' ) ):
368
379
369
- process_file_unix (inputFile , outputFile , llvmLinker , llvmArchiver )
380
+ process_file_unix (inputFile , outputFile , llvmLinker , llvmArchiver , manifestFlag )
370
381
371
382
elif sys .platform .startswith ('darwin' ):
372
383
373
- process_file_darwin (inputFile , outputFile , llvmLinker , llvmArchiver )
384
+ process_file_darwin (inputFile , outputFile , llvmLinker , llvmArchiver , manifestFlag )
374
385
375
386
else :
376
387
#iam: do we work on anything else?
377
388
logging .error ('Unsupported or unrecognized platform: {0}' .format (sys .platform ))
378
389
return 1
379
390
380
391
381
- def process_file_unix (inputFile , outputFile , llvmLinker , llvmArchiver ):
392
+ def process_file_unix (inputFile , outputFile , llvmLinker , llvmArchiver , manifestFlag ):
382
393
ft = FileType .getFileType (inputFile )
383
394
logging .debug ('Detected file type is {0}' .format (FileType .revMap [ft ]))
384
395
@@ -388,17 +399,17 @@ def process_file_unix(inputFile, outputFile, llvmLinker, llvmArchiver):
388
399
389
400
if ft == FileType .ELF_EXECUTABLE or ft == FileType .ELF_SHARED or ft == FileType .ELF_OBJECT :
390
401
logging .info ('Generating LLVM Bitcode module' )
391
- return handleExecutable (inputFile , outputFile , extractor , llvmLinker )
402
+ return handleExecutable (inputFile , outputFile , extractor , llvmLinker , manifestFlag )
392
403
elif ft == FileType .ARCHIVE :
393
404
logging .info ('Generating LLVM Bitcode archive' )
394
- return handleArchive (inputFile , outputFile , arCmd , ofileType , extractor , llvmArchiver )
405
+ return handleArchive (inputFile , outputFile , arCmd , ofileType , extractor , llvmArchiver , manifestFlag )
395
406
else :
396
407
logging .error ('File "{0}" of type {1} cannot be used' .format (inputFile ,FileType .revMap [ft ]))
397
408
return 1
398
409
399
410
400
411
401
- def process_file_darwin (inputFile , outputFile , llvmLinker , llvmArchiver ):
412
+ def process_file_darwin (inputFile , outputFile , llvmLinker , llvmArchiver , manifestFlag ):
402
413
ft = FileType .getFileType (inputFile )
403
414
logging .debug ('Detected file type is {0}' .format (FileType .revMap [ft ]))
404
415
@@ -408,10 +419,10 @@ def process_file_darwin(inputFile, outputFile, llvmLinker, llvmArchiver):
408
419
409
420
if ft == FileType .MACH_EXECUTABLE or ft == FileType .MACH_SHARED or ft == FileType .MACH_OBJECT :
410
421
logging .info ('Generating LLVM Bitcode module' )
411
- return handleExecutable (inputFile , outputFile , extractor , llvmLinker )
422
+ return handleExecutable (inputFile , outputFile , extractor , llvmLinker , manifestFlag )
412
423
elif ft == FileType .ARCHIVE :
413
424
logging .info ('Generating LLVM Bitcode archive' )
414
- return handleArchive (inputFile , outputFile , arCmd , ofileType , extractor , llvmArchiver )
425
+ return handleArchive (inputFile , outputFile , arCmd , ofileType , extractor , llvmArchiver , manifestFlag )
415
426
else :
416
427
logging .error ('File "{0}" of type {1} cannot be used' .format (inputFile ,FileType .revMap [ft ]))
417
428
return 1
0 commit comments