From: Luke Kenneth Casson Leighton Date: Tue, 30 Jun 2020 11:31:42 +0000 (+0100) Subject: add in pseudocode keyword into mdwn isa files X-Git-Tag: div_pipeline~194 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d7b33b3682b9bdd4139bc329c9ce7587c4c3198e;p=soc.git add in pseudocode keyword into mdwn isa files --- diff --git a/libreriscv b/libreriscv index a2df7a1b..34254f4b 160000 --- a/libreriscv +++ b/libreriscv @@ -1 +1 @@ -Subproject commit a2df7a1b8dc03e7e0b146aad074ef6cd2584d602 +Subproject commit 34254f4b3c7c7ceb49fbf806014f0d90eee9011a diff --git a/src/soc/decoder/pseudo/pagereader.py b/src/soc/decoder/pseudo/pagereader.py index f9e15349..b7e978dd 100644 --- a/src/soc/decoder/pseudo/pagereader.py +++ b/src/soc/decoder/pseudo/pagereader.py @@ -71,16 +71,97 @@ class ISA: print (get_isa_dir(), pth) assert pth.endswith(".mdwn"), "only %s in isa dir" % pth self.read_file(pth) + continue + # code which helped add in the keyword "Pseudo-code:" automatically + rewrite = self.read_file_for_rewrite(pth) + name = os.path.join("/tmp", pth) + with open(name, "w") as f: + f.write('\n'.join(rewrite) + '\n') + + def read_file_for_rewrite(self, fname): + pagename = fname.split('.')[0] + fname = os.path.join(get_isa_dir(), fname) + with open(fname) as f: + lines = f.readlines() + rewrite = [] + + l = lines.pop(0).rstrip() # get first line + rewrite.append(l) + while lines: + print (l) + # expect get heading + assert l.startswith('#'), ("# not found in line %s" % l) + + # whitespace expected + l = lines.pop(0).strip() + print (repr(l)) + assert len(l) == 0, ("blank line not found %s" % l) + rewrite.append(l) + + # Form expected + l = lines.pop(0).strip() + assert l.endswith('-Form'), ("line with -Form expected %s" % l) + rewrite.append(l) + + # whitespace expected + l = lines.pop(0).strip() + assert len(l) == 0, ("blank line not found %s" % l) + rewrite.append(l) + + # get list of opcodes + while True: + l = lines.pop(0).strip() + rewrite.append(l) + if len(l) == 0: break + assert l.startswith('*'), ("* not found in line %s" % l) + + rewrite.append("Pseudo-code:") + rewrite.append("") + # get pseudocode + while True: + l = lines.pop(0).rstrip() + rewrite.append(l) + if len(l) == 0: break + assert l.startswith(' '), ("4spcs not found in line %s" % l) + + # "Special Registers Altered" expected + l = lines.pop(0).rstrip() + assert l.startswith("Special"), ("special not found %s" % l) + rewrite.append(l) + + # whitespace expected + l = lines.pop(0).strip() + assert len(l) == 0, ("blank line not found %s" % l) + rewrite.append(l) + + # get special regs + while lines: + l = lines.pop(0).rstrip() + rewrite.append(l) + if len(l) == 0: break + assert l.startswith(' '), ("4spcs not found in line %s" % l) + + # expect and drop whitespace + while lines: + l = lines.pop(0).rstrip() + rewrite.append(l) + if len(l) != 0: break + + return rewrite def read_file(self, fname): pagename = fname.split('.')[0] fname = os.path.join(get_isa_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) @@ -113,6 +194,15 @@ class ISA: li.append(list(l)) opcodes = li + # "Pseudocode" expected + l = lines.pop(0).rstrip() + assert l.startswith("Pseudo-code:"), ("pseudocode found %s" % l) + + # whitespace expected + l = lines.pop(0).strip() + print (repr(l)) + assert len(l) == 0, ("blank line not found %s" % l) + # get pseudocode li = [] while True: