From cb26d373ae2ade33fb71f9d1f5791537fd13b40d Mon Sep 17 00:00:00 2001 From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com> Date: Sat, 3 May 2025 17:04:37 +0100 Subject: [PATCH] Added C# project for calling the different modules --- .gitignore | 5 + IR-Generator/IR-Generator.vcxproj | 7 +- IR-Generator/IR-Generator.vcxproj.filters | 2 +- IR-Generator/IR-Generator.vcxproj.user | 6 +- IR-Generator/src/{main.cpp => Generator.cpp} | 35 +---- LX-Build/LX-API.cs | 26 ++++ LX-Build/LX-Build.csproj | 12 ++ LX-Build/Main.cs | 16 +++ LX-Build/Properties/launchSettings.json | 8 ++ LX-Compiler.sln | 51 ++++++- Linker/Linker.vcxproj | 144 +++++++++++++++++++ Linker/Linker.vcxproj.filters | 13 ++ Linker/Linker.vcxproj.user | 4 + example/main.lx | 11 +- 14 files changed, 295 insertions(+), 45 deletions(-) rename IR-Generator/src/{main.cpp => Generator.cpp} (86%) create mode 100644 LX-Build/LX-API.cs create mode 100644 LX-Build/LX-Build.csproj create mode 100644 LX-Build/Main.cs create mode 100644 LX-Build/Properties/launchSettings.json create mode 100644 Linker/Linker.vcxproj create mode 100644 Linker/Linker.vcxproj.filters create mode 100644 Linker/Linker.vcxproj.user diff --git a/.gitignore b/.gitignore index 72115f6..2584030 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ x64/ .vs/ +# Ignore build directories # + +bin/ +obj/ + # Ignore runtime outputs # *.ll diff --git a/IR-Generator/IR-Generator.vcxproj b/IR-Generator/IR-Generator.vcxproj index 8db02db..760a044 100644 --- a/IR-Generator/IR-Generator.vcxproj +++ b/IR-Generator/IR-Generator.vcxproj @@ -24,6 +24,7 @@ {c88042e2-0e09-4383-93f8-c79f9ee1e897} IRGenerator 10.0 + Generator @@ -40,13 +41,13 @@ Unicode - Application + DynamicLibrary true v143 Unicode - Application + DynamicLibrary false v143 true @@ -144,7 +145,7 @@ - + diff --git a/IR-Generator/IR-Generator.vcxproj.filters b/IR-Generator/IR-Generator.vcxproj.filters index 5107377..9beeead 100644 --- a/IR-Generator/IR-Generator.vcxproj.filters +++ b/IR-Generator/IR-Generator.vcxproj.filters @@ -11,7 +11,7 @@ - + Source Files diff --git a/IR-Generator/IR-Generator.vcxproj.user b/IR-Generator/IR-Generator.vcxproj.user index 0b615f4..4fd003e 100644 --- a/IR-Generator/IR-Generator.vcxproj.user +++ b/IR-Generator/IR-Generator.vcxproj.user @@ -1,12 +1,14 @@  - example/main.lx example/main.ll example/log + + WindowsLocalDebugger $(SolutionDir) - example/main.lx example/main.ll example/log + + WindowsLocalDebugger $(SolutionDir) diff --git a/IR-Generator/src/main.cpp b/IR-Generator/src/Generator.cpp similarity index 86% rename from IR-Generator/src/main.cpp rename to IR-Generator/src/Generator.cpp index d959dfa..7d73367 100644 --- a/IR-Generator/src/main.cpp +++ b/IR-Generator/src/Generator.cpp @@ -35,7 +35,9 @@ namespace LX } } -int main(int argc, char** argv) +//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 // std::filesystem::path inpPath; @@ -51,12 +53,9 @@ int main(int argc, char** argv) try { - // Checks there is the correct ammount of arguments // - LX::ThrowIf((argc == 3 || argc == 4) == false); - // Turns the file paths into the C++ type for handling them // - inpPath = argv[1]; - outPath = argv[2]; + inpPath = arg1; + outPath = arg2; // Checks the input file exists and opens it // LX::ThrowIf(std::filesystem::exists(inpPath) == false); @@ -75,9 +74,9 @@ int main(int argc, char** argv) outFile.close(); // Opened just to check we can // Opens the log file (if there is one specified // - if (argc == 4) + if (arg3 != nullptr) { - logPath = argv[3]; + logPath = arg3; log = std::make_unique(logPath); LX::ThrowIf(log->is_open() == false); } @@ -101,26 +100,6 @@ int main(int argc, char** argv) return 0; } - catch (LX::IncorrectCommandLineArgs) - { - // Prints out how to correctly use the program // - LX::PrintStringAsColor("Error: ", LX::Color::LIGHT_RED); - std::cout << "Incorrect use of " << std::filesystem::path(argv[0]).filename().string() << ":\n\n"; - std::cout << "Usage: "; - LX::PrintStringAsColor("[source file] [output file] [optional args]", LX::Color::WHITE); - std::cout << "\n\nOptional arguments:\n"; - std::cout << "\tLog file for additional information\n\n"; - - // Warns the user that they are better of using a build system // - LX::PrintStringAsColor("Warning:\n", LX::Color::LIGHT_YELLOW); - std::cout << "\tIf you are seeing this message it is probably because you are not using a build-system\n"; - std::cout << "\tWorking with a build system is recommended for use of " << std::filesystem::path(argv[0]).filename().string() << "\n"; - std::cout << "\tOne can be found here: NULL\n\n"; // <- TODO: Make a build system - - // Returns Exit id of 1 so other process can be alerted of the error // - return 1; - } - catch (LX::InvalidInputFilePath) { // Tells the user the input file could not be found and how to fix the issue // diff --git a/LX-Build/LX-API.cs b/LX-Build/LX-API.cs new file mode 100644 index 0000000..5fc981d --- /dev/null +++ b/LX-Build/LX-API.cs @@ -0,0 +1,26 @@ +using System; +using System.Runtime.InteropServices; + +namespace LX_Build +{ + internal class LX_API + { + // Imports SetDllDirectory to change where Dlls are imported from // + [DllImport("kernel32.dll", SetLastError = true)] + private static extern bool SetDllDirectory(string lpPathName); + + // Imports the Frontend of the compiler // + [DllImport("Generator.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int GenIR(string arg1, string arg2, string? arg3); + + // Sets the directory to import the DLLs from // + public static void Init() + { + #if DEBUG + SetDllDirectory("bin\\x64\\Debug"); + #else + SetDllDirectory("bin\\x64\\Release"); + #endif + } + } +} diff --git a/LX-Build/LX-Build.csproj b/LX-Build/LX-Build.csproj new file mode 100644 index 0000000..a51eeb8 --- /dev/null +++ b/LX-Build/LX-Build.csproj @@ -0,0 +1,12 @@ + + + + Exe + net8.0 + LX_Build + enable + enable + + + + diff --git a/LX-Build/Main.cs b/LX-Build/Main.cs new file mode 100644 index 0000000..17c3500 --- /dev/null +++ b/LX-Build/Main.cs @@ -0,0 +1,16 @@ +using System; + +namespace LX_Build +{ + class Program + { + static void Main(string[] args) + { + // Initalises the CPP interface // + LX_API.Init(); + + // Generates LLVM IR with the example files // + _ = LX_API.GenIR("example/main.lx", "example/main.ll", "example/log"); + } + } +} diff --git a/LX-Build/Properties/launchSettings.json b/LX-Build/Properties/launchSettings.json new file mode 100644 index 0000000..6e52371 --- /dev/null +++ b/LX-Build/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "LX-Build": { + "commandName": "Project", + "workingDirectory": "$(SolutionDir)" + } + } +} \ No newline at end of file diff --git a/LX-Compiler.sln b/LX-Compiler.sln index 06efb02..8f58eb1 100644 --- a/LX-Compiler.sln +++ b/LX-Compiler.sln @@ -9,44 +9,92 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frontend-Modules", "Fronten EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Parser", "Parser\Parser.vcxproj", "{D6EAFB31-4AFD-4989-9522-D6609AC4ED64}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IR-Generator", "IR-Generator\IR-Generator.vcxproj", "{C88042E2-0E09-4383-93F8-C79F9EE1E897}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Generator", "IR-Generator\IR-Generator.vcxproj", "{C88042E2-0E09-4383-93F8-C79F9EE1E897}" ProjectSection(ProjectDependencies) = postProject {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA} = {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA} {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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Debug|Any CPU.ActiveCfg = Debug|x64 + {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Debug|Any CPU.Build.0 = Debug|x64 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Debug|x64.ActiveCfg = Debug|x64 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Debug|x64.Build.0 = Debug|x64 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Debug|x86.ActiveCfg = Debug|Win32 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Debug|x86.Build.0 = Debug|Win32 + {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Release|Any CPU.ActiveCfg = Release|x64 + {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Release|Any CPU.Build.0 = Release|x64 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Release|x64.ActiveCfg = Release|x64 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Release|x64.Build.0 = Release|x64 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Release|x86.ActiveCfg = Release|Win32 {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}.Release|x86.Build.0 = Release|Win32 + {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Debug|Any CPU.ActiveCfg = Debug|x64 + {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Debug|Any CPU.Build.0 = Debug|x64 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Debug|x64.ActiveCfg = Debug|x64 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Debug|x64.Build.0 = Debug|x64 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Debug|x86.ActiveCfg = Debug|Win32 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Debug|x86.Build.0 = Debug|Win32 + {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Release|Any CPU.ActiveCfg = Release|x64 + {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Release|Any CPU.Build.0 = Release|x64 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Release|x64.ActiveCfg = Release|x64 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Release|x64.Build.0 = Release|x64 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Release|x86.ActiveCfg = Release|Win32 {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}.Release|x86.Build.0 = Release|Win32 + {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Debug|Any CPU.ActiveCfg = Debug|x64 + {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Debug|Any CPU.Build.0 = Debug|x64 {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Debug|x64.ActiveCfg = Debug|x64 {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Debug|x64.Build.0 = Debug|x64 {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Debug|x86.ActiveCfg = Debug|Win32 {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Debug|x86.Build.0 = Debug|Win32 + {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Release|Any CPU.ActiveCfg = Release|x64 + {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Release|Any CPU.Build.0 = Release|x64 {C88042E2-0E09-4383-93F8-C79F9EE1E897}.Release|x64.ActiveCfg = Release|x64 {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 + {DE9DB560-F002-4922-98E6-558C3D04C607}.Debug|x64.Build.0 = Debug|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Debug|x86.ActiveCfg = Debug|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Debug|x86.Build.0 = Debug|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Release|Any CPU.Build.0 = Release|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Release|x64.ActiveCfg = Release|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Release|x64.Build.0 = Release|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Release|x86.ActiveCfg = Release|Any CPU + {DE9DB560-F002-4922-98E6-558C3D04C607}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -55,6 +103,7 @@ 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} diff --git a/Linker/Linker.vcxproj b/Linker/Linker.vcxproj new file mode 100644 index 0000000..28a26e2 --- /dev/null +++ b/Linker/Linker.vcxproj @@ -0,0 +1,144 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {043afda7-5ac5-4dd2-aca8-029051e72961} + Linker + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(SolutionDir)bin\inter\$(Platform)\$(Configuration)\$(ProjectName)\ + + + $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(SolutionDir)bin\inter\$(Platform)\$(Configuration)\$(ProjectName)\ + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + + + Console + true + true + true + + + + + + + + \ No newline at end of file diff --git a/Linker/Linker.vcxproj.filters b/Linker/Linker.vcxproj.filters new file mode 100644 index 0000000..ce609f0 --- /dev/null +++ b/Linker/Linker.vcxproj.filters @@ -0,0 +1,13 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + \ No newline at end of file diff --git a/Linker/Linker.vcxproj.user b/Linker/Linker.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/Linker/Linker.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/example/main.lx b/example/main.lx index 96d54e8..f38dbb8 100644 --- a/example/main.lx +++ b/example/main.lx @@ -1,13 +1,4 @@ func main() { - int a - a = 4 - - int b - b = 7 - - int c - c = a / b - - return c + return 34 }