private void BuildIR(IRBuildTasks tasks) { var goalLoader = new IRGenerator(Compiler.Context); while (tasks.Inputs.TryDequeue(out GoalScript script)) { using (var stream = new MemoryStream(script.ScriptBody)) { var ast = goalLoader.ParseGoal(script.Path, stream); if (ast != null) { var ir = goalLoader.GenerateGoalIR(ast); ir.Name = script.Name; tasks.IRs.Enqueue(ir); } else { var msg = new Diagnostic(goalLoader.LastLocation, MessageLevel.Error, "X00", $"Could not parse goal file " + script.Name); Logger.CompilationDiagnostic(msg); HasErrors = true; } } } }
private List <IRGoal> ParallelBuildIR() { var tasks = new IRBuildTasks(); foreach (var script in GoalScripts) { tasks.Inputs.Enqueue(script); } IRBuildTasks[] threadTasks = new[] { tasks, tasks, tasks, tasks }; Task.WhenAll(threadTasks.Select(task => Task.Run(() => { BuildIR(task); }))).Wait(); var sorted = new SortedDictionary <string, IRGoal>(); while (tasks.IRs.TryDequeue(out IRGoal goal)) { sorted[goal.Name] = goal; } return(sorted.Values.ToList()); }