From 00b37f0d0508ebf24759449eb8fb716e932fa3cf Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 12 Nov 2017 01:38:50 +0100 Subject: [PATCH] code_compiler: Add LLVM, Boost, licensing and help Boost is used to parse program arguments into a usable format, print help and so on. This makes it far easier to quickly get off the ground and is also reasonably fast with relatively small impact. Since Boost provides prebuilt versions with all recent compilers, it shouldn't impact newer people. LLVM will be used for compiling the actual code, as of right now there is no Tokenizer, Parser or Compiler implemented. This will be the biggest task as it requires careful planning in order to not end up like Mark Sibly did with BlitzBasic and all the programming languages that ended up being created by it. Additionally removed the VERSION_BUILD from the template so that version updates work better. --- projects/code_compiler/CMakeLists.txt | 42 +++++---- projects/code_compiler/CMakeVersion.txt | 1 - projects/code_compiler/source/main.cpp | 105 +++++++++++++++++++++ projects/code_compiler/templates/version.h | 1 - 4 files changed, 131 insertions(+), 18 deletions(-) diff --git a/projects/code_compiler/CMakeLists.txt b/projects/code_compiler/CMakeLists.txt index fa17ec1..4c3c8a9 100644 --- a/projects/code_compiler/CMakeLists.txt +++ b/projects/code_compiler/CMakeLists.txt @@ -2,17 +2,15 @@ cmake_minimum_required(VERSION 2.8.12) project(CodeCompiler) # Configuration -SET(THIRDPARTY_LLVM "${CMAKE_SOURCE_DIR}/thirdparty/llvm" CACHE PATH "Path to LLVM source code") ## Dependencies # LLVM -SET(LLVM_BUILD_TOOLS OFF) -SET(LLVM_BUILD_EXAMPLES OFF) -SET(LLVM_BUILD_TESTS OFF) -SET(LLVM_INCLUDE_TESTS OFF) -SET(BUILD_SHARED_LIBS OFF) -SET(LLVM_BUILD_LLVM_DYLIB OFF) -ADD_SUBDIRECTORY("${DEPENDENCY_LLVM}") +find_package(LLVM REQUIRED CONFIG) +llvm_map_components_to_libnames(llvm_libs support core irreader) + +# Boost +SET(Boost_USE_STATIC_LIBS ON) +find_package(Boost REQUIRED COMPONENTS program_options) ## Version INCLUDE("CMakeVersion.txt") @@ -23,22 +21,34 @@ SET(SOURCE "source/main.cpp" ) SET(DATA - "templates/version.h" + "CMakeVersion.txt" ) -# Include Directories +# Definitions +ADD_DEFINITIONS( + ${LLVM_DEFINITIONS} +) + +# Directories INCLUDE_DIRECTORIES( - "${CMAKE_SOURCE_DIR}" - "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/source" - "${THIRDPARTY_LLVM}/include" "${PROJECT_BINARY_DIR}" + ${LLVM_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} +) +LINK_DIRECTORIES( + ${LLVM_LIBRARY_DIRS} + ${Boost_LIBRARY_DIRS} ) # Building -add_executable(${PROJECT_NAME} ${SOURCE}) +ADD_EXECUTABLE(cc + ${SOURCE} + ${DATA} +) # Linking -TARGET_LINK_LIBRARIES(${PROJECT_NAME} - LLVM +TARGET_LINK_LIBRARIES(cc + ${Boost_LIBRARIES} + ${llvm_libs} ) diff --git a/projects/code_compiler/CMakeVersion.txt b/projects/code_compiler/CMakeVersion.txt index c485331..e6dce61 100644 --- a/projects/code_compiler/CMakeVersion.txt +++ b/projects/code_compiler/CMakeVersion.txt @@ -1,7 +1,6 @@ SET(VERSION_MAJOR 0) SET(VERSION_MINOR 0) SET(VERSION_PATCH 1) -SET(VERSION_BUILD 0) configure_file( "${PROJECT_SOURCE_DIR}/templates/version.h" "${PROJECT_BINARY_DIR}/version.h" diff --git a/projects/code_compiler/source/main.cpp b/projects/code_compiler/source/main.cpp index 6bcd22a..6c45926 100644 --- a/projects/code_compiler/source/main.cpp +++ b/projects/code_compiler/source/main.cpp @@ -1,4 +1,109 @@ +// 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 "version.h" + +#define LICENSE "Copyright (C) 2017 Michael Fabian Dirks\n\ +This program comes with ABSOLUTELY NO WARRANTY, for details launch with `--warranty`. 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 + + + +#pragma endregion Process Input + +#ifdef _DEBUG + std::cin.get(); +#endif + return 0; } \ No newline at end of file diff --git a/projects/code_compiler/templates/version.h b/projects/code_compiler/templates/version.h index 3cd9dea..2061084 100644 --- a/projects/code_compiler/templates/version.h +++ b/projects/code_compiler/templates/version.h @@ -3,5 +3,4 @@ #define VERSION_MAJOR @VERSION_MAJOR@ #define VERSION_MINOR @VERSION_MINOR@ #define VERSION_PATCH @VERSION_PATCH@ -#define VERSION_BUILD @VERSION_BUILD@ #define VERSION_FULL (((uint64_t)VERSION_MAJOR << 48ull) | ((uint64_t)VERSION_MINOR << 32ull) | ((uint64_t)VERSION_PATCH << 16ull) | ((uint64_t)VERSION_BUILD))