@gasm-compiler/cli 0.1.0 → 0.1.1
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 +79 -125
- package/dist/cli.js +0 -1
- package/package.json +3 -2
- package/dist/cli.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,172 +1,126 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gasm-compiler/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Command-line compiler for WebAssembly → WGSL**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Compile WebAssembly (`.wasm`) or AssemblyScript (`.as`/`.ts`) files to WGSL compute shaders from the command line. Built on top of [`@gasm-compiler/core`](https://www.npmjs.com/package/@gasm-compiler/core).
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
1. **Write AssemblyScript** code (a TypeScript-like subset of WebAssembly)
|
|
10
|
-
2. **Compile to WebAssembly** using the AssemblyScript compiler
|
|
11
|
-
3. **Transform to WGSL** using the Gasm Compiler Gasm compiler
|
|
12
|
-
4. **Execute on GPU** using WebGPU
|
|
13
|
-
|
|
14
|
-
## Quick Start
|
|
15
|
-
|
|
16
|
-
### Prerequisites
|
|
17
|
-
|
|
18
|
-
- [Deno](https://deno.com) installed
|
|
19
|
-
- AssemblyScript installed (or use `npm` within the examples folder)
|
|
7
|
+
---
|
|
20
8
|
|
|
21
|
-
|
|
9
|
+
## Installation
|
|
22
10
|
|
|
23
11
|
```bash
|
|
24
|
-
|
|
25
|
-
deno run --allow-all src/cli.ts compile examples/demo.as --output output.wgsl
|
|
26
|
-
|
|
27
|
-
# View help
|
|
28
|
-
deno run --allow-all src/cli.ts --help
|
|
29
|
-
|
|
30
|
-
# Show detailed compiler output
|
|
31
|
-
deno run --allow-all src/cli.ts compile examples/demo.as --verbose
|
|
12
|
+
npm install -g @gasm-compiler/cli
|
|
32
13
|
```
|
|
33
14
|
|
|
34
|
-
|
|
15
|
+
Or use without installing:
|
|
35
16
|
|
|
17
|
+
```bash
|
|
18
|
+
npx @gasm-compiler/cli compile shader.wasm -o shader.wgsl
|
|
36
19
|
```
|
|
37
|
-
packages/cli/
|
|
38
|
-
├── src/
|
|
39
|
-
│ ├── cli.ts # Main CLI entry point
|
|
40
|
-
│ ├── compiler.ts # Compilation orchestration
|
|
41
|
-
│ └── utils.ts # Utility functions
|
|
42
|
-
├── examples/
|
|
43
|
-
│ ├── package.json # AssemblyScript dependencies
|
|
44
|
-
│ ├── demo.as # Sample AssemblyScript program
|
|
45
|
-
│ └── asconfig.json # AssemblyScript compiler config
|
|
46
|
-
├── deno.json # Deno configuration
|
|
47
|
-
├── package.json # NPM package metadata
|
|
48
|
-
└── README.md # This file
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Example AssemblyScript Programs
|
|
52
|
-
|
|
53
|
-
### Simple Arithmetic
|
|
54
20
|
|
|
55
|
-
|
|
56
|
-
- Function definitions
|
|
57
|
-
- Integer arithmetic
|
|
58
|
-
- Memory operations
|
|
59
|
-
- Control flow
|
|
60
|
-
|
|
61
|
-
### WASM vs WGSL Execution Comparison
|
|
21
|
+
---
|
|
62
22
|
|
|
63
|
-
|
|
23
|
+
## Quick Start
|
|
64
24
|
|
|
65
25
|
```bash
|
|
66
|
-
#
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# 2. Run comparison (executes WASM natively and compiles to WGSL)
|
|
70
|
-
cd ../.. && deno run --allow-all --unstable-webgpu packages/cli/examples/compare.ts packages/cli/examples/simple_math.wasm
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
This validates that:
|
|
74
|
-
- ✅ WASM functions produce expected results
|
|
75
|
-
- ✅ WGSL code compiles successfully
|
|
76
|
-
- ✅ Compilation preserves semantics
|
|
26
|
+
# Compile a .wasm file to WGSL
|
|
27
|
+
gasm-compiler compile shader.wasm --output shader.wgsl
|
|
77
28
|
|
|
78
|
-
|
|
29
|
+
# Compile AssemblyScript to WGSL (compiles to Wasm first, then to WGSL)
|
|
30
|
+
gasm-compiler compile kernel.as --output kernel.wgsl
|
|
79
31
|
|
|
80
|
-
|
|
32
|
+
# Print WGSL to stdout
|
|
33
|
+
gasm-compiler compile shader.wasm
|
|
81
34
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
deno run --allow-all src/cli.ts compile examples/demo.as
|
|
85
|
-
|
|
86
|
-
# Save to file
|
|
87
|
-
deno run --allow-all src/cli.ts compile examples/demo.as --output output.wgsl
|
|
35
|
+
# Show verbose compilation steps
|
|
36
|
+
gasm-compiler compile shader.wasm --verbose
|
|
88
37
|
|
|
89
|
-
#
|
|
90
|
-
|
|
38
|
+
# View help
|
|
39
|
+
gasm-compiler --help
|
|
91
40
|
```
|
|
92
41
|
|
|
93
|
-
|
|
42
|
+
---
|
|
94
43
|
|
|
95
|
-
|
|
96
|
-
2. **Gasm Validation**: The compiler validates that the Wasm conforms to the Gasm specification
|
|
97
|
-
3. **IR Generation**: An intermediate representation is built for analysis and transformation
|
|
98
|
-
4. **WGSL Code Generation**: The IR is transformed into WGSL shader code ready for WebGPU
|
|
44
|
+
## Commands
|
|
99
45
|
|
|
100
|
-
|
|
46
|
+
### `compile <input>`
|
|
101
47
|
|
|
102
|
-
|
|
103
|
-
- `--output <file>` - Write output to file (default: stdout)
|
|
104
|
-
- `--verbose` - Show detailed compilation steps
|
|
105
|
-
- `--keep-wasm` - Keep intermediate WASM files
|
|
106
|
-
- `--optimize` - Apply optimization passes
|
|
48
|
+
Compiles a WebAssembly binary or AssemblyScript source to WGSL.
|
|
107
49
|
|
|
108
|
-
|
|
50
|
+
| Option | Description |
|
|
51
|
+
|--------|-------------|
|
|
52
|
+
| `--output <file>`, `-o` | Write WGSL output to a file (default: stdout) |
|
|
53
|
+
| `--verbose` | Show detailed compilation steps |
|
|
54
|
+
| `--keep-wasm` | Keep intermediate `.wasm` file when compiling from AssemblyScript |
|
|
55
|
+
| `--optimize` | Apply optimization passes |
|
|
109
56
|
|
|
110
|
-
|
|
57
|
+
**Examples:**
|
|
111
58
|
|
|
112
59
|
```bash
|
|
113
|
-
#
|
|
114
|
-
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Running Tests
|
|
60
|
+
# Compile pre-built Wasm
|
|
61
|
+
gasm-compiler compile my_shader.wasm -o my_shader.wgsl
|
|
118
62
|
|
|
119
|
-
|
|
63
|
+
# Compile AssemblyScript with verbose output
|
|
64
|
+
gasm-compiler compile gpu_kernel.as --verbose -o output.wgsl
|
|
120
65
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
deno test --allow-all
|
|
66
|
+
# Pipe output into another tool
|
|
67
|
+
gasm-compiler compile shader.wasm | tee shader.wgsl
|
|
124
68
|
```
|
|
125
69
|
|
|
126
|
-
|
|
70
|
+
---
|
|
127
71
|
|
|
128
|
-
|
|
72
|
+
## How It Works
|
|
129
73
|
|
|
130
74
|
```
|
|
131
|
-
AssemblyScript (.as)
|
|
75
|
+
AssemblyScript (.as/.ts) WebAssembly (.wasm)
|
|
76
|
+
↓ │
|
|
77
|
+
ASC Compiler │
|
|
78
|
+
↓ │
|
|
79
|
+
WebAssembly Binary ←────────────────┘
|
|
132
80
|
↓
|
|
133
|
-
|
|
81
|
+
Gasm Compiler (parse, validate, transform)
|
|
134
82
|
↓
|
|
135
|
-
|
|
136
|
-
↓
|
|
137
|
-
Core Compiler (Gasm)
|
|
138
|
-
├─ Parser
|
|
139
|
-
├─ Validator
|
|
140
|
-
├─ IR Generator
|
|
141
|
-
└─ Code Generator
|
|
142
|
-
↓
|
|
143
|
-
WGSL Code (.wgsl)
|
|
83
|
+
WGSL Compute Shader (.wgsl)
|
|
144
84
|
```
|
|
145
85
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
86
|
+
1. If the input is AssemblyScript, it is first compiled to WebAssembly using the AssemblyScript compiler
|
|
87
|
+
2. The WebAssembly binary is validated against the Gasm specification (GPU-safe subset)
|
|
88
|
+
3. The compiler transforms the Wasm into WGSL, restructuring control flow and lowering memory operations
|
|
89
|
+
4. The output is a valid WGSL compute shader ready for use with WebGPU
|
|
149
90
|
|
|
150
|
-
|
|
151
|
-
deno test --allow-all tests/cli_test.ts
|
|
91
|
+
---
|
|
152
92
|
|
|
153
|
-
|
|
154
|
-
deno test --allow-all --unstable-webgpu tests/execution_test.ts
|
|
93
|
+
## Writing Gasm-Compatible WebAssembly
|
|
155
94
|
|
|
156
|
-
|
|
95
|
+
Your WebAssembly module must conform to the Gasm subset:
|
|
157
96
|
|
|
158
|
-
-
|
|
159
|
-
-
|
|
160
|
-
-
|
|
161
|
-
-
|
|
162
|
-
- [ ] Integration with gpu.js or wgpu for execution
|
|
97
|
+
- Export a single linear memory as `"memory"`
|
|
98
|
+
- Only import globals from the `"gasm"` module (GPU built-ins like `global_invocation_id_x`)
|
|
99
|
+
- No function or memory imports
|
|
100
|
+
- Export your entry point function
|
|
163
101
|
|
|
164
|
-
|
|
102
|
+
**Example (WAT):**
|
|
103
|
+
```wasm
|
|
104
|
+
(module
|
|
105
|
+
(import "gasm" "global_invocation_id_x" (global $gid_x i32))
|
|
106
|
+
(memory (export "memory") 1)
|
|
107
|
+
(func (export "main")
|
|
108
|
+
;; Your GPU kernel logic here
|
|
109
|
+
;; Use $gid_x for per-thread indexing
|
|
110
|
+
))
|
|
111
|
+
```
|
|
165
112
|
|
|
166
|
-
- [
|
|
167
|
-
- [Gasm Specification](../../spec/gasm-v0.1.md)
|
|
168
|
-
- [AssemblyScript Handbook](https://www.assemblyscript.org/)
|
|
113
|
+
For the full list of available Gasm built-in globals and supported instructions, see the [`@gasm-compiler/core` documentation](https://www.npmjs.com/package/@gasm-compiler/core).
|
|
169
114
|
|
|
170
115
|
---
|
|
171
116
|
|
|
172
|
-
|
|
117
|
+
## Related Packages
|
|
118
|
+
|
|
119
|
+
- [`@gasm-compiler/core`](https://www.npmjs.com/package/@gasm-compiler/core) — Core compiler library (programmatic API)
|
|
120
|
+
- [`@gasm-compiler/math-reference`](https://www.npmjs.com/package/@gasm-compiler/math-reference) — CPU-side reference implementations of Gasm math functions
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
See [LICENSE](./LICENSE) for details.
|
package/dist/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasm-compiler/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "CLI for compiling WebAssembly/AssemblyScript to WGSL using Gasm Compiler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cli.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
|
+
"!dist/**/*.map",
|
|
20
21
|
"LICENSE",
|
|
21
22
|
"README.md"
|
|
22
23
|
],
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"cli"
|
|
35
36
|
],
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@gasm-compiler/core": "0.1.
|
|
38
|
+
"@gasm-compiler/core": "0.1.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"assemblyscript": "v0.28.9",
|
package/dist/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/compiler.ts"],"sourcesContent":["/**\n * Gasm Compiler CLI - Main Entry Point\n *\n * Provides a command-line interface for compiling AssemblyScript to WGSL\n * using the Gasm compiler.\n */\n\nimport { parseArgs } from \"jsr:@std/cli/parse-args\";\nimport { compileAssemblyScriptToWGSL } from \"./compiler.ts\";\n\nconst VERSION = \"0.1.0\";\n\ninterface CLIOptions {\n help?: boolean;\n version?: boolean;\n output?: string;\n \"wat-output\"?: string;\n verbose?: boolean;\n \"keep-wasm\"?: boolean;\n optimize?: boolean;\n \"deny-f64-demotion\"?: boolean;\n \"allow-i64-demotion\"?: boolean;\n \"warnings-as-errors\"?: boolean;\n \"source-mapping\"?: string;\n _: string[];\n}\n\nasync function main() {\n const args = parseArgs(Deno.args, {\n string: [\"output\", \"wat-output\", \"source-mapping\"],\n boolean: [\n \"help\",\n \"version\",\n \"verbose\",\n \"keep-wasm\",\n \"optimize\",\n \"deny-f64-demotion\",\n \"allow-i64-demotion\",\n \"warnings-as-errors\",\n ],\n default: {\n verbose: false,\n \"keep-wasm\": false,\n optimize: false,\n },\n }) as CLIOptions;\n\n // Handle --version\n if (args.version) {\n console.log(`Gasm Compiler CLI v${VERSION}`);\n Deno.exit(0);\n }\n\n // Handle --help or no command\n if (args.help || args._.length === 0) {\n printHelp();\n Deno.exit(args.help ? 0 : 1);\n }\n\n const command = args._[0];\n\n try {\n if (command === \"compile\") {\n if (args._.length < 2) {\n console.error(\"Error: compile requires an input file\");\n console.error(\"Usage: cli compile <input.as|wasm> [--output <output.wgsl>]\");\n Deno.exit(1);\n }\n\n const inputFile = args._[1] as string;\n const options = {\n output: args.output as string | undefined,\n watOutput: args[\"wat-output\"] as string | undefined,\n verbose: args.verbose as boolean,\n keepWasm: args[\"keep-wasm\"] as boolean,\n optimize: args.optimize as boolean,\n denyF64Demotion: args[\"deny-f64-demotion\"] as boolean,\n allowI64Demotion: args[\"allow-i64-demotion\"] as boolean,\n warningsAsErrors: args[\"warnings-as-errors\"] as boolean,\n sourceMapping: args[\"source-mapping\"] as string | undefined,\n };\n\n await compileAssemblyScriptToWGSL(inputFile, options);\n } else {\n console.error(`Unknown command: ${command}`);\n printHelp();\n Deno.exit(1);\n }\n } catch (error) {\n console.error(\"Error:\", error instanceof Error ? error.message : String(error));\n if (args.verbose && error instanceof Error && error.stack) {\n console.error(\"\\nStack trace:\");\n console.error(error.stack);\n }\n Deno.exit(1);\n }\n}\n\nfunction printHelp() {\n console.log(`\nGasm Compiler CLI v${VERSION}\nCompile WebAssembly or AssemblyScript to WGSL using the Gasm compiler\n\nUSAGE:\n gasm-compiler <COMMAND> [OPTIONS] [ARGS]\n\nCOMMANDS:\n compile <input.wasm|.as> Compile WebAssembly or AssemblyScript to WGSL\n help Show this help message\n version Show version information\n\nOPTIONS:\n --output <file> Write WGSL output to file (default: stdout)\n --wat-output <file> Also write WAT (WebAssembly Text) disassembly to file\n --verbose Show detailed compilation steps\n --keep-wasm Keep intermediate WASM files\n --optimize Apply optimization passes\n --deny-f64-demotion Fail if f64 would be demoted to f32\n --allow-i64-demotion Allow lossy i64→i32 demotion (mod 2^32)\n --warnings-as-errors Treat compiler warnings as errors\n --source-mapping <level> Add source mapping comments (none, minimal, normal, detailed, verbose)\n --help Show this help message\n --version Show version information\n\nEXAMPLES:\n # Compile WASM to stdout\n deno run --allow-all src/cli.ts compile input.wasm\n\n # Compile WASM to file\n deno run --allow-all src/cli.ts compile input.wasm --output output.wgsl\n\n # Compile with verbose output\n deno run --allow-all src/cli.ts compile input.wasm --verbose --output output.wgsl\n\n # Compile with optimization\n deno run --allow-all src/cli.ts compile input.wasm --optimize --output output.wgsl\n\nDOCUMENTATION:\n https://github.com/MartinEricsson/gasm-compiler\n `);\n}\n\n// Run main\nmain().catch((error) => {\n console.error(\"Fatal error:\", error);\n Deno.exit(1);\n});\n","/**\n * Gasm Compiler CLI - Compilation Orchestration\n *\n * Handles the compilation pipeline:\n * AssemblyScript → WASM → Gasm Validation → IR → WGSL\n * \n * Note: This Deno-based CLI wrapper will be deprecated in favor of\n * the Node.js compiler exported from @gasm-compiler/core/compiler\n */\n\nimport { resolve } from \"jsr:@std/path\";\nimport { ensureFile } from \"jsr:@std/fs\";\nimport { \n compileWithDiagnostics, \n disassembleToWAT,\n parseWasmModule,\n isParseError,\n type CompileDiagnostics \n} from \"@gasm-compiler/core\";\n\nexport interface CompileOptions {\n output?: string;\n watOutput?: string;\n verbose?: boolean;\n keepWasm?: boolean;\n optimize?: boolean;\n denyF64Demotion?: boolean;\n allowI64Demotion?: boolean;\n warningsAsErrors?: boolean;\n sourceMapping?: string;\n}\n\nfunction printDiagnostics(diagnostics: CompileDiagnostics, verbose: boolean): void {\n for (const w of diagnostics.warnings) {\n const where = w.functionName ? ` (${w.functionName})` : \"\";\n console.error(`warning${where}: ${w.message}`);\n }\n\n if (verbose && diagnostics.demotions.length > 0) {\n const counts = new Map<string, number>();\n for (const d of diagnostics.demotions) {\n counts.set(d.kind, (counts.get(d.kind) ?? 0) + 1);\n }\n const parts = [...counts.entries()].map(([kind, count]) => `${kind} (${count})`);\n console.error(`demotions: ${parts.join(\", \")}`);\n }\n}\n\n/**\n * Compiles an AssemblyScript file to WGSL using the Gasm compiler.\n *\n * Pipeline:\n * 1. Validate input file exists\n * 2. Compile AssemblyScript to WASM using asc\n * 3. Read WASM binary\n * 4. Compile WASM to WGSL using Gasm\n * 5. Write output to file or stdout\n *\n * @param inputFile - Path to .as file\n * @param options - Compilation options\n */\nexport async function compileAssemblyScriptToWGSL(\n inputFile: string,\n options: CompileOptions = {},\n) {\n const {\n output: outputFile,\n watOutput: watOutputFile,\n verbose = false,\n keepWasm = false,\n optimize = false,\n denyF64Demotion = false,\n allowI64Demotion = false,\n warningsAsErrors = false,\n sourceMapping,\n } = options;\n\n try {\n // 1. Validate input file\n if (verbose) console.log(`[1/4] Validating input file: ${inputFile}`);\n\n const resolvedInput = resolve(inputFile);\n const stats = await Deno.stat(resolvedInput);\n\n if (!stats.isFile) {\n throw new Error(`Not a file: ${inputFile}`);\n }\n\n const isWasm = resolvedInput.endsWith(\".wasm\");\n\n if (!isWasm && !resolvedInput.endsWith(\".as\") && !resolvedInput.endsWith(\".ts\")) {\n console.warn(\"Warning: Input file does not have .as, .ts, or .wasm extension\");\n }\n\n let wasmPath = resolvedInput.replace(/\\.(as|ts)$/, \".wasm\");\n\n // 2. Compile AssemblyScript to WASM (if input is not already WASM)\n if (!isWasm) {\n if (verbose) console.log(\"[2/4] Compiling AssemblyScript to WASM...\");\n\n const asmPath = await getAssemblyScriptPath();\n\n // If input ends with .as, create a temporary .ts file for asc\n // (asc appends .ts to .as files, causing lookup failures)\n let inputForAsc = resolvedInput;\n let cleanupTsFile = false;\n\n if (resolvedInput.endsWith(\".as\")) {\n inputForAsc = resolvedInput.replace(/\\.as$/, \".ts\");\n cleanupTsFile = true;\n\n try {\n // Create a symlink from .as to .ts\n await Deno.symlink(resolvedInput, inputForAsc);\n } catch (e) {\n if (!(e instanceof Deno.errors.AlreadyExists)) {\n // If symlink fails for other reasons, copy the file instead\n const content = await Deno.readTextFile(resolvedInput);\n await Deno.writeTextFile(inputForAsc, content);\n }\n }\n }\n\n const compileCommand = new Deno.Command(asmPath, {\n args: [inputForAsc, \"-o\", wasmPath],\n stdout: \"piped\",\n stderr: \"piped\",\n });\n\n const compileProcess = compileCommand.spawn();\n const { success, stdout, stderr } = await compileProcess.output();\n\n // Clean up temporary .ts file if we created it\n if (cleanupTsFile) {\n try {\n await Deno.remove(inputForAsc);\n } catch {\n // Ignore cleanup errors\n }\n }\n\n if (!success) {\n const errorMsg = new TextDecoder().decode(stderr);\n throw new Error(`AssemblyScript compilation failed:\\n${errorMsg}`);\n }\n\n if (verbose) {\n const output = new TextDecoder().decode(stdout);\n if (output) console.log(output);\n }\n } else {\n if (verbose) console.log(\"[2/4] Input is WASM, skipping compilation...\");\n wasmPath = resolvedInput;\n }\n\n // 3. Read WASM binary and compile to WGSL\n if (verbose) console.log(\"[3/4] Reading WASM binary...\");\n\n const wasmBytes = await Deno.readFile(wasmPath);\n\n if (verbose) {\n console.log(` WASM size: ${wasmBytes.length} bytes`);\n console.log(\"[4/4] Compiling WASM to WGSL using Gasm...\");\n }\n\n const demotionPolicy: {\n f64?: \"allow\" | \"deny\";\n i64?: \"deny\" | \"allow-lossy\";\n } = {};\n if (denyF64Demotion) demotionPolicy.f64 = \"deny\";\n if (allowI64Demotion) demotionPolicy.i64 = \"allow-lossy\";\n\n // Parse source mapping level\n type SourceMappingLevel = \"none\" | \"minimal\" | \"normal\" | \"detailed\" | \"verbose\";\n const validLevels: SourceMappingLevel[] = [\"none\", \"minimal\", \"normal\", \"detailed\", \"verbose\"];\n let sourceMappingLevel: SourceMappingLevel | undefined;\n if (sourceMapping) {\n if (validLevels.includes(sourceMapping as SourceMappingLevel)) {\n sourceMappingLevel = sourceMapping as SourceMappingLevel;\n } else {\n console.warn(`Warning: Unknown source-mapping level \"${sourceMapping}\", using \"normal\"`);\n sourceMappingLevel = \"normal\";\n }\n }\n\n const result = compileWithDiagnostics(wasmBytes, {\n optimize,\n demotionPolicy,\n warningsAsErrors,\n sourceMapping: sourceMappingLevel,\n });\n\n printDiagnostics(result.diagnostics, verbose);\n\n if (!result.ok) {\n const first = result.diagnostics.errors[0];\n throw new Error(first?.message ?? \"Compilation failed\");\n }\n\n const wgslCode = result.wgsl;\n\n // 4. Generate WAT disassembly if requested\n if (watOutputFile) {\n if (verbose) console.log(\"[4a/4] Generating WAT disassembly...\");\n \n // Parse the WASM to get the module structure\n const parseResult = parseWasmModule(wasmBytes);\n \n // Check if parsing succeeded\n if (!isParseError(parseResult)) {\n const watCode = disassembleToWAT(parseResult);\n const resolvedWatOutput = resolve(watOutputFile);\n await ensureFile(resolvedWatOutput);\n await Deno.writeTextFile(resolvedWatOutput, watCode);\n \n if (verbose) {\n console.log(`✓ WAT disassembly written to: ${resolvedWatOutput}`);\n } else {\n console.log(`✓ WAT written to: ${watOutputFile}`);\n }\n } else {\n console.warn(`Warning: Failed to parse WASM for WAT disassembly: ${parseResult.message}`);\n }\n }\n\n // 5. Write WGSL output\n if (outputFile) {\n const resolvedOutput = resolve(outputFile);\n await ensureFile(resolvedOutput);\n await Deno.writeTextFile(resolvedOutput, wgslCode);\n\n if (verbose) {\n console.log(`✓ Successfully compiled to: ${resolvedOutput}`);\n } else {\n console.log(`✓ Compiled to: ${outputFile}`);\n }\n } else {\n console.log(wgslCode);\n }\n\n // Clean up intermediate WASM if not keeping (and we generated it)\n if (!keepWasm && !isWasm) {\n try {\n await Deno.remove(wasmPath);\n if (verbose) console.log(\" Cleaned up intermediate WASM file\");\n } catch {\n // Ignore cleanup errors\n }\n }\n } catch (error) {\n if (error instanceof Error) {\n throw error;\n }\n throw new Error(`Unknown error: ${String(error)}`);\n }\n}\n\n/**\n * Locates the AssemblyScript compiler executable\n * Tries multiple common paths\n */\nasync function getAssemblyScriptPath(): Promise<string> {\n // Get the directory of the current script for relative path resolution\n const scriptDir = new URL(\".\", import.meta.url).pathname;\n\n const possiblePaths = [\n // Relative to CLI package\n resolve(scriptDir, \"../../node_modules/.bin/asc\"),\n resolve(scriptDir, \"../../node_modules/.pnpm/assemblyscript@0.28.9/node_modules/assemblyscript/node_modules/.bin/asc\"),\n resolve(scriptDir, \"../node_modules/.bin/asc\"),\n resolve(scriptDir, \"../examples/node_modules/.bin/asc\"),\n \n // Relative to workspace root\n resolve(scriptDir, \"../../node_modules/.bin/asc\"),\n resolve(scriptDir, \"../../../node_modules/.bin/asc\"),\n \n // AssemblyScript toy example\n resolve(scriptDir, \"../../assemblyscript-toy/node_modules/.bin/asc\"),\n ];\n\n for (const path of possiblePaths) {\n try {\n const stat = await Deno.stat(path);\n if (stat.isFile) {\n return path;\n }\n } catch {\n // Path doesn't exist, try next\n }\n }\n\n // If not found, assume 'asc' is in PATH\n return \"asc\";\n}\n"],"mappings":";;;;;AAOA,SAAS,iBAAiB;;;ACG1B,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAcP,SAAS,iBAAiB,aAAiC,SAAwB;AACjF,aAAW,KAAK,YAAY,UAAU;AACpC,UAAM,QAAQ,EAAE,eAAe,KAAK,EAAE,YAAY,MAAM;AACxD,YAAQ,MAAM,UAAU,KAAK,KAAK,EAAE,OAAO,EAAE;AAAA,EAC/C;AAEA,MAAI,WAAW,YAAY,UAAU,SAAS,GAAG;AAC/C,UAAM,SAAS,oBAAI,IAAoB;AACvC,eAAW,KAAK,YAAY,WAAW;AACrC,aAAO,IAAI,EAAE,OAAO,OAAO,IAAI,EAAE,I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