Modernize and remove useless header text
This commit is contained in:
+2
-2
@@ -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)
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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"
|
||||
|
||||
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)) {}
|
||||
|
||||
BlitzLLVM::AST::ArithmeticExpression::~ArithmeticExpression() {}
|
||||
blitz::AST::ArithmeticExpression::~ArithmeticExpression() {}
|
||||
|
||||
@@ -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
|
||||
#include "ast.hpp"
|
||||
#include "value.hpp"
|
||||
|
||||
namespace BlitzLLVM {
|
||||
namespace blitz {
|
||||
namespace AST {
|
||||
enum class Operator : int8_t {
|
||||
Add, /*+*/
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
|
||||
namespace BlitzLLVM {
|
||||
namespace blitz {
|
||||
namespace AST {
|
||||
class Expression {
|
||||
public:
|
||||
|
||||
@@ -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"
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
BlitzLLVM::AST::FunctionExpression::FunctionExpression(ValueType returnType,
|
||||
blitz::AST::FunctionExpression::FunctionExpression(ValueType returnType,
|
||||
std::string& m_name,
|
||||
std::list<std::unique_ptr<VariableExpression>> parameters,
|
||||
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)) {
|
||||
|
||||
}
|
||||
|
||||
BlitzLLVM::AST::CallExpression::~CallExpression() {}
|
||||
blitz::AST::CallExpression::~CallExpression() {}
|
||||
|
||||
@@ -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
|
||||
#include "ast.hpp"
|
||||
#include "value.hpp"
|
||||
@@ -21,7 +5,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace BlitzLLVM {
|
||||
namespace blitz {
|
||||
namespace AST {
|
||||
class ScopeExpression : public Expression {
|
||||
public:
|
||||
|
||||
@@ -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"
|
||||
|
||||
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<ValueExpression> value)
|
||||
blitz::AST::ConstExpression::ConstExpression(std::string& name, std::unique_ptr<ValueExpression> 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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
#include "ast.hpp"
|
||||
#include "lexer.hpp"
|
||||
@@ -23,7 +7,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace BlitzLLVM {
|
||||
namespace blitz {
|
||||
namespace AST {
|
||||
enum class ValueType : int8_t {
|
||||
Unknown,
|
||||
|
||||
@@ -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 "parser.hpp"
|
||||
#include "lexer.hpp"
|
||||
#include <fstream>
|
||||
#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;
|
||||
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()) {
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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 <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::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::Token, std::string> BlitzLLVM::Lexer::GetCurrentToken() {
|
||||
std::pair<blitz::Lexer::Token, std::string> blitz::Lexer::GetCurrentToken() {
|
||||
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;
|
||||
Token tkn = Token::TokenEOF;
|
||||
bool haveResult = false;
|
||||
@@ -213,7 +196,7 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> 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<const char*, Token> l_textToTokenList[] = {
|
||||
// Binary
|
||||
{ "not", Token::TokenNot },
|
||||
|
||||
@@ -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
|
||||
#include <inttypes.h>
|
||||
#include <istream>
|
||||
@@ -21,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace BlitzLLVM {
|
||||
namespace blitz {
|
||||
class Lexer {
|
||||
public:
|
||||
enum class Token : uint64_t {
|
||||
@@ -116,7 +100,7 @@ namespace BlitzLLVM {
|
||||
std::pair<Token, std::string> GetNextToken(std::shared_ptr<std::istream> 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;
|
||||
|
||||
@@ -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 "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<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
|
||||
blitz::compiler comp;
|
||||
comp.compile(argv[1], std::string(argv[1]) + ".exe");
|
||||
std::cin.get();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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 "ast/function.hpp"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdarg.h>
|
||||
|
||||
BlitzLLVM::Parser::Parser(std::string file) {
|
||||
blitz::parser::parser(std::string file) {
|
||||
// Try and load the file
|
||||
std::shared_ptr<std::ifstream> instream = std::make_shared<std::ifstream>(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<std::ifstream> file = std::dynamic_pointer_cast<std::ifstream>(m_files.top().second);
|
||||
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::Expression> 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<char> 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<char> 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::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);
|
||||
}
|
||||
|
||||
std::unique_ptr<BlitzLLVM::AST::Expression> BlitzLLVM::Parser::ParseExpression() {
|
||||
std::unique_ptr<blitz::AST::Expression> 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::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) {
|
||||
LogError("Unexpected Token during parsing, expected number.");
|
||||
return nullptr;
|
||||
@@ -105,10 +89,10 @@ std::unique_ptr<BlitzLLVM::AST::NumberExpression> BlitzLLVM::Parser::ParseNumber
|
||||
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) {
|
||||
LogError("Unexpected Token during parsing, expected number.");
|
||||
return nullptr;
|
||||
@@ -121,5 +105,5 @@ std::unique_ptr<BlitzLLVM::AST::DecimalExpression> BlitzLLVM::Parser::ParseDecim
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_unique<BlitzLLVM::AST::DecimalExpression>(parsed);
|
||||
return std::make_unique<blitz::AST::DecimalExpression>(parsed);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
#include "lexer.hpp"
|
||||
#include "ast/ast.hpp"
|
||||
@@ -24,11 +8,11 @@
|
||||
#include <string>
|
||||
#include <stack>
|
||||
|
||||
namespace BlitzLLVM {
|
||||
class Parser {
|
||||
namespace blitz {
|
||||
class parser {
|
||||
public:
|
||||
Parser(std::string file);
|
||||
~Parser();
|
||||
parser(std::string file);
|
||||
~parser();
|
||||
|
||||
std::unique_ptr<AST::Expression> Parse();
|
||||
|
||||
@@ -37,12 +21,12 @@ namespace BlitzLLVM {
|
||||
void LogError(const char* msg, ...);
|
||||
|
||||
private:
|
||||
std::pair<BlitzLLVM::Lexer::Token, std::string> GetNextToken();
|
||||
std::pair<blitz::Lexer::Token, std::string> GetNextToken();
|
||||
|
||||
private:
|
||||
std::unique_ptr<AST::Expression> ParseExpression();
|
||||
std::unique_ptr<AST::NumberExpression> ParseNumber(BlitzLLVM::Lexer::Token token, std::string value);
|
||||
std::unique_ptr<AST::DecimalExpression> ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value);
|
||||
std::unique_ptr<AST::Expression> parse_expression();
|
||||
std::unique_ptr<AST::NumberExpression> parse_number(blitz::Lexer::Token token, std::string value);
|
||||
std::unique_ptr<AST::DecimalExpression> parse_decimal(blitz::Lexer::Token token, std::string value);
|
||||
|
||||
private:
|
||||
Lexer m_lexer;
|
||||
|
||||
@@ -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))
|
||||
Reference in New Issue
Block a user