[Libre-soc-bugs] [Bug 980] Implement C-based Power ISA pseudocode compiler

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Fri Jan 5 15:15:03 GMT 2024


https://bugs.libre-soc.org/show_bug.cgi?id=980

--- Comment #51 from Dmitry Selyutin <ghostmansd at gmail.com> ---
OK, it seems we're able to parse all code EXCEPT functions we had so far. I
used the following quick and dirty script:


def dedent(line):
    if line.startswith("    "):
        return line[4:].rstrip()
    return line.rstrip()

def ignore(line):
    line = line.strip()
    if line.startswith("<!--"):
        return True
    return False

def parse(parser, origin):
    origin = tuple(itertools.filterfalse(ignore, origin))
    tree = parser.parse(code="\n".join(origin))
    stream = io.StringIO()
    for (level, line) in pc_util.pseudocode(tree):
        print(f"{' ' * 4 * level}{line}", file=stream)
    stream.seek(0)
    target = tuple(itertools.filterfalse(ignore, stream))
    return (origin, target)

lexer = pc_lexer.IndentLexer(debug=False)
parser = pc_parser.Parser(lexer=lexer)
pattern = re.compile(r"Pseudo-code:(.*?)(?:Special Registers
Altered|Description):", re.DOTALL)
for path in glob.glob("openpower/isa/*.mdwn"):
    with open(path, "r", encoding="UTF-8") as stream:
        data = stream.read()
    for code in pattern.findall(data):
        (stage0, stage1) = parse(parser, map(dedent, code.split("\n")))
        (stage2, stage3) = parse(parser, map(dedent, stage1))
        stage1 = tuple(map(dedent, itertools.filterfalse(ignore, stage1)))
        stage3 = tuple(map(dedent, itertools.filterfalse(ignore, stage3)))
        assert stage1 == stage2 and stage2 == stage3


As I said, I don't have time to deal with all the creepy stuff around. The
definition of the "creepy stuff" includes "fallthrough" keywords, adding pesudo
tokens like "colons", custom "indent/dedent" filter (which should've been
simpler by order of magnitude), inept rule names, etc. etc.

This already wasted way more efforts and time than it deserved, and that's just
only to make the real AST work. :-)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list