Remove `run-cpu.js` (it is superseded by `cardiograph`)
This commit is contained in:
parent
fbda5ce927
commit
5b52143ad0
|
|
@ -1,71 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
// Usage: ./run-cpu.js -f code.asm [--debug] [--step] [--pretty]
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const computer = require('./cpu.js');
|
|
||||||
const assembler = require('./assembler.js');
|
|
||||||
const { logRunningHeader } = require('./logging.js');
|
|
||||||
|
|
||||||
// Load file...
|
|
||||||
|
|
||||||
let filename;
|
|
||||||
try {
|
|
||||||
filename = getArgumentValue('-f', `Missing filename`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
process.exit()
|
|
||||||
}
|
|
||||||
|
|
||||||
const inputFile_str = fs.readFileSync(filename, 'utf8');
|
|
||||||
|
|
||||||
|
|
||||||
// Check optional arguments...
|
|
||||||
|
|
||||||
let debug = false;
|
|
||||||
let singleStep = false;
|
|
||||||
let prettyPrint = false;
|
|
||||||
process.argv.forEach((arg) => { if (arg === '--debug') { debug = true } });
|
|
||||||
process.argv.forEach((arg) => { if (arg === '--step') { singleStep = true } });
|
|
||||||
process.argv.forEach((arg) => { if (arg === '--pretty') { prettyPrint = true } });
|
|
||||||
|
|
||||||
let speed = null;
|
|
||||||
process.argv.forEach((arg, index) => {
|
|
||||||
if (arg === '--speed' && process.argv.length > (index -1)) {
|
|
||||||
speed = parseInt(process.argv[index + 1]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
let assemblerOutput = assembler.assemble(inputFile_str);
|
|
||||||
logRunningHeader();
|
|
||||||
computer.runProgram(
|
|
||||||
assemblerOutput.machineCode,
|
|
||||||
assemblerOutput.debugInfo,
|
|
||||||
debug,
|
|
||||||
singleStep,
|
|
||||||
prettyPrint,
|
|
||||||
speed
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// CLI args TODO
|
|
||||||
// - check if value is the name of another arg
|
|
||||||
// - usage info
|
|
||||||
// - catch nonexistant flags
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} flag - The command line flag, eg. '-f'
|
|
||||||
* @param {string} errorMessage - The error to throw if a value isn't found
|
|
||||||
* @returns {string}
|
|
||||||
**/
|
|
||||||
function getArgumentValue(flag, errorMessage) {
|
|
||||||
let value = null;
|
|
||||||
process.argv.forEach((arg, index) => {
|
|
||||||
if (arg === flag && process.argv.length > (index -1)) {
|
|
||||||
value = process.argv[index + 1];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!value) throw new Error(errorMessage);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue