@coana-tech/cli 14.12.76 → 14.12.78
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/cli.mjs +1 -1
- package/package.json +1 -1
- package/reachability-analyzers-cli.mjs +1 -2
- package/repos/coana-tech/alucard/alucard.jar +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/cli.mjs +24669 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/LICENSE.md +9 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/README.md +95 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/common.gypi +21 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/except.gypi +25 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/index.js +14 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/napi-inl.h +6941 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/napi.h +3295 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/node_addon_api.gyp +42 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/node_api.gyp +9 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/nothing.c +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/package-support.json +21 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/package.json +480 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/tools/README.md +73 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/tools/check-napi.js +99 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-addon-api/tools/conversion.js +301 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/LICENSE +21 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/README.md +58 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/SECURITY.md +5 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/bin.js +84 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/build-test.js +19 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/index.js +6 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/node-gyp-build.js +207 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/optional.js +7 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/node-gyp-build/package.json +43 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/LICENSE +21 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/README.md +128 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/binding.gyp +80 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/index.js +919 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/node_modules/.bin/node-gyp-build +16 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/node_modules/.bin/node-gyp-build-optional +16 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/node_modules/.bin/node-gyp-build-test +16 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/package.json +76 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/prebuilds/linux-arm64/tree-sitter.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/prebuilds/win32-arm64/tree-sitter.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/binding.cc +35 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/conversions.h +22 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/language.cc +106 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/language.h +17 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/logger.cc +70 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/logger.h +19 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/node.cc +1088 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/node.h +30 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/parser.cc +306 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/parser.h +35 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/query.cc +397 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/query.h +40 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/tree.cc +316 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/tree.h +45 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/tree-sitter.d.ts +1042 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1318 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +291 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +501 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +223 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +297 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +435 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +49 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +12 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +920 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2165 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +266 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +62 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +206 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4187 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +899 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +130 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1066 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +399 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +170 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +712 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +11 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +83 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +24 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +109 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1302 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1859 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/LICENSE +22 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/README.md +21 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/binding.gyp +30 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/bindings/node/binding.cc +20 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/bindings/node/binding_test.js +9 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/bindings/node/index.d.ts +28 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/bindings/node/index.js +11 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/grammar.js +1281 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/node_modules/.bin/node-gyp-build +16 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/node_modules/.bin/node-gyp-build-optional +16 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/node_modules/.bin/node-gyp-build-test +16 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/package.json +77 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/prebuilds/darwin-arm64/tree-sitter-ruby.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/prebuilds/darwin-x64/tree-sitter-ruby.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/prebuilds/linux-arm64/tree-sitter-ruby.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/prebuilds/linux-x64/tree-sitter-ruby.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/prebuilds/win32-arm64/tree-sitter-ruby.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/prebuilds/win32-x64/tree-sitter-ruby.node +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/queries/highlights.scm +154 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/queries/locals.scm +27 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/queries/tags.scm +64 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/src/grammar.json +8364 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/src/node-types.json +4108 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/src/parser.c +471247 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/src/scanner.c +1107 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/src/tree_sitter/alloc.h +54 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/src/tree_sitter/array.h +290 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/src/tree_sitter/parser.h +266 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/tree-sitter-ruby.wasm +0 -0
- package/repos/coana-tech/callgraph-reachability-analyzers/packages/cli/dist/bundle/node_modules/tree-sitter-ruby/tree-sitter.json +46 -0
- package/repos/coana-tech/goana/bin/goana-darwin-amd64.gz +0 -0
- package/repos/coana-tech/goana/bin/goana-darwin-arm64.gz +0 -0
- package/repos/coana-tech/goana/bin/goana-linux-amd64.gz +0 -0
- package/repos/coana-tech/goana/bin/goana-linux-arm64.gz +0 -0
|
@@ -0,0 +1,1859 @@
|
|
|
1
|
+
#include "tree_sitter/api.h"
|
|
2
|
+
#include "./parser.h"
|
|
3
|
+
#include <stdint.h>
|
|
4
|
+
|
|
5
|
+
#ifdef TREE_SITTER_FEATURE_WASM
|
|
6
|
+
|
|
7
|
+
#include "./alloc.h"
|
|
8
|
+
#include "./array.h"
|
|
9
|
+
#include "./atomic.h"
|
|
10
|
+
#include "./language.h"
|
|
11
|
+
#include "./lexer.h"
|
|
12
|
+
#include "./wasm/wasm-stdlib.h"
|
|
13
|
+
#include "./wasm_store.h"
|
|
14
|
+
|
|
15
|
+
#include <string.h>
|
|
16
|
+
#include <wasm.h>
|
|
17
|
+
#include <wasmtime.h>
|
|
18
|
+
|
|
19
|
+
#ifdef _MSC_VER
|
|
20
|
+
#pragma warning(push)
|
|
21
|
+
#pragma warning(disable : 4100)
|
|
22
|
+
#elif defined(__GNUC__) || defined(__clang__)
|
|
23
|
+
#pragma GCC diagnostic push
|
|
24
|
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
#define array_len(a) (sizeof(a) / sizeof(a[0]))
|
|
28
|
+
|
|
29
|
+
// The following symbols from the C and C++ standard libraries are available
|
|
30
|
+
// for external scanners to use.
|
|
31
|
+
const char *STDLIB_SYMBOLS[] = {
|
|
32
|
+
#include "./stdlib-symbols.txt"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// The contents of the `dylink.0` custom section of a wasm module,
|
|
36
|
+
// as specified by the current WebAssembly dynamic linking ABI proposal.
|
|
37
|
+
typedef struct {
|
|
38
|
+
uint32_t memory_size;
|
|
39
|
+
uint32_t memory_align;
|
|
40
|
+
uint32_t table_size;
|
|
41
|
+
uint32_t table_align;
|
|
42
|
+
} WasmDylinkInfo;
|
|
43
|
+
|
|
44
|
+
// WasmLanguageId - A pointer used to identify a language. This language id is
|
|
45
|
+
// reference-counted, so that its ownership can be shared between the language
|
|
46
|
+
// itself and the instances of the language that are held in wasm stores.
|
|
47
|
+
typedef struct {
|
|
48
|
+
volatile uint32_t ref_count;
|
|
49
|
+
volatile uint32_t is_language_deleted;
|
|
50
|
+
} WasmLanguageId;
|
|
51
|
+
|
|
52
|
+
// LanguageWasmModule - Additional data associated with a wasm-backed
|
|
53
|
+
// `TSLanguage`. This data is read-only and does not reference a particular
|
|
54
|
+
// wasm store, so it can be shared by all users of a `TSLanguage`. A pointer to
|
|
55
|
+
// this is stored on the language itself.
|
|
56
|
+
typedef struct {
|
|
57
|
+
volatile uint32_t ref_count;
|
|
58
|
+
WasmLanguageId *language_id;
|
|
59
|
+
wasmtime_module_t *module;
|
|
60
|
+
const char *name;
|
|
61
|
+
char *symbol_name_buffer;
|
|
62
|
+
char *field_name_buffer;
|
|
63
|
+
WasmDylinkInfo dylink_info;
|
|
64
|
+
} LanguageWasmModule;
|
|
65
|
+
|
|
66
|
+
// LanguageWasmInstance - Additional data associated with an instantiation of
|
|
67
|
+
// a `TSLanguage` in a particular wasm store. The wasm store holds one of
|
|
68
|
+
// these structs for each language that it has instantiated.
|
|
69
|
+
typedef struct {
|
|
70
|
+
WasmLanguageId *language_id;
|
|
71
|
+
wasmtime_instance_t instance;
|
|
72
|
+
int32_t external_states_address;
|
|
73
|
+
int32_t lex_main_fn_index;
|
|
74
|
+
int32_t lex_keyword_fn_index;
|
|
75
|
+
int32_t scanner_create_fn_index;
|
|
76
|
+
int32_t scanner_destroy_fn_index;
|
|
77
|
+
int32_t scanner_serialize_fn_index;
|
|
78
|
+
int32_t scanner_deserialize_fn_index;
|
|
79
|
+
int32_t scanner_scan_fn_index;
|
|
80
|
+
} LanguageWasmInstance;
|
|
81
|
+
|
|
82
|
+
typedef struct {
|
|
83
|
+
uint32_t reset_heap;
|
|
84
|
+
uint32_t proc_exit;
|
|
85
|
+
uint32_t abort;
|
|
86
|
+
uint32_t assert_fail;
|
|
87
|
+
uint32_t notify_memory_growth;
|
|
88
|
+
uint32_t debug_message;
|
|
89
|
+
uint32_t at_exit;
|
|
90
|
+
uint32_t args_get;
|
|
91
|
+
uint32_t args_sizes_get;
|
|
92
|
+
} BuiltinFunctionIndices;
|
|
93
|
+
|
|
94
|
+
// TSWasmStore - A struct that allows a given `Parser` to use wasm-backed
|
|
95
|
+
// languages. This struct is mutable, and can only be used by one parser at a
|
|
96
|
+
// time.
|
|
97
|
+
struct TSWasmStore {
|
|
98
|
+
wasm_engine_t *engine;
|
|
99
|
+
wasmtime_store_t *store;
|
|
100
|
+
wasmtime_table_t function_table;
|
|
101
|
+
wasmtime_memory_t memory;
|
|
102
|
+
TSLexer *current_lexer;
|
|
103
|
+
LanguageWasmInstance *current_instance;
|
|
104
|
+
Array(LanguageWasmInstance) language_instances;
|
|
105
|
+
uint32_t current_memory_offset;
|
|
106
|
+
uint32_t current_function_table_offset;
|
|
107
|
+
uint32_t *stdlib_fn_indices;
|
|
108
|
+
BuiltinFunctionIndices builtin_fn_indices;
|
|
109
|
+
wasmtime_global_t stack_pointer_global;
|
|
110
|
+
wasm_globaltype_t *const_i32_type;
|
|
111
|
+
bool has_error;
|
|
112
|
+
uint32_t lexer_address;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
typedef Array(char) StringData;
|
|
116
|
+
|
|
117
|
+
// LanguageInWasmMemory - The memory layout of a `TSLanguage` when compiled to
|
|
118
|
+
// wasm32. This is used to copy static language data out of the wasm memory.
|
|
119
|
+
typedef struct {
|
|
120
|
+
uint32_t version;
|
|
121
|
+
uint32_t symbol_count;
|
|
122
|
+
uint32_t alias_count;
|
|
123
|
+
uint32_t token_count;
|
|
124
|
+
uint32_t external_token_count;
|
|
125
|
+
uint32_t state_count;
|
|
126
|
+
uint32_t large_state_count;
|
|
127
|
+
uint32_t production_id_count;
|
|
128
|
+
uint32_t field_count;
|
|
129
|
+
uint16_t max_alias_sequence_length;
|
|
130
|
+
int32_t parse_table;
|
|
131
|
+
int32_t small_parse_table;
|
|
132
|
+
int32_t small_parse_table_map;
|
|
133
|
+
int32_t parse_actions;
|
|
134
|
+
int32_t symbol_names;
|
|
135
|
+
int32_t field_names;
|
|
136
|
+
int32_t field_map_slices;
|
|
137
|
+
int32_t field_map_entries;
|
|
138
|
+
int32_t symbol_metadata;
|
|
139
|
+
int32_t public_symbol_map;
|
|
140
|
+
int32_t alias_map;
|
|
141
|
+
int32_t alias_sequences;
|
|
142
|
+
int32_t lex_modes;
|
|
143
|
+
int32_t lex_fn;
|
|
144
|
+
int32_t keyword_lex_fn;
|
|
145
|
+
TSSymbol keyword_capture_token;
|
|
146
|
+
struct {
|
|
147
|
+
int32_t states;
|
|
148
|
+
int32_t symbol_map;
|
|
149
|
+
int32_t create;
|
|
150
|
+
int32_t destroy;
|
|
151
|
+
int32_t scan;
|
|
152
|
+
int32_t serialize;
|
|
153
|
+
int32_t deserialize;
|
|
154
|
+
} external_scanner;
|
|
155
|
+
int32_t primary_state_ids;
|
|
156
|
+
} LanguageInWasmMemory;
|
|
157
|
+
|
|
158
|
+
// LexerInWasmMemory - The memory layout of a `TSLexer` when compiled to wasm32.
|
|
159
|
+
// This is used to copy mutable lexing state in and out of the wasm memory.
|
|
160
|
+
typedef struct {
|
|
161
|
+
int32_t lookahead;
|
|
162
|
+
TSSymbol result_symbol;
|
|
163
|
+
int32_t advance;
|
|
164
|
+
int32_t mark_end;
|
|
165
|
+
int32_t get_column;
|
|
166
|
+
int32_t is_at_included_range_start;
|
|
167
|
+
int32_t eof;
|
|
168
|
+
} LexerInWasmMemory;
|
|
169
|
+
|
|
170
|
+
// Linear memory layout:
|
|
171
|
+
// [ <-- stack | stdlib statics | lexer | language statics --> | serialization_buffer | heap --> ]
|
|
172
|
+
#define MAX_MEMORY_SIZE (128 * 1024 * 1024 / MEMORY_PAGE_SIZE)
|
|
173
|
+
|
|
174
|
+
/************************
|
|
175
|
+
* WasmDylinkMemoryInfo
|
|
176
|
+
***********************/
|
|
177
|
+
|
|
178
|
+
static uint8_t read_u8(const uint8_t **p) {
|
|
179
|
+
return *(*p)++;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static inline uint64_t read_uleb128(const uint8_t **p, const uint8_t *end) {
|
|
183
|
+
uint64_t value = 0;
|
|
184
|
+
unsigned shift = 0;
|
|
185
|
+
do {
|
|
186
|
+
if (*p == end) return UINT64_MAX;
|
|
187
|
+
value += (uint64_t)(**p & 0x7f) << shift;
|
|
188
|
+
shift += 7;
|
|
189
|
+
} while (*((*p)++) >= 128);
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static bool wasm_dylink_info__parse(
|
|
194
|
+
const uint8_t *bytes,
|
|
195
|
+
size_t length,
|
|
196
|
+
WasmDylinkInfo *info
|
|
197
|
+
) {
|
|
198
|
+
const uint8_t WASM_MAGIC_NUMBER[4] = {0, 'a', 's', 'm'};
|
|
199
|
+
const uint8_t WASM_VERSION[4] = {1, 0, 0, 0};
|
|
200
|
+
const uint8_t WASM_CUSTOM_SECTION = 0x0;
|
|
201
|
+
const uint8_t WASM_DYLINK_MEM_INFO = 0x1;
|
|
202
|
+
|
|
203
|
+
const uint8_t *p = bytes;
|
|
204
|
+
const uint8_t *end = bytes + length;
|
|
205
|
+
|
|
206
|
+
if (length < 8) return false;
|
|
207
|
+
if (memcmp(p, WASM_MAGIC_NUMBER, 4) != 0) return false;
|
|
208
|
+
p += 4;
|
|
209
|
+
if (memcmp(p, WASM_VERSION, 4) != 0) return false;
|
|
210
|
+
p += 4;
|
|
211
|
+
|
|
212
|
+
while (p < end) {
|
|
213
|
+
uint8_t section_id = read_u8(&p);
|
|
214
|
+
uint32_t section_length = read_uleb128(&p, end);
|
|
215
|
+
const uint8_t *section_end = p + section_length;
|
|
216
|
+
if (section_end > end) return false;
|
|
217
|
+
|
|
218
|
+
if (section_id == WASM_CUSTOM_SECTION) {
|
|
219
|
+
uint32_t name_length = read_uleb128(&p, section_end);
|
|
220
|
+
const uint8_t *name_end = p + name_length;
|
|
221
|
+
if (name_end > section_end) return false;
|
|
222
|
+
|
|
223
|
+
if (name_length == 8 && memcmp(p, "dylink.0", 8) == 0) {
|
|
224
|
+
p = name_end;
|
|
225
|
+
while (p < section_end) {
|
|
226
|
+
uint8_t subsection_type = read_u8(&p);
|
|
227
|
+
uint32_t subsection_size = read_uleb128(&p, section_end);
|
|
228
|
+
const uint8_t *subsection_end = p + subsection_size;
|
|
229
|
+
if (subsection_end > section_end) return false;
|
|
230
|
+
if (subsection_type == WASM_DYLINK_MEM_INFO) {
|
|
231
|
+
info->memory_size = read_uleb128(&p, subsection_end);
|
|
232
|
+
info->memory_align = read_uleb128(&p, subsection_end);
|
|
233
|
+
info->table_size = read_uleb128(&p, subsection_end);
|
|
234
|
+
info->table_align = read_uleb128(&p, subsection_end);
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
p = subsection_end;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
p = section_end;
|
|
242
|
+
}
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/*******************************************
|
|
247
|
+
* Native callbacks exposed to wasm modules
|
|
248
|
+
*******************************************/
|
|
249
|
+
|
|
250
|
+
static wasm_trap_t *callback__abort(
|
|
251
|
+
void *env,
|
|
252
|
+
wasmtime_caller_t* caller,
|
|
253
|
+
wasmtime_val_raw_t *args_and_results,
|
|
254
|
+
size_t args_and_results_len
|
|
255
|
+
) {
|
|
256
|
+
return wasmtime_trap_new("wasm module called abort", 24);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static wasm_trap_t *callback__debug_message(
|
|
260
|
+
void *env,
|
|
261
|
+
wasmtime_caller_t* caller,
|
|
262
|
+
wasmtime_val_raw_t *args_and_results,
|
|
263
|
+
size_t args_and_results_len
|
|
264
|
+
) {
|
|
265
|
+
wasmtime_context_t *context = wasmtime_caller_context(caller);
|
|
266
|
+
TSWasmStore *store = env;
|
|
267
|
+
ts_assert(args_and_results_len == 2);
|
|
268
|
+
uint32_t string_address = args_and_results[0].i32;
|
|
269
|
+
uint32_t value = args_and_results[1].i32;
|
|
270
|
+
uint8_t *memory = wasmtime_memory_data(context, &store->memory);
|
|
271
|
+
printf("DEBUG: %s %u\n", &memory[string_address], value);
|
|
272
|
+
return NULL;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
static wasm_trap_t *callback__noop(
|
|
276
|
+
void *env,
|
|
277
|
+
wasmtime_caller_t* caller,
|
|
278
|
+
wasmtime_val_raw_t *args_and_results,
|
|
279
|
+
size_t args_and_results_len
|
|
280
|
+
) {
|
|
281
|
+
return NULL;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static wasm_trap_t *callback__lexer_advance(
|
|
285
|
+
void *env,
|
|
286
|
+
wasmtime_caller_t* caller,
|
|
287
|
+
wasmtime_val_raw_t *args_and_results,
|
|
288
|
+
size_t args_and_results_len
|
|
289
|
+
) {
|
|
290
|
+
wasmtime_context_t *context = wasmtime_caller_context(caller);
|
|
291
|
+
ts_assert(args_and_results_len == 2);
|
|
292
|
+
|
|
293
|
+
TSWasmStore *store = env;
|
|
294
|
+
TSLexer *lexer = store->current_lexer;
|
|
295
|
+
bool skip = args_and_results[1].i32;
|
|
296
|
+
lexer->advance(lexer, skip);
|
|
297
|
+
|
|
298
|
+
uint8_t *memory = wasmtime_memory_data(context, &store->memory);
|
|
299
|
+
memcpy(&memory[store->lexer_address], &lexer->lookahead, sizeof(lexer->lookahead));
|
|
300
|
+
return NULL;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
static wasm_trap_t *callback__lexer_mark_end(
|
|
304
|
+
void *env,
|
|
305
|
+
wasmtime_caller_t* caller,
|
|
306
|
+
wasmtime_val_raw_t *args_and_results,
|
|
307
|
+
size_t args_and_results_len
|
|
308
|
+
) {
|
|
309
|
+
TSWasmStore *store = env;
|
|
310
|
+
TSLexer *lexer = store->current_lexer;
|
|
311
|
+
lexer->mark_end(lexer);
|
|
312
|
+
return NULL;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static wasm_trap_t *callback__lexer_get_column(
|
|
316
|
+
void *env,
|
|
317
|
+
wasmtime_caller_t* caller,
|
|
318
|
+
wasmtime_val_raw_t *args_and_results,
|
|
319
|
+
size_t args_and_results_len
|
|
320
|
+
) {
|
|
321
|
+
TSWasmStore *store = env;
|
|
322
|
+
TSLexer *lexer = store->current_lexer;
|
|
323
|
+
uint32_t result = lexer->get_column(lexer);
|
|
324
|
+
args_and_results[0].i32 = result;
|
|
325
|
+
return NULL;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static wasm_trap_t *callback__lexer_is_at_included_range_start(
|
|
329
|
+
void *env,
|
|
330
|
+
wasmtime_caller_t* caller,
|
|
331
|
+
wasmtime_val_raw_t *args_and_results,
|
|
332
|
+
size_t args_and_results_len
|
|
333
|
+
) {
|
|
334
|
+
TSWasmStore *store = env;
|
|
335
|
+
TSLexer *lexer = store->current_lexer;
|
|
336
|
+
bool result = lexer->is_at_included_range_start(lexer);
|
|
337
|
+
args_and_results[0].i32 = result;
|
|
338
|
+
return NULL;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
static wasm_trap_t *callback__lexer_eof(
|
|
342
|
+
void *env,
|
|
343
|
+
wasmtime_caller_t* caller,
|
|
344
|
+
wasmtime_val_raw_t *args_and_results,
|
|
345
|
+
size_t args_and_results_len
|
|
346
|
+
) {
|
|
347
|
+
TSWasmStore *store = env;
|
|
348
|
+
TSLexer *lexer = store->current_lexer;
|
|
349
|
+
bool result = lexer->eof(lexer);
|
|
350
|
+
args_and_results[0].i32 = result;
|
|
351
|
+
return NULL;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
typedef struct {
|
|
355
|
+
uint32_t *storage_location;
|
|
356
|
+
wasmtime_func_unchecked_callback_t callback;
|
|
357
|
+
wasm_functype_t *type;
|
|
358
|
+
} FunctionDefinition;
|
|
359
|
+
|
|
360
|
+
static void *copy(const void *data, size_t size) {
|
|
361
|
+
void *result = ts_malloc(size);
|
|
362
|
+
memcpy(result, data, size);
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
static void *copy_unsized_static_array(
|
|
367
|
+
const uint8_t *data,
|
|
368
|
+
int32_t start_address,
|
|
369
|
+
const int32_t all_addresses[],
|
|
370
|
+
size_t address_count
|
|
371
|
+
) {
|
|
372
|
+
int32_t end_address = 0;
|
|
373
|
+
for (unsigned i = 0; i < address_count; i++) {
|
|
374
|
+
if (all_addresses[i] > start_address) {
|
|
375
|
+
if (!end_address || all_addresses[i] < end_address) {
|
|
376
|
+
end_address = all_addresses[i];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (!end_address) return NULL;
|
|
382
|
+
size_t size = end_address - start_address;
|
|
383
|
+
void *result = ts_malloc(size);
|
|
384
|
+
memcpy(result, &data[start_address], size);
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
static void *copy_strings(
|
|
389
|
+
const uint8_t *data,
|
|
390
|
+
int32_t array_address,
|
|
391
|
+
size_t count,
|
|
392
|
+
StringData *string_data
|
|
393
|
+
) {
|
|
394
|
+
const char **result = ts_malloc(count * sizeof(char *));
|
|
395
|
+
for (unsigned i = 0; i < count; i++) {
|
|
396
|
+
int32_t address;
|
|
397
|
+
memcpy(&address, &data[array_address + i * sizeof(address)], sizeof(address));
|
|
398
|
+
if (address == 0) {
|
|
399
|
+
result[i] = (const char *)-1;
|
|
400
|
+
} else {
|
|
401
|
+
const uint8_t *string = &data[address];
|
|
402
|
+
uint32_t len = strlen((const char *)string);
|
|
403
|
+
result[i] = (const char *)(uintptr_t)string_data->size;
|
|
404
|
+
array_extend(string_data, len + 1, string);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
for (unsigned i = 0; i < count; i++) {
|
|
408
|
+
if (result[i] == (const char *)-1) {
|
|
409
|
+
result[i] = NULL;
|
|
410
|
+
} else {
|
|
411
|
+
result[i] = string_data->contents + (uintptr_t)result[i];
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
static bool name_eq(const wasm_name_t *name, const char *string) {
|
|
418
|
+
return strncmp(string, name->data, name->size) == 0;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
static inline wasm_functype_t* wasm_functype_new_4_0(
|
|
422
|
+
wasm_valtype_t* p1,
|
|
423
|
+
wasm_valtype_t* p2,
|
|
424
|
+
wasm_valtype_t* p3,
|
|
425
|
+
wasm_valtype_t* p4
|
|
426
|
+
) {
|
|
427
|
+
wasm_valtype_t* ps[4] = {p1, p2, p3, p4};
|
|
428
|
+
wasm_valtype_vec_t params, results;
|
|
429
|
+
wasm_valtype_vec_new(¶ms, 4, ps);
|
|
430
|
+
wasm_valtype_vec_new_empty(&results);
|
|
431
|
+
return wasm_functype_new(¶ms, &results);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
#define format(output, ...) \
|
|
435
|
+
do { \
|
|
436
|
+
size_t message_length = snprintf((char *)NULL, 0, __VA_ARGS__); \
|
|
437
|
+
*output = ts_malloc(message_length + 1); \
|
|
438
|
+
snprintf(*output, message_length + 1, __VA_ARGS__); \
|
|
439
|
+
} while (0)
|
|
440
|
+
|
|
441
|
+
WasmLanguageId *language_id_new(void) {
|
|
442
|
+
WasmLanguageId *self = ts_malloc(sizeof(WasmLanguageId));
|
|
443
|
+
self->is_language_deleted = false;
|
|
444
|
+
self->ref_count = 1;
|
|
445
|
+
return self;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
WasmLanguageId *language_id_clone(WasmLanguageId *self) {
|
|
449
|
+
atomic_inc(&self->ref_count);
|
|
450
|
+
return self;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
void language_id_delete(WasmLanguageId *self) {
|
|
454
|
+
if (atomic_dec(&self->ref_count) == 0) {
|
|
455
|
+
ts_free(self);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
static wasmtime_extern_t get_builtin_extern(
|
|
460
|
+
wasmtime_table_t *table,
|
|
461
|
+
unsigned index
|
|
462
|
+
) {
|
|
463
|
+
return (wasmtime_extern_t) {
|
|
464
|
+
.kind = WASMTIME_EXTERN_FUNC,
|
|
465
|
+
.of.func = (wasmtime_func_t) {
|
|
466
|
+
.store_id = table->store_id,
|
|
467
|
+
.__private = index
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
static bool ts_wasm_store__provide_builtin_import(
|
|
473
|
+
TSWasmStore *self,
|
|
474
|
+
const wasm_name_t *import_name,
|
|
475
|
+
wasmtime_extern_t *import
|
|
476
|
+
) {
|
|
477
|
+
wasmtime_error_t *error = NULL;
|
|
478
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
479
|
+
|
|
480
|
+
// Dynamic linking parameters
|
|
481
|
+
if (name_eq(import_name, "__memory_base")) {
|
|
482
|
+
wasmtime_val_t value = WASM_I32_VAL(self->current_memory_offset);
|
|
483
|
+
wasmtime_global_t global;
|
|
484
|
+
error = wasmtime_global_new(context, self->const_i32_type, &value, &global);
|
|
485
|
+
ts_assert(!error);
|
|
486
|
+
*import = (wasmtime_extern_t) {.kind = WASMTIME_EXTERN_GLOBAL, .of.global = global};
|
|
487
|
+
} else if (name_eq(import_name, "__table_base")) {
|
|
488
|
+
wasmtime_val_t value = WASM_I32_VAL(self->current_function_table_offset);
|
|
489
|
+
wasmtime_global_t global;
|
|
490
|
+
error = wasmtime_global_new(context, self->const_i32_type, &value, &global);
|
|
491
|
+
ts_assert(!error);
|
|
492
|
+
*import = (wasmtime_extern_t) {.kind = WASMTIME_EXTERN_GLOBAL, .of.global = global};
|
|
493
|
+
} else if (name_eq(import_name, "__stack_pointer")) {
|
|
494
|
+
*import = (wasmtime_extern_t) {.kind = WASMTIME_EXTERN_GLOBAL, .of.global = self->stack_pointer_global};
|
|
495
|
+
} else if (name_eq(import_name, "__indirect_function_table")) {
|
|
496
|
+
*import = (wasmtime_extern_t) {.kind = WASMTIME_EXTERN_TABLE, .of.table = self->function_table};
|
|
497
|
+
} else if (name_eq(import_name, "memory")) {
|
|
498
|
+
*import = (wasmtime_extern_t) {.kind = WASMTIME_EXTERN_MEMORY, .of.memory = self->memory};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Builtin functions
|
|
502
|
+
else if (name_eq(import_name, "__assert_fail")) {
|
|
503
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.assert_fail);
|
|
504
|
+
} else if (name_eq(import_name, "__cxa_atexit")) {
|
|
505
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.at_exit);
|
|
506
|
+
} else if (name_eq(import_name, "args_get")) {
|
|
507
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.args_get);
|
|
508
|
+
} else if (name_eq(import_name, "args_sizes_get")) {
|
|
509
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.args_sizes_get);
|
|
510
|
+
} else if (name_eq(import_name, "abort")) {
|
|
511
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.abort);
|
|
512
|
+
} else if (name_eq(import_name, "proc_exit")) {
|
|
513
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.proc_exit);
|
|
514
|
+
} else if (name_eq(import_name, "emscripten_notify_memory_growth")) {
|
|
515
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.notify_memory_growth);
|
|
516
|
+
} else if (name_eq(import_name, "tree_sitter_debug_message")) {
|
|
517
|
+
*import = get_builtin_extern(&self->function_table, self->builtin_fn_indices.debug_message);
|
|
518
|
+
} else {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
static bool ts_wasm_store__call_module_initializer(
|
|
526
|
+
TSWasmStore *self,
|
|
527
|
+
const wasm_name_t *export_name,
|
|
528
|
+
wasmtime_extern_t *export,
|
|
529
|
+
wasm_trap_t **trap
|
|
530
|
+
) {
|
|
531
|
+
if (
|
|
532
|
+
name_eq(export_name, "_initialize") ||
|
|
533
|
+
name_eq(export_name, "__wasm_apply_data_relocs") ||
|
|
534
|
+
name_eq(export_name, "__wasm_call_ctors")
|
|
535
|
+
) {
|
|
536
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
537
|
+
wasmtime_func_t initialization_func = export->of.func;
|
|
538
|
+
wasmtime_error_t *error = wasmtime_func_call(context, &initialization_func, NULL, 0, NULL, 0, trap);
|
|
539
|
+
ts_assert(!error);
|
|
540
|
+
return true;
|
|
541
|
+
} else {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
TSWasmStore *ts_wasm_store_new(TSWasmEngine *engine, TSWasmError *wasm_error) {
|
|
547
|
+
TSWasmStore *self = ts_calloc(1, sizeof(TSWasmStore));
|
|
548
|
+
wasmtime_store_t *store = wasmtime_store_new(engine, self, NULL);
|
|
549
|
+
wasmtime_context_t *context = wasmtime_store_context(store);
|
|
550
|
+
wasmtime_error_t *error = NULL;
|
|
551
|
+
wasm_trap_t *trap = NULL;
|
|
552
|
+
wasm_message_t message = WASM_EMPTY_VEC;
|
|
553
|
+
wasm_exporttype_vec_t export_types = WASM_EMPTY_VEC;
|
|
554
|
+
wasm_importtype_vec_t import_types = WASM_EMPTY_VEC;
|
|
555
|
+
wasmtime_extern_t *imports = NULL;
|
|
556
|
+
wasmtime_module_t *stdlib_module = NULL;
|
|
557
|
+
wasm_memorytype_t *memory_type = NULL;
|
|
558
|
+
wasm_tabletype_t *table_type = NULL;
|
|
559
|
+
|
|
560
|
+
// Define functions called by scanners via function pointers on the lexer.
|
|
561
|
+
LexerInWasmMemory lexer = {
|
|
562
|
+
.lookahead = 0,
|
|
563
|
+
.result_symbol = 0,
|
|
564
|
+
};
|
|
565
|
+
FunctionDefinition lexer_definitions[] = {
|
|
566
|
+
{
|
|
567
|
+
(uint32_t *)&lexer.advance,
|
|
568
|
+
callback__lexer_advance,
|
|
569
|
+
wasm_functype_new_2_0(wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
(uint32_t *)&lexer.mark_end,
|
|
573
|
+
callback__lexer_mark_end,
|
|
574
|
+
wasm_functype_new_1_0(wasm_valtype_new_i32())
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
(uint32_t *)&lexer.get_column,
|
|
578
|
+
callback__lexer_get_column,
|
|
579
|
+
wasm_functype_new_1_1(wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
(uint32_t *)&lexer.is_at_included_range_start,
|
|
583
|
+
callback__lexer_is_at_included_range_start,
|
|
584
|
+
wasm_functype_new_1_1(wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
(uint32_t *)&lexer.eof,
|
|
588
|
+
callback__lexer_eof,
|
|
589
|
+
wasm_functype_new_1_1(wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
590
|
+
},
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
// Define builtin functions that can be imported by scanners.
|
|
594
|
+
BuiltinFunctionIndices builtin_fn_indices;
|
|
595
|
+
FunctionDefinition builtin_definitions[] = {
|
|
596
|
+
{
|
|
597
|
+
&builtin_fn_indices.proc_exit,
|
|
598
|
+
callback__abort,
|
|
599
|
+
wasm_functype_new_1_0(wasm_valtype_new_i32())
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
&builtin_fn_indices.abort,
|
|
603
|
+
callback__abort,
|
|
604
|
+
wasm_functype_new_0_0()
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
&builtin_fn_indices.assert_fail,
|
|
608
|
+
callback__abort,
|
|
609
|
+
wasm_functype_new_4_0(wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
&builtin_fn_indices.notify_memory_growth,
|
|
613
|
+
callback__noop,
|
|
614
|
+
wasm_functype_new_1_0(wasm_valtype_new_i32())
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
&builtin_fn_indices.debug_message,
|
|
618
|
+
callback__debug_message,
|
|
619
|
+
wasm_functype_new_2_0(wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
&builtin_fn_indices.at_exit,
|
|
623
|
+
callback__noop,
|
|
624
|
+
wasm_functype_new_3_1(wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
&builtin_fn_indices.args_get,
|
|
628
|
+
callback__noop,
|
|
629
|
+
wasm_functype_new_2_1(wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
&builtin_fn_indices.args_sizes_get,
|
|
633
|
+
callback__noop,
|
|
634
|
+
wasm_functype_new_2_1(wasm_valtype_new_i32(), wasm_valtype_new_i32(), wasm_valtype_new_i32())
|
|
635
|
+
},
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// Create all of the wasm functions.
|
|
639
|
+
unsigned builtin_definitions_len = array_len(builtin_definitions);
|
|
640
|
+
unsigned lexer_definitions_len = array_len(lexer_definitions);
|
|
641
|
+
for (unsigned i = 0; i < builtin_definitions_len; i++) {
|
|
642
|
+
FunctionDefinition *definition = &builtin_definitions[i];
|
|
643
|
+
wasmtime_func_t func;
|
|
644
|
+
wasmtime_func_new_unchecked(context, definition->type, definition->callback, self, NULL, &func);
|
|
645
|
+
*definition->storage_location = func.__private;
|
|
646
|
+
wasm_functype_delete(definition->type);
|
|
647
|
+
}
|
|
648
|
+
for (unsigned i = 0; i < lexer_definitions_len; i++) {
|
|
649
|
+
FunctionDefinition *definition = &lexer_definitions[i];
|
|
650
|
+
wasmtime_func_t func;
|
|
651
|
+
wasmtime_func_new_unchecked(context, definition->type, definition->callback, self, NULL, &func);
|
|
652
|
+
*definition->storage_location = func.__private;
|
|
653
|
+
wasm_functype_delete(definition->type);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Compile the stdlib module.
|
|
657
|
+
error = wasmtime_module_new(engine, STDLIB_WASM, STDLIB_WASM_LEN, &stdlib_module);
|
|
658
|
+
if (error) {
|
|
659
|
+
wasmtime_error_message(error, &message);
|
|
660
|
+
wasm_error->kind = TSWasmErrorKindCompile;
|
|
661
|
+
format(
|
|
662
|
+
&wasm_error->message,
|
|
663
|
+
"failed to compile wasm stdlib: %.*s",
|
|
664
|
+
(int)message.size, message.data
|
|
665
|
+
);
|
|
666
|
+
goto error;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// Retrieve the stdlib module's imports.
|
|
670
|
+
wasmtime_module_imports(stdlib_module, &import_types);
|
|
671
|
+
|
|
672
|
+
// Find the initial number of memory pages needed by the stdlib.
|
|
673
|
+
const wasm_memorytype_t *stdlib_memory_type = NULL;
|
|
674
|
+
for (unsigned i = 0; i < import_types.size; i++) {
|
|
675
|
+
wasm_importtype_t *import_type = import_types.data[i];
|
|
676
|
+
const wasm_name_t *import_name = wasm_importtype_name(import_type);
|
|
677
|
+
if (name_eq(import_name, "memory")) {
|
|
678
|
+
const wasm_externtype_t *type = wasm_importtype_type(import_type);
|
|
679
|
+
stdlib_memory_type = wasm_externtype_as_memorytype_const(type);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (!stdlib_memory_type) {
|
|
683
|
+
wasm_error->kind = TSWasmErrorKindCompile;
|
|
684
|
+
format(
|
|
685
|
+
&wasm_error->message,
|
|
686
|
+
"wasm stdlib is missing the 'memory' import"
|
|
687
|
+
);
|
|
688
|
+
goto error;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// Initialize store's memory
|
|
692
|
+
uint64_t initial_memory_pages = wasmtime_memorytype_minimum(stdlib_memory_type);
|
|
693
|
+
wasm_limits_t memory_limits = {.min = initial_memory_pages, .max = MAX_MEMORY_SIZE};
|
|
694
|
+
memory_type = wasm_memorytype_new(&memory_limits);
|
|
695
|
+
wasmtime_memory_t memory;
|
|
696
|
+
error = wasmtime_memory_new(context, memory_type, &memory);
|
|
697
|
+
if (error) {
|
|
698
|
+
wasmtime_error_message(error, &message);
|
|
699
|
+
wasm_error->kind = TSWasmErrorKindAllocate;
|
|
700
|
+
format(
|
|
701
|
+
&wasm_error->message,
|
|
702
|
+
"failed to allocate wasm memory: %.*s",
|
|
703
|
+
(int)message.size, message.data
|
|
704
|
+
);
|
|
705
|
+
goto error;
|
|
706
|
+
}
|
|
707
|
+
wasm_memorytype_delete(memory_type);
|
|
708
|
+
memory_type = NULL;
|
|
709
|
+
|
|
710
|
+
// Initialize store's function table
|
|
711
|
+
wasm_limits_t table_limits = {.min = 1, .max = wasm_limits_max_default};
|
|
712
|
+
table_type = wasm_tabletype_new(wasm_valtype_new(WASM_FUNCREF), &table_limits);
|
|
713
|
+
wasmtime_val_t initializer = {.kind = WASMTIME_FUNCREF};
|
|
714
|
+
wasmtime_table_t function_table;
|
|
715
|
+
error = wasmtime_table_new(context, table_type, &initializer, &function_table);
|
|
716
|
+
if (error) {
|
|
717
|
+
wasmtime_error_message(error, &message);
|
|
718
|
+
wasm_error->kind = TSWasmErrorKindAllocate;
|
|
719
|
+
format(
|
|
720
|
+
&wasm_error->message,
|
|
721
|
+
"failed to allocate wasm table: %.*s",
|
|
722
|
+
(int)message.size, message.data
|
|
723
|
+
);
|
|
724
|
+
goto error;
|
|
725
|
+
}
|
|
726
|
+
wasm_tabletype_delete(table_type);
|
|
727
|
+
table_type = NULL;
|
|
728
|
+
|
|
729
|
+
unsigned stdlib_symbols_len = array_len(STDLIB_SYMBOLS);
|
|
730
|
+
|
|
731
|
+
// Define globals for the stack and heap start addresses.
|
|
732
|
+
wasm_globaltype_t *const_i32_type = wasm_globaltype_new(wasm_valtype_new_i32(), WASM_CONST);
|
|
733
|
+
wasm_globaltype_t *var_i32_type = wasm_globaltype_new(wasm_valtype_new_i32(), WASM_VAR);
|
|
734
|
+
|
|
735
|
+
wasmtime_val_t stack_pointer_value = WASM_I32_VAL(0);
|
|
736
|
+
wasmtime_global_t stack_pointer_global;
|
|
737
|
+
error = wasmtime_global_new(context, var_i32_type, &stack_pointer_value, &stack_pointer_global);
|
|
738
|
+
ts_assert(!error);
|
|
739
|
+
|
|
740
|
+
*self = (TSWasmStore) {
|
|
741
|
+
.engine = wasmtime_engine_clone(engine),
|
|
742
|
+
.store = store,
|
|
743
|
+
.memory = memory,
|
|
744
|
+
.function_table = function_table,
|
|
745
|
+
.language_instances = array_new(),
|
|
746
|
+
.stdlib_fn_indices = ts_calloc(stdlib_symbols_len, sizeof(uint32_t)),
|
|
747
|
+
.builtin_fn_indices = builtin_fn_indices,
|
|
748
|
+
.stack_pointer_global = stack_pointer_global,
|
|
749
|
+
.current_memory_offset = 0,
|
|
750
|
+
.current_function_table_offset = 0,
|
|
751
|
+
.const_i32_type = const_i32_type,
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// Set up the imports for the stdlib module.
|
|
755
|
+
imports = ts_calloc(import_types.size, sizeof(wasmtime_extern_t));
|
|
756
|
+
for (unsigned i = 0; i < import_types.size; i++) {
|
|
757
|
+
wasm_importtype_t *type = import_types.data[i];
|
|
758
|
+
const wasm_name_t *import_name = wasm_importtype_name(type);
|
|
759
|
+
if (!ts_wasm_store__provide_builtin_import(self, import_name, &imports[i])) {
|
|
760
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
761
|
+
format(
|
|
762
|
+
&wasm_error->message,
|
|
763
|
+
"unexpected import in wasm stdlib: %.*s\n",
|
|
764
|
+
(int)import_name->size, import_name->data
|
|
765
|
+
);
|
|
766
|
+
goto error;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// Instantiate the stdlib module.
|
|
771
|
+
wasmtime_instance_t instance;
|
|
772
|
+
error = wasmtime_instance_new(context, stdlib_module, imports, import_types.size, &instance, &trap);
|
|
773
|
+
ts_free(imports);
|
|
774
|
+
imports = NULL;
|
|
775
|
+
if (error) {
|
|
776
|
+
wasmtime_error_message(error, &message);
|
|
777
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
778
|
+
format(
|
|
779
|
+
&wasm_error->message,
|
|
780
|
+
"failed to instantiate wasm stdlib module: %.*s",
|
|
781
|
+
(int)message.size, message.data
|
|
782
|
+
);
|
|
783
|
+
goto error;
|
|
784
|
+
}
|
|
785
|
+
if (trap) {
|
|
786
|
+
wasm_trap_message(trap, &message);
|
|
787
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
788
|
+
format(
|
|
789
|
+
&wasm_error->message,
|
|
790
|
+
"trapped when instantiating wasm stdlib module: %.*s",
|
|
791
|
+
(int)message.size, message.data
|
|
792
|
+
);
|
|
793
|
+
goto error;
|
|
794
|
+
}
|
|
795
|
+
wasm_importtype_vec_delete(&import_types);
|
|
796
|
+
|
|
797
|
+
// Process the stdlib module's exports.
|
|
798
|
+
for (unsigned i = 0; i < stdlib_symbols_len; i++) {
|
|
799
|
+
self->stdlib_fn_indices[i] = UINT32_MAX;
|
|
800
|
+
}
|
|
801
|
+
wasmtime_module_exports(stdlib_module, &export_types);
|
|
802
|
+
for (unsigned i = 0; i < export_types.size; i++) {
|
|
803
|
+
wasm_exporttype_t *export_type = export_types.data[i];
|
|
804
|
+
const wasm_name_t *name = wasm_exporttype_name(export_type);
|
|
805
|
+
|
|
806
|
+
char *export_name;
|
|
807
|
+
size_t name_len;
|
|
808
|
+
wasmtime_extern_t export = {.kind = WASM_EXTERN_GLOBAL};
|
|
809
|
+
bool exists = wasmtime_instance_export_nth(context, &instance, i, &export_name, &name_len, &export);
|
|
810
|
+
ts_assert(exists);
|
|
811
|
+
|
|
812
|
+
if (export.kind == WASMTIME_EXTERN_GLOBAL) {
|
|
813
|
+
if (name_eq(name, "__stack_pointer")) {
|
|
814
|
+
self->stack_pointer_global = export.of.global;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
if (export.kind == WASMTIME_EXTERN_FUNC) {
|
|
819
|
+
if (ts_wasm_store__call_module_initializer(self, name, &export, &trap)) {
|
|
820
|
+
if (trap) {
|
|
821
|
+
wasm_trap_message(trap, &message);
|
|
822
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
823
|
+
format(
|
|
824
|
+
&wasm_error->message,
|
|
825
|
+
"trap when calling stdlib relocation function: %.*s\n",
|
|
826
|
+
(int)message.size, message.data
|
|
827
|
+
);
|
|
828
|
+
goto error;
|
|
829
|
+
}
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
if (name_eq(name, "reset_heap")) {
|
|
834
|
+
self->builtin_fn_indices.reset_heap = export.of.func.__private;
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
for (unsigned j = 0; j < stdlib_symbols_len; j++) {
|
|
839
|
+
if (name_eq(name, STDLIB_SYMBOLS[j])) {
|
|
840
|
+
self->stdlib_fn_indices[j] = export.of.func.__private;
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
if (self->builtin_fn_indices.reset_heap == UINT32_MAX) {
|
|
848
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
849
|
+
format(
|
|
850
|
+
&wasm_error->message,
|
|
851
|
+
"missing malloc reset function in wasm stdlib"
|
|
852
|
+
);
|
|
853
|
+
goto error;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
for (unsigned i = 0; i < stdlib_symbols_len; i++) {
|
|
857
|
+
if (self->stdlib_fn_indices[i] == UINT32_MAX) {
|
|
858
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
859
|
+
format(
|
|
860
|
+
&wasm_error->message,
|
|
861
|
+
"missing exported symbol in wasm stdlib: %s",
|
|
862
|
+
STDLIB_SYMBOLS[i]
|
|
863
|
+
);
|
|
864
|
+
goto error;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
wasm_exporttype_vec_delete(&export_types);
|
|
869
|
+
wasmtime_module_delete(stdlib_module);
|
|
870
|
+
|
|
871
|
+
// Add all of the lexer callback functions to the function table. Store their function table
|
|
872
|
+
// indices on the in-memory lexer.
|
|
873
|
+
uint64_t table_index;
|
|
874
|
+
error = wasmtime_table_grow(context, &function_table, lexer_definitions_len, &initializer, &table_index);
|
|
875
|
+
if (error) {
|
|
876
|
+
wasmtime_error_message(error, &message);
|
|
877
|
+
wasm_error->kind = TSWasmErrorKindAllocate;
|
|
878
|
+
format(
|
|
879
|
+
&wasm_error->message,
|
|
880
|
+
"failed to grow wasm table to initial size: %.*s",
|
|
881
|
+
(int)message.size, message.data
|
|
882
|
+
);
|
|
883
|
+
goto error;
|
|
884
|
+
}
|
|
885
|
+
for (unsigned i = 0; i < lexer_definitions_len; i++) {
|
|
886
|
+
FunctionDefinition *definition = &lexer_definitions[i];
|
|
887
|
+
wasmtime_func_t func = {function_table.store_id, *definition->storage_location};
|
|
888
|
+
wasmtime_val_t func_val = {.kind = WASMTIME_FUNCREF, .of.funcref = func};
|
|
889
|
+
error = wasmtime_table_set(context, &function_table, table_index, &func_val);
|
|
890
|
+
ts_assert(!error);
|
|
891
|
+
*(int32_t *)(definition->storage_location) = table_index;
|
|
892
|
+
table_index++;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
self->current_function_table_offset = table_index;
|
|
896
|
+
self->lexer_address = initial_memory_pages * MEMORY_PAGE_SIZE;
|
|
897
|
+
self->current_memory_offset = self->lexer_address + sizeof(LexerInWasmMemory);
|
|
898
|
+
|
|
899
|
+
// Grow the memory enough to hold the builtin lexer and serialization buffer.
|
|
900
|
+
uint32_t new_pages_needed = (self->current_memory_offset - self->lexer_address - 1) / MEMORY_PAGE_SIZE + 1;
|
|
901
|
+
uint64_t prev_memory_size;
|
|
902
|
+
wasmtime_memory_grow(context, &memory, new_pages_needed, &prev_memory_size);
|
|
903
|
+
|
|
904
|
+
uint8_t *memory_data = wasmtime_memory_data(context, &memory);
|
|
905
|
+
memcpy(&memory_data[self->lexer_address], &lexer, sizeof(lexer));
|
|
906
|
+
return self;
|
|
907
|
+
|
|
908
|
+
error:
|
|
909
|
+
ts_free(self);
|
|
910
|
+
if (stdlib_module) wasmtime_module_delete(stdlib_module);
|
|
911
|
+
if (store) wasmtime_store_delete(store);
|
|
912
|
+
if (import_types.size) wasm_importtype_vec_delete(&import_types);
|
|
913
|
+
if (memory_type) wasm_memorytype_delete(memory_type);
|
|
914
|
+
if (table_type) wasm_tabletype_delete(table_type);
|
|
915
|
+
if (trap) wasm_trap_delete(trap);
|
|
916
|
+
if (error) wasmtime_error_delete(error);
|
|
917
|
+
if (message.size) wasm_byte_vec_delete(&message);
|
|
918
|
+
if (export_types.size) wasm_exporttype_vec_delete(&export_types);
|
|
919
|
+
if (imports) ts_free(imports);
|
|
920
|
+
return NULL;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
void ts_wasm_store_delete(TSWasmStore *self) {
|
|
924
|
+
if (!self) return;
|
|
925
|
+
ts_free(self->stdlib_fn_indices);
|
|
926
|
+
wasm_globaltype_delete(self->const_i32_type);
|
|
927
|
+
wasmtime_store_delete(self->store);
|
|
928
|
+
wasm_engine_delete(self->engine);
|
|
929
|
+
for (unsigned i = 0; i < self->language_instances.size; i++) {
|
|
930
|
+
LanguageWasmInstance *instance = &self->language_instances.contents[i];
|
|
931
|
+
language_id_delete(instance->language_id);
|
|
932
|
+
}
|
|
933
|
+
array_delete(&self->language_instances);
|
|
934
|
+
ts_free(self);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
size_t ts_wasm_store_language_count(const TSWasmStore *self) {
|
|
938
|
+
size_t result = 0;
|
|
939
|
+
for (unsigned i = 0; i < self->language_instances.size; i++) {
|
|
940
|
+
const WasmLanguageId *id = self->language_instances.contents[i].language_id;
|
|
941
|
+
if (!id->is_language_deleted) {
|
|
942
|
+
result++;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return result;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
static uint32_t ts_wasm_store__heap_address(TSWasmStore *self) {
|
|
949
|
+
return self->current_memory_offset + TREE_SITTER_SERIALIZATION_BUFFER_SIZE;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
static uint32_t ts_wasm_store__serialization_buffer_address(TSWasmStore *self) {
|
|
953
|
+
return self->current_memory_offset;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
static bool ts_wasm_store__instantiate(
|
|
957
|
+
TSWasmStore *self,
|
|
958
|
+
wasmtime_module_t *module,
|
|
959
|
+
const char *language_name,
|
|
960
|
+
const WasmDylinkInfo *dylink_info,
|
|
961
|
+
wasmtime_instance_t *result,
|
|
962
|
+
int32_t *language_address,
|
|
963
|
+
char **error_message
|
|
964
|
+
) {
|
|
965
|
+
wasmtime_error_t *error = NULL;
|
|
966
|
+
wasm_trap_t *trap = NULL;
|
|
967
|
+
wasm_message_t message = WASM_EMPTY_VEC;
|
|
968
|
+
char *language_function_name = NULL;
|
|
969
|
+
wasmtime_extern_t *imports = NULL;
|
|
970
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
971
|
+
|
|
972
|
+
// Grow the function table to make room for the new functions.
|
|
973
|
+
wasmtime_val_t initializer = {.kind = WASMTIME_FUNCREF};
|
|
974
|
+
uint64_t prev_table_size;
|
|
975
|
+
error = wasmtime_table_grow(context, &self->function_table, dylink_info->table_size, &initializer, &prev_table_size);
|
|
976
|
+
if (error) {
|
|
977
|
+
format(error_message, "invalid function table size %u", dylink_info->table_size);
|
|
978
|
+
goto error;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// Grow the memory to make room for the new data.
|
|
982
|
+
uint32_t needed_memory_size = ts_wasm_store__heap_address(self) + dylink_info->memory_size;
|
|
983
|
+
uint32_t current_memory_size = wasmtime_memory_data_size(context, &self->memory);
|
|
984
|
+
if (needed_memory_size > current_memory_size) {
|
|
985
|
+
uint32_t pages_to_grow = (
|
|
986
|
+
needed_memory_size - current_memory_size + MEMORY_PAGE_SIZE - 1) /
|
|
987
|
+
MEMORY_PAGE_SIZE;
|
|
988
|
+
uint64_t prev_memory_size;
|
|
989
|
+
error = wasmtime_memory_grow(context, &self->memory, pages_to_grow, &prev_memory_size);
|
|
990
|
+
if (error) {
|
|
991
|
+
format(error_message, "invalid memory size %u", dylink_info->memory_size);
|
|
992
|
+
goto error;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// Construct the language function name as string.
|
|
997
|
+
format(&language_function_name, "tree_sitter_%s", language_name);
|
|
998
|
+
|
|
999
|
+
const uint64_t store_id = self->function_table.store_id;
|
|
1000
|
+
|
|
1001
|
+
// Build the imports list for the module.
|
|
1002
|
+
wasm_importtype_vec_t import_types = WASM_EMPTY_VEC;
|
|
1003
|
+
wasmtime_module_imports(module, &import_types);
|
|
1004
|
+
imports = ts_calloc(import_types.size, sizeof(wasmtime_extern_t));
|
|
1005
|
+
|
|
1006
|
+
for (unsigned i = 0; i < import_types.size; i++) {
|
|
1007
|
+
const wasm_importtype_t *import_type = import_types.data[i];
|
|
1008
|
+
const wasm_name_t *import_name = wasm_importtype_name(import_type);
|
|
1009
|
+
if (import_name->size == 0) {
|
|
1010
|
+
format(error_message, "empty import name");
|
|
1011
|
+
goto error;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
if (ts_wasm_store__provide_builtin_import(self, import_name, &imports[i])) {
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
bool defined_in_stdlib = false;
|
|
1019
|
+
for (unsigned j = 0; j < array_len(STDLIB_SYMBOLS); j++) {
|
|
1020
|
+
if (name_eq(import_name, STDLIB_SYMBOLS[j])) {
|
|
1021
|
+
uint16_t address = self->stdlib_fn_indices[j];
|
|
1022
|
+
imports[i] = (wasmtime_extern_t) {.kind = WASMTIME_EXTERN_FUNC, .of.func = {store_id, address}};
|
|
1023
|
+
defined_in_stdlib = true;
|
|
1024
|
+
break;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
if (!defined_in_stdlib) {
|
|
1029
|
+
format(
|
|
1030
|
+
error_message,
|
|
1031
|
+
"invalid import '%.*s'\n",
|
|
1032
|
+
(int)import_name->size, import_name->data
|
|
1033
|
+
);
|
|
1034
|
+
goto error;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
wasmtime_instance_t instance;
|
|
1039
|
+
error = wasmtime_instance_new(context, module, imports, import_types.size, &instance, &trap);
|
|
1040
|
+
wasm_importtype_vec_delete(&import_types);
|
|
1041
|
+
ts_free(imports);
|
|
1042
|
+
imports = NULL;
|
|
1043
|
+
if (error) {
|
|
1044
|
+
wasmtime_error_message(error, &message);
|
|
1045
|
+
format(
|
|
1046
|
+
error_message,
|
|
1047
|
+
"error instantiating wasm module: %.*s\n",
|
|
1048
|
+
(int)message.size, message.data
|
|
1049
|
+
);
|
|
1050
|
+
goto error;
|
|
1051
|
+
}
|
|
1052
|
+
if (trap) {
|
|
1053
|
+
wasm_trap_message(trap, &message);
|
|
1054
|
+
format(
|
|
1055
|
+
error_message,
|
|
1056
|
+
"trap when instantiating wasm module: %.*s\n",
|
|
1057
|
+
(int)message.size, message.data
|
|
1058
|
+
);
|
|
1059
|
+
goto error;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
self->current_memory_offset += dylink_info->memory_size;
|
|
1063
|
+
self->current_function_table_offset += dylink_info->table_size;
|
|
1064
|
+
|
|
1065
|
+
// Process the module's exports.
|
|
1066
|
+
bool found_language = false;
|
|
1067
|
+
wasmtime_extern_t language_extern;
|
|
1068
|
+
wasm_exporttype_vec_t export_types = WASM_EMPTY_VEC;
|
|
1069
|
+
wasmtime_module_exports(module, &export_types);
|
|
1070
|
+
for (unsigned i = 0; i < export_types.size; i++) {
|
|
1071
|
+
wasm_exporttype_t *export_type = export_types.data[i];
|
|
1072
|
+
const wasm_name_t *name = wasm_exporttype_name(export_type);
|
|
1073
|
+
|
|
1074
|
+
size_t name_len;
|
|
1075
|
+
char *export_name;
|
|
1076
|
+
wasmtime_extern_t export = {.kind = WASM_EXTERN_GLOBAL};
|
|
1077
|
+
bool exists = wasmtime_instance_export_nth(context, &instance, i, &export_name, &name_len, &export);
|
|
1078
|
+
ts_assert(exists);
|
|
1079
|
+
|
|
1080
|
+
// If the module exports an initialization or data-relocation function, call it.
|
|
1081
|
+
if (ts_wasm_store__call_module_initializer(self, name, &export, &trap)) {
|
|
1082
|
+
if (trap) {
|
|
1083
|
+
wasm_trap_message(trap, &message);
|
|
1084
|
+
format(
|
|
1085
|
+
error_message,
|
|
1086
|
+
"trap when calling data relocation function: %.*s\n",
|
|
1087
|
+
(int)message.size, message.data
|
|
1088
|
+
);
|
|
1089
|
+
goto error;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// Find the main language function for the module.
|
|
1094
|
+
else if (name_eq(name, language_function_name)) {
|
|
1095
|
+
language_extern = export;
|
|
1096
|
+
found_language = true;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
wasm_exporttype_vec_delete(&export_types);
|
|
1100
|
+
|
|
1101
|
+
if (!found_language) {
|
|
1102
|
+
format(
|
|
1103
|
+
error_message,
|
|
1104
|
+
"module did not contain language function: %s",
|
|
1105
|
+
language_function_name
|
|
1106
|
+
);
|
|
1107
|
+
goto error;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// Invoke the language function to get the static address of the language object.
|
|
1111
|
+
wasmtime_func_t language_func = language_extern.of.func;
|
|
1112
|
+
wasmtime_val_t language_address_val;
|
|
1113
|
+
error = wasmtime_func_call(context, &language_func, NULL, 0, &language_address_val, 1, &trap);
|
|
1114
|
+
ts_assert(!error);
|
|
1115
|
+
if (trap) {
|
|
1116
|
+
wasm_trap_message(trap, &message);
|
|
1117
|
+
format(
|
|
1118
|
+
error_message,
|
|
1119
|
+
"trapped when calling language function: %s: %.*s\n",
|
|
1120
|
+
language_function_name, (int)message.size, message.data
|
|
1121
|
+
);
|
|
1122
|
+
goto error;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
if (language_address_val.kind != WASMTIME_I32) {
|
|
1126
|
+
format(
|
|
1127
|
+
error_message,
|
|
1128
|
+
"language function did not return an integer: %s\n",
|
|
1129
|
+
language_function_name
|
|
1130
|
+
);
|
|
1131
|
+
goto error;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
ts_free(language_function_name);
|
|
1135
|
+
*result = instance;
|
|
1136
|
+
*language_address = language_address_val.of.i32;
|
|
1137
|
+
return true;
|
|
1138
|
+
|
|
1139
|
+
error:
|
|
1140
|
+
if (language_function_name) ts_free(language_function_name);
|
|
1141
|
+
if (message.size) wasm_byte_vec_delete(&message);
|
|
1142
|
+
if (error) wasmtime_error_delete(error);
|
|
1143
|
+
if (trap) wasm_trap_delete(trap);
|
|
1144
|
+
if (imports) ts_free(imports);
|
|
1145
|
+
return false;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
static bool ts_wasm_store__sentinel_lex_fn(TSLexer *_lexer, TSStateId state) {
|
|
1149
|
+
return false;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
const TSLanguage *ts_wasm_store_load_language(
|
|
1153
|
+
TSWasmStore *self,
|
|
1154
|
+
const char *language_name,
|
|
1155
|
+
const char *wasm,
|
|
1156
|
+
uint32_t wasm_len,
|
|
1157
|
+
TSWasmError *wasm_error
|
|
1158
|
+
) {
|
|
1159
|
+
WasmDylinkInfo dylink_info;
|
|
1160
|
+
wasmtime_module_t *module = NULL;
|
|
1161
|
+
wasmtime_error_t *error = NULL;
|
|
1162
|
+
wasm_error->kind = TSWasmErrorKindNone;
|
|
1163
|
+
|
|
1164
|
+
if (!wasm_dylink_info__parse((const unsigned char *)wasm, wasm_len, &dylink_info)) {
|
|
1165
|
+
wasm_error->kind = TSWasmErrorKindParse;
|
|
1166
|
+
format(&wasm_error->message, "failed to parse dylink section of wasm module");
|
|
1167
|
+
goto error;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// Compile the wasm code.
|
|
1171
|
+
error = wasmtime_module_new(self->engine, (const uint8_t *)wasm, wasm_len, &module);
|
|
1172
|
+
if (error) {
|
|
1173
|
+
wasm_message_t message;
|
|
1174
|
+
wasmtime_error_message(error, &message);
|
|
1175
|
+
wasm_error->kind = TSWasmErrorKindCompile;
|
|
1176
|
+
format(&wasm_error->message, "error compiling wasm module: %.*s", (int)message.size, message.data);
|
|
1177
|
+
wasm_byte_vec_delete(&message);
|
|
1178
|
+
goto error;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// Instantiate the module in this store.
|
|
1182
|
+
wasmtime_instance_t instance;
|
|
1183
|
+
int32_t language_address;
|
|
1184
|
+
if (!ts_wasm_store__instantiate(
|
|
1185
|
+
self,
|
|
1186
|
+
module,
|
|
1187
|
+
language_name,
|
|
1188
|
+
&dylink_info,
|
|
1189
|
+
&instance,
|
|
1190
|
+
&language_address,
|
|
1191
|
+
&wasm_error->message
|
|
1192
|
+
)) {
|
|
1193
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
1194
|
+
goto error;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
// Copy all of the static data out of the language object in wasm memory,
|
|
1198
|
+
// constructing a native language object.
|
|
1199
|
+
LanguageInWasmMemory wasm_language;
|
|
1200
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1201
|
+
const uint8_t *memory = wasmtime_memory_data(context, &self->memory);
|
|
1202
|
+
memcpy(&wasm_language, &memory[language_address], sizeof(LanguageInWasmMemory));
|
|
1203
|
+
|
|
1204
|
+
if (wasm_language.version < LANGUAGE_VERSION_USABLE_VIA_WASM) {
|
|
1205
|
+
wasm_error->kind = TSWasmErrorKindInstantiate;
|
|
1206
|
+
format(&wasm_error->message, "language version %u is too old for wasm", wasm_language.version);
|
|
1207
|
+
goto error;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
int32_t addresses[] = {
|
|
1211
|
+
wasm_language.alias_map,
|
|
1212
|
+
wasm_language.alias_sequences,
|
|
1213
|
+
wasm_language.field_map_entries,
|
|
1214
|
+
wasm_language.field_map_slices,
|
|
1215
|
+
wasm_language.field_names,
|
|
1216
|
+
wasm_language.keyword_lex_fn,
|
|
1217
|
+
wasm_language.lex_fn,
|
|
1218
|
+
wasm_language.lex_modes,
|
|
1219
|
+
wasm_language.parse_actions,
|
|
1220
|
+
wasm_language.parse_table,
|
|
1221
|
+
wasm_language.primary_state_ids,
|
|
1222
|
+
wasm_language.primary_state_ids,
|
|
1223
|
+
wasm_language.public_symbol_map,
|
|
1224
|
+
wasm_language.small_parse_table,
|
|
1225
|
+
wasm_language.small_parse_table_map,
|
|
1226
|
+
wasm_language.symbol_metadata,
|
|
1227
|
+
wasm_language.symbol_metadata,
|
|
1228
|
+
wasm_language.symbol_names,
|
|
1229
|
+
wasm_language.external_token_count > 0 ? wasm_language.external_scanner.states : 0,
|
|
1230
|
+
wasm_language.external_token_count > 0 ? wasm_language.external_scanner.symbol_map : 0,
|
|
1231
|
+
wasm_language.external_token_count > 0 ? wasm_language.external_scanner.create : 0,
|
|
1232
|
+
wasm_language.external_token_count > 0 ? wasm_language.external_scanner.destroy : 0,
|
|
1233
|
+
wasm_language.external_token_count > 0 ? wasm_language.external_scanner.scan : 0,
|
|
1234
|
+
wasm_language.external_token_count > 0 ? wasm_language.external_scanner.serialize : 0,
|
|
1235
|
+
wasm_language.external_token_count > 0 ? wasm_language.external_scanner.deserialize : 0,
|
|
1236
|
+
language_address,
|
|
1237
|
+
self->current_memory_offset,
|
|
1238
|
+
};
|
|
1239
|
+
uint32_t address_count = array_len(addresses);
|
|
1240
|
+
|
|
1241
|
+
TSLanguage *language = ts_calloc(1, sizeof(TSLanguage));
|
|
1242
|
+
StringData symbol_name_buffer = array_new();
|
|
1243
|
+
StringData field_name_buffer = array_new();
|
|
1244
|
+
|
|
1245
|
+
*language = (TSLanguage) {
|
|
1246
|
+
.version = wasm_language.version,
|
|
1247
|
+
.symbol_count = wasm_language.symbol_count,
|
|
1248
|
+
.alias_count = wasm_language.alias_count,
|
|
1249
|
+
.token_count = wasm_language.token_count,
|
|
1250
|
+
.external_token_count = wasm_language.external_token_count,
|
|
1251
|
+
.state_count = wasm_language.state_count,
|
|
1252
|
+
.large_state_count = wasm_language.large_state_count,
|
|
1253
|
+
.production_id_count = wasm_language.production_id_count,
|
|
1254
|
+
.field_count = wasm_language.field_count,
|
|
1255
|
+
.max_alias_sequence_length = wasm_language.max_alias_sequence_length,
|
|
1256
|
+
.keyword_capture_token = wasm_language.keyword_capture_token,
|
|
1257
|
+
.parse_table = copy(
|
|
1258
|
+
&memory[wasm_language.parse_table],
|
|
1259
|
+
wasm_language.large_state_count * wasm_language.symbol_count * sizeof(uint16_t)
|
|
1260
|
+
),
|
|
1261
|
+
.parse_actions = copy_unsized_static_array(
|
|
1262
|
+
memory,
|
|
1263
|
+
wasm_language.parse_actions,
|
|
1264
|
+
addresses,
|
|
1265
|
+
address_count
|
|
1266
|
+
),
|
|
1267
|
+
.symbol_names = copy_strings(
|
|
1268
|
+
memory,
|
|
1269
|
+
wasm_language.symbol_names,
|
|
1270
|
+
wasm_language.symbol_count + wasm_language.alias_count,
|
|
1271
|
+
&symbol_name_buffer
|
|
1272
|
+
),
|
|
1273
|
+
.symbol_metadata = copy(
|
|
1274
|
+
&memory[wasm_language.symbol_metadata],
|
|
1275
|
+
(wasm_language.symbol_count + wasm_language.alias_count) * sizeof(TSSymbolMetadata)
|
|
1276
|
+
),
|
|
1277
|
+
.public_symbol_map = copy(
|
|
1278
|
+
&memory[wasm_language.public_symbol_map],
|
|
1279
|
+
(wasm_language.symbol_count + wasm_language.alias_count) * sizeof(TSSymbol)
|
|
1280
|
+
),
|
|
1281
|
+
.lex_modes = copy(
|
|
1282
|
+
&memory[wasm_language.lex_modes],
|
|
1283
|
+
wasm_language.state_count * sizeof(TSLexMode)
|
|
1284
|
+
),
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1287
|
+
if (language->field_count > 0 && language->production_id_count > 0) {
|
|
1288
|
+
language->field_map_slices = copy(
|
|
1289
|
+
&memory[wasm_language.field_map_slices],
|
|
1290
|
+
wasm_language.production_id_count * sizeof(TSFieldMapSlice)
|
|
1291
|
+
);
|
|
1292
|
+
|
|
1293
|
+
// Determine the number of field map entries by finding the greatest index
|
|
1294
|
+
// in any of the slices.
|
|
1295
|
+
uint32_t field_map_entry_count = 0;
|
|
1296
|
+
for (uint32_t i = 0; i < wasm_language.production_id_count; i++) {
|
|
1297
|
+
TSFieldMapSlice slice = language->field_map_slices[i];
|
|
1298
|
+
uint32_t slice_end = slice.index + slice.length;
|
|
1299
|
+
if (slice_end > field_map_entry_count) {
|
|
1300
|
+
field_map_entry_count = slice_end;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
language->field_map_entries = copy(
|
|
1305
|
+
&memory[wasm_language.field_map_entries],
|
|
1306
|
+
field_map_entry_count * sizeof(TSFieldMapEntry)
|
|
1307
|
+
);
|
|
1308
|
+
language->field_names = copy_strings(
|
|
1309
|
+
memory,
|
|
1310
|
+
wasm_language.field_names,
|
|
1311
|
+
wasm_language.field_count + 1,
|
|
1312
|
+
&field_name_buffer
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
if (language->max_alias_sequence_length > 0 && language->production_id_count > 0) {
|
|
1317
|
+
// The alias map contains symbols, alias counts, and aliases, terminated by a null symbol.
|
|
1318
|
+
int32_t alias_map_size = 0;
|
|
1319
|
+
for (;;) {
|
|
1320
|
+
TSSymbol symbol;
|
|
1321
|
+
memcpy(&symbol, &memory[wasm_language.alias_map + alias_map_size], sizeof(symbol));
|
|
1322
|
+
alias_map_size += sizeof(TSSymbol);
|
|
1323
|
+
if (symbol == 0) break;
|
|
1324
|
+
uint16_t value_count;
|
|
1325
|
+
memcpy(&value_count, &memory[wasm_language.alias_map + alias_map_size], sizeof(value_count));
|
|
1326
|
+
alias_map_size += value_count * sizeof(TSSymbol);
|
|
1327
|
+
}
|
|
1328
|
+
language->alias_map = copy(
|
|
1329
|
+
&memory[wasm_language.alias_map],
|
|
1330
|
+
alias_map_size * sizeof(TSSymbol)
|
|
1331
|
+
);
|
|
1332
|
+
language->alias_sequences = copy(
|
|
1333
|
+
&memory[wasm_language.alias_sequences],
|
|
1334
|
+
wasm_language.production_id_count * wasm_language.max_alias_sequence_length * sizeof(TSSymbol)
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
if (language->state_count > language->large_state_count) {
|
|
1339
|
+
uint32_t small_state_count = wasm_language.state_count - wasm_language.large_state_count;
|
|
1340
|
+
language->small_parse_table_map = copy(
|
|
1341
|
+
&memory[wasm_language.small_parse_table_map],
|
|
1342
|
+
small_state_count * sizeof(uint32_t)
|
|
1343
|
+
);
|
|
1344
|
+
language->small_parse_table = copy_unsized_static_array(
|
|
1345
|
+
memory,
|
|
1346
|
+
wasm_language.small_parse_table,
|
|
1347
|
+
addresses,
|
|
1348
|
+
address_count
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
if (language->version >= LANGUAGE_VERSION_WITH_PRIMARY_STATES) {
|
|
1353
|
+
language->primary_state_ids = copy(
|
|
1354
|
+
&memory[wasm_language.primary_state_ids],
|
|
1355
|
+
wasm_language.state_count * sizeof(TSStateId)
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
if (language->external_token_count > 0) {
|
|
1360
|
+
language->external_scanner.symbol_map = copy(
|
|
1361
|
+
&memory[wasm_language.external_scanner.symbol_map],
|
|
1362
|
+
wasm_language.external_token_count * sizeof(TSSymbol)
|
|
1363
|
+
);
|
|
1364
|
+
language->external_scanner.states = (void *)(uintptr_t)wasm_language.external_scanner.states;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
unsigned name_len = strlen(language_name);
|
|
1368
|
+
char *name = ts_malloc(name_len + 1);
|
|
1369
|
+
memcpy(name, language_name, name_len);
|
|
1370
|
+
name[name_len] = '\0';
|
|
1371
|
+
|
|
1372
|
+
LanguageWasmModule *language_module = ts_malloc(sizeof(LanguageWasmModule));
|
|
1373
|
+
*language_module = (LanguageWasmModule) {
|
|
1374
|
+
.language_id = language_id_new(),
|
|
1375
|
+
.module = module,
|
|
1376
|
+
.name = name,
|
|
1377
|
+
.symbol_name_buffer = symbol_name_buffer.contents,
|
|
1378
|
+
.field_name_buffer = field_name_buffer.contents,
|
|
1379
|
+
.dylink_info = dylink_info,
|
|
1380
|
+
.ref_count = 1,
|
|
1381
|
+
};
|
|
1382
|
+
|
|
1383
|
+
// The lex functions are not used for wasm languages. Use those two fields
|
|
1384
|
+
// to mark this language as WASM-based and to store the language's
|
|
1385
|
+
// WASM-specific data.
|
|
1386
|
+
language->lex_fn = ts_wasm_store__sentinel_lex_fn;
|
|
1387
|
+
language->keyword_lex_fn = (bool (*)(TSLexer *, TSStateId))language_module;
|
|
1388
|
+
|
|
1389
|
+
// Clear out any instances of languages that have been deleted.
|
|
1390
|
+
for (unsigned i = 0; i < self->language_instances.size; i++) {
|
|
1391
|
+
WasmLanguageId *id = self->language_instances.contents[i].language_id;
|
|
1392
|
+
if (id->is_language_deleted) {
|
|
1393
|
+
language_id_delete(id);
|
|
1394
|
+
array_erase(&self->language_instances, i);
|
|
1395
|
+
i--;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// Store this store's instance of this language module.
|
|
1400
|
+
array_push(&self->language_instances, ((LanguageWasmInstance) {
|
|
1401
|
+
.language_id = language_id_clone(language_module->language_id),
|
|
1402
|
+
.instance = instance,
|
|
1403
|
+
.external_states_address = wasm_language.external_scanner.states,
|
|
1404
|
+
.lex_main_fn_index = wasm_language.lex_fn,
|
|
1405
|
+
.lex_keyword_fn_index = wasm_language.keyword_lex_fn,
|
|
1406
|
+
.scanner_create_fn_index = wasm_language.external_scanner.create,
|
|
1407
|
+
.scanner_destroy_fn_index = wasm_language.external_scanner.destroy,
|
|
1408
|
+
.scanner_serialize_fn_index = wasm_language.external_scanner.serialize,
|
|
1409
|
+
.scanner_deserialize_fn_index = wasm_language.external_scanner.deserialize,
|
|
1410
|
+
.scanner_scan_fn_index = wasm_language.external_scanner.scan,
|
|
1411
|
+
}));
|
|
1412
|
+
|
|
1413
|
+
return language;
|
|
1414
|
+
|
|
1415
|
+
error:
|
|
1416
|
+
if (module) wasmtime_module_delete(module);
|
|
1417
|
+
return NULL;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
bool ts_wasm_store_add_language(
|
|
1421
|
+
TSWasmStore *self,
|
|
1422
|
+
const TSLanguage *language,
|
|
1423
|
+
uint32_t *index
|
|
1424
|
+
) {
|
|
1425
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1426
|
+
const LanguageWasmModule *language_module = (void *)language->keyword_lex_fn;
|
|
1427
|
+
|
|
1428
|
+
// Search for this store's instance of the language module. Also clear out any
|
|
1429
|
+
// instances of languages that have been deleted.
|
|
1430
|
+
bool exists = false;
|
|
1431
|
+
for (unsigned i = 0; i < self->language_instances.size; i++) {
|
|
1432
|
+
WasmLanguageId *id = self->language_instances.contents[i].language_id;
|
|
1433
|
+
if (id->is_language_deleted) {
|
|
1434
|
+
language_id_delete(id);
|
|
1435
|
+
array_erase(&self->language_instances, i);
|
|
1436
|
+
i--;
|
|
1437
|
+
} else if (id == language_module->language_id) {
|
|
1438
|
+
exists = true;
|
|
1439
|
+
*index = i;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// If the language module has not been instantiated in this store, then add
|
|
1444
|
+
// it to this store.
|
|
1445
|
+
if (!exists) {
|
|
1446
|
+
*index = self->language_instances.size;
|
|
1447
|
+
char *message;
|
|
1448
|
+
wasmtime_instance_t instance;
|
|
1449
|
+
int32_t language_address;
|
|
1450
|
+
if (!ts_wasm_store__instantiate(
|
|
1451
|
+
self,
|
|
1452
|
+
language_module->module,
|
|
1453
|
+
language_module->name,
|
|
1454
|
+
&language_module->dylink_info,
|
|
1455
|
+
&instance,
|
|
1456
|
+
&language_address,
|
|
1457
|
+
&message
|
|
1458
|
+
)) {
|
|
1459
|
+
ts_free(message);
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
LanguageInWasmMemory wasm_language;
|
|
1464
|
+
const uint8_t *memory = wasmtime_memory_data(context, &self->memory);
|
|
1465
|
+
memcpy(&wasm_language, &memory[language_address], sizeof(LanguageInWasmMemory));
|
|
1466
|
+
array_push(&self->language_instances, ((LanguageWasmInstance) {
|
|
1467
|
+
.language_id = language_id_clone(language_module->language_id),
|
|
1468
|
+
.instance = instance,
|
|
1469
|
+
.external_states_address = wasm_language.external_scanner.states,
|
|
1470
|
+
.lex_main_fn_index = wasm_language.lex_fn,
|
|
1471
|
+
.lex_keyword_fn_index = wasm_language.keyword_lex_fn,
|
|
1472
|
+
.scanner_create_fn_index = wasm_language.external_scanner.create,
|
|
1473
|
+
.scanner_destroy_fn_index = wasm_language.external_scanner.destroy,
|
|
1474
|
+
.scanner_serialize_fn_index = wasm_language.external_scanner.serialize,
|
|
1475
|
+
.scanner_deserialize_fn_index = wasm_language.external_scanner.deserialize,
|
|
1476
|
+
.scanner_scan_fn_index = wasm_language.external_scanner.scan,
|
|
1477
|
+
}));
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
return true;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
void ts_wasm_store_reset_heap(TSWasmStore *self) {
|
|
1484
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1485
|
+
wasmtime_func_t func = {
|
|
1486
|
+
self->function_table.store_id,
|
|
1487
|
+
self->builtin_fn_indices.reset_heap
|
|
1488
|
+
};
|
|
1489
|
+
wasm_trap_t *trap = NULL;
|
|
1490
|
+
wasmtime_val_t args[1] = {
|
|
1491
|
+
{.of.i32 = ts_wasm_store__heap_address(self), .kind = WASMTIME_I32},
|
|
1492
|
+
};
|
|
1493
|
+
|
|
1494
|
+
wasmtime_error_t *error = wasmtime_func_call(context, &func, args, 1, NULL, 0, &trap);
|
|
1495
|
+
ts_assert(!error);
|
|
1496
|
+
ts_assert(!trap);
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
bool ts_wasm_store_start(TSWasmStore *self, TSLexer *lexer, const TSLanguage *language) {
|
|
1500
|
+
uint32_t instance_index;
|
|
1501
|
+
if (!ts_wasm_store_add_language(self, language, &instance_index)) return false;
|
|
1502
|
+
self->current_lexer = lexer;
|
|
1503
|
+
self->current_instance = &self->language_instances.contents[instance_index];
|
|
1504
|
+
self->has_error = false;
|
|
1505
|
+
ts_wasm_store_reset_heap(self);
|
|
1506
|
+
return true;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
void ts_wasm_store_reset(TSWasmStore *self) {
|
|
1510
|
+
self->current_lexer = NULL;
|
|
1511
|
+
self->current_instance = NULL;
|
|
1512
|
+
self->has_error = false;
|
|
1513
|
+
ts_wasm_store_reset_heap(self);
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
static void ts_wasm_store__call(
|
|
1517
|
+
TSWasmStore *self,
|
|
1518
|
+
int32_t function_index,
|
|
1519
|
+
wasmtime_val_raw_t *args_and_results,
|
|
1520
|
+
size_t args_and_results_len
|
|
1521
|
+
) {
|
|
1522
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1523
|
+
wasmtime_val_t value;
|
|
1524
|
+
bool succeeded = wasmtime_table_get(context, &self->function_table, function_index, &value);
|
|
1525
|
+
ts_assert(succeeded);
|
|
1526
|
+
ts_assert(value.kind == WASMTIME_FUNCREF);
|
|
1527
|
+
wasmtime_func_t func = value.of.funcref;
|
|
1528
|
+
|
|
1529
|
+
wasm_trap_t *trap = NULL;
|
|
1530
|
+
wasmtime_error_t *error = wasmtime_func_call_unchecked(context, &func, args_and_results, args_and_results_len, &trap);
|
|
1531
|
+
if (error) {
|
|
1532
|
+
// wasm_message_t message;
|
|
1533
|
+
// wasmtime_error_message(error, &message);
|
|
1534
|
+
// fprintf(
|
|
1535
|
+
// stderr,
|
|
1536
|
+
// "error in wasm module: %.*s\n",
|
|
1537
|
+
// (int)message.size, message.data
|
|
1538
|
+
// );
|
|
1539
|
+
wasmtime_error_delete(error);
|
|
1540
|
+
self->has_error = true;
|
|
1541
|
+
} else if (trap) {
|
|
1542
|
+
// wasm_message_t message;
|
|
1543
|
+
// wasm_trap_message(trap, &message);
|
|
1544
|
+
// fprintf(
|
|
1545
|
+
// stderr,
|
|
1546
|
+
// "trap in wasm module: %.*s\n",
|
|
1547
|
+
// (int)message.size, message.data
|
|
1548
|
+
// );
|
|
1549
|
+
wasm_trap_delete(trap);
|
|
1550
|
+
self->has_error = true;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
static bool ts_wasm_store__call_lex_function(TSWasmStore *self, unsigned function_index, TSStateId state) {
|
|
1555
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1556
|
+
uint8_t *memory_data = wasmtime_memory_data(context, &self->memory);
|
|
1557
|
+
memcpy(
|
|
1558
|
+
&memory_data[self->lexer_address],
|
|
1559
|
+
&self->current_lexer->lookahead,
|
|
1560
|
+
sizeof(self->current_lexer->lookahead)
|
|
1561
|
+
);
|
|
1562
|
+
|
|
1563
|
+
wasmtime_val_raw_t args[2] = {
|
|
1564
|
+
{.i32 = self->lexer_address},
|
|
1565
|
+
{.i32 = state},
|
|
1566
|
+
};
|
|
1567
|
+
ts_wasm_store__call(self, function_index, args, 2);
|
|
1568
|
+
if (self->has_error) return false;
|
|
1569
|
+
bool result = args[0].i32;
|
|
1570
|
+
|
|
1571
|
+
memcpy(
|
|
1572
|
+
&self->current_lexer->lookahead,
|
|
1573
|
+
&memory_data[self->lexer_address],
|
|
1574
|
+
sizeof(self->current_lexer->lookahead) + sizeof(self->current_lexer->result_symbol)
|
|
1575
|
+
);
|
|
1576
|
+
return result;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
bool ts_wasm_store_call_lex_main(TSWasmStore *self, TSStateId state) {
|
|
1580
|
+
return ts_wasm_store__call_lex_function(
|
|
1581
|
+
self,
|
|
1582
|
+
self->current_instance->lex_main_fn_index,
|
|
1583
|
+
state
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
bool ts_wasm_store_call_lex_keyword(TSWasmStore *self, TSStateId state) {
|
|
1588
|
+
return ts_wasm_store__call_lex_function(
|
|
1589
|
+
self,
|
|
1590
|
+
self->current_instance->lex_keyword_fn_index,
|
|
1591
|
+
state
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
uint32_t ts_wasm_store_call_scanner_create(TSWasmStore *self) {
|
|
1596
|
+
wasmtime_val_raw_t args[1] = {{.i32 = 0}};
|
|
1597
|
+
ts_wasm_store__call(self, self->current_instance->scanner_create_fn_index, args, 1);
|
|
1598
|
+
if (self->has_error) return 0;
|
|
1599
|
+
return args[0].i32;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
void ts_wasm_store_call_scanner_destroy(TSWasmStore *self, uint32_t scanner_address) {
|
|
1603
|
+
if (self->current_instance) {
|
|
1604
|
+
wasmtime_val_raw_t args[1] = {{.i32 = scanner_address}};
|
|
1605
|
+
ts_wasm_store__call(self, self->current_instance->scanner_destroy_fn_index, args, 1);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
bool ts_wasm_store_call_scanner_scan(
|
|
1610
|
+
TSWasmStore *self,
|
|
1611
|
+
uint32_t scanner_address,
|
|
1612
|
+
uint32_t valid_tokens_ix
|
|
1613
|
+
) {
|
|
1614
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1615
|
+
uint8_t *memory_data = wasmtime_memory_data(context, &self->memory);
|
|
1616
|
+
|
|
1617
|
+
memcpy(
|
|
1618
|
+
&memory_data[self->lexer_address],
|
|
1619
|
+
&self->current_lexer->lookahead,
|
|
1620
|
+
sizeof(self->current_lexer->lookahead)
|
|
1621
|
+
);
|
|
1622
|
+
|
|
1623
|
+
uint32_t valid_tokens_address =
|
|
1624
|
+
self->current_instance->external_states_address +
|
|
1625
|
+
(valid_tokens_ix * sizeof(bool));
|
|
1626
|
+
wasmtime_val_raw_t args[3] = {
|
|
1627
|
+
{.i32 = scanner_address},
|
|
1628
|
+
{.i32 = self->lexer_address},
|
|
1629
|
+
{.i32 = valid_tokens_address}
|
|
1630
|
+
};
|
|
1631
|
+
ts_wasm_store__call(self, self->current_instance->scanner_scan_fn_index, args, 3);
|
|
1632
|
+
if (self->has_error) return false;
|
|
1633
|
+
|
|
1634
|
+
memcpy(
|
|
1635
|
+
&self->current_lexer->lookahead,
|
|
1636
|
+
&memory_data[self->lexer_address],
|
|
1637
|
+
sizeof(self->current_lexer->lookahead) + sizeof(self->current_lexer->result_symbol)
|
|
1638
|
+
);
|
|
1639
|
+
return args[0].i32;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
uint32_t ts_wasm_store_call_scanner_serialize(
|
|
1643
|
+
TSWasmStore *self,
|
|
1644
|
+
uint32_t scanner_address,
|
|
1645
|
+
char *buffer
|
|
1646
|
+
) {
|
|
1647
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1648
|
+
uint8_t *memory_data = wasmtime_memory_data(context, &self->memory);
|
|
1649
|
+
uint32_t serialization_buffer_address = ts_wasm_store__serialization_buffer_address(self);
|
|
1650
|
+
|
|
1651
|
+
wasmtime_val_raw_t args[2] = {
|
|
1652
|
+
{.i32 = scanner_address},
|
|
1653
|
+
{.i32 = serialization_buffer_address},
|
|
1654
|
+
};
|
|
1655
|
+
ts_wasm_store__call(self, self->current_instance->scanner_serialize_fn_index, args, 2);
|
|
1656
|
+
if (self->has_error) return 0;
|
|
1657
|
+
|
|
1658
|
+
uint32_t length = args[0].i32;
|
|
1659
|
+
if (length > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) {
|
|
1660
|
+
self->has_error = true;
|
|
1661
|
+
return 0;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
if (length > 0) {
|
|
1665
|
+
memcpy(
|
|
1666
|
+
((Lexer *)self->current_lexer)->debug_buffer,
|
|
1667
|
+
&memory_data[serialization_buffer_address],
|
|
1668
|
+
length
|
|
1669
|
+
);
|
|
1670
|
+
}
|
|
1671
|
+
return length;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
void ts_wasm_store_call_scanner_deserialize(
|
|
1675
|
+
TSWasmStore *self,
|
|
1676
|
+
uint32_t scanner_address,
|
|
1677
|
+
const char *buffer,
|
|
1678
|
+
unsigned length
|
|
1679
|
+
) {
|
|
1680
|
+
wasmtime_context_t *context = wasmtime_store_context(self->store);
|
|
1681
|
+
uint8_t *memory_data = wasmtime_memory_data(context, &self->memory);
|
|
1682
|
+
uint32_t serialization_buffer_address = ts_wasm_store__serialization_buffer_address(self);
|
|
1683
|
+
|
|
1684
|
+
if (length > 0) {
|
|
1685
|
+
memcpy(
|
|
1686
|
+
&memory_data[serialization_buffer_address],
|
|
1687
|
+
buffer,
|
|
1688
|
+
length
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
wasmtime_val_raw_t args[3] = {
|
|
1693
|
+
{.i32 = scanner_address},
|
|
1694
|
+
{.i32 = serialization_buffer_address},
|
|
1695
|
+
{.i32 = length},
|
|
1696
|
+
};
|
|
1697
|
+
ts_wasm_store__call(self, self->current_instance->scanner_deserialize_fn_index, args, 3);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
bool ts_wasm_store_has_error(const TSWasmStore *self) {
|
|
1701
|
+
return self->has_error;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
bool ts_language_is_wasm(const TSLanguage *self) {
|
|
1705
|
+
return self->lex_fn == ts_wasm_store__sentinel_lex_fn;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
static inline LanguageWasmModule *ts_language__wasm_module(const TSLanguage *self) {
|
|
1709
|
+
return (LanguageWasmModule *)self->keyword_lex_fn;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
void ts_wasm_language_retain(const TSLanguage *self) {
|
|
1713
|
+
LanguageWasmModule *module = ts_language__wasm_module(self);
|
|
1714
|
+
ts_assert(module->ref_count > 0);
|
|
1715
|
+
atomic_inc(&module->ref_count);
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
void ts_wasm_language_release(const TSLanguage *self) {
|
|
1719
|
+
LanguageWasmModule *module = ts_language__wasm_module(self);
|
|
1720
|
+
ts_assert(module->ref_count > 0);
|
|
1721
|
+
if (atomic_dec(&module->ref_count) == 0) {
|
|
1722
|
+
// Update the language id to reflect that the language is deleted. This allows any wasm stores
|
|
1723
|
+
// that hold wasm instances for this language to delete those instances.
|
|
1724
|
+
atomic_inc(&module->language_id->is_language_deleted);
|
|
1725
|
+
language_id_delete(module->language_id);
|
|
1726
|
+
|
|
1727
|
+
ts_free((void *)module->field_name_buffer);
|
|
1728
|
+
ts_free((void *)module->symbol_name_buffer);
|
|
1729
|
+
ts_free((void *)module->name);
|
|
1730
|
+
wasmtime_module_delete(module->module);
|
|
1731
|
+
ts_free(module);
|
|
1732
|
+
|
|
1733
|
+
ts_free((void *)self->alias_map);
|
|
1734
|
+
ts_free((void *)self->alias_sequences);
|
|
1735
|
+
ts_free((void *)self->external_scanner.symbol_map);
|
|
1736
|
+
ts_free((void *)self->field_map_entries);
|
|
1737
|
+
ts_free((void *)self->field_map_slices);
|
|
1738
|
+
ts_free((void *)self->field_names);
|
|
1739
|
+
ts_free((void *)self->lex_modes);
|
|
1740
|
+
ts_free((void *)self->parse_actions);
|
|
1741
|
+
ts_free((void *)self->parse_table);
|
|
1742
|
+
ts_free((void *)self->primary_state_ids);
|
|
1743
|
+
ts_free((void *)self->public_symbol_map);
|
|
1744
|
+
ts_free((void *)self->small_parse_table);
|
|
1745
|
+
ts_free((void *)self->small_parse_table_map);
|
|
1746
|
+
ts_free((void *)self->symbol_metadata);
|
|
1747
|
+
ts_free((void *)self->symbol_names);
|
|
1748
|
+
ts_free((void *)self);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
#ifdef _MSC_VER
|
|
1753
|
+
#pragma warning(pop)
|
|
1754
|
+
#elif defined(__GNUC__) || defined(__clang__)
|
|
1755
|
+
#pragma GCC diagnostic pop
|
|
1756
|
+
#endif
|
|
1757
|
+
|
|
1758
|
+
#else
|
|
1759
|
+
|
|
1760
|
+
// If the WASM feature is not enabled, define dummy versions of all of the
|
|
1761
|
+
// wasm-related functions.
|
|
1762
|
+
|
|
1763
|
+
void ts_wasm_store_delete(TSWasmStore *self) {
|
|
1764
|
+
(void)self;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
bool ts_wasm_store_start(
|
|
1768
|
+
TSWasmStore *self,
|
|
1769
|
+
TSLexer *lexer,
|
|
1770
|
+
const TSLanguage *language
|
|
1771
|
+
) {
|
|
1772
|
+
(void)self;
|
|
1773
|
+
(void)lexer;
|
|
1774
|
+
(void)language;
|
|
1775
|
+
return false;
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
void ts_wasm_store_reset(TSWasmStore *self) {
|
|
1779
|
+
(void)self;
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
bool ts_wasm_store_call_lex_main(TSWasmStore *self, TSStateId state) {
|
|
1783
|
+
(void)self;
|
|
1784
|
+
(void)state;
|
|
1785
|
+
return false;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
bool ts_wasm_store_call_lex_keyword(TSWasmStore *self, TSStateId state) {
|
|
1789
|
+
(void)self;
|
|
1790
|
+
(void)state;
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
uint32_t ts_wasm_store_call_scanner_create(TSWasmStore *self) {
|
|
1795
|
+
(void)self;
|
|
1796
|
+
return 0;
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
void ts_wasm_store_call_scanner_destroy(
|
|
1800
|
+
TSWasmStore *self,
|
|
1801
|
+
uint32_t scanner_address
|
|
1802
|
+
) {
|
|
1803
|
+
(void)self;
|
|
1804
|
+
(void)scanner_address;
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
bool ts_wasm_store_call_scanner_scan(
|
|
1808
|
+
TSWasmStore *self,
|
|
1809
|
+
uint32_t scanner_address,
|
|
1810
|
+
uint32_t valid_tokens_ix
|
|
1811
|
+
) {
|
|
1812
|
+
(void)self;
|
|
1813
|
+
(void)scanner_address;
|
|
1814
|
+
(void)valid_tokens_ix;
|
|
1815
|
+
return false;
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
uint32_t ts_wasm_store_call_scanner_serialize(
|
|
1819
|
+
TSWasmStore *self,
|
|
1820
|
+
uint32_t scanner_address,
|
|
1821
|
+
char *buffer
|
|
1822
|
+
) {
|
|
1823
|
+
(void)self;
|
|
1824
|
+
(void)scanner_address;
|
|
1825
|
+
(void)buffer;
|
|
1826
|
+
return 0;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
void ts_wasm_store_call_scanner_deserialize(
|
|
1830
|
+
TSWasmStore *self,
|
|
1831
|
+
uint32_t scanner_address,
|
|
1832
|
+
const char *buffer,
|
|
1833
|
+
unsigned length
|
|
1834
|
+
) {
|
|
1835
|
+
(void)self;
|
|
1836
|
+
(void)scanner_address;
|
|
1837
|
+
(void)buffer;
|
|
1838
|
+
(void)length;
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
bool ts_wasm_store_has_error(const TSWasmStore *self) {
|
|
1842
|
+
(void)self;
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
bool ts_language_is_wasm(const TSLanguage *self) {
|
|
1847
|
+
(void)self;
|
|
1848
|
+
return false;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
void ts_wasm_language_retain(const TSLanguage *self) {
|
|
1852
|
+
(void)self;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
void ts_wasm_language_release(const TSLanguage *self) {
|
|
1856
|
+
(void)self;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
#endif
|