Move the old libserene aside and start a new one
This commit is contained in:
parent
8a32489500
commit
8553b5f43f
|
@ -31,7 +31,7 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: clang-format
|
- id: clang-format
|
||||||
- id: cppcheck
|
- id: cppcheck
|
||||||
args: ['--project=compile_commands.json', '-j 4']
|
args: ['--project=compile_commands.json']
|
||||||
- id: include-what-you-use
|
- id: include-what-you-use
|
||||||
- repo: https://github.com/detailyang/pre-commit-shell
|
- repo: https://github.com/detailyang/pre-commit-shell
|
||||||
rev: 1.0.5
|
rev: 1.0.5
|
||||||
|
|
|
@ -241,16 +241,15 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||||
# Create the tools we use to compile Serene
|
# Create the tools we use to compile Serene
|
||||||
add_subdirectory(serene-tblgen)
|
add_subdirectory(serene-tblgen)
|
||||||
|
|
||||||
|
# Binary tools of the compiler
|
||||||
|
# add_subdirectory(serenec)
|
||||||
|
# add_subdirectory(serene-repl)
|
||||||
|
# The compiled library code is here
|
||||||
|
add_subdirectory(libserene)
|
||||||
# The static library containing builtin special forms and functions
|
# The static library containing builtin special forms and functions
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
|
|
||||||
# Binary tools of the compiler
|
# add_subdirectory(devtools)
|
||||||
add_subdirectory(serenec)
|
|
||||||
add_subdirectory(serene-repl)
|
|
||||||
# The compiled library code is here
|
|
||||||
add_subdirectory(libserene)
|
|
||||||
|
|
||||||
add_subdirectory(devtools)
|
|
||||||
|
|
||||||
|
|
||||||
if (SERENE_ENABLE_DOCS)
|
if (SERENE_ENABLE_DOCS)
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
# Serene Programming Language
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
#
|
||||||
|
# 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, version 2.
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
include_directories(${INCLUDE_DIR})
|
||||||
|
|
||||||
|
add_subdirectory(include)
|
||||||
|
add_subdirectory(lib)
|
||||||
|
|
||||||
|
# Install rules for libserene target
|
||||||
|
install(TARGETS serene
|
||||||
|
EXPORT SereneExports
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
||||||
|
|
||||||
|
# Install rules for the public header files.
|
||||||
|
install(DIRECTORY ${INCLUDE_DIR}/serene
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
FILES_MATCHING
|
||||||
|
PATTERN *.h
|
||||||
|
PATTERN *.td
|
||||||
|
PATTERN "CMake*" EXCLUDE)
|
||||||
|
|
||||||
|
# Install rule for the public generated header files
|
||||||
|
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
FILES_MATCHING
|
||||||
|
PATTERN *.h
|
||||||
|
PATTERN *.td
|
||||||
|
PATTERN *.h.inc
|
||||||
|
PATTERN "CMake*" EXCLUDE)
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
# Package config file let us use find_package with serene
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
|
||||||
|
INSTALL_DESTINATION
|
||||||
|
${CMAKE_INSTALL_LIBDIR}/cmake/serene-${PROJECT_VERSION}
|
||||||
|
)
|
||||||
|
|
||||||
|
write_basic_package_version_file(
|
||||||
|
"${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
install(FILES
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
DESTINATION
|
||||||
|
${CMAKE_INSTALL_LIBDIR}/cmake/serene-${PROJECT_VERSION}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Install the package exports
|
||||||
|
install(EXPORT SereneExports
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/serene-${PROJECT_VERSION}
|
||||||
|
NAMESPACE serene::)
|
||||||
|
|
||||||
|
# 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(tests)
|
||||||
|
endif()
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Serene Programming Language
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
#
|
||||||
|
# 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, version 2.
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Exports.cmake")
|
||||||
|
|
||||||
|
check_required_components("@PROJECT_NAME@")
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
// the configured options and settings
|
||||||
|
|
||||||
|
#define SERENE_VERSION "@PROJECT_VERSION@"
|
||||||
|
|
||||||
|
// Why so obvious? to make the linter shutup :))
|
||||||
|
#define I8_SIZE 8
|
||||||
|
#define I32_SIZE 32
|
||||||
|
#define I64_SIZE 64
|
||||||
|
|
||||||
|
// Should we build the support for MLIR CL OPTIONS?
|
||||||
|
#cmakedefine SERENE_WITH_MLIR_CL_OPTION
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* -*- C++ -*-
|
||||||
|
* Serene Programming Language
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
*
|
||||||
|
* 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, version 2.
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SERENE_SERENE_H
|
||||||
|
#define SERENE_SERENE_H
|
||||||
|
|
||||||
|
#include "serene/config.h"
|
||||||
|
#include "serene/context.h"
|
||||||
|
#include "serene/export.h"
|
||||||
|
#include "serene/exprs/expression.h"
|
||||||
|
#include "serene/source_mgr.h"
|
||||||
|
|
||||||
|
namespace serene {
|
||||||
|
|
||||||
|
/// Clinet applications have to call this function before any interaction with
|
||||||
|
/// the Serene's compiler API.
|
||||||
|
SERENE_EXPORT void initCompiler();
|
||||||
|
|
||||||
|
/// Register the global CLI options of the serene compiler. If the client
|
||||||
|
/// application needs to setup the compilers options automatically use this
|
||||||
|
/// function in conjunction with `applySereneCLOptions`.
|
||||||
|
SERENE_EXPORT void registerSereneCLOptions();
|
||||||
|
|
||||||
|
/// Applies the global compiler options on the give \p SereneContext. This
|
||||||
|
/// function has to be called after `llvm::cl::ParseCommandLineOptions`.
|
||||||
|
SERENE_EXPORT void applySereneCLOptions(SereneContext &ctx);
|
||||||
|
|
||||||
|
/// \brief Reads the the given \p input as Serene source code in the given
|
||||||
|
/// \c SereneContext \p ctx and returns the possible AST tree of the input or an
|
||||||
|
/// error otherwise.
|
||||||
|
///
|
||||||
|
/// If any thing goes wrong it will return an \return \c llvm::Error describing
|
||||||
|
/// the issue.
|
||||||
|
///
|
||||||
|
/// Be aware than this function reads the input in the context of the current
|
||||||
|
/// namespace. So for example if the input is somthing like:
|
||||||
|
///
|
||||||
|
/// (ns example.code) ....
|
||||||
|
///
|
||||||
|
/// and the current ns is `user` then if there is a syntax error in the input
|
||||||
|
/// the error will be reported under the `user` ns. This is logical because
|
||||||
|
/// this function reads the code and not evaluate it. the `ns` form has to be
|
||||||
|
/// evaluated in order to change the ns.
|
||||||
|
SERENE_EXPORT exprs::MaybeAst read(SereneContext &ctx, std::string &input);
|
||||||
|
|
||||||
|
/// Evaluates the given AST form \p input in the given \c SereneContext \p ctx
|
||||||
|
/// and retuns a new expression as the result or a possible error.
|
||||||
|
///
|
||||||
|
/// In case of an error Serene will throw the error messages vis the diagnostic
|
||||||
|
/// engine as well and the error that this function returns will be the
|
||||||
|
/// generic error message.
|
||||||
|
SERENE_EXPORT exprs::MaybeNode eval(SereneContext &ctx, exprs::Ast &input);
|
||||||
|
|
||||||
|
// TODO: Return a Serene String type instead of the std::string
|
||||||
|
// TODO: Create an overload to get a stream instead of the result string
|
||||||
|
/// Prints the given AST form \p input in the given \c SereneContext \p ctx
|
||||||
|
/// into the given \p result.
|
||||||
|
/// Note: print is a lisp action. Don't confuse it with a print function such
|
||||||
|
/// as `println`.
|
||||||
|
SERENE_EXPORT void print(SereneContext &ctx, const exprs::Ast &input,
|
||||||
|
std::string &result);
|
||||||
|
|
||||||
|
} // namespace serene
|
||||||
|
#endif
|
|
@ -0,0 +1,169 @@
|
||||||
|
# Serene Programming Language
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
#
|
||||||
|
# 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, version 2.
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#TODO: To support MacOS look into cmake's public headers
|
||||||
|
# https://cmake.org/cmake/help/latest/prop_tgt/PUBLIC_HEADER.html
|
||||||
|
|
||||||
|
# Prevent any future RPATH issue on Posix
|
||||||
|
if(NOT APPLE)
|
||||||
|
set(CMAKE_INSTALL_RPATH $ORIGIN)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(serene
|
||||||
|
exprs/symbol.cpp
|
||||||
|
exprs/list.cpp
|
||||||
|
exprs/number.cpp
|
||||||
|
exprs/expression.cpp
|
||||||
|
exprs/def.cpp
|
||||||
|
exprs/fn.cpp
|
||||||
|
exprs/call.cpp
|
||||||
|
|
||||||
|
serene.cpp
|
||||||
|
context.cpp
|
||||||
|
namespace.cpp
|
||||||
|
source_mgr.cpp
|
||||||
|
diagnostics.cpp
|
||||||
|
semantics.cpp
|
||||||
|
|
||||||
|
# jit.cpp
|
||||||
|
# jit/engine.cpp
|
||||||
|
# jit/layers.cpp
|
||||||
|
jit/halley.cpp
|
||||||
|
|
||||||
|
errors.cpp
|
||||||
|
|
||||||
|
# Reader
|
||||||
|
reader/reader.cpp
|
||||||
|
|
||||||
|
# IR
|
||||||
|
slir/types.cpp
|
||||||
|
slir/slir.cpp
|
||||||
|
slir/value_op.cpp
|
||||||
|
slir/generatable.cpp
|
||||||
|
slir/utils.cpp
|
||||||
|
slir/ops.cpp
|
||||||
|
slir/type_converter.cpp
|
||||||
|
slir/dialect.cpp
|
||||||
|
passes/slir_lowering.cpp
|
||||||
|
passes/to_llvm_dialect.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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 serene has to
|
||||||
|
# use `Serene::lib` alias instead
|
||||||
|
add_library(Serene::lib ALIAS serene)
|
||||||
|
|
||||||
|
set_target_properties(serene PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||||
|
# Warn on unused libs
|
||||||
|
LINK_WHAT_YOU_USE TRUE
|
||||||
|
# LTO support
|
||||||
|
INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
|
||||||
|
if(SERENE_ENABLE_TIDY)
|
||||||
|
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Do we need to build serene as a shared lib? default is "yes"
|
||||||
|
if(SERENE_SHARED_LIB)
|
||||||
|
|
||||||
|
# We need to use libsan as a shared lib on debug mode. The
|
||||||
|
# target executable has to be built with `-fsanitize=address`
|
||||||
|
# as well and it has to run with:
|
||||||
|
# LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)
|
||||||
|
target_compile_options(serene PRIVATE
|
||||||
|
$<$<CONFIG:DEBUG>:-shared-libsan>
|
||||||
|
)
|
||||||
|
target_link_options(
|
||||||
|
serene PRIVATE
|
||||||
|
$<$<CONFIG:DEBUG>:-shared-libsan>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if (CPP_20_SUPPORT)
|
||||||
|
target_compile_features(serene PUBLIC cxx_std_20)
|
||||||
|
else()
|
||||||
|
target_compile_features(serene PUBLIC cxx_std_17)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Generate the tablegen ODS files before this target
|
||||||
|
add_dependencies(serene SereneTablegen SereneDialectGen SerenePassGen SereneErrorGen)
|
||||||
|
|
||||||
|
# We need this directory, and users of our library will need it too
|
||||||
|
target_include_directories(serene PUBLIC "$<BUILD_INTERFACE:${INCLUDE_DIR}>")
|
||||||
|
target_include_directories(serene PUBLIC "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>")
|
||||||
|
|
||||||
|
# Generate the export.h
|
||||||
|
include(GenerateExportHeader)
|
||||||
|
generate_export_header(serene EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/serene/export.h)
|
||||||
|
target_compile_definitions(
|
||||||
|
serene PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SERENE_STATIC_DEFINE>")
|
||||||
|
|
||||||
|
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||||
|
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
MLIRFunc)
|
||||||
|
|
||||||
|
set(serene_lib_transformers_in_use
|
||||||
|
MLIRFuncToLLVM)
|
||||||
|
|
||||||
|
target_link_libraries(serene PRIVATE
|
||||||
|
MLIRIR
|
||||||
|
MLIRPass
|
||||||
|
MLIRTransforms
|
||||||
|
|
||||||
|
${serene_lib_dialects_in_use}
|
||||||
|
${serene_lib_transformers_in_use}
|
||||||
|
|
||||||
|
#TODO: Remove this lib, we're just using one func
|
||||||
|
MLIRExecutionEngine
|
||||||
|
|
||||||
|
# LLVM's JIT lib
|
||||||
|
LLVMExecutionEngine
|
||||||
|
LLVMOrcJIT
|
||||||
|
MLIRLLVMToLLVMIRTranslation
|
||||||
|
|
||||||
|
LLVMTarget
|
||||||
|
LLVMX86AsmParser
|
||||||
|
|
||||||
|
${llvm_libs})
|
|
@ -0,0 +1,157 @@
|
||||||
|
/* -*- C++ -*-
|
||||||
|
* Serene Programming Language
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
*
|
||||||
|
* 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, version 2.
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "serene/serene.h"
|
||||||
|
|
||||||
|
#include "serene/diagnostics.h"
|
||||||
|
#include "serene/exprs/expression.h"
|
||||||
|
|
||||||
|
// TODO: Remove it
|
||||||
|
#include "serene/exprs/number.h"
|
||||||
|
#include "serene/jit/halley.h"
|
||||||
|
#include "serene/reader/reader.h"
|
||||||
|
#include "serene/utils.h"
|
||||||
|
|
||||||
|
#include <llvm/ADT/None.h>
|
||||||
|
#include <llvm/Support/Casting.h>
|
||||||
|
#include <llvm/Support/CommandLine.h>
|
||||||
|
#include <llvm/Support/Error.h>
|
||||||
|
#include <llvm/Support/TargetSelect.h>
|
||||||
|
#include <llvm/Support/raw_ostream.h>
|
||||||
|
|
||||||
|
namespace serene {
|
||||||
|
using exprs::Number;
|
||||||
|
|
||||||
|
void initCompiler() {
|
||||||
|
llvm::InitializeAllTargetInfos();
|
||||||
|
llvm::InitializeAllTargets();
|
||||||
|
llvm::InitializeAllTargetMCs();
|
||||||
|
llvm::InitializeAllAsmParsers();
|
||||||
|
llvm::InitializeAllAsmPrinters();
|
||||||
|
};
|
||||||
|
|
||||||
|
// CLI Option ----------------
|
||||||
|
|
||||||
|
/// All the global CLI option ar defined here. If you need to add a new global
|
||||||
|
/// option
|
||||||
|
/// make sure that you are handling it in `applySereneCLOptions` too.
|
||||||
|
struct SereneOptions {
|
||||||
|
|
||||||
|
llvm::cl::OptionCategory clOptionsCategory{"Discovery options"};
|
||||||
|
|
||||||
|
llvm::cl::list<std::string> loadPaths{
|
||||||
|
"l", llvm::cl::desc("The load path to use for compilation."),
|
||||||
|
llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::PositionalEatsArgs,
|
||||||
|
llvm::cl::cat(clOptionsCategory)};
|
||||||
|
|
||||||
|
llvm::cl::list<std::string> sharedLibraryPaths{
|
||||||
|
"sl", llvm::cl::desc("Where to find shared libraries"),
|
||||||
|
llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::PositionalEatsArgs,
|
||||||
|
llvm::cl::cat(clOptionsCategory)};
|
||||||
|
};
|
||||||
|
|
||||||
|
static llvm::ManagedStatic<SereneOptions> options;
|
||||||
|
|
||||||
|
void registerSereneCLOptions() {
|
||||||
|
// Make sure that the options struct has been constructed.
|
||||||
|
*options;
|
||||||
|
|
||||||
|
#ifdef SERENE_WITH_MLIR_CL_OPTION
|
||||||
|
// mlir::registerAsmPrinterCLOptions();
|
||||||
|
mlir::registerMLIRContextCLOptions();
|
||||||
|
mlir::registerPassManagerCLOptions();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void applySereneCLOptions(SereneContext &ctx) {
|
||||||
|
if (!options.isConstructed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.sourceManager.setLoadPaths(options->loadPaths);
|
||||||
|
|
||||||
|
#ifdef SERENE_WITH_MLIR_CL_OPTION
|
||||||
|
mlir::applyPassManagerCLOptions(ctx.pm);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
SERENE_EXPORT exprs::MaybeAst read(SereneContext &ctx, std::string &input) {
|
||||||
|
auto ¤tNS = ctx.getCurrentNS();
|
||||||
|
auto filename =
|
||||||
|
!currentNS.filename.hasValue()
|
||||||
|
? llvm::None
|
||||||
|
: llvm::Optional<llvm::StringRef>(currentNS.filename.getValue());
|
||||||
|
|
||||||
|
return reader::read(ctx, input, currentNS.name, filename);
|
||||||
|
};
|
||||||
|
|
||||||
|
SERENE_EXPORT exprs::MaybeNode eval(SereneContext &ctx, exprs::Ast &input) {
|
||||||
|
|
||||||
|
auto loc = reader::LocationRange::UnknownLocation("nsname");
|
||||||
|
|
||||||
|
// auto ns = ctx.importNamespace("docs.examples.hello_world", loc);
|
||||||
|
|
||||||
|
// if (!ns) {
|
||||||
|
// auto es = ns.getError();
|
||||||
|
// auto nsloadErr = errors::makeError(loc, errors::NSLoadError);
|
||||||
|
// es.push_back(nsloadErr);
|
||||||
|
// return exprs::MaybeNode::error(es);
|
||||||
|
// }
|
||||||
|
|
||||||
|
auto errs = ctx.jit->addAST(input);
|
||||||
|
if (errs) {
|
||||||
|
return errs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// auto e = input[0];
|
||||||
|
// auto *sym = llvm::dyn_cast<exprs::Symbol>(e.get());
|
||||||
|
|
||||||
|
// if (sym == nullptr) {
|
||||||
|
// return exprs::makeErrorNode(e->location, errors::UnknownError, "only
|
||||||
|
// sym");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// llvm::outs() << "Read: " << sym->toString() << "\n";
|
||||||
|
|
||||||
|
// // Get the anonymous expression's JITSymbol.
|
||||||
|
// auto symptr = ctx.jit->lookup(*sym);
|
||||||
|
// if (!symptr) {
|
||||||
|
// return exprs::MaybeNode::error(symptr.getError());
|
||||||
|
// }
|
||||||
|
|
||||||
|
llvm::outs() << "eval here\n";
|
||||||
|
|
||||||
|
// sym((void **)3);
|
||||||
|
|
||||||
|
// err = ctx.jit->addAst(input);
|
||||||
|
// if (err) {
|
||||||
|
// llvm::errs() << err;
|
||||||
|
// auto e = errors::makeErrorTree(loc, errors::NSLoadError);
|
||||||
|
|
||||||
|
// return exprs::makeErrorNode(loc, errors::NSLoadError);
|
||||||
|
// }
|
||||||
|
return exprs::make<exprs::Number>(loc, "4", false, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
SERENE_EXPORT void print(SereneContext &ctx, const exprs::Ast &input,
|
||||||
|
std::string &result) {
|
||||||
|
UNUSED(ctx);
|
||||||
|
result = exprs::astToString(&input);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace serene
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue