reduce debug output (#10638)

This commit is contained in:
Arne Döring 2019-02-12 08:27:38 +01:00 • committed by Andreas Rumpf
commit f4b2793bdf

View file

@ -238,17 +238,6 @@ proc symToYamlAux(conf: ConfigRef; n: PSym, marker: var IntSet,
proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet,
indent, maxRecDepth: int): Rope indent, maxRecDepth: int): Rope
proc ropeConstr(indent: int, c: openArray[Rope]): Rope =
# array of (name, value) pairs
var istr = rspaces(indent + 2)
result = rope("{")
var i = 0
while i <= high(c):
if i > 0: add(result, ",")
addf(result, "$N$1\"$2\": $3", [istr, c[i], c[i + 1]])
inc(i, 2)
addf(result, "$N$1}", [rspaces(indent)])
proc symToYamlAux(conf: ConfigRef; n: PSym, marker: var IntSet, indent: int, proc symToYamlAux(conf: ConfigRef; n: PSym, marker: var IntSet, indent: int,
maxRecDepth: int): Rope = maxRecDepth: int): Rope =
if n == nil: if n == nil:
@ -257,51 +246,60 @@ proc symToYamlAux(conf: ConfigRef; n: PSym, marker: var IntSet, indent: int,
result = "\"$1\"" % [rope(n.name.s)] result = "\"$1\"" % [rope(n.name.s)]
else: else:
var ast = treeToYamlAux(conf, n.ast, marker, indent + 2, maxRecDepth - 1) var ast = treeToYamlAux(conf, n.ast, marker, indent + 2, maxRecDepth - 1)
result = ropeConstr(indent, [rope("kind"),
makeYamlString($n.kind),
rope("name"), makeYamlString(n.name.s),
#rope("typ"), typeToYamlAux(conf, n.typ, marker, #rope("typ"), typeToYamlAux(conf, n.typ, marker,
# indent + 2, maxRecDepth - 1), # indent + 2, maxRecDepth - 1),
rope("info"), lineInfoToStr(conf, n.info), let istr = rspaces(indent + 2)
rope("flags"), flagsToStr(n.flags), result = rope("{")
rope("magic"), makeYamlString($n.magic), addf(result, "$N$1\"kind\": $2", [istr, makeYamlString($n.kind)])
rope("ast"), ast, rope("options"), addf(result, "$N$1\"name\": $2", [istr, makeYamlString(n.name.s)])
flagsToStr(n.options), rope("position"), addf(result, "$N$1\"typ\": $2", [istr, typeToYamlAux(conf, n.typ, marker, indent + 2, maxRecDepth - 1)])
rope(n.position), if conf != nil:
rope("k"), makeYamlString($n.loc.k), # if we don't pass the config, we probably don't care about the line info
rope("storage"), makeYamlString($n.loc.storage), addf(result, "$N$1\"info\": $2", [istr, lineInfoToStr(conf, n.info)])
rope("flags"), makeYamlString($n.loc.flags), if card(n.flags) > 0:
rope("r"), n.loc.r, addf(result, "$N$1\"flags\": $2", [istr, flagsToStr(n.flags)])
rope("lode"), treeToYamlAux(conf, n.loc.lode, marker, indent + 2, maxRecDepth - 1) addf(result, "$N$1\"magic\": $2", [istr, makeYamlString($n.magic)])
]) addf(result, "$N$1\"ast\": $2", [istr, ast])
addf(result, "$N$1\"options\": $2", [istr, flagsToStr(n.options)])
addf(result, "$N$1\"position\": $2", [istr, rope(n.position)])
addf(result, "$N$1\"k\": $2", [istr, makeYamlString($n.loc.k)])
addf(result, "$N$1\"storage\": $2", [istr, makeYamlString($n.loc.storage)])
if card(n.loc.flags) > 0:
addf(result, "$N$1\"flags\": $2", [istr, makeYamlString($n.loc.flags)])
addf(result, "$N$1\"r\": $2", [istr, n.loc.r])
addf(result, "$N$1\"lode\": $2", [istr, treeToYamlAux(conf, n.loc.lode, marker, indent + 2, maxRecDepth - 1)])
addf(result, "$N$1}", [rspaces(indent)])
proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, indent: int, proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, indent: int,
maxRecDepth: int): Rope = maxRecDepth: int): Rope =
var sonsRope: Rope
if n == nil: if n == nil:
result = rope("null") sonsRope = rope("null")
elif containsOrIncl(marker, n.id): elif containsOrIncl(marker, n.id):
result = "\"$1 @$2\"" % [rope($n.kind), rope( sonsRope = "\"$1 @$2\"" % [rope($n.kind), rope(
strutils.toHex(cast[ByteAddress](n), sizeof(n) * 2))] strutils.toHex(cast[ByteAddress](n), sizeof(n) * 2))]
else: else:
if sonsLen(n) > 0: if sonsLen(n) > 0:
result = rope("[") sonsRope = rope("[")
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
if i > 0: add(result, ",") if i > 0: add(sonsRope, ",")
addf(result, "$N$1$2", [rspaces(indent + 4), typeToYamlAux(conf, n.sons[i], addf(sonsRope, "$N$1$2", [rspaces(indent + 4), typeToYamlAux(conf, n.sons[i],
marker, indent + 4, maxRecDepth - 1)]) marker, indent + 4, maxRecDepth - 1)])
addf(result, "$N$1]", [rspaces(indent + 2)]) addf(sonsRope, "$N$1]", [rspaces(indent + 2)])
else: else:
result = rope("null") sonsRope = rope("null")
result = ropeConstr(indent, [rope("kind"),
makeYamlString($n.kind), let istr = rspaces(indent + 2)
rope("sym"), symToYamlAux(conf, n.sym, marker, result = rope("{")
indent + 2, maxRecDepth - 1), rope("n"), treeToYamlAux(conf, n.n, marker, addf(result, "$N$1\"kind\": $2", [istr, makeYamlString($n.kind)])
indent + 2, maxRecDepth - 1), rope("flags"), flagsToStr(n.flags), addf(result, "$N$1\"sym\": $2", [istr, symToYamlAux(conf, n.sym, marker, indent + 2, maxRecDepth - 1)])
rope("callconv"), addf(result, "$N$1\"n\": $2", [istr, treeToYamlAux(conf, n.n, marker, indent + 2, maxRecDepth - 1)])
makeYamlString(CallingConvToStr[n.callConv]), if card(n.flags) > 0:
rope("size"), rope(n.size), addf(result, "$N$1\"flags\": $2", [istr, flagsToStr(n.flags)])
rope("align"), rope(n.align), addf(result, "$N$1\"callconv\": $2", [istr, makeYamlString(CallingConvToStr[n.callConv])])
rope("sons"), result]) addf(result, "$N$1\"size\": $2", [istr, rope(n.size)])
addf(result, "$N$1\"align\": $2", [istr, rope(n.align)])
addf(result, "$N$1\"sons\": $2", [istr, sonsRope])
proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet, indent: int, proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet, indent: int,
maxRecDepth: int): Rope = maxRecDepth: int): Rope =
@ -311,7 +309,8 @@ proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet, indent: int,
var istr = rspaces(indent + 2) var istr = rspaces(indent + 2)
result = "{$N$1\"kind\": $2" % [istr, makeYamlString($n.kind)] result = "{$N$1\"kind\": $2" % [istr, makeYamlString($n.kind)]
if maxRecDepth != 0: if maxRecDepth != 0:
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(conf, n.info)]) if conf != nil:
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(conf, n.info)])
case n.kind case n.kind
of nkCharLit..nkInt64Lit: of nkCharLit..nkInt64Lit:
addf(result, ",$N$1\"intVal\": $2", [istr, rope(n.intVal)]) addf(result, ",$N$1\"intVal\": $2", [istr, rope(n.intVal)])
@ -362,8 +361,8 @@ proc debugType(conf: ConfigRef; n: PType, maxRecDepth=100): Rope =
add(result, " ") add(result, " ")
add(result, n.sym.name.s) add(result, n.sym.name.s)
if n.kind in IntegralTypes and n.n != nil: if n.kind in IntegralTypes and n.n != nil:
add(result, ", node: ") add(result, ", n: ")
add(result, debugTree(conf, n.n, 2, maxRecDepth-1, renderType=true)) add(result, debugTree(conf, n.n, 2, maxRecDepth-1, renderType=false))
if (n.kind != tyString) and (sonsLen(n) > 0) and maxRecDepth != 0: if (n.kind != tyString) and (sonsLen(n) > 0) and maxRecDepth != 0:
add(result, "(") add(result, "(")
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
@ -373,7 +372,7 @@ proc debugType(conf: ConfigRef; n: PType, maxRecDepth=100): Rope =
else: else:
add(result, debugType(conf, n.sons[i], maxRecDepth-1)) add(result, debugType(conf, n.sons[i], maxRecDepth-1))
if n.kind == tyObject and n.n != nil: if n.kind == tyObject and n.n != nil:
add(result, ", node: ") add(result, ", n: ")
add(result, debugTree(conf, n.n, 2, maxRecDepth-1, renderType=true)) add(result, debugTree(conf, n.n, 2, maxRecDepth-1, renderType=true))
add(result, ")") add(result, ")")
@ -387,9 +386,11 @@ proc debugTree(conf: ConfigRef; n: PNode, indent: int, maxRecDepth: int;
[istr, makeYamlString($n.kind)] [istr, makeYamlString($n.kind)]
when defined(useNodeIds): when defined(useNodeIds):
addf(result, ",$N$1\"id\": $2", [istr, rope(n.id)]) addf(result, ",$N$1\"id\": $2", [istr, rope(n.id)])
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(conf, n.info)]) if conf != nil:
addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(conf, n.info)])
if maxRecDepth != 0: if maxRecDepth != 0:
addf(result, ",$N$1\"flags\": $2", [istr, rope($n.flags)]) if card(n.flags) > 0:
addf(result, ",$N$1\"flags\": $2", [istr, rope($n.flags)])
case n.kind case n.kind
of nkCharLit..nkUInt64Lit: of nkCharLit..nkUInt64Lit:
addf(result, ",$N$1\"intVal\": $2", [istr, rope(n.intVal)]) addf(result, ",$N$1\"intVal\": $2", [istr, rope(n.intVal)])
@ -400,15 +401,19 @@ proc debugTree(conf: ConfigRef; n: PNode, indent: int, maxRecDepth: int;
addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)])
of nkSym: of nkSym:
let s = n.sym let s = n.sym
addf(result, ",$N$1\"sym\": $2_$3 k: $4 storage: $5 flags: $6 r: $7", var symStr = ""
[istr, rope(s.name.s), rope(s.id), symStr.add "\"kind\": "
rope($s.loc.k), symStr.add $s.kind
rope($s.loc.storage), symStr.add ", \"name\": "
rope($s.loc.flags), symStr.add s.name.s
s.loc.r symStr.add ", \"id\": "
]) symStr.add s.id
# [istr, symToYaml(conf, n.sym, indent, maxRecDepth), if s.kind in {skField, skEnumField, skParam}:
# rope(n.sym.id)]) symStr.add ", \"position\": "
symStr.add s.position
addf(result, ",$N$1\"sym\": {$2}", [
istr, rope(symStr)])
if renderType and n.sym.typ != nil: if renderType and n.sym.typ != nil:
addf(result, ",$N$1\"typ\": $2", [istr, debugType(conf, n.sym.typ, 2)]) addf(result, ",$N$1\"typ\": $2", [istr, debugType(conf, n.sym.typ, 2)])
of nkIdent: of nkIdent: