예제 #1
0
        public override string GetArgumentSignatureForInstruction(SerializableFLInstruction instruction)
        {
            if (!KernelList.TryGetClKernel(instruction.InstructionKey, out CLKernel kernel))
            {
                return(null);
            }

            char[] arg = new char[kernel.Parameter.Count - KernelFLInstruction.FL_HEADER_ARG_COUNT];
            foreach (KeyValuePair <string, KernelParameter> kernelParameter in kernel.Parameter)
            {
                if (kernelParameter.Value.Id < KernelFLInstruction.FL_HEADER_ARG_COUNT)
                {
                    continue;
                }

                if (kernelParameter.Value.IsArray)
                {
                    arg[kernelParameter.Value.Id - KernelFLInstruction.FL_HEADER_ARG_COUNT] = 'E';
                }
                else
                {
                    arg[kernelParameter.Value.Id - KernelFLInstruction.FL_HEADER_ARG_COUNT] = 'V';
                }
            }

            return(new string(arg));
        }
예제 #2
0
        public override object Process(object o)
        {
            SerializableFLProgram input = (SerializableFLProgram)o;

            foreach (SerializableFLFunction serializableFlFunction in input.Functions)
            {
                for (int i = 0; i < serializableFlFunction.Instructions.Count; i++)
                {
                    SerializableFLInstruction serializableFlInstruction = serializableFlFunction.Instructions[i];
                    if (serializableFlInstruction.InstructionKey == "urnd" ||
                        serializableFlInstruction.InstructionKey == "rnd")
                    {
                        if (serializableFlInstruction.Arguments.Count == 0)
                        {
                            serializableFlFunction.Instructions[i] = new SerializableFLInstruction(
                                serializableFlInstruction.InstructionKey + "_gpu",
                                new List <SerializableFLInstructionArgument>());
                            Logger.Log(LogType.Log, "Weaved: " + serializableFlFunction.Instructions[i], 2);
                        }
                        else
                        {
                            Logger.Log(LogType.Log, "Can not Weave random instruction with arguments.", 1);
                        }
                    }
                }
            }

            return(input);
        }
예제 #3
0
        public override object Process(object o)
        {
            SerializableFLProgram input = (SerializableFLProgram)o;
            bool removedOne             = true;

            while (removedOne)
            {
                removedOne = false;
                foreach (SerializableFLFunction f in input.Functions)
                {
                    for (int i = f.Instructions.Count - 1; i >= 0; i--)
                    {
                        SerializableFLInstruction t = f.Instructions[i];
                        if (t.InstructionKey == "jmp" &&
                            t.Arguments[0].ArgumentCategory == InstructionArgumentCategory.Function)
                        {
                            string fname = t.Arguments[0].Identifier;
                            SerializableFLFunction func = input.Functions.First(x => x.Name == fname);
                            f.Instructions.RemoveAt(i);
                            f.Instructions.AddRange(func.Instructions);
                            removedOne = true;
                        }
                    }
                }
            }
            return(input);
        }
예제 #4
0
        public static FLInstruction Initialize(this SerializableFLInstruction instruction, FLProgram script,
                                               FLInstructionSet instructionSet)
        {
            FLInstruction i = instructionSet.Create(script, instruction);

            return(i);
        }
예제 #5
0
        public override FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction)
        {
            List <FLInstructionArgument> args = new List <FLInstructionArgument>();

            for (int i = 0; i < instruction.Arguments.Count; i++)
            {
                FLInstructionArgument arg = new FLInstructionArgument(instruction.Arguments[i].GetValue(script, func));
                args.Add(arg);
            }

            return(new GPUArrangeFLInstruction(args, ArrangeKernel));
        }
예제 #6
0
        public override FLInstruction Create(FLProgram script, SerializableFLInstruction instruction)
        {
            List <FLInstructionArgument> args = new List <FLInstructionArgument>();

            for (int i = 0; i < instruction.Arguments.Count; i++)
            {
                FLInstructionArgument arg = new FLInstructionArgument(instruction.Arguments[i].GetValue(script));
                args.Add(arg);
            }

            return((FLInstruction)Activator.CreateInstance(type, new object[] { args }));
        }
예제 #7
0
        public FLInstructionCreator GetCreator(SerializableFLInstruction instruction)
        {
            for (int i = 0; i < creators.Count; i++)
            {
                if (creators[i].IsInstruction(instruction.InstructionKey))
                {
                    return(creators[i]);
                }
            }

            throw new FLInstructionCreatorNotFoundException("Could not find Instruction creator for Key: " +
                                                            instruction.InstructionKey);
        }
