1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/usr/bin/env python
# SPDX_License-Identifier: MIT
#
# Copyright (C) 2018 Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
#
"""
///
// To document the instructions used in the intermediate representation
// a new domain is defined: 'ir' with a directive::
//
// .. op: <OP_NAME>
// <description of OP_NAME>
// ...
//
// This is equivalent to using a definition list but with the name
// also placed in the index (with 'IR instruction' as descriptions).
"""
import docutils
import sphinx
class IROpDirective(docutils.parsers.rst.Directive):
# use the first line of content as the argument, this allow
# to not have to write a blanck line after the directive
final_argument_whitespace = True
required_argument = 0
#optional_arguments = 0
has_content = True
objtype = None
def run(self):
self.env = self.state.document.settings.env
source = self.state.document
lineno = self.lineno
text = self.content
name = text[0]
node = docutils.nodes.section()
node['ids'].append(name)
node.document = source
index = '.. index:: pair: %s; IR instruction' % name
content = docutils.statemachine.ViewList()
content.append(index, source, lineno)
content.append('' , source, lineno)
content.append(name , source, lineno)
content.append('' , source, lineno)
self.state.nested_parse(content, self.content_offset, node)
defnode = docutils.nodes.definition()
self.state.nested_parse(text[1:], self.content_offset, defnode)
node.append(defnode)
return [node]
class IRDomain(sphinx.domains.Domain):
"""IR domain."""
name = 'ir'
def setup(app):
app.add_domain(IRDomain)
app.add_directive_to_domain('ir', 'op', IROpDirective)
return {
'version': '1.0',
'parallel_read_safe': True,
}
# vim: tabstop=4
|