diff --git a/cranelift/docs/langref.rst b/cranelift/docs/langref.rst index ad2ccb4299..845bc4da37 100644 --- a/cranelift/docs/langref.rst +++ b/cranelift/docs/langref.rst @@ -200,6 +200,18 @@ in this reference. Either :type:`bool` or :type:`iN`. +Immediate operand types +----------------------- + +These types are not part of the normal SSA type system. They are used to +indicate the different kinds of immediate operands on an instruction. + +.. type:: imm64 + + A 64-bit immediate integer. The value of this operand is interpreted as a + signed two's complement integer. Instruction encodings may limit the valid + range. + Control flow ============ diff --git a/cranelift/docs/metaref.rst b/cranelift/docs/metaref.rst index 7a8c156142..b4dda9576d 100644 --- a/cranelift/docs/metaref.rst +++ b/cranelift/docs/metaref.rst @@ -38,13 +38,28 @@ Predefined types .. automodule:: cretonne.types :members: +.. currentmodule:: cretonne + Parametric polymorphism ----------------------- -.. currentmodule:: cretonne Instruction operands can be defined with *type variables* instead of concrete types for their operands. This makes the instructions polymorphic. .. autoclass:: TypeVar +Immediates +---------- +Immediate instruction operands don't correspond to SSA values, but have values +that are encoded directly in the instruction. Immediate operands don't +have types from the :class:`cretonne.Type` type system; they often have +enumerated values of a specific type. The type of an immediate operand is +indicated with an instance of :class:`ImmediateType`. + +.. autoclass:: ImmediateType + +.. automodule:: cretonne.immediates + :members: + +.. currentmodule:: cretonne diff --git a/meta/cretonne/__init__.py b/meta/cretonne/__init__.py index e8cdfe3f55..60c3748106 100644 --- a/meta/cretonne/__init__.py +++ b/meta/cretonne/__init__.py @@ -110,3 +110,23 @@ class TypeVar(object): def __init__(self, name): self.name = name +# +# Immediate operands. +# +# Instances of immediate operand types are provided in the cretonne.immediates +# module. + +class ImmediateType(object): + """ + The type of an immediate instruction operand. + """ + + def __init__(self, name, doc): + self.name = name + self.__doc__ = doc + + def __str__(self): + return self.name + + def __repr__(self): + return 'ImmediateType({})'.format(self.name) diff --git a/meta/cretonne/immediates.py b/meta/cretonne/immediates.py new file mode 100644 index 0000000000..6b499d5215 --- /dev/null +++ b/meta/cretonne/immediates.py @@ -0,0 +1,12 @@ +""" +The cretonne.immdiates module predefines all the Cretonne immediate operand +types. +""" + +from . import ImmediateType + +#: A 64-bit immediate integer operand. +#: +#: This type of immediate integer can interact with SSA values with any +#: :py:class:`cretonne.IntType` type. +imm64 = ImmediateType('imm64', 'A 64-bit immediate integer.')