From 225ff6bba1ec6ec5b2d155c2df1874d0c2d7e903 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Mon, 27 Sep 2021 13:05:15 +0100 Subject: [PATCH] Refactor the main cmake list file and fix the unused warns --- CMakeLists.txt | 136 ++++++++++++++++++++++--------- bin/CMakeLists.txt | 31 +++++-- builder | 7 +- dev.org | 8 +- include/serene/context.h | 6 ++ include/serene/exprs/call.h | 13 ++- include/serene/exprs/def.h | 13 ++- include/serene/exprs/fn.h | 13 ++- include/serene/exprs/list.h | 8 +- include/serene/exprs/number.h | 8 +- include/serene/exprs/symbol.h | 8 +- include/serene/jit.h | 5 ++ include/serene/reader/errors.h | 65 --------------- include/serene/reader/location.h | 6 +- include/serene/reader/reader.h | 1 - src/serene/CMakeLists.txt | 71 ++++++---------- src/serene/diagnostics.cpp | 6 +- src/serene/exprs/call.cpp | 12 ++- src/serene/exprs/def.cpp | 5 +- src/serene/exprs/fn.cpp | 5 +- src/serene/exprs/number.cpp | 5 +- src/serene/exprs/symbol.cpp | 8 +- src/serene/jit.cpp | 1 + src/serene/reader/errors.cpp | 32 -------- 24 files changed, 231 insertions(+), 242 deletions(-) delete mode 100644 include/serene/reader/errors.h delete mode 100644 src/serene/reader/errors.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b37c6d..23f8aa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,24 @@ +# Serene programming language. +# +# Copyright (c) 2019-2021 Sameer Rahmani +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. cmake_minimum_required(VERSION 3.16) # Project name and a few useful settings. Other commands can pick up the results @@ -6,13 +27,23 @@ project(Serene DESCRIPTION "Serene language is a modern Lisp." LANGUAGES CXX C) +# Clangd command file set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +# Policies ========================== +cmake_policy(SET CMP0116 NEW) + +# User Options ====================== option(CPP_20_SUPPORT "C++20 Support" OFF) +option(SERENE_BUILD_TESTING "Enable tests" OFF) +option(SERENE_ENABLE_BUILDID "Enable build id." OFF) +option(SERENE_ENABLE_THINLTO "Enable ThisLTO." ON) +option(SERENE_ENABLE_ASAN "Enable address sanitizer" ON) +option(SERENE_ENABLE_DOCS "Enable document generation" OFF) # Only do these if this is the main project, and not if it is included through add_subdirectory if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - - ## Settings ----------------------------------------- + ## Settings ======================= # specify the C++ standard if (CPP_20_SUPPORT) set(CMAKE_CXX_STANDARD 20) @@ -22,50 +53,73 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(CMAKE_CXX_STANDARD_REQUIRED True) + # Setup the source locations set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include) set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) set(BIN_DIR ${CMAKE_SOURCE_DIR}/bin) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") - #set(CMAKE_CXX_LINK_EXECUTABLE "ld.lld") - #set(CMAKE_C_LINK_EXECUTABLE "ld.lld") - #set(LLVM_USE_LINKER "ld.lld") - #set(LLVM_ENABLE_LLD ON) set(CMAKE_CXX_CLANG_TIDY clang-tidy) # Let's ensure -std=c++xx instead of -std=g++xx set(CMAKE_CXX_EXTENSIONS OFF) - set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -g -fno-omit-frame-pointer $ENV{ASAN_FLAG} -fno-builtin-strlen -ggdb -fno-inline -fdebug-prefix-map=$PWD=.") - set(CMAKE_LINKER_FLAGS_DEBUG - "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer $ENV{ASAN_FLAG}") - - set(CMAKE_CXX_FLAGS_RELEASE - "${CMAKE_CXX_FLAGS_RELEASE} -O3") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/scripts/cmake") set(MemoryCheckCommand "valgrind") - add_compile_options(-fno-rtti) - configure_file(${INCLUDE_DIR}/serene/config.h.in serene/config.h) # Let's nicely support folders in IDEs set_property(GLOBAL PROPERTY USE_FOLDERS ON) - ## Options ------------------------------------------ - option(ENABLE_LOG "Enable logging" OFF) - option(ENABLE_EXPR_LOG "Enable AExpr logging" OFF) - option(ENABLE_READER_LOG "Enable reader logging" OFF) - option(BUILD_TESTING "Enable tests" OFF) + # Setup the basic compiler flags + add_compile_options( + -Wall + -Wextra + -Werror + -fno-rtti + -fno-builtin-strlen + # Dedicate a section to each function, so the linker + # can do a better job on dead code elimination + -ffunction-sections + -fdata-sections - include(cotire) - include(FetchContent) + $<$:-g3> + $<$:-ggdb> + # For the sake of debugging + $<$:-fno-inline> + # To make the local ccache happy + $<$:-fdebug-prefix-map=$PWD=.> + $<$:-fno-omit-frame-pointer> + $<$:-fomit-frame-pointer> + + $<$:-O3> + ) + + add_link_options( + # We enforce the lld linker + -fuse-ld=lld + -fsanitize=address + # Do not link against shared libraries + #--static + ) + + if(SERENE_ENABLE_BUILDID) + add_link_options(-Wl,--build-id) + endif() + + if(SERENE_ENABLE_ASAN) + add_compile_options(-fsanitize=address) + endif() + + if(SERENE_ENABLE_THINLTO) + endif() + + # LLVM setup ========================================= find_package(LLVM REQUIRED CONFIG) find_package(MLIR REQUIRED CONFIG) - message(STATUS "Found LLVM ${LLVM_PAsCKAGE_VERSION}") + message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") @@ -81,36 +135,42 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(AddMLIR) include(HandleLLVMOptions) - include_directories(${LLVM_INCLUDE_DIRS}) - include_directories(${MLIR_INCLUDE_DIRS}) - include_directories(${PROJECT_SOURCE_DIR}/include) - include_directories(${PROJECT_BINARY_DIR}/include) - link_directories(${LLVM_BUILD_LIBRARY_DIR}) - add_definitions(${LLVM_DEFINITIONS}) - include_directories(${LLVM_INCLUDE_DIRS}) + + include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) + separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) + add_definitions(${LLVM_DEFINITIONS_LIST}) + + link_directories(${LLVM_BUILD_LIBRARY_DIR}) add_definitions(${LLVM_DEFINITIONS}) llvm_map_components_to_libnames(llvm_libs support core irreader) + + + # Serene Setup =================================== + include_directories(${PROJECT_SOURCE_DIR}/include) + + # We don't want the generated files from table gen + # to be treated as local since the contain warnings + include_directories(SYSTEM ${PROJECT_BINARY_DIR}/include) + include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) + # The compiled library code is here add_subdirectory(src/serene) - # The executable code is here add_subdirectory(bin) - add_subdirectory(include) - include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) + # Testing only available if this is the main app # Emergency override SERENE_CMAKE_BUILD_TESTING provided as well - if(BUILD_TESTING) + if(SERENE_BUILD_TESTING) message("Build the test binary") add_subdirectory(src/tests) endif() - if (CMAKE_BUILD_TYPE STREQUAL "Release") + if (SERENE_ENABLE_DOCS) # Docs only available if this is the main app - find_package(Doxygen REQUIRED dot OPTIONAL_COMPONENTS dia) @@ -121,6 +181,4 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) message(STATUS "Doxygen not found, not building docs") endif() endif() - - endif() diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 0f33abe..cd6cb86 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -1,7 +1,26 @@ -add_executable(serenec serene.cpp) +# Serene programming language. +# +# Copyright (c) 2019-2021 Sameer Rahmani +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. -# Make sure to generate files related to the dialects first -#add_dependencies(serenec SereneDialectGen) +add_executable(serenec serene.cpp) if (CPP_20_SUPPORT) target_compile_features(serenec PRIVATE cxx_std_20) @@ -10,8 +29,6 @@ else() endif() - - target_link_libraries(serenec PRIVATE serene ${llvm_libs} @@ -32,8 +49,8 @@ target_link_libraries(serenec PRIVATE ) -target_include_directories(serene SYSTEM PRIVATE $ENV{INCLUDE}) +#target_include_directories(serene SYSTEM PRIVATE $ENV{INCLUDE}) target_include_directories(serene PRIVATE ${INCLUDE_DIR}) install(TARGETS serenec DESTINATION bin) -install(FILES "${PROJECT_BINARY_DIR}/config.h" DESTINATION include) +#install(FILES "${PROJECT_BINARY_DIR}/config.h" DESTINATION include) diff --git a/builder b/builder index 44dac05..b9defbf 100755 --- a/builder +++ b/builder @@ -19,8 +19,6 @@ export CXX=$(which clang++) export CCACHE_SLOPPINESS="pch_defines,time_macros" # Meke sure to use `lld` linker it faster and has a better UX -export LDFLAGS="-fuse-ld=lld" -export ASAN_FLAG="-fsanitize=address" export ASAN_OPTIONS=check_initialization_order=1 LSAN_OPTIONS=suppressions=$(pwd)/.ignore_sanitize export LSAN_OPTIONS @@ -28,6 +26,7 @@ export LSAN_OPTIONS # The `builder` script is supposed to be run from the # root of the source tree ROOT_DIR=$(pwd) +CMAKEARGS="-DLLVM_PARALLEL_COMPILE_JOBS=7 -DLLVM_PARALLEL_LINK_JOBS=7 " BUILD_DIR=$ROOT_DIR/build ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P) @@ -60,8 +59,8 @@ function compile() { function build() { pushed_build echo "Running: " - echo "cmake -G Ninja $CMAKE_CCACHE -DCMAKE_BUILD_TYPE=Debug \"$@\" \"$ROOT_DIR\"" - cmake -G Ninja $CMAKE_CCACHE -DCMAKE_BUILD_TYPE=Debug "$@" "$ROOT_DIR" + echo "cmake -G Ninja $CMAKE_CCACHE $CMAKEARGS -DCMAKE_BUILD_TYPE=Debug \"$@\" \"$ROOT_DIR\"" + cmake -G Ninja $CMAKE_CCACHE $CMAKEARGS -DCMAKE_BUILD_TYPE=Debug "$@" "$ROOT_DIR" cmake --build . popd_build } diff --git a/dev.org b/dev.org index a2c8c8f..127f83a 100644 --- a/dev.org +++ b/dev.org @@ -108,7 +108,13 @@ on ADF * TODOs ** Bootstrap* -*** TODO Add the support for =ns-paths= :serenecli:context: +*** TODO Investigate the huge size of serenec +- Checkout -ffunction-sections -fdata-sections flags of lld +*** DONE Add the support for =ns-paths= :serenecli:context: +CLOSED: [2021-09-25 Sat 19:22] +:LOGBOOK: +- State "DONE" from "TODO" [2021-09-25 Sat 19:22] +:END: We need to add the support for an array of paths to lookup namespaces. The =ns-paths= should be an array that each entry represents a path which serene has to look into in order to find a namespace. For instance, when serene wants to load the =foo.bar= namespace, it should walk diff --git a/include/serene/context.h b/include/serene/context.h index d8186f8..cfe478a 100644 --- a/include/serene/context.h +++ b/include/serene/context.h @@ -32,6 +32,7 @@ #include "serene/slir/dialect.h" #include "serene/source_mgr.h" +#include #include #include #include @@ -118,6 +119,11 @@ public: targetPhase(CompilationPhase::NoOptimization) { mlirContext.getOrLoadDialect(); mlirContext.getOrLoadDialect(); + + // We need to create one empty namespace, so that the JIT can + // start it's operation. + auto ns = makeNamespace(*this, "serene.user", llvm::None); + // TODO: Get the crash report path dynamically from the cli // pm.enableCrashReproducerGeneration("/home/lxsameer/mlir.mlir"); diff --git a/include/serene/exprs/call.h b/include/serene/exprs/call.h index 13bddaa..732d627 100644 --- a/include/serene/exprs/call.h +++ b/include/serene/exprs/call.h @@ -30,9 +30,8 @@ #include "serene/exprs/expression.h" #include "serene/exprs/list.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Error.h" - +#include +#include #include #include @@ -54,10 +53,10 @@ public: Call(Call &) = delete; - ExprType getType() const; - std::string toString() const; - MaybeNode analyze(SereneContext &); - void generateIR(serene::Namespace &, mlir::ModuleOp &){}; + ExprType getType() const override; + std::string toString() const override; + MaybeNode analyze(SereneContext &) override; + void generateIR(serene::Namespace &, mlir::ModuleOp &) override{}; static bool classof(const Expression *e); diff --git a/include/serene/exprs/def.h b/include/serene/exprs/def.h index ebfb316..d1b49e3 100644 --- a/include/serene/exprs/def.h +++ b/include/serene/exprs/def.h @@ -29,9 +29,8 @@ #include "serene/errors/error.h" #include "serene/exprs/expression.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Error.h" - +#include +#include #include #include @@ -53,10 +52,10 @@ public: Def(Def &d) = delete; - ExprType getType() const; - std::string toString() const; - MaybeNode analyze(SereneContext &); - void generateIR(serene::Namespace &, mlir::ModuleOp &); + ExprType getType() const override; + std::string toString() const override; + MaybeNode analyze(SereneContext &) override; + void generateIR(serene::Namespace &, mlir::ModuleOp &) override; static bool classof(const Expression *e); diff --git a/include/serene/exprs/fn.h b/include/serene/exprs/fn.h index 8b4b4c4..effcef9 100644 --- a/include/serene/exprs/fn.h +++ b/include/serene/exprs/fn.h @@ -31,9 +31,8 @@ #include "serene/exprs/list.h" #include "serene/namespace.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Error.h" - +#include +#include #include #include @@ -57,10 +56,10 @@ public: Fn(Fn &f) = delete; - ExprType getType() const; - std::string toString() const; - MaybeNode analyze(SereneContext &); - void generateIR(serene::Namespace &, mlir::ModuleOp &); + ExprType getType() const override; + std::string toString() const override; + MaybeNode analyze(SereneContext &) override; + void generateIR(serene::Namespace &, mlir::ModuleOp &) override; static bool classof(const Expression *e); diff --git a/include/serene/exprs/list.h b/include/serene/exprs/list.h index 4151a95..8c5bb01 100644 --- a/include/serene/exprs/list.h +++ b/include/serene/exprs/list.h @@ -50,8 +50,8 @@ public: List(const reader::LocationRange &loc, Node &e); List(const reader::LocationRange &loc, Ast elems); - ExprType getType() const; - std::string toString() const; + ExprType getType() const override; + std::string toString() const override; void append(Node); @@ -77,8 +77,8 @@ public: /// by the for loop. std::vector::iterator end(); - MaybeNode analyze(SereneContext &); - void generateIR(serene::Namespace &, mlir::ModuleOp &){}; + MaybeNode analyze(SereneContext &) override; + void generateIR(serene::Namespace &, mlir::ModuleOp &) override{}; ~List() = default; diff --git a/include/serene/exprs/number.h b/include/serene/exprs/number.h index 274eada..3284760 100644 --- a/include/serene/exprs/number.h +++ b/include/serene/exprs/number.h @@ -50,11 +50,11 @@ struct Number : public Expression { bool isFloat) : Expression(loc), value(num), isNeg(isNeg), isFloat(isFloat){}; - ExprType getType() const; - std::string toString() const; + ExprType getType() const override; + std::string toString() const override; - MaybeNode analyze(SereneContext &ctx); - void generateIR(serene::Namespace &, mlir::ModuleOp &); + MaybeNode analyze(SereneContext &ctx) override; + void generateIR(serene::Namespace &, mlir::ModuleOp &) override; // TODO: This is horrible, we need to fix it after the mvp int toI64(); diff --git a/include/serene/exprs/symbol.h b/include/serene/exprs/symbol.h index b6a0aeb..ce2fe4e 100644 --- a/include/serene/exprs/symbol.h +++ b/include/serene/exprs/symbol.h @@ -47,11 +47,11 @@ public: Symbol(Symbol &s) : Expression(s.location) { this->name = s.name; } - ExprType getType() const; - std::string toString() const; + ExprType getType() const override; + std::string toString() const override; - MaybeNode analyze(SereneContext &); - void generateIR(serene::Namespace &, mlir::ModuleOp &){}; + MaybeNode analyze(SereneContext &) override; + void generateIR(serene::Namespace &, mlir::ModuleOp &) override{}; ~Symbol() = default; diff --git a/include/serene/jit.h b/include/serene/jit.h index 752cfb1..3b13f85 100644 --- a/include/serene/jit.h +++ b/include/serene/jit.h @@ -22,6 +22,10 @@ * SOFTWARE. */ +/** + * Commentary: + */ + #ifndef SERENE_JIT_H #define SERENE_JIT_H @@ -153,6 +157,7 @@ public: (void)dummy; return invokePacked(adapterName, argsArray); }; + /// Dump object code to output file `filename`. void dumpToObjectFile(llvm::StringRef filename); diff --git a/include/serene/reader/errors.h b/include/serene/reader/errors.h deleted file mode 100644 index 40c7697..0000000 --- a/include/serene/reader/errors.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- C++ -*- - * Serene programming language. - * - * Copyright (c) 2019-2021 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef SERENE_READER_ERRORS_H -#define SERENE_READER_ERRORS_H -#include "serene/errors.h" - -namespace serene { -namespace reader { - -class ReadError : public std::exception { -private: - char *message; - -public: - ReadError(char *msg) : message(msg){}; - const char *what() const throw() { return message; } -}; - -class MissingFileError : public llvm::ErrorInfo { - - using llvm::ErrorInfo::log; - using llvm::ErrorInfo::convertToErrorCode; - -public: - static char ID; - std::string path; - - // TODO: Move this to an error namespace somewhere. - int file_is_missing = int(); - - void log(llvm::raw_ostream &os) const { - os << "File does not exist: " << path << "\n"; - } - - MissingFileError(llvm::StringRef path) : path(path.str()){}; - std::error_code convertToErrorCode() const { - return make_error_code(errc::no_such_file_or_directory); - } -}; - -} // namespace reader -} // namespace serene -#endif diff --git a/include/serene/reader/location.h b/include/serene/reader/location.h index 334e0c0..a285aea 100644 --- a/include/serene/reader/location.h +++ b/include/serene/reader/location.h @@ -25,8 +25,7 @@ #ifndef SERENE_LOCATION_H #define SERENE_LOCATION_H -#include "mlir/IR/Diagnostics.h" - +#include #include #include @@ -60,7 +59,8 @@ struct Location { llvm::Optional fname = llvm::None, const char *c = nullptr, unsigned short int line = 0, unsigned short int col = 0, bool knownLocation = true) - : ns(ns), filename(fname), c(c), line(line), col(col){}; + : ns(ns), filename(fname), c(c), line(line), col(col), + knownLocation(knownLocation){}; Location clone(); Location clone() const; diff --git a/include/serene/reader/reader.h b/include/serene/reader/reader.h index cce7ea7..535c839 100644 --- a/include/serene/reader/reader.h +++ b/include/serene/reader/reader.h @@ -44,7 +44,6 @@ #include "serene/exprs/expression.h" #include "serene/exprs/list.h" #include "serene/exprs/symbol.h" -#include "serene/reader/errors.h" #include "serene/reader/location.h" #include "serene/serene.h" diff --git a/src/serene/CMakeLists.txt b/src/serene/CMakeLists.txt index 3d31aa9..f26da4e 100644 --- a/src/serene/CMakeLists.txt +++ b/src/serene/CMakeLists.txt @@ -1,42 +1,24 @@ -set(HEADER_LIST - "${INCLUDE_DIR}/serene/serene.h" - "${INCLUDE_DIR}/serene/utils.h" - "${INCLUDE_DIR}/serene/context.h" - "${INCLUDE_DIR}/serene/environment.h" - "${INCLUDE_DIR}/serene/traits.h" - "${INCLUDE_DIR}/serene/diagnostics.h" - - "${INCLUDE_DIR}/serene/exprs/expression.h" - "${INCLUDE_DIR}/serene/exprs/symbol.h" - "${INCLUDE_DIR}/serene/exprs/list.h" - "${INCLUDE_DIR}/serene/exprs/number.h" - "${INCLUDE_DIR}/serene/exprs/def.h" - "${INCLUDE_DIR}/serene/exprs/fn.h" - "${INCLUDE_DIR}/serene/exprs/traits.h" - "${INCLUDE_DIR}/serene/exprs/call.h" - - # Reader - "${INCLUDE_DIR}/serene/reader/reader.h" - "${INCLUDE_DIR}/serene/reader/location.h" - "${INCLUDE_DIR}/serene/reader/errors.h" - "${INCLUDE_DIR}/serene/reader/semantics.h" - "${INCLUDE_DIR}/serene/reader/traits.h" - - "${INCLUDE_DIR}/serene/errors.h" - "${INCLUDE_DIR}/serene/errors/error.h" - "${INCLUDE_DIR}/serene/errors/errc.h" - "${INCLUDE_DIR}/serene/errors/constants.h" - "${INCLUDE_DIR}/serene/errors/traits.h" - - - "${INCLUDE_DIR}/serene/slir/slir.h" - "${INCLUDE_DIR}/serene/slir/dialect.h" - "${INCLUDE_DIR}/serene/slir/generatable.h" - "${INCLUDE_DIR}/serene/slir/utils.h" - "${INCLUDE_DIR}/serene/namespace.h" - "${INCLUDE_DIR}/serene/jit.h" - "${INCLUDE_DIR}/serene/source_mgr.h" - "${INCLUDE_DIR}/serene/passes.h") +# Serene programming language. +# +# Copyright (c) 2019-2021 Sameer Rahmani +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. # Make an automatic library - will be static or dynamic based on user setting add_library(serene @@ -48,7 +30,6 @@ add_library(serene exprs/fn.cpp exprs/call.cpp - context.cpp serene.cpp namespace.cpp @@ -59,7 +40,6 @@ add_library(serene # Reader reader/reader.cpp reader/location.cpp - reader/errors.cpp reader/semantics.cpp # Errors @@ -74,13 +54,12 @@ add_library(serene slir/ops.cpp passes/slir_lowering.cpp passes/to_llvm_dialect.cpp - ${HEADER_LIST}) - + ) +#${HEADER_LIST} # Make sure to generate files related to the dialects first add_dependencies(serene SereneDialectGen) - if (CPP_20_SUPPORT) target_compile_features(serene PUBLIC cxx_std_20) else() @@ -89,7 +68,7 @@ endif() # We need this directory, and users of our library will need it too -target_include_directories(serene PRIVATE ${INCLUDE_DIR}) +target_include_directories(serene PUBLIC ${INCLUDE_DIR}) target_include_directories(serene PUBLIC ${PROJECT_BINARY_DIR}) @@ -99,7 +78,7 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) # This depends on (header only) boost target_link_libraries(serene - PRIVATE + PUBLIC ${dialect_libs} ${conversion_libs} MLIRAnalysis diff --git a/src/serene/diagnostics.cpp b/src/serene/diagnostics.cpp index 7ce3a6f..24f4cb6 100644 --- a/src/serene/diagnostics.cpp +++ b/src/serene/diagnostics.cpp @@ -27,6 +27,7 @@ #include "serene/context.h" #include "serene/reader/location.h" #include "serene/source_mgr.h" +#include "serene/utils.h" #include #include @@ -155,7 +156,10 @@ void Diagnostic::print(llvm::raw_ostream &os, llvm::StringRef prefix) { DiagnosticEngine::DiagnosticEngine(SereneContext &ctx) : ctx(ctx), diagEngine(ctx.mlirContext.getDiagEngine()){}; -void DiagnosticEngine::print(llvm::raw_ostream &os, Diagnostic &d){}; +void DiagnosticEngine::print(llvm::raw_ostream &os, Diagnostic &d) { + UNUSED(os); + UNUSED(d); +}; Diagnostic DiagnosticEngine::toDiagnostic(reader::LocationRange loc, errors::ErrorVariant &e, diff --git a/src/serene/exprs/call.cpp b/src/serene/exprs/call.cpp index 3b64345..2aaa08d 100644 --- a/src/serene/exprs/call.cpp +++ b/src/serene/exprs/call.cpp @@ -30,10 +30,11 @@ #include "serene/exprs/list.h" #include "serene/exprs/symbol.h" #include "serene/reader/semantics.h" +#include "serene/utils.h" -#include "llvm/Support/Casting.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/FormatVariadic.h" +#include +#include +#include namespace serene { namespace exprs { @@ -45,7 +46,10 @@ std::string Call::toString() const { astToString(&this->params)); } -MaybeNode Call::analyze(SereneContext &ctx) { return EmptyNode; }; +MaybeNode Call::analyze(SereneContext &ctx) { + UNUSED(ctx); + return EmptyNode; +}; bool Call::classof(const Expression *e) { return e->getType() == ExprType::Call; diff --git a/src/serene/exprs/def.cpp b/src/serene/exprs/def.cpp index 857b30b..4b2f4c1 100644 --- a/src/serene/exprs/def.cpp +++ b/src/serene/exprs/def.cpp @@ -45,7 +45,10 @@ std::string Def::toString() const { this->value->toString()); } -MaybeNode Def::analyze(SereneContext &ctx) { return EmptyNode; }; +MaybeNode Def::analyze(SereneContext &ctx) { + UNUSED(ctx); + return EmptyNode; +}; bool Def::classof(const Expression *e) { return e->getType() == ExprType::Def; diff --git a/src/serene/exprs/fn.cpp b/src/serene/exprs/fn.cpp index 0cc9d6d..571ad25 100644 --- a/src/serene/exprs/fn.cpp +++ b/src/serene/exprs/fn.cpp @@ -56,7 +56,10 @@ std::string Fn::toString() const { this->body.empty() ? "<>" : astToString(&this->body)); } -MaybeNode Fn::analyze(SereneContext &ctx) { return EmptyNode; }; +MaybeNode Fn::analyze(SereneContext &ctx) { + UNUSED(ctx); + return EmptyNode; +}; bool Fn::classof(const Expression *e) { return e->getType() == ExprType::Fn; }; diff --git a/src/serene/exprs/number.cpp b/src/serene/exprs/number.cpp index 46b9ab9..90e6599 100644 --- a/src/serene/exprs/number.cpp +++ b/src/serene/exprs/number.cpp @@ -38,7 +38,10 @@ std::string Number::toString() const { return llvm::formatv("", value); } -MaybeNode Number::analyze(SereneContext &ctx) { return EmptyNode; }; +MaybeNode Number::analyze(SereneContext &ctx) { + UNUSED(ctx); + return EmptyNode; +}; bool Number::classof(const Expression *e) { return e->getType() == ExprType::Number; diff --git a/src/serene/exprs/symbol.cpp b/src/serene/exprs/symbol.cpp index f7916d2..7e13e88 100644 --- a/src/serene/exprs/symbol.cpp +++ b/src/serene/exprs/symbol.cpp @@ -26,8 +26,7 @@ #include "serene/exprs/expression.h" -#include "llvm/Support/Casting.h" - +#include #include namespace serene { @@ -39,7 +38,10 @@ std::string Symbol::toString() const { return llvm::formatv("", this->name); } -MaybeNode Symbol::analyze(SereneContext &ctx) { return EmptyNode; }; +MaybeNode Symbol::analyze(SereneContext &ctx) { + UNUSED(ctx); + return EmptyNode; +}; bool Symbol::classof(const Expression *e) { return e->getType() == ExprType::Symbol; diff --git a/src/serene/jit.cpp b/src/serene/jit.cpp index 88353a4..0cc3520 100644 --- a/src/serene/jit.cpp +++ b/src/serene/jit.cpp @@ -206,6 +206,7 @@ MaybeJIT JIT::make(Namespace &ns, // process and dynamically linked libraries. auto objectLinkingLayerCreator = [&](llvm::orc::ExecutionSession &session, const llvm::Triple &tt) { + UNUSED(tt); auto objectLayer = std::make_unique(session, []() { return std::make_unique(); diff --git a/src/serene/reader/errors.cpp b/src/serene/reader/errors.cpp deleted file mode 100644 index 965e828..0000000 --- a/src/serene/reader/errors.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- C++ -*- - * Serene programming language. - * - * Copyright (c) 2019-2021 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "serene/reader/errors.h" - -namespace serene { -namespace reader { -/// This one should be here, llvm's rules -char MissingFileError::ID; -}; // namespace reader -}; // namespace serene