2017-11-22 14:42:07 +00:00
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var fs = require('fs');
|
|
|
|
var wtu = require('./workertestutils.js');
|
|
|
|
|
2019-10-26 01:55:50 +00:00
|
|
|
var emu = require('gen/common/emu.js');
|
2018-08-16 23:19:20 +00:00
|
|
|
var verilog = require('gen/platform/verilog.js');
|
|
|
|
var VerilogPlatform = emu.PLATFORMS['verilog'];
|
|
|
|
|
|
|
|
Object.assign(global, verilog); // copy global VL_* properties
|
2017-11-22 14:42:07 +00:00
|
|
|
|
2018-10-11 15:08:15 +00:00
|
|
|
// TODO: must define $
|
|
|
|
|
2017-11-22 14:42:07 +00:00
|
|
|
function loadPlatform(msg) {
|
|
|
|
var platform = new VerilogPlatform();
|
2018-10-11 15:08:15 +00:00
|
|
|
platform.resume = function() { }; // prevent resume after reset
|
2017-11-22 14:42:07 +00:00
|
|
|
try {
|
2018-07-24 15:38:56 +00:00
|
|
|
//console.log(msg.output.ports);
|
|
|
|
//console.log(msg.output.signals);
|
2017-11-22 14:42:07 +00:00
|
|
|
platform.loadROM("ROM", msg.output);
|
2018-08-29 12:24:13 +00:00
|
|
|
platform.loadROM("ROM", msg.output);
|
|
|
|
platform.loadROM("ROM", msg.output);
|
|
|
|
verilog.vl_finished = verilog.vl_stopped = false;
|
|
|
|
for (var i=0; i<10000 && !(verilog.vl_finished||verilog.vl_stopped); i++) {
|
2017-11-22 14:42:07 +00:00
|
|
|
platform.tick();
|
2018-08-29 12:24:13 +00:00
|
|
|
}
|
|
|
|
assert.ok(!verilog.vl_stopped);
|
|
|
|
var state = platform.saveState();
|
|
|
|
platform.reset();
|
|
|
|
platform.loadState(state);
|
|
|
|
assert.deepEqual(state, platform.saveState());
|
2017-11-22 14:42:07 +00:00
|
|
|
} catch (e) {
|
|
|
|
//platform.printErrorCodeContext(e, msg.output.code);
|
2018-10-11 15:08:15 +00:00
|
|
|
//console.log(msg.intermediate.listing);
|
2017-11-22 14:42:07 +00:00
|
|
|
console.log(msg.output.code);
|
|
|
|
console.log(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return platform;
|
|
|
|
}
|
|
|
|
|
2018-08-29 12:24:13 +00:00
|
|
|
function testPerf(msg) {
|
|
|
|
var platform = new VerilogPlatform();
|
|
|
|
platform.loadROM("ROM", msg.output);
|
|
|
|
var niters = 2000000;
|
|
|
|
|
|
|
|
console.time("before");
|
|
|
|
for (var i=0; i<niters; i++)
|
|
|
|
platform.tick();
|
|
|
|
console.timeEnd("before");
|
|
|
|
|
|
|
|
var state = platform.saveState();
|
|
|
|
platform.reset();
|
|
|
|
platform.loadState(state);
|
|
|
|
console.time("after");
|
|
|
|
for (var i=0; i<niters; i++)
|
|
|
|
platform.tick();
|
|
|
|
console.timeEnd("after");
|
|
|
|
|
|
|
|
return platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
function compileVerilator(filename, code, callback, nerrors) {
|
2017-11-22 14:42:07 +00:00
|
|
|
global.postMessage = function(msg) {
|
|
|
|
if (msg.errors && msg.errors.length) {
|
|
|
|
console.log(msg.errors);
|
|
|
|
assert.equal(nerrors||0, msg.errors.length, "errors");
|
|
|
|
} else {
|
|
|
|
assert.equal(nerrors||0, 0, "errors");
|
|
|
|
loadPlatform(msg);
|
2018-08-29 12:24:13 +00:00
|
|
|
//testPerf(msg);
|
|
|
|
if (filename.indexOf('t_') >= 0) {
|
|
|
|
//assert.ok(verilog.vl_finished);
|
|
|
|
}
|
2017-11-22 14:42:07 +00:00
|
|
|
}
|
|
|
|
callback(null, msg);
|
|
|
|
};
|
|
|
|
global.onmessage({
|
2018-07-10 01:58:24 +00:00
|
|
|
data:{code:code, platform:'verilog', tool:'verilator', path:'main.v'}
|
2017-11-22 14:42:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testVerilator(filename, disables, nerrors) {
|
|
|
|
it('should translate '+filename, function(done) {
|
|
|
|
var csource = ab2str(fs.readFileSync(filename));
|
|
|
|
for (var i=0; i<(disables||[]).length; i++)
|
|
|
|
csource = "/* verilator lint_off " + disables[i] + " */\n" + csource;
|
2018-08-29 12:24:13 +00:00
|
|
|
compileVerilator(filename, csource, done, nerrors||0);
|
2017-11-22 14:42:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Verilog Worker', function() {
|
2017-11-22 23:23:00 +00:00
|
|
|
|
2017-11-24 02:54:51 +00:00
|
|
|
testVerilator('presets/verilog/hvsync_generator.v');
|
|
|
|
testVerilator('presets/verilog/lfsr.v');
|
2018-07-24 15:38:56 +00:00
|
|
|
testVerilator('presets/verilog/ram.v');
|
2017-11-24 02:54:51 +00:00
|
|
|
// TODO: how to include files?
|
|
|
|
|
2017-11-28 02:08:19 +00:00
|
|
|
//testVerilator('test/cli/verilog/t_tri_gate.v');
|
|
|
|
testVerilator('test/cli/verilog/t_tri_gen.v', ['UNDRIVEN']);
|
|
|
|
testVerilator('test/cli/verilog/t_tri_graph.v', ['UNDRIVEN']);
|
|
|
|
testVerilator('test/cli/verilog/t_tri_ifbegin.v', ['UNDRIVEN']);
|
|
|
|
testVerilator('test/cli/verilog/t_tri_inout.v');
|
|
|
|
testVerilator('test/cli/verilog/t_tri_inout2.v');
|
|
|
|
testVerilator('test/cli/verilog/t_tri_pullup.v', ['UNDRIVEN']);
|
|
|
|
testVerilator('test/cli/verilog/t_tri_select_unsized.v', ['WIDTH']);
|
|
|
|
testVerilator('test/cli/verilog/t_tri_unconn.v', ['PINCONNECTEMPTY']);
|
|
|
|
testVerilator('test/cli/verilog/t_tri_various.v', ['UNDRIVEN']);
|
|
|
|
|
2017-11-22 23:23:00 +00:00
|
|
|
/* TODO: fix tests
|
|
|
|
testVerilator('test/cli/verilog/t_order_doubleloop.v', ['BLKSEQ']);
|
|
|
|
testVerilator('test/cli/verilog/t_alw_combdly.v');
|
|
|
|
testVerilator('test/cli/verilog/t_math_const.v', ['BLKSEQ']);
|
|
|
|
testVerilator('test/cli/verilog/t_clk_gen.v', ['BLKSEQ']);
|
|
|
|
testVerilator('test/cli/verilog/t_clk_first.v', ['UNDRIVEN','SYNCASYNCNET']);
|
|
|
|
testVerilator('test/cli/verilog/t_clk_2in.v', ['BLKSEQ']);
|
2017-11-24 02:54:51 +00:00
|
|
|
testVerilator('test/cli/verilog/t_order_comboclkloop.v');
|
2017-11-22 23:23:00 +00:00
|
|
|
*/
|
2017-11-22 21:31:30 +00:00
|
|
|
testVerilator('test/cli/verilog/t_gen_alw.v');
|
|
|
|
testVerilator('test/cli/verilog/t_case_huge_sub3.v');
|
|
|
|
|
|
|
|
//testVerilator('test/cli/verilog/t_order.v');
|
|
|
|
//testVerilator('test/cli/verilog/t_order_2d.v');
|
|
|
|
//testVerilator('test/cli/verilog/t_order_a.v');
|
|
|
|
//testVerilator('test/cli/verilog/t_order_b.v');
|
|
|
|
//testVerilator('test/cli/verilog/t_order_clkinst.v');
|
|
|
|
//testVerilator('test/cli/verilog/t_order_comboloop.v', ['BLKSEQ']);
|
|
|
|
testVerilator('test/cli/verilog/t_order_first.v');
|
2018-12-30 19:06:18 +00:00
|
|
|
//testVerilator('test/cli/verilog/t_order_loop_bad.v', ['BLKSEQ'], 10);
|
2017-11-22 21:31:30 +00:00
|
|
|
testVerilator('test/cli/verilog/t_order_multialways.v');
|
|
|
|
testVerilator('test/cli/verilog/t_order_multidriven.v', ['UNDRIVEN']);
|
|
|
|
//testVerilator('test/cli/verilog/t_order_quad.v');
|
|
|
|
testVerilator('test/cli/verilog/t_order_wireloop.v', ['UNOPT']);
|
|
|
|
|
2017-11-22 14:42:07 +00:00
|
|
|
testVerilator('test/cli/verilog/t_mem.v');
|
|
|
|
|
|
|
|
testVerilator('test/cli/verilog/t_alw_dly.v', ['BLKSEQ']);
|
|
|
|
testVerilator('test/cli/verilog/t_alw_split.v', ['BLKSEQ']);
|
|
|
|
testVerilator('test/cli/verilog/t_alw_splitord.v', ['BLKSEQ']);
|
|
|
|
|
|
|
|
testVerilator('test/cli/verilog/t_array_compare.v');
|
|
|
|
|
|
|
|
testVerilator('test/cli/verilog/t_math_arith.v', ['BLKSEQ']);
|
|
|
|
//testVerilator('test/cli/verilog/t_math_div.v');
|
|
|
|
testVerilator('test/cli/verilog/t_math_div0.v');
|
|
|
|
|
|
|
|
testVerilator('test/cli/verilog/t_clk_powerdn.v', ['BLKSEQ','SYNCASYNCNET']);
|
|
|
|
//testVerilator('test/cli/verilog/t_clk_latchgate.v', ['BLKSEQ']);
|
|
|
|
//testVerilator('test/cli/verilog/t_clk_latch.v');
|
|
|
|
//testVerilator('test/cli/verilog/t_clk_gater.v', ['BLKSEQ']);
|
|
|
|
testVerilator('test/cli/verilog/t_clk_dsp.v');
|
|
|
|
testVerilator('test/cli/verilog/t_clk_dpulse.v');
|
|
|
|
testVerilator('test/cli/verilog/t_clk_condflop_nord.v');
|
|
|
|
testVerilator('test/cli/verilog/t_clk_condflop.v', ['BLKSEQ']);
|
|
|
|
|
|
|
|
testVerilator('presets/verilog/hvsync_generator.v');
|
|
|
|
/*
|
|
|
|
it('should compile verilog example', function(done) {
|
|
|
|
var csource = ab2str(fs.readFileSync('presets/verilog/hvsync_generator.v'));
|
|
|
|
compileVerilator(csource, done);
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
});
|