Files
MIRROR-LX-OriginalRepo/LX-Build/Main.cs
Pasha Bibko f88c1e0455 Made the outputted .exe be run on built
Outputs the exit code of the process as that is currently the only way to output information with the language.
2025-05-04 13:53:19 +01:00

65 lines
2.0 KiB
C#

using System;
using System.Diagnostics;
namespace LX_Build
{
class Program
{
static void CompileToObj(string inPath, string outPath)
{
// The arguments to compiler LLVM IR to object files //
string arguments = $"-filetype=obj -o \"{outPath}\" \"{inPath}\"";
// Runs the command //
CommandProcess process = new("llc", arguments);
if (process.ExitCode() == 0)
{
Console.WriteLine(inPath + " -> " + outPath);
return;
}
Console.WriteLine(process.Error());
}
static void LinkToExe(string objectFile)
{
// The arguments to turn object files into an .exe //
string arguments = $"/OUT:example/Main.exe {objectFile} /ENTRY:main";
// Runs the command //
CommandProcess process = new("lld-link", arguments);
if (process.ExitCode() == 0)
{
Console.WriteLine(objectFile + " -> " + "Main.exe");
return;
}
Console.WriteLine(process.Error());
}
static void Main()
{
// Initalises the CPP interface, MUST ALWAYS BE CALLED FIRST //
LX_API.Init();
// Generates LLVM IR with the example files //
_ = LX_API.GenIR("example/main.lx", "example/main.ll", "example/log");
// Compilers the LLVM IR to an object file using the command line //
CompileToObj("example/main.ll", "example/main.obj");
// Links the object file to an .exe //
LinkToExe("example/main.obj");
// Runs the outputted .exe //
string command = "example/Main.exe";
CommandProcess exe = new(command);
// Outputs that the program ended with {x} exit code //
Console.WriteLine("\nProcess {Main.exe} finished with exit code: " + exe.ExitCode());
}
}
}