Exemplo n.º 1
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            SerializableFLProgram prog = FLSerializer.LoadProgram(stream, runner.InstructionSet);

            progressIndicator?.SetProgress($"[{UnpackerName}]Running FL Program: {name}", 2, 3);
            FLProgram p = runner.Run(prog, 512, 512, 1);

            string filePath = Path.Combine(
                targetDir,
                name.Replace("/", "\\").StartsWith("\\")
                                               ? name.Replace("/", "\\").Substring(1)
                                               : name.Replace("/", "\\")
                );

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            filePath = filePath.Remove(filePath.Length - 3, 3) + "png";

            progressIndicator?.SetProgress(
                $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                3,
                3
                );
            Bitmap bmp = new Bitmap(512, 512);

            CLAPI.UpdateBitmap(runner.Instance, bmp, p.GetActiveBuffer(false).Buffer);
            bmp.Save(filePath);
            stream.Close();
            p.FreeResources();
            progressIndicator?.Dispose();
        }
Exemplo n.º 2
0
        public static string RunProgramDeserializationBenchmark(string testAdd, List <string> files, int iterations,
                                                                string performanceFolder = "performance", Type[] checkPipeline = null, bool useMultiThreading = false,
                                                                int workSizeMultiplier   = 2)
        {
            FLSetup setup = new FLSetup("FL_DeserializationProcess_Performance" + testAdd, "resources/kernel", performanceFolder,
                                        checkPipeline, useMultiThreading, workSizeMultiplier);


            StringBuilder logOut = new StringBuilder($"Performance Tests: {DateTime.Now:HH:mm:ss}\n");

            MemoryStream dst = new MemoryStream();

            for (int i = 0; i < files.Count; i++)
            {
                SerializableFLProgram pr = setup.Parser.Process(new FLParserInput(files[i]));
                string key = "ProgramDeserializationPerformance+" + Path.GetFileNameWithoutExtension(files[i]) + "." +
                             i;
                FLSerializer.SaveProgram(dst, pr, setup.InstructionSet, new string[] { });
                Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1);

                PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations,
                                                                                              (int its) => dst.Position = 0,
                                                                                              (int its) => FLSerializer.LoadProgram(dst, setup.InstructionSet),
                                                                                              null);
                logOut.AppendLine("\t" + result);
                Logger.Log(LogType.Log, $"------------------------Run {key} Finished------------------------", 1);
                setup.WriteResult(result);
            }

            dst.Dispose();
            logOut.AppendLine();
            setup.WriteLog(logOut.ToString());
            setup.Dispose();
            return(logOut.ToString());
        }
Exemplo n.º 3
0
        protected FLProgram Process(FlScriptExecutionContext context)
        {
            FLBuffer input = new FLBuffer(
                Instance,
                context.Input,
                context.Width,
                context.Height,
                context.Depth,
                context.Filename
                );

            FLProgram program;

            if (context.IsCompiled)
            {
                Stream s = IOManager.GetStream(context.Filename);
                program = FLSerializer.LoadProgram(s, InstructionSet).Initialize(Instance, InstructionSet);
                s.Close();
            }
            else
            {
                program = Parser.Process(new FLParserInput(context.Filename)).Initialize(Instance, InstructionSet);
            }

            program.Run(input, true);

            return(program);
        }
Exemplo n.º 4
0
 protected SerializableFLProgram Load(string input)
 {
     using (Stream s = File.OpenRead(input))
     {
         return(FLSerializer.LoadProgram(s, FLData.Container.InstructionSet));
     }
 }
Exemplo n.º 5
0
 protected void Save(string path, SerializableFLProgram prog, string[] extraSteps)
 {
     using (Stream s = File.Create(path))
     {
         FLSerializer.SaveProgram(s, prog, FLData.Container.InstructionSet, extraSteps);
     }
 }
