Add a TypeDocumenter for Cretonne types.

Use the autodoc Sphinx module to add a .. autoctontype:: directive which
generates documentation for one of the types in the cretonne.types module.
This commit is contained in:
Jakob Olesen
2016-02-08 18:21:58 -08:00
parent c459c11a5a
commit 19b4facbe0
4 changed files with 87 additions and 50 deletions

View File

@@ -13,6 +13,7 @@
import re
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx import addnodes
from sphinx.directives import ObjectDescription
@@ -22,6 +23,8 @@ from sphinx.roles import XRefRole
from sphinx.util.docfields import Field, GroupedField, TypedField
from sphinx.util.nodes import make_refnode
import sphinx.ext.autodoc
class CtonObject(ObjectDescription):
"""
Any kind of Cretonne IL object.
@@ -29,6 +32,11 @@ class CtonObject(ObjectDescription):
This is a shared base class for the different kinds of indexable objects
in the Cretonne IL reference.
"""
option_spec = {
'noindex': directives.flag,
'module': directives.unchanged,
'annotation': directives.unchanged,
}
def add_target_and_index(self, name, sig, signode):
"""
@@ -209,7 +217,33 @@ class CretonneDomain(Domain):
make_refnode(builder, fromdocname, obj[0],
obj[1] + '-' + target, contnode, target))]
class TypeDocumenter(sphinx.ext.autodoc.Documenter):
# Invoke with .. autoctontype::
objtype = 'ctontype'
# Convert into cton:type directives
domain = 'cton'
directivetype = 'type'
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
return False
def resolve_name(self, modname, parents, path, base):
return 'cretonne.types', [ base ]
def add_content(self, more_content, no_docstring=False):
super(TypeDocumenter, self).add_content(more_content, no_docstring)
sourcename = self.get_sourcename()
membytes = self.object.membytes
if membytes:
self.add_line(u':bytes: {}'.format(membytes), sourcename)
else:
self.add_line(u':bytes: Can\'t be stored in memory', sourcename)
def setup(app):
app.add_domain(CretonneDomain)
app.add_autodocumenter(TypeDocumenter)
return { 'version' : '0.1' }

View File

@@ -87,10 +87,7 @@ All SSA values have a type which determines the size and shape (for SIMD
vectors) of the value. Many instructions are polymorphic -- they can operate on
different types.
.. type:: bool
A boolean value that is either true or false. Booleans can't be stored in
memory.
.. autoctontype:: bool
Integer types
-------------
@@ -99,21 +96,10 @@ Integer values have a fixed size and can be interpreted as either signed or
unsigned. Some instructions will interpret an operand as a signed or unsigned
number, others don't care.
.. type:: i8
A 8-bit integer value taking up 1 byte in memory.
.. type:: i16
A 16-bit integer value taking up 2 bytes in memory.
.. type:: i32
A 32-bit integer value taking up 4 bytes in memory.
.. type:: i64
A 64-bit integer value taking up 8 bytes in memory.
.. autoctontype:: i8
.. autoctontype:: i16
.. autoctontype:: i32
.. autoctontype:: i64
Floating point types
--------------------
@@ -122,17 +108,8 @@ The floating point types have the IEEE semantics that are supported by most
hardware. There is no support for higher-precision types like quads or
double-double formats.
.. type:: f32
A 32-bit floating point type represented in the IEEE 754 *single precision*
format. This corresponds to the :c:type:`float` type in most C
implementations.
.. type:: f64
A 64-bit floating point type represented in the IEEE 754 *double precision*
format. This corresponds to the :c:type:`double` type in most C
implementations.
.. autoctontype:: f32
.. autoctontype:: f64
SIMD vector types
-----------------
@@ -201,7 +178,7 @@ in this reference.
.. type:: fB
Either of the floating point scalar types: :type:`f32` or :type:`f64.
Either of the floating point scalar types: :type:`f32` or :type:`f64`.
.. type:: Float