From c64a2c692cff5a02e3d4647896d2efa4b42064e0 Mon Sep 17 00:00:00 2001
From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com>
Date: Mon, 5 May 2025 16:45:34 +0100
Subject: [PATCH] Made common a project
---
.gitignore | 2 +
Common/Common.vcxproj | 170 ++++++++++++++++++
Common/Common.vcxproj.filters | 41 +++++
Common/Common.vcxproj.user | 4 +
Common/LX-Common.h | 59 ++++++
{common => Common/inc}/Console.h | 8 -
{common => Common/inc}/Error.h | 2 -
.../inc/Util.h => Common/inc/Logger.h | 16 +-
{common => Common/inc}/ThrowIf.h | 5 -
Common/src/dllmain.cpp | 17 ++
Common/src/pch.cpp | 2 +
IR-Generator/IR-Generator.vcxproj | 2 -
IR-Generator/IR-Generator.vcxproj.filters | 6 -
IR-Generator/inc/LLVM.h | 25 ---
IR-Generator/inc/Lexer.h | 18 +-
IR-Generator/inc/Parser.h | 16 +-
IR-Generator/src/Generator.cpp | 11 +-
LX-Compiler.sln | 29 ++-
Lexer/src/Lexer.cpp | 15 +-
Lexer/src/Token.cpp | 3 +-
Parser/inc/AST.h | 4 +-
Parser/src/AST-LLVM.cpp | 4 +-
Parser/src/AST-Loggers.cpp | 2 +-
Parser/src/GenIR.cpp | 6 +-
Parser/src/Parser.cpp | 6 +-
Parser/src/ParserErrors.cpp | 6 +-
Parser/src/Scope.cpp | 4 +-
27 files changed, 337 insertions(+), 146 deletions(-)
create mode 100644 Common/Common.vcxproj
create mode 100644 Common/Common.vcxproj.filters
create mode 100644 Common/Common.vcxproj.user
create mode 100644 Common/LX-Common.h
rename {common => Common/inc}/Console.h (93%)
rename {common => Common/inc}/Error.h (98%)
rename IR-Generator/inc/Util.h => Common/inc/Logger.h (57%)
rename {common => Common/inc}/ThrowIf.h (90%)
create mode 100644 Common/src/dllmain.cpp
create mode 100644 Common/src/pch.cpp
delete mode 100644 IR-Generator/inc/LLVM.h
diff --git a/.gitignore b/.gitignore
index cefb631..ba6fde8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,8 @@ obj/
# Ignore runtime outputs #
*.ll
+*.obj
+*.exe
log
# Ignore user specific options #
diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj
new file mode 100644
index 0000000..a410ccc
--- /dev/null
+++ b/Common/Common.vcxproj
@@ -0,0 +1,170 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ Win32Proj
+ {0abb03b7-e61a-4040-a512-fc05aa35b2a6}
+ Common
+ 10.0
+
+
+
+ DynamicLibrary
+ true
+ v143
+ Unicode
+
+
+ DynamicLibrary
+ false
+ v143
+ true
+ Unicode
+
+
+ DynamicLibrary
+ true
+ v143
+ Unicode
+
+
+ DynamicLibrary
+ 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;COMMON_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
+ true
+ Use
+ pch.h
+
+
+ Windows
+ true
+ false
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;COMMON_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
+ true
+ Use
+ pch.h
+
+
+ Windows
+ true
+ true
+ true
+ false
+
+
+
+
+ Level3
+ true
+ _DEBUG;COMMON_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
+ true
+ Use
+ LX-Common.h
+ $(ProjectDir);%(AdditionalIncludeDirectories)
+ stdcpp20
+
+
+ Windows
+ true
+ false
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;COMMON_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
+ true
+ Use
+ LX-Common.h
+ $(ProjectDir);%(AdditionalIncludeDirectories)
+ stdcpp20
+
+
+ Windows
+ true
+ true
+ true
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+ Create
+ Create
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters
new file mode 100644
index 0000000..ec082b4
--- /dev/null
+++ b/Common/Common.vcxproj.filters
@@ -0,0 +1,41 @@
+
+
+
+
+ {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
+
+
+ {f3a1ae14-8b71-41d9-ba66-60c952867261}
+
+
+
+
+ Header Files
+
+
+ Header Files\Sections
+
+
+ Header Files\Sections
+
+
+ Header Files\Sections
+
+
+ Header Files\Sections
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+
\ No newline at end of file
diff --git a/Common/Common.vcxproj.user b/Common/Common.vcxproj.user
new file mode 100644
index 0000000..88a5509
--- /dev/null
+++ b/Common/Common.vcxproj.user
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/Common/LX-Common.h b/Common/LX-Common.h
new file mode 100644
index 0000000..a6b1312
--- /dev/null
+++ b/Common/LX-Common.h
@@ -0,0 +1,59 @@
+// This is a precompiled header file. //
+// Files listed below are compiled only once, improving build performance for future builds. //
+// This also affects IntelliSense performance, including code completion and many code browsing features. //
+// However, files listed here are ALL re-compiled if any one of them is updated between builds. //
+// Do not add files here that you will be updating frequently as this negates the performance advantage. //
+
+#pragma once
+
+// Includes Windows API if on the correct system //
+#ifdef _WIN32
+ #define NOMINMAX
+ #define WIN32_LEAN_AND_MEAN
+ #include
+
+// Else alerts the user that their system is not supported //
+#else
+ #error "This code is only designed to work on windows"
+#endif // _WIN32
+
+// Checks the user is using MSVC as it is required for this code to compile //
+#ifndef _MSC_VER
+ #error "This code is only designed to work with Visual Studio"
+#endif // _MSC_VER
+
+// Includes commonly used STD files //
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+// Includes LLVM files (disables warnings thrown by them) //
+
+#pragma warning(push)
+#pragma warning(disable : 4244)
+#pragma warning(disable : 4267)
+#pragma warning(disable : 4624)
+#pragma warning(disable : 4800)
+
+#include
+#include
+#include
+#include
+
+#pragma warning(pop) // <- Renables all warnings
+
+// Includes the rest of common //
+
+#include
+#include
+#include
+#include
diff --git a/common/Console.h b/Common/inc/Console.h
similarity index 93%
rename from common/Console.h
rename to Common/inc/Console.h
index 84b88d8..f516810 100644
--- a/common/Console.h
+++ b/Common/inc/Console.h
@@ -1,11 +1,3 @@
-#pragma once
-
-#define NOMINMAX
-#include
-
-#include
-#include
-
namespace LX
{
enum class Color
diff --git a/common/Error.h b/Common/inc/Error.h
similarity index 98%
rename from common/Error.h
rename to Common/inc/Error.h
index a0c67a4..bb7e8ac 100644
--- a/common/Error.h
+++ b/Common/inc/Error.h
@@ -1,5 +1,3 @@
-#pragma once
-
namespace LX
{
// Base error class for all LX thrown errors //
diff --git a/IR-Generator/inc/Util.h b/Common/inc/Logger.h
similarity index 57%
rename from IR-Generator/inc/Util.h
rename to Common/inc/Logger.h
index 6882b0d..d7ceebe 100644
--- a/IR-Generator/inc/Util.h
+++ b/Common/inc/Logger.h
@@ -1,19 +1,13 @@
-#pragma once
-
-#include
-
-// Defining this is only if you are at the point where you should be using a debugger //
-#define LOG_EVERYTHING
-
namespace LX
{
-
template
- // Helper function for logging //
- // Only logs the given args if the log is not null //
inline void SafeLog(std::ofstream* log, Args... args)
{
- if (log != nullptr) { (*log << ... << args); *log << "\n"; }
+ if (log != nullptr)
+ {
+ (*log << ... << args);
+ (*log << '\n');
+ }
}
inline void SafeFlush(std::ofstream* log)
diff --git a/common/ThrowIf.h b/Common/inc/ThrowIf.h
similarity index 90%
rename from common/ThrowIf.h
rename to Common/inc/ThrowIf.h
index 66c383b..177eeae 100644
--- a/common/ThrowIf.h
+++ b/Common/inc/ThrowIf.h
@@ -1,8 +1,3 @@
-#pragma once
-
-// Type traits is included for std::is_base_of_v //
-#include
-
namespace LX
{
// Foward declares LX::RuntimeError so it can be used to see if a class derives from //
diff --git a/Common/src/dllmain.cpp b/Common/src/dllmain.cpp
new file mode 100644
index 0000000..9d0ab34
--- /dev/null
+++ b/Common/src/dllmain.cpp
@@ -0,0 +1,17 @@
+// dllmain.cpp : Defines the entry point for the DLL application.
+#include
+
+BOOL __stdcall DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+
+ return true;
+}
+
diff --git a/Common/src/pch.cpp b/Common/src/pch.cpp
new file mode 100644
index 0000000..b43841a
--- /dev/null
+++ b/Common/src/pch.cpp
@@ -0,0 +1,2 @@
+// Wow, such an intresting file. Don't put anything else in here //
+#include
diff --git a/IR-Generator/IR-Generator.vcxproj b/IR-Generator/IR-Generator.vcxproj
index c480f35..7f278ad 100644
--- a/IR-Generator/IR-Generator.vcxproj
+++ b/IR-Generator/IR-Generator.vcxproj
@@ -148,9 +148,7 @@
-
-
diff --git a/IR-Generator/IR-Generator.vcxproj.filters b/IR-Generator/IR-Generator.vcxproj.filters
index 70c5e72..b8e873d 100644
--- a/IR-Generator/IR-Generator.vcxproj.filters
+++ b/IR-Generator/IR-Generator.vcxproj.filters
@@ -19,14 +19,8 @@
Header Files
-
- Header Files
-
Header Files
-
- Header Files
-
\ No newline at end of file
diff --git a/IR-Generator/inc/LLVM.h b/IR-Generator/inc/LLVM.h
deleted file mode 100644
index ca09a55..0000000
--- a/IR-Generator/inc/LLVM.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-// Helper file for including all neccesarry parts of LLVM //
-#ifdef _MSC_VER
-
- // Disables all warnings as LLVM files have a lot of Data-loss casts that won't cause issues //
- #pragma warning(push)
- #pragma warning(disable : 4244)
- #pragma warning(disable : 4267)
- #pragma warning(disable : 4624)
- #pragma warning(disable : 4800)
-
- // Includes the LLVM files //
-
- #include
- #include
- #include
- #include
-
- // Re-enables all warnings //
- #pragma warning(pop)
-
-#else
- #error This code is only designed to work with MSVC due to the use of vcpkg and other aspects
-#endif // _MSC_VER
diff --git a/IR-Generator/inc/Lexer.h b/IR-Generator/inc/Lexer.h
index 77f6f70..2e610a0 100644
--- a/IR-Generator/inc/Lexer.h
+++ b/IR-Generator/inc/Lexer.h
@@ -1,22 +1,6 @@
#pragma once
-#include
-
-#include
-#include
-#include
-
-// Foward declarations of STD classes to minimise includes //
-namespace std
-{
- template
- struct char_traits;
-
- template
- class basic_ofstream;
-
- using ofstream = basic_ofstream>;
-}
+#include
// This file contains everything that is exported from Lexer.lib
// The rest of the items within the Lexer project are internal only
diff --git a/IR-Generator/inc/Parser.h b/IR-Generator/inc/Parser.h
index c2fc376..a20c706 100644
--- a/IR-Generator/inc/Parser.h
+++ b/IR-Generator/inc/Parser.h
@@ -3,21 +3,7 @@
// Lexer foward declares fstream components so we can use them here //
#include
-#include
-
-#include
-#include
-
-// Foward declares STD stuff that is passed around //
-namespace std::filesystem { class path; }
-
-// Foward declares all items of the llvm lib that we need //
-// Done to avoid including LLVM.h to shorten compile times //
-namespace llvm
-{
- class Value;
- class AllocaInst;
-}
+#include
// Foward declares the wrapper around the LLVM objects we need to pass around //
namespace LX { struct InfoLLVM; }
diff --git a/IR-Generator/src/Generator.cpp b/IR-Generator/src/Generator.cpp
index 154acb4..ccbc27e 100644
--- a/IR-Generator/src/Generator.cpp
+++ b/IR-Generator/src/Generator.cpp
@@ -1,16 +1,7 @@
-#include
-#include
-#include
-#include
-#include
+#include
-#include
-#include
#include
#include
-#include
-
-#include
namespace LX
{
diff --git a/LX-Compiler.sln b/LX-Compiler.sln
index 027dd86..79bfa9a 100644
--- a/LX-Compiler.sln
+++ b/LX-Compiler.sln
@@ -4,13 +4,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.13.35931.197
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lexer", "Lexer\Lexer.vcxproj", "{4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}"
+ ProjectSection(ProjectDependencies) = postProject
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6} = {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}
+ EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frontend-Modules", "Frontend-Modules", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Parser", "Parser\Parser.vcxproj", "{D6EAFB31-4AFD-4989-9522-D6609AC4ED64}"
+ ProjectSection(ProjectDependencies) = postProject
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6} = {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}
+ EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Generator", "IR-Generator\IR-Generator.vcxproj", "{C88042E2-0E09-4383-93F8-C79F9EE1E897}"
ProjectSection(ProjectDependencies) = postProject
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6} = {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}
{4E4019F5-12E0-4EE2-9658-A0DD3038EEDA} = {4E4019F5-12E0-4EE2-9658-A0DD3038EEDA}
{D6EAFB31-4AFD-4989-9522-D6609AC4ED64} = {D6EAFB31-4AFD-4989-9522-D6609AC4ED64}
EndProjectSection
@@ -20,12 +27,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LX-Build", "LX-Build\LX-Bui
{C88042E2-0E09-4383-93F8-C79F9EE1E897} = {C88042E2-0E09-4383-93F8-C79F9EE1E897}
EndProjectSection
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common-Include", "Common-Include", "{4AD62954-631A-4D0F-877E-E1C66E8CEC00}"
- ProjectSection(SolutionItems) = preProject
- common\Console.h = common\Console.h
- common\Error.h = common\Error.h
- common\ThrowIf.h = common\ThrowIf.h
- EndProjectSection
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{4AD62954-631A-4D0F-877E-E1C66E8CEC00}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Common\Common.vcxproj", "{0ABB03B7-E61A-4040-A512-FC05AA35B2A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -85,6 +89,18 @@ Global
{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
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Debug|Any CPU.ActiveCfg = Debug|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Debug|Any CPU.Build.0 = Debug|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Debug|x64.ActiveCfg = Debug|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Debug|x64.Build.0 = Debug|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Debug|x86.ActiveCfg = Debug|Win32
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Debug|x86.Build.0 = Debug|Win32
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Release|Any CPU.ActiveCfg = Release|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Release|Any CPU.Build.0 = Release|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Release|x64.ActiveCfg = Release|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Release|x64.Build.0 = Release|x64
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Release|x86.ActiveCfg = Release|Win32
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -93,6 +109,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}
+ {0ABB03B7-E61A-4040-A512-FC05AA35B2A6} = {4AD62954-631A-4D0F-877E-E1C66E8CEC00}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {411AFEC9-4075-4FCC-B95A-9288BC822E90}
diff --git a/Lexer/src/Lexer.cpp b/Lexer/src/Lexer.cpp
index 700bb89..90af71a 100644
--- a/Lexer/src/Lexer.cpp
+++ b/Lexer/src/Lexer.cpp
@@ -1,19 +1,6 @@
#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
+#include
namespace LX
{
diff --git a/Lexer/src/Token.cpp b/Lexer/src/Token.cpp
index 01ebd0a..0c7e727 100644
--- a/Lexer/src/Token.cpp
+++ b/Lexer/src/Token.cpp
@@ -1,7 +1,6 @@
#include
-#include
-#include
+#include
namespace LX
{
diff --git a/Parser/inc/AST.h b/Parser/inc/AST.h
index ef08d62..ecdbf3e 100644
--- a/Parser/inc/AST.h
+++ b/Parser/inc/AST.h
@@ -1,8 +1,6 @@
#include
-#include
-
-#include
+#include
namespace LX
{
diff --git a/Parser/src/AST-LLVM.cpp b/Parser/src/AST-LLVM.cpp
index cd3d4b4..6e1b124 100644
--- a/Parser/src/AST-LLVM.cpp
+++ b/Parser/src/AST-LLVM.cpp
@@ -1,9 +1,7 @@
#include
-#include
+#include
-#include
-#include
#include
namespace LX::AST
diff --git a/Parser/src/AST-Loggers.cpp b/Parser/src/AST-Loggers.cpp
index 1c0940f..4792b5a 100644
--- a/Parser/src/AST-Loggers.cpp
+++ b/Parser/src/AST-Loggers.cpp
@@ -1,6 +1,6 @@
#include
-#include
+#include
namespace LX::AST
{
diff --git a/Parser/src/GenIR.cpp b/Parser/src/GenIR.cpp
index 75f86cf..6418a8e 100644
--- a/Parser/src/GenIR.cpp
+++ b/Parser/src/GenIR.cpp
@@ -1,13 +1,9 @@
#include
-#include
+#include
-#include
#include
-#include
-#include
-
namespace LX
{
// Tells the generator if the current node is allowed to be within a top-level context //
diff --git a/Parser/src/Parser.cpp b/Parser/src/Parser.cpp
index af5f074..0bfa69f 100644
--- a/Parser/src/Parser.cpp
+++ b/Parser/src/Parser.cpp
@@ -1,10 +1,8 @@
#include
-#include
-#include
-#include
+#include
-#include
+#include
namespace LX
{
diff --git a/Parser/src/ParserErrors.cpp b/Parser/src/ParserErrors.cpp
index 328f355..6a0fb0a 100644
--- a/Parser/src/ParserErrors.cpp
+++ b/Parser/src/ParserErrors.cpp
@@ -1,10 +1,6 @@
#include
-#include
-
-#include
-#include
-#include
+#include
namespace LX
{
diff --git a/Parser/src/Scope.cpp b/Parser/src/Scope.cpp
index 110bfad..70dbdeb 100644
--- a/Parser/src/Scope.cpp
+++ b/Parser/src/Scope.cpp
@@ -1,7 +1,7 @@
#include
-#include
-#include
+#include
+
#include
namespace LX