azonenberg / openfpga

Open FPGA tools
Other
257 stars 30 forks source link

'called `Option::unwrap()` on a `None` value' -- bug 4 from #132 #133

Closed ArcaneNibble closed 4 years ago

ArcaneNibble commented 4 years ago

MCVE

module top(r0, r1,
    clk_,
    but0);

(* LOC = "FB1_2" *)
output r0;
(* LOC = "FB1_6" *)
output r1;

(* LOC = "FB1_14" *)
input but0;

(* LOC = "FB2_5" *)
input clk_;

// NOTE: Must manually instantiate BUFG
wire clk;
BUFG bufg0 (
    .I(clk_),
    .O(clk),
);

reg [2:0] dotcnt;

always @(*)
    if (dotcnt >= 2) begin
        if (but0) begin
            r1 <= 0;
            r0 <= 1;
        end else begin
            r1 <= 1;
            r0 <= 1;
        end
    end

always @(posedge clk)
    dotcnt <= dotcnt + 1;

endmodule
ArcaneNibble commented 4 years ago

more minimized

module top(r0, clk_);

(* LOC = "FB1_2" *)
output r0;

(* LOC = "FB2_5" *)
input clk_;

// NOTE: Must manually instantiate BUFG
wire clk;
BUFG bufg0 (
    .I(clk_),
    .O(clk),
);

reg [1:0] dotcnt;

always @(*)
    if (dotcnt >= 2) begin
        r0 <= 1;
    end

always @(posedge clk)
    dotcnt <= dotcnt + 1;

endmodule
ArcaneNibble commented 4 years ago

Bug happens when a constant 0/1 value tries to feed into a FF/latch (which has to be written in such a way so that yosys doesn't optimize it out). The coolrunner2_fixup pass ends up buffering the constant into an ANDTERM which is not valid. Will fix in yosys.