mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-04 13:34:27 +00:00
added nodemain; jsasm cache
This commit is contained in:
parent
7fd94e4a98
commit
020aa0d378
71
src/worker/nodemain.js
Normal file
71
src/worker/nodemain.js
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var vm = require('vm');
|
||||
|
||||
var worker = {};
|
||||
|
||||
global.includeInThisContext = function(path) {
|
||||
var code = fs.readFileSync(path);
|
||||
vm.runInThisContext(code, path);
|
||||
};
|
||||
|
||||
global.importScripts = function(path) {
|
||||
includeInThisContext('./'+path);
|
||||
}
|
||||
|
||||
function Blob(blob) {
|
||||
this.size = blob.length;
|
||||
this.length = blob.length;
|
||||
this.slice = function(a,b) {
|
||||
var data = blob.slice(a,b);
|
||||
var b = new Blob(data);
|
||||
return b;
|
||||
}
|
||||
this.asArrayBuffer = function() {
|
||||
var buf = new ArrayBuffer(blob.length);
|
||||
var arr = new Uint8Array(buf);
|
||||
for (var i=0; i<blob.length; i++)
|
||||
arr[i] = blob[i].charCodeAt(0);
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
|
||||
global.XMLHttpRequest = function() {
|
||||
this.open = function(a,b,c) {
|
||||
if (this.responseType == 'json') {
|
||||
var txt = fs.readFileSync(',/'+b);
|
||||
this.response = JSON.parse(txt);
|
||||
} else if (this.responseType == 'blob') {
|
||||
var data = fs.readFileSync('./'+b, {encoding:'binary'});
|
||||
this.response = new Blob(data);
|
||||
} else if (this.responseType == 'arraybuffer') {
|
||||
var data = fs.readFileSync('./'+b, {encoding:'binary'});
|
||||
this.response = new Blob(data).asArrayBuffer();
|
||||
} else {
|
||||
throw new Error("responseType " + this.responseType + " not handled");
|
||||
}
|
||||
}
|
||||
this.send = function() { }
|
||||
}
|
||||
|
||||
global.FileReaderSync = function() {
|
||||
this.readAsArrayBuffer = function(blob) {
|
||||
return blob.asArrayBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
global.onmessage = null;
|
||||
global.postMessage = null;
|
||||
|
||||
includeInThisContext("./workermain.js");
|
||||
|
||||
global.ab2str = function(buf) {
|
||||
return String.fromCharCode.apply(null, new Uint16Array(buf));
|
||||
}
|
||||
|
||||
if (require.main == module) {
|
||||
var data = fs.readFileSync(process.argv[2]);
|
||||
var result = handleMessage(JSON.parse(data));
|
||||
console.log(result);
|
||||
}
|
@ -145,7 +145,7 @@ function loadWASM(modulename, debug) {
|
||||
console.log("Loaded " + modulename + ".wasm");
|
||||
loaded[modulename] = 1;
|
||||
} else {
|
||||
throw Error("Could not load WASM file");
|
||||
throw Error("Could not load WASM file " + modulename + ".wasm");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1118,6 +1118,10 @@ function compileCASPR(code, platform, options) {
|
||||
}
|
||||
}
|
||||
|
||||
var jsasm_module_top;
|
||||
var jsasm_module_output;
|
||||
var jsasm_module_key;
|
||||
|
||||
function compileJSASM(asmcode, platform, options, is_inline) {
|
||||
load("assembler");
|
||||
var asm = new Assembler();
|
||||
@ -1137,27 +1141,28 @@ function compileJSASM(asmcode, platform, options, is_inline) {
|
||||
filename = filename.substr(1, filename.length-2);
|
||||
includes.push(filename);
|
||||
};
|
||||
var module_top;
|
||||
var module_output;
|
||||
asm.loadModule = function(top_module) {
|
||||
// TODO: cache module
|
||||
// compile last file in list
|
||||
module_top = top_module;
|
||||
var main_filename = includes[includes.length-1];
|
||||
var code = '`include "' + main_filename + '"\n';
|
||||
code += "/* module " + top_module + " */\n";
|
||||
var voutput = compileVerilator(code, platform, options);
|
||||
if (voutput.errors.length)
|
||||
return voutput.errors[0].msg;
|
||||
module_output = voutput;
|
||||
var key = top_module + '/' + includes;
|
||||
if (key != jsasm_module_key) {
|
||||
jsasm_module_top = top_module;
|
||||
var main_filename = includes[includes.length-1];
|
||||
var code = '`include "' + main_filename + '"\n';
|
||||
code += "/* module " + top_module + " */\n";
|
||||
var voutput = compileVerilator(code, platform, options);
|
||||
if (voutput.errors.length)
|
||||
return voutput.errors[0].msg;
|
||||
jsasm_module_output = voutput;
|
||||
}
|
||||
}
|
||||
var result = asm.assembleFile(asmcode);
|
||||
if (module_output) {
|
||||
if (jsasm_module_output) {
|
||||
var asmout = result.output;
|
||||
result.output = module_output.output;
|
||||
result.output = jsasm_module_output.output;
|
||||
result.output.program_rom = asmout;
|
||||
// cpu_platform__DOT__program_rom
|
||||
result.output.program_rom_variable = module_top + "__DOT__program_rom";
|
||||
result.output.program_rom_variable = jsasm_module_top + "__DOT__program_rom";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user