cardiograph - Change to programmatically infer whether the input includes annotations or not
This commit is contained in:
parent
91cba57aa1
commit
3e32cb97e1
|
|
@ -19,14 +19,9 @@ main();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const opter = new Opter();
|
const opter = new Opter();
|
||||||
opter.addOption('-d', '--debug');
|
|
||||||
opter.addOption('-i', '--in', false, true, 1);
|
opter.addOption('-i', '--in', false, true, 1);
|
||||||
const opts = opter.parse(process.argv);
|
const opts = opter.parse(process.argv);
|
||||||
|
|
||||||
const sourcecodeHasAnnotations = 'debug' in opts;
|
|
||||||
// if true, then the input is JSON {sourceInfo, machineCode}
|
|
||||||
// otherwise, the input is a string of space-separated numbers
|
|
||||||
|
|
||||||
let input = null;
|
let input = null;
|
||||||
if ('in' in opts) { // Read from file
|
if ('in' in opts) { // Read from file
|
||||||
input = fs.readFileSync(opts.in[0], 'utf8');
|
input = fs.readFileSync(opts.in[0], 'utf8');
|
||||||
|
|
@ -36,16 +31,19 @@ async function main() {
|
||||||
|
|
||||||
let code = null;
|
let code = null;
|
||||||
let sourceInfo = null;
|
let sourceInfo = null;
|
||||||
if (!sourcecodeHasAnnotations) {
|
|
||||||
code = new Uint8Array(input.split(' '));
|
try {
|
||||||
} else {
|
|
||||||
const parsedInput = JSON.parse(input);
|
const parsedInput = JSON.parse(input);
|
||||||
code = new Uint8Array(parsedInput.machineCode);
|
|
||||||
sourceInfo = parsedInput.sourceInfo;
|
sourceInfo = parsedInput.sourceInfo;
|
||||||
|
code = new Uint8Array(parsedInput.machineCode);
|
||||||
|
} catch (error) {
|
||||||
|
if (error.name === 'SyntaxError') {
|
||||||
|
code = new Uint8Array(input.split(' '));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cpu.loadMemory(code);
|
cpu.loadMemory(code);
|
||||||
if (sourcecodeHasAnnotations) { cpu.loadSourceInfo(sourceInfo); }
|
if (sourceInfo !== null) { cpu.loadSourceInfo(sourceInfo); }
|
||||||
|
|
||||||
cpu.onCycleEnd(tick);
|
cpu.onCycleEnd(tick);
|
||||||
cpu.onCycleEnd(logCPUState);
|
cpu.onCycleEnd(logCPUState);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue