This commit is contained in:
nub31
2025-06-26 12:53:13 +02:00
parent 34ac247eff
commit e4f052b883
45 changed files with 5562 additions and 0 deletions

37
src/compiler/CLI/QBE.cs Normal file
View File

@@ -0,0 +1,37 @@
using System.Diagnostics;
namespace CLI;
public static class QBE
{
public static async Task<string?> Invoke(string ssa)
{
using var qbeProcess = new Process();
qbeProcess.StartInfo = new ProcessStartInfo
{
FileName = "qbe",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
qbeProcess.Start();
await qbeProcess.StandardInput.WriteAsync(ssa);
qbeProcess.StandardInput.Close();
await qbeProcess.WaitForExitAsync();
var qbeErrors = await qbeProcess.StandardError.ReadToEndAsync();
if (!string.IsNullOrWhiteSpace(qbeErrors))
{
await Console.Error.WriteLineAsync("qbe error:\n" + qbeErrors);
}
var asm = await qbeProcess.StandardOutput.ReadToEndAsync();
return qbeProcess.ExitCode == 0 ? asm : null;
}
}