Ejemplo n.º 1
0
        /// <summary>
        /// Compiles the added files into a target output appropriate for the output path extension.
        /// </summary>
        /// <param name="type">Package type to generate.</param>
        /// <param name="architecture">Package architecture to generate.</param>
        /// <param name="languages">Package languages to generate.</param>
        /// <param name="outputPath">Path to generate output. Output path file extension determines the output type.</param>
        public void Compile(PackageType type, PackageArchitecture architecture, CultureInfo[] languages, string outputPath)
        {
            FrontendCompiler frontend = new FrontendCompiler(architecture, this.referenceAssemblies);

            frontend.Messages += this.Messages;

            foreach (KeyValuePair <string, string> define in this.PreprocessorDefines)
            {
                frontend.Substitutions.Add(define.Key, define.Value);
            }

            foreach (Swix root in this.roots)
            {
                frontend.AddRoot(root);
            }

            foreach (string path in this.sourceFiles)
            {
                frontend.Parse(path);
            }

            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Resolve();
            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Harvest();
            if (frontend.EncounteredError)
            {
                return;
            }

            Intermediate[] intermediates = frontend.GetIntermediates();

            CompilerFileManager fileManager = this.FileManager ?? new CompilerFileManager();

            fileManager.Architecture = architecture;
            fileManager.Language     = languages.Length == 0 ? null : languages[0];
            fileManager.OutputPath   = outputPath;
            foreach (string searchPath in this.SearchPaths)
            {
                fileManager.SearchPaths.Add(searchPath);
            }

            using (BackendCompiler backend = BackendCompiler.Create(type, outputPath))
            {
                backend.Messages    += this.Messages;
                backend.Architecture = architecture;
                backend.FileManager  = fileManager;
                backend.Languages    = languages;

                backend.Generate(intermediates, outputPath);
            }
        }
Ejemplo n.º 2
0
        public void Compile()
        {
            if (!this.NeedsCompilation)
            {
                return;
            }

            lock (compileLock)
            {
                FrontendCompiler frontend = new FrontendCompiler(PackageArchitecture.Unknown, null);

                List <CompilerMessageEventArgs> compilerMessages = new List <CompilerMessageEventArgs>();
                frontend.Messages += (s, e) => { compilerMessages.Add(e); };

                try
                {
                    // Parse all the files in the set, then resolve and harvest them.
                    this.files.ForEach(file =>
                    {
                        file.Parse(frontend);
                    });
                    frontend.Resolve();
                    frontend.Harvest();
                }
                catch (Exception ex)
                {
                    // create/add message here?
                    System.Diagnostics.Debug.WriteLine("compiler exception: {0}", ex.Message);
                }
                finally
                {
                    // update the messages...
                    this.messages = compilerMessages;

                    // GetIntermediates() returns an array of IEnumerable...
                    // we just want to flatten that to a single list.
                    var newItems = frontend.GetIntermediates().SelectMany(i => i.Items);
                    this.Items = new List <PackageItem>(newItems);

                    this.OnCompileComplete();
                }
            }
        }