+from collections import namedtuple
+import io
+import unittest
+
+# trace file entries are lists of these.
+Hazards = namedtuple("Hazards", ["action", "target", "ident", "offs", "elwid"])
+
+# key: readport, writeport (per clock cycle)
+HazardProfiles = {
+ "GPR": (4, 1), # GPR allows 4 reads 1 write possible in 1 cycle...
+ "FPR": (3, 1),
+ "CR" : (2, 1), # Condition Register (32-bit)
+ "CRf": (3, 3), # Condition Register Fields (4-bit each)
+ "XER": (1, 1),
+ "MSR": (1, 1),
+ "FPSCR": (1, 1),
+ "PC": (1, 1), # Program Counter
+ "SPRf" : (4, 3), # Fast SPR (actually STATE regfile in TestIssuer)
+ "SPRs" : (1, 1), # Slow SPR
+}
+
+
+def read_file(fname):
+ """reads a trace file in the format "[r:FILE:regnum:offset:width]* # insn"
+ """
+ is_file = hasattr(fname, "write")
+ if not is_file:
+ fname = open(fname, "r")
+ res = []
+ for line in fname.readlines():
+ (specs, insn) = map(str.strip, line.strip().split("#"))
+ line = [insn]
+ for spec in specs.split(" "):
+ line.append(Hazards._make(spec.split(":")))
+ res.append(line)
+ if not is_file:
+ fname.close()
+ return res
+