decoder: replace print with log
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 3 Dec 2023 10:21:22 +0000 (13:21 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 3 Dec 2023 11:35:13 +0000 (14:35 +0300)
src/openpower/decoder/power_pseudo.py
src/openpower/decoder/pseudo/functionreader.py
src/openpower/decoder/pseudo/lexer.py
src/openpower/decoder/pseudo/pagereader.py
src/openpower/decoder/pseudo/parser.py
src/openpower/decoder/pseudo/pyfnwriter.py
src/openpower/decoder/pseudo/pywriter.py

index 8feb80df4c7d21d0c2d777c0b7f37097dc3c9245..e9dcbd550d5157067172b841f5e389bf29c991c3 100644 (file)
@@ -22,6 +22,7 @@ from nmigen import Module, Signal
 from openpower.decoder.pseudo.parser import GardenSnakeCompiler
 from openpower.decoder.selectable_int import SelectableInt, selectconcat
 from openpower.decoder.isa.caller import GPR, Mem
+from openpower.util import log
 
 
 ####### Test code #######
@@ -268,8 +269,7 @@ def convert_to_pure_python(pcode, helper=False, filename="string"):
 
 
 def convert_to_python(pcode, form, incl_carry, helper=False, filename="string"):
-
-    print("form", form)
+    log("form", form)
     gsc = GardenSnakeCompiler(form=form, incl_carry=incl_carry, helper=helper)
 
     tree = gsc.compile(pcode, mode="exec", filename=filename)
@@ -312,20 +312,20 @@ def test():
 
     tree = _compile(code, mode="single", filename="string")
     tree = ast.fix_missing_locations(tree)
-    print(ast.dump(tree))
+    log(ast.dump(tree))
 
-    print("astor dump")
-    print(astor.dump_tree(tree))
-    print("to source")
+    log("astor dump")
+    log(astor.dump_tree(tree))
+    log("to source")
     source = astor.to_source(tree)
-    print(source)
+    log(source)
 
     # sys.exit(0)
 
     # Set up the GardenSnake run-time environment
     def print_(*args):
-        print("args", args)
-        print("-->", " ".join(map(str, args)))
+        log("args", args)
+        log("-->", " ".join(map(str, args)))
 
     from openpower.decoder.helpers import (EXTS64, EXTZ64, ROTL64, ROTL32, MASK,
                                      trunc_div, trunc_rem)
@@ -364,7 +364,7 @@ def test():
 
     def process():
         for ins in instr:
-            print("0x{:X}".format(ins & 0xffffffff))
+            log("0x{:X}".format(ins & 0xffffffff))
 
             # ask the decoder to decode this binary data (endian'd)
             yield decode.bigendian.eq(0)  # little / big?
@@ -374,32 +374,32 @@ def test():
             # uninitialised regs, drop them into dict for function
             for rname in gsc.parser.uninit_regs:
                 d[rname] = SelectableInt(0, 64)  # uninitialised (to zero)
-                print("uninitialised", rname, hex(d[rname].value))
+                log("uninitialised", rname, hex(d[rname].value))
 
             # read regs, drop them into dict for function
             for rname in gsc.parser.read_regs:
                 regidx = yield getattr(decode.sigforms['X'], rname)
                 d[rname] = gsc.gpr[regidx]  # contents of regfile
                 d["_%s" % rname] = regidx  # actual register value
-                print("read reg", rname, regidx, hex(d[rname].value))
+                log("read reg", rname, regidx, hex(d[rname].value))
 
             exec(compiled_code, d)  # code gets executed here in dict "d"
-            print("Done")
+            log("Done")
 
-            print(d.keys())  # shows the variables that may have been created
+            log(d.keys())  # shows the variables that may have been created
 
-            print(decode.sigforms['X'])
+            log(decode.sigforms['X'])
             x = yield decode.sigforms['X'].RS
             ra = yield decode.sigforms['X'].RA
             rb = yield decode.sigforms['X'].RB
-            print("RA", ra, d['RA'])
-            print("RB", rb, d['RB'])
-            print("RS", x)
+            log("RA", ra, d['RA'])
+            log("RB", rb, d['RB'])
+            log("RS", x)
 
             for wname in gsc.parser.write_regs:
                 reg = getform[wname]
                 regidx = yield reg
-                print("write regs", regidx, wname, d[wname], reg)
+                log("write regs", regidx, wname, d[wname], reg)
                 gsc.gpr[regidx] = d[wname]
 
     sim.add_process(process)
@@ -414,7 +414,7 @@ def test():
         for j in range(16):
             hexstr.append("%02x" % gsc.mem.mem[i+j])
         hexstr = ' '.join(hexstr)
-        print("mem %4x" % i, hexstr)
+        log("mem %4x" % i, hexstr)
 
 
 if __name__ == '__main__':
index 4e06523964fcd5741b41b2d825d3e45f5bcc88a1..14eefbd14337f6afc8175ee0a51b99e7dad5aba4 100644 (file)
@@ -8,6 +8,8 @@ from collections import OrderedDict
 from copy import copy
 import os
 
+from openpower.util import log
+
 
 def get_isafn_dir():
     fdir = os.path.abspath(os.path.dirname(__file__))
@@ -15,7 +17,7 @@ def get_isafn_dir():
     fdir = os.path.split(fdir)[0]
     fdir = os.path.split(fdir)[0]
     fdir = os.path.split(fdir)[0]
-    print (fdir)
+    log(fdir)
     return os.path.join(fdir, "openpower", "isafunctions")
 
 
@@ -24,11 +26,11 @@ class ISAFunctions:
     def __init__(self):
         self.fns = OrderedDict()
         for pth in os.listdir(os.path.join(get_isafn_dir())):
-            print("examining", get_isafn_dir(), pth)
+            log("examining", get_isafn_dir(), pth)
             if "swp" in pth:
                 continue
             if not pth.endswith(".mdwn"):
-                print ("warning, file not .mdwn, skipping", pth)
+                log ("warning, file not .mdwn, skipping", pth)
                 continue
             self.read_file(pth)
 
@@ -48,14 +50,14 @@ class ISAFunctions:
         l = lines.pop(0).rstrip()  # get first line
         prefix_lines = 0
         while lines:
-            print(l)
+            log(l)
             # look for HTML comment, if starting, skip line.
             # XXX this is braindead!  it doesn't look for the end
             # so please put ending of comments on one line:
             # <!-- line 1 comment -->
             # <!-- line 2 comment -->
             if l.strip().startswith('<!--'):
-                # print ("skipping comment", l)
+                # log ("skipping comment", l)
                 l = lines.pop(0).rstrip()  # get next line
                 prefix_lines += 1
                 continue
@@ -74,7 +76,7 @@ class ISAFunctions:
             while True:
                 l = lines.pop(0).rstrip()
                 prefix_lines += 1
-                print ("examining", repr(l))
+                log ("examining", repr(l))
                 if l.startswith("    "):
                     break
                 if l.startswith('<!--'):
@@ -88,7 +90,7 @@ class ISAFunctions:
             li += [l[4:]]  # first line detected with 4-space
             while lines:
                 l = lines.pop(0).rstrip()
-                print ("examining", repr(l))
+                log ("examining", repr(l))
                 if len(l) == 0:
                     li.append(l)
                     continue
@@ -105,9 +107,9 @@ class ISAFunctions:
 
     def pprint(self):
         for k, v in self.fns.items():
-            print("# %s %s" % (k, v['desc']))
-            print(v['pcode'])
-            print()
+            log("# %s %s" % (k, v['desc']))
+            log(v['pcode'])
+            log()
 
 
 if __name__ == '__main__':
index c42f8330e5fde38f82ef37c6cba1b0077c207a4c..b501e56f35e6f441bc765061399d78230c1f926d 100644 (file)
@@ -11,6 +11,7 @@
 from copy import copy
 from ply import lex
 from openpower.decoder.selectable_int import SelectableInt
+from openpower.util import log
 
 
 class SyntaxError2(Exception):
@@ -69,7 +70,7 @@ def python_colonify(lexer, tokens):
 
     implied_colon_needed = False
     for token in tokens:
-        #print ("track colon token", token, token.type)
+        #log ("track colon token", token, token.type)
 
         if token.type == 'THEN':
             # turn then into colon
@@ -101,7 +102,7 @@ def track_tokens_filter(lexer, tokens):
     indent = NO_INDENT
     saw_colon = False
     for token in tokens:
-        #print ("track token", token, token.type)
+        #log ("track token", token, token.type)
         token.at_line_start = at_line_start
 
         if token.type == "COLON":
@@ -195,14 +196,14 @@ def annoying_case_hack_filter(code):
             res.append('')
             continue
         if nwhite.startswith("case") or nwhite.startswith("default"):
-            #print ("case/default", nwhite, spc_count, prev_spc_count)
+            #log ("case/default", nwhite, spc_count, prev_spc_count)
             if (prev_spc_count is not None and
                 prev_spc_count == spc_count and
                     (res[-1].endswith(":") or res[-1].endswith(": fallthrough"))):
                 res[-1] += " fallthrough"  # add to previous line
             prev_spc_count = spc_count
         else:
-            #print ("notstarts", spc_count, nwhite)
+            #log ("notstarts", spc_count, nwhite)
             prev_spc_count = None
         res.append(l)
     return '\n'.join(res)
@@ -217,12 +218,11 @@ def indentation_filter(tokens, filename):
     prev_was_ws = False
     for token in tokens:
         if 0:
-            print("Process", depth, token.indent, token,)
+            log("Process", depth, token.indent, token,)
             if token.at_line_start:
-                print("at_line_start",)
+                log("at_line_start",)
             if token.must_indent:
-                print("must_indent",)
-            print
+                log("must_indent",)
 
         # WS only occurs at the start of the line
         # There may be WS followed by NEWLINE so
@@ -399,7 +399,7 @@ class PowerLexer:
 
     def t_STRING(self, t):
         r"'([^\\']+|\\'|\\\\)*'"  # I think this is right ...
-        print(repr(t.value))
+        log(repr(t.value))
         t.value = t.value[1:-1]
         return t
 
@@ -509,7 +509,7 @@ class PowerLexer:
         raise_syntax_error("Unknown symbol %r" % (t.value[0],),
                            self.filename, t.lexer.lineno,
                            t.lexer.lexpos, t.lexer.lexdata)
-        print("Skipping", repr(t.value[0]))
+        log("Skipping", repr(t.value[0]))
         t.lexer.skip(1)
 
 
@@ -525,7 +525,7 @@ class IndentLexer(PowerLexer):
     def input(self, s, add_endmarker=True):
         s = annoying_case_hack_filter(s)
         if self.debug:
-            print(s)
+            log(s)
         s += "\n"
         self.lexer.paren_count = 0
         self.lexer.brack_count = 0
@@ -570,14 +570,14 @@ if __name__ == '__main__':
     # quick test/demo
     #code = cnttzd
     code = switchtest
-    print(code)
+    log(code)
 
     lexer = IndentLexer(debug=1)
     # Give the lexer some input
-    print("code")
-    print(code)
+    log("code")
+    log(code)
     lexer.input(code)
 
     tokens = iter(lexer.token, None)
     for token in tokens:
-        print(token)
+        log(token)
index 736034f459898d7a3c4474c7cfeead62eed4f1a7..3241b60b0fea8b632a8749cae485ed586129d217 100644 (file)
@@ -46,6 +46,8 @@ this translates to:
 
 from openpower.util import log
 from openpower.decoder.orderedset import OrderedSet
+from openpower.util import log
+
 from collections import namedtuple, OrderedDict
 from copy import copy
 import os
@@ -62,7 +64,7 @@ def get_isa_dir():
     fdir = os.path.split(fdir)[0]
     fdir = os.path.split(fdir)[0]
     fdir = os.path.split(fdir)[0]
-    # print (fdir)
+    # log (fdir)
     return os.path.join(fdir, "openpower", "isa")
 
 
@@ -121,7 +123,7 @@ class ISA:
         self.verbose = False
         for pth in os.listdir(os.path.join(get_isa_dir())):
             if self.verbose:
-                print("examining", get_isa_dir(), pth)
+                log("examining", get_isa_dir(), pth)
             if "swp" in pth:
                 continue
             if not pth.endswith(".mdwn"):
@@ -150,14 +152,14 @@ class ISA:
         rewrite.append(l)
         while lines:
             if self.verbose:
-                print(l)
+                log(l)
             # look for HTML comment, if starting, skip line.
             # XXX this is braindead!  it doesn't look for the end
             # so please put ending of comments on one line:
             # <!-- line 1 comment -->
             # {some whitespace}<!-- line 2 comment -->
             if l.strip().startswith('<!--'):
-                # print ("skipping comment", l)
+                # log ("skipping comment", l)
                 l = lines.pop(0).rstrip()  # get first line
                 continue
 
@@ -171,7 +173,7 @@ class ISA:
             # whitespace expected
             l = lines.pop(0).strip()
             if self.verbose:
-                print(repr(l))
+                log(repr(l))
             assert len(l) == 0, ("blank line not found %s" % l)
             rewrite.append(l)
 
@@ -199,7 +201,7 @@ class ISA:
             while True:
                 l = lines.pop(0).rstrip()
                 if l.strip().startswith('<!--'):
-                    # print ("skipping comment", l)
+                    # log ("skipping comment", l)
                     l = lines.pop(0).rstrip()  # get first line
                     continue
                 rewrite.append(l)
@@ -250,14 +252,14 @@ class ISA:
         l = lines.pop(0).rstrip()  # get first line
         while lines:
             if self.verbose:
-                print(l)
+                log(l)
             # look for HTML comment, if starting, skip line.
             # XXX this is braindead!  it doesn't look for the end
             # so please put ending of comments on one line:
             # <!-- line 1 comment -->
             # <!-- line 2 comment -->
             if l.strip().startswith('<!--'):
-                # print ("skipping comment", l)
+                # log ("skipping comment", l)
                 l = lines.pop(0).rstrip()  # get next line
                 continue
 
@@ -273,7 +275,7 @@ class ISA:
             # whitespace expected
             l = lines.pop(0).strip()
             if self.verbose:
-                print(repr(l))
+                log(repr(l))
             assert len(l) == 0, ("blank line not found %s" % l)
 
             # Form expected
@@ -314,7 +316,7 @@ class ISA:
             # whitespace expected
             l = lines.pop(0).strip()
             if self.verbose:
-                print(repr(l))
+                log(repr(l))
             assert len(l) == 0, ("blank line not found %s" % l)
 
             extra_uninit_regs = OrderedSet()
@@ -374,20 +376,20 @@ class ISA:
         pl = self.page.get(page, [])
         self.page[page] = pl + [opcode]
 
-    def pprint_ops(self):
+    def plog_ops(self):
         for k, v in self.instr.items():
-            print("# %s %s" % (v.opcode, v.desc))
-            print("Form: %s Regs: %s" % (v.form, v.regs))
-            print('\n'.join(map(lambda x: "    %s" % x, v.pcode)))
-            print("Specials")
-            print('\n'.join(map(lambda x: "    %s" % x, v.sregs)))
-            print()
+            log("# %s %s" % (v.opcode, v.desc))
+            log("Form: %s Regs: %s" % (v.form, v.regs))
+            log('\n'.join(map(lambda x: "    %s" % x, v.pcode)))
+            log("Specials")
+            log('\n'.join(map(lambda x: "    %s" % x, v.sregs)))
+            log()
         for k, v in isa.forms.items():
-            print(k, v)
+            log(k, v)
 
 
 if __name__ == '__main__':
     isa = ISA()
-    isa.pprint_ops()
+    isa.plog_ops()
     # example on how to access cmp regs:
-    print ("cmp regs:", isa.instr["cmp"].regs)
+    log ("cmp regs:", isa.instr["cmp"].regs)
index 4a168041e6ea2f71c2830b5105abd04ba8a79250..b7d3ecb58fad542757d2985b9c7d1707863ba1fd 100644 (file)
@@ -18,6 +18,7 @@ from openpower.decoder.pseudo.lexer import (
     IndentLexer, raise_syntax_error, SyntaxError2)
 from openpower.decoder.orderedset import OrderedSet
 from openpower.decoder.power_enums import BFP_FLAG_NAMES
+from openpower.util import log
 
 # I use the Python AST
 #from compiler import ast
@@ -107,11 +108,11 @@ unary_ops = {
 
 
 def check_concat(node):  # checks if the comparison is already a concat
-    print("check concat", node)
+    log("check concat", node)
     if not isinstance(node, ast.Call):
         return [node]
     node_func_id = getattr(node.func, "id", None)
-    print("func", node_func_id)
+    log("func", node_func_id)
     if node_func_id != 'concat':
         return [node]
     if node.keywords:  # a repeated list-constant, don't optimise
@@ -129,9 +130,9 @@ def identify_sint_mul_pattern(p):
         [item] * something
     these must specifically be returned as concat(item, repeat=something)
     """
-    #print ("identify_sint_mul_pattern")
+    #log ("identify_sint_mul_pattern")
     # for pat in p:
-    #    print("    ", astor.dump_tree(pat))
+    #    log("    ", astor.dump_tree(pat))
     if p[2] != '*':  # multiply
         return False
     if (not isinstance(p[3], ast.Constant) and  # rhs = Num
@@ -196,7 +197,7 @@ class PowerParser:
         self.gprs = {}
         if self.form is not None:
             form = self.sd.sigforms[self.form]
-            print(form)
+            log(form)
             formkeys = form._asdict().keys()
         else:
             formkeys = []
@@ -232,7 +233,7 @@ class PowerParser:
 
     def p_file_input_end(self, p):
         """file_input_end : file_input ENDMARKER"""
-        print("end", p[1])
+        log("end", p[1])
         p[0] = p[1]
 
     def p_file_input(self, p):
@@ -275,7 +276,7 @@ class PowerParser:
         # in-scope, for use to not overwrite them with auto-assign
         self.fnparm_vars = set()
         for arg in args:
-            print("adding fn parm", arg)
+            log("adding fn parm", arg)
             self.fnparm_vars.add(arg)
 
     # varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] |
@@ -286,7 +287,7 @@ class PowerParser:
         """varargslist : varargslist COMMA NAME
                        | NAME"""
         if len(p) == 4:
-            print(p[1], p[3])
+            log(p[1], p[3])
             p[0] = p[1] + [p[3]]
         else:
             p[0] = [p[1]]
@@ -343,7 +344,7 @@ class PowerParser:
         """expr_stmt : testlist ASSIGNEA testlist
                      | testlist ASSIGN testlist
                      | testlist """
-        print("expr_stmt", p)
+        log("expr_stmt", p)
         if len(p) == 2:
             # a list of expressions
             #p[0] = ast.Discard(p[1])
@@ -351,21 +352,21 @@ class PowerParser:
         else:
             iea_mode = p[2] == '<-iea'
             if iea_mode:
-                print ("iea_mode")
+                log ("iea_mode")
             name = None
             autoassign = False
             if isinstance(p[1], ast.Name):
                 name = p[1].id
             elif isinstance(p[1], ast.Subscript):
-                print("assign subscript", p[1].value,
+                log("assign subscript", p[1].value,
                       self.declared_vars,
                       self.fnparm_vars,
                       self.special_regs)
-                print(astor.dump_tree(p[1]))
-                print(astor.dump_tree(p[3]))
+                log(astor.dump_tree(p[1]))
+                log(astor.dump_tree(p[3]))
                 if isinstance(p[1].value, ast.Name):
                     name = p[1].value.id
-                    print("assign subscript value to name", name)
+                    log("assign subscript value to name", name)
                     if name in self.gprs:
                         # add to list of uninitialised
                         self.uninit_regs.add(name)
@@ -378,7 +379,7 @@ class PowerParser:
                 pass
             elif isinstance(p[1], ast.Call) and p[1].func.id in \
                     ['GPR', 'FPR', 'SPR']:
-                print(astor.dump_tree(p[1]))
+                log(astor.dump_tree(p[1]))
                 # replace GPR(x) with GPR[x]
                 idx = p[1].args[0].id
                 if idx in regs + fregs:
@@ -389,21 +390,21 @@ class PowerParser:
                 if idx in self.gprs:
                     self.read_regs.add(idx)  # add to list of regs to read
             elif isinstance(p[1], ast.Call) and p[1].func.id == 'MEM':
-                print("mem assign")
-                print(astor.dump_tree(p[1]))
+                log("mem assign")
+                log(astor.dump_tree(p[1]))
                 p[1].func.id = "memassign"  # change function name to set
                 p[1].args.append(p[3])
                 p[0] = p[1]
-                print("mem rewrite")
-                print(astor.dump_tree(p[0]))
+                log("mem rewrite")
+                log(astor.dump_tree(p[0]))
                 return
             else:
-                print(astor.dump_tree(p[1]))
+                log(astor.dump_tree(p[1]))
                 raise_syntax_error("help, help", self.filename,
                                    p.slice[2].lineno, p.slice[2].lexpos,
                                    self.input_text)
-            print("expr assign", name, p[1], "to", p[3])
-            print(astor.dump_tree(p[3]))
+            log("expr assign", name, p[1], "to", p[3])
+            log(astor.dump_tree(p[3]))
             if isinstance(p[3], ast.Name):
                 toname = p[3].id
                 if toname in self.gprs:
@@ -465,13 +466,13 @@ class PowerParser:
         """switch_stmt : SWITCH LPAR atom RPAR COLON NEWLINE INDENT switches DEDENT
         """
         switchon = p[3]
-        print("switch stmt")
-        print(astor.dump_tree(p[1]))
+        log("switch stmt")
+        log(astor.dump_tree(p[1]))
 
         cases = []
         current_cases = []  # for deferral
         for (case, suite) in p[8]:
-            print("for", case, suite)
+            log("for", case, suite)
             if suite is None:
                 for c in case:
                     current_cases.append(ast.Num(c))
@@ -480,13 +481,13 @@ class PowerParser:
                 break
             for c in case:
                 current_cases.append(ast.Num(c))
-            print("cases", current_cases)
+            log("cases", current_cases)
             compare = ast.Compare(switchon, [ast.In()],
                                   [ast.List(current_cases, ast.Load())])
             current_cases = []
             cases.append((compare, suite))
 
-        print("ended", case, current_cases)
+        log("ended", case, current_cases)
         if case == 'default':
             if current_cases:
                 compare = ast.Compare(switchon, [ast.In()],
@@ -497,7 +498,7 @@ class PowerParser:
         cases.reverse()
         res = []
         for compare, suite in cases:
-            print("after rev", compare, suite)
+            log("after rev", compare, suite)
             if compare is None:
                 assert len(res) == 0, "last case should be default"
                 res = suite
@@ -601,7 +602,7 @@ class PowerParser:
                       | comparison APPEND comparison
                       | power"""
         if len(p) == 4:
-            print(list(p))
+            log(list(p))
             if p[2] == '<u':
                 p[0] = ast.Call(ast.Name("ltu", ast.Load()), (p[1], p[3]), [])
             elif p[2] == '>u':
@@ -655,14 +656,14 @@ class PowerParser:
         """power : atom
                  | atom trailerlist"""
         if len(p) == 2:
-            print("power dump atom notrailer")
-            print(astor.dump_tree(p[1]))
+            log("power dump atom notrailer")
+            log(astor.dump_tree(p[1]))
             p[0] = p[1]
         else:
-            print("power dump atom")
-            print(astor.dump_tree(p[1]))
-            print("power dump trailerlist")
-            print(astor.dump_tree(p[2]))
+            log("power dump atom")
+            log(astor.dump_tree(p[1]))
+            log("power dump trailerlist")
+            log(astor.dump_tree(p[2]))
             p[0] = self.apply_trailer(p[1], p[2], self.read_regs)
             if isinstance(p[1], ast.Name):
                 name = p[1].id
@@ -720,13 +721,13 @@ class PowerParser:
 
     def p_atom_tuple(self, p):
         """atom : LPAR testlist RPAR"""
-        print("tuple", p[2])
-        print("astor dump")
-        print(astor.dump_tree(p[2]))
+        log("tuple", p[2])
+        log("astor dump")
+        log(astor.dump_tree(p[2]))
 
         if isinstance(p[2], ast.Name):
             name = p[2].id
-            print("tuple name", name)
+            log("tuple name", name)
             if name in self.gprs:
                 self.read_regs.add(name)  # add to list of regs to read
                 #p[0] = ast.Subscript(ast.Name("GPR", ast.Load()), ast.Str(p[2].id))
@@ -749,7 +750,7 @@ class PowerParser:
                 # *sigh* see class GPR.  we need index itself not reg value
                 ridx = ast.Name("_%s" % rid, ast.Load())
                 p[0] = ast.Call(gprz, [ridx], [])
-                print("tree", astor.dump_tree(p[0]))
+                log("tree", astor.dump_tree(p[0]))
             else:
                 p[0] = p[2]
         else:
@@ -863,13 +864,13 @@ class PowerParser:
         p[0] = p[1]
 
     def p_error(self, p):
-        # print "Error!", repr(p)
+        # log("Error!", repr(p))
         raise_syntax_error(str(p), self.filename, p.lineno, p.lexpos,
                            self.input_text)
 
     def Assign(self, autoassign, assignname, left, right, iea_mode, eq_tok):
         names = []
-        print("Assign", autoassign, assignname, left, right)
+        log("Assign", autoassign, assignname, left, right)
         if isinstance(left, ast.Name):
             # Single assignment on left
             # XXX when doing IntClass, which will have an "eq" function,
@@ -907,7 +908,7 @@ class PowerParser:
                 #       dividend[0:32] = (RA)[0:32]
                 # the declaration makes the slice-assignment "work"
                 lower, upper, step = ls.lower, ls.upper, ls.step
-                print("lower, upper, step", repr(lower), repr(upper), step)
+                log("lower, upper, step", repr(lower), repr(upper), step)
                 # XXX relax constraint that indices on auto-assign have
                 # to be constants x[0:32]
                 # if not isinstance(lower, ast.Constant) or \
@@ -925,7 +926,7 @@ class PowerParser:
             ls = left.slice
             if isinstance(ls, ast.Slice):
                 lower, upper, step = ls.lower, ls.upper, ls.step
-                print("slice assign", lower, upper, step)
+                log("slice assign", lower, upper, step)
                 if step is None:
                     ls = (lower, upper, None)
                 else:
@@ -934,7 +935,7 @@ class PowerParser:
             return ast.Call(ast.Name("selectassign", ast.Load()),
                             [left.value, ls, right], [])
         else:
-            print("Assign fail")
+            log("Assign fail")
             raise_syntax_error("Can't do that yet", self.filename,
                                eq_tok.lineno, eq_tok.lexpos, self.input_text)
 
@@ -1008,7 +1009,7 @@ class PowerParser:
             if attr is not None:
                 return ast.Attribute(atom, attr, ast.Load())
             assert trailer[0] == "SUBS"
-            print("subscript atom", trailer[1])
+            log("subscript atom", trailer[1])
             #raise AssertionError("not implemented %s" % p[2][0])
             subs = trailer[1]
             if len(subs) == 1:
@@ -1016,13 +1017,13 @@ class PowerParser:
                 if isinstance(idx, ast.Name) and idx.id in regs + fregs:
                     read_regs.add(idx.id)
                 if isinstance(idx, ast.Name) and idx.id in regs:
-                    print("single atom subscript, underscored", idx.id)
+                    log("single atom subscript, underscored", idx.id)
                     idx = ast.Name("_%s" % idx.id, ast.Load())
             else:
                 idx = ast.Slice(subs[0], subs[1], None)
             # if isinstance(atom, ast.Name) and atom.id == 'CR':
                 # atom.id = 'CR' # bad hack
-                #print ("apply_trailer Subscript", atom.id, idx)
+                #log ("apply_trailer Subscript", atom.id, idx)
             return ast.Subscript(atom, idx, ast.Load())
 
 
@@ -1091,8 +1092,8 @@ class GardenSnakeCompiler(object):
             tree = self.parser.parse(code)
         except SyntaxError2 as e:
             e.raise_syntax_error()
-        print("snake")
-        pprint(tree)
+        log("snake")
+        pprint(tree)
         return tree
         #misc.set_filename(filename, tree)
         return compile(tree, mode="exec", filename="<string>")
index 417706a4df0af58f1be1af6c285998a3862a607e..ebb9158fe766106cac2c2f622f6e9610835d27ff 100644 (file)
@@ -7,7 +7,7 @@ import subprocess
 from openpower.decoder.pseudo.functionreader import ISAFunctions, get_isafn_dir
 from openpower.decoder.power_pseudo import (convert_to_pure_python,
                                             check_in_gitignore)
-
+from openpower.util import log
 
 def get_isafn_src_dir():
     fdir = os.path.abspath(os.path.dirname(__file__))
@@ -47,7 +47,7 @@ class PyISAFnWriter(ISAFunctions):
             f.write(header % function['desc'])  # write out header
             # go through all instructions
             pcode = function['pcode']
-            print(pcode)
+            log(pcode)
             # check if the code has already been compiled
             phash = hash(pcode)
             if phash in sourcecache:
@@ -93,14 +93,14 @@ def pyfnwriter():
     isa = PyISAFnWriter()
     write_isa_class = True
     if len(sys.argv) == 1:  # quick way to do it
-        print(dir(isa))
+        log(dir(isa))
         sources = isa.fns.keys()
     else:
         sources = sys.argv[1:]
         if sources[0] == "noall": # don't rewrite all.py
             write_isa_class = False
             sources.pop(0)
-    print ("sources", write_isa_class, sources)
+    log("sources", write_isa_class, sources)
     for source in sources:
         isa.write_pysource(source)
     if write_isa_class:
index 16465822bc4858b2f8eee42f9af2ec3b26afe833..0bf918c84521ccc303c32cf512342aa2485eb65a 100644 (file)
@@ -9,6 +9,7 @@ from openpower.decoder.power_pseudo import (convert_to_python,
                                             check_in_gitignore)
 from openpower.decoder.orderedset import OrderedSet
 from openpower.decoder.isa.caller import create_args, create_full_args
+from openpower.util import log
 
 
 def get_isasrc_dir():
@@ -108,9 +109,9 @@ class PyISAWriter(ISA):
             # go through all instructions
             for page in instrs:
                 d = self.instr[page]
-                print("page", pagename, page, fname, d.opcode)
+                log("page", pagename, page, fname, d.opcode)
                 pcode = '\n'.join(d.pcode) + '\n'
-                print(pcode)
+                log(pcode)
                 incl_carry = pagename == 'fixedshift'
                 filename = os.path.join(get_isa_dir(), pagename + ".mdwn")
                 pycode, rused = convert_to_python(pcode, d.form, incl_carry,
@@ -200,14 +201,14 @@ def pywriter():
     isa = PyISAWriter()
     write_isa_class = True
     if len(sys.argv) == 1:  # quick way to do it
-        print(dir(isa))
+        log(dir(isa))
         sources = isa.page.keys()
     else:
         sources = sys.argv[1:]
         if sources[0] == "noall": # don't rewrite all.py
             write_isa_class = False
             sources.pop(0)
-    print("sources", write_isa_class, sources)
+    log("sources", write_isa_class, sources)
     isa.check_for_old_generated_files(sources)
     for source in sources:
         isa.write_pysource(source)