概要
ビジュアルプログラミングで組み合わせ回路を組み立てて、シュミレーションして、verilogを生成します。
高位合成です。
実は、今の実装では、半加算器、全加算器が高位合成できません。
半加算器の高位合成を実装します。
実装編
成果物
生成したverilog
module x(input A, input B, output Sum, output Carry);
assign Sum = (A ^ B);
assign Carry = (A & B);
endmodule
サンプルコード
function make(s) {
var i;
var j;
var k;
var res = "";
var ins = [];
var outs = [];
var divs = [];
var ass = [];
var json = JSON.parse(s);
var koko = document.getElementById("koko");
for (i = 0; i < json.devices.length; i++)
{
if (json.devices[i].type == "In")
{
ins.push({
id: json.devices[i].id,
label: json.devices[i].label
});
}
}
for (i = 0; i < json.devices.length; i++)
{
if (json.devices[i].type == "Out")
{
outs.push({
id: json.devices[i].id,
label: json.devices[i].label
});
}
}
for (i = 0; i < json.devices.length; i++)
{
if (json.devices[i].type == "XOR" || json.devices[i].type == "NAND" || json.devices[i].type == "AND" || json.devices[i].type == "OR" || json.devices[i].type == "NOR" || json.devices[i].type == "NXOR")
{
divs.push({
id: json.devices[i].id,
type: json.devices[i].type
});
}
}
res += "module x(";
if (ins.length == 2)
{
res += "input " + ins[0].label + ", ";
res += "input " + ins[1].label + ", ";
}
if (outs.length == 1)
{
res += "output " + outs[0].label + ");\n";
}
if (outs.length == 2)
{
res += "output " + outs[0].label + ", ";
res += "output " + outs[1].label + ");\n";
}
for (k = 0; k < divs.length; k++)
{
res += "\tassign ";
for (i = 0; i < json.connectors.length; i++)
{
if (json.connectors[i].to == divs[k].id + ".out0")
{
for (j = 0; j < json.devices.length; j++)
{
if (json.devices[j].id + ".in0" == json.connectors[i].from)
{
res += json.devices[j].label + " = (";
}
}
}
}
for (i = 0; i < json.connectors.length; i++)
{
if (json.connectors[i].from == divs[k].id + ".in0")
{
for (j = 0; j < json.devices.length; j++)
{
if (json.devices[j].id + ".out0" == json.connectors[i].to)
{
res += json.devices[j].label;
}
}
}
}
if (divs[k].type == "XOR")
{
res += " ^ ";
}
if (divs[k].type == "AND")
{
res += " & ";
}
if (divs[k].type == "OR")
{
res += " | ";
}
if (divs[k].type == "NAND")
{
res += " ~& ";
}
if (divs[k].type == "NOR")
{
res += " ~| ";
}
if (divs[k].type == "XNOR")
{
res += " ~^ ";
}
for (i = 0; i < json.connectors.length; i++)
{
if (json.connectors[i].from == divs[k].id + ".in1")
{
for (j = 0; j < json.devices.length; j++)
{
if (json.devices[j].id + ".out0" == json.connectors[i].to)
{
res += json.devices[j].label + ");\n";
}
}
}
}
}
res += "endmodule";
koko.value = res;
}
以上