io.py 883 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import re
  2. import time
  3. def showHex(txt, i):
  4. time, unit, val = txt.strip().split(" ")
  5. time = int(time)
  6. for x in ["s", "ms", "us", "ns", "ps", "fs"]:
  7. if unit == x:
  8. break
  9. time /= 1000.0
  10. if re.match(r'[01]{32}', val, re.M):
  11. num = int(val, 2)
  12. print("{:6d} {:8.0f} ns {} {:08X}".format(i, time * 10**9, val, num))
  13. else:
  14. print("{:6d} {:8.0f} ns {}".format(i, time * 10**9, val))
  15. def main():
  16. with open("vivado_project/vhdl-modules.sim/sim_1/behav/xsim/input.txt", "r") as inFile:
  17. print("Input:")
  18. i = 0
  19. for line in inFile:
  20. showHex(line, i)
  21. i += 1
  22. with open("vivado_project/vhdl-modules.sim/sim_1/behav/xsim/output.txt", "r") as outFile:
  23. print("Output:")
  24. i = 0
  25. for line in outFile:
  26. showHex(line, i)
  27. i += 1
  28. while True:
  29. print("\n\n\n\n")
  30. main()
  31. time.sleep(1)