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)); }
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); }
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); }
public static FLInstruction Initialize(this SerializableFLInstruction instruction, FLProgram script, FLInstructionSet instructionSet) { FLInstruction i = instructionSet.Create(script, instruction); return(i); }
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)); }
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 })); }
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); }
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." ); } }
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); }
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); } }
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); }
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);
public FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction) { return(GetCreator(instruction).Create(script, func, instruction)); }
protected abstract bool AppliesOnInstruction(SerializableFLInstruction instr);
public virtual string GetArgumentSignatureForInstruction(SerializableFLInstruction instruction) { return(null); }
public override string GetArgumentSignatureForInstruction(SerializableFLInstruction instruction) { return(argumentSignature); }
public abstract FLInstruction Create(FLProgram script, SerializableFLInstruction instruction);
protected override bool AppliesOnInstruction(SerializableFLInstruction instr) { return(InvalidInstructions.Contains(instr.InstructionKey)); }