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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user