Exemplo n.º 6
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            SerializableFLProgram prog = runner.Parser.Process(new FLParserInput(name));

            string filePath = Path.Combine(
                targetDir,
                name.Replace("/", "\\").StartsWith("\\")
                                               ? name.Replace("/", "\\").Substring(1)
                                               : name.Replace("/", "\\")
                );

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            filePath = filePath + "c";

            progressIndicator?.SetProgress(
                $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                3,
                3
                );
            Stream s = File.OpenWrite(filePath);

            FLSerializer.SaveProgram(s, prog, runner.InstructionSet, new string[0]);
            s.Dispose();
            progressIndicator?.Dispose();
        }
Exemplo n.º 7
0
        public static string RunDeserializedFLExecutionBenchmark(string testAdd, List <string> files, int iterations,
                                                                 string performanceFolder = "performance", Type[] checkPipeline = null, bool useMultiThreading = false,
                                                                 int workSizeMultiplier   = 2)
        {
            FLSetup setup = new FLSetup("FL_DeserializedExecution_Performance" + testAdd, "resources/kernel", performanceFolder,
                                        checkPipeline, useMultiThreading, workSizeMultiplier);
            StringBuilder logOut = new StringBuilder($"Performance Tests: {DateTime.Now:HH:mm:ss}\n");

            for (int i = 0; i < files.Count; i++)
            {
                Bitmap   bmp = null;
                FLBuffer buf = null;
                SerializableFLProgram parsedProgram = null;
                MemoryStream          ms            = new MemoryStream();
                FLProgram             program       = null;
                string key = "FLDeserializedExecutionPerformance+" + Path.GetFileNameWithoutExtension(files[i]) + "." +
                             i;

                Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1);

                parsedProgram = setup.Parser.Process(new FLParserInput(files[i]));
                FLSerializer.SaveProgram(ms, parsedProgram, setup.InstructionSet, new string[0]);

                ms.Position   = 0;
                parsedProgram = FLSerializer.LoadProgram(ms, setup.InstructionSet);

                ms.Dispose();
                PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations,
                                                                                              (int its) => //BeforeTest
                {
                    bmp     = new Bitmap(BITMAP_RESOLUTION, BITMAP_RESOLUTION);
                    buf     = new FLBuffer(CLAPI.MainThread, bmp, files[i]);
                    program = parsedProgram.Initialize(setup.InstructionSet);
                },
                                                                                              (int its) => program.Run(CLAPI.MainThread, buf, true),
                                                                                              (int its) => //After Test
                {
                    if (its == iterations - 1)
                    {
                        SaveOutput("deserialized-output", bmp, program, setup, files[i]);
                    }

                    program.FreeResources();
                    bmp.Dispose();
                    buf.Dispose();
                });
                logOut.AppendLine("\t" + result);

                Logger.Log(LogType.Log, $"------------------------Run {key} Finished------------------------", 1);
                setup.WriteResult(result);
            }

            logOut.AppendLine();
            setup.WriteLog(logOut.ToString());
            setup.Dispose();
            return(logOut.ToString());
        }
Exemplo n.º 8
0
        private void OnSaveFile()
        {
            if (sfdScript.ShowDialog() == DialogResult.OK)
            {
                if (sfdScript.FileName.EndsWith(".fl"))
                {
                    PluginHost.Editor.Path = sfdScript.FileName;
                    File.WriteAllText(PluginHost.Editor.Path, PluginHost.Editor.WrittenText);
                }
                else if (sfdScript.FileName.EndsWith(".flc"))
                {
                    PluginHost.Editor.FLContainer.SerializedProgram = null;
                    PluginHost.Editor.WriteAndBuild();
                    PluginHost.Editor.Build();
                    if (PluginHost.Editor.FLContainer.SerializedProgram == null)
                    {
                        return;
                    }

                    Stream stream = File.OpenWrite(sfdScript.FileName);
                    FLSerializer.SaveProgram(
                        stream,
                        PluginHost.Editor.FLContainer.SerializedProgram,
                        PluginHost.Editor.FLContainer.InstructionSet,
                        new string[0]
                        );
                    stream.Close();
                }
                else if (sfdScript.FileName.EndsWith(".png"))
                {
                    PluginHost.Editor.FLContainer.SerializedProgram = null;
                    PluginHost.Editor.WriteAndBuild();
                    PluginHost.Editor.Build();
                    if (PluginHost.Editor.FLContainer.SerializedProgram == null)
                    {
                        return;
                    }

                    FLBuffer input = PluginHost.Editor.FLContainer.CreateBuffer(
                        FLScriptEditor.Settings.ResX,
                        FLScriptEditor.Settings.ResY,
                        1,
                        "ImageExportInput"
                        );
                    FLProgram prog =
                        PluginHost.Editor.FLContainer.SerializedProgram.Initialize(PluginHost.Editor.FLContainer);
                    prog.Run(input, true);

                    Bitmap bmp = prog.GetActiveBitmap();

                    prog.FreeResources();
                    bmp.Save(sfdScript.FileName);
                    bmp.Dispose();
                }
            }
        }
