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
51 # look for HTML comment, if starting, skip line.
52 # XXX this is braindead! it doesn't look for the end
53 # so please put ending of comments on one line:
54 # <!-- line 1 comment -->
55 # <!-- line 2 comment -->
56 if l
.startswith('<!--'):
57 # print ("skipping comment", l)
58 l
= lines
.pop(0).rstrip() # get next line
61 # Ignore blank lines before the first #
63 l
= lines
.pop(0).rstrip() # get next line
67 assert l
.startswith('#'), ("# not found in line '%s'" % l
)
68 d
['desc'] = l
[1:].strip()
70 # any lines not starting with space, ignore
72 l
= lines
.pop(0).rstrip()
73 print ("examining", repr(l
))
76 if l
.startswith('<!--'):
80 li
= [l
[4:]] # first line detected with 4-space
82 l
= lines
.pop(0).rstrip()
83 print ("examining", repr(l
))
87 if l
.startswith('<!--'):
89 assert l
.startswith(' '), ("4spcs not found in line %s" % l
)
90 l
= l
[4:] # lose 4 spaces
92 d
['pcode'] = '\n'.join(li
)
95 self
.fns
[pagename
] = d
98 for k
, v
in self
.fns
.items():
99 print("# %s %s" % (k
, v
['desc']))
104 if __name__
== '__main__':