/// Not really a constant string; can be explicitly released...
llvm::Constant *CGObjCJit::GenerateConstantString(const StringLiteral *SL) {
  if (isUsable && stringClass) {
    void *stringInstance = stringAlloc_imp(stringClass, allocSel);
    const llvm::StringRef& literalStringRef(SL->getString());

    // Need to get specific class of instance
    void *instanceStringClass = _object_getClass(stringInstance);
    _imp_t init_imp;

    if (!SL->isWide()) {
      init_imp = _class_getMethodImplementation(instanceStringClass,
                 stringInitSel);
      stringInstance = init_imp(stringInstance,
                                stringInitSel,
                                literalStringRef.data(),
                                literalStringRef.size(),
                                4); // NSUTF8StringEncoding = 4 (shouldn't change)

    } else { // shouldn't see this anyway; does StringRef support wide?
      init_imp = _class_getMethodImplementation(instanceStringClass,
                 wideStringInitSel);
      stringInstance = init_imp(stringInstance,
                                wideStringInitSel,
                                literalStringRef.data(),
                                literalStringRef.size());
    }

    // If applicable, make sure the string is not freed by the garbage collector
    if (defaultCollector) {
      disableCollector_imp(defaultCollector,
                           disableCollectorSel,
                           stringInstance);
    }

    // TODO: save string objects to a list?

    return llvm::Constant::getIntegerValue(ObjCTypes.ObjectPtrTy,
                                           llvm::APInt(sizeof(void*) * 8,
                                               (uint64_t)stringInstance));
  }
  return 0;
}
예제 #2
0
	static int init(T *o, lua_State *L) {
		return init_imp(o, L, 0);
	}