chunk-print-before-all.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. # Given a -print-before-all -print-module-scope log from an opt invocation,
  3. # chunk it into a series of individual IR files, one for each pass invocation.
  4. # If the log ends with an obvious stack trace, try to split off a separate
  5. # "crashinfo.txt" file leaving only the valid input IR in the last chunk.
  6. # Files are written to current working directory.
  7. import sys
  8. basename = "chunk-"
  9. chunk_id = 0
  10. def print_chunk(lines):
  11. global chunk_id
  12. global basename
  13. fname = basename + str(chunk_id) + ".ll"
  14. chunk_id = chunk_id + 1
  15. print "writing chunk " + fname + " (" + str(len(lines)) + " lines)"
  16. with open(fname, "w") as f:
  17. f.writelines(lines)
  18. is_dump = False
  19. cur = []
  20. for line in sys.stdin:
  21. if line.startswith("*** IR Dump Before ") and len(cur) != 0:
  22. print_chunk(cur);
  23. cur = []
  24. cur.append("; " + line)
  25. elif line.startswith("Stack dump:"):
  26. print_chunk(cur);
  27. cur = []
  28. cur.append(line)
  29. is_dump = True
  30. else:
  31. cur.append(line)
  32. if is_dump:
  33. print "writing crashinfo.txt (" + str(len(cur)) + " lines)"
  34. with open("crashinfo.txt", "w") as f:
  35. f.writelines(cur)
  36. else:
  37. print_chunk(cur);