Create a tablegen instance for Serene to be used locally
This commit is contained in:
parent
cfa4f54b5a
commit
a085f0b7ea
|
@ -209,6 +209,21 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
include_directories(SYSTEM ${PROJECT_BINARY_DIR}/include)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
|
||||
|
||||
# Make sure that our source directory is on the current cmake module path so
|
||||
# that we can include cmake files from this directory.
|
||||
list(INSERT CMAKE_MODULE_PATH 0
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
|
||||
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
|
||||
)
|
||||
|
||||
include(tablegen-serene)
|
||||
|
||||
# Create the tools we use to compile Serene
|
||||
add_subdirectory(tools)
|
||||
|
||||
# Make sure that serene_tablegen can use the tbl-srn result
|
||||
set(SERENE_TABLEGEN_EXE "$<TARGET_FILE:tbl-srn>")
|
||||
|
||||
# The compiled library code is here
|
||||
add_subdirectory(src)
|
||||
# The executable code is here
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
# Serene Programming Language
|
||||
#
|
||||
# Copyright (c) 2019-2021 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/>.
|
||||
|
||||
macro(add_ target project)
|
||||
set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
|
||||
set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
|
||||
|
||||
# CMake doesn't let compilation units depend on their dependent libraries on some generators.
|
||||
if(NOT CMAKE_GENERATOR STREQUAL "Ninja" AND NOT XCODE)
|
||||
# FIXME: It leaks to user, callee of add_tablegen.
|
||||
set(LLVM_ENABLE_OBJLIB ON)
|
||||
endif()
|
||||
|
||||
|
||||
set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})
|
||||
|
||||
set(${project}_TABLEGEN "${target}" CACHE
|
||||
STRING "Native TableGen executable. Saves building one when cross-compiling.")
|
||||
|
||||
# Effective tblgen executable to be used:
|
||||
set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN} PARENT_SCOPE)
|
||||
set(${project}_TABLEGEN_TARGET ${${project}_TABLEGEN} PARENT_SCOPE)
|
||||
|
||||
if(LLVM_USE_HOST_TOOLS)
|
||||
if( ${${project}_TABLEGEN} STREQUAL "${target}" )
|
||||
# The NATIVE tablegen executable *must* depend on the current target one
|
||||
# otherwise the native one won't get rebuilt when the tablgen sources
|
||||
# change, and we end up with incorrect builds.
|
||||
build_native_tool(${target} ${project}_TABLEGEN_EXE DEPENDS ${target})
|
||||
set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE)
|
||||
|
||||
add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE})
|
||||
set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE)
|
||||
|
||||
# Create an artificial dependency between tablegen projects, because they
|
||||
# compile the same dependencies, thus using the same build folders.
|
||||
# FIXME: A proper fix requires sequentially chaining tablegens.
|
||||
if (NOT ${project} STREQUAL LLVM AND TARGET ${project}-tablegen-host AND
|
||||
TARGET LLVM-tablegen-host)
|
||||
add_dependencies(${project}-tablegen-host LLVM-tablegen-host)
|
||||
endif()
|
||||
|
||||
# If we're using the host tablegen, and utils were not requested, we have no
|
||||
# need to build this tablegen.
|
||||
if ( NOT LLVM_BUILD_UTILS )
|
||||
set_target_properties(${target} PROPERTIES EXCLUDE_FROM_ALL ON)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if ((${project} STREQUAL LLVM OR ${project} STREQUAL MLIR) AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_BUILD_UTILS)
|
||||
set(export_to_llvmexports)
|
||||
if(${target} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
|
||||
NOT LLVM_DISTRIBUTION_COMPONENTS)
|
||||
set(export_to_llvmexports EXPORT LLVMExports)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${target}
|
||||
${export_to_llvmexports}
|
||||
COMPONENT ${target}
|
||||
RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR})
|
||||
if(NOT LLVM_ENABLE_IDE)
|
||||
add_llvm_install_targets("install-${target}"
|
||||
DEPENDS ${target}
|
||||
COMPONENT ${target})
|
||||
endif()
|
||||
endif()
|
||||
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${target})
|
||||
endmacro()
|
||||
|
||||
function(serene_tablegen ofn)
|
||||
tablegen(SERENE ${ARGV})
|
||||
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
|
||||
PARENT_SCOPE)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
endfunction()
|
|
@ -0,0 +1 @@
|
|||
lxsameer@underworld.2515108:1638986649
|
|
@ -0,0 +1,22 @@
|
|||
# Serene Programming Language
|
||||
#
|
||||
# Copyright (c) 2019-2021 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/>.
|
||||
|
||||
function(serene_tablegen ofn)
|
||||
tablegen(SERENE ${ARGV})
|
||||
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
|
||||
PARENT_SCOPE)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
endfunction()
|
|
@ -1 +1,2 @@
|
|||
add_subdirectory("serene/slir/")
|
||||
add_subdirectory("serene/errors/")
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
set(LLVM_TARGET_DEFINITIONS errors.td)
|
||||
|
||||
# serene_tablegen(ops.h.inc -gen-op-decls)
|
||||
# serene_tablegen(ops.cpp.inc -gen-op-defs)
|
||||
# serene_tablegen(types.h.inc -gen-typedef-decls)
|
||||
# serene_tablegen(types.cpp.inc -gen-typedef-defs)
|
||||
# serene_tablegen(dialect.h.inc -gen-dialect-decls)
|
||||
# serene_tablegen(dialect.cpp.inc -gen-dialect-defs)
|
||||
|
||||
#add_public_tablegen_target(SereneErrorGen)
|
|
@ -0,0 +1 @@
|
|||
def Err;
|
|
@ -18,6 +18,7 @@ add_subdirectory(libserene)
|
|||
add_subdirectory(serenec)
|
||||
add_subdirectory(serene-repl)
|
||||
|
||||
|
||||
# Testing only available if this is the main app
|
||||
# Emergency override SERENE_CMAKE_BUILD_TESTING provided as well
|
||||
if(SERENE_BUILD_TESTING)
|
||||
|
|
|
@ -110,7 +110,7 @@ else()
|
|||
endif()
|
||||
|
||||
# Generate the tablegen ODS files before this target
|
||||
add_dependencies(serene SereneDialectGen)
|
||||
add_dependencies(serene tbl-srn SereneDialectGen ) #SereneErrorGen
|
||||
|
||||
# We need this directory, and users of our library will need it too
|
||||
target_include_directories(serene PUBLIC "$<BUILD_INTERFACE:${INCLUDE_DIR}>")
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Serene Programming Language
|
||||
#
|
||||
# Copyright (c) 2019-2021 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(tbl-srn)
|
|
@ -0,0 +1,32 @@
|
|||
# Serene Programming Language
|
||||
#
|
||||
# Copyright (c) 2019-2021 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/>.
|
||||
|
||||
set(LLVM_LINK_COMPONENTS Support TableGen)
|
||||
|
||||
add_executable(tbl-srn
|
||||
errors-backend.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set(SERENE_TABLEGEN "tbl-srn" CACHE
|
||||
STRING "Native TableGen executable. Saves building one when cross-compiling.")
|
||||
|
||||
# Effective tblgen executable to be used:
|
||||
set(SERENE_TABLEGEN_EXE ${SERENE_TABLEGEN} PARENT_SCOPE)
|
||||
set(SERENE_TABLEGEN_TARGET ${SERENE_TABLEGEN} PARENT_SCOPE)
|
||||
|
||||
target_link_libraries(tbl-srn PRIVATE LLVMTableGenGlobalISel)
|
||||
set_target_properties(tbl-srn PROPERTIES FOLDER "tbl-srn")
|
|
@ -0,0 +1,50 @@
|
|||
/* -*- C++ -*-
|
||||
* Serene Programming Language
|
||||
*
|
||||
* Copyright (c) 2019-2021 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 <errors-backend.h>
|
||||
|
||||
#include <llvm/Support/Format.h>
|
||||
|
||||
#define DEBUG_TYPE "errors-backend"
|
||||
|
||||
namespace serene {
|
||||
|
||||
// Any helper data structures can be defined here. Some backends use
|
||||
// structs to collect information from the records.
|
||||
|
||||
class ErrorsBackend {
|
||||
private:
|
||||
llvm::RecordKeeper &records;
|
||||
|
||||
public:
|
||||
ErrorsBackend(llvm::RecordKeeper &rk) : records(rk) {}
|
||||
|
||||
void run(llvm::raw_ostream &os);
|
||||
}; // emitter class
|
||||
|
||||
void ErrorsBackend::run(llvm::raw_ostream &os) {
|
||||
llvm::emitSourceFileHeader("Serene's Errors collection", os);
|
||||
|
||||
(void)records;
|
||||
}
|
||||
|
||||
void emitErrors(llvm::RecordKeeper &rk, llvm::raw_ostream &os) {
|
||||
ErrorsBackend(rk).run(os);
|
||||
}
|
||||
|
||||
} // namespace serene
|
|
@ -0,0 +1,28 @@
|
|||
/* -*- C++ -*-
|
||||
* Serene Programming Language
|
||||
*
|
||||
* Copyright (c) 2019-2021 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 <llvm/TableGen/Record.h>
|
||||
#include <llvm/TableGen/TableGenBackend.h>
|
||||
|
||||
#define DEBUG_TYPE "errors-backend"
|
||||
|
||||
namespace serene {
|
||||
|
||||
void emitErrors(llvm::RecordKeeper &rk, llvm::raw_ostream &os);
|
||||
|
||||
} // namespace serene
|
|
@ -0,0 +1,74 @@
|
|||
/* -*- C++ -*-
|
||||
* Serene Programming Language
|
||||
*
|
||||
* Copyright (c) 2019-2021 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Commentary:
|
||||
* This is the main file for Serene's tablegen instance. All the backends
|
||||
* are local to this instance and we use this instance alongside the official
|
||||
* instances.
|
||||
*/
|
||||
|
||||
#include <errors-backend.h>
|
||||
|
||||
#include <llvm/Support/CommandLine.h>
|
||||
#include <llvm/Support/InitLLVM.h>
|
||||
#include <llvm/TableGen/Main.h>
|
||||
#include <llvm/TableGen/Record.h>
|
||||
#include <llvm/TableGen/SetTheory.h>
|
||||
|
||||
namespace cl = llvm::cl;
|
||||
|
||||
namespace serene {
|
||||
enum ActionType { ErrorsBackend };
|
||||
|
||||
cl::opt<ActionType>
|
||||
action(cl::desc("Action to perform:"),
|
||||
cl::values(clEnumValN(
|
||||
ErrorsBackend, "errors-backend",
|
||||
"Generate a C++ file containing errors in the input file")));
|
||||
|
||||
bool llvmTableGenMain(llvm::raw_ostream &os, llvm::RecordKeeper &records) {
|
||||
switch (action) {
|
||||
case ErrorsBackend:
|
||||
emitErrors(records, os);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace serene
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
llvm::InitLLVM x(argc, argv);
|
||||
cl::ParseCommandLineOptions(argc, argv);
|
||||
|
||||
return llvm::TableGenMain(argv[0], &serene::llvmTableGenMain);
|
||||
}
|
||||
|
||||
#ifndef __has_feature
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
|
||||
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) || \
|
||||
__has_feature(leak_sanitizer)
|
||||
|
||||
#include <sanitizer/lsan_interface.h>
|
||||
// Disable LeakSanitizer for this binary as it has too many leaks that are not
|
||||
// very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
|
||||
LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return 1; }
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue