Re: [myhdl-list] Constant ints in interfaces
Brought to you by:
jandecaluwe
From: SHEN C. <she...@co...> - 2015-03-16 12:01:51
|
Hi Keerthan, I will write more cases as you said. So I hope folks here will post exotic way of abusing interface, so we could clarifying what are supported v.s. what are not. By doing this, we can have a spec first, before anyone attempting a fix. For instance, do you think it's a good idea to have a Interface base class, and requires all interface to derive from the base class? With this convention, during extractHier/analyze, we can unambiguously identify interface objects, descend into it and extract its member signals. regards, Shenchen On 2015-03-16 19:46, Keerthan JC wrote: > This is a bug, not a limitation. Please post additional testcases to the issue I just created. https://github.com/jandecaluwe/myhdl/issues/33 [10] > > I will look into this later this week. > > On Mon, Mar 16, 2015 at 7:18 AM, SHEN Chen <she...@co... [11]> wrote: > >> 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 [1] >> - >> https://github.com/jandecaluwe/myhdl/blob/master/myhdl/conversion/_analyze.py#L149 [2] >> >> 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 [3]). >> >> 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/ [4] >> > _______________________________________________ >> > myhdl-list mailing list >> > myh...@li... [5] >> > https://lists.sourceforge.net/lists/listinfo/myhdl-list [6] >> >> ------------------------------------------------------------------------------ >> 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/ [7] >> _______________________________________________ >> myhdl-list mailing list >> myh...@li... [8] >> https://lists.sourceforge.net/lists/listinfo/myhdl-list [9] > > -- > > have a nice day > -jck -- SHEN Chen General Manager --------------------------------- Cogenda Co Ltd SISPARK II Room C102-1, 1355 Jinjihu Avenue, Suzhou, Jiangsu, China Phone(Fax): +86 512 67900636 Homepage: http://www.cogenda.com Links: ------ [1] https://github.com/jandecaluwe/myhdl/blob/master/myhdl/_extractHierarchy.py#L317 [2] https://github.com/jandecaluwe/myhdl/blob/master/myhdl/conversion/_analyze.py#L149 [3] https://github.com/jandecaluwe/myhdl/pull/21 [4] http://goparallel.sourceforge.net/ [5] mailto:myh...@li... [6] https://lists.sourceforge.net/lists/listinfo/myhdl-list [7] http://goparallel.sourceforge.net/ [8] mailto:myh...@li... [9] https://lists.sourceforge.net/lists/listinfo/myhdl-list [10] https://github.com/jandecaluwe/myhdl/issues/33 [11] mailto:she...@co... |