示例#1
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)
示例#2
0
 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)
示例#3
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)
示例#4
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)
示例#5
0
 def serialize_object(self, obj):
     """
     Serialize the given object in the bitcode, and return it
     as a pointer to a {i8* data, i32 length}, structure constant
     (suitable for passing to unserialize()).
     """
     try:
         gv = self.module.__serialized[obj]
     except KeyError:
         # First make the array constant
         data = pickle.dumps(obj, protocol=-1)
         name = ".const.pickledata.%s" % (id(obj))
         bdata = cgutils.make_bytearray(data)
         arr = self.context.insert_unique_const(self.module, name, bdata)
         # Then populate the structure constant
         struct = ir.Constant.literal_struct([
             arr.bitcast(self.voidptr),
             ir.Constant(ir.IntType(32), arr.type.pointee.count),
             ])
         name = ".const.picklebuf.%s" % (id(obj))
         gv = self.context.insert_unique_const(self.module, name, struct)
         # Make the id() (and hence the name) unique while populating the module.
         self.module.__serialized[obj] = gv
     return gv
示例#6
0
 def serialize_object(self, obj):
     """
     Serialize the given object in the bitcode, and return it
     as a pointer to a {i8* data, i32 length}, structure constant
     (suitable for passing to unserialize()).
     """
     try:
         gv = self.module.__serialized[obj]
     except KeyError:
         # First make the array constant
         data = pickle.dumps(obj, protocol=-1)
         name = ".const.pickledata.%s" % (id(obj))
         bdata = cgutils.make_bytearray(data)
         arr = self.context.insert_unique_const(self.module, name, bdata)
         # Then populate the structure constant
         struct = ir.Constant.literal_struct([
             arr.bitcast(self.voidptr),
             ir.Constant(ir.IntType(32), arr.type.pointee.count),
         ])
         name = ".const.picklebuf.%s" % (id(obj))
         gv = self.context.insert_unique_const(self.module, name, struct)
         # Make the id() (and hence the name) unique while populating the module.
         self.module.__serialized[obj] = gv
     return gv