summaryrefslogtreecommitdiffhomepage
path: root/dev/CompilerKit
diff options
context:
space:
mode:
Diffstat (limited to 'dev/CompilerKit')
-rw-r--r--dev/CompilerKit/Compiler.h16
-rw-r--r--dev/CompilerKit/Defines.h6
-rw-r--r--dev/CompilerKit/ErrorID.h6
-rw-r--r--dev/CompilerKit/ErrorOr.h6
-rw-r--r--dev/CompilerKit/Frontend.h19
-rw-r--r--dev/CompilerKit/StringKit.h6
-rw-r--r--dev/CompilerKit/Version.h2
7 files changed, 60 insertions, 1 deletions
diff --git a/dev/CompilerKit/Compiler.h b/dev/CompilerKit/Compiler.h
index 3da99ca..a14005b 100644
--- a/dev/CompilerKit/Compiler.h
+++ b/dev/CompilerKit/Compiler.h
@@ -17,7 +17,9 @@ namespace CompilerKit {
class AssemblyFactory;
class AssemblyInterface;
+/// =========================================================== ///
/// @brief Simple assembly factory
+/// =========================================================== ///
class AssemblyFactory final {
public:
explicit AssemblyFactory() = default;
@@ -47,8 +49,10 @@ class AssemblyFactory final {
AssemblyInterface* fMounted{nullptr};
};
+/// =========================================================== ///
/// @brief Assembly to binary generator class.
/// @note This interface creates according to the CPU target of the child class.
+/// =========================================================== ///
class AssemblyInterface {
public:
explicit AssemblyInterface() = default;
@@ -58,11 +62,16 @@ class AssemblyInterface {
virtual UInt32 Arch() noexcept { return AssemblyFactory::kArchAMD64; }
+ /// =========================================================== ///
/// @brief compile to object file.
/// @note Example C++ -> MASM -> AE object.
+ /// =========================================================== ///
virtual Int32 CompileToFormat(std::string src, Int32 arch) = 0;
};
+/// =========================================================== ///
+/// @brief Number casting unions for different sizes.
+/// =========================================================== ///
union NumberCastBase {
NumberCastBase() = default;
~NumberCastBase() = default;
@@ -108,6 +117,9 @@ union NumberCast8 final {
UInt8 raw;
};
+/// =========================================================== ///
+/// @brief Assembly encoder interface.
+/// =========================================================== ///
class EncoderInterface {
public:
explicit EncoderInterface() = default;
@@ -120,6 +132,10 @@ class EncoderInterface {
virtual bool WriteNumber(const std::size_t& pos, std::string& from_what) = 0;
};
+/// =========================================================== ///
+/// @brief Different architecture encoders.
+/// =========================================================== ///
+
#ifdef __ASM_NEED_AMD64__
class EncoderAMD64 final : public EncoderInterface {
diff --git a/dev/CompilerKit/Defines.h b/dev/CompilerKit/Defines.h
index 56e8dd3..34b43d6 100644
--- a/dev/CompilerKit/Defines.h
+++ b/dev/CompilerKit/Defines.h
@@ -7,6 +7,12 @@
#ifndef __NECTI_DEFINES_H__
#define __NECTI_DEFINES_H__
+/// =========================================================== ///
+/// @file Defines.h
+/// @author Amlal El Mahrouss
+/// @brief Basic defines and types for CompilerKit.
+/// =========================================================== ///
+
#ifndef Yes
#define Yes true
#endif // ifndef Yes
diff --git a/dev/CompilerKit/ErrorID.h b/dev/CompilerKit/ErrorID.h
index 7c76f86..c16f682 100644
--- a/dev/CompilerKit/ErrorID.h
+++ b/dev/CompilerKit/ErrorID.h
@@ -11,6 +11,12 @@
#include <CompilerKit/Defines.h>
+/// =========================================================== ///
+/// @file ErrorID.h
+/// @author Amlal El Mahrouss
+/// @brief Error IDs for CompilerKit.
+/// =========================================================== ///
+
#define NECTI_SUCCESS 0
#define NECTI_EXEC_ERROR -30
#define NECTI_FILE_NOT_FOUND -31
diff --git a/dev/CompilerKit/ErrorOr.h b/dev/CompilerKit/ErrorOr.h
index d5a1c08..66a90ee 100644
--- a/dev/CompilerKit/ErrorOr.h
+++ b/dev/CompilerKit/ErrorOr.h
@@ -9,6 +9,12 @@
#pragma once
+/// =========================================================== ///
+/// @file ErrorOr.h
+/// @author Amlal El Mahrouss
+/// @brief ErrorOr for CompilerKit.
+/// =========================================================== ///
+
#include <CompilerKit/StringKit.h>
#include <CompilerKit/Defines.h>
#include <CompilerKit/ErrorID.h>
diff --git a/dev/CompilerKit/Frontend.h b/dev/CompilerKit/Frontend.h
index 4b03651..225de96 100644
--- a/dev/CompilerKit/Frontend.h
+++ b/dev/CompilerKit/Frontend.h
@@ -17,7 +17,10 @@ struct SyntaxLeafList;
struct SyntaxLeafList;
struct CompilerKeyword;
+/// =========================================================== ///
/// we want to do that because to separate keywords.
+/// =========================================================== ///
+
enum KeywordKind {
kKeywordKindNamespace,
kKeywordKindFunctionStart,
@@ -56,7 +59,9 @@ enum KeywordKind {
kKeywordKindPtr,
};
+/// =========================================================== ///
/// \brief Compiler keyword information struct.
+/// =========================================================== ///
struct CompilerKeyword {
CompilerKeyword(STLString name, KeywordKind kind) : keyword_name(name), keyword_kind(kind) {}
@@ -81,20 +86,26 @@ struct SyntaxLeafList final {
SyntaxLeaf& At(SizeType index) { return fLeafList[index]; }
};
+/// =========================================================== ///
/// find the perfect matching word in a haystack.
/// \param haystack base string
/// \param needle the string we search for.
/// \return if we found it or not.
+/// =========================================================== ///
Bool find_word(STLString haystack, STLString needle) noexcept;
+/// =========================================================== ///
/// find a word within strict conditions and returns a range of it.
/// \param haystack
/// \param needle
/// \return position of needle.
+/// =========================================================== ///
SizeType find_word_range(STLString haystack, STLString needle) noexcept;
+/// =========================================================== ///
/// @brief Compiler backend, implements a frontend, such as C, C++...
/// See Toolchain, for some examples.
+/// =========================================================== ///
class CompilerFrontendInterface {
public:
explicit CompilerFrontendInterface() = default;
@@ -102,18 +113,26 @@ class CompilerFrontendInterface {
NECTI_COPY_DEFAULT(CompilerFrontendInterface);
+ /// =========================================================== ///
// NOTE: cast this to your user defined ast.
+ /// =========================================================== ///
typedef void* AstType;
+ /// =========================================================== ///
//! @brief Compile a syntax tree ouf of the text.
//! Also takes the source file name for metadata.
+ /// =========================================================== ///
virtual CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) = 0;
+ /// =========================================================== ///
//! @brief What language are we dealing with?
+ /// =========================================================== ///
virtual const char* Language() { return kInvalidFrontend; }
+ /// =========================================================== ///
/// @brief Checks if language is a valid frontend.
+ /// =========================================================== ///
virtual bool IsValid() { return strcmp(this->Language(), kInvalidFrontend) > 0; }
};
} // namespace CompilerKit
diff --git a/dev/CompilerKit/StringKit.h b/dev/CompilerKit/StringKit.h
index 69efb9c..0fbe58a 100644
--- a/dev/CompilerKit/StringKit.h
+++ b/dev/CompilerKit/StringKit.h
@@ -13,6 +13,12 @@
#include <CompilerKit/Defines.h>
#include <CompilerKit/ErrorOr.h>
+/// =========================================================== ///
+/// @file StringKit.h
+/// @author Amlal El Mahrouss
+/// @brief StringKit for CompilerKit.
+/// =========================================================== ///
+
namespace CompilerKit {
class StringBuilder;
class BasicString;
diff --git a/dev/CompilerKit/Version.h b/dev/CompilerKit/Version.h
index dd5e1f8..577e034 100644
--- a/dev/CompilerKit/Version.h
+++ b/dev/CompilerKit/Version.h
@@ -6,7 +6,7 @@
#pragma once
-#define kDistVersion "v0.0.6-compilerkit"
+#define kDistVersion "v0.0.7-compilerkit"
#define kDistVersionBCD 0x0002
#define ToString(X) Stringify(X)