@specy/risc-v 0.1.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 ADDED
@@ -0,0 +1,152 @@
1
+ # RiscV-js
2
+ This is a Typescript implementation of a RISC-V simulator made by compiling the [RARS RISC-V simulator](https://github.com/TheThirdOne/rars) to Javascript.
3
+ It is part of a family of javascript assembly interpreters/simulators:
4
+
5
+ - MIPS: [git repo](https://github.com/Specy/mars), [npm package](https://www.npmjs.com/package/@specy/mips)
6
+ - RISC-V: [git repo](https://github.com/Specy/rars), [npm package](https://www.npmjs.com/package/@specy/risc-v)
7
+ - X86: [git repo](https://github.com/Specy/x86-js), [npm package](https://www.npmjs.com/package/@specy/x86)
8
+ - M68K: [git repo](https://github.com/Specy/s68k), [npm package](https://www.npmjs.com/package/@specy/s68k)
9
+
10
+ ## Usage
11
+
12
+ First, create an instance of the simulator with the `RISCV.makeRiscvFromSource` function.
13
+
14
+ Before running the simulator, you must assemble and initialize it. You can then step through the program, simulate with breakpoints, or simulate with a limit.
15
+
16
+ ⚠️**WARNING**⚠️ You must have only one instance of the simulator at a time. Memory, registers, and other state may be shared or behave unpredictably with multiple instances.
17
+
18
+ ```typescript
19
+ import {RISCV, JsRiscV, RegisterName, BackStepAction} from '@specy/risc-v';
20
+ const sourceCode = `
21
+ li t0, 5 # Load immediate value 5 into register t0
22
+ li t1, 7 # Load immediate value 7 into register t1
23
+ add t2, t0, t1 # Add t0 and t1, store result in t2
24
+ `;
25
+
26
+ // RISCV.setIs64Bit(true); // Set to 64-bit mode if needed
27
+ const riscvSimulator: JsRiscV = RISCV.makeRiscVFromSource(sourceCode);
28
+
29
+ riscvSimulator.assemble();
30
+ riscvSimulator.initialize(true); // Start at 'main'
31
+
32
+ while (!riscvSimulator.terminated) {
33
+ riscvSimulator.step();
34
+ }
35
+ // or riscvSimulator.simulate()
36
+
37
+ const pc = riscvSimulator.programCounter;
38
+ const t2 = riscvSimulator.getRegisterValue('t2');
39
+
40
+ console.log(`Program Counter: ${pc}`);
41
+ console.log(`t2: ${t2}`);
42
+
43
+ // Accessing memory:
44
+ const data = riscvSimulator.readMemoryBytes(0xffff0000, 4); // Read 4 bytes from address 0xffff0000
45
+ riscvSimulator.setMemoryBytes(0xffff0000, [0x01, 0x02, 0x03, 0x04]); // Write 4 bytes to address 0xffff0000
46
+
47
+ // Registering Handlers (for syscalls and other events):
48
+ riscvSimulator.registerHandler("printInt", (value: number) => {
49
+ console.log("printInt syscall called with:", value);
50
+ });
51
+
52
+ // Accessing the undo stack:
53
+ const undoStack = riscvSimulator.getUndoStack();
54
+ undoStack.forEach(step => {
55
+ if (step.action === BackStepAction.REGISTER_RESTORE) {
56
+ console.log(`Register restored at PC ${step.pc}`);
57
+ }
58
+ });
59
+
60
+
61
+ // Simulating with breakpoints:
62
+ const breakpoints = [0x00400004, 0x00400008]; // Example breakpoint addresses
63
+ riscvSimulator.simulateWithBreakpoints(breakpoints);
64
+
65
+ //Simulating with a limit
66
+ const limit = 100
67
+ riscvSimulator.simulateWithLimit(limit);
68
+
69
+ //Simulating with breakpoints and a limit
70
+ riscvSimulator.simulateWithBreakpointsAndLimit(breakpoints, limit);
71
+
72
+ //Setting Register Values:
73
+ riscvSimulator.setRegisterValue("t0", 42);
74
+ ```
75
+
76
+ ## API
77
+
78
+ ### `RISCV` Static Class
79
+
80
+ Provides static methods to initialize and create simulator instances.
81
+
82
+ * `RISCV.makeRiscvFromSource(source: string): JsRiscv`
83
+ Creates a new `JsRiscv` instance from RISC-V assembly source code. This also initializes the underlying RISC-V simulation environment if it hasn't been already.
84
+ * `RISCV.initializeRISCV(): void`
85
+ Initializes the core RISC-V simulation environment. Called internally by `makeRiscvFromSource`, but can be called explicitly if needed.
86
+ * `RISCV.getInstructionSet(): JsInstruction[]`
87
+ Returns an array of objects, each describing a supported RISC-V instruction (name, example, description, tokens).
88
+ * `RISCV.setIs64Bit(is64Bit: boolean): void`
89
+ Sets the simulator to operate in 32-bit or 64-bit mode. This affects the instruction set.
90
+
91
+ ### `JsRiscv` Interface
92
+
93
+ This interface provides methods to control and interact with a RISC-V simulator instance.
94
+
95
+ #### Properties
96
+
97
+ * `canUndo: boolean` (Read-only): True if an undo operation can be performed.
98
+ * `programCounter: number` (Read-only): The current value of the program counter (PC).
99
+ * `stackPointer: number` (Read-only): The current value of the stack pointer (`$sp`).
100
+ * `terminated: boolean` (Read-only): True if the simulation has terminated (e.g., via an exit syscall or error).
101
+
102
+ #### Methods
103
+
104
+ * `assemble(): RISCVAssembleResult`: Assembles the program. Returns an object containing a report, error list, and an `hasErrors` flag.
105
+ * `initialize(startAtMain: boolean): void`: Initializes the simulator state for execution. If `startAtMain` is true, execution begins at the `main` label; otherwise, it starts at the first instruction.
106
+ * `step(): boolean`: Executes a single instruction. Returns `true` if the execution is complete (program terminated), `false` otherwise.
107
+ * `undo(): void`: Undoes the last instruction executed, if `canUndo` is true and undo is enabled.
108
+ * `setUndoEnabled(enabled: boolean): void`: Enables or disables the undo feature.
109
+ * `setUndoSize(size: number): void`: Sets the maximum number of steps kept in the undo history. Must be called before assembling.
110
+ * `simulateWithLimit(limit: number): boolean`: Simulates the program for a maximum of `limit` instructions. Returns `true` if execution completes/terminates before the limit, `false` otherwise.
111
+ * `simulateWithBreakpoints(breakpoints: number[]): boolean`: Simulates the program until a breakpoint is reached or the program terminates. `breakpoints` is an array of memory addresses. Returns `true` if execution completes/terminates, `false` if a breakpoint is hit.
112
+ * `simulateWithBreakpointsAndLimit(breakpoints: number[], limit: number): boolean`: Simulates until a breakpoint, limit is reached, or termination. Returns `true` if execution completes/terminates, `false` otherwise.
113
+ * `getRegisterValue(register: RegisterName): number`: Returns the value of the specified register.
114
+ * `setRegisterValue(register: RegisterName, value: number): void`: Sets the value of the specified register.
115
+ * `getRegistersValues(): number[]`: Returns an array of all general-purpose register values. The order might be implementation-defined but usually corresponds to register numbers 0-31.
116
+ * `getConditionFlags(): number[]`: Gets the 8 condition flags (if applicable, typically related to floating-point or custom extensions).
117
+ * `registerHandler<T extends HandlerName>(name: T, handler: (...args: HandlerMap[T]['in']) => HandlerMap[T]['out']): void`: Registers a handler function for a specific event (e.g., syscalls). See `HandlerName` and `HandlerMap` for details.
118
+ * `getUndoStack(): JsBackStep[]`: Returns the undo stack, an array of `JsBackStep` objects representing simulation history.
119
+ * `readMemoryBytes(address: number, length: number): number[]`: Reads `length` bytes from memory starting at `address`. Returns an array of byte values.
120
+ * `setMemoryBytes(address: number, bytes: number[]): void`: Writes an array of `bytes` to memory starting at `address`.
121
+ * `getCurrentStatementIndex(): number`: Returns the index of the current instruction in the list of assembled program statements.
122
+ * `getNextStatement(): JsProgramStatement | null`: Returns the next `JsProgramStatement` to be executed, or `null` if at the end.
123
+ * `getStatementAtAddress(address: number): JsProgramStatement | null`: Gets the program statement at the given memory `address`.
124
+ * `getStatementAtSourceLine(line: number): JsProgramStatement | null`: Gets the program statement corresponding to the original source `line` number.
125
+ * `getCompiledStatements(): JsProgramStatement[]`: Returns an array of all assembled program statements.
126
+ * `getParsedStatements(): JsInstructionToken[]`: Returns an array of tokens from the initial parsing stage.
127
+ * `getTokenizedLines(): RiscvTokenizedLine[]`: Returns an array of lines, each with its source string and corresponding tokens.
128
+ * `getCallStack(): JsRiscvStackFrame[]`: Returns the current call stack as an array of stack frame objects.
129
+ * `getLabelAtAddress(address: number): string | null`: Returns the label name at the given memory `address`, or `null` if no label exists there.
130
+
131
+ #### Helper Functions (for use with `JsRiscv`)
132
+
133
+ * `registerHandlers(riscv: JsRiscv, handlers: Partial<HandlerMapFns>): void`: A utility to register multiple handlers at once.
134
+ * `unimplementedHandler(name: HandlerName): (...args: any[]) => any`: Returns a function that throws an error indicating the handler `name` is not implemented. Useful for stubbing handlers.
135
+
136
+ #### Types
137
+
138
+ * `RegisterName`: Union type for RISC-V register names (e.g., `'ra'`, `'sp'`, `'a0'`, `'t0'`, etc.).
139
+ * `HandlerName`: Union type of all possible handler names (keys of `HandlerMap`).
140
+ * `HandlerMap`: An object type mapping `HandlerName`s to their expected input argument types (`in`) and return type (`out`). This defines the signature for syscall/event handlers.
141
+ * `HandlerMapFns`: An object type where keys are `HandlerName`s and values are the corresponding handler functions.
142
+ * `DialogType`: Enum for message dialog types (`ERROR_MESSAGE`, `INFORMATION_MESSAGE`, `WARNING_MESSAGE`, `QUESTION_MESSAGE`).
143
+ * `ConfirmResult`: Enum for confirm dialog results (`YES`, `NO`, `CANCEL`).
144
+ * `BackStepAction`: Enum representing types of actions that can be undone (e.g., `MEMORY_RESTORE_WORD`, `REGISTER_RESTORE`).
145
+ * `JsBackStep`: Interface representing an entry in the undo stack, detailing the action, parameters, and PC value.
146
+ * `JsProgramStatement`: Interface representing an assembled instruction, including source line, address, binary/machine/assembly representations.
147
+ * `JsInstructionToken`: Interface representing a token from the assembly source (value, type, source position).
148
+ * `JsInstruction`: Interface describing a RISC-V instruction (name, example, description, token patterns).
149
+ * `RiscvTokenizedLine`: An object containing the original line string and its parsed `JsInstructionToken`s.
150
+ * `RISCVAssembleError`: Interface describing an assembly error (message, line/column, warning status, etc.).
151
+ * `RISCVAssembleResult`: Interface for the result of `assemble()`, containing a report string, list of `RISCVAssembleError`s, and a `hasErrors` boolean.
152
+ * `JsRiscvStackFrame`: Interface describing a frame on the call stack (PC, target address, SP, FP, register snapshot).
@@ -0,0 +1,467 @@
1
+ type JsInstructionToken = {
2
+ sourceLine: number;
3
+ sourceColumn: number;
4
+ originalSourceLine: number;
5
+ value: string;
6
+ type: string;
7
+ };
8
+ declare enum StopReason {
9
+ BREAKPOINT = 0,
10
+ EXCEPTION = 1,
11
+ MAX_STEPS = 2,// includes step mode (where maxSteps is 1)
12
+ NORMAL_TERMINATION = 3,
13
+ CLIFF_TERMINATION = 4,// run off bottom of program
14
+ PAUSE = 5,
15
+ STOP = 6
16
+ }
17
+ declare enum DialogType {
18
+ ERROR_MESSAGE = 0,
19
+ INFORMATION_MESSAGE = 1,
20
+ WARNING_MESSAGE = 2,
21
+ QUESTION_MESSAGE = 3
22
+ }
23
+ declare enum ConfirmResult {
24
+ YES = 0,
25
+ NO = 1,
26
+ CANCEL = 2
27
+ }
28
+ type HandlerMap = {
29
+ openFile: {
30
+ in: [filename: string, flags: number, append: boolean];
31
+ out: number;
32
+ };
33
+ closeFile: {
34
+ in: [fileDescriptor: number];
35
+ out: void;
36
+ };
37
+ writeFile: {
38
+ in: [fileDescriptor: number, buffer: number[]];
39
+ out: void;
40
+ };
41
+ readFile: {
42
+ in: [fileDescriptor: number, destination: number[], length: number];
43
+ out: number;
44
+ };
45
+ confirm: {
46
+ in: [message: string];
47
+ out: ConfirmResult;
48
+ };
49
+ inputDialog: {
50
+ in: [message: string];
51
+ out: string;
52
+ };
53
+ outputDialog: {
54
+ in: [message: string, type: DialogType];
55
+ out: void;
56
+ };
57
+ askDouble: {
58
+ in: [message: string];
59
+ out: number;
60
+ };
61
+ askFloat: {
62
+ in: [message: string];
63
+ out: number;
64
+ };
65
+ askInt: {
66
+ in: [message: string];
67
+ out: number;
68
+ };
69
+ askString: {
70
+ in: [message: string];
71
+ out: string;
72
+ };
73
+ readDouble: {
74
+ in: [];
75
+ out: number;
76
+ };
77
+ readFloat: {
78
+ in: [];
79
+ out: number;
80
+ };
81
+ readInt: {
82
+ in: [];
83
+ out: number;
84
+ };
85
+ readString: {
86
+ in: [];
87
+ out: string;
88
+ };
89
+ readChar: {
90
+ in: [];
91
+ out: string;
92
+ };
93
+ logLine: {
94
+ in: [message: string];
95
+ out: void;
96
+ };
97
+ log: {
98
+ in: [message: string];
99
+ out: void;
100
+ };
101
+ printChar: {
102
+ in: [c: string];
103
+ out: void;
104
+ };
105
+ printDouble: {
106
+ in: [d: number];
107
+ out: void;
108
+ };
109
+ printFloat: {
110
+ in: [f: number];
111
+ out: void;
112
+ };
113
+ printInt: {
114
+ in: [i: number];
115
+ out: void;
116
+ };
117
+ printString: {
118
+ in: [l: string];
119
+ out: void;
120
+ };
121
+ sleep: {
122
+ in: [milliseconds: number];
123
+ out: void;
124
+ };
125
+ stdIn: {
126
+ in: [buffer: number[], length: number];
127
+ out: void;
128
+ };
129
+ stdOut: {
130
+ in: [buffer: number[]];
131
+ out: void;
132
+ };
133
+ };
134
+ type JsInstruction = {
135
+ name: string;
136
+ example: string;
137
+ description: string;
138
+ tokens: JsInstructionToken[];
139
+ };
140
+ type RiscvTokenizedLine = {
141
+ line: string;
142
+ tokens: JsInstructionToken[];
143
+ };
144
+ type RISCVAssembleError = {
145
+ isWarning: boolean;
146
+ message: string;
147
+ macroExpansionHistory: string;
148
+ filename: string;
149
+ lineNumber: number;
150
+ columnNumber: number;
151
+ };
152
+ type RISCVAssembleResult = {
153
+ report: string;
154
+ errors: RISCVAssembleError[];
155
+ hasErrors: boolean;
156
+ };
157
+ declare class RISCV {
158
+ static makeRiscVFromSource: typeof makeRiscVfromSource;
159
+ static initializeRISCV: typeof initializeRISCV;
160
+ static getInstructionSet(): JsInstruction[];
161
+ static setIs64Bit(is64Bit: boolean): void;
162
+ }
163
+ type JsRiscVStackFrame = {
164
+ /**
165
+ * The program counter value at the moment the stack frame was created.
166
+ */
167
+ pc: number;
168
+ /**
169
+ * The address of the target instruction.
170
+ */
171
+ toAddress: number;
172
+ /**
173
+ * The stack pointer value at the moment the stack frame was created.
174
+ */
175
+ sp: number;
176
+ /**
177
+ * The frame pointer value at the moment the stack frame was created.
178
+ */
179
+ fp: number;
180
+ /**
181
+ * The values of all registers at the moment the stack frame was created.
182
+ */
183
+ registers: number[];
184
+ };
185
+ /**
186
+ * Represents a statement in the assembled program.
187
+ */
188
+ interface JsProgramStatement {
189
+ /**
190
+ * The line number in the original source code.
191
+ */
192
+ readonly sourceLine: number;
193
+ /**
194
+ * The memory address of the instruction.
195
+ */
196
+ readonly address: number;
197
+ /**
198
+ * The binary representation of the instruction.
199
+ */
200
+ readonly binaryStatement: number;
201
+ /**
202
+ * The original source code line.
203
+ */
204
+ readonly source: string;
205
+ /**
206
+ * The machine code representation of the instruction.
207
+ */
208
+ readonly machineStatement: string;
209
+ /**
210
+ * The assembly representation of the instruction.
211
+ */
212
+ readonly assemblyStatement: string;
213
+ }
214
+ /**
215
+ * Enum representing the types of "undo" actions.
216
+ */
217
+ declare enum BackStepAction {
218
+ MEMORY_RESTORE_RAW_WORD = 0,
219
+ MEMORY_RESTORE_WORD = 1,
220
+ MEMORY_RESTORE_HALF = 2,
221
+ MEMORY_RESTORE_BYTE = 3,
222
+ REGISTER_RESTORE = 4,
223
+ PC_RESTORE = 5,
224
+ COPROC0_REGISTER_RESTORE = 6,
225
+ COPROC1_REGISTER_RESTORE = 7,
226
+ COPROC1_CONDITION_CLEAR = 8,
227
+ COPROC1_CONDITION_SET = 9,
228
+ DO_NOTHING = 10
229
+ }
230
+ /**
231
+ * Represents a back step in the simulation undo stack.
232
+ */
233
+ interface JsBackStep {
234
+ /**
235
+ * The action performed (e.g., register write, memory write).
236
+ */
237
+ readonly action: BackStepAction;
238
+ /**
239
+ * Information about the action
240
+ */
241
+ readonly param1: number;
242
+ /**
243
+ * Information about the action
244
+ */
245
+ readonly param2: number;
246
+ /**
247
+ * The program counter value before the action.
248
+ */
249
+ readonly pc: number;
250
+ }
251
+ declare enum RISCVRegisters {
252
+ zero = 0,
253
+ ra = 1,
254
+ sp = 2,
255
+ gp = 3,
256
+ tp = 4,
257
+ t0 = 5,
258
+ t1 = 6,
259
+ t2 = 7,
260
+ s0 = 8,
261
+ s1 = 9,
262
+ a0 = 10,
263
+ a1 = 11,
264
+ a2 = 12,
265
+ a3 = 13,
266
+ a4 = 14,
267
+ a5 = 15,
268
+ a6 = 16,
269
+ a7 = 17,
270
+ s2 = 18,
271
+ s3 = 19,
272
+ s4 = 20,
273
+ s5 = 21,
274
+ s6 = 22,
275
+ s7 = 23,
276
+ s8 = 24,
277
+ s9 = 25,
278
+ s10 = 26,
279
+ s11 = 27,
280
+ t3 = 28,
281
+ t4 = 29,
282
+ t5 = 30,
283
+ t6 = 31
284
+ }
285
+ type RegisterName = keyof typeof RISCVRegisters;
286
+ declare const RISCV_REGISTERS: RegisterName[];
287
+ type HandlerName = keyof HandlerMap;
288
+ type HandlerMapFns = {
289
+ [K in HandlerName]: (...args: HandlerMap[K]['in']) => HandlerMap[K]['out'];
290
+ };
291
+ declare function registerHandlers(riscv: JsRiscV, handlers: HandlerMapFns): void;
292
+ declare function unimplementedHandler(name: HandlerName): () => never;
293
+ /**
294
+ * Interface for interacting with a RISCV simulator.
295
+ */
296
+ interface JsRiscV {
297
+ /**
298
+ * Assembles the program.
299
+ */
300
+ assemble(): RISCVAssembleResult;
301
+ /**
302
+ * Initializes the simulator.
303
+ * @param startAtMain If true, starts execution at the 'main' label. Otherwise, starts at the first instruction.
304
+ */
305
+ initialize(startAtMain: boolean): void;
306
+ /**
307
+ * Gets the current stop reason.
308
+ */
309
+ getStopReason(): StopReason;
310
+ /**
311
+ * Executes a single instruction.
312
+ * @returns True if the execution is complete, false otherwise.
313
+ */
314
+ step(): StopReason;
315
+ /**
316
+ * Gets the 8 condition flags.
317
+ */
318
+ getConditionFlags(): number[];
319
+ /**
320
+ * Sets the size of the undo stack, must be called before assembling the program.
321
+ * @param size
322
+ */
323
+ setUndoSize(size: number): void;
324
+ /**
325
+ * Undoes the last instruction executed.
326
+ */
327
+ undo(): void;
328
+ /**
329
+ * Gets the statement at the given address.
330
+ * @param address
331
+ */
332
+ getStatementAtAddress(address: number): JsProgramStatement;
333
+ /**
334
+ * Gets the statement at the given source line.
335
+ * @param line
336
+ */
337
+ getStatementAtSourceLine(line: number): JsProgramStatement;
338
+ getTokenizedLines(): RiscvTokenizedLine[];
339
+ /**
340
+ * Checks if the simulation can be undone.
341
+ * @returns True if the simulation can be undone, false otherwise.
342
+ * */
343
+ canUndo: boolean;
344
+ /**
345
+ * Gets the call stack.
346
+ * @returns An array of memory addresses representing the call stack.
347
+ */
348
+ getCallStack(): JsRiscVStackFrame[];
349
+ /**
350
+ * Gets the compiled statements.
351
+ * @returns An array of `JsProgramStatement` objects representing the compiled program.
352
+ */
353
+ getCompiledStatements(): JsProgramStatement[];
354
+ getParsedStatements(): JsInstructionToken[];
355
+ /**
356
+ * Gets the label at the given address.
357
+ * @param address The memory address.
358
+ * @returns The label at the given address, or null if no label is found.
359
+ */
360
+ getLabelAtAddress(address: number): string | null;
361
+ /**
362
+ * Sets whether the undo feature is enabled.
363
+ * @param enabled True to enable the undo feature, false to disable it.
364
+ */
365
+ setUndoEnabled(enabled: boolean): void;
366
+ /**
367
+ * Simulates until the stop condition is met. it might be a breakpoint, exception, etc...
368
+ */
369
+ simulate(): StopReason;
370
+ /**
371
+ * Simulates the program for a limited number of instructions.
372
+ * @param limit The maximum number of instructions to execute.
373
+ * @returns True if the execution is complete, false otherwise.
374
+ */
375
+ simulateWithLimit(limit: number): StopReason;
376
+ /**
377
+ * Simulates the program until a breakpoint is reached.
378
+ * @param breakpoints An array of memory addresses where the simulation should pause.
379
+ * @returns True if the execution is complete, false otherwise.
380
+ */
381
+ simulateWithBreakpoints(breakpoints: number[]): StopReason;
382
+ /**
383
+ * Simulates the program with both breakpoints and a limit.
384
+ * @param breakpoints An array of memory addresses where the simulation should pause.
385
+ * @param limit The maximum number of instructions to execute.
386
+ * @returns True if the execution is complete, false otherwise.
387
+ */
388
+ simulateWithBreakpointsAndLimit(breakpoints: number[], limit: number): StopReason;
389
+ /**
390
+ * Gets the value of a register.
391
+ * @param register The name of the register.
392
+ * @returns The value of the register.
393
+ */
394
+ getRegisterValue(register: RegisterName): number;
395
+ /**
396
+ * Registers a handler function for a specific event or condition.
397
+ * @param name The name of the event or condition.
398
+ * @param handler The handler function to be called when the event occurs. The function signature depends on the event name.
399
+ */
400
+ registerHandler<T extends HandlerName>(name: T, handler: (...args: HandlerMap[T]['in']) => HandlerMap[T]['out']): void;
401
+ /**
402
+ * Gets the current value of the stack pointer.
403
+ * @returns The value of the stack pointer.
404
+ */
405
+ stackPointer: number;
406
+ /**
407
+ * Gets the current value of the program counter.
408
+ * @returns The value of the program counter.
409
+ */
410
+ programCounter: number;
411
+ /**
412
+ * Gets the values of all registers.
413
+ * @returns An array containing the register values. The order of the values is implementation defined.
414
+ */
415
+ getRegistersValues(): number[];
416
+ /**
417
+ * Gets the undo stack.
418
+ * @returns An array of `JsBackStep` objects representing the history of the simulation.
419
+ */
420
+ getUndoStack(): JsBackStep[];
421
+ /**
422
+ * Reads a sequence of bytes from memory.
423
+ * @param address The starting memory address.
424
+ * @param length The number of bytes to read.
425
+ * @returns An array of bytes read from memory.
426
+ */
427
+ readMemoryBytes(address: number, length: number): number[];
428
+ /**
429
+ * Writes a sequence of bytes to memory.
430
+ * @param address The starting memory address.
431
+ * @param bytes An array of bytes to write to memory.
432
+ */
433
+ setMemoryBytes(address: number, bytes: number[]): void;
434
+ /**
435
+ * Gets the index of the current statement in the assembled program.
436
+ * @returns The index of the current statement.
437
+ */
438
+ getCurrentStatementIndex(): number;
439
+ /**
440
+ * Gets the next statement to be executed.
441
+ * @returns The next `JsProgramStatement`.
442
+ */
443
+ getNextStatement(): JsProgramStatement;
444
+ /**
445
+ * Sets the value of a register.
446
+ * @param register The name of the register.
447
+ * @param value The value to set the register to.
448
+ */
449
+ setRegisterValue(register: RegisterName, value: number): void;
450
+ /**
451
+ * Checks if the simulation has terminated.
452
+ * @returns True if the simulation has terminated, false otherwise.
453
+ */
454
+ terminated: boolean;
455
+ }
456
+ /**
457
+ * Creates a new RISCV simulator from the given source code.
458
+ * @param source The source code to assemble.
459
+ * @returns A new `JsRiscV` object.
460
+ */
461
+ declare function makeRiscVfromSource(source: string): JsRiscV;
462
+ /**
463
+ * Initializes the RISCV simulator.
464
+ */
465
+ declare function initializeRISCV(): void;
466
+
467
+ export { BackStepAction, ConfirmResult, DialogType, type HandlerMap, type HandlerMapFns, type JsBackStep, type JsInstruction, type JsInstructionToken, type JsProgramStatement, type JsRiscV, type JsRiscVStackFrame, RISCV, type RISCVAssembleError, type RISCVAssembleResult, RISCVRegisters, RISCV_REGISTERS, type RegisterName, type RiscvTokenizedLine, StopReason, registerHandlers, unimplementedHandler };