예제 #1
0
        public string CompleteSource(ILSource source)
        {
            var linked = new List <ILCode>();

            source.Complete(linked);

            var builder = new StringBuilder();

            foreach (var code in linked.OfType <ILStruct>().Reverse())
            {
                var signature = code.Signature;

                builder.AppendLine($"{signature};");
            }

            foreach (var signature in linked.OfType <ILSource>().Select(l => l.Signature))
            {
                builder.AppendLine($"{signature};");
            }

            foreach (var code in linked.Select(l => l.Source))
            {
                builder.AppendLine($"{code}");
            }

            return(builder.ToString());
        }
예제 #2
0
        public T Compile <T>(MethodInfo info) where T : ILSource, new()
        {
            var source = Code.OfType <T>().FirstOrDefault(
                s => s.Info.Equals(info)
                );

            source ??= ILSource.Compile <T>(info, this);

            if (!Code.Contains(source))
            {
                Code.Add(source);
            }

            return(source);
        }
예제 #3
0
        private void KernelInvoker(ILSource source, UIntPtr[] parameters, Kernel kernel, uint workers)
        {
            var values = new List <KernelArgument>();

            var method = source.Info;

            var types = method.GetParameters();

            for (var index = 0; index < parameters.Length; index++)
            {
                var parameter = parameters[index];
                var info      = types[index].ParameterType;

                if (info.IsArray)
                {
                    values.Add(new KernelArgument
                    {
                        Size  = 8,
                        Value = parameter
                    });

                    continue;
                }

                values.Add(new KernelArgument
                {
                    Size  = (uint)Marshal.SizeOf(info),
                    Value = parameter
                });
            }

            lock (kernel)
            {
                kernel.Invoke(workers, values.ToArray());
            }
        }