예제 #1
0
파일: base.py 프로젝트: yuguen/numba
 def insert_const_string(self, mod, string):
     """
     Insert constant *string* (a str object) into module *mod*.
     """
     stringtype = GENERIC_POINTER
     name = ".const.%s" % string
     text = cgutils.make_bytearray(string.encode("utf-8") + b"\x00")
     gv = self.insert_unique_const(mod, name, text)
     return Constant.bitcast(gv, stringtype)
예제 #2
0
파일: base.py 프로젝트: numba/numba
 def insert_const_bytes(self, mod, bytes, name=None):
     """
     Insert constant *byte* (a `bytes` object) into module *mod*.
     """
     stringtype = GENERIC_POINTER
     name = ".bytes.%s" % (name or hash(bytes))
     text = cgutils.make_bytearray(bytes)
     gv = self.insert_unique_const(mod, name, text)
     return Constant.bitcast(gv, stringtype)
예제 #3
0
파일: base.py 프로젝트: yesin25/numba
 def insert_const_string(self, mod, string):
     """
     Insert constant *string* (a str object) into module *mod*.
     """
     stringtype = GENERIC_POINTER
     name = ".const.%s" % string
     text = cgutils.make_bytearray(string.encode("utf-8") + b"\x00")
     gv = self.insert_unique_const(mod, name, text)
     return Constant.bitcast(gv, stringtype)
예제 #4
0
 def insert_const_bytes(self, mod, bytes, name=None):
     """
     Insert constant *byte* (a `bytes` object) into module *mod*.
     """
     stringtype = GENERIC_POINTER
     name = ".bytes.%s" % (name or hash(bytes))
     text = cgutils.make_bytearray(bytes)
     gv = self.insert_unique_const(mod, name, text)
     return Constant.bitcast(gv, stringtype)
예제 #5
0
    def make_keywords(self, kws):
        strings = []
        stringtype = Type.pointer(Type.int(8))
        for k in kws:
            strings.append(self.make_const_string(k))

        strings.append(Constant.null(stringtype))
        kwlist = Constant.array(stringtype, strings)
        kwlist = cgutils.global_constant(self.module, ".kwlist", kwlist)
        return Constant.bitcast(kwlist, Type.pointer(stringtype))
예제 #6
0
 def insert_const_string(self, mod, string):
     stringtype = GENERIC_POINTER
     text = Constant.stringz(string)
     name = ".const.%s" % string
     for gv in mod.global_variables:
         if gv.name == name and gv.type.pointee == text.type:
             break
     else:
         gv = cgutils.global_constant(mod, name, text)
         gv.linkage = lc.LINKAGE_INTERNAL
     return Constant.bitcast(gv, stringtype)
예제 #7
0
파일: base.py 프로젝트: johandroid/numba
 def insert_const_string(self, mod, string):
     stringtype = GENERIC_POINTER
     text = Constant.stringz(string)
     name = ".const.%s" % string
     for gv in mod.global_variables:
         if gv.name == name and gv.type.pointee == text.type:
             break
     else:
         gv = cgutils.global_constant(mod, name, text)
         gv.linkage = lc.LINKAGE_INTERNAL
     return Constant.bitcast(gv, stringtype)
예제 #8
0
파일: target.py 프로젝트: gdementen/numba
    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__", self.mangle_name(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))
예제 #9
0
파일: target.py 프로젝트: Alexhuszagh/numba
    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__", self.mangle_name(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))