change to only support fully-split instructions (split pseudocode is still optional)
authorJacob Lifshay <programmerjake@gmail.com>
Mon, 7 Aug 2023 23:02:51 +0000 (16:02 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Mon, 7 Aug 2023 23:06:28 +0000 (16:06 -0700)
src/openpower/decoder/pseudo/pagereader.py

index 5f30b95440edea848262ad7e229d0c304d254508..27fb5a05c508046e14dca681b01ead5d4794f521 100644 (file)
@@ -101,7 +101,7 @@ class ISA:
                 if not os.path.isdir(os.path.join(get_isa_dir(), pth)):
                     log("warning, file not .mdwn, skipping", pth)
                 continue
-            self.read_file(pth)
+            self.read_top_file(pth)
             continue
             # code which helped add in the keyword "Pseudo-code:" automatically
             rewrite = self.read_file_for_rewrite(pth)
@@ -207,12 +207,39 @@ class ISA:
 
         return rewrite
 
-    def read_file(self, fname):
+    def read_top_file(self, fname):
         pagename = fname.split('.')[0]
         fname = os.path.join(get_isa_dir(), fname)
         with open(fname) as f:
             lines = f.readlines()
 
+        for lineno, line in enumerate(lines):
+            # 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:
+            # <!-- line 1 comment -->
+            # <!-- line 2 comment -->
+            line = line.strip()
+            if line.startswith('<!--'):
+                continue
+            if line == "":
+                continue
+            re_match = re.fullmatch(
+                r'\[\[!inline pagenames="openpower/isa/([^" ]*[^"/ ])" '
+                r'raw="yes"]]', line)
+            assert re_match, (
+                f"{fname}:{lineno+1}: error: "
+                'expected [[!inline]] directive, must be of the form:\n'
+                '[[!inline pagenames="openpower/isa/foo/bar" '
+                'raw="yes"]]')
+            insn_fname = re_match[1] + ".mdwn"
+            insn_fname = os.path.join(get_isa_dir(), insn_fname)
+            self.read_file(pagename, insn_fname)
+
+    def read_file(self, pagename, fname):
+        with open(fname) as f:
+            lines = f.readlines()
+
         # set up dict with current page name
         d = {'page': pagename}