MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
gendoc Namespace Reference

Classes

class  FuncDoc
class  HtmlDoc

Functions

def is_all_char
def cleanup
def cleanup_lst
def parse_args
def getdoc
def getlatexdoc
def getoutputdoc
def main

Function Documentation

def gendoc.cleanup (   txt)

Definition at line 25 of file gendoc.py.

References cleanup_lst().

25 
26 def cleanup(txt):
27  return "\n".join(cleanup_lst(txt.split("\n")))

Here is the call graph for this function:

Here is the caller graph for this function:

def gendoc.cleanup_lst (   txtlst)

Definition at line 28 of file gendoc.py.

References max, and min.

28 
29 def cleanup_lst(txtlst):
30  last_empty = 0
31  only_empty = 1
32  empty_line = 0
33  i = 0
34  first_full = len(txtlst)
35 
36  if len(txtlst) > 1:
37  min_indent = max(map(len, txtlst))
38  else:
39  min_indent = 0
40 
41  for line in txtlst:
42  if len(line.strip()) == 0: # empty line
43  if not empty_line:
44  last_empty = i
45  empty_line = 1
46  else:
47  if only_empty:
48  first_full = i
49  only_empty = 0
50  empty_line = 0
51 
52  if not empty_line:
53  min_indent = min(min_indent, len(line) - len(line.lstrip()))
54 
55  i += 1
56 
57  all_lines = list()
58 
59  i = 0
60  for line in txtlst:
61  if i >= first_full and i <= last_empty:
62  all_lines.append(line.rstrip()[min_indent:])
63  i += 1
64 
65  return all_lines

Here is the caller graph for this function:

def gendoc.getdoc (   fname)

Definition at line 85 of file gendoc.py.

References cleanup(), cleanup_lst(), is_all_char(), and parse_args().

85 
86 def getdoc(fname):
87  txt = open(fname).read()
88  purpose_idx = txt.find("\n", txt.find("Purpose")+14)+1
89  args_idx = txt.find("Arguments", purpose_idx)
90  func_idx = txt.rfind('extern "C"', 1, purpose_idx)
91  funcname = txt[txt.find("\n", func_idx)+1 : txt.find("(", func_idx)]
92  C_args_idx = txt.find("(", func_idx) + 1
93  # I'm counting on the fact that there is no ')' in arg list
94  C_args = parse_args(txt[C_args_idx : txt.find(")", C_args_idx)])
95 
96  details_idx = txt.find(" Further Details", args_idx)
97 
98  eoc_idx = txt.find("*/", args_idx)
99  argend_idx = eoc_idx
100  if details_idx > 0:
101  argend_idx = details_idx
102 
103  if details_idx > 0:
104  details_idx = txt.find("\n", details_idx + 30) + 1
105 
106  if details_idx > 0:
107  details = cleanup(txt[details_idx:eoc_idx])
108  else:
109  details = ""
110 
111  argdict = dict()
112  argname = "_____" # dummy argument name
113  argdict[argname] = list()
114 
115  # go through each "argline" in the section with arguments
116  for argline in txt[args_idx:argend_idx].split("\n"):
117  argfields = argline.split()
118 
119  switcharg = 0
120  #for inout in ("(input)", "(output)", "(input/output)", "(workspace)", "(input/workspace)", "(workspace/output)", "(input"):
121  for inout in ("input", "output", "workspace"):
122  #if len(argfields) > 1 and inout == argfields[1]:
123  if re.match(" *\w+ *\(%s" % inout, argline):
124  argname = argfields[0]
125  arginout = argline[argline.find("(") : argline.find(")")+1]
126  argtype = argline[argline.find(")")+1 :].strip()
127  argdict[argname] = [(arginout, argtype)]
128  switcharg = 1
129  break
130 
131  if not switcharg:
132  argdict[argname].append(argline)
133 
134  for key in argdict:
135  inout = argdict[key][0]
136  argdict[key] = [inout] + cleanup_lst(argdict[key][1:])
137  continue
138  l = argdict[key]
139  idx = len(l) - 1
140  fields = l[idx].split()
141  if len(fields) == 1 and is_all_char(fields[0], "="):
142  del l[idx]
143 
144  purpose = cleanup(txt[purpose_idx:args_idx])
145 
146  return FuncDoc(funcname, C_args, argdict, purpose, details)
147 
# this function is out of date

Here is the call graph for this function:

Here is the caller graph for this function:

def gendoc.getlatexdoc (   funcdoc)

Definition at line 148 of file gendoc.py.

References min.

