From 12946b8316bedf517145eb73b23d827c250fd105 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 16 May 2021 13:58:52 +0100 Subject: [PATCH] add function reader for appendix and other v3.0B pseudocode --- .../decoder/pseudo/functionreader.py | 102 ++++++++++++++++++ src/openpower/decoder/pseudo/pagereader.py | 2 +- 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/openpower/decoder/pseudo/functionreader.py diff --git a/src/openpower/decoder/pseudo/functionreader.py b/src/openpower/decoder/pseudo/functionreader.py new file mode 100644 index 00000000..4447fde2 --- /dev/null +++ b/src/openpower/decoder/pseudo/functionreader.py @@ -0,0 +1,102 @@ +# Reads OpenPOWER ISA pages from http://libre-soc.org/openpower/isafunctions +"""OpenPOWER ISA function reader + +reads markdown files looking for indented code blocks +""" + +from collections import OrderedDict +from copy import copy +import os + + +def get_isafn_dir(): + fdir = os.path.abspath(os.path.dirname(__file__)) + fdir = os.path.split(fdir)[0] + fdir = os.path.split(fdir)[0] + fdir = os.path.split(fdir)[0] + fdir = os.path.split(fdir)[0] + print (fdir) + return os.path.join(fdir, "openpower", "isafunctions") + + +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) + if "swp" in pth: + continue + if not pth.endswith(".mdwn"): + print ("warning, file not .mdwn, skipping", pth) + continue + self.read_file(pth) + + def read_file(self, fname): + pagename = fname.split('.')[0] + fname = os.path.join(get_isafn_dir(), fname) + with open(fname) as f: + lines = f.readlines() + + # set up dict with current page name + d = {'page': pagename} + + # line-by-line lexer/parser, quite straightforward: pops one + # line off the list and checks it. nothing complicated needed, + # all sections are mandatory so no need for a full LALR parser. + + l = lines.pop(0).rstrip() # get first line + while lines: + print(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: + # + # + if l.startswith('