mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
COMPILES TO EXE
This commit is contained in:
@@ -35,8 +35,6 @@ namespace LX
|
||||
}
|
||||
}
|
||||
|
||||
//int main(int argc, char** argv)
|
||||
|
||||
extern "C" int __declspec(dllexport) GenIR(const char* arg1, const char* arg2, const char* arg3)
|
||||
{
|
||||
// Creates the file paths outside of the try-catch so they can be used in errors //
|
||||
|
||||
47
LX-Build/CommandProcess.cs
Normal file
47
LX-Build/CommandProcess.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LX_Build
|
||||
{
|
||||
internal class CommandProcess
|
||||
{
|
||||
private readonly string m_ErrorMessage;
|
||||
private readonly int m_ExitCode;
|
||||
|
||||
public int ExitCode() => m_ExitCode;
|
||||
|
||||
public string Error() => m_ErrorMessage;
|
||||
|
||||
public CommandProcess(string command)
|
||||
{
|
||||
// Creates a process to run the command //
|
||||
ProcessStartInfo info = new()
|
||||
{
|
||||
FileName = "cmd.exe",
|
||||
Arguments = $"/c {command}",
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
};
|
||||
|
||||
// Starts the process //
|
||||
using Process process = Process.Start(info);
|
||||
|
||||
// Reads the streams of the output //
|
||||
string output = process.StandardOutput.ReadToEnd();
|
||||
string error = process.StandardError.ReadToEnd();
|
||||
|
||||
// Waits for the process to exit //
|
||||
process.WaitForExit();
|
||||
|
||||
// Assigns output of the error for external access //
|
||||
m_ExitCode = process.ExitCode;
|
||||
m_ErrorMessage = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,8 @@ namespace LX_Build
|
||||
private static partial bool SetDllDirectory(string lpPathName);
|
||||
|
||||
// Imports the Frontend of the compiler //
|
||||
[LibraryImport("Generator.dll", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
|
||||
[LibraryImport ("Generator.dll", StringMarshalling = StringMarshalling.Custom,
|
||||
StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int GenIR(string arg1, string arg2, string? arg3);
|
||||
|
||||
|
||||
@@ -1,16 +1,57 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace LX_Build
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
static void CompileToObj(string inPath, string outPath)
|
||||
{
|
||||
// Initalises the CPP interface //
|
||||
// The command to compile the IR to .obj //
|
||||
string command = $"llc -filetype=obj -o \"{outPath}\" \"{inPath}\"";
|
||||
|
||||
// Runs the command //
|
||||
CommandProcess process = new(command);
|
||||
|
||||
if (process.ExitCode() == 0)
|
||||
{
|
||||
Console.WriteLine(inPath + " -> " + outPath);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(process.Error());
|
||||
}
|
||||
|
||||
static void LinkToExe(string objectFile)
|
||||
{
|
||||
// The command to link the object file to an .exe //
|
||||
string command = $"lld-link /OUT:example/Main.exe {objectFile} /ENTRY:main";
|
||||
|
||||
// Runs the command //
|
||||
CommandProcess process = new(command);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Generator", "IR-Generator\I
|
||||
{D6EAFB31-4AFD-4989-9522-D6609AC4ED64} = {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Linker", "Linker\Linker.vcxproj", "{043AFDA7-5AC5-4DD2-ACA8-029051E72961}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Backend-Modules", "Backend-Modules", "{E45BA655-FA9A-412B-BCD8-7F85E94859B8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LX-Build", "LX-Build\LX-Build.csproj", "{DE9DB560-F002-4922-98E6-558C3D04C607}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961} = {043AFDA7-5AC5-4DD2-ACA8-029051E72961}
|
||||
{C88042E2-0E09-4383-93F8-C79F9EE1E897} = {C88042E2-0E09-4383-93F8-C79F9EE1E897}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
@@ -71,18 +66,6 @@ Global
|
||||
{C88042E2-0E09-4383-93F8-C79F9EE1E897}.Release|x64.Build.0 = Release|x64
|
||||
{C88042E2-0E09-4383-93F8-C79F9EE1E897}.Release|x86.ActiveCfg = Release|Win32
|
||||
{C88042E2-0E09-4383-93F8-C79F9EE1E897}.Release|x86.Build.0 = Release|Win32
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Debug|x64.Build.0 = Debug|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Debug|x86.Build.0 = Debug|Win32
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Release|Any CPU.Build.0 = Release|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Release|x64.ActiveCfg = Release|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Release|x64.Build.0 = Release|x64
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Release|x86.ActiveCfg = Release|Win32
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961}.Release|x86.Build.0 = Release|Win32
|
||||
{DE9DB560-F002-4922-98E6-558C3D04C607}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DE9DB560-F002-4922-98E6-558C3D04C607}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DE9DB560-F002-4922-98E6-558C3D04C607}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
@@ -103,7 +86,6 @@ Global
|
||||
{4E4019F5-12E0-4EE2-9658-A0DD3038EEDA} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{D6EAFB31-4AFD-4989-9522-D6609AC4ED64} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{C88042E2-0E09-4383-93F8-C79F9EE1E897} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{043AFDA7-5AC5-4DD2-ACA8-029051E72961} = {E45BA655-FA9A-412B-BCD8-7F85E94859B8}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {411AFEC9-4075-4FCC-B95A-9288BC822E90}
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{043afda7-5ac5-4dd2-aca8-029051e72961}</ProjectGuid>
|
||||
<RootNamespace>Linker</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)bin\inter\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)bin\inter\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user