public override CompileResult Compile(IConsole console, IStandardProject superProject, IStandardProject project,
ISourceFile file, string outputFile)
{
var result = new CompileResult();
if (Path.GetExtension(file.FilePath) == ".cs")
{
CompileCS(console, superProject, project, file, outputFile);
TransformMSIL(console, superProject, project, file, outputFile);
CompileLLVMIR(console, superProject, project, file, outputFile + ".bc", outputFile);
}
else if (Path.GetExtension(file.FilePath) == ".cpp" || Path.GetExtension(file.FilePath) == ".c")
{
var startInfo = new ProcessStartInfo();
if (file.Extension == ".cpp")
{
startInfo.FileName = Path.Combine(BaseDirectory, "GCC\\bin", "arm-none-eabi-g++.exe");
}
else
{
startInfo.FileName = Path.Combine(BaseDirectory, "GCC\\bin", "arm-none-eabi-gcc.exe");
}
startInfo.WorkingDirectory = project.Solution.CurrentDirectory;
if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName))
{
result.ExitCode = -1;
console.WriteLine("Unable to find compiler (" + startInfo.FileName + ") Please check project compiler settings.");
}
else
{
var fileArguments = string.Empty;
if (file.Extension == ".cpp")
{
fileArguments = "-x c++ -std=c++14 -fno-use-cxa-atexit";
}
startInfo.Arguments = string.Format("{0} {1} {2} -o{3} -MMD -MP", GetCompilerArguments(superProject, project, file),
fileArguments, file.Location, outputFile);
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
//console.WriteLine (Path.GetFileNameWithoutExtension(startInfo.FileName) + " " + startInfo.Arguments);
using (var process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) => { console.WriteLine(e.Data); };
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
console.WriteLine();
console.WriteLine(e.Data);
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
result.ExitCode = process.ExitCode;
}
}
}
return result;
}