...
This commit is contained in:
36
src/compiler/NubLang.CLI/QBE.cs
Normal file
36
src/compiler/NubLang.CLI/QBE.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace NubLang.CLI;
|
||||
|
||||
public static class QBE
|
||||
{
|
||||
public static async Task<string?> Invoke(string ssa)
|
||||
{
|
||||
using var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo("qbe")
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
process.Start();
|
||||
|
||||
await process.StandardInput.WriteAsync(ssa);
|
||||
process.StandardInput.Close();
|
||||
|
||||
await process.WaitForExitAsync();
|
||||
|
||||
var errors = await process.StandardError.ReadToEndAsync();
|
||||
if (!string.IsNullOrWhiteSpace(errors))
|
||||
{
|
||||
await Console.Error.WriteLineAsync("qbe error:\n" + errors);
|
||||
}
|
||||
|
||||
var asm = await process.StandardOutput.ReadToEndAsync();
|
||||
|
||||
return process.ExitCode == 0 ? asm : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user