differentiate suffixes from endings in filename_type_ending as well

This commit is contained in:
Alon Zakai 2013-12-24 09:47:20 -08:00
Родитель b1f10031a3
Коммит 48dbd4de6e
1 изменённых файлов: 20 добавлений и 16 удалений

36
emcc
Просмотреть файл

@ -765,9 +765,13 @@ def in_temp(name):
def filename_type_suffix(filename): def filename_type_suffix(filename):
for i in reversed(filename.split('.')[1:]): for i in reversed(filename.split('.')[1:]):
if not i.isdigit(): if not i.isdigit():
return '.' + i return i
return '' return ''
def filename_type_ending(filename):
suffix = filename_type_suffix(filename)
return '' if not suffix else ('.' + suffix)
try: try:
call = CXX if use_cxx else CC call = CXX if use_cxx else CC
@ -1064,15 +1068,15 @@ try:
logging.error(arg + ': No such file or directory') logging.error(arg + ': No such file or directory')
exit(1) exit(1)
arg_suffix = filename_type_suffix(arg) arg_ending = filename_type_ending(arg)
if arg_suffix.endswith(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + ASSEMBLY_ENDINGS) or shared.Building.is_ar(arg): # we already removed -o <target>, so all these should be inputs if arg_ending.endswith(SOURCE_ENDINGS + BITCODE_ENDINGS + DYNAMICLIB_ENDINGS + ASSEMBLY_ENDINGS) or shared.Building.is_ar(arg): # we already removed -o <target>, so all these should be inputs
newargs[i] = '' newargs[i] = ''
if arg_suffix.endswith(SOURCE_ENDINGS): if arg_ending.endswith(SOURCE_ENDINGS):
input_files.append(arg) input_files.append(arg)
has_source_inputs = True has_source_inputs = True
elif arg_suffix.endswith(ASSEMBLY_ENDINGS) or shared.Building.is_bitcode(arg): # this should be bitcode, make sure it is valid elif arg_ending.endswith(ASSEMBLY_ENDINGS) or shared.Building.is_bitcode(arg): # this should be bitcode, make sure it is valid
input_files.append(arg) input_files.append(arg)
elif arg_suffix.endswith(STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS): elif arg_ending.endswith(STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS):
# if it's not, and it's a library, just add it to libs to find later # if it's not, and it's a library, just add it to libs to find later
l = unsuffixed_basename(arg) l = unsuffixed_basename(arg)
for prefix in LIB_PREFIXES: for prefix in LIB_PREFIXES:
@ -1084,7 +1088,7 @@ try:
newargs[i] = '' newargs[i] = ''
else: else:
logging.warning(arg + ' is not valid LLVM bitcode') logging.warning(arg + ' is not valid LLVM bitcode')
elif arg_suffix.endswith(STATICLIB_ENDINGS): elif arg_ending.endswith(STATICLIB_ENDINGS):
if not shared.Building.is_ar(arg): if not shared.Building.is_ar(arg):
if shared.Building.is_bitcode(arg): if shared.Building.is_bitcode(arg):
logging.error(arg + ': File has a suffix of a static library ' + str(STATICLIB_ENDINGS) + ', but instead is an LLVM bitcode file! When linking LLVM bitcode files, use one of the suffixes ' + str(BITCODE_ENDINGS)) logging.error(arg + ': File has a suffix of a static library ' + str(STATICLIB_ENDINGS) + ', but instead is an LLVM bitcode file! When linking LLVM bitcode files, use one of the suffixes ' + str(BITCODE_ENDINGS))
@ -1131,7 +1135,7 @@ try:
# If not compiling to JS, then we are compiling to an intermediate bitcode objects or library, so # If not compiling to JS, then we are compiling to an intermediate bitcode objects or library, so
# ignore dynamic linking, since multiple dynamic linkings can interfere with each other # ignore dynamic linking, since multiple dynamic linkings can interfere with each other
if not filename_type_suffix(target)[1:] in JS_CONTAINING_SUFFIXES or ignore_dynamic_linking: if not filename_type_suffix(target) in JS_CONTAINING_SUFFIXES or ignore_dynamic_linking:
def check(input_file): def check(input_file):
if input_file.endswith(DYNAMICLIB_ENDINGS): if input_file.endswith(DYNAMICLIB_ENDINGS):
if not ignore_dynamic_linking: logging.warning('ignoring dynamic library %s because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end' % os.path.basename(input_file)) if not ignore_dynamic_linking: logging.warning('ignoring dynamic library %s because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end' % os.path.basename(input_file))
@ -1278,14 +1282,14 @@ try:
# First, generate LLVM bitcode. For each input file, we get base.o with bitcode # First, generate LLVM bitcode. For each input file, we get base.o with bitcode
for input_file in input_files: for input_file in input_files:
file_suffix = filename_type_suffix(input_file) file_ending = filename_type_ending(input_file)
if file_suffix.endswith(SOURCE_ENDINGS): if file_ending.endswith(SOURCE_ENDINGS):
logging.debug('compiling source file: ' + input_file) logging.debug('compiling source file: ' + input_file)
input_file = shared.Building.preprocess(input_file, in_temp(uniquename(input_file))) input_file = shared.Building.preprocess(input_file, in_temp(uniquename(input_file)))
output_file = in_temp(unsuffixed(uniquename(input_file)) + '.o') output_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
temp_files.append(output_file) temp_files.append(output_file)
args = newargs + ['-emit-llvm', '-c', input_file, '-o', output_file] args = newargs + ['-emit-llvm', '-c', input_file, '-o', output_file]
if file_suffix.endswith(CXX_ENDINGS): if file_ending.endswith(CXX_ENDINGS):
args += shared.EMSDK_CXX_OPTS args += shared.EMSDK_CXX_OPTS
logging.debug("running: " + call + ' ' + ' '.join(args)) logging.debug("running: " + call + ' ' + ' '.join(args))
execute([call] + args) # let compiler frontend print directly, so colors are saved (PIPE kills that) execute([call] + args) # let compiler frontend print directly, so colors are saved (PIPE kills that)
@ -1293,17 +1297,17 @@ try:
logging.error('compiler frontend failed to generate LLVM bitcode, halting') logging.error('compiler frontend failed to generate LLVM bitcode, halting')
sys.exit(1) sys.exit(1)
else: # bitcode else: # bitcode
if file_suffix.endswith(BITCODE_ENDINGS): if file_ending.endswith(BITCODE_ENDINGS):
logging.debug('copying bitcode file: ' + input_file) logging.debug('copying bitcode file: ' + input_file)
temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o') temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
shutil.copyfile(input_file, temp_file) shutil.copyfile(input_file, temp_file)
temp_files.append(temp_file) temp_files.append(temp_file)
elif file_suffix.endswith(DYNAMICLIB_ENDINGS) or shared.Building.is_ar(input_file): elif file_ending.endswith(DYNAMICLIB_ENDINGS) or shared.Building.is_ar(input_file):
logging.debug('copying library file: ' + input_file) logging.debug('copying library file: ' + input_file)
temp_file = in_temp(uniquename(input_file)) temp_file = in_temp(uniquename(input_file))
shutil.copyfile(input_file, temp_file) shutil.copyfile(input_file, temp_file)
temp_files.append(temp_file) temp_files.append(temp_file)
elif file_suffix.endswith(ASSEMBLY_ENDINGS): elif file_ending.endswith(ASSEMBLY_ENDINGS):
if not LEAVE_INPUTS_RAW: if not LEAVE_INPUTS_RAW:
# Note that by assembling the .ll file, then disassembling it later, we will # Note that by assembling the .ll file, then disassembling it later, we will
# remove annotations which is a good thing for compilation time # remove annotations which is a good thing for compilation time
@ -1321,8 +1325,8 @@ try:
# Optimize source files # Optimize source files
if llvm_opts > 0: if llvm_opts > 0:
for i, input_file in enumerate(input_files): for i, input_file in enumerate(input_files):
file_suffix = filename_type_suffix(input_file) file_ending = filename_type_ending(input_file)
if file_suffix.endswith(SOURCE_ENDINGS): if file_ending.endswith(SOURCE_ENDINGS):
temp_file = temp_files[i] temp_file = temp_files[i]
logging.debug('optimizing %s with -O%s' % (input_file, llvm_opts)) logging.debug('optimizing %s with -O%s' % (input_file, llvm_opts))
shared.Building.llvm_opt(temp_file, llvm_opts) shared.Building.llvm_opt(temp_file, llvm_opts)