5 import docutils.writers.html4css1
6 from datetime import datetime
7 from jinja2 import Environment, Template
8 from jinja2.filters import do_dictsort
9 from spec_util import is_dynamic_pinned, verify_node, isAbstract, setdefault
10 from ir_spec import nodes
15 # Convert tabs to spaces (following the normal Python rules)
16 # and split into a list of lines:
17 lines = docstring.expandtabs().splitlines()
18 # Determine minimum indentation (first line doesn't count):
20 for line in lines[1:]:
21 stripped = line.lstrip()
23 indent = min(indent, len(line) - len(stripped))
24 # Remove indentation (first line is special):
25 trimmed = [lines[0].strip()]
26 if indent < sys.maxint:
27 for line in lines[1:]:
28 trimmed.append(line[indent:].rstrip())
29 # Strip off trailing and leading blank lines:
30 while trimmed and not trimmed[-1]:
32 while trimmed and not trimmed[0]:
34 # Return a single string:
35 return '\n'.join(trimmed)
37 def format_docutils(string):
38 writer = docutils.writers.html4css1.Writer()
39 document = docutils.core.publish_parts(string, writer=writer)['body']
43 env.filters['docutils'] = format_docutils
45 docu_template = env.from_string(
48 <title>libFirm node specifications</title>
49 <link rel='stylesheet' type='text/css' href='style.css'/>
52 <div class="document">
53 <div class="documentwrapper">
54 <div class="bodywrapper"><div class="body">
55 <h1>Firm Node Types</h1>
56 {% for node in nodes %}
57 <div class="section" id="{{node.name}}">
58 <h3>{{node.name}}</h3>
62 {% for input in node.ins %}
63 <dt>{{input[0]}}</dt><dd>{{input[1]}}</dd>
65 {% if node.arity == "variable" %}
66 <dt>...</dt><dd>additional inputs (oparity_variable)</dd>
67 {% elif node.arity == "dynamic" %}
68 <dt>...</dt><dd>inputs dynamically mananged (oparity_dynamic)</dd>
74 {% for output in node.outs %}
75 <dt>{{output[0]}}</dt><dd>{{output[1]}}</dd>
82 {% for attr in node.attrs %}
83 <dt>{{attr.name}}</dt><dd>{{attr.comment}} ({{attr.type}})</dd>
88 {% for flag in node.flags %} {{flag}} {% endfor %}
94 <div class="sidebarwrapper">
95 <h3>Table Of Contents</h3>
97 <li><a href="#">Firm Node Types</a>
99 {% for node in nodes %}
100 <li><a href="#{{node.name}}">{{node.name}}</a></li>
114 #############################
116 def preprocess_node(node):
117 node.doc = trim(node.__doc__)
122 preprocess_node(node)
125 real_nodes.append(node)
132 output = open(argv[1], "w")
134 real_nodes = prepare_nodes()
135 time = datetime.now().replace(microsecond=0).isoformat(' ')
136 output.write(docu_template.render(nodes = real_nodes, time=time))
137 if output != sys.stdout: