instructionstocases.py 824 Bytes
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
"""
Generate match cases to match against instructions.
"""

from refimpl2injectablefiles import _refimpl2_root
import injecttools

import os.path, sys
import re

case_class_r = re.compile(r'case class (\w+)\(([^)]*)\)', re.MULTILINE)

param_r = re.compile(r'va[lr]\s+(\w+)\s*:\s*([a-zA-Z0-9\[\]_]+)', re.MULTILINE)

ssavariables_path = os.path.join(_refimpl2_root, "src/main/scala/uvm/ssavariables/ssavariables.scala")

def main():
    with open(ssavariables_path) as f:
        txt = f.read()

    txt = injecttools.extract_lines(txt, "EXTRACT:BEGIN:INSTS", "EXTRACT:END:INSTS")

    for name, params in case_class_r.findall(txt):
        pns = []
        for pn, pt in param_r.findall(params):
            pns.append(pn)

        print("case {}({}) => ".format(name, ", ".join(pns)))

if __name__=="__main__":
    main()