assembler - WIP - Add a 'return on stdout' mode that turns off all debug logging, and prints machine code output to stdout, so that output can be piped directly to the simulator
This commit is contained in:
parent
5671314b10
commit
12d592c262
|
|
@ -404,7 +404,9 @@ function hex2num(hex) { return parseInt(hex, 16) };
|
|||
/** MAIN **/
|
||||
|
||||
// Initialize debugger
|
||||
const dbg = new DBG('nitpick');
|
||||
let dbg = new DBG('nitpick');
|
||||
let returnOnStdout = true; // FIXME - set this using a CLI arg
|
||||
if (returnOnStdout) { dbg = new DBG('none'); }
|
||||
|
||||
// Get input
|
||||
const filename = process.argv[2]; // FIXME - Get filename in a more robust way
|
||||
|
|
@ -414,13 +416,24 @@ assemble(inputFile_str, outputFilename);
|
|||
|
||||
|
||||
/**
|
||||
* @param {string} assemblyCode
|
||||
* @param {string} outputFile
|
||||
* Assemble source code into machine code.
|
||||
* If 'includeMetadata' is true, a JSON object containing
|
||||
* both machine code and metadata is written to the output file.
|
||||
* Otherwise, a string of decimal numbers is written.
|
||||
* @arg {string} sourceCode - Source code to assemble
|
||||
* @arg {string} [outputFile='out.txt'] - Output file for machine code (and optional metadata)
|
||||
* @arg {boolean} [includeMetadata=false] - Include metadata for use when debugging using the simulator?
|
||||
**/
|
||||
function assemble(assemblyCode, outputFile='out.txt', debuggable='false') {
|
||||
const out = decodeInstructions(assemblyCode);
|
||||
function assemble(sourceCode, outputFile='out.txt', includeMetadata=false) {
|
||||
const out = decodeInstructions(sourceCode);
|
||||
|
||||
if (!debuggable) {
|
||||
if (returnOnStdout) {
|
||||
const debugJSON = JSON.stringify(out);
|
||||
console.log(debugJSON);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!includeMetadata) {
|
||||
const asciiMachineCode = out.machineCode.toString().replace(/,/g, ' ');
|
||||
fs.writeFileSync(outputFile, asciiMachineCode);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue