2017-01-06 00:14:12 +00:00
|
|
|
"use strict";
|
2017-01-09 21:28:20 +00:00
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
import { WorkerResult, WorkerFileUpdate, WorkerBuildStep, WorkerMessage, WorkerError, Dependency } from "../workertypes";
|
|
|
|
|
|
|
|
const emglobal : any = this['window'] || this['global'] || this;
|
|
|
|
declare var WebAssembly;
|
|
|
|
declare function importScripts(path:string);
|
|
|
|
declare function postMessage(msg);
|
|
|
|
|
2018-07-10 05:09:10 +00:00
|
|
|
var ENVIRONMENT_IS_WEB = typeof window === 'object';
|
|
|
|
var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
|
|
|
|
|
2018-07-10 04:44:17 +00:00
|
|
|
// WebAssembly module cache
|
|
|
|
// TODO: leaks memory even when disabled...
|
|
|
|
var _WASM_module_cache = {};
|
2018-07-11 00:58:46 +00:00
|
|
|
var CACHE_WASM_MODULES = true;
|
2018-10-05 13:47:15 +00:00
|
|
|
function getWASMModule(module_id:string) {
|
2018-07-10 04:44:17 +00:00
|
|
|
var module = _WASM_module_cache[module_id];
|
|
|
|
if (!module) {
|
|
|
|
starttime();
|
|
|
|
module = new WebAssembly.Module(wasmBlob[module_id]);
|
|
|
|
if (CACHE_WASM_MODULES) {
|
|
|
|
_WASM_module_cache[module_id] = module;
|
|
|
|
delete wasmBlob[module_id];
|
|
|
|
}
|
|
|
|
endtime("module creation " + module_id);
|
|
|
|
}
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
// function for use with instantiateWasm
|
2018-10-05 13:47:15 +00:00
|
|
|
function moduleInstFn(module_id:string) {
|
2018-07-10 04:44:17 +00:00
|
|
|
return function(imports,ri) {
|
|
|
|
var mod = getWASMModule(module_id);
|
|
|
|
var inst = new WebAssembly.Instance(mod, imports);
|
|
|
|
ri(inst);
|
|
|
|
return inst.exports;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 05:09:57 +00:00
|
|
|
var PLATFORM_PARAMS = {
|
2018-12-05 19:05:10 +00:00
|
|
|
'vcs': {
|
|
|
|
code_start: 0x1000,
|
|
|
|
code_size: 0xf000,
|
|
|
|
data_start: 0x80,
|
|
|
|
data_size: 0x80,
|
|
|
|
},
|
2017-01-26 05:09:57 +00:00
|
|
|
'mw8080bw': {
|
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x2000,
|
2017-01-26 05:09:57 +00:00
|
|
|
data_start: 0x2000,
|
|
|
|
data_size: 0x400,
|
2017-04-22 01:56:49 +00:00
|
|
|
stack_end: 0x2400,
|
2017-01-26 05:09:57 +00:00
|
|
|
},
|
|
|
|
'vicdual': {
|
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x4020,
|
2017-02-18 22:50:51 +00:00
|
|
|
data_start: 0xe400,
|
2017-01-26 05:09:57 +00:00
|
|
|
data_size: 0x400,
|
2017-04-22 01:56:49 +00:00
|
|
|
stack_end: 0xe800,
|
2017-01-26 05:09:57 +00:00
|
|
|
},
|
|
|
|
'galaxian': {
|
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x4000,
|
2017-01-26 05:09:57 +00:00
|
|
|
data_start: 0x4000,
|
|
|
|
data_size: 0x400,
|
2017-04-22 01:56:49 +00:00
|
|
|
stack_end: 0x4800,
|
2017-01-26 05:09:57 +00:00
|
|
|
},
|
2017-02-15 21:03:52 +00:00
|
|
|
'galaxian-scramble': {
|
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x5020,
|
2017-02-15 21:03:52 +00:00
|
|
|
data_start: 0x4000,
|
|
|
|
data_size: 0x400,
|
2017-04-22 01:56:49 +00:00
|
|
|
stack_end: 0x4800,
|
2017-02-15 21:03:52 +00:00
|
|
|
},
|
2017-01-29 21:06:05 +00:00
|
|
|
'williams-z80': {
|
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x9800,
|
2017-03-28 16:22:33 +00:00
|
|
|
data_start: 0x9800,
|
|
|
|
data_size: 0x2800,
|
2017-04-22 01:56:49 +00:00
|
|
|
stack_end: 0xc000,
|
2017-01-29 21:06:05 +00:00
|
|
|
},
|
2017-02-05 04:19:54 +00:00
|
|
|
'vector-z80color': {
|
2017-02-01 18:21:17 +00:00
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x8000,
|
2017-02-05 04:19:54 +00:00
|
|
|
data_start: 0xe000,
|
|
|
|
data_size: 0x2000,
|
2017-04-22 01:56:49 +00:00
|
|
|
stack_end: 0x0,
|
2017-02-01 18:21:17 +00:00
|
|
|
},
|
2017-04-02 18:54:51 +00:00
|
|
|
'sound_williams-z80': {
|
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x4000,
|
2017-04-02 18:54:51 +00:00
|
|
|
data_start: 0x4000,
|
2017-04-15 04:12:21 +00:00
|
|
|
data_size: 0x400,
|
2017-04-22 01:56:49 +00:00
|
|
|
stack_end: 0x8000,
|
2017-04-02 18:54:51 +00:00
|
|
|
},
|
2017-04-29 15:31:11 +00:00
|
|
|
'base_z80': {
|
|
|
|
code_start: 0x0,
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_size: 0x8000,
|
2017-04-29 15:31:11 +00:00
|
|
|
data_start: 0x8000,
|
|
|
|
data_size: 0x8000,
|
|
|
|
stack_end: 0x0,
|
|
|
|
},
|
2017-05-01 11:37:48 +00:00
|
|
|
'coleco': {
|
2017-05-02 13:09:53 +00:00
|
|
|
rom_start: 0x8000,
|
|
|
|
code_start: 0x8100,
|
|
|
|
rom_size: 0x8000,
|
|
|
|
data_start: 0x7000,
|
2017-05-01 11:37:48 +00:00
|
|
|
data_size: 0x400,
|
|
|
|
stack_end: 0x8000,
|
2017-05-21 03:40:05 +00:00
|
|
|
extra_preproc_args: ['-I', '/share/include/coleco'],
|
2018-11-28 15:31:07 +00:00
|
|
|
extra_link_args: ['-k', '/share/lib/coleco', '-l', 'libcv', '-l', 'libcvu', 'crt0.rel'],
|
|
|
|
},
|
2018-11-29 22:40:53 +00:00
|
|
|
'sms-sg1000-libcv': {
|
2018-11-28 15:31:07 +00:00
|
|
|
rom_start: 0x0000,
|
|
|
|
code_start: 0x0100,
|
|
|
|
rom_size: 0xc000,
|
|
|
|
data_start: 0xc000,
|
|
|
|
data_size: 0x400,
|
|
|
|
stack_end: 0xe000,
|
|
|
|
extra_preproc_args: ['-I', '.', '-D', 'CV_SMS'],
|
|
|
|
extra_link_args: ['-k', '.', '-l', 'libcv-sms', '-l', 'libcvu-sms', 'crt0-sms.rel'],
|
|
|
|
extra_link_files: ['libcv-sms.lib', 'libcvu-sms.lib', 'crt0-sms.rel', 'crt0-sms.lst'],
|
|
|
|
extra_compile_files: ['cv.h','cv_graphics.h','cv_input.h','cv_sound.h','cv_support.h','cvu.h','cvu_c.h','cvu_compression.h','cvu_f.h','cvu_graphics.h','cvu_input.h','cvu_sound.h'],
|
2017-05-01 11:37:48 +00:00
|
|
|
},
|
2018-07-27 17:39:09 +00:00
|
|
|
'nes': { //TODO
|
|
|
|
define: '__NES__',
|
|
|
|
cfgfile: 'neslib.cfg',
|
2018-11-19 14:10:13 +00:00
|
|
|
libargs: ['crt0.o', 'nes.lib',
|
2019-02-10 16:04:31 +00:00
|
|
|
'-D', 'NES_MAPPER=2', // UxROM
|
|
|
|
'-D', 'NES_PRG_BANKS=2', // 2 PRG banks
|
2018-08-14 20:28:29 +00:00
|
|
|
'-D', 'NES_CHR_BANKS=0', // TODO: >0 doesn't seem to work
|
2019-02-10 16:04:31 +00:00
|
|
|
'-D', 'NES_MIRRORING=0', // horizontal mirroring
|
2018-08-14 20:28:29 +00:00
|
|
|
],
|
2018-11-28 15:31:07 +00:00
|
|
|
extra_link_files: ['crt0.o'],
|
2018-07-27 17:39:09 +00:00
|
|
|
},
|
2017-05-21 21:34:57 +00:00
|
|
|
'nes-conio': {
|
|
|
|
cfgfile: 'nes.cfg',
|
2018-06-18 08:12:52 +00:00
|
|
|
define: '__NES__',
|
2017-05-21 21:34:57 +00:00
|
|
|
libargs: ['nes.lib'],
|
|
|
|
},
|
|
|
|
'nes-lib': {
|
|
|
|
define: '__NES__',
|
|
|
|
cfgfile: 'neslib.cfg',
|
|
|
|
libargs: ['neslib.lib', 'nes.lib'],
|
|
|
|
},
|
2017-12-30 17:48:30 +00:00
|
|
|
'apple2': {
|
|
|
|
define: '__APPLE2__',
|
2018-06-20 07:09:37 +00:00
|
|
|
cfgfile: 'apple2-hgr.cfg',
|
2017-12-30 17:48:30 +00:00
|
|
|
libargs: ['apple2.lib'],
|
2018-08-06 20:23:19 +00:00
|
|
|
__CODE_RUN__: 16384,
|
2018-09-25 23:46:24 +00:00
|
|
|
code_start: 0x803,
|
2017-12-30 17:48:30 +00:00
|
|
|
},
|
2018-06-18 08:12:52 +00:00
|
|
|
'apple2-e': {
|
|
|
|
define: '__APPLE2__',
|
|
|
|
cfgfile: 'apple2.cfg',
|
|
|
|
libargs: ['apple2.lib'],
|
2018-06-20 08:06:18 +00:00
|
|
|
},
|
2018-06-22 06:24:52 +00:00
|
|
|
'atari8-800': {
|
|
|
|
define: '__ATARI__',
|
|
|
|
cfgfile: 'atari-cart.cfg',
|
|
|
|
libargs: ['atari.lib'],
|
|
|
|
},
|
2018-06-20 08:06:18 +00:00
|
|
|
'atari8-5200': {
|
2018-06-21 18:15:05 +00:00
|
|
|
define: '__ATARI5200__',
|
|
|
|
cfgfile: 'atari5200.cfg',
|
2018-09-21 12:39:15 +00:00
|
|
|
libargs: ['atari5200.lib',
|
|
|
|
'-D', '__CARTFLAGS__=255'],
|
2018-06-22 06:24:52 +00:00
|
|
|
},
|
|
|
|
'c64': {
|
|
|
|
define: '__C64__',
|
|
|
|
cfgfile: 'c64.cfg',
|
|
|
|
libargs: ['c64.lib'],
|
2018-06-18 08:12:52 +00:00
|
|
|
},
|
2017-11-11 19:45:32 +00:00
|
|
|
'verilog': {
|
|
|
|
},
|
2018-08-27 21:31:49 +00:00
|
|
|
'astrocade': {
|
|
|
|
code_start: 0x2000,
|
2018-09-03 13:37:17 +00:00
|
|
|
rom_size: 0x2000,
|
2018-09-02 14:48:43 +00:00
|
|
|
data_start: 0x4e10,
|
2018-09-03 13:37:17 +00:00
|
|
|
data_size: 0x1f0,
|
|
|
|
stack_end: 0x5000,
|
|
|
|
},
|
|
|
|
'astrocade-arcade': {
|
|
|
|
code_start: 0x0000,
|
|
|
|
rom_size: 0x4000,
|
|
|
|
data_start: 0x7de0,
|
|
|
|
data_size: 0x220,
|
|
|
|
stack_end: 0x8000,
|
2018-08-27 21:31:49 +00:00
|
|
|
},
|
2018-09-05 02:28:12 +00:00
|
|
|
'astrocade-bios': {
|
|
|
|
code_start: 0x0000,
|
|
|
|
rom_size: 0x2000,
|
|
|
|
data_start: 0x4fce,
|
|
|
|
data_size: 50,
|
|
|
|
stack_end: 0x4fce,
|
|
|
|
},
|
2017-01-26 05:09:57 +00:00
|
|
|
};
|
|
|
|
|
2018-11-19 14:10:13 +00:00
|
|
|
PLATFORM_PARAMS['coleco.mame'] = PLATFORM_PARAMS['coleco'];
|
2018-11-30 17:37:00 +00:00
|
|
|
PLATFORM_PARAMS['sms-sms-libcv'] = PLATFORM_PARAMS['sms-sg1000-libcv'];
|
2018-11-19 14:10:13 +00:00
|
|
|
|
2018-07-10 04:44:17 +00:00
|
|
|
var _t1;
|
2017-11-07 21:41:07 +00:00
|
|
|
function starttime() { _t1 = new Date(); }
|
2018-07-10 04:44:17 +00:00
|
|
|
function endtime(msg) { var _t2 = new Date(); console.log(msg, _t2.getTime() - _t1.getTime(), "ms"); }
|
2017-11-07 21:41:07 +00:00
|
|
|
|
2018-06-25 04:52:40 +00:00
|
|
|
/// working file store and build steps
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
type FileData = string | Uint8Array;
|
|
|
|
|
|
|
|
type FileEntry = {
|
|
|
|
path: string
|
|
|
|
encoding: string
|
|
|
|
data: FileData
|
|
|
|
ts: number
|
|
|
|
};
|
|
|
|
|
|
|
|
type BuildOptions = {
|
2018-12-15 18:14:40 +00:00
|
|
|
mainFilePath : string,
|
|
|
|
processFn?: (FileData) => FileData
|
2018-10-05 13:47:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
interface BuildStep extends WorkerBuildStep {
|
|
|
|
files? : string[]
|
|
|
|
args? : string[]
|
|
|
|
nextstep? : BuildStep
|
|
|
|
linkstep? : BuildStep
|
|
|
|
params?
|
|
|
|
result?
|
|
|
|
code?
|
|
|
|
generated?
|
|
|
|
prefix?
|
|
|
|
maxts?
|
|
|
|
};
|
|
|
|
|
|
|
|
var buildsteps : BuildStep[] = [];
|
|
|
|
var buildstartseq : number = 0;
|
|
|
|
var workfs : {[path:string]:FileEntry} = {};
|
|
|
|
var workerseq : number = 0;
|
2018-06-25 14:43:15 +00:00
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function compareData(a:FileData, b:FileData) : boolean {
|
2018-06-25 14:43:15 +00:00
|
|
|
if (a.length != b.length) return false;
|
|
|
|
if (typeof a === 'string' && typeof b === 'string')
|
|
|
|
return a==b;
|
|
|
|
else {
|
|
|
|
for (var i=0; i<a.length; i++) {
|
|
|
|
//if (a[i] != b[i]) console.log('differ at byte',i,a[i],b[i]);
|
|
|
|
if (a[i] != b[i]) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 04:52:40 +00:00
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function putWorkFile(path:string, data:FileData) {
|
2018-06-25 04:52:40 +00:00
|
|
|
var encoding = (typeof data === 'string') ? 'utf8' : 'binary';
|
|
|
|
var entry = workfs[path];
|
2018-06-25 14:43:15 +00:00
|
|
|
if (!entry || !compareData(entry.data, data) || entry.encoding != encoding) {
|
2018-06-28 03:26:23 +00:00
|
|
|
workfs[path] = entry = {path:path, data:data, encoding:encoding, ts:++workerseq};
|
2018-06-25 14:43:15 +00:00
|
|
|
console.log('+++', entry.path, entry.encoding, entry.data.length, entry.ts);
|
2018-06-25 04:52:40 +00:00
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2018-06-28 03:26:23 +00:00
|
|
|
// returns true if file changed during this build step
|
2018-10-05 13:47:15 +00:00
|
|
|
function wasChanged(entry:FileEntry) : boolean {
|
2018-06-28 03:26:23 +00:00
|
|
|
return entry.ts > buildstartseq;
|
|
|
|
}
|
|
|
|
|
2018-11-28 16:10:24 +00:00
|
|
|
function getWorkFileAsString(path:string) : string {
|
|
|
|
return workfs[path] && workfs[path].data as string; // TODO
|
|
|
|
}
|
|
|
|
|
2018-12-15 18:14:40 +00:00
|
|
|
function populateEntry(fs, path:string, entry:FileEntry, options:BuildOptions) {
|
|
|
|
var data = entry.data;
|
|
|
|
if (options && options.processFn)
|
|
|
|
data = options.processFn(data);
|
|
|
|
fs.writeFile(path, data, {encoding:entry.encoding});
|
2018-06-25 14:43:15 +00:00
|
|
|
fs.utime(path, entry.ts, entry.ts);
|
2018-06-28 00:26:22 +00:00
|
|
|
console.log("<<<", path, entry.data.length);
|
2018-06-25 14:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// can call multiple times (from populateFiles)
|
2018-10-05 13:47:15 +00:00
|
|
|
function gatherFiles(step:BuildStep, options?:BuildOptions) {
|
2018-06-25 14:43:15 +00:00
|
|
|
var maxts = 0;
|
|
|
|
if (step.files) {
|
|
|
|
for (var i=0; i<step.files.length; i++) {
|
|
|
|
var path = step.files[i];
|
|
|
|
var entry = workfs[path];
|
2018-12-15 18:14:40 +00:00
|
|
|
if (!entry) {
|
|
|
|
throw new Error("No entry for path '" + path + "'");
|
|
|
|
} else {
|
|
|
|
maxts = Math.max(maxts, entry.ts);
|
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-28 00:26:22 +00:00
|
|
|
else if (step.code) {
|
2018-10-05 13:47:15 +00:00
|
|
|
var path = step.path ? step.path : options.mainFilePath; // TODO: what if options null
|
2018-06-28 00:26:22 +00:00
|
|
|
if (!path) throw "need path or mainFilePath";
|
2018-06-25 04:52:40 +00:00
|
|
|
var code = step.code;
|
|
|
|
var entry = putWorkFile(path, code);
|
|
|
|
step.path = path;
|
2018-06-25 14:43:15 +00:00
|
|
|
step.files = [path];
|
|
|
|
maxts = entry.ts;
|
2018-06-25 04:52:40 +00:00
|
|
|
}
|
|
|
|
else if (step.path) {
|
|
|
|
var path = step.path;
|
|
|
|
var entry = workfs[path];
|
2018-06-25 14:43:15 +00:00
|
|
|
maxts = entry.ts;
|
|
|
|
step.files = [path];
|
2018-06-25 04:52:40 +00:00
|
|
|
}
|
|
|
|
if (step.path && !step.prefix) {
|
|
|
|
step.prefix = step.path.split(/[./]/)[0]; // TODO
|
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
step.maxts = maxts;
|
|
|
|
return maxts;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function populateFiles(step:BuildStep, fs, options?:BuildOptions) {
|
2018-06-25 14:43:15 +00:00
|
|
|
gatherFiles(step, options);
|
|
|
|
if (!step.files) throw "call gatherFiles() first";
|
|
|
|
for (var i=0; i<step.files.length; i++) {
|
|
|
|
var path = step.files[i];
|
2018-12-15 18:14:40 +00:00
|
|
|
populateEntry(fs, path, workfs[path], options);
|
2018-06-25 14:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 15:31:07 +00:00
|
|
|
function populateExtraFiles(step:BuildStep, fs, extrafiles) {
|
2018-08-14 20:28:29 +00:00
|
|
|
// TODO: cache extra files
|
|
|
|
if (extrafiles) {
|
|
|
|
for (var i=0; i<extrafiles.length; i++) {
|
|
|
|
var xfn = extrafiles[i];
|
|
|
|
var xpath = "lib/" + step.platform + "/" + xfn;
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'arraybuffer';
|
|
|
|
xhr.open("GET", xpath, false); // synchronous request
|
|
|
|
xhr.send(null);
|
|
|
|
if (xhr.response && xhr.status == 200) {
|
|
|
|
var data = new Uint8Array(xhr.response);
|
|
|
|
fs.writeFile(xfn, data, {encoding:'binary'});
|
2018-08-15 04:43:52 +00:00
|
|
|
console.log(":::",xfn,data.length);
|
2018-08-14 20:28:29 +00:00
|
|
|
} else {
|
|
|
|
throw Error("Could not load extra file " + xpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function staleFiles(step:BuildStep, targets:string[]) {
|
2018-06-25 14:43:15 +00:00
|
|
|
if (!step.maxts) throw "call populateFiles() first";
|
2018-06-28 03:26:23 +00:00
|
|
|
// see if any target files are more recent than inputs
|
2018-06-25 14:43:15 +00:00
|
|
|
for (var i=0; i<targets.length; i++) {
|
|
|
|
var entry = workfs[targets[i]];
|
|
|
|
if (!entry || step.maxts > entry.ts)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
console.log("unchanged", step.maxts, targets);
|
|
|
|
return false;
|
2018-06-25 04:52:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function anyTargetChanged(step:BuildStep, targets:string[]) {
|
2018-06-28 04:57:06 +00:00
|
|
|
if (!step.maxts) throw "call populateFiles() first";
|
|
|
|
// see if any target files are more recent than inputs
|
|
|
|
for (var i=0; i<targets.length; i++) {
|
|
|
|
var entry = workfs[targets[i]];
|
|
|
|
if (!entry || entry.ts > step.maxts)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
console.log("unchanged", step.maxts, targets);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function execMain(step:BuildStep, mod, args:string[]) {
|
2018-06-25 04:52:40 +00:00
|
|
|
starttime();
|
|
|
|
mod.callMain(args);
|
|
|
|
endtime(step.tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// asm.js / WASM / filesystem loading
|
|
|
|
|
2017-01-23 21:21:45 +00:00
|
|
|
var fsMeta = {};
|
|
|
|
var fsBlob = {};
|
2017-11-05 18:34:00 +00:00
|
|
|
var wasmBlob = {};
|
2017-01-23 21:21:45 +00:00
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
const PSRC = "../../src/";
|
|
|
|
const PWORKER = PSRC+"worker/";
|
|
|
|
|
2017-01-10 08:18:54 +00:00
|
|
|
// load filesystems for CC65 and others asynchronously
|
2018-10-05 13:47:15 +00:00
|
|
|
function loadFilesystem(name:string) {
|
2017-01-06 00:14:12 +00:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'blob';
|
2018-10-05 13:47:15 +00:00
|
|
|
xhr.open("GET", PWORKER+"fs/fs"+name+".data", false); // synchronous request
|
2017-01-06 00:14:12 +00:00
|
|
|
xhr.send(null);
|
2017-01-23 21:21:45 +00:00
|
|
|
fsBlob[name] = xhr.response;
|
2017-01-06 00:14:12 +00:00
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'json';
|
2018-10-05 13:47:15 +00:00
|
|
|
xhr.open("GET", PWORKER+"fs/fs"+name+".js.metadata", false); // synchronous request
|
2017-01-06 00:14:12 +00:00
|
|
|
xhr.send(null);
|
2017-01-23 21:21:45 +00:00
|
|
|
fsMeta[name] = xhr.response;
|
|
|
|
console.log("Loaded "+name+" filesystem", fsMeta[name].files.length, 'files', fsBlob[name].size, 'bytes');
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 18:34:00 +00:00
|
|
|
var loaded = {}
|
2018-10-05 13:47:15 +00:00
|
|
|
function load(modulename:string, debug?:boolean) {
|
2017-11-05 18:34:00 +00:00
|
|
|
if (!loaded[modulename]) {
|
2018-10-05 13:47:15 +00:00
|
|
|
importScripts(PWORKER+'asmjs/'+modulename+(debug?"."+debug+".js":".js"));
|
2017-11-05 18:34:00 +00:00
|
|
|
loaded[modulename] = 1;
|
|
|
|
}
|
|
|
|
}
|
2018-10-05 13:47:15 +00:00
|
|
|
function loadGen(modulename:string) {
|
2018-07-11 04:04:28 +00:00
|
|
|
if (!loaded[modulename]) {
|
|
|
|
importScripts('../../gen/'+modulename+".js");
|
|
|
|
loaded[modulename] = 1;
|
|
|
|
}
|
|
|
|
}
|
2018-10-05 13:47:15 +00:00
|
|
|
function loadWASM(modulename:string, debug?:boolean) {
|
2017-11-05 18:34:00 +00:00
|
|
|
if (!loaded[modulename]) {
|
2018-10-05 13:47:15 +00:00
|
|
|
importScripts(PWORKER+"wasm/" + modulename+(debug?"."+debug+".js":".js"));
|
2017-11-05 18:34:00 +00:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'arraybuffer';
|
2018-10-05 13:47:15 +00:00
|
|
|
xhr.open("GET", PWORKER+"wasm/"+modulename+".wasm", false); // synchronous request
|
2017-11-05 18:34:00 +00:00
|
|
|
xhr.send(null);
|
|
|
|
if (xhr.response) {
|
2018-07-10 04:44:17 +00:00
|
|
|
wasmBlob[modulename] = new Uint8Array(xhr.response);
|
2017-11-05 18:34:00 +00:00
|
|
|
console.log("Loaded " + modulename + ".wasm");
|
|
|
|
loaded[modulename] = 1;
|
|
|
|
} else {
|
2018-03-03 02:41:56 +00:00
|
|
|
throw Error("Could not load WASM file " + modulename + ".wasm");
|
2017-11-05 18:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-05 13:47:15 +00:00
|
|
|
function loadNative(modulename:string) {
|
2017-11-07 21:41:07 +00:00
|
|
|
// detect WASM
|
2018-07-10 05:09:10 +00:00
|
|
|
if (CACHE_WASM_MODULES && typeof WebAssembly === 'object') {
|
2017-11-07 21:41:07 +00:00
|
|
|
loadWASM(modulename);
|
|
|
|
} else {
|
|
|
|
load(modulename);
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 18:34:00 +00:00
|
|
|
|
2017-01-10 08:18:54 +00:00
|
|
|
// mount the filesystem at /share
|
2018-10-05 13:47:15 +00:00
|
|
|
function setupFS(FS, name:string) {
|
2018-08-06 15:20:55 +00:00
|
|
|
var WORKERFS = FS.filesystems['WORKERFS']
|
2017-01-06 00:14:12 +00:00
|
|
|
FS.mkdir('/share');
|
2018-08-06 15:20:55 +00:00
|
|
|
FS.mount(WORKERFS, {
|
2017-01-23 21:21:45 +00:00
|
|
|
packages: [{ metadata: fsMeta[name], blob: fsBlob[name] }]
|
2017-01-06 00:14:12 +00:00
|
|
|
}, '/share');
|
2018-08-06 15:20:55 +00:00
|
|
|
// fix for slow Blob operations by caching typed arrays
|
|
|
|
// https://github.com/kripken/emscripten/blob/incoming/src/library_workerfs.js
|
|
|
|
var reader = WORKERFS.reader;
|
|
|
|
var blobcache = {};
|
|
|
|
WORKERFS.stream_ops.read = function (stream, buffer, offset, length, position) {
|
|
|
|
if (position >= stream.node.size) return 0;
|
|
|
|
var contents = blobcache[stream.path];
|
|
|
|
if (!contents) {
|
|
|
|
var ab = reader.readAsArrayBuffer(stream.node.contents);
|
|
|
|
contents = blobcache[stream.path] = new Uint8Array(ab);
|
|
|
|
}
|
|
|
|
if (position + length > contents.length)
|
|
|
|
length = contents.length - position;
|
|
|
|
for (var i=0; i<length; i++) {
|
|
|
|
buffer[offset+i] = contents[position+i];
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
};
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
2016-12-16 01:21:51 +00:00
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
var print_fn = function(s:string) {
|
2017-01-12 16:22:27 +00:00
|
|
|
console.log(s);
|
|
|
|
//console.log(new Error().stack);
|
|
|
|
}
|
2017-01-06 00:14:12 +00:00
|
|
|
|
2017-01-13 02:21:35 +00:00
|
|
|
// test.c(6) : warning 85: in function main unreferenced local variable : 'x'
|
2017-01-16 15:35:19 +00:00
|
|
|
// main.a (4): error: Unknown Mnemonic 'xxx'.
|
2017-01-22 14:35:04 +00:00
|
|
|
// at 2: warning 190: ISO C forbids an empty source file
|
2018-08-18 00:46:55 +00:00
|
|
|
var re_msvc = /[/]*([^( ]+)\s*[(](\d+)[)]\s*:\s*(.+?):\s*(.*)/;
|
2017-01-16 15:35:19 +00:00
|
|
|
var re_msvc2 = /\s*(at)\s+(\d+)\s*(:)\s*(.*)/;
|
2018-06-19 22:42:02 +00:00
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function msvcErrorMatcher(errors:WorkerError[]) {
|
|
|
|
return function(s:string) {
|
2018-06-19 22:42:02 +00:00
|
|
|
var matches = re_msvc.exec(s) || re_msvc2.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
var errline = parseInt(matches[2]);
|
|
|
|
errors.push({
|
|
|
|
line:errline,
|
2018-08-18 00:46:55 +00:00
|
|
|
path:matches[1],
|
2018-10-05 13:47:15 +00:00
|
|
|
//type:matches[3],
|
2018-06-19 22:42:02 +00:00
|
|
|
msg:matches[4]
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log(s);
|
|
|
|
}
|
2017-01-13 02:21:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-15 18:14:40 +00:00
|
|
|
function makeErrorMatcher(errors:WorkerError[], regex, iline:number, imsg:number, mainpath:string, ifilename?:number) {
|
2017-01-23 21:21:45 +00:00
|
|
|
return function(s) {
|
|
|
|
var matches = regex.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
errors.push({
|
2017-11-13 05:24:19 +00:00
|
|
|
line:parseInt(matches[iline]) || 1,
|
2018-08-18 00:46:55 +00:00
|
|
|
msg:matches[imsg],
|
2018-12-15 18:14:40 +00:00
|
|
|
path:ifilename ? matches[ifilename] : mainpath
|
2017-01-23 21:21:45 +00:00
|
|
|
});
|
2017-11-13 05:24:19 +00:00
|
|
|
} else {
|
2018-07-03 03:55:38 +00:00
|
|
|
console.log("??? "+s);
|
2017-01-23 21:21:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function extractErrors(regex, strings:string[], path:string) {
|
2017-01-23 21:21:45 +00:00
|
|
|
var errors = [];
|
2018-08-18 00:46:55 +00:00
|
|
|
var matcher = makeErrorMatcher(errors, regex, 1, 2, path);
|
2017-01-23 21:21:45 +00:00
|
|
|
for (var i=0; i<strings.length; i++) {
|
|
|
|
matcher(strings[i]);
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
2018-07-30 02:33:15 +00:00
|
|
|
// TODO: "of" doesn't work in MSIE
|
|
|
|
|
2018-08-28 17:59:12 +00:00
|
|
|
var re_crlf = /\r?\n/;
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function parseListing(code:string, lineMatch, iline:number, ioffset:number, iinsns:number) {
|
2017-01-14 02:31:04 +00:00
|
|
|
var lines = [];
|
2018-08-28 17:59:12 +00:00
|
|
|
for (var line of code.split(re_crlf)) {
|
2017-01-14 02:31:04 +00:00
|
|
|
var linem = lineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
2017-01-15 03:46:12 +00:00
|
|
|
var linenum = parseInt(linem[iline]);
|
|
|
|
var offset = parseInt(linem[ioffset], 16);
|
|
|
|
var insns = linem[iinsns];
|
2017-01-14 02:31:04 +00:00
|
|
|
if (insns) {
|
|
|
|
lines.push({
|
|
|
|
line:linenum,
|
2018-08-29 12:24:13 +00:00
|
|
|
offset:offset,
|
2017-01-14 02:31:04 +00:00
|
|
|
insns:insns,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function parseSourceLines(code:string, lineMatch, offsetMatch) {
|
2017-01-15 18:31:52 +00:00
|
|
|
var lines = [];
|
|
|
|
var lastlinenum = 0;
|
2018-08-28 17:59:12 +00:00
|
|
|
for (var line of code.split(re_crlf)) {
|
2017-01-15 18:31:52 +00:00
|
|
|
var linem = lineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
|
|
|
lastlinenum = parseInt(linem[1]);
|
|
|
|
} else if (lastlinenum) {
|
|
|
|
var linem = offsetMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
|
|
|
var offset = parseInt(linem[1], 16);
|
|
|
|
lines.push({
|
|
|
|
line:lastlinenum,
|
2018-08-29 12:24:13 +00:00
|
|
|
offset:offset,
|
2017-01-15 18:31:52 +00:00
|
|
|
});
|
|
|
|
lastlinenum = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function parseDASMListing(code:string, unresolved:{}, mainFilename:string) {
|
2016-12-16 01:21:51 +00:00
|
|
|
// 4 08ee a9 00 start lda #01workermain.js:23:5
|
2018-08-25 02:55:16 +00:00
|
|
|
var lineMatch = /\s*(\d+)\s+(\S+)\s+([0-9a-f]+)\s+([?0-9a-f][?0-9a-f ]+)?\s+(.+)?/i;
|
|
|
|
var equMatch = /\bequ\b/i;
|
|
|
|
var macroMatch = /\bMAC\s+(.+)?/i;
|
2016-12-16 01:21:51 +00:00
|
|
|
var errors = [];
|
|
|
|
var lines = [];
|
2018-08-25 02:55:16 +00:00
|
|
|
var macrolines = [];
|
2016-12-16 01:21:51 +00:00
|
|
|
var lastline = 0;
|
2018-08-25 02:55:16 +00:00
|
|
|
var macros = {};
|
2018-08-28 17:59:12 +00:00
|
|
|
for (var line of code.split(re_crlf)) {
|
2016-12-16 01:21:51 +00:00
|
|
|
var linem = lineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
2018-07-02 13:34:20 +00:00
|
|
|
var linenum = parseInt(linem[1]);
|
2016-12-16 01:21:51 +00:00
|
|
|
var filename = linem[2];
|
|
|
|
var offset = parseInt(linem[3], 16);
|
|
|
|
var insns = linem[4];
|
|
|
|
var restline = linem[5];
|
2018-08-25 02:55:16 +00:00
|
|
|
if (insns && insns.startsWith('?')) insns = null;
|
2016-12-16 01:21:51 +00:00
|
|
|
// inside of main file?
|
2018-06-25 04:52:40 +00:00
|
|
|
if (filename == mainFilename) {
|
2018-08-25 02:55:16 +00:00
|
|
|
// look for MAC statement
|
|
|
|
var macmatch = macroMatch.exec(restline);
|
|
|
|
if (macmatch) {
|
|
|
|
macros[macmatch[1]] = {line:parseInt(linem[1]), file:linem[2].toLowerCase()};
|
|
|
|
}
|
|
|
|
else if (insns && !restline.match(equMatch)) {
|
2016-12-16 01:21:51 +00:00
|
|
|
lines.push({
|
|
|
|
line:linenum,
|
|
|
|
offset:offset,
|
|
|
|
insns:insns,
|
|
|
|
iscode:restline[0] != '.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
lastline = linenum;
|
|
|
|
} else {
|
|
|
|
// inside of macro or include file
|
2017-01-16 15:35:19 +00:00
|
|
|
if (insns && linem[3] && lastline>0) {
|
2016-12-16 01:21:51 +00:00
|
|
|
lines.push({
|
|
|
|
line:lastline+1,
|
|
|
|
offset:offset,
|
|
|
|
insns:null
|
|
|
|
});
|
|
|
|
}
|
2018-08-25 02:55:16 +00:00
|
|
|
// inside of macro?
|
|
|
|
var mac = macros[filename.toLowerCase()];
|
|
|
|
if (insns && mac) {
|
|
|
|
macrolines.push({
|
|
|
|
filename:mac.file,
|
|
|
|
line:mac.line+linenum,
|
|
|
|
offset:offset,
|
|
|
|
insns:insns
|
|
|
|
});
|
|
|
|
}
|
2016-12-16 01:21:51 +00:00
|
|
|
}
|
|
|
|
// TODO: better symbol test (word boundaries)
|
2018-08-26 02:00:45 +00:00
|
|
|
// TODO: ignore IFCONST and IFNCONST usage
|
2017-01-03 15:43:40 +00:00
|
|
|
for (var key in unresolved) {
|
2016-12-16 01:21:51 +00:00
|
|
|
var pos = restline ? restline.indexOf(key) : line.indexOf(key);
|
|
|
|
if (pos >= 0) {
|
|
|
|
errors.push({
|
2018-08-26 02:00:45 +00:00
|
|
|
path:filename,
|
2016-12-16 01:21:51 +00:00
|
|
|
line:linenum,
|
|
|
|
msg:"Unresolved symbol '" + key + "'"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-16 15:35:19 +00:00
|
|
|
var errm = re_msvc.exec(line);
|
2016-12-16 01:21:51 +00:00
|
|
|
if (errm) {
|
|
|
|
errors.push({
|
2018-08-18 00:46:55 +00:00
|
|
|
path:errm[1],
|
2017-01-16 15:35:19 +00:00
|
|
|
line:parseInt(errm[2]),
|
|
|
|
msg:errm[4]
|
2016-12-16 01:21:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-08-25 02:55:16 +00:00
|
|
|
// TODO: use macrolines
|
2018-08-27 00:22:50 +00:00
|
|
|
// TODO: return {text:code, asmlines:lines, macrolines:macrolines, errors:errors};
|
2018-08-25 02:55:16 +00:00
|
|
|
return {lines:lines, macrolines:macrolines, errors:errors};
|
2016-12-16 01:21:51 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function assembleDASM(step:BuildStep) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("dasm");
|
2016-12-16 01:21:51 +00:00
|
|
|
var re_usl = /(\w+)\s+0000\s+[?][?][?][?]/;
|
|
|
|
var unresolved = {};
|
2018-08-03 18:06:08 +00:00
|
|
|
var errors = [];
|
2018-10-05 13:47:15 +00:00
|
|
|
var errorMatcher = msvcErrorMatcher(errors);
|
2017-01-06 00:14:12 +00:00
|
|
|
function match_fn(s) {
|
2016-12-16 01:21:51 +00:00
|
|
|
var matches = re_usl.exec(s);
|
|
|
|
if (matches) {
|
2018-08-26 02:00:45 +00:00
|
|
|
var key = matches[1];
|
|
|
|
if (key != 'NO_ILLEGAL_OPCODES') { // TODO
|
|
|
|
unresolved[matches[1]] = 0;
|
|
|
|
}
|
2018-08-03 18:06:08 +00:00
|
|
|
} else if (s.startsWith("Warning:")) {
|
2018-09-05 02:28:12 +00:00
|
|
|
errors.push({line:0, msg:s.substr(9)});
|
2018-10-05 13:47:15 +00:00
|
|
|
} else {
|
|
|
|
errorMatcher(s);
|
2016-12-16 01:21:51 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-05 13:47:15 +00:00
|
|
|
var Module = emglobal.DASM({
|
2016-12-16 01:21:51 +00:00
|
|
|
noInitialRun:true,
|
2017-01-06 00:14:12 +00:00
|
|
|
print:match_fn
|
2016-12-16 01:21:51 +00:00
|
|
|
});
|
|
|
|
var FS = Module['FS'];
|
2018-06-25 04:52:40 +00:00
|
|
|
populateFiles(step, FS, {
|
2018-07-02 13:34:20 +00:00
|
|
|
mainFilePath:'main.a'
|
2018-06-25 04:52:40 +00:00
|
|
|
});
|
2018-06-28 00:26:22 +00:00
|
|
|
var binpath = step.prefix+'.bin';
|
|
|
|
var lstpath = step.prefix+'.lst';
|
2018-07-02 13:34:20 +00:00
|
|
|
var sympath = step.prefix+'.sym';
|
2018-11-22 16:22:54 +00:00
|
|
|
execMain(step, Module, [step.path, '-f3',
|
2018-11-20 17:31:19 +00:00
|
|
|
"-l"+lstpath,
|
|
|
|
"-o"+binpath,
|
|
|
|
"-s"+sympath ]);
|
2018-06-28 00:26:22 +00:00
|
|
|
var alst = FS.readFile(lstpath, {'encoding':'utf8'});
|
2018-08-04 14:21:50 +00:00
|
|
|
// parse main listing, get errors
|
2018-07-04 02:14:07 +00:00
|
|
|
var listing = parseDASMListing(alst, unresolved, step.path);
|
2018-08-03 18:06:08 +00:00
|
|
|
errors = errors.concat(listing.errors);
|
|
|
|
if (errors.length) {
|
|
|
|
return {errors:errors};
|
2018-07-04 02:14:07 +00:00
|
|
|
}
|
2018-08-04 14:21:50 +00:00
|
|
|
var listings = {};
|
2018-08-25 02:55:16 +00:00
|
|
|
listings[lstpath] = listing;
|
2018-08-04 14:21:50 +00:00
|
|
|
// parse include files
|
2018-08-07 20:15:45 +00:00
|
|
|
// TODO: kinda wasted effort
|
2018-08-04 14:21:50 +00:00
|
|
|
for (var fn of step.files) {
|
|
|
|
if (fn != step.path) {
|
|
|
|
var lst = parseDASMListing(alst, unresolved, fn);
|
|
|
|
listings[fn] = lst; // TODO: foo.asm.lst
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 19:39:33 +00:00
|
|
|
var aout, asym;
|
|
|
|
aout = FS.readFile(binpath);
|
|
|
|
try {
|
|
|
|
asym = FS.readFile(sympath, {'encoding':'utf8'});
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
errors.push({line:0,msg:"No symbol table generated, maybe segment overflow?"});
|
|
|
|
return {errors:errors}
|
|
|
|
}
|
2018-06-28 00:26:22 +00:00
|
|
|
putWorkFile(binpath, aout);
|
|
|
|
putWorkFile(lstpath, alst);
|
2018-07-02 13:34:20 +00:00
|
|
|
putWorkFile(sympath, asym);
|
2018-07-04 02:14:07 +00:00
|
|
|
// return unchanged if no files changed
|
|
|
|
// TODO: what if listing or symbols change?
|
|
|
|
if (!anyTargetChanged(step, [binpath/*, lstpath, sympath*/]))
|
|
|
|
return;
|
2018-07-02 13:34:20 +00:00
|
|
|
var symbolmap = {};
|
|
|
|
for (var s of asym.split("\n")) {
|
2018-08-19 13:27:00 +00:00
|
|
|
var toks = s.split(/\s+/);
|
2018-07-02 13:34:20 +00:00
|
|
|
if (toks && toks.length >= 2 && !toks[0].startsWith('-')) {
|
|
|
|
symbolmap[toks[0]] = parseInt(toks[1], 16);
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
// for bataribasic (TODO)
|
|
|
|
if (step['bblines']) {
|
|
|
|
let lst = listings[lstpath];
|
|
|
|
lst.asmlines = lst.lines;
|
|
|
|
lst.text = alst;
|
|
|
|
lst.lines = [];
|
|
|
|
}
|
2017-01-10 08:18:54 +00:00
|
|
|
return {
|
2018-11-22 16:22:54 +00:00
|
|
|
output:aout,
|
2018-06-28 00:26:22 +00:00
|
|
|
listings:listings,
|
2018-08-03 18:06:08 +00:00
|
|
|
errors:errors,
|
2018-07-02 13:34:20 +00:00
|
|
|
symbolmap:symbolmap,
|
2017-01-10 08:18:54 +00:00
|
|
|
};
|
2017-01-04 21:07:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function setupStdin(fs, code:string) {
|
2017-01-13 02:21:35 +00:00
|
|
|
var i = 0;
|
|
|
|
fs.init(
|
|
|
|
function() { return i<code.length ? code.charCodeAt(i++) : null; }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-25 23:47:40 +00:00
|
|
|
/*
|
|
|
|
000000r 1 .segment "CODE"
|
|
|
|
000000r 1 ; int main() { return mul2(2); }
|
|
|
|
000000r 1 .dbg line, "main.c", 3
|
|
|
|
000000r 1 A2 00 ldx #$00
|
|
|
|
*/
|
2018-08-06 20:23:19 +00:00
|
|
|
function parseCA65Listing(code, symbols, params, dbg) {
|
2018-06-25 23:47:40 +00:00
|
|
|
var segofs = 0;
|
2017-01-06 00:14:12 +00:00
|
|
|
// .dbg line, "main.c", 1
|
2018-06-25 23:47:40 +00:00
|
|
|
var segLineMatch = /[.]segment\s+"(\w+)"/;
|
|
|
|
//var dbgLineMatch = /^([0-9A-F]+)([r]?)\s+(\d+)\s+[.]dbg\s+line,\s+\S+,\s+(\d+)/;
|
2018-06-28 00:26:22 +00:00
|
|
|
var dbgLineMatch = /^([0-9A-F]+)([r]?)\s+(\d+)\s+[.]dbg\s+line,\s+"(\w+[.]\w+)", (\d+)/;
|
2018-06-25 23:47:40 +00:00
|
|
|
var insnLineMatch = /^([0-9A-F]+)([r]?)\s+(\d+)\s+([0-9A-F][0-9A-F ]*[0-9A-F])\s+/;
|
2017-01-06 00:14:12 +00:00
|
|
|
var lines = [];
|
2018-06-25 23:47:40 +00:00
|
|
|
var linenum = 0;
|
2018-08-28 17:59:12 +00:00
|
|
|
for (var line of code.split(re_crlf)) {
|
2018-06-25 23:47:40 +00:00
|
|
|
linenum++;
|
|
|
|
var segm = segLineMatch.exec(line);
|
|
|
|
if (segm) {
|
|
|
|
var segname = segm[1];
|
|
|
|
var segsym = '__'+segname+'_RUN__';
|
2018-08-06 20:23:19 +00:00
|
|
|
segofs = parseInt(symbols[segsym] || params[segsym]) || 0;
|
2018-06-25 23:47:40 +00:00
|
|
|
}
|
|
|
|
if (dbg) {
|
|
|
|
var linem = dbgLineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
|
|
|
var offset = parseInt(linem[1], 16);
|
|
|
|
lines.push({
|
|
|
|
// TODO: sourcefile
|
|
|
|
line:parseInt(linem[5]),
|
|
|
|
offset:offset + segofs,
|
|
|
|
insns:null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var linem = insnLineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
|
|
|
var offset = parseInt(linem[1], 16);
|
|
|
|
var insns = linem[4].trim();
|
|
|
|
if (insns.length) {
|
|
|
|
lines.push({
|
|
|
|
line:linenum,
|
|
|
|
offset:offset + segofs,
|
|
|
|
insns:insns
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-25 23:47:40 +00:00
|
|
|
return lines;
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function assembleCA65(step:BuildStep) {
|
2017-11-07 21:41:07 +00:00
|
|
|
loadNative("ca65");
|
2018-06-19 22:42:02 +00:00
|
|
|
var errors = [];
|
2018-06-25 14:43:15 +00:00
|
|
|
gatherFiles(step, {mainFilePath:"main.s"});
|
|
|
|
var objpath = step.prefix+".o";
|
|
|
|
var lstpath = step.prefix+".lst";
|
|
|
|
if (staleFiles(step, [objpath, lstpath])) {
|
|
|
|
var objout, lstout;
|
2018-10-05 13:47:15 +00:00
|
|
|
var CA65 = emglobal.ca65({
|
2018-07-10 04:44:17 +00:00
|
|
|
instantiateWasm: moduleInstFn('ca65'),
|
2017-01-06 00:14:12 +00:00
|
|
|
noInitialRun:true,
|
2017-01-10 08:18:54 +00:00
|
|
|
//logReadFiles:true,
|
2017-01-06 00:14:12 +00:00
|
|
|
print:print_fn,
|
2018-06-19 22:42:02 +00:00
|
|
|
printErr:msvcErrorMatcher(errors),
|
2017-01-06 00:14:12 +00:00
|
|
|
});
|
|
|
|
var FS = CA65['FS'];
|
2018-06-25 04:52:40 +00:00
|
|
|
setupFS(FS, '65-'+step.platform.split('-')[0]);
|
2018-06-25 14:43:15 +00:00
|
|
|
populateFiles(step, FS);
|
2018-06-28 00:26:22 +00:00
|
|
|
execMain(step, CA65, ['-v', '-g', '-I', '/share/asminc', '-o', objpath, '-l', lstpath, step.path]);
|
2018-06-19 22:42:02 +00:00
|
|
|
if (errors.length)
|
|
|
|
return {errors:errors};
|
2018-06-25 14:43:15 +00:00
|
|
|
objout = FS.readFile(objpath, {encoding:'binary'});
|
|
|
|
lstout = FS.readFile(lstpath, {encoding:'utf8'});
|
|
|
|
putWorkFile(objpath, objout);
|
|
|
|
putWorkFile(lstpath, lstout);
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
return {
|
|
|
|
linktool:"ld65",
|
|
|
|
files:[objpath, lstpath],
|
|
|
|
args:[objpath]
|
|
|
|
};
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function linkLD65(step:BuildStep) {
|
2018-06-25 04:52:40 +00:00
|
|
|
loadNative("ld65");
|
|
|
|
var params = step.params;
|
|
|
|
var platform = step.platform;
|
2018-06-25 14:43:15 +00:00
|
|
|
gatherFiles(step);
|
|
|
|
var binpath = "main";
|
|
|
|
if (staleFiles(step, [binpath])) {
|
|
|
|
var errors = [];
|
2018-07-03 03:55:38 +00:00
|
|
|
var errmsg = '';
|
2018-10-05 13:47:15 +00:00
|
|
|
var LD65 = emglobal.ld65({
|
2018-07-10 04:44:17 +00:00
|
|
|
instantiateWasm: moduleInstFn('ld65'),
|
2017-01-06 00:14:12 +00:00
|
|
|
noInitialRun:true,
|
2017-01-10 08:18:54 +00:00
|
|
|
//logReadFiles:true,
|
2017-01-06 00:14:12 +00:00
|
|
|
print:print_fn,
|
2018-07-03 03:55:38 +00:00
|
|
|
printErr:function(s) { errmsg += s + '\n'; }
|
2017-01-06 00:14:12 +00:00
|
|
|
});
|
|
|
|
var FS = LD65['FS'];
|
2017-04-12 02:46:06 +00:00
|
|
|
var cfgfile = '/' + platform + '.cfg';
|
2018-06-20 07:09:37 +00:00
|
|
|
setupFS(FS, '65-'+platform.split('-')[0]);
|
2018-06-25 14:43:15 +00:00
|
|
|
populateFiles(step, FS);
|
2018-11-28 15:31:07 +00:00
|
|
|
populateExtraFiles(step, FS, params.extra_link_files);
|
2017-05-21 21:34:57 +00:00
|
|
|
var libargs = params.libargs;
|
2018-06-25 14:43:15 +00:00
|
|
|
var args = ['--cfg-path', '/share/cfg',
|
2018-06-20 04:13:19 +00:00
|
|
|
'--lib-path', '/share/lib',
|
2018-06-22 06:24:52 +00:00
|
|
|
'--lib-path', '/share/target/apple2/drv', // TODO
|
|
|
|
'-D', '__EXEHDR__=0', // TODO
|
2017-05-21 21:34:57 +00:00
|
|
|
'-C', params.cfgfile,
|
2018-06-21 18:15:05 +00:00
|
|
|
'-Ln', 'main.vice',
|
2017-05-18 02:33:56 +00:00
|
|
|
//'--dbgfile', 'main.dbg',
|
2018-06-25 14:43:15 +00:00
|
|
|
'-o', 'main', '-m', 'main.map'].concat(step.args, libargs);
|
2018-06-28 00:26:22 +00:00
|
|
|
//console.log(args);
|
2018-06-25 14:43:15 +00:00
|
|
|
execMain(step, LD65, args);
|
2018-07-03 03:55:38 +00:00
|
|
|
if (errmsg.length)
|
|
|
|
errors.push({line:0, msg:errmsg});
|
2018-06-25 14:43:15 +00:00
|
|
|
if (errors.length)
|
2018-06-19 22:42:02 +00:00
|
|
|
return {errors:errors};
|
2018-06-25 14:43:15 +00:00
|
|
|
var aout = FS.readFile("main", {encoding:'binary'});
|
|
|
|
var mapout = FS.readFile("main.map", {encoding:'utf8'});
|
|
|
|
var viceout = FS.readFile("main.vice", {encoding:'utf8'});
|
2018-08-16 23:19:20 +00:00
|
|
|
//var dbgout = FS.readFile("main.dbg", {encoding:'utf8'});
|
2018-06-28 03:26:23 +00:00
|
|
|
putWorkFile("main", aout);
|
|
|
|
putWorkFile("main.map", mapout);
|
|
|
|
putWorkFile("main.vice", viceout);
|
|
|
|
// return unchanged if no files changed
|
2018-06-28 04:57:06 +00:00
|
|
|
if (!anyTargetChanged(step, ["main", "main.map", "main.vice"]))
|
2018-06-28 03:26:23 +00:00
|
|
|
return;
|
2018-06-21 18:15:05 +00:00
|
|
|
// parse symbol map (TODO: omit segments, constants)
|
|
|
|
var symbolmap = {};
|
|
|
|
for (var s of viceout.split("\n")) {
|
|
|
|
var toks = s.split(" ");
|
|
|
|
if (toks[0] == 'al') {
|
|
|
|
symbolmap[toks[2].substr(1)] = parseInt(toks[1], 16);
|
|
|
|
}
|
|
|
|
}
|
2018-06-28 00:26:22 +00:00
|
|
|
// TODO: "of" in IE?
|
|
|
|
var listings = {};
|
|
|
|
for (var fn of step.files) {
|
|
|
|
if (fn.endsWith('.lst')) {
|
|
|
|
var lstout = FS.readFile(fn, {encoding:'utf8'});
|
2018-08-06 20:23:19 +00:00
|
|
|
var asmlines = parseCA65Listing(lstout, symbolmap, params, false);
|
|
|
|
var srclines = parseCA65Listing(lstout, symbolmap, params, true);
|
2018-06-28 00:26:22 +00:00
|
|
|
putWorkFile(fn, lstout);
|
|
|
|
listings[fn] = {
|
|
|
|
asmlines:srclines.length ? asmlines : null,
|
|
|
|
lines:srclines.length ? srclines : asmlines,
|
|
|
|
text:lstout
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 08:18:54 +00:00
|
|
|
return {
|
2018-06-25 23:47:40 +00:00
|
|
|
output:aout, //.slice(0),
|
2018-06-28 00:26:22 +00:00
|
|
|
listings:listings,
|
2018-06-25 23:47:40 +00:00
|
|
|
errors:errors,
|
2018-06-21 18:15:05 +00:00
|
|
|
symbolmap:symbolmap,
|
2017-01-10 08:18:54 +00:00
|
|
|
};
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function compileCC65(step:BuildStep) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("cc65");
|
2018-06-25 04:52:40 +00:00
|
|
|
var params = step.params;
|
2017-01-10 08:18:54 +00:00
|
|
|
// stderr
|
2018-07-30 02:33:15 +00:00
|
|
|
var re_err1 = /.*?[(](\d+)[)].*?: (.+)/;
|
2017-01-10 08:18:54 +00:00
|
|
|
var errors = [];
|
|
|
|
var errline = 0;
|
|
|
|
function match_fn(s) {
|
2017-02-01 18:21:17 +00:00
|
|
|
console.log(s);
|
2017-01-10 08:18:54 +00:00
|
|
|
var matches = re_err1.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
errline = parseInt(matches[1]);
|
|
|
|
errors.push({
|
|
|
|
line:errline,
|
|
|
|
msg:matches[2]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
gatherFiles(step, {mainFilePath:"main.c"});
|
|
|
|
var destpath = step.prefix + '.s';
|
|
|
|
if (staleFiles(step, [destpath])) {
|
2018-10-05 13:47:15 +00:00
|
|
|
var CC65 = emglobal.cc65({
|
2018-06-25 14:43:15 +00:00
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
|
|
|
print:print_fn,
|
|
|
|
printErr:match_fn,
|
|
|
|
});
|
|
|
|
var FS = CC65['FS'];
|
|
|
|
setupFS(FS, '65-'+step.platform.split('-')[0]);
|
|
|
|
populateFiles(step, FS);
|
2018-08-16 23:19:20 +00:00
|
|
|
execMain(step, CC65, ['-T', '-g',
|
2018-06-25 14:43:15 +00:00
|
|
|
'-Oirs',
|
2018-08-15 04:43:52 +00:00
|
|
|
'-Cl', // static locals
|
2018-06-25 14:43:15 +00:00
|
|
|
'-I', '/share/include',
|
|
|
|
'-D' + params.define,
|
|
|
|
step.path]);
|
|
|
|
if (errors.length)
|
|
|
|
return {errors:errors};
|
|
|
|
var asmout = FS.readFile(destpath, {encoding:'utf8'});
|
|
|
|
putWorkFile(destpath, asmout);
|
2017-01-10 08:18:54 +00:00
|
|
|
}
|
2018-06-25 04:52:40 +00:00
|
|
|
return {
|
|
|
|
nexttool:"ca65",
|
2018-06-25 14:43:15 +00:00
|
|
|
path:destpath,
|
2018-11-20 17:31:19 +00:00
|
|
|
args:[destpath],
|
|
|
|
files:[destpath],
|
2018-06-25 04:52:40 +00:00
|
|
|
};
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 18:31:52 +00:00
|
|
|
function hexToArray(s, ofs) {
|
|
|
|
var buf = new ArrayBuffer(s.length/2);
|
|
|
|
var arr = new Uint8Array(buf);
|
|
|
|
for (var i=0; i<arr.length; i++) {
|
|
|
|
arr[i] = parseInt(s.slice(i*2+ofs,i*2+ofs+2), 16);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2017-05-02 13:09:53 +00:00
|
|
|
function parseIHX(ihx, rom_start, rom_size) {
|
|
|
|
var output = new Uint8Array(new ArrayBuffer(rom_size));
|
2017-01-15 18:31:52 +00:00
|
|
|
for (var s of ihx.split("\n")) {
|
|
|
|
if (s[0] == ':') {
|
|
|
|
var arr = hexToArray(s, 1);
|
|
|
|
var count = arr[0];
|
2017-05-02 13:09:53 +00:00
|
|
|
var address = (arr[1]<<8) + arr[2] - rom_start;
|
2017-01-15 18:31:52 +00:00
|
|
|
var rectype = arr[3];
|
|
|
|
if (rectype == 0) {
|
|
|
|
for (var i=0; i<count; i++) {
|
|
|
|
var b = arr[4+i];
|
|
|
|
output[i+address] = b;
|
|
|
|
}
|
|
|
|
} else if (rectype == 1) {
|
|
|
|
return output;
|
2018-11-28 15:31:07 +00:00
|
|
|
} else {
|
|
|
|
console.log(s); // unknown record type
|
2017-01-15 18:31:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-28 17:59:12 +00:00
|
|
|
return output;
|
2017-01-15 18:31:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function assembleSDASZ80(step:BuildStep) {
|
2017-11-07 21:41:07 +00:00
|
|
|
loadNative("sdasz80");
|
2017-01-15 18:31:52 +00:00
|
|
|
var objout, lstout, symout;
|
2018-06-19 22:42:02 +00:00
|
|
|
var errors = [];
|
2018-06-25 14:43:15 +00:00
|
|
|
gatherFiles(step, {mainFilePath:"main.asm"});
|
|
|
|
var objpath = step.prefix + ".rel";
|
|
|
|
var lstpath = step.prefix + ".lst";
|
|
|
|
if (staleFiles(step, [objpath, lstpath])) {
|
2017-01-22 14:35:04 +00:00
|
|
|
//?ASxxxx-Error-<o> in line 1 of main.asm null
|
|
|
|
// <o> .org in REL area or directive / mnemonic error
|
2018-09-21 12:39:15 +00:00
|
|
|
// ?ASxxxx-Error-<q> in line 1627 of cosmic.asm
|
|
|
|
// <q> missing or improper operators, terminators, or delimiters
|
|
|
|
var match_asm_re1 = / in line (\d+) of (\S+)/; // TODO
|
|
|
|
var match_asm_re2 = / <\w> (.+)/; // TODO
|
|
|
|
var errline = 0;
|
|
|
|
var errpath = step.path;
|
2018-10-05 13:47:15 +00:00
|
|
|
var match_asm_fn = (s:string) => {
|
2018-09-21 12:39:15 +00:00
|
|
|
var m = match_asm_re1.exec(s);
|
|
|
|
if (m) {
|
|
|
|
errline = parseInt(m[1]);
|
|
|
|
errpath = m[2];
|
2018-08-29 01:41:51 +00:00
|
|
|
} else {
|
2018-09-21 12:39:15 +00:00
|
|
|
m = match_asm_re2.exec(s);
|
|
|
|
if (m) {
|
|
|
|
errors.push({
|
|
|
|
line:errline,
|
|
|
|
path:errpath,
|
|
|
|
msg:m[1]
|
|
|
|
});
|
|
|
|
}
|
2017-01-15 18:31:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-05 13:47:15 +00:00
|
|
|
var ASZ80 = emglobal.sdasz80({
|
2018-07-10 04:44:17 +00:00
|
|
|
instantiateWasm: moduleInstFn('sdasz80'),
|
2017-01-15 18:31:52 +00:00
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
2017-01-22 14:35:04 +00:00
|
|
|
print:match_asm_fn,
|
|
|
|
printErr:match_asm_fn,
|
2017-01-15 18:31:52 +00:00
|
|
|
});
|
|
|
|
var FS = ASZ80['FS'];
|
2018-06-25 14:43:15 +00:00
|
|
|
populateFiles(step, FS);
|
2018-06-25 04:52:40 +00:00
|
|
|
execMain(step, ASZ80, ['-plosgffwy', step.path]);
|
2018-06-19 22:42:02 +00:00
|
|
|
if (errors.length) {
|
|
|
|
return {errors:errors};
|
2017-01-15 18:31:52 +00:00
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
objout = FS.readFile(objpath, {encoding:'utf8'});
|
|
|
|
lstout = FS.readFile(lstpath, {encoding:'utf8'});
|
|
|
|
putWorkFile(objpath, objout);
|
|
|
|
putWorkFile(lstpath, lstout);
|
2018-06-25 04:52:40 +00:00
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
return {
|
|
|
|
linktool:"sdldz80",
|
|
|
|
files:[objpath, lstpath],
|
|
|
|
args:[objpath]
|
|
|
|
};
|
|
|
|
//symout = FS.readFile("main.sym", {encoding:'utf8'});
|
2018-06-25 04:52:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function linkSDLDZ80(step:BuildStep)
|
2018-06-25 04:52:40 +00:00
|
|
|
{
|
|
|
|
loadNative("sdldz80");
|
|
|
|
var errors = [];
|
2018-06-25 14:43:15 +00:00
|
|
|
gatherFiles(step);
|
|
|
|
var binpath = "main.ihx";
|
|
|
|
if (staleFiles(step, [binpath])) {
|
2017-01-22 14:35:04 +00:00
|
|
|
//?ASlink-Warning-Undefined Global '__divsint' referenced by module 'main'
|
|
|
|
var match_aslink_re = /\?ASlink-(\w+)-(.+)/;
|
2018-10-05 13:47:15 +00:00
|
|
|
var match_aslink_fn = (s:string) => {
|
2017-01-22 14:35:04 +00:00
|
|
|
var matches = match_aslink_re.exec(s);
|
|
|
|
if (matches) {
|
2018-06-19 22:42:02 +00:00
|
|
|
errors.push({
|
2018-07-03 03:45:08 +00:00
|
|
|
line:0,
|
2017-01-22 14:35:04 +00:00
|
|
|
msg:matches[2]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 04:52:40 +00:00
|
|
|
var params = step.params;
|
2018-10-05 13:47:15 +00:00
|
|
|
var LDZ80 = emglobal.sdldz80({
|
2018-07-10 04:44:17 +00:00
|
|
|
instantiateWasm: moduleInstFn('sdldz80'),
|
2017-01-15 18:31:52 +00:00
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
2017-01-22 14:35:04 +00:00
|
|
|
print:match_aslink_fn,
|
|
|
|
printErr:match_aslink_fn,
|
2017-01-15 18:31:52 +00:00
|
|
|
});
|
|
|
|
var FS = LDZ80['FS'];
|
2017-01-23 21:21:45 +00:00
|
|
|
setupFS(FS, 'sdcc');
|
2018-06-25 04:52:40 +00:00
|
|
|
populateFiles(step, FS);
|
2018-11-28 15:31:07 +00:00
|
|
|
populateExtraFiles(step, FS, params.extra_link_files);
|
2018-06-25 06:12:11 +00:00
|
|
|
// TODO: coleco hack so that -u flag works
|
2018-11-19 14:10:13 +00:00
|
|
|
if (step.platform.startsWith("coleco")) {
|
2018-06-25 06:12:11 +00:00
|
|
|
FS.writeFile('crt0.rel', FS.readFile('/share/lib/coleco/crt0.rel', {encoding:'utf8'}));
|
|
|
|
FS.writeFile('crt0.lst', '\n'); // TODO: needed so -u flag works
|
2017-05-02 13:09:53 +00:00
|
|
|
}
|
2018-06-28 00:26:22 +00:00
|
|
|
var args = ['-mjwxyu',
|
2018-06-25 04:52:40 +00:00
|
|
|
'-i', 'main.ihx', // TODO: main?
|
2017-01-15 18:31:52 +00:00
|
|
|
'-b', '_CODE=0x'+params.code_start.toString(16),
|
|
|
|
'-b', '_DATA=0x'+params.data_start.toString(16),
|
2017-01-23 21:21:45 +00:00
|
|
|
'-k', '/share/lib/z80',
|
2017-05-02 13:09:53 +00:00
|
|
|
'-l', 'z80'];
|
2018-06-25 06:12:11 +00:00
|
|
|
if (params.extra_link_args)
|
2017-05-02 13:09:53 +00:00
|
|
|
args.push.apply(args, params.extra_link_args);
|
2018-06-25 06:12:11 +00:00
|
|
|
args.push.apply(args, step.args);
|
2018-11-28 15:31:07 +00:00
|
|
|
//console.log(args);
|
2018-06-25 04:52:40 +00:00
|
|
|
execMain(step, LDZ80, args);
|
2017-01-15 18:31:52 +00:00
|
|
|
var hexout = FS.readFile("main.ihx", {encoding:'utf8'});
|
|
|
|
var mapout = FS.readFile("main.noi", {encoding:'utf8'});
|
2018-11-28 15:31:07 +00:00
|
|
|
//console.log(mapout);
|
2018-06-28 03:26:23 +00:00
|
|
|
putWorkFile("main.ihx", hexout);
|
|
|
|
putWorkFile("main.noi", mapout);
|
|
|
|
// return unchanged if no files changed
|
2018-06-28 04:57:06 +00:00
|
|
|
if (!anyTargetChanged(step, ["main.ihx", "main.noi"]))
|
2018-06-28 03:26:23 +00:00
|
|
|
return;
|
2018-11-19 14:10:13 +00:00
|
|
|
|
2018-06-28 00:26:22 +00:00
|
|
|
var listings = {};
|
|
|
|
for (var fn of step.files) {
|
|
|
|
if (fn.endsWith('.lst')) {
|
|
|
|
var rstout = FS.readFile(fn.replace('.lst','.rst'), {encoding:'utf8'});
|
|
|
|
// 0000 21 02 00 [10] 52 ld hl, #2
|
|
|
|
var asmlines = parseListing(rstout, /^\s*([0-9A-F]+)\s+([0-9A-F][0-9A-F r]*[0-9A-F])\s+\[([0-9 ]+)\]\s+(\d+) (.*)/i, 4, 1, 2);
|
|
|
|
var srclines = parseSourceLines(rstout, /^\s+\d+ ;<stdin>:(\d+):/i, /^\s*([0-9A-F]{4})/i);
|
|
|
|
putWorkFile(fn, rstout);
|
2018-08-27 21:31:49 +00:00
|
|
|
// TODO: you have to get rid of all source lines to get asm listing
|
2018-06-28 00:26:22 +00:00
|
|
|
listings[fn] = {
|
|
|
|
asmlines:srclines.length ? asmlines : null,
|
|
|
|
lines:srclines.length ? srclines : asmlines,
|
|
|
|
text:rstout
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2017-01-16 04:47:12 +00:00
|
|
|
// parse symbol map
|
|
|
|
var symbolmap = {};
|
|
|
|
for (var s of mapout.split("\n")) {
|
|
|
|
var toks = s.split(" ");
|
2017-04-22 01:56:49 +00:00
|
|
|
if (toks[0] == 'DEF' && !toks[1].startsWith("A$main$")) {
|
|
|
|
symbolmap[toks[1]] = parseInt(toks[2], 16);
|
2017-01-16 04:47:12 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-15 18:31:52 +00:00
|
|
|
return {
|
2018-11-28 15:31:07 +00:00
|
|
|
output:parseIHX(hexout, params.rom_start!==undefined?params.rom_start:params.code_start, params.rom_size),
|
2018-06-28 00:26:22 +00:00
|
|
|
listings:listings,
|
|
|
|
errors:errors,
|
2017-04-22 01:56:49 +00:00
|
|
|
symbolmap:symbolmap,
|
2017-01-15 18:31:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 18:34:00 +00:00
|
|
|
var sdcc;
|
2018-10-05 13:47:15 +00:00
|
|
|
function compileSDCC(step:BuildStep) {
|
2018-06-26 06:56:36 +00:00
|
|
|
|
2018-06-25 14:43:15 +00:00
|
|
|
gatherFiles(step, {
|
2018-06-25 04:52:40 +00:00
|
|
|
mainFilePath:"main.c" // not used
|
2017-01-13 02:21:35 +00:00
|
|
|
});
|
2018-06-25 14:43:15 +00:00
|
|
|
var outpath = step.prefix + ".asm";
|
|
|
|
if (staleFiles(step, [outpath])) {
|
|
|
|
var errors = [];
|
|
|
|
var params = step.params;
|
|
|
|
loadNative('sdcc');
|
|
|
|
var SDCC = sdcc({
|
2018-07-10 04:44:17 +00:00
|
|
|
instantiateWasm: moduleInstFn('sdcc'),
|
2018-06-25 14:43:15 +00:00
|
|
|
noInitialRun:true,
|
|
|
|
noFSInit:true,
|
|
|
|
print:print_fn,
|
|
|
|
printErr:msvcErrorMatcher(errors),
|
2018-07-10 04:44:17 +00:00
|
|
|
//TOTAL_MEMORY:256*1024*1024,
|
2018-06-25 14:43:15 +00:00
|
|
|
});
|
|
|
|
var FS = SDCC['FS'];
|
|
|
|
populateFiles(step, FS);
|
|
|
|
// load source file and preprocess
|
2018-11-28 16:10:24 +00:00
|
|
|
var code = getWorkFileAsString(step.path);
|
2018-08-12 23:59:08 +00:00
|
|
|
var preproc = preprocessMCPP(step);
|
2018-06-25 14:43:15 +00:00
|
|
|
if (preproc.errors) return preproc;
|
|
|
|
else code = preproc.code;
|
|
|
|
// pipe file to stdin
|
|
|
|
setupStdin(FS, code);
|
|
|
|
setupFS(FS, 'sdcc');
|
|
|
|
var args = ['--vc', '--std-sdcc99', '-mz80', //'-Wall',
|
2018-11-26 15:03:35 +00:00
|
|
|
'--c1mode',
|
|
|
|
//'--debug',
|
2018-06-25 14:43:15 +00:00
|
|
|
//'-S', 'main.c',
|
|
|
|
//'--asm=sdasz80',
|
|
|
|
//'--reserve-regs-iy',
|
|
|
|
'--less-pedantic',
|
|
|
|
///'--fomit-frame-pointer',
|
2018-12-06 14:41:45 +00:00
|
|
|
//'--opt-code-speed',
|
2018-11-26 15:03:35 +00:00
|
|
|
'--oldralloc',
|
2018-12-06 14:41:45 +00:00
|
|
|
//'--max-allocs-per-node', '1000',
|
2018-06-25 14:43:15 +00:00
|
|
|
//'--cyclomatic',
|
2018-11-26 15:03:35 +00:00
|
|
|
//'--nooverlay',
|
|
|
|
//'--nogcse',
|
|
|
|
//'--nolabelopt',
|
|
|
|
//'--noinvariant',
|
|
|
|
//'--noinduction',
|
|
|
|
//'--nojtbound',
|
|
|
|
//'--noloopreverse',
|
|
|
|
'--no-peep',
|
|
|
|
'--nolospre',
|
2018-06-25 14:43:15 +00:00
|
|
|
'-o', outpath];
|
|
|
|
if (params.extra_compile_args) {
|
|
|
|
args.push.apply(args, params.extra_compile_args);
|
|
|
|
}
|
|
|
|
execMain(step, SDCC, args);
|
|
|
|
// TODO: preprocessor errors w/ correct file
|
|
|
|
if (errors.length /* && nwarnings < msvc_errors.length*/) {
|
|
|
|
return {errors:errors};
|
|
|
|
}
|
|
|
|
// massage the asm output
|
|
|
|
var asmout = FS.readFile(outpath, {encoding:'utf8'});
|
2017-02-18 22:50:51 +00:00
|
|
|
asmout = " .area _HOME\n .area _CODE\n .area _INITIALIZER\n .area _DATA\n .area _INITIALIZED\n .area _BSEG\n .area _BSS\n .area _HEAP\n" + asmout;
|
2018-06-25 14:43:15 +00:00
|
|
|
putWorkFile(outpath, asmout);
|
2017-02-01 18:21:17 +00:00
|
|
|
}
|
2018-06-25 04:52:40 +00:00
|
|
|
return {
|
|
|
|
nexttool:"sdasz80",
|
2018-06-25 14:43:15 +00:00
|
|
|
path:outpath,
|
2018-11-20 17:31:19 +00:00
|
|
|
args:[outpath],
|
|
|
|
files:[outpath],
|
2018-06-25 04:52:40 +00:00
|
|
|
};
|
2017-01-13 02:21:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 17:28:50 +00:00
|
|
|
function makeCPPSafe(s:string) : string {
|
|
|
|
return s.replace(/[^A-Za-z0-9_]/g,'_');
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function preprocessMCPP(step:BuildStep) {
|
2017-01-22 14:35:04 +00:00
|
|
|
load("mcpp");
|
2018-08-12 23:59:08 +00:00
|
|
|
var platform = step.platform;
|
2017-05-02 13:09:53 +00:00
|
|
|
var params = PLATFORM_PARAMS[platform];
|
|
|
|
if (!params) throw Error("Platform not supported: " + platform);
|
2017-01-23 21:21:45 +00:00
|
|
|
// <stdin>:2: error: Can't open include file "foo.h"
|
|
|
|
var errors = [];
|
2018-08-18 00:46:55 +00:00
|
|
|
var match_fn = makeErrorMatcher(errors, /<stdin>:(\d+): (.+)/, 1, 2, step.path);
|
2018-10-05 13:47:15 +00:00
|
|
|
var MCPP = emglobal.mcpp({
|
2017-01-22 14:35:04 +00:00
|
|
|
noInitialRun:true,
|
|
|
|
noFSInit:true,
|
|
|
|
print:print_fn,
|
2017-01-23 21:21:45 +00:00
|
|
|
printErr:match_fn,
|
2017-01-22 14:35:04 +00:00
|
|
|
});
|
|
|
|
var FS = MCPP['FS'];
|
2018-06-25 21:51:07 +00:00
|
|
|
setupFS(FS, 'sdcc'); // TODO: toolname
|
2018-08-12 23:59:08 +00:00
|
|
|
populateFiles(step, FS);
|
2018-11-28 15:31:07 +00:00
|
|
|
populateExtraFiles(step, FS, params.extra_compile_files);
|
2018-06-25 04:52:40 +00:00
|
|
|
// TODO: make configurable by other compilers
|
2017-05-02 13:09:53 +00:00
|
|
|
var args = [
|
2017-01-23 21:21:45 +00:00
|
|
|
"-D", "__8BITWORKSHOP__",
|
2017-02-20 23:50:29 +00:00
|
|
|
"-D", "__SDCC_z80",
|
2018-11-22 17:28:50 +00:00
|
|
|
"-D", makeCPPSafe(platform.toUpperCase()),
|
2017-01-23 21:21:45 +00:00
|
|
|
"-I", "/share/include",
|
|
|
|
"-Q",
|
2018-08-12 23:59:08 +00:00
|
|
|
step.path, "main.i"];
|
2018-11-29 23:55:20 +00:00
|
|
|
if (step.mainfile) {
|
|
|
|
args.unshift.apply(args, ["-D", "__MAIN__"]);
|
|
|
|
}
|
2017-05-02 13:09:53 +00:00
|
|
|
if (params.extra_preproc_args) {
|
|
|
|
args.push.apply(args, params.extra_preproc_args);
|
|
|
|
}
|
|
|
|
MCPP.callMain(args);
|
2018-06-25 04:52:40 +00:00
|
|
|
if (errors.length)
|
|
|
|
return {errors:errors};
|
|
|
|
var iout = FS.readFile("main.i", {encoding:'utf8'});
|
|
|
|
iout = iout.replace(/^#line /gm,'\n# ');
|
2017-01-23 21:21:45 +00:00
|
|
|
try {
|
|
|
|
var errout = FS.readFile("mcpp.err", {encoding:'utf8'});
|
|
|
|
if (errout.length) {
|
|
|
|
// //main.c:2: error: Can't open include file "stdiosd.h"
|
2018-08-18 00:46:55 +00:00
|
|
|
var errors = extractErrors(/[^:]+:(\d+): (.+)/, errout.split("\n"), step.path);
|
2017-01-29 21:06:05 +00:00
|
|
|
if (errors.length == 0) {
|
2018-07-03 03:45:08 +00:00
|
|
|
errors = [{line:0, msg:errout}];
|
2017-01-29 21:06:05 +00:00
|
|
|
}
|
|
|
|
return {errors: errors};
|
2017-01-23 21:21:45 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
//
|
2017-01-22 14:35:04 +00:00
|
|
|
}
|
|
|
|
return {code:iout};
|
|
|
|
}
|
|
|
|
|
2018-06-28 00:26:22 +00:00
|
|
|
// TODO: must be a better way to do all this
|
2017-04-27 11:48:59 +00:00
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function detectModuleName(code:string) {
|
2018-10-03 19:06:48 +00:00
|
|
|
var m = /^\s*module\s+(\w+_top)\b/m.exec(code)
|
|
|
|
|| /^\s*module\s+(top)\b/m.exec(code)
|
|
|
|
|| /^\s*module\s+(\w+)\b/m.exec(code);
|
2017-11-14 14:33:15 +00:00
|
|
|
return m ? m[1] : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function detectTopModuleName(code:string) {
|
2017-11-20 01:32:58 +00:00
|
|
|
var topmod = detectModuleName(code) || "top";
|
2018-10-03 19:06:48 +00:00
|
|
|
var m = /^\s*module\s+(\w+?_top)/m.exec(code);
|
2017-11-20 01:32:58 +00:00
|
|
|
if (m && m[1]) topmod = m[1];
|
|
|
|
return topmod;
|
|
|
|
}
|
|
|
|
|
2018-12-15 18:14:40 +00:00
|
|
|
// cached stuff (TODO)
|
2018-03-03 02:41:56 +00:00
|
|
|
var jsasm_module_top;
|
|
|
|
var jsasm_module_output;
|
|
|
|
var jsasm_module_key;
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function compileJSASM(asmcode:string, platform, options, is_inline) {
|
2018-07-11 04:04:28 +00:00
|
|
|
loadGen("worker/assembler");
|
2018-10-05 18:02:46 +00:00
|
|
|
var asm = new emglobal.exports.Assembler();
|
2018-03-02 05:15:33 +00:00
|
|
|
var includes = [];
|
2018-11-28 16:10:24 +00:00
|
|
|
asm.loadJSON = (filename:string) => {
|
2018-12-15 18:14:40 +00:00
|
|
|
var jsontext = getWorkFileAsString(filename);
|
2018-11-28 16:10:24 +00:00
|
|
|
if (!jsontext) throw "could not load " + filename;
|
|
|
|
return JSON.parse(jsontext);
|
2018-02-18 05:12:09 +00:00
|
|
|
};
|
2018-03-02 05:15:33 +00:00
|
|
|
asm.loadInclude = function(filename) {
|
|
|
|
if (!filename.startsWith('"') || !filename.endsWith('"'))
|
|
|
|
return 'Expected filename in "double quotes"';
|
|
|
|
filename = filename.substr(1, filename.length-2);
|
|
|
|
includes.push(filename);
|
|
|
|
};
|
2018-03-03 03:39:32 +00:00
|
|
|
var loaded_module = false;
|
2018-03-02 05:15:33 +00:00
|
|
|
asm.loadModule = function(top_module) {
|
|
|
|
// compile last file in list
|
2018-03-03 03:39:32 +00:00
|
|
|
loaded_module = true;
|
2018-03-03 02:41:56 +00:00
|
|
|
var key = top_module + '/' + includes;
|
2018-12-15 18:14:40 +00:00
|
|
|
if (jsasm_module_key != key) {
|
2018-03-03 03:39:32 +00:00
|
|
|
jsasm_module_key = key;
|
2018-12-15 18:14:40 +00:00
|
|
|
jsasm_module_output = null;
|
2018-03-03 02:41:56 +00:00
|
|
|
}
|
2018-12-15 18:14:40 +00:00
|
|
|
jsasm_module_top = top_module;
|
|
|
|
var main_filename = includes[includes.length-1];
|
|
|
|
// TODO: take out .asm dependency
|
|
|
|
var voutput = compileVerilator({platform:platform, files:includes, path:main_filename, tool:'verilator'});
|
|
|
|
if (voutput)
|
|
|
|
jsasm_module_output = voutput;
|
2018-03-02 05:15:33 +00:00
|
|
|
}
|
2018-02-18 05:12:09 +00:00
|
|
|
var result = asm.assembleFile(asmcode);
|
2018-03-03 03:39:32 +00:00
|
|
|
if (loaded_module && jsasm_module_output) {
|
2018-12-15 18:14:40 +00:00
|
|
|
// errors? return them
|
|
|
|
if (jsasm_module_output.errors && jsasm_module_output.errors.length)
|
|
|
|
return jsasm_module_output;
|
|
|
|
// return program ROM array
|
2018-03-02 05:15:33 +00:00
|
|
|
var asmout = result.output;
|
2018-06-28 00:26:22 +00:00
|
|
|
// TODO: unify
|
2018-03-03 02:41:56 +00:00
|
|
|
result.output = jsasm_module_output.output;
|
2018-03-02 05:15:33 +00:00
|
|
|
result.output.program_rom = asmout;
|
|
|
|
// cpu_platform__DOT__program_rom
|
2018-03-03 02:41:56 +00:00
|
|
|
result.output.program_rom_variable = jsasm_module_top + "__DOT__program_rom";
|
2018-07-31 18:41:27 +00:00
|
|
|
result.listings = {};
|
|
|
|
result.listings[options.path] = {lines:result.lines};
|
2018-03-02 05:15:33 +00:00
|
|
|
}
|
2018-02-18 05:12:09 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function compileJSASMStep(step:BuildStep) {
|
2018-12-15 18:14:40 +00:00
|
|
|
gatherFiles(step);
|
|
|
|
var code = getWorkFileAsString(step.path);
|
2018-06-28 00:26:22 +00:00
|
|
|
var platform = step.platform || 'verilog';
|
2018-12-15 18:14:40 +00:00
|
|
|
return compileJSASM(code, platform, step, false);
|
2018-06-28 00:26:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function compileInlineASM(code:string, platform, options, errors, asmlines) {
|
2018-02-18 05:12:09 +00:00
|
|
|
code = code.replace(/__asm\b([\s\S]+?)\b__endasm\b/g, function(s,asmcode,index) {
|
|
|
|
var firstline = code.substr(0,index).match(/\n/g).length;
|
2018-03-02 05:15:33 +00:00
|
|
|
var asmout = compileJSASM(asmcode, platform, options, true);
|
2018-02-15 00:26:40 +00:00
|
|
|
if (asmout.errors && asmout.errors.length) {
|
2018-02-21 19:32:11 +00:00
|
|
|
for (var i=0; i<asmout.errors.length; i++) {
|
|
|
|
asmout.errors[i].line += firstline;
|
|
|
|
errors.push(asmout.errors[i]);
|
|
|
|
}
|
2018-02-15 00:26:40 +00:00
|
|
|
return "";
|
|
|
|
} else if (asmout.output) {
|
2018-10-05 13:47:15 +00:00
|
|
|
let s = "";
|
2018-02-15 00:26:40 +00:00
|
|
|
var out = asmout.output;
|
|
|
|
for (var i=0; i<out.length; i++) {
|
|
|
|
if (i>0) s += ",";
|
2018-02-18 05:12:09 +00:00
|
|
|
s += 0|out[i];
|
2018-02-15 00:26:40 +00:00
|
|
|
}
|
2018-02-28 03:35:42 +00:00
|
|
|
if (asmlines) {
|
2018-03-02 05:15:33 +00:00
|
|
|
var al = asmout.lines;
|
2018-02-28 03:35:42 +00:00
|
|
|
for (var i=0; i<al.length; i++) {
|
|
|
|
al[i].line += firstline;
|
|
|
|
asmlines.push(al[i]);
|
|
|
|
}
|
|
|
|
}
|
2018-02-15 00:26:40 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
});
|
2018-02-21 19:32:11 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function compileVerilator(step:BuildStep) {
|
2018-02-21 19:32:11 +00:00
|
|
|
loadNative("verilator_bin");
|
2018-07-11 04:04:28 +00:00
|
|
|
loadGen("worker/verilator2js");
|
2018-06-25 16:02:06 +00:00
|
|
|
var platform = step.platform || 'verilog';
|
2018-02-21 19:32:11 +00:00
|
|
|
var errors = [];
|
|
|
|
var asmlines = [];
|
2018-12-15 18:14:40 +00:00
|
|
|
gatherFiles(step);
|
|
|
|
// compile verilog if files are stale
|
|
|
|
var outjs = "main.js";
|
|
|
|
if (staleFiles(step, [outjs])) {
|
|
|
|
var match_fn = makeErrorMatcher(errors, /%(.+?): (.+?):(\d+)?[:]?\s*(.+)/i, 3, 4, step.path, 2);
|
|
|
|
var verilator_mod = emglobal.verilator_bin({
|
|
|
|
instantiateWasm: moduleInstFn('verilator_bin'),
|
|
|
|
noInitialRun:true,
|
|
|
|
print:print_fn,
|
|
|
|
printErr:match_fn,
|
|
|
|
TOTAL_MEMORY:256*1024*1024,
|
|
|
|
});
|
|
|
|
var code = getWorkFileAsString(step.path);
|
|
|
|
var topmod = detectTopModuleName(code);
|
|
|
|
var FS = verilator_mod['FS'];
|
|
|
|
populateFiles(step, FS, {
|
|
|
|
mainFilePath:step.path,
|
|
|
|
processFn:(code) => {
|
|
|
|
return compileInlineASM(code, platform, step, errors, asmlines);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
starttime();
|
|
|
|
try {
|
|
|
|
var args = ["--cc", "-O3", "-DEXT_INLINE_ASM", "-DTOPMOD__"+topmod,
|
|
|
|
"-Wall", "-Wno-DECLFILENAME", "-Wno-UNUSED", '--report-unoptflat',
|
|
|
|
"--x-assign", "fast", "--noassert", "--pins-bv", "33",
|
|
|
|
"--top-module", topmod, step.path]
|
|
|
|
verilator_mod.callMain(args);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
errors.push({line:0,msg:"Compiler internal error: " + e});
|
|
|
|
}
|
|
|
|
endtime("compile");
|
|
|
|
// remove boring errors
|
|
|
|
errors = errors.filter(function(e) { return !/Exiting due to \d+/.exec(e.msg); }, errors);
|
|
|
|
errors = errors.filter(function(e) { return !/Use ["][/][*]/.exec(e.msg); }, errors);
|
|
|
|
if (errors.length) {
|
|
|
|
return {errors:errors};
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
var h_file = FS.readFile("obj_dir/V"+topmod+".h", {encoding:'utf8'});
|
|
|
|
var cpp_file = FS.readFile("obj_dir/V"+topmod+".cpp", {encoding:'utf8'});
|
|
|
|
var rtn = translateVerilatorOutputToJS(h_file, cpp_file);
|
|
|
|
putWorkFile(outjs, rtn.output.code);
|
|
|
|
if (!anyTargetChanged(step, [outjs]))
|
|
|
|
return;
|
|
|
|
} catch(e) {
|
|
|
|
console.log(e);
|
2018-12-30 19:06:18 +00:00
|
|
|
errors.push({line:0,msg:""+e});
|
2018-12-15 18:14:40 +00:00
|
|
|
return {errors:errors};
|
|
|
|
}
|
2018-10-05 13:47:15 +00:00
|
|
|
//rtn.intermediate = {listing:h_file + cpp_file}; // TODO
|
|
|
|
var listings = {};
|
2018-06-28 00:26:22 +00:00
|
|
|
// TODO: what if found in non-top-module?
|
|
|
|
if (asmlines.length)
|
2018-10-05 13:47:15 +00:00
|
|
|
listings[step.path] = {lines:asmlines};
|
|
|
|
return {
|
|
|
|
output: rtn.output,
|
|
|
|
errors: errors,
|
2018-10-05 18:02:46 +00:00
|
|
|
listings: listings,
|
2018-10-05 13:47:15 +00:00
|
|
|
};
|
2017-11-11 19:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 00:26:22 +00:00
|
|
|
// TODO: test
|
2018-10-05 13:47:15 +00:00
|
|
|
function compileYosys(step:BuildStep) {
|
2017-11-20 01:32:58 +00:00
|
|
|
loadNative("yosys");
|
2018-06-28 00:26:22 +00:00
|
|
|
var code = step.code;
|
2017-11-20 01:32:58 +00:00
|
|
|
var errors = [];
|
2018-10-05 13:47:15 +00:00
|
|
|
var match_fn = makeErrorMatcher(errors, /ERROR: (.+?) in line (.+?[.]v):(\d+)[: ]+(.+)/i, 3, 4, step.path);
|
2017-11-20 01:32:58 +00:00
|
|
|
starttime();
|
2018-10-05 13:47:15 +00:00
|
|
|
var yosys_mod = emglobal.yosys({
|
2018-07-10 04:44:17 +00:00
|
|
|
instantiateWasm: moduleInstFn('yosys'),
|
2017-11-20 01:32:58 +00:00
|
|
|
noInitialRun:true,
|
|
|
|
print:print_fn,
|
|
|
|
printErr:match_fn,
|
|
|
|
});
|
|
|
|
endtime("create module");
|
|
|
|
var topmod = detectTopModuleName(code);
|
|
|
|
var FS = yosys_mod['FS'];
|
|
|
|
FS.writeFile(topmod+".v", code);
|
|
|
|
starttime();
|
2017-11-29 01:48:27 +00:00
|
|
|
try {
|
|
|
|
yosys_mod.callMain(["-q", "-o", topmod+".json", "-S", topmod+".v"]);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
endtime("compile");
|
|
|
|
return {errors:errors};
|
|
|
|
}
|
2017-11-20 01:32:58 +00:00
|
|
|
endtime("compile");
|
2018-02-03 20:20:56 +00:00
|
|
|
//TODO: filename in errors
|
2017-11-20 01:32:58 +00:00
|
|
|
if (errors.length) return {errors:errors};
|
|
|
|
try {
|
|
|
|
var json_file = FS.readFile(topmod+".json", {encoding:'utf8'});
|
|
|
|
var json = JSON.parse(json_file);
|
|
|
|
console.log(json);
|
2018-06-28 00:26:22 +00:00
|
|
|
return {yosys_json:json, errors:errors}; // TODO
|
2017-11-20 01:32:58 +00:00
|
|
|
} catch(e) {
|
|
|
|
console.log(e);
|
|
|
|
return {errors:errors};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function assembleZMAC(step:BuildStep) {
|
2018-08-28 14:10:59 +00:00
|
|
|
loadNative("zmac");
|
2018-09-27 18:26:42 +00:00
|
|
|
var hexout, lstout, binout;
|
2018-08-28 14:10:59 +00:00
|
|
|
var errors = [];
|
2018-08-28 17:59:12 +00:00
|
|
|
var params = step.params;
|
2018-08-28 14:10:59 +00:00
|
|
|
gatherFiles(step, {mainFilePath:"main.asm"});
|
2018-08-28 17:59:12 +00:00
|
|
|
var lstpath = step.prefix + ".lst";
|
2018-09-27 18:26:42 +00:00
|
|
|
var binpath = step.prefix + ".cim";
|
2018-10-01 20:18:59 +00:00
|
|
|
if (staleFiles(step, [binpath, lstpath])) {
|
2018-08-28 14:10:59 +00:00
|
|
|
/*
|
|
|
|
error1.asm(4) : 'l18d4' Undeclared
|
|
|
|
JP L18D4
|
|
|
|
|
|
|
|
error1.asm(11): warning: 'foobar' treated as label (instruction typo?)
|
|
|
|
Add a colon or move to first column to stop this warning.
|
|
|
|
1 errors (see listing if no diagnostics appeared here)
|
|
|
|
*/
|
2018-10-05 13:47:15 +00:00
|
|
|
var ZMAC = emglobal.zmac({
|
2018-08-28 14:10:59 +00:00
|
|
|
instantiateWasm: moduleInstFn('zmac'),
|
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
|
|
|
print:print_fn,
|
|
|
|
printErr:makeErrorMatcher(errors, /([^( ]+)\s*[(](\d+)[)]\s*:\s*(.+)/, 2, 3, step.path),
|
|
|
|
});
|
|
|
|
var FS = ZMAC['FS'];
|
|
|
|
populateFiles(step, FS);
|
2018-08-28 17:59:12 +00:00
|
|
|
// TODO: don't know why CIM (hexary) doesn't work
|
2018-09-27 18:26:42 +00:00
|
|
|
execMain(step, ZMAC, ['-z', '-c', '--oo', 'lst,cim', step.path]);
|
2018-08-28 14:10:59 +00:00
|
|
|
if (errors.length) {
|
|
|
|
return {errors:errors};
|
|
|
|
}
|
2018-08-28 17:59:12 +00:00
|
|
|
lstout = FS.readFile("zout/"+lstpath, {encoding:'utf8'});
|
2018-09-27 18:26:42 +00:00
|
|
|
binout = FS.readFile("zout/"+binpath, {encoding:'binary'});
|
|
|
|
putWorkFile(binpath, binout);
|
2018-08-28 14:10:59 +00:00
|
|
|
putWorkFile(lstpath, lstout);
|
2018-09-27 18:26:42 +00:00
|
|
|
if (!anyTargetChanged(step, [binpath, lstpath]))
|
2018-08-28 17:59:12 +00:00
|
|
|
return;
|
|
|
|
// 230: 1739+7+x 017A 1600 L017A: LD D,00h
|
2018-09-03 13:37:17 +00:00
|
|
|
var lines = parseListing(lstout, /\s*(\d+):\s*([0-9a-f]+)\s+([0-9a-f]+)\s+(.+)/i, 1, 2, 3);
|
2018-08-28 14:10:59 +00:00
|
|
|
var listings = {};
|
2018-08-28 17:59:12 +00:00
|
|
|
listings[lstpath] = {lines:lines};
|
|
|
|
// parse symbol table
|
|
|
|
var symbolmap = {};
|
|
|
|
var sympos = lstout.indexOf('Symbol Table:');
|
|
|
|
if (sympos > 0) {
|
|
|
|
var symout = lstout.slice(sympos+14);
|
|
|
|
symout.split('\n').forEach(function(l) {
|
|
|
|
var m = l.match(/(\S+)\s+([= ]*)([0-9a-f]+)/i);
|
|
|
|
if (m) {
|
|
|
|
symbolmap[m[1]] = parseInt(m[3],16);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-08-28 14:10:59 +00:00
|
|
|
return {
|
2018-09-27 18:26:42 +00:00
|
|
|
output:binout,
|
2018-08-28 14:10:59 +00:00
|
|
|
listings:listings,
|
|
|
|
errors:errors,
|
2018-08-28 17:59:12 +00:00
|
|
|
symbolmap:symbolmap
|
2018-08-28 14:10:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 19:10:04 +00:00
|
|
|
function preprocessBatariBasic(code:string) : string {
|
|
|
|
load("bbpreprocess");
|
|
|
|
var bbout = "";
|
|
|
|
function addbbout_fn(s) {
|
|
|
|
bbout += s;
|
|
|
|
bbout += "\n";
|
|
|
|
}
|
|
|
|
var BBPRE = emglobal.preprocess({
|
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
|
|
|
print:addbbout_fn,
|
|
|
|
printErr:print_fn,
|
|
|
|
noFSInit:true,
|
|
|
|
});
|
|
|
|
var FS = BBPRE['FS'];
|
|
|
|
setupStdin(FS, code);
|
|
|
|
BBPRE.callMain([]);
|
|
|
|
console.log("preprocess " + code.length + " -> " + bbout.length + " bytes");
|
|
|
|
return bbout;
|
|
|
|
}
|
|
|
|
|
2018-11-20 17:31:19 +00:00
|
|
|
function compileBatariBasic(step:BuildStep) {
|
|
|
|
load("bb2600basic");
|
|
|
|
var params = step.params;
|
|
|
|
// stdout
|
|
|
|
var asmout = "";
|
|
|
|
function addasmout_fn(s) {
|
|
|
|
asmout += s;
|
|
|
|
asmout += "\n";
|
|
|
|
}
|
|
|
|
// stderr
|
|
|
|
var re_err1 = /[(](\d+)[)]:?\s*(.+)/;
|
|
|
|
var errors = [];
|
|
|
|
var errline = 0;
|
|
|
|
function match_fn(s) {
|
|
|
|
console.log(s);
|
|
|
|
var matches = re_err1.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
errline = parseInt(matches[1]);
|
|
|
|
errors.push({
|
|
|
|
line:errline,
|
|
|
|
msg:matches[2]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gatherFiles(step, {mainFilePath:"main.bas"});
|
|
|
|
var destpath = step.prefix + '.asm';
|
|
|
|
if (staleFiles(step, [destpath])) {
|
|
|
|
var BB = emglobal.bb2600basic({
|
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
|
|
|
print:addasmout_fn,
|
|
|
|
printErr:match_fn,
|
|
|
|
noFSInit:true,
|
2018-11-20 19:39:33 +00:00
|
|
|
TOTAL_MEMORY:64*1024*1024,
|
2018-11-20 17:31:19 +00:00
|
|
|
});
|
|
|
|
var FS = BB['FS'];
|
|
|
|
populateFiles(step, FS);
|
2018-11-20 19:10:04 +00:00
|
|
|
// preprocess, pipe file to stdin
|
2018-11-28 16:10:24 +00:00
|
|
|
var code = getWorkFileAsString(step.path);
|
2018-11-20 19:10:04 +00:00
|
|
|
code = preprocessBatariBasic(code);
|
2018-11-20 17:31:19 +00:00
|
|
|
setupStdin(FS, code);
|
|
|
|
setupFS(FS, '2600basic');
|
|
|
|
execMain(step, BB, ["-i", "/share", step.path]);
|
|
|
|
if (errors.length)
|
|
|
|
return {errors:errors};
|
|
|
|
// build final assembly output from include file list
|
|
|
|
var includesout = FS.readFile("includes.bB", {encoding:'utf8'});
|
|
|
|
var redefsout = FS.readFile("2600basic_variable_redefs.h", {encoding:'utf8'});
|
|
|
|
var includes = includesout.trim().split("\n");
|
|
|
|
var combinedasm = "";
|
2018-11-20 19:10:04 +00:00
|
|
|
var splitasm = asmout.split("bB.asm file is split here");
|
2018-11-20 17:31:19 +00:00
|
|
|
for (var incfile of includes) {
|
2018-11-20 19:10:04 +00:00
|
|
|
var inctext;
|
|
|
|
if (incfile=="bB.asm")
|
|
|
|
inctext = splitasm[0];
|
|
|
|
else if (incfile=="bB2.asm")
|
|
|
|
inctext = splitasm[1];
|
|
|
|
else
|
|
|
|
inctext = FS.readFile("/share/includes/"+incfile, {encoding:'utf8'});
|
2018-11-20 17:31:19 +00:00
|
|
|
console.log(incfile, inctext.length);
|
|
|
|
combinedasm += "\n\n;;;" + incfile + "\n\n";
|
|
|
|
combinedasm += inctext;
|
|
|
|
}
|
|
|
|
// TODO: ; bB.asm file is split here
|
|
|
|
putWorkFile(destpath, combinedasm);
|
|
|
|
putWorkFile("2600basic.h", FS.readFile("/share/includes/2600basic.h"));
|
|
|
|
putWorkFile("2600basic_variable_redefs.h", redefsout);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
nexttool:"dasm",
|
|
|
|
path:destpath,
|
|
|
|
args:[destpath],
|
2018-11-21 12:21:07 +00:00
|
|
|
files:[destpath, "2600basic.h", "2600basic_variable_redefs.h"],
|
|
|
|
bblines:true,
|
2018-11-20 17:31:19 +00:00
|
|
|
};
|
|
|
|
}
|
2018-08-28 14:10:59 +00:00
|
|
|
|
2018-11-21 16:53:33 +00:00
|
|
|
function setupRequireFunction() {
|
|
|
|
var exports = {};
|
|
|
|
exports['jsdom'] = {
|
|
|
|
JSDOM: function(a,b) {
|
|
|
|
this.window = {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
emglobal['require'] = (modname:string) => {
|
|
|
|
console.log('require',modname);
|
|
|
|
return exports[modname];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function translateShowdown(step:BuildStep) {
|
|
|
|
setupRequireFunction();
|
|
|
|
load("showdown.min");
|
|
|
|
var showdown = emglobal['showdown'];
|
|
|
|
var converter = new showdown.Converter({
|
|
|
|
tables:'true',
|
|
|
|
smoothLivePreview:'true',
|
|
|
|
requireSpaceBeforeHeadingText:'true',
|
|
|
|
emoji:'true',
|
|
|
|
});
|
2018-11-28 16:10:24 +00:00
|
|
|
var code = getWorkFileAsString(step.path);
|
2018-11-21 16:53:33 +00:00
|
|
|
var html = converter.makeHtml(code);
|
|
|
|
delete emglobal['require'];
|
|
|
|
return {
|
|
|
|
output:html
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-28 14:10:59 +00:00
|
|
|
////////////////////////////
|
|
|
|
|
2017-01-15 03:46:12 +00:00
|
|
|
var TOOLS = {
|
2017-01-04 21:07:59 +00:00
|
|
|
'dasm': assembleDASM,
|
2018-06-28 00:26:22 +00:00
|
|
|
|
|
|
|
//'acme': assembleACME,
|
|
|
|
//'plasm': compilePLASMA,
|
2017-01-06 00:14:12 +00:00
|
|
|
'cc65': compileCC65,
|
2018-06-25 04:52:40 +00:00
|
|
|
'ca65': assembleCA65,
|
|
|
|
'ld65': linkLD65,
|
2018-06-28 00:26:22 +00:00
|
|
|
//'z80asm': assembleZ80ASM,
|
|
|
|
//'sccz80': compileSCCZ80,
|
2018-06-25 04:52:40 +00:00
|
|
|
'sdasz80': assembleSDASZ80,
|
|
|
|
'sdldz80': linkSDLDZ80,
|
2017-01-13 02:21:35 +00:00
|
|
|
'sdcc': compileSDCC,
|
2018-06-25 04:52:40 +00:00
|
|
|
//'xasm6809': assembleXASM6809,
|
|
|
|
//'naken': assembleNAKEN,
|
2017-11-11 19:45:32 +00:00
|
|
|
'verilator': compileVerilator,
|
2017-11-20 01:32:58 +00:00
|
|
|
'yosys': compileYosys,
|
2018-06-25 04:52:40 +00:00
|
|
|
//'caspr': compileCASPR,
|
2018-06-28 00:26:22 +00:00
|
|
|
'jsasm': compileJSASMStep,
|
2018-08-28 14:10:59 +00:00
|
|
|
'zmac': assembleZMAC,
|
2018-11-20 17:31:19 +00:00
|
|
|
'bataribasic': compileBatariBasic,
|
2018-11-21 16:53:33 +00:00
|
|
|
'markdown': translateShowdown,
|
2017-01-04 21:07:59 +00:00
|
|
|
}
|
2016-12-16 01:21:51 +00:00
|
|
|
|
2017-01-23 21:21:45 +00:00
|
|
|
var TOOL_PRELOADFS = {
|
2018-06-20 07:09:37 +00:00
|
|
|
'cc65-apple2': '65-apple2',
|
|
|
|
'ca65-apple2': '65-apple2',
|
|
|
|
'cc65-c64': '65-c64',
|
|
|
|
'ca65-c64': '65-c64',
|
|
|
|
'cc65-nes': '65-nes',
|
|
|
|
'ca65-nes': '65-nes',
|
|
|
|
'cc65-atari8': '65-atari8',
|
|
|
|
'ca65-atari8': '65-atari8',
|
2017-01-23 21:21:45 +00:00
|
|
|
'sdasz80': 'sdcc',
|
|
|
|
'sdcc': 'sdcc',
|
2018-06-24 05:01:38 +00:00
|
|
|
'sccz80': 'sccz80',
|
2018-11-20 17:31:19 +00:00
|
|
|
'bataribasic': '2600basic',
|
2017-01-23 21:21:45 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 13:47:15 +00:00
|
|
|
function applyDefaultErrorPath(errors:WorkerError[], path:string) {
|
2018-07-03 03:45:08 +00:00
|
|
|
if (!path) return;
|
|
|
|
for (var i=0; i<errors.length; i++) {
|
|
|
|
var err = errors[i];
|
|
|
|
if (!err.path && err.line) err.path = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 14:43:15 +00:00
|
|
|
function executeBuildSteps() {
|
2018-06-28 03:26:23 +00:00
|
|
|
buildstartseq = workerseq;
|
2018-06-25 04:52:40 +00:00
|
|
|
while (buildsteps.length) {
|
|
|
|
var step = buildsteps.shift(); // get top of array
|
|
|
|
var platform = step.platform;
|
|
|
|
var toolfn = TOOLS[step.tool];
|
|
|
|
if (!toolfn) throw "no tool named " + step.tool;
|
|
|
|
step.params = PLATFORM_PARAMS[platform];
|
2018-06-25 06:12:11 +00:00
|
|
|
console.log(step.platform + " " + step.tool);
|
2018-06-25 04:52:40 +00:00
|
|
|
try {
|
|
|
|
step.result = toolfn(step);
|
|
|
|
} catch (e) {
|
2018-06-25 21:51:07 +00:00
|
|
|
console.log("EXCEPTION", e.stack);
|
2018-07-03 03:45:08 +00:00
|
|
|
return {errors:[{line:0, msg:e+""}]}; // TODO: catch errors already generated?
|
2018-06-25 04:52:40 +00:00
|
|
|
}
|
|
|
|
if (step.result) {
|
2018-09-25 23:46:24 +00:00
|
|
|
step.result.params = step.params;
|
2018-06-25 04:52:40 +00:00
|
|
|
// errors? return them
|
2018-09-25 23:46:24 +00:00
|
|
|
if (step.result.errors && step.result.errors.length) {
|
2018-07-03 03:45:08 +00:00
|
|
|
applyDefaultErrorPath(step.result.errors, step.path);
|
2018-06-25 04:52:40 +00:00
|
|
|
return step.result;
|
|
|
|
}
|
|
|
|
// if we got some output, return it immediately
|
|
|
|
if (step.result.output) {
|
|
|
|
return step.result;
|
|
|
|
}
|
|
|
|
// combine files with a link tool?
|
|
|
|
if (step.result.linktool) {
|
|
|
|
var linkstep = {
|
|
|
|
tool:step.result.linktool,
|
|
|
|
platform:platform,
|
|
|
|
files:step.result.files,
|
|
|
|
args:step.result.args
|
|
|
|
};
|
|
|
|
step.generated = linkstep.files;
|
|
|
|
// find previous link step to combine
|
|
|
|
for (var i=0; i<buildsteps.length; i++) {
|
|
|
|
var ls = buildsteps[i];
|
2018-09-21 12:39:15 +00:00
|
|
|
if (ls.tool == linkstep.tool && ls.platform == linkstep.platform && ls.files && ls.args) {
|
2018-06-25 04:52:40 +00:00
|
|
|
ls.files = ls.files.concat(linkstep.files);
|
|
|
|
ls.args = ls.args.concat(linkstep.args);
|
|
|
|
linkstep = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (linkstep) buildsteps.push(linkstep);
|
2018-06-25 21:51:07 +00:00
|
|
|
}
|
|
|
|
// process with another tool?
|
2018-06-25 04:52:40 +00:00
|
|
|
if (step.result.nexttool) {
|
2018-11-21 12:21:07 +00:00
|
|
|
var asmstep = step.result;
|
|
|
|
asmstep.tool = step.result.nexttool;
|
|
|
|
asmstep.platform = platform;
|
2018-09-21 12:39:15 +00:00
|
|
|
buildsteps.push(asmstep); // TODO: unshift changes order
|
2018-06-25 04:52:40 +00:00
|
|
|
step.generated = asmstep.files;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 13:33:40 +00:00
|
|
|
function handleMessage(data : WorkerMessage) : WorkerResult {
|
2018-06-25 14:43:15 +00:00
|
|
|
// preload file system
|
2018-03-03 02:16:25 +00:00
|
|
|
if (data.preload) {
|
|
|
|
var fs = TOOL_PRELOADFS[data.preload];
|
2018-06-20 07:09:37 +00:00
|
|
|
if (!fs && data.platform)
|
|
|
|
fs = TOOL_PRELOADFS[data.preload+'-'+data.platform.split('-')[0]];
|
|
|
|
if (fs && !fsMeta[fs])
|
|
|
|
loadFilesystem(fs);
|
2017-01-23 21:21:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-06-25 21:51:07 +00:00
|
|
|
// clear filesystem? (TODO: buildkey)
|
|
|
|
if (data.reset) {
|
|
|
|
workfs = {};
|
|
|
|
return;
|
|
|
|
}
|
2018-06-25 14:43:15 +00:00
|
|
|
buildsteps = [];
|
|
|
|
// file updates
|
|
|
|
if (data.updates) {
|
|
|
|
for (var i=0; i<data.updates.length; i++) {
|
|
|
|
var u = data.updates[i];
|
|
|
|
putWorkFile(u.path, u.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// build steps
|
|
|
|
if (data.buildsteps) {
|
|
|
|
buildsteps.push.apply(buildsteps, data.buildsteps);
|
|
|
|
}
|
|
|
|
// single-file
|
|
|
|
if (data.code) {
|
|
|
|
buildsteps.push(data);
|
|
|
|
}
|
|
|
|
// execute build steps
|
|
|
|
if (buildsteps.length) {
|
|
|
|
var result = executeBuildSteps();
|
|
|
|
return result ? result : {unchanged:true};
|
|
|
|
}
|
2018-06-25 04:52:40 +00:00
|
|
|
// TODO: cache results
|
|
|
|
// message not recognized
|
|
|
|
console.log("Unknown message",data);
|
2018-03-03 02:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ENVIRONMENT_IS_WORKER) {
|
|
|
|
onmessage = function(e) {
|
|
|
|
var result = handleMessage(e.data);
|
|
|
|
if (result) {
|
|
|
|
postMessage(result);
|
|
|
|
}
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
2016-12-16 01:21:51 +00:00
|
|
|
}
|