示例#1
0
        public Compiler(Types types, Frontend.Result fres)
        {
            this.types = types;
            module     = fres.module;
            ast        = fres.ast;
            curr_scope = module.symbols;

            UseInit();
        }
示例#2
0
 public Frontend.Result Patch(Frontend.Result fres, string src_file)
 {
     return(fres);
 }
示例#3
0
            public static void DoWork(object data)
            {
                var sw = new Stopwatch();

                sw.Start();

                var w = (CompilerWorker)data;

                w.file2path.Clear();
                w.file2compiled.Clear();

                var imp = new Frontend.Importer();

                imp.SetParsedCache(w.cache);
                imp.AddToIncludePath(w.inc_dir);

                int i = w.start;

                int cache_hit  = 0;
                int cache_miss = 0;

                try
                {
                    for (int cnt = 0; i < (w.start + w.count); ++i, ++cnt)
                    {
                        var file = w.files[i];

                        var compiled_file = GetCompiledCacheFile(w.cache_dir, file);
                        var file_module   = new Module(w.ts.globs, imp.FilePath2ModuleName(file), file);

                        InterimResult interim;
                        if (w.cache.file2interim.TryGetValue(file, out interim) &&
                            interim.use_file_cache)
                        {
                            ++cache_hit;

                            w.file2path.Add(file, file_module.path);
                            //TODO: load from the cached file?
                            //w.file2symbols.Add(file, ...);
                        }
                        else
                        {
                            ++cache_miss;

                            Frontend.Result front_res = null;

                            if (interim.parsed != null)
                            {
                                front_res = Frontend.ProcessParsed(file_module, interim.parsed, w.ts, imp);
                            }
                            else
                            {
                                front_res = Frontend.ProcessFile(file, w.ts, imp);
                            }

                            front_res = w.postproc.Patch(front_res, file);

                            w.file2path.Add(file, file_module.path);
                            w.file2symbols.Add(file, front_res.module.symbols);

                            var c  = new Compiler(w.ts, front_res);
                            var cm = c.Compile();
                            CompiledModule.ToFile(cm, compiled_file);
                        }

                        w.file2compiled.Add(file, compiled_file);
                    }
                }
                catch (Exception e)
                {
                    if (e is IError)
                    {
                        w.error = e;
                    }
                    else
                    {
                        //let's log unexpected exceptions immediately
                        Console.Error.WriteLine(e.Message + " " + e.StackTrace);
                        w.error = new BuildError(w.files[i], e);
                    }
                }

                sw.Stop();
                Console.WriteLine("BHL compiler {0} done(hit/miss:{2}/{3}, {1} sec)", w.id, Math.Round(sw.ElapsedMilliseconds / 1000.0f, 2), cache_hit, cache_miss);
            }