Skip to content

Convert type

convert_type

convert_type(type_attr: Attribute) -> ir.Type cached

Convert an xDSL type attribute to an LLVM IR type.

This function handles the conversion of various xDSL type attributes (integers, floats, pointers, vectors, arrays, structs, tuples and functions) to their corresponding llvmlite IR type representations.

Parameters:

Name Type Description Default
type_attr Attribute

The xDSL type attribute to convert.

required

Returns:

Type Description
Type

The corresponding llvmlite IR type.

Raises:

Type Description
LLVMTranslationException

If the type is not supported, including: - Scalable vectors (vectors with scalable dimensions) - Multi-dimensional vectors (vectors with more than one dimension) - Any other unsupported type attribute

Source code in xdsl/backend/llvm/convert_type.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@cache
def convert_type(type_attr: Attribute) -> ir.Type:
    """
    Convert an xDSL type attribute to an LLVM IR type.

    This function handles the conversion of various xDSL type attributes (integers, floats,
    pointers, vectors, arrays, structs, tuples and functions) to their corresponding
    llvmlite IR type representations.

    Args:
        type_attr: The xDSL type attribute to convert.

    Returns:
        The corresponding llvmlite IR type.

    Raises:
        LLVMTranslationException: If the type is not supported, including:
            - Scalable vectors (vectors with scalable dimensions)
            - Multi-dimensional vectors (vectors with more than one dimension)
            - Any other unsupported type attribute
    """
    try:
        converter = _TYPE_CONVERTERS[type(type_attr)]
        return converter(type_attr)
    except KeyError:
        raise LLVMTranslationException(f"Type not supported: {type_attr}")