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

@@ -12,6 +12,11 @@ instructions.
class Type(object):
"""A concrete value type."""
def __init__(self, name, membytes, doc):
self.name = name
self.membytes = membytes
self.__doc__ = doc
def __str__(self):
return self.name
@@ -19,12 +24,12 @@ class ScalarType(Type):
"""
A concrete scalar (not vector) type.
Also tracks a unique set of :class:`VectorType` instances with this type as
the lane type.
Also tracks a unique set of :py:class:`VectorType` instances with this type
as the lane type.
"""
def __init__(self, name):
self.name = name
def __init__(self, name, membytes, doc):
super(ScalarType, self).__init__(name, membytes, doc)
self._vectors = dict()
def __repr__(self):
@@ -53,9 +58,14 @@ class VectorType(Type):
def __init__(self, base, lanes):
assert isinstance(base, ScalarType), 'SIMD lanes must be scalar types'
super(VectorType, self).__init__(
name='{}x{}'.format(base.name, lanes),
membytes=lanes*base.membytes,
doc="""
A SIMD vector with {} lanes containing a {} each.
""".format(lanes, base.name))
self.base = base
self.lanes = lanes
self.name = '{}x{}'.format(base.name, lanes)
def __repr__(self):
return 'VectorType(base={}, lanes={})'.format(self.base.name, self.lanes)
@@ -65,7 +75,10 @@ class IntType(ScalarType):
def __init__(self, bits):
assert bits > 0, 'IntType must have positive number of bits'
super(IntType, self).__init__('i{:d}'.format(bits))
super(IntType, self).__init__(
name='i{:d}'.format(bits),
membytes=bits/8,
doc="An integer type with {} bits.".format(bits))
self.bits = bits
def __repr__(self):
@@ -74,9 +87,9 @@ class IntType(ScalarType):
class FloatType(ScalarType):
"""A concrete scalar floating point type."""
def __init__(self, bits):
def __init__(self, bits, doc):
assert bits > 0, 'FloatType must have positive number of bits'
super(FloatType, self).__init__('f{:d}'.format(bits))
super(FloatType, self).__init__( name='f{:d}'.format(bits), membytes=bits/8, doc=doc)
self.bits = bits
def __repr__(self):

View File

@@ -2,19 +2,32 @@
from . import ScalarType, IntType, FloatType
#: A boolean value.
bool = ScalarType('bool')
bool = ScalarType('bool', 0,
"""
A boolean value that is either true or false.
""")
i8 = IntType(8) #: 8-bit int.
i16 = IntType(16) #: 16-bit int.
i32 = IntType(32) #: 32-bit int.
i64 = IntType(64) #: 64-bit int.
i8 = IntType(8)
i16 = IntType(16)
i32 = IntType(32)
i64 = IntType(64)
f32 = FloatType(32) #: IEEE 32-bit float.
f64 = FloatType(64) #: IEEE 64-bit float
f32 = FloatType(32,
"""
A 32-bit floating point type represented in the IEEE 754-2008 *binary32*
interchange format. This corresponds to the :c:type:`float` type in most
C implementations.
""")
i8x16 = i8.by(16) #: Vector of 16 i8 lanes.
f64 = FloatType(64,
"""
A 64-bit floating point type represented in the IEEE 754-2008 *binary64*
interchange format. This corresponds to the :c:type:`double` type in
most C implementations.
""")
f32x4 = f32.by(4) #: Vector of 4 f32 lanes.
f64x2 = f64.by(2) #: Vector of 2 f64 lanes.
i8x16 = i8.by(16)
f32x4 = f32.by(4)
f64x2 = f64.by(2)