예제 #8
0
 public override FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction)
 {
     return(new KernelFLInstruction(
                KernelParameter.GetDataMaxSize(KernelList.GenDataType),
                KernelList.GetClKernel(instruction.InstructionKey),
                instruction.Arguments.Select(
                    x => new FLInstructionArgument(
                        x.GetValue(
                            script,
                            func
                            )
                        )
                    ).ToList()
                ));
 }
        protected override void Validate(
            SerializableFLProgram prog, SerializableFLFunction func,
            SerializableFLInstruction inst, SerializableFLInstructionArgument arg)
        {
            FLExecutableElementModifiers calledFunc =
                prog.Functions.FirstOrDefault(x => x.Name == arg.Identifier)?.Modifiers ??
                prog.ExternalFunctions.First(x => x.Name == arg.Identifier).Modifiers;

            if (calledFunc.NoCall)
            {
                throw new FLInvalidFLElementModifierUseException(
                          func.Name,
                          FLKeywords.NoCallKeyword,
                          $"Can not use instruction {inst.InstructionKey} with a Defined Function that is marked with the nocall modifier."
                          );
            }
        }
예제 #10
0
        private List <SerializableFLInstruction> ParseInstructions(List <StaticFunction> functionHeaders,
                                                                   string[] definedBuffers,
                                                                   string[] definedScripts,
                                                                   StaticInstruction[] functionBody)
        {
            List <SerializableFLInstruction> instructions = new List <SerializableFLInstruction>();

            for (int i = 0; i < functionBody.Length; i++)
            {
                SerializableFLInstruction inst =
                    ParseInstruction(functionHeaders, definedBuffers, definedScripts, functionBody[i]);
                if (inst != null)
                {
                    instructions.Add(inst);
                }
            }

            return(instructions);
        }
예제 #11
0
        public override void Serialize(PrimitiveValueWrapper s, object input)
        {
            SerializableFLInstruction obj = (SerializableFLInstruction)input;

            s.Write(ResolveName(obj.InstructionKey));
            s.Write(obj.Arguments.Count);

            for (int i = 0; i < obj.Arguments.Count; i++)
            {
                MemoryStream temp = new MemoryStream();
                if (!argSerializer.TryWritePacket(temp, obj.Arguments[i]))
                {
                    throw new FLSerializationException("Can not serialize Serializable Argument: " +
                                                       obj.Arguments[i].GetType());
                }

                s.Write(temp.GetBuffer(), (int)temp.Position);
            }
        }
예제 #12
0
        private List <SerializableFLInstruction> ParseInstructions(
            List <StaticFunction> functionHeaders,
            DefineStatement[] definedBuffers,
            DefineStatement[] definedScripts,
            StaticFunction currentFunction)
        {
            List <SerializableFLInstruction> instructions = new List <SerializableFLInstruction>();

            for (int i = 0; i < currentFunction.Body.Length; i++)
            {
                SerializableFLInstruction inst =
                    ParseInstruction(functionHeaders, definedBuffers, definedScripts, currentFunction, i);
                if (inst != null)
                {
                    instructions.Add(inst);
                }
            }

            return(instructions);
        }
예제 #13
0
        protected override void Validate(
            SerializableFLProgram prog, SerializableFLFunction func,
            SerializableFLInstruction inst, SerializableFLInstructionArgument arg)
        {
            SerializableFLBuffer buf = prog.DefinedBuffers.First(x => x.Name == arg.Identifier);

            if (buf.Modifiers.IsReadOnly)
            {
                throw new FLInvalidFLElementModifierUseException(
                          func.Name,
                          FLKeywords.ReadOnlyBufferModifier,
                          $"Can not use instruction {inst.InstructionKey} with a static buffer."
                          );
            }

            if (buf.Modifiers.IsArray)
            {
                throw new FLInvalidFLElementModifierUseException(
                          func.Name,
                          FLKeywords.ArrayKey,
                          $"Can not use instruction {inst.InstructionKey} with an array buffer."
                          );
            }
        }
 protected abstract void Validate(
     SerializableFLProgram prog, SerializableFLFunction func,
     SerializableFLInstruction inst, SerializableFLInstructionArgument arg);
예제 #15
0
 public FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction)
 {
     return(GetCreator(instruction).Create(script, func, instruction));
 }
 protected abstract bool AppliesOnInstruction(SerializableFLInstruction instr);
예제 #17
0
 public virtual string GetArgumentSignatureForInstruction(SerializableFLInstruction instruction)
 {
     return(null);
 }
예제 #18
0
 public override string GetArgumentSignatureForInstruction(SerializableFLInstruction instruction)
 {
     return(argumentSignature);
 }
예제 #19
0
 public abstract FLInstruction Create(FLProgram script, SerializableFLInstruction instruction);
예제 #20
0
 protected override bool AppliesOnInstruction(SerializableFLInstruction instr)
 {
     return(InvalidInstructions.Contains(instr.InstructionKey));
 }