From 5abcdf4cbcfe720784dcb51db1c1fde9a793f4ce Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 28 Sep 2021 19:50:41 +0100 Subject: [PATCH] move PCat to separate module (didnt help but hey), solve recursive import by moving import of PartitionedCat into the PCat function --- src/ieee754/part/partsig.py | 7 +++---- src/ieee754/part_cat/cat.py | 8 ++++++++ src/ieee754/part_cat/pcat.py | 13 +++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/ieee754/part_cat/pcat.py diff --git a/src/ieee754/part/partsig.py b/src/ieee754/part/partsig.py index 69f9734f..b5faf35a 100644 --- a/src/ieee754/part/partsig.py +++ b/src/ieee754/part/partsig.py @@ -23,7 +23,7 @@ from ieee754.part_shift.part_shift_dynamic import PartitionedDynamicShift from ieee754.part_shift.part_shift_scalar import PartitionedScalarShift from ieee754.part_mul_add.partpoints import make_partition2, PartitionPoints from ieee754.part_mux.part_mux import PMux -from ieee754.part_cat.cat import PartitionedCat +from ieee754.part_cat.pcat import PCat from operator import or_, xor, and_, not_ from nmigen import (Signal, Const) @@ -48,7 +48,7 @@ global modnames modnames = {} # for sub-modules to be created on-demand. Mux is done slightly # differently (has its own global) -for name in ['add', 'eq', 'gt', 'ge', 'ls', 'xor', 'cat']: +for name in ['add', 'eq', 'gt', 'ge', 'ls', 'xor']: modnames[name] = 0 @@ -100,8 +100,7 @@ class PartitionedSignal(UserValue): assert isinstance(sig, PartitionedSignal), \ "All PartitionedSignal.__Cat__ arguments must be " \ "a PartitionedSignal. %s is not." % repr(sig) - pc = PartitionedCat(args, self.partpoints) - setattr(self.m.submodules, self.get_modname('cat'), pc) + return PCat(self.m, args, self.partpoints) # unary ops that do not require partitioning diff --git a/src/ieee754/part_cat/cat.py b/src/ieee754/part_cat/cat.py index ac91f42d..a9541080 100644 --- a/src/ieee754/part_cat/cat.py +++ b/src/ieee754/part_cat/cat.py @@ -38,6 +38,14 @@ from ieee754.part.partsig import PartitionedSignal from ieee754.part.test.test_partsig import create_simulator +modcount = 0 # global for now +def PCat(m, arglist, mask): + global modcount + modcount += 1 + pc = PartitionedCat(arglist, mask) + setattr(m.submodules, "pcat%d" % modcount, pc) + return pc.output + def get_runlengths(pbit, size): res = [] diff --git a/src/ieee754/part_cat/pcat.py b/src/ieee754/part_cat/pcat.py new file mode 100644 index 00000000..f15bc869 --- /dev/null +++ b/src/ieee754/part_cat/pcat.py @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# See Notices.txt for copyright information +# Copyright (C) 2021 Luke Kenneth Casson Leighton + + +modcount = 0 # global for now +def PCat(m, arglist, mask): + from ieee754.part_cat.cat import PartitionedCat # avoid recursive import + global modcount + modcount += 1 + pc = PartitionedCat(arglist, mask) + setattr(m.submodules, "pcat%d" % modcount, pc) + return pc.output -- 2.30.2