Refactor the main cmake list file and fix the unused warns

This commit is contained in:
Sameer Rahmani 2021-09-27 13:05:15 +01:00
parent 6ef69d329a
commit 225ff6bba1
24 changed files with 231 additions and 242 deletions

View File

@ -1,3 +1,24 @@
# Serene programming language.
#
# Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
#
# 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) cmake_minimum_required(VERSION 3.16)
# Project name and a few useful settings. Other commands can pick up the results # 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." DESCRIPTION "Serene language is a modern Lisp."
LANGUAGES CXX C) LANGUAGES CXX C)
# Clangd command file
set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Policies ==========================
cmake_policy(SET CMP0116 NEW)
# User Options ======================
option(CPP_20_SUPPORT "C++20 Support" OFF) 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 # 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) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
## Settings =======================
## Settings -----------------------------------------
# specify the C++ standard # specify the C++ standard
if (CPP_20_SUPPORT) if (CPP_20_SUPPORT)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
@ -22,50 +53,73 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
# Setup the source locations
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include) set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set(BIN_DIR ${CMAKE_SOURCE_DIR}/bin) 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) set(CMAKE_CXX_CLANG_TIDY clang-tidy)
# Let's ensure -std=c++xx instead of -std=g++xx # Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF) 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(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/scripts/cmake")
set(MemoryCheckCommand "valgrind") set(MemoryCheckCommand "valgrind")
add_compile_options(-fno-rtti)
configure_file(${INCLUDE_DIR}/serene/config.h.in serene/config.h) configure_file(${INCLUDE_DIR}/serene/config.h.in serene/config.h)
# Let's nicely support folders in IDEs # Let's nicely support folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
## Options ------------------------------------------ # Setup the basic compiler flags
option(ENABLE_LOG "Enable logging" OFF) add_compile_options(
option(ENABLE_EXPR_LOG "Enable AExpr logging" OFF) -Wall
option(ENABLE_READER_LOG "Enable reader logging" OFF) -Wextra
option(BUILD_TESTING "Enable tests" OFF) -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) $<$<CONFIG:DEBUG>:-g3>
include(FetchContent) $<$<CONFIG:DEBUG>:-ggdb>
# For the sake of debugging
$<$<CONFIG:DEBUG>:-fno-inline>
# To make the local ccache happy
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=$PWD=.>
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
$<$<CONFIG:RELEASE>:-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(LLVM REQUIRED CONFIG)
find_package(MLIR 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 LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
@ -81,36 +135,42 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(AddMLIR) include(AddMLIR)
include(HandleLLVMOptions) 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}) add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(llvm_libs support core irreader) 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 # The compiled library code is here
add_subdirectory(src/serene) add_subdirectory(src/serene)
# The executable code is here # The executable code is here
add_subdirectory(bin) add_subdirectory(bin)
add_subdirectory(include) add_subdirectory(include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
# Testing only available if this is the main app # Testing only available if this is the main app
# Emergency override SERENE_CMAKE_BUILD_TESTING provided as well # Emergency override SERENE_CMAKE_BUILD_TESTING provided as well
if(BUILD_TESTING) if(SERENE_BUILD_TESTING)
message("Build the test binary") message("Build the test binary")
add_subdirectory(src/tests) add_subdirectory(src/tests)
endif() endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release") if (SERENE_ENABLE_DOCS)
# Docs only available if this is the main app # Docs only available if this is the main app
find_package(Doxygen find_package(Doxygen
REQUIRED dot REQUIRED dot
OPTIONAL_COMPONENTS dia) OPTIONAL_COMPONENTS dia)
@ -121,6 +181,4 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
message(STATUS "Doxygen not found, not building docs") message(STATUS "Doxygen not found, not building docs")
endif() endif()
endif() endif()
endif() endif()

View File

@ -1,7 +1,26 @@
add_executable(serenec serene.cpp) # Serene programming language.
#
# Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
#
# 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_executable(serenec serene.cpp)
#add_dependencies(serenec SereneDialectGen)
if (CPP_20_SUPPORT) if (CPP_20_SUPPORT)
target_compile_features(serenec PRIVATE cxx_std_20) target_compile_features(serenec PRIVATE cxx_std_20)
@ -10,8 +29,6 @@ else()
endif() endif()
target_link_libraries(serenec PRIVATE target_link_libraries(serenec PRIVATE
serene serene
${llvm_libs} ${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}) target_include_directories(serene PRIVATE ${INCLUDE_DIR})
install(TARGETS serenec DESTINATION bin) install(TARGETS serenec DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/config.h" DESTINATION include) #install(FILES "${PROJECT_BINARY_DIR}/config.h" DESTINATION include)

View File

@ -19,8 +19,6 @@ export CXX=$(which clang++)
export CCACHE_SLOPPINESS="pch_defines,time_macros" export CCACHE_SLOPPINESS="pch_defines,time_macros"
# Meke sure to use `lld` linker it faster and has a better UX # 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 export ASAN_OPTIONS=check_initialization_order=1
LSAN_OPTIONS=suppressions=$(pwd)/.ignore_sanitize LSAN_OPTIONS=suppressions=$(pwd)/.ignore_sanitize
export LSAN_OPTIONS export LSAN_OPTIONS
@ -28,6 +26,7 @@ export LSAN_OPTIONS
# The `builder` script is supposed to be run from the # The `builder` script is supposed to be run from the
# root of the source tree # root of the source tree
ROOT_DIR=$(pwd) ROOT_DIR=$(pwd)
CMAKEARGS="-DLLVM_PARALLEL_COMPILE_JOBS=7 -DLLVM_PARALLEL_LINK_JOBS=7 "
BUILD_DIR=$ROOT_DIR/build BUILD_DIR=$ROOT_DIR/build
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P) ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
@ -60,8 +59,8 @@ function compile() {
function build() { function build() {
pushed_build pushed_build
echo "Running: " echo "Running: "
echo "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 -DCMAKE_BUILD_TYPE=Debug "$@" "$ROOT_DIR" cmake -G Ninja $CMAKE_CCACHE $CMAKEARGS -DCMAKE_BUILD_TYPE=Debug "$@" "$ROOT_DIR"
cmake --build . cmake --build .
popd_build popd_build
} }

View File

@ -108,7 +108,13 @@ on ADF
* TODOs * TODOs
** Bootstrap* ** 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 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 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 a namespace. For instance, when serene wants to load the =foo.bar= namespace, it should walk

View File

@ -32,6 +32,7 @@
#include "serene/slir/dialect.h" #include "serene/slir/dialect.h"
#include "serene/source_mgr.h" #include "serene/source_mgr.h"
#include <llvm/ADT/None.h>
#include <llvm/ADT/Optional.h> #include <llvm/ADT/Optional.h>
#include <llvm/ADT/StringRef.h> #include <llvm/ADT/StringRef.h>
#include <llvm/IR/LLVMContext.h> #include <llvm/IR/LLVMContext.h>
@ -118,6 +119,11 @@ public:
targetPhase(CompilationPhase::NoOptimization) { targetPhase(CompilationPhase::NoOptimization) {
mlirContext.getOrLoadDialect<serene::slir::SereneDialect>(); mlirContext.getOrLoadDialect<serene::slir::SereneDialect>();
mlirContext.getOrLoadDialect<mlir::StandardOpsDialect>(); mlirContext.getOrLoadDialect<mlir::StandardOpsDialect>();
// 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 // TODO: Get the crash report path dynamically from the cli
// pm.enableCrashReproducerGeneration("/home/lxsameer/mlir.mlir"); // pm.enableCrashReproducerGeneration("/home/lxsameer/mlir.mlir");

View File

@ -30,9 +30,8 @@
#include "serene/exprs/expression.h" #include "serene/exprs/expression.h"
#include "serene/exprs/list.h" #include "serene/exprs/list.h"
#include "llvm/ADT/StringRef.h" #include <llvm/ADT/StringRef.h>
#include "llvm/Support/Error.h" #include <llvm/Support/Error.h>
#include <memory> #include <memory>
#include <string> #include <string>
@ -54,10 +53,10 @@ public:
Call(Call &) = delete; Call(Call &) = delete;
ExprType getType() const; ExprType getType() const override;
std::string toString() const; std::string toString() const override;
MaybeNode analyze(SereneContext &); MaybeNode analyze(SereneContext &) override;
void generateIR(serene::Namespace &, mlir::ModuleOp &){}; void generateIR(serene::Namespace &, mlir::ModuleOp &) override{};
static bool classof(const Expression *e); static bool classof(const Expression *e);

View File

@ -29,9 +29,8 @@
#include "serene/errors/error.h" #include "serene/errors/error.h"
#include "serene/exprs/expression.h" #include "serene/exprs/expression.h"
#include "llvm/ADT/StringRef.h" #include <llvm/ADT/StringRef.h>
#include "llvm/Support/Error.h" #include <llvm/Support/Error.h>
#include <memory> #include <memory>
#include <string> #include <string>
@ -53,10 +52,10 @@ public:
Def(Def &d) = delete; Def(Def &d) = delete;
ExprType getType() const; ExprType getType() const override;
std::string toString() const; std::string toString() const override;
MaybeNode analyze(SereneContext &); MaybeNode analyze(SereneContext &) override;
void generateIR(serene::Namespace &, mlir::ModuleOp &); void generateIR(serene::Namespace &, mlir::ModuleOp &) override;
static bool classof(const Expression *e); static bool classof(const Expression *e);

View File

@ -31,9 +31,8 @@
#include "serene/exprs/list.h" #include "serene/exprs/list.h"
#include "serene/namespace.h" #include "serene/namespace.h"
#include "llvm/ADT/StringRef.h" #include <llvm/ADT/StringRef.h>
#include "llvm/Support/Error.h" #include <llvm/Support/Error.h>
#include <memory> #include <memory>
#include <string> #include <string>
@ -57,10 +56,10 @@ public:
Fn(Fn &f) = delete; Fn(Fn &f) = delete;
ExprType getType() const; ExprType getType() const override;
std::string toString() const; std::string toString() const override;
MaybeNode analyze(SereneContext &); MaybeNode analyze(SereneContext &) override;
void generateIR(serene::Namespace &, mlir::ModuleOp &); void generateIR(serene::Namespace &, mlir::ModuleOp &) override;
static bool classof(const Expression *e); static bool classof(const Expression *e);

View File

@ -50,8 +50,8 @@ public:
List(const reader::LocationRange &loc, Node &e); List(const reader::LocationRange &loc, Node &e);
List(const reader::LocationRange &loc, Ast elems); List(const reader::LocationRange &loc, Ast elems);
ExprType getType() const; ExprType getType() const override;
std::string toString() const; std::string toString() const override;
void append(Node); void append(Node);
@ -77,8 +77,8 @@ public:
/// by the for loop. /// by the for loop.
std::vector<Node>::iterator end(); std::vector<Node>::iterator end();
MaybeNode analyze(SereneContext &); MaybeNode analyze(SereneContext &) override;
void generateIR(serene::Namespace &, mlir::ModuleOp &){}; void generateIR(serene::Namespace &, mlir::ModuleOp &) override{};
~List() = default; ~List() = default;

View File

@ -50,11 +50,11 @@ struct Number : public Expression {
bool isFloat) bool isFloat)
: Expression(loc), value(num), isNeg(isNeg), isFloat(isFloat){}; : Expression(loc), value(num), isNeg(isNeg), isFloat(isFloat){};
ExprType getType() const; ExprType getType() const override;
std::string toString() const; std::string toString() const override;
MaybeNode analyze(SereneContext &ctx); MaybeNode analyze(SereneContext &ctx) override;
void generateIR(serene::Namespace &, mlir::ModuleOp &); void generateIR(serene::Namespace &, mlir::ModuleOp &) override;
// TODO: This is horrible, we need to fix it after the mvp // TODO: This is horrible, we need to fix it after the mvp
int toI64(); int toI64();

View File

@ -47,11 +47,11 @@ public:
Symbol(Symbol &s) : Expression(s.location) { this->name = s.name; } Symbol(Symbol &s) : Expression(s.location) { this->name = s.name; }
ExprType getType() const; ExprType getType() const override;
std::string toString() const; std::string toString() const override;
MaybeNode analyze(SereneContext &); MaybeNode analyze(SereneContext &) override;
void generateIR(serene::Namespace &, mlir::ModuleOp &){}; void generateIR(serene::Namespace &, mlir::ModuleOp &) override{};
~Symbol() = default; ~Symbol() = default;

View File

@ -22,6 +22,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
/**
* Commentary:
*/
#ifndef SERENE_JIT_H #ifndef SERENE_JIT_H
#define SERENE_JIT_H #define SERENE_JIT_H
@ -153,6 +157,7 @@ public:
(void)dummy; (void)dummy;
return invokePacked(adapterName, argsArray); return invokePacked(adapterName, argsArray);
}; };
/// Dump object code to output file `filename`. /// Dump object code to output file `filename`.
void dumpToObjectFile(llvm::StringRef filename); void dumpToObjectFile(llvm::StringRef filename);

View File

@ -1,65 +0,0 @@
/* -*- C++ -*-
* Serene programming language.
*
* Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
*
* 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<MissingFileError> {
using llvm::ErrorInfo<MissingFileError>::log;
using llvm::ErrorInfo<MissingFileError>::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

View File

@ -25,8 +25,7 @@
#ifndef SERENE_LOCATION_H #ifndef SERENE_LOCATION_H
#define SERENE_LOCATION_H #define SERENE_LOCATION_H
#include "mlir/IR/Diagnostics.h" #include <mlir/IR/Diagnostics.h>
#include <mlir/IR/Location.h> #include <mlir/IR/Location.h>
#include <string> #include <string>
@ -60,7 +59,8 @@ struct Location {
llvm::Optional<llvm::StringRef> fname = llvm::None, llvm::Optional<llvm::StringRef> fname = llvm::None,
const char *c = nullptr, unsigned short int line = 0, const char *c = nullptr, unsigned short int line = 0,
unsigned short int col = 0, bool knownLocation = true) 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();
Location clone() const; Location clone() const;

View File

@ -44,7 +44,6 @@
#include "serene/exprs/expression.h" #include "serene/exprs/expression.h"
#include "serene/exprs/list.h" #include "serene/exprs/list.h"
#include "serene/exprs/symbol.h" #include "serene/exprs/symbol.h"
#include "serene/reader/errors.h"
#include "serene/reader/location.h" #include "serene/reader/location.h"
#include "serene/serene.h" #include "serene/serene.h"

View File

@ -1,42 +1,24 @@
set(HEADER_LIST # Serene programming language.
"${INCLUDE_DIR}/serene/serene.h" #
"${INCLUDE_DIR}/serene/utils.h" # Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
"${INCLUDE_DIR}/serene/context.h" #
"${INCLUDE_DIR}/serene/environment.h" # Permission is hereby granted, free of charge, to any person obtaining a copy
"${INCLUDE_DIR}/serene/traits.h" # of this software and associated documentation files (the "Software"), to deal
"${INCLUDE_DIR}/serene/diagnostics.h" # in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
"${INCLUDE_DIR}/serene/exprs/expression.h" # copies of the Software, and to permit persons to whom the Software is
"${INCLUDE_DIR}/serene/exprs/symbol.h" # furnished to do so, subject to the following conditions:
"${INCLUDE_DIR}/serene/exprs/list.h" #
"${INCLUDE_DIR}/serene/exprs/number.h" # The above copyright notice and this permission notice shall be included in
"${INCLUDE_DIR}/serene/exprs/def.h" # all copies or substantial portions of the Software.
"${INCLUDE_DIR}/serene/exprs/fn.h" #
"${INCLUDE_DIR}/serene/exprs/traits.h" # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
"${INCLUDE_DIR}/serene/exprs/call.h" # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# Reader # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
"${INCLUDE_DIR}/serene/reader/reader.h" # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
"${INCLUDE_DIR}/serene/reader/location.h" # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
"${INCLUDE_DIR}/serene/reader/errors.h" # SOFTWARE.
"${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")
# Make an automatic library - will be static or dynamic based on user setting # Make an automatic library - will be static or dynamic based on user setting
add_library(serene add_library(serene
@ -48,7 +30,6 @@ add_library(serene
exprs/fn.cpp exprs/fn.cpp
exprs/call.cpp exprs/call.cpp
context.cpp context.cpp
serene.cpp serene.cpp
namespace.cpp namespace.cpp
@ -59,7 +40,6 @@ add_library(serene
# Reader # Reader
reader/reader.cpp reader/reader.cpp
reader/location.cpp reader/location.cpp
reader/errors.cpp
reader/semantics.cpp reader/semantics.cpp
# Errors # Errors
@ -74,13 +54,12 @@ add_library(serene
slir/ops.cpp slir/ops.cpp
passes/slir_lowering.cpp passes/slir_lowering.cpp
passes/to_llvm_dialect.cpp passes/to_llvm_dialect.cpp
${HEADER_LIST}) )
#${HEADER_LIST}
# Make sure to generate files related to the dialects first # Make sure to generate files related to the dialects first
add_dependencies(serene SereneDialectGen) add_dependencies(serene SereneDialectGen)
if (CPP_20_SUPPORT) if (CPP_20_SUPPORT)
target_compile_features(serene PUBLIC cxx_std_20) target_compile_features(serene PUBLIC cxx_std_20)
else() else()
@ -89,7 +68,7 @@ endif()
# We need this directory, and users of our library will need it too # 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}) 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) get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
# This depends on (header only) boost # This depends on (header only) boost
target_link_libraries(serene target_link_libraries(serene
PRIVATE PUBLIC
${dialect_libs} ${dialect_libs}
${conversion_libs} ${conversion_libs}
MLIRAnalysis MLIRAnalysis

View File

@ -27,6 +27,7 @@
#include "serene/context.h" #include "serene/context.h"
#include "serene/reader/location.h" #include "serene/reader/location.h"
#include "serene/source_mgr.h" #include "serene/source_mgr.h"
#include "serene/utils.h"
#include <llvm/ADT/StringRef.h> #include <llvm/ADT/StringRef.h>
#include <llvm/Support/FormatAdapters.h> #include <llvm/Support/FormatAdapters.h>
@ -155,7 +156,10 @@ void Diagnostic::print(llvm::raw_ostream &os, llvm::StringRef prefix) {
DiagnosticEngine::DiagnosticEngine(SereneContext &ctx) DiagnosticEngine::DiagnosticEngine(SereneContext &ctx)
: ctx(ctx), diagEngine(ctx.mlirContext.getDiagEngine()){}; : 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, Diagnostic DiagnosticEngine::toDiagnostic(reader::LocationRange loc,
errors::ErrorVariant &e, errors::ErrorVariant &e,

View File

@ -30,10 +30,11 @@
#include "serene/exprs/list.h" #include "serene/exprs/list.h"
#include "serene/exprs/symbol.h" #include "serene/exprs/symbol.h"
#include "serene/reader/semantics.h" #include "serene/reader/semantics.h"
#include "serene/utils.h"
#include "llvm/Support/Casting.h" #include <llvm/Support/Casting.h>
#include "llvm/Support/ErrorHandling.h" #include <llvm/Support/ErrorHandling.h>
#include "llvm/Support/FormatVariadic.h" #include <llvm/Support/FormatVariadic.h>
namespace serene { namespace serene {
namespace exprs { namespace exprs {
@ -45,7 +46,10 @@ std::string Call::toString() const {
astToString(&this->params)); 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) { bool Call::classof(const Expression *e) {
return e->getType() == ExprType::Call; return e->getType() == ExprType::Call;

View File

@ -45,7 +45,10 @@ std::string Def::toString() const {
this->value->toString()); 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) { bool Def::classof(const Expression *e) {
return e->getType() == ExprType::Def; return e->getType() == ExprType::Def;

View File

@ -56,7 +56,10 @@ std::string Fn::toString() const {
this->body.empty() ? "<>" : astToString(&this->body)); 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; }; bool Fn::classof(const Expression *e) { return e->getType() == ExprType::Fn; };

View File

@ -38,7 +38,10 @@ std::string Number::toString() const {
return llvm::formatv("<Number {0}>", value); return llvm::formatv("<Number {0}>", value);
} }
MaybeNode Number::analyze(SereneContext &ctx) { return EmptyNode; }; MaybeNode Number::analyze(SereneContext &ctx) {
UNUSED(ctx);
return EmptyNode;
};
bool Number::classof(const Expression *e) { bool Number::classof(const Expression *e) {
return e->getType() == ExprType::Number; return e->getType() == ExprType::Number;

View File

@ -26,8 +26,7 @@
#include "serene/exprs/expression.h" #include "serene/exprs/expression.h"
#include "llvm/Support/Casting.h" #include <llvm/Support/Casting.h>
#include <llvm/Support/FormatVariadic.h> #include <llvm/Support/FormatVariadic.h>
namespace serene { namespace serene {
@ -39,7 +38,10 @@ std::string Symbol::toString() const {
return llvm::formatv("<Symbol {0}>", this->name); return llvm::formatv("<Symbol {0}>", this->name);
} }
MaybeNode Symbol::analyze(SereneContext &ctx) { return EmptyNode; }; MaybeNode Symbol::analyze(SereneContext &ctx) {
UNUSED(ctx);
return EmptyNode;
};
bool Symbol::classof(const Expression *e) { bool Symbol::classof(const Expression *e) {
return e->getType() == ExprType::Symbol; return e->getType() == ExprType::Symbol;

View File

@ -206,6 +206,7 @@ MaybeJIT JIT::make(Namespace &ns,
// process and dynamically linked libraries. // process and dynamically linked libraries.
auto objectLinkingLayerCreator = [&](llvm::orc::ExecutionSession &session, auto objectLinkingLayerCreator = [&](llvm::orc::ExecutionSession &session,
const llvm::Triple &tt) { const llvm::Triple &tt) {
UNUSED(tt);
auto objectLayer = auto objectLayer =
std::make_unique<llvm::orc::RTDyldObjectLinkingLayer>(session, []() { std::make_unique<llvm::orc::RTDyldObjectLinkingLayer>(session, []() {
return std::make_unique<llvm::SectionMemoryManager>(); return std::make_unique<llvm::SectionMemoryManager>();

View File

@ -1,32 +0,0 @@
/* -*- C++ -*-
* Serene programming language.
*
* Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
*
* 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