ndi.nim 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2017 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## This module implements the generation of ``.ndi`` files for better debugging
  10. ## support of Nim code. "ndi" stands for "Nim debug info".
  11. import ast, msgs, ropes, options, pathutils
  12. type
  13. NdiFile* = object
  14. enabled: bool
  15. f: File
  16. buf: string
  17. proc doWrite(f: var NdiFile; s: PSym; conf: ConfigRef) =
  18. f.buf.setLen 0
  19. f.buf.addInt s.info.line.int
  20. f.buf.add "\t"
  21. f.buf.addInt s.info.col.int
  22. f.f.write(s.name.s, "\t")
  23. f.f.writeRope(s.loc.r)
  24. f.f.writeLine("\t", toFullPath(conf, s.info), "\t", f.buf)
  25. template writeMangledName*(f: NdiFile; s: PSym; conf: ConfigRef) =
  26. if f.enabled: doWrite(f, s, conf)
  27. proc open*(f: var NdiFile; filename: AbsoluteFile; conf: ConfigRef) =
  28. f.enabled = not filename.isEmpty
  29. if f.enabled:
  30. f.f = open(filename.string, fmWrite, 8000)
  31. f.buf = newStringOfCap(20)
  32. proc close*(f: var NdiFile) =
  33. if f.enabled: close(f.f)