mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Begin UIX compiler CLI
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
using Errata;
|
||||||
|
using Microsoft.Iris;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
namespace UIXC;
|
||||||
|
|
||||||
|
internal class IrisSourceRepository : ISourceRepository
|
||||||
|
{
|
||||||
|
private readonly Dictionary<string, Source?> _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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Errata" Version="0.13.0" />
|
||||||
|
<PackageReference Include="Spectre.Console" Version="0.48.0" />
|
||||||
|
<ProjectReference Include="..\libs\MicrosoftIris\UIX\UIX.csproj" />
|
||||||
|
<ProjectReference Include="..\libs\UIX.Asm\UIX.Asm.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
+15
-1
@@ -23,7 +23,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{470F14DD-0
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UIX.Asm", "libs\UIX.Asm\UIX.Asm.csproj", "{D311AFFC-CA27-4349-8B01-D5CF0E5FC2B6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UIX.Asm", "libs\UIX.Asm\UIX.Asm.csproj", "{D311AFFC-CA27-4349-8B01-D5CF0E5FC2B6}"
|
||||||
EndProject
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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|x64.Build.0 = Release|Any CPU
|
||||||
{C401799F-64DA-41E2-BC37-BE3C304FAE19}.Release|x86.ActiveCfg = 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
|
{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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user