split out function which processes initial test memory values in Mem class
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 22 Sep 2021 15:48:45 +0000 (16:48 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 22 Sep 2021 15:48:45 +0000 (16:48 +0100)
src/openpower/decoder/isa/mem.py

index adaa84b44a3b9019cda5f5dfa4d2b23b68aa3698..c41e436e5e5133a6bebaf76b9df81d4d60baa51c 100644 (file)
@@ -31,6 +31,27 @@ def swap_order(x, nbytes):
 class MemException(Exception):
     pass
 
+def process_mem(initial_mem, row_bytes=8):
+    res = {}
+    # different types of memory data structures recognised (for convenience)
+    if isinstance(initial_mem, list):
+        initial_mem = (0, initial_mem)
+    if isinstance(initial_mem, tuple):
+        startaddr, mem = initial_mem
+        initial_mem = {}
+        for i, val in enumerate(mem):
+            initial_mem[startaddr + row_bytes*i] = (val, row_bytes)
+
+    for addr, val in initial_mem.items():
+        if isinstance(val, tuple):
+            (val, width) = val
+        else:
+            width = row_bytes # assume same width
+        #val = swap_order(val, width)
+        res[addr] = (val, width)
+
+    return res
+
 
 class Mem:
 
@@ -44,20 +65,7 @@ class Mem:
         if not initial_mem:
             return
 
-        # different types of memory data structures recognised (for convenience)
-        if isinstance(initial_mem, list):
-            initial_mem = (0, initial_mem)
-        if isinstance(initial_mem, tuple):
-            startaddr, mem = initial_mem
-            initial_mem = {}
-            for i, val in enumerate(mem):
-                initial_mem[startaddr + row_bytes*i] = (val, row_bytes)
-
-        for addr, val in initial_mem.items():
-            if isinstance(val, tuple):
-                (val, width) = val
-            else:
-                width = row_bytes # assume same width
+        for addr, (val, width) in process_mem(initial_mem, row_bytes).items():
             #val = swap_order(val, width)
             self.st(addr, val, width, swap=False)