diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dcf8db..96d83ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ +cmake_minimum_required(VERSION 3.26...3.29.2 FATAL_ERROR) + ################################################################################ # CMake Setup ################################################################################ -cmake_minimum_required(VERSION 3.26...) project(BlitzLLVM) list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ") @@ -23,7 +24,6 @@ include("version") #- CMake-based Clang integration include("clang") - SET_PROPERTY( GLOBAL PROPERTY USE_FOLDERS ON) ################################################################################ diff --git a/code_compiler/CMakeLists.txt b/code_compiler/CMakeLists.txt index 7072c0b..e93cb6b 100644 --- a/code_compiler/CMakeLists.txt +++ b/code_compiler/CMakeLists.txt @@ -1,24 +1,7 @@ -cmake_minimum_required(VERSION 3.0.2) -project(CodeCompiler) +project(code_compiler) +add_executable(${PROJECT_NAME}) -# Configuration - -## 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 +target_sources(${PROJECT_NAME} PRIVATE "source/main.cpp" "source/lexer.hpp" "source/lexer.cpp" @@ -35,38 +18,10 @@ SET(SOURCE "source/compiler.hpp" "source/compiler.cpp" ) -SET(DATA - "CMakeVersion.txt" -) - -# Source Grouping -SOURCE_GROUP(TREE ${PROJECT_SOURCE_DIR}/source PREFIX Source FILES ${SOURCE}) - -# Definitions -ADD_DEFINITIONS( - ${LLVM_DEFINITIONS} -) - -# Directories -INCLUDE_DIRECTORIES( +target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/source" "${PROJECT_BINARY_DIR}" - ${LLVM_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} -) -LINK_DIRECTORIES( - ${LLVM_LIBRARY_DIRS} - ${Boost_LIBRARY_DIRS} ) -# Building -ADD_EXECUTABLE(cc - ${SOURCE} - ${DATA} -) - -# Linking -TARGET_LINK_LIBRARIES(cc - ${Boost_LIBRARIES} - ${llvm_libs} -) +get_target_property(_SOURCES ${PROJECT_NAME} SOURCES) +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${_SOURCES}) diff --git a/code_compiler/source/ast/arithmetic.cpp b/code_compiler/source/ast/arithmetic.cpp index c34b9ce..1b2f8ec 100644 --- a/code_compiler/source/ast/arithmetic.cpp +++ b/code_compiler/source/ast/arithmetic.cpp @@ -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 . - #include "arithmetic.hpp" -BlitzLLVM::AST::ArithmeticExpression::ArithmeticExpression(Operator op, std::unique_ptr left, std::unique_ptr right) +blitz::AST::ArithmeticExpression::ArithmeticExpression(Operator op, std::unique_ptr left, std::unique_ptr right) : m_operator(op), m_left(std::move(left)), m_right(std::move(right)) {} -BlitzLLVM::AST::ArithmeticExpression::~ArithmeticExpression() {} +blitz::AST::ArithmeticExpression::~ArithmeticExpression() {} diff --git a/code_compiler/source/ast/arithmetic.hpp b/code_compiler/source/ast/arithmetic.hpp index a7795ba..7fd0569 100644 --- a/code_compiler/source/ast/arithmetic.hpp +++ b/code_compiler/source/ast/arithmetic.hpp @@ -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 . - #pragma once #include "ast.hpp" #include "value.hpp" -namespace BlitzLLVM { +namespace blitz { namespace AST { enum class Operator : int8_t { Add, /*+*/ diff --git a/code_compiler/source/ast/ast.cpp b/code_compiler/source/ast/ast.cpp index 69a0ca4..caa9173 100644 --- a/code_compiler/source/ast/ast.cpp +++ b/code_compiler/source/ast/ast.cpp @@ -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 . - #include "ast.hpp" \ No newline at end of file diff --git a/code_compiler/source/ast/ast.hpp b/code_compiler/source/ast/ast.hpp index bb7bc2e..a36afba 100644 --- a/code_compiler/source/ast/ast.hpp +++ b/code_compiler/source/ast/ast.hpp @@ -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 . - #pragma once -namespace BlitzLLVM { +namespace blitz { namespace AST { class Expression { public: diff --git a/code_compiler/source/ast/function.cpp b/code_compiler/source/ast/function.cpp index 339135d..faac237 100644 --- a/code_compiler/source/ast/function.cpp +++ b/code_compiler/source/ast/function.cpp @@ -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 . - #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 ex) { +void blitz::AST::ScopeExpression::AddExpression(std::unique_ptr 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::list> parameters, std::unique_ptr 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> arguments) +blitz::AST::CallExpression::CallExpression(std::string& name, std::list> arguments) : m_name(name), m_arguments(std::move(arguments)) { } -BlitzLLVM::AST::CallExpression::~CallExpression() {} +blitz::AST::CallExpression::~CallExpression() {} diff --git a/code_compiler/source/ast/function.hpp b/code_compiler/source/ast/function.hpp index 77157d2..041ce8b 100644 --- a/code_compiler/source/ast/function.hpp +++ b/code_compiler/source/ast/function.hpp @@ -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 . - #pragma once #include "ast.hpp" #include "value.hpp" @@ -21,7 +5,7 @@ #include #include -namespace BlitzLLVM { +namespace blitz { namespace AST { class ScopeExpression : public Expression { public: diff --git a/code_compiler/source/ast/value.cpp b/code_compiler/source/ast/value.cpp index d228ff2..f2dbc76 100644 --- a/code_compiler/source/ast/value.cpp +++ b/code_compiler/source/ast/value.cpp @@ -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 . - #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) {} -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; } -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; } -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; } -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; } -BlitzLLVM::AST::ConstExpression::ConstExpression(std::string& name, std::unique_ptr value) +blitz::AST::ConstExpression::ConstExpression(std::string& name, std::unique_ptr 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(); } diff --git a/code_compiler/source/ast/value.hpp b/code_compiler/source/ast/value.hpp index 493043f..028b3fa 100644 --- a/code_compiler/source/ast/value.hpp +++ b/code_compiler/source/ast/value.hpp @@ -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 . - #pragma once #include "ast.hpp" #include "lexer.hpp" @@ -23,7 +7,7 @@ #include #include -namespace BlitzLLVM { +namespace blitz { namespace AST { enum class ValueType : int8_t { Unknown, diff --git a/code_compiler/source/compiler.cpp b/code_compiler/source/compiler.cpp index 10b19e7..35705bb 100644 --- a/code_compiler/source/compiler.cpp +++ b/code_compiler/source/compiler.cpp @@ -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 . - #include "compiler.hpp" #include "parser.hpp" #include "lexer.hpp" #include #include -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; infile.open(in); if (infile.bad() || !infile.good() || infile.eof()) { @@ -32,7 +16,7 @@ bool BlitzLLVM::Compiler::Compile(std::string in, std::string out) { return false; }*/ - Parser psr = Parser(in); + parser psr = parser(in); if (!psr.Parse()) { } diff --git a/code_compiler/source/compiler.hpp b/code_compiler/source/compiler.hpp index e2b5f2f..75dd7b7 100644 --- a/code_compiler/source/compiler.hpp +++ b/code_compiler/source/compiler.hpp @@ -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 . - #pragma once #include -namespace BlitzLLVM { - class Compiler { +namespace blitz { + class compiler { public: - Compiler(); - ~Compiler(); + compiler(); + ~compiler(); - bool Compile(std::string in, std::string out); - - private: + bool compile(std::string in, std::string out); }; } diff --git a/code_compiler/source/lexer.cpp b/code_compiler/source/lexer.cpp index 09a6ce7..32a97a5 100644 --- a/code_compiler/source/lexer.cpp +++ b/code_compiler/source/lexer.cpp @@ -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 . - #include "lexer.hpp" #include -#include -std::pair g_symbolCharacters[] = { +std::pair g_symbolCharacters[] = { //{ '\"', BlitzLLVM::Lexer::Token::TokenDoubleQuote }, // Has special meaning. - { '+', BlitzLLVM::Lexer::Token::TokenPlus }, - { '-', BlitzLLVM::Lexer::Token::TokenMinus }, - { '/', BlitzLLVM::Lexer::Token::TokenSlashForward }, - { '\\', BlitzLLVM::Lexer::Token::TokenSlashBackward }, - { '*', BlitzLLVM::Lexer::Token::TokenMultiply }, - { '=', BlitzLLVM::Lexer::Token::TokenEqual }, - { '#', BlitzLLVM::Lexer::Token::TokenOctothorp }, - { '%', BlitzLLVM::Lexer::Token::TokenPercent }, - { '$', BlitzLLVM::Lexer::Token::TokenDollar }, - { '(', BlitzLLVM::Lexer::Token::TokenRoundBracketOpen }, - { ')', BlitzLLVM::Lexer::Token::TokenRoundBracketClose }, - { '[', BlitzLLVM::Lexer::Token::TokenSquareBracketOpen }, - { ']', BlitzLLVM::Lexer::Token::TokenSquareBracketClose }, - { '<', BlitzLLVM::Lexer::Token::TokenAngleBracketOpen }, - { '>', BlitzLLVM::Lexer::Token::TokenAngleBracketClose }, + { '+', blitz::Lexer::Token::TokenPlus }, + { '-', blitz::Lexer::Token::TokenMinus }, + { '/', blitz::Lexer::Token::TokenSlashForward }, + { '\\', blitz::Lexer::Token::TokenSlashBackward }, + { '*', blitz::Lexer::Token::TokenMultiply }, + { '=', blitz::Lexer::Token::TokenEqual }, + { '#', blitz::Lexer::Token::TokenOctothorp }, + { '%', blitz::Lexer::Token::TokenPercent }, + { '$', blitz::Lexer::Token::TokenDollar }, + { '(', blitz::Lexer::Token::TokenRoundBracketOpen }, + { ')', blitz::Lexer::Token::TokenRoundBracketClose }, + { '[', blitz::Lexer::Token::TokenSquareBracketOpen }, + { ']', blitz::Lexer::Token::TokenSquareBracketClose }, + { '<', blitz::Lexer::Token::TokenAngleBracketOpen }, + { '>', blitz::Lexer::Token::TokenAngleBracketClose }, //{ '.', BlitzLLVM::Lexer::Token::TokenDot }, // Special meaning. - { ':', BlitzLLVM::Lexer::Token::TokenColon }, - { ',', BlitzLLVM::Lexer::Token::TokenComma }, + { ':', blitz::Lexer::Token::TokenColon }, + { ',', blitz::Lexer::Token::TokenComma }, //{ ';', BlitzLLVM::Lexer::Token::TokenSemicolon }, - { '^', BlitzLLVM::Lexer::Token::TokenCaret }, - { '~', BlitzLLVM::Lexer::Token::TokenBitNot }, + { '^', blitz::Lexer::Token::TokenCaret }, + { '~', blitz::Lexer::Token::TokenBitNot }, }; -BlitzLLVM::Lexer::Lexer() {} +blitz::Lexer::Lexer() {} -BlitzLLVM::Lexer::~Lexer() {} +blitz::Lexer::~Lexer() {} -std::pair BlitzLLVM::Lexer::GetCurrentToken() { +std::pair blitz::Lexer::GetCurrentToken() { return std::make_pair(m_currentToken, m_currentText); } -std::pair BlitzLLVM::Lexer::GetNextToken(std::shared_ptr fs) { +std::pair blitz::Lexer::GetNextToken(std::shared_ptr fs) { std::string buf; Token tkn = Token::TokenEOF; bool haveResult = false; @@ -213,7 +196,7 @@ std::pair BlitzLLVM::Lexer::GetNextToken(s 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 l_textToTokenList[] = { // Binary { "not", Token::TokenNot }, diff --git a/code_compiler/source/lexer.hpp b/code_compiler/source/lexer.hpp index 6b5cb84..6d19996 100644 --- a/code_compiler/source/lexer.hpp +++ b/code_compiler/source/lexer.hpp @@ -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 . - #pragma once #include #include @@ -21,7 +5,7 @@ #include #include -namespace BlitzLLVM { +namespace blitz { class Lexer { public: enum class Token : uint64_t { @@ -116,7 +100,7 @@ namespace BlitzLLVM { std::pair GetNextToken(std::shared_ptr fs); private: - BlitzLLVM::Lexer::Token ConvertTextToToken(Token in, std::string text); + blitz::Lexer::Token ConvertTextToToken(Token in, std::string text); private: Token m_currentToken = Token::TokenUnknown; diff --git a/code_compiler/source/main.cpp b/code_compiler/source/main.cpp index d953525..624f8dc 100644 --- a/code_compiler/source/main.cpp +++ b/code_compiler/source/main.cpp @@ -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 . - #include -#include "boost/program_options.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) { - std::string optInput; - bool optQuiet, optVerbose; - -#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(&optQuiet)->default_value(false), "Use quieter logging.") - ("verbose,v", boost::program_options::value(&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(&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] " << '\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 + blitz::compiler comp; + comp.compile(argv[1], std::string(argv[1]) + ".exe"); std::cin.get(); -#endif return 0; } diff --git a/code_compiler/source/parser.cpp b/code_compiler/source/parser.cpp index 5e4c1a1..fef4c8e 100644 --- a/code_compiler/source/parser.cpp +++ b/code_compiler/source/parser.cpp @@ -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 . - #include "parser.hpp" #include "ast/function.hpp" #include #include #include -BlitzLLVM::Parser::Parser(std::string file) { +blitz::parser::parser(std::string file) { // Try and load the file std::shared_ptr instream = std::make_shared(file); if (instream->bad() || !instream->good()) { @@ -29,7 +13,7 @@ BlitzLLVM::Parser::Parser(std::string file) { m_files.push(std::make_pair(file, instream)); } -BlitzLLVM::Parser::~Parser() { +blitz::parser::~parser() { while (m_files.size() > 0) { std::shared_ptr file = std::dynamic_pointer_cast(m_files.top().second); file->close(); @@ -37,18 +21,18 @@ BlitzLLVM::Parser::~Parser() { } } -std::unique_ptr BlitzLLVM::Parser::Parse() { +std::unique_ptr blitz::parser::Parse() { std::unique_ptr scope = std::make_unique(); std::unique_ptr expr; - while ((expr = std::move(ParseExpression())) != nullptr) { + while ((expr = std::move(parse_expression())) != nullptr) { scope->AddExpression(std::move(expr)); } return std::move(scope); } -void BlitzLLVM::Parser::LogMessage(const char* msg, ...) { +void blitz::parser::LogMessage(const char* msg, ...) { std::vector buf(65535); va_list val; va_start(val, msg); @@ -57,7 +41,7 @@ void BlitzLLVM::Parser::LogMessage(const char* msg, ...) { std::cout << buf.data() << '\n'; } -void BlitzLLVM::Parser::LogError(const char* msg, ...) { +void blitz::parser::LogError(const char* msg, ...) { std::vector buf(65535); va_list val; va_start(val, msg); @@ -66,33 +50,33 @@ void BlitzLLVM::Parser::LogError(const char* msg, ...) { std::cerr << buf.data() << '\n'; } -std::pair BlitzLLVM::Parser::GetNextToken() { +std::pair blitz::parser::GetNextToken() { return m_lexer.GetNextToken(m_files.top().second); } -std::unique_ptr BlitzLLVM::Parser::ParseExpression() { +std::unique_ptr blitz::parser::parse_expression() { while (true) { auto tkn = GetNextToken(); switch (tkn.first) { - case BlitzLLVM::Lexer::Token::TokenNewLine: - case BlitzLLVM::Lexer::Token::TokenComment: + case blitz::Lexer::Token::TokenNewLine: + case blitz::Lexer::Token::TokenComment: // Skip Comments, since we don't really need them for the AST. continue; - case BlitzLLVM::Lexer::Token::TokenPlus: - case BlitzLLVM::Lexer::Token::TokenMinus: + case blitz::Lexer::Token::TokenPlus: + case blitz::Lexer::Token::TokenMinus: default: // End Of File / Unknown - case BlitzLLVM::Lexer::Token::TokenUnknown: - case BlitzLLVM::Lexer::Token::TokenEOF: + case blitz::Lexer::Token::TokenUnknown: + case blitz::Lexer::Token::TokenEOF: return nullptr; break; } } } -std::unique_ptr BlitzLLVM::Parser::ParseNumber(BlitzLLVM::Lexer::Token token, std::string value) { +std::unique_ptr blitz::parser::parse_number(blitz::Lexer::Token token, std::string value) { if (token != Lexer::Token::TokenNumber) { LogError("Unexpected Token during parsing, expected number."); return nullptr; @@ -105,10 +89,10 @@ std::unique_ptr BlitzLLVM::Parser::ParseNumber return nullptr; } - return std::make_unique(parsed); + return std::make_unique(parsed); } -std::unique_ptr BlitzLLVM::Parser::ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value) { +std::unique_ptr blitz::parser::parse_decimal(blitz::Lexer::Token token, std::string value) { if (token != Lexer::Token::TokenNumber) { LogError("Unexpected Token during parsing, expected number."); return nullptr; @@ -121,5 +105,5 @@ std::unique_ptr BlitzLLVM::Parser::ParseDecim return nullptr; } - return std::make_unique(parsed); + return std::make_unique(parsed); } diff --git a/code_compiler/source/parser.hpp b/code_compiler/source/parser.hpp index af99a0c..9a27315 100644 --- a/code_compiler/source/parser.hpp +++ b/code_compiler/source/parser.hpp @@ -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 . - #pragma once #include "lexer.hpp" #include "ast/ast.hpp" @@ -24,11 +8,11 @@ #include #include -namespace BlitzLLVM { - class Parser { +namespace blitz { + class parser { public: - Parser(std::string file); - ~Parser(); + parser(std::string file); + ~parser(); std::unique_ptr Parse(); @@ -37,12 +21,12 @@ namespace BlitzLLVM { void LogError(const char* msg, ...); private: - std::pair GetNextToken(); + std::pair GetNextToken(); private: - std::unique_ptr ParseExpression(); - std::unique_ptr ParseNumber(BlitzLLVM::Lexer::Token token, std::string value); - std::unique_ptr ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value); + std::unique_ptr parse_expression(); + std::unique_ptr parse_number(blitz::Lexer::Token token, std::string value); + std::unique_ptr parse_decimal(blitz::Lexer::Token token, std::string value); private: Lexer m_lexer; diff --git a/code_compiler/templates/version.h b/code_compiler/templates/version.h deleted file mode 100644 index 2061084..0000000 --- a/code_compiler/templates/version.h +++ /dev/null @@ -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))