...
This commit is contained in:
37
src/compiler/CLI/QBE.cs
Normal file
37
src/compiler/CLI/QBE.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user