cardiograph - Change to read command line options using Opter
This commit is contained in:
parent
98bfa50269
commit
91cba57aa1
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const DBG = require('./dbg.js');
|
||||
const Opter = require('./opter/opter.js');
|
||||
const { num2hex, bool2bit } = require('./conversions.js');
|
||||
|
||||
const CFG = require('./machine.config.js');
|
||||
|
|
@ -15,16 +18,25 @@ let cpu = new CPU(CFG.initialIP, CFG.defaultCycleLimit);
|
|||
main();
|
||||
|
||||
async function main() {
|
||||
const input = await readPipedStdin();
|
||||
const opter = new Opter();
|
||||
opter.addOption('-d', '--debug');
|
||||
opter.addOption('-i', '--in', false, true, 1);
|
||||
const opts = opter.parse(process.argv);
|
||||
|
||||
const debuggable = true; // FIXME - Get this as a command line flag instead
|
||||
// if debuggable === true, the input is JSON {sourceInfo, machineCode}
|
||||
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;
|
||||
if ('in' in opts) { // Read from file
|
||||
input = fs.readFileSync(opts.in[0], 'utf8');
|
||||
} else { // Read from stdin
|
||||
input = await readPipedStdin();
|
||||
}
|
||||
|
||||
let code = null;
|
||||
let sourceInfo = null;
|
||||
|
||||
if (!debuggable) {
|
||||
if (!sourcecodeHasAnnotations) {
|
||||
code = new Uint8Array(input.split(' '));
|
||||
} else {
|
||||
const parsedInput = JSON.parse(input);
|
||||
|
|
@ -33,7 +45,7 @@ async function main() {
|
|||
}
|
||||
|
||||
cpu.loadMemory(code);
|
||||
if (debuggable) { cpu.loadSourceInfo(sourceInfo); }
|
||||
if (sourcecodeHasAnnotations) { cpu.loadSourceInfo(sourceInfo); }
|
||||
|
||||
cpu.onCycleEnd(tick);
|
||||
cpu.onCycleEnd(logCPUState);
|
||||
|
|
|
|||
Loading…
Reference in New Issue