wasm-idle 0.7.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +760 -81
- package/dist/index.d.ts +4 -9
- package/dist/index.js +2 -4
- package/dist/playground/applicationAssets.d.ts +4 -0
- package/dist/playground/applicationAssets.js +277 -0
- package/dist/playground/assemblyscript.d.ts +41 -0
- package/dist/playground/assemblyscript.js +630 -0
- package/dist/playground/assetBridge.d.ts +18 -7
- package/dist/playground/assetBridge.js +824 -100
- package/dist/playground/assets.d.ts +813 -19
- package/dist/playground/assets.js +2096 -156
- package/dist/playground/awk.d.ts +5 -0
- package/dist/playground/awk.js +60 -0
- package/dist/playground/bash.d.ts +53 -0
- package/dist/playground/bash.js +1096 -0
- package/dist/playground/bashWorkerProtocol.d.ts +88 -0
- package/dist/playground/bashWorkerProtocol.js +135 -0
- package/dist/playground/bqn.d.ts +5 -0
- package/dist/playground/bqn.js +57 -0
- package/dist/playground/bqnPreflight.d.ts +26 -0
- package/dist/playground/bqnPreflight.js +399 -0
- package/dist/playground/c3.d.ts +15 -0
- package/dist/playground/c3.js +154 -0
- package/dist/playground/clang.d.ts +35 -19
- package/dist/playground/clang.js +241 -52
- package/dist/playground/clangAssetIntegrity.d.ts +32 -0
- package/dist/playground/clangAssetIntegrity.js +8 -0
- package/dist/playground/clojurescript.d.ts +5 -0
- package/dist/playground/clojurescript.js +59 -0
- package/dist/playground/clojurescriptPreflight.d.ts +26 -0
- package/dist/playground/clojurescriptPreflight.js +383 -0
- package/dist/playground/cobol.d.ts +46 -0
- package/dist/playground/cobol.js +703 -0
- package/dist/playground/d.d.ts +47 -0
- package/dist/playground/d.js +644 -0
- package/dist/playground/dOuterAssets.d.ts +16 -0
- package/dist/playground/dOuterAssets.js +163 -0
- package/dist/playground/dotnet.d.ts +99 -0
- package/dist/playground/dotnet.js +1131 -0
- package/dist/playground/duckdb.d.ts +36 -0
- package/dist/playground/duckdb.js +542 -0
- package/dist/playground/elixir.d.ts +18 -10
- package/dist/playground/elixir.js +630 -96
- package/dist/playground/elixirAssets.d.ts +6 -0
- package/dist/playground/elixirAssets.js +33 -0
- package/dist/playground/executionObservation.d.ts +22 -0
- package/dist/playground/executionObservation.js +65 -0
- package/dist/playground/forth.d.ts +5 -0
- package/dist/playground/forth.js +53 -0
- package/dist/playground/forthPreflight.d.ts +24 -0
- package/dist/playground/forthPreflight.js +198 -0
- package/dist/playground/fortran.d.ts +47 -0
- package/dist/playground/fortran.js +651 -0
- package/dist/playground/fortranAssets.d.ts +6 -0
- package/dist/playground/fortranAssets.js +27 -0
- package/dist/playground/gleam.d.ts +6 -0
- package/dist/playground/gleam.js +33 -0
- package/dist/playground/go.d.ts +17 -11
- package/dist/playground/go.js +376 -72
- package/dist/playground/goDebugInstrumentation.d.ts +1 -0
- package/dist/playground/goDebugInstrumentation.js +229 -0
- package/dist/playground/haskell.d.ts +44 -0
- package/dist/playground/haskell.js +678 -0
- package/dist/playground/haskellAssets.d.ts +24 -0
- package/dist/playground/haskellAssets.js +93 -0
- package/dist/playground/index.d.ts +1 -1
- package/dist/playground/index.js +360 -111
- package/dist/playground/j.d.ts +5 -0
- package/dist/playground/j.js +60 -0
- package/dist/playground/jPreflight.d.ts +26 -0
- package/dist/playground/jPreflight.js +372 -0
- package/dist/playground/janet.d.ts +5 -0
- package/dist/playground/janet.js +64 -0
- package/dist/playground/java.d.ts +24 -10
- package/dist/playground/java.js +706 -84
- package/dist/playground/javaSource.d.ts +5 -0
- package/dist/playground/javaSource.js +16 -0
- package/dist/playground/javaStdin.d.ts +1 -1
- package/dist/playground/javaStdin.js +13 -4
- package/dist/playground/julia.d.ts +5 -0
- package/dist/playground/julia.js +64 -0
- package/dist/playground/lfortran.d.ts +8 -0
- package/dist/playground/lfortran.js +30 -0
- package/dist/playground/lfortranAssets.d.ts +21 -0
- package/dist/playground/lfortranAssets.js +118 -0
- package/dist/playground/lisp.d.ts +45 -0
- package/dist/playground/lisp.js +640 -0
- package/dist/playground/lispAssets.d.ts +9 -0
- package/dist/playground/lispAssets.js +74 -0
- package/dist/playground/lldbManifest.d.ts +3 -0
- package/dist/playground/lldbManifest.js +155 -0
- package/dist/playground/lldbSession.d.ts +115 -0
- package/dist/playground/lldbSession.js +1347 -0
- package/dist/playground/loadingProgress.d.ts +16 -0
- package/dist/playground/loadingProgress.js +166 -0
- package/dist/playground/lua.d.ts +44 -0
- package/dist/playground/lua.js +630 -0
- package/dist/playground/nim.d.ts +5 -0
- package/dist/playground/nim.js +76 -0
- package/dist/playground/objectivec.d.ts +39 -0
- package/dist/playground/objectivec.js +288 -0
- package/dist/playground/ocaml.d.ts +28 -10
- package/dist/playground/ocaml.js +815 -253
- package/dist/playground/octave.d.ts +43 -0
- package/dist/playground/octave.js +783 -0
- package/dist/playground/options.d.ts +19 -40
- package/dist/playground/options.js +2 -1
- package/dist/playground/pascal.d.ts +5 -0
- package/dist/playground/pascal.js +60 -0
- package/dist/playground/perl.d.ts +5 -0
- package/dist/playground/perl.js +61 -0
- package/dist/playground/php.d.ts +44 -0
- package/dist/playground/php.js +665 -0
- package/dist/playground/prolog.d.ts +6 -0
- package/dist/playground/prolog.js +75 -0
- package/dist/playground/python.d.ts +20 -14
- package/dist/playground/python.js +445 -101
- package/dist/playground/pythonPackageLock.d.ts +6 -0
- package/dist/playground/pythonPackageLock.js +56 -0
- package/dist/playground/r.d.ts +44 -0
- package/dist/playground/r.js +637 -0
- package/dist/playground/ruby.d.ts +46 -0
- package/dist/playground/ruby.js +732 -0
- package/dist/playground/rubyAssets.d.ts +23 -0
- package/dist/playground/rubyAssets.js +68 -0
- package/dist/playground/rubyTestPreflight.d.ts +2 -0
- package/dist/playground/rubyTestPreflight.js +18 -0
- package/dist/playground/runtimeModule.d.ts +1 -0
- package/dist/playground/runtimeModule.js +5 -0
- package/dist/playground/rust.d.ts +44 -13
- package/dist/playground/rust.js +714 -76
- package/dist/playground/rustExecutableGraph.d.ts +85 -0
- package/dist/playground/rustExecutableGraph.js +946 -0
- package/dist/playground/rustWorkerLimits.d.ts +17 -0
- package/dist/playground/rustWorkerLimits.js +34 -0
- package/dist/playground/sandbox.d.ts +16 -10
- package/dist/playground/sharedBuffer.d.ts +6 -0
- package/dist/playground/sharedBuffer.js +12 -0
- package/dist/playground/sqlite.d.ts +38 -0
- package/dist/playground/sqlite.js +550 -0
- package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
- package/dist/playground/staticRuntimeModuleVersion.js +2 -0
- package/dist/playground/staticRuntimePreflight.d.ts +13 -0
- package/dist/playground/staticRuntimePreflight.js +231 -0
- package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
- package/dist/playground/staticRuntimePreflightExecute.js +66 -0
- package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
- package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
- package/dist/playground/staticStdinRing.d.ts +45 -0
- package/dist/playground/staticStdinRing.js +158 -0
- package/dist/playground/staticWorkerRuntime.d.ts +154 -0
- package/dist/playground/staticWorkerRuntime.js +1917 -0
- package/dist/playground/stdinBuffer.d.ts +9 -7
- package/dist/playground/stdinBuffer.js +9 -18
- package/dist/playground/swift.d.ts +5 -0
- package/dist/playground/swift.js +17 -0
- package/dist/playground/tcl.d.ts +5 -0
- package/dist/playground/tcl.js +62 -0
- package/dist/playground/teavmConfig.d.ts +1 -1
- package/dist/playground/teavmConfig.js +2 -2
- package/dist/playground/tinygo.d.ts +48 -18
- package/dist/playground/tinygo.js +1202 -329
- package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
- package/dist/playground/tinygoExecutableGraph.js +449 -0
- package/dist/playground/typescript.d.ts +55 -0
- package/dist/playground/typescript.js +924 -0
- package/dist/playground/wasm.d.ts +43 -0
- package/dist/playground/wasm.js +608 -0
- package/dist/playground/wasmAwkVersion.d.ts +59 -0
- package/dist/playground/wasmAwkVersion.js +31 -0
- package/dist/playground/wasmBashVersion.d.ts +63 -0
- package/dist/playground/wasmBashVersion.js +36 -0
- package/dist/playground/wasmBqnVersion.d.ts +24 -0
- package/dist/playground/wasmBqnVersion.js +24 -0
- package/dist/playground/wasmC3Version.d.ts +20 -0
- package/dist/playground/wasmC3Version.js +21 -0
- package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
- package/dist/playground/wasmClojureScriptVersion.js +21 -0
- package/dist/playground/wasmDIntegrity.d.ts +15 -0
- package/dist/playground/wasmDIntegrity.js +15 -0
- package/dist/playground/wasmDVersion.d.ts +1 -0
- package/dist/playground/wasmDVersion.js +1 -0
- package/dist/playground/wasmDebugVersion.d.ts +6 -0
- package/dist/playground/wasmDebugVersion.js +6 -0
- package/dist/playground/wasmDotnetVersion.d.ts +1 -0
- package/dist/playground/wasmDotnetVersion.js +1 -0
- package/dist/playground/wasmElixirVersion.d.ts +21 -1
- package/dist/playground/wasmElixirVersion.js +21 -1
- package/dist/playground/wasmForthVersion.d.ts +18 -0
- package/dist/playground/wasmForthVersion.js +18 -0
- package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
- package/dist/playground/wasmFortranExecutionAssets.js +15 -0
- package/dist/playground/wasmFortranVersion.d.ts +1 -0
- package/dist/playground/wasmFortranVersion.js +1 -0
- package/dist/playground/wasmGleamVersion.d.ts +5 -0
- package/dist/playground/wasmGleamVersion.js +5 -0
- package/dist/playground/wasmGoVersion.d.ts +1 -1
- package/dist/playground/wasmGoVersion.js +1 -1
- package/dist/playground/wasmHaskellVersion.d.ts +1 -0
- package/dist/playground/wasmHaskellVersion.js +1 -0
- package/dist/playground/wasmJVersion.d.ts +24 -0
- package/dist/playground/wasmJVersion.js +24 -0
- package/dist/playground/wasmJanetVersion.d.ts +53 -0
- package/dist/playground/wasmJanetVersion.js +30 -0
- package/dist/playground/wasmJuliaVersion.d.ts +71 -0
- package/dist/playground/wasmJuliaVersion.js +39 -0
- package/dist/playground/wasmLfortranVersion.d.ts +28 -0
- package/dist/playground/wasmLfortranVersion.js +29 -0
- package/dist/playground/wasmLispVersion.d.ts +1 -0
- package/dist/playground/wasmLispVersion.js +1 -0
- package/dist/playground/wasmLuaVersion.d.ts +1 -0
- package/dist/playground/wasmLuaVersion.js +1 -0
- package/dist/playground/wasmNimVersion.d.ts +125 -0
- package/dist/playground/wasmNimVersion.js +66 -0
- package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
- package/dist/playground/wasmObjectiveCVersion.js +27 -0
- package/dist/playground/wasmOcamlVersion.d.ts +12 -1
- package/dist/playground/wasmOcamlVersion.js +12 -1
- package/dist/playground/wasmOctaveVersion.d.ts +1 -0
- package/dist/playground/wasmOctaveVersion.js +1 -0
- package/dist/playground/wasmPascalVersion.d.ts +61 -0
- package/dist/playground/wasmPascalVersion.js +34 -0
- package/dist/playground/wasmPerlVersion.d.ts +71 -0
- package/dist/playground/wasmPerlVersion.js +39 -0
- package/dist/playground/wasmPrologVersion.d.ts +31 -0
- package/dist/playground/wasmPrologVersion.js +31 -0
- package/dist/playground/wasmRVersion.d.ts +1 -0
- package/dist/playground/wasmRVersion.js +1 -0
- package/dist/playground/wasmRustVersion.d.ts +1306 -1
- package/dist/playground/wasmRustVersion.js +1458 -1
- package/dist/playground/wasmSwiftVersion.d.ts +1 -0
- package/dist/playground/wasmSwiftVersion.js +1 -0
- package/dist/playground/wasmTclVersion.d.ts +85 -0
- package/dist/playground/wasmTclVersion.js +46 -0
- package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
- package/dist/playground/wasmTinyGoVersion.js +107 -1
- package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
- package/dist/playground/wasmTypeScriptVersion.js +5 -0
- package/dist/playground/wasmWatVersion.d.ts +1 -0
- package/dist/playground/wasmWatVersion.js +1 -0
- package/dist/playground/wasmZigVersion.d.ts +13 -0
- package/dist/playground/wasmZigVersion.js +13 -0
- package/dist/playground/wat.d.ts +44 -0
- package/dist/playground/wat.js +622 -0
- package/dist/playground/worker/assemblyscript.js +339 -0
- package/dist/playground/worker/assets.d.ts +7 -0
- package/dist/playground/worker/assets.js +288 -39
- package/dist/playground/worker/bash.js +338 -0
- package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
- package/dist/playground/worker/bashNestedBootstrap.js +59 -0
- package/dist/playground/worker/bashRuntime.d.ts +89 -0
- package/dist/playground/worker/bashRuntime.js +982 -0
- package/dist/playground/worker/clang.js +92 -13
- package/dist/playground/worker/cobol.js +107 -0
- package/dist/playground/worker/d.js +199 -0
- package/dist/playground/worker/dotnet.js +141 -0
- package/dist/playground/worker/duckdb.d.ts +1 -0
- package/dist/playground/worker/duckdb.js +136 -0
- package/dist/playground/worker/elixir.js +307 -41
- package/dist/playground/worker/fortran.d.ts +1 -0
- package/dist/playground/worker/fortran.js +295 -0
- package/dist/playground/worker/go.js +246 -40
- package/dist/playground/worker/haskell.d.ts +7 -0
- package/dist/playground/worker/haskell.js +465 -0
- package/dist/playground/worker/java.js +59 -20
- package/dist/playground/worker/lisp.d.ts +1 -0
- package/dist/playground/worker/lisp.js +195 -0
- package/dist/playground/worker/lua.d.ts +1 -0
- package/dist/playground/worker/lua.js +163 -0
- package/dist/playground/worker/objectivec.d.ts +1 -0
- package/dist/playground/worker/objectivec.js +10 -0
- package/dist/playground/worker/ocaml.js +206 -58
- package/dist/playground/worker/php.d.ts +1 -0
- package/dist/playground/worker/php.js +261 -0
- package/dist/playground/worker/python.js +201 -44
- package/dist/playground/worker/r.d.ts +1 -0
- package/dist/playground/worker/r.js +192 -0
- package/dist/playground/worker/ruby.d.ts +1 -0
- package/dist/playground/worker/ruby.js +248 -0
- package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
- package/dist/playground/worker/runtimeAssetFetch.js +375 -0
- package/dist/playground/worker/rust.js +546 -20
- package/dist/playground/worker/sqlite.d.ts +1 -0
- package/dist/playground/worker/sqlite.js +112 -0
- package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
- package/dist/playground/worker/staticRuntimePreflight.js +56 -0
- package/dist/playground/worker/tinygo.js +34 -9
- package/dist/playground/worker/typescript.d.ts +1 -0
- package/dist/playground/worker/typescript.js +251 -0
- package/dist/playground/worker/wasm.d.ts +1 -0
- package/dist/playground/worker/wasm.js +273 -0
- package/dist/playground/worker/wat.d.ts +1 -0
- package/dist/playground/worker/wat.js +188 -0
- package/dist/playground/worker/zig.d.ts +8 -0
- package/dist/playground/worker/zig.js +578 -0
- package/dist/playground/workerProgress.d.ts +15 -0
- package/dist/playground/workerProgress.js +72 -0
- package/dist/playground/workerSession.d.ts +28 -0
- package/dist/playground/workerSession.js +164 -0
- package/dist/playground/zig.d.ts +46 -0
- package/dist/playground/zig.js +690 -0
- package/dist/playground/zigAssets.d.ts +6 -0
- package/dist/playground/zigAssets.js +49 -0
- package/package.json +234 -105
- package/dist/clang/app.d.ts +0 -75
- package/dist/clang/app.js +0 -744
- package/dist/clang/apply.d.ts +0 -2
- package/dist/clang/apply.js +0 -11
- package/dist/clang/color.d.ts +0 -3
- package/dist/clang/color.js +0 -3
- package/dist/clang/encode.d.ts +0 -4
- package/dist/clang/encode.js +0 -20
- package/dist/clang/error.d.ts +0 -14
- package/dist/clang/error.js +0 -27
- package/dist/clang/gccCompat.d.ts +0 -15
- package/dist/clang/gccCompat.js +0 -767
- package/dist/clang/index.d.ts +0 -85
- package/dist/clang/index.js +0 -1077
- package/dist/clang/memory/index.d.ts +0 -4
- package/dist/clang/memory/index.js +0 -4
- package/dist/clang/memory/memFs.d.ts +0 -35
- package/dist/clang/memory/memFs.js +0 -132
- package/dist/clang/memory/memory.d.ts +0 -22
- package/dist/clang/memory/memory.js +0 -73
- package/dist/clang/memory/tar.d.ts +0 -2
- package/dist/clang/memory/tar.js +0 -59
- package/dist/clang/url.d.ts +0 -4
- package/dist/clang/url.js +0 -5
- package/dist/clang/wasm.d.ts +0 -4
- package/dist/clang/wasm.js +0 -50
- package/dist/clangd/config.d.ts +0 -18
- package/dist/clangd/config.js +0 -14
- package/dist/clangd/jsonStream.d.ts +0 -9
- package/dist/clangd/jsonStream.js +0 -48
- package/dist/clangd/session.d.ts +0 -18
- package/dist/clangd/session.js +0 -112
- package/dist/clangd/worker.js +0 -131
- package/dist/debug/controller.svelte.d.ts +0 -43
- package/dist/debug/controller.svelte.js +0 -268
- package/dist/debug/editor/index.d.ts +0 -2
- package/dist/debug/editor/index.js +0 -1
- package/dist/debug/editor/monaco.d.ts +0 -26
- package/dist/debug/editor/monaco.js +0 -128
- package/dist/debug/expression.d.ts +0 -26
- package/dist/debug/expression.js +0 -547
- package/dist/debug/index.d.ts +0 -8
- package/dist/debug/index.js +0 -5
- package/dist/debug/language/cpp.d.ts +0 -2
- package/dist/debug/language/cpp.js +0 -7
- package/dist/debug/language/index.d.ts +0 -3
- package/dist/debug/language/index.js +0 -2
- package/dist/debug/language/python.d.ts +0 -2
- package/dist/debug/language/python.js +0 -14
- package/dist/debug/language/types.d.ts +0 -6
- package/dist/debug/locals.d.ts +0 -2
- package/dist/debug/locals.js +0 -8
- package/dist/lsp/cpp/server.d.ts +0 -2
- package/dist/lsp/cpp/server.js +0 -68
- package/dist/lsp/index.d.ts +0 -5
- package/dist/lsp/index.js +0 -4
- package/dist/lsp/python/main.worker.js +0 -92
- package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
- package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
- package/dist/lsp/python/server.d.ts +0 -2
- package/dist/lsp/python/server.js +0 -54
- package/dist/lsp/registry.d.ts +0 -2
- package/dist/lsp/registry.js +0 -12
- package/dist/lsp/runtime.d.ts +0 -5
- package/dist/lsp/runtime.js +0 -31
- package/dist/lsp/types.d.ts +0 -17
- package/dist/terminal/Terminal.svelte +0 -422
- package/dist/terminal/Terminal.svelte.d.ts +0 -26
- package/dist/terminal/index.d.ts +0 -7
- package/dist/terminal/index.js +0 -5
- package/dist/terminal/plugin/index.d.ts +0 -9
- package/dist/terminal/plugin/index.js +0 -19
- package/dist/terminal/theme.d.ts +0 -49
- package/dist/terminal/theme.js +0 -49
- package/dist/terminal/types.d.ts +0 -18
- package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
- package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
- /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
- /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
- /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
- /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
- /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
package/dist/clang/index.js
DELETED
|
@@ -1,1077 +0,0 @@
|
|
|
1
|
-
import App from './app';
|
|
2
|
-
import { MemFS, untar } from './memory';
|
|
3
|
-
import { green, yellow, normal } from './color';
|
|
4
|
-
import { compile, readBuffer } from './wasm';
|
|
5
|
-
import { clangUrl, lldUrl, rootUrl } from './url';
|
|
6
|
-
import { installGccCompatibilityHeaders } from './gccCompat';
|
|
7
|
-
import { derived, writable } from 'svelte/store';
|
|
8
|
-
const clangCommonArgs = [
|
|
9
|
-
'-disable-free',
|
|
10
|
-
'-isysroot',
|
|
11
|
-
'/',
|
|
12
|
-
'-internal-isystem',
|
|
13
|
-
'/include/c++/v1',
|
|
14
|
-
'-internal-isystem',
|
|
15
|
-
'/include',
|
|
16
|
-
'-internal-isystem',
|
|
17
|
-
'/lib/clang/8.0.1/include',
|
|
18
|
-
'-ferror-limit',
|
|
19
|
-
'19',
|
|
20
|
-
'-fmessage-length',
|
|
21
|
-
'80',
|
|
22
|
-
'-fcolor-diagnostics'
|
|
23
|
-
];
|
|
24
|
-
const defaultCppStandardArg = '-std=gnu++2a';
|
|
25
|
-
const defaultCStandardArg = '-std=gnu11';
|
|
26
|
-
function normalizeStandardCode(value) {
|
|
27
|
-
return (value || '').trim().toUpperCase().replaceAll(/\s+/g, '');
|
|
28
|
-
}
|
|
29
|
-
function resolveCppStandardArg(version) {
|
|
30
|
-
switch (normalizeStandardCode(version)) {
|
|
31
|
-
case '03':
|
|
32
|
-
case 'CPP03':
|
|
33
|
-
case 'C++03':
|
|
34
|
-
case 'GNU++03':
|
|
35
|
-
case 'GNUC++03':
|
|
36
|
-
return '-std=gnu++03';
|
|
37
|
-
case '11':
|
|
38
|
-
case 'CPP11':
|
|
39
|
-
case 'C++11':
|
|
40
|
-
case 'GNU++11':
|
|
41
|
-
case 'GNUC++11':
|
|
42
|
-
return '-std=gnu++11';
|
|
43
|
-
case '14':
|
|
44
|
-
case 'CPP14':
|
|
45
|
-
case 'C++14':
|
|
46
|
-
case 'GNU++14':
|
|
47
|
-
case 'GNUC++14':
|
|
48
|
-
return '-std=gnu++14';
|
|
49
|
-
case '17':
|
|
50
|
-
case 'CPP17':
|
|
51
|
-
case 'C++17':
|
|
52
|
-
case 'GNU++17':
|
|
53
|
-
case 'GNUC++17':
|
|
54
|
-
return '-std=gnu++17';
|
|
55
|
-
case '20':
|
|
56
|
-
case '23':
|
|
57
|
-
case '26':
|
|
58
|
-
case 'CPP20':
|
|
59
|
-
case 'CPP23':
|
|
60
|
-
case 'CPP26':
|
|
61
|
-
case 'C++20':
|
|
62
|
-
case 'C++23':
|
|
63
|
-
case 'C++26':
|
|
64
|
-
case 'GNU++20':
|
|
65
|
-
case 'GNU++23':
|
|
66
|
-
case 'GNU++26':
|
|
67
|
-
case 'GNUC++20':
|
|
68
|
-
case 'GNUC++23':
|
|
69
|
-
case 'GNUC++26':
|
|
70
|
-
return defaultCppStandardArg;
|
|
71
|
-
default:
|
|
72
|
-
return defaultCppStandardArg;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function resolveCStandardArg(version) {
|
|
76
|
-
switch (normalizeStandardCode(version)) {
|
|
77
|
-
case '99':
|
|
78
|
-
case 'C99':
|
|
79
|
-
case 'GNU99':
|
|
80
|
-
case 'GNUC99':
|
|
81
|
-
return '-std=gnu99';
|
|
82
|
-
case '11':
|
|
83
|
-
case 'C11':
|
|
84
|
-
case 'GNU11':
|
|
85
|
-
case 'GNUC11':
|
|
86
|
-
return '-std=gnu11';
|
|
87
|
-
case '17':
|
|
88
|
-
case '18':
|
|
89
|
-
case 'C17':
|
|
90
|
-
case 'C18':
|
|
91
|
-
case 'GNU17':
|
|
92
|
-
case 'GNU18':
|
|
93
|
-
case 'GNUC17':
|
|
94
|
-
case 'GNUC18':
|
|
95
|
-
return '-std=gnu17';
|
|
96
|
-
default:
|
|
97
|
-
return defaultCStandardArg;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function resolveClangLanguageArgs(language, options) {
|
|
101
|
-
if (language === 'C') {
|
|
102
|
-
return {
|
|
103
|
-
languageArg: 'c',
|
|
104
|
-
standardArg: resolveCStandardArg(options.cVersion)
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
languageArg: 'c++',
|
|
109
|
-
standardArg: resolveCppStandardArg(options.cppVersion)
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
const toUtf8 = (text) => {
|
|
113
|
-
const surrogate = encodeURIComponent(text);
|
|
114
|
-
let result = '';
|
|
115
|
-
for (let i = 0; i < surrogate.length;) {
|
|
116
|
-
const character = surrogate[i];
|
|
117
|
-
i += 1;
|
|
118
|
-
if (character == '%') {
|
|
119
|
-
const hex = surrogate.substring(i, (i += 2));
|
|
120
|
-
if (hex)
|
|
121
|
-
result += String.fromCharCode(parseInt(hex, 16));
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
result += character;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return result;
|
|
128
|
-
};
|
|
129
|
-
export default class Clang {
|
|
130
|
-
ready;
|
|
131
|
-
memfs;
|
|
132
|
-
stdout;
|
|
133
|
-
moduleCache;
|
|
134
|
-
showTiming;
|
|
135
|
-
log;
|
|
136
|
-
debug = false;
|
|
137
|
-
debugBreakpoints = new Set();
|
|
138
|
-
debugPauseOnEntry = false;
|
|
139
|
-
debugBuffer;
|
|
140
|
-
debugInterruptBuffer;
|
|
141
|
-
debugWatchBuffer;
|
|
142
|
-
debugWatchResultBuffer;
|
|
143
|
-
onDebugEvent;
|
|
144
|
-
debugVariableMetadata = {};
|
|
145
|
-
debugGlobalMetadata = [];
|
|
146
|
-
debugFunctionMetadata = {};
|
|
147
|
-
lastBuildKey = '';
|
|
148
|
-
path;
|
|
149
|
-
wasm;
|
|
150
|
-
traceStartedAt = 0;
|
|
151
|
-
progress = {
|
|
152
|
-
clang: writable(0),
|
|
153
|
-
lld: writable(0),
|
|
154
|
-
memfs: writable(0)
|
|
155
|
-
};
|
|
156
|
-
constructor(options) {
|
|
157
|
-
this.moduleCache = {};
|
|
158
|
-
this.stdout = options.stdout;
|
|
159
|
-
this.showTiming = options.showTiming || false;
|
|
160
|
-
this.log = options.log || false;
|
|
161
|
-
this.path = options.path;
|
|
162
|
-
this.onDebugEvent = options.onDebugEvent;
|
|
163
|
-
this.memfs = new MemFS({
|
|
164
|
-
stdout: this.stdout,
|
|
165
|
-
stdin: options.stdin,
|
|
166
|
-
path: this.path,
|
|
167
|
-
progress: this.progress.memfs,
|
|
168
|
-
trace: (message) => this.trace(message)
|
|
169
|
-
});
|
|
170
|
-
const progress = derived([this.progress.clang, this.progress.lld, this.progress.memfs], ([clang, lld, memfs]) => {
|
|
171
|
-
return (clang + lld + memfs) / 3;
|
|
172
|
-
});
|
|
173
|
-
progress.subscribe((value) => {
|
|
174
|
-
options.progress(value);
|
|
175
|
-
});
|
|
176
|
-
this.getModule(clangUrl(this.path), this.progress.clang);
|
|
177
|
-
this.getModule(lldUrl(this.path), this.progress.lld);
|
|
178
|
-
this.ready = this.memfs.ready.then(async () => {
|
|
179
|
-
await this.hostLogAsync(`Untarring ${rootUrl(this.path)}`, readBuffer(rootUrl(this.path)).then((buffer) => untar(buffer, this.memfs)));
|
|
180
|
-
installGccCompatibilityHeaders(this.memfs);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
hostLog(message) {
|
|
184
|
-
if (!this.log)
|
|
185
|
-
return;
|
|
186
|
-
const yellowArrow = `${yellow}>${normal} `;
|
|
187
|
-
this.stdout(`${yellowArrow}${message}`);
|
|
188
|
-
}
|
|
189
|
-
beginTrace(debug) {
|
|
190
|
-
this.debug = debug;
|
|
191
|
-
this.traceStartedAt = Date.now();
|
|
192
|
-
}
|
|
193
|
-
trace(message) {
|
|
194
|
-
if (!this.debug || !this.log)
|
|
195
|
-
return;
|
|
196
|
-
const elapsed = Date.now() - this.traceStartedAt;
|
|
197
|
-
this.stdout(`\x1b[2m[debug +${elapsed}ms] ${message}\x1b[0m\n`);
|
|
198
|
-
}
|
|
199
|
-
async hostLogAsync(message, promise) {
|
|
200
|
-
const start = +new Date();
|
|
201
|
-
this.hostLog(`${message}...`);
|
|
202
|
-
const result = await promise;
|
|
203
|
-
const end = +new Date();
|
|
204
|
-
if (this.log)
|
|
205
|
-
this.stdout(' done.');
|
|
206
|
-
if (this.showTiming)
|
|
207
|
-
this.stdout(` ${green}(${end - start}ms)${normal}\n`);
|
|
208
|
-
if (this.log)
|
|
209
|
-
this.stdout('\n');
|
|
210
|
-
return result;
|
|
211
|
-
}
|
|
212
|
-
async getModule(name, progress) {
|
|
213
|
-
if (this.moduleCache[name])
|
|
214
|
-
return this.moduleCache[name];
|
|
215
|
-
const module = await this.hostLogAsync(`Fetching and compiling ${name}`, compile(name, progress));
|
|
216
|
-
this.moduleCache[name] = module;
|
|
217
|
-
return module;
|
|
218
|
-
}
|
|
219
|
-
async compile(options) {
|
|
220
|
-
const input = options.input;
|
|
221
|
-
let source = options.code;
|
|
222
|
-
const obj = options.obj;
|
|
223
|
-
const language = options.language === 'C' ? 'C' : 'CPP';
|
|
224
|
-
const compileArgs = options.compileArgs ?? options.args ?? [];
|
|
225
|
-
const { languageArg, standardArg } = resolveClangLanguageArgs(language, options);
|
|
226
|
-
const debug = !!options.debug;
|
|
227
|
-
const opt = debug ? '0' : options.opt || '2';
|
|
228
|
-
if (debug) {
|
|
229
|
-
const lines = source.split('\n');
|
|
230
|
-
let braceDepth = 0;
|
|
231
|
-
let functionDepth = 0;
|
|
232
|
-
let currentFunctionId = 0;
|
|
233
|
-
let nextFunctionId = 1;
|
|
234
|
-
let nextVariableSlot = 1;
|
|
235
|
-
let currentFunctionVariables = new Map();
|
|
236
|
-
let globalVariables = new Map();
|
|
237
|
-
let currentFunctionContainers = new Map();
|
|
238
|
-
let inBlockComment = false;
|
|
239
|
-
let pendingFunctionHeader;
|
|
240
|
-
const debugStructTypes = new Map();
|
|
241
|
-
let structName = '';
|
|
242
|
-
let structFields = [];
|
|
243
|
-
let structInBlockComment = false;
|
|
244
|
-
for (const rawLine of lines) {
|
|
245
|
-
let structLine = rawLine;
|
|
246
|
-
if (structInBlockComment) {
|
|
247
|
-
const commentEnd = structLine.indexOf('*/');
|
|
248
|
-
if (commentEnd === -1)
|
|
249
|
-
continue;
|
|
250
|
-
structLine = structLine.slice(commentEnd + 2);
|
|
251
|
-
structInBlockComment = false;
|
|
252
|
-
}
|
|
253
|
-
const commentStart = structLine.indexOf('/*');
|
|
254
|
-
if (commentStart !== -1) {
|
|
255
|
-
const commentEnd = structLine.indexOf('*/', commentStart + 2);
|
|
256
|
-
if (commentEnd === -1) {
|
|
257
|
-
structInBlockComment = true;
|
|
258
|
-
structLine = structLine.slice(0, commentStart);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
structLine =
|
|
262
|
-
structLine.slice(0, commentStart) + structLine.slice(commentEnd + 2);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const lineComment = structLine.indexOf('//');
|
|
266
|
-
if (lineComment !== -1)
|
|
267
|
-
structLine = structLine.slice(0, lineComment);
|
|
268
|
-
const normalizedStructLine = structLine.trim();
|
|
269
|
-
if (!structName) {
|
|
270
|
-
const structMatch = normalizedStructLine.match(/^struct\s+([A-Za-z_]\w*)\s*\{$/);
|
|
271
|
-
if (structMatch?.[1]) {
|
|
272
|
-
structName = structMatch[1];
|
|
273
|
-
structFields = [];
|
|
274
|
-
}
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
if (normalizedStructLine === '};') {
|
|
278
|
-
let structOffset = 0;
|
|
279
|
-
let structAlignment = 1;
|
|
280
|
-
const resolvedFields = [];
|
|
281
|
-
for (const field of structFields) {
|
|
282
|
-
const fieldSize = field.kind === 'double'
|
|
283
|
-
? 8
|
|
284
|
-
: field.kind === 'bool' || field.kind === 'char'
|
|
285
|
-
? 1
|
|
286
|
-
: 4;
|
|
287
|
-
if (structOffset % fieldSize !== 0) {
|
|
288
|
-
structOffset += fieldSize - (structOffset % fieldSize);
|
|
289
|
-
}
|
|
290
|
-
resolvedFields.push({
|
|
291
|
-
name: field.name,
|
|
292
|
-
kind: field.kind,
|
|
293
|
-
offset: structOffset
|
|
294
|
-
});
|
|
295
|
-
structOffset += fieldSize;
|
|
296
|
-
structAlignment = Math.max(structAlignment, fieldSize);
|
|
297
|
-
}
|
|
298
|
-
if (structOffset % structAlignment !== 0) {
|
|
299
|
-
structOffset += structAlignment - (structOffset % structAlignment);
|
|
300
|
-
}
|
|
301
|
-
debugStructTypes.set(structName, {
|
|
302
|
-
fields: resolvedFields,
|
|
303
|
-
size: Math.max(structOffset, 1)
|
|
304
|
-
});
|
|
305
|
-
structName = '';
|
|
306
|
-
structFields = [];
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
const structFieldMatch = normalizedStructLine.match(/^(?:const\s+)?(?:(?:unsigned|signed)\s+)?(?:(?:short|long long|long)\s+)?(int|float|double|bool|char)\s+(.+);$/);
|
|
310
|
-
if (!structFieldMatch)
|
|
311
|
-
continue;
|
|
312
|
-
for (const declaration of structFieldMatch[2].split(',')) {
|
|
313
|
-
const declarator = declaration.split('=')[0]?.trim() || '';
|
|
314
|
-
if (!declarator || /[*&\[]/.test(declarator))
|
|
315
|
-
continue;
|
|
316
|
-
const name = declarator.match(/([A-Za-z_]\w*)\s*$/)?.[1];
|
|
317
|
-
if (!name)
|
|
318
|
-
continue;
|
|
319
|
-
structFields.push({
|
|
320
|
-
name,
|
|
321
|
-
kind: structFieldMatch[1]
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
this.debugVariableMetadata = {};
|
|
326
|
-
this.debugGlobalMetadata = [];
|
|
327
|
-
this.debugFunctionMetadata = {};
|
|
328
|
-
const globalInitialization = [];
|
|
329
|
-
const instrumented = [
|
|
330
|
-
'#include <cstdio>',
|
|
331
|
-
'#include <iostream>',
|
|
332
|
-
'#include <map>',
|
|
333
|
-
'#include <set>',
|
|
334
|
-
'#include <string>',
|
|
335
|
-
'#include <type_traits>',
|
|
336
|
-
'#include <vector>',
|
|
337
|
-
'extern "C" __attribute__((import_module("env"), import_name("__wasm_idle_debug_enter"))) void __wasm_idle_debug_enter(int functionId, int line);',
|
|
338
|
-
'extern "C" __attribute__((import_module("env"), import_name("__wasm_idle_debug_leave"))) void __wasm_idle_debug_leave(int functionId);',
|
|
339
|
-
'extern "C" __attribute__((import_module("env"), import_name("__wasm_idle_debug_value_num"))) void __wasm_idle_debug_value_num(int functionId, int slot, double value);',
|
|
340
|
-
'extern "C" __attribute__((import_module("env"), import_name("__wasm_idle_debug_value_bool"))) void __wasm_idle_debug_value_bool(int functionId, int slot, int value);',
|
|
341
|
-
'extern "C" __attribute__((import_module("env"), import_name("__wasm_idle_debug_value_addr"))) void __wasm_idle_debug_value_addr(int functionId, int slot, int value);',
|
|
342
|
-
'extern "C" __attribute__((import_module("env"), import_name("__wasm_idle_debug_value_text"))) void __wasm_idle_debug_value_text(int functionId, int slot, const char* ptr, int len);',
|
|
343
|
-
'template <typename T>',
|
|
344
|
-
'static inline std::string __wasm_idle_debug_format_value(const T& value) {',
|
|
345
|
-
' if constexpr (std::is_same_v<T, bool>) return value ? "true" : "false";',
|
|
346
|
-
` else if constexpr (std::is_same_v<T, char>) return std::string("'") + value + "'";`,
|
|
347
|
-
' else if constexpr (std::is_same_v<T, signed char> || std::is_same_v<T, unsigned char>) return std::to_string((int)value);',
|
|
348
|
-
' else if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>) return std::to_string(value);',
|
|
349
|
-
' else return "?";',
|
|
350
|
-
'}',
|
|
351
|
-
'template <typename T>',
|
|
352
|
-
'static inline void __wasm_idle_debug_emit_vector(int functionId, int slot, const std::vector<T>& values) {',
|
|
353
|
-
' std::string text = "[";',
|
|
354
|
-
' int count = 0;',
|
|
355
|
-
' for (const auto& value : values) {',
|
|
356
|
-
' if (count > 0) text += ", ";',
|
|
357
|
-
' if (count >= 8) { text += "..."; break; }',
|
|
358
|
-
' text += __wasm_idle_debug_format_value(value);',
|
|
359
|
-
' count += 1;',
|
|
360
|
-
' }',
|
|
361
|
-
' text += "]";',
|
|
362
|
-
' __wasm_idle_debug_value_text(functionId, slot, text.c_str(), (int)text.size());',
|
|
363
|
-
'}',
|
|
364
|
-
'template <typename T>',
|
|
365
|
-
'static inline void __wasm_idle_debug_emit_set(int functionId, int slot, const std::set<T>& values) {',
|
|
366
|
-
' std::string text = "{";',
|
|
367
|
-
' int count = 0;',
|
|
368
|
-
' for (const auto& value : values) {',
|
|
369
|
-
' if (count > 0) text += ", ";',
|
|
370
|
-
' if (count >= 8) { text += "..."; break; }',
|
|
371
|
-
' text += __wasm_idle_debug_format_value(value);',
|
|
372
|
-
' count += 1;',
|
|
373
|
-
' }',
|
|
374
|
-
' text += "}";',
|
|
375
|
-
' __wasm_idle_debug_value_text(functionId, slot, text.c_str(), (int)text.size());',
|
|
376
|
-
'}',
|
|
377
|
-
'template <typename K, typename V>',
|
|
378
|
-
'static inline void __wasm_idle_debug_emit_map(int functionId, int slot, const std::map<K, V>& values) {',
|
|
379
|
-
' std::string text = "{";',
|
|
380
|
-
' int count = 0;',
|
|
381
|
-
' for (const auto& entry : values) {',
|
|
382
|
-
' if (count > 0) text += ", ";',
|
|
383
|
-
' if (count >= 8) { text += "..."; break; }',
|
|
384
|
-
' text += __wasm_idle_debug_format_value(entry.first);',
|
|
385
|
-
' text += ": ";',
|
|
386
|
-
' text += __wasm_idle_debug_format_value(entry.second);',
|
|
387
|
-
' count += 1;',
|
|
388
|
-
' }',
|
|
389
|
-
' text += "}";',
|
|
390
|
-
' __wasm_idle_debug_value_text(functionId, slot, text.c_str(), (int)text.size());',
|
|
391
|
-
'}',
|
|
392
|
-
'extern "C" __attribute__((import_module("env"), import_name("__wasm_idle_debug_line"))) void __wasm_idle_debug_line(int functionId, int line);'
|
|
393
|
-
];
|
|
394
|
-
for (let index = 0; index < lines.length; index += 1) {
|
|
395
|
-
const line = lines[index];
|
|
396
|
-
const indent = line.match(/^\s*/)?.[0] || '';
|
|
397
|
-
let rewrittenLine = line;
|
|
398
|
-
let analysisLine = line;
|
|
399
|
-
if (inBlockComment) {
|
|
400
|
-
const commentEnd = analysisLine.indexOf('*/');
|
|
401
|
-
if (commentEnd === -1) {
|
|
402
|
-
instrumented.push(line);
|
|
403
|
-
continue;
|
|
404
|
-
}
|
|
405
|
-
analysisLine = analysisLine.slice(commentEnd + 2);
|
|
406
|
-
inBlockComment = false;
|
|
407
|
-
}
|
|
408
|
-
const commentStart = analysisLine.indexOf('/*');
|
|
409
|
-
if (commentStart !== -1) {
|
|
410
|
-
const commentEnd = analysisLine.indexOf('*/', commentStart + 2);
|
|
411
|
-
if (commentEnd === -1) {
|
|
412
|
-
inBlockComment = true;
|
|
413
|
-
analysisLine = analysisLine.slice(0, commentStart);
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
analysisLine =
|
|
417
|
-
analysisLine.slice(0, commentStart) +
|
|
418
|
-
analysisLine.slice(commentEnd + 2);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const lineComment = analysisLine.indexOf('//');
|
|
422
|
-
if (lineComment !== -1)
|
|
423
|
-
analysisLine = analysisLine.slice(0, lineComment);
|
|
424
|
-
const normalized = analysisLine.trim();
|
|
425
|
-
const inFunctionBody = functionDepth > 0 && braceDepth >= functionDepth;
|
|
426
|
-
const isTopLevelDeclarationContext = functionDepth === 0 &&
|
|
427
|
-
braceDepth === 0 &&
|
|
428
|
-
!normalized.includes('(') &&
|
|
429
|
-
!normalized.startsWith('#');
|
|
430
|
-
const controlHeaderWithoutInlineBlock = /^(while|if|for)\s*\(/.test(normalized) && !normalized.includes('{');
|
|
431
|
-
const leadingInstrumentation = [];
|
|
432
|
-
const trailingInstrumentation = [];
|
|
433
|
-
const declaredContainerNames = new Set();
|
|
434
|
-
const globalDeclarationMatch = isTopLevelDeclarationContext &&
|
|
435
|
-
normalized.match(/^(?:const\s+)?(?:(?:unsigned|signed)\s+)?(?:(?:short|long long|long)\s+)?(int|float|double|bool|char)\s+(.+);$/);
|
|
436
|
-
if (globalDeclarationMatch) {
|
|
437
|
-
const kind = globalDeclarationMatch[1] === 'bool' ? 'bool' : 'number';
|
|
438
|
-
const declarations = [];
|
|
439
|
-
let declarationBuffer = '';
|
|
440
|
-
let declarationBraceDepth = 0;
|
|
441
|
-
for (const character of globalDeclarationMatch[2]) {
|
|
442
|
-
if (character === ',' && declarationBraceDepth === 0) {
|
|
443
|
-
if (declarationBuffer.trim())
|
|
444
|
-
declarations.push(declarationBuffer.trim());
|
|
445
|
-
declarationBuffer = '';
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
if (character === '{')
|
|
449
|
-
declarationBraceDepth += 1;
|
|
450
|
-
if (character === '}')
|
|
451
|
-
declarationBraceDepth = Math.max(0, declarationBraceDepth - 1);
|
|
452
|
-
declarationBuffer += character;
|
|
453
|
-
}
|
|
454
|
-
if (declarationBuffer.trim())
|
|
455
|
-
declarations.push(declarationBuffer.trim());
|
|
456
|
-
for (const declaration of declarations) {
|
|
457
|
-
const [left] = declaration.split('=');
|
|
458
|
-
const declarator = left?.trim() || '';
|
|
459
|
-
if (/[*&\[]/.test(declarator))
|
|
460
|
-
continue;
|
|
461
|
-
const name = declarator.match(/([A-Za-z_]\w*)\s*$/)?.[1];
|
|
462
|
-
if (!name)
|
|
463
|
-
continue;
|
|
464
|
-
const slot = nextVariableSlot++;
|
|
465
|
-
globalVariables.set(name, {
|
|
466
|
-
slot,
|
|
467
|
-
kind,
|
|
468
|
-
fromLine: index + 1,
|
|
469
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
470
|
-
});
|
|
471
|
-
this.debugGlobalMetadata = [
|
|
472
|
-
...this.debugGlobalMetadata,
|
|
473
|
-
{
|
|
474
|
-
slot,
|
|
475
|
-
name,
|
|
476
|
-
kind,
|
|
477
|
-
fromLine: index + 1,
|
|
478
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
479
|
-
}
|
|
480
|
-
];
|
|
481
|
-
globalInitialization.push(`${kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(0, ${slot}, ${name});`);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
const globalStructArrayMatch = isTopLevelDeclarationContext &&
|
|
485
|
-
normalized.match(/^(?:const\s+)?([A-Za-z_]\w*)\s+([A-Za-z_]\w*)\s*\[(\d+)\]\s*(?:=.*)?;$/);
|
|
486
|
-
if (globalStructArrayMatch) {
|
|
487
|
-
const structType = debugStructTypes.get(globalStructArrayMatch[1]);
|
|
488
|
-
if (structType) {
|
|
489
|
-
const slot = nextVariableSlot++;
|
|
490
|
-
this.debugGlobalMetadata = [
|
|
491
|
-
...this.debugGlobalMetadata,
|
|
492
|
-
{
|
|
493
|
-
slot,
|
|
494
|
-
name: globalStructArrayMatch[2],
|
|
495
|
-
kind: 'array',
|
|
496
|
-
length: Number(globalStructArrayMatch[3]),
|
|
497
|
-
dimensions: [Number(globalStructArrayMatch[3])],
|
|
498
|
-
structFields: structType.fields,
|
|
499
|
-
structSize: structType.size,
|
|
500
|
-
fromLine: index + 1,
|
|
501
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
502
|
-
}
|
|
503
|
-
];
|
|
504
|
-
globalInitialization.push(`__wasm_idle_debug_value_addr(0, ${slot}, (int)((unsigned long long)(${globalStructArrayMatch[2]})));`);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
if (inFunctionBody &&
|
|
508
|
-
normalized &&
|
|
509
|
-
!normalized.startsWith('#') &&
|
|
510
|
-
normalized !== '{' &&
|
|
511
|
-
normalized !== '}' &&
|
|
512
|
-
!normalized.startsWith('else') &&
|
|
513
|
-
!normalized.startsWith('case ') &&
|
|
514
|
-
normalized !== 'case' &&
|
|
515
|
-
!normalized.startsWith('default') &&
|
|
516
|
-
!normalized.startsWith('catch') &&
|
|
517
|
-
!/^(public|private|protected)\s*:/.test(normalized) &&
|
|
518
|
-
!normalized.endsWith(':') &&
|
|
519
|
-
!normalized.includes(' else ')) {
|
|
520
|
-
leadingInstrumentation.push(`${indent}__wasm_idle_debug_line(${currentFunctionId}, ${index + 1});`);
|
|
521
|
-
const declarationMatch = normalized.match(/^(?:const\s+)?(?:(?:unsigned|signed)\s+)?(?:(?:short|long long|long)\s+)?(int|float|double|bool|char)\s+(.+);$/);
|
|
522
|
-
const containerDeclarationMatch = normalized.match(/^(?:const\s+)?(?:(?:std::)?(vector|set|map))\s*<(.+)>\s+([A-Za-z_]\w*)\s*(?:=.*)?;$/);
|
|
523
|
-
if (containerDeclarationMatch && currentFunctionId) {
|
|
524
|
-
const slot = nextVariableSlot++;
|
|
525
|
-
const container = containerDeclarationMatch[1];
|
|
526
|
-
const name = containerDeclarationMatch[3];
|
|
527
|
-
declaredContainerNames.add(name);
|
|
528
|
-
currentFunctionContainers.set(name, {
|
|
529
|
-
slot,
|
|
530
|
-
container,
|
|
531
|
-
fromLine: index + 1,
|
|
532
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
533
|
-
});
|
|
534
|
-
this.debugVariableMetadata[currentFunctionId] = [
|
|
535
|
-
...(this.debugVariableMetadata[currentFunctionId] || []),
|
|
536
|
-
{
|
|
537
|
-
slot,
|
|
538
|
-
name,
|
|
539
|
-
kind: 'text',
|
|
540
|
-
fromLine: index + 1,
|
|
541
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
542
|
-
}
|
|
543
|
-
];
|
|
544
|
-
trailingInstrumentation.push(`${indent}__wasm_idle_debug_emit_${container}(${currentFunctionId}, ${slot}, ${name});`);
|
|
545
|
-
}
|
|
546
|
-
if (declarationMatch && currentFunctionId) {
|
|
547
|
-
const kind = declarationMatch[1] === 'bool' ? 'bool' : 'number';
|
|
548
|
-
const declarations = [];
|
|
549
|
-
let declarationBuffer = '';
|
|
550
|
-
let declarationParenDepth = 0;
|
|
551
|
-
let declarationBraceDepth = 0;
|
|
552
|
-
for (const character of declarationMatch[2]) {
|
|
553
|
-
if (character === ',' &&
|
|
554
|
-
declarationParenDepth === 0 &&
|
|
555
|
-
declarationBraceDepth === 0) {
|
|
556
|
-
if (declarationBuffer.trim())
|
|
557
|
-
declarations.push(declarationBuffer.trim());
|
|
558
|
-
declarationBuffer = '';
|
|
559
|
-
continue;
|
|
560
|
-
}
|
|
561
|
-
if (character === '(')
|
|
562
|
-
declarationParenDepth += 1;
|
|
563
|
-
if (character === ')')
|
|
564
|
-
declarationParenDepth = Math.max(0, declarationParenDepth - 1);
|
|
565
|
-
if (character === '{')
|
|
566
|
-
declarationBraceDepth += 1;
|
|
567
|
-
if (character === '}')
|
|
568
|
-
declarationBraceDepth = Math.max(0, declarationBraceDepth - 1);
|
|
569
|
-
declarationBuffer += character;
|
|
570
|
-
}
|
|
571
|
-
if (declarationBuffer.trim())
|
|
572
|
-
declarations.push(declarationBuffer.trim());
|
|
573
|
-
for (const declaration of declarations) {
|
|
574
|
-
const [left] = declaration.split('=');
|
|
575
|
-
const declarator = left?.trim() || '';
|
|
576
|
-
const arrayDimensions = [];
|
|
577
|
-
for (const match of declarator.matchAll(/\[(\d+)\]/g)) {
|
|
578
|
-
arrayDimensions.push(Number(match[1]));
|
|
579
|
-
}
|
|
580
|
-
const arrayName = declarator.match(/([A-Za-z_]\w*)\s*(?=\[\d+\])/);
|
|
581
|
-
if (arrayDimensions.length && arrayName) {
|
|
582
|
-
const slot = nextVariableSlot++;
|
|
583
|
-
this.debugVariableMetadata[currentFunctionId] = [
|
|
584
|
-
...(this.debugVariableMetadata[currentFunctionId] || []),
|
|
585
|
-
{
|
|
586
|
-
slot,
|
|
587
|
-
name: arrayName[1],
|
|
588
|
-
kind: 'array',
|
|
589
|
-
elementKind: declarationMatch[1],
|
|
590
|
-
length: arrayDimensions[0],
|
|
591
|
-
dimensions: arrayDimensions,
|
|
592
|
-
fromLine: index + 1,
|
|
593
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
594
|
-
}
|
|
595
|
-
];
|
|
596
|
-
trailingInstrumentation.push(`${indent}__wasm_idle_debug_value_addr(${currentFunctionId}, ${slot}, (int)((unsigned long long)(${arrayName[1]})));`);
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
if (/[*&]/.test(declarator))
|
|
600
|
-
continue;
|
|
601
|
-
const name = declarator.match(/([A-Za-z_]\w*)\s*(?:\[[^\]]*\])?$/)?.[1];
|
|
602
|
-
if (!name)
|
|
603
|
-
continue;
|
|
604
|
-
if (!currentFunctionVariables.has(name)) {
|
|
605
|
-
const slot = nextVariableSlot++;
|
|
606
|
-
currentFunctionVariables.set(name, {
|
|
607
|
-
slot,
|
|
608
|
-
kind,
|
|
609
|
-
fromLine: index + 1,
|
|
610
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
611
|
-
});
|
|
612
|
-
this.debugVariableMetadata[currentFunctionId] = [
|
|
613
|
-
...(this.debugVariableMetadata[currentFunctionId] || []),
|
|
614
|
-
{
|
|
615
|
-
slot,
|
|
616
|
-
name,
|
|
617
|
-
kind,
|
|
618
|
-
fromLine: index + 1,
|
|
619
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
620
|
-
}
|
|
621
|
-
];
|
|
622
|
-
}
|
|
623
|
-
if (declaration.includes('=')) {
|
|
624
|
-
const variable = currentFunctionVariables.get(name);
|
|
625
|
-
if (variable) {
|
|
626
|
-
trailingInstrumentation.push(`${indent}${variable.kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(${currentFunctionId}, ${variable.slot}, ${name});`);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
const forDeclarationMatch = normalized.match(/^for\s*\(\s*(?:const\s+)?(?:(?:unsigned|signed)\s+)?(?:(?:short|long long|long)\s+)?(int|float|double|bool|char)\s+([A-Za-z_]\w*)\s*=/);
|
|
632
|
-
if (forDeclarationMatch && currentFunctionId) {
|
|
633
|
-
const kind = forDeclarationMatch[1] === 'bool' ? 'bool' : 'number';
|
|
634
|
-
const name = forDeclarationMatch[2];
|
|
635
|
-
if (!currentFunctionVariables.has(name)) {
|
|
636
|
-
const slot = nextVariableSlot++;
|
|
637
|
-
currentFunctionVariables.set(name, {
|
|
638
|
-
slot,
|
|
639
|
-
kind,
|
|
640
|
-
fromLine: index + 1,
|
|
641
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
642
|
-
});
|
|
643
|
-
this.debugVariableMetadata[currentFunctionId] = [
|
|
644
|
-
...(this.debugVariableMetadata[currentFunctionId] || []),
|
|
645
|
-
{
|
|
646
|
-
slot,
|
|
647
|
-
name,
|
|
648
|
-
kind,
|
|
649
|
-
fromLine: index + 1,
|
|
650
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
651
|
-
}
|
|
652
|
-
];
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
if (!controlHeaderWithoutInlineBlock) {
|
|
656
|
-
for (const [name, container] of currentFunctionContainers) {
|
|
657
|
-
if (declaredContainerNames.has(name))
|
|
658
|
-
continue;
|
|
659
|
-
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
660
|
-
if (!new RegExp(`\\b${escapedName}\\b`).test(normalized))
|
|
661
|
-
continue;
|
|
662
|
-
trailingInstrumentation.push(`${indent}__wasm_idle_debug_emit_${container.container}(${currentFunctionId}, ${container.slot}, ${name});`);
|
|
663
|
-
}
|
|
664
|
-
for (const [name, variable] of currentFunctionVariables) {
|
|
665
|
-
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
666
|
-
if (normalized.startsWith('for') && variable.toLine === index + 1)
|
|
667
|
-
continue;
|
|
668
|
-
if (new RegExp(`(?:^|[^\\w])(?:\\+\\+|--)\\s*${escapedName}\\b`).test(normalized) ||
|
|
669
|
-
new RegExp(`\\b${escapedName}\\s*(?:[+\\-*/%]?=|\\+\\+|--)`).test(normalized) ||
|
|
670
|
-
new RegExp(`&\\s*${escapedName}\\b`).test(normalized) ||
|
|
671
|
-
new RegExp(`\\b(?:cin|std::cin)\\b[^;]*>>\\s*${escapedName}\\b`).test(normalized)) {
|
|
672
|
-
trailingInstrumentation.push(`${indent}${variable.kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(${currentFunctionId}, ${variable.slot}, ${name});`);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
for (const [name, variable] of globalVariables) {
|
|
676
|
-
if (currentFunctionVariables.has(name) ||
|
|
677
|
-
currentFunctionContainers.has(name))
|
|
678
|
-
continue;
|
|
679
|
-
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
680
|
-
if (new RegExp(`(?:^|[^\\w])(?:\\+\\+|--)\\s*${escapedName}\\b`).test(normalized) ||
|
|
681
|
-
new RegExp(`\\b${escapedName}\\s*(?:[+\\-*/%]?=|\\+\\+|--)`).test(normalized) ||
|
|
682
|
-
new RegExp(`&\\s*${escapedName}\\b`).test(normalized) ||
|
|
683
|
-
new RegExp(`\\b(?:cin|std::cin)\\b[^;]*>>\\s*${escapedName}\\b`).test(normalized)) {
|
|
684
|
-
trailingInstrumentation.push(`${indent}${variable.kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(0, ${variable.slot}, ${name});`);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
if (/^return\b/.test(normalized))
|
|
689
|
-
leadingInstrumentation.push(`${indent}__wasm_idle_debug_leave(${currentFunctionId});`);
|
|
690
|
-
}
|
|
691
|
-
if (functionDepth > 0 && braceDepth === functionDepth && normalized === '}') {
|
|
692
|
-
leadingInstrumentation.push(`${indent}__wasm_idle_debug_leave(${currentFunctionId});`);
|
|
693
|
-
}
|
|
694
|
-
if (inFunctionBody &&
|
|
695
|
-
currentFunctionId &&
|
|
696
|
-
(/^(while|if)\s*\(/.test(normalized) || /^for\s*\(/.test(normalized))) {
|
|
697
|
-
const keywordMatch = normalized.match(/^(while|if|for)\b/);
|
|
698
|
-
const keyword = keywordMatch?.[1];
|
|
699
|
-
const keywordIndex = line.indexOf(keyword || '');
|
|
700
|
-
const openIndex = keywordIndex >= 0 ? line.indexOf('(', keywordIndex) : -1;
|
|
701
|
-
if (openIndex >= 0) {
|
|
702
|
-
let closeIndex = -1;
|
|
703
|
-
let parenDepth = 0;
|
|
704
|
-
for (let cursor = openIndex; cursor < line.length; cursor += 1) {
|
|
705
|
-
const character = line[cursor];
|
|
706
|
-
if (character === '(')
|
|
707
|
-
parenDepth += 1;
|
|
708
|
-
if (character === ')') {
|
|
709
|
-
parenDepth -= 1;
|
|
710
|
-
if (parenDepth === 0) {
|
|
711
|
-
closeIndex = cursor;
|
|
712
|
-
break;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
for (const [name, variable] of globalVariables) {
|
|
716
|
-
if (currentFunctionVariables.has(name) ||
|
|
717
|
-
currentFunctionContainers.has(name))
|
|
718
|
-
continue;
|
|
719
|
-
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
720
|
-
if (new RegExp(`(?:^|[^\\w])(?:\\+\\+|--)\\s*${escapedName}\\b`).test(normalized) ||
|
|
721
|
-
new RegExp(`\\b${escapedName}\\s*(?:[+\\-*/%]?=|\\+\\+|--)`).test(normalized) ||
|
|
722
|
-
new RegExp(`&\\s*${escapedName}\\b`).test(normalized)) {
|
|
723
|
-
trailingInstrumentation.push(`${indent}${variable.kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(0, ${variable.slot}, ${name});`);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
if (closeIndex > openIndex) {
|
|
728
|
-
const conditionSource = line.slice(openIndex + 1, closeIndex);
|
|
729
|
-
if (keyword === 'for') {
|
|
730
|
-
const segments = [];
|
|
731
|
-
let segmentBuffer = '';
|
|
732
|
-
let segmentDepth = 0;
|
|
733
|
-
for (const character of conditionSource) {
|
|
734
|
-
if (character === ';' && segmentDepth === 0) {
|
|
735
|
-
segments.push(segmentBuffer);
|
|
736
|
-
segmentBuffer = '';
|
|
737
|
-
continue;
|
|
738
|
-
}
|
|
739
|
-
if (character === '(')
|
|
740
|
-
segmentDepth += 1;
|
|
741
|
-
if (character === ')')
|
|
742
|
-
segmentDepth = Math.max(0, segmentDepth - 1);
|
|
743
|
-
segmentBuffer += character;
|
|
744
|
-
}
|
|
745
|
-
segments.push(segmentBuffer);
|
|
746
|
-
if (segments.length === 3 && segments[1]?.trim()) {
|
|
747
|
-
const initSource = segments[0].trim();
|
|
748
|
-
const updateSource = segments[2].trim();
|
|
749
|
-
const initHooks = [];
|
|
750
|
-
const conditionHooks = [];
|
|
751
|
-
const updateHooks = [];
|
|
752
|
-
const initLooksLikeDeclaration = /^(?:const\s+)?(?:(?:unsigned|signed)\s+)?(?:(?:short|long long|long)\s+)?(?:int|float|double|bool|char)\b/.test(initSource);
|
|
753
|
-
for (const [name, variable] of currentFunctionVariables) {
|
|
754
|
-
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
755
|
-
const mutationPattern = new RegExp(`(?:^|[^\\w])(?:\\+\\+|--)\\s*${escapedName}\\b|\\b${escapedName}\\s*(?:[+\\-*/%]?=|\\+\\+|--)`);
|
|
756
|
-
if (!initLooksLikeDeclaration &&
|
|
757
|
-
mutationPattern.test(initSource)) {
|
|
758
|
-
initHooks.push(`${variable.kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(${currentFunctionId}, ${variable.slot}, ${name})`);
|
|
759
|
-
}
|
|
760
|
-
if (initLooksLikeDeclaration &&
|
|
761
|
-
mutationPattern.test(initSource)) {
|
|
762
|
-
conditionHooks.push(`${variable.kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(${currentFunctionId}, ${variable.slot}, ${name})`);
|
|
763
|
-
}
|
|
764
|
-
if (mutationPattern.test(updateSource)) {
|
|
765
|
-
updateHooks.push(`${variable.kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(${currentFunctionId}, ${variable.slot}, ${name})`);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
const instrumentedInit = initHooks.length && initSource
|
|
769
|
-
? `(${initSource}, ${initHooks.join(', ')})`
|
|
770
|
-
: segments[0];
|
|
771
|
-
const instrumentedUpdate = updateHooks.length && updateSource
|
|
772
|
-
? `(${updateSource}, ${updateHooks.join(', ')})`
|
|
773
|
-
: segments[2];
|
|
774
|
-
rewrittenLine =
|
|
775
|
-
line.slice(0, openIndex + 1) +
|
|
776
|
-
`${instrumentedInit}; (${conditionHooks.length ? `${conditionHooks.join(', ')}, ` : ''}__wasm_idle_debug_line(${currentFunctionId}, ${index + 1}), (${segments[1].trim()})); ${instrumentedUpdate}` +
|
|
777
|
-
line.slice(closeIndex);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
rewrittenLine =
|
|
782
|
-
line.slice(0, openIndex + 1) +
|
|
783
|
-
`(__wasm_idle_debug_line(${currentFunctionId}, ${index + 1}), (${conditionSource.trim()}))` +
|
|
784
|
-
line.slice(closeIndex);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
instrumented.push(...leadingInstrumentation);
|
|
790
|
-
instrumented.push(rewrittenLine);
|
|
791
|
-
instrumented.push(...trailingInstrumentation);
|
|
792
|
-
const startsInlineFunctionBody = functionDepth === 0 &&
|
|
793
|
-
normalized.includes('(') &&
|
|
794
|
-
normalized.includes(')') &&
|
|
795
|
-
normalized.includes('{') &&
|
|
796
|
-
!/^(if|for|while|switch|catch)\b/.test(normalized) &&
|
|
797
|
-
!/^(class|struct|namespace|enum|union)\b/.test(normalized);
|
|
798
|
-
const startsPendingFunctionBody = functionDepth === 0 && !!pendingFunctionHeader && normalized === '{';
|
|
799
|
-
braceDepth += (analysisLine.match(/{/g) || []).length;
|
|
800
|
-
braceDepth -= (analysisLine.match(/}/g) || []).length;
|
|
801
|
-
if (startsInlineFunctionBody || startsPendingFunctionBody) {
|
|
802
|
-
functionDepth = braceDepth;
|
|
803
|
-
currentFunctionId = nextFunctionId++;
|
|
804
|
-
let functionName = 'anonymous';
|
|
805
|
-
if (startsInlineFunctionBody) {
|
|
806
|
-
const beforeParen = normalized.slice(0, normalized.indexOf('(')).trim();
|
|
807
|
-
functionName = beforeParen.split(/\s+/).pop() || functionName;
|
|
808
|
-
}
|
|
809
|
-
else if (pendingFunctionHeader) {
|
|
810
|
-
functionName = pendingFunctionHeader.functionName || functionName;
|
|
811
|
-
}
|
|
812
|
-
this.debugFunctionMetadata[currentFunctionId] = functionName;
|
|
813
|
-
nextVariableSlot = 1;
|
|
814
|
-
currentFunctionVariables = new Map();
|
|
815
|
-
currentFunctionContainers = new Map();
|
|
816
|
-
instrumented.push(`${indent} __wasm_idle_debug_enter(${currentFunctionId}, ${index + 1});`);
|
|
817
|
-
if (functionName === 'main') {
|
|
818
|
-
instrumented.push(`${indent} std::cout.setf(std::ios::unitbuf);`);
|
|
819
|
-
instrumented.push(`${indent} std::cerr.setf(std::ios::unitbuf);`);
|
|
820
|
-
instrumented.push(`${indent} setvbuf(stdout, nullptr, _IONBF, 0);`);
|
|
821
|
-
instrumented.push(`${indent} setvbuf(stderr, nullptr, _IONBF, 0);`);
|
|
822
|
-
}
|
|
823
|
-
const parameterSource = startsInlineFunctionBody
|
|
824
|
-
? normalized.slice(normalized.indexOf('(') + 1, normalized.lastIndexOf(')'))
|
|
825
|
-
: pendingFunctionHeader?.parameters || '';
|
|
826
|
-
for (const parameter of parameterSource
|
|
827
|
-
.split(',')
|
|
828
|
-
.map((value) => value.trim())
|
|
829
|
-
.filter(Boolean)) {
|
|
830
|
-
const cleaned = parameter.split('=')[0]?.trim() || '';
|
|
831
|
-
const containerParameterMatch = cleaned.match(/^(?:const\s+)?(?:(?:std::)?(vector|set|map)\s*<.+>)\s*&?\s*([A-Za-z_]\w*)\s*$/);
|
|
832
|
-
if (containerParameterMatch) {
|
|
833
|
-
const slot = nextVariableSlot++;
|
|
834
|
-
const container = containerParameterMatch[1];
|
|
835
|
-
const name = containerParameterMatch[2];
|
|
836
|
-
currentFunctionContainers.set(name, {
|
|
837
|
-
slot,
|
|
838
|
-
container,
|
|
839
|
-
fromLine: index + 1,
|
|
840
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
841
|
-
});
|
|
842
|
-
this.debugVariableMetadata[currentFunctionId] = [
|
|
843
|
-
...(this.debugVariableMetadata[currentFunctionId] || []),
|
|
844
|
-
{
|
|
845
|
-
slot,
|
|
846
|
-
name,
|
|
847
|
-
kind: 'text',
|
|
848
|
-
fromLine: index + 1,
|
|
849
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
850
|
-
}
|
|
851
|
-
];
|
|
852
|
-
instrumented.push(`${indent} __wasm_idle_debug_emit_${container}(${currentFunctionId}, ${slot}, ${name});`);
|
|
853
|
-
continue;
|
|
854
|
-
}
|
|
855
|
-
const parameterArrayDimensions = [];
|
|
856
|
-
for (const match of cleaned.matchAll(/\[(\d+)\]/g)) {
|
|
857
|
-
parameterArrayDimensions.push(Number(match[1]));
|
|
858
|
-
}
|
|
859
|
-
const parameterArrayName = cleaned.match(/([A-Za-z_]\w*)\s*(?=\[\d+\])/);
|
|
860
|
-
if (parameterArrayDimensions.length &&
|
|
861
|
-
parameterArrayName &&
|
|
862
|
-
/\b(int|float|double|bool|char)\b/.test(cleaned)) {
|
|
863
|
-
const slot = nextVariableSlot++;
|
|
864
|
-
this.debugVariableMetadata[currentFunctionId] = [
|
|
865
|
-
...(this.debugVariableMetadata[currentFunctionId] || []),
|
|
866
|
-
{
|
|
867
|
-
slot,
|
|
868
|
-
name: parameterArrayName[1],
|
|
869
|
-
kind: 'array',
|
|
870
|
-
elementKind: (cleaned.match(/\b(int|float|double|bool|char)\b/)?.[1] || 'int'),
|
|
871
|
-
length: parameterArrayDimensions[0],
|
|
872
|
-
dimensions: parameterArrayDimensions,
|
|
873
|
-
fromLine: index + 1,
|
|
874
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
875
|
-
}
|
|
876
|
-
];
|
|
877
|
-
instrumented.push(`${indent} __wasm_idle_debug_value_addr(${currentFunctionId}, ${slot}, (int)((unsigned long long)(${parameterArrayName[1]})));`);
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
if (/[*&\[]/.test(cleaned))
|
|
881
|
-
continue;
|
|
882
|
-
const nameMatch = cleaned.match(/([A-Za-z_]\w*)\s*(?:\[[^\]]*\])?\s*$/);
|
|
883
|
-
if (!nameMatch)
|
|
884
|
-
continue;
|
|
885
|
-
const name = nameMatch[1];
|
|
886
|
-
const kind = /\bbool\b/.test(cleaned)
|
|
887
|
-
? 'bool'
|
|
888
|
-
: /\b(?:int|float|double|char|short|long)\b/.test(cleaned)
|
|
889
|
-
? 'number'
|
|
890
|
-
: '';
|
|
891
|
-
if (!kind)
|
|
892
|
-
continue;
|
|
893
|
-
const slot = nextVariableSlot++;
|
|
894
|
-
currentFunctionVariables.set(name, {
|
|
895
|
-
slot,
|
|
896
|
-
kind,
|
|
897
|
-
fromLine: index + 1,
|
|
898
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
899
|
-
});
|
|
900
|
-
this.debugVariableMetadata[currentFunctionId] = [
|
|
901
|
-
...(this.debugVariableMetadata[currentFunctionId] || []),
|
|
902
|
-
{
|
|
903
|
-
slot,
|
|
904
|
-
name,
|
|
905
|
-
kind,
|
|
906
|
-
fromLine: index + 1,
|
|
907
|
-
toLine: Number.MAX_SAFE_INTEGER
|
|
908
|
-
}
|
|
909
|
-
];
|
|
910
|
-
instrumented.push(`${indent} ${kind === 'bool' ? '__wasm_idle_debug_value_bool' : '__wasm_idle_debug_value_num'}(${currentFunctionId}, ${slot}, ${name});`);
|
|
911
|
-
}
|
|
912
|
-
pendingFunctionHeader = undefined;
|
|
913
|
-
}
|
|
914
|
-
else if (functionDepth === 0 &&
|
|
915
|
-
normalized.includes('(') &&
|
|
916
|
-
normalized.includes(')') &&
|
|
917
|
-
!normalized.includes('{') &&
|
|
918
|
-
!normalized.endsWith(';') &&
|
|
919
|
-
!/^(if|for|while|switch|catch)\b/.test(normalized) &&
|
|
920
|
-
!/^(class|struct|namespace|enum|union)\b/.test(normalized)) {
|
|
921
|
-
const beforeParen = normalized.slice(0, normalized.indexOf('(')).trim();
|
|
922
|
-
pendingFunctionHeader = {
|
|
923
|
-
functionName: beforeParen.split(/\s+/).pop() || 'anonymous',
|
|
924
|
-
parameters: normalized.slice(normalized.indexOf('(') + 1, normalized.lastIndexOf(')'))
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
else if (normalized && normalized !== '{') {
|
|
928
|
-
pendingFunctionHeader = undefined;
|
|
929
|
-
}
|
|
930
|
-
if (functionDepth > 0 && braceDepth < functionDepth) {
|
|
931
|
-
functionDepth = 0;
|
|
932
|
-
currentFunctionId = 0;
|
|
933
|
-
currentFunctionVariables = new Map();
|
|
934
|
-
currentFunctionContainers = new Map();
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
if (globalInitialization.length) {
|
|
938
|
-
instrumented.push('struct __wasm_idle_debug_globals_init {');
|
|
939
|
-
instrumented.push(' __wasm_idle_debug_globals_init() {');
|
|
940
|
-
instrumented.push(...globalInitialization.map((line) => ` ${line}`));
|
|
941
|
-
instrumented.push(' }');
|
|
942
|
-
instrumented.push('} __wasm_idle_debug_globals_init_instance;');
|
|
943
|
-
}
|
|
944
|
-
source = instrumented.join('\n');
|
|
945
|
-
}
|
|
946
|
-
else {
|
|
947
|
-
this.debugVariableMetadata = {};
|
|
948
|
-
this.debugGlobalMetadata = [];
|
|
949
|
-
}
|
|
950
|
-
const code = toUtf8(source);
|
|
951
|
-
await this.ready;
|
|
952
|
-
this.memfs.addFile(input, code);
|
|
953
|
-
const clang = await this.getModule(clangUrl(this.path));
|
|
954
|
-
const compilerArgs = [
|
|
955
|
-
'-cc1',
|
|
956
|
-
'-emit-obj',
|
|
957
|
-
...clangCommonArgs,
|
|
958
|
-
'-O' + opt,
|
|
959
|
-
'-o',
|
|
960
|
-
obj,
|
|
961
|
-
standardArg,
|
|
962
|
-
'-x',
|
|
963
|
-
languageArg,
|
|
964
|
-
input,
|
|
965
|
-
...compileArgs
|
|
966
|
-
];
|
|
967
|
-
this.trace(`compile ${input} -> ${obj}`);
|
|
968
|
-
return await this.run(clang, true, 'clang', ...compilerArgs);
|
|
969
|
-
}
|
|
970
|
-
async link(obj, wasm, debug = false) {
|
|
971
|
-
const stackSize = 1024 * 1024;
|
|
972
|
-
const libdir = 'lib/wasm32-wasi';
|
|
973
|
-
const crt1 = `${libdir}/crt1.o`;
|
|
974
|
-
await this.ready;
|
|
975
|
-
const lld = await this.getModule(lldUrl(this.path));
|
|
976
|
-
this.trace(`link ${obj} -> ${wasm}`);
|
|
977
|
-
return await this.run(lld, this.log, 'wasm-ld', '--no-threads', '--export-dynamic', // TODO required?
|
|
978
|
-
...(debug ? ['--allow-undefined'] : []), '-z', `stack-size=${stackSize}`, `-L${libdir}`, crt1, obj, '-lc', '-lc++', '-lc++abi', '-lm', `-Llib/clang/8.0.1/lib/wasi`, '-lclang_rt.builtins-wasm32', '-o', wasm);
|
|
979
|
-
}
|
|
980
|
-
async run(module, out, ...args) {
|
|
981
|
-
this.memfs.out = out;
|
|
982
|
-
this.hostLog(`${args.join(' ')}\n`);
|
|
983
|
-
this.trace(`run ${args.join(' ')}`);
|
|
984
|
-
const start = +new Date();
|
|
985
|
-
const app = new App(module, this.memfs, args[0], ...args.slice(1));
|
|
986
|
-
app.trace = (message) => this.trace(message);
|
|
987
|
-
app.debugSession = {
|
|
988
|
-
buffer: this.debugBuffer,
|
|
989
|
-
interruptBuffer: this.debugInterruptBuffer,
|
|
990
|
-
watchBuffer: this.debugWatchBuffer,
|
|
991
|
-
watchResultBuffer: this.debugWatchResultBuffer,
|
|
992
|
-
breakpoints: new Set(this.debugBreakpoints),
|
|
993
|
-
breakpointVersion: 0,
|
|
994
|
-
pauseOnEntry: this.debugPauseOnEntry,
|
|
995
|
-
stepArmed: this.debugPauseOnEntry,
|
|
996
|
-
nextLineArmed: false,
|
|
997
|
-
stepOutArmed: false,
|
|
998
|
-
callDepth: 0,
|
|
999
|
-
stepOutDepth: 0,
|
|
1000
|
-
currentFunctionId: 0,
|
|
1001
|
-
currentLine: 0,
|
|
1002
|
-
resumeSkipActive: false,
|
|
1003
|
-
resumeSkipFunctionId: 0,
|
|
1004
|
-
resumeSkipLine: 0,
|
|
1005
|
-
nextLineFunctionId: 0,
|
|
1006
|
-
nextLineLine: 0,
|
|
1007
|
-
variableMetadata: this.debugVariableMetadata,
|
|
1008
|
-
globalVariableMetadata: this.debugGlobalMetadata,
|
|
1009
|
-
functionMetadata: this.debugFunctionMetadata,
|
|
1010
|
-
frames: [],
|
|
1011
|
-
globalValues: new Map(),
|
|
1012
|
-
onPause: (event) => this.onDebugEvent?.(event)
|
|
1013
|
-
};
|
|
1014
|
-
const instantiate = +new Date();
|
|
1015
|
-
const stillRunning = await app.run();
|
|
1016
|
-
const end = +new Date();
|
|
1017
|
-
if (this.log)
|
|
1018
|
-
this.stdout('\n');
|
|
1019
|
-
if (this.showTiming)
|
|
1020
|
-
this.stdout(`${green}(${start - instantiate}ms/${end - instantiate}ms)${normal}\n`);
|
|
1021
|
-
return stillRunning ? app : null;
|
|
1022
|
-
}
|
|
1023
|
-
async compileLink(code, options = {}) {
|
|
1024
|
-
const { language = 'CPP', args = [], compileArgs = args, debug = false, breakpoints = [], pauseOnEntry = false, cppVersion, cVersion, debugBuffer, interruptBuffer, watchBuffer, watchResultBuffer } = options;
|
|
1025
|
-
const input = language === 'C' ? `test.c` : `test.cc`, obj = `test.o`, wasm = `test.wasm`;
|
|
1026
|
-
this.beginTrace(debug);
|
|
1027
|
-
this.debugBreakpoints = new Set(debug ? breakpoints : []);
|
|
1028
|
-
this.debugPauseOnEntry = debug && pauseOnEntry;
|
|
1029
|
-
this.debugBuffer = debugBuffer;
|
|
1030
|
-
this.debugInterruptBuffer = interruptBuffer;
|
|
1031
|
-
this.debugWatchBuffer = watchBuffer;
|
|
1032
|
-
this.debugWatchResultBuffer = watchResultBuffer;
|
|
1033
|
-
const buildKey = JSON.stringify({
|
|
1034
|
-
code,
|
|
1035
|
-
language,
|
|
1036
|
-
compileArgs,
|
|
1037
|
-
cppVersion,
|
|
1038
|
-
cVersion,
|
|
1039
|
-
debug
|
|
1040
|
-
});
|
|
1041
|
-
if (this.lastBuildKey === buildKey) {
|
|
1042
|
-
this.trace(`reuse ${wasm}`);
|
|
1043
|
-
return this.wasm;
|
|
1044
|
-
}
|
|
1045
|
-
await this.compile({
|
|
1046
|
-
input,
|
|
1047
|
-
code,
|
|
1048
|
-
obj,
|
|
1049
|
-
language,
|
|
1050
|
-
compileArgs,
|
|
1051
|
-
cppVersion,
|
|
1052
|
-
cVersion,
|
|
1053
|
-
debug
|
|
1054
|
-
});
|
|
1055
|
-
await this.link(obj, wasm, debug);
|
|
1056
|
-
this.lastBuildKey = buildKey;
|
|
1057
|
-
const wasmBytes = Uint8Array.from(this.memfs.getFileContents(wasm));
|
|
1058
|
-
return (this.wasm = await this.hostLogAsync(`Compiling ${wasm}`, WebAssembly.compile(wasmBytes)));
|
|
1059
|
-
}
|
|
1060
|
-
async compileLinkRun(code, options = {}) {
|
|
1061
|
-
const { language = 'CPP', args = [], compileArgs = args, programArgs = [], debug = false, breakpoints = [], pauseOnEntry = false, cppVersion, cVersion, debugBuffer, interruptBuffer, watchBuffer, watchResultBuffer } = options;
|
|
1062
|
-
this.debug = debug;
|
|
1063
|
-
return await this.run(await this.compileLink(code, {
|
|
1064
|
-
language,
|
|
1065
|
-
compileArgs,
|
|
1066
|
-
debug,
|
|
1067
|
-
breakpoints,
|
|
1068
|
-
pauseOnEntry,
|
|
1069
|
-
cppVersion,
|
|
1070
|
-
cVersion,
|
|
1071
|
-
debugBuffer,
|
|
1072
|
-
interruptBuffer,
|
|
1073
|
-
watchBuffer,
|
|
1074
|
-
watchResultBuffer
|
|
1075
|
-
}), true, `test.wasm`, ...programArgs);
|
|
1076
|
-
}
|
|
1077
|
-
}
|