31 Function *dispatch_semaphore_create_function = module->getFunction(
"dispatch_semaphore_create");
32 if (! dispatch_semaphore_create_function)
34 vector<Type *> dispatch_semaphore_create_functionParams;
35 dispatch_semaphore_create_functionParams.push_back(IntegerType::get(module->getContext(), 64));
36 FunctionType *dispatch_semaphore_create_functionType = FunctionType::get(dispatch_semaphore_t_type,
37 dispatch_semaphore_create_functionParams,
39 dispatch_semaphore_create_function = Function::Create(dispatch_semaphore_create_functionType,
40 GlobalValue::ExternalLinkage,
41 "dispatch_semaphore_create",
45 ConstantInt *initialValueConst = ConstantInt::get(module->getContext(), APInt(64, initialValue));
46 return CallInst::Create(dispatch_semaphore_create_function, initialValueConst,
"", block);
59 LoadInst *semaphoreValue =
new LoadInst(semaphoreVariable,
"",
false, block);
74 LoadInst *semaphoreValue =
new LoadInst(semaphoreVariable,
"",
false, block);
83 IntegerType *dispatch_time_t_type = IntegerType::get(module->getContext(), 64);
84 Value *timeoutValue = ConstantInt::get(dispatch_time_t_type, DISPATCH_TIME_FOREVER);
94 IntegerType *dispatch_time_t_type = IntegerType::get(module->getContext(), 64);
96 vector<Type *> dispatch_semaphore_wait_functionParams;
97 dispatch_semaphore_wait_functionParams.push_back(dispatch_semaphore_t_type);
98 dispatch_semaphore_wait_functionParams.push_back(dispatch_time_t_type);
99 FunctionType *dispatch_semaphore_wait_functionType = FunctionType::get(IntegerType::get(module->getContext(), 64),
100 dispatch_semaphore_wait_functionParams,
103 Function *dispatch_semaphore_wait_function = module->getFunction(
"dispatch_semaphore_wait");
104 if (! dispatch_semaphore_wait_function) {
105 dispatch_semaphore_wait_function = Function::Create(dispatch_semaphore_wait_functionType,
106 GlobalValue::ExternalLinkage,
107 "dispatch_semaphore_wait",
111 vector<Value *> args;
112 args.push_back(semaphoreValue);
113 args.push_back(timeoutValue);
114 return CallInst::Create(dispatch_semaphore_wait_function, args,
"", block);
122 LoadInst *semaphoreValue =
new LoadInst(semaphoreVariable,
"",
false, block);
133 vector<Type *> dispatch_semaphore_signal_functionParams;
134 dispatch_semaphore_signal_functionParams.push_back(dispatch_semaphore_t_type);
135 FunctionType *dispatch_semaphore_signal_functionType = FunctionType::get(IntegerType::get(module->getContext(), 64),
136 dispatch_semaphore_signal_functionParams,
139 Function *dispatch_semaphore_signal_function = module->getFunction(
"dispatch_semaphore_signal");
140 if (! dispatch_semaphore_signal_function) {
141 dispatch_semaphore_signal_function = Function::Create(dispatch_semaphore_signal_functionType,
142 GlobalValue::ExternalLinkage,
143 "dispatch_semaphore_signal",
147 CallInst::Create(dispatch_semaphore_signal_function, semaphoreValue,
"", block);
159 Function *dispatch_group_create_function = module->getFunction(
"dispatch_group_create");
160 if (! dispatch_group_create_function)
162 vector<Type *> dispatch_group_create_functionParams;
163 FunctionType *dispatch_group_create_functionType = FunctionType::get(
getDispatchGroupType(module),
164 dispatch_group_create_functionParams,
166 dispatch_group_create_function = Function::Create(dispatch_group_create_functionType,
167 GlobalValue::ExternalLinkage,
168 "dispatch_group_create", module);
171 return CallInst::Create(dispatch_group_create_function,
"", block);
179 Function *dispatch_group_enter_function = module->getFunction(
"dispatch_group_enter");
180 if (! dispatch_group_enter_function)
183 FunctionType *dispatch_group_enter_functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
184 dispatch_group_t_type,
186 dispatch_group_enter_function = Function::Create(dispatch_group_enter_functionType,
187 GlobalValue::ExternalLinkage,
188 "dispatch_group_enter",
192 CallInst::Create(dispatch_group_enter_function, dispatchGroupValue,
"", block);
200 Function *dispatch_group_leave_function = module->getFunction(
"dispatch_group_leave");
201 if (! dispatch_group_leave_function)
204 FunctionType *dispatch_group_leave_functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
205 dispatch_group_t_type,
207 dispatch_group_leave_function = Function::Create(dispatch_group_leave_functionType,
208 GlobalValue::ExternalLinkage,
209 "dispatch_group_leave",
213 CallInst::Create(dispatch_group_leave_function, dispatchGroupValue,
"", block);
220 dispatch_time_t timeout)
222 Function *dispatch_group_wait_function = module->getFunction(
"dispatch_group_wait");
223 if (! dispatch_group_wait_function)
227 vector<Type *> dispatch_group_wait_functionParams;
228 dispatch_group_wait_functionParams.push_back(dispatch_group_t_type);
229 dispatch_group_wait_functionParams.push_back(IntegerType::get(module->getContext(), 64));
230 FunctionType *dispatch_group_wait_functionType = FunctionType::get(IntegerType::get(module->getContext(), 64),
231 dispatch_group_wait_functionParams,
234 dispatch_group_wait_function = Function::Create(dispatch_group_wait_functionType,
235 GlobalValue::ExternalLinkage,
236 "dispatch_group_wait",
240 ConstantInt *timeout_value = ConstantInt::get(module->getContext(), APInt(64, timeout,
true));
242 vector<Value *> args;
243 args.push_back(dispatchGroupValue);
244 args.push_back(timeout_value);
245 CallInst::Create(dispatch_group_wait_function, args,
"", block);
253 PointerType *dispatch_queue_t_type = getDispatchQueueType(module);
255 vector<Type *> dispatch_get_global_queue_functionParams;
256 dispatch_get_global_queue_functionParams.push_back(IntegerType::get(module->getContext(), 64));
257 dispatch_get_global_queue_functionParams.push_back(IntegerType::get(module->getContext(), 64));
258 FunctionType *dispatch_get_global_queue_functionType = FunctionType::get(dispatch_queue_t_type,
259 dispatch_get_global_queue_functionParams,
262 Function *dispatch_get_global_queue_function = module->getFunction(
"dispatch_get_global_queue");
263 if (! dispatch_get_global_queue_function) {
264 dispatch_get_global_queue_function = Function::Create(dispatch_get_global_queue_functionType,
265 GlobalValue::ExternalLinkage,
266 "dispatch_get_global_queue",
270 Constant *zeroValue = ConstantInt::get(dispatch_get_global_queue_functionType->getParamType(0), 0);
272 vector<Value *> args;
273 args.push_back(zeroValue);
274 args.push_back(zeroValue);
275 return CallInst::Create(dispatch_get_global_queue_function, args,
"", block);
288 PointerType *dispatch_queue_t_type = getDispatchQueueType(module);
289 PointerType *pointerToi8 = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
291 StructType *dispatch_queue_attr_s_type = module->getTypeByName(
"struct.dispatch_queue_attr_s");
292 if (! dispatch_queue_attr_s_type)
293 dispatch_queue_attr_s_type = StructType::create(module->getContext(),
"struct.dispatch_queue_attr_s");
294 PointerType *dispatch_queue_attr_t_type = PointerType::get(dispatch_queue_attr_s_type, 0);
296 vector<Type *> dispatch_queue_create_functionParams;
297 dispatch_queue_create_functionParams.push_back(pointerToi8);
298 dispatch_queue_create_functionParams.push_back(dispatch_queue_attr_t_type);
299 FunctionType *dispatch_queue_create_functionType = FunctionType::get(dispatch_queue_t_type,
300 dispatch_queue_create_functionParams,
303 Function *dispatch_queue_create_function = module->getFunction(
"dispatch_queue_create");
304 if (! dispatch_queue_create_function)
306 dispatch_queue_create_function = Function::Create(dispatch_queue_create_functionType,
307 GlobalValue::ExternalLinkage,
308 "dispatch_queue_create",
312 ArrayType *dispatchQueueNameType = ArrayType::get(IntegerType::get(module->getContext(), 8), dispatchQueueName.length() + 1);
313 GlobalVariable *dispatchQueueNameVariable =
new GlobalVariable(*module,
314 dispatchQueueNameType,
316 GlobalValue::InternalLinkage,
319 Constant *dispatchQueueNameValue = ConstantDataArray::getString(module->getContext(), dispatchQueueName,
true);
320 dispatchQueueNameVariable->setInitializer(dispatchQueueNameValue);
322 ConstantInt *zeroi64Value = ConstantInt::get(module->getContext(), APInt(64, 0));
323 ConstantPointerNull *nullValue = ConstantPointerNull::get(dispatch_queue_attr_t_type);
325 std::vector<Constant*> dispatchQueueLabel_indices;
326 dispatchQueueLabel_indices.push_back(zeroi64Value);
327 dispatchQueueLabel_indices.push_back(zeroi64Value);
328 Constant *dispatchQueueLabel = ConstantExpr::getGetElementPtr(dispatchQueueNameVariable, dispatchQueueLabel_indices);
330 vector<Value *> args;
331 args.push_back(dispatchQueueLabel);
332 args.push_back(nullValue);
333 return CallInst::Create(dispatch_queue_create_function, args,
"", block);
340 Function *workerFunction, Value *contextValue)
342 generateSubmissionToDispatchQueue(module, block, dispatchQueueValue, workerFunction, contextValue,
false);
349 Function *workerFunction, Value *contextValue)
351 generateSubmissionToDispatchQueue(module, block, dispatchQueueValue, workerFunction, contextValue,
true);
357 void VuoCompilerCodeGenUtilities::generateSubmissionToDispatchQueue(Module *module, BasicBlock *block, Value *dispatchQueueValue,
358 Function *workerFunction, Value *contextValue,
bool isSynchronous)
360 PointerType *dispatch_queue_t_type = getDispatchQueueType(module);
361 PointerType *pointerToi8 = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
363 vector<Type *> dispatchSubmitFunctionParams;
364 dispatchSubmitFunctionParams.push_back(dispatch_queue_t_type);
365 dispatchSubmitFunctionParams.push_back(pointerToi8);
366 dispatchSubmitFunctionParams.push_back(workerFunction->getType());
367 FunctionType *dispatchSubmitFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()),
368 dispatchSubmitFunctionParams,
371 const char *dispatchSubmitFunctionName = (isSynchronous ?
"dispatch_sync_f" :
"dispatch_async_f");
372 Function *dispatchSubmitFunction = module->getFunction(dispatchSubmitFunctionName);
373 if (! dispatchSubmitFunction) {
374 dispatchSubmitFunction = Function::Create(dispatchSubmitFunctionType,
375 GlobalValue::ExternalLinkage,
376 dispatchSubmitFunctionName,
380 vector<Value *> args;
381 args.push_back(dispatchQueueValue);
382 args.push_back(contextValue);
383 args.push_back(workerFunction);
384 CallInst::Create(dispatchSubmitFunction, args,
"", block);
390 Value * VuoCompilerCodeGenUtilities::generateConversionToDispatchObject(Module *module, BasicBlock *block, Value *dispatchObjectVariable)
392 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
393 PointerType *dispatchObjectOriginalType = cast<PointerType>(dispatchObjectVariable->getType());
396 vector<Type *> llvm_memcpy_p0i8_p0i8_i64_functionParams;
397 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(pointerToi8Type);
398 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(pointerToi8Type);
399 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(IntegerType::get(module->getContext(), 64));
400 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(IntegerType::get(module->getContext(), 32));
401 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(IntegerType::get(module->getContext(), 1));
402 FunctionType *llvm_memcpy_p0i8_p0i8_i64_functionType = FunctionType::get(Type::getVoidTy(module->getContext()), llvm_memcpy_p0i8_p0i8_i64_functionParams,
false);
403 Function *llvm_memcpy_p0i8_p0i8_i64_function = module->getFunction(
"llvm.memcpy.p0i8.p0i8.i64");
404 if (! llvm_memcpy_p0i8_p0i8_i64_function)
405 llvm_memcpy_p0i8_p0i8_i64_function = Function::Create(llvm_memcpy_p0i8_p0i8_i64_functionType, GlobalValue::ExternalLinkage,
"llvm.memcpy.p0i8.p0i8.i64", module);
407 ConstantInt *zeroValue32 = ConstantInt::get(module->getContext(), APInt(32, 0));
408 ConstantInt *zeroValue1 = ConstantInt::get(module->getContext(), APInt(1, 0));
409 ConstantInt *eightValue64 = ConstantInt::get(module->getContext(), APInt(64, 8));
410 ConstantInt *eightValue32 = ConstantInt::get(module->getContext(), APInt(32, 8));
412 AllocaInst *dispatchObjectUnion =
new AllocaInst(dispatch_object_t_type,
"", block);
413 AllocaInst *compoundLiteral =
new AllocaInst(dispatch_object_t_type,
"", block);
415 CastInst *compoundLiteralAsDispatchObjectOriginalType =
new BitCastInst(compoundLiteral, dispatchObjectOriginalType,
"", block);
416 LoadInst *dispatchObjectValue =
new LoadInst(dispatchObjectVariable,
"",
false, block);
417 new StoreInst(dispatchObjectValue, compoundLiteralAsDispatchObjectOriginalType,
false, block);
419 CastInst *dispatchObjectUnionAsPointerToi8 =
new BitCastInst(dispatchObjectUnion, pointerToi8Type,
"", block);
420 CastInst *compoundLiteralAsPointerToi8 =
new BitCastInst(compoundLiteral, pointerToi8Type,
"", block);
422 std::vector<Value *> llvm_memcpy_p0i8_p0i8_i64_functionArgs;
423 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(dispatchObjectUnionAsPointerToi8);
424 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(compoundLiteralAsPointerToi8);
425 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(eightValue64);
426 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(eightValue32);
427 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(zeroValue1);
428 CallInst::Create(llvm_memcpy_p0i8_p0i8_i64_function, llvm_memcpy_p0i8_p0i8_i64_functionArgs,
"", block);
430 vector<Value *> gepIndices;
431 gepIndices.push_back(zeroValue32);
432 gepIndices.push_back(zeroValue32);
433 Instruction *dispatchObjectUnionMember = GetElementPtrInst::Create(dispatchObjectUnion, gepIndices,
"", block);
434 return new LoadInst(dispatchObjectUnionMember,
"",
false, block);
446 Value *dispatchObjectValueAsDispatchObject = generateConversionToDispatchObject(module, block, dispatchObjectVariable);
448 StructType *dispatch_object_s_type = getDispatchObjectElementType(module);
449 PointerType *pointerTo_dispatch_object_s_type = PointerType::get(dispatch_object_s_type, 0);
451 vector<Type*> dispatchRetainFunctionParams;
452 dispatchRetainFunctionParams.push_back(pointerTo_dispatch_object_s_type);
453 FunctionType *dispatchRetainFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()), dispatchRetainFunctionParams,
false);
454 Function *dispatchRetainFunction = module->getFunction(
"dispatch_retain");
455 if (! dispatchRetainFunction)
456 dispatchRetainFunction = Function::Create(dispatchRetainFunctionType, GlobalValue::ExternalLinkage,
"dispatch_retain", module);
458 CallInst::Create(dispatchRetainFunction, dispatchObjectValueAsDispatchObject,
"", block);
470 Value *dispatchObjectValueAsDispatchObject = generateConversionToDispatchObject(module, block, dispatchObjectVariable);
472 StructType *dispatch_object_s_type = getDispatchObjectElementType(module);
473 PointerType *pointerTo_dispatch_object_s_type = PointerType::get(dispatch_object_s_type, 0);
475 vector<Type*> dispatchReleaseFunctionParams;
476 dispatchReleaseFunctionParams.push_back(pointerTo_dispatch_object_s_type);
477 FunctionType *dispatchReleaseFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()), dispatchReleaseFunctionParams,
false);
478 Function *dispatchReleaseFunction = module->getFunction(
"dispatch_release");
479 if (! dispatchReleaseFunction)
480 dispatchReleaseFunction = Function::Create(dispatchReleaseFunctionType, GlobalValue::ExternalLinkage,
"dispatch_release", module);
482 CallInst::Create(dispatchReleaseFunction, dispatchObjectValueAsDispatchObject,
"", block);
495 Type *dispatch_time_t_type = IntegerType::get(module->getContext(), 64);
497 vector<Type *> dispatch_time_functionParams;
498 dispatch_time_functionParams.push_back(dispatch_time_t_type);
499 dispatch_time_functionParams.push_back(IntegerType::get(module->getContext(), 64));
500 FunctionType *dispatch_time_functionType = FunctionType::get(dispatch_time_t_type,
501 dispatch_time_functionParams,
504 Function *dispatch_time_function = module->getFunction(
"dispatch_time");
505 if (! dispatch_time_function) {
506 dispatch_time_function = Function::Create(dispatch_time_functionType,
507 GlobalValue::ExternalLinkage,
512 ConstantInt *whenValue = ConstantInt::get(module->getContext(), APInt(64, DISPATCH_TIME_NOW));
514 vector<Value *> args;
515 args.push_back(whenValue);
516 args.push_back(deltaValue);
517 return CallInst::Create(dispatch_time_function, args,
"", block);
531 bool isTrigger,
string triggerQueueName)
533 IntegerType *boolType = IntegerType::get(module->getContext(), 64);
534 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
535 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
537 const char *functionName =
"vuoCreatePortContext";
538 Function *
function = module->getFunction(functionName);
543 vector<Type *> params;
544 params.push_back(voidPointerType);
545 params.push_back(boolType);
546 params.push_back(pointerToCharType);
548 FunctionType *functionType = FunctionType::get(pointerToPortContext, params,
false);
549 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
552 Value *pointerToDataAsVoidPointer;
556 pointerToDataAsVoidPointer =
new BitCastInst(pointerToData, voidPointerType,
"", block);
559 pointerToDataAsVoidPointer = ConstantPointerNull::get(voidPointerType);
561 vector<Value *> args;
562 args.push_back(pointerToDataAsVoidPointer);
563 args.push_back(ConstantInt::get(boolType, isTrigger));
565 return CallInst::Create(
function, args,
"", block);
578 const char *functionName =
"vuoSetPortContextEvent";
579 Function *
function = module->getFunction(functionName);
583 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
584 Type *boolType = portContextType->getElementType(0);
586 vector<Type *> params;
587 params.push_back(pointerToPortContext);
588 params.push_back(boolType);
589 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
590 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
593 vector<Value *> args;
594 args.push_back(portContextValue);
595 args.push_back(eventValue);
596 CallInst::Create(
function, args,
"", block);
610 new StoreInst(dataValue, pointerToData,
false, block);
623 const char *functionName =
"vuoSetPortContextTriggerFunction";
624 Function *
function = module->getFunction(functionName);
628 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
629 Type *triggerFunctionType = portContextType->getElementType(5);
631 vector<Type *> params;
632 params.push_back(pointerToPortContext);
633 params.push_back(triggerFunctionType);
634 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
635 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
638 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
639 Value *triggerFunctionAsVoidPointer =
new BitCastInst(triggerFunctionValue, voidPointerType,
"", block);
641 vector<Value *> args;
642 args.push_back(portContextValue);
643 args.push_back(triggerFunctionAsVoidPointer);
644 CallInst::Create(
function, args,
"", block);
657 const char *functionName =
"vuoGetPortContextEvent";
658 Function *
function = module->getFunction(functionName);
662 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
663 Type *boolType = portContextType->getElementType(0);
665 FunctionType *functionType = FunctionType::get(boolType, pointerToPortContext,
false);
666 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
669 return CallInst::Create(
function, portContextValue,
"", block);
684 return new LoadInst(pointerToData,
"",
false, block);
699 return new BitCastInst(pointerToDataAsVoidPointer, PointerType::get(dataType, 0),
"", block);
712 const char *functionName =
"vuoGetPortContextData";
713 Function *
function = module->getFunction(functionName);
717 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
718 Type *voidPointerType = portContextType->getElementType(1);
720 FunctionType *functionType = FunctionType::get(voidPointerType, pointerToPortContext,
false);
721 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
724 return CallInst::Create(
function, portContextValue,
"", block);
737 const char *functionName =
"vuoGetPortContextTriggerQueue";
738 Function *
function = module->getFunction(functionName);
742 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
743 Type *dispatchQueueType = portContextType->getElementType(3);
745 FunctionType *functionType = FunctionType::get(dispatchQueueType, pointerToPortContext,
false);
746 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
749 return CallInst::Create(
function, portContextValue,
"", block);
762 const char *functionName =
"vuoGetPortContextTriggerSemaphore";
763 Function *
function = module->getFunction(functionName);
767 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
768 Type *dispatchSemaphoreType = portContextType->getElementType(4);
770 FunctionType *functionType = FunctionType::get(dispatchSemaphoreType, pointerToPortContext,
false);
771 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
774 return CallInst::Create(
function, portContextValue,
"", block);
788 const char *functionName =
"vuoGetPortContextTriggerFunction";
789 Function *
function = module->getFunction(functionName);
793 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
794 Type *triggerFunctionType = portContextType->getElementType(5);
796 FunctionType *functionType = FunctionType::get(triggerFunctionType, pointerToPortContext,
false);
797 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
800 Value *triggerFunctionAsVoidPointer = CallInst::Create(
function, portContextValue,
"", block);
801 PointerType *pointerToTriggerFunctionType = PointerType::get(functionType, 0);
802 return new BitCastInst(triggerFunctionAsVoidPointer, pointerToTriggerFunctionType,
"", block);
814 const char *functionName =
"vuoRetainPortContextData";
815 Function *
function = module->getFunction(functionName);
819 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
821 vector<Type *> params;
822 params.push_back(pointerToPortContext);
823 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
824 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
827 vector<Value *> args;
828 args.push_back(portContextValue);
829 CallInst::Create(
function, args,
"", block);
843 bool isComposition,
size_t outputEventCount)
845 IntegerType *boolType = IntegerType::get(module->getContext(), 64);
846 IntegerType *sizeType = IntegerType::get(module->getContext(), 64);
848 const char *functionName =
"vuoCreateNodeContext";
849 Function *
function = module->getFunction(functionName);
854 vector<Type *> params;
855 params.push_back(boolType);
856 params.push_back(boolType);
857 params.push_back(sizeType);
859 FunctionType *functionType = FunctionType::get(pointerToNodeContext, params,
false);
860 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
863 vector<Value *> args;
864 args.push_back(ConstantInt::get(boolType, hasInstanceData));
865 args.push_back(ConstantInt::get(boolType, isComposition));
866 args.push_back(ConstantInt::get(sizeType, outputEventCount));
867 return CallInst::Create(
function, args,
"", block);
881 PointerType *pointerToPointerToPortContext = PointerType::get(pointerToPortContext, 0);
882 IntegerType *sizeType = IntegerType::get(module->getContext(), 64);
884 Value *portContextsArrayValue =
generateMemoryAllocation(module, block, pointerToPortContext, portContextValues.size());
885 for (
size_t i = 0; i < portContextValues.size(); ++i)
888 const char *functionName =
"vuoSetNodeContextPortContexts";
889 Function *
function = module->getFunction(functionName);
893 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
895 vector<Type *> params;
896 params.push_back(pointerToNodeContext);
897 params.push_back(pointerToPointerToPortContext);
898 params.push_back(sizeType);
899 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
900 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
903 vector<Value *> args;
904 args.push_back(nodeContextValue);
905 args.push_back(portContextsArrayValue);
906 args.push_back(ConstantInt::get(sizeType, portContextValues.size()));
907 CallInst::Create(
function, args,
"", block);
921 Type *voidPointerType = nodeContextType->getElementType(2);
923 const char *functionName =
"vuoSetNodeContextInstanceData";
924 Function *
function = module->getFunction(functionName);
927 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
929 vector<Type *> params;
930 params.push_back(pointerToNodeContext);
931 params.push_back(voidPointerType);
932 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
933 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
937 new StoreInst(instanceDataValue, pointerToInstanceData,
false, block);
938 Value *pointerToInstanceDataAsVoidPointer =
new BitCastInst(pointerToInstanceData, voidPointerType,
"", block);
940 vector<Value *> args;
941 args.push_back(nodeContextValue);
942 args.push_back(pointerToInstanceDataAsVoidPointer);
943 CallInst::Create(
function, args,
"", block);
956 const char *functionName =
"vuoSetNodeContextClaimingEventId";
957 Function *
function = module->getFunction(functionName);
961 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
962 Type *eventIdType = nodeContextType->getElementType(4);
964 vector<Type *> params;
965 params.push_back(pointerToNodeContext);
966 params.push_back(eventIdType);
967 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
968 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
971 vector<Value *> args;
972 args.push_back(nodeContextValue);
973 args.push_back(claimingEventIdValue);
974 CallInst::Create(
function, args,
"", block);
988 Type *sizeType = IntegerType::get(module->getContext(), 64);
990 const char *functionName =
"vuoSetNodeContextOutputEvent";
991 Function *
function = module->getFunction(functionName);
995 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
996 Type *boolType = IntegerType::get(module->getContext(), 64);
998 vector<Type *> params;
999 params.push_back(pointerToNodeContext);
1000 params.push_back(sizeType);
1001 params.push_back(boolType);
1002 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1003 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1006 eventValue =
new ZExtInst(eventValue, sizeType,
"", block);
1008 vector<Value *> args;
1009 args.push_back(nodeContextValue);
1010 args.push_back(ConstantInt::get(sizeType, index));
1011 args.push_back(eventValue);
1012 CallInst::Create(
function, args,
"", block);
1026 Type *indexType = IntegerType::get(module->getContext(), 64);
1028 const char *functionName =
"vuoGetNodeContextPortContext";
1029 Function *
function = module->getFunction(functionName);
1033 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1035 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
1037 vector<Type *> params;
1038 params.push_back(pointerToNodeContext);
1039 params.push_back(indexType);
1041 FunctionType *functionType = FunctionType::get(pointerToPortContext, params,
false);
1042 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1045 vector<Value *> args;
1046 args.push_back(nodeContextValue);
1047 args.push_back(ConstantInt::get(indexType, index));
1048 return CallInst::Create(
function, args,
"", block);
1063 return new LoadInst(pointerToInstanceData,
"",
false, block);
1077 const char *functionName =
"vuoGetNodeContextInstanceData";
1078 Function *
function = module->getFunction(functionName);
1082 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1083 Type *voidPointerType = nodeContextType->getElementType(2);
1085 FunctionType *functionType = FunctionType::get(voidPointerType, pointerToNodeContext,
false);
1086 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1089 Value *pointerToInstanceDataAsVoidPointer = CallInst::Create(
function, nodeContextValue,
"", block);
1090 return new BitCastInst(pointerToInstanceDataAsVoidPointer, PointerType::get(instanceDataType, 0),
"", block);
1103 const char *functionName =
"vuoGetNodeContextSemaphore";
1104 Function *
function = module->getFunction(functionName);
1108 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1109 Type *dispatchSemaphoreType = nodeContextType->getElementType(3);
1111 FunctionType *functionType = FunctionType::get(dispatchSemaphoreType, pointerToNodeContext,
false);
1112 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1115 return CallInst::Create(
function, nodeContextValue,
"", block);
1128 const char *functionName =
"vuoGetNodeContextClaimingEventId";
1129 Function *
function = module->getFunction(functionName);
1133 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1134 Type *eventIdType = nodeContextType->getElementType(4);
1136 FunctionType *functionType = FunctionType::get(eventIdType, pointerToNodeContext,
false);
1137 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1140 return CallInst::Create(
function, nodeContextValue,
"", block);
1153 const char *functionName =
"vuoGetNodeContextExecutingGroup";
1154 Function *
function = module->getFunction(functionName);
1158 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1159 Type *dispatchGroupType = nodeContextType->getElementType(5);
1161 FunctionType *functionType = FunctionType::get(dispatchGroupType, pointerToNodeContext,
false);
1162 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1165 return CallInst::Create(
function, nodeContextValue,
"", block);
1179 Type *sizeType = IntegerType::get(module->getContext(), 64);
1181 const char *functionName =
"vuoGetNodeContextOutputEvent";
1182 Function *
function = module->getFunction(functionName);
1186 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1187 Type *boolType = IntegerType::get(module->getContext(), 64);
1189 vector<Type *> params;
1190 params.push_back(pointerToNodeContext);
1191 params.push_back(sizeType);
1192 FunctionType *functionType = FunctionType::get(boolType, params,
false);
1193 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1196 vector<Value *> args;
1197 args.push_back(nodeContextValue);
1198 args.push_back(ConstantInt::get(sizeType, index));
1199 Value *eventValue = CallInst::Create(
function, args,
"", block);
1201 return new TruncInst(eventValue, IntegerType::get(module->getContext(), 1),
"", block);
1213 const char *functionName =
"vuoResetNodeContextEvents";
1214 Function *
function = module->getFunction(functionName);
1217 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1219 vector<Type *> params;
1220 params.push_back(pointerToNodeContextType);
1222 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1223 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1226 vector<Value *> args;
1227 args.push_back(nodeContextValue);
1228 CallInst::Create(
function, args,
"", block);
1241 const char *functionName =
"vuoStartedExecutingEvent";
1242 Function *
function = module->getFunction(functionName);
1245 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1248 vector<Type *> params;
1249 params.push_back(pointerToNodeContextType);
1250 params.push_back(eventIdType);
1252 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1253 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1256 vector<Value *> args;
1257 args.push_back(nodeContextValue);
1258 args.push_back(eventIdValue);
1259 CallInst::Create(
function, args,
"", block);
1272 const char *functionName =
"vuoSpunOffExecutingEvent";
1273 Function *
function = module->getFunction(functionName);
1276 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1279 vector<Type *> params;
1280 params.push_back(pointerToNodeContextType);
1281 params.push_back(eventIdType);
1283 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1284 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1287 vector<Value *> args;
1288 args.push_back(nodeContextValue);
1289 args.push_back(eventIdValue);
1290 CallInst::Create(
function, args,
"", block);
1304 const char *functionName =
"vuoFinishedExecutingEvent";
1305 Function *
function = module->getFunction(functionName);
1308 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1310 Type *boolType = IntegerType::get(module->getContext(), 64);
1312 vector<Type *> params;
1313 params.push_back(pointerToNodeContextType);
1314 params.push_back(eventIdType);
1316 FunctionType *functionType = FunctionType::get(boolType, params,
false);
1317 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1320 vector<Value *> args;
1321 args.push_back(nodeContextValue);
1322 args.push_back(eventIdValue);
1323 return CallInst::Create(
function, args,
"", block);
1336 const char *functionName =
"vuoGetOneExecutingEvent";
1337 Function *
function = module->getFunction(functionName);
1340 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1343 vector<Type *> params;
1344 params.push_back(pointerToNodeContextType);
1346 FunctionType *functionType = FunctionType::get(eventIdType, params,
false);
1347 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1350 vector<Value *> args;
1351 args.push_back(nodeContextValue);
1352 return CallInst::Create(
function, args,
"", block);
1360 const char *functionName =
"vuoCreateCompositionState";
1361 Function *
function = module->getFunction(functionName);
1364 PointerType *pointerToChar = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1365 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1368 vector<Type *> params;
1369 params.push_back(voidPointer);
1370 params.push_back(pointerToChar);
1372 FunctionType *functionType = FunctionType::get(pointerToCompositionState, params,
false);
1373 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1376 vector<Value *> args;
1377 args.push_back(runtimeStateValue);
1378 args.push_back(compositionIdentifierValue);
1379 return CallInst::Create(
function, args,
"", block);
1387 const char *functionName =
"vuoGetCompositionStateRuntimeState";
1388 Function *
function = module->getFunction(functionName);
1392 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1394 vector<Type *> params;
1395 params.push_back(pointerToCompositionState);
1397 FunctionType *functionType = FunctionType::get(voidPointer, params,
false);
1398 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1401 vector<Value *> args;
1402 args.push_back(compositionStateValue);
1403 return CallInst::Create(
function, args,
"", block);
1411 const char *functionName =
"vuoGetCompositionStateCompositionIdentifier";
1412 Function *
function = module->getFunction(functionName);
1416 PointerType *pointerToChar = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1418 vector<Type *> params;
1419 params.push_back(pointerToCompositionState);
1421 FunctionType *functionType = FunctionType::get(pointerToChar, params,
false);
1422 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1425 vector<Value *> args;
1426 args.push_back(compositionStateValue);
1427 return CallInst::Create(
function, args,
"", block);
1435 const char *functionName =
"vuoFreeCompositionState";
1436 Function *
function = module->getFunction(functionName);
1441 vector<Type *> params;
1442 params.push_back(pointerToCompositionState);
1444 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1445 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1448 vector<Value *> args;
1449 args.push_back(compositionStateValue);
1450 CallInst::Create(
function, args,
"", block);
1457 Value *compositionStateValue, Value *portIdentifierValue)
1459 const char *functionName =
"vuoGetDataForPort";
1460 Function *
function = module->getFunction(functionName);
1463 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1464 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1466 vector<Type *> params;
1467 params.push_back(compositionStateValue->getType());
1468 params.push_back(pointerToCharType);
1470 FunctionType *functionType = FunctionType::get(voidPointerType, params,
false);
1471 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1474 vector<Value *> args;
1475 args.push_back(compositionStateValue);
1476 args.push_back(portIdentifierValue);
1477 return CallInst::Create(
function, args,
"", block);
1484 Value *compositionStateValue, Value *portIdentifierValue)
1486 const char *functionName =
"vuoGetNodeSemaphoreForPort";
1487 Function *
function = module->getFunction(functionName);
1490 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1493 vector<Type *> params;
1494 params.push_back(compositionStateValue->getType());
1495 params.push_back(pointerToCharType);
1497 FunctionType *functionType = FunctionType::get(dispatchSemaphoreType, params,
false);
1498 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1501 vector<Value *> args;
1502 args.push_back(compositionStateValue);
1503 args.push_back(portIdentifierValue);
1504 return CallInst::Create(
function, args,
"", block);
1511 Value *compositionStateValue, Value *portIdentifierValue)
1513 const char *functionName =
"vuoGetNodeIndexForPort";
1514 Function *
function = module->getFunction(functionName);
1517 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1518 Type *unsignedLongType = IntegerType::get(module->getContext(), 64);
1520 vector<Type *> params;
1521 params.push_back(compositionStateValue->getType());
1522 params.push_back(pointerToCharType);
1524 FunctionType *functionType = FunctionType::get(unsignedLongType, params,
false);
1525 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1528 vector<Value *> args;
1529 args.push_back(compositionStateValue);
1530 args.push_back(portIdentifierValue);
1531 return CallInst::Create(
function, args,
"", block);
1538 Value *compositionStateValue, Value *portIdentifierValue)
1540 const char *functionName =
"vuoGetTypeIndexForPort";
1541 Function *
function = module->getFunction(functionName);
1544 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1545 Type *unsignedLongType = IntegerType::get(module->getContext(), 64);
1547 vector<Type *> params;
1548 params.push_back(compositionStateValue->getType());
1549 params.push_back(pointerToCharType);
1551 FunctionType *functionType = FunctionType::get(unsignedLongType, params,
false);
1552 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1555 vector<Value *> args;
1556 args.push_back(compositionStateValue);
1557 args.push_back(portIdentifierValue);
1558 return CallInst::Create(
function, args,
"", block);
1565 Value *queueValue, Value *contextValue, Value *workerFunctionValue,
1566 int minThreadsNeeded,
int maxThreadsNeeded,
1567 Value *eventIdValue, Value *compositionStateValue,
1570 Type *intType = IntegerType::get(module->getContext(), 64);
1572 const char *functionName =
"vuoScheduleTriggerWorker";
1573 Function *
function = module->getFunction(functionName);
1576 Type *dispatchQueueType = getDispatchQueueType(module);
1577 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1578 Type *workerFunctionType = workerFunctionValue->getType();
1581 vector<Type *> params;
1582 params.push_back(compositionStateValue->getType());
1583 params.push_back(dispatchQueueType);
1584 params.push_back(voidPointerType);
1585 params.push_back(workerFunctionType);
1586 params.push_back(intType);
1587 params.push_back(intType);
1588 params.push_back(eventIdType);
1589 params.push_back(intType);
1591 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1592 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1595 Value *minThreadsNeededValue = ConstantInt::get(intType, minThreadsNeeded);
1596 Value *maxThreadsNeededValue = ConstantInt::get(intType, maxThreadsNeeded);
1597 Value *chainCountValue = ConstantInt::get(intType, chainCount);
1599 vector<Value *> args;
1600 args.push_back(compositionStateValue);
1601 args.push_back(queueValue);
1602 args.push_back(contextValue);
1603 args.push_back(workerFunctionValue);
1604 args.push_back(minThreadsNeededValue);
1605 args.push_back(maxThreadsNeededValue);
1606 args.push_back(eventIdValue);
1607 args.push_back(chainCountValue);
1608 CallInst::Create(
function, args,
"", block);
1615 Value *queueValue, Value *contextValue, Value *workerFunctionValue,
1616 int minThreadsNeeded,
int maxThreadsNeeded,
1617 Value *eventIdValue, Value *compositionStateValue,
1618 size_t chainIndex, vector<size_t> upstreamChainIndices)
1620 Type *intType = IntegerType::get(module->getContext(), 64);
1623 const char *functionName =
"vuoScheduleChainWorker";
1624 Function *
function = module->getFunction(functionName);
1627 Type *dispatchQueueType = getDispatchQueueType(module);
1628 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1629 Type *workerFunctionType = workerFunctionValue->getType();
1630 PointerType *unsignedLongPointerType = PointerType::get(eventIdType, 0);
1632 vector<Type *> params;
1633 params.push_back(compositionStateValue->getType());
1634 params.push_back(dispatchQueueType);
1635 params.push_back(voidPointerType);
1636 params.push_back(workerFunctionType);
1637 params.push_back(intType);
1638 params.push_back(intType);
1639 params.push_back(eventIdType);
1640 params.push_back(eventIdType);
1641 params.push_back(unsignedLongPointerType);
1642 params.push_back(intType);
1644 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1645 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1648 Value *minThreadsNeededValue = ConstantInt::get(intType, minThreadsNeeded);
1649 Value *maxThreadsNeededValue = ConstantInt::get(intType, maxThreadsNeeded);
1650 Value *chainIndexValue = ConstantInt::get(eventIdType, chainIndex);
1652 Value *upstreamChainIndicesCountValue = ConstantInt::get(intType, (
int)upstreamChainIndices.size());
1653 Value *upstreamChainIndicesValue =
generateMemoryAllocation(module, block, eventIdType, upstreamChainIndices.size());
1654 for (
size_t i = 0; i < upstreamChainIndices.size(); ++i)
1656 Value *upstreamChainIndexValue = ConstantInt::get(eventIdType, upstreamChainIndices[i]);
1660 vector<Value *> args;
1661 args.push_back(compositionStateValue);
1662 args.push_back(queueValue);
1663 args.push_back(contextValue);
1664 args.push_back(workerFunctionValue);
1665 args.push_back(minThreadsNeededValue);
1666 args.push_back(maxThreadsNeededValue);
1667 args.push_back(eventIdValue);
1668 args.push_back(chainIndexValue);
1669 args.push_back(upstreamChainIndicesValue);
1670 args.push_back(upstreamChainIndicesCountValue);
1671 CallInst::Create(
function, args,
"", block);
1678 int minThreadsNeeded,
int maxThreadsNeeded,
1679 Value *eventIdValue, Value *compositionStateValue,
1682 Type *intType = IntegerType::get(module->getContext(), 64);
1685 const char *functionName =
"vuoGrantThreadsToChain";
1686 Function *
function = module->getFunction(functionName);
1689 vector<Type *> params;
1690 params.push_back(compositionStateValue->getType());
1691 params.push_back(intType);
1692 params.push_back(intType);
1693 params.push_back(eventIdType);
1694 params.push_back(eventIdType);
1696 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1697 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1700 Value *minThreadsNeededValue = ConstantInt::get(intType, minThreadsNeeded);
1701 Value *maxThreadsNeededValue = ConstantInt::get(intType, maxThreadsNeeded);
1702 Value *chainIndexValue = ConstantInt::get(eventIdType, chainIndex);
1704 vector<Value *> args;
1705 args.push_back(compositionStateValue);
1706 args.push_back(minThreadsNeededValue);
1707 args.push_back(maxThreadsNeededValue);
1708 args.push_back(eventIdValue);
1709 args.push_back(chainIndexValue);
1710 CallInst::Create(
function, args,
"", block);
1717 Value *eventIdValue, Value *compositionStateValue,
1718 Value *chainIndexValue, Value *subcompositionIdentifierValue)
1720 const char *functionName =
"vuoGrantThreadsToSubcomposition";
1721 Function *
function = module->getFunction(functionName);
1725 PointerType *charPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1727 vector<Type *> params;
1728 params.push_back(compositionStateValue->getType());
1729 params.push_back(eventIdType);
1730 params.push_back(eventIdType);
1731 params.push_back(charPointerType);
1733 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1734 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1737 vector<Value *> args;
1738 args.push_back(compositionStateValue);
1739 args.push_back(eventIdValue);
1740 args.push_back(chainIndexValue);
1741 args.push_back(subcompositionIdentifierValue);
1742 CallInst::Create(
function, args,
"", block);
1749 Value *eventIdValue, Value *compositionStateValue)
1751 const char *functionName =
"vuoReturnThreadsForTriggerWorker";
1752 Function *
function = module->getFunction(functionName);
1757 vector<Type *> params;
1758 params.push_back(compositionStateValue->getType());
1759 params.push_back(eventIdType);
1761 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1762 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1765 vector<Value *> args;
1766 args.push_back(compositionStateValue);
1767 args.push_back(eventIdValue);
1768 CallInst::Create(
function, args,
"", block);
1775 Value *eventIdValue, Value *compositionStateValue,
1776 Value *chainIndexValue)
1778 const char *functionName =
"vuoReturnThreadsForChainWorker";
1779 Function *
function = module->getFunction(functionName);
1784 vector<Type *> params;
1785 params.push_back(compositionStateValue->getType());
1786 params.push_back(eventIdType);
1787 params.push_back(eventIdType);
1789 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1790 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1793 vector<Value *> args;
1794 args.push_back(compositionStateValue);
1795 args.push_back(eventIdValue);
1796 args.push_back(chainIndexValue);
1797 CallInst::Create(
function, args,
"", block);
1805 Value *memberPointer = generateGetArrayElementVariable(module, block, arrayValue, elementIndex);
1806 new StoreInst(value, memberPointer,
false, block);
1814 Value *memberPointer = generateGetArrayElementVariable(module, block, arrayValue, elementIndex);
1815 return new LoadInst(memberPointer,
"", block);
1823 Value *memberPointer = generateGetArrayElementVariable(module, block, arrayValue, elementIndexValue);
1824 return new LoadInst(memberPointer,
"", block);
1830 Value * VuoCompilerCodeGenUtilities::generateGetArrayElementVariable(Module *module, BasicBlock *block, Value *arrayValue,
size_t elementIndex)
1832 ConstantInt *indexValue = ConstantInt::get(module->getContext(), APInt(32, elementIndex));
1833 return generateGetArrayElementVariable(module, block, arrayValue, indexValue);
1839 Value * VuoCompilerCodeGenUtilities::generateGetArrayElementVariable(Module *module, BasicBlock *block, Value *arrayValue, Value *elementIndexValue)
1841 return GetElementPtrInst::Create(arrayValue, elementIndexValue,
"", block);
1849 Value *memberPointer = generateGetStructPointerElementVariable(module, block, structPointer, elementIndex);
1850 new StoreInst(value, memberPointer,
false, block);
1858 Value *memberPointer = generateGetStructPointerElementVariable(module, block, structPointer, elementIndex);
1859 return new LoadInst(memberPointer,
"", block);
1865 Value * VuoCompilerCodeGenUtilities::generateGetStructPointerElementVariable(Module *module, BasicBlock *block, Value *structPointer,
size_t elementIndex)
1867 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
1868 ConstantInt *indexValue = ConstantInt::get(module->getContext(), APInt(32, elementIndex));
1870 vector<Value *> memberIndices;
1871 memberIndices.push_back(zeroValue);
1872 memberIndices.push_back(indexValue);
1873 return GetElementPtrInst::Create(structPointer, memberIndices,
"", block);
1881 AllocaInst *variable =
new AllocaInst(value->getType(),
"", block);
1882 new StoreInst(value, variable,
false, block);
1896 Constant *array = ConstantDataArray::getString(module->getContext(), stringValue);
1897 ArrayType *arrayType = ArrayType::get(IntegerType::get(module->getContext(), 8), stringValue.length() + 1);
1898 GlobalVariable *global =
new GlobalVariable(*module, arrayType,
true, GlobalValue::InternalLinkage, 0,
"");
1899 global->setInitializer(array);
1900 global->setName(globalVariableName);
1902 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
1903 vector<Constant *> pointerIndices;
1904 pointerIndices.push_back(zeroValue);
1905 pointerIndices.push_back(zeroValue);
1906 Constant *pointer = ConstantExpr::getGetElementPtr(global, pointerIndices);
1921 vector<Constant *> arrayElements;
1922 for (vector<string>::iterator i = stringValues.begin(); i != stringValues.end(); ++i)
1925 arrayElements.push_back(stringPointer);
1928 ArrayType *arrayType = ArrayType::get(PointerType::get(IntegerType::get(module->getContext(), 8), 0), arrayElements.size());
1929 GlobalVariable *global =
new GlobalVariable(*module, arrayType,
false, GlobalValue::ExternalLinkage, 0, globalVariableName);
1930 Constant *arrayConstant = ConstantArray::get(arrayType, arrayElements);
1931 global->setInitializer(arrayConstant);
1933 ConstantInt *zeroi64Constant = ConstantInt::get(module->getContext(), APInt(64, 0));
1934 vector<Constant *> pointerIndices;
1935 pointerIndices.push_back(zeroi64Constant);
1936 pointerIndices.push_back(zeroi64Constant);
1937 Constant *pointer = ConstantExpr::getGetElementPtr(global, pointerIndices);
1967 BasicBlock *initialBlock, BasicBlock *finalBlock, Value *inputStringValue,
1968 map<
string, pair<BasicBlock *, BasicBlock *> > blocksForString,
1972 BasicBlock *currentBlock = initialBlock;
1974 for (map<
string, pair<BasicBlock *, BasicBlock *> >::iterator i = blocksForString.begin(); i != blocksForString.end(); ++i)
1976 string currentString = i->first;
1977 BasicBlock *firstTrueBlock = i->second.first;
1978 BasicBlock *lastTrueBlock = i->second.second;
1980 Constant *currentStringValue = constantStrings.
get(module, currentString);
1982 vector<Value *> strcmpArgs;
1983 strcmpArgs.push_back(inputStringValue);
1984 strcmpArgs.push_back(currentStringValue);
1985 CallInst *strcmpCall = CallInst::Create(strcmpFunction, strcmpArgs,
"", currentBlock);
1987 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
1988 ICmpInst *strcmpEqualsZero =
new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, strcmpCall, zeroValue,
"");
1989 BasicBlock *falseBlock = BasicBlock::Create(module->getContext(),
string(
"strcmp-") + currentString,
function, 0);
1990 BranchInst::Create(firstTrueBlock, falseBlock, strcmpEqualsZero, currentBlock);
1992 BranchInst::Create(finalBlock, lastTrueBlock);
1994 currentBlock = falseBlock;
1997 BranchInst::Create(finalBlock, currentBlock);
2024 BasicBlock *initialBlock, BasicBlock *finalBlock, Value *inputIndexValue,
2025 vector< pair<BasicBlock *, BasicBlock *> > blocksForIndex)
2027 BasicBlock *currentBlock = initialBlock;
2029 for (
size_t i = 0; i < blocksForIndex.size(); ++i)
2031 BasicBlock *firstTrueBlock = blocksForIndex[i].first;
2032 BasicBlock *lastTrueBlock = blocksForIndex[i].second;
2034 Constant *currentIndexValue = ConstantInt::get(inputIndexValue->getType(), i);
2035 ICmpInst *indexEqualsCurrent =
new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, inputIndexValue, currentIndexValue,
"");
2036 BasicBlock *falseBlock = BasicBlock::Create(module->getContext(),
"",
function, 0);
2037 BranchInst::Create(firstTrueBlock, falseBlock, indexEqualsCurrent, currentBlock);
2039 BranchInst::Create(finalBlock, lastTrueBlock);
2041 currentBlock = falseBlock;
2044 BranchInst::Create(finalBlock, currentBlock);
2063 Type *charType = IntegerType::get(module->getContext(), 8);
2064 PointerType *pointerToCharType = PointerType::get(charType, 0);
2065 ConstantPointerNull *nullValue = ConstantPointerNull::get(pointerToCharType);
2066 ConstantInt *zeroValue64 = ConstantInt::get(module->getContext(), APInt(64, 0));
2067 ConstantInt *oneValue64 = ConstantInt::get(module->getContext(), APInt(64, 1));
2070 Constant *formatStringValue = constantStrings.
get(module, formatString);
2071 vector<Value *> snprintfArgs;
2072 snprintfArgs.push_back(nullValue);
2073 snprintfArgs.push_back(zeroValue64);
2074 snprintfArgs.push_back(formatStringValue);
2075 for (vector<Value *>::iterator i = replacementValues.begin(); i != replacementValues.end(); ++i)
2076 snprintfArgs.push_back(*i);
2077 Value *bufferLengthValue32 = CallInst::Create(snprintfFunction, snprintfArgs,
"", block);
2078 Value *bufferLengthValue =
new SExtInst(bufferLengthValue32, IntegerType::get(module->getContext(), 64),
"", block);
2079 bufferLengthValue = BinaryOperator::Create(Instruction::Add, bufferLengthValue, oneValue64,
"", block);
2082 AllocaInst *bufferVariable =
new AllocaInst(pointerToCharType,
"buffer", block);
2084 new StoreInst(bufferValue, bufferVariable,
false, block);
2087 snprintfArgs[0] = bufferValue;
2088 snprintfArgs[1] = bufferLengthValue;
2089 CallInst::Create(snprintfFunction, snprintfArgs,
"", block);
2106 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2108 if (stringsToConcatenate.empty())
2110 return constantStrings.
get(module,
"");
2112 else if (stringsToConcatenate.size() == 2)
2114 const char *functionName =
"vuoConcatenateStrings2";
2115 Function *
function = module->getFunction(functionName);
2118 vector<Type *> params;
2119 params.push_back(pointerToCharType);
2120 params.push_back(pointerToCharType);
2122 FunctionType *functionType = FunctionType::get(pointerToCharType, params,
false);
2123 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2126 vector<Value *> args;
2127 args.push_back(stringsToConcatenate[0]);
2128 args.push_back(stringsToConcatenate[1]);
2129 return CallInst::Create(
function, args,
"", block);
2131 else if (stringsToConcatenate.size() == 3)
2133 const char *functionName =
"vuoConcatenateStrings3";
2134 Function *
function = module->getFunction(functionName);
2137 vector<Type *> params;
2138 params.push_back(pointerToCharType);
2139 params.push_back(pointerToCharType);
2140 params.push_back(pointerToCharType);
2142 FunctionType *functionType = FunctionType::get(pointerToCharType, params,
false);
2143 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2146 vector<Value *> args;
2147 args.push_back(stringsToConcatenate[0]);
2148 args.push_back(stringsToConcatenate[1]);
2149 args.push_back(stringsToConcatenate[2]);
2150 return CallInst::Create(
function, args,
"", block);
2154 IntegerType *sizeType = IntegerType::get(module->getContext(), 64);
2156 const char *functionName =
"vuoConcatenateStrings";
2157 Function *
function = module->getFunction(functionName);
2160 vector<Type *> params;
2161 params.push_back(PointerType::get(pointerToCharType, 0));
2162 params.push_back(sizeType);
2164 FunctionType *functionType = FunctionType::get(pointerToCharType, params,
false);
2165 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2169 for (
size_t i = 0; i < stringsToConcatenate.size(); ++i)
2172 vector<Value *> args;
2173 args.push_back(stringsValue);
2174 args.push_back(ConstantInt::get(sizeType, stringsToConcatenate.size()));
2175 Value *concatenatedStringValue = CallInst::Create(
function, args,
"", block);
2179 return concatenatedStringValue;
2194 Value *elementCountValue = ConstantInt::get(module->getContext(), APInt(64, elementCount));
2209 Constant *elementBytesValue = ConstantExpr::getSizeOf(elementType);
2210 Value *elementCountValue64;
2211 if (
static_cast<IntegerType *
>(elementCountValue->getType())->getBitWidth() < 64)
2212 elementCountValue64 =
new SExtInst(elementCountValue, IntegerType::get(module->getContext(), 64),
"", block);
2214 elementCountValue64 = elementCountValue;
2216 BinaryOperator *bytesValue = BinaryOperator::Create(Instruction::Mul, elementBytesValue, elementCountValue64,
"", block);
2219 CallInst *mallocReturnValue = CallInst::Create(mallocFunction, bytesValue,
"", block);
2221 Type *elementPointerType = PointerType::get(elementType, 0);
2222 CastInst *mallocReturnValueCasted =
new BitCastInst(mallocReturnValue, elementPointerType,
"", block);
2224 return mallocReturnValueCasted;
2234 if (valueToCast->getType() == typeToCastTo)
2237 if (valueToCast->getType()->isIntegerTy() && typeToCastTo->isIntegerTy())
2238 return CastInst::CreateIntegerCast(valueToCast, typeToCastTo,
true,
"", block);
2239 else if (valueToCast->getType()->isIntegerTy() && typeToCastTo->isPointerTy())
2240 return generateTypeCastFromIntegerToPointer(module, block, valueToCast, typeToCastTo);
2241 else if (valueToCast->getType()->isFloatingPointTy() && typeToCastTo->isPointerTy())
2242 return generateTypeCastFromFloatingPointToPointer(module, block, valueToCast, typeToCastTo);
2243 else if (valueToCast->getType()->isPointerTy() && typeToCastTo->isIntegerTy())
2244 return generateTypeCastFromPointerToInteger(module, block, valueToCast, typeToCastTo);
2245 else if (valueToCast->getType()->isPointerTy() && typeToCastTo->isFloatingPointTy())
2246 return generateTypeCastFromPointerToFloatingPoint(module, block, valueToCast, typeToCastTo);
2247 else if (typeToCastTo->isStructTy())
2248 return generateTypeCastFromLoweredTypeToStruct(block, valueToCast, typeToCastTo);
2249 else if (typeToCastTo->isVectorTy())
2250 return generateTypeCastFromLoweredTypeToVector(block, valueToCast, typeToCastTo);
2252 return new BitCastInst(valueToCast, typeToCastTo,
"", block);
2267 string annotation,
string fileName,
unsigned int lineNumber,
2271 string valueName = value->getName();
2272 string variableName = valueName +
".addr";
2273 string valueAsVoidPointerName = valueName +
".addr1";
2274 string annotationVariableName = valueName +
"__annotation";
2277 vector<Value *> annotateFunctionArgs;
2280 variable->setName(variableName);
2281 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2282 Value *valueAsVoidPointer =
generateTypeCast(module, block, variable, voidPointerType);
2283 valueAsVoidPointer->setName(valueAsVoidPointerName);
2284 annotateFunctionArgs.push_back(valueAsVoidPointer);
2287 annotateFunctionArgs.push_back(annotationPointer);
2289 Constant *fileNamePointer = constantStrings.
get(module, fileName);
2290 annotateFunctionArgs.push_back(fileNamePointer);
2292 ConstantInt *lineNumberValue = ConstantInt::get(module->getContext(), APInt(32, lineNumber));
2293 annotateFunctionArgs.push_back(lineNumberValue);
2295 CallInst::Create(annotateFunction, annotateFunctionArgs,
"", block);
2305 Type *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2306 string variableName =
"moduleDetails";
2307 if (! moduleKey.empty())
2309 GlobalVariable *moduleDetailsVariable =
new GlobalVariable(*module, pointerToCharType,
false, GlobalValue::ExternalLinkage, 0, variableName);
2310 moduleDetailsVariable->setInitializer(moduleDetailsValue);
2318 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromIntegerToPointer(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2320 unsigned pointerBitWidth = 64;
2321 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2322 CastInst *valueAsIntegerWithPointerBitWidth = CastInst::CreateIntegerCast(valueToCast, integerWithPointerBitWidth,
true,
"", block);
2323 return new IntToPtrInst(valueAsIntegerWithPointerBitWidth, typeToCastTo,
"", block);
2331 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromFloatingPointToPointer(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2333 unsigned pointerBitWidth = 64;
2334 Type *floatingPointWithPointerBitWidth = Type::getDoubleTy(module->getContext());
2335 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2336 CastInst *valueAsFloatingPointWithPointerBitWidth = CastInst::CreateFPCast(valueToCast, floatingPointWithPointerBitWidth,
"", block);
2337 Value *valueAsIntegerWithPointerBitWidth =
new BitCastInst(valueAsFloatingPointWithPointerBitWidth, integerWithPointerBitWidth,
"", block);
2338 return generateTypeCastFromIntegerToPointer(module, block, valueAsIntegerWithPointerBitWidth, typeToCastTo);
2346 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromPointerToInteger(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2348 unsigned pointerBitWidth = 64;
2349 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2350 CastInst *valueAsIntegerWithPointerBitWidth =
new PtrToIntInst(valueToCast, integerWithPointerBitWidth,
"", block);
2351 return CastInst::CreateIntegerCast(valueAsIntegerWithPointerBitWidth, typeToCastTo,
true,
"", block);
2359 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromPointerToFloatingPoint(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2361 unsigned pointerBitWidth = 64;
2362 Type *floatingPointWithPointerBitWidth = Type::getDoubleTy(module->getContext());
2363 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2364 Value *valueAsIntegerWithPointerBitWidth = generateTypeCastFromPointerToInteger(module, block, valueToCast, integerWithPointerBitWidth);
2365 CastInst *valueAsFloatingPointWithPointerBitWidth =
new BitCastInst(valueAsIntegerWithPointerBitWidth, floatingPointWithPointerBitWidth,
"", block);
2366 return CastInst::CreateFPCast(valueAsFloatingPointWithPointerBitWidth, typeToCastTo,
"", block);
2374 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromLoweredTypeToStruct(BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2376 Value *originalValueToCast = valueToCast;
2378 if (valueToCast->getType()->isVectorTy() || valueToCast->getType()->isDoubleTy())
2381 PointerType *pointerToLoweredType = PointerType::get(valueToCast->getType(), 0);
2383 AllocaInst *structVariable =
new AllocaInst(typeToCastTo,
"", block);
2384 CastInst *structVariableAsLoweredType =
new BitCastInst(structVariable, pointerToLoweredType,
"", block);
2385 new StoreInst(valueToCast, structVariableAsLoweredType,
false, block);
2386 return new LoadInst(structVariable,
"",
false, block);
2389 if (valueToCast->getType()->isPointerTy())
2392 valueToCast =
new LoadInst(valueToCast,
"",
false, block);
2393 if (valueToCast->getType() == typeToCastTo)
2397 if (valueToCast->getType()->isStructTy())
2400 StructType *structTypeOfValueToCast =
static_cast<StructType *
>(valueToCast->getType());
2401 PointerType *pointerToTypeToCastTo = PointerType::get(typeToCastTo, 0);
2403 AllocaInst *otherStructVariable =
new AllocaInst(structTypeOfValueToCast,
"", block);
2404 new StoreInst(valueToCast, otherStructVariable,
false, block);
2405 CastInst *otherStructAsTypeToCastTo =
new BitCastInst(otherStructVariable, pointerToTypeToCastTo,
"", block);
2406 return new LoadInst(otherStructAsTypeToCastTo,
"",
false, block);
2409 VUserLog(
"Error: Couldn't cast from lowered type to struct.");
2410 originalValueToCast->getType()->dump(); fprintf(stderr,
"\n");
2411 typeToCastTo->dump(); fprintf(stderr,
"\n");
2412 return originalValueToCast;
2420 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromLoweredTypeToVector(BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2422 if (typeToCastTo->isVectorTy() &&
static_cast<VectorType *
>(typeToCastTo)->getElementType()->isFloatTy())
2424 uint64_t elementCount =
static_cast<VectorType *
>(typeToCastTo)->getNumElements();
2425 if (elementCount == 2 && valueToCast->getType()->isDoubleTy())
2428 PointerType *pointerToDoubleType = PointerType::get(valueToCast->getType(), 0);
2430 AllocaInst *vectorVariable =
new AllocaInst(typeToCastTo,
"", block);
2431 CastInst *dstVectorVariableAsDouble =
new BitCastInst(vectorVariable, pointerToDoubleType,
"", block);
2432 new StoreInst(valueToCast, dstVectorVariableAsDouble,
false, block);
2433 return new LoadInst(vectorVariable,
"",
false, block);
2435 else if (elementCount == 3 && valueToCast->getType()->isVectorTy() &&
2436 static_cast<VectorType *
>(valueToCast->getType())->getNumElements() == 2 &&
2437 static_cast<VectorType *
>(valueToCast->getType())->getElementType()->isDoubleTy())
2440 PointerType *pointerToDoubleVectorType = PointerType::get(valueToCast->getType(), 0);
2442 AllocaInst *floatVectorVariable =
new AllocaInst(typeToCastTo,
"", block);
2443 CastInst *floatVectorVariableAsDoubleVector =
new BitCastInst(floatVectorVariable, pointerToDoubleVectorType,
"", block);
2444 new StoreInst(valueToCast, floatVectorVariableAsDoubleVector,
false, block);
2445 return new LoadInst(floatVectorVariable,
"",
false, block);
2449 VUserLog(
"Error: Couldn't cast from lowered type to vector.");
2450 valueToCast->getType()->dump(); fprintf(stderr,
"\n");
2451 typeToCastTo->dump(); fprintf(stderr,
"\n");
2460 Function *
function = getVuoRegisterFunction(module);
2462 Type *voidPointerType =
function->getFunctionType()->getParamType(0);
2463 Type *pointerToCharType =
function->getFunctionType()->getParamType(2);
2464 Type *intType =
function->getFunctionType()->getParamType(3);
2466 ConstantPointerNull *nullValue = ConstantPointerNull::get(
static_cast<PointerType *
>(pointerToCharType) );
2467 Constant *zeroValue = ConstantInt::get(intType, 0);
2469 vector<Value *> args;
2471 BitCastInst *argumentAsVoidPointer =
new BitCastInst(argument, voidPointerType,
"", block);
2472 args.push_back(argumentAsVoidPointer);
2474 args.push_back(freeFunction);
2476 args.push_back(nullValue);
2477 args.push_back(zeroValue);
2478 args.push_back(nullValue);
2479 args.push_back(nullValue);
2481 CallInst::Create(
function, args,
"", block);
2489 generateRetainOrReleaseCall(module, block, argument,
true);
2497 generateRetainOrReleaseCall(module, block, argument,
false);
2509 void VuoCompilerCodeGenUtilities::generateRetainOrReleaseCall(Module *module, BasicBlock *block, Value *argument,
bool isRetain)
2511 if (argument->getType()->isPointerTy())
2513 Function *
function = (isRetain ? getVuoRetainFunction(module) : getVuoReleaseFunction(module));
2514 Type *voidPointerType =
function->getFunctionType()->getParamType(0);
2516 vector<Value *> retainOrReleaseArgs;
2518 CallInst::Create(
function, retainOrReleaseArgs,
"", block);
2520 else if (argument->getType()->isStructTy())
2522 AllocaInst *structPointer =
new AllocaInst(argument->getType(),
"", block);
2523 new StoreInst(argument, structPointer,
false, block);
2525 int numElements =
static_cast<StructType *
>(argument->getType())->getNumElements();
2526 for (
unsigned i = 0; i < numElements; ++i)
2529 generateRetainOrReleaseCall(module, block, member, isRetain);
2540 return type->isPointerTy() || type->isStructTy();
2549 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2550 Value *argumentAsVoidPointer =
new BitCastInst(argument, voidPointerType,
"", block);
2551 CallInst::Create(freeFunction, argumentAsVoidPointer,
"", block);
2560 CallInst::Create(
function, jsonObjectValue,
"", block);
2568 BasicBlock *initialBlock, BasicBlock *&nullBlock, BasicBlock *¬NullBlock)
2570 nullBlock = BasicBlock::Create(module->getContext(),
"null",
function, NULL);
2571 notNullBlock = BasicBlock::Create(module->getContext(),
"notNull",
function, NULL);
2573 Value *nullValue = ConstantPointerNull::get(
static_cast<PointerType *
>(valueToCheck->getType()) );
2574 ICmpInst *isNotNull =
new ICmpInst(*initialBlock, ICmpInst::ICMP_NE, valueToCheck, nullValue,
"");
2575 BranchInst::Create(notNullBlock, nullBlock, isNotNull, initialBlock);
2584 if (valueToSerialize->getType()->isPointerTy())
2586 vector<Value *> replacementValues;
2587 replacementValues.push_back(valueToSerialize);
2593 VUserLog(
"Error: Couldn't serialize non-pointer value.");
2605 if (destinationVariable->getType()->isPointerTy())
2608 Value *formatString = constantStrings.
get(module,
"%lx");
2610 vector<Value *> sscanfArgs;
2611 sscanfArgs.push_back(stringToUnserialize);
2612 sscanfArgs.push_back(formatString);
2613 sscanfArgs.push_back(destinationVariable);
2614 CallInst::Create(sscanfFunction, sscanfArgs,
"", block);
2627 Type *boolType = IntegerType::get(module->getContext(), 64);
2629 const char *functionName =
"vuoIsPaused";
2630 Function *
function = module->getFunction(functionName);
2633 FunctionType *functionType = FunctionType::get(boolType, compositionStateValue->getType(),
false);
2634 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2637 CallInst *isPausedValue = CallInst::Create(
function, compositionStateValue,
"", block);
2638 Constant *falseValue = ConstantInt::get(boolType, 0);
2639 return new ICmpInst(*block, ICmpInst::ICMP_NE, isPausedValue, falseValue,
"");
2646 Value *compositionStateValue, Value *nodeIdentifierValue)
2648 const char *functionName =
"vuoSendNodeExecutionStarted";
2649 Function *
function = module->getFunction(functionName);
2653 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2655 vector<Type *> functionParams;
2656 functionParams.push_back(pointerToCompositionState);
2657 functionParams.push_back(pointerToCharType);
2658 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2659 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2662 vector<Value *> args;
2663 args.push_back(compositionStateValue);
2664 args.push_back(nodeIdentifierValue);
2665 CallInst::Create(
function, args,
"", block);
2672 Value *compositionStateValue, Value *nodeIdentifierValue)
2674 const char *functionName =
"vuoSendNodeExecutionFinished";
2675 Function *
function = module->getFunction(functionName);
2679 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2681 vector<Type *> functionParams;
2682 functionParams.push_back(pointerToCompositionState);
2683 functionParams.push_back(pointerToCharType);
2684 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2685 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2688 vector<Value *> args;
2689 args.push_back(compositionStateValue);
2690 args.push_back(nodeIdentifierValue);
2691 CallInst::Create(
function, args,
"", block);
2698 Value *compositionStateValue, Value *portIdentifierValue,
2699 bool receivedEvent,
bool receivedData,
2700 Value *portDataSummaryValue)
2702 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2703 Value *receivedEventValue = ConstantInt::get(boolType, receivedEvent ? 1 : 0);
2704 Value *receivedDataValue = ConstantInt::get(boolType, receivedData ? 1 : 0);
2705 generateSendInputPortsUpdated(module, block, compositionStateValue, portIdentifierValue, receivedEventValue, receivedDataValue, portDataSummaryValue);
2712 Value *compositionStateValue, Value *portIdentifierValue,
2713 Value *receivedEventValue, Value *receivedDataValue,
2714 Value *portDataSummaryValue)
2716 const char *functionName =
"vuoSendInputPortsUpdated";
2717 Function *
function = module->getFunction(functionName);
2721 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2722 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2724 vector<Type *> functionParams;
2725 functionParams.push_back(pointerToCompositionState);
2726 functionParams.push_back(pointerToCharType);
2727 functionParams.push_back(boolType);
2728 functionParams.push_back(boolType);
2729 functionParams.push_back(pointerToCharType);
2730 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2731 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2734 vector<Value *> args;
2735 args.push_back(compositionStateValue);
2736 args.push_back(portIdentifierValue);
2737 args.push_back(receivedEventValue);
2738 args.push_back(receivedDataValue);
2739 args.push_back(portDataSummaryValue);
2740 CallInst::Create(
function, args,
"", block);
2747 Value *compositionStateValue, Value *portIdentifierValue,
2748 Value *sentEventValue, Value *sentDataValue,
2749 Value *portDataSummaryValue)
2751 const char *functionName =
"vuoSendOutputPortsUpdated";
2752 Function *
function = module->getFunction(functionName);
2756 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2757 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2759 vector<Type *> functionParams;
2760 functionParams.push_back(pointerToCompositionState);
2761 functionParams.push_back(pointerToCharType);
2762 functionParams.push_back(boolType);
2763 functionParams.push_back(boolType);
2764 functionParams.push_back(pointerToCharType);
2765 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2766 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2769 vector<Value *> args;
2770 args.push_back(compositionStateValue);
2771 args.push_back(portIdentifierValue);
2772 args.push_back(sentEventValue);
2773 args.push_back(sentDataValue);
2774 args.push_back(portDataSummaryValue);
2775 CallInst::Create(
function, args,
"", block);
2782 Value *compositionStateValue, Value *portIdentifierValue,
2783 Value *sentDataValue, Value *portDataSummaryValue)
2785 const char *functionName =
"vuoSendPublishedOutputPortsUpdated";
2786 Function *
function = module->getFunction(functionName);
2790 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2791 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2793 vector<Type *> functionParams;
2794 functionParams.push_back(pointerToCompositionState);
2795 functionParams.push_back(pointerToCharType);
2796 functionParams.push_back(boolType);
2797 functionParams.push_back(pointerToCharType);
2798 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2799 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2802 vector<Value *> args;
2803 args.push_back(compositionStateValue);
2804 args.push_back(portIdentifierValue);
2805 args.push_back(sentDataValue);
2806 args.push_back(portDataSummaryValue);
2807 CallInst::Create(
function, args,
"", block);
2814 Value *compositionStateValue, Value *eventIdValue)
2816 const char *functionName =
"vuoSendEventFinished";
2817 Function *
function = module->getFunction(functionName);
2823 vector<Type *> functionParams;
2824 functionParams.push_back(pointerToCompositionState);
2825 functionParams.push_back(eventIdType);
2826 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2827 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2830 vector<Value *> args;
2831 args.push_back(compositionStateValue);
2832 args.push_back(eventIdValue);
2833 CallInst::Create(
function, args,
"", block);
2840 Value *compositionStateValue, Value *portIdentifierValue)
2842 const char *functionName =
"vuoSendEventDropped";
2843 Function *
function = module->getFunction(functionName);
2847 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2849 vector<Type *> functionParams;
2850 functionParams.push_back(pointerToCompositionState);
2851 functionParams.push_back(pointerToCharType);
2852 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2853 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2856 vector<Value *> args;
2857 args.push_back(compositionStateValue);
2858 args.push_back(portIdentifierValue);
2859 CallInst::Create(
function, args,
"", block);
2866 Value *compositionStateValue,
2869 const char *functionName =
"vuoShouldSendPortDataTelemetry";
2870 Function *shouldSendTelemetryFunction = module->getFunction(functionName);
2871 if (! shouldSendTelemetryFunction)
2874 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2876 vector<Type *> functionParams;
2877 functionParams.push_back(pointerToCompositionState);
2878 functionParams.push_back(pointerToCharType);
2879 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
2880 shouldSendTelemetryFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2883 Constant *portIdentifierValue = constantStrings.
get(module, portIdentifier);
2885 vector<Value *> args;
2886 args.push_back(compositionStateValue);
2887 args.push_back(portIdentifierValue);
2888 CallInst *retValue = CallInst::Create(shouldSendTelemetryFunction, args,
"", block);
2890 Constant *zeroValue = ConstantInt::get(retValue->getType(), 0);
2891 return new ICmpInst(*block, ICmpInst::ICMP_NE, retValue, zeroValue,
"");
2899 Value *compositionStateValue,
2900 BasicBlock *initialBlock, BasicBlock *&trueBlock, BasicBlock *&falseBlock,
2902 Value *&replacementJsonValue)
2904 Type *boolType = IntegerType::get(module->getContext(), 64);
2905 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
2907 const char *functionName =
"vuoIsNodeBeingRemovedOrReplaced";
2908 Function *calledFunction = module->getFunction(functionName);
2909 if (! calledFunction)
2911 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2912 PointerType *pointerToPointerToJsonObjectType = PointerType::get(pointerToJsonObjectType, 0);
2914 vector<Type *> functionParams;
2915 functionParams.push_back(compositionStateValue->getType());
2916 functionParams.push_back(pointerToCharType);
2917 functionParams.push_back(pointerToPointerToJsonObjectType);
2918 FunctionType *functionType = FunctionType::get(boolType, functionParams,
false);
2919 calledFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2922 Value *nodeIdentifierValue = constantStrings.
get(module, nodeIdentifier);
2924 AllocaInst *replacementJsonVariable =
new AllocaInst(pointerToJsonObjectType,
"", initialBlock);
2925 new StoreInst(ConstantPointerNull::get(pointerToJsonObjectType), replacementJsonVariable,
false, initialBlock);
2927 vector<Value *> args;
2928 args.push_back(compositionStateValue);
2929 args.push_back(nodeIdentifierValue);
2930 args.push_back(replacementJsonVariable);
2931 CallInst *retValue = CallInst::Create(calledFunction, args,
"", initialBlock);
2933 replacementJsonValue =
new LoadInst(replacementJsonVariable,
"",
false, initialBlock);
2935 trueBlock = BasicBlock::Create(module->getContext(),
"removedReplaced",
function, NULL);
2936 falseBlock = BasicBlock::Create(module->getContext(),
"notRemovedReplaced",
function, NULL);
2937 Constant *falseValue = ConstantInt::get(boolType, 0);
2938 ICmpInst *retIsTrue =
new ICmpInst(*initialBlock, ICmpInst::ICMP_NE, retValue, falseValue,
"");
2939 BranchInst::Create(trueBlock, falseBlock, retIsTrue, initialBlock);
2947 Value *compositionStateValue,
2948 BasicBlock *initialBlock, BasicBlock *&trueBlock, BasicBlock *&falseBlock,
2950 Value *&replacementJsonValue)
2952 Type *boolType = IntegerType::get(module->getContext(), 64);
2953 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
2955 const char *functionName =
"vuoIsNodeBeingAddedOrReplaced";
2956 Function *calledFunction = module->getFunction(functionName);
2957 if (! calledFunction)
2959 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2960 PointerType *pointerToPointerToJsonObjectType = PointerType::get(pointerToJsonObjectType, 0);
2962 vector<Type *> functionParams;
2963 functionParams.push_back(compositionStateValue->getType());
2964 functionParams.push_back(pointerToCharType);
2965 functionParams.push_back(pointerToPointerToJsonObjectType);
2966 FunctionType *functionType = FunctionType::get(boolType, functionParams,
false);
2967 calledFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2970 Value *nodeIdentifierValue = constantStrings.
get(module, nodeIdentifier);
2972 AllocaInst *replacementJsonVariable =
new AllocaInst(pointerToJsonObjectType,
"", initialBlock);
2973 new StoreInst(ConstantPointerNull::get(pointerToJsonObjectType), replacementJsonVariable,
false, initialBlock);
2975 vector<Value *> args;
2976 args.push_back(compositionStateValue);
2977 args.push_back(nodeIdentifierValue);
2978 args.push_back(replacementJsonVariable);
2979 CallInst *retValue = CallInst::Create(calledFunction, args,
"", initialBlock);
2981 replacementJsonValue =
new LoadInst(replacementJsonVariable,
"",
false, initialBlock);
2983 trueBlock = BasicBlock::Create(module->getContext(),
"addedReplaced",
function, NULL);
2984 falseBlock = BasicBlock::Create(module->getContext(),
"notAddedReplaced",
function, NULL);
2985 Constant *falseValue = ConstantInt::get(boolType, 0);
2986 ICmpInst *retIsTrue =
new ICmpInst(*initialBlock, ICmpInst::ICMP_NE, retValue, falseValue,
"");
2987 BranchInst::Create(trueBlock, falseBlock, retIsTrue, initialBlock);
2997 return ConstantInt::get(module->getContext(), APInt(64, 0));
3004 Value *compositionStateValue,
size_t nodeIndex)
3006 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3007 Value *nodeIndexValue = ConstantInt::get(unsignedLongType, nodeIndex);
3015 Value *compositionStateValue, Value *nodeIndexValue)
3017 const char *functionName =
"vuoGetNodeContext";
3018 Function *
function = module->getFunction(functionName);
3021 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3022 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
3024 vector<Type *> functionParams;
3025 functionParams.push_back(compositionStateValue->getType());
3026 functionParams.push_back(unsignedLongType);
3027 FunctionType *functionType = FunctionType::get(pointerToNodeContextType, functionParams,
false);
3028 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3031 vector<Value *> args;
3032 args.push_back(compositionStateValue);
3033 args.push_back(nodeIndexValue);
3034 return CallInst::Create(
function, args,
"", block);
3041 Value *compositionStateValue)
3043 const char *functionName =
"vuoGetCompositionContext";
3044 Function *
function = module->getFunction(functionName);
3047 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
3049 vector<Type *> functionParams;
3050 functionParams.push_back(compositionStateValue->getType());
3051 FunctionType *functionType = FunctionType::get(pointerToNodeContextType, functionParams,
false);
3052 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3055 vector<Value *> args;
3056 args.push_back(compositionStateValue);
3057 return CallInst::Create(
function, args,
"", block);
3064 Value *compositionStateValue, Value *nodeIdentifierValue,
3065 Function *compositionCreateContextForNodeFunction,
3066 Function *compositionSetPortValueFunction,
3067 Function *compositionGetPortValueFunction,
3068 Function *compositionFireTriggerPortEventFunction,
3069 Function *compositionReleasePortDataFunction)
3071 const char *functionName =
"vuoAddNodeMetadata";
3072 Function *
function = module->getFunction(functionName);
3075 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3082 vector<Type *> functionParams;
3083 functionParams.push_back(compositionStateValue->getType());
3084 functionParams.push_back(pointerToCharType);
3085 functionParams.push_back(compositionCreateContextForNodeFunctionType);
3086 functionParams.push_back(compositionSetPortValueFunctionType);
3087 functionParams.push_back(compositionGetPortValueFunctionType);
3088 functionParams.push_back(compositionFireTriggerPortEventFunctionType);
3089 functionParams.push_back(compositionReleasePortDataFunctionType);
3090 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3091 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3094 vector<Value *> args;
3095 args.push_back(compositionStateValue);
3096 args.push_back(nodeIdentifierValue);
3097 args.push_back(compositionCreateContextForNodeFunction);
3098 args.push_back(compositionSetPortValueFunction);
3099 args.push_back(compositionGetPortValueFunction);
3100 args.push_back(compositionFireTriggerPortEventFunction);
3101 args.push_back(compositionReleasePortDataFunction);
3102 CallInst::Create(
function, args,
"", block);
3109 Value *compositionStateValue, Value *portIdentifierValue,
3110 Value *portNameValue,
size_t typeIndex, Value *initialValueValue)
3112 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3114 const char *functionName =
"vuoAddPortMetadata";
3115 Function *
function = module->getFunction(functionName);
3118 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3120 vector<Type *> functionParams;
3121 functionParams.push_back(compositionStateValue->getType());
3122 functionParams.push_back(pointerToCharType);
3123 functionParams.push_back(pointerToCharType);
3124 functionParams.push_back(unsignedLongType);
3125 functionParams.push_back(pointerToCharType);
3126 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3127 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3130 Value *typeIndexValue = ConstantInt::get(unsignedLongType, typeIndex);
3132 vector<Value *> args;
3133 args.push_back(compositionStateValue);
3134 args.push_back(portIdentifierValue);
3135 args.push_back(portNameValue);
3136 args.push_back(typeIndexValue);
3137 args.push_back(initialValueValue);
3138 CallInst::Create(
function, args,
"", block);
3145 bool isStatefulComposition,
size_t publishedOutputPortCount)
3147 IntegerType *boolType = IntegerType::get(module->getContext(), 64);
3148 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3150 const char *functionName =
"vuoInitContextForTopLevelComposition";
3151 Function *
function = module->getFunction(functionName);
3156 vector<Type *> functionParams;
3157 functionParams.push_back(pointerToCompositionState);
3158 functionParams.push_back(boolType);
3159 functionParams.push_back(unsignedLongType);
3160 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3161 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3164 Value *isStatefulCompositionValue = ConstantInt::get(boolType, isStatefulComposition);
3165 Value *publishedOutputPortCountValue = ConstantInt::get(unsignedLongType, publishedOutputPortCount);
3167 vector<Value *> args;
3168 args.push_back(compositionStateValue);
3169 args.push_back(isStatefulCompositionValue);
3170 args.push_back(publishedOutputPortCountValue);
3171 CallInst::Create(
function, args,
"", block);
3179 const char *functionName =
"vuoFiniContextForTopLevelComposition";
3180 Function *
function = module->getFunction(functionName);
3185 vector<Type *> functionParams;
3186 functionParams.push_back(pointerToCompositionState);
3187 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3188 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3191 vector<Value *> args;
3192 args.push_back(compositionStateValue);
3193 CallInst::Create(
function, args,
"", block);
3201 const char *functionName =
"vuoGetTriggerWorkersScheduled";
3202 Function *
function = module->getFunction(functionName);
3208 vector<Type *> functionParams;
3209 functionParams.push_back(pointerToCompositionState);
3210 FunctionType *functionType = FunctionType::get(dispatchGroupType, functionParams,
false);
3211 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3214 vector<Value *> args;
3215 args.push_back(compositionStateValue);
3216 return CallInst::Create(
function, args,
"", block);
3223 Value *portIdentifierValue, Value *interprocessSerializationValue)
3225 const char *functionName =
"vuoGetInputPortString";
3226 Function *
function = module->getFunction(functionName);
3230 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3231 IntegerType *boolType = IntegerType::get(module->getContext(), 32);
3233 vector<Type *> functionParams;
3234 functionParams.push_back(pointerToCompositionState);
3235 functionParams.push_back(pointerToCharType);
3236 functionParams.push_back(boolType);
3237 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3238 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3241 vector<Value *> args;
3242 args.push_back(compositionStateValue);
3243 args.push_back(portIdentifierValue);
3244 args.push_back(interprocessSerializationValue);
3245 return CallInst::Create(
function, args,
"", block);
3252 Value *portIdentifierValue, Value *interprocessSerializationValue)
3254 const char *functionName =
"vuoGetOutputPortString";
3255 Function *
function = module->getFunction(functionName);
3259 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3260 IntegerType *boolType = IntegerType::get(module->getContext(), 32);
3262 vector<Type *> functionParams;
3263 functionParams.push_back(pointerToCompositionState);
3264 functionParams.push_back(pointerToCharType);
3265 functionParams.push_back(boolType);
3266 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3267 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3270 vector<Value *> args;
3271 args.push_back(compositionStateValue);
3272 args.push_back(portIdentifierValue);
3273 args.push_back(interprocessSerializationValue);
3274 return CallInst::Create(
function, args,
"", block);
3282 const char *variableName =
"vuoRuntimeState";
3283 GlobalVariable *variable = module->getNamedGlobal(variableName);
3286 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3287 variable =
new GlobalVariable(*module, voidPointer,
false, GlobalValue::ExternalLinkage, 0, variableName);
3290 return new LoadInst(variable,
"",
false, block);
3298 const char *functionName =
"vuoGetNextEventId";
3299 Function *
function = module->getFunction(functionName);
3303 Type *eventIdType = IntegerType::get(module->getContext(), 64);
3305 vector<Type *> functionParams;
3306 functionParams.push_back(pointerToCompositionState);
3307 FunctionType *functionType = FunctionType::get(eventIdType, functionParams,
false);
3308 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3311 vector<Value *> args;
3312 args.push_back(compositionStateValue);
3313 return CallInst::Create(
function, args,
"", block);
3320 Value *compositionStateValue, Value *dataCopyValue,
3321 Value *eventIdCopyValue)
3323 const char *functionName =
"vuoCreateTriggerWorkerContext";
3324 Function *
function = module->getFunction(functionName);
3328 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3331 vector<Type *> functionParams;
3332 functionParams.push_back(pointerToCompositionState);
3333 functionParams.push_back(voidPointerType);
3334 functionParams.push_back(pointerToEventIdType);
3335 FunctionType *functionType = FunctionType::get(voidPointerType, functionParams,
false);
3336 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3339 vector<Value *> args;
3340 args.push_back(compositionStateValue);
3341 args.push_back(dataCopyValue);
3342 args.push_back(eventIdCopyValue);
3343 return CallInst::Create(
function, args,
"", block);
3351 const char *functionName =
"vuoFreeTriggerWorkerContext";
3352 Function *
function = module->getFunction(functionName);
3355 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3357 vector<Type *> functionParams;
3358 functionParams.push_back(voidPointerType);
3359 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3360 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3363 vector<Value *> args;
3364 args.push_back(contextValue);
3365 CallInst::Create(
function, args,
"", block);
3372 Value *compositionStateValue, Value *inputPortIdentifierValue,
3373 Value *valueAsStringValue, Value *isCompositionRunningValue)
3375 const char *functionName =
"vuoCreatePublishedInputWorkerContext";
3376 Function *
function = module->getFunction(functionName);
3380 PointerType *pointerToChar = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3381 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3382 Type *boolType = IntegerType::get(module->getContext(), 64);
3384 vector<Type *> functionParams;
3385 functionParams.push_back(pointerToCompositionState);
3386 functionParams.push_back(pointerToChar);
3387 functionParams.push_back(pointerToChar);
3388 functionParams.push_back(boolType);
3389 FunctionType *functionType = FunctionType::get(voidPointerType, functionParams,
false);
3390 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3393 vector<Value *> args;
3394 args.push_back(compositionStateValue);
3395 args.push_back(inputPortIdentifierValue);
3396 args.push_back(valueAsStringValue);
3397 args.push_back(isCompositionRunningValue);
3398 return CallInst::Create(
function, args,
"", block);
3405 Value *compositionStateValue)
3407 const char *functionName =
"vuoAddCompositionStateToThreadLocalStorage";
3408 Function *
function = module->getFunction(functionName);
3413 vector<Type *> functionParams;
3414 functionParams.push_back(pointerToCompositionState);
3415 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3416 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3419 vector<Value *> args;
3420 args.push_back(compositionStateValue);
3421 CallInst::Create(
function, args,
"", block);
3429 const char *functionName =
"vuoRemoveCompositionStateFromThreadLocalStorage";
3430 Function *
function = module->getFunction(functionName);
3433 vector<Type *> functionParams;
3434 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3435 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3438 vector<Value *> args;
3439 CallInst::Create(
function, args,
"", block);
3445 Value * VuoCompilerCodeGenUtilities::generateStderr(Module *module, BasicBlock *block)
3447 PointerType *pointerToFileType = getPointerToFileType(module);
3449 string variableName =
"__stderrp";
3450 GlobalVariable *stderrVariable = module->getNamedGlobal(variableName);
3451 if (! stderrVariable)
3452 stderrVariable =
new GlobalVariable(*module, pointerToFileType,
false, GlobalValue::ExternalLinkage, 0, variableName);
3454 return new LoadInst(stderrVariable,
"",
false, block);
3462 vector<Value *> values;
3464 values.push_back(value);
3474 Value *stderrValue = generateStderr(module, block);
3477 vector<Value *> fprintfArgs;
3478 fprintfArgs.push_back(stderrValue);
3479 fprintfArgs.push_back(formatStringValue);
3480 for (vector<Value *>::const_iterator i = values.begin(); i != values.end(); ++i)
3481 fprintfArgs.push_back(*i);
3482 CallInst::Create(fprintfFunction, fprintfArgs,
"", block);
3491 StructType *dispatch_semaphore_s_type = module->getTypeByName(
"struct.dispatch_semaphore_s");
3492 if (! dispatch_semaphore_s_type)
3493 dispatch_semaphore_s_type = StructType::create(module->getContext(),
"struct.dispatch_semaphore_s");
3495 PointerType *dispatch_semaphore_t_type = PointerType::get(dispatch_semaphore_s_type, 0);
3496 return dispatch_semaphore_t_type;
3501 StructType *dispatch_group_s_type = module->getTypeByName(
"struct.dispatch_group_s");
3502 if (! dispatch_group_s_type)
3503 dispatch_group_s_type = StructType::create(module->getContext(),
"struct.dispatch_group_s");
3505 PointerType *dispatch_group_t_type = PointerType::get(dispatch_group_s_type, 0);
3506 return dispatch_group_t_type;
3509 PointerType * VuoCompilerCodeGenUtilities::getDispatchQueueType(Module *module)
3511 StructType *dispatch_queue_s_type = module->getTypeByName(
"struct.dispatch_queue_s");
3512 if (! dispatch_queue_s_type)
3513 dispatch_queue_s_type = StructType::create(module->getContext(),
"struct.dispatch_queue_s");
3515 PointerType *dispatch_queue_t_type = PointerType::get(dispatch_queue_s_type, 0);
3516 return dispatch_queue_t_type;
3519 StructType * VuoCompilerCodeGenUtilities::getDispatchObjectElementType(Module *module)
3521 StructType *dispatch_object_s_type = module->getTypeByName(
"struct.dispatch_object_s");
3522 if (! dispatch_object_s_type)
3523 dispatch_object_s_type = StructType::create(module->getContext(),
"struct.dispatch_object_s");
3524 vector<Type *> dispatch_object_s_fields;
3525 if (dispatch_object_s_type->isOpaque())
3526 dispatch_object_s_type->setBody(dispatch_object_s_fields,
false);
3527 return dispatch_object_s_type;
3532 StructType *dispatch_object_s_type = getDispatchObjectElementType(module);
3533 PointerType *pointerTo_dispatch_object_s_type = PointerType::get(dispatch_object_s_type, 0);
3535 StructType *dispatch_object_t_type = module->getTypeByName(
"union.dispatch_object_t");
3536 if (! dispatch_object_t_type)
3537 dispatch_object_t_type = StructType::create(module->getContext(),
"union.dispatch_object_t");
3538 vector<Type *> dispatch_object_t_fields;
3539 dispatch_object_t_fields.push_back(pointerTo_dispatch_object_s_type);
3540 if (dispatch_object_t_type->isOpaque())
3541 dispatch_object_t_type->setBody(dispatch_object_t_fields,
false);
3542 return dispatch_object_t_type;
3547 StructType *nodeContextType = module->getTypeByName(
"struct.NodeContext");
3548 if (! nodeContextType)
3549 nodeContextType = StructType::create(module->getContext(),
"struct.NodeContext");
3551 if (nodeContextType->isOpaque())
3553 PointerType *pointerToPointerToPortContextType = PointerType::get(PointerType::get(
getPortContextType(module), 0), 0);
3554 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3555 Type *longType = IntegerType::get(module->getContext(), 64);
3557 vector<Type *> fields;
3558 fields.push_back(pointerToPointerToPortContextType);
3559 fields.push_back(longType);
3560 fields.push_back(voidPointerType);
3562 fields.push_back(longType);
3564 fields.push_back(longType);
3565 nodeContextType->setBody(fields,
false);
3568 return nodeContextType;
3573 StructType *portContextType = module->getTypeByName(
"struct.PortContext");
3574 if (! portContextType)
3575 portContextType = StructType::create(module->getContext(),
"struct.PortContext");
3577 if (portContextType->isOpaque())
3579 Type *boolType = IntegerType::get(module->getContext(), 64);
3580 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3582 vector<Type *> fields;
3583 fields.push_back(boolType);
3584 fields.push_back(voidPointerType);
3585 fields.push_back(boolType);
3586 fields.push_back(getDispatchQueueType(module));
3588 fields.push_back(voidPointerType);
3589 portContextType->setBody(fields,
false);
3592 return portContextType;
3597 StructType *compositionStateType = module->getTypeByName(
"struct.VuoCompositionState");
3598 if (! compositionStateType)
3599 compositionStateType = StructType::create(module->getContext(),
"struct.VuoCompositionState");
3601 if (compositionStateType->isOpaque())
3603 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3604 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3606 vector<Type *> fields;
3607 fields.push_back(voidPointerType);
3608 fields.push_back(pointerToCharType);
3609 compositionStateType->setBody(fields,
false);
3612 return compositionStateType;
3615 StructType * VuoCompilerCodeGenUtilities::getGraphvizGraphType(Module *module)
3617 StructType *graphType = module->getTypeByName(
"struct.Agraph_t");
3619 graphType = StructType::create(module->getContext(),
"struct.Agraph_t");
3626 StructType *jsonObjectType = module->getTypeByName(
"struct.json_object");
3627 if (! jsonObjectType)
3628 jsonObjectType = StructType::create(module->getContext(),
"struct.json_object");
3630 return jsonObjectType;
3633 PointerType * VuoCompilerCodeGenUtilities::getPointerToFileType(Module *module)
3635 StructType *fileType = module->getTypeByName(
"struct.__sFILE");
3637 fileType = StructType::create(module->getContext(),
"struct.__sFILE");
3639 return PointerType::get(fileType, 0);
3642 PointerType * VuoCompilerCodeGenUtilities::getVuoShaderType(Module *module)
3644 StructType *shaderStructType = module->getTypeByName(
"struct._VuoShader");
3645 if (! shaderStructType)
3646 shaderStructType = StructType::create(module->getContext(),
"struct._VuoShader");
3648 return PointerType::get(shaderStructType, 0);
3651 PointerType * VuoCompilerCodeGenUtilities::getVuoImageType(Module *module)
3653 StructType *imageStructType = module->getTypeByName(
"struct._VuoImage");
3654 if (! imageStructType)
3655 imageStructType = StructType::create(module->getContext(),
"struct._VuoImage");
3657 return PointerType::get(imageStructType, 0);
3660 Type * VuoCompilerCodeGenUtilities::getVuoImageColorDepthType(Module *module)
3662 return IntegerType::get(module->getContext(), 32);
3667 return PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3678 const char *functionName =
"strcat";
3679 Function *
function = module->getFunction(functionName);
3682 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3684 vector<Type *> functionParams;
3685 functionParams.push_back(pointerToCharType);
3686 functionParams.push_back(pointerToCharType);
3687 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3688 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3695 const char *functionName =
"strcmp";
3696 Function *
function = module->getFunction(functionName);
3699 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3700 vector<Type *> functionParams;
3701 functionParams.push_back(pointerToi8Type);
3702 functionParams.push_back(pointerToi8Type);
3703 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
3704 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3711 const char *functionName =
"strdup";
3712 Function *
function = module->getFunction(functionName);
3715 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3717 vector<Type *> functionParams;
3718 functionParams.push_back(pointerToCharType);
3719 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3720 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3727 const char *functionName =
"strlen";
3728 Function *
function = module->getFunction(functionName);
3731 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3733 vector<Type *> functionParams;
3734 functionParams.push_back(pointerToCharType);
3735 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 64), functionParams,
false);
3736 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3743 const char *functionName =
"snprintf";
3744 Function *
function = module->getFunction(functionName);
3747 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3749 vector<Type *> functionParams;
3750 functionParams.push_back(pointerToCharType);
3751 functionParams.push_back(IntegerType::get(module->getContext(), 64));
3752 functionParams.push_back(pointerToCharType);
3753 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
true);
3754 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3761 const char *functionName =
"sscanf";
3762 Function *
function = module->getFunction(functionName);
3765 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3767 vector<Type *> functionParams;
3768 functionParams.push_back(pointerToCharType);
3769 functionParams.push_back(pointerToCharType);
3770 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
true);
3771 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3778 const char *functionName =
"fprintf";
3779 Function *
function = module->getFunction(functionName);
3782 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3784 vector<Type *> functionParams;
3785 functionParams.push_back( getPointerToFileType(module) );
3786 functionParams.push_back(pointerToCharType);
3787 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
true);
3788 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3795 const char *functionName =
"puts";
3796 Function *
function = module->getFunction(functionName);
3799 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3801 vector<Type *> functionParams;
3802 functionParams.push_back(pointerToCharType);
3803 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
3804 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3811 const char *functionName =
"malloc";
3812 Function *
function = module->getFunction(functionName);
3815 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3817 vector<Type *> functionParams;
3818 functionParams.push_back(IntegerType::get(module->getContext(),
sizeof(
size_t)*CHAR_BIT));
3819 FunctionType *functionType = FunctionType::get(pointerToi8Type, functionParams,
false);
3820 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3827 const char *functionName =
"free";
3828 Function *
function = module->getFunction(functionName);
3831 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3833 vector<Type *> functionParams;
3834 functionParams.push_back(pointerToi8Type);
3835 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3836 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3843 const char *functionName =
"llvm.var.annotation";
3844 Function *
function = module->getFunction(functionName);
3847 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3849 vector<Type *> functionParams;
3850 functionParams.push_back(pointerToi8Type);
3851 functionParams.push_back(pointerToi8Type);
3852 functionParams.push_back(pointerToi8Type);
3853 functionParams.push_back(IntegerType::get(module->getContext(), 32));
3854 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3855 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3862 const char *functionName =
"json_object_put";
3863 Function *
function = module->getFunction(functionName);
3866 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
3868 vector<Type *> functionParams;
3869 functionParams.push_back(pointerToJsonObjectType);
3870 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
3871 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3878 const char *functionName =
"json_object_to_json_string_ext";
3879 Function *
function = module->getFunction(functionName);
3882 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3883 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
3885 vector<Type *> functionParams;
3886 functionParams.push_back(pointerToJsonObjectType);
3887 functionParams.push_back(IntegerType::get(module->getContext(), 32));
3888 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3889 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3896 const char *functionName =
"json_tokener_parse";
3897 Function *
function = module->getFunction(functionName);
3900 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3901 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
3903 vector<Type *> functionParams;
3904 functionParams.push_back(pointerToCharType);
3905 FunctionType *functionType = FunctionType::get(pointerToJsonObjectType, functionParams,
false);
3906 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3913 const char *functionName =
"VuoShader_make";
3914 Function *
function = module->getFunction(functionName);
3917 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3918 Type *shaderType = getVuoShaderType(module);
3920 vector<Type *> functionParams;
3921 functionParams.push_back(pointerToCharType);
3922 FunctionType *functionType = FunctionType::get(shaderType, functionParams,
false);
3923 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3930 const char *functionName =
"VuoShader_addSource";
3931 Function *
function = module->getFunction(functionName);
3934 Type *shaderType = getVuoShaderType(module);
3935 Type *elementAsseblyMethodType = IntegerType::get(module->getContext(), 64);
3936 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3938 vector<Type *> functionParams;
3939 functionParams.push_back(shaderType);
3940 functionParams.push_back(elementAsseblyMethodType);
3941 functionParams.push_back(pointerToCharType);
3942 functionParams.push_back(pointerToCharType);
3943 functionParams.push_back(pointerToCharType);
3944 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3945 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3952 const char *functionName =
"VuoShader_setTransparent";
3953 Function *
function = module->getFunction(functionName);
3956 Type *shaderType = getVuoShaderType(module);
3957 Type *boolType = IntegerType::get(module->getContext(), 1);
3959 vector<Type *> functionParams;
3960 functionParams.push_back(shaderType);
3961 functionParams.push_back(boolType);
3962 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3963 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3971 Function *
function = module->getFunction(functionName);
3974 Type *shaderType = getVuoShaderType(module);
3975 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3977 Type *dataSecondParam =
nullptr;
3980 vector<Type *> functionParams;
3981 functionParams.push_back(shaderType);
3982 functionParams.push_back(pointerToCharType);
3983 functionParams.push_back(dataParam);
3984 if (dataSecondParam)
3985 functionParams.push_back(dataSecondParam);
3986 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3987 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3994 string functionName =
"VuoShader_samplerRectCoordinatesFromNormalizedCoordinates";
3995 Function *
function = module->getFunction(functionName);
3998 Type *loweredPoint2dType = Type::getDoubleTy(module->getContext());
3999 Type *intType = IntegerType::get(module->getContext(), 64);
4001 vector<Type *> functionParams;
4002 functionParams.push_back(loweredPoint2dType);
4003 functionParams.push_back(intType);
4004 functionParams.push_back(intType);
4005 FunctionType *functionType = FunctionType::get(loweredPoint2dType, functionParams,
false);
4006 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4013 const char *functionName =
"VuoImage_getColorDepth";
4014 Function *
function = module->getFunction(functionName);
4017 Type *imageType = getVuoImageType(module);
4018 Type *imageColorDepthType = getVuoImageColorDepthType(module);
4020 vector<Type *> functionParams;
4021 functionParams.push_back(imageType);
4022 FunctionType *functionType = FunctionType::get(imageColorDepthType, functionParams,
false);
4023 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4030 const char *functionName =
"VuoImageRenderer_render";
4031 Function *
function = module->getFunction(functionName);
4034 Type *shaderType = getVuoShaderType(module);
4035 Type *intType = IntegerType::get(module->getContext(), 64);
4036 Type *imageColorDepthType = getVuoImageColorDepthType(module);
4037 Type *imageType = getVuoImageType(module);
4039 vector<Type *> functionParams;
4040 functionParams.push_back(shaderType);
4041 functionParams.push_back(intType);
4042 functionParams.push_back(intType);
4043 functionParams.push_back(imageColorDepthType);
4044 FunctionType *functionType = FunctionType::get(imageType, functionParams,
false);
4045 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4052 string functionName =
"compositionAddNodeMetadata";
4053 string moduleKey = module->getModuleIdentifier();
4054 if (! moduleKey.empty())
4056 Function *
function = module->getFunction(functionName.c_str());
4061 vector<Type *> functionParams;
4062 functionParams.push_back(pointerToCompositionState);
4063 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4064 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4071 string functionName =
"compositionCreateContextForNode";
4072 string moduleKey = module->getModuleIdentifier();
4073 if (! moduleKey.empty())
4075 Function *
function = module->getFunction(functionName.c_str());
4078 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
4079 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
4081 vector<Type *> functionParams;
4082 functionParams.push_back(unsignedLongType);
4083 FunctionType *functionType = FunctionType::get(pointerToNodeContextType, functionParams,
false);
4084 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4091 string functionName =
"compositionPerformDataOnlyTransmissions";
4092 string moduleKey = module->getModuleIdentifier();
4093 if (! moduleKey.empty())
4095 Function *
function = module->getFunction(functionName.c_str());
4100 vector<Type *> functionParams;
4101 functionParams.push_back(pointerToCompositionState);
4102 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4103 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4110 string functionName =
"compositionReleasePortData";
4111 string moduleKey = module->getModuleIdentifier();
4112 if (! moduleKey.empty())
4114 Function *
function = module->getFunction(functionName.c_str());
4117 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4118 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
4120 vector<Type *> functionParams;
4121 functionParams.push_back(voidPointer);
4122 functionParams.push_back(unsignedLongType);
4123 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4124 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4131 const char *functionName =
"vuoSetup";
4132 Function *
function = module->getFunction(functionName);
4135 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4136 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4143 const char *functionName =
"vuoCleanup";
4144 Function *
function = module->getFunction(functionName);
4147 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4148 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4155 const char *functionName =
"vuoInstanceInit";
4156 Function *
function = module->getFunction(functionName);
4159 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4160 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4167 const char *functionName =
"vuoInstanceFini";
4168 Function *
function = module->getFunction(functionName);
4171 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4172 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4179 const char *functionName =
"vuoInstanceTriggerStart";
4180 Function *
function = module->getFunction(functionName);
4183 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), PointerType::get(
getCompositionInstanceDataType(module), 0),
false);
4184 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4191 const char *functionName =
"vuoInstanceTriggerStop";
4192 Function *
function = module->getFunction(functionName);
4195 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), PointerType::get(
getCompositionInstanceDataType(module), 0),
false);
4196 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4202 Type *instanceDataType,
4203 const vector<VuoPort *> &modelInputPorts,
4204 map<VuoPort *, size_t> &indexOfParameter,
4207 map<VuoPort *, size_t> indexOfEventParameter;
4208 return getNodeFunction(module, moduleKey,
"nodeInstanceInit", isSubcomposition,
false,
true,
false, instanceDataType, modelInputPorts, vector<VuoPort *>(),
4209 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4210 indexOfParameter, indexOfEventParameter, constantStrings);
4214 Type *instanceDataType,
4217 map<VuoPort *, size_t> indexOfParameter;
4218 map<VuoPort *, size_t> indexOfEventParameter;
4219 return getNodeFunction(module, moduleKey,
"nodeInstanceFini",
true,
true,
false,
false, instanceDataType, vector<VuoPort *>(), vector<VuoPort *>(),
4220 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4221 indexOfParameter, indexOfEventParameter, constantStrings);
4225 Type *instanceDataType,
4226 const vector<VuoPort *> &modelInputPorts,
4227 map<VuoPort *, size_t> &indexOfParameter,
4230 map<VuoPort *, size_t> indexOfEventParameter;
4231 return getNodeFunction(module, moduleKey,
"nodeInstanceTriggerStart",
true,
true,
false,
false, instanceDataType, modelInputPorts, vector<VuoPort *>(),
4232 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4233 indexOfParameter, indexOfEventParameter, constantStrings);
4237 Type *instanceDataType,
4240 map<VuoPort *, size_t> indexOfParameter;
4241 map<VuoPort *, size_t> indexOfEventParameter;
4242 return getNodeFunction(module, moduleKey,
"nodeInstanceTriggerStop",
true,
true,
false,
false, instanceDataType, vector<VuoPort *>(), vector<VuoPort *>(),
4243 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4244 indexOfParameter, indexOfEventParameter, constantStrings);
4248 Type *instanceDataType,
4249 const vector<VuoPort *> &modelInputPorts,
4250 map<VuoPort *, size_t> &indexOfParameter,
4253 map<VuoPort *, size_t> indexOfEventParameter;
4254 return getNodeFunction(module, moduleKey,
"nodeInstanceTriggerUpdate",
true,
true,
false,
false, instanceDataType, modelInputPorts, vector<VuoPort *>(),
4255 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4256 indexOfParameter, indexOfEventParameter, constantStrings);
4260 Type *instanceDataType,
4261 const vector<VuoPort *> &modelInputPorts,
4262 const vector<VuoPort *> &modelOutputPorts,
4263 const map<VuoPort *, json_object *> &detailsForPorts,
4264 const map<VuoPort *, string> &displayNamesForPorts,
4265 const map<VuoPort *, string> &defaultValuesForInputPorts,
4266 const map<VuoPort *, VuoPortClass::EventBlocking> &eventBlockingForInputPorts,
4267 map<VuoPort *, size_t> &indexOfParameter,
4268 map<VuoPort *, size_t> &indexOfEventParameter,
4271 string functionName = (isStateful ?
"nodeInstanceEvent" :
"nodeEvent");
4272 return getNodeFunction(module, moduleKey, functionName, isSubcomposition, isStateful,
false,
true, instanceDataType, modelInputPorts, modelOutputPorts,
4273 detailsForPorts, displayNamesForPorts, defaultValuesForInputPorts, eventBlockingForInputPorts,
4274 indexOfParameter, indexOfEventParameter, constantStrings);
4277 Function * VuoCompilerCodeGenUtilities::getNodeFunction(Module *module,
string moduleKey,
string functionName,
4278 bool hasCompositionStateArg,
bool hasInstanceDataArg,
4279 bool hasInstanceDataReturn,
bool hasEventArgs,
4280 Type *instanceDataType,
4281 const vector<VuoPort *> &modelInputPorts,
const vector<VuoPort *> &modelOutputPorts,
4282 const map<VuoPort *, json_object *> &detailsForPorts,
4283 const map<VuoPort *, string> &displayNamesForPorts,
4284 const map<VuoPort *, string> &defaultValuesForInputPorts,
4285 const map<VuoPort *, VuoPortClass::EventBlocking> &eventBlockingForInputPorts,
4286 map<VuoPort *, size_t> &indexOfParameter,
4287 map<VuoPort *, size_t> &indexOfEventParameter,
4290 if (! moduleKey.empty())
4292 Function *
function = module->getFunction(functionName.c_str());
4296 vector<Type *> functionParams;
4297 map<int, AttributeSet> functionAttributes;
4298 map<VuoPort *, bool> hasSecondParam;
4299 Type *boolType = IntegerType::get(module->getContext(), 1);
4300 size_t indexInEventFunction = 0;
4302 if (hasCompositionStateArg)
4305 functionParams.push_back(pointerToCompositionState);
4306 indexInEventFunction++;
4309 if (hasInstanceDataArg)
4311 functionParams.push_back( PointerType::get(instanceDataType, 0) );
4312 indexInEventFunction++;
4315 for (vector<VuoPort *>::const_iterator i = modelInputPorts.begin(); i != modelInputPorts.end(); ++i)
4322 Type *paramSecondType = NULL;
4326 functionParams.push_back(paramType);
4334 if (! (hasCompositionStateArg &&
4336 paramAttributes.hasAttrSomewhere(Attribute::ByVal)) )
4338 functionAttributes[ functionParams.size() - 1] = paramAttributes;
4341 indexOfParameter[modelInputPort->
getBase()] = indexInEventFunction++;
4343 if (paramSecondType)
4345 functionParams.push_back(paramSecondType);
4346 functionAttributes[ functionParams.size() - 1] = paramAttributes;
4347 hasSecondParam[*i] =
true;
4349 indexInEventFunction++;
4354 functionParams.push_back(boolType);
4356 indexOfEventParameter[modelInputPort->
getBase()] = indexInEventFunction++;
4359 else if (hasEventArgs)
4361 functionParams.push_back(boolType);
4363 indexOfParameter[modelInputPort->
getBase()] = indexInEventFunction++;
4367 for (vector<VuoPort *>::const_iterator i = modelOutputPorts.begin(); i != modelOutputPorts.end(); ++i)
4375 PointerType *triggerFunctionPointerType = PointerType::get(functionType, 0);
4376 functionParams.push_back(triggerFunctionPointerType);
4378 indexOfParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4385 functionParams.push_back(paramType);
4387 indexOfParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4391 PointerType *eventParamType = PointerType::get( boolType, 0 );
4392 functionParams.push_back(eventParamType);
4394 indexOfEventParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4397 else if (hasEventArgs)
4399 PointerType *paramType = PointerType::get( boolType, 0 );
4400 functionParams.push_back(paramType);
4402 indexOfParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4407 Type *returnType = (hasInstanceDataReturn ? instanceDataType : Type::getVoidTy(module->getContext()));
4408 FunctionType *functionType = FunctionType::get(returnType, functionParams,
false);
4409 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4411 for (map<int, AttributeSet>::iterator i = functionAttributes.begin(); i != functionAttributes.end(); ++i)
4413 int attributesIndex = i->first + 1;
4414 AttributeSet attributes = i->second;
4418 set<string> argNamesUsed;
4420 BasicBlock *block = BasicBlock::Create(module->getContext(),
"",
function, 0);
4421 Function::arg_iterator argIter =
function->arg_begin();
4423 if (hasCompositionStateArg)
4425 Value *arg = argIter++;
4426 string argName =
"compositionState";
4427 arg->setName(argName);
4428 argNamesUsed.insert(argName);
4431 if (hasInstanceDataArg)
4433 Value *arg = argIter++;
4434 string argName =
"instanceData";
4435 arg->setName(argName);
4436 argNamesUsed.insert(argName);
4440 argNamesUsed.insert(
"refresh");
4442 map<VuoPort *, string> primaryArgNames;
4443 auto recordUniqueArgName = [&primaryArgNames, &argNamesUsed] (
VuoPort *modelPort)
4446 primaryArgNames[modelPort] = argName;
4448 std::for_each(modelInputPorts.begin(), modelInputPorts.end(), recordUniqueArgName);
4449 std::for_each(modelOutputPorts.begin(), modelOutputPorts.end(), recordUniqueArgName);
4451 for (vector<VuoPort *>::const_iterator i = modelInputPorts.begin(); i != modelInputPorts.end(); ++i)
4456 if (type || hasEventArgs)
4458 Value *arg = argIter++;
4461 string argName = primaryArgNames[modelInputPort];
4462 arg->setName(argName);
4464 map<VuoPort *, VuoPortClass::EventBlocking>::const_iterator eventBlockingIter = eventBlockingForInputPorts.find(modelInputPort);
4465 bool hasNonDefaultEventBlocking = (eventBlockingIter != eventBlockingForInputPorts.end() && eventBlockingIter->second !=
VuoPortClass::EventBlocking_None);
4469 map<VuoPort *, json_object *>::const_iterator detailsIter = detailsForPorts.find(modelInputPort);
4470 if (detailsIter != detailsForPorts.end())
4472 json_object_object_foreach(detailsIter->second, key, val)
4474 json_object_object_add(details, key, val);
4475 json_object_get(val);
4478 map<VuoPort *, string>::const_iterator displayNameIter = displayNamesForPorts.find(modelInputPort);
4479 if (displayNameIter != displayNamesForPorts.end())
4480 json_object_object_add(details,
"name", json_object_new_string(displayNameIter->second.c_str()));
4487 map<VuoPort *, string>::const_iterator defaultValueIter = defaultValuesForInputPorts.find(modelInputPort);
4488 if (defaultValueIter != defaultValuesForInputPorts.end())
4489 json_object_object_add(details,
"default", json_tokener_parse(defaultValueIter->second.c_str()));
4491 if (hasSecondParam[modelInputPort])
4493 Value *secondArg = argIter++;
4494 secondArg->setName(argName +
".1");
4499 Value *eventArg = argIter++;
4501 string preferredEventArgName = portName +
"Event";
4503 eventArg->setName(eventArgName);
4505 generateAnnotation(module, block, eventArg,
"vuoInputEvent",
"", 0, constantStrings);
4507 json_object *eventDetails = json_object_new_object();
4508 json_object_object_add(eventDetails,
"data", json_object_new_string(argName.c_str()));
4509 if (hasNonDefaultEventBlocking)
4510 json_object_object_add(eventDetails,
"eventBlocking", json_object_new_string(eventBlockingStr.c_str()));
4511 string eventDetailsStr = json_object_to_json_string_ext(eventDetails, JSON_C_TO_STRING_PLAIN);
4512 json_object_put(eventDetails);
4513 generateAnnotation(module, block, eventArg,
"vuoDetails:" + eventDetailsStr,
"", 0, constantStrings);
4516 else if (hasEventArgs)
4520 if (hasNonDefaultEventBlocking)
4521 json_object_object_add(details,
"eventBlocking", json_object_new_string(eventBlockingStr.c_str()));
4524 string detailsStr = json_object_to_json_string_ext(details, JSON_C_TO_STRING_PLAIN);
4525 json_object_put(details);
4526 generateAnnotation(module, block, arg,
"vuoDetails:" + detailsStr,
"", 0, constantStrings);
4530 for (vector<VuoPort *>::const_iterator i = modelOutputPorts.begin(); i != modelOutputPorts.end(); ++i)
4532 VuoPort *modelOutputPort = *i;
4534 Value *arg = argIter++;
4537 string argName = primaryArgNames[modelOutputPort];
4538 arg->setName(argName);
4541 map<VuoPort *, json_object *>::const_iterator detailsIter = detailsForPorts.find(modelOutputPort);
4542 if (detailsIter != detailsForPorts.end())
4544 json_object_object_foreach(detailsIter->second, key, val)
4546 json_object_object_add(details, key, val);
4547 json_object_get(val);
4550 map<VuoPort *, string>::const_iterator displayNameIter = displayNamesForPorts.find(modelOutputPort);
4551 if (displayNameIter != displayNamesForPorts.end())
4552 json_object_object_add(details,
"name", json_object_new_string(displayNameIter->second.c_str()));
4553 string detailsStr = json_object_to_json_string_ext(details, JSON_C_TO_STRING_PLAIN);
4554 json_object_put(details);
4555 generateAnnotation(module, block, arg,
"vuoDetails:" + detailsStr,
"", 0, constantStrings);
4560 generateAnnotation(module, block, arg,
"vuoOutputTrigger:" + argName,
"", 0, constantStrings);
4572 Value *eventArg = argIter++;
4574 string preferredEventArgName = portName +
"Event";
4576 eventArg->setName(eventArgName);
4578 generateAnnotation(module, block, eventArg,
"vuoOutputEvent",
"", 0, constantStrings);
4580 json_object *eventDetails = json_object_new_object();
4581 json_object_object_add(eventDetails,
"data", json_object_new_string(argName.c_str()));
4582 string eventDetailsStr = json_object_to_json_string_ext(eventDetails, JSON_C_TO_STRING_PLAIN);
4583 json_object_put(eventDetails);
4584 generateAnnotation(module, block, eventArg,
"vuoDetails:" + eventDetailsStr,
"", 0, constantStrings);
4587 else if (hasEventArgs)
4598 Function * VuoCompilerCodeGenUtilities::getVuoRegisterFunction(Module *module)
4600 const char *functionName =
"VuoRegisterF";
4601 Function *
function = module->getFunction(functionName);
4604 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4605 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4606 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4608 FunctionType *deallocateFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()), voidPointerType,
false);
4609 PointerType *deallocateFunctionPointerType = PointerType::get(deallocateFunctionType, 0);
4611 vector<Type *> functionParams;
4612 functionParams.push_back(voidPointerType);
4613 functionParams.push_back(deallocateFunctionPointerType);
4614 functionParams.push_back(pointerToCharType);
4615 functionParams.push_back(intType);
4616 functionParams.push_back(pointerToCharType);
4617 functionParams.push_back(pointerToCharType);
4618 FunctionType *functionType = FunctionType::get(intType, functionParams,
false);
4619 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4624 Function * VuoCompilerCodeGenUtilities::getVuoRetainFunction(Module *module)
4626 const char *functionName =
"VuoRetain";
4627 Function *
function = module->getFunction(functionName);
4630 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4631 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4633 vector<Type *> functionParams;
4634 functionParams.push_back(voidPointerType);
4635 FunctionType *functionType = FunctionType::get(intType, functionParams,
false);
4636 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4641 Function * VuoCompilerCodeGenUtilities::getVuoReleaseFunction(Module *module)
4643 const char *functionName =
"VuoRelease";
4644 Function *
function = module->getFunction(functionName);
4647 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4648 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4650 vector<Type *> functionParams;
4651 functionParams.push_back(voidPointerType);
4652 FunctionType *functionType = FunctionType::get(intType, functionParams,
false);
4653 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4660 string functionName =
"compositionWaitForNode";
4661 if (! moduleKey.empty())
4663 Function *
function = module->getFunction(functionName.c_str());
4667 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
4668 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
4670 vector<Type *> functionParams;
4671 functionParams.push_back(pointerToCompositionState);
4672 functionParams.push_back(unsignedLongType);
4673 functionParams.push_back(unsignedLongType);
4674 functionParams.push_back(boolType);
4675 FunctionType *functionType = FunctionType::get(boolType, functionParams,
false);
4676 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4683 string functionName =
"compositionGetPortValue";
4684 string moduleKey = module->getModuleIdentifier();
4685 if (! moduleKey.empty())
4687 Function *
function = module->getFunction(functionName.c_str());
4691 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4692 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4694 vector<Type *> functionParams;
4695 functionParams.push_back(pointerToCompositionState);
4696 functionParams.push_back(pointerToCharType);
4697 functionParams.push_back(intType);
4698 functionParams.push_back(intType);
4699 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
4700 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4707 string functionName =
"compositionSetPortValue";
4708 string moduleKey = module->getModuleIdentifier();
4709 if (! moduleKey.empty())
4711 Function *
function = module->getFunction(functionName.c_str());
4715 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4716 Type *boolType = IntegerType::get(module->getContext(), 32);
4718 vector<Type *> functionParams;
4719 functionParams.push_back(pointerToCompositionState);
4720 functionParams.push_back(pointerToCharType);
4721 functionParams.push_back(pointerToCharType);
4722 functionParams.push_back(boolType);
4723 functionParams.push_back(boolType);
4724 functionParams.push_back(boolType);
4725 functionParams.push_back(boolType);
4726 functionParams.push_back(boolType);
4727 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4728 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4735 string functionName =
"compositionFireTriggerPortEvent";
4736 string moduleKey = module->getModuleIdentifier();
4737 if (! moduleKey.empty())
4739 Function *
function = module->getFunction(functionName.c_str());
4743 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4745 vector<Type *> functionParams;
4746 functionParams.push_back(pointerToCompositionState);
4747 functionParams.push_back(pointerToCharType);
4748 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4749 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4756 const char *functionName =
"vuoSetInputPortValue";
4757 Function *
function = module->getFunction(functionName);
4760 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4762 vector<Type *> functionParams;
4763 functionParams.push_back(pointerToCharType);
4764 functionParams.push_back(pointerToCharType);
4765 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4766 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4773 const char *functionName =
"getPublishedInputPortValue";
4774 Function *
function = module->getFunction(functionName);
4777 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4778 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4780 vector<Type *> functionParams;
4781 functionParams.push_back(pointerToCharType);
4782 functionParams.push_back(intType);
4783 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
4784 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4791 const char *functionName =
"getPublishedOutputPortValue";
4792 Function *
function = module->getFunction(functionName);
4795 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4796 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4798 vector<Type *> functionParams;
4799 functionParams.push_back(pointerToCharType);
4800 functionParams.push_back(intType);
4801 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
4802 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4809 string functionName =
"compositionSetPublishedInputPortValue";
4810 string moduleKey = module->getModuleIdentifier();
4811 if (! moduleKey.empty())
4813 Function *
function = module->getFunction(functionName.c_str());
4817 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4818 Type *boolType = IntegerType::get(module->getContext(), 64);
4820 vector<Type *> functionParams;
4821 functionParams.push_back(pointerToCompositionState);
4822 functionParams.push_back(pointerToCharType);
4823 functionParams.push_back(pointerToCharType);
4824 functionParams.push_back(boolType);
4825 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4826 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4833 const char *functionName =
"setPublishedInputPortValue";
4834 Function *
function = module->getFunction(functionName);
4837 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4839 vector<Type *> functionParams;
4840 functionParams.push_back(pointerToCharType);
4841 functionParams.push_back(pointerToCharType);
4842 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4843 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4856 if (typeName ==
"VuoPoint2d")
4857 return VectorType::get(Type::getFloatTy(module->getContext()), 2);
4858 if (typeName ==
"VuoPoint3d")
4859 return VectorType::get(Type::getFloatTy(module->getContext()), 3);
4860 if (typeName ==
"VuoPoint4d")
4861 return VectorType::get(Type::getFloatTy(module->getContext()), 4);
4863 Type *type =
function->getFunctionType()->getParamType(0);
4864 bool hasSecondType = (
function->getFunctionType()->getNumParams() == 2);
4867 if (isParameterPassedByValue(
function, 0) || type->isVectorTy() || hasSecondType)
4868 type = module->getTypeByName(
"struct." + typeName);
4872 VUserLog(
"Couldn't guess the original type for %s", typeName.c_str());
4873 function->getFunctionType()->dump(); fprintf(stderr,
"\n");
4890 Module *module, BasicBlock *block)
4892 Type *unloweredType = unloweredVuoType->
getType();
4894 Type *secondLoweredType = NULL;
4896 bool hasSecondArgument = (secondLoweredType != NULL);
4898 Function::arg_iterator argIter =
function->arg_begin();
4899 for (
int i = 0; i < parameterIndex; ++i)
4901 Value *argument = argIter;
4902 Value *secondArgument = (hasSecondArgument ? ++argIter : NULL);
4904 if (unloweredType->isVectorTy())
4906 if (
static_cast<VectorType *
>(unloweredType)->getElementType()->isFloatTy())
4908 uint64_t elementCount =
static_cast<VectorType *
>(unloweredType)->getNumElements();
4909 if (elementCount == 2 && argument->getType()->isDoubleTy())
4912 PointerType *pointerToVectorType = PointerType::get(unloweredType, 0);
4915 Value *vectorVariable =
new BitCastInst(vectorVariableAsDouble, pointerToVectorType,
"", block);
4916 return new LoadInst(vectorVariable,
"",
false, block);
4918 else if (elementCount == 3 && argument->getType()->isVectorTy() &&
4919 static_cast<VectorType *
>(argument->getType())->getNumElements() == 2 &&
4920 static_cast<VectorType *
>(argument->getType())->getElementType()->isDoubleTy())
4923 PointerType *pointerToFloatVectorType = PointerType::get(unloweredType, 0);
4926 Value *floatVectorVariable =
new BitCastInst(floatVectorValueAsDoubleVector, pointerToFloatVectorType,
"", block);
4927 return new LoadInst(floatVectorVariable,
"",
false, block);
4931 else if (unloweredType->isStructTy())
4933 if (! hasSecondArgument)
4935 if (argument->getType()->isVectorTy())
4938 PointerType *pointerToStructType = PointerType::get(unloweredType, 0);
4941 Value *structVariable =
new BitCastInst(structVariableAsVector, pointerToStructType,
"", block);
4942 return new LoadInst(structVariable,
"",
false, block);
4948 PointerType *pointerToStructType = PointerType::get(unloweredType, 0);
4950 vector<Type *> bothLoweredMembers;
4951 bothLoweredMembers.push_back(argument->getType());
4952 bothLoweredMembers.push_back(secondLoweredType);
4953 StructType *bothLoweredTypes = StructType::create(bothLoweredMembers);
4955 Value *structVariableAsBothLoweredTypes =
new AllocaInst(bothLoweredTypes,
"", block);
4957 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
4958 ConstantInt *oneValue = ConstantInt::get(module->getContext(), APInt(32, 1));
4960 vector<Value *> firstMemberIndices;
4961 firstMemberIndices.push_back(zeroValue);
4962 firstMemberIndices.push_back(zeroValue);
4963 Value *firstMemberPointer = GetElementPtrInst::Create(structVariableAsBothLoweredTypes, firstMemberIndices,
"", block);
4964 new StoreInst(argument, firstMemberPointer, block);
4966 vector<Value *> secondMemberIndices;
4967 secondMemberIndices.push_back(zeroValue);
4968 secondMemberIndices.push_back(oneValue);
4969 Value *secondMemberPointer = GetElementPtrInst::Create(structVariableAsBothLoweredTypes, secondMemberIndices,
"", block);
4970 new StoreInst(secondArgument, secondMemberPointer, block);
4972 Value *structVariable =
new BitCastInst(structVariableAsBothLoweredTypes, pointerToStructType,
"", block);
4973 return new LoadInst(structVariable,
"",
false, block);
4976 if (isParameterPassedByValue(
function, parameterIndex))
4979 argument =
new LoadInst(argument,
"",
false, block);
4983 if (argument->getType() != unloweredType)
4986 if (argument->getType()->isStructTy() && unloweredType->isStructTy())
4989 Type *pointerToUnloweredType = PointerType::get(unloweredType, 0);
4990 Value *argumentVariableAsUnloweredType =
new BitCastInst(argumentVariable, pointerToUnloweredType,
"", block);
4991 return new LoadInst(argumentVariableAsUnloweredType,
"",
false, block);
4995 Type *sourceType = argument->getType();
4996 Type *destinationType = unloweredType;
4997 while (sourceType->isPointerTy() && destinationType->isPointerTy())
4999 Type *sourceElementType =
static_cast<PointerType *
>(sourceType)->getElementType();
5000 Type *destinationElementType =
static_cast<PointerType *
>(destinationType)->getElementType();
5001 if (sourceElementType->isStructTy() && destinationElementType->isStructTy())
5002 return new BitCastInst(argument, unloweredType,
"", block);
5003 sourceType = sourceElementType;
5004 destinationType = destinationElementType;
5009 if (argument->getType() != unloweredType)
5011 VUserLog(
"Couldn't convert argument %d of %s to the type of %s", parameterIndex, function->getName().str().c_str(), unloweredVuoType->
getBase()->
getModuleKey().c_str());
5012 function->arg_begin()->getType()->dump(); fprintf(stderr,
"\n");
5013 argument->getType()->dump(); fprintf(stderr,
"\n");
5014 unloweredType->dump(); fprintf(stderr,
"\n");
5033 Value **secondArgument, Module *module, BasicBlock *block)
5036 secondArgument, module, block);
5052 Value **secondArgument, Module *module, BasicBlock *block)
5055 *secondArgument = NULL;
5057 Type *parameterType = functionType->getParamType(parameterIndex);
5059 if (argument->getType()->isVectorTy())
5061 if (
static_cast<VectorType *
>(argument->getType())->getElementType()->isFloatTy())
5063 uint64_t elementCount =
static_cast<VectorType *
>(argument->getType())->getNumElements();
5064 if (elementCount == 2 && parameterType->isDoubleTy())
5067 PointerType *pointerToDoubleType = PointerType::get(parameterType, 0);
5070 CastInst *vectorVariableAsDouble =
new BitCastInst(vectorVariable, pointerToDoubleType,
"", block);
5071 return new LoadInst(vectorVariableAsDouble,
"",
false, block);
5073 else if (elementCount == 3 && parameterType->isVectorTy() &&
5074 static_cast<VectorType *
>(parameterType)->getNumElements() == 2 &&
5075 static_cast<VectorType *
>(parameterType)->getElementType()->isDoubleTy())
5078 PointerType *pointerToDoubleVectorType = PointerType::get(parameterType, 0);
5081 CastInst *floatVectorVariableAsDoubleVector =
new BitCastInst(floatVectorVariable, pointerToDoubleVectorType,
"", block);
5082 return new LoadInst(floatVectorVariableAsDoubleVector,
"",
false, block);
5084 else if (elementCount == 2 && parameterType->isPointerTy() &&
static_cast<PointerType *
>(parameterType)->getElementType() == argument->getType())
5092 else if (argument->getType()->isStructTy())
5094 if (! secondArgument)
5096 if (parameterType->isVectorTy())
5099 PointerType *pointerToVectorType = PointerType::get(parameterType, 0);
5102 CastInst *structVariableAsVector =
new BitCastInst(structVariable, pointerToVectorType,
"", block);
5103 return new LoadInst(structVariableAsVector,
"",
false, block);
5109 Type *secondParameterType = functionType->getParamType(parameterIndex + 1);
5110 vector<Type *> bothParameterMembers;
5111 bothParameterMembers.push_back(parameterType);
5112 bothParameterMembers.push_back(secondParameterType);
5113 StructType *bothParameterTypes = StructType::create(bothParameterMembers);
5114 PointerType *pointerToBothParameterTypes = PointerType::get(bothParameterTypes, 0);
5117 CastInst *structVariableAsBothParameterTypes =
new BitCastInst(structVariable, pointerToBothParameterTypes,
"", block);
5119 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
5120 ConstantInt *oneValue = ConstantInt::get(module->getContext(), APInt(32, 1));
5122 vector<Value *> firstMemberIndices;
5123 firstMemberIndices.push_back(zeroValue);
5124 firstMemberIndices.push_back(zeroValue);
5125 Value *firstMemberPointer = GetElementPtrInst::Create(structVariableAsBothParameterTypes, firstMemberIndices,
"", block);
5126 Value *firstMember =
new LoadInst(firstMemberPointer,
"",
false, block);
5128 vector<Value *> secondMemberIndices;
5129 secondMemberIndices.push_back(zeroValue);
5130 secondMemberIndices.push_back(oneValue);
5131 Value *secondMemberPointer = GetElementPtrInst::Create(structVariableAsBothParameterTypes, secondMemberIndices,
"", block);
5132 Value *secondMember =
new LoadInst(secondMemberPointer,
"",
false, block);
5134 *secondArgument = secondMember;
5138 if (isPassedByValue)
5145 if (argument->getType() != parameterType)
5148 if (argument->getType()->isStructTy() && parameterType->isStructTy())
5151 Type *pointerToParameterType = PointerType::get(parameterType, 0);
5152 Value *argumentVariableAsParameterType =
new BitCastInst(argumentVariable, pointerToParameterType,
"", block);
5153 return new LoadInst(argumentVariableAsParameterType,
"",
false, block);
5157 Type *sourceType = argument->getType();
5158 Type *destinationType = parameterType;
5159 while (sourceType->isPointerTy() && destinationType->isPointerTy())
5161 Type *sourceElementType =
static_cast<PointerType *
>(sourceType)->getElementType();
5162 Type *destinationElementType =
static_cast<PointerType *
>(destinationType)->getElementType();
5163 if (! sourceElementType->isPointerTy() && ! destinationElementType->isPointerTy())
5164 return new BitCastInst(argument, parameterType,
"", block);
5165 sourceType = sourceElementType;
5166 destinationType = destinationElementType;
5171 if (argument->getType() != parameterType)
5174 raw_string_ostream oss(s);
5175 oss <<
"functionType : "; functionType->print(oss); oss <<
'\n';
5176 oss <<
"argumentType : "; argument->getType()->print(oss); oss <<
'\n';
5177 oss <<
"parameterType: "; parameterType->print(oss);
5178 VUserLog(
"Warning: Couldn't convert an argument to the type of parameter %d:\n%s", parameterIndex, oss.str().c_str());
5190 bool VuoCompilerCodeGenUtilities::isParameterPassedByValue(Function *
function,
int parameterIndex)
5192 AttributeSet functionAttrs =
function->getAttributes();
5193 AttributeSet paramAttrs = functionAttrs.getParamAttributes(parameterIndex + 1);
5194 return paramAttrs.hasAttrSomewhere(Attribute::ByVal);
5202 PointerType *pointerToReturnType =
static_cast<PointerType *
>(
function->getFunctionType()->getParamType(0));
5203 Type *returnType = pointerToReturnType->getElementType();
5204 Value *returnVariable =
new AllocaInst(returnType,
"", block);
5205 args.insert(args.begin(), returnVariable);
5206 CallInst::Create(
function, args,
"", block);
5207 return returnVariable;
5216 AttributeSet functionAttrs =
function->getAttributes();
5217 AttributeSet paramAttrs = functionAttrs.getParamAttributes(1);
5218 return paramAttrs.hasAttrSomewhere(Attribute::StructRet);
5227 vector<Type *> params;
5231 Type *secondParamType = NULL;
5233 params.push_back(firstParamType);
5234 if (secondParamType)
5235 params.push_back(secondParamType);
5238 return FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
5246 Value *argValue = NULL;
5248 Function::arg_iterator args =
function->arg_begin();
5249 for (
size_t i = 0; i <= index && i <
function->arg_size(); ++i)
5262 if (attributesToCopy.getNumSlots() > 1)
5263 VUserLog(
"Warning: I was expecting an AttributeSet with 0 or 1 slots, but got %d.", attributesToCopy.getNumSlots());
5265 int inputIndex = AttributeSet::ReturnIndex + 1;
5267 string attributeString = attributesToCopy.getAsString(inputIndex);
5268 if (!attributeString.empty()
5269 && attributeString !=
"byval align 8"
5270 && attributeString !=
"byval align 16")
5271 VUserLog(
"Warning: I don't know how to handle all the attributes in '%s'.", attributeString.c_str());
5273 AttrBuilder builder;
5275 if (attributesToCopy.hasAttribute(inputIndex, Attribute::ByVal))
5276 builder.addAttribute(Attribute::ByVal);
5278 if (attributesToCopy.hasAttribute(inputIndex, Attribute::Alignment))
5279 builder.addAlignmentAttr(attributesToCopy.getParamAlignment(inputIndex));
5281 return AttributeSet::get(getGlobalContext(), destinationIndex, builder);