From b4749d8fa48ee065f1e8776e862a9ce330cf4544 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Tue, 17 Oct 2017 23:32:33 +0200 Subject: [PATCH] Add debug code to display a subtree in a friendlier format than repr(). --- lslopt/lslfoldconst.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index e003d15..2695abf 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -25,6 +25,32 @@ import math from lslparse import warning from lslfuncopt import OptimizeFunc, OptimizeArgs, FuncOptSetup + +# Debug +import sys +def print_node(node, indent): + nt = node['nt'] + write = sys.stdout.write + spaces = ' ' * (indent*4+2) + write('%s{ nt:%s\n' % (' '*(indent*4), nt)) + if 't' in node: + write('%s,t:%s\n' % (spaces, node['t'])) + if 'name' in node: + write('%s,name:%s\n' % (spaces, node['name'])) + if 'value' in node: + write('%s,value:%s\n' % (spaces, repr(node['value']))) + + for prop in node: + if prop not in ('ch', 'nt', 't', 'name', 'value','X','SEF'): + write('%s,%s:%s\n' % (spaces, prop, repr(node[prop]))) + if 'ch' in node: + write(spaces + ',ch:[\n') + for subnode in node['ch']: + print_node(subnode, indent+1) + write(spaces + ']\n') + write(' '*(indent*4) + '}\n\n') + + class foldconst(object): def isLocalVar(self, node):