Skip to content

Commit 589120d

Browse files
committed
Command line switch to extract a bitcode module from an archive.
1 parent f7d8ae1 commit 589120d

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

extract-bc

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def handleExecutable(pArgs):
208208
return 1
209209

210210
if pArgs.manifestFlag:
211-
manifestFile = '{0}.wllvm.manifest'.format(pArgs.inputFile)
211+
manifestFile = '{0}.llvm.manifest'.format(pArgs.inputFile)
212212
with open(manifestFile, 'w') as output:
213213
for f in fileNames:
214214
output.write('{0}\n'.format(f))
@@ -293,18 +293,30 @@ def handleArchive(pArgs):
293293
return buildArchive(pArgs, bitCodeFiles)
294294

295295
def buildArchive(pArgs, bitCodeFiles):
296-
# Pick output file path if outputFile not set
297-
if pArgs.outputFile == None:
298-
if pArgs.inputFile.endswith('.a'):
299-
# Strip off .a suffix
300-
pArgs.outputFile = pArgs.inputFile[:-2]
301-
else:
302-
pArgs.outputFile = pArgs.inputFile
303-
pArgs.outputFile +='.' + bitCodeArchiveExtension
304296

305-
logging.info('Writing output to {0}'.format(pArgs.outputFile))
297+
if pArgs.bitcodeModuleFlag:
306298

307-
return archiveFiles(pArgs, bitCodeFiles)
299+
# Pick output file path if outputFile not set
300+
if pArgs.outputFile == None:
301+
pArgs.outputFile = pArgs.inputFile
302+
pArgs.outputFile += '.' + moduleExtension
303+
304+
logging.info('Writing output to {0}'.format(pArgs.outputFile))
305+
306+
return linkFiles(pArgs, bitCodeFiles)
307+
308+
else:
309+
310+
# Pick output file path if outputFile not set
311+
if pArgs.outputFile == None:
312+
if pArgs.inputFile.endswith('.a'):
313+
# Strip off .a suffix
314+
pArgs.outputFile = pArgs.inputFile[:-2]
315+
pArgs.outputFile += '.' + bitCodeArchiveExtension
316+
317+
logging.info('Writing output to {0}'.format(pArgs.outputFile))
318+
319+
return archiveFiles(pArgs, bitCodeFiles)
308320

309321

310322
class ExtractedArgs:
@@ -354,9 +366,9 @@ def extract_bc_args(args):
354366
dest='manifestFlag',
355367
help='Write a manifest file listing all the .bc files used.',
356368
action='store_true')
357-
parser.add_argument('--bytecode', '-b',
358-
dest='bytecodeModuleFlag',
359-
help='Extract a bytecode module rather than an archive. ' +
369+
parser.add_argument('--bitcode', '-b',
370+
dest='bitcodeModuleFlag',
371+
help='Extract a bitcode module rather than an archive. ' +
360372
'Only useful when extracting from an archive.',
361373
action='store_true')
362374
parser.add_argument('--output','-o',
@@ -425,7 +437,10 @@ def process_file_unix(pArgs):
425437
logging.info('Generating LLVM Bitcode module')
426438
return handleExecutable(pArgs)
427439
elif ft == FileType.ARCHIVE:
428-
logging.info('Generating LLVM Bitcode archive')
440+
if pArgs.bitcodeModuleFlag:
441+
logging.info('Generating LLVM Bitcode module from an archive')
442+
else:
443+
logging.info('Generating LLVM Bitcode archive from an archive')
429444
return handleArchive(pArgs)
430445
else:
431446
logging.error('File "{0}" of type {1} cannot be used'.format(pArgs.inputFile, FileType.revMap[ft]))
@@ -446,7 +461,10 @@ def process_file_darwin(pArgs):
446461
logging.info('Generating LLVM Bitcode module')
447462
return handleExecutable(pArgs)
448463
elif ft == FileType.ARCHIVE:
449-
logging.info('Generating LLVM Bitcode archive')
464+
if pArgs.bitcodeModuleFlag:
465+
logging.info('Generating LLVM Bitcode module from an archive')
466+
else:
467+
logging.info('Generating LLVM Bitcode archive from an archive')
450468
return handleArchive(pArgs)
451469
else:
452470
logging.error('File "{0}" of type {1} cannot be used'.format(pArgs.inputFile, FileType.revMap[ft]))

0 commit comments

Comments
 (0)