1 # Reads OpenPOWER ISA pages from http://libre-soc.org/openpower/isafunctions
2 """OpenPOWER ISA function reader
4 reads markdown files looking for indented code blocks
7 from collections
import OrderedDict
13 fdir
= os
.path
.abspath(os
.path
.dirname(__file__
))
14 fdir
= os
.path
.split(fdir
)[0]
15 fdir
= os
.path
.split(fdir
)[0]
16 fdir
= os
.path
.split(fdir
)[0]
17 fdir
= os
.path
.split(fdir
)[0]
19 return os
.path
.join(fdir
, "openpower", "isafunctions")
25 self
.fns
= OrderedDict()
26 for pth
in os
.listdir(os
.path
.join(get_isafn_dir())):
27 print("examining", get_isafn_dir(), pth
)
30 if not pth
.endswith(".mdwn"):
31 print ("warning, file not .mdwn, skipping", pth
)
35 def read_file(self
, fname
):
36 pagename
= fname
.split('.')[0]
37 fname
= os
.path
.join(get_isafn_dir(), fname
)
38 with
open(fname
) as f
:
41 # set up dict with current page name
42 d
= {'page': pagename
}
44 # line-by-line lexer/parser, quite straightforward: pops one
45 # line off the list and checks it. nothing complicated needed,
46 # all sections are mandatory so no need for a full LALR parser.
48 l
= lines
.pop(0).rstrip() # get first line
52 # look for HTML comment, if starting, skip line.
53 # XXX this is braindead! it doesn't look for the end
54 # so please put ending of comments on one line:
55 # <!-- line 1 comment -->
56 # <!-- line 2 comment -->
57 if l
.strip().startswith('<!--'):
58 # print ("skipping comment", l)
59 l
= lines
.pop(0).rstrip() # get next line
63 # Ignore blank lines before the first #
65 l
= lines
.pop(0).rstrip() # get next line
70 assert l
.startswith('#'), ("# not found in line '%s'" % l
)
71 d
['desc'] = l
[1:].strip()
73 # any lines not starting with space, ignore
75 l
= lines
.pop(0).rstrip()
77 print ("examining", repr(l
))
80 if l
.startswith('<!--'):
85 # fix parser line numbers by prepending the right number of
86 # blank lines to the parser input
87 li
= [""] * prefix_lines
88 li
+= [l
[4:]] # first line detected with 4-space
90 l
= lines
.pop(0).rstrip()
91 print ("examining", repr(l
))
95 if l
.strip().startswith('<!--'):
98 assert l
.startswith(' '), ("4spcs not found in line %s" % l
)
99 l
= l
[4:] # lose 4 spaces
101 d
['pcode'] = '\n'.join(li
)
104 self
.fns
[pagename
] = d
107 for k
, v
in self
.fns
.items():
108 print("# %s %s" % (k
, v
['desc']))
113 if __name__
== '__main__':