Exemplo n.º 9
0
        protected override void Run(string input, string output)
        {
            Logger.Log(LogType.Log, "Parsing", 2);
            SerializableFLProgram prog = Parse(input, Defines);

            Logger.Log(LogType.Log, "Serializing", 2);
            using (Stream s = File.Create(output))
            {
                FLSerializer.SaveProgram(s, prog, FLData.Container.InstructionSet, ExtraSteps);
            }
        }
Exemplo n.º 10
0
        public override void Serialize(PrimitiveValueWrapper s, object obj)
        {
            SerializableExternalFLFunction input = (SerializableExternalFLFunction)obj;

            s.Write(input.Name);
            s.WriteArray(input.Modifiers.GetModifiers().ToArray());
            MemoryStream ms = new MemoryStream();

            FLSerializer.SaveProgram(ms, input.ExternalProgram, instructionSet, new string[0]);

            s.Write(ms.GetBuffer(), (int)ms.Position);
        }
Exemplo n.º 11
0
        public override object Deserialize(PrimitiveValueWrapper s)
        {
            string name = s.ReadString();
            FLExecutableElementModifiers emod = new FLExecutableElementModifiers(name, s.ReadArray <string>());

            byte[] payload = s.ReadBytes();

            MemoryStream ms = new MemoryStream(payload);

            return(new SerializableExternalFLFunction(
                       name,
                       FLSerializer.LoadProgram(ms, instructionSet),
                       emod
                       ));
        }
Exemplo n.º 12
0
        private void ExportViewer_Load(object sender, EventArgs e)
        {
            StyleManager.RegisterControls(this);


            Stream s = File.OpenRead(file);


            FLProgram p     = FLSerializer.LoadProgram(s, FLContainer.InstructionSet).Initialize(FLContainer);
            FLBuffer  input = FLContainer.CreateBuffer(512, 512, 1, "Input");

            p.Run(input, true);

            Bitmap bmp = p.GetActiveBitmap();

            pbExportView.Image = bmp;
        }
