From 753c72c65326bbc2701e37b59051896f712eec56 Mon Sep 17 00:00:00 2001
From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com>
Date: Wed, 16 Apr 2025 15:27:43 +0100
Subject: [PATCH] Inital commit
---
.gitattributes | 2 +
.gitignore | 4 ++
LX-Compiler.sln | 31 +++++++++
LX-LLVM.vcxproj | 143 ++++++++++++++++++++++++++++++++++++++++
LX-LLVM.vcxproj.filters | 23 +++++++
LX-LLVM.vcxproj.user | 14 ++++
Main.cpp | 62 +++++++++++++++++
build-test/Main.ll | 0
build-test/main.lx | 0
common/Util.h | 8 +++
10 files changed, 287 insertions(+)
create mode 100644 .gitattributes
create mode 100644 .gitignore
create mode 100644 LX-Compiler.sln
create mode 100644 LX-LLVM.vcxproj
create mode 100644 LX-LLVM.vcxproj.filters
create mode 100644 LX-LLVM.vcxproj.user
create mode 100644 Main.cpp
create mode 100644 build-test/Main.ll
create mode 100644 build-test/main.lx
create mode 100644 common/Util.h
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..dfe0770
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1066d77
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+# Ignore cache directories #
+
+x64/
+.vs/
diff --git a/LX-Compiler.sln b/LX-Compiler.sln
new file mode 100644
index 0000000..06aa645
--- /dev/null
+++ b/LX-Compiler.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.13.35931.197 d17.13
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LX-LLVM", "LX-LLVM.vcxproj", "{CC37E36F-B3B3-41B0-A887-01E8EFE84994}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Debug|x64.ActiveCfg = Debug|x64
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Debug|x64.Build.0 = Debug|x64
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Debug|x86.ActiveCfg = Debug|Win32
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Debug|x86.Build.0 = Debug|Win32
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Release|x64.ActiveCfg = Release|x64
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Release|x64.Build.0 = Release|x64
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Release|x86.ActiveCfg = Release|Win32
+ {CC37E36F-B3B3-41B0-A887-01E8EFE84994}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {411AFEC9-4075-4FCC-B95A-9288BC822E90}
+ EndGlobalSection
+EndGlobal
diff --git a/LX-LLVM.vcxproj b/LX-LLVM.vcxproj
new file mode 100644
index 0000000..7bad884
--- /dev/null
+++ b/LX-LLVM.vcxproj
@@ -0,0 +1,143 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ Win32Proj
+ {cc37e36f-b3b3-41b0-a887-01e8efe84994}
+ LXLLVM
+ 10.0
+ LX-Compiler
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+ $(SolutionDir)/Common;%(AdditionalIncludeDirectories)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)/Common;%(AdditionalIncludeDirectories)
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LX-LLVM.vcxproj.filters b/LX-LLVM.vcxproj.filters
new file mode 100644
index 0000000..805c715
--- /dev/null
+++ b/LX-LLVM.vcxproj.filters
@@ -0,0 +1,23 @@
+
+
+
+
+ {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
+
+
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+
\ No newline at end of file
diff --git a/LX-LLVM.vcxproj.user b/LX-LLVM.vcxproj.user
new file mode 100644
index 0000000..bf3f381
--- /dev/null
+++ b/LX-LLVM.vcxproj.user
@@ -0,0 +1,14 @@
+
+
+
+ false
+
+
+ build-test/Main.lx build-test/Main.ll
+ WindowsLocalDebugger
+
+
+ build-test/Main.lx build-test/Main.ll
+ WindowsLocalDebugger
+
+
\ No newline at end of file
diff --git a/Main.cpp b/Main.cpp
new file mode 100644
index 0000000..613bd1a
--- /dev/null
+++ b/Main.cpp
@@ -0,0 +1,62 @@
+#include
+#include
+#include
+#include
+
+#include
+
+namespace LX
+{
+ // Different errors thrown by main //
+
+ struct IncorrectCommandLineArgs {};
+ struct InvalidInputFilePath {};
+ struct InvalidOutputFilePath {};
+}
+
+int main(int argc, char** argv)
+{
+ try
+ {
+ // Checks there is the correct ammount of arguments
+ LX::ThrowIf(argc != 3);
+
+ // Turns the file paths into the C++ type for handling them
+ std::filesystem::path inpPath = argv[1];
+ std::filesystem::path outPath = argv[2];
+
+ // Prints the full paths to the console to let the user know compiling is being done
+ std::cout << std::filesystem::absolute(inpPath) << " -> " << std::filesystem::absolute(outPath) << std::endl;
+
+ // Checks the input file exists
+ LX::ThrowIf(std::filesystem::exists(inpPath) == false);
+
+ // Opens / Creates the output file and checks if it is open
+ std::ofstream outFile(outPath);
+ LX::ThrowIf(outFile.is_open() == false);
+ }
+
+ catch (LX::IncorrectCommandLineArgs)
+ {
+ // Displays to the console of how to use the program
+ std::cout << "\nUsage: [source file] [output file]\n";
+
+ return 1;
+ }
+
+ catch (LX::InvalidInputFilePath)
+ {
+ // Tells user the input file could not be found
+ std::cout << "\nFile path: {" << argv[1] << "} could not be found\n";
+
+ return 2;
+ }
+
+ catch (LX::InvalidOutputFilePath)
+ {
+ // Tells the user the output file could not be opened
+ std::cout << "\nCould not open/create {" << argv[2] << "}";
+ }
+
+ return 0;
+}
diff --git a/build-test/Main.ll b/build-test/Main.ll
new file mode 100644
index 0000000..e69de29
diff --git a/build-test/main.lx b/build-test/main.lx
new file mode 100644
index 0000000..e69de29
diff --git a/common/Util.h b/common/Util.h
new file mode 100644
index 0000000..c72015b
--- /dev/null
+++ b/common/Util.h
@@ -0,0 +1,8 @@
+#pragma once
+
+namespace LX
+{
+ template
+ inline void ThrowIf(const bool condition, Args... args)
+ { if (condition) [[unlikely]] { throw T(args...); }}
+}