Skip to content

Commit

Permalink
Merge branch 'incoming'
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Sep 25, 2013
2 parents 6010666 + 8e2d812 commit 05b6aa3
Show file tree
Hide file tree
Showing 330 changed files with 19,587 additions and 19,642 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ a license to everyone to use it as detailed in LICENSE.)
* Aidan Hobson Sayers <[email protected]>
* Charlie Birks <[email protected]>
* Ranger Harke <[email protected]> (copyright owned by Autodesk, Inc.)
* Tobias Vrinssen <[email protected]>

57 changes: 57 additions & 0 deletions cmake/Platform/Emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,60 @@ set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "-O2" CACHE STRING "Emscripten-over
function(em_validate_asmjs_after_build target)
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo Validating build output for asm.js... COMMAND "python" ARGS "${EMSCRIPTEN_ROOT_PATH}/tools/validate_asmjs.py" "$<TARGET_FILE:${target}>")
endfunction()

# A global counter to guarantee unique names for js library files.
set(link_js_counter 1)

# Internal function: Do not call from user CMakeLists.txt files. Use one of em_link_js_library()/em_link_pre_js()/em_link_post_js() instead.
function(em_add_tracked_link_flag target flagname)
get_target_property(props ${target} LINK_FLAGS)
# User can input list of JS files either as a single list, or as variable arguments to this function, so iterate over varargs, and treat each
# item in varargs as a list itself, to support both syntax forms.
foreach(jsFileList ${ARGN})
foreach(jsfile ${jsFileList})
# Add link command to the given JS file.
set(props "${props} ${flagname} \"${jsfile}\"")

# If the user edits the JS file, we want to relink the emscripten application, but unfortunately it is not possible to make a link step
# depend directly on a source file. Instead, we must make a dummy no-op build target on that source file, and make the project depend on
# that target.

# Sanitate the source .js filename to a good symbol name to use as a dummy filename.
get_filename_component(jsname "${jsfile}" NAME)
string(REGEX REPLACE "[/:\\\\.\ ]" "_" dummy_js_target ${jsname})
set(dummy_lib_name ${target}_${link_js_counter}_${dummy_js_target})
set(dummy_c_name "${CMAKE_BINARY_DIR}/${dummy_js_target}_tracker.c")

# Create a new static library target that with a single dummy .c file.
add_library(${dummy_lib_name} STATIC ${dummy_c_name})
# Make the dummy .c file depend on the .js file we are linking, so that if the .js file is edited, the dummy .c file, and hence the static library will be rebuild (no-op). This causes the main application to be relinked, which is what we want.
# This approach was recommended by http://www.cmake.org/pipermail/cmake/2010-May/037206.html
add_custom_command(OUTPUT ${dummy_c_name} COMMAND ${CMAKE_COMMAND} -E touch ${dummy_c_name} DEPENDS ${jsfile})
target_link_libraries(${target} ${dummy_lib_name})

math(EXPR link_js_counter "${link_js_counter} + 1")
endforeach()
endforeach()
set_target_properties(${target} PROPERTIES LINK_FLAGS "${props}")
endfunction()

# This function links a (list of ) .js library file(s) to the given CMake project.
# Example: em_link_js_library(my_executable "lib1.js" "lib2.js")
# will result in emcc passing --js-library lib1.js --js-library lib2.js to the emscripten linker, as well as
# tracking the modification timestamp between the linked .js files and the main project, so that editing the .js file
# will cause the target project to be relinked.
function(em_link_js_library target)
em_add_tracked_link_flag(${target} "--js-library" ${ARGN})
endfunction()

# This function is identical to em_link_js_library(), except the .js files will be added with '--pre-js file.js' command line flag,
# which is generally used to add some preamble .js code to a generated output file.
function(em_link_pre_js target)
em_add_tracked_link_flag(${target} "--pre-js" ${ARGN})
endfunction()

# This function is identical to em_link_js_library(), except the .js files will be added with '--post-js file.js' command line flag,
# which is generally used to add some postamble .js code to a generated output file.
function(em_link_post_js target)
em_add_tracked_link_flag(${target} "--post-js" ${ARGN})
endfunction()
9 changes: 7 additions & 2 deletions emcc
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ Options that are modified or new in %s include:
(see --llvm-opts), setting this has no
effect.
Note that LLVM LTO is not perfectly stable yet,
and can can cause code to behave incorrectly.
--closure <on> 0: No closure compiler (default in -O2 and below)
1: Run closure compiler. This greatly reduces
code size and may in some cases increase
Expand Down Expand Up @@ -556,6 +559,8 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG:
elif arg.endswith('.s'):
if debug_configure: open(tempout, 'a').write('(compiling .s assembly, must use clang\n')
use_js = 0
elif arg == '-E':
use_js = 0

if src:
if 'fopen' in src and '"w"' in src:
Expand Down Expand Up @@ -669,7 +674,7 @@ if '-M' in sys.argv or '-MM' in sys.argv:
if '-E' in sys.argv:
# Just run the preprocessor
cmd = [CC] + sys.argv[1:]
logging.debug('just preprocssor ' + ' '.join(cmd))
logging.debug('just preprocessor ' + ' '.join(cmd))
exit(subprocess.call(cmd))

# Check if a target is specified
Expand Down Expand Up @@ -1618,7 +1623,7 @@ try:
temp_memfile = os.path.join(shared.EMSCRIPTEN_TEMP_DIR, os.path.basename(memfile))
if os.path.abspath(memfile) != os.path.abspath(memfile):
shutil.copyfile(memfile, temp_memfile)
return 'loadMemoryInitializer("%s");' % os.path.basename(memfile)
return 'var memoryInitializer = "%s";' % os.path.basename(memfile)
src = re.sub(shared.JS.memory_initializer_pattern, repl, open(final).read(), count=1)
open(final + '.mem.js', 'w').write(src)
final += '.mem.js'
Expand Down
4 changes: 2 additions & 2 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def scan(ll, settings):
if len(blockaddrs) > 0:
settings['NECESSARY_BLOCKADDRS'] = blockaddrs

NUM_CHUNKS_PER_CORE = 1.25
NUM_CHUNKS_PER_CORE = 1.0
MIN_CHUNK_SIZE = 1024*1024
MAX_CHUNK_SIZE = float(os.environ.get('EMSCRIPT_MAX_CHUNK_SIZE') or 'inf') # configuring this is just for debugging purposes

Expand Down Expand Up @@ -209,7 +209,7 @@ def save_settings():
if cores > 1:
intended_num_chunks = int(round(cores * NUM_CHUNKS_PER_CORE))
chunk_size = max(MIN_CHUNK_SIZE, total_ll_size / intended_num_chunks)
chunk_size += 3*len(meta) + len(forwarded_data)/3 # keep ratio of lots of function code to meta (expensive to process, and done in each parallel task) and forwarded data (less expensive but potentially significant)
chunk_size += 3*len(meta) # keep ratio of lots of function code to meta (expensive to process, and done in each parallel task)
chunk_size = min(MAX_CHUNK_SIZE, chunk_size)
else:
chunk_size = MAX_CHUNK_SIZE # if 1 core, just use the max chunk size
Expand Down
Loading

0 comments on commit 05b6aa3

Please sign in to comment.