Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
swift_gan committed Oct 31, 2024
1 parent 970b548 commit 4b95372
Show file tree
Hide file tree
Showing 102 changed files with 8,445 additions and 1,228 deletions.
47 changes: 46 additions & 1 deletion source/base/common_funcs.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "runtime/common/logging.h"
#include "base/logging.h"
#include <string_view>
#include <type_traits>
#include <tuple>

namespace swift {

Expand Down Expand Up @@ -92,4 +93,48 @@ bool ContainsElement(const Container& container, const T& value, size_t start_po
#define ENUM_TO_STRING_CASE(r) case ENUM_CLASS::r: return #r;
#define ENUM_DEFINE(r) r,

template <typename T> struct Identity {
using type = T;
};

template<typename T>
constexpr T RoundDown(T x, typename Identity<T>::type n) {
return (x & -n);
}

template<typename T>
constexpr T RoundUp(T x, std::remove_reference_t<T> n) {
return RoundDown(x + n - 1, n);
}


template<class... E>
struct list {};

template<class F>
struct function_info : function_info<decltype(&F::operator())> {};

template<class R, class... As>
struct function_info<R(As...)> {
using return_type = R;
using parameter_list = list<As...>;
static constexpr std::size_t parameter_count = sizeof...(As);

using equivalent_function_type = R(As...);

template<std::size_t I>
struct parameter {
static_assert(I < parameter_count, "Non-existent parameter");
using type = std::tuple_element_t<I, std::tuple<As...>>;
};
};

template<class F>
using equivalent_function_type = typename function_info<F>::equivalent_function_type;

template<class Function>
inline auto FuncPtrCast(Function f) noexcept {
return static_cast<equivalent_function_type<Function>*>(f);
}

}
4 changes: 2 additions & 2 deletions source/base/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ void* File::Map(size_t offset, size_t size) {
}
#if HAS_UNIX_FD
int prot{0};
if ((open_mode & FileAccessMode::Read) != FileAccessMode::None) {
if (True(open_mode & FileAccessMode::Read)) {
prot |= PROT_READ;
}
if ((open_mode & FileAccessMode::Write) != FileAccessMode::None) {
if (True(open_mode & FileAccessMode::Write)) {
prot |= PROT_WRITE;
}
auto res = mmap(nullptr, size, prot, MAP_SHARED, fileno(file), offset);
Expand Down
3 changes: 2 additions & 1 deletion source/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(slang)
add_subdirectory(slang)
add_subdirectory(clang)
12 changes: 12 additions & 0 deletions source/compiler/clang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
antlr4_gen(${CMAKE_CURRENT_SOURCE_DIR}/antlr ${CMAKE_CURRENT_BINARY_DIR}/antlr)
file(GLOB G4_DEFS ${CMAKE_CURRENT_BINARY_DIR}/antlr/*.h)
file(GLOB G4_SRCS ${CMAKE_CURRENT_BINARY_DIR}/antlr/*.cpp)

add_library(clang_compiler STATIC
${G4_SRCS}
${G4_DEFS}
clang.cpp
clang.h)

target_link_libraries(clang_compiler PUBLIC swift::base antlr4_static)
target_include_directories(clang_compiler PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/antlr)
Loading

0 comments on commit 4b95372

Please sign in to comment.