Exemplo n.º 13
0
        private void Build()
        {
            FLConsole.Settings.SetVerbosity();
            string[] inputFiles  = SetInputFilesCommand.InputFiles;
            string[] outputFiles = SetOutputFilesCommand.OutputFiles;

            BufferCreator creator = new BufferCreator();

            FLConsole.Settings.BufferCreatorTypes.ForEach(x =>
                                                          creator.AddBufferCreator((ASerializableBufferCreator)Activator.CreateInstance(x)));
            FLInstructionSet iset =
                FLInstructionSet.CreateWithBuiltInTypes(CLAPI.MainThread, FLConsole.Settings.KernelFolder);
            FLProgramCheckBuilder programCheckBuilder = new FLProgramCheckBuilder(iset, creator);

            FLParser p = new FLParser(iset, creator,
                                      new WorkItemRunnerSettings(FLConsole.Settings.MultiThread,
                                                                 FLConsole.Settings.WorkSizeMultiplier));

            programCheckBuilder.Attach(p, true);

            Logger.Log(LogType.Log, $"Building {inputFiles.Length} Files", 1);

            for (int i = 0; i < inputFiles.Length; i++)
            {
                string inp = inputFiles[i];
                Logger.Log(LogType.Log, $"Building {inp}", 2);
                string outp = outputFiles.Length > i
                    ? outputFiles[i]
                    : $"./{Path.GetFileNameWithoutExtension(inp)}.flc";

                SerializableFLProgram prog = p.Process(new FLParserInput(inp));

                Stream dst = File.Create(outp);
                FLSerializer.SaveProgram(dst, prog, iset, ExtraStepCommand.extras);
                dst.Close();
                Logger.Log(LogType.Log, $"Output: {outp}", 2);
            }

            Logger.Log(LogType.Log, $"Finished Building {inputFiles.Length} Files", 1);
        }
        private void btnCreatePackage_Click(object sender, EventArgs e)
        {
            if (sfdSavePackage.ShowDialog() == DialogResult.OK)
            {
                string curDir = Directory.GetCurrentDirectory();

                IProgressIndicator ind = ProgressIndicator.CreateProgressIndicator(panelProgress);
                ind.SetProgress("Running Preparations.", 0, 2);
                if (cbExport.Checked)
                {
                    IProgressIndicator preps = ind.CreateSubTask(false);
                    preps.SetProgress("Copying Folder Contents...", 0, 1);

                    string dir = Path.Combine(
                        Path.GetDirectoryName(Directory.GetCurrentDirectory()),
                        "temp_" +
                        Path.GetFileNameWithoutExtension(Directory.GetCurrentDirectory())
                        );
                    CopyDirectory(Directory.GetCurrentDirectory(), dir, preps.CreateSubTask(false));
                    Directory.SetCurrentDirectory(dir);
                    string[] files = Directory.GetFiles(dir, "*.fl", SearchOption.AllDirectories);
                    preps.SetProgress("Exporting FL Scripts..", 0, 1);
                    IProgressIndicator fl2flc  = ind.CreateSubTask(false);
                    IProgressIndicator fl2flcf = fl2flc.CreateSubTask(false);
                    for (int i = 0; i < files.Length; i++)
                    {
                        string file = files[i];

                        fl2flc.SetProgress("Exporting File:" + file, i, files.Length);
                        fl2flcf.SetProgress("Parsing..", 0, 1);
                        Editor.Path = file;
                        Editor.FLContainer.SerializedProgram = null;

                        //Editor.InitProgram();
                        Editor.Build();
                        if (Editor.FLContainer.SerializedProgram == null)
                        {
                            return;
                        }

                        fl2flcf.SetProgress("Exporting..", 1, 1);
                        string f      = file + "c";
                        Stream stream = File.OpenWrite(f);
                        FLSerializer.SaveProgram(
                            stream,
                            Editor.FLContainer.SerializedProgram,
                            Editor.FLContainer.InstructionSet,
                            new string[0]
                            );
                        stream.Close();
                        if (!cbKeepFlScripts.Checked)
                        {
                            File.Delete(file);
                        }
                    }

                    fl2flcf.Dispose();
                    fl2flc.Dispose();
                    preps.Dispose();
                }

                ind.SetProgress("Creating Package.", 1, 2);
                ProgressIndicator.RunTask(
                    indicator => ResourceManager.Create(
                        Directory.GetCurrentDirectory(),
                        sfdSavePackage.FileName,
                        tbPackageName.Text,
                        tbUnpackConfig.Text,
                        indicator
                        ),
                    panelProgress,
                    Application.DoEvents,
                    ind.CreateSubTask(false)
                    );

                ind.SetProgress("Cleaning Up.", 2, 2);
                string oldDir = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(curDir);
                if (cbExport.Checked)
                {
                    Directory.Delete(oldDir, true);
                }

                Close();
                ind.Dispose();
            }
        }