0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ビジュアルプログラミングで高位合成 その2

Last updated at Posted at 2024-09-18

概要

ビジュアルプログラミングで組み合わせ回路を組み立てて、シュミレーションして、verilogを生成します。
高位合成です。
実装編

ビジュアルプログラミングした組み合わせ回路

image.png

生成されたverilog

module x(input In0, input In1, output Out0);
	assign Out0 = (In1  ^ In0);
endmodule


成果物

Toggle Buttonをクリックして、シュミレーションできます。

verilogを生成します。

サンプルコード


function make(s) {
	var i;
	var j;
	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")
    {
			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 (divs.length == 1) 
	{
		res += "\tassign ";
		for (i = 0; i < json.connectors.length; i++) 
		{
  	  if (json.connectors[i].to == divs[0].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[0].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[0].type == "XOR")
		{
			res += " ^ ";
		}
		if (divs[0].type == "AND")
		{
			res += " & ";
		}
		if (divs[0].type == "OR")
		{
			res += " | ";
		}
		if (divs[0].type == "NAND")
		{
			res += " ~& ";
		}
		if (divs[0].type == "NOR")
		{
			res += " ~| ";
		}
		if (divs[0].type == "NOT")
		{
			res += " ~ ";
		}
		if (divs[0].type == "XNOR")
		{
			res += " ~^ ";
		}

		for (i = 0; i < json.connectors.length; i++) 
		{
    	if (json.connectors[i].from == divs[0].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;
}


以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?