Add the userene binary

This commit is contained in:
Sameer Rahmani 2023-07-11 18:54:06 +01:00
parent 255045c552
commit 23522ea491
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
9 changed files with 394 additions and 1 deletions

View File

@ -184,7 +184,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# /LLVM setup =================================================================
add_subdirectory(serene)
add_subdirectory(userene)
# include(tablegen-serene)
# Create the tools we use to compile Serene
#add_subdirectory(serene-tblgen)

135
userene/CMakeLists.txt Normal file
View File

@ -0,0 +1,135 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 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/>.
find_package(BDWgc 8.2.0 REQUIRED)
# Main Binary =================================================================
add_executable(userene)
set_target_properties(userene PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
C_INCLUDE_WHAT_YOU_USE ${iwyu}
CXX_INCLUDE_WHAT_YOU_USE ${iwyu}
# Warn on unused libs
LINK_WHAT_YOU_USE TRUE
)
if (CPP_20_SUPPORT)
target_compile_features(userene PRIVATE cxx_std_20)
else()
target_compile_features(userene PRIVATE cxx_std_17)
endif()
# Setup header directory and auto generated headers
target_include_directories(userene
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_include_directories(userene SYSTEM PUBLIC
# We don't want the generated files from table gen
# to be treated as local since the contain warnings
${PROJECT_BINARY_DIR}/serene/include)
target_link_libraries(userene PRIVATE
LLVMSupport
)
# Autogenerate the `config.h` file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/serene/config.h.in include/serene/config.h)
target_compile_options(userene
PRIVATE
$<$<NOT:$<BOOL:${SERENE_DISABLE_LIBCXX}>>:-stdlib=libc++>
# LLVM has it's own RTTI
-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
$<$<CONFIG:DEBUG>:-fsanitize=address>
$<$<CONFIG:DEBUG>:-static-libsan>
$<$<CONFIG:DEBUG>:-g3>
$<$<CONFIG:DEBUG>:-O0>
$<$<CONFIG:DEBUG>:-ggdb>
# For the sake of debugging
$<$<CONFIG:DEBUG>:-fno-inline>
# To make the local ccache happy
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=.>
# No tail call elimination on Debug to let asan provide
# better stacktrackes
$<$<CONFIG:DEBUG>:-fno-optimize-sibling-calls>
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
$<$<CONFIG:RELEASE>:-O3>
$<$<CONFIG:RELEASE>:-fmerge-all-constants>
)
target_link_options(userene PRIVATE
$<$<NOT:$<BOOL:${SERENE_DISABLE_LIBCXX}>>:-stdlib=libc++>
$<$<NOT:$<BOOL:${SERENE_DISABLE_LIBCXX}>>:-lc++abi>
$<$<NOT:$<BOOL:${SERENE_DISABLE_COMPILER_RT}>>:--rtlib=compiler-rt>
-Wl,--gc-sections
$<$<CONFIG:RELEASE>:-s>
$<$<CONFIG:DEBUG>:-fsanitize=address>
$<$<CONFIG:DEBUG>:-static-libsan>
# Do not link against shared libraries
--static
)
if(SERENE_ENABLE_BUILDID)
target_link_options(userene -Wl,--build-id)
endif()
if(SERENE_ENABLE_TIDY)
set_target_properties(userene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
endif()
if(SERENE_ENABLE_THINLTO)
include(CheckIPOSupported)
# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT result OUTPUT output)
if(result)
message(STATUS "IPO is supported and is turned on")
set_property(TARGET userene PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${output}")
message(WARNING "Make sure to use lld")
endif()
endif()
include(GNUInstallDirs)
install(TARGETS userene EXPORT SereneTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
add_subdirectory(src)
add_subdirectory(include)

View File

@ -0,0 +1,17 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 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/>.
# add_subdirectory("serene/slir/")

View File

@ -0,0 +1,27 @@
/* -*- C++ -*-
* Serene Programming Language
*
* Copyright (c) 2019-2023 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_COMMANDS_H
#define SERENE_COMMANDS_H
namespace serene::commands {
int cc(int argc, char **argv);
int run();
} // namespace serene::commands
#endif

View File

@ -0,0 +1,22 @@
#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
#define MAX_PATH_SLOTS 256
#define COMMON_ARGS_COUNT 6
#define PACKED_FUNCTION_NAME_PREFIX "__serene_"
// Should we build the support for MLIR CL OPTIONS?
#cmakedefine SERENE_WITH_MLIR_CL_OPTION
#endif

View File

@ -0,0 +1,71 @@
/* -*- C++ -*-
* Serene Programming Language
*
* Copyright (c) 2019-2023 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_TYPES_TYPE_H
#define SERENE_TYPES_TYPE_H
#include <cstddef>
namespace serene::types {
// ============================================================================
// Expression
// ============================================================================
struct Expression {
const unsigned char *data;
explicit Expression(const unsigned char *data) : data(data){};
};
// ============================================================================
// Internal String
// ============================================================================
/// Internal string represts a smaller type of string with limited set of
/// functionalities that we use only for internal usage. for exmaple if you need
/// to bring something 2
struct InternalString {
// We store the actual string in a "string" data section
const char *data;
size_t len;
InternalString(const char *data, const unsigned int len)
: data(data), len(len){};
};
// ============================================================================
// Symbol
// ============================================================================
struct Symbol {
const InternalString *ns;
const InternalString *name;
Symbol(const InternalString *ns, const InternalString *name)
: ns(ns), name(name){};
};
// ============================================================================
// Namespace
// ============================================================================
struct Namespace {
const InternalString *name;
explicit Namespace(const InternalString *name) : name(name){};
};
}; // namespace serene::types
#endif

View File

@ -0,0 +1,21 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 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/>.
target_sources(userene PRIVATE
userene.cpp
commands/commands.cpp
)

View File

@ -0,0 +1,30 @@
/* -*- C++ -*-
* Serene Programming Language
*
* Copyright (c) 2019-2023 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/commands.h"
#include <stdio.h>
namespace serene::commands {
int cc(int argc, char **argv) {
printf(">> %d, %s\n", argc, argv[0]);
return 0;
}
int run() { return 0; }
} // namespace serene::commands

70
userene/src/userene.cpp Normal file
View File

@ -0,0 +1,70 @@
/* -*- C++ -*-
* Serene Programming Language
*
* Copyright (c) 2019-2023 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/commands.h"
#include "serene/config.h"
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/FormatVariadic.h>
#include <cstring>
#include <string>
namespace cl = llvm::cl;
static std::string banner =
llvm::formatv("\n\nSerene Compiler Version {0}"
"\nCopyright (C) 2019-2023 "
"Sameer Rahmani <lxsameer@gnu.org>\n"
"Serene comes with ABSOLUTELY NO WARRANTY;\n"
"This is free software, and you are welcome\n"
"to redistribute it under certain conditions; \n"
"for details take a look at the LICENSE file.\n",
SERENE_VERSION);
namespace serene::opts {
// Global options ===========================================================
static cl::opt<bool> verbose("v", cl::desc("Use verbose output"),
cl::cat(cl::getGeneralCategory()),
cl::sub(cl::SubCommand::getAll()));
// Subcommands ==============================================================
// We don't use this subcommand directly but we need it for the CLI interface
static cl::SubCommand CC("cc", "Serene's C compiler interface");
static cl::SubCommand Run("run", "Run a Serene file");
} // namespace serene::opts
int main(int argc, char **argv) {
// We don't use llvm::cl here cause we want to let
// the clang take care of the argument parsing.
if ((argc >= 2) && (strcmp(argv[1], "cc") == 0)) {
return serene::commands::cc(--argc, ++argv);
}
// We start using llvm::cl from here onward which
// enforces our rules even for the subcommands.
cl::ParseCommandLineOptions(argc, argv, banner);
if (serene::opts::Run) {
serene::commands::run();
}
return 0;
}