Re: [myhdl-list] AttributeError: '_ConvertFunctionVisitor' object has no attribute 'funcBuf'
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2009-03-04 19:48:50
|
Neal Becker wrote: > Translating to verilog produced the above error. Mm, it seems the convertor has difficulties when an ordinary function calls another ordinary function. Should work, I know :-) Before showing a workaround below, I notice that you're also using function calls to calculate constants inside generator code. An important trick with conversion (because it is so limited) is too keep as much as possible outside of generator code. If possible, calculate constants outside generators and pass them as parameters - this way the computation can be arbitrarily complex, as the convertor only needs to convert code used inside generators. The following modified code seems to convert fine: def sat_rnd (x, bits, outbits): y1 = x >> (bits-1) y2 = y1 + 1 y3 = y2 >> 1 if (y3 > (2**outbits-1)): return 2**outbits - 1 elif (y3 < - (2**outbits)): return - (2**outbits) else: return y3 def Counter (count, clock, en, n, reset): @always (clock.posedge, reset.posedge) def cntLogic(): if reset == 1: count.next = 0 elif en: if count == n-1: count.next = 0 else: count.next = count + 1 # print "count:", count return cntLogic def accum (x, result, count, clock, en, n, reset): def log2 (x): "positive only!" cnt = 0 while (x != 0): x >>= 1 cnt += 1 return cnt-1 m = log2(n) sumbits = m + len (result) _sum = Signal (intbv(0)[sumbits:]) p = len(result) @always (clock.posedge, reset.posedge) def accum_logic(): if reset == 1: _sum.next = 0 result.next = 0 elif en: _sum.next = _sum + x if count == n-1: ##print 'count:', count, 'sum:', _sum result.next = sat_rnd (_sum, m, p) _sum.next = 0 return accum_logic def Decimator (clock, en, x, n, count, result, reset): cnt1 = Counter (count, clock, en, n, reset) acc1 = accum (x, result, count, clock, en, n, reset) return cnt1, acc1 -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a hardware description language: http://www.myhdl.org |