add setmodule function to SimdScope
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 30 Oct 2021 10:26:31 +0000 (11:26 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 30 Oct 2021 10:26:31 +0000 (11:26 +0100)
src/ieee754/part/simd_scope.py

index 290c83e6c20f0c06ff7c8acd847dcda8eb03ab7b..680fea3265e2a4ed2f31c40a1918fcb61cbe933f 100644 (file)
@@ -50,18 +50,22 @@ class SimdScope:
 
     def __init__(self, module, elwid, vec_el_counts, scalar=False):
 
+        self.elwid = elwid
+        self.vec_el_counts = vec_el_counts
+        self.scalar = scalar
+        self.set_module(module)
+
+    def set_module(self, module):
         # in SIMD mode, must establish module as part of context and inform
         # the module to operate under "SIMD" Type 1 (AST) casting rules,
         # not the # default "Value.cast" rules.
-        if not scalar:
-            self.module = module
-            from ieee754.part.partsig import SimdSignal
+        if self.scalar:
+            return
+        self.module = module
+        from ieee754.part.partsig import SimdSignal
+        if module is not None:
             module._setAstTypeCastFn(SimdSignal.cast)
 
-        self.elwid = elwid
-        self.vec_el_counts = vec_el_counts
-        self.scalar = scalar
-
     def __repr__(self):
         return (f"SimdScope(\n"
                 f"        elwid={self.elwid},\n"