aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2020-05-23 00:29:45 -0700
committerAustin Adams <git@austinjadams.com>2020-05-23 00:29:45 -0700
commit0343cace92056e323a9cc8fbfabaaaad063f4728 (patch)
tree6abac47b1b34d74adf9ebc7d3fc2d766989767bf
parent4c1cc3b3e21032b75b2e4858aca8d32772f91e8d (diff)
downloadnovice-0343cace92056e323a9cc8fbfabaaaad063f4728.tar.gz
novice-0343cace92056e323a9cc8fbfabaaaad063f4728.tar.xz
Disassemble instructions in GUI memory view
-rw-r--r--packages/novice-cli/novice-cli/cli-debugger.ts11
-rw-r--r--packages/novice-web/novice-web/components/GuiDebugger.tsx22
-rw-r--r--packages/novice/novice/index.ts5
-rw-r--r--packages/novice/novice/util.ts7
4 files changed, 28 insertions, 17 deletions
diff --git a/packages/novice-cli/novice-cli/cli-debugger.ts b/packages/novice-cli/novice-cli/cli-debugger.ts
index 2c89600..a663b0c 100644
--- a/packages/novice-cli/novice-cli/cli-debugger.ts
+++ b/packages/novice-cli/novice-cli/cli-debugger.ts
@@ -1,4 +1,4 @@
-import { Debugger, forceUnsigned, IO, Isa, maxUnsignedVal, padStr } from 'novice';
+import { Debugger, forceUnsigned, IO, Isa, maxUnsignedVal, padStr, fmtHex } from 'novice';
import * as readline from 'readline';
import { Readable, Writable } from 'stream';
@@ -208,17 +208,12 @@ class CliDebugger extends Debugger {
return [lo, hi];
}
- private fmtHex(val: number, bits: number): string {
- return '0x' + padStr(forceUnsigned(val, bits).toString(16),
- Math.ceil(bits / 4), '0');
- }
-
private fmtAddr(addr: number): string {
- return this.fmtHex(addr, this.isa.spec.mem.space);
+ return fmtHex(addr, this.isa.spec.mem.space);
}
private fmtWord(word: number): string {
- return this.fmtHex(word, this.isa.spec.mem.word);
+ return fmtHex(word, this.isa.spec.mem.word);
}
private async unstepCmd(): Promise<void> {
diff --git a/packages/novice-web/novice-web/components/GuiDebugger.tsx b/packages/novice-web/novice-web/components/GuiDebugger.tsx
index 993d20b..f0e6fb3 100644
--- a/packages/novice-web/novice-web/components/GuiDebugger.tsx
+++ b/packages/novice-web/novice-web/components/GuiDebugger.tsx
@@ -1,4 +1,4 @@
-import { FullMachineState, getIsa, Isa } from 'novice';
+import { FullMachineState, getIsa, Isa, fmtHex, Symbols, BaseSymbols } from 'novice';
import * as React from 'react';
import { VariableSizeGrid as Grid } from 'react-window';
import { FrontendMessage, WorkerMessage } from '../worker/proto';
@@ -12,16 +12,17 @@ export interface GuiDebuggerState {
state: FullMachineState;
}
-// State is never set so we use the '{}' type.
export class GuiDebugger extends React.Component<GuiDebuggerProps,
GuiDebuggerState> {
private isa: Isa;
+ private symbols: Symbols;
private worker: Worker;
constructor(props: GuiDebuggerProps) {
super(props);
this.isa = getIsa(this.props.isaName);
+ this.symbols = new BaseSymbols();
this.state = {
state: this.isa.initMachineState(),
};
@@ -66,12 +67,13 @@ export class GuiDebugger extends React.Component<GuiDebuggerProps,
}
public render() {
- const cols = [50, 50, 50, 200];
+ const cols = [80, 80, 80, 200];
const colVal: ((addr: number) => string)[] = [
- addr => addr.toString(16),
- addr => this.isa.stateLoad(this.state.state, addr).toString(16),
+ addr => this.fmtAddr(addr),
+ addr => this.fmtWord(this.isa.stateLoad(this.state.state, addr)),
addr => this.isa.stateLoad(this.state.state, addr).toString(10),
- addr => 'disassembled',
+ addr => this.isa.disassemble(addr, this.isa.stateLoad(this.state.state, addr),
+ this.symbols, true) || '',
];
const cell = (props: { columnIndex: number,
@@ -95,4 +97,12 @@ export class GuiDebugger extends React.Component<GuiDebuggerProps,
private postMessage(msg: FrontendMessage): void {
this.worker.postMessage(msg);
}
+
+ private fmtAddr(addr: number): string {
+ return fmtHex(addr, this.isa.spec.mem.space);
+ }
+
+ private fmtWord(word: number): string {
+ return fmtHex(word, this.isa.spec.mem.word);
+ }
}
diff --git a/packages/novice/novice/index.ts b/packages/novice/novice/index.ts
index a28c94f..241a07b 100644
--- a/packages/novice/novice/index.ts
+++ b/packages/novice/novice/index.ts
@@ -7,7 +7,8 @@ import { AliasContext, AliasFields, AliasSpec, Assembly, BaseSymbols, Fields,
RegIdentifier, RegisterOperand, Section, StringOperand,
Symbols, SymbTable } from './isa';
import { Debugger, Memory, Simulator } from './simulator';
-import { forceUnsigned, maskTo, maxUnsignedVal, padStr, sextTo } from './util';
+import { forceUnsigned, maskTo, maxUnsignedVal, padStr, sextTo,
+ fmtHex } from './util';
export { //// assembler
Assembler, AssemblerConfig, getParser, getGenerator, getOpSpec,
@@ -29,4 +30,4 @@ export { //// assembler
//// simulator
Debugger, Simulator, Memory,
//// util
- forceUnsigned, maskTo, maxUnsignedVal, sextTo, padStr };
+ forceUnsigned, maskTo, maxUnsignedVal, sextTo, padStr, fmtHex };
diff --git a/packages/novice/novice/util.ts b/packages/novice/novice/util.ts
index a1e3b93..b069fc2 100644
--- a/packages/novice/novice/util.ts
+++ b/packages/novice/novice/util.ts
@@ -29,4 +29,9 @@ function padStr(str: string, to: number, withChar: string, right?: boolean) {
return str;
}
-export { forceUnsigned, maskTo, maxUnsignedVal, sextTo, padStr };
+function fmtHex(val: number, bits: number): string {
+ return '0x' + padStr(forceUnsigned(val, bits).toString(16),
+ Math.ceil(bits / 4), '0');
+}
+
+export { forceUnsigned, maskTo, maxUnsignedVal, sextTo, padStr, fmtHex };