add compiler/debugutils.nim to help debugging compiler (#17652)
* add compiler/debugutils.nim * address comments
This commit is contained in:
parent
020c0a3344
commit
6ab5816866
2 changed files with 35 additions and 7 deletions
19
compiler/debugutils.nim
Normal file
19
compiler/debugutils.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
##[
|
||||||
|
Utilities to help with debugging nim compiler.
|
||||||
|
|
||||||
|
Experimental API, subject to change.
|
||||||
|
]##
|
||||||
|
|
||||||
|
import options
|
||||||
|
|
||||||
|
var conf0: ConfigRef
|
||||||
|
|
||||||
|
proc onNewConfigRef*(conf: ConfigRef) {.inline.} =
|
||||||
|
## Caches `conf`, which can be retrieved with `getConfigRef`.
|
||||||
|
## This avoids having to forward `conf` all the way down the call chain to
|
||||||
|
## procs that need it during a debugging session.
|
||||||
|
conf0 = conf
|
||||||
|
|
||||||
|
proc getConfigRef*(): ConfigRef =
|
||||||
|
## nil, if -d:nimDebugUtils wasn't specified
|
||||||
|
result = conf0
|
||||||
|
|
@ -446,6 +446,10 @@ proc newProfileData(): ProfileData =
|
||||||
const foreignPackageNotesDefault* = {
|
const foreignPackageNotesDefault* = {
|
||||||
hintProcessing, warnUnknownMagic, hintQuitCalled, hintExecuting, hintUser, warnUser}
|
hintProcessing, warnUnknownMagic, hintQuitCalled, hintExecuting, hintUser, warnUser}
|
||||||
|
|
||||||
|
proc isDefined*(conf: ConfigRef; symbol: string): bool
|
||||||
|
|
||||||
|
import debugutils
|
||||||
|
|
||||||
proc newConfigRef*(): ConfigRef =
|
proc newConfigRef*(): ConfigRef =
|
||||||
result = ConfigRef(
|
result = ConfigRef(
|
||||||
selectedGC: gcRefc,
|
selectedGC: gcRefc,
|
||||||
|
|
@ -504,16 +508,21 @@ proc newConfigRef*(): ConfigRef =
|
||||||
# enable colors by default on terminals
|
# enable colors by default on terminals
|
||||||
if terminal.isatty(stderr):
|
if terminal.isatty(stderr):
|
||||||
incl(result.globalOptions, optUseColors)
|
incl(result.globalOptions, optUseColors)
|
||||||
|
when defined(nimDebugUtils):
|
||||||
|
onNewConfigRef(result)
|
||||||
|
|
||||||
proc newPartialConfigRef*(): ConfigRef =
|
proc newPartialConfigRef*(): ConfigRef =
|
||||||
## create a new ConfigRef that is only good enough for error reporting.
|
## create a new ConfigRef that is only good enough for error reporting.
|
||||||
result = ConfigRef(
|
when defined(nimDebugUtils):
|
||||||
selectedGC: gcRefc,
|
result = getConfigRef()
|
||||||
verbosity: 1,
|
else:
|
||||||
options: DefaultOptions,
|
result = ConfigRef(
|
||||||
globalOptions: DefaultGlobalOptions,
|
selectedGC: gcRefc,
|
||||||
foreignPackageNotes: foreignPackageNotesDefault,
|
verbosity: 1,
|
||||||
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1])
|
options: DefaultOptions,
|
||||||
|
globalOptions: DefaultGlobalOptions,
|
||||||
|
foreignPackageNotes: foreignPackageNotesDefault,
|
||||||
|
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1])
|
||||||
|
|
||||||
proc cppDefine*(c: ConfigRef; define: string) =
|
proc cppDefine*(c: ConfigRef; define: string) =
|
||||||
c.cppDefines.incl define
|
c.cppDefines.incl define
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue