svp64_utf_8_validation.py: convert labels to addresses
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 22 Jan 2023 17:46:58 +0000 (20:46 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:16 +0000 (19:51 +0100)
src/openpower/test/algorithms/svp64_utf_8_validation.py

index 933a9fd87665104707f4efb2d8a8a358ac041f77..1a4247bbc4a3ffc1e8e60d93c6c4529048f4838d 100644 (file)
@@ -302,9 +302,27 @@ def assemble(instructions, start_pc=0):
             pc += 8
         else:
             pc += 4
-        out_instructions.append(instr)
+        out_instructions.append((pc, instr))
+    last_pc = pc
+
+    for (idx, (pc, instr)) in enumerate(tuple(out_instructions)):
+        for (label, target) in labels.items():
+            if label in instr:
+                if pc < target:
+                    sign = ""
+                    addr = (target - pc + 4)
+                else:
+                    sign = "-"
+                    addr = (pc - target - 4)
+
+                origin = instr
+                instr = instr.replace(label, f"{sign}0x{addr:X}")
+                break
+        out_instructions[idx] = instr
+
     for k, v in labels.items():
-        out_instructions.append(f".set {k}, . - 0x{pc - v:X} # 0x{v:X}")
+        out_instructions.append(f".set {k}, . - 0x{last_pc - v:X} # 0x{v:X}")
+
     return Program(list(SVP64Asm(out_instructions)), 0)