summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/gen-emscripten-exported-json.py108
-rw-r--r--src/emscripten-exported.json122
-rw-r--r--src/wasm.js7
-rw-r--r--test/utils.py10
4 files changed, 232 insertions, 15 deletions
diff --git a/scripts/gen-emscripten-exported-json.py b/scripts/gen-emscripten-exported-json.py
new file mode 100755
index 00000000..0693ce23
--- /dev/null
+++ b/scripts/gen-emscripten-exported-json.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 WebAssembly Community Group participants
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import argparse
+import json
+import os
+import re
+import sys
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+ROOT_DIR = os.path.dirname(SCRIPT_DIR)
+TEST_DIR = os.path.join(ROOT_DIR, 'test')
+DEFAULT_EMSCRIPTEN_DIR = os.path.join(ROOT_DIR, 'emscripten')
+
+sys.path.append(TEST_DIR)
+
+from utils import Executable, Error
+
+
+def FindFiles(cmake_build_dir):
+ result = []
+ for root, dirs, files in os.walk(cmake_build_dir):
+ for file_ in files:
+ path = os.path.join(root, file_)
+ if file_ == 'libwasm.a' or re.search(r'wasm-emscripten-helpers', file_):
+ result.append(path)
+ return result
+
+
+def GetNM(emscripten_dir):
+ python = Executable(sys.executable)
+ stdout = python.RunWithArgsForStdout(
+ '-c', 'import tools.shared; print(tools.shared.LLVM_ROOT)',
+ cwd=emscripten_dir)
+ return Executable(os.path.join(stdout.strip(), 'llvm-nm'))
+
+
+def ProcessFile(nm, file_):
+ names = []
+ for line in nm.RunWithArgsForStdout(file_).splitlines():
+ line = line.rstrip()
+ if not line.lstrip(): continue
+ if line.endswith(':'):
+ # displaying the archive name, e.g. "foo.c.o:"
+ continue
+ # line looks like:
+ #
+ # -------- d yycheck
+ # -------- t wasm_strndup_
+ # U wasm_parse_int64
+ # -------- T wasm_offsetof_allocator_alloc
+ #
+ # we want to only keep the "T" names; the extern function symbols defined
+ # in the object.
+ type_ = line[9]
+ if type_ != 'T':
+ continue
+ name = line[11:]
+ names.append('_' + name)
+ return names
+
+
+def main(args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-o', '--output', metavar='PATH', help='output file.')
+ parser.add_argument('-v', '--verbose',
+ help='print more diagnotic messages.',
+ action='store_true')
+ parser.add_argument('--emscripten-dir', metavar='PATH',
+ help='emscripten directory',
+ default=DEFAULT_EMSCRIPTEN_DIR)
+ parser.add_argument('cmake_build_dir', metavar='cmake_build_dir')
+ options = parser.parse_args(args)
+ nm = GetNM(options.emscripten_dir)
+
+ names = []
+ for file_ in FindFiles(options.cmake_build_dir):
+ names.extend(ProcessFile(nm, file_))
+
+ out_data = json.dumps(sorted(names), separators=(',\n',':\n'))
+ if options.output:
+ with open(options.output, 'w') as out_file:
+ out_file.write(out_data)
+ else:
+ print out_data
+ return 0
+
+
+if __name__ == '__main__':
+ try:
+ sys.exit(main(sys.argv[1:]))
+ except Error as e:
+ sys.stderr.write(str(e) + '\n')
+ sys.exit(1)
diff --git a/src/emscripten-exported.json b/src/emscripten-exported.json
index 28002175..549cf6b3 100644
--- a/src/emscripten-exported.json
+++ b/src/emscripten-exported.json
@@ -1,18 +1,100 @@
-[
+["_wasm_append_element",
+"_wasm_append_module_field",
+"_wasm_apply_names",
+"_wasm_ast_format_error",
+"_wasm_ast_lexer_get_allocator",
+"_wasm_ast_lexer_get_source_line",
+"_wasm_ast_lexer_lex",
+"_wasm_ast_parser_error",
+"_wasm_ast_parser_parse",
"_wasm_check_assert_invalid",
"_wasm_check_ast",
+"_wasm_close_file_writer",
"_wasm_close_mem_writer",
"_wasm_default_assert_invalid_source_error_callback",
+"_wasm_default_binary_error_callback",
"_wasm_default_source_error_callback",
"_wasm_destroy_ast_lexer",
+"_wasm_destroy_block",
+"_wasm_destroy_command",
+"_wasm_destroy_command_vector_and_elements",
+"_wasm_destroy_export",
+"_wasm_destroy_expr",
+"_wasm_destroy_expr_list",
+"_wasm_destroy_func",
+"_wasm_destroy_func_declaration",
+"_wasm_destroy_func_fields",
+"_wasm_destroy_func_signature",
+"_wasm_destroy_func_type",
+"_wasm_destroy_import",
+"_wasm_destroy_interpreter_module",
+"_wasm_destroy_interpreter_thread",
+"_wasm_destroy_memory",
+"_wasm_destroy_module",
+"_wasm_destroy_output_buffer",
"_wasm_destroy_script",
+"_wasm_destroy_segment",
+"_wasm_destroy_segment_vector_and_elements",
"_wasm_destroy_stack_allocator",
-"_wasm_destroy_output_buffer",
+"_wasm_destroy_string_slice",
+"_wasm_destroy_var",
+"_wasm_destroy_var_vector_and_elements",
+"_wasm_disassemble_module",
+"_wasm_ensure_capacity",
+"_wasm_extend_elements",
+"_wasm_generate_names",
+"_wasm_get_export_by_name",
+"_wasm_get_func_by_var",
+"_wasm_get_func_index_by_var",
+"_wasm_get_func_type_by_var",
+"_wasm_get_func_type_index_by_var",
+"_wasm_get_import_by_var",
+"_wasm_get_import_index_by_var",
+"_wasm_get_index_from_var",
+"_wasm_get_interpreter_export_by_name",
+"_wasm_get_interpreter_import_by_name",
"_wasm_get_libc_allocator",
+"_wasm_get_local_index_by_var",
+"_wasm_get_opcode_alignment",
+"_wasm_hash_entry_is_free",
+"_wasm_init_file_stream_from_existing",
+"_wasm_init_file_writer",
+"_wasm_init_file_writer_existing",
+"_wasm_init_interpreter_thread",
"_wasm_init_mem_writer",
-"_wasm_init_stream",
"_wasm_init_stack_allocator",
+"_wasm_init_stderr_stream",
+"_wasm_init_stdout_stream",
+"_wasm_init_stream",
+"_wasm_insert_binding",
+"_wasm_is_naturally_aligned",
+"_wasm_make_type_binding_reverse_mapping",
+"_wasm_move_data",
"_wasm_new_ast_buffer_lexer",
+"_wasm_new_ast_file_lexer",
+"_wasm_new_binary_expr",
+"_wasm_new_block_expr",
+"_wasm_new_br_expr",
+"_wasm_new_br_if_expr",
+"_wasm_new_br_table_expr",
+"_wasm_new_call_expr",
+"_wasm_new_call_import_expr",
+"_wasm_new_call_indirect_expr",
+"_wasm_new_compare_expr",
+"_wasm_new_const_expr",
+"_wasm_new_convert_expr",
+"_wasm_new_empty_expr",
+"_wasm_new_get_local_expr",
+"_wasm_new_grow_memory_expr",
+"_wasm_new_if_else_expr",
+"_wasm_new_if_expr",
+"_wasm_new_load_expr",
+"_wasm_new_loop_expr",
+"_wasm_new_return_expr",
+"_wasm_new_select_expr",
+"_wasm_new_set_local_expr",
+"_wasm_new_store_expr",
+"_wasm_new_unary_expr",
"_wasm_offsetof_allocator_alloc",
"_wasm_offsetof_allocator_destroy",
"_wasm_offsetof_allocator_free",
@@ -49,6 +131,21 @@
"_wasm_offsetof_writer_move_data",
"_wasm_offsetof_writer_write_data",
"_wasm_parse_ast",
+"_wasm_parse_double",
+"_wasm_parse_float",
+"_wasm_parse_hexdigit",
+"_wasm_parse_int32",
+"_wasm_parse_int64",
+"_wasm_parse_options",
+"_wasm_parse_uint64",
+"_wasm_print_help",
+"_wasm_push_thread_value",
+"_wasm_read_binary",
+"_wasm_read_binary_ast",
+"_wasm_read_binary_interpreter",
+"_wasm_read_file",
+"_wasm_resize_vector",
+"_wasm_run_interpreter",
"_wasm_sizeof_allocator",
"_wasm_sizeof_binary_error_handler",
"_wasm_sizeof_location",
@@ -61,6 +158,21 @@
"_wasm_sizeof_string_slice",
"_wasm_sizeof_write_binary_options",
"_wasm_sizeof_writer",
+"_wasm_steal_mem_writer_output_buffer",
+"_wasm_string_slices_are_equal",
+"_wasm_trace_pc",
+"_wasm_visit_func",
+"_wasm_write_ast",
+"_wasm_write_binary_module",
"_wasm_write_binary_script",
-"_wasm_write_binary_spec_script"
-]
+"_wasm_write_binary_spec_script",
+"_wasm_write_data",
+"_wasm_write_data_at",
+"_wasm_write_double_hex",
+"_wasm_write_float_hex",
+"_wasm_write_memory_dump",
+"_wasm_write_output_buffer_to_file",
+"_wasm_write_u32",
+"_wasm_write_u64",
+"_wasm_write_u8",
+"_wasm_writef"] \ No newline at end of file
diff --git a/src/wasm.js b/src/wasm.js
index 38ca2f8f..fa2d732a 100644
--- a/src/wasm.js
+++ b/src/wasm.js
@@ -485,12 +485,6 @@ var checkAst = function(lexer, script, errorHandler) {
throw "checkAst failed";
};
-var markUsedBlocks = function(allocator, script) {
- var result = Module._wasm_mark_used_blocks(allocator.$addr, script.$addr);
- if (result != OK)
- throw "markUsedBlocks failed";
-};
-
var writeBinaryScript = function(allocator, writer, script, options) {
var result = Module._wasm_write_binary_script(allocator.$addr, writer.$addr,
script.$addr, options.$addr);
@@ -523,7 +517,6 @@ wasm = {
Writer: Writer,
checkAst: checkAst,
- markUsedBlocks: markUsedBlocks,
parseAst: parseAst,
writeBinaryScript: writeBinaryScript,
};
diff --git a/test/utils.py b/test/utils.py
index 6cd91954..858eec9e 100644
--- a/test/utils.py
+++ b/test/utils.py
@@ -41,7 +41,7 @@ class Executable(object):
self.clean_stdout = kwargs.get('clean_stdout')
self.clean_stderr = kwargs.get('clean_stderr')
- def RunWithArgs(self, *args):
+ def RunWithArgsForStdout(self, *args, **kwargs):
cmd = [self.exe] + self.before_args + list(args) + self.after_args
cmd_str = ' '.join(cmd)
@@ -51,13 +51,13 @@ class Executable(object):
try:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+ stderr=subprocess.PIPE,
+ **kwargs)
stdout, stderr = process.communicate()
if self.clean_stdout:
stdout = self.clean_stdout(stdout)
if self.clean_stderr:
stderr = self.clean_stderr(stderr)
- sys.stdout.write(stdout)
if process.returncode < 0:
# Terminated by signal
signame = SIGNAMES.get(-process.returncode, '<unknown>')
@@ -67,6 +67,10 @@ class Executable(object):
raise Error('Error running "%s":\n%s' % (err_cmd_str, stderr))
except OSError as e:
raise Error('Error running "%s": %s' % (err_cmd_str, str(e)))
+ return stdout
+
+ def RunWithArgs(self, *args, **kwargs):
+ sys.stdout.write(self.RunWithArgsForStdout(*args, **kwargs))
def AppendArg(self, arg):
self.after_args.append(arg)