comparison python/ppci/report.py @ 331:a78b41ff6ad2

Added better recipe files
author Windel Bouwman
date Fri, 07 Feb 2014 12:39:59 +0100
parents
children 86b02c98a717
comparison
equal deleted inserted replaced
330:a79ac866732f 331:a78b41ff6ad2
1
2 import logging
3 import io
4
5 import outstream
6 from .c3 import AstPrinter
7 from . import logformat
8 from .irutils import Writer
9
10 class RstFormatter(logging.Formatter):
11 """ Formatter that tries to create an rst document """
12 def __init__(self):
13 super().__init__(fmt=logformat)
14
15 def format(self, record):
16 s = super().format(record)
17 s += '\n'
18 if hasattr(record, 'c3_ast'):
19 f = io.StringIO()
20 print('', file=f)
21 print('', file=f)
22 print('.. code::', file=f)
23 print('', file=f)
24 AstPrinter().printAst(record.c3_ast, f)
25 print('', file=f)
26 s += '\n' + f.getvalue()
27 if hasattr(record, 'ircode'):
28 f = io.StringIO()
29 print('', file=f)
30 print('', file=f)
31 print('.. code::', file=f)
32 print('', file=f)
33 Writer(' ').write(record.ircode, f)
34 print('', file=f)
35 s += '\n' + f.getvalue()
36 if hasattr(record, 'irfunc'):
37 f = io.StringIO()
38 print('', file=f)
39 print('', file=f)
40 print('.. code::', file=f)
41 print('', file=f)
42 Writer(' ').write_function(record.irfunc, f)
43 print('', file=f)
44 s += '\n' + f.getvalue()
45 if hasattr(record, 'ppci_frame'):
46 f = io.StringIO()
47 frame = record.ppci_frame
48 print('', file=f)
49 print('.. code::', file=f)
50 print('', file=f)
51 print(' {}'.format(frame.name), file=f)
52 for i in frame.instructions:
53 print(' {}'.format(i),file=f)
54 print('', file=f)
55 s += '\n' + f.getvalue()
56 if hasattr(record, 'ra_cfg'):
57 f = io.StringIO()
58 print('', file=f)
59 print('', file=f)
60 print('.. graphviz::', file=f)
61 print('', file=f)
62 print(' digraph G {', file=f)
63 print(' size="8,80";', file=f)
64 cfg = record.ra_cfg
65 cfg.to_dot(f)
66 print(' }', file=f)
67 print('', file=f)
68 s += '\n' + f.getvalue()
69 if hasattr(record, 'ra_ig'):
70 f = io.StringIO()
71 print('', file=f)
72 print('', file=f)
73 print('.. graphviz::', file=f)
74 print('', file=f)
75 print(' digraph G {', file=f)
76 print(' ratio="compress";', file=f)
77 print(' size="8,80";', file=f)
78 ig = record.ra_ig
79 ig.to_dot(f)
80 print(' }', file=f)
81 print('', file=f)
82 s += '\n' + f.getvalue()
83 if hasattr(record, 'zcc_outs'):
84 f = io.StringIO()
85 print('', file=f)
86 print('', file=f)
87 print('.. code::', file=f)
88 print('', file=f)
89 outstream.OutputStreamWriter(' ').dump(record.zcc_outs, f)
90 print('', file=f)
91 s += '\n' + f.getvalue()
92 return s
93