More analysis code changes

This commit is contained in:
Adrian Conlon
2024-10-10 00:11:55 +01:00
parent 4cd689350e
commit 5c71acc40a
8 changed files with 49 additions and 102 deletions

View File

@@ -12,43 +12,25 @@
: base(container)
{ }
private bool MaybeExtractFromParsed(string key, out string value)
private bool MaybeExtractFromParsed(string key, out string? value)
{
Debug.Assert(this._parsed != null);
var found = this._parsed.TryGetValue(key, out var extracted);
if (found)
{
Debug.Assert(extracted != null);
value = extracted;
}
else
{
value = string.Empty;
}
value = extracted;
return found;
}
private bool MaybeExtractIntegerFromParsed(string key, out int value)
{
var available = this.MaybeExtractFromParsed(key, out var extracted);
if (!available)
{
value = 0;
return false;
}
value = ExtractInteger(extracted);
value = extracted == null ? 0 : ExtractInteger(extracted);
return available;
}
protected bool MaybeExtractCompoundInteger(string key, out List<int> value)
{
var available = this.MaybeExtractFromParsed(key, out var extracted);
if (!available)
{
value = [];
return false;
}
value = ExtractCompoundInteger(extracted);
value = extracted == null ? [] : ExtractCompoundInteger(extracted);
return available;
}

View File

@@ -4,34 +4,34 @@
[M6502.Symbols.Section("info")]
public sealed class Information(Parser container) : Section(container)
{
[M6502.Symbols.SectionProperty("csym")]
[SectionProperty("csym")]
public int CSymbol { get; private set; }
[M6502.Symbols.SectionProperty("file")]
[SectionProperty("file")]
public int File { get; private set; }
[M6502.Symbols.SectionProperty("lib")]
[SectionProperty("lib")]
public int Library { get; private set; }
[M6502.Symbols.SectionProperty("line")]
[SectionProperty("line")]
public int Line { get; private set; }
[M6502.Symbols.SectionProperty("mod")]
[SectionProperty("mod")]
public int Module { get; private set; }
[M6502.Symbols.SectionProperty("scope")]
[SectionProperty("scope")]
public int Scope { get; private set; }
[M6502.Symbols.SectionProperty("seg")]
[SectionProperty("seg")]
public int Segment { get; private set; }
[M6502.Symbols.SectionProperty("span")]
[SectionProperty("span")]
public int Span { get; private set; }
[M6502.Symbols.SectionProperty("sym")]
[SectionProperty("sym")]
public int Symbol { get; private set; }
[M6502.Symbols.SectionProperty("type")]
[SectionProperty("type")]
public int Type { get; private set; }
public int Count(string key) => this.GetValueT<int>(key);

View File

@@ -282,7 +282,7 @@
private void VerifyInformationCount(string key, int actual)
{
Debug.Assert(this._information != null);
var expected = this._information?.Count(key);
var expected = this._information.Count(key);
if (expected != actual)
{
throw new InvalidOperationException($"information count mismatch for {key}. Expected {expected}, actual {actual}");
@@ -316,7 +316,7 @@
}
using var reader = new StreamReader(path);
await this.ParseAsync(reader);
await this.ParseAsync(reader).ConfigureAwait(false);
this.ExtractSections();
this.ExtractReferences();
@@ -330,7 +330,7 @@
{
while (!reader.EndOfStream)
{
var line = await reader.ReadLineAsync();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line == null)
{
break;
@@ -408,8 +408,8 @@
throw new InvalidOperationException("Version has not yet been parsed");
}
var major = this._version?.Major;
var minor = this._version?.Minor;
var major = this._version.Major;
var minor = this._version.Minor;
var valid = major == 2 && minor == 0;
if (!valid)
{

View File

@@ -154,7 +154,7 @@
if (attribute is SectionReferenceAttribute)
{
this.ReferenceAttributes.Add(key, new Tuple<string, System.Type>(name, originalType));
} else if (attribute is SectionReferencesAttribute referencesAttribute)
} else if (attribute is SectionReferencesAttribute)
{
this.ReferencesAttributes.Add(key, new Tuple<string, System.Type>(name, originalType));
}

View File

@@ -1,7 +1,7 @@
namespace M6502.Symbols
{
[AttributeUsage(AttributeTargets.Class)]
internal class SectionAttribute(string key, string? referencing = null) : Attribute
internal sealed class SectionAttribute(string key, string? referencing = null) : Attribute
{
public string Key { get; private set; } = key;

View File

@@ -27,7 +27,7 @@ namespace M6502.Test
private bool keyHandled;
private bool keyAvailable;
private bool inputting = false;
private bool inputting;
public Board(Configuration configuration)
{

View File

@@ -7,22 +7,13 @@ namespace M6502.Test
using System;
using System.Diagnostics;
internal class TestHarness(Configuration configuration) : IDisposable
internal sealed class TestHarness(Configuration configuration)
{
private readonly Process process = Process.GetCurrentProcess();
private readonly Stopwatch timer = new();
private readonly Board board = new(configuration);
private long totalCycles = 0;
private long totalCycles;
private TimeSpan totalUserProcessorTime;
private bool disposed = false;
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
public long ElapsedMilliseconds => this.timer.ElapsedMilliseconds;
public float ElapsedSeconds => this.ElapsedMilliseconds / 1000.0f;
@@ -31,40 +22,32 @@ namespace M6502.Test
public void Run()
{
this.timer.Start();
var startingUsage = this.process.UserProcessorTime;
this.board.Initialize();
this.board.RaisePOWER();
var cpu = this.board.CPU;
while (cpu.Powered)
using var process = Process.GetCurrentProcess();
{
this.totalCycles += cpu.Step();
}
this.timer.Start();
var startingUsage = process.UserProcessorTime;
var finishingUsage = this.process.UserProcessorTime;
this.timer.Stop();
this.totalUserProcessorTime = finishingUsage - startingUsage;
}
this.board.Initialize();
this.board.RaisePOWER();
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
var cpu = this.board.CPU;
while (cpu.Powered)
{
System.Console.Out.WriteLine();
System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles:N0}");
System.Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}");
System.Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz");
System.Console.Out.WriteLine($"Processor time = {this.totalUserProcessorTime.TotalSeconds:g}");
this.totalCycles += cpu.Step();
}
this.disposed = true;
var finishingUsage = process.UserProcessorTime;
this.timer.Stop();
this.totalUserProcessorTime = finishingUsage - startingUsage;
}
System.Console.Out.WriteLine();
System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles:N0}");
System.Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}");
System.Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz");
System.Console.Out.WriteLine($"Processor time = {this.totalUserProcessorTime.TotalSeconds:g}");
}
}
}

View File

@@ -7,20 +7,13 @@ namespace Z80.Test
using System;
using System.Diagnostics;
internal class TestHarness(Configuration configuration) : IDisposable
internal class TestHarness(Configuration configuration)
{
private readonly Stopwatch timer = new();
private readonly Board board = new(configuration);
private long totalCycles;
private TimeSpan totalUserProcessorTime;
private bool disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public long ElapsedMilliseconds => timer.ElapsedMilliseconds;
public float ElapsedSeconds => ElapsedMilliseconds / 1000.0f;
@@ -47,25 +40,14 @@ namespace Z80.Test
timer.Stop();
totalUserProcessorTime = finishingUsage - startingUsage;
}
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
System.Console.Out.WriteLine();
System.Console.Out.WriteLine();
System.Console.Out.WriteLine($"Guest cycles = {totalCycles:N0}");
System.Console.Out.WriteLine($"Seconds = {ElapsedSeconds}");
System.Console.Out.WriteLine($"Guest cycles = {totalCycles:N0}");
System.Console.Out.WriteLine($"Seconds = {ElapsedSeconds}");
System.Console.Out.WriteLine($"{CyclesPerSecond / 1000000} MHz");
System.Console.Out.WriteLine($"Processor time = {totalUserProcessorTime.TotalSeconds:g}");
}
disposed = true;
}
System.Console.Out.WriteLine($"{CyclesPerSecond / 1000000} MHz");
System.Console.Out.WriteLine($"Processor time = {totalUserProcessorTime.TotalSeconds:g}");
}
}
}