2 <title>YosysJS Example Application #
02</title>
3 <script type=
"text/javascript" src=
"yosysjs.js"></script>
4 <script src=
"http://wavedrom.com/skins/default.js" type=
"text/javascript"></script>
5 <script src=
"http://wavedrom.com/WaveDrom.js" type=
"text/javascript"></script>
6 <style type=
"text/css">
7 .noedit { color: #
666; }
9 <script id=
"golden_verilog" type=
"text/plain">
10 module ref(input clk, reset, input [
7:
0] A, output reg [
7:
0] Y);
11 always @(posedge clk) begin
15 Y <= ((Y <<
5) + Y) ^ A;
20 <div id=
"popup" style=
"position: fixed; left: 0; top: 0; width:100%; height:100%; text-align:center; z-index: 1000;
21 background-color: rgba(100, 100, 100, 0.5);"><div style=
"width:300px; margin: 200px auto; background-color: #88f;
22 border:3px dashed #000; padding:15px; text-align:center;"><span id=
"popupmsg">Loading...
</span></div>
24 <h1>YosysJS Example Application #
03</h1>
25 <b>Your mission:
</b> Create a behavioral Verilog model for the following circuit:
27 <div id=
"main" style=
"visibility: hidden">
28 <svg id=
"schem" width=
"800"></svg>
30 <pre id=
"code" style=
"width: 800px; border:2px solid #000; padding: 0.5em;"><span class=
"noedit">module top(input clk, reset, input [
7:
0] A, output reg [
7:
0] Y);
31 always @(posedge clock) begin
</span><span class=
"edit" contenteditable=
"true">
32 Y
<= A | {
4{reset}};
33 </span><span class=
"noedit">end
34 endmodule
</span></pre><p/>
35 <input type=
"button" value=
"Check Model" onclick=
"check_model()"> <span id=
"checkmessage"></span>
37 <p id=
"wave"> </p>
39 <script type=
"text/javascript">
40 function on_ys_ready() {
41 ys.write_file('golden.v', document.getElementById('golden_verilog').textContent);
42 ys.run('echo on; read_verilog golden.v; proc;;');
43 ys.run('show -notitle -width -stretch');
44 YosysJS.dot_into_svg(ys.read_file('show.dot'), 'schem');
45 document.getElementById('popup').style.visibility = 'hidden';
46 document.getElementById('popupmsg').textContent = 'Please wait..';
47 document.getElementById('main').style.visibility = 'visible';
49 function check_model() {
51 ys.remove_file('wave.json');
52 ys.write_file('code.v', document.getElementById('code').textContent);
54 ys.run('design -reset; read_verilog code.v; hierarchy -top top; proc; opt; flatten; hierarchy; ' +
55 'read_verilog golden.v; proc; miter -equiv -ignore_gold_x -make_outputs -flatten ref top miter; ' +
56 'hierarchy -top miter; clean -purge; sat -set-init-undef -seq
8 -dump_json wave.json -show-ports ' +
57 '-max_undef -prove trigger
0 miter');
58 w = document.getElementById('wave')
60 w.innerHTML = '
<b><pre>ERROR: ' + ys.errmsg.replace('&', '
&').replace('<', '
<').replace('
>', '
>') + '
</pre></b>';
62 wdata = ys.read_file('wave.json');
64 wdata = JSON.parse(wdata);
65 function wsignal(signame, newname) {
66 for (i =
0; i < wdata[
"signal"].length; i++)
67 if (wdata[
"signal"][i].name == signame) {
69 wdata[
"signal"][i].name = newname;
70 return wdata[
"signal"][i];
76 { name: 'clk', wave: 'P........' },
79 [
"Inputs", wsignal(
"in_reset",
"reset"), wsignal(
"in_A",
"A") ],
81 [
"Y Output", wsignal(
"gold_Y",
"Ref"), wsignal(
"gate_Y",
"UUT") ],
83 "config" : wdata[
"config"]
85 wdata2 = JSON.stringify(wdata2)
86 w.innerHTML = '
<b>The model did not pass verification:
</b><p/>' +
87 '
<script type=
"WaveDrom">' + wdata2 + '<\/script
>';
88 WaveDrom.ProcessAll();
90 w.innerHTML = '
<b>Congratulations! The model did pass verification.
</b><p/>';
93 document.getElementById('popup').style.visibility = 'hidden';
95 document.getElementById('popup').style.visibility = 'visible';
96 window.setTimeout(work,
100);
100 var ys = YosysJS.create('', on_ys_ready);