[Libre-soc-dev] Confusing nmigen assert error

Luke Kenneth Casson Leighton lkcl at lkcl.net
Wed Sep 23 19:11:42 BST 2020


On 9/23/20, Cole Poirier <colepoirier at gmail.com> wrote:
> On Wednesday, September 23, 2020, Luke Kenneth Casson Leighton <
> lkcl at lkcl.net> wrote:
>
>> On Wed, Sep 23, 2020 at 5:48 PM Cole Poirier <colepoirier at gmail.com>
>> wrote:
>> >
>> > Hi Luke,
>> >
>> > I'm working on icache.py and running into a TypeError in the
>> icache_sim() test:
>> >
>> >   File "icache.py", line 1629, in icache_sim
>> >     assert i_in.valid
>> >   File "/home/colepoirier/src/nmigen/nmigen/hdl/ast.py", line 152, in
>> __bool__
>> >     raise TypeError("Attempted to convert nMigen value to Python
>> boolean")
>> > TypeError: Attempted to convert nMigen value to Python boolean
>> >
>> > I get the same error with the modifications:
>> > "assert i_in.valid == 1" and
>> > "assert i_in.valid == Const(1, 1)"
>> >
>> > Any ideas what I'm doing wrong?
>>
>> you're trying to do python asserts.  l_in.valid is a nmigen AST object
>> of type "Signal".  "assert object of type Signal equal to 1" is 100%
>> guaranteed to fail.
>>
>
> Ok, that doesn’t give me any idea as to what I should be doing that would
> succeed. Any tips)

you are trying something that is 100% guaranteed to fail, therefore
don't do it! :)

therefore just delete those lines.

or you can look in dcache.py where i have converted similar code to
report a debug message on the console.

Assertions normally can only be put into formsl proofs.

how can a *python* assertion be valid for a *hardware* chip?

we cannot embed the python programming language esp. the "assert"
statement into gates in a chip, can we?

remember to create a model in your head of what is expected and think
it through, comparing against not just the code but what the code
*does*.

l.



More information about the Libre-soc-dev mailing list