add support for adding extra uninit_regs from html comment
authorJacob Lifshay <programmerjake@gmail.com>
Wed, 24 May 2023 02:24:34 +0000 (19:24 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Wed, 24 May 2023 02:24:34 +0000 (19:24 -0700)
I chose an html comment since it's not part of the proposed pseudocode

like so:
* blah RT,RA
Pseudo-code:

<!-- EXTRA_UNINIT_REGS: RT -->
    if rand() then
        RT <- 42 + (RA)

src/openpower/decoder/pseudo/pagereader.py
src/openpower/decoder/pseudo/pywriter.py

index 71301f2f6d3e05154039f2b4309d5f7807a8b517..b2fca28e8b030b59a131797f545abbc3d81e090e 100644 (file)
@@ -45,12 +45,14 @@ this translates to:
 """
 
 from openpower.util import log
+from openpower.decoder.orderedset import OrderedSet
 from collections import namedtuple, OrderedDict
 from copy import copy
 import os
 import re
 
-opfields = ("desc", "form", "opcode", "regs", "pcode", "sregs", "page")
+opfields = ("desc", "form", "opcode", "regs", "pcode", "sregs", "page",
+            "extra_uninit_regs")
 Ops = namedtuple("Ops", opfields)
 
 
@@ -302,6 +304,8 @@ class ISA:
                 print(repr(l))
             assert len(l) == 0, ("blank line not found %s" % l)
 
+            extra_uninit_regs = OrderedSet()
+
             # get pseudocode
 
             # fix parser line numbers by prepending the right number of
@@ -314,6 +318,13 @@ class ISA:
                 if len(l) == 0:
                     li.append(l)
                     break
+                re_match = re.fullmatch(r" *<!-- EXTRA_UNINIT_REGS:(.*)-->", l)
+                if re_match:
+                    for i in re_match[1].split(' '):
+                        if i != "":
+                            extra_uninit_regs.add(i)
+                    li.append("")
+                    continue
                 if l.strip().startswith('<!--'):
                     li.append("")
                     continue
@@ -321,6 +332,7 @@ class ISA:
                 l = l[4:]  # lose 4 spaces
                 li.append(l)
             d['pcode'] = li
+            d['extra_uninit_regs'] = extra_uninit_regs
 
             # "Special Registers Altered" expected
             l = lines.pop(0).rstrip()
index b2f39186e0ccdb9fba42b390873206bc464bc142..a45ca07917f34ae7870ef9dd92f5a29c057e37bb 100644 (file)
@@ -82,6 +82,7 @@ class PyISAWriter(ISA):
                 filename = os.path.join(get_isa_dir(), pagename + ".mdwn")
                 pycode, rused = convert_to_python(pcode, d.form, incl_carry,
                                                   filename=filename)
+                rused['uninit_regs'] |= d.extra_uninit_regs
                 # create list of arguments to call
                 regs = list(rused['read_regs']) + list(rused['uninit_regs'])
                 regs += list(rused['special_regs'])