Cannot save simple design due to BigInt
yuyichao opened this issue · comments
The following simple design cannot be saved due to JSON.stringify() not knowing how to serialize a BigInt
.
module counter(input wire clock, output reg [0:0] out);
initial begin
out = 1'b0;
end
always @(posedge clock) begin
out <= out + 1'b1;
end
endmodule
The culprit seems to be the increment. Monkey patching BigInt using GoogleChromeLabs/jsbi#30 (comment) seems to work around the issue and produces a usable json output. A less invasive method by adding a replacement argument to the stringify call is probably better.
I would have tested this locally and submit a PR instead but somehow sass dependency doesn't work on node 17 right now so I couldn't test this...
Thank you for reporting this issue. This is an issue with digitaljs
, not digitaljs_online
, and I will be transferring it there. The problem is with the circuit.toJSON
function, and possibly with element constructors. Because bigints can't be serialized to JSON reliably, they should probably be converted to Numbers (if they can represent them) or Strings (if they can't), and element constructors should parse the strings if they get them instead of BigInts.
I don't have the time currently to fix this, and I'll happily accept a pull request.
I could give it a try. I was able to run digitaljs locally, but I have difficulty reproducing the issue locally....
The JSON returned from yosys2digitaljs of course doesn't have any BigInt, and indeed, plugging that directly into HeadlessCircuit and calling toJSON on that doesn't have any bigint either.... I'm not sure how to trigger the condition that introduces the BigInt ATM...
I think the problem exists with the *Const
family of arithmetic cells, which are generated by the integrateArithConstant
transform.