Re: [myhdl-list] Constant ints in interfaces
Brought to you by:
jandecaluwe
From: SHEN C. <she...@co...> - 2015-03-16 11:18:43
|
Hi all, I encountered similar problem recently. This is a generic problem in the current implementation of interface. In your code, the following line is critical: tiWIDTH_FPN = self.WIDTH_FPN With this line, Python creates a local variable named "tiWIDTH_FPN". In the previous versions of MyHDL, during conversion/elaboration, we put all local variables to "symdict". I found two places where symdict is constructed, in _extractHier and in _analyzeGens: - https://github.com/jandecaluwe/myhdl/blob/master/myhdl/_extractHierarchy.py#L317 - https://github.com/jandecaluwe/myhdl/blob/master/myhdl/conversion/_analyze.py#L149 Unfortunately, in the current implementation of interface, I couldn't find a place where self.WIDTH_FPN being added to symdict. I recently found that, if a signal isn't included in symdict, it will appear as constant in converted code. This is the origin of the remaining caveat I mentioned in pull request 21 (https://github.com/jandecaluwe/myhdl/pull/21). One workaround is simply to create a local copy of all signals in the interface. In my project, I even created an Interface base class, and defined an signals() member method, so in the logic generators I can write: tiWIDTH_FPN, tiWIDTH_PRNU = self.signals() Unfortunately, Python does not allow the following: createLocalVars( self.signals() ) so you will have to hand-write the left-hand-side of the assignment, in order to create local variables. regards, shenchne On 2015-03-16 18:03, Josy Boelen wrote: >> class Interface(object): def __init__(self): self.a = >> Signal(intbv(0, >> min=-1000, max=1000)) self.c = 10 where c gets converted as >> interface_name.c. My understanding from the docs is that this should >> be >> supported, but I might be missing something. I noticed this >> previously >> with IntEnum, > > but > > Henry, > > I noticed similar behaviour when using a class (as I also have local > functions in the class), here is my code: > class CorrectionCoefficients(object): > ''' a VHDL-record like object ''' > def __init__(self, WIDTH_PRNU, WIDTH_FPN, p = 0, f = 0): > self.WIDTH_FPN = WIDTH_FPN > self.WIDTH_PRNU = WIDTH_PRNU > self.fpn = Signal(intbv(f)[WIDTH_FPN:]) > self.prnu = Signal(intbv(p)[WIDTH_PRNU:]) > > def toCorrectionCoefficients(self, v): > # need an unique name as 'alias' otherwise the 'self.WIDTH_FPN' > shows up as a constant in the VHDL > tccWIDTH_FPN = self.WIDTH_FPN > @always_comb > def tcc(): > lv = v > self.fpn.next = lv[tccWIDTH_FPN:] > self.prnu.next = lv[:tccWIDTH_FPN] > > return tcc > > def tointbv(self, y): > ''' build a flattened vector from the record's elements in > ascending order''' > # need an unique name as 'alias' otherwise the 'self.WIDTH_FPN' > shows up as a constant in the VHDL :) > tiWIDTH_FPN = self.WIDTH_FPN > > @always_comb > def ti(): > y.next[tiWIDTH_FPN:] = self.fpn > y.next[:tiWIDTH_FPN] = self.prnu > > return ti > > Regards, > > Josy > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming The Go Parallel Website, > sponsored > by Intel and developed in partnership with Slashdot Media, is your > hub > for all > things parallel software development, from weekly thought leadership > blogs to > news, videos, case studies, tutorials and more. Take a look and join > the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list |