Пример #1
0
    def test_ident(self):
        got = itanium_mangler.mangle_identifier("apple")
        expect = "5apple"
        self.assertEqual(expect, got)

        got = itanium_mangler.mangle_identifier("ap_ple")
        expect = "6ap_ple"
        self.assertEqual(expect, got)

        got = itanium_mangler.mangle_identifier("apple213")
        expect = "8apple213"
        self.assertEqual(expect, got)
Пример #2
0
def mangle_type_or_value(typ):
    """
    Mangle type parameter and arbitrary value.

    This function extends Numba's `magle_type_or_value()` to
    support numba.types.CPointer type, e.g. an ``int *`` argument will be
    mangled to "Pi".
    Mangling of extended qualifiers is supported only
    for address space qualifiers. In which case, the mangling
    follows the rule defined in Section 5.1.5.1 of the ``Itanium ABI
    <https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.qualified-type>``_.
    For example, an ``int global *`` argument will be mangeled to "PU3AS1i".

    Args:
        typ (numba.types, int, str) : Type to mangle

    Returns:
        str: The mangled name of the type

    """
    if isinstance(typ, types.CPointer):
        rc = "P"
        if typ.addrspace is not None:
            rc += "U" + itanium_mangler.mangle_identifier("AS" +
                                                          str(typ.addrspace))
        rc += itanium_mangler.mangle_type_or_value(typ.dtype)
        return rc
    else:
        return itanium_mangler.mangle_type_or_value(typ)
Пример #3
0
def mangle(ident, argtys, *, abi_tags=()):
    """
    Mangle identifier with Numba type objects and abi-tags.
    """
    kwargs = {}

    # for support numba 0.54 and <=0.55.0dev0=*_469
    if abi_tags:
        kwargs["abi_tags"] = abi_tags

    return (itanium_mangler.PREFIX +
            itanium_mangler.mangle_identifier(ident, **kwargs) +
            mangle_args(argtys))
Пример #4
0
    def insert_const_string(self, mod, string):
        """
        Unlike the parent version.  This returns a a pointer in the constant
        addrspace.
        """
        text = cgutils.make_bytearray(string.encode("utf-8") + b"\x00")
        name = '$'.join(["__conststring__",
                         itanium_mangler.mangle_identifier(string)])
        # Try to reuse existing global
        gv = mod.globals.get(name)
        if gv is None:
            # Not defined yet
            gv = cgutils.add_global_variable(mod, text.type, name,
                                             addrspace=nvvm.ADDRSPACE_CONSTANT)
            gv.linkage = 'internal'
            gv.global_constant = True
            gv.initializer = text

        # Cast to a i8* pointer
        charty = gv.type.pointee.element
        return gv.bitcast(charty.as_pointer(nvvm.ADDRSPACE_CONSTANT))
Пример #5
0
    def insert_const_string(self, mod, string):
        """
        Unlike the parent version.  This returns a a pointer in the constant
        addrspace.
        """
        text = Constant.stringz(string)
        name = '$'.join(["__conststring__",
                         itanium_mangler.mangle_identifier(string)])
        # Try to reuse existing global
        gv = mod.globals.get(name)
        if gv is None:
            # Not defined yet
            gv = mod.add_global_variable(text.type, name=name,
                                         addrspace=nvvm.ADDRSPACE_CONSTANT)
            gv.linkage = LINKAGE_INTERNAL
            gv.global_constant = True
            gv.initializer = text

        # Cast to a i8* pointer
        charty = gv.type.pointee.element
        return Constant.bitcast(gv,
                                charty.as_pointer(nvvm.ADDRSPACE_CONSTANT))
Пример #6
0
 def test_mangle_unicode(self):
     name = u'f∂ƒ©z'
     got = itanium_mangler.mangle_identifier(name)
     self.assertRegexpMatches(got, r'^\d+f(\$[a-z0-9][a-z0-9])+z$')
def mangle(ident, argtys):
    """
    Mangle identifier with Numba type objects and arbitrary values.
    """
    return (itanium_mangler.PREFIX + itanium_mangler.mangle_identifier(ident) +
            mangle_args(argtys))