@specy/x86 2.1.0 → 2.2.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/LICENSE.md +39 -0
- package/dist/index.d.mts +334 -231
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +418 -125
- package/dist/index.mjs.map +1 -1
- package/dist/wasm/nasm.d.mts +47 -0
- package/dist/wasm/nasm.mjs +2 -0
- package/dist/wasm/nasm.wasm +0 -0
- package/package.json +2 -1
- package/dist/assets/assemblers/nasm.3.00.elf +0 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright 2022 Justine Alexandra Roberts Tunney
|
|
4
|
+
Copyright 2024 Alberto Ventafridda
|
|
5
|
+
Copyright 2026 Specy
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
The three notices above are all carried by this package. The wrapper is the
|
|
22
|
+
work of Specy; `dist/index.mjs` inlines blink compiled to WebAssembly, which
|
|
23
|
+
is the work of Justine Tunney (https://github.com/jart/blink) as extended by
|
|
24
|
+
Alberto Ventafridda's libblink target. All three are under the ISC license
|
|
25
|
+
above.
|
|
26
|
+
|
|
27
|
+
## Bundled binaries
|
|
28
|
+
|
|
29
|
+
`dist/assets/assemblers` holds static x86-64 executables that the emulator
|
|
30
|
+
runs as guest programs. They are separate works under their own licenses,
|
|
31
|
+
which the ISC license above does not cover:
|
|
32
|
+
|
|
33
|
+
- `nasm.3.00.elf` - NASM 3.00, 2-clause BSD.
|
|
34
|
+
https://www.nasm.us
|
|
35
|
+
- `gnu-as.2.43.50.elf`, `gnu-ld.2.43.50.elf` - GNU Binutils 2.43.50, GPL-3.0
|
|
36
|
+
or later. https://sourceware.org/binutils
|
|
37
|
+
- `fasm.1.73.32.elf` - flat assembler 1.73.32, Copyright (c) 1999-2022 Tomasz
|
|
38
|
+
Grysztar, under its own permissive license.
|
|
39
|
+
https://flatassembler.net
|
package/dist/index.d.mts
CHANGED
|
@@ -5,78 +5,173 @@ declare function toResourceUrl(source: string | URL): URL;
|
|
|
5
5
|
declare function readResourceBytes(source: ResourceSource): Promise<Uint8Array>;
|
|
6
6
|
declare function defaultResourceUrl(relativePath: string, baseUrl: string): URL;
|
|
7
7
|
//#endregion
|
|
8
|
-
//#region src/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
//#region src/interface.d.ts
|
|
9
|
+
type StatusRegister = {
|
|
10
|
+
name: string;
|
|
11
|
+
value: number;
|
|
12
|
+
prev: number;
|
|
13
|
+
};
|
|
14
|
+
type DiagnosticSeverity = 'error' | 'warning';
|
|
15
|
+
type MonacoError = {
|
|
16
|
+
/** Project-relative source path when checking a virtual Project. */file?: string;
|
|
17
|
+
lineIndex: number;
|
|
18
|
+
column: number;
|
|
19
|
+
line: {
|
|
20
|
+
line: string;
|
|
21
|
+
line_index: number;
|
|
22
|
+
};
|
|
23
|
+
message: string;
|
|
24
|
+
formatted: string; /** A warning still assembles; only an error stops the build. Absent means error. */
|
|
25
|
+
severity?: DiagnosticSeverity; /** The assembler's own name for the warning, such as `label-orphan`. */
|
|
26
|
+
code?: string; /** Help beyond what the assembler said, when this diagnostic has a known explanation. */
|
|
27
|
+
hint?: string;
|
|
28
|
+
};
|
|
29
|
+
type StackFrame = {
|
|
30
|
+
name: string;
|
|
31
|
+
address: bigint;
|
|
32
|
+
destination: bigint;
|
|
33
|
+
sp: bigint;
|
|
15
34
|
line: number;
|
|
16
|
-
|
|
35
|
+
file?: string;
|
|
36
|
+
color: string;
|
|
37
|
+
};
|
|
38
|
+
type RegisterHex = [hi: string, lo: string];
|
|
39
|
+
declare enum RegisterSize {
|
|
40
|
+
Byte = 1,
|
|
41
|
+
Word = 2,
|
|
42
|
+
Long = 4,
|
|
43
|
+
Double = 8
|
|
17
44
|
}
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
diagnosticsParser?: DiagnosticsParser;
|
|
24
|
-
binaries: {
|
|
25
|
-
assembler: Binary;
|
|
26
|
-
linker?: Binary;
|
|
45
|
+
type ExecutionStep = {
|
|
46
|
+
mutations: MutationOperation[];
|
|
47
|
+
pc: number;
|
|
48
|
+
old_ccr: {
|
|
49
|
+
bits: number;
|
|
27
50
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
GNU_trunk: {
|
|
31
|
-
id: string;
|
|
32
|
-
displayName: string;
|
|
33
|
-
description: string;
|
|
34
|
-
diagnosticsParser: typeof gnuDiagnostics;
|
|
35
|
-
binaries: {
|
|
36
|
-
assembler: {
|
|
37
|
-
file: URL;
|
|
38
|
-
commands: string;
|
|
39
|
-
};
|
|
40
|
-
linker: {
|
|
41
|
-
file: URL;
|
|
42
|
-
commands: string;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
51
|
+
new_ccr: {
|
|
52
|
+
bits: number;
|
|
45
53
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
};
|
|
54
|
+
line: number;
|
|
55
|
+
file?: string;
|
|
56
|
+
};
|
|
57
|
+
type MutationOperation = {
|
|
58
|
+
type: 'WriteRegister';
|
|
59
|
+
value: {
|
|
60
|
+
register: string;
|
|
61
|
+
old: bigint;
|
|
62
|
+
size: RegisterSize;
|
|
57
63
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
} | {
|
|
65
|
+
type: 'WriteMemory';
|
|
66
|
+
value: {
|
|
67
|
+
address: bigint;
|
|
68
|
+
old: bigint;
|
|
69
|
+
size: RegisterSize;
|
|
70
|
+
};
|
|
71
|
+
} | {
|
|
72
|
+
type: 'WriteMemoryBytes';
|
|
73
|
+
value: {
|
|
74
|
+
address: bigint;
|
|
75
|
+
old: number[];
|
|
76
|
+
};
|
|
77
|
+
} | {
|
|
78
|
+
type: 'PopCallStack';
|
|
79
|
+
value: {
|
|
80
|
+
to: bigint;
|
|
81
|
+
from: bigint;
|
|
73
82
|
};
|
|
83
|
+
} | {
|
|
84
|
+
type: 'PushCallStack';
|
|
85
|
+
value: {
|
|
86
|
+
to: bigint;
|
|
87
|
+
from: bigint;
|
|
88
|
+
};
|
|
89
|
+
} | {
|
|
90
|
+
type: 'Other';
|
|
91
|
+
value: string;
|
|
74
92
|
};
|
|
75
|
-
type
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
93
|
+
type EmulatorDecoration = {
|
|
94
|
+
type: 'below-line';
|
|
95
|
+
note?: string;
|
|
96
|
+
belowLine: number;
|
|
97
|
+
md: string;
|
|
98
|
+
};
|
|
99
|
+
type CompilationError = {
|
|
100
|
+
type: 'raw';
|
|
101
|
+
message: string;
|
|
102
|
+
};
|
|
103
|
+
declare enum EmulatorStatus {
|
|
104
|
+
Terminated = 0,
|
|
105
|
+
Running = 1,
|
|
106
|
+
WaitingForInput = 2,
|
|
107
|
+
NotReady = 3
|
|
108
|
+
}
|
|
109
|
+
type Instruction = {
|
|
110
|
+
address: bigint;
|
|
111
|
+
lineNumber: number;
|
|
112
|
+
file?: string;
|
|
113
|
+
size?: number;
|
|
114
|
+
bytes?: Uint8Array;
|
|
115
|
+
code: string;
|
|
116
|
+
};
|
|
117
|
+
type EmulatorConfig<R extends string> = {
|
|
118
|
+
systemSize: RegisterSize;
|
|
119
|
+
registerNames: R[];
|
|
120
|
+
endianness?: 'little' | 'big';
|
|
121
|
+
hiddenRegisters?: R[];
|
|
122
|
+
};
|
|
123
|
+
declare abstract class BaseEmulator<T, R extends string, CompileResult = {
|
|
124
|
+
ok: true;
|
|
125
|
+
} | {
|
|
126
|
+
ok: false;
|
|
127
|
+
errors: CompilationError[];
|
|
128
|
+
report: string;
|
|
129
|
+
}> {
|
|
130
|
+
protected _registerNames: R[];
|
|
131
|
+
protected _systemSize: RegisterSize;
|
|
132
|
+
protected _endianness: 'little' | 'big';
|
|
133
|
+
constructor(options: EmulatorConfig<R>);
|
|
134
|
+
getSystemSize(): RegisterSize;
|
|
135
|
+
getEndianness(): 'little' | 'big';
|
|
136
|
+
getRegisterNames(): R[];
|
|
137
|
+
abstract initialize(undoSize: number): void;
|
|
138
|
+
abstract getCompiledCode(): {
|
|
139
|
+
decorations: EmulatorDecoration[];
|
|
140
|
+
code: string;
|
|
141
|
+
};
|
|
142
|
+
abstract dispose(): void;
|
|
143
|
+
abstract stringifyError(error: unknown): string;
|
|
144
|
+
abstract compile(code: string): Promise<CompileResult>;
|
|
145
|
+
abstract checkCode(code: string): Promise<MonacoError[]>;
|
|
146
|
+
abstract undo(): void;
|
|
147
|
+
abstract canUndo(): boolean;
|
|
148
|
+
abstract step(): Promise<{
|
|
149
|
+
terminated: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
abstract getStatus(): EmulatorStatus;
|
|
152
|
+
abstract writeMemoryBytes(address: bigint, data: Uint8Array): void;
|
|
153
|
+
abstract readMemoryBytes(address: bigint, length: bigint): Uint8Array;
|
|
154
|
+
abstract getNextInstruction(): Instruction | null;
|
|
155
|
+
abstract getUndoHistory(max: number): ExecutionStep[];
|
|
156
|
+
abstract getPc(): bigint;
|
|
157
|
+
abstract getSp(): bigint;
|
|
158
|
+
abstract getFlags(): {
|
|
159
|
+
name: string;
|
|
160
|
+
value: number;
|
|
161
|
+
prev?: number;
|
|
162
|
+
}[];
|
|
163
|
+
abstract getCallStack(): StackFrame[];
|
|
164
|
+
abstract getInstructionAt(address: bigint): Instruction | null;
|
|
165
|
+
abstract getRegisterValues(): bigint[];
|
|
166
|
+
abstract getRegisterValuesRecord(): Record<R, bigint>;
|
|
167
|
+
abstract getRegisterValue(register: R, size?: RegisterSize): bigint;
|
|
168
|
+
abstract setRegisterValue(register: R, value: bigint, size?: RegisterSize): void;
|
|
169
|
+
abstract hasTerminated(): boolean;
|
|
170
|
+
abstract run(limit?: number, breakpoints?: Array<number | {
|
|
171
|
+
path: string;
|
|
172
|
+
line: number;
|
|
173
|
+
}>): Promise<EmulatorStatus>;
|
|
174
|
+
}
|
|
80
175
|
//#endregion
|
|
81
176
|
//#region src/callbacks.d.ts
|
|
82
177
|
type MaybePromise<T> = T | PromiseLike<T>;
|
|
@@ -110,7 +205,9 @@ type StopReason = {
|
|
|
110
205
|
type X86CompilationDiagnostic = {
|
|
111
206
|
line: number;
|
|
112
207
|
error: string; /** Project-relative source path when compiling a virtual Project. */
|
|
113
|
-
file?: string;
|
|
208
|
+
file?: string; /** A warning still assembles; only an error stops the build. */
|
|
209
|
+
severity: DiagnosticSeverity; /** The assembler's own name for the warning, such as `label-orphan`. */
|
|
210
|
+
warningClass?: string;
|
|
114
211
|
};
|
|
115
212
|
type X86ProjectFile = string | Uint8Array;
|
|
116
213
|
type X86Project = {
|
|
@@ -122,13 +219,20 @@ type X86SourceLocation = {
|
|
|
122
219
|
line: number;
|
|
123
220
|
};
|
|
124
221
|
type X86Breakpoint = number | X86SourceLocation;
|
|
222
|
+
/**
|
|
223
|
+
* `diagnostics` carries everything the assembler said, warnings included - a
|
|
224
|
+
* successful build routinely has some, and they are the most useful thing it
|
|
225
|
+
* produces. `errors` is the subset that stopped the build.
|
|
226
|
+
*/
|
|
125
227
|
type X86CompileResult = {
|
|
126
228
|
ok: true;
|
|
127
229
|
report: string;
|
|
230
|
+
diagnostics: X86CompilationDiagnostic[];
|
|
128
231
|
} | {
|
|
129
232
|
ok: false;
|
|
130
233
|
errors: X86CompilationDiagnostic[];
|
|
131
234
|
report: string;
|
|
235
|
+
diagnostics: X86CompilationDiagnostic[];
|
|
132
236
|
};
|
|
133
237
|
type X86EmulatorEventMap = {
|
|
134
238
|
stateChange: {
|
|
@@ -148,6 +252,122 @@ type X86EmulatorEventMap = {
|
|
|
148
252
|
type X86EmulatorEventName = keyof X86EmulatorEventMap;
|
|
149
253
|
type X86EmulatorEventHandler<T extends X86EmulatorEventName> = (event: X86EmulatorEventMap[T]) => MaybePromise<void>;
|
|
150
254
|
//#endregion
|
|
255
|
+
//#region src/wasm-assembler.d.ts
|
|
256
|
+
/**
|
|
257
|
+
* An assembler that runs as its own WebAssembly module rather than as an x86-64
|
|
258
|
+
* ELF interpreted by blink. Blink costs roughly 1.2s of startup plus 14ms per
|
|
259
|
+
* line of source for NASM; the same work in its own module takes single-digit
|
|
260
|
+
* milliseconds, and produces byte-identical output.
|
|
261
|
+
*
|
|
262
|
+
* The object file comes back as bytes for the caller to stage wherever the
|
|
263
|
+
* linker expects it, so the linker can keep running inside blink unchanged.
|
|
264
|
+
*/
|
|
265
|
+
interface WasmAssembler {
|
|
266
|
+
assemble(project: X86Project): Promise<WasmAssemblyResult>;
|
|
267
|
+
}
|
|
268
|
+
type WasmAssemblyResult = {
|
|
269
|
+
/** The assembler's exit status: 0 when it wrote an object file. */status: number; /** What it wrote to stdout, verbatim. */
|
|
270
|
+
stdout: string; /** What it wrote to stderr, verbatim - the diagnostics a parser reads. */
|
|
271
|
+
stderr: string; /** The object file, or null when the assembly failed. */
|
|
272
|
+
object: Uint8Array | null;
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/assemblers.d.ts
|
|
276
|
+
interface Binary {
|
|
277
|
+
file: ResourceSource;
|
|
278
|
+
commands: string;
|
|
279
|
+
}
|
|
280
|
+
interface DiagnosticLine {
|
|
281
|
+
file?: string;
|
|
282
|
+
line: number;
|
|
283
|
+
error: string;
|
|
284
|
+
/** A warning still assembles; only an error stops the build. */
|
|
285
|
+
severity: DiagnosticSeverity;
|
|
286
|
+
/**
|
|
287
|
+
* NASM's own name for the warning, taken from the `[-w+label-orphan]` tag it
|
|
288
|
+
* appends. It is a stable identifier for the kind of mistake, which is what
|
|
289
|
+
* an explanation can be keyed on.
|
|
290
|
+
*/
|
|
291
|
+
warningClass?: string;
|
|
292
|
+
}
|
|
293
|
+
type DiagnosticsParser = (assemblerLogs: string) => DiagnosticLine[];
|
|
294
|
+
interface AssemblerMode {
|
|
295
|
+
id: string;
|
|
296
|
+
displayName: string;
|
|
297
|
+
description: string;
|
|
298
|
+
diagnosticsParser?: DiagnosticsParser;
|
|
299
|
+
binaries: {
|
|
300
|
+
/**
|
|
301
|
+
* The assembler as an x86-64 ELF for blink to interpret. Absent when
|
|
302
|
+
* `wasmAssembler` is set, which runs the assembler as its own module
|
|
303
|
+
* instead - far faster, but only possible for an assembler written in
|
|
304
|
+
* portable C. Fasm is written in x86 assembly and has no such build.
|
|
305
|
+
*/
|
|
306
|
+
assembler?: Binary;
|
|
307
|
+
linker?: Binary;
|
|
308
|
+
};
|
|
309
|
+
/** Runs outside blink, and takes precedence over `binaries.assembler`. */
|
|
310
|
+
wasmAssembler?: WasmAssembler;
|
|
311
|
+
}
|
|
312
|
+
declare const assemblers: {
|
|
313
|
+
GNU_trunk: {
|
|
314
|
+
id: string;
|
|
315
|
+
displayName: string;
|
|
316
|
+
description: string;
|
|
317
|
+
diagnosticsParser: typeof gnuDiagnostics;
|
|
318
|
+
binaries: {
|
|
319
|
+
assembler: {
|
|
320
|
+
file: URL;
|
|
321
|
+
commands: string;
|
|
322
|
+
};
|
|
323
|
+
linker: {
|
|
324
|
+
file: URL;
|
|
325
|
+
commands: string;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
FASM_trunk: {
|
|
330
|
+
id: string;
|
|
331
|
+
displayName: string;
|
|
332
|
+
description: string;
|
|
333
|
+
diagnosticsParser: typeof fasmDiagnostics;
|
|
334
|
+
binaries: {
|
|
335
|
+
assembler: {
|
|
336
|
+
file: URL;
|
|
337
|
+
commands: string;
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
NASM_trunk: {
|
|
342
|
+
id: string;
|
|
343
|
+
displayName: string;
|
|
344
|
+
description: string;
|
|
345
|
+
diagnosticsParser: typeof nasmDiagnostics;
|
|
346
|
+
binaries: {
|
|
347
|
+
linker: {
|
|
348
|
+
file: URL;
|
|
349
|
+
commands: string;
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
wasmAssembler: WasmAssembler;
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
type AssemblerId = keyof typeof assemblers;
|
|
356
|
+
declare const DEFAULT_ASSEMBLER_ID: AssemblerId;
|
|
357
|
+
declare function nasmDiagnostics(str: string): DiagnosticLine[];
|
|
358
|
+
declare function gnuDiagnostics(str: string): DiagnosticLine[];
|
|
359
|
+
declare function fasmDiagnostics(str: string): DiagnosticLine[];
|
|
360
|
+
/**
|
|
361
|
+
* The one-based column a diagnostic belongs on. NASM reports a line and no
|
|
362
|
+
* column, but it names the thing it is complaining about: `msg' in "symbol
|
|
363
|
+
* `msg' not defined", `.data' in a section warning. Finding that name in the
|
|
364
|
+
* line turns a whole-line squiggle into one under the mistake itself.
|
|
365
|
+
*
|
|
366
|
+
* Falls back to the first column, which is what the caller would have used
|
|
367
|
+
* anyway, so a message that names nothing findable is no worse off.
|
|
368
|
+
*/
|
|
369
|
+
declare function locateDiagnosticColumn(message: string, line: string, warningClass?: string): number;
|
|
370
|
+
//#endregion
|
|
151
371
|
//#region src/wasm-types.d.ts
|
|
152
372
|
type EmscriptenFS = {
|
|
153
373
|
init(stdin: () => number | null, stdout: (charCode: number) => void, stderr: (charCode: number) => void): void;
|
|
@@ -291,13 +511,18 @@ declare class BlinkRuntime {
|
|
|
291
511
|
state: BlinkState;
|
|
292
512
|
stopReason: StopReason | null;
|
|
293
513
|
assemblerLogs: string;
|
|
514
|
+
/** The subset of `assemblerDiagnostics` that stopped the build. */
|
|
294
515
|
assemblerErrors: X86CompilationDiagnostic[];
|
|
516
|
+
/** Everything the assembler said, warnings included. */
|
|
517
|
+
assemblerDiagnostics: X86CompilationDiagnostic[];
|
|
295
518
|
private readonly callbacks;
|
|
296
519
|
private readonly scheduler;
|
|
297
520
|
private readonly stateWaiters;
|
|
298
521
|
private readonly stdinBytes;
|
|
299
522
|
private sourceMap;
|
|
300
523
|
private sourceProject;
|
|
524
|
+
private assembleOnly;
|
|
525
|
+
private assembledObject;
|
|
301
526
|
private readonly defaultArgc;
|
|
302
527
|
private readonly defaultArgv;
|
|
303
528
|
private constructor();
|
|
@@ -305,6 +530,43 @@ declare class BlinkRuntime {
|
|
|
305
530
|
setMode(mode: AssemblerMode | AssemblerId): Promise<void>;
|
|
306
531
|
compileAssembly(code: string): Promise<X86CompileResult>;
|
|
307
532
|
compileProject(project: X86Project): Promise<X86CompileResult>;
|
|
533
|
+
/**
|
|
534
|
+
* Assembles without linking, for diagnostics. The linked executable is only
|
|
535
|
+
* needed to run or debug a program; a caller that just wants to know what is
|
|
536
|
+
* wrong with the source pays ~450ms for a link it never looks at.
|
|
537
|
+
*
|
|
538
|
+
* A mode with a `wasmAssembler` never touches blink here, so checking also
|
|
539
|
+
* leaves a loaded program - and anything paused in the debugger - alone.
|
|
540
|
+
*/
|
|
541
|
+
checkProject(project: X86Project): Promise<X86CompileResult>;
|
|
542
|
+
private checkProjectWithWasmAssembler;
|
|
543
|
+
private buildProject;
|
|
544
|
+
/**
|
|
545
|
+
* The object this build's assembler wrote, for the checks that read it
|
|
546
|
+
* rather than the assembler's own words. Null when the assembly failed, and
|
|
547
|
+
* when the assembler writes an executable directly and never produces one.
|
|
548
|
+
* Read once per build, so a previous build's object can never stand in for
|
|
549
|
+
* one that was never written.
|
|
550
|
+
*/
|
|
551
|
+
private takeAssembledObject;
|
|
552
|
+
/**
|
|
553
|
+
* Nothing in the toolchain treats a missing entry point as a failure: NASM
|
|
554
|
+
* has no opinion on it and `ld` only warns, then starts the program at the
|
|
555
|
+
* top of its text segment, where it runs whatever happens to be first. That
|
|
556
|
+
* is the least explicable thing a program can do to someone learning, so it
|
|
557
|
+
* is reported as an error here and the mistake is usually a misspelling.
|
|
558
|
+
*/
|
|
559
|
+
private entryPointDiagnostics;
|
|
560
|
+
private assembleInBlink;
|
|
561
|
+
/**
|
|
562
|
+
* Assembles outside blink and hands the object file to the linker inside it,
|
|
563
|
+
* which is where the state machine picks up again as if blink had produced
|
|
564
|
+
* the object itself.
|
|
565
|
+
*/
|
|
566
|
+
private assembleWithWasmAssembler;
|
|
567
|
+
private collectAssemblerDiagnostics;
|
|
568
|
+
private emitAssemblerOutput;
|
|
569
|
+
private parseAssemblerDiagnostics;
|
|
308
570
|
loadElf(data: ArrayBuffer | Uint8Array): void;
|
|
309
571
|
starti(): void;
|
|
310
572
|
pauseAtEntry(): void;
|
|
@@ -355,170 +617,6 @@ declare class BlinkRuntime {
|
|
|
355
617
|
private tryReadSourceMap;
|
|
356
618
|
}
|
|
357
619
|
//#endregion
|
|
358
|
-
//#region src/interface.d.ts
|
|
359
|
-
type StatusRegister = {
|
|
360
|
-
name: string;
|
|
361
|
-
value: number;
|
|
362
|
-
prev: number;
|
|
363
|
-
};
|
|
364
|
-
type MonacoError = {
|
|
365
|
-
/** Project-relative source path when checking a virtual Project. */file?: string;
|
|
366
|
-
lineIndex: number;
|
|
367
|
-
column: number;
|
|
368
|
-
line: {
|
|
369
|
-
line: string;
|
|
370
|
-
line_index: number;
|
|
371
|
-
};
|
|
372
|
-
message: string;
|
|
373
|
-
formatted: string;
|
|
374
|
-
};
|
|
375
|
-
type StackFrame = {
|
|
376
|
-
name: string;
|
|
377
|
-
address: bigint;
|
|
378
|
-
destination: bigint;
|
|
379
|
-
sp: bigint;
|
|
380
|
-
line: number;
|
|
381
|
-
file?: string;
|
|
382
|
-
color: string;
|
|
383
|
-
};
|
|
384
|
-
type RegisterHex = [hi: string, lo: string];
|
|
385
|
-
declare enum RegisterSize {
|
|
386
|
-
Byte = 1,
|
|
387
|
-
Word = 2,
|
|
388
|
-
Long = 4,
|
|
389
|
-
Double = 8
|
|
390
|
-
}
|
|
391
|
-
type ExecutionStep = {
|
|
392
|
-
mutations: MutationOperation[];
|
|
393
|
-
pc: number;
|
|
394
|
-
old_ccr: {
|
|
395
|
-
bits: number;
|
|
396
|
-
};
|
|
397
|
-
new_ccr: {
|
|
398
|
-
bits: number;
|
|
399
|
-
};
|
|
400
|
-
line: number;
|
|
401
|
-
file?: string;
|
|
402
|
-
};
|
|
403
|
-
type MutationOperation = {
|
|
404
|
-
type: 'WriteRegister';
|
|
405
|
-
value: {
|
|
406
|
-
register: string;
|
|
407
|
-
old: bigint;
|
|
408
|
-
size: RegisterSize;
|
|
409
|
-
};
|
|
410
|
-
} | {
|
|
411
|
-
type: 'WriteMemory';
|
|
412
|
-
value: {
|
|
413
|
-
address: bigint;
|
|
414
|
-
old: bigint;
|
|
415
|
-
size: RegisterSize;
|
|
416
|
-
};
|
|
417
|
-
} | {
|
|
418
|
-
type: 'WriteMemoryBytes';
|
|
419
|
-
value: {
|
|
420
|
-
address: bigint;
|
|
421
|
-
old: number[];
|
|
422
|
-
};
|
|
423
|
-
} | {
|
|
424
|
-
type: 'PopCallStack';
|
|
425
|
-
value: {
|
|
426
|
-
to: bigint;
|
|
427
|
-
from: bigint;
|
|
428
|
-
};
|
|
429
|
-
} | {
|
|
430
|
-
type: 'PushCallStack';
|
|
431
|
-
value: {
|
|
432
|
-
to: bigint;
|
|
433
|
-
from: bigint;
|
|
434
|
-
};
|
|
435
|
-
} | {
|
|
436
|
-
type: 'Other';
|
|
437
|
-
value: string;
|
|
438
|
-
};
|
|
439
|
-
type EmulatorDecoration = {
|
|
440
|
-
type: 'below-line';
|
|
441
|
-
note?: string;
|
|
442
|
-
belowLine: number;
|
|
443
|
-
md: string;
|
|
444
|
-
};
|
|
445
|
-
type CompilationError = {
|
|
446
|
-
type: 'raw';
|
|
447
|
-
message: string;
|
|
448
|
-
};
|
|
449
|
-
declare enum EmulatorStatus {
|
|
450
|
-
Terminated = 0,
|
|
451
|
-
Running = 1,
|
|
452
|
-
WaitingForInput = 2,
|
|
453
|
-
NotReady = 3
|
|
454
|
-
}
|
|
455
|
-
type Instruction = {
|
|
456
|
-
address: bigint;
|
|
457
|
-
lineNumber: number;
|
|
458
|
-
file?: string;
|
|
459
|
-
size?: number;
|
|
460
|
-
bytes?: Uint8Array;
|
|
461
|
-
code: string;
|
|
462
|
-
};
|
|
463
|
-
type EmulatorConfig<R extends string> = {
|
|
464
|
-
systemSize: RegisterSize;
|
|
465
|
-
registerNames: R[];
|
|
466
|
-
endianness?: 'little' | 'big';
|
|
467
|
-
hiddenRegisters?: R[];
|
|
468
|
-
};
|
|
469
|
-
declare abstract class BaseEmulator<T, R extends string, CompileResult = {
|
|
470
|
-
ok: true;
|
|
471
|
-
} | {
|
|
472
|
-
ok: false;
|
|
473
|
-
errors: CompilationError[];
|
|
474
|
-
report: string;
|
|
475
|
-
}> {
|
|
476
|
-
protected _registerNames: R[];
|
|
477
|
-
protected _systemSize: RegisterSize;
|
|
478
|
-
protected _endianness: 'little' | 'big';
|
|
479
|
-
constructor(options: EmulatorConfig<R>);
|
|
480
|
-
getSystemSize(): RegisterSize;
|
|
481
|
-
getEndianness(): 'little' | 'big';
|
|
482
|
-
getRegisterNames(): R[];
|
|
483
|
-
abstract initialize(undoSize: number): void;
|
|
484
|
-
abstract getCompiledCode(): {
|
|
485
|
-
decorations: EmulatorDecoration[];
|
|
486
|
-
code: string;
|
|
487
|
-
};
|
|
488
|
-
abstract dispose(): void;
|
|
489
|
-
abstract stringifyError(error: unknown): string;
|
|
490
|
-
abstract compile(code: string): Promise<CompileResult>;
|
|
491
|
-
abstract checkCode(code: string): Promise<MonacoError[]>;
|
|
492
|
-
abstract undo(): void;
|
|
493
|
-
abstract canUndo(): boolean;
|
|
494
|
-
abstract step(): Promise<{
|
|
495
|
-
terminated: boolean;
|
|
496
|
-
}>;
|
|
497
|
-
abstract getStatus(): EmulatorStatus;
|
|
498
|
-
abstract writeMemoryBytes(address: bigint, data: Uint8Array): void;
|
|
499
|
-
abstract readMemoryBytes(address: bigint, length: bigint): Uint8Array;
|
|
500
|
-
abstract getNextInstruction(): Instruction | null;
|
|
501
|
-
abstract getUndoHistory(max: number): ExecutionStep[];
|
|
502
|
-
abstract getPc(): bigint;
|
|
503
|
-
abstract getSp(): bigint;
|
|
504
|
-
abstract getFlags(): {
|
|
505
|
-
name: string;
|
|
506
|
-
value: number;
|
|
507
|
-
prev?: number;
|
|
508
|
-
}[];
|
|
509
|
-
abstract getCallStack(): StackFrame[];
|
|
510
|
-
abstract getInstructionAt(address: bigint): Instruction | null;
|
|
511
|
-
abstract getRegisterValues(): bigint[];
|
|
512
|
-
abstract getRegisterValuesRecord(): Record<R, bigint>;
|
|
513
|
-
abstract getRegisterValue(register: R, size?: RegisterSize): bigint;
|
|
514
|
-
abstract setRegisterValue(register: R, value: bigint, size?: RegisterSize): void;
|
|
515
|
-
abstract hasTerminated(): boolean;
|
|
516
|
-
abstract run(limit?: number, breakpoints?: Array<number | {
|
|
517
|
-
path: string;
|
|
518
|
-
line: number;
|
|
519
|
-
}>): Promise<EmulatorStatus>;
|
|
520
|
-
}
|
|
521
|
-
//#endregion
|
|
522
620
|
//#region src/project.d.ts
|
|
523
621
|
declare const X86_PROJECT_ROOT = "/__x86_project";
|
|
524
622
|
declare function validateX86Project(project: X86Project): void;
|
|
@@ -564,6 +662,11 @@ declare class X86Emulator extends BaseEmulator<BlinkRuntime, X86RegisterName, X8
|
|
|
564
662
|
dispose(): void;
|
|
565
663
|
stringifyError(error: unknown): string;
|
|
566
664
|
checkCode(code: string): Promise<MonacoError[]>;
|
|
665
|
+
/**
|
|
666
|
+
* Diagnostics only: this assembles but does not link, and for an assembler
|
|
667
|
+
* that runs as its own wasm module it does not touch blink at all, so a
|
|
668
|
+
* loaded or paused program survives a check.
|
|
669
|
+
*/
|
|
567
670
|
checkProject(project: X86Project): Promise<MonacoError[]>;
|
|
568
671
|
undo(): void;
|
|
569
672
|
canUndo(): boolean;
|
|
@@ -607,5 +710,5 @@ declare class X86Emulator extends BaseEmulator<BlinkRuntime, X86RegisterName, X8
|
|
|
607
710
|
}
|
|
608
711
|
declare function createX86Emulator(options?: X86EmulatorOptions): Promise<X86Emulator>;
|
|
609
712
|
//#endregion
|
|
610
|
-
export { AssemblerId, AssemblerMode, BaseEmulator, Binary, BlinkRunOptions, BlinkRuntime, BlinkRuntimeCallbacks, BlinkRuntimeOptions, BlinkState, BlinkenlibModule, BlinkenlibModuleOptions, CompilationError, DEFAULT_ASSEMBLER_ID, DiagnosticLine, DiagnosticsParser, DisassemblySnapshot, EmscriptenFS, EmulatorConfig, EmulatorDecoration, EmulatorStatus, ExecutionStep, Instruction, MaybePromise, MemoryReadResult, MemoryWriteResult, MonacoError, MutationOperation, NativeControlFlowKind, NativeInstruction, NativeMemoryWrite, NativeRunControls, NativeRunStop, NativeRunStopKind, NativeStepInfo, NativeSymbol, RegisterHex, RegisterSize, RegisterSnapshot, ResourceSource, StackFrame, StatusRegister, StopReason, StopReasonKind, X86Breakpoint, X86CompilationDiagnostic, X86CompileResult, X86Emulator, X86EmulatorEventHandler, X86EmulatorEventMap, X86EmulatorEventName, X86EmulatorOptions, X86Project, X86ProjectFile, X86RegisterName, X86SourceLocation, X86_PROJECT_ROOT, X86_REGISTER_NAMES, assemblers, createX86Emulator, defaultResourceUrl, fasmDiagnostics, gnuDiagnostics, isNodeRuntime, nasmDiagnostics, observeCallbackResult, readResourceBytes, stageX86Project, toResourceUrl, validateX86Project, x86ProjectSourcePath, x86ProjectText };
|
|
713
|
+
export { AssemblerId, AssemblerMode, BaseEmulator, Binary, BlinkRunOptions, BlinkRuntime, BlinkRuntimeCallbacks, BlinkRuntimeOptions, BlinkState, BlinkenlibModule, BlinkenlibModuleOptions, CompilationError, DEFAULT_ASSEMBLER_ID, DiagnosticLine, DiagnosticSeverity, DiagnosticsParser, DisassemblySnapshot, EmscriptenFS, EmulatorConfig, EmulatorDecoration, EmulatorStatus, ExecutionStep, Instruction, MaybePromise, MemoryReadResult, MemoryWriteResult, MonacoError, MutationOperation, NativeControlFlowKind, NativeInstruction, NativeMemoryWrite, NativeRunControls, NativeRunStop, NativeRunStopKind, NativeStepInfo, NativeSymbol, RegisterHex, RegisterSize, RegisterSnapshot, ResourceSource, StackFrame, StatusRegister, StopReason, StopReasonKind, X86Breakpoint, X86CompilationDiagnostic, X86CompileResult, X86Emulator, X86EmulatorEventHandler, X86EmulatorEventMap, X86EmulatorEventName, X86EmulatorOptions, X86Project, X86ProjectFile, X86RegisterName, X86SourceLocation, X86_PROJECT_ROOT, X86_REGISTER_NAMES, assemblers, createX86Emulator, defaultResourceUrl, fasmDiagnostics, gnuDiagnostics, isNodeRuntime, locateDiagnosticColumn, nasmDiagnostics, observeCallbackResult, readResourceBytes, stageX86Project, toResourceUrl, validateX86Project, x86ProjectSourcePath, x86ProjectText };
|
|
611
714
|
//# sourceMappingURL=index.d.mts.map
|