Example #1
0
        public ComponentCompileResult Run(Stream input, Stream output, CompileOptions compileOptions)
        {
            var context = new CompileContext
            {
                Input     = input,
                Output    = output,
                Options   = compileOptions,
                Resources = resourceResolver
            };

            var compiledEntry = new ComponentCompileResult();

            foreach (var stage in stages)
            {
                stage.Run(context);

                if (context.Description != null && compiledEntry.ComponentName == null)
                {
                    compiledEntry.ComponentName = context.Description.ComponentName;
                    compiledEntry.Author        = context.Description.Metadata.Author;
                    compiledEntry.Guid          = context.Description.Metadata.GUID;
                    compiledEntry.Description   = context.Description;
                }
            }

            compiledEntry.Success = context.Errors.Count(e => e.Level.Value == LoadErrorCategory.Error) == 0;

            return(compiledEntry);
        }
Example #2
0
        internal VkShaderModule LoadSPIR_V_Shader(string path, Zeckoxe.ShaderCompiler.ShaderCompiler.Stage stage)
        {
            byte[] shaderCode = File.ReadAllBytes(path);

            Zeckoxe.ShaderCompiler.ShaderCompiler c = new Zeckoxe.ShaderCompiler.ShaderCompiler();
            var o = new CompileOptions();

            o.Language = CompileOptions.InputLanguage.HLSL;

            string testShader = File.ReadAllText(path);

            var r = c.Compile(testShader, stage, o, "testShader", "main");


            var bc = r.GetBytes();


            fixed(byte *scPtr = bc)
            {
                // Create a new shader module that will be used for Pipeline creation
                VkShaderModuleCreateInfo moduleCreateInfo = VkShaderModuleCreateInfo.New();

                moduleCreateInfo.codeSize = new UIntPtr((ulong)bc.Length);
                moduleCreateInfo.pCode    = (uint *)scPtr;

                vkCreateShaderModule(Device, ref moduleCreateInfo, null, out VkShaderModule shaderModule);

                return(shaderModule);
            }
        }
Example #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="options">Options for the compiler.</param>
        public CompileAction(CompileOptions options, bool usedExternally = false)
        {
            Opcode.InitMachineCodeData();
            CompiledObject.InitTypeData();
            SafeSerializationMgr.CheckIDumperStatics();

            _usedExternally = usedExternally;
            _options        = options;

            _shared = new SafeSharedObjects();
            _shared.FunctionManager          = new FunctionManager(_shared);
            _shared.GameEventDispatchManager = new NoopGameEventDispatchManager();
            _shared.Processor     = new NoopProcessor();
            _shared.ScriptHandler = new KSScript();
            _shared.Screen        = new Screen();
            _shared.UpdateHandler = new UpdateHandler();
            _shared.VolumeMgr     = new VolumeManager();
            _shared.FunctionManager.Load();

            _compilerOptions = new CompilerOptions()
            {
                LoadProgramsInSameAddressSpace = false,
                IsCalledFromRun = false,
                FuncManager     = _shared.FunctionManager
            };

            _logger        = new CompilerLogger();
            _scriptLoader  = new KerboscriptLoader(_shared.VolumeMgr as VolumeManager, _logger, _options);
            _scriptDeleter = new KerboscriptDeleter(_options);
        }
 public override void Compile(CompileOptions hint = CompileOptions.None, bool forceCompilation = false)
 {
     if (forceCompilation || (options.ShouldCompile(hint) && !upToDate))
     {
         for (int index = this.Entries.Count - 1; index >= 0; index--)
         {
             var entry = entries[index];
             var path  = AssetDatabase.GUIDToAssetPath(entry.guid);
             if (!File.Exists(path))
             {
                 this.Entries.RemoveAt(index);
                 continue;
             }
             if (entry.options.ShouldCompile(hint))
             {
                 var compileableAsset = AssetDatabase.LoadAssetAtPath <CompileableObject>(path);
                 if (compileableAsset == null)
                 {
                     this.Entries.RemoveAt(index);
                     continue;
                 }
                 compileableAsset.Compile(hint, forceCompilation);
             }
         }
     }
 }
 private static void CheckPrintout(CompileOptions options, ProcessSystem system)
 {
     //Check whether we want to print out a formatted version of the source
     if (options["p"] != "")
     {
         string        format    = options["p"];
         BaseFormatter formatter = null;
         if (format.ToLower() == "html")
         {
             formatter = new BaseFormatter();
         }
         else if (format.ToLower() == "latex" || format.ToLower() == "tex")
         {
             format    = "tex";
             formatter = new LaTeXFormatter();
         }
         else if (format.ToLower() == "txt" || format.ToLower() == "ccs")
         {
             format    = "formatted_ccs"; //So we don't overwrite the original file...
             formatter = new BaseFormatter();
         }
         else
         {
             DieIf(true, "Format for /print options must be one of ccs,html,latex");
         }
         formatter.Start(system);
         string result   = formatter.GetFormatted();
         string filename = Path.ChangeExtension(options.OutputFile, format);
         File.WriteAllText(filename, result);
         Console.WriteLine("Formatted source written to {0}", filename);
     }
 }
Example #6
0
        public void IncludeTest()
        {
            var c = new ShaderCompiler();
            var o = new CompileOptions();

            o.Language        = CompileOptions.InputLanguage.GLSL;
            o.IncludeCallback = IncludeHandler;

            string testShader = @"#version 450
                                #include ""common.glsl""
                                void main()
                                {}";

            var r = c.Preprocess(testShader, ShaderCompiler.Stage.Vertex, o, "testShader");

            Assert.True(r.NumberOfErrors == 0, "[Vulkan] GLSL->PREPROCESS: Has error messages");

            Assert.True(r.CompileStatus == CompileResult.Status.Success, "[Vulkan] GLSL->PREPROCESS: Compilation failed:" + r.ErrorMessage);

            var bc = r.GetBytes();

            var preprocessed = Encoding.ASCII.GetString(bc);

            Assert.False(preprocessed.Contains("#include"), "[Vulkan] GLSL->PREPROCESS: Preprocessed shader still " +
                         "contains include directive:" + preprocessed);
        }
        public void Compile(List <TupleInfo> tuples, ProcessSystem processes, CompileOptions options)
        {
            this.processes = processes;
            this.processes.MeetTheParents();
            this.tuples = tuples;
            this.processes.MainMethodStart += new CompileEventHandler(CompileTupleSpaces);
            PLRString.DisplayWithoutQuotes  = true; //To make localities look right...

            processes.Compile(options);
        }
Example #8
0
        private Veldrid.Shader LoadShader(ResourceFactory factory, string set, ShaderStages stage, string entryPoint)
        {
            string name       = $"{set}-{stage.ToString().ToLower()}.{GetExtension(factory.BackendType)}";
            var    assetBytes = ReadEmbeddedAssetBytes(name);

            if (factory.BackendType == GraphicsBackend.Vulkan)
            {
                //Create a new compiler and new options
                var c = new ShaderCompiler();
                var o = new CompileOptions();

                //Set our compile options
                o.Language     = CompileOptions.InputLanguage.GLSL;
                o.Optimization = CompileOptions.OptimizationLevel.Performance;

                //Compile the specified vertex shader and give it a name
                var r = c.Compile(Encoding.UTF8.GetString(assetBytes), stage == ShaderStages.Vertex ? ShaderCompiler.Stage.Vertex : ShaderCompiler.Stage.Fragment, o, stage == ShaderStages.Vertex ? "VS" : "PS");

                //Check if we had any compilation errors
                if (r.CompileStatus != CompileResult.Status.Success)
                {
                    //Write the error out
                    System.Console.WriteLine(r.ErrorMessage);
                    throw new Exception("Cannot compile Vulkan shader");
                }

                //Get the produced SPV bytecode
                assetBytes = r.GetBytes();
            }

            var hash = 0l;

            using (var sha = SHA256Managed.Create())
            {
                using (var stream = new MemoryStream(assetBytes))
                {
                    var rawHash = sha.ComputeHash(stream);
                    hash = BitConverter.ToInt64(rawHash, 0);
                }
            }

            if (stage == ShaderStages.Vertex)
            {
                _vertexHash = hash;
            }
            else
            {
                if (stage == ShaderStages.Fragment)
                {
                    _fragmentHash = hash;
                }
            }

            return(factory.CreateShader(new ShaderDescription(stage, assetBytes, entryPoint)));
        }
Example #9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="options">Watch CLI options.</param>
        public WatchAction(WatchOptions options)
        {
            _options  = options;
            _compiler = new CompileAction(CompileOptions.FromWatchOptions(options), true);
            _logger   = new WatcherLogger();

            _timer = new Timer
            {
                AutoReset = true,
                Interval  = 200
            };
            _timer.Elapsed += OnRecompile;
        }
Example #10
0
        /// <summary>
        /// Runs the compile action.
        /// </summary>
        /// <param name="options">CLI options for the compile action.</param>
        /// <param name="fromMain">Wheter or not this is called from the main method.</param>
        /// <returns>CLI return code.</returns>
        private static int Compile(CompileOptions options, bool fromMain = true)
        {
            CompileAction compiler = new CompileAction(options);
            int           result   = compiler.Run();

#if DEBUG
            if (fromMain == true)
            {
                Console.Read();
            }
#endif

            return(result);
        }
Example #11
0
        public void SetCompileOptions(CompileOptions options)
        {
            CompileOptions = options;
            
            _compileOptions = string.Empty;

            // UseNativeFunctions = ((options & CompileOptions.UseNativeFunctions) == CompileOptions.UseNativeFunctions);
            _compileOptions += ((options & CompileOptions.FastRelaxedMath) == CompileOptions.FastRelaxedMath ? " -cl-fast-relaxed-math " : string.Empty);
            _compileOptions += ((options & CompileOptions.FusedMultiplyAdd) == CompileOptions.FusedMultiplyAdd ? " -cl-mad-enable " : string.Empty);
            _compileOptions += ((options & CompileOptions.DisableOptimizations) == CompileOptions.DisableOptimizations ? " -cl-opt-disable " : string.Empty);
            _compileOptions += ((options & CompileOptions.StrictAliasing) == CompileOptions.StrictAliasing ? " -cl-strict-aliasing " : string.Empty);
            _compileOptions += ((options & CompileOptions.NoSignedZeros) == CompileOptions.NoSignedZeros ? " -cl-no-signed-zeros " : string.Empty);
            _compileOptions += ((options & CompileOptions.UnsafeMathOptimizations) == CompileOptions.UnsafeMathOptimizations ? " -cl-unsafe-math-optimizations " : string.Empty);
            _compileOptions += ((options & CompileOptions.FiniteMathOnly) == CompileOptions.FiniteMathOnly ? " -cl-finite-math-only " : string.Empty);
        }
        public void SetCompileOptions(CompileOptions options)
        {
            CompileOptions = options;

            _compileOptions = string.Empty;

            // UseNativeFunctions = ((options & CompileOptions.UseNativeFunctions) == CompileOptions.UseNativeFunctions);
            _compileOptions += ((options & CompileOptions.FastRelaxedMath) == CompileOptions.FastRelaxedMath ? " -cl-fast-relaxed-math " : string.Empty);
            _compileOptions += ((options & CompileOptions.FusedMultiplyAdd) == CompileOptions.FusedMultiplyAdd ? " -cl-mad-enable " : string.Empty);
            _compileOptions += ((options & CompileOptions.DisableOptimizations) == CompileOptions.DisableOptimizations ? " -cl-opt-disable " : string.Empty);
            _compileOptions += ((options & CompileOptions.StrictAliasing) == CompileOptions.StrictAliasing ? " -cl-strict-aliasing " : string.Empty);
            _compileOptions += ((options & CompileOptions.NoSignedZeros) == CompileOptions.NoSignedZeros ? " -cl-no-signed-zeros " : string.Empty);
            _compileOptions += ((options & CompileOptions.UnsafeMathOptimizations) == CompileOptions.UnsafeMathOptimizations ? " -cl-unsafe-math-optimizations " : string.Empty);
            _compileOptions += ((options & CompileOptions.FiniteMathOnly) == CompileOptions.FiniteMathOnly ? " -cl-finite-math-only " : string.Empty);
        }
Example #13
0
        public void IncludeTestFail()
        {
            var c = new ShaderCompiler();
            var o = new CompileOptions();

            o.Language = CompileOptions.InputLanguage.GLSL;

            string testShader = @"#version 450
                                #include ""common.glsl""
                                void main()
                                {}";

            var r = c.Preprocess(testShader, ShaderCompiler.Stage.Vertex, o, "testShader");

            Assert.True(r.CompileStatus != CompileResult.Status.Success, "[Vulkan] GLSL->PREPROCESS: Compilation succeeded unexpected:" + r.ErrorMessage);
        }
Example #14
0
        static void Main(string[] args)
        {
            var config = CheckDataAndGetOptions(args);

            if (config == null)
            {
                return;
            }

            _compileOptions = BuildOptions(args, config);

            Console.WriteLine("Reading files...");
            _timeWatch = new TimeWatch();
            var files = Parse(args[0]);

            _timeWatch.Elapsed("reading files in project");

            Console.WriteLine("Hashing files...");

            var code = new List <string>();

            foreach (var hash in _hashes)
            {
                var newHash = Md5.GenerateHash(hash.Value + VERSION);

                if (File.Exists(".temp/" + newHash))
                {
                    code.Add(File.ReadAllText(".temp/" + newHash));
                    files.Remove(hash.Key);
                }
            }

            _timeWatch.Elapsed("hashing files");

            if (!Compile(_compileOptions, TranslateCode(BuildTree(files), code)))
            {
                return;
            }

            Console.WriteLine("Success! Compiled to " + (_compileOptions.CompiledOutputPath + "/" + _compileOptions.Name + (_compileOptions.IsExecutable ? ".exe" : ".dll")));
            if (_isRunStatistics)
            {
                _timeWatch.PrintStatistics();
                Console.WriteLine("Count lines: " + _countLines);
            }
        }
Example #15
0
        private static bool Compile(CompileOptions compileOptions, List <string> strings)
        {
            Console.WriteLine("Compiling...");
            compileOptions.Code = strings;
            var compiler = new Compiler(compileOptions);

            compiler.Compile();
            _timeWatch.Elapsed("compiling");

            foreach (CompilerError error in compiler.CompilerErrors)
            {
                Console.WriteLine($"Error {error.ErrorNumber}: {error.ErrorText} ({error.FileName.Replace(".cs", ".tengri")})");
                return(false);
            }

            return(true);
        }
Example #16
0
        public void Assemble()
        {
            var c = new ShaderCompiler();
            var o = new CompileOptions();

            o.Language = CompileOptions.InputLanguage.GLSL;

            string testShader = @"#version 450
                                void main()
                                {}";

            var r = c.Assemble(testShader, ShaderCompiler.Stage.Vertex, o, "testShader");

            Assert.True(r.CompileStatus == CompileResult.Status.Success, "[Vulkan] GLSL->ASSEMBLE: Compilation failed unexpected:" + r.ErrorMessage);

            var assembly = r.GetString();

            Assert.True(assembly.Length > 0, "[Vulkan] GLSL->ASSEMBLE: Assembly is empty!");
        }
Example #17
0
        public void BrokenShader()
        {
            var c = new ShaderCompiler();
            var o = new CompileOptions();

            o.Language = CompileOptions.InputLanguage.GLSL;

            string testShader = @"#version 450
                                   void main()
                                   {";

            var r = c.Compile(testShader, ShaderCompiler.Stage.Vertex, o, "testShader");

            Assert.True(r.CompileStatus == CompileResult.Status.CompilationError, "[Vulkan] GLSL-> SPIRV: Broken shader result wrong!");

            string msg = r.ErrorMessage;

            Assert.True(msg.Length > 0, "[Vulkan] GLSL->SPIRV: No error message for broken shader produced!");
        }
Example #18
0
        /// <summary>
        /// Prints no files found messages.
        /// </summary>
        /// <param name="options"></param>
        public void NoFilesFound(CompileOptions options)
        {
            Warn(Draw.PrefixAndColor, "No Kerboscript files found.");
            if (options.Input != Constants.CurrentDirectory ||
                options.Output != Constants.CurrentDirectory)
            {
                NewLine();
                Warn(Draw.Color, "Options:");
                if (_noFilesFound == false)
                {
                    Warn(Draw.Color, "    Input: {0}", Path.GetFullPath(options.Input));
                }

                Warn(Draw.Color, "    Ouput: {0}", Path.GetFullPath(options.Output));

                NewLine();
                Warn(Draw.Color, "Please check if the given input is valid.");
            }
        }
Example #19
0
        static void Main(string[] args)
        {
            if (!ExtractParams(args))
            {
                ShowMessage();
                return;
            }
            else
            {
                CompileEngine engine        = new CompileEngine();
                ArtifactsType artifactsType = ArtifactsType.Console;
                if (_writeFile)
                {
                    if (_singleFile)
                    {
                        artifactsType = ArtifactsType.SingleFile;
                    }
                    else
                    {
                        artifactsType = ArtifactsType.MultipleFile;
                    }
                }

                if ((!string.IsNullOrEmpty(_config)) && _config.ToUpper() == "RELEASE")
                {
                    _config = CompileOptions.RELEASE_ANY_CPU;
                }
                else
                {
                    _config = CompileOptions.DEBUG_ANY_CPU;
                }


                CompileOptions opts = new CompileOptions(artifactsType, _config);
                opts.GenerateSourceMap = _generateSourceMap;

                engine.InitializeCompiler(_csprojFile, opts, _suppressWarnings);
                var errors = engine.Compile();
                errors.WriteToStdErr(opts.StdError);
            }
            System.Console.ReadLine();
        }
 private void UpdateSettings(CompileOptions value)
 {
     if (serializedObject.targetObject is BehaviourGraphModel model)
     {
         var guid  = AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(model)).ToString();
         var index = model.Settings.Models.FindIndex(m => m.asset == guid);
         var e     = new BehaviourGraphSettings.ModelEntry
         {
             asset   = guid,
             options = value
         };
         if (index < 0)
         {
             model.Settings.Models.Add(e);
         }
         else
         {
             model.Settings.Models[index] = e;
         }
     }
 }
Example #21
0
        public void GlslVulkan()
        {
            var c = new ShaderCompiler();
            var o = new CompileOptions();

            o.Language = CompileOptions.InputLanguage.GLSL;

            string testShader = @"#version 450
                                   void main()
                                   {}";

            var r = c.Compile(testShader, ShaderCompiler.Stage.Vertex, o, "testShader");

            Assert.True(r.NumberOfErrors == 0, "[Vulkan] GLSL->SPIRV: Has error messages");

            Assert.True(r.CompileStatus == CompileResult.Status.Success, "[Vulkan] GLSL-> SPIRV: Compilation failed:" + r.ErrorMessage);

            var bc = r.GetBytes();

            Assert.True(bc.Length > 0, "[Vulkan] GLSL-> SPIRV: No bytecode produced!");
        }
Example #22
0
        private void cmdCompile_Click(object sender, RoutedEventArgs e)
        {
            cmdCompile.IsEnabled = false;
            progress.Visibility  = Visibility.Visible;
            SaveValues();
            txtOutput.Text = "";
            progress.Value = 0;
            TaskbarItemInfo.ProgressValue = 0;
            TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal;
            var options = new CompileOptions
            {
                Filename     = txtSource.Text,
                OutputFolder = txtDestination.Text,
                DebugMode    = (bool)chkDebug.IsChecked,
                Profile      = cmbProfile.Text,
                Minify       = (bool)chkMinify.IsChecked,
                Gamebook     = (bool)chkGamebook.IsChecked,
            };
            Thread newThread = new Thread(() => compiler.StartCompile(options));

            newThread.Start();
        }
Example #23
0
        private static int Compile(CompileOptions options)
        {
            Console.WriteLine("Compiling {0}", options.ProjectPath);

            Project project = Project.LoadFromPath(options.ProjectPath);

            project.CompileProject();

            while (project.IsCompiling)
            {
                Console.Write(".");
                Thread.Sleep(1000);
            }

            Console.WriteLine();

            if (project.LastCompilationSucceeded)
            {
                Console.WriteLine("Compilation succeeded.");

                if (options.Run)
                {
                    Console.WriteLine($"Running...");
                    project.RunProject();
                }

                return(1);
            }
            else
            {
                Console.WriteLine($"Compilation failed with {project.LastCompileErrors.Count} errors:");
                foreach (var error in project.LastCompileErrors)
                {
                    Console.WriteLine(error);
                }
            }

            return(0);
        }
Example #24
0
        public void hlslVulkan()
        {
            var c = new ShaderCompiler();
            var o = new CompileOptions()
            {
                Target = CompileOptions.Environment.Vulkan,
            };

            o.Language = CompileOptions.InputLanguage.GLSL;


            string testShader = File.ReadAllText("Shaders/raygen.rgen");

            var r = c.Compile(testShader, ShaderCompiler.Stage.shaderc_raygen_shader, o, "raygen");


            byte[] bc = r.GetBytes();
            foreach (var item in bc)
            {
                Console.WriteLine(item);
            }
        }
        public ConvolutionWeights(CompileOptions options, int inChannels, int outChannels, int kernelSize, int stride, bool bias, string label, int seed)
        {
            this.options = options.ExecutionOptions;

            descriptor = MPSCnnConvolutionDescriptor.CreateCnnConvolutionDescriptor(
                (System.nuint)kernelSize, (System.nuint)kernelSize,
                (System.nuint)inChannels,
                (System.nuint)outChannels);
            descriptor.StrideInPixelsX = (nuint)stride;
            descriptor.StrideInPixelsY = (nuint)stride;
            this.bias  = bias;
            this.label = string.IsNullOrEmpty(label) ? Guid.NewGuid().ToString() : label;

            var lenWeights = inChannels * kernelSize * kernelSize * outChannels;

            var vDescWeights = VectorDescriptor(lenWeights);

            weightVectors = new OptimizableVector(options.Device, vDescWeights, 0.0f);

            var vDescBiases = VectorDescriptor(outChannels);

            biasVectors = new OptimizableVector(options.Device, vDescBiases, 0.1f);

            RandomizeWeights((nuint)seed);

            convWtsAndBias  = new MPSCnnConvolutionWeightsAndBiasesState(weightVectors.Value.Data, biasVectors.Value.Data);
            momentumVectors = NSArray <MPSVector> .FromNSObjects(weightVectors.Momentum, biasVectors.Momentum);

            velocityVectors = NSArray <MPSVector> .FromNSObjects(weightVectors.Velocity, biasVectors.Velocity);

            var odesc = new MPSNNOptimizerDescriptor(options.LearningRate, 1.0f, MPSNNRegularizationType.None, 1.0f);

            updater = new MPSNNOptimizerAdam(
                options.Device,
                beta1: 0.9f, beta2: 0.999f, epsilon: 1e-8f,
                timeStep: 0,
                optimizerDescriptor: odesc);
        }
Example #26
0
        private static int Compile(CompileOptions compileOptions)
        {
            var metadataSearchSubDirectories = Convert.ToBoolean(ConfigurationManager.AppSettings["MetadataSearchSubDirectories"] ?? bool.TrueString);

            var metadataSearchPattern = compileOptions.MetadataSearchPattern ?? ConfigurationManager.AppSettings["MetadataSearchPattern"] ?? "*.json";

            if (metadataSearchPattern.EndsWith("*"))
            {
                metadataSearchPattern += ABIFileSystemOptions.StandardMetadataFileExtension;
            }

            var fileSystemRootPath = ConfigurationManager.AppSettings["FileSystemRootPath"] ?? @".";
            var metadataFolderName = ConfigurationManager.AppSettings["MetadataFolderName"] ?? @"metadata";
            var templateFolderName = ConfigurationManager.AppSettings["TemplateFolderName"] ?? @"templates";
            var outputFolderName   = ConfigurationManager.AppSettings["OutputFolderName"] ?? @"output";

            var options = new ABIFileSystemOptions(
                rootPath: fileSystemRootPath,
                metadataFolder: metadataFolderName,
                templateFolder: templateFolderName,
                outputFolder: outputFolderName,
                metadataSearchPattern: metadataSearchPattern,
                metadataSearchSubDirectories: metadataSearchSubDirectories
                );

            var result = ABIFileSystemCompiler.Compile(options, _logger.Factory);

            if (result != ABIExitCode.CompileCompleted)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(result);
                Console.ResetColor();
            }

            return((int)result);
        }
        public override void Compile(CompileOptions hint = CompileOptions.None, bool forceCompilation = false)
        {
            if (forceCompilation || (options.ShouldCompile(hint) && !upToDate))
            {
                if (this.compiler.Value == null)
                {
                    Debug.LogError($"Compiler for Behaviour Type {this.behaviourType} is not set.");
                    return;
                }
                var compiler = Activator.CreateInstance(this.compiler.Value) as BehaviourGraphCompiler;
                if (compiler == null)
                {
                    Debug.LogError($"Unable to create compiler for Behaviour Type {this.behaviourType}.");
                    return;
                }

                /* var behaviourGuids = AssetDatabase.FindAssets($"t:{nameof(BehaviourGraphModel)}");
                 * var behaviourType = BehaviourType;
                 * var behaviours = new List<BehaviourGraphModel>(); */

                foreach (var modelData in Models)
                {
                    var model = AssetDatabase.LoadAssetAtPath <BehaviourGraphModel>(AssetDatabase.GUIDToAssetPath(modelData.asset));
                    if (model == null || model.BehaviourType.Value != behaviourType)
                    {
                        continue;
                    }
                    if (options != CompileOptions.None && (model.options | options) == 0)
                    {
                        continue;
                    }
                    compiler.Compile(model, forceCompilation);
                }
                compiler.Dispose();
            }
        }
Example #28
0
        public static ShaderModule CreateShaderModule(VkShaderStageFlags shaderStage, string code, string includeFile)
        {
#if SHARP_SHADER_COMPILER
            ShaderCompiler.Stage stage = ShaderCompiler.Stage.Vertex;
            switch (shaderStage)
            {
            case VkShaderStageFlags.Vertex:
                stage = ShaderCompiler.Stage.Vertex;
                break;

            case VkShaderStageFlags.Fragment:
                stage = ShaderCompiler.Stage.Fragment;
                break;

            case VkShaderStageFlags.Geometry:
                stage = ShaderCompiler.Stage.Geometry;
                break;

            case VkShaderStageFlags.Compute:
                stage = ShaderCompiler.Stage.Compute;
                break;

            case VkShaderStageFlags.TessellationControl:
                stage = ShaderCompiler.Stage.TessControl;
                break;

            case VkShaderStageFlags.TessellationEvaluation:
                stage = ShaderCompiler.Stage.TessEvaluation;
                break;
            }

            var c = new ShaderCompiler();
            var o = new CompileOptions(IncludeHandler)
            {
                Language      = CompileOptions.InputLanguage.GLSL,
                Target        = CompileOptions.Environment.Vulkan,
                GenerateDebug = true,
            };

            var r = c.Preprocess(code, stage, o, "main");
            if (r.NumberOfErrors > 0)
            {
                Log.Error(r.ErrorMessage);
            }

            if (r.CompileStatus != CompileResult.Status.Success)
            {
                return(null);
            }

            var source = r.GetString();

            var res = c.Compile(source, stage, o, includeFile, "main");
            if (res.NumberOfErrors > 0)
            {
                Log.Error(res.ErrorMessage);
            }

            if (res.CompileStatus != CompileResult.Status.Success)
            {
                return(null);
            }

            uint len          = res.GetCode(out var codePointer);
            var  refl         = ReflectionShaderModule(source, codePointer, len / 4);
            var  shaderModule = new ShaderModule(shaderStage, codePointer, len)
            {
                ShaderReflection = refl
            };
#else
            shaderc.ShaderKind stage = shaderc.ShaderKind.VertexShader;
            switch (shaderStage)
            {
            case VkShaderStageFlags.Vertex:
                stage = shaderc.ShaderKind.VertexShader;
                break;

            case VkShaderStageFlags.Fragment:
                stage = shaderc.ShaderKind.FragmentShader;
                break;

            case VkShaderStageFlags.Geometry:
                stage = shaderc.ShaderKind.GeometryShader;
                break;

            case VkShaderStageFlags.Compute:
                stage = shaderc.ShaderKind.ComputeShader;
                break;

            case VkShaderStageFlags.TessControl:
                stage = shaderc.ShaderKind.TessControlShader;
                break;

            case VkShaderStageFlags.TessEvaluation:
                stage = shaderc.ShaderKind.TessEvaluationShader;
                break;
            }

            shaderc.Compiler.GetSpvVersion(out shaderc.SpirVVersion version, out uint revision);

            shaderc.Options o = new shaderc.Options() //new ShadercOptions()
            {
                //SourceLanguage = shaderc.SourceLanguage.Glsl,
                //TargetSpirVVersion = new shaderc.SpirVVersion(1,5),
                //Optimization = shaderc.OptimizationLevel.Performance
            };

            o.EnableDebugInfo();

            o.IncludeDirectories.Add(FileSystem.WorkSpace + "data/shaders/common");
            o.IncludeDirectories.Add(FileSystem.WorkSpace + "data/shaders/glsl");

            var c   = new shaderc.Compiler(o);
            var res = c.Compile(code, includeFile, stage);

            if (res.ErrorCount > 0)
            {
                Log.Error(res.ErrorMessage);
            }

            if (res.Status != Status.Success)
            {
                return(null);
            }

            var refl         = ReflectionShaderModule(code, res.CodePointer, res.CodeLength / 4);
            var shaderModule = new ShaderModule(shaderStage, res.CodePointer, res.CodeLength)
            {
                ShaderReflection = refl
            };
#endif


            return(shaderModule);
        }
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.Error.WriteLine(@"
CCS Compiler
Copyright (C) 2009 Einar Egilsson

Usage: CCS [options] <filename>
");
                return(1);
            }
            List <string> listArgs = new List <string>(args);

            CompileOptions.AddOptionWithArgument("p", "print", ""); //Allow printouts
            CompileOptions options = CompileOptions.Parse(listArgs);

            if (options.Help)
            {
                Console.Error.WriteLine(@"
CCS Compiler
Copyright (C) 2009 Einar Egilsson

Usage: CCS [options] <filename>

Available options:

    /reference:<filenames>   The assemblies that this program requires. It is 
    /r:<filenames>           not neccessary to specify the PLR assembly. 
                             Other assemblies should be specified in a comma
                             seperated list, e.g. /reference:Foo.dll,Bar.dll.
    
    /optimize                If specified then the generated assembly will be
    /op                      optimized, dead code eliminated and expressions
                             pre-evaluated where possible. Do not combine this
                             with the /debug switch.
    
    /embedPLR                Embeds the PLR into the generated file, so it can
    /e                       be distributed as a stand-alone file.
  
    /debug                   Emit debugging symbols in the generated file,
    /d                       this allows it to be debugged in Visual Studio, or
                             in the free graphical debugger that comes with the
                             .NET Framework SDK.

    /out:<filename>          Specify the name of the compiled executable. If 
    /o:<filename>            this is not specified then the name of the input
                             file is used, with .ccs replaced by .exe.

    /print:<format>          Prints a version of the program source in the
    /p:<format>              specified format. Allowed formats are ccs, html 
                             and latex. The generated file will have the same
                             name as the input file, except with the format
                             as extension.

");

                return(1);
            }

            DieIf(options.Arguments.Count == 0, "ERROR: Missing input file name");
            DieIf(options.Arguments.Count > 1, "ERROR: Only one input file is expected");
            string filename = options.Arguments[0];

            DieIf(!File.Exists(filename), "ERROR: File '{0}' does not exist!", filename);
            if (string.IsNullOrEmpty(options.OutputFile))
            {
                options.OutputFile = filename;
                if (options.OutputFile.ToLower().EndsWith(".ccs"))
                {
                    options.OutputFile = options.OutputFile.Substring(0, options.OutputFile.Length - 4);
                }
            }
            if (!options.OutputFile.ToLower().EndsWith(".exe"))
            {
                options.OutputFile += ".exe";
            }
            try {
                Parser parser = new Parser(new Scanner(new FileStream(filename, FileMode.Open)));
                parser.Parse();
                if (parser.errors.count > 0)
                {
                    Environment.Exit(1);
                }
                ProcessSystem system = parser.System;
                system.MeetTheParents();
                List <Warning> warnings = system.Analyze(new ReachingDefinitions());

                if (warnings.Count > 0)
                {
                    foreach (Warning warn in warnings)
                    {
                        Console.Error.WriteLine("ERROR({0},{1}): {2}", warn.LexicalInfo.StartLine, warn.LexicalInfo.StartColumn, warn.Message);
                    }
                    return(1); //This is an error so we die before attempting to compile
                }

                //These are just warnings, so just warn...
                warnings = system.Analyze(
                    new LiveVariables(),
                    new NilProcessWarning(),
                    new UnmatchedChannels(),
                    new UnusedProcesses(options.Optimize)
                    );

                foreach (Warning warn in warnings)
                {
                    Console.Error.WriteLine("WARNING({0},{1}): {2}", warn.LexicalInfo.StartLine, warn.LexicalInfo.StartColumn, warn.Message);
                }

                //This optimizes the tree before compilation, only do if we should optimize
                if (options.Optimize)
                {
                    system.Analyze(new FoldConstantExpressions());
                }

                CheckPrintout(options, system);
                system.Compile(options);
            } catch (Exception ex) {
                //Console.WriteLine(ex.StackTrace);
                DieIf(true, "ERROR: " + ex.Message);
            }
            return(0);
        }
Example #30
0
        private static CompileResult Compile (
            Func<CompileOptions, CodeDomProvider> getProvider, IEnumerable<string> _filenames, string assemblyName, string compilerOptions
        ) {
            var filenames = _filenames.ToArray();
            var tempPath = Path.Combine(TempPath, assemblyName);
            Directory.CreateDirectory(tempPath);

            var warningTextPath = Path.Combine(
                tempPath, "warnings.txt"
            );

            var references = new List<string> {
                "System.dll", 
                "System.Core.dll", "System.Xml.dll", 
                "Microsoft.CSharp.dll",
                typeof(JSIL.Meta.JSIgnore).Assembly.Location
            };

            bool generateExecutable = false;

            var compilerCreationOptions = new CompileOptions();

            var metacomments = new List<Metacomment>();
            foreach (var sourceFile in filenames) {
                var sourceText = File.ReadAllText(sourceFile);

                var localMetacomments = Metacomment.FromText(sourceText);
                foreach (var metacomment in localMetacomments) {
                    switch (metacomment.Command.ToLower()) {
                        case "reference":
                            references.Add(metacomment.Arguments);
                            break;

                        case "compileroption":
                            compilerOptions += " " + metacomment.Arguments;
                            break;

                        case "generateexecutable":
                            generateExecutable = true;
                            break;

                        case "useroslyn":
                            compilerCreationOptions.UseRoslyn = true;
                            break;
                    }
                }

                metacomments.AddRange(localMetacomments);
            }

            var outputAssembly = Path.Combine(
                tempPath,
                Path.GetFileNameWithoutExtension(assemblyName) + 
                (generateExecutable ? ".exe" : ".dll")
            );

            if (
                File.Exists(outputAssembly) &&
                CheckCompileManifest(filenames, tempPath)
            ) {
                if (File.Exists(warningTextPath))
                    Console.Error.WriteLine(File.ReadAllText(warningTextPath));

                return new CompileResult(
                    generateExecutable ? Assembly.ReflectionOnlyLoadFrom(outputAssembly) : Assembly.LoadFile(outputAssembly),
                    metacomments.ToArray()
                );
            }

            var files = Directory.GetFiles(tempPath);
            foreach (var file in files) {
                try {
                    File.Delete(file);
                } catch {
                }
            }

            var parameters = new CompilerParameters(references.ToArray()) {
                CompilerOptions = compilerOptions,
                GenerateExecutable = generateExecutable,
                GenerateInMemory = false,
                IncludeDebugInformation = true,
                TempFiles = new TempFileCollection(tempPath, true),
                OutputAssembly = outputAssembly,
                WarningLevel = 4,
                TreatWarningsAsErrors = false,
            };

            CompilerResults results;
            using (var provider = getProvider(compilerCreationOptions)) {
                results = provider.CompileAssemblyFromFile(
                    parameters,
                    filenames.ToArray()
                );
            }

            var compileErrorsAndWarnings = results.Errors.Cast<CompilerError>().ToArray();
            var compileWarnings = (from ce in compileErrorsAndWarnings where ce.IsWarning select ce).ToArray();
            var compileErrors = (from ce in compileErrorsAndWarnings where !ce.IsWarning select ce).ToArray();

            // Mono incorrectly trats some warnings as errors;
            if (Type.GetType("Mono.Runtime") != null)
            {
                if (compileErrors.Length > 0 && File.Exists(outputAssembly))
                {
                    try
                    {
                        results.CompiledAssembly = Assembly.LoadFrom(outputAssembly);
                        compileErrors = new CompilerError[0];
                        compileWarnings = compileErrorsAndWarnings;
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (compileWarnings.Length > 0) {
                var warningText = String.Format(
                    "// C# Compiler warning(s) follow //\r\n{0}\r\n// End of C# compiler warning(s) //",
                    String.Join(Environment.NewLine, compileWarnings.Select(Convert.ToString).ToArray())
                );
                Console.Error.WriteLine(
                    warningText
                );
                File.WriteAllText(
                    warningTextPath, warningText
                );
            } else {
                if (File.Exists(warningTextPath))
                    File.Delete(warningTextPath);
            }

            if (compileErrors.Length > 0) {
                throw new Exception(
                    String.Join(Environment.NewLine, compileErrors.Select(Convert.ToString).ToArray())
                );
            }

            WriteCompileManifest(filenames, tempPath);

            return new CompileResult(
                results.CompiledAssembly,
                metacomments.ToArray()
            );
        }
Example #31
0
        protected override void SetExecutionInfo()
        {
            _useXmlXref = CompileUseXmlXref && (!CompileInAnalysisMode || AnalysisModeSimplifiedDatabaseReferences);

            base.SetExecutionInfo();

            // for each file of the list
            var filesListcontent = new StringBuilder();

            var count = 0;

            foreach (var file in FilesToCompile)
            {
                if (!File.Exists(file.CompiledPath))
                {
                    throw new UoeExecutionParametersException($"Can not find the source file : {file.CompiledPath.PrettyQuote()}.");
                }

                var localSubTempDir = Path.Combine(_tempDir, count.ToString());
                var baseFileName    = Path.GetFileNameWithoutExtension(file.CompiledPath);

                var compiledFile = new UoeCompiledFile(file);
                if (!CompiledFiles.TryAdd(compiledFile))
                {
                    continue;
                }

                // get the output directory that will be use to generate the .r (and listing debug-list...)
                if (Path.GetExtension(file.Path ?? "").Equals(UoeConstants.ExtCls))
                {
                    // for *.cls files, as many *.r files are generated, we need to compile in a temp directory
                    // we need to know which *.r files were generated for each input file
                    // so each file gets his own sub tempDir
                    compiledFile.CompilationOutputDirectory = localSubTempDir;
                }
                else if (!string.IsNullOrEmpty(file.PreferredTargetDirectory))
                {
                    compiledFile.CompilationOutputDirectory = file.PreferredTargetDirectory;
                }
                else
                {
                    compiledFile.CompilationOutputDirectory = localSubTempDir;
                }

                Utils.CreateDirectoryIfNeeded(localSubTempDir);
                Utils.CreateDirectoryIfNeeded(compiledFile.CompilationOutputDirectory);

                compiledFile.CompilationRcodeFilePath  = Path.Combine(compiledFile.CompilationOutputDirectory, $"{baseFileName}{UoeConstants.ExtR}");
                compiledFile.CompilationErrorsFilePath = Path.Combine(localSubTempDir, $"{baseFileName}{UoeConstants.ExtCompileErrorsLog}");
                if (CompileWithListing)
                {
                    compiledFile.CompilationListingFilePath = Path.Combine(compiledFile.CompilationOutputDirectory, $"{baseFileName}{UoeConstants.ExtListing}");
                }

                if (CompileWithXref && !_useXmlXref)
                {
                    compiledFile.CompilationXrefFilePath = Path.Combine(compiledFile.CompilationOutputDirectory, $"{baseFileName}{UoeConstants.ExtXref}");
                }
                if (CompileWithXref && _useXmlXref)
                {
                    compiledFile.CompilationXmlXrefFilePath = Path.Combine(compiledFile.CompilationOutputDirectory, $"{baseFileName}{UoeConstants.ExtXrefXml}");
                }
                if (CompileWithDebugList)
                {
                    compiledFile.CompilationDebugListFilePath = Path.Combine(compiledFile.CompilationOutputDirectory, $"{baseFileName}{UoeConstants.ExtDebugList}");
                }
                if (CompileWithPreprocess)
                {
                    compiledFile.CompilationPreprocessedFilePath = Path.Combine(compiledFile.CompilationOutputDirectory, $"{baseFileName}{UoeConstants.ExtPreprocessed}");
                }

                compiledFile.IsAnalysisMode = CompileInAnalysisMode;

                if (CompileInAnalysisMode)
                {
                    compiledFile.CompilationFileIdLogFilePath = Path.Combine(localSubTempDir, $"{baseFileName}{UoeConstants.ExtFileIdLog}");
                    if (AnalysisModeSimplifiedDatabaseReferences)
                    {
                        compiledFile.CompilationRcodeTableListFilePath = Path.Combine(compiledFile.CompilationOutputDirectory, $"{baseFileName}{UoeConstants.ExtTableList}");
                    }
                    else if (string.IsNullOrEmpty(compiledFile.CompilationXrefFilePath))
                    {
                        compiledFile.CompilationXrefFilePath = Path.Combine(localSubTempDir, $"{baseFileName}{UoeConstants.ExtXref}");
                    }
                }

                // feed files list
                filesListcontent
                .Append(file.CompiledPath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationOutputDirectory.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationErrorsFilePath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationListingFilePath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationXrefFilePath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationXmlXrefFilePath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationDebugListFilePath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationPreprocessedFilePath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationFileIdLogFilePath.ProQuoter())
                .Append(" ")
                .Append(compiledFile.CompilationRcodeTableListFilePath.ProQuoter())
                .AppendLine();

                count++;
            }


            File.WriteAllText(_filesListPath, filesListcontent.ToString(), Env.IoEncoding);

            SetPreprocessedVar("CompileListFilePath", _filesListPath.ProPreProcStringify());
            SetPreprocessedVar("CompileProgressionFilePath", _progressionFilePath.ProPreProcStringify());
            SetPreprocessedVar("CompileLogPath", _compilationLog.ProPreProcStringify());
            SetPreprocessedVar("IsAnalysisMode", CompileInAnalysisMode.ToString());
            SetPreprocessedVar("GetRcodeTableList", AnalysisModeSimplifiedDatabaseReferences.ToString());
            SetPreprocessedVar("ProVerHigherOrEqualTo10.2", Env.IsProVersionHigherOrEqualTo(new Version(10, 2, 0)).ToString());
            SetPreprocessedVar("UseXmlXref", _useXmlXref.ToString());
            SetPreprocessedVar("CompileStatementExtraOptions", CompileStatementExtraOptions.ProPreProcStringify().StripQuotes());
            SetPreprocessedVar("CompilerMultiCompile", CompilerMultiCompile.ToString());
            SetPreprocessedVar("ProVerHigherOrEqualTo11.7", Env.IsProVersionHigherOrEqualTo(new Version(11, 7, 0)).ToString());
            SetPreprocessedVar("CompileOptions", CompileOptions.ProPreProcStringify());
            SetPreprocessedVar("StopOnCompilationError", StopOnCompilationError.ToString());
            SetPreprocessedVar("StopOnCompilationWarning", StopOnCompilationWarning.ToString());
            SetPreprocessedVar("StopOnCompilationReturnErrorCode", UoeConstants.StopOnCompilationReturnErrorCode.ToString());
        }
Example #32
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="volumeManager">Volume manager.</param>
 /// <param name="compilerOptions">Compiler ClI options.</param>
 /// <param name="deployOptions">Deployer ClI options.</param>
 /// <param name="logger">Compiler specific logger.</param>
 public KerboscriptLoader(VolumeManager volumeManager, CompilerLogger logger, CompileOptions compilerOptions)
 {
     _compilerOptions = compilerOptions;
     _volumeManager   = volumeManager;
     _logger          = logger;
 }