Re: [myhdl-list] Conversion error: Type mismatch with earlier assignment
Brought to you by:
jandecaluwe
From: Josy B. <jos...@gm...> - 2015-09-07 09:41:00
|
Hi Guy, > I actually run into this issue quite often, probably because of my liberal use of variables to store intermediate results. Here's a code snippet that triggers the conversion error: > > --- > > from myhdl import * > > def mymodule(clk_i, reset_i, count_o): > > count_r_s = Signal(intbv(0)[32:]) > > <at> always_seq(clk_i.posedge, reset=reset_i) > def logic(): > count_v = count_r_s[:] > count_v = count_v + 1 > count_r_s.next = count_v > > <at> always_comb > def outputs(): > count_o.next = count_r_s > > return instances() > > if __name__ == "__main__": > clk_i = Signal(bool(0)) > reset_i = ResetSignal(0, active=1, async=False) > count_o = Signal(intbv(0)[32:]) > toVHDL(mymodule, clk_i, reset_i, count_o) > > --- > > > Of course, the fix is to change the second variable assignment to: > > count_v[:] = count_v + 1 > > but this is not necessarily obvious from the error message, especially if you're new to Python/MyHDL. Also, if the same variable gets assigned many times same function, it may not always be easy to find the assignment that overwrites the variable (instead of just its value). > To my idea, you should have been able to write it as follows: def mymodule(clk_i, reset_i, count_o): count_r_s = Signal(intbv(0)[32:]) @always_seq(clk_i.posedge, reset=reset_i) def logic(): count_v = count_r_s count_v = count_v + 1 count_r_s.next = count_v @always_comb def outputs(): count_o.next = count_r_s return instances() so without the [:]. Anyway also when written like this we get the same error message for the same line. What happens, IMO, is that the converter thinks it sees a second, duplicate variable declaration and complains ... If you add the [:] the converter follows another path, as you are slicing, and doesn't do the 'check' and all ends well. I only use variables sparingly and the one example I could immediately find does a single assignment only: endval = int(startValue) + int(Length) explaining my 'rare' remark. I'm not sure yet but this may be a bug. Can you show me some code where you have a more elaborate use of a variable - saving me from writing one myself? Best regards, Josy |