digitaljs icon indicating copy to clipboard operation
digitaljs copied to clipboard

Detect and disallow invalid connections in JSON

Open tilk opened this issue 4 years ago • 6 comments

If the input JSON has a connection between different-sized ports, DigitalJS will happily connect them, with disastrous results. For example, yosys2digitaljs currently generates such a bad JSON for:

module test2(input [1:0] i, output o);
  assign o = i;
endmodule
module test(output o);
  test2 x(0'b1, o);
endmodule

tilk avatar Mar 23 '20 15:03 tilk

Hi, can you explain how is JSON converted into digital circuits using yosys2digitaljs? A simple workflow describing which files are being used in the process would be great.

ShreyaPrasad1209 avatar Mar 27 '20 22:03 ShreyaPrasad1209

I don't really understand your question. Yosys2digitaljs takes Yosys-genereated JSON, and generates DigitalJS-compatible JSON. Yosys's JSON format describes connections using numbered, single bit nets, while DigitalJS's format describes connections of whole ports. The complex part is converting the single bit connections to whole port connections, adding adapter elements (bit extensions, bit vector splitting and concatenation, etc.) as needed. The code is currently a little bit messy, it's here: https://github.com/tilk/yosys2digitaljs/blob/master/index.js

tilk avatar Mar 28 '20 10:03 tilk

I saw the mention of JointJS and BackboneJS being used. Would you please help me with their functionality also. Also, You mentioned, "Yosys's JSON format describes connections using numbered, single bit nets, while DigitalJS's format describes connections of whole ports." This is pretty vague as I wasn't able to understand "DigitalJS's JSON" part. Can you help me with an example?

ShreyaPrasad1209 avatar Mar 28 '20 12:03 ShreyaPrasad1209

JointJS and BackboneJS

JointJS is used to render the circuit as a graph in an SVG and JointJS already builds on top of BackboneJS. It also uses jQuery and lodash.

DigitalJS's JSON

Please refer to the README's section on the input format. Some examples to get you started are available under examples, e.g. a (relatively simple) fulladder.

ialokim avatar Apr 06 '20 14:04 ialokim

How would you like digitaljs to react in such a case? I would propose to show a warning/error (e.g. using a red shadow) on the affected wire (or port?), perhaps with a tooltip shown on mouseover stating the problem, and only allow circuit.start() in case there are no errors in the whole graph.

This would then also be another step towards #2 by handling invalid connections introduced by changing bit lengths after initialization.

ialokim avatar Jun 27 '20 10:06 ialokim

Your proposition is fine. The information about the circuit correctness should also be accessible by code, for example by a property on HeadlessCircuit. Also, I worry about complexity of the solution. It should be simple (so that it's easy to see it's correct), and should not impact the performance for error-free circuits.

tilk avatar Jun 27 '20 12:06 tilk