149 def getlatexdoc(funcdoc):
150  latexdoc = "\\textsf{magma\_int\_t} "
151  latexdoc += "\\textsf{\\textbf{%s}}" % funcdoc.funcname.replace("_", "\\_")
152  latexdoc += "(\\textsf{"
153  latexdoc += ", ".join(funcdoc.C_args).replace("_", "\\_")
154  latexdoc += "}); \\\n"
155 
156  latexdoc += "Arguments:\\\n\\begin{description}"
157 
158  for arg in funcdoc.C_args:
159  argname = ""
160  larg = len(arg)
161  for idx in range(larg):
162  ch = arg[larg-idx-1]
163  if ch.isalpha():
164  argname = ch + argname
165  else:
166  break
167 
168  latexdoc += "\\item[" + argname + "] "
169 
170  karg = argname.upper()
171  if 0 and not funcdoc.argdict.has_key(karg):
172  karg = "D" + karg
173 
174  try:
175  ldoc = funcdoc.argdict[karg]
176  latexdoc += ldoc[0] + "\n" # input/output/workspace
177  latexdoc += "\\begin{verbatim}\n"
178 
179  lidx = len(ldoc[1])
180  # remove extra indentation
181  for l in ldoc[1:]:
182  if len(l) > 0:
183  lidx = min(lidx, len(l) - len(l.lstrip()))
184 
185  for l in ldoc[1:]:
186  if l.rstrip():
187  latexdoc += l[lidx:] + "\n"
188  latexdoc += "\end{verbatim}\n"
189 
190  except:
191  #sys.stderr.write("MAGMA %s\n" % " ".join(list((funcdoc.funcname, karg, str(funcdoc.argdict.keys()), latexdoc, str(funcdoc.argdict)))))
192  pass
193 
194  latexdoc += "\n"
195 
196  latexdoc += "\\end{description}"
197 
198  return latexdoc
def gendoc.getoutputdoc (   fdoc,
  output 
)

Definition at line 314 of file gendoc.py.

References min.

315 def getoutputdoc(fdoc, output):
316  doc = output.begin_decl()
317  doc += output.ret_type("magma_int_t")
318  doc += output.funcname(fdoc.funcname)
319  doc += output.begin_args_decl(len(fdoc.C_args))
320  doc += "".join(map(lambda s: output.decl_arg(s[0], s[1]), fdoc.C_args))
321  doc += output.end_args_decl()
322  doc += output.end_decl()
323 
324  doc += output.begin_purpose("Purpose:")
325  doc += fdoc.purpose
326  doc += output.end_purpose("Purpose:")
327 
328  doc += output.begin_arguments("Arguments:")
329 
330  for arg in fdoc.C_args:
331  argname = arg[1]
332  doc += output.begin_arg(argname)
333  doc += output.end_arg(argname)
334 
335  karg = argname.upper()
336  if 0 and not funcdoc.argdict.has_key(karg):
337  karg = "D" + karg
338 
339  ldoc = fdoc.argdict.get(karg, [("(missing)", arg[0]), "MISSING"])
340  #sys.stderr.write("MAGMA %s\n" % " ".join(list((fdoc.funcname, karg, str(fdoc.argdict.keys()), doc, str(fdoc.argdict)))))
341 
342  if len(ldoc) > 1:
343  lidx = len(ldoc[1])
344  else:
345  lidx = 0
346  # remove extra indentation
347  for l in ldoc[1:]:
348  if len(l) > 0:
349  lidx = min(lidx, len(l) - len(l.lstrip()))
350 
351  doc += output.inoutwork(ldoc[0][0]) # input/output/workspace
352  doc += output.arg_type(ldoc[0][1])
353  doc += output.begin_arg_desc(argname)
354 
355  for l in ldoc[1:]:
356  if l.rstrip():
357  doc += output.arg_desc_line(l[lidx:])
358 
359  doc += output.end_arg_desc(argname)
360 
361 
362  doc += output.end_arguments("Arguments:")
363 
364  if fdoc.details:
365  doc += output.begin_details("Further Details:")
366  doc += fdoc.details
367  doc += output.end_details("Further Details:")
368 
369  return doc

Here is the caller graph for this function:

def gendoc.is_all_char (   s,
  ch 
)
All characters in 's' are 'ch'.

Definition at line 14 of file gendoc.py.

14 
15 def is_all_char(s, ch):
16  """
17  All characters in 's' are 'ch'.
18  """
19 
20  for c in s:
21  if c != ch:
22  return 0
23 
24  return 1

Here is the caller graph for this function:

def gendoc.main (   argv)

Definition at line 370 of file gendoc.py.

References getdoc(), and getoutputdoc().

371 def main(argv):
372  outdir = "htmldoc"
373 
374  if not os.path.exists(outdir):
375  os.mkdir(outdir)
376 
377  fl = list()
378  for fname in argv[1:]:
379  ofname = os.path.basename(fname).replace("cpp", "html")
380  of = open(os.path.join(outdir, ofname), "w")
381 
382  odoc = HtmlDoc()
383 
384  of.write(odoc.preamble("MAGMA"))
385 
386  funcdoc = getdoc(fname)
387  #latexdoc = getlatexdoc(funcdoc)
388  doc = getoutputdoc(funcdoc, odoc)
389  of.write(doc)
390  of.write(odoc.epilog("MAGMA"))
391 
392  fl.append((funcdoc.funcname, ofname))
393 
394  idxf = open(os.path.join(outdir, "index.html"), "w")
395  idxf.write("<html>\n<head><title>MAGMA 1.0</title></head>\n<body>\n<h1>MAGMA 1.0 Function Index</h1><ul>\n")
396  for t in fl:
397  funcname, ofname = t
398  idxf.write("""<li><a href="%s"><code>%s</code></a></li>\n""" % (ofname, funcname))
399  idxf.write("</ul>\n</body>\n</html>\n")
400 
401  return 0

Here is the call graph for this function:

def gendoc.parse_args (   argstr)

Definition at line 66 of file gendoc.py.

66 
67 def parse_args(argstr):
68  arglst = argstr.split(",")
69  newarglist = list()
70  for a in arglst:
71  a = a.strip()
72  name = re.match("(\w+)", a[::-1]).group() # match argument name from the end (I'm assuming the name ends each argument)
73  prefix = a[:-len(name)]
74  newarglist.append((prefix, name[::-1]))
75 
76  return newarglist

Here is the caller graph for this function: