protected override TestResult HandleCompilerException(ITestExecutionContext context, MethodInfo methodInfo) { var arguments = GetArgumentsArray(_originalMethod); Type[] nativeArgTypes = new Type[arguments.Length]; for (var i = 0; i < arguments.Length; ++i) { nativeArgTypes[i] = arguments[i].GetType(); } bool isInRegistry; Func <object, object[], object> caller; var delegateType = CreateNativeDelegateType(methodInfo.ReturnType, nativeArgTypes, out isInRegistry, out caller); var functionDelegate = Delegate.CreateDelegate(delegateType, methodInfo); Delegate compiledFunction = BurstCompiler.CompileDelegate(functionDelegate); if (functionDelegate == compiledFunction) { context.CurrentResult.SetResult(ResultState.Success); } else { context.CurrentResult.SetResult(ResultState.Failure, $"The function have been compiled successfully, but an error was expected."); } return(context.CurrentResult); }
protected override Delegate CompileDelegate(ITestExecutionContext context, MethodInfo methodInfo, Type delegateType) { var functionDelegate = Delegate.CreateDelegate(delegateType, methodInfo); var compiledFunction = BurstCompiler.CompileDelegate(functionDelegate); return(compiledFunction); }
/// <summary> /// don't ask me why it's so complicated, I am hacking here. Use at your risk. /// </summary> /// <param name="action"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T ConvertBurstMethodToDelegate <T>(T action) where T : MulticastDelegate { var delegateType = DelegateHelper.NewDelegateType(action.Method.ReturnType, typeof(T).GetGenericArguments()); var functionDelegate = Delegate.CreateDelegate(delegateType, action.Method); var o = BurstCompiler.CompileDelegate(functionDelegate); var compile = DelegateCompiler.Compile <T>(o.Method); return(compile); }
protected unsafe override Delegate CompileDelegate(ITestExecutionContext context, MethodInfo methodInfo, Type delegateType, byte *returnBox, out Type returnBoxType) { returnBoxType = null; var functionDelegate = Delegate.CreateDelegate(delegateType, methodInfo); var compiledFunction = BurstCompiler.CompileDelegate(functionDelegate); return(compiledFunction); }