|
58 | 58 | JS_CONTAINING_SUFFIXES = ('js', 'html')
|
59 | 59 | EXECUTABLE_SUFFIXES = JS_CONTAINING_SUFFIXES + ('wasm',)
|
60 | 60 |
|
| 61 | +EXPLICIT_OUTPUT_TYPES = ('js', 'html', 'bc') |
| 62 | + |
61 | 63 | DEFERRED_REPONSE_FILES = ('EMTERPRETIFY_BLACKLIST', 'EMTERPRETIFY_WHITELIST')
|
62 | 64 |
|
63 | 65 | # Mapping of emcc opt levels to llvm opt levels. We use llvm opt level 3 in emcc opt
|
@@ -165,6 +167,7 @@ def __init__(self):
|
165 | 167 | # Specifies the line ending format to use for all generated text files.
|
166 | 168 | # Defaults to using the native EOL on each platform (\r\n on Windows, \n on Linux&OSX)
|
167 | 169 | self.output_eol = os.linesep
|
| 170 | + self.force_output_type = None |
168 | 171 |
|
169 | 172 |
|
170 | 173 | class JSOptimizer(object):
|
@@ -542,11 +545,6 @@ def uniquename(name):
|
542 | 545 | target = specified_target if specified_target is not None else 'a.out.js' # specified_target is the user-specified one, target is what we will generate
|
543 | 546 | target_basename = unsuffixed_basename(target)
|
544 | 547 |
|
545 |
| - if '.' in target: |
546 |
| - final_suffix = target.split('.')[-1] |
547 |
| - else: |
548 |
| - final_suffix = '' |
549 |
| - |
550 | 548 | if TEMP_DIR:
|
551 | 549 | temp_dir = TEMP_DIR
|
552 | 550 | if os.path.exists(temp_dir):
|
@@ -777,24 +775,37 @@ def detect_fixed_language_mode(args):
|
777 | 775 |
|
778 | 776 | newargs = [arg for arg in newargs if arg is not '']
|
779 | 777 |
|
| 778 | + final_suffix = None |
780 | 779 | # -c means do not link in gcc, and for us, the parallel is to not go all the way to JS, but stop at bitcode
|
781 | 780 | has_dash_c = '-c' in newargs
|
782 | 781 | if has_dash_c:
|
783 | 782 | assert has_source_inputs or has_header_inputs, 'Must have source code or header inputs to use -c'
|
784 |
| - target = target_basename + '.o' |
| 783 | + if specified_target == None: |
| 784 | + target = target_basename + '.o' |
785 | 785 | final_suffix = 'o'
|
786 | 786 | if '-E' in newargs:
|
787 | 787 | final_suffix = 'eout' # not bitcode, not js; but just result from preprocessing stage of the input file
|
788 | 788 | if '-M' in newargs or '-MM' in newargs:
|
789 | 789 | final_suffix = 'mout' # not bitcode, not js; but just dependency rule of the input file
|
| 790 | + |
| 791 | + if final_suffix == None: |
| 792 | + if options.force_output_type != None: |
| 793 | + final_suffix = options.force_output_type |
| 794 | + else: |
| 795 | + final_suffix = suffix(target) |
| 796 | + if final_suffix == None: |
| 797 | + final_suffix = '' # generate bitcode by default |
| 798 | + |
790 | 799 | final_ending = ('.' + final_suffix) if len(final_suffix) > 0 else ''
|
791 | 800 |
|
| 801 | + target_unsuffixed = unsuffixed(target) |
| 802 | + |
792 | 803 | # target is now finalized, can finalize other _target s
|
793 |
| - js_target = unsuffixed(target) + '.js' |
| 804 | + js_target = target if options.force_output_type == 'js' else target_unsuffixed + '.js' |
794 | 805 |
|
795 |
| - asm_target = unsuffixed(js_target) + '.asm.js' # might not be used, but if it is, this is the name |
796 |
| - wasm_text_target = asm_target.replace('.asm.js', '.wast') # ditto, might not be used |
797 |
| - wasm_binary_target = asm_target.replace('.asm.js', '.wasm') # ditto, might not be used |
| 806 | + asm_target = target_unsuffixed + '.asm.js' # might not be used, but if it is, this is the name |
| 807 | + wasm_text_target = target_unsuffixed + '.wast' # ditto, might not be used |
| 808 | + wasm_binary_target = target_unsuffixed + '.wasm' # ditto, might not be used |
798 | 809 |
|
799 | 810 | if final_suffix == 'html' and not options.separate_asm and ('PRECISE_F32=2' in settings_changes or 'USE_PTHREADS=2' in settings_changes):
|
800 | 811 | options.separate_asm = True
|
@@ -2102,6 +2113,14 @@ def parse_args(newargs):
|
2102 | 2113 | exit(1)
|
2103 | 2114 | newargs[i] = ''
|
2104 | 2115 | newargs[i+1] = ''
|
| 2116 | + elif newargs[i] == '--force-output-type': |
| 2117 | + if newargs[i+1] in EXPLICIT_OUTPUT_TYPES: |
| 2118 | + options.force_output_type = newargs[i+1] |
| 2119 | + else: |
| 2120 | + logging.error('Invalid value "' + newargs[i+1] + '" to --force-output-type') |
| 2121 | + exit(1) |
| 2122 | + newargs[i] = '' |
| 2123 | + newargs[i+1] = '' |
2105 | 2124 |
|
2106 | 2125 | if should_exit:
|
2107 | 2126 | sys.exit(0)
|
|
0 commit comments