diff --git a/UIXC/IrisSourceRepository.cs b/UIXC/IrisSourceRepository.cs new file mode 100644 index 0000000..53d5ec1 --- /dev/null +++ b/UIXC/IrisSourceRepository.cs @@ -0,0 +1,37 @@ +using Errata; +using Microsoft.Iris; +using System.Diagnostics.CodeAnalysis; +namespace UIXC; + +internal class IrisSourceRepository : ISourceRepository +{ + private readonly Dictionary _sourceCache; + + public IrisSourceRepository(CompilerInput[] compilands, CompilerInput? sharedBinaryDataTable) + { + _sourceCache = new(compilands.Length + 1); + + foreach (var compiland in compilands) + { + var id = compiland.SourceFileName; + _sourceCache.Add(id, null); + } + + if (sharedBinaryDataTable?.SourceFileName is not null) + _sourceCache.Add(sharedBinaryDataTable.Value.SourceFileName, null); + } + + public bool TryGet(string id, [NotNullWhen(true)] out Source? source) + { + if (!_sourceCache.TryGetValue(id, out source)) + throw new ArgumentException($"No compiland with ID '{id}' was loaded."); + + if (source is null) + { + var sourceText = File.ReadAllText(id); + source = _sourceCache[id] = new(id, sourceText); + } + + return true; + } +} diff --git a/UIXC/Program.cs b/UIXC/Program.cs new file mode 100644 index 0000000..70faa0b --- /dev/null +++ b/UIXC/Program.cs @@ -0,0 +1,74 @@ +using Errata; +using Microsoft.Iris; +using Microsoft.Iris.Asm; +using Microsoft.Iris.Debug; +using Microsoft.Iris.Markup; +using Microsoft.Iris.Session; +using Spectre.Console; + +namespace UIXC; + +internal class Program +{ + static int Main(string[] args) + { + if (args.Length == 0) + { + AnsiConsole.MarkupLine("[red]Missing arguments: must specify a file to compile. Accepts XML and Asm source.[/]"); + return -1; + } + + // TODO: Use Spectre.Console.Cli + string sourcePath = args[0]; + CompilerInput compiland = new() + { + SourceFileName = sourcePath, + OutputFileName = Path.Combine(Environment.CurrentDirectory, Path.ChangeExtension(sourcePath, ".uib")) + }; + CompilerInput[] compilands = [compiland]; + + // Configure error and warning messages + var report = new Report(new IrisSourceRepository(compilands, default)); + ErrorManager.OnErrors += (errors) => + { + foreach (ErrorRecord error in errors) + { + var l = Math.Max(0, error.Line); + var c = Math.Max(0, error.Column); + var msg = error.Message; + var ctx = error.Context; + + const string compilerError = "Iris error"; + var diagnostic = error.Warning ? Diagnostic.Warning(compilerError) : Diagnostic.Error(compilerError); + + report.AddDiagnostic(diagnostic + .WithCode("UIX0000") + .WithLabel(new(ctx, new Location(l, c), msg)) + ); + } + }; + TraceSettings.Current.SetCategoryLevel(TraceCategory.Markup, byte.MaxValue); + TraceSettings.Current.SetCategoryLevel(TraceCategory.MarkupCompiler, byte.MaxValue); + TraceSettings.Current.OnWriteLine += (line) => + { + AnsiConsole.MarkupLineInterpolated($"[grey]{line}[/]"); + }; + + MarkupSystem.Startup(true); + Assembler.RegisterLoader(); + + // TODO: Support shared binary data tables + var success = MarkupCompiler.Compile(compilands, default); + + if (!success) + { + AnsiConsole.MarkupLine("[red]Compilation failed.[/]"); + return -1; + } + else + { + AnsiConsole.MarkupLine("[green]Compilation finished.[/]"); + return 0; + } + } +} diff --git a/UIXC/UIXC.csproj b/UIXC/UIXC.csproj new file mode 100644 index 0000000..c0dbb0d --- /dev/null +++ b/UIXC/UIXC.csproj @@ -0,0 +1,17 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + diff --git a/ZuneUIXTools.sln b/ZuneUIXTools.sln index 6e35e1d..d42d6c0 100644 --- a/ZuneUIXTools.sln +++ b/ZuneUIXTools.sln @@ -23,7 +23,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{470F14DD-0 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UIX.Asm", "libs\UIX.Asm\UIX.Asm.csproj", "{D311AFFC-CA27-4349-8B01-D5CF0E5FC2B6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UIX.Test", "libs\UIX.Test\UIX.Test.csproj", "{C401799F-64DA-41E2-BC37-BE3C304FAE19}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UIX.Test", "libs\UIX.Test\UIX.Test.csproj", "{C401799F-64DA-41E2-BC37-BE3C304FAE19}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UIXC", "UIXC\UIXC.csproj", "{F918CB09-0AE6-420E-B75C-852C0666483C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -141,6 +143,18 @@ Global {C401799F-64DA-41E2-BC37-BE3C304FAE19}.Release|x64.Build.0 = Release|Any CPU {C401799F-64DA-41E2-BC37-BE3C304FAE19}.Release|x86.ActiveCfg = Release|Any CPU {C401799F-64DA-41E2-BC37-BE3C304FAE19}.Release|x86.Build.0 = Release|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Debug|x64.ActiveCfg = Debug|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Debug|x64.Build.0 = Debug|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Debug|x86.ActiveCfg = Debug|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Debug|x86.Build.0 = Debug|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Release|Any CPU.Build.0 = Release|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Release|x64.ActiveCfg = Release|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Release|x64.Build.0 = Release|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Release|x86.ActiveCfg = Release|Any CPU + {F918CB09-0AE6-420E-B75C-852C0666483C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE