public CompilationResult(CompilationStatus status, IEnumerable <CompilationMessage> messages)
 {
     Status = status;
     //This should really not be needed and just accept a IReadonlyCollecection
     //but for some reason C# belives nothing implements IReadonlyCollection...
     Messages = messages.ToList().AsReadOnly();
 }
 public void SendStatusNotification(TextDocumentItem textDocument, CompilationStatus status)
 {
     languageServer.SendNotification(new CompilationStatusParams {
         Uri     = textDocument.Uri,
         Version = textDocument.Version,
         Status  = status
     });
 }
        private void Abort(CompilationStatus errCode, int nErrPosition, int nErrLen)
        {
            _validationInfo.ErrorCode    = errCode;
            _validationInfo.ErrorStartAt = nErrPosition;
            _validationInfo.ErrorLength  = nErrLen;

            throw new Exception("A Syntex error occured.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Compiles the specified source GLSL450 code to a Vulkan SPIR-V binary.
        /// </summary>
        /// <param name="source">GLSL450 source code.</param>
        /// <param name="kind">Shader type.</param>
        /// <param name="entry">Main entry point function name.</param>
        /// <returns>An instance of <see cref="CompileResult"/> struct containing the compilation result.</returns>
        public CompileResult CompileToSpirV(string source, ShaderKind kind, string entry)
        {
            // - Executes extern library compilation and takes the result as a pointer
            IntPtr result = shaderc_compile_into_spv(pHandle, source, source.Length, kind, "", entry, IntPtr.Zero);

            // - Gets the compilation status and metadata
            CompilationStatus status = shaderc_result_get_compilation_status(result);
            uint errors   = shaderc_result_get_num_errors(result);
            uint warnings = shaderc_result_get_num_warnings(result);

            if (status != CompilationStatus.Success)
            {
                switch (status)
                {
                case CompilationStatus.InternalError:
                case CompilationStatus.CompilationError:
                    return(new CompileResult
                    {
                        WarningCount = warnings,
                        ErrorCount = errors,
                        Errors = shaderc_result_get_error_message(result),
                        Status = status,
                        Binary = new uint[] { }
                    });

                default:
                    throw new Exception("Unknow error");
                }
            }

            // - Gets the result's binary size
            uint binarySize = shaderc_result_get_length(result);

            // - Prepare output binary
            byte[] binary  = new byte[binarySize];
            uint[] outCode = new uint[binarySize / 4];

            // - Gets shader data from the compiler
            IntPtr bytes = shaderc_result_get_bytes(result);

            // - Copy shader binary to a managed array
            Marshal.Copy(bytes, binary, 0, (int)binarySize);
            Buffer.BlockCopy(binary, 0, outCode, 0, (int)binarySize);

            // - Release result resources
            shaderc_result_release(result);

            return(new CompileResult
            {
                WarningCount = warnings,
                ErrorCount = errors,
                Errors = "",
                Status = status,
                Binary = outCode
            });
        }
Exemplo n.º 5
0
        private CompilationStatus ExecuteCompilation(string code)
        {
            CompilationStatus c = new CompilationStatus();

            try{
                c.javaScriptCode = _jsContext.Run(code);
            }
            catch (System.Exception ex) {
                c.ex = ex;
            }
            return(c);
        }
Exemplo n.º 6
0
        private void UpdateValidationInfo(ValidationInfo vi)
        {
            if (vi.ErrorCode == CompilationStatus.SUCCESS)
            {
                _matchAtEnd   = vi.MatchAtEnd;
                _matchAtStart = vi.MatchAtStart;
            }

            _lastCompilationStatus = vi.ErrorCode;
            _lastErrorIndex        = vi.ErrorStartAt;
            _lastErrorLength       = vi.ErrorLength;
        }
Exemplo n.º 7
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            CompilationStatus status = (CompilationStatus)value;

            switch (status)
            {
            default:
                return(Uncompiled);

            case CompilationStatus.Successful:
                return(Successful);

            case CompilationStatus.Failed:
                return(Failed);
            }
        }
Exemplo n.º 8
0
        static void ApplyPluginsToAst(ref Microsoft.CodeAnalysis.SyntaxTree syntaxTree, CompilationOptions options, Stencil stencil, ref CompilationResult result)
        {
            Profiler.BeginSample("Code Analysis");

            // run all the syntactic code analyzers
            CompilationStatus status = CompilationStatus.Succeeded;

            result.pluginSourceCode = new Dictionary <Type, string>();

            foreach (IRoslynPluginHandler handler in stencil.GetCompilationPluginHandlers(options).OfType <IRoslynPluginHandler>())
            {
                handler.Apply(ref syntaxTree, options);
                result.pluginSourceCode[handler.GetType()] = syntaxTree.GetText().ToString();
            }
            result.status = status;
            Profiler.EndSample();
        }
 public AssetProcessingResult(CompilationStatus status, string result = null, string message = null)
 {
     this.Status  = status;
     this.Result  = result;
     this.Message = message;
 }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="configuration">Paths to source code, referenced assemblies and compiler directives</param>
        /// <returns>Any resulting errors, logs and executables.</returns>
        public static CompilationResult Compile(CrawlCompilerConfiguration configuration)
        {
            TextWriter output = Utils.GetPrimaryOutputStream(configuration);
            //TraceListners.AssemblyResolverListner =
            //    new System.Diagnostics.TextWriterTraceListener(Utils.GetPrimaryOutputStream(configuration));

            //From referenced files, build list of existing namespaces
            ConcurrentDictionary <string, Namespace> allNamespaces = NamespaceLoader.LoadAll(configuration.Assemblies);

            allNamespaces.MergeInto(Namespace.BuiltinNamespace.AsSingleIEnumerable());

            //Set up logging and status
            SideeffectHelper  sideeffectHelper = new SideeffectHelper();
            CompilationStatus status           = CompilationStatus.Success;

            try
            {
                //single line comments with /* */ are referering to a stage in general_archtechture.md


                bool parallel = !configuration.ForceSingleThreaded;

                //The ConcurrentBag is an unordered, thread safe, collection
                ConcurrentBag <AstData> parsedFiles = Run <AstData, string>(configuration.Files, parallel, sideeffectHelper,
                                                                            (destination, helper) =>
                {
                    //Syntax is slightly wonky, but cannot assign variable to method group.
                    //_Could_ be hidden in ParsePipeline by making them properties instead....

                    //Get the starting transformaton
                    /* Create parse tree */
                    Func <string, SideeffectHelper, ParseTreeData> parsePT = ParsePipeline.ReadFileToPt;

                    //Jump out if we are intrested in earlier stage.
                    if (configuration.TargetStage == TargetStage.ParseTree)
                    {
                        return(parsePT.EndWith(output.WriteLine, helper));
                    }

                    /* Create AST */
                    var parseASt = parsePT
                                   .Then(ParsePipeline.CreateAst); //.Then adds another stage

                    if (configuration.TargetStage == TargetStage.AbstractSyntaxTree)
                    {
                        return(parseASt.EndWith(output.WriteLine, helper));
                    }

                    /* Collect types*/
                    var firstscopepass = parseASt.Then(SemanticAnalysisPipeline.CollectTypes);

                    //.EndWith collects it
                    return(firstscopepass.EndWith(destination.Add, helper));
                }
                                                                            );

                MaybeDie(sideeffectHelper);
                /* Merge type tables */
                foreach (AstData file in parsedFiles)
                {
                    TranslationUnitNode node          = (TranslationUnitNode)file.Tree.RootNode;
                    Namespace           exportedTypes = new Namespace(node.Namespace.Module, node.Code.Scope.Classes());

                    allNamespaces.MergeInto(exportedTypes.AsSingleIEnumerable());
                }

                //TODO: finish Semantic analysis
                ConcurrentBag <AstData> filesWithScope = Run <AstData, AstData>(parsedFiles, parallel, sideeffectHelper,
                                                                                (destination, helper) =>
                {
                    /* Find visible namespace*/
                    //NamespaceDecorator is a hack to pass all namespaces in to the function that finds the relevant ones
                    Func <AstData, SideeffectHelper, AstData> first = new SemanticAnalysisPipeline.NamespaceDecorator(allNamespaces).AddExport;

                    return(first
                           /* Decorate TypeNode */
                           .Then(SemanticAnalysisPipeline.PutTypes)
                           /* Collect remaining scope information */
                           .Then(SemanticAnalysisPipeline.SecondScopePass)
                           /* Finish types */
                           .Then(SemanticAnalysisPipeline.FinishTypes)
                           .EndWith(destination.Add, helper));
                }
                                                                                );

                //TODO: Merge namespaces again with extra (Methods/Variables) from scope. Right now, only classes are visible
                //in other files

                ConcurrentBag <AstData> decoratedAsts = Run <AstData, AstData>(filesWithScope, parallel, sideeffectHelper,
                                                                               (destination, helper) =>
                {
                    /* scope check */
                    Func <AstData, SideeffectHelper, AstData> first = SemanticAnalysisPipeline.DeclerationOrderCheck;
                    var final = first
                                .Then(SemanticAnalysisPipeline.TypeCheck)
                                .EndWith(destination.Add, helper); //Typechecker would be added here or line above

                    return(final);
                }
                                                                               );

                ConcurrentBag <AstData> optimizedAsts = Run <AstData, AstData>(decoratedAsts, parallel, sideeffectHelper,
                                                                               (destination, helper) =>
                {
                    Func <AstData, SideeffectHelper, AstData> first = OptimizationPipeline.FoldConstants;
                    var final = first
                                .Then(OptimizationPipeline.RefWherePossible)
                                .EndWith(destination.Add, helper);

                    return(final);
                }
                                                                               );
                //TODO: Interpeter or code generation

                //Until meaningfull end, print everything

                Execute(decoratedAsts, output.WriteLine, parallel);
                output.WriteLine("\n===Optimized To===>\n");
                Execute(optimizedAsts, output.WriteLine, parallel);

                if (sideeffectHelper.CompilationMessages.Count(message => message.Severity >= MessageSeverity.Error) > 0)
                {
                    status = CompilationStatus.Failure;
                }
            }
            catch (ExitCompilationException)
            { status = CompilationStatus.Failure; }
            catch (Exception e) when(false && !Debugger.IsAttached)
            {
                sideeffectHelper.CompilationMessages.Add(CompilationMessage.CreateNonCodeMessage(MessageCode.InternalCompilerError, e.ToString(), MessageSeverity.Fatal));
                status = CompilationStatus.Failure;
            }

            return(new CompilationResult(status, sideeffectHelper.CompilationMessages));
        }
Exemplo n.º 11
0
        private CompilationStatus ExecuteCompilation(string code){            

            CompilationStatus c = new CompilationStatus();
            try{                
                c.javaScriptCode = _jsContext.Run(code);                
            }
            catch(System.Exception ex){                
                c.ex = ex;                
            }            
            return c;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompilationCompletedEventArgs"/> class.
 /// </summary>
 public CompilationCompletedEventArgs(string filePath, CompilationStatus status, List <string> errors)
 {
     File   = filePath;
     Status = status;
     Errors = errors;
 }