cornell-brg / pymtl

Python-based hardware modeling framework
BSD 3-Clause "New" or "Revised" License
234 stars 83 forks source link

Throw useful Error during translation when non-literal Bits constructors encountered. #123

Closed dmlockhart closed 9 years ago

dmlockhart commented 9 years ago

Bits are only Verilog translatable if the argument provided to them is a numeric literal:

   s.out.value = s.in_ + Bits( 4, 2 )

The following is not supported:

    @s.combinational
    def block():
      s.resp.msg.value = Bits( 32, s.a_reg.out * s.b_reg.out, trunc=True )

It translates to this:

  // PYMTL SOURCE:
  // @s.combinational
  // def block():
  //   s.resp.msg.value = Bits( 32, s.a_reg.out * s.b_reg.out, trunc=True )

  // logic for block()
  always @ (*) begin
    resp_msg = 32'd(a_reg$out*b_reg$out);
  end

The above is invalid Verilog (see 32'd(...)). We should really be able to catch this and throw a useful Exception message to the user.