@fluffylabs/anan-as 1.1.6 → 1.2.0-47bd114
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/dist/bin/index.js +50 -49
- package/dist/build/debug-inline.js +1 -1
- package/dist/build/debug-raw-inline.js +1 -1
- package/dist/build/debug-raw.d.ts +13 -0
- package/dist/build/debug-raw.js +8 -0
- package/dist/build/debug-raw.wasm +0 -0
- package/dist/build/debug.d.ts +13 -0
- package/dist/build/debug.js +10 -0
- package/dist/build/debug.wasm +0 -0
- package/dist/build/release-inline.js +1 -1
- package/dist/build/release-mini-inline.js +1 -1
- package/dist/build/release-mini.d.ts +13 -0
- package/dist/build/release-mini.js +10 -0
- package/dist/build/release-mini.wasm +0 -0
- package/dist/build/release-stub-inline.js +1 -1
- package/dist/build/release-stub.d.ts +13 -0
- package/dist/build/release-stub.js +10 -0
- package/dist/build/release-stub.wasm +0 -0
- package/dist/build/release.d.ts +13 -0
- package/dist/build/release.js +10 -0
- package/dist/build/release.wasm +0 -0
- package/dist/build/test-inline.js +1 -1
- package/dist/build/test.wasm +0 -0
- package/package.json +5 -4
package/dist/bin/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
4
|
import { disassemble, HasMetadata, InputKind, prepareProgram, pvmDestroy, pvmResume, pvmSetRegisters, pvmStart, } from "../build/release.js";
|
|
5
5
|
import { LOG_GAS_COST, LOG_HOST_CALL_INDEX, printLogHostCall, WHAT } from "./src/log-host-call.js";
|
|
6
6
|
import { STATUS } from "./src/trace-parse.js";
|
|
@@ -52,16 +52,19 @@ function main() {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
function handleDisassemble(args) {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const { values, positionals: files } = parseArgs({
|
|
56
|
+
args,
|
|
57
|
+
allowPositionals: true,
|
|
58
|
+
options: {
|
|
59
|
+
spi: { type: "boolean", default: false },
|
|
60
|
+
"no-metadata": { type: "boolean", default: false },
|
|
61
|
+
help: { type: "boolean", short: "h", default: false },
|
|
62
|
+
},
|
|
59
63
|
});
|
|
60
|
-
if (
|
|
64
|
+
if (values.help) {
|
|
61
65
|
console.log(HELP_TEXT);
|
|
62
66
|
return;
|
|
63
67
|
}
|
|
64
|
-
const files = parsed._;
|
|
65
68
|
if (files.length === 0) {
|
|
66
69
|
console.error("Error: No file provided for disassemble command.");
|
|
67
70
|
console.error("Usage: anan-as disassemble [--spi] [--no-metadata] <file.(jam|pvm|spi|bin)>");
|
|
@@ -87,32 +90,37 @@ function handleDisassemble(args) {
|
|
|
87
90
|
console.error("Supported extensions: .jam, .pvm, .spi, .bin");
|
|
88
91
|
process.exit(1);
|
|
89
92
|
}
|
|
90
|
-
const kind =
|
|
91
|
-
const hasMetadata =
|
|
93
|
+
const kind = values.spi ? InputKind.SPI : InputKind.Generic;
|
|
94
|
+
const hasMetadata = values["no-metadata"] ? HasMetadata.No : HasMetadata.Yes;
|
|
92
95
|
const f = readFileSync(file);
|
|
93
96
|
const name = kind === InputKind.Generic ? "generic PVM" : "JAM SPI";
|
|
94
97
|
console.log(`🤖 Assembly of ${file} (as ${name})`);
|
|
95
98
|
console.log(disassemble(Array.from(f), kind, hasMetadata));
|
|
96
99
|
}
|
|
97
100
|
function handleRun(args) {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const { values, positionals: files } = parseArgs({
|
|
102
|
+
args,
|
|
103
|
+
allowPositionals: true,
|
|
104
|
+
options: {
|
|
105
|
+
spi: { type: "boolean", default: false },
|
|
106
|
+
"no-logs": { type: "boolean", default: false },
|
|
107
|
+
"no-metadata": { type: "boolean", default: false },
|
|
108
|
+
"no-log-host-call": { type: "boolean", default: false },
|
|
109
|
+
help: { type: "boolean", short: "h", default: false },
|
|
110
|
+
pc: { type: "string" },
|
|
111
|
+
gas: { type: "string" },
|
|
112
|
+
},
|
|
104
113
|
});
|
|
105
|
-
if (
|
|
114
|
+
if (values.help) {
|
|
106
115
|
console.log(HELP_TEXT);
|
|
107
116
|
return;
|
|
108
117
|
}
|
|
109
|
-
const files = parsed._;
|
|
110
118
|
if (files.length === 0) {
|
|
111
119
|
console.error("Error: No file provided for run command.");
|
|
112
120
|
console.error("Usage: anan-as run [--spi] [--no-logs] [--no-metadata] [--pc <number>] [--gas <number>] <file.jam> [spi-args.bin]");
|
|
113
121
|
process.exit(1);
|
|
114
122
|
}
|
|
115
|
-
const kind =
|
|
123
|
+
const kind = values.spi ? InputKind.SPI : InputKind.Generic;
|
|
116
124
|
let programFile;
|
|
117
125
|
let spiArgsStr;
|
|
118
126
|
if (kind === InputKind.SPI) {
|
|
@@ -136,12 +144,12 @@ function handleRun(args) {
|
|
|
136
144
|
}
|
|
137
145
|
// Validate SPI args file if provided
|
|
138
146
|
const spiArgs = parseSpiArgs(spiArgsStr);
|
|
139
|
-
const logs =
|
|
140
|
-
const logHostCall =
|
|
141
|
-
const hasMetadata =
|
|
147
|
+
const logs = !values["no-logs"];
|
|
148
|
+
const logHostCall = !values["no-log-host-call"];
|
|
149
|
+
const hasMetadata = values["no-metadata"] ? HasMetadata.No : HasMetadata.Yes;
|
|
142
150
|
// Parse and validate PC and gas options
|
|
143
|
-
const initialPc = parsePc(
|
|
144
|
-
const initialGas = parseGas(
|
|
151
|
+
const initialPc = parsePc(values.pc);
|
|
152
|
+
const initialGas = parseGas(values.gas);
|
|
145
153
|
const programCode = Array.from(readFileSync(programFile));
|
|
146
154
|
const name = kind === InputKind.Generic ? "generic PVM" : "JAM SPI";
|
|
147
155
|
console.log(`🚀 Running ${programFile} (as ${name})`);
|
|
@@ -185,16 +193,21 @@ function handleRun(args) {
|
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
function handleReplayTrace(args) {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
196
|
+
const { values, positionals: files } = parseArgs({
|
|
197
|
+
args,
|
|
198
|
+
allowPositionals: true,
|
|
199
|
+
options: {
|
|
200
|
+
"no-metadata": { type: "boolean", default: false },
|
|
201
|
+
"no-verify": { type: "boolean", default: false },
|
|
202
|
+
"no-logs": { type: "boolean", default: false },
|
|
203
|
+
"no-log-host-call": { type: "boolean", default: false },
|
|
204
|
+
help: { type: "boolean", short: "h", default: false },
|
|
205
|
+
},
|
|
192
206
|
});
|
|
193
|
-
if (
|
|
207
|
+
if (values.help) {
|
|
194
208
|
console.log(HELP_TEXT);
|
|
195
209
|
return;
|
|
196
210
|
}
|
|
197
|
-
const files = parsed._;
|
|
198
211
|
if (files.length === 0) {
|
|
199
212
|
console.error("Error: No trace file provided for replay-trace command.");
|
|
200
213
|
console.error("Usage: anan-as replay-trace [--no-metadata] [--no-verify] [--no-logs] <trace.log>");
|
|
@@ -206,10 +219,10 @@ function handleReplayTrace(args) {
|
|
|
206
219
|
process.exit(1);
|
|
207
220
|
}
|
|
208
221
|
const file = files[0];
|
|
209
|
-
const hasMetadata =
|
|
210
|
-
const verify =
|
|
211
|
-
const logs =
|
|
212
|
-
const logHostCall =
|
|
222
|
+
const hasMetadata = values["no-metadata"] ? HasMetadata.No : HasMetadata.Yes;
|
|
223
|
+
const verify = !values["no-verify"];
|
|
224
|
+
const logs = !values["no-logs"];
|
|
225
|
+
const logHostCall = !values["no-log-host-call"];
|
|
213
226
|
try {
|
|
214
227
|
const summary = replayTraceFile(file, {
|
|
215
228
|
logs,
|
|
@@ -227,16 +240,10 @@ function handleReplayTrace(args) {
|
|
|
227
240
|
process.exit(1);
|
|
228
241
|
}
|
|
229
242
|
}
|
|
230
|
-
function parseGas(
|
|
231
|
-
if (
|
|
243
|
+
function parseGas(gasStr) {
|
|
244
|
+
if (gasStr === undefined) {
|
|
232
245
|
return BigInt(10_000);
|
|
233
246
|
}
|
|
234
|
-
// Ensure it's a string/number, not boolean
|
|
235
|
-
if (typeof parsed.gas === "boolean") {
|
|
236
|
-
console.error("Error: --gas requires a value.");
|
|
237
|
-
process.exit(1);
|
|
238
|
-
}
|
|
239
|
-
const gasStr = String(parsed.gas);
|
|
240
247
|
// Reject floats and non-integer strings
|
|
241
248
|
if (gasStr.includes(".") || !/^-?\d+$/.test(gasStr)) {
|
|
242
249
|
console.error("Error: --gas must be a valid integer.");
|
|
@@ -269,16 +276,10 @@ function parseSpiArgs(spiArgsStr) {
|
|
|
269
276
|
return Array.from(readFileSync(spiArgsStr));
|
|
270
277
|
}
|
|
271
278
|
}
|
|
272
|
-
function parsePc(
|
|
273
|
-
if (
|
|
279
|
+
function parsePc(pcStr) {
|
|
280
|
+
if (pcStr === undefined) {
|
|
274
281
|
return 0;
|
|
275
282
|
}
|
|
276
|
-
// Ensure it's a string/number, not boolean
|
|
277
|
-
if (typeof parsed.pc === "boolean") {
|
|
278
|
-
console.error("Error: --pc requires a value.");
|
|
279
|
-
process.exit(1);
|
|
280
|
-
}
|
|
281
|
-
const pcStr = String(parsed.pc);
|
|
282
283
|
// Reject floats and non-integer strings
|
|
283
284
|
if (pcStr.includes(".") || !/^-?\d+$/.test(pcStr)) {
|
|
284
285
|
console.error("Error: --pc must be a valid integer.");
|