From 14c790fe0b8f487d126505d7bb40c4126d0cfe95 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 29 Apr 2019 04:55:25 +0100 Subject: [PATCH] remove unneeded imports, move RecordBasedStage and PassThroughStage --- src/add/singlepipe.py | 61 ++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/add/singlepipe.py b/src/add/singlepipe.py index ebbb1e9b..1c72aa84 100644 --- a/src/add/singlepipe.py +++ b/src/add/singlepipe.py @@ -129,15 +129,12 @@ https://github.com/ZipCPU/dbgbus/blob/master/hexbus/rtl/hbdeword.v """ -from nmigen import Signal, Cat, Const, Mux, Module, Value, Elaboratable +from nmigen import Signal, Mux, Module, Elaboratable from nmigen.cli import verilog, rtlil from nmigen.lib.fifo import SyncFIFO, SyncFIFOBuffered from nmigen.hdl.ast import ArrayProxy from nmigen.hdl.rec import Record -from abc import ABCMeta, abstractmethod -from collections.abc import Sequence, Iterable -from collections import OrderedDict from queue import Queue import inspect @@ -147,6 +144,34 @@ from stageapi import (_spec, PrevControl, NextControl, StageCls, Stage, StageChain, StageHelper) +class RecordBasedStage(Stage): + """ convenience class which provides a Records-based layout. + honestly it's a lot easier just to create a direct Records-based + class (see ExampleAddRecordStage) + """ + def __init__(self, in_shape, out_shape, processfn, setupfn=None): + self.in_shape = in_shape + self.out_shape = out_shape + self.__process = processfn + self.__setup = setupfn + def ispec(self): return Record(self.in_shape) + def ospec(self): return Record(self.out_shape) + def process(seif, i): return self.__process(i) + def setup(seif, m, i): return self.__setup(m, i) + + +class PassThroughStage(StageCls): + """ a pass-through stage with its input data spec identical to its output, + and "passes through" its data from input to output (does nothing). + + use this basically to explicitly make any data spec Stage-compliant. + (many APIs would potentially use a static "wrap" method in e.g. + StageCls to achieve a similar effect) + """ + def __init__(self, iospecfn): self.iospecfn = iospecfn + def ispec(self): return self.iospecfn() + def ospec(self): return self.iospecfn() + class ControlBase(StageHelper, Elaboratable): """ Common functions for Pipeline API. Note: a "pipeline stage" only @@ -297,21 +322,6 @@ class ControlBase(StageHelper, Elaboratable): return m -class RecordBasedStage(Stage): - """ convenience class which provides a Records-based layout. - honestly it's a lot easier just to create a direct Records-based - class (see ExampleAddRecordStage) - """ - def __init__(self, in_shape, out_shape, processfn, setupfn=None): - self.in_shape = in_shape - self.out_shape = out_shape - self.__process = processfn - self.__setup = setupfn - def ispec(self): return Record(self.in_shape) - def ospec(self): return Record(self.out_shape) - def process(seif, i): return self.__process(i) - def setup(seif, m, i): return self.__setup(m, i) - class BufferedHandshake(ControlBase): """ buffered pipeline stage. data and strobe signals travel in sync. @@ -654,19 +664,6 @@ class UnbufferedPipeline2(ControlBase): return self.m -class PassThroughStage(StageCls): - """ a pass-through stage with its input data spec identical to its output, - and "passes through" its data from input to output (does nothing). - - use this basically to explicitly make any data spec Stage-compliant. - (many APIs would potentially use a static "wrap" method in e.g. - StageCls to achieve a similar effect) - """ - def __init__(self, iospecfn): self.iospecfn = iospecfn - def ispec(self): return self.iospecfn() - def ospec(self): return self.iospecfn() - - class PassThroughHandshake(ControlBase): """ A control block that delays by one clock cycle. -- 2.30.2