X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fnmutil%2Fstageapi.py;h=17c4f6509852045a4b812f2121aec6b14ea695ef;hb=HEAD;hp=b709abd801d5b9c31aa574bcf32bc03c6bd788a0;hpb=4241aad8550d189a4aff51a0ecba9777347ac3bf;p=nmutil.git diff --git a/src/nmutil/stageapi.py b/src/nmutil/stageapi.py index b709abd..17c4f65 100644 --- a/src/nmutil/stageapi.py +++ b/src/nmutil/stageapi.py @@ -1,5 +1,11 @@ +# SPDX-License-Identifier: LGPL-3-or-later """ Stage API + This work is funded through NLnet under Grant 2019-02-012 + + License: LGPLv3+ + + Associated development bugs: * http://bugs.libre-riscv.org/show_bug.cgi?id=148 * http://bugs.libre-riscv.org/show_bug.cgi?id=64 @@ -113,10 +119,10 @@ class StageCls(metaclass=ABCMeta): def ispec(self): pass # REQUIRED @abstractmethod def ospec(self): pass # REQUIRED - #@abstractmethod - #def setup(self, m, i): pass # OPTIONAL - #@abstractmethod - #def process(self, i): pass # OPTIONAL + # @abstractmethod + # def setup(self, m, i): pass # OPTIONAL + # @abstractmethod + # def process(self, i): pass # OPTIONAL class Stage(metaclass=ABCMeta): @@ -135,12 +141,12 @@ class Stage(metaclass=ABCMeta): @abstractmethod def ospec(): pass - #@staticmethod - #@abstractmethod + # @staticmethod + # @abstractmethod #def setup(m, i): pass - #@staticmethod - #@abstractmethod + # @staticmethod + # @abstractmethod #def process(i): pass @@ -152,6 +158,7 @@ class StageHelper(Stage): it differs from the stage that it wraps in that all the "optional" functions are provided (hence the designation "convenience wrapper") """ + def __init__(self, stage): self.stage = stage self._ispecfn = None @@ -190,10 +197,11 @@ class StageHelper(Stage): def setup(self, m, i): if self.stage is not None and hasattr(self.stage, "setup"): - self.stage.setup(m, i) + if self.stage is not self: # stop infinite recursion + self.stage.setup(m, i) - def _postprocess(self, i): # XXX DISABLED - return i # RETURNS INPUT + def _postprocess(self, i): # XXX DISABLED + return i # RETURNS INPUT if hasattr(self.stage, "postprocess"): return self.stage.postprocess(i) return i @@ -238,6 +246,7 @@ class StageChain(StageHelper): side-effects (state-based / clock-based input) or conditional (inter-chain) dependencies, unless you really know what you are doing. """ + def __init__(self, chain, specallocate=False): assert len(chain) > 0, "stage chain must be non-zero length" self.chain = chain @@ -257,12 +266,13 @@ class StageChain(StageHelper): o = _spec(ofn, cname) if isinstance(o, Elaboratable): setattr(m.submodules, cname, o) - m.d.comb += nmoperator.eq(o, c.process(i)) # process input into "o" + # process input into "o" + m.d.comb += nmoperator.eq(o, c.process(i)) if idx == len(self.chain)-1: break ifn = self.chain[idx+1].ispec # new input on next loop i = _spec(ifn, 'chainin%d' % (idx+1)) - m.d.comb += nmoperator.eq(i, o) # assign to next input + m.d.comb += nmoperator.eq(i, o) # assign to next input self.o = o return self.o # last loop is the output @@ -275,6 +285,4 @@ class StageChain(StageHelper): return self.o # last loop is the output def process(self, i): - return self.o # conform to Stage API: return last-loop output - - + return self.o # conform to Stage API: return last-loop output