38 lines
1006 B
C#
38 lines
1006 B
C#
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;
|
|
}
|
|
}
|