Modernize and remove useless header text

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2024-06-06 14:04:34 +02:00
parent 4e2dd8e30b
commit 7f669f55e2
18 changed files with 100 additions and 479 deletions
+2 -2
View File
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.26...3.29.2 FATAL_ERROR)
################################################################################ ################################################################################
# CMake Setup # CMake Setup
################################################################################ ################################################################################
cmake_minimum_required(VERSION 3.26...)
project(BlitzLLVM) project(BlitzLLVM)
list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ") list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ")
@@ -23,7 +24,6 @@ include("version")
#- CMake-based Clang integration #- CMake-based Clang integration
include("clang") include("clang")
SET_PROPERTY( GLOBAL PROPERTY USE_FOLDERS ON) SET_PROPERTY( GLOBAL PROPERTY USE_FOLDERS ON)
################################################################################ ################################################################################
+6 -51
View File
@@ -1,24 +1,7 @@
cmake_minimum_required(VERSION 3.0.2) project(code_compiler)
project(CodeCompiler) add_executable(${PROJECT_NAME})
# Configuration target_sources(${PROJECT_NAME} PRIVATE
## Dependencies
# LLVM
#find_package(LLVM REQUIRED CONFIG)
#llvm_map_components_to_libnames(llvm_libs support core irreader)
# Boost
#SET(BOOST_ROOT "" CACHE PATH "Path to Boost")
#SET(Boost_USE_STATIC_LIBS ON)
#find_package(Boost REQUIRED COMPONENTS program_options)
## Version
INCLUDE("CMakeVersion.txt")
## Compiling
# Source Files
SET(SOURCE
"source/main.cpp" "source/main.cpp"
"source/lexer.hpp" "source/lexer.hpp"
"source/lexer.cpp" "source/lexer.cpp"
@@ -35,38 +18,10 @@ SET(SOURCE
"source/compiler.hpp" "source/compiler.hpp"
"source/compiler.cpp" "source/compiler.cpp"
) )
SET(DATA target_include_directories(${PROJECT_NAME} PRIVATE
"CMakeVersion.txt"
)
# Source Grouping
SOURCE_GROUP(TREE ${PROJECT_SOURCE_DIR}/source PREFIX Source FILES ${SOURCE})
# Definitions
ADD_DEFINITIONS(
${LLVM_DEFINITIONS}
)
# Directories
INCLUDE_DIRECTORIES(
"${PROJECT_SOURCE_DIR}/source" "${PROJECT_SOURCE_DIR}/source"
"${PROJECT_BINARY_DIR}" "${PROJECT_BINARY_DIR}"
${LLVM_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
LINK_DIRECTORIES(
${LLVM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
) )
# Building get_target_property(_SOURCES ${PROJECT_NAME} SOURCES)
ADD_EXECUTABLE(cc source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${_SOURCES})
${SOURCE}
${DATA}
)
# Linking
TARGET_LINK_LIBRARIES(cc
${Boost_LIBRARIES}
${llvm_libs}
)
+2 -18
View File
@@ -1,22 +1,6 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "arithmetic.hpp" #include "arithmetic.hpp"
BlitzLLVM::AST::ArithmeticExpression::ArithmeticExpression(Operator op, std::unique_ptr<Expression> left, std::unique_ptr<Expression> right) blitz::AST::ArithmeticExpression::ArithmeticExpression(Operator op, std::unique_ptr<Expression> left, std::unique_ptr<Expression> right)
: m_operator(op), m_left(std::move(left)), m_right(std::move(right)) {} : m_operator(op), m_left(std::move(left)), m_right(std::move(right)) {}
BlitzLLVM::AST::ArithmeticExpression::~ArithmeticExpression() {} blitz::AST::ArithmeticExpression::~ArithmeticExpression() {}
+1 -17
View File
@@ -1,24 +1,8 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
#include "ast.hpp" #include "ast.hpp"
#include "value.hpp" #include "value.hpp"
namespace BlitzLLVM { namespace blitz {
namespace AST { namespace AST {
enum class Operator : int8_t { enum class Operator : int8_t {
Add, /*+*/ Add, /*+*/
-16
View File
@@ -1,17 +1 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "ast.hpp" #include "ast.hpp"
+1 -17
View File
@@ -1,22 +1,6 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
namespace BlitzLLVM { namespace blitz {
namespace AST { namespace AST {
class Expression { class Expression {
public: public:
+7 -23
View File
@@ -1,30 +1,14 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "function.hpp" #include "function.hpp"
BlitzLLVM::AST::ScopeExpression::ScopeExpression() {} blitz::AST::ScopeExpression::ScopeExpression() {}
BlitzLLVM::AST::ScopeExpression::~ScopeExpression() {} blitz::AST::ScopeExpression::~ScopeExpression() {}
void BlitzLLVM::AST::ScopeExpression::AddExpression(std::unique_ptr<Expression> ex) { void blitz::AST::ScopeExpression::AddExpression(std::unique_ptr<Expression> ex) {
m_expressions.push_back(std::move(ex)); m_expressions.push_back(std::move(ex));
} }
BlitzLLVM::AST::FunctionExpression::FunctionExpression(ValueType returnType, blitz::AST::FunctionExpression::FunctionExpression(ValueType returnType,
std::string& m_name, std::string& m_name,
std::list<std::unique_ptr<VariableExpression>> parameters, std::list<std::unique_ptr<VariableExpression>> parameters,
std::unique_ptr<ScopeExpression> scope) std::unique_ptr<ScopeExpression> scope)
@@ -32,11 +16,11 @@ BlitzLLVM::AST::FunctionExpression::FunctionExpression(ValueType returnType,
} }
BlitzLLVM::AST::FunctionExpression::~FunctionExpression() {} blitz::AST::FunctionExpression::~FunctionExpression() {}
BlitzLLVM::AST::CallExpression::CallExpression(std::string& name, std::list<std::unique_ptr<VariableExpression>> arguments) blitz::AST::CallExpression::CallExpression(std::string& name, std::list<std::unique_ptr<VariableExpression>> arguments)
: m_name(name), m_arguments(std::move(arguments)) { : m_name(name), m_arguments(std::move(arguments)) {
} }
BlitzLLVM::AST::CallExpression::~CallExpression() {} blitz::AST::CallExpression::~CallExpression() {}
+1 -17
View File
@@ -1,19 +1,3 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
#include "ast.hpp" #include "ast.hpp"
#include "value.hpp" #include "value.hpp"
@@ -21,7 +5,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
namespace BlitzLLVM { namespace blitz {
namespace AST { namespace AST {
class ScopeExpression : public Expression { class ScopeExpression : public Expression {
public: public:
+15 -31
View File
@@ -1,59 +1,43 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "value.hpp" #include "value.hpp"
BlitzLLVM::AST::VariableExpression::VariableExpression(std::string& name, ValueType type /*= ValueType::Number*/) blitz::AST::VariableExpression::VariableExpression(std::string& name, ValueType type /*= ValueType::Number*/)
: m_name(name), m_type(type) {} : m_name(name), m_type(type) {}
BlitzLLVM::AST::VariableExpression::~VariableExpression() {} blitz::AST::VariableExpression::~VariableExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::VariableExpression::GetType() { blitz::AST::ValueType blitz::AST::VariableExpression::GetType() {
return m_type; return m_type;
} }
BlitzLLVM::AST::NumberExpression::NumberExpression(int32_t value) : value(value) {} blitz::AST::NumberExpression::NumberExpression(int32_t value) : value(value) {}
BlitzLLVM::AST::NumberExpression::~NumberExpression() {} blitz::AST::NumberExpression::~NumberExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::NumberExpression::GetType() { blitz::AST::ValueType blitz::AST::NumberExpression::GetType() {
return ValueType::Number; return ValueType::Number;
} }
BlitzLLVM::AST::DecimalExpression::DecimalExpression(float_t value) : value(value) {} blitz::AST::DecimalExpression::DecimalExpression(float_t value) : value(value) {}
BlitzLLVM::AST::DecimalExpression::~DecimalExpression() {} blitz::AST::DecimalExpression::~DecimalExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::DecimalExpression::GetType() { blitz::AST::ValueType blitz::AST::DecimalExpression::GetType() {
return ValueType::Decimal; return ValueType::Decimal;
} }
BlitzLLVM::AST::StringExpression::StringExpression(std::string value) : value(value) {} blitz::AST::StringExpression::StringExpression(std::string value) : value(value) {}
BlitzLLVM::AST::StringExpression::~StringExpression() {} blitz::AST::StringExpression::~StringExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::StringExpression::GetType() { blitz::AST::ValueType blitz::AST::StringExpression::GetType() {
return ValueType::String; return ValueType::String;
} }
BlitzLLVM::AST::ConstExpression::ConstExpression(std::string& name, std::unique_ptr<ValueExpression> value) blitz::AST::ConstExpression::ConstExpression(std::string& name, std::unique_ptr<ValueExpression> value)
: m_name(name), m_value(std::move(value)) {} : m_name(name), m_value(std::move(value)) {}
BlitzLLVM::AST::ConstExpression::~ConstExpression() {} blitz::AST::ConstExpression::~ConstExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::ConstExpression::GetType() { blitz::AST::ValueType blitz::AST::ConstExpression::GetType() {
return m_value->GetType(); return m_value->GetType();
} }
+1 -17
View File
@@ -1,19 +1,3 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
#include "ast.hpp" #include "ast.hpp"
#include "lexer.hpp" #include "lexer.hpp"
@@ -23,7 +7,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
namespace BlitzLLVM { namespace blitz {
namespace AST { namespace AST {
enum class ValueType : int8_t { enum class ValueType : int8_t {
Unknown, Unknown,
+4 -20
View File
@@ -1,30 +1,14 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "compiler.hpp" #include "compiler.hpp"
#include "parser.hpp" #include "parser.hpp"
#include "lexer.hpp" #include "lexer.hpp"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
BlitzLLVM::Compiler::Compiler() {} blitz::compiler::compiler() {}
BlitzLLVM::Compiler::~Compiler() {} blitz::compiler::~compiler() {}
bool BlitzLLVM::Compiler::Compile(std::string in, std::string out) { bool blitz::compiler::compile(std::string in, std::string out) {
/*std::ifstream infile; /*std::ifstream infile;
infile.open(in); infile.open(in);
if (infile.bad() || !infile.good() || infile.eof()) { if (infile.bad() || !infile.good() || infile.eof()) {
@@ -32,7 +16,7 @@ bool BlitzLLVM::Compiler::Compile(std::string in, std::string out) {
return false; return false;
}*/ }*/
Parser psr = Parser(in); parser psr = parser(in);
if (!psr.Parse()) { if (!psr.Parse()) {
} }
+5 -23
View File
@@ -1,30 +1,12 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
#include <string> #include <string>
namespace BlitzLLVM { namespace blitz {
class Compiler { class compiler {
public: public:
Compiler(); compiler();
~Compiler(); ~compiler();
bool Compile(std::string in, std::string out); bool compile(std::string in, std::string out);
private:
}; };
} }
+25 -42
View File
@@ -1,57 +1,40 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "lexer.hpp" #include "lexer.hpp"
#include <codecvt> #include <codecvt>
#include <boost/algorithm/string/predicate.hpp>
std::pair<char, BlitzLLVM::Lexer::Token> g_symbolCharacters[] = { std::pair<char, blitz::Lexer::Token> g_symbolCharacters[] = {
//{ '\"', BlitzLLVM::Lexer::Token::TokenDoubleQuote }, // Has special meaning. //{ '\"', BlitzLLVM::Lexer::Token::TokenDoubleQuote }, // Has special meaning.
{ '+', BlitzLLVM::Lexer::Token::TokenPlus }, { '+', blitz::Lexer::Token::TokenPlus },
{ '-', BlitzLLVM::Lexer::Token::TokenMinus }, { '-', blitz::Lexer::Token::TokenMinus },
{ '/', BlitzLLVM::Lexer::Token::TokenSlashForward }, { '/', blitz::Lexer::Token::TokenSlashForward },
{ '\\', BlitzLLVM::Lexer::Token::TokenSlashBackward }, { '\\', blitz::Lexer::Token::TokenSlashBackward },
{ '*', BlitzLLVM::Lexer::Token::TokenMultiply }, { '*', blitz::Lexer::Token::TokenMultiply },
{ '=', BlitzLLVM::Lexer::Token::TokenEqual }, { '=', blitz::Lexer::Token::TokenEqual },
{ '#', BlitzLLVM::Lexer::Token::TokenOctothorp }, { '#', blitz::Lexer::Token::TokenOctothorp },
{ '%', BlitzLLVM::Lexer::Token::TokenPercent }, { '%', blitz::Lexer::Token::TokenPercent },
{ '$', BlitzLLVM::Lexer::Token::TokenDollar }, { '$', blitz::Lexer::Token::TokenDollar },
{ '(', BlitzLLVM::Lexer::Token::TokenRoundBracketOpen }, { '(', blitz::Lexer::Token::TokenRoundBracketOpen },
{ ')', BlitzLLVM::Lexer::Token::TokenRoundBracketClose }, { ')', blitz::Lexer::Token::TokenRoundBracketClose },
{ '[', BlitzLLVM::Lexer::Token::TokenSquareBracketOpen }, { '[', blitz::Lexer::Token::TokenSquareBracketOpen },
{ ']', BlitzLLVM::Lexer::Token::TokenSquareBracketClose }, { ']', blitz::Lexer::Token::TokenSquareBracketClose },
{ '<', BlitzLLVM::Lexer::Token::TokenAngleBracketOpen }, { '<', blitz::Lexer::Token::TokenAngleBracketOpen },
{ '>', BlitzLLVM::Lexer::Token::TokenAngleBracketClose }, { '>', blitz::Lexer::Token::TokenAngleBracketClose },
//{ '.', BlitzLLVM::Lexer::Token::TokenDot }, // Special meaning. //{ '.', BlitzLLVM::Lexer::Token::TokenDot }, // Special meaning.
{ ':', BlitzLLVM::Lexer::Token::TokenColon }, { ':', blitz::Lexer::Token::TokenColon },
{ ',', BlitzLLVM::Lexer::Token::TokenComma }, { ',', blitz::Lexer::Token::TokenComma },
//{ ';', BlitzLLVM::Lexer::Token::TokenSemicolon }, //{ ';', BlitzLLVM::Lexer::Token::TokenSemicolon },
{ '^', BlitzLLVM::Lexer::Token::TokenCaret }, { '^', blitz::Lexer::Token::TokenCaret },
{ '~', BlitzLLVM::Lexer::Token::TokenBitNot }, { '~', blitz::Lexer::Token::TokenBitNot },
}; };
BlitzLLVM::Lexer::Lexer() {} blitz::Lexer::Lexer() {}
BlitzLLVM::Lexer::~Lexer() {} blitz::Lexer::~Lexer() {}
std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetCurrentToken() { std::pair<blitz::Lexer::Token, std::string> blitz::Lexer::GetCurrentToken() {
return std::make_pair(m_currentToken, m_currentText); return std::make_pair(m_currentToken, m_currentText);
} }
std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken(std::shared_ptr<std::istream> fs) { std::pair<blitz::Lexer::Token, std::string> blitz::Lexer::GetNextToken(std::shared_ptr<std::istream> fs) {
std::string buf; std::string buf;
Token tkn = Token::TokenEOF; Token tkn = Token::TokenEOF;
bool haveResult = false; bool haveResult = false;
@@ -213,7 +196,7 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken(s
return std::make_pair(tkn, buf); return std::make_pair(tkn, buf);
} }
BlitzLLVM::Lexer::Token BlitzLLVM::Lexer::ConvertTextToToken(Token in, std::string text) { blitz::Lexer::Token blitz::Lexer::ConvertTextToToken(Token in, std::string text) {
static std::pair<const char*, Token> l_textToTokenList[] = { static std::pair<const char*, Token> l_textToTokenList[] = {
// Binary // Binary
{ "not", Token::TokenNot }, { "not", Token::TokenNot },
+2 -18
View File
@@ -1,19 +1,3 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
#include <inttypes.h> #include <inttypes.h>
#include <istream> #include <istream>
@@ -21,7 +5,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
namespace BlitzLLVM { namespace blitz {
class Lexer { class Lexer {
public: public:
enum class Token : uint64_t { enum class Token : uint64_t {
@@ -116,7 +100,7 @@ namespace BlitzLLVM {
std::pair<Token, std::string> GetNextToken(std::shared_ptr<std::istream> fs); std::pair<Token, std::string> GetNextToken(std::shared_ptr<std::istream> fs);
private: private:
BlitzLLVM::Lexer::Token ConvertTextToToken(Token in, std::string text); blitz::Lexer::Token ConvertTextToToken(Token in, std::string text);
private: private:
Token m_currentToken = Token::TokenUnknown; Token m_currentToken = Token::TokenUnknown;
+2 -103
View File
@@ -1,110 +1,9 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include <iostream> #include <iostream>
#include "boost/program_options.hpp"
#include "compiler.hpp" #include "compiler.hpp"
#include "version.h"
#define LICENSE "Copyright (C) 2017 Michael Fabian Dirks\n\
This program comes with ABSOLUTELY NO WARRANTY, for details launch with `--warranty`.\n\
This is free software, and you are welcome to redistribute it under certain conditions."
#define WARRANTY "\
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.EXCEPT WHEN OTHERWISE STATED IN \
WRITING THE COPYRIGHT HOLDERS AND / OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, \
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM \
PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION."
int main(int argc, char** argv) { int main(int argc, char** argv) {
std::string optInput; blitz::compiler comp;
bool optQuiet, optVerbose; comp.compile(argv[1], std::string(argv[1]) + ".exe");
#pragma region Define Program Options
boost::program_options::options_description opts_help("Generic");
opts_help.add_options()
("help,h", "Show this help message.")
("warranty", "Show warranty information.")
("quiet,q", boost::program_options::value<bool>(&optQuiet)->default_value(false), "Use quieter logging.")
("verbose,v", boost::program_options::value<bool>(&optVerbose)->default_value(false), "Use verbose logging (overrides quiet).")
;
boost::program_options::options_description opts_param("Parameters");
opts_param.add_options()
("input,i", boost::program_options::value<std::string>(&optInput), "Input .bb file.")
;
boost::program_options::options_description opts;
opts.add(opts_help).add(opts_param);
boost::program_options::positional_options_description opts_pos;
opts_pos.add("input", -1);
#pragma endregion Define Program Options
#pragma region Convert ArgC/ArgV to Program Options
boost::program_options::variables_map vm;
{
auto clp = boost::program_options::command_line_parser(argc, argv);
boost::program_options::store(clp.options(opts).positional(opts_pos).run(), vm);
boost::program_options::notify(vm);
}
#pragma endregion Convert ArgC/ArgV to Program Options
#pragma region Header, Warranty, Help
// Header
if (!optQuiet || optVerbose) {
std::cout
<< "BlitzLLVM Code Compiler"
<< " v" << VERSION_MAJOR
<< "." << VERSION_MINOR
<< "." << VERSION_PATCH
<< " " << LICENSE
<< '\n' << std::endl;
}
// Warranty
if (vm.count("warranty")) {
std::cout << '\n' << WARRANTY << '\n' << std::endl;
#ifdef _DEBUG
std::cin.get();
#endif
return 1;
}
// Help
if (vm.empty() || vm.count("help")) {
std::cout
<< "Usage: cc [options] <file.bb>" << '\n'
<< opts
<< std::endl;
#ifdef _DEBUG
std::cin.get();
#endif
return 1;
}
#pragma endregion Header, Warranty, Help
#pragma region Process Input
BlitzLLVM::Compiler comp;
comp.Compile(optInput, optInput + ".exe");
#pragma endregion Process Input
#ifdef _DEBUG
std::cin.get(); std::cin.get();
#endif
return 0; return 0;
} }
+18 -34
View File
@@ -1,26 +1,10 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "parser.hpp" #include "parser.hpp"
#include "ast/function.hpp" #include "ast/function.hpp"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <stdarg.h> #include <stdarg.h>
BlitzLLVM::Parser::Parser(std::string file) { blitz::parser::parser(std::string file) {
// Try and load the file // Try and load the file
std::shared_ptr<std::ifstream> instream = std::make_shared<std::ifstream>(file); std::shared_ptr<std::ifstream> instream = std::make_shared<std::ifstream>(file);
if (instream->bad() || !instream->good()) { if (instream->bad() || !instream->good()) {
@@ -29,7 +13,7 @@ BlitzLLVM::Parser::Parser(std::string file) {
m_files.push(std::make_pair(file, instream)); m_files.push(std::make_pair(file, instream));
} }
BlitzLLVM::Parser::~Parser() { blitz::parser::~parser() {
while (m_files.size() > 0) { while (m_files.size() > 0) {
std::shared_ptr<std::ifstream> file = std::dynamic_pointer_cast<std::ifstream>(m_files.top().second); std::shared_ptr<std::ifstream> file = std::dynamic_pointer_cast<std::ifstream>(m_files.top().second);
file->close(); file->close();
@@ -37,18 +21,18 @@ BlitzLLVM::Parser::~Parser() {
} }
} }
std::unique_ptr<BlitzLLVM::AST::Expression> BlitzLLVM::Parser::Parse() { std::unique_ptr<blitz::AST::Expression> blitz::parser::Parse() {
std::unique_ptr<AST::ScopeExpression> scope = std::make_unique<AST::ScopeExpression>(); std::unique_ptr<AST::ScopeExpression> scope = std::make_unique<AST::ScopeExpression>();
std::unique_ptr<AST::Expression> expr; std::unique_ptr<AST::Expression> expr;
while ((expr = std::move(ParseExpression())) != nullptr) { while ((expr = std::move(parse_expression())) != nullptr) {
scope->AddExpression(std::move(expr)); scope->AddExpression(std::move(expr));
} }
return std::move(scope); return std::move(scope);
} }
void BlitzLLVM::Parser::LogMessage(const char* msg, ...) { void blitz::parser::LogMessage(const char* msg, ...) {
std::vector<char> buf(65535); std::vector<char> buf(65535);
va_list val; va_list val;
va_start(val, msg); va_start(val, msg);
@@ -57,7 +41,7 @@ void BlitzLLVM::Parser::LogMessage(const char* msg, ...) {
std::cout << buf.data() << '\n'; std::cout << buf.data() << '\n';
} }
void BlitzLLVM::Parser::LogError(const char* msg, ...) { void blitz::parser::LogError(const char* msg, ...) {
std::vector<char> buf(65535); std::vector<char> buf(65535);
va_list val; va_list val;
va_start(val, msg); va_start(val, msg);
@@ -66,33 +50,33 @@ void BlitzLLVM::Parser::LogError(const char* msg, ...) {
std::cerr << buf.data() << '\n'; std::cerr << buf.data() << '\n';
} }
std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Parser::GetNextToken() { std::pair<blitz::Lexer::Token, std::string> blitz::parser::GetNextToken() {
return m_lexer.GetNextToken(m_files.top().second); return m_lexer.GetNextToken(m_files.top().second);
} }
std::unique_ptr<BlitzLLVM::AST::Expression> BlitzLLVM::Parser::ParseExpression() { std::unique_ptr<blitz::AST::Expression> blitz::parser::parse_expression() {
while (true) { while (true) {
auto tkn = GetNextToken(); auto tkn = GetNextToken();
switch (tkn.first) { switch (tkn.first) {
case BlitzLLVM::Lexer::Token::TokenNewLine: case blitz::Lexer::Token::TokenNewLine:
case BlitzLLVM::Lexer::Token::TokenComment: case blitz::Lexer::Token::TokenComment:
// Skip Comments, since we don't really need them for the AST. // Skip Comments, since we don't really need them for the AST.
continue; continue;
case BlitzLLVM::Lexer::Token::TokenPlus: case blitz::Lexer::Token::TokenPlus:
case BlitzLLVM::Lexer::Token::TokenMinus: case blitz::Lexer::Token::TokenMinus:
default: // End Of File / Unknown default: // End Of File / Unknown
case BlitzLLVM::Lexer::Token::TokenUnknown: case blitz::Lexer::Token::TokenUnknown:
case BlitzLLVM::Lexer::Token::TokenEOF: case blitz::Lexer::Token::TokenEOF:
return nullptr; return nullptr;
break; break;
} }
} }
} }
std::unique_ptr<BlitzLLVM::AST::NumberExpression> BlitzLLVM::Parser::ParseNumber(BlitzLLVM::Lexer::Token token, std::string value) { std::unique_ptr<blitz::AST::NumberExpression> blitz::parser::parse_number(blitz::Lexer::Token token, std::string value) {
if (token != Lexer::Token::TokenNumber) { if (token != Lexer::Token::TokenNumber) {
LogError("Unexpected Token during parsing, expected number."); LogError("Unexpected Token during parsing, expected number.");
return nullptr; return nullptr;
@@ -105,10 +89,10 @@ std::unique_ptr<BlitzLLVM::AST::NumberExpression> BlitzLLVM::Parser::ParseNumber
return nullptr; return nullptr;
} }
return std::make_unique<BlitzLLVM::AST::NumberExpression>(parsed); return std::make_unique<blitz::AST::NumberExpression>(parsed);
} }
std::unique_ptr<BlitzLLVM::AST::DecimalExpression> BlitzLLVM::Parser::ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value) { std::unique_ptr<blitz::AST::DecimalExpression> blitz::parser::parse_decimal(blitz::Lexer::Token token, std::string value) {
if (token != Lexer::Token::TokenNumber) { if (token != Lexer::Token::TokenNumber) {
LogError("Unexpected Token during parsing, expected number."); LogError("Unexpected Token during parsing, expected number.");
return nullptr; return nullptr;
@@ -121,5 +105,5 @@ std::unique_ptr<BlitzLLVM::AST::DecimalExpression> BlitzLLVM::Parser::ParseDecim
return nullptr; return nullptr;
} }
return std::make_unique<BlitzLLVM::AST::DecimalExpression>(parsed); return std::make_unique<blitz::AST::DecimalExpression>(parsed);
} }
+8 -24
View File
@@ -1,19 +1,3 @@
// Code Compiler for BlitzLLVM
// Copyright(C) 2017 Michael Fabian Dirks
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
#include "lexer.hpp" #include "lexer.hpp"
#include "ast/ast.hpp" #include "ast/ast.hpp"
@@ -24,11 +8,11 @@
#include <string> #include <string>
#include <stack> #include <stack>
namespace BlitzLLVM { namespace blitz {
class Parser { class parser {
public: public:
Parser(std::string file); parser(std::string file);
~Parser(); ~parser();
std::unique_ptr<AST::Expression> Parse(); std::unique_ptr<AST::Expression> Parse();
@@ -37,12 +21,12 @@ namespace BlitzLLVM {
void LogError(const char* msg, ...); void LogError(const char* msg, ...);
private: private:
std::pair<BlitzLLVM::Lexer::Token, std::string> GetNextToken(); std::pair<blitz::Lexer::Token, std::string> GetNextToken();
private: private:
std::unique_ptr<AST::Expression> ParseExpression(); std::unique_ptr<AST::Expression> parse_expression();
std::unique_ptr<AST::NumberExpression> ParseNumber(BlitzLLVM::Lexer::Token token, std::string value); std::unique_ptr<AST::NumberExpression> parse_number(blitz::Lexer::Token token, std::string value);
std::unique_ptr<AST::DecimalExpression> ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value); std::unique_ptr<AST::DecimalExpression> parse_decimal(blitz::Lexer::Token token, std::string value);
private: private:
Lexer m_lexer; Lexer m_lexer;
-6
View File
@@ -1,6 +0,0 @@
#pragma once
#define VERSION_MAJOR @VERSION_MAJOR@
#define VERSION_MINOR @VERSION_MINOR@
#define VERSION_PATCH @VERSION_PATCH@
#define VERSION_FULL (((uint64_t)VERSION_MAJOR << 48ull) | ((uint64_t)VERSION_MINOR << 32ull) | ((uint64_t)VERSION_PATCH << 16ull) | ((uint64_t)VERSION_BUILD))