Refactor the cmake script and move the binary into its own package
This commit is contained in:
parent
5802e87121
commit
a174a3a342
|
@ -19,7 +19,7 @@
|
|||
# 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.19)
|
||||
|
||||
# Project name and a few useful settings. Other commands can pick up the results
|
||||
project(Serene
|
||||
|
@ -189,18 +189,10 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
|
||||
|
||||
# The compiled library code is here
|
||||
add_subdirectory(src/serene)
|
||||
add_subdirectory(src)
|
||||
# The executable code is here
|
||||
add_subdirectory(bin)
|
||||
add_subdirectory(include)
|
||||
|
||||
# Testing only available if this is the main app
|
||||
# Emergency override SERENE_CMAKE_BUILD_TESTING provided as well
|
||||
if(SERENE_BUILD_TESTING)
|
||||
message("Build the test binary")
|
||||
add_subdirectory(src/tests)
|
||||
endif()
|
||||
|
||||
if (SERENE_ENABLE_DOCS)
|
||||
# Docs only available if this is the main app
|
||||
find_package(Doxygen
|
||||
|
|
3
builder
3
builder
|
@ -16,7 +16,8 @@ export LSAN_OPTIONS
|
|||
ROOT_DIR=$(pwd)
|
||||
BUILD_DIR=$ROOT_DIR/build
|
||||
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
|
||||
CMAKEARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DSERENE_CCACHE_DIR=~/.ccache"
|
||||
# -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
|
||||
CMAKEARGS=" -DSERENE_CCACHE_DIR=~/.ccache"
|
||||
scanbuild=scan-build
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#! /bin/bash
|
||||
|
||||
function get_changed_files() {
|
||||
git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '$1 != "D" { print $2 }'
|
||||
local add_modified
|
||||
local renamed
|
||||
add_modified=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '($1 != "D" && $1 !~ /R.+/) { print $2 }')
|
||||
renamed=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '$1 ~ /^R.+/ { print $3 }')
|
||||
|
||||
echo $add_modified | sed '/^[[:space:]]*$/d'
|
||||
echo $renamed | sed '/^[[:space:]]*$/d'
|
||||
}
|
||||
|
||||
function fix_includes(){
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# 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.
|
||||
|
||||
add_subdirectory(libserene)
|
||||
add_subdirectory(serenec)
|
||||
|
||||
# Testing only available if this is the main app
|
||||
# Emergency override SERENE_CMAKE_BUILD_TESTING provided as well
|
||||
if(SERENE_BUILD_TESTING)
|
||||
message("Build the test binary")
|
||||
add_subdirectory(src/tests)
|
||||
endif()
|
|
@ -20,8 +20,12 @@
|
|||
# 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
|
||||
option(SERENE_SHOW_MLIR_DIALECTS "Print out a list of MLIR dialect libs" OFF)
|
||||
option(SERENE_SHOW_MLIR_TRANSFORMERS "Print out a list of MLIR dialect transformer libs" OFF)
|
||||
option(SERENE_SHOW_LLVM_LIBS "Print all the llvm libs available" OFF)
|
||||
|
||||
|
||||
add_library(libserene OBJECT
|
||||
exprs/symbol.cpp
|
||||
exprs/list.cpp
|
||||
exprs/number.cpp
|
||||
|
@ -31,7 +35,6 @@ add_library(serene
|
|||
exprs/call.cpp
|
||||
|
||||
context.cpp
|
||||
serene.cpp
|
||||
namespace.cpp
|
||||
jit.cpp
|
||||
source_mgr.cpp
|
||||
|
@ -55,46 +58,76 @@ add_library(serene
|
|||
passes/slir_lowering.cpp
|
||||
passes/to_llvm_dialect.cpp
|
||||
)
|
||||
#${HEADER_LIST}
|
||||
|
||||
# Make sure to generate files related to the dialects first
|
||||
add_dependencies(serene SereneDialectGen)
|
||||
add_dependencies(libserene SereneDialectGen)
|
||||
|
||||
if (CPP_20_SUPPORT)
|
||||
target_compile_features(serene PUBLIC cxx_std_20)
|
||||
target_compile_features(libserene PUBLIC cxx_std_20)
|
||||
else()
|
||||
target_compile_features(serene PUBLIC cxx_std_17)
|
||||
target_compile_features(libserene PUBLIC cxx_std_17)
|
||||
endif()
|
||||
|
||||
|
||||
# We need this directory, and users of our library will need it too
|
||||
target_include_directories(serene PUBLIC ${INCLUDE_DIR})
|
||||
target_include_directories(serene PUBLIC ${PROJECT_BINARY_DIR})
|
||||
target_include_directories(libserene PUBLIC ${INCLUDE_DIR})
|
||||
target_include_directories(libserene PUBLIC ${PROJECT_BINARY_DIR})
|
||||
|
||||
|
||||
source_group(TREE "${INCLUDE_DIR}" PREFIX "Header Files" FILES ${HEADER_LIST})
|
||||
#target_precompile_headers(serene PRIVATE ${HEADER_LIST})
|
||||
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
|
||||
PUBLIC
|
||||
${dialect_libs}
|
||||
${conversion_libs}
|
||||
MLIRAnalysis
|
||||
MLIRCallInterfaces
|
||||
MLIRCastInterfaces
|
||||
MLIRExecutionEngine
|
||||
MLIRIR
|
||||
MLIRLLVMToLLVMIRTranslation
|
||||
MLIRParser
|
||||
MLIRPass
|
||||
MLIRSideEffectInterfaces
|
||||
MLIRTargetLLVMIRExport
|
||||
MLIRTransforms
|
||||
${llvm_libs})
|
||||
|
||||
# target_precompile_headers(serene
|
||||
# PRIVATE
|
||||
# <serene_precompiles.h>
|
||||
# )
|
||||
|
||||
if(SERENE_SHOW_MLIR_DIALECTS)
|
||||
message(STATUS "MLIR Dialects to choose from:")
|
||||
foreach(lib ${dialect_libs})
|
||||
message(STATUS "\t${lib}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
||||
if(SERENE_SHOW_MLIR_TRANSFORMERS)
|
||||
message(STATUS "MLIR Dialects transformers to choose from:")
|
||||
foreach(lib ${conversion_libs})
|
||||
message(STATUS "\t${lib}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(SERENE_SHOW_LLVM_LIBS)
|
||||
execute_process(COMMAND llvm-config --libs all
|
||||
OUTPUT_VARIABLE SERENE_LLVM_LIBS)
|
||||
message(STATUS "LLVM libs available:\n ${SERENE_LLVM_LIBS}")
|
||||
endif()
|
||||
|
||||
|
||||
set(serene_lib_dialects_in_use
|
||||
MLIRStandard)
|
||||
|
||||
set(serene_lib_transformers_in_use
|
||||
MLIRStandardToLLVM)
|
||||
|
||||
set(static_deps
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
MLIRTransforms
|
||||
|
||||
${serene_lib_dialects_in_use}
|
||||
${serene_lib_transformers_in_use}
|
||||
|
||||
# LLVM's JIT lib
|
||||
LLVMExecutionEngine
|
||||
LLVMOrcJIT
|
||||
MLIRLLVMToLLVMIRTranslation
|
||||
|
||||
#TODO: Remove this lib, we're just using one func
|
||||
MLIRExecutionEngine
|
||||
|
||||
${llvm_libs})
|
||||
|
||||
set_target_properties(libserene PROPERTIES StaticDeps "${static_deps}")
|
||||
|
||||
|
||||
|
||||
# Create an ALIAS target. This way if we mess up the name
|
||||
# there will be an cmake error inseat of a linker error which is harder
|
||||
# to understand. So any binary that wants to use libserene has to
|
||||
# use `Serene::lib` alias instead
|
||||
add_library(Serene::lib ALIAS libserene)
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "serene/exprs/expression.h"
|
||||
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include <llvm/Support/FormatVariadic.h>
|
||||
|
||||
namespace serene {
|
||||
namespace exprs {
|
|
@ -22,17 +22,16 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mlir/IR/Attributes.h"
|
||||
#include "mlir/IR/BuiltinAttributes.h"
|
||||
#include "serene/passes.h"
|
||||
#include "serene/slir/dialect.h"
|
||||
|
||||
#include "llvm/Support/Casting.h"
|
||||
|
||||
#include <llvm/Support/Casting.h>
|
||||
#include <mlir/Dialect/Affine/IR/AffineOps.h>
|
||||
#include <mlir/Dialect/LLVMIR/LLVMDialect.h>
|
||||
#include <mlir/Dialect/MemRef/IR/MemRef.h>
|
||||
#include <mlir/Dialect/StandardOps/IR/Ops.h>
|
||||
#include <mlir/IR/Attributes.h>
|
||||
#include <mlir/IR/BuiltinAttributes.h>
|
||||
#include <mlir/IR/BuiltinOps.h>
|
||||
#include <mlir/Pass/Pass.h>
|
||||
#include <mlir/Transforms/DialectConversion.h>
|
||||
|
@ -150,8 +149,7 @@ struct SLIRToAffinePass
|
|||
|
||||
void SLIRToAffinePass::getDependentDialects(
|
||||
mlir::DialectRegistry ®istry) const {
|
||||
registry.insert<mlir::AffineDialect, mlir::memref::MemRefDialect,
|
||||
mlir::StandardOpsDialect>();
|
||||
registry.insert<mlir::StandardOpsDialect>();
|
||||
};
|
||||
|
||||
/// Return the current function being transformed.
|
||||
|
@ -170,8 +168,7 @@ void SLIRToAffinePass::runOnModule() {
|
|||
// We define the specific operations, or dialects, that are legal targets for
|
||||
// this lowering. In our case, we are lowering to a combination of the
|
||||
// `Affine`, `MemRef` and `Standard` dialects.
|
||||
target.addLegalDialect<mlir::AffineDialect, mlir::memref::MemRefDialect,
|
||||
mlir::StandardOpsDialect>();
|
||||
target.addLegalDialect<mlir::StandardOpsDialect>();
|
||||
|
||||
// We also define the Toy dialect as Illegal so that the conversion will fail
|
||||
// if any of these operations are *not* converted. Given that we actually want
|
|
@ -65,16 +65,17 @@ void SLIRToLLVMDialect::runOnOperation() {
|
|||
|
||||
// Now that the conversion target has been defined, we need to provide the
|
||||
// patterns used for lowering. At this point of the compilation process, we
|
||||
// have a combination of `toy`, `affine`, and `std` operations. Luckily, there
|
||||
// are already exists a set of patterns to transform `affine` and `std`
|
||||
// have a combination of `serene`, `affine`, and `std` operations. Luckily,
|
||||
// there are already exists a set of patterns to transform `affine` and `std`
|
||||
// dialects. These patterns lowering in multiple stages, relying on transitive
|
||||
// lowerings. Transitive lowering, or A->B->C lowering, is when multiple
|
||||
// patterns must be applied to fully transform an illegal operation into a
|
||||
// set of legal ones.
|
||||
mlir::RewritePatternSet patterns(&getContext());
|
||||
mlir::populateAffineToStdConversionPatterns(patterns);
|
||||
populateLoopToStdConversionPatterns(patterns);
|
||||
populateStdToLLVMConversionPatterns(typeConverter, patterns);
|
||||
|
||||
// mlir::populateAffineToStdConversionPatterns(patterns);
|
||||
// populateLoopToStdConversionPatterns(patterns);
|
||||
// populateStdToLLVMConversionPatterns(typeConverter, patterns);
|
||||
|
||||
// patterns.add<PrintOpLowering>(&getContext());
|
||||
|
|
@ -24,27 +24,26 @@
|
|||
|
||||
#include "serene/reader/reader.h"
|
||||
|
||||
#include "mlir/IR/Diagnostics.h"
|
||||
#include "mlir/IR/Location.h"
|
||||
#include "mlir/Support/LogicalResult.h"
|
||||
#include "serene/errors/constants.h"
|
||||
#include "serene/exprs/list.h"
|
||||
#include "serene/exprs/number.h"
|
||||
#include "serene/exprs/symbol.h"
|
||||
#include "serene/namespace.h"
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <cctype>
|
||||
#include <fstream>
|
||||
#include <llvm/ADT/StringRef.h>
|
||||
#include <llvm/Support/Error.h>
|
||||
#include <llvm/Support/ErrorHandling.h>
|
||||
#include <llvm/Support/ErrorOr.h>
|
||||
#include <llvm/Support/FormatVariadic.h>
|
||||
#include <llvm/Support/MemoryBuffer.h>
|
||||
#include <llvm/Support/SMLoc.h>
|
||||
#include <memory>
|
||||
#include <mlir/IR/Diagnostics.h>
|
||||
#include <mlir/IR/Location.h>
|
||||
#include <mlir/Support/LogicalResult.h>
|
||||
#include <string>
|
||||
|
||||
namespace serene {
|
|
@ -23,11 +23,12 @@
|
|||
*/
|
||||
#include "serene/slir/dialect.h"
|
||||
|
||||
#include "mlir/IR/Builders.h"
|
||||
#include "mlir/IR/BuiltinTypes.h"
|
||||
#include "mlir/IR/OpImplementation.h"
|
||||
#include "serene/slir/dialect.cpp.inc"
|
||||
|
||||
#include <mlir/IR/Builders.h>
|
||||
#include <mlir/IR/BuiltinTypes.h>
|
||||
#include <mlir/IR/OpImplementation.h>
|
||||
|
||||
namespace serene {
|
||||
namespace slir {
|
||||
|
|
@ -22,13 +22,13 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mlir/IR/Attributes.h"
|
||||
#include "mlir/IR/BuiltinAttributes.h"
|
||||
#include "mlir/IR/Identifier.h"
|
||||
#include "serene/slir/dialect.h"
|
||||
|
||||
#include <llvm/Support/FormatVariadic.h>
|
||||
#include <mlir/IR/Attributes.h>
|
||||
#include <mlir/IR/Builders.h>
|
||||
#include <mlir/IR/BuiltinAttributes.h>
|
||||
#include <mlir/IR/Identifier.h>
|
||||
#include <mlir/IR/OperationSupport.h>
|
||||
|
||||
namespace serene::slir {
|
|
@ -22,16 +22,17 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mlir/IR/BuiltinOps.h"
|
||||
#include "serene/context.h"
|
||||
#include "serene/namespace.h"
|
||||
#include "serene/reader/location.h"
|
||||
|
||||
#include <mlir/IR/BuiltinOps.h>
|
||||
|
||||
namespace serene::slir {
|
||||
::mlir::Location toMLIRLocation(serene::Namespace &ns,
|
||||
serene::reader::Location &loc) {
|
||||
mlir::OpBuilder builder(&ns.getContext().mlirContext);
|
||||
auto file = ns.filename;
|
||||
auto file = ns.filename;
|
||||
std::string filename{file.getValueOr("REPL")};
|
||||
|
||||
return mlir::FileLineColLoc::get(builder.getIdentifier(filename), loc.line,
|
|
@ -21,13 +21,13 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include "mlir/IR/Builders.h"
|
||||
#include "mlir/IR/MLIRContext.h"
|
||||
#include "mlir/IR/Value.h"
|
||||
#include "serene/slir/dialect.h"
|
||||
#include "serene/slir/slir.h"
|
||||
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include <llvm/Support/Casting.h>
|
||||
#include <mlir/IR/Builders.h>
|
||||
#include <mlir/IR/MLIRContext.h>
|
||||
#include <mlir/IR/Value.h>
|
||||
|
||||
namespace serene {
|
||||
namespace slir {} // namespace slir
|
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 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/serene.h"
|
||||
|
||||
#include "serene/reader/reader.h"
|
||||
|
||||
#include <iostream>
|
|
@ -20,7 +20,7 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
add_executable(serenec serene.cpp)
|
||||
add_executable(serenec serenec.cpp $<TARGET_OBJECTS:Serene::lib>)
|
||||
|
||||
if (CPP_20_SUPPORT)
|
||||
target_compile_features(serenec PRIVATE cxx_std_20)
|
||||
|
@ -28,18 +28,13 @@ else()
|
|||
target_compile_features(serenec PRIVATE cxx_std_17)
|
||||
endif()
|
||||
|
||||
|
||||
target_link_libraries(serenec PRIVATE
|
||||
serene
|
||||
${llvm_libs}
|
||||
MLIRAnalysis
|
||||
MLIRIR
|
||||
MLIRParser
|
||||
MLIRSideEffectInterfaces
|
||||
MLIRTransforms
|
||||
get_property(serene_lib_deps TARGET Serene::lib PROPERTY StaticDeps)
|
||||
set(serenec_deps
|
||||
${serene_lib_deps}
|
||||
LLVMX86AsmParser
|
||||
LLVMTarget
|
||||
LLVMOption
|
||||
#clangTooling
|
||||
|
||||
clangDriver
|
||||
clangBasic
|
||||
clangdSupport
|
||||
|
@ -48,9 +43,14 @@ target_link_libraries(serenec PRIVATE
|
|||
clangLex
|
||||
)
|
||||
|
||||
message(STATUS "ooooooo ${serene_lib_deps}")
|
||||
message(STATUS "ooooooo ${serenec_deps}")
|
||||
|
||||
#target_include_directories(serene SYSTEM PRIVATE $ENV{INCLUDE})
|
||||
target_include_directories(serene PRIVATE ${INCLUDE_DIR})
|
||||
target_link_libraries(serenec PUBLIC
|
||||
${serenec_deps}
|
||||
)
|
||||
|
||||
target_include_directories(serenec PRIVATE ${PROJECT_BINARY_DIR})
|
||||
target_include_directories(serenec PRIVATE ${INCLUDE_DIR})
|
||||
|
||||
install(TARGETS serenec DESTINATION bin)
|
||||
#install(FILES "${PROJECT_BINARY_DIR}/config.h" DESTINATION include)
|
|
@ -22,8 +22,6 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "serene/serene.h"
|
||||
|
||||
#include "serene/config.h"
|
||||
#include "serene/context.h"
|
||||
#include "serene/jit.h"
|
||||
|
@ -31,6 +29,7 @@
|
|||
#include "serene/reader/location.h"
|
||||
#include "serene/reader/reader.h"
|
||||
#include "serene/reader/semantics.h"
|
||||
#include "serene/serene.h"
|
||||
#include "serene/slir/generatable.h"
|
||||
#include "serene/slir/slir.h"
|
||||
|
Loading…
Reference in New Issue