internal static void BuildCreateNotifierPairFunction(FunctionModuleContext moduleContext, NIType signature, LLVMValueRef createNotifierPairFunction)
        {
            LLVMTypeRef valueType          = moduleContext.LLVMContext.AsLLVMType(signature.GetGenericParameters().First()),
                        notifierReaderType = moduleContext.LLVMContext.CreateLLVMNotifierReaderType(valueType),
                        notifierWriterType = moduleContext.LLVMContext.CreateLLVMNotifierWriterType(valueType);

            LLVMBasicBlockRef entryBlock = createNotifierPairFunction.AppendBasicBlock("entry");
            var builder = moduleContext.LLVMContext.CreateIRBuilder();

            builder.PositionBuilderAtEnd(entryBlock);
            LLVMTypeRef  sharedDataType        = moduleContext.LLVMContext.CreateLLVMNotifierSharedDataType(valueType);
            LLVMTypeRef  refCountType          = moduleContext.LLVMContext.CreateLLVMRefCountType(sharedDataType);
            LLVMValueRef refCountAllocationPtr = moduleContext.CreateMalloc(builder, refCountType, "refCountAllocationPtr"),
                         refCount = builder.BuildStructValue(
                refCountType,
                new LLVMValueRef[] { moduleContext.LLVMContext.AsLLVMValue(2), LLVMSharp.LLVM.ConstNull(sharedDataType) },
                "refCount");

            builder.CreateStore(refCount, refCountAllocationPtr);

            LLVMValueRef notifierReader = builder.BuildStructValue(notifierReaderType, new[] { refCountAllocationPtr });

            builder.CreateStore(notifierReader, createNotifierPairFunction.GetParam(0u));
            LLVMValueRef notifierWriter = builder.BuildStructValue(notifierWriterType, new[] { refCountAllocationPtr });

            builder.CreateStore(notifierWriter, createNotifierPairFunction.GetParam(1u));
            builder.CreateRetVoid();
        }
예제 #2
0
        internal static void BuildSharedCreateFunction(FunctionModuleContext moduleContext, NIType signature, LLVMValueRef sharedCreateFunction)
        {
            LLVMTypeRef valueType = moduleContext.LLVMContext.AsLLVMType(signature.GetGenericParameters().First());

            LLVMBasicBlockRef entryBlock = sharedCreateFunction.AppendBasicBlock("entry");
            var builder = moduleContext.LLVMContext.CreateIRBuilder();

            builder.PositionBuilderAtEnd(entryBlock);
            LLVMTypeRef  refCountType          = moduleContext.LLVMContext.CreateLLVMRefCountType(valueType);
            LLVMValueRef refCountAllocationPtr = moduleContext.CreateMalloc(builder, refCountType, "refCountAllocationPtr"),
                         refCount = builder.BuildStructValue(
                refCountType,
                new LLVMValueRef[] { moduleContext.LLVMContext.AsLLVMValue(1), sharedCreateFunction.GetParam(0u) },
                "refCount");

            builder.CreateStore(refCount, refCountAllocationPtr);
            LLVMValueRef sharedPtr = sharedCreateFunction.GetParam(1u);

            builder.CreateStore(refCountAllocationPtr, sharedPtr);
            builder.CreateRetVoid();
        }