ttmg-wasm-tool 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +126 -0
- package/README.md +147 -0
- package/build/CMakeCache.txt +430 -0
- package/build/CMakeFiles/4.0.3/CMakeCCompiler.cmake +84 -0
- package/build/CMakeFiles/4.0.3/CMakeCXXCompiler.cmake +104 -0
- package/build/CMakeFiles/4.0.3/CMakeDetermineCompilerABI_C.bin +0 -0
- package/build/CMakeFiles/4.0.3/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/build/CMakeFiles/4.0.3/CMakeSystem.cmake +15 -0
- package/build/CMakeFiles/4.0.3/CompilerIdC/CMakeCCompilerId.c +905 -0
- package/build/CMakeFiles/4.0.3/CompilerIdC/a.out +0 -0
- package/build/CMakeFiles/4.0.3/CompilerIdC/apple-sdk.c +1 -0
- package/build/CMakeFiles/4.0.3/CompilerIdCXX/CMakeCXXCompilerId.cpp +920 -0
- package/build/CMakeFiles/4.0.3/CompilerIdCXX/a.out +0 -0
- package/build/CMakeFiles/4.0.3/CompilerIdCXX/apple-sdk.cpp +1 -0
- package/build/CMakeFiles/CMakeConfigureLog.yaml +841 -0
- package/build/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- package/build/CMakeFiles/CheckTypeSize/SIZEOF_SIZE_T.bin +0 -0
- package/build/CMakeFiles/CheckTypeSize/SSIZE_T.bin +0 -0
- package/build/CMakeFiles/InstallScripts.json +7 -0
- package/build/CMakeFiles/Makefile.cmake +152 -0
- package/build/CMakeFiles/Makefile2 +122 -0
- package/build/CMakeFiles/TargetDirectories.txt +3 -0
- package/build/CMakeFiles/cmake.check_cache +1 -0
- package/build/CMakeFiles/progress.marks +1 -0
- package/build/CMakeFiles/wasm_tool_node.dir/DependInfo.cmake +65 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/apply-names.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/apply-names.cc.o.d +810 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-reader-ir.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-reader-ir.cc.o.d +822 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-reader-logging.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-reader-logging.cc.o.d +818 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-reader.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-reader.cc.o.d +819 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-writer.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary-writer.cc.o.d +816 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binary.cc.o.d +802 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binding-hash.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/binding-hash.cc.o.d +808 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/color.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/color.cc.o.d +808 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/common.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/common.cc.o.d +804 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/config.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/config.cc.o.d +106 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/error-formatter.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/error-formatter.cc.o.d +807 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/expr-visitor.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/expr-visitor.cc.o.d +810 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/feature.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/feature.cc.o.d +804 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/filenames.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/filenames.cc.o.d +802 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/generate-names.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/generate-names.cc.o.d +811 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/hash-util.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/hash-util.cc.o.d +779 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/ir-util.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/ir-util.cc.o.d +822 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/ir.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/ir.cc.o.d +824 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/leb128.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/leb128.cc.o.d +803 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/lexer-source-line-finder.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/lexer-source-line-finder.cc.o.d +804 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/lexer-source.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/lexer-source.cc.o.d +803 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/literal.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/literal.cc.o.d +808 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/opcode-code-table.c.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/opcode-code-table.c.o.d +79 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/opcode.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/opcode.cc.o.d +807 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/option-parser.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/option-parser.cc.o.d +802 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/resolve-names.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/resolve-names.cc.o.d +819 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/shared-validator.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/shared-validator.cc.o.d +824 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/stream.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/stream.cc.o.d +802 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/string-view.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/string-view.cc.o.d +796 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/token.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/token.cc.o.d +809 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wasm-prepare.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wasm-prepare.cc.o.d +811 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wasm-reader-writer.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wasm-reader-writer.cc.o.d +839 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wasm-split.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wasm-split.cc.o.d +833 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wat-writer.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tools/wat-writer.cc.o.d +823 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tracing.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/tracing.cc.o.d +802 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/type-checker.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/type-checker.cc.o.d +814 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/utf8.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/utf8.cc.o.d +87 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/validator.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/validator.cc.o.d +827 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/wast-lexer.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/wast-lexer.cc.o.d +821 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/wast-parser.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/wast-parser.cc.o.d +835 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/wat-writer.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/Users/anrans/Desktop/workspace/ttop/ttmg-fe/packages/libs/wasm_tools/wasm-split/src/wat-writer.cc.o.d +823 -0
- package/build/CMakeFiles/wasm_tool_node.dir/build.make +785 -0
- package/build/CMakeFiles/wasm_tool_node.dir/cmake_clean.cmake +95 -0
- package/build/CMakeFiles/wasm_tool_node.dir/compiler_depend.make +2 -0
- package/build/CMakeFiles/wasm_tool_node.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/wasm_tool_node.dir/depend.make +2 -0
- package/build/CMakeFiles/wasm_tool_node.dir/flags.make +21 -0
- package/build/CMakeFiles/wasm_tool_node.dir/link.txt +1 -0
- package/build/CMakeFiles/wasm_tool_node.dir/progress.make +45 -0
- package/build/CMakeFiles/wasm_tool_node.dir/src/napi-binding.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/src/napi-binding.cc.o.d +787 -0
- package/build/CMakeFiles/wasm_tool_node.dir/src/wasm-buffer-ops.cc.o +0 -0
- package/build/CMakeFiles/wasm_tool_node.dir/src/wasm-buffer-ops.cc.o.d +837 -0
- package/build/Makefile +1315 -0
- package/build/Release/wasm_tool_node.node +0 -0
- package/build/cmake_install.cmake +61 -0
- package/build/compile_commands.json +260 -0
- package/build/config.h +316 -0
- package/index.d.ts +99 -0
- package/index.js +104 -0
- package/package.json +52 -0
- package/src/napi-binding.cc +139 -0
- package/src/wasm-buffer-ops.cc +867 -0
- package/src/wasm-buffer-ops.h +43 -0
package/build/config.h
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2016 WebAssembly Community Group participants
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef WABT_CONFIG_H_
|
|
18
|
+
#define WABT_CONFIG_H_
|
|
19
|
+
|
|
20
|
+
#include <stdint.h>
|
|
21
|
+
#include <stdlib.h>
|
|
22
|
+
|
|
23
|
+
#define CMAKE_PROJECT_VERSION "1.0.0"
|
|
24
|
+
|
|
25
|
+
/* TODO(binji): nice way to define these with WABT_ prefix? */
|
|
26
|
+
|
|
27
|
+
/* Whether <alloca.h> is available */
|
|
28
|
+
#define HAVE_ALLOCA_H 1
|
|
29
|
+
|
|
30
|
+
/* Whether <unistd.h> is available */
|
|
31
|
+
#define HAVE_UNISTD_H 1
|
|
32
|
+
|
|
33
|
+
/* Whether snprintf is defined by stdio.h */
|
|
34
|
+
#define HAVE_SNPRINTF 1
|
|
35
|
+
|
|
36
|
+
/* Whether ssize_t is defined by stddef.h */
|
|
37
|
+
#define HAVE_SSIZE_T 1
|
|
38
|
+
|
|
39
|
+
/* Whether strcasecmp is defined by strings.h */
|
|
40
|
+
#define HAVE_STRCASECMP 1
|
|
41
|
+
|
|
42
|
+
/* Whether ENABLE_VIRTUAL_TERMINAL_PROCESSING is defined by windows.h */
|
|
43
|
+
#define HAVE_WIN32_VT100 0
|
|
44
|
+
|
|
45
|
+
#define COMPILER_IS_CLANG 1
|
|
46
|
+
#define COMPILER_IS_GNU 0
|
|
47
|
+
#define COMPILER_IS_MSVC 0
|
|
48
|
+
|
|
49
|
+
#define WITH_EXCEPTIONS 0
|
|
50
|
+
|
|
51
|
+
#define SIZEOF_SIZE_T 8
|
|
52
|
+
|
|
53
|
+
#if HAVE_ALLOCA_H
|
|
54
|
+
#include <alloca.h>
|
|
55
|
+
#elif COMPILER_IS_MSVC
|
|
56
|
+
#include <malloc.h>
|
|
57
|
+
#define alloca _alloca
|
|
58
|
+
#elif defined(__MINGW32__)
|
|
59
|
+
#include <malloc.h>
|
|
60
|
+
#endif
|
|
61
|
+
|
|
62
|
+
#if COMPILER_IS_CLANG || COMPILER_IS_GNU
|
|
63
|
+
|
|
64
|
+
#define WABT_UNUSED __attribute__((unused))
|
|
65
|
+
#define WABT_WARN_UNUSED __attribute__((warn_unused_result))
|
|
66
|
+
#define WABT_INLINE inline
|
|
67
|
+
#define WABT_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
|
68
|
+
#define WABT_LIKELY(x) __builtin_expect(!!(x), 1)
|
|
69
|
+
|
|
70
|
+
#define WABT_VECTORCALL
|
|
71
|
+
|
|
72
|
+
#if __MINGW32__
|
|
73
|
+
// mingw defaults to printf format specifier being ms_printf (which doesn't
|
|
74
|
+
// understand 'llu', etc.) We always want gnu_printf, and force mingw to always
|
|
75
|
+
// use mingw_printf, mingw_vprintf, etc.
|
|
76
|
+
#define WABT_PRINTF_FORMAT(format_arg, first_arg) \
|
|
77
|
+
__attribute__((format(gnu_printf, (format_arg), (first_arg))))
|
|
78
|
+
#else
|
|
79
|
+
#define WABT_PRINTF_FORMAT(format_arg, first_arg) \
|
|
80
|
+
__attribute__((format(printf, (format_arg), (first_arg))))
|
|
81
|
+
#endif
|
|
82
|
+
|
|
83
|
+
#ifdef __cplusplus
|
|
84
|
+
#if __cplusplus >= 201103L
|
|
85
|
+
#define WABT_STATIC_ASSERT(x) static_assert((x), #x)
|
|
86
|
+
#else
|
|
87
|
+
#define WABT_STATIC_ASSERT__(x, c) \
|
|
88
|
+
static int static_assert_##c[(x ? 0 : -1)] WABT_UNUSED
|
|
89
|
+
#define WABT_STATIC_ASSERT_(x, c) WABT_STATIC_ASSERT__(x, c)
|
|
90
|
+
#define WABT_STATIC_ASSERT(x) WABT_STATIC_ASSERT_(x, __COUNTER__)
|
|
91
|
+
#endif
|
|
92
|
+
#else
|
|
93
|
+
#define WABT_STATIC_ASSERT(x) _Static_assert((x), #x)
|
|
94
|
+
#endif
|
|
95
|
+
|
|
96
|
+
#elif COMPILER_IS_MSVC
|
|
97
|
+
|
|
98
|
+
#include <intrin.h>
|
|
99
|
+
#include <string.h>
|
|
100
|
+
|
|
101
|
+
#define WABT_UNUSED
|
|
102
|
+
#define WABT_WARN_UNUSED
|
|
103
|
+
#define WABT_INLINE __inline
|
|
104
|
+
#define WABT_STATIC_ASSERT(x) _STATIC_ASSERT(x)
|
|
105
|
+
#define WABT_UNLIKELY(x) (x)
|
|
106
|
+
#define WABT_LIKELY(x) (x)
|
|
107
|
+
#define WABT_PRINTF_FORMAT(format_arg, first_arg)
|
|
108
|
+
|
|
109
|
+
#define WABT_VECTORCALL __vectorcall
|
|
110
|
+
|
|
111
|
+
#else
|
|
112
|
+
|
|
113
|
+
#error unknown compiler
|
|
114
|
+
|
|
115
|
+
#endif
|
|
116
|
+
|
|
117
|
+
#define WABT_UNREACHABLE abort()
|
|
118
|
+
|
|
119
|
+
#ifdef __cplusplus
|
|
120
|
+
|
|
121
|
+
namespace wabt {
|
|
122
|
+
|
|
123
|
+
#if COMPILER_IS_CLANG || COMPILER_IS_GNU
|
|
124
|
+
|
|
125
|
+
inline int Clz(unsigned x) { return x ? __builtin_clz(x) : sizeof(x) * 8; }
|
|
126
|
+
inline int Clz(unsigned long x) { return x ? __builtin_clzl(x) : sizeof(x) * 8; }
|
|
127
|
+
inline int Clz(unsigned long long x) { return x ? __builtin_clzll(x) : sizeof(x) * 8; }
|
|
128
|
+
|
|
129
|
+
inline int Ctz(unsigned x) { return x ? __builtin_ctz(x) : sizeof(x) * 8; }
|
|
130
|
+
inline int Ctz(unsigned long x) { return x ? __builtin_ctzl(x) : sizeof(x) * 8; }
|
|
131
|
+
inline int Ctz(unsigned long long x) { return x ? __builtin_ctzll(x) : sizeof(x) * 8; }
|
|
132
|
+
|
|
133
|
+
inline int Popcount(uint8_t x) { return __builtin_popcount(x); }
|
|
134
|
+
inline int Popcount(unsigned x) { return __builtin_popcount(x); }
|
|
135
|
+
inline int Popcount(unsigned long x) { return __builtin_popcountl(x); }
|
|
136
|
+
inline int Popcount(unsigned long long x) { return __builtin_popcountll(x); }
|
|
137
|
+
|
|
138
|
+
#elif COMPILER_IS_MSVC
|
|
139
|
+
|
|
140
|
+
#if _M_IX86
|
|
141
|
+
inline unsigned long LowDword(unsigned __int64 value) {
|
|
142
|
+
return (unsigned long)value;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
inline unsigned long HighDword(unsigned __int64 value) {
|
|
146
|
+
unsigned long high;
|
|
147
|
+
memcpy(&high, (unsigned char*)&value + sizeof(high), sizeof(high));
|
|
148
|
+
return high;
|
|
149
|
+
}
|
|
150
|
+
#endif
|
|
151
|
+
|
|
152
|
+
inline int Clz(unsigned long mask) {
|
|
153
|
+
if (mask == 0)
|
|
154
|
+
return 32;
|
|
155
|
+
|
|
156
|
+
unsigned long index;
|
|
157
|
+
_BitScanReverse(&index, mask);
|
|
158
|
+
return sizeof(unsigned long) * 8 - (index + 1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
inline int Clz(unsigned int mask) {
|
|
162
|
+
return Clz((unsigned long)mask);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
inline int Clz(unsigned __int64 mask) {
|
|
166
|
+
#if _M_X64
|
|
167
|
+
if (mask == 0)
|
|
168
|
+
return 64;
|
|
169
|
+
|
|
170
|
+
unsigned long index;
|
|
171
|
+
_BitScanReverse64(&index, mask);
|
|
172
|
+
return sizeof(unsigned __int64) * 8 - (index + 1);
|
|
173
|
+
#elif _M_IX86
|
|
174
|
+
int result = Clz(HighDword(mask));
|
|
175
|
+
if (result == 32)
|
|
176
|
+
result += Clz(LowDword(mask));
|
|
177
|
+
|
|
178
|
+
return result;
|
|
179
|
+
#else
|
|
180
|
+
#error unexpected architecture
|
|
181
|
+
#endif
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
inline int Ctz(unsigned long mask) {
|
|
185
|
+
if (mask == 0)
|
|
186
|
+
return 32;
|
|
187
|
+
|
|
188
|
+
unsigned long index;
|
|
189
|
+
_BitScanForward(&index, mask);
|
|
190
|
+
return index;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
inline int Ctz(unsigned int mask) {
|
|
194
|
+
return Ctz((unsigned long)mask);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
inline int Ctz(unsigned __int64 mask) {
|
|
198
|
+
#if _M_X64
|
|
199
|
+
if (mask == 0)
|
|
200
|
+
return 64;
|
|
201
|
+
|
|
202
|
+
unsigned long index;
|
|
203
|
+
_BitScanForward64(&index, mask);
|
|
204
|
+
return index;
|
|
205
|
+
#elif _M_IX86
|
|
206
|
+
int result = Ctz(LowDword(mask));
|
|
207
|
+
if (result == 32)
|
|
208
|
+
result += Ctz(HighDword(mask));
|
|
209
|
+
|
|
210
|
+
return result;
|
|
211
|
+
#else
|
|
212
|
+
#error unexpected architecture
|
|
213
|
+
#endif
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
inline int Popcount(uint8_t value) {
|
|
217
|
+
return __popcnt(value);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
inline int Popcount(unsigned long value) {
|
|
221
|
+
return __popcnt(value);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
inline int Popcount(unsigned int value) {
|
|
225
|
+
return Popcount((unsigned long)value);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
inline int Popcount(unsigned __int64 value) {
|
|
229
|
+
#if _M_X64
|
|
230
|
+
return __popcnt64(value);
|
|
231
|
+
#elif _M_IX86
|
|
232
|
+
return Popcount(HighDword(value)) + Popcount(LowDword(value));
|
|
233
|
+
#else
|
|
234
|
+
#error unexpected architecture
|
|
235
|
+
#endif
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#else
|
|
239
|
+
|
|
240
|
+
#error unknown compiler
|
|
241
|
+
|
|
242
|
+
#endif
|
|
243
|
+
|
|
244
|
+
} // namespace wabt
|
|
245
|
+
|
|
246
|
+
#if COMPILER_IS_MSVC
|
|
247
|
+
|
|
248
|
+
/* print format specifier for size_t */
|
|
249
|
+
#if SIZEOF_SIZE_T == 4
|
|
250
|
+
#define PRIzd "d"
|
|
251
|
+
#define PRIzx "x"
|
|
252
|
+
#elif SIZEOF_SIZE_T == 8
|
|
253
|
+
#define PRIzd "I64d"
|
|
254
|
+
#define PRIzx "I64x"
|
|
255
|
+
#else
|
|
256
|
+
#error "weird sizeof size_t"
|
|
257
|
+
#endif
|
|
258
|
+
|
|
259
|
+
#elif COMPILER_IS_CLANG || COMPILER_IS_GNU
|
|
260
|
+
|
|
261
|
+
/* print format specifier for size_t */
|
|
262
|
+
#define PRIzd "zd"
|
|
263
|
+
#define PRIzx "zx"
|
|
264
|
+
|
|
265
|
+
#else
|
|
266
|
+
|
|
267
|
+
#error unknown compiler
|
|
268
|
+
|
|
269
|
+
#endif
|
|
270
|
+
|
|
271
|
+
#if HAVE_SNPRINTF
|
|
272
|
+
#define wabt_snprintf snprintf
|
|
273
|
+
#elif COMPILER_IS_MSVC
|
|
274
|
+
/* can't just use _snprintf because it doesn't always null terminate */
|
|
275
|
+
#include <cstdarg>
|
|
276
|
+
int wabt_snprintf(char* str, size_t size, const char* format, ...);
|
|
277
|
+
#else
|
|
278
|
+
#error no snprintf
|
|
279
|
+
#endif
|
|
280
|
+
|
|
281
|
+
#if COMPILER_IS_MSVC
|
|
282
|
+
/* can't just use vsnprintf because it doesn't always null terminate */
|
|
283
|
+
int wabt_vsnprintf(char* str, size_t size, const char* format, va_list ap);
|
|
284
|
+
#else
|
|
285
|
+
#define wabt_vsnprintf vsnprintf
|
|
286
|
+
#endif
|
|
287
|
+
|
|
288
|
+
#if !HAVE_SSIZE_T
|
|
289
|
+
#if COMPILER_IS_MSVC
|
|
290
|
+
/* define ssize_t identically to how LLVM does, to avoid conflicts if including both */
|
|
291
|
+
#if defined(_WIN64)
|
|
292
|
+
typedef signed __int64 ssize_t;
|
|
293
|
+
#else
|
|
294
|
+
typedef signed int ssize_t;
|
|
295
|
+
#endif /* _WIN64 */
|
|
296
|
+
#else
|
|
297
|
+
typedef long ssize_t;
|
|
298
|
+
#endif
|
|
299
|
+
#endif
|
|
300
|
+
|
|
301
|
+
#if !HAVE_STRCASECMP
|
|
302
|
+
#if COMPILER_IS_MSVC
|
|
303
|
+
#define strcasecmp _stricmp
|
|
304
|
+
#else
|
|
305
|
+
#error no strcasecmp
|
|
306
|
+
#endif
|
|
307
|
+
#endif
|
|
308
|
+
|
|
309
|
+
double wabt_convert_uint64_to_double(uint64_t x);
|
|
310
|
+
float wabt_convert_uint64_to_float(uint64_t x);
|
|
311
|
+
double wabt_convert_int64_to_double(int64_t x);
|
|
312
|
+
float wabt_convert_int64_to_float(int64_t x);
|
|
313
|
+
|
|
314
|
+
#endif // __cplusplus
|
|
315
|
+
|
|
316
|
+
#endif /* WABT_CONFIG_H_ */
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Tool Node - Native module for WASM manipulation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Result of prepareWasm operation
|
|
7
|
+
*/
|
|
8
|
+
export interface PrepareResult {
|
|
9
|
+
/** Whether the operation succeeded */
|
|
10
|
+
success: boolean;
|
|
11
|
+
/** Error message if operation failed */
|
|
12
|
+
error?: string;
|
|
13
|
+
/** Number of functions in the WASM module */
|
|
14
|
+
funcCount?: number;
|
|
15
|
+
/** The instrumented WASM binary buffer */
|
|
16
|
+
wasmBuffer?: Buffer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Result of splitWasm operation
|
|
21
|
+
*/
|
|
22
|
+
export interface SplitResult {
|
|
23
|
+
/** Whether the operation succeeded */
|
|
24
|
+
success: boolean;
|
|
25
|
+
/** Error message if operation failed */
|
|
26
|
+
error?: string;
|
|
27
|
+
/** Total number of functions in original WASM */
|
|
28
|
+
totalFuncCount?: number;
|
|
29
|
+
/** Number of functions in main package */
|
|
30
|
+
mainFuncCount?: number;
|
|
31
|
+
/** Number of functions in sub package */
|
|
32
|
+
subFuncCount?: number;
|
|
33
|
+
/** Table size after split */
|
|
34
|
+
tableSize?: number;
|
|
35
|
+
/** Global variable list info */
|
|
36
|
+
globalVarList?: string;
|
|
37
|
+
/** Main package WASM buffer */
|
|
38
|
+
mainWasmBuffer?: Buffer;
|
|
39
|
+
/** Sub package WASM buffer */
|
|
40
|
+
subWasmBuffer?: Buffer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Prepare a WASM module by inserting logCall instrumentation
|
|
45
|
+
* This inserts a call to scwebgl.logCall at the beginning of each function
|
|
46
|
+
*
|
|
47
|
+
* @param wasmBuffer - The input WASM binary buffer
|
|
48
|
+
* @returns PrepareResult containing the instrumented WASM
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { prepareWasm } from '@aspect/wasm-tool-node';
|
|
53
|
+
* import { readFileSync, writeFileSync } from 'fs';
|
|
54
|
+
*
|
|
55
|
+
* const wasm = readFileSync('input.wasm');
|
|
56
|
+
* const result = prepareWasm(wasm);
|
|
57
|
+
*
|
|
58
|
+
* if (result.success) {
|
|
59
|
+
* console.log(`Prepared ${result.funcCount} functions`);
|
|
60
|
+
* writeFileSync('output.wasm', result.wasmBuffer!);
|
|
61
|
+
* } else {
|
|
62
|
+
* console.error(result.error);
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function prepareWasm(wasmBuffer: Buffer): PrepareResult;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Split a WASM module into main and sub packages
|
|
70
|
+
*
|
|
71
|
+
* The split follows these rules:
|
|
72
|
+
* 1. All import functions and elem segment functions go to main package
|
|
73
|
+
* 2. Main package creates stub functions for missing calls that wait for sub package
|
|
74
|
+
* 3. Sub package contains all non-main package functions
|
|
75
|
+
* 4. Sub package functions get logCall instrumentation
|
|
76
|
+
* 5. Global variables are converted to imports for sharing between packages
|
|
77
|
+
*
|
|
78
|
+
* @param wasmBuffer - The input WASM binary buffer
|
|
79
|
+
* @param funcIdList - Optional newline-separated list of function IDs to include in main package
|
|
80
|
+
* @returns SplitResult containing main and sub package WASM buffers
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { splitWasm } from '@aspect/wasm-tool-node';
|
|
85
|
+
* import { readFileSync, writeFileSync } from 'fs';
|
|
86
|
+
*
|
|
87
|
+
* const wasm = readFileSync('input.wasm');
|
|
88
|
+
* const result = splitWasm(wasm);
|
|
89
|
+
*
|
|
90
|
+
* if (result.success) {
|
|
91
|
+
* console.log(`Total: ${result.totalFuncCount}, Main: ${result.mainFuncCount}, Sub: ${result.subFuncCount}`);
|
|
92
|
+
* writeFileSync('main.wasm', result.mainWasmBuffer!);
|
|
93
|
+
* writeFileSync('sub.wasm', result.subWasmBuffer!);
|
|
94
|
+
* } else {
|
|
95
|
+
* console.error(result.error);
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function splitWasm(wasmBuffer: Buffer, funcIdList?: string): SplitResult;
|
package/index.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Tool Node - Native module for WASM manipulation
|
|
3
|
+
*
|
|
4
|
+
* This module provides Node.js bindings for WASM preparation and splitting tools.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
|
|
10
|
+
// Determine the correct binary path based on platform
|
|
11
|
+
function getBindingPath() {
|
|
12
|
+
const platform = os.platform();
|
|
13
|
+
const arch = os.arch();
|
|
14
|
+
|
|
15
|
+
// Try prebuilt binary first
|
|
16
|
+
const prebuiltDir = path.join(__dirname, 'prebuilds', `${platform}-${arch}`);
|
|
17
|
+
const prebuiltPath = path.join(prebuiltDir, 'wasm_tool_node.node');
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
require.resolve(prebuiltPath);
|
|
21
|
+
return prebuiltPath;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
// Fall back to build directory
|
|
24
|
+
const buildPath = path.join(__dirname, 'build', 'Release', 'wasm_tool_node.node');
|
|
25
|
+
try {
|
|
26
|
+
require.resolve(buildPath);
|
|
27
|
+
return buildPath;
|
|
28
|
+
} catch (e2) {
|
|
29
|
+
// Try Debug build
|
|
30
|
+
const debugPath = path.join(__dirname, 'build', 'Debug', 'wasm_tool_node.node');
|
|
31
|
+
return debugPath;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let binding;
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
binding = require(getBindingPath());
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error('Failed to load wasm_tool_node native module.');
|
|
42
|
+
console.error('Please ensure the module is properly built using: npm run build');
|
|
43
|
+
console.error('Error:', e.message);
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Prepare a WASM module by inserting logCall instrumentation
|
|
49
|
+
* @param {Buffer} wasmBuffer - The input WASM binary buffer
|
|
50
|
+
* @returns {import('./index').PrepareResult} Result containing the instrumented WASM
|
|
51
|
+
*/
|
|
52
|
+
function prepareWasm(wasmBuffer) {
|
|
53
|
+
if (!Buffer.isBuffer(wasmBuffer)) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
error: 'Input must be a Buffer'
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (wasmBuffer.length === 0) {
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: 'Empty buffer provided'
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return binding.prepareWasm(wasmBuffer);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Split a WASM module into main and sub packages
|
|
72
|
+
* @param {Buffer} wasmBuffer - The input WASM binary buffer
|
|
73
|
+
* @param {string} [funcIdList] - Optional newline-separated list of function IDs for main package
|
|
74
|
+
* @returns {import('./index').SplitResult} Result containing main and sub package WASM buffers
|
|
75
|
+
*/
|
|
76
|
+
function splitWasm(wasmBuffer, funcIdList) {
|
|
77
|
+
if (!Buffer.isBuffer(wasmBuffer)) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
error: 'Input must be a Buffer'
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (wasmBuffer.length === 0) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: 'Empty buffer provided'
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (funcIdList !== undefined && typeof funcIdList !== 'string') {
|
|
92
|
+
return {
|
|
93
|
+
success: false,
|
|
94
|
+
error: 'funcIdList must be a string if provided'
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return binding.splitWasm(wasmBuffer, funcIdList || '');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
prepareWasm,
|
|
103
|
+
splitWasm
|
|
104
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ttmg-wasm-tool",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Native Node.js module for WASM preparation and splitting",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"src/",
|
|
11
|
+
"CMakeLists.txt",
|
|
12
|
+
"prebuilds/",
|
|
13
|
+
"build/"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"install": "cmake-js compile -G \"Unix Makefiles\"",
|
|
17
|
+
"build": "cmake-js compile --release -G \"Unix Makefiles\"",
|
|
18
|
+
"build:debug": "cmake-js compile --debug -G \"Unix Makefiles\"",
|
|
19
|
+
"rebuild": "cmake-js rebuild --release -G \"Unix Makefiles\"",
|
|
20
|
+
"clean": "cmake-js clean",
|
|
21
|
+
"test": "node test/test.js"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"wasm",
|
|
25
|
+
"webassembly",
|
|
26
|
+
"split",
|
|
27
|
+
"native",
|
|
28
|
+
"napi"
|
|
29
|
+
],
|
|
30
|
+
"author": "gaopeng.anran",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"cmake-js": "^7.3.0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"node-addon-api": "^7.0.0"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=16.0.0"
|
|
40
|
+
},
|
|
41
|
+
"binary": {
|
|
42
|
+
"napi_versions": [8]
|
|
43
|
+
},
|
|
44
|
+
"os": [
|
|
45
|
+
"darwin",
|
|
46
|
+
"win32"
|
|
47
|
+
],
|
|
48
|
+
"cpu": [
|
|
49
|
+
"x64",
|
|
50
|
+
"arm64"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
//
|
|
2
|
+
// N-API binding for WASM tools
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#include <napi.h>
|
|
6
|
+
#include "wasm-buffer-ops.h"
|
|
7
|
+
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
// Convert PrepareResult to Napi::Object
|
|
11
|
+
Napi::Object PrepareResultToObject(Napi::Env env, const wasm_tool::PrepareResult& result) {
|
|
12
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
13
|
+
|
|
14
|
+
obj.Set("success", Napi::Boolean::New(env, result.success));
|
|
15
|
+
|
|
16
|
+
if (!result.success) {
|
|
17
|
+
obj.Set("error", Napi::String::New(env, result.error));
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
obj.Set("funcCount", Napi::Number::New(env, static_cast<double>(result.func_count)));
|
|
22
|
+
|
|
23
|
+
// Create Buffer from wasm data
|
|
24
|
+
Napi::Buffer<uint8_t> buffer = Napi::Buffer<uint8_t>::Copy(
|
|
25
|
+
env, result.wasm_buffer.data(), result.wasm_buffer.size());
|
|
26
|
+
obj.Set("wasmBuffer", buffer);
|
|
27
|
+
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Convert SplitResult to Napi::Object
|
|
32
|
+
Napi::Object SplitResultToObject(Napi::Env env, const wasm_tool::SplitResult& result) {
|
|
33
|
+
Napi::Object obj = Napi::Object::New(env);
|
|
34
|
+
|
|
35
|
+
obj.Set("success", Napi::Boolean::New(env, result.success));
|
|
36
|
+
|
|
37
|
+
if (!result.success) {
|
|
38
|
+
obj.Set("error", Napi::String::New(env, result.error));
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
obj.Set("totalFuncCount", Napi::Number::New(env, static_cast<double>(result.total_func_count)));
|
|
43
|
+
obj.Set("mainFuncCount", Napi::Number::New(env, static_cast<double>(result.main_func_count)));
|
|
44
|
+
obj.Set("subFuncCount", Napi::Number::New(env, static_cast<double>(result.sub_func_count)));
|
|
45
|
+
obj.Set("tableSize", Napi::Number::New(env, static_cast<double>(result.table_size)));
|
|
46
|
+
obj.Set("globalVarList", Napi::String::New(env, result.global_var_list));
|
|
47
|
+
|
|
48
|
+
// Create Buffers from wasm data
|
|
49
|
+
Napi::Buffer<uint8_t> mainBuffer = Napi::Buffer<uint8_t>::Copy(
|
|
50
|
+
env, result.main_wasm_buffer.data(), result.main_wasm_buffer.size());
|
|
51
|
+
obj.Set("mainWasmBuffer", mainBuffer);
|
|
52
|
+
|
|
53
|
+
Napi::Buffer<uint8_t> subBuffer = Napi::Buffer<uint8_t>::Copy(
|
|
54
|
+
env, result.sub_wasm_buffer.data(), result.sub_wasm_buffer.size());
|
|
55
|
+
obj.Set("subWasmBuffer", subBuffer);
|
|
56
|
+
|
|
57
|
+
return obj;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// prepareWasm(wasmBuffer: Buffer) => PrepareResult
|
|
61
|
+
Napi::Value PrepareWasm(const Napi::CallbackInfo& info) {
|
|
62
|
+
Napi::Env env = info.Env();
|
|
63
|
+
|
|
64
|
+
// Validate arguments
|
|
65
|
+
if (info.Length() < 1) {
|
|
66
|
+
Napi::TypeError::New(env, "Expected 1 argument: wasmBuffer").ThrowAsJavaScriptException();
|
|
67
|
+
return env.Null();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!info[0].IsBuffer()) {
|
|
71
|
+
Napi::TypeError::New(env, "First argument must be a Buffer").ThrowAsJavaScriptException();
|
|
72
|
+
return env.Null();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Napi::Buffer<uint8_t> buffer = info[0].As<Napi::Buffer<uint8_t>>();
|
|
76
|
+
const uint8_t* data = buffer.Data();
|
|
77
|
+
size_t size = buffer.Length();
|
|
78
|
+
|
|
79
|
+
if (size == 0) {
|
|
80
|
+
Napi::Object result = Napi::Object::New(env);
|
|
81
|
+
result.Set("success", Napi::Boolean::New(env, false));
|
|
82
|
+
result.Set("error", Napi::String::New(env, "Empty buffer provided"));
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Call the C++ implementation
|
|
87
|
+
wasm_tool::PrepareResult result = wasm_tool::PrepareWasmFromBuffer(data, size);
|
|
88
|
+
|
|
89
|
+
return PrepareResultToObject(env, result);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// splitWasm(wasmBuffer: Buffer, funcIdList?: string) => SplitResult
|
|
93
|
+
Napi::Value SplitWasm(const Napi::CallbackInfo& info) {
|
|
94
|
+
Napi::Env env = info.Env();
|
|
95
|
+
|
|
96
|
+
// Validate arguments
|
|
97
|
+
if (info.Length() < 1) {
|
|
98
|
+
Napi::TypeError::New(env, "Expected at least 1 argument: wasmBuffer").ThrowAsJavaScriptException();
|
|
99
|
+
return env.Null();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!info[0].IsBuffer()) {
|
|
103
|
+
Napi::TypeError::New(env, "First argument must be a Buffer").ThrowAsJavaScriptException();
|
|
104
|
+
return env.Null();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Napi::Buffer<uint8_t> buffer = info[0].As<Napi::Buffer<uint8_t>>();
|
|
108
|
+
const uint8_t* data = buffer.Data();
|
|
109
|
+
size_t size = buffer.Length();
|
|
110
|
+
|
|
111
|
+
if (size == 0) {
|
|
112
|
+
Napi::Object result = Napi::Object::New(env);
|
|
113
|
+
result.Set("success", Napi::Boolean::New(env, false));
|
|
114
|
+
result.Set("error", Napi::String::New(env, "Empty buffer provided"));
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Get optional func id list
|
|
119
|
+
std::string funcIdList;
|
|
120
|
+
if (info.Length() >= 2 && info[1].IsString()) {
|
|
121
|
+
funcIdList = info[1].As<Napi::String>().Utf8Value();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Call the C++ implementation
|
|
125
|
+
wasm_tool::SplitResult result = wasm_tool::SplitWasmFromBuffer(data, size, funcIdList);
|
|
126
|
+
|
|
127
|
+
return SplitResultToObject(env, result);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Module initialization
|
|
131
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
132
|
+
exports.Set("prepareWasm", Napi::Function::New(env, PrepareWasm));
|
|
133
|
+
exports.Set("splitWasm", Napi::Function::New(env, SplitWasm));
|
|
134
|
+
return exports;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
NODE_API_MODULE(wasm_tool_node, Init)
|
|
138
|
+
|
|
139
|
+
} // anonymous namespace
|