Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Records don't work in Assert #403

Closed
BracketMaster opened this issue Jun 13, 2020 · 5 comments
Closed

Records don't work in Assert #403

BracketMaster opened this issue Jun 13, 2020 · 5 comments
Labels
Milestone

Comments

@BracketMaster
Copy link

You can't don Assert on records.
The following will fail in elaboration.

from nmigen import *
from nmigen.asserts import Assert

rec = Record([("sig1", 3), ("sig2", 3)])
Assert(rec == 3)
@whitequark whitequark added the bug label Jun 13, 2020
@whitequark
Copy link
Member

whitequark commented Nov 7, 2020

Works for me on latest nMigen:

from nmigen import *
from nmigen.asserts import Assert
from nmigen.back import verilog

rec = Record([("sig1", 3), ("sig2", 3)])
m = Module()
m.d.sync += Assert(rec == 3)
print(verilog.convert(m))

Can you please confirm?

@BracketMaster
Copy link
Author

Seems fine. I'm honestly not sure what I was trying to
do in the original issue. Its been four months haha.

@rroohhh
Copy link
Contributor

rroohhh commented Nov 7, 2020

Due to #533, while it works it probably does not produce what one expects:

>>> from nmigen import *
>>> from nmigen.asserts import Assert
>>>
>>> rec = Record([("sig1", 3), ("sig2", 3)])
>>> Assert(rec == 3)
(assert (const 1'd0))

@whitequark whitequark reopened this Nov 7, 2020
@whitequark
Copy link
Member

@rroohhh Thanks for noticing!

@rroohhh
Copy link
Contributor

rroohhh commented Nov 9, 2020

Should be fixed by #541 now:

>>> from nmigen import *
>>> from nmigen.asserts import Assert
>>> rec = Record([("sig1", 3), ("sig2", 3)])
>>> Assert(rec == 3)
(assert (== (cat (sig rec__sig1) (sig rec__sig2)) (const 2'd3)))
>>>

and

from nmigen import *
from nmigen.asserts import Assert
from nmigen.back import verilog

rec = Record([("sig1", 3), ("sig2", 3)])
m = Module()
m.d.sync += Assert(rec == 3)
print(verilog.convert(m))
/* Generated by Yosys 0.9+3477 (git sha1 UNKNOWN, g++ 7.5.0 -fPIC -Os) */

(* \nmigen.hierarchy  = "top" *)
(* top =  1  *)
(* generator = "nMigen" *)
module top(rec__sig2, rst, clk, rec__sig1);
  reg \initial  = 0;
  (* src = "/data/projects/nmigen/nmigen/hdl/rec.py:255" *)
  wire \$1 ;
  (* src = "<stdin>:1" *)
  reg \$assert$check  = 1'h0;
  (* src = "<stdin>:1" *)
  reg \$assert$check$next ;
  (* src = "<stdin>:1" *)
  reg \$assert$en  = 1'h0;
  (* src = "<stdin>:1" *)
  reg \$assert$en$next ;
  (* src = "/data/projects/nmigen/nmigen/hdl/ir.py:526" *)
  input clk;
  (* src = "<stdin>:1" *)
  input [2:0] rec__sig1;
  (* src = "<stdin>:1" *)
  input [2:0] rec__sig2;
  (* src = "/data/projects/nmigen/nmigen/hdl/ir.py:526" *)
  input rst;
  assign \$1  = { rec__sig2, rec__sig1 } == (* src = "/data/projects/nmigen/nmigen/hdl/rec.py:255" *) 2'h3;
  always @* if (\$assert$en ) assert(\$assert$check );
  always @(posedge clk)
    \$assert$en  <= \$assert$en$next ;
  always @(posedge clk)
    \$assert$check  <= \$assert$check$next ;
  always @* begin
    if (\initial ) begin end
    \$assert$en$next  = \$assert$en ;
    \$assert$check$next  = \$assert$check ;
    \$assert$check$next  = \$1 ;
    \$assert$en$next  = 1'h1;
  end
endmodule

@whitequark whitequark added this to the 0.3 milestone Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants