From 7ba78a830bf9a6349572c14fe5c1b579ab351e72 Mon Sep 17 00:00:00 2001 From: Adrian Conlon <98398945+AdrianConlon@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:12:19 +0100 Subject: [PATCH] First stab at asynchronous sysmbols parsing --- M6502/M6502.Symbols/Parser.cs | 36 +++++++++++++++++++++-------------- M6502/M6502.Test/Board.cs | 14 +++++++++----- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/M6502/M6502.Symbols/Parser.cs b/M6502/M6502.Symbols/Parser.cs index 3bd51eb..564603c 100644 --- a/M6502/M6502.Symbols/Parser.cs +++ b/M6502/M6502.Symbols/Parser.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Frozen; using System.Diagnostics; + using System.Threading.Tasks; public sealed class Parser { @@ -329,7 +330,7 @@ #region Parser driver - public void Parse(string? path) + public async Task ParseAsync(string? path) { if (this.Parsed) { @@ -342,24 +343,19 @@ } using var reader = new StreamReader(path); - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - if (line == null) - { - break; - } + await this.ParseAsync(reader); + } - this.ParseLine(line.Split(' ', '\t')); - } + private async Task ParseAsync(StreamReader reader) + { + await this.ParseLinesAsync(reader); this.FreezeParsedData(); // Intermediate data no longer needed // Only "frozen" parsed data is needed. -#if DEBUG this._parsed_intermediate.Clear(); -#endif + this.ExtractFiles(); this.ExtractLines(); this.ExtractModules(); @@ -370,9 +366,7 @@ this.ExtractTypes(); // Frozen parsed data is no longer needed -#if DEBUG this._parsed = null; -#endif // We are now mostly parsed this.Parsed = true; @@ -381,6 +375,20 @@ this.BuildAddressableScopes(); } + private async Task ParseLinesAsync(StreamReader reader) + { + while (!reader.EndOfStream) + { + var line = await reader.ReadLineAsync(); + if (line == null) + { + break; + } + + this.ParseLine(line.Split(' ', '\t')); + } + } + private void FreezeParsedData() { var intermediateSections = new Dictionary>>(this._parsed_intermediate.Count); diff --git a/M6502/M6502.Test/Board.cs b/M6502/M6502.Test/Board.cs index 03a02d6..4ff3e16 100644 --- a/M6502/M6502.Test/Board.cs +++ b/M6502/M6502.Test/Board.cs @@ -7,6 +7,7 @@ namespace M6502.Test using System.Diagnostics; using System.Globalization; using System.Text; + using System.Threading.Tasks; using EightBit; internal class Board : Bus @@ -61,6 +62,12 @@ namespace M6502.Test public override void Initialize() { + Task? symbolsParserTask = null; + if (this.configuration.Profile || this.configuration.DebugMode) + { + symbolsParserTask = this.symbols.ParseAsync(string.IsNullOrEmpty(this.configuration.Symbols) ? string.Empty : this.configuration.RomDirectory + "/" + this.configuration.Symbols); + } + var programPath = this.configuration.RomDirectory + "/" + this.configuration.Program; var loadAddress = this.configuration.LoadAddress; this.ram.Load(programPath, loadAddress.Word); @@ -80,11 +87,6 @@ namespace M6502.Test this.CPU.ExecutedInstruction += this.CPU_ExecutedInstruction; this.WrittenByte += this.Bus_WrittenByte; - if (this.configuration.Profile || this.configuration.DebugMode) - { - this.symbols.Parse(string.IsNullOrEmpty(this.configuration.Symbols) ? string.Empty : this.configuration.RomDirectory + "/" + this.configuration.Symbols); - } - if (this.configuration.Profile) { this.profiler.StartingOutput += this.Profiler_StartingOutput; @@ -102,6 +104,8 @@ namespace M6502.Test this.Poke(0x00, 0x4c); this.CPU.PokeWord(0x01, this.configuration.StartAddress); + + symbolsParserTask?.Wait(); } public override MemoryMapping Mapping(ushort absolute) => this.mapping;