34 Function *dispatch_semaphore_create_function = module->getFunction(
"dispatch_semaphore_create");
35 if (! dispatch_semaphore_create_function)
37 vector<Type *> dispatch_semaphore_create_functionParams;
38 dispatch_semaphore_create_functionParams.push_back(IntegerType::get(module->getContext(), 64));
39 FunctionType *dispatch_semaphore_create_functionType = FunctionType::get(dispatch_semaphore_t_type,
40 dispatch_semaphore_create_functionParams,
42 dispatch_semaphore_create_function = Function::Create(dispatch_semaphore_create_functionType,
43 GlobalValue::ExternalLinkage,
44 "dispatch_semaphore_create",
48 ConstantInt *initialValueConst = ConstantInt::get(module->getContext(), APInt(64, initialValue));
49 return CallInst::Create(dispatch_semaphore_create_function, initialValueConst,
"", block);
62 LoadInst *semaphoreValue =
new LoadInst(semaphoreVariable,
"",
false, block);
77 LoadInst *semaphoreValue =
new LoadInst(semaphoreVariable,
"",
false, block);
86 IntegerType *dispatch_time_t_type = IntegerType::get(module->getContext(), 64);
87 Value *timeoutValue = ConstantInt::get(dispatch_time_t_type, DISPATCH_TIME_FOREVER);
97 IntegerType *dispatch_time_t_type = IntegerType::get(module->getContext(), 64);
99 vector<Type *> dispatch_semaphore_wait_functionParams;
100 dispatch_semaphore_wait_functionParams.push_back(dispatch_semaphore_t_type);
101 dispatch_semaphore_wait_functionParams.push_back(dispatch_time_t_type);
102 FunctionType *dispatch_semaphore_wait_functionType = FunctionType::get(IntegerType::get(module->getContext(), 64),
103 dispatch_semaphore_wait_functionParams,
106 Function *dispatch_semaphore_wait_function = module->getFunction(
"dispatch_semaphore_wait");
107 if (! dispatch_semaphore_wait_function) {
108 dispatch_semaphore_wait_function = Function::Create(dispatch_semaphore_wait_functionType,
109 GlobalValue::ExternalLinkage,
110 "dispatch_semaphore_wait",
114 vector<Value *> args;
115 args.push_back(semaphoreValue);
116 args.push_back(timeoutValue);
117 return CallInst::Create(dispatch_semaphore_wait_function, args,
"", block);
125 LoadInst *semaphoreValue =
new LoadInst(semaphoreVariable,
"",
false, block);
136 vector<Type *> dispatch_semaphore_signal_functionParams;
137 dispatch_semaphore_signal_functionParams.push_back(dispatch_semaphore_t_type);
138 FunctionType *dispatch_semaphore_signal_functionType = FunctionType::get(IntegerType::get(module->getContext(), 64),
139 dispatch_semaphore_signal_functionParams,
142 Function *dispatch_semaphore_signal_function = module->getFunction(
"dispatch_semaphore_signal");
143 if (! dispatch_semaphore_signal_function) {
144 dispatch_semaphore_signal_function = Function::Create(dispatch_semaphore_signal_functionType,
145 GlobalValue::ExternalLinkage,
146 "dispatch_semaphore_signal",
150 CallInst::Create(dispatch_semaphore_signal_function, semaphoreValue,
"", block);
162 Function *dispatch_group_create_function = module->getFunction(
"dispatch_group_create");
163 if (! dispatch_group_create_function)
165 vector<Type *> dispatch_group_create_functionParams;
166 FunctionType *dispatch_group_create_functionType = FunctionType::get(
getDispatchGroupType(module),
167 dispatch_group_create_functionParams,
169 dispatch_group_create_function = Function::Create(dispatch_group_create_functionType,
170 GlobalValue::ExternalLinkage,
171 "dispatch_group_create", module);
174 return CallInst::Create(dispatch_group_create_function,
"", block);
182 Function *dispatch_group_enter_function = module->getFunction(
"dispatch_group_enter");
183 if (! dispatch_group_enter_function)
186 FunctionType *dispatch_group_enter_functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
187 dispatch_group_t_type,
189 dispatch_group_enter_function = Function::Create(dispatch_group_enter_functionType,
190 GlobalValue::ExternalLinkage,
191 "dispatch_group_enter",
195 CallInst::Create(dispatch_group_enter_function, dispatchGroupValue,
"", block);
203 Function *dispatch_group_leave_function = module->getFunction(
"dispatch_group_leave");
204 if (! dispatch_group_leave_function)
207 FunctionType *dispatch_group_leave_functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
208 dispatch_group_t_type,
210 dispatch_group_leave_function = Function::Create(dispatch_group_leave_functionType,
211 GlobalValue::ExternalLinkage,
212 "dispatch_group_leave",
216 CallInst::Create(dispatch_group_leave_function, dispatchGroupValue,
"", block);
223 dispatch_time_t timeout)
225 Function *dispatch_group_wait_function = module->getFunction(
"dispatch_group_wait");
226 if (! dispatch_group_wait_function)
230 vector<Type *> dispatch_group_wait_functionParams;
231 dispatch_group_wait_functionParams.push_back(dispatch_group_t_type);
232 dispatch_group_wait_functionParams.push_back(IntegerType::get(module->getContext(), 64));
233 FunctionType *dispatch_group_wait_functionType = FunctionType::get(IntegerType::get(module->getContext(), 64),
234 dispatch_group_wait_functionParams,
237 dispatch_group_wait_function = Function::Create(dispatch_group_wait_functionType,
238 GlobalValue::ExternalLinkage,
239 "dispatch_group_wait",
243 ConstantInt *timeout_value = ConstantInt::get(module->getContext(), APInt(64, timeout,
true));
245 vector<Value *> args;
246 args.push_back(dispatchGroupValue);
247 args.push_back(timeout_value);
248 CallInst::Create(dispatch_group_wait_function, args,
"", block);
256 PointerType *dispatch_queue_t_type = getDispatchQueueType(module);
258 vector<Type *> dispatch_get_global_queue_functionParams;
259 dispatch_get_global_queue_functionParams.push_back(IntegerType::get(module->getContext(), 64));
260 dispatch_get_global_queue_functionParams.push_back(IntegerType::get(module->getContext(), 64));
261 FunctionType *dispatch_get_global_queue_functionType = FunctionType::get(dispatch_queue_t_type,
262 dispatch_get_global_queue_functionParams,
265 Function *dispatch_get_global_queue_function = module->getFunction(
"dispatch_get_global_queue");
266 if (! dispatch_get_global_queue_function) {
267 dispatch_get_global_queue_function = Function::Create(dispatch_get_global_queue_functionType,
268 GlobalValue::ExternalLinkage,
269 "dispatch_get_global_queue",
273 Constant *zeroValue = ConstantInt::get(dispatch_get_global_queue_functionType->getParamType(0), 0);
275 vector<Value *> args;
276 args.push_back(zeroValue);
277 args.push_back(zeroValue);
278 return CallInst::Create(dispatch_get_global_queue_function, args,
"", block);
291 PointerType *dispatch_queue_t_type = getDispatchQueueType(module);
292 PointerType *pointerToi8 = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
294 StructType *dispatch_queue_attr_s_type = module->getTypeByName(
"struct.dispatch_queue_attr_s");
295 if (! dispatch_queue_attr_s_type)
296 dispatch_queue_attr_s_type = StructType::create(module->getContext(),
"struct.dispatch_queue_attr_s");
297 PointerType *dispatch_queue_attr_t_type = PointerType::get(dispatch_queue_attr_s_type, 0);
299 vector<Type *> dispatch_queue_create_functionParams;
300 dispatch_queue_create_functionParams.push_back(pointerToi8);
301 dispatch_queue_create_functionParams.push_back(dispatch_queue_attr_t_type);
302 FunctionType *dispatch_queue_create_functionType = FunctionType::get(dispatch_queue_t_type,
303 dispatch_queue_create_functionParams,
306 Function *dispatch_queue_create_function = module->getFunction(
"dispatch_queue_create");
307 if (! dispatch_queue_create_function)
309 dispatch_queue_create_function = Function::Create(dispatch_queue_create_functionType,
310 GlobalValue::ExternalLinkage,
311 "dispatch_queue_create",
315 ArrayType *dispatchQueueNameType = ArrayType::get(IntegerType::get(module->getContext(), 8), dispatchQueueName.length() + 1);
316 GlobalVariable *dispatchQueueNameVariable =
new GlobalVariable(*module,
317 dispatchQueueNameType,
319 GlobalValue::InternalLinkage,
322 Constant *dispatchQueueNameValue = ConstantDataArray::getString(module->getContext(), dispatchQueueName,
true);
323 dispatchQueueNameVariable->setInitializer(dispatchQueueNameValue);
325 ConstantInt *zeroi64Value = ConstantInt::get(module->getContext(), APInt(64, 0));
326 ConstantPointerNull *nullValue = ConstantPointerNull::get(dispatch_queue_attr_t_type);
328 std::vector<Constant*> dispatchQueueLabel_indices;
329 dispatchQueueLabel_indices.push_back(zeroi64Value);
330 dispatchQueueLabel_indices.push_back(zeroi64Value);
331 Constant *dispatchQueueLabel = ConstantExpr::getGetElementPtr(dispatchQueueNameType, dispatchQueueNameVariable, dispatchQueueLabel_indices);
333 vector<Value *> args;
334 args.push_back(dispatchQueueLabel);
335 args.push_back(nullValue);
336 return CallInst::Create(dispatch_queue_create_function, args,
"", block);
343 Function *workerFunction, Value *contextValue)
345 generateSubmissionToDispatchQueue(module, block, dispatchQueueValue, workerFunction, contextValue,
false);
352 Function *workerFunction, Value *contextValue)
354 generateSubmissionToDispatchQueue(module, block, dispatchQueueValue, workerFunction, contextValue,
true);
360 void VuoCompilerCodeGenUtilities::generateSubmissionToDispatchQueue(Module *module, BasicBlock *block, Value *dispatchQueueValue,
361 Function *workerFunction, Value *contextValue,
bool isSynchronous)
363 PointerType *dispatch_queue_t_type = getDispatchQueueType(module);
364 PointerType *pointerToi8 = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
366 vector<Type *> dispatchSubmitFunctionParams;
367 dispatchSubmitFunctionParams.push_back(dispatch_queue_t_type);
368 dispatchSubmitFunctionParams.push_back(pointerToi8);
369 dispatchSubmitFunctionParams.push_back(workerFunction->getType());
370 FunctionType *dispatchSubmitFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()),
371 dispatchSubmitFunctionParams,
374 const char *dispatchSubmitFunctionName = (isSynchronous ?
"dispatch_sync_f" :
"dispatch_async_f");
375 Function *dispatchSubmitFunction = module->getFunction(dispatchSubmitFunctionName);
376 if (! dispatchSubmitFunction) {
377 dispatchSubmitFunction = Function::Create(dispatchSubmitFunctionType,
378 GlobalValue::ExternalLinkage,
379 dispatchSubmitFunctionName,
383 vector<Value *> args;
384 args.push_back(dispatchQueueValue);
385 args.push_back(contextValue);
386 args.push_back(workerFunction);
387 CallInst::Create(dispatchSubmitFunction, args,
"", block);
393 Value * VuoCompilerCodeGenUtilities::generateConversionToDispatchObject(Module *module, BasicBlock *block, Value *dispatchObjectVariable)
395 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
396 PointerType *dispatchObjectOriginalType = cast<PointerType>(dispatchObjectVariable->getType());
399 vector<Type *> llvm_memcpy_p0i8_p0i8_i64_functionParams;
400 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(pointerToi8Type);
401 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(pointerToi8Type);
402 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(IntegerType::get(module->getContext(), 64));
403 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(IntegerType::get(module->getContext(), 32));
404 llvm_memcpy_p0i8_p0i8_i64_functionParams.push_back(IntegerType::get(module->getContext(), 1));
405 FunctionType *llvm_memcpy_p0i8_p0i8_i64_functionType = FunctionType::get(Type::getVoidTy(module->getContext()), llvm_memcpy_p0i8_p0i8_i64_functionParams,
false);
406 Function *llvm_memcpy_p0i8_p0i8_i64_function = module->getFunction(
"llvm.memcpy.p0i8.p0i8.i64");
407 if (! llvm_memcpy_p0i8_p0i8_i64_function)
408 llvm_memcpy_p0i8_p0i8_i64_function = Function::Create(llvm_memcpy_p0i8_p0i8_i64_functionType, GlobalValue::ExternalLinkage,
"llvm.memcpy.p0i8.p0i8.i64", module);
410 ConstantInt *zeroValue32 = ConstantInt::get(module->getContext(), APInt(32, 0));
411 ConstantInt *zeroValue1 = ConstantInt::get(module->getContext(), APInt(1, 0));
412 ConstantInt *eightValue64 = ConstantInt::get(module->getContext(), APInt(64, 8));
413 ConstantInt *eightValue32 = ConstantInt::get(module->getContext(), APInt(32, 8));
415 AllocaInst *dispatchObjectUnion =
new AllocaInst(dispatch_object_t_type, 0,
"", block);
416 AllocaInst *compoundLiteral =
new AllocaInst(dispatch_object_t_type, 0,
"", block);
418 CastInst *compoundLiteralAsDispatchObjectOriginalType =
new BitCastInst(compoundLiteral, dispatchObjectOriginalType,
"", block);
419 LoadInst *dispatchObjectValue =
new LoadInst(dispatchObjectVariable,
"",
false, block);
420 new StoreInst(dispatchObjectValue, compoundLiteralAsDispatchObjectOriginalType,
false, block);
422 CastInst *dispatchObjectUnionAsPointerToi8 =
new BitCastInst(dispatchObjectUnion, pointerToi8Type,
"", block);
423 CastInst *compoundLiteralAsPointerToi8 =
new BitCastInst(compoundLiteral, pointerToi8Type,
"", block);
425 std::vector<Value *> llvm_memcpy_p0i8_p0i8_i64_functionArgs;
426 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(dispatchObjectUnionAsPointerToi8);
427 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(compoundLiteralAsPointerToi8);
428 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(eightValue64);
429 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(eightValue32);
430 llvm_memcpy_p0i8_p0i8_i64_functionArgs.push_back(zeroValue1);
431 CallInst::Create(llvm_memcpy_p0i8_p0i8_i64_function, llvm_memcpy_p0i8_p0i8_i64_functionArgs,
"", block);
433 vector<Value *> gepIndices;
434 gepIndices.push_back(zeroValue32);
435 gepIndices.push_back(zeroValue32);
436 Instruction *dispatchObjectUnionMember = GetElementPtrInst::Create(dispatch_object_t_type, dispatchObjectUnion, gepIndices,
"", block);
437 return new LoadInst(dispatchObjectUnionMember,
"",
false, block);
449 Value *dispatchObjectValueAsDispatchObject = generateConversionToDispatchObject(module, block, dispatchObjectVariable);
451 StructType *dispatch_object_s_type = getDispatchObjectElementType(module);
452 PointerType *pointerTo_dispatch_object_s_type = PointerType::get(dispatch_object_s_type, 0);
454 vector<Type*> dispatchRetainFunctionParams;
455 dispatchRetainFunctionParams.push_back(pointerTo_dispatch_object_s_type);
456 FunctionType *dispatchRetainFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()), dispatchRetainFunctionParams,
false);
457 Function *dispatchRetainFunction = module->getFunction(
"dispatch_retain");
458 if (! dispatchRetainFunction)
459 dispatchRetainFunction = Function::Create(dispatchRetainFunctionType, GlobalValue::ExternalLinkage,
"dispatch_retain", module);
461 CallInst::Create(dispatchRetainFunction, dispatchObjectValueAsDispatchObject,
"", block);
473 Value *dispatchObjectValueAsDispatchObject = generateConversionToDispatchObject(module, block, dispatchObjectVariable);
475 StructType *dispatch_object_s_type = getDispatchObjectElementType(module);
476 PointerType *pointerTo_dispatch_object_s_type = PointerType::get(dispatch_object_s_type, 0);
478 vector<Type*> dispatchReleaseFunctionParams;
479 dispatchReleaseFunctionParams.push_back(pointerTo_dispatch_object_s_type);
480 FunctionType *dispatchReleaseFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()), dispatchReleaseFunctionParams,
false);
481 Function *dispatchReleaseFunction = module->getFunction(
"dispatch_release");
482 if (! dispatchReleaseFunction)
483 dispatchReleaseFunction = Function::Create(dispatchReleaseFunctionType, GlobalValue::ExternalLinkage,
"dispatch_release", module);
485 CallInst::Create(dispatchReleaseFunction, dispatchObjectValueAsDispatchObject,
"", block);
498 Type *dispatch_time_t_type = IntegerType::get(module->getContext(), 64);
500 vector<Type *> dispatch_time_functionParams;
501 dispatch_time_functionParams.push_back(dispatch_time_t_type);
502 dispatch_time_functionParams.push_back(IntegerType::get(module->getContext(), 64));
503 FunctionType *dispatch_time_functionType = FunctionType::get(dispatch_time_t_type,
504 dispatch_time_functionParams,
507 Function *dispatch_time_function = module->getFunction(
"dispatch_time");
508 if (! dispatch_time_function) {
509 dispatch_time_function = Function::Create(dispatch_time_functionType,
510 GlobalValue::ExternalLinkage,
515 ConstantInt *whenValue = ConstantInt::get(module->getContext(), APInt(64, DISPATCH_TIME_NOW));
517 vector<Value *> args;
518 args.push_back(whenValue);
519 args.push_back(deltaValue);
520 return CallInst::Create(dispatch_time_function, args,
"", block);
534 bool isTrigger,
string triggerQueueName)
536 IntegerType *boolType = IntegerType::get(module->getContext(), 64);
537 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
538 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
540 const char *functionName =
"vuoCreatePortContext";
541 Function *
function = module->getFunction(functionName);
546 vector<Type *> params;
547 params.push_back(voidPointerType);
548 params.push_back(boolType);
549 params.push_back(pointerToCharType);
551 FunctionType *functionType = FunctionType::get(pointerToPortContext, params,
false);
552 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
555 Value *pointerToDataAsVoidPointer;
559 pointerToDataAsVoidPointer =
new BitCastInst(pointerToData, voidPointerType,
"", block);
562 pointerToDataAsVoidPointer = ConstantPointerNull::get(voidPointerType);
564 vector<Value *> args;
565 args.push_back(pointerToDataAsVoidPointer);
566 args.push_back(ConstantInt::get(boolType, isTrigger));
568 return CallInst::Create(
function, args,
"", block);
581 const char *functionName =
"vuoSetPortContextEvent";
582 Function *
function = module->getFunction(functionName);
586 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
587 Type *boolType = portContextType->getElementType(0);
589 vector<Type *> params;
590 params.push_back(pointerToPortContext);
591 params.push_back(boolType);
592 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
593 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
596 vector<Value *> args;
597 args.push_back(portContextValue);
598 args.push_back(eventValue);
599 CallInst::Create(
function, args,
"", block);
614 new StoreInst(dataValue, pointerToData,
false, block);
627 const char *functionName =
"vuoSetPortContextTriggerFunction";
628 Function *
function = module->getFunction(functionName);
632 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
633 Type *triggerFunctionType = portContextType->getElementType(5);
635 vector<Type *> params;
636 params.push_back(pointerToPortContext);
637 params.push_back(triggerFunctionType);
638 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
639 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
642 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
643 Value *triggerFunctionAsVoidPointer =
new BitCastInst(triggerFunctionValue, voidPointerType,
"", block);
645 vector<Value *> args;
646 args.push_back(portContextValue);
647 args.push_back(triggerFunctionAsVoidPointer);
648 CallInst::Create(
function, args,
"", block);
661 const char *functionName =
"vuoGetPortContextEvent";
662 Function *
function = module->getFunction(functionName);
666 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
667 Type *boolType = portContextType->getElementType(0);
669 FunctionType *functionType = FunctionType::get(boolType, pointerToPortContext,
false);
670 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
673 return CallInst::Create(
function, portContextValue,
"", block);
701 const char *functionName =
"vuoGetPortContextData";
702 Function *
function = module->getFunction(functionName);
706 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
707 Type *voidPointerType = portContextType->getElementType(1);
709 FunctionType *functionType = FunctionType::get(voidPointerType, pointerToPortContext,
false);
710 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
713 return CallInst::Create(
function, portContextValue,
"", block);
726 const char *functionName =
"vuoGetPortContextTriggerQueue";
727 Function *
function = module->getFunction(functionName);
731 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
732 Type *dispatchQueueType = portContextType->getElementType(3);
734 FunctionType *functionType = FunctionType::get(dispatchQueueType, pointerToPortContext,
false);
735 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
738 return CallInst::Create(
function, portContextValue,
"", block);
751 const char *functionName =
"vuoGetPortContextTriggerSemaphore";
752 Function *
function = module->getFunction(functionName);
756 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
757 Type *dispatchSemaphoreType = portContextType->getElementType(4);
759 FunctionType *functionType = FunctionType::get(dispatchSemaphoreType, pointerToPortContext,
false);
760 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
763 return CallInst::Create(
function, portContextValue,
"", block);
777 const char *functionName =
"vuoGetPortContextTriggerFunction";
778 Function *
function = module->getFunction(functionName);
782 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
783 Type *triggerFunctionType = portContextType->getElementType(5);
785 FunctionType *functionType = FunctionType::get(triggerFunctionType, pointerToPortContext,
false);
786 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
789 Value *triggerFunctionAsVoidPointer = CallInst::Create(
function, portContextValue,
"", block);
790 PointerType *pointerToTriggerFunctionType = PointerType::get(functionType, 0);
791 return new BitCastInst(triggerFunctionAsVoidPointer, pointerToTriggerFunctionType,
"", block);
803 const char *functionName =
"vuoRetainPortContextData";
804 Function *
function = module->getFunction(functionName);
808 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
810 vector<Type *> params;
811 params.push_back(pointerToPortContext);
812 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
813 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
816 vector<Value *> args;
817 args.push_back(portContextValue);
818 CallInst::Create(
function, args,
"", block);
832 bool isComposition,
size_t outputEventCount)
834 IntegerType *boolType = IntegerType::get(module->getContext(), 64);
835 IntegerType *sizeType = IntegerType::get(module->getContext(), 64);
837 const char *functionName =
"vuoCreateNodeContext";
838 Function *
function = module->getFunction(functionName);
843 vector<Type *> params;
844 params.push_back(boolType);
845 params.push_back(boolType);
846 params.push_back(sizeType);
848 FunctionType *functionType = FunctionType::get(pointerToNodeContext, params,
false);
849 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
852 vector<Value *> args;
853 args.push_back(ConstantInt::get(boolType, hasInstanceData));
854 args.push_back(ConstantInt::get(boolType, isComposition));
855 args.push_back(ConstantInt::get(sizeType, outputEventCount));
856 return CallInst::Create(
function, args,
"", block);
870 PointerType *pointerToPointerToPortContext = PointerType::get(pointerToPortContext, 0);
871 IntegerType *sizeType = IntegerType::get(module->getContext(), 64);
873 Value *portContextsArrayValue =
generateMemoryAllocation(module, block, pointerToPortContext, portContextValues.size());
874 for (
size_t i = 0; i < portContextValues.size(); ++i)
877 const char *functionName =
"vuoSetNodeContextPortContexts";
878 Function *
function = module->getFunction(functionName);
882 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
884 vector<Type *> params;
885 params.push_back(pointerToNodeContext);
886 params.push_back(pointerToPointerToPortContext);
887 params.push_back(sizeType);
888 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
889 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
892 vector<Value *> args;
893 args.push_back(nodeContextValue);
894 args.push_back(portContextsArrayValue);
895 args.push_back(ConstantInt::get(sizeType, portContextValues.size()));
896 CallInst::Create(
function, args,
"", block);
910 Type *voidPointerType = nodeContextType->getElementType(2);
912 const char *functionName =
"vuoSetNodeContextInstanceData";
913 Function *
function = module->getFunction(functionName);
916 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
918 vector<Type *> params;
919 params.push_back(pointerToNodeContext);
920 params.push_back(voidPointerType);
921 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
922 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
926 new StoreInst(instanceDataValue, pointerToInstanceData,
false, block);
927 Value *pointerToInstanceDataAsVoidPointer =
new BitCastInst(pointerToInstanceData, voidPointerType,
"", block);
929 vector<Value *> args;
930 args.push_back(nodeContextValue);
931 args.push_back(pointerToInstanceDataAsVoidPointer);
932 CallInst::Create(
function, args,
"", block);
945 const char *functionName =
"vuoSetNodeContextClaimingEventId";
946 Function *
function = module->getFunction(functionName);
950 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
951 Type *eventIdType = nodeContextType->getElementType(4);
953 vector<Type *> params;
954 params.push_back(pointerToNodeContext);
955 params.push_back(eventIdType);
956 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
957 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
960 vector<Value *> args;
961 args.push_back(nodeContextValue);
962 args.push_back(claimingEventIdValue);
963 CallInst::Create(
function, args,
"", block);
977 Type *sizeType = IntegerType::get(module->getContext(), 64);
979 const char *functionName =
"vuoSetNodeContextOutputEvent";
980 Function *
function = module->getFunction(functionName);
984 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
985 Type *boolType = IntegerType::get(module->getContext(), 64);
987 vector<Type *> params;
988 params.push_back(pointerToNodeContext);
989 params.push_back(sizeType);
990 params.push_back(boolType);
991 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
992 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
995 eventValue =
new ZExtInst(eventValue, sizeType,
"", block);
997 vector<Value *> args;
998 args.push_back(nodeContextValue);
999 args.push_back(ConstantInt::get(sizeType, index));
1000 args.push_back(eventValue);
1001 CallInst::Create(
function, args,
"", block);
1015 Type *indexType = IntegerType::get(module->getContext(), 64);
1017 const char *functionName =
"vuoGetNodeContextPortContext";
1018 Function *
function = module->getFunction(functionName);
1022 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1024 PointerType *pointerToPortContext = PointerType::get(portContextType, 0);
1026 vector<Type *> params;
1027 params.push_back(pointerToNodeContext);
1028 params.push_back(indexType);
1030 FunctionType *functionType = FunctionType::get(pointerToPortContext, params,
false);
1031 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1034 vector<Value *> args;
1035 args.push_back(nodeContextValue);
1036 args.push_back(ConstantInt::get(indexType, index));
1037 return CallInst::Create(
function, args,
"", block);
1052 return new LoadInst(pointerToInstanceData,
"",
false, block);
1066 const char *functionName =
"vuoGetNodeContextInstanceData";
1067 Function *
function = module->getFunction(functionName);
1071 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1072 Type *voidPointerType = nodeContextType->getElementType(2);
1074 FunctionType *functionType = FunctionType::get(voidPointerType, pointerToNodeContext,
false);
1075 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1078 Value *pointerToInstanceDataAsVoidPointer = CallInst::Create(
function, nodeContextValue,
"", block);
1079 return new BitCastInst(pointerToInstanceDataAsVoidPointer, PointerType::get(instanceDataType, 0),
"", block);
1092 const char *functionName =
"vuoGetNodeContextClaimingEventId";
1093 Function *
function = module->getFunction(functionName);
1097 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1098 Type *eventIdType = nodeContextType->getElementType(4);
1100 FunctionType *functionType = FunctionType::get(eventIdType, pointerToNodeContext,
false);
1101 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1104 return CallInst::Create(
function, nodeContextValue,
"", block);
1117 const char *functionName =
"vuoGetNodeContextExecutingGroup";
1118 Function *
function = module->getFunction(functionName);
1122 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1123 Type *dispatchGroupType = nodeContextType->getElementType(5);
1125 FunctionType *functionType = FunctionType::get(dispatchGroupType, pointerToNodeContext,
false);
1126 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1129 return CallInst::Create(
function, nodeContextValue,
"", block);
1143 Type *sizeType = IntegerType::get(module->getContext(), 64);
1145 const char *functionName =
"vuoGetNodeContextOutputEvent";
1146 Function *
function = module->getFunction(functionName);
1150 PointerType *pointerToNodeContext = PointerType::get(nodeContextType, 0);
1151 Type *boolType = IntegerType::get(module->getContext(), 64);
1153 vector<Type *> params;
1154 params.push_back(pointerToNodeContext);
1155 params.push_back(sizeType);
1156 FunctionType *functionType = FunctionType::get(boolType, params,
false);
1157 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1160 vector<Value *> args;
1161 args.push_back(nodeContextValue);
1162 args.push_back(ConstantInt::get(sizeType, index));
1163 Value *eventValue = CallInst::Create(
function, args,
"", block);
1165 return new TruncInst(eventValue, IntegerType::get(module->getContext(), 1),
"", block);
1177 const char *functionName =
"vuoResetNodeContextEvents";
1178 Function *
function = module->getFunction(functionName);
1181 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1183 vector<Type *> params;
1184 params.push_back(pointerToNodeContextType);
1186 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1187 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1190 vector<Value *> args;
1191 args.push_back(nodeContextValue);
1192 CallInst::Create(
function, args,
"", block);
1205 const char *functionName =
"vuoStartedExecutingEvent";
1206 Function *
function = module->getFunction(functionName);
1209 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1212 vector<Type *> params;
1213 params.push_back(pointerToNodeContextType);
1214 params.push_back(eventIdType);
1216 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1217 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1220 vector<Value *> args;
1221 args.push_back(nodeContextValue);
1222 args.push_back(eventIdValue);
1223 CallInst::Create(
function, args,
"", block);
1236 const char *functionName =
"vuoSpunOffExecutingEvent";
1237 Function *
function = module->getFunction(functionName);
1240 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1243 vector<Type *> params;
1244 params.push_back(pointerToNodeContextType);
1245 params.push_back(eventIdType);
1247 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1248 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1251 vector<Value *> args;
1252 args.push_back(nodeContextValue);
1253 args.push_back(eventIdValue);
1254 CallInst::Create(
function, args,
"", block);
1268 const char *functionName =
"vuoFinishedExecutingEvent";
1269 Function *
function = module->getFunction(functionName);
1272 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1274 Type *boolType = IntegerType::get(module->getContext(), 64);
1276 vector<Type *> params;
1277 params.push_back(pointerToNodeContextType);
1278 params.push_back(eventIdType);
1280 FunctionType *functionType = FunctionType::get(boolType, params,
false);
1281 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1284 vector<Value *> args;
1285 args.push_back(nodeContextValue);
1286 args.push_back(eventIdValue);
1287 return CallInst::Create(
function, args,
"", block);
1300 const char *functionName =
"vuoGetOneExecutingEvent";
1301 Function *
function = module->getFunction(functionName);
1304 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
1307 vector<Type *> params;
1308 params.push_back(pointerToNodeContextType);
1310 FunctionType *functionType = FunctionType::get(eventIdType, params,
false);
1311 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1314 vector<Value *> args;
1315 args.push_back(nodeContextValue);
1316 return CallInst::Create(
function, args,
"", block);
1324 const char *functionName =
"vuoCreateCompositionState";
1325 Function *
function = module->getFunction(functionName);
1328 PointerType *pointerToChar = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1329 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1332 vector<Type *> params;
1333 params.push_back(voidPointer);
1334 params.push_back(pointerToChar);
1336 FunctionType *functionType = FunctionType::get(pointerToCompositionState, params,
false);
1337 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1340 vector<Value *> args;
1341 args.push_back(runtimeStateValue);
1342 args.push_back(compositionIdentifierValue);
1343 return CallInst::Create(
function, args,
"", block);
1351 const char *functionName =
"vuoGetCompositionStateRuntimeState";
1352 Function *
function = module->getFunction(functionName);
1356 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1358 vector<Type *> params;
1359 params.push_back(pointerToCompositionState);
1361 FunctionType *functionType = FunctionType::get(voidPointer, params,
false);
1362 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1365 vector<Value *> args;
1366 args.push_back(compositionStateValue);
1367 return CallInst::Create(
function, args,
"", block);
1375 const char *functionName =
"vuoGetCompositionStateCompositionIdentifier";
1376 Function *
function = module->getFunction(functionName);
1380 PointerType *pointerToChar = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1382 vector<Type *> params;
1383 params.push_back(pointerToCompositionState);
1385 FunctionType *functionType = FunctionType::get(pointerToChar, params,
false);
1386 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1389 vector<Value *> args;
1390 args.push_back(compositionStateValue);
1391 return CallInst::Create(
function, args,
"", block);
1399 const char *functionName =
"vuoFreeCompositionState";
1400 Function *
function = module->getFunction(functionName);
1405 vector<Type *> params;
1406 params.push_back(pointerToCompositionState);
1408 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1409 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1412 vector<Value *> args;
1413 args.push_back(compositionStateValue);
1414 CallInst::Create(
function, args,
"", block);
1421 Value *compositionStateValue, Value *portIdentifierValue)
1423 const char *functionName =
"vuoGetDataForPort";
1424 Function *
function = module->getFunction(functionName);
1427 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1428 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1430 vector<Type *> params;
1431 params.push_back(compositionStateValue->getType());
1432 params.push_back(pointerToCharType);
1434 FunctionType *functionType = FunctionType::get(voidPointerType, params,
false);
1435 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1438 vector<Value *> args;
1439 args.push_back(compositionStateValue);
1440 args.push_back(portIdentifierValue);
1441 return CallInst::Create(
function, args,
"", block);
1448 Value *compositionStateValue, Value *portIdentifierValue)
1450 const char *functionName =
"vuoGetNodeIndexForPort";
1451 Function *
function = module->getFunction(functionName);
1454 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1455 Type *unsignedLongType = IntegerType::get(module->getContext(), 64);
1457 vector<Type *> params;
1458 params.push_back(compositionStateValue->getType());
1459 params.push_back(pointerToCharType);
1461 FunctionType *functionType = FunctionType::get(unsignedLongType, params,
false);
1462 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1465 vector<Value *> args;
1466 args.push_back(compositionStateValue);
1467 args.push_back(portIdentifierValue);
1468 return CallInst::Create(
function, args,
"", block);
1475 Value *compositionStateValue, Value *portIdentifierValue)
1477 const char *functionName =
"vuoGetTypeIndexForPort";
1478 Function *
function = module->getFunction(functionName);
1481 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1482 Type *unsignedLongType = IntegerType::get(module->getContext(), 64);
1484 vector<Type *> params;
1485 params.push_back(compositionStateValue->getType());
1486 params.push_back(pointerToCharType);
1488 FunctionType *functionType = FunctionType::get(unsignedLongType, params,
false);
1489 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1492 vector<Value *> args;
1493 args.push_back(compositionStateValue);
1494 args.push_back(portIdentifierValue);
1495 return CallInst::Create(
function, args,
"", block);
1502 Value *queueValue, Value *contextValue, Value *workerFunctionValue,
1503 int minThreadsNeeded,
int maxThreadsNeeded,
1504 Value *eventIdValue, Value *compositionStateValue,
1507 Type *intType = IntegerType::get(module->getContext(), 64);
1509 const char *functionName =
"vuoScheduleTriggerWorker";
1510 Function *
function = module->getFunction(functionName);
1513 Type *dispatchQueueType = getDispatchQueueType(module);
1514 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1515 Type *workerFunctionType = workerFunctionValue->getType();
1518 vector<Type *> params;
1519 params.push_back(compositionStateValue->getType());
1520 params.push_back(dispatchQueueType);
1521 params.push_back(voidPointerType);
1522 params.push_back(workerFunctionType);
1523 params.push_back(intType);
1524 params.push_back(intType);
1525 params.push_back(eventIdType);
1526 params.push_back(intType);
1528 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1529 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1532 Value *minThreadsNeededValue = ConstantInt::get(intType, minThreadsNeeded);
1533 Value *maxThreadsNeededValue = ConstantInt::get(intType, maxThreadsNeeded);
1534 Value *chainCountValue = ConstantInt::get(intType, chainCount);
1536 vector<Value *> args;
1537 args.push_back(compositionStateValue);
1538 args.push_back(queueValue);
1539 args.push_back(contextValue);
1540 args.push_back(workerFunctionValue);
1541 args.push_back(minThreadsNeededValue);
1542 args.push_back(maxThreadsNeededValue);
1543 args.push_back(eventIdValue);
1544 args.push_back(chainCountValue);
1545 CallInst::Create(
function, args,
"", block);
1552 Value *queueValue, Value *contextValue, Value *workerFunctionValue,
1553 int minThreadsNeeded,
int maxThreadsNeeded,
1554 Value *eventIdValue, Value *compositionStateValue,
1555 size_t chainIndex, vector<size_t> upstreamChainIndices)
1557 Type *intType = IntegerType::get(module->getContext(), 64);
1560 const char *functionName =
"vuoScheduleChainWorker";
1561 Function *
function = module->getFunction(functionName);
1564 Type *dispatchQueueType = getDispatchQueueType(module);
1565 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1566 Type *workerFunctionType = workerFunctionValue->getType();
1567 PointerType *unsignedLongPointerType = PointerType::get(eventIdType, 0);
1569 vector<Type *> params;
1570 params.push_back(compositionStateValue->getType());
1571 params.push_back(dispatchQueueType);
1572 params.push_back(voidPointerType);
1573 params.push_back(workerFunctionType);
1574 params.push_back(intType);
1575 params.push_back(intType);
1576 params.push_back(eventIdType);
1577 params.push_back(eventIdType);
1578 params.push_back(unsignedLongPointerType);
1579 params.push_back(intType);
1581 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1582 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1585 Value *minThreadsNeededValue = ConstantInt::get(intType, minThreadsNeeded);
1586 Value *maxThreadsNeededValue = ConstantInt::get(intType, maxThreadsNeeded);
1587 Value *chainIndexValue = ConstantInt::get(eventIdType, chainIndex);
1589 Value *upstreamChainIndicesCountValue = ConstantInt::get(intType, (
int)upstreamChainIndices.size());
1590 Value *upstreamChainIndicesValue =
generateMemoryAllocation(module, block, eventIdType, upstreamChainIndices.size());
1591 for (
size_t i = 0; i < upstreamChainIndices.size(); ++i)
1593 Value *upstreamChainIndexValue = ConstantInt::get(eventIdType, upstreamChainIndices[i]);
1597 vector<Value *> args;
1598 args.push_back(compositionStateValue);
1599 args.push_back(queueValue);
1600 args.push_back(contextValue);
1601 args.push_back(workerFunctionValue);
1602 args.push_back(minThreadsNeededValue);
1603 args.push_back(maxThreadsNeededValue);
1604 args.push_back(eventIdValue);
1605 args.push_back(chainIndexValue);
1606 args.push_back(upstreamChainIndicesValue);
1607 args.push_back(upstreamChainIndicesCountValue);
1608 CallInst::Create(
function, args,
"", block);
1615 int minThreadsNeeded,
int maxThreadsNeeded,
1616 Value *eventIdValue, Value *compositionStateValue,
1619 Type *intType = IntegerType::get(module->getContext(), 64);
1622 const char *functionName =
"vuoGrantThreadsToChain";
1623 Function *
function = module->getFunction(functionName);
1626 vector<Type *> params;
1627 params.push_back(compositionStateValue->getType());
1628 params.push_back(intType);
1629 params.push_back(intType);
1630 params.push_back(eventIdType);
1631 params.push_back(eventIdType);
1633 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1634 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1637 Value *minThreadsNeededValue = ConstantInt::get(intType, minThreadsNeeded);
1638 Value *maxThreadsNeededValue = ConstantInt::get(intType, maxThreadsNeeded);
1639 Value *chainIndexValue = ConstantInt::get(eventIdType, chainIndex);
1641 vector<Value *> args;
1642 args.push_back(compositionStateValue);
1643 args.push_back(minThreadsNeededValue);
1644 args.push_back(maxThreadsNeededValue);
1645 args.push_back(eventIdValue);
1646 args.push_back(chainIndexValue);
1647 CallInst::Create(
function, args,
"", block);
1654 Value *eventIdValue, Value *compositionStateValue,
1655 Value *chainIndexValue, Value *subcompositionIdentifierValue)
1657 const char *functionName =
"vuoGrantThreadsToSubcomposition";
1658 Function *
function = module->getFunction(functionName);
1662 PointerType *charPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
1664 vector<Type *> params;
1665 params.push_back(compositionStateValue->getType());
1666 params.push_back(eventIdType);
1667 params.push_back(eventIdType);
1668 params.push_back(charPointerType);
1670 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1671 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1674 vector<Value *> args;
1675 args.push_back(compositionStateValue);
1676 args.push_back(eventIdValue);
1677 args.push_back(chainIndexValue);
1678 args.push_back(subcompositionIdentifierValue);
1679 CallInst::Create(
function, args,
"", block);
1686 Value *eventIdValue, Value *compositionStateValue)
1688 const char *functionName =
"vuoReturnThreadsForTriggerWorker";
1689 Function *
function = module->getFunction(functionName);
1694 vector<Type *> params;
1695 params.push_back(compositionStateValue->getType());
1696 params.push_back(eventIdType);
1698 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1699 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1702 vector<Value *> args;
1703 args.push_back(compositionStateValue);
1704 args.push_back(eventIdValue);
1705 CallInst::Create(
function, args,
"", block);
1712 Value *eventIdValue, Value *compositionStateValue,
1713 Value *chainIndexValue)
1715 const char *functionName =
"vuoReturnThreadsForChainWorker";
1716 Function *
function = module->getFunction(functionName);
1721 vector<Type *> params;
1722 params.push_back(compositionStateValue->getType());
1723 params.push_back(eventIdType);
1724 params.push_back(eventIdType);
1726 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1727 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1730 vector<Value *> args;
1731 args.push_back(compositionStateValue);
1732 args.push_back(eventIdValue);
1733 args.push_back(chainIndexValue);
1734 CallInst::Create(
function, args,
"", block);
1741 Value *compositionStateValue,
const vector<size_t> &nodeIndices, Value *eventIdValue,
1744 string functionName =
"vuoLockNodes";
1745 Function *
function = module->getFunction(functionName.c_str());
1749 PointerType *pointerToCompositionState = PointerType::get(compositionStateType, 0);
1750 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
1751 PointerType *pointerToUnsignedLong = PointerType::get(unsignedLongType, 0);
1753 vector<Type *> params;
1754 params.push_back(pointerToCompositionState);
1755 params.push_back(pointerToUnsignedLong);
1756 params.push_back(unsignedLongType);
1757 params.push_back(unsignedLongType);
1758 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1759 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1762 Constant *nodeCountValue = ConstantInt::get(module->getContext(), APInt(64, nodeIndices.size()));
1763 Constant *nodeIndicesValue = constantsCache->
get(nodeIndices);
1765 vector<Value *> args;
1766 args.push_back(compositionStateValue);
1767 args.push_back(nodeIndicesValue);
1768 args.push_back(nodeCountValue);
1769 args.push_back(eventIdValue);
1770 CallInst::Create(
function, args,
"", block);
1777 Value *compositionStateValue,
size_t nodeIndex, Value *eventIdValue)
1779 Constant *nodeIndexValue = ConstantInt::get(module->getContext(), APInt(64, nodeIndex));
1780 generateLockNode(module, block, compositionStateValue, nodeIndexValue, eventIdValue);
1787 Value *compositionStateValue, Value *nodeIndexValue, Value *eventIdValue)
1789 string functionName =
"vuoLockNode";
1790 Function *
function = module->getFunction(functionName.c_str());
1794 PointerType *pointerToCompositionState = PointerType::get(compositionStateType, 0);
1795 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
1797 vector<Type *> params;
1798 params.push_back(pointerToCompositionState);
1799 params.push_back(unsignedLongType);
1800 params.push_back(unsignedLongType);
1801 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1802 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1805 vector<Value *> args;
1806 args.push_back(compositionStateValue);
1807 args.push_back(nodeIndexValue);
1808 args.push_back(eventIdValue);
1809 CallInst::Create(
function, args,
"", block);
1816 Value *compositionStateValue,
const vector<size_t> &nodeIndices,
1819 string functionName =
"vuoUnlockNodes";
1820 Function *
function = module->getFunction(functionName.c_str());
1824 PointerType *pointerToCompositionState = PointerType::get(compositionStateType, 0);
1825 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
1826 PointerType *pointerToUnsignedLong = PointerType::get(unsignedLongType, 0);
1828 vector<Type *> params;
1829 params.push_back(pointerToCompositionState);
1830 params.push_back(pointerToUnsignedLong);
1831 params.push_back(unsignedLongType);
1832 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1833 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1836 Constant *nodeCountValue = ConstantInt::get(module->getContext(), APInt(64, nodeIndices.size()));
1837 Constant *nodeIndicesValue = constantsCache->
get(nodeIndices);
1839 vector<Value *> args;
1840 args.push_back(compositionStateValue);
1841 args.push_back(nodeIndicesValue);
1842 args.push_back(nodeCountValue);
1843 CallInst::Create(
function, args,
"", block);
1850 Value *compositionStateValue,
size_t nodeIndex)
1852 Constant *nodeIndexValue = ConstantInt::get(module->getContext(), APInt(64, nodeIndex));
1860 Value *compositionStateValue, Value *nodeIndexValue)
1862 string functionName =
"vuoUnlockNode";
1863 Function *
function = module->getFunction(functionName.c_str());
1867 PointerType *pointerToCompositionState = PointerType::get(compositionStateType, 0);
1868 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
1870 vector<Type *> params;
1871 params.push_back(pointerToCompositionState);
1872 params.push_back(unsignedLongType);
1873 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
1874 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
1877 vector<Value *> args;
1878 args.push_back(compositionStateValue);
1879 args.push_back(nodeIndexValue);
1880 CallInst::Create(
function, args,
"", block);
1888 Value *memberPointer = generateGetArrayElementVariable(module, block, arrayValue, elementIndex);
1889 new StoreInst(value, memberPointer,
false, block);
1897 Value *memberPointer = generateGetArrayElementVariable(module, block, arrayValue, elementIndex);
1898 return new LoadInst(memberPointer,
"", block);
1906 Value *memberPointer = generateGetArrayElementVariable(module, block, arrayValue, elementIndexValue);
1907 return new LoadInst(memberPointer,
"", block);
1913 Value * VuoCompilerCodeGenUtilities::generateGetArrayElementVariable(Module *module, BasicBlock *block, Value *arrayValue,
size_t elementIndex)
1915 ConstantInt *indexValue = ConstantInt::get(module->getContext(), APInt(32, elementIndex));
1916 return generateGetArrayElementVariable(module, block, arrayValue, indexValue);
1922 Value * VuoCompilerCodeGenUtilities::generateGetArrayElementVariable(Module *module, BasicBlock *block, Value *arrayValue, Value *elementIndexValue)
1924 return GetElementPtrInst::Create(
nullptr, arrayValue, elementIndexValue,
"", block);
1932 Value *memberPointer = generateGetStructPointerElementVariable(module, block, structPointer, elementIndex);
1933 new StoreInst(value, memberPointer,
false, block);
1941 Value *memberPointer = generateGetStructPointerElementVariable(module, block, structPointer, elementIndex);
1942 return new LoadInst(memberPointer,
"", block);
1948 Value * VuoCompilerCodeGenUtilities::generateGetStructPointerElementVariable(Module *module, BasicBlock *block, Value *structPointer,
size_t elementIndex)
1950 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
1951 ConstantInt *indexValue = ConstantInt::get(module->getContext(), APInt(32, elementIndex));
1953 vector<Value *> memberIndices;
1954 memberIndices.push_back(zeroValue);
1955 memberIndices.push_back(indexValue);
1956 return GetElementPtrInst::Create(
nullptr, structPointer, memberIndices,
"", block);
1964 AllocaInst *variable =
new AllocaInst(value->getType(), 0,
"", block);
1965 new StoreInst(value, variable,
false, block);
1979 Constant *array = ConstantDataArray::getString(module->getContext(), stringValue);
1980 ArrayType *arrayType = ArrayType::get(IntegerType::get(module->getContext(), 8), stringValue.length() + 1);
1981 GlobalVariable *global =
new GlobalVariable(*module, arrayType,
true, GlobalValue::InternalLinkage, 0,
"");
1982 global->setInitializer(array);
1983 global->setName(globalVariableName);
1985 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
1986 vector<Constant *> pointerIndices;
1987 pointerIndices.push_back(zeroValue);
1988 pointerIndices.push_back(zeroValue);
1989 Constant *pointer = ConstantExpr::getGetElementPtr(arrayType, global, pointerIndices);
2004 vector<Constant *> arrayElements;
2005 for (vector<string>::iterator i = stringValues.begin(); i != stringValues.end(); ++i)
2008 arrayElements.push_back(stringPointer);
2011 ArrayType *arrayType = ArrayType::get(PointerType::get(IntegerType::get(module->getContext(), 8), 0), arrayElements.size());
2012 GlobalVariable *global =
new GlobalVariable(*module, arrayType,
false, GlobalValue::ExternalLinkage, 0, globalVariableName);
2013 Constant *arrayConstant = ConstantArray::get(arrayType, arrayElements);
2014 global->setInitializer(arrayConstant);
2016 ConstantInt *zeroi64Constant = ConstantInt::get(module->getContext(), APInt(64, 0));
2017 vector<Constant *> pointerIndices;
2018 pointerIndices.push_back(zeroi64Constant);
2019 pointerIndices.push_back(zeroi64Constant);
2020 Constant *pointer = ConstantExpr::getGetElementPtr(arrayType, global, pointerIndices);
2035 vector<Constant *> arrayElements;
2036 for (
unsigned long value : values)
2038 Constant *valueConstant = ConstantInt::get(module->getContext(), APInt(64, value));
2039 arrayElements.push_back(valueConstant);
2042 ArrayType *arrayType = ArrayType::get(IntegerType::get(module->getContext(), 64), arrayElements.size());
2043 GlobalVariable *global =
new GlobalVariable(*module, arrayType,
false, GlobalValue::ExternalLinkage, 0, globalVariableName);
2044 Constant *arrayConstant = ConstantArray::get(arrayType, arrayElements);
2045 global->setInitializer(arrayConstant);
2047 ConstantInt *zeroi64Constant = ConstantInt::get(module->getContext(), APInt(64, 0));
2048 vector<Constant *> pointerIndices;
2049 pointerIndices.push_back(zeroi64Constant);
2050 pointerIndices.push_back(zeroi64Constant);
2051 Constant *pointer = ConstantExpr::getGetElementPtr(arrayType, global, pointerIndices);
2081 BasicBlock *initialBlock, BasicBlock *finalBlock, Value *inputStringValue,
2082 map<
string, pair<BasicBlock *, BasicBlock *> > blocksForString,
2086 BasicBlock *currentBlock = initialBlock;
2088 for (map<
string, pair<BasicBlock *, BasicBlock *> >::iterator i = blocksForString.begin(); i != blocksForString.end(); ++i)
2090 string currentString = i->first;
2091 BasicBlock *firstTrueBlock = i->second.first;
2092 BasicBlock *lastTrueBlock = i->second.second;
2094 Constant *currentStringValue = constantsCache->
get(currentString);
2096 vector<Value *> strcmpArgs;
2097 strcmpArgs.push_back(inputStringValue);
2098 strcmpArgs.push_back(currentStringValue);
2099 CallInst *strcmpCall = CallInst::Create(strcmpFunction, strcmpArgs,
"", currentBlock);
2101 ConstantInt *zeroValue = ConstantInt::get(module->getContext(), APInt(32, 0));
2102 ICmpInst *strcmpEqualsZero =
new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, strcmpCall, zeroValue,
"");
2103 BasicBlock *falseBlock = BasicBlock::Create(module->getContext(),
string(
"strcmp-") + currentString,
function, 0);
2104 BranchInst::Create(firstTrueBlock, falseBlock, strcmpEqualsZero, currentBlock);
2106 BranchInst::Create(finalBlock, lastTrueBlock);
2108 currentBlock = falseBlock;
2111 BranchInst::Create(finalBlock, currentBlock);
2138 BasicBlock *initialBlock, BasicBlock *finalBlock, Value *inputIndexValue,
2139 vector< pair<BasicBlock *, BasicBlock *> > blocksForIndex)
2141 BasicBlock *currentBlock = initialBlock;
2143 for (
size_t i = 0; i < blocksForIndex.size(); ++i)
2145 BasicBlock *firstTrueBlock = blocksForIndex[i].first;
2146 BasicBlock *lastTrueBlock = blocksForIndex[i].second;
2148 Constant *currentIndexValue = ConstantInt::get(inputIndexValue->getType(), i);
2149 ICmpInst *indexEqualsCurrent =
new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, inputIndexValue, currentIndexValue,
"");
2150 BasicBlock *falseBlock = BasicBlock::Create(module->getContext(),
"",
function, 0);
2151 BranchInst::Create(firstTrueBlock, falseBlock, indexEqualsCurrent, currentBlock);
2153 BranchInst::Create(finalBlock, lastTrueBlock);
2155 currentBlock = falseBlock;
2158 BranchInst::Create(finalBlock, currentBlock);
2177 Type *charType = IntegerType::get(module->getContext(), 8);
2178 PointerType *pointerToCharType = PointerType::get(charType, 0);
2179 ConstantPointerNull *nullValue = ConstantPointerNull::get(pointerToCharType);
2180 ConstantInt *zeroValue64 = ConstantInt::get(module->getContext(), APInt(64, 0));
2181 ConstantInt *oneValue64 = ConstantInt::get(module->getContext(), APInt(64, 1));
2184 Constant *formatStringValue = constantsCache->
get(formatString);
2185 vector<Value *> snprintfArgs;
2186 snprintfArgs.push_back(nullValue);
2187 snprintfArgs.push_back(zeroValue64);
2188 snprintfArgs.push_back(formatStringValue);
2189 for (vector<Value *>::iterator i = replacementValues.begin(); i != replacementValues.end(); ++i)
2190 snprintfArgs.push_back(*i);
2191 Value *bufferLengthValue32 = CallInst::Create(snprintfFunction, snprintfArgs,
"", block);
2192 Value *bufferLengthValue =
new SExtInst(bufferLengthValue32, IntegerType::get(module->getContext(), 64),
"", block);
2193 bufferLengthValue = BinaryOperator::Create(Instruction::Add, bufferLengthValue, oneValue64,
"", block);
2196 AllocaInst *bufferVariable =
new AllocaInst(pointerToCharType, 0,
"buffer", block);
2198 new StoreInst(bufferValue, bufferVariable,
false, block);
2201 snprintfArgs[0] = bufferValue;
2202 snprintfArgs[1] = bufferLengthValue;
2203 CallInst::Create(snprintfFunction, snprintfArgs,
"", block);
2220 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2222 if (stringsToConcatenate.empty())
2224 return constantsCache->
get(
"");
2226 else if (stringsToConcatenate.size() == 2)
2228 const char *functionName =
"vuoConcatenateStrings2";
2229 Function *
function = module->getFunction(functionName);
2232 vector<Type *> params;
2233 params.push_back(pointerToCharType);
2234 params.push_back(pointerToCharType);
2236 FunctionType *functionType = FunctionType::get(pointerToCharType, params,
false);
2237 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2240 vector<Value *> args;
2241 args.push_back(stringsToConcatenate[0]);
2242 args.push_back(stringsToConcatenate[1]);
2243 return CallInst::Create(
function, args,
"", block);
2245 else if (stringsToConcatenate.size() == 3)
2247 const char *functionName =
"vuoConcatenateStrings3";
2248 Function *
function = module->getFunction(functionName);
2251 vector<Type *> params;
2252 params.push_back(pointerToCharType);
2253 params.push_back(pointerToCharType);
2254 params.push_back(pointerToCharType);
2256 FunctionType *functionType = FunctionType::get(pointerToCharType, params,
false);
2257 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2260 vector<Value *> args;
2261 args.push_back(stringsToConcatenate[0]);
2262 args.push_back(stringsToConcatenate[1]);
2263 args.push_back(stringsToConcatenate[2]);
2264 return CallInst::Create(
function, args,
"", block);
2268 IntegerType *sizeType = IntegerType::get(module->getContext(), 64);
2270 const char *functionName =
"vuoConcatenateStrings";
2271 Function *
function = module->getFunction(functionName);
2274 vector<Type *> params;
2275 params.push_back(PointerType::get(pointerToCharType, 0));
2276 params.push_back(sizeType);
2278 FunctionType *functionType = FunctionType::get(pointerToCharType, params,
false);
2279 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2283 for (
size_t i = 0; i < stringsToConcatenate.size(); ++i)
2286 vector<Value *> args;
2287 args.push_back(stringsValue);
2288 args.push_back(ConstantInt::get(sizeType, stringsToConcatenate.size()));
2289 Value *concatenatedStringValue = CallInst::Create(
function, args,
"", block);
2293 return concatenatedStringValue;
2308 Value *elementCountValue = ConstantInt::get(module->getContext(), APInt(64, elementCount));
2323 Constant *elementBytesValue = ConstantExpr::getSizeOf(elementType);
2324 Value *elementCountValue64;
2325 if (
static_cast<IntegerType *
>(elementCountValue->getType())->getBitWidth() < 64)
2326 elementCountValue64 =
new SExtInst(elementCountValue, IntegerType::get(module->getContext(), 64),
"", block);
2328 elementCountValue64 = elementCountValue;
2330 BinaryOperator *bytesValue = BinaryOperator::Create(Instruction::Mul, elementBytesValue, elementCountValue64,
"", block);
2333 CallInst *mallocReturnValue = CallInst::Create(mallocFunction, bytesValue,
"", block);
2335 Type *elementPointerType = PointerType::get(elementType, 0);
2336 CastInst *mallocReturnValueCasted =
new BitCastInst(mallocReturnValue, elementPointerType,
"", block);
2338 return mallocReturnValueCasted;
2351 Value *bytesValue = ConstantInt::get(module->getContext(), APInt(
sizeof(
size_t) * 8, bytes));
2353 return CallInst::Create(mallocFunction, bytesValue,
"", block);
2371 vector<Value *> args;
2373 PointerType *voidPointerType = PointerType::getUnqual(IntegerType::get(module->getContext(), 8));
2374 destAddress =
new BitCastInst(destAddress, voidPointerType,
"", block);
2375 args.push_back(destAddress);
2377 sourceAddress =
new BitCastInst(sourceAddress, voidPointerType,
"", block);
2378 args.push_back(sourceAddress);
2380 args.push_back(ConstantInt::get(module->getContext(), APInt(
sizeof(
size_t) * 8, bytes)));
2383 CallInst::Create(memcpyFunction, args,
"", block);
2393 if (valueToCast->getType() == typeToCastTo)
2396 if (valueToCast->getType()->isIntegerTy() && typeToCastTo->isIntegerTy())
2397 return CastInst::CreateIntegerCast(valueToCast, typeToCastTo,
true,
"", block);
2398 else if (valueToCast->getType()->isIntegerTy() && typeToCastTo->isPointerTy())
2399 return generateTypeCastFromIntegerToPointer(module, block, valueToCast, typeToCastTo);
2400 else if (valueToCast->getType()->isFloatingPointTy() && typeToCastTo->isPointerTy())
2401 return generateTypeCastFromFloatingPointToPointer(module, block, valueToCast, typeToCastTo);
2402 else if (valueToCast->getType()->isPointerTy() && typeToCastTo->isIntegerTy())
2403 return generateTypeCastFromPointerToInteger(module, block, valueToCast, typeToCastTo);
2404 else if (valueToCast->getType()->isPointerTy() && typeToCastTo->isFloatingPointTy())
2405 return generateTypeCastFromPointerToFloatingPoint(module, block, valueToCast, typeToCastTo);
2406 else if (typeToCastTo->isStructTy())
2407 return generateTypeCastFromLoweredTypeToStruct(block, valueToCast, typeToCastTo);
2408 else if (typeToCastTo->isVectorTy())
2409 return generateTypeCastFromLoweredTypeToVector(block, valueToCast, typeToCastTo);
2410 else if (typeToCastTo->isArrayTy())
2411 return generateTypeCastFromLoweredTypeToArray(module, block, valueToCast, typeToCastTo);
2413 return new BitCastInst(valueToCast, typeToCastTo,
"", block);
2428 string annotation,
string fileName,
unsigned int lineNumber,
2432 string valueName = value->getName();
2433 string variableName = valueName +
".addr";
2434 string valueAsVoidPointerName = valueName +
".addr1";
2435 string annotationVariableName = valueName +
"__annotation";
2438 vector<Value *> annotateFunctionArgs;
2441 variable->setName(variableName);
2442 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2443 Value *valueAsVoidPointer =
generateTypeCast(module, block, variable, voidPointerType);
2444 valueAsVoidPointer->setName(valueAsVoidPointerName);
2445 annotateFunctionArgs.push_back(valueAsVoidPointer);
2448 annotateFunctionArgs.push_back(annotationPointer);
2450 Constant *fileNamePointer = constantsCache->
get(fileName);
2451 annotateFunctionArgs.push_back(fileNamePointer);
2453 ConstantInt *lineNumberValue = ConstantInt::get(module->getContext(), APInt(32, lineNumber));
2454 annotateFunctionArgs.push_back(lineNumberValue);
2456 CallInst::Create(annotateFunction, annotateFunctionArgs,
"", block);
2466 Type *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2467 string variableName =
"moduleDetails";
2468 if (! moduleKey.empty())
2470 GlobalVariable *moduleDetailsVariable =
new GlobalVariable(*module, pointerToCharType,
false, GlobalValue::ExternalLinkage, 0, variableName);
2471 moduleDetailsVariable->setInitializer(moduleDetailsValue);
2479 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromIntegerToPointer(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2481 unsigned pointerBitWidth = 64;
2482 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2483 CastInst *valueAsIntegerWithPointerBitWidth = CastInst::CreateIntegerCast(valueToCast, integerWithPointerBitWidth,
true,
"", block);
2484 return new IntToPtrInst(valueAsIntegerWithPointerBitWidth, typeToCastTo,
"", block);
2492 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromFloatingPointToPointer(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2494 unsigned pointerBitWidth = 64;
2495 Type *floatingPointWithPointerBitWidth = Type::getDoubleTy(module->getContext());
2496 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2497 CastInst *valueAsFloatingPointWithPointerBitWidth = CastInst::CreateFPCast(valueToCast, floatingPointWithPointerBitWidth,
"", block);
2498 Value *valueAsIntegerWithPointerBitWidth =
new BitCastInst(valueAsFloatingPointWithPointerBitWidth, integerWithPointerBitWidth,
"", block);
2499 return generateTypeCastFromIntegerToPointer(module, block, valueAsIntegerWithPointerBitWidth, typeToCastTo);
2507 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromPointerToInteger(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2509 unsigned pointerBitWidth = 64;
2510 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2511 CastInst *valueAsIntegerWithPointerBitWidth =
new PtrToIntInst(valueToCast, integerWithPointerBitWidth,
"", block);
2512 return CastInst::CreateIntegerCast(valueAsIntegerWithPointerBitWidth, typeToCastTo,
true,
"", block);
2520 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromPointerToFloatingPoint(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2522 unsigned pointerBitWidth = 64;
2523 Type *floatingPointWithPointerBitWidth = Type::getDoubleTy(module->getContext());
2524 IntegerType *integerWithPointerBitWidth = IntegerType::get(module->getContext(), pointerBitWidth);
2525 Value *valueAsIntegerWithPointerBitWidth = generateTypeCastFromPointerToInteger(module, block, valueToCast, integerWithPointerBitWidth);
2526 CastInst *valueAsFloatingPointWithPointerBitWidth =
new BitCastInst(valueAsIntegerWithPointerBitWidth, floatingPointWithPointerBitWidth,
"", block);
2527 return CastInst::CreateFPCast(valueAsFloatingPointWithPointerBitWidth, typeToCastTo,
"", block);
2535 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromLoweredTypeToStruct(BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2537 Value *originalValueToCast = valueToCast;
2539 if (valueToCast->getType()->isVectorTy() || valueToCast->getType()->isDoubleTy())
2542 PointerType *pointerToLoweredType = PointerType::get(valueToCast->getType(), 0);
2544 AllocaInst *structVariable =
new AllocaInst(typeToCastTo, 0,
"", block);
2545 CastInst *structVariableAsLoweredType =
new BitCastInst(structVariable, pointerToLoweredType,
"", block);
2546 new StoreInst(valueToCast, structVariableAsLoweredType,
false, block);
2547 return new LoadInst(structVariable,
"",
false, block);
2550 if (valueToCast->getType()->isPointerTy())
2553 valueToCast =
new LoadInst(valueToCast,
"",
false, block);
2554 if (valueToCast->getType() == typeToCastTo)
2558 if (valueToCast->getType()->isStructTy())
2561 StructType *structTypeOfValueToCast =
static_cast<StructType *
>(valueToCast->getType());
2562 PointerType *pointerToTypeToCastTo = PointerType::get(typeToCastTo, 0);
2564 AllocaInst *otherStructVariable =
new AllocaInst(structTypeOfValueToCast, 0,
"", block);
2565 new StoreInst(valueToCast, otherStructVariable,
false, block);
2566 CastInst *otherStructAsTypeToCastTo =
new BitCastInst(otherStructVariable, pointerToTypeToCastTo,
"", block);
2567 return new LoadInst(otherStructAsTypeToCastTo,
"",
false, block);
2570 VUserLog(
"Error: Couldn't cast from lowered type to struct.");
2571 originalValueToCast->getType()->dump(); fprintf(stderr,
"\n");
2572 typeToCastTo->dump(); fprintf(stderr,
"\n");
2573 return originalValueToCast;
2581 Value * VuoCompilerCodeGenUtilities::generateTypeCastFromLoweredTypeToVector(BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2583 if (typeToCastTo->isVectorTy() &&
static_cast<VectorType *
>(typeToCastTo)->getElementType()->isFloatTy())
2585 uint64_t elementCount =
static_cast<VectorType *
>(typeToCastTo)->getNumElements();
2586 if (elementCount == 2 && valueToCast->getType()->isDoubleTy())
2589 PointerType *pointerToDoubleType = PointerType::get(valueToCast->getType(), 0);
2591 AllocaInst *vectorVariable =
new AllocaInst(typeToCastTo, 0,
"", block);
2592 CastInst *dstVectorVariableAsDouble =
new BitCastInst(vectorVariable, pointerToDoubleType,
"", block);
2593 new StoreInst(valueToCast, dstVectorVariableAsDouble,
false, block);
2594 return new LoadInst(vectorVariable,
"",
false, block);
2596 else if (elementCount == 3 && valueToCast->getType()->isVectorTy() &&
2597 static_cast<VectorType *
>(valueToCast->getType())->getNumElements() == 2 &&
2598 static_cast<VectorType *
>(valueToCast->getType())->getElementType()->isDoubleTy())
2601 PointerType *pointerToDoubleVectorType = PointerType::get(valueToCast->getType(), 0);
2603 AllocaInst *floatVectorVariable =
new AllocaInst(typeToCastTo, 0,
"", block);
2604 CastInst *floatVectorVariableAsDoubleVector =
new BitCastInst(floatVectorVariable, pointerToDoubleVectorType,
"", block);
2605 new StoreInst(valueToCast, floatVectorVariableAsDoubleVector,
false, block);
2606 return new LoadInst(floatVectorVariable,
"",
false, block);
2608 else if (elementCount == 3 && valueToCast->getType()->isVectorTy() &&
2609 static_cast<VectorType *
>(valueToCast->getType())->getNumElements() == 4 &&
2610 static_cast<VectorType *
>(valueToCast->getType())->getElementType()->isIntegerTy(32))
2613 PointerType *pointerToIntVectorType = PointerType::get(valueToCast->getType(), 0);
2614 AllocaInst *floatVectorVariable =
new AllocaInst(typeToCastTo, 0,
"", block);
2615 CastInst *floatVectorVariableAsIntVector =
new BitCastInst(floatVectorVariable, pointerToIntVectorType,
"", block);
2616 new StoreInst(valueToCast, floatVectorVariableAsIntVector,
false, block);
2617 return new LoadInst(floatVectorVariable,
"",
false, block);
2621 VUserLog(
"Error: Couldn't cast from lowered type to vector.");
2622 valueToCast->getType()->dump(); fprintf(stderr,
"\n");
2623 typeToCastTo->dump(); fprintf(stderr,
"\n");
2632 Value *VuoCompilerCodeGenUtilities::generateTypeCastFromLoweredTypeToArray(Module *module, BasicBlock *block, Value *valueToCast, Type *typeToCastTo)
2634 if (valueToCast->getType()->isStructTy())
2636 StructType *valueType =
static_cast<StructType *
>(valueToCast->getType());
2637 ArrayType *arrayTypeToCastTo =
static_cast<ArrayType *
>(typeToCastTo);
2638 if (valueType->getElementType(0)->isFloatTy() && arrayTypeToCastTo->getElementType()->isFloatTy())
2640 AllocaInst *arrayVariable =
new AllocaInst(typeToCastTo, 0,
"", block);
2641 PointerType *pointerToLoweredType = PointerType::get(valueToCast->getType(), 0);
2642 CastInst *arrayVariableAsLoweredType =
new BitCastInst(arrayVariable, pointerToLoweredType,
"", block);
2643 new StoreInst(valueToCast, arrayVariableAsLoweredType,
false, block);
2644 return new LoadInst(arrayVariable,
"",
false, block);
2648 VUserLog(
"Error: Couldn't cast from lowered type to array.");
2649 valueToCast->getType()->dump(); fprintf(stderr,
"\n");
2650 typeToCastTo->dump(); fprintf(stderr,
"\n");
2659 Function *
function = getVuoRegisterFunction(module);
2661 Type *voidPointerType =
function->getFunctionType()->getParamType(0);
2662 Type *pointerToCharType =
function->getFunctionType()->getParamType(2);
2663 Type *intType =
function->getFunctionType()->getParamType(3);
2665 ConstantPointerNull *nullValue = ConstantPointerNull::get(
static_cast<PointerType *
>(pointerToCharType) );
2666 Constant *zeroValue = ConstantInt::get(intType, 0);
2668 vector<Value *> args;
2670 BitCastInst *argumentAsVoidPointer =
new BitCastInst(argument, voidPointerType,
"", block);
2671 args.push_back(argumentAsVoidPointer);
2673 args.push_back(freeFunction);
2675 args.push_back(nullValue);
2676 args.push_back(zeroValue);
2677 args.push_back(nullValue);
2678 args.push_back(nullValue);
2680 CallInst::Create(
function, args,
"", block);
2710 if (argument->getType()->isPointerTy())
2712 Function *
function = (isRetain ? getVuoRetainFunction(module) : getVuoReleaseFunction(module));
2713 Type *voidPointerType =
function->getFunctionType()->getParamType(0);
2715 vector<Value *> retainOrReleaseArgs;
2717 CallInst::Create(
function, retainOrReleaseArgs,
"", block);
2719 else if (argument->getType()->isStructTy())
2721 AllocaInst *structPointer =
new AllocaInst(argument->getType(), 0,
"", block);
2722 new StoreInst(argument, structPointer,
false, block);
2724 int numElements =
static_cast<StructType *
>(argument->getType())->getNumElements();
2725 for (
unsigned i = 0; i < numElements; ++i)
2739 return type->isPointerTy() || type->isStructTy();
2748 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2749 Value *argumentAsVoidPointer =
new BitCastInst(argument, voidPointerType,
"", block);
2750 CallInst::Create(freeFunction, argumentAsVoidPointer,
"", block);
2759 CallInst::Create(
function, jsonObjectValue,
"", block);
2767 BasicBlock *initialBlock, BasicBlock *&nullBlock, BasicBlock *¬NullBlock)
2769 nullBlock = BasicBlock::Create(module->getContext(),
"null",
function, NULL);
2770 notNullBlock = BasicBlock::Create(module->getContext(),
"notNull",
function, NULL);
2772 Value *nullValue = ConstantPointerNull::get(
static_cast<PointerType *
>(valueToCheck->getType()) );
2773 ICmpInst *isNotNull =
new ICmpInst(*initialBlock, ICmpInst::ICMP_NE, valueToCheck, nullValue,
"");
2774 BranchInst::Create(notNullBlock, nullBlock, isNotNull, initialBlock);
2783 if (valueToSerialize->getType()->isPointerTy())
2785 vector<Value *> replacementValues;
2786 replacementValues.push_back(valueToSerialize);
2792 VUserLog(
"Error: Couldn't serialize non-pointer value.");
2804 if (destinationVariable->getType()->isPointerTy())
2807 Value *formatString = constantsCache->
get(
"%lx");
2809 vector<Value *> sscanfArgs;
2810 sscanfArgs.push_back(stringToUnserialize);
2811 sscanfArgs.push_back(formatString);
2812 sscanfArgs.push_back(destinationVariable);
2813 CallInst::Create(sscanfFunction, sscanfArgs,
"", block);
2826 Type *boolType = IntegerType::get(module->getContext(), 64);
2828 const char *functionName =
"vuoIsPaused";
2829 Function *
function = module->getFunction(functionName);
2832 FunctionType *functionType = FunctionType::get(boolType, compositionStateValue->getType(),
false);
2833 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2836 CallInst *isPausedValue = CallInst::Create(
function, compositionStateValue,
"", block);
2837 Constant *falseValue = ConstantInt::get(boolType, 0);
2838 return new ICmpInst(*block, ICmpInst::ICMP_NE, isPausedValue, falseValue,
"");
2845 Value *compositionStateValue, Value *nodeIdentifierValue)
2847 const char *functionName =
"vuoSendNodeExecutionStarted";
2848 Function *
function = module->getFunction(functionName);
2852 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2854 vector<Type *> functionParams;
2855 functionParams.push_back(pointerToCompositionState);
2856 functionParams.push_back(pointerToCharType);
2857 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2858 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2861 vector<Value *> args;
2862 args.push_back(compositionStateValue);
2863 args.push_back(nodeIdentifierValue);
2864 CallInst::Create(
function, args,
"", block);
2871 Value *compositionStateValue, Value *nodeIdentifierValue)
2873 const char *functionName =
"vuoSendNodeExecutionFinished";
2874 Function *
function = module->getFunction(functionName);
2878 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2880 vector<Type *> functionParams;
2881 functionParams.push_back(pointerToCompositionState);
2882 functionParams.push_back(pointerToCharType);
2883 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2884 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2887 vector<Value *> args;
2888 args.push_back(compositionStateValue);
2889 args.push_back(nodeIdentifierValue);
2890 CallInst::Create(
function, args,
"", block);
2897 Value *compositionStateValue, Value *portIdentifierValue,
2898 bool receivedEvent,
bool receivedData,
2899 Value *portDataSummaryValue)
2901 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2902 Value *receivedEventValue = ConstantInt::get(boolType, receivedEvent ? 1 : 0);
2903 Value *receivedDataValue = ConstantInt::get(boolType, receivedData ? 1 : 0);
2904 generateSendInputPortsUpdated(module, block, compositionStateValue, portIdentifierValue, receivedEventValue, receivedDataValue, portDataSummaryValue);
2911 Value *compositionStateValue, Value *portIdentifierValue,
2912 Value *receivedEventValue, Value *receivedDataValue,
2913 Value *portDataSummaryValue)
2915 const char *functionName =
"vuoSendInputPortsUpdated";
2916 Function *
function = module->getFunction(functionName);
2920 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2921 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2923 vector<Type *> functionParams;
2924 functionParams.push_back(pointerToCompositionState);
2925 functionParams.push_back(pointerToCharType);
2926 functionParams.push_back(boolType);
2927 functionParams.push_back(boolType);
2928 functionParams.push_back(pointerToCharType);
2929 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2930 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2933 vector<Value *> args;
2934 args.push_back(compositionStateValue);
2935 args.push_back(portIdentifierValue);
2936 args.push_back(receivedEventValue);
2937 args.push_back(receivedDataValue);
2938 args.push_back(portDataSummaryValue);
2939 CallInst::Create(
function, args,
"", block);
2946 Value *compositionStateValue, Value *portIdentifierValue,
2947 Value *sentEventValue, Value *sentDataValue,
2948 Value *portDataSummaryValue)
2950 const char *functionName =
"vuoSendOutputPortsUpdated";
2951 Function *
function = module->getFunction(functionName);
2955 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2956 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2958 vector<Type *> functionParams;
2959 functionParams.push_back(pointerToCompositionState);
2960 functionParams.push_back(pointerToCharType);
2961 functionParams.push_back(boolType);
2962 functionParams.push_back(boolType);
2963 functionParams.push_back(pointerToCharType);
2964 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2965 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
2968 vector<Value *> args;
2969 args.push_back(compositionStateValue);
2970 args.push_back(portIdentifierValue);
2971 args.push_back(sentEventValue);
2972 args.push_back(sentDataValue);
2973 args.push_back(portDataSummaryValue);
2974 CallInst::Create(
function, args,
"", block);
2981 Value *compositionStateValue, Value *portIdentifierValue,
2982 Value *sentDataValue, Value *portDataSummaryValue)
2984 const char *functionName =
"vuoSendPublishedOutputPortsUpdated";
2985 Function *
function = module->getFunction(functionName);
2989 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
2990 IntegerType *boolType = IntegerType::get(module->getContext(), 1);
2992 vector<Type *> functionParams;
2993 functionParams.push_back(pointerToCompositionState);
2994 functionParams.push_back(pointerToCharType);
2995 functionParams.push_back(boolType);
2996 functionParams.push_back(pointerToCharType);
2997 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
2998 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3001 vector<Value *> args;
3002 args.push_back(compositionStateValue);
3003 args.push_back(portIdentifierValue);
3004 args.push_back(sentDataValue);
3005 args.push_back(portDataSummaryValue);
3006 CallInst::Create(
function, args,
"", block);
3013 Value *compositionStateValue, Value *eventIdValue)
3015 const char *functionName =
"vuoSendEventFinished";
3016 Function *
function = module->getFunction(functionName);
3022 vector<Type *> functionParams;
3023 functionParams.push_back(pointerToCompositionState);
3024 functionParams.push_back(eventIdType);
3025 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3026 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3029 vector<Value *> args;
3030 args.push_back(compositionStateValue);
3031 args.push_back(eventIdValue);
3032 CallInst::Create(
function, args,
"", block);
3039 Value *compositionStateValue, Value *portIdentifierValue)
3041 const char *functionName =
"vuoSendEventDropped";
3042 Function *
function = module->getFunction(functionName);
3046 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3048 vector<Type *> functionParams;
3049 functionParams.push_back(pointerToCompositionState);
3050 functionParams.push_back(pointerToCharType);
3051 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3052 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3055 vector<Value *> args;
3056 args.push_back(compositionStateValue);
3057 args.push_back(portIdentifierValue);
3058 CallInst::Create(
function, args,
"", block);
3065 Value *compositionStateValue,
3068 const char *functionName =
"vuoShouldSendPortDataTelemetry";
3069 Function *shouldSendTelemetryFunction = module->getFunction(functionName);
3070 if (! shouldSendTelemetryFunction)
3073 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3075 vector<Type *> functionParams;
3076 functionParams.push_back(pointerToCompositionState);
3077 functionParams.push_back(pointerToCharType);
3078 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
3079 shouldSendTelemetryFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3082 Constant *portIdentifierValue = constantsCache->
get(portIdentifier);
3084 vector<Value *> args;
3085 args.push_back(compositionStateValue);
3086 args.push_back(portIdentifierValue);
3087 CallInst *retValue = CallInst::Create(shouldSendTelemetryFunction, args,
"", block);
3089 Constant *zeroValue = ConstantInt::get(retValue->getType(), 0);
3090 return new ICmpInst(*block, ICmpInst::ICMP_NE, retValue, zeroValue,
"");
3098 Value *compositionStateValue,
3099 BasicBlock *initialBlock, BasicBlock *&trueBlock, BasicBlock *&falseBlock,
3101 Value *&replacementJsonValue)
3103 Type *boolType = IntegerType::get(module->getContext(), 64);
3104 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
3106 const char *functionName =
"vuoIsNodeBeingRemovedOrReplaced";
3107 Function *calledFunction = module->getFunction(functionName);
3108 if (! calledFunction)
3110 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3111 PointerType *pointerToPointerToJsonObjectType = PointerType::get(pointerToJsonObjectType, 0);
3113 vector<Type *> functionParams;
3114 functionParams.push_back(compositionStateValue->getType());
3115 functionParams.push_back(pointerToCharType);
3116 functionParams.push_back(pointerToPointerToJsonObjectType);
3117 FunctionType *functionType = FunctionType::get(boolType, functionParams,
false);
3118 calledFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3121 Value *nodeIdentifierValue = constantsCache->
get(nodeIdentifier);
3123 AllocaInst *replacementJsonVariable =
new AllocaInst(pointerToJsonObjectType, 0,
"", initialBlock);
3124 new StoreInst(ConstantPointerNull::get(pointerToJsonObjectType), replacementJsonVariable,
false, initialBlock);
3126 vector<Value *> args;
3127 args.push_back(compositionStateValue);
3128 args.push_back(nodeIdentifierValue);
3129 args.push_back(replacementJsonVariable);
3130 CallInst *retValue = CallInst::Create(calledFunction, args,
"", initialBlock);
3132 replacementJsonValue =
new LoadInst(replacementJsonVariable,
"",
false, initialBlock);
3134 trueBlock = BasicBlock::Create(module->getContext(),
"removedReplaced",
function, NULL);
3135 falseBlock = BasicBlock::Create(module->getContext(),
"notRemovedReplaced",
function, NULL);
3136 Constant *falseValue = ConstantInt::get(boolType, 0);
3137 ICmpInst *retIsTrue =
new ICmpInst(*initialBlock, ICmpInst::ICMP_NE, retValue, falseValue,
"");
3138 BranchInst::Create(trueBlock, falseBlock, retIsTrue, initialBlock);
3146 Value *compositionStateValue,
3147 BasicBlock *initialBlock, BasicBlock *&trueBlock, BasicBlock *&falseBlock,
3149 Value *&replacementJsonValue)
3151 Type *boolType = IntegerType::get(module->getContext(), 64);
3152 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
3154 const char *functionName =
"vuoIsNodeBeingAddedOrReplaced";
3155 Function *calledFunction = module->getFunction(functionName);
3156 if (! calledFunction)
3158 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3159 PointerType *pointerToPointerToJsonObjectType = PointerType::get(pointerToJsonObjectType, 0);
3161 vector<Type *> functionParams;
3162 functionParams.push_back(compositionStateValue->getType());
3163 functionParams.push_back(pointerToCharType);
3164 functionParams.push_back(pointerToPointerToJsonObjectType);
3165 FunctionType *functionType = FunctionType::get(boolType, functionParams,
false);
3166 calledFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3169 Value *nodeIdentifierValue = constantsCache->
get(nodeIdentifier);
3171 AllocaInst *replacementJsonVariable =
new AllocaInst(pointerToJsonObjectType, 0,
"", initialBlock);
3172 new StoreInst(ConstantPointerNull::get(pointerToJsonObjectType), replacementJsonVariable,
false, initialBlock);
3174 vector<Value *> args;
3175 args.push_back(compositionStateValue);
3176 args.push_back(nodeIdentifierValue);
3177 args.push_back(replacementJsonVariable);
3178 CallInst *retValue = CallInst::Create(calledFunction, args,
"", initialBlock);
3180 replacementJsonValue =
new LoadInst(replacementJsonVariable,
"",
false, initialBlock);
3182 trueBlock = BasicBlock::Create(module->getContext(),
"addedReplaced",
function, NULL);
3183 falseBlock = BasicBlock::Create(module->getContext(),
"notAddedReplaced",
function, NULL);
3184 Constant *falseValue = ConstantInt::get(boolType, 0);
3185 ICmpInst *retIsTrue =
new ICmpInst(*initialBlock, ICmpInst::ICMP_NE, retValue, falseValue,
"");
3186 BranchInst::Create(trueBlock, falseBlock, retIsTrue, initialBlock);
3196 return ConstantInt::get(module->getContext(), APInt(64, 0));
3203 Value *compositionStateValue,
size_t nodeIndex)
3205 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3206 Value *nodeIndexValue = ConstantInt::get(unsignedLongType, nodeIndex);
3214 Value *compositionStateValue, Value *nodeIndexValue)
3216 const char *functionName =
"vuoGetNodeContext";
3217 Function *
function = module->getFunction(functionName);
3220 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3221 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
3223 vector<Type *> functionParams;
3224 functionParams.push_back(compositionStateValue->getType());
3225 functionParams.push_back(unsignedLongType);
3226 FunctionType *functionType = FunctionType::get(pointerToNodeContextType, functionParams,
false);
3227 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3230 vector<Value *> args;
3231 args.push_back(compositionStateValue);
3232 args.push_back(nodeIndexValue);
3233 return CallInst::Create(
function, args,
"", block);
3240 Value *compositionStateValue)
3242 const char *functionName =
"vuoGetCompositionContext";
3243 Function *
function = module->getFunction(functionName);
3246 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
3248 vector<Type *> functionParams;
3249 functionParams.push_back(compositionStateValue->getType());
3250 FunctionType *functionType = FunctionType::get(pointerToNodeContextType, functionParams,
false);
3251 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3254 vector<Value *> args;
3255 args.push_back(compositionStateValue);
3256 return CallInst::Create(
function, args,
"", block);
3263 Value *compositionStateValue, Value *nodeIdentifierValue,
3264 Function *compositionCreateContextForNodeFunction,
3265 Function *compositionSetPortValueFunction,
3266 Function *compositionGetPortValueFunction,
3267 Function *compositionFireTriggerPortEventFunction,
3268 Function *compositionReleasePortDataFunction)
3270 const char *functionName =
"vuoAddNodeMetadata";
3271 Function *
function = module->getFunction(functionName);
3274 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3281 vector<Type *> functionParams;
3282 functionParams.push_back(compositionStateValue->getType());
3283 functionParams.push_back(pointerToCharType);
3284 functionParams.push_back(compositionCreateContextForNodeFunctionType);
3285 functionParams.push_back(compositionSetPortValueFunctionType);
3286 functionParams.push_back(compositionGetPortValueFunctionType);
3287 functionParams.push_back(compositionFireTriggerPortEventFunctionType);
3288 functionParams.push_back(compositionReleasePortDataFunctionType);
3289 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3290 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3293 vector<Value *> args;
3294 args.push_back(compositionStateValue);
3295 args.push_back(nodeIdentifierValue);
3296 args.push_back(compositionCreateContextForNodeFunction);
3297 args.push_back(compositionSetPortValueFunction);
3298 args.push_back(compositionGetPortValueFunction);
3299 args.push_back(compositionFireTriggerPortEventFunction);
3300 args.push_back(compositionReleasePortDataFunction);
3301 CallInst::Create(
function, args,
"", block);
3308 Value *compositionStateValue, Value *portIdentifierValue,
3309 Value *portNameValue,
size_t typeIndex, Value *initialValueValue)
3311 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3313 const char *functionName =
"vuoAddPortMetadata";
3314 Function *
function = module->getFunction(functionName);
3317 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3319 vector<Type *> functionParams;
3320 functionParams.push_back(compositionStateValue->getType());
3321 functionParams.push_back(pointerToCharType);
3322 functionParams.push_back(pointerToCharType);
3323 functionParams.push_back(unsignedLongType);
3324 functionParams.push_back(pointerToCharType);
3325 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3326 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3329 Value *typeIndexValue = ConstantInt::get(unsignedLongType, typeIndex);
3331 vector<Value *> args;
3332 args.push_back(compositionStateValue);
3333 args.push_back(portIdentifierValue);
3334 args.push_back(portNameValue);
3335 args.push_back(typeIndexValue);
3336 args.push_back(initialValueValue);
3337 CallInst::Create(
function, args,
"", block);
3344 bool isStatefulComposition,
size_t publishedOutputPortCount)
3346 IntegerType *boolType = IntegerType::get(module->getContext(), 64);
3347 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
3349 const char *functionName =
"vuoInitContextForTopLevelComposition";
3350 Function *
function = module->getFunction(functionName);
3355 vector<Type *> functionParams;
3356 functionParams.push_back(pointerToCompositionState);
3357 functionParams.push_back(boolType);
3358 functionParams.push_back(unsignedLongType);
3359 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3360 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3363 Value *isStatefulCompositionValue = ConstantInt::get(boolType, isStatefulComposition);
3364 Value *publishedOutputPortCountValue = ConstantInt::get(unsignedLongType, publishedOutputPortCount);
3366 vector<Value *> args;
3367 args.push_back(compositionStateValue);
3368 args.push_back(isStatefulCompositionValue);
3369 args.push_back(publishedOutputPortCountValue);
3370 CallInst::Create(
function, args,
"", block);
3378 const char *functionName =
"vuoFiniContextForTopLevelComposition";
3379 Function *
function = module->getFunction(functionName);
3384 vector<Type *> functionParams;
3385 functionParams.push_back(pointerToCompositionState);
3386 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3387 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3390 vector<Value *> args;
3391 args.push_back(compositionStateValue);
3392 CallInst::Create(
function, args,
"", block);
3400 const char *functionName =
"vuoGetTriggerWorkersScheduled";
3401 Function *
function = module->getFunction(functionName);
3407 vector<Type *> functionParams;
3408 functionParams.push_back(pointerToCompositionState);
3409 FunctionType *functionType = FunctionType::get(dispatchGroupType, functionParams,
false);
3410 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3413 vector<Value *> args;
3414 args.push_back(compositionStateValue);
3415 return CallInst::Create(
function, args,
"", block);
3422 Value *portIdentifierValue, Value *interprocessSerializationValue)
3424 const char *functionName =
"vuoGetInputPortString";
3425 Function *
function = module->getFunction(functionName);
3429 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3430 IntegerType *boolType = IntegerType::get(module->getContext(), 32);
3432 vector<Type *> functionParams;
3433 functionParams.push_back(pointerToCompositionState);
3434 functionParams.push_back(pointerToCharType);
3435 functionParams.push_back(boolType);
3436 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3437 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3440 vector<Value *> args;
3441 args.push_back(compositionStateValue);
3442 args.push_back(portIdentifierValue);
3443 args.push_back(interprocessSerializationValue);
3444 return CallInst::Create(
function, args,
"", block);
3451 Value *portIdentifierValue, Value *interprocessSerializationValue)
3453 const char *functionName =
"vuoGetOutputPortString";
3454 Function *
function = module->getFunction(functionName);
3458 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3459 IntegerType *boolType = IntegerType::get(module->getContext(), 32);
3461 vector<Type *> functionParams;
3462 functionParams.push_back(pointerToCompositionState);
3463 functionParams.push_back(pointerToCharType);
3464 functionParams.push_back(boolType);
3465 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3466 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3469 vector<Value *> args;
3470 args.push_back(compositionStateValue);
3471 args.push_back(portIdentifierValue);
3472 args.push_back(interprocessSerializationValue);
3473 return CallInst::Create(
function, args,
"", block);
3481 const char *variableName =
"vuoRuntimeState";
3482 GlobalVariable *variable = module->getNamedGlobal(variableName);
3485 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3486 variable =
new GlobalVariable(*module, voidPointer,
false, GlobalValue::ExternalLinkage, 0, variableName);
3489 return new LoadInst(variable,
"",
false, block);
3497 const char *functionName =
"vuoGetNextEventId";
3498 Function *
function = module->getFunction(functionName);
3502 Type *eventIdType = IntegerType::get(module->getContext(), 64);
3504 vector<Type *> functionParams;
3505 functionParams.push_back(pointerToCompositionState);
3506 FunctionType *functionType = FunctionType::get(eventIdType, functionParams,
false);
3507 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3510 vector<Value *> args;
3511 args.push_back(compositionStateValue);
3512 return CallInst::Create(
function, args,
"", block);
3519 Value *compositionStateValue, Value *dataCopyValue,
3520 Value *eventIdCopyValue)
3522 const char *functionName =
"vuoCreateTriggerWorkerContext";
3523 Function *
function = module->getFunction(functionName);
3527 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3530 vector<Type *> functionParams;
3531 functionParams.push_back(pointerToCompositionState);
3532 functionParams.push_back(voidPointerType);
3533 functionParams.push_back(pointerToEventIdType);
3534 FunctionType *functionType = FunctionType::get(voidPointerType, functionParams,
false);
3535 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3538 vector<Value *> args;
3539 args.push_back(compositionStateValue);
3540 args.push_back(dataCopyValue);
3541 args.push_back(eventIdCopyValue);
3542 return CallInst::Create(
function, args,
"", block);
3550 const char *functionName =
"vuoFreeTriggerWorkerContext";
3551 Function *
function = module->getFunction(functionName);
3554 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3556 vector<Type *> functionParams;
3557 functionParams.push_back(voidPointerType);
3558 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3559 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3562 vector<Value *> args;
3563 args.push_back(contextValue);
3564 CallInst::Create(
function, args,
"", block);
3571 Value *compositionStateValue, Value *inputPortIdentifierValue,
3572 Value *valueAsStringValue, Value *isCompositionRunningValue)
3574 const char *functionName =
"vuoCreatePublishedInputWorkerContext";
3575 Function *
function = module->getFunction(functionName);
3579 PointerType *pointerToChar = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3580 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3581 Type *boolType = IntegerType::get(module->getContext(), 64);
3583 vector<Type *> functionParams;
3584 functionParams.push_back(pointerToCompositionState);
3585 functionParams.push_back(pointerToChar);
3586 functionParams.push_back(pointerToChar);
3587 functionParams.push_back(boolType);
3588 FunctionType *functionType = FunctionType::get(voidPointerType, functionParams,
false);
3589 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3592 vector<Value *> args;
3593 args.push_back(compositionStateValue);
3594 args.push_back(inputPortIdentifierValue);
3595 args.push_back(valueAsStringValue);
3596 args.push_back(isCompositionRunningValue);
3597 return CallInst::Create(
function, args,
"", block);
3604 Value *compositionStateValue)
3606 const char *functionName =
"vuoAddCompositionStateToThreadLocalStorage";
3607 Function *
function = module->getFunction(functionName);
3612 vector<Type *> functionParams;
3613 functionParams.push_back(pointerToCompositionState);
3614 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3615 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3618 vector<Value *> args;
3619 args.push_back(compositionStateValue);
3620 CallInst::Create(
function, args,
"", block);
3628 const char *functionName =
"vuoRemoveCompositionStateFromThreadLocalStorage";
3629 Function *
function = module->getFunction(functionName);
3632 vector<Type *> functionParams;
3633 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
3634 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3637 vector<Value *> args;
3638 CallInst::Create(
function, args,
"", block);
3644 Value * VuoCompilerCodeGenUtilities::generateStderr(Module *module, BasicBlock *block)
3646 PointerType *pointerToFileType = getPointerToFileType(module);
3648 string variableName =
"__stderrp";
3649 GlobalVariable *stderrVariable = module->getNamedGlobal(variableName);
3650 if (! stderrVariable)
3651 stderrVariable =
new GlobalVariable(*module, pointerToFileType,
false, GlobalValue::ExternalLinkage, 0, variableName);
3653 return new LoadInst(stderrVariable,
"",
false, block);
3661 vector<Value *> values;
3663 values.push_back(value);
3673 Value *stderrValue = generateStderr(module, block);
3676 vector<Value *> fprintfArgs;
3677 fprintfArgs.push_back(stderrValue);
3678 fprintfArgs.push_back(formatStringValue);
3679 for (vector<Value *>::const_iterator i = values.begin(); i != values.end(); ++i)
3680 fprintfArgs.push_back(*i);
3681 CallInst::Create(fprintfFunction, fprintfArgs,
"", block);
3690 StructType *dispatch_semaphore_s_type = module->getTypeByName(
"struct.dispatch_semaphore_s");
3691 if (! dispatch_semaphore_s_type)
3692 dispatch_semaphore_s_type = StructType::create(module->getContext(),
"struct.dispatch_semaphore_s");
3694 PointerType *dispatch_semaphore_t_type = PointerType::get(dispatch_semaphore_s_type, 0);
3695 return dispatch_semaphore_t_type;
3700 StructType *dispatch_group_s_type = module->getTypeByName(
"struct.dispatch_group_s");
3701 if (! dispatch_group_s_type)
3702 dispatch_group_s_type = StructType::create(module->getContext(),
"struct.dispatch_group_s");
3704 PointerType *dispatch_group_t_type = PointerType::get(dispatch_group_s_type, 0);
3705 return dispatch_group_t_type;
3708 PointerType * VuoCompilerCodeGenUtilities::getDispatchQueueType(Module *module)
3710 StructType *dispatch_queue_s_type = module->getTypeByName(
"struct.dispatch_queue_s");
3711 if (! dispatch_queue_s_type)
3712 dispatch_queue_s_type = StructType::create(module->getContext(),
"struct.dispatch_queue_s");
3714 PointerType *dispatch_queue_t_type = PointerType::get(dispatch_queue_s_type, 0);
3715 return dispatch_queue_t_type;
3718 StructType * VuoCompilerCodeGenUtilities::getDispatchObjectElementType(Module *module)
3720 StructType *dispatch_object_s_type = module->getTypeByName(
"struct.dispatch_object_s");
3721 if (! dispatch_object_s_type)
3722 dispatch_object_s_type = StructType::create(module->getContext(),
"struct.dispatch_object_s");
3723 vector<Type *> dispatch_object_s_fields;
3724 if (dispatch_object_s_type->isOpaque())
3725 dispatch_object_s_type->setBody(dispatch_object_s_fields,
false);
3726 return dispatch_object_s_type;
3731 StructType *dispatch_object_s_type = getDispatchObjectElementType(module);
3732 PointerType *pointerTo_dispatch_object_s_type = PointerType::get(dispatch_object_s_type, 0);
3734 StructType *dispatch_object_t_type = module->getTypeByName(
"union.dispatch_object_t");
3735 if (! dispatch_object_t_type)
3736 dispatch_object_t_type = StructType::create(module->getContext(),
"union.dispatch_object_t");
3737 vector<Type *> dispatch_object_t_fields;
3738 dispatch_object_t_fields.push_back(pointerTo_dispatch_object_s_type);
3739 if (dispatch_object_t_type->isOpaque())
3740 dispatch_object_t_type->setBody(dispatch_object_t_fields,
false);
3741 return dispatch_object_t_type;
3746 StructType *nodeContextType = module->getTypeByName(
"struct.NodeContext");
3747 if (! nodeContextType)
3748 nodeContextType = StructType::create(module->getContext(),
"struct.NodeContext");
3750 if (nodeContextType->isOpaque())
3752 PointerType *pointerToPointerToPortContextType = PointerType::get(PointerType::get(
getPortContextType(module), 0), 0);
3753 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3754 Type *longType = IntegerType::get(module->getContext(), 64);
3756 vector<Type *> fields;
3757 fields.push_back(pointerToPointerToPortContextType);
3758 fields.push_back(longType);
3759 fields.push_back(voidPointerType);
3761 fields.push_back(longType);
3763 fields.push_back(longType);
3764 nodeContextType->setBody(fields,
false);
3767 return nodeContextType;
3772 StructType *portContextType = module->getTypeByName(
"struct.PortContext");
3773 if (! portContextType)
3774 portContextType = StructType::create(module->getContext(),
"struct.PortContext");
3776 if (portContextType->isOpaque())
3778 Type *boolType = IntegerType::get(module->getContext(), 64);
3779 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3781 vector<Type *> fields;
3782 fields.push_back(boolType);
3783 fields.push_back(voidPointerType);
3784 fields.push_back(boolType);
3785 fields.push_back(getDispatchQueueType(module));
3787 fields.push_back(voidPointerType);
3788 portContextType->setBody(fields,
false);
3791 return portContextType;
3796 StructType *compositionStateType = module->getTypeByName(
"struct.VuoCompositionState");
3797 if (! compositionStateType)
3798 compositionStateType = StructType::create(module->getContext(),
"struct.VuoCompositionState");
3800 if (compositionStateType->isOpaque())
3802 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3803 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3805 vector<Type *> fields;
3806 fields.push_back(voidPointerType);
3807 fields.push_back(pointerToCharType);
3808 compositionStateType->setBody(fields,
false);
3811 return compositionStateType;
3814 StructType * VuoCompilerCodeGenUtilities::getGraphvizGraphType(Module *module)
3816 StructType *graphType = module->getTypeByName(
"struct.Agraph_t");
3818 graphType = StructType::create(module->getContext(),
"struct.Agraph_t");
3825 StructType *jsonObjectType = module->getTypeByName(
"struct.json_object");
3826 if (! jsonObjectType)
3827 jsonObjectType = StructType::create(module->getContext(),
"struct.json_object");
3829 return jsonObjectType;
3832 PointerType * VuoCompilerCodeGenUtilities::getPointerToFileType(Module *module)
3834 StructType *fileType = module->getTypeByName(
"struct.__sFILE");
3836 fileType = StructType::create(module->getContext(),
"struct.__sFILE");
3838 return PointerType::get(fileType, 0);
3841 PointerType * VuoCompilerCodeGenUtilities::getVuoShaderType(Module *module)
3843 StructType *shaderStructType = module->getTypeByName(
"struct._VuoShader");
3844 if (! shaderStructType)
3845 shaderStructType = StructType::create(module->getContext(),
"struct._VuoShader");
3847 return PointerType::get(shaderStructType, 0);
3850 PointerType * VuoCompilerCodeGenUtilities::getVuoImageType(Module *module)
3852 StructType *imageStructType = module->getTypeByName(
"struct._VuoImage");
3853 if (! imageStructType)
3854 imageStructType = StructType::create(module->getContext(),
"struct._VuoImage");
3856 return PointerType::get(imageStructType, 0);
3859 Type * VuoCompilerCodeGenUtilities::getVuoImageColorDepthType(Module *module)
3861 return IntegerType::get(module->getContext(), 32);
3866 return PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3877 const char *functionName =
"strcat";
3878 Function *
function = module->getFunction(functionName);
3881 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3883 vector<Type *> functionParams;
3884 functionParams.push_back(pointerToCharType);
3885 functionParams.push_back(pointerToCharType);
3886 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3887 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3894 const char *functionName =
"strcmp";
3895 Function *
function = module->getFunction(functionName);
3898 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3899 vector<Type *> functionParams;
3900 functionParams.push_back(pointerToi8Type);
3901 functionParams.push_back(pointerToi8Type);
3902 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
3903 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3910 const char *functionName =
"strdup";
3911 Function *
function = module->getFunction(functionName);
3914 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3916 vector<Type *> functionParams;
3917 functionParams.push_back(pointerToCharType);
3918 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
3919 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3926 const char *functionName =
"strlen";
3927 Function *
function = module->getFunction(functionName);
3930 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3932 vector<Type *> functionParams;
3933 functionParams.push_back(pointerToCharType);
3934 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 64), functionParams,
false);
3935 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3942 const char *functionName =
"snprintf";
3943 Function *
function = module->getFunction(functionName);
3946 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3948 vector<Type *> functionParams;
3949 functionParams.push_back(pointerToCharType);
3950 functionParams.push_back(IntegerType::get(module->getContext(), 64));
3951 functionParams.push_back(pointerToCharType);
3952 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
true);
3953 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3960 const char *functionName =
"sscanf";
3961 Function *
function = module->getFunction(functionName);
3964 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3966 vector<Type *> functionParams;
3967 functionParams.push_back(pointerToCharType);
3968 functionParams.push_back(pointerToCharType);
3969 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
true);
3970 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3977 const char *functionName =
"fprintf";
3978 Function *
function = module->getFunction(functionName);
3981 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
3983 vector<Type *> functionParams;
3984 functionParams.push_back( getPointerToFileType(module) );
3985 functionParams.push_back(pointerToCharType);
3986 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
true);
3987 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
3994 const char *functionName =
"puts";
3995 Function *
function = module->getFunction(functionName);
3998 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4000 vector<Type *> functionParams;
4001 functionParams.push_back(pointerToCharType);
4002 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
4003 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4010 const char *functionName =
"malloc";
4011 Function *
function = module->getFunction(functionName);
4014 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4016 vector<Type *> functionParams;
4017 functionParams.push_back(IntegerType::get(module->getContext(),
sizeof(
size_t)*CHAR_BIT));
4018 FunctionType *functionType = FunctionType::get(pointerToi8Type, functionParams,
false);
4019 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4026 const char *functionName =
"memcpy";
4027 Function *
function = module->getFunction(functionName);
4030 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4032 vector<Type *> functionParams;
4033 functionParams.push_back(pointerToi8Type);
4034 functionParams.push_back(pointerToi8Type);
4035 functionParams.push_back(IntegerType::get(module->getContext(),
sizeof(
size_t)*CHAR_BIT));
4036 FunctionType *functionType = FunctionType::get(pointerToi8Type, functionParams,
false);
4037 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4044 const char *functionName =
"free";
4045 Function *
function = module->getFunction(functionName);
4048 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4050 vector<Type *> functionParams;
4051 functionParams.push_back(pointerToi8Type);
4052 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4053 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4060 const char *functionName =
"llvm.var.annotation";
4061 Function *
function = module->getFunction(functionName);
4064 PointerType *pointerToi8Type = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4066 vector<Type *> functionParams;
4067 functionParams.push_back(pointerToi8Type);
4068 functionParams.push_back(pointerToi8Type);
4069 functionParams.push_back(pointerToi8Type);
4070 functionParams.push_back(IntegerType::get(module->getContext(), 32));
4071 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4072 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4079 const char *functionName =
"json_object_put";
4080 Function *
function = module->getFunction(functionName);
4083 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
4085 vector<Type *> functionParams;
4086 functionParams.push_back(pointerToJsonObjectType);
4087 FunctionType *functionType = FunctionType::get(IntegerType::get(module->getContext(), 32), functionParams,
false);
4088 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4095 const char *functionName =
"json_object_to_json_string_ext";
4096 Function *
function = module->getFunction(functionName);
4099 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4100 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
4102 vector<Type *> functionParams;
4103 functionParams.push_back(pointerToJsonObjectType);
4104 functionParams.push_back(IntegerType::get(module->getContext(), 32));
4105 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
4106 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4113 const char *functionName =
"json_tokener_parse";
4114 Function *
function = module->getFunction(functionName);
4117 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4118 PointerType *pointerToJsonObjectType = PointerType::get(
getJsonObjectType(module), 0);
4120 vector<Type *> functionParams;
4121 functionParams.push_back(pointerToCharType);
4122 FunctionType *functionType = FunctionType::get(pointerToJsonObjectType, functionParams,
false);
4123 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4130 const char *functionName =
"VuoShader_make";
4131 Function *
function = module->getFunction(functionName);
4134 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4135 Type *shaderType = getVuoShaderType(module);
4137 vector<Type *> functionParams;
4138 functionParams.push_back(pointerToCharType);
4139 FunctionType *functionType = FunctionType::get(shaderType, functionParams,
false);
4140 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4147 const char *functionName =
"VuoShader_addSource";
4148 Function *
function = module->getFunction(functionName);
4151 Type *shaderType = getVuoShaderType(module);
4152 Type *elementAsseblyMethodType = IntegerType::get(module->getContext(), 64);
4153 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4155 vector<Type *> functionParams;
4156 functionParams.push_back(shaderType);
4157 functionParams.push_back(elementAsseblyMethodType);
4158 functionParams.push_back(pointerToCharType);
4159 functionParams.push_back(pointerToCharType);
4160 functionParams.push_back(pointerToCharType);
4161 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4162 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4169 const char *functionName =
"VuoShader_setTransparent";
4170 Function *
function = module->getFunction(functionName);
4173 Type *shaderType = getVuoShaderType(module);
4174 Type *boolType = IntegerType::get(module->getContext(), 1);
4176 vector<Type *> functionParams;
4177 functionParams.push_back(shaderType);
4178 functionParams.push_back(boolType);
4179 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4180 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4188 Function *
function = module->getFunction(functionName);
4191 Type *shaderType = getVuoShaderType(module);
4192 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4196 vector<Type *> functionParams;
4197 functionParams.push_back(shaderType);
4198 functionParams.push_back(pointerToCharType);
4199 functionParams.insert(functionParams.end(), dataParams.begin(), dataParams.end());
4200 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4201 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4208 string functionName =
"VuoShader_samplerRectCoordinatesFromNormalizedCoordinates";
4209 Function *
function = module->getFunction(functionName);
4212 Type *loweredPoint2dType = Type::getDoubleTy(module->getContext());
4213 Type *intType = IntegerType::get(module->getContext(), 64);
4215 vector<Type *> functionParams;
4216 functionParams.push_back(loweredPoint2dType);
4217 functionParams.push_back(intType);
4218 functionParams.push_back(intType);
4219 FunctionType *functionType = FunctionType::get(loweredPoint2dType, functionParams,
false);
4220 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4227 const char *functionName =
"VuoImage_getColorDepth";
4228 Function *
function = module->getFunction(functionName);
4231 Type *imageType = getVuoImageType(module);
4232 Type *imageColorDepthType = getVuoImageColorDepthType(module);
4234 vector<Type *> functionParams;
4235 functionParams.push_back(imageType);
4236 FunctionType *functionType = FunctionType::get(imageColorDepthType, functionParams,
false);
4237 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4244 const char *functionName =
"VuoImageRenderer_render";
4245 Function *
function = module->getFunction(functionName);
4248 Type *shaderType = getVuoShaderType(module);
4249 Type *intType = IntegerType::get(module->getContext(), 64);
4250 Type *imageColorDepthType = getVuoImageColorDepthType(module);
4251 Type *imageType = getVuoImageType(module);
4253 vector<Type *> functionParams;
4254 functionParams.push_back(shaderType);
4255 functionParams.push_back(intType);
4256 functionParams.push_back(intType);
4257 functionParams.push_back(imageColorDepthType);
4258 FunctionType *functionType = FunctionType::get(imageType, functionParams,
false);
4259 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4266 string functionName =
"compositionAddNodeMetadata";
4267 string moduleKey = module->getModuleIdentifier();
4268 if (! moduleKey.empty())
4270 Function *
function = module->getFunction(functionName.c_str());
4275 vector<Type *> functionParams;
4276 functionParams.push_back(pointerToCompositionState);
4277 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4278 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4285 string functionName =
"compositionCreateContextForNode";
4286 string moduleKey = module->getModuleIdentifier();
4287 if (! moduleKey.empty())
4289 Function *
function = module->getFunction(functionName.c_str());
4292 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
4293 PointerType *pointerToNodeContextType = PointerType::get(
getNodeContextType(module), 0);
4295 vector<Type *> functionParams;
4296 functionParams.push_back(unsignedLongType);
4297 FunctionType *functionType = FunctionType::get(pointerToNodeContextType, functionParams,
false);
4298 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4305 string functionName =
"compositionPerformDataOnlyTransmissions";
4306 string moduleKey = module->getModuleIdentifier();
4307 if (! moduleKey.empty())
4309 Function *
function = module->getFunction(functionName.c_str());
4314 vector<Type *> functionParams;
4315 functionParams.push_back(pointerToCompositionState);
4316 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4317 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4324 string functionName =
"compositionReleasePortData";
4325 string moduleKey = module->getModuleIdentifier();
4326 if (! moduleKey.empty())
4328 Function *
function = module->getFunction(functionName.c_str());
4331 PointerType *voidPointer = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4332 IntegerType *unsignedLongType = IntegerType::get(module->getContext(), 64);
4334 vector<Type *> functionParams;
4335 functionParams.push_back(voidPointer);
4336 functionParams.push_back(unsignedLongType);
4337 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4338 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4345 const char *functionName =
"vuoSetup";
4346 Function *
function = module->getFunction(functionName);
4349 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4350 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4357 const char *functionName =
"vuoCleanup";
4358 Function *
function = module->getFunction(functionName);
4361 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4362 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4369 const char *functionName =
"vuoInstanceInit";
4370 Function *
function = module->getFunction(functionName);
4373 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4374 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4381 const char *functionName =
"vuoInstanceFini";
4382 Function *
function = module->getFunction(functionName);
4385 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()),
false);
4386 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4393 const char *functionName =
"vuoInstanceTriggerStart";
4394 Function *
function = module->getFunction(functionName);
4397 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), PointerType::get(
getCompositionInstanceDataType(module), 0),
false);
4398 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4405 const char *functionName =
"vuoInstanceTriggerStop";
4406 Function *
function = module->getFunction(functionName);
4409 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), PointerType::get(
getCompositionInstanceDataType(module), 0),
false);
4410 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4416 Type *instanceDataType,
4417 const vector<VuoPort *> &modelInputPorts,
4418 map<VuoPort *, size_t> &indexOfParameter,
4421 map<VuoPort *, size_t> indexOfEventParameter;
4422 return getNodeFunction(module, moduleKey,
"nodeInstanceInit", isSubcomposition,
false,
true,
false, instanceDataType, modelInputPorts, vector<VuoPort *>(),
4423 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4424 indexOfParameter, indexOfEventParameter, constantsCache);
4428 Type *instanceDataType,
4431 map<VuoPort *, size_t> indexOfParameter;
4432 map<VuoPort *, size_t> indexOfEventParameter;
4433 return getNodeFunction(module, moduleKey,
"nodeInstanceFini",
true,
true,
false,
false, instanceDataType, vector<VuoPort *>(), vector<VuoPort *>(),
4434 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4435 indexOfParameter, indexOfEventParameter, constantsCache);
4439 Type *instanceDataType,
4440 const vector<VuoPort *> &modelInputPorts,
4441 map<VuoPort *, size_t> &indexOfParameter,
4444 map<VuoPort *, size_t> indexOfEventParameter;
4445 return getNodeFunction(module, moduleKey,
"nodeInstanceTriggerStart",
true,
true,
false,
false, instanceDataType, modelInputPorts, vector<VuoPort *>(),
4446 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4447 indexOfParameter, indexOfEventParameter, constantsCache);
4451 Type *instanceDataType,
4454 map<VuoPort *, size_t> indexOfParameter;
4455 map<VuoPort *, size_t> indexOfEventParameter;
4456 return getNodeFunction(module, moduleKey,
"nodeInstanceTriggerStop",
true,
true,
false,
false, instanceDataType, vector<VuoPort *>(), vector<VuoPort *>(),
4457 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4458 indexOfParameter, indexOfEventParameter, constantsCache);
4462 Type *instanceDataType,
4463 const vector<VuoPort *> &modelInputPorts,
4464 map<VuoPort *, size_t> &indexOfParameter,
4467 map<VuoPort *, size_t> indexOfEventParameter;
4468 return getNodeFunction(module, moduleKey,
"nodeInstanceTriggerUpdate",
true,
true,
false,
false, instanceDataType, modelInputPorts, vector<VuoPort *>(),
4469 map<VuoPort *, json_object *>(), map<VuoPort *, string>(), map<VuoPort *, string>(), map<VuoPort *, VuoPortClass::EventBlocking>(),
4470 indexOfParameter, indexOfEventParameter, constantsCache);
4474 Type *instanceDataType,
4475 const vector<VuoPort *> &modelInputPorts,
4476 const vector<VuoPort *> &modelOutputPorts,
4477 const map<VuoPort *, json_object *> &detailsForPorts,
4478 const map<VuoPort *, string> &displayNamesForPorts,
4479 const map<VuoPort *, string> &defaultValuesForInputPorts,
4480 const map<VuoPort *, VuoPortClass::EventBlocking> &eventBlockingForInputPorts,
4481 map<VuoPort *, size_t> &indexOfParameter,
4482 map<VuoPort *, size_t> &indexOfEventParameter,
4485 string functionName = (isStateful ?
"nodeInstanceEvent" :
"nodeEvent");
4486 return getNodeFunction(module, moduleKey, functionName, isSubcomposition, isStateful,
false,
true, instanceDataType, modelInputPorts, modelOutputPorts,
4487 detailsForPorts, displayNamesForPorts, defaultValuesForInputPorts, eventBlockingForInputPorts,
4488 indexOfParameter, indexOfEventParameter, constantsCache);
4491 Function * VuoCompilerCodeGenUtilities::getNodeFunction(Module *module,
string moduleKey,
string functionName,
4492 bool hasCompositionStateArg,
bool hasInstanceDataArg,
4493 bool hasInstanceDataReturn,
bool hasEventArgs,
4494 Type *instanceDataType,
4495 const vector<VuoPort *> &modelInputPorts,
const vector<VuoPort *> &modelOutputPorts,
4496 const map<VuoPort *, json_object *> &detailsForPorts,
4497 const map<VuoPort *, string> &displayNamesForPorts,
4498 const map<VuoPort *, string> &defaultValuesForInputPorts,
4499 const map<VuoPort *, VuoPortClass::EventBlocking> &eventBlockingForInputPorts,
4500 map<VuoPort *, size_t> &indexOfParameter,
4501 map<VuoPort *, size_t> &indexOfEventParameter,
4504 if (! moduleKey.empty())
4506 Function *
function = module->getFunction(functionName.c_str());
4510 vector<Type *> functionParams;
4511 AttributeList functionAttributes;
4512 map<VuoPort *, bool> hasSecondParam;
4513 Type *boolType = IntegerType::get(module->getContext(), 1);
4514 size_t indexInEventFunction = 0;
4516 if (hasCompositionStateArg)
4519 functionParams.push_back(pointerToCompositionState);
4520 indexInEventFunction++;
4523 if (hasInstanceDataArg)
4525 functionParams.push_back( PointerType::get(instanceDataType, 0) );
4526 indexInEventFunction++;
4529 for (vector<VuoPort *>::const_iterator i = modelInputPorts.begin(); i != modelInputPorts.end(); ++i)
4539 functionParams.insert(functionParams.end(), paramTypes.begin(), paramTypes.end());
4541 for (
size_t j = 0; j < paramTypes.size(); ++j)
4542 functionAttributes = functionAttributes.addParamAttributes(module->getContext(), functionParams.size() - 1, typeFunctionAttributes.getParamAttributes(j));
4544 indexOfParameter[modelInputPort->
getBase()] = indexInEventFunction;
4545 indexInEventFunction += paramTypes.size();
4547 hasSecondParam[*i] = paramTypes.size() > 1;
4551 functionParams.push_back(boolType);
4553 indexOfEventParameter[modelInputPort->
getBase()] = indexInEventFunction++;
4556 else if (hasEventArgs)
4558 functionParams.push_back(boolType);
4560 indexOfParameter[modelInputPort->
getBase()] = indexInEventFunction++;
4564 for (vector<VuoPort *>::const_iterator i = modelOutputPorts.begin(); i != modelOutputPorts.end(); ++i)
4572 PointerType *triggerFunctionPointerType = PointerType::get(functionType, 0);
4573 functionParams.push_back(triggerFunctionPointerType);
4575 indexOfParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4582 functionParams.push_back(paramType);
4584 indexOfParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4588 PointerType *eventParamType = PointerType::get( boolType, 0 );
4589 functionParams.push_back(eventParamType);
4591 indexOfEventParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4594 else if (hasEventArgs)
4596 PointerType *paramType = PointerType::get( boolType, 0 );
4597 functionParams.push_back(paramType);
4599 indexOfParameter[modelOutputPort->
getBase()] = indexInEventFunction++;
4604 Type *returnType = (hasInstanceDataReturn ? instanceDataType : Type::getVoidTy(module->getContext()));
4605 FunctionType *functionType = FunctionType::get(returnType, functionParams,
false);
4606 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4607 function->setAttributes(functionAttributes);
4609 set<string> argNamesUsed;
4611 BasicBlock *block = BasicBlock::Create(module->getContext(),
"",
function, 0);
4612 Function::arg_iterator argIter =
function->arg_begin();
4614 if (hasCompositionStateArg)
4616 Value *arg = argIter++;
4617 string argName =
"compositionState";
4618 arg->setName(argName);
4619 argNamesUsed.insert(argName);
4622 if (hasInstanceDataArg)
4624 Value *arg = argIter++;
4625 string argName =
"instanceData";
4626 arg->setName(argName);
4627 argNamesUsed.insert(argName);
4631 argNamesUsed.insert(
"refresh");
4633 map<VuoPort *, string> primaryArgNames;
4634 auto recordUniqueArgName = [&primaryArgNames, &argNamesUsed] (
VuoPort *modelPort)
4637 primaryArgNames[modelPort] = argName;
4639 std::for_each(modelInputPorts.begin(), modelInputPorts.end(), recordUniqueArgName);
4640 std::for_each(modelOutputPorts.begin(), modelOutputPorts.end(), recordUniqueArgName);
4642 for (vector<VuoPort *>::const_iterator i = modelInputPorts.begin(); i != modelInputPorts.end(); ++i)
4647 if (type || hasEventArgs)
4649 Value *arg = argIter++;
4652 string argName = primaryArgNames[modelInputPort];
4653 arg->setName(argName);
4655 map<VuoPort *, VuoPortClass::EventBlocking>::const_iterator eventBlockingIter = eventBlockingForInputPorts.find(modelInputPort);
4656 bool hasNonDefaultEventBlocking = (eventBlockingIter != eventBlockingForInputPorts.end() && eventBlockingIter->second !=
VuoPortClass::EventBlocking_None);
4660 map<VuoPort *, json_object *>::const_iterator detailsIter = detailsForPorts.find(modelInputPort);
4661 if (detailsIter != detailsForPorts.end())
4663 json_object_object_foreach(detailsIter->second, key, val)
4665 json_object_object_add(details, key, val);
4666 json_object_get(val);
4669 map<VuoPort *, string>::const_iterator displayNameIter = displayNamesForPorts.find(modelInputPort);
4670 if (displayNameIter != displayNamesForPorts.end())
4671 json_object_object_add(details,
"name", json_object_new_string(displayNameIter->second.c_str()));
4678 map<VuoPort *, string>::const_iterator defaultValueIter = defaultValuesForInputPorts.find(modelInputPort);
4679 if (defaultValueIter != defaultValuesForInputPorts.end())
4680 json_object_object_add(details,
"default", json_tokener_parse(defaultValueIter->second.c_str()));
4682 if (hasSecondParam[modelInputPort])
4684 Value *secondArg = argIter++;
4685 secondArg->setName(argName +
".1");
4690 Value *eventArg = argIter++;
4692 string preferredEventArgName = portName +
"Event";
4694 eventArg->setName(eventArgName);
4698 json_object *eventDetails = json_object_new_object();
4699 json_object_object_add(eventDetails,
"data", json_object_new_string(argName.c_str()));
4700 if (hasNonDefaultEventBlocking)
4701 json_object_object_add(eventDetails,
"eventBlocking", json_object_new_string(eventBlockingStr.c_str()));
4702 string eventDetailsStr = json_object_to_json_string_ext(eventDetails, JSON_C_TO_STRING_PLAIN);
4703 json_object_put(eventDetails);
4704 generateAnnotation(module, block, eventArg,
"vuoDetails:" + eventDetailsStr,
"", 0, constantsCache);
4707 else if (hasEventArgs)
4711 if (hasNonDefaultEventBlocking)
4712 json_object_object_add(details,
"eventBlocking", json_object_new_string(eventBlockingStr.c_str()));
4715 string detailsStr = json_object_to_json_string_ext(details, JSON_C_TO_STRING_PLAIN);
4716 json_object_put(details);
4717 generateAnnotation(module, block, arg,
"vuoDetails:" + detailsStr,
"", 0, constantsCache);
4721 for (vector<VuoPort *>::const_iterator i = modelOutputPorts.begin(); i != modelOutputPorts.end(); ++i)
4723 VuoPort *modelOutputPort = *i;
4725 Value *arg = argIter++;
4728 string argName = primaryArgNames[modelOutputPort];
4729 arg->setName(argName);
4732 map<VuoPort *, json_object *>::const_iterator detailsIter = detailsForPorts.find(modelOutputPort);
4733 if (detailsIter != detailsForPorts.end())
4735 json_object_object_foreach(detailsIter->second, key, val)
4737 json_object_object_add(details, key, val);
4738 json_object_get(val);
4741 map<VuoPort *, string>::const_iterator displayNameIter = displayNamesForPorts.find(modelOutputPort);
4742 if (displayNameIter != displayNamesForPorts.end())
4743 json_object_object_add(details,
"name", json_object_new_string(displayNameIter->second.c_str()));
4744 string detailsStr = json_object_to_json_string_ext(details, JSON_C_TO_STRING_PLAIN);
4745 json_object_put(details);
4746 generateAnnotation(module, block, arg,
"vuoDetails:" + detailsStr,
"", 0, constantsCache);
4751 generateAnnotation(module, block, arg,
"vuoOutputTrigger:" + argName,
"", 0, constantsCache);
4763 Value *eventArg = argIter++;
4765 string preferredEventArgName = portName +
"Event";
4767 eventArg->setName(eventArgName);
4769 generateAnnotation(module, block, eventArg,
"vuoOutputEvent",
"", 0, constantsCache);
4771 json_object *eventDetails = json_object_new_object();
4772 json_object_object_add(eventDetails,
"data", json_object_new_string(argName.c_str()));
4773 string eventDetailsStr = json_object_to_json_string_ext(eventDetails, JSON_C_TO_STRING_PLAIN);
4774 json_object_put(eventDetails);
4775 generateAnnotation(module, block, eventArg,
"vuoDetails:" + eventDetailsStr,
"", 0, constantsCache);
4778 else if (hasEventArgs)
4789 Function * VuoCompilerCodeGenUtilities::getVuoRegisterFunction(Module *module)
4791 const char *functionName =
"VuoRegisterF";
4792 Function *
function = module->getFunction(functionName);
4795 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4796 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4797 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4799 FunctionType *deallocateFunctionType = FunctionType::get(Type::getVoidTy(module->getContext()), voidPointerType,
false);
4800 PointerType *deallocateFunctionPointerType = PointerType::get(deallocateFunctionType, 0);
4802 vector<Type *> functionParams;
4803 functionParams.push_back(voidPointerType);
4804 functionParams.push_back(deallocateFunctionPointerType);
4805 functionParams.push_back(pointerToCharType);
4806 functionParams.push_back(intType);
4807 functionParams.push_back(pointerToCharType);
4808 functionParams.push_back(pointerToCharType);
4809 FunctionType *functionType = FunctionType::get(intType, functionParams,
false);
4810 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4815 Function * VuoCompilerCodeGenUtilities::getVuoRetainFunction(Module *module)
4817 const char *functionName =
"VuoRetain";
4818 Function *
function = module->getFunction(functionName);
4821 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4822 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4824 vector<Type *> functionParams;
4825 functionParams.push_back(voidPointerType);
4826 FunctionType *functionType = FunctionType::get(intType, functionParams,
false);
4827 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4832 Function * VuoCompilerCodeGenUtilities::getVuoReleaseFunction(Module *module)
4834 const char *functionName =
"VuoRelease";
4835 Function *
function = module->getFunction(functionName);
4838 PointerType *voidPointerType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4839 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4841 vector<Type *> functionParams;
4842 functionParams.push_back(voidPointerType);
4843 FunctionType *functionType = FunctionType::get(intType, functionParams,
false);
4844 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4851 string functionName =
"compositionGetPortValue";
4852 string moduleKey = module->getModuleIdentifier();
4853 if (! moduleKey.empty())
4855 Function *
function = module->getFunction(functionName.c_str());
4859 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4860 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4862 vector<Type *> functionParams;
4863 functionParams.push_back(pointerToCompositionState);
4864 functionParams.push_back(pointerToCharType);
4865 functionParams.push_back(intType);
4866 functionParams.push_back(intType);
4867 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
4868 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4875 string functionName =
"compositionSetPortValue";
4876 string moduleKey = module->getModuleIdentifier();
4877 if (! moduleKey.empty())
4879 Function *
function = module->getFunction(functionName.c_str());
4883 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4884 Type *boolType = IntegerType::get(module->getContext(), 32);
4886 vector<Type *> functionParams;
4887 functionParams.push_back(pointerToCompositionState);
4888 functionParams.push_back(pointerToCharType);
4889 functionParams.push_back(pointerToCharType);
4890 functionParams.push_back(boolType);
4891 functionParams.push_back(boolType);
4892 functionParams.push_back(boolType);
4893 functionParams.push_back(boolType);
4894 functionParams.push_back(boolType);
4895 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4896 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4903 string functionName =
"compositionFireTriggerPortEvent";
4904 string moduleKey = module->getModuleIdentifier();
4905 if (! moduleKey.empty())
4907 Function *
function = module->getFunction(functionName.c_str());
4911 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4913 vector<Type *> functionParams;
4914 functionParams.push_back(pointerToCompositionState);
4915 functionParams.push_back(pointerToCharType);
4916 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4917 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4924 const char *functionName =
"vuoSetInputPortValue";
4925 Function *
function = module->getFunction(functionName);
4928 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4930 vector<Type *> functionParams;
4931 functionParams.push_back(pointerToCharType);
4932 functionParams.push_back(pointerToCharType);
4933 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4934 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4941 const char *functionName =
"getPublishedInputPortValue";
4942 Function *
function = module->getFunction(functionName);
4945 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4946 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4948 vector<Type *> functionParams;
4949 functionParams.push_back(pointerToCharType);
4950 functionParams.push_back(intType);
4951 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
4952 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4959 const char *functionName =
"getPublishedOutputPortValue";
4960 Function *
function = module->getFunction(functionName);
4963 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4964 IntegerType *intType = IntegerType::get(module->getContext(), 32);
4966 vector<Type *> functionParams;
4967 functionParams.push_back(pointerToCharType);
4968 functionParams.push_back(intType);
4969 FunctionType *functionType = FunctionType::get(pointerToCharType, functionParams,
false);
4970 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
4977 string functionName =
"compositionSetPublishedInputPortValue";
4978 string moduleKey = module->getModuleIdentifier();
4979 if (! moduleKey.empty())
4981 Function *
function = module->getFunction(functionName.c_str());
4985 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
4986 Type *boolType = IntegerType::get(module->getContext(), 64);
4988 vector<Type *> functionParams;
4989 functionParams.push_back(pointerToCompositionState);
4990 functionParams.push_back(pointerToCharType);
4991 functionParams.push_back(pointerToCharType);
4992 functionParams.push_back(boolType);
4993 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
4994 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
5001 const char *functionName =
"setPublishedInputPortValue";
5002 Function *
function = module->getFunction(functionName);
5005 PointerType *pointerToCharType = PointerType::get(IntegerType::get(module->getContext(), 8), 0);
5007 vector<Type *> functionParams;
5008 functionParams.push_back(pointerToCharType);
5009 functionParams.push_back(pointerToCharType);
5010 FunctionType *functionType = FunctionType::get(Type::getVoidTy(module->getContext()), functionParams,
false);
5011 function = Function::Create(functionType, GlobalValue::ExternalLinkage, functionName, module);
5022 if (type->isPointerTy())
5024 Type *elementType = cast<PointerType>(type)->getElementType();
5025 if (elementType->isStructTy())
5028 *structType = cast<StructType>(elementType);
5042 PointerType *pointerToReturnType =
static_cast<PointerType *
>(
function->getFunctionType()->getParamType(0));
5043 Type *returnType = pointerToReturnType->getElementType();
5044 Value *returnVariable =
new AllocaInst(returnType, 0,
"", block);
5045 args.insert(args.begin(), returnVariable);
5046 CallInst::Create(
function, args,
"", block);
5047 return returnVariable;
5056 AttributeList functionAttrs =
function->getAttributes();
5057 AttributeSet paramAttrs = functionAttrs.getParamAttributes(0);
5058 return paramAttrs.hasAttribute(Attribute::StructRet);
5066 AttributeList srcAttributes = srcFunction->getAttributes();
5067 for (
int i = 0; i < srcFunction->getFunctionType()->getNumParams(); ++i)
5068 dstFunction->addParamAttrs(i, srcAttributes.getParamAttributes(i));
5076 copyParameterAttributes(module, srcFunction->getAttributes(), 0, srcFunction->getFunctionType()->getNumParams(), dstCall, 0);
5083 const AttributeList &srcAttributes,
size_t srcStartParam,
size_t srcNumParams,
5084 Function *dstFunction,
size_t dstStartParam)
5086 AttributeList dstAttributes = dstFunction->getAttributes();
5087 for (
size_t i = 0; i < srcNumParams; ++i)
5089 size_t srcIndex = srcStartParam + i;
5090 size_t dstIndex = dstStartParam + i;
5091 dstAttributes = dstAttributes.addParamAttributes(module->getContext(), dstIndex, srcAttributes.getParamAttributes(srcIndex));
5093 dstFunction->setAttributes(dstAttributes);
5100 const AttributeList &srcAttributes,
size_t srcStartParam,
size_t srcNumParams,
5101 CallInst *dstCall,
size_t dstStartParam)
5103 AttributeList dstAttributes = dstCall->getAttributes();
5104 for (
size_t i = 0; i < srcNumParams; ++i)
5106 size_t srcIndex = srcStartParam + i;
5107 size_t dstIndex = dstStartParam + i;
5108 dstAttributes = dstAttributes.addParamAttributes(module->getContext(), dstIndex, srcAttributes.getParamAttributes(srcIndex));
5110 dstCall->setAttributes(dstAttributes);
5119 vector<Type *> params;
5124 return FunctionType::get(Type::getVoidTy(module->getContext()), params,
false);
5132 Value *argValue = NULL;
5134 Function::arg_iterator args =
function->arg_begin();
5135 for (
size_t i = 0; i <= index && i <
function->arg_size(); ++i)