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.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2017-11-12 01:38:50 +01:00
parent c0556b3b16
commit 00b37f0d05
4 changed files with 131 additions and 18 deletions
+26 -16
View File
@@ -2,17 +2,15 @@ cmake_minimum_required(VERSION 2.8.12)
project(CodeCompiler) project(CodeCompiler)
# Configuration # Configuration
SET(THIRDPARTY_LLVM "${CMAKE_SOURCE_DIR}/thirdparty/llvm" CACHE PATH "Path to LLVM source code")
## Dependencies ## Dependencies
# LLVM # LLVM
SET(LLVM_BUILD_TOOLS OFF) find_package(LLVM REQUIRED CONFIG)
SET(LLVM_BUILD_EXAMPLES OFF) llvm_map_components_to_libnames(llvm_libs support core irreader)
SET(LLVM_BUILD_TESTS OFF)
SET(LLVM_INCLUDE_TESTS OFF) # Boost
SET(BUILD_SHARED_LIBS OFF) SET(Boost_USE_STATIC_LIBS ON)
SET(LLVM_BUILD_LLVM_DYLIB OFF) find_package(Boost REQUIRED COMPONENTS program_options)
ADD_SUBDIRECTORY("${DEPENDENCY_LLVM}")
## Version ## Version
INCLUDE("CMakeVersion.txt") INCLUDE("CMakeVersion.txt")
@@ -23,22 +21,34 @@ SET(SOURCE
"source/main.cpp" "source/main.cpp"
) )
SET(DATA SET(DATA
"templates/version.h" "CMakeVersion.txt"
) )
# Include Directories # Definitions
ADD_DEFINITIONS(
${LLVM_DEFINITIONS}
)
# Directories
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
"${CMAKE_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/source" "${PROJECT_SOURCE_DIR}/source"
"${THIRDPARTY_LLVM}/include"
"${PROJECT_BINARY_DIR}" "${PROJECT_BINARY_DIR}"
${LLVM_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
LINK_DIRECTORIES(
${LLVM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
) )
# Building # Building
add_executable(${PROJECT_NAME} ${SOURCE}) ADD_EXECUTABLE(cc
${SOURCE}
${DATA}
)
# Linking # Linking
TARGET_LINK_LIBRARIES(${PROJECT_NAME} TARGET_LINK_LIBRARIES(cc
LLVM ${Boost_LIBRARIES}
${llvm_libs}
) )
-1
View File
@@ -1,7 +1,6 @@
SET(VERSION_MAJOR 0) SET(VERSION_MAJOR 0)
SET(VERSION_MINOR 0) SET(VERSION_MINOR 0)
SET(VERSION_PATCH 1) SET(VERSION_PATCH 1)
SET(VERSION_BUILD 0)
configure_file( configure_file(
"${PROJECT_SOURCE_DIR}/templates/version.h" "${PROJECT_SOURCE_DIR}/templates/version.h"
"${PROJECT_BINARY_DIR}/version.h" "${PROJECT_BINARY_DIR}/version.h"
+105
View File
@@ -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 <https://www.gnu.org/licenses/>.
#include <iostream>
#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) { 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
#pragma endregion Process Input
#ifdef _DEBUG
std::cin.get();
#endif
return 0;
} }
@@ -3,5 +3,4 @@
#define VERSION_MAJOR @VERSION_MAJOR@ #define VERSION_MAJOR @VERSION_MAJOR@
#define VERSION_MINOR @VERSION_MINOR@ #define VERSION_MINOR @VERSION_MINOR@
#define VERSION_PATCH @VERSION_PATCH@ #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)) #define VERSION_FULL (((uint64_t)VERSION_MAJOR << 48ull) | ((uint64_t)VERSION_MINOR << 32ull) | ((uint64_t)VERSION_PATCH << 16ull) | ((uint64_t)VERSION_BUILD))