Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #147 from seq-lang/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
arshajii authored Aug 9, 2020
2 parents 9591b0d + 5fe65d0 commit 4ba42e5
Show file tree
Hide file tree
Showing 15 changed files with 1,168 additions and 1,005 deletions.
71 changes: 37 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.9)
project(Seq)

set(CMAKE_CXX_STANDARD 14)
Expand All @@ -19,21 +19,23 @@ find_package(Threads REQUIRED)
option(SEQ_THREADED "compile runtime library for multithreading" OFF)
option(SEQ_JITBRIDGE "support JIT interoperability" OFF)
find_package(ZLIB REQUIRED)

include(ExternalProject)
ExternalProject_Add(bdwgc
URL https://github.com/ivmai/bdwgc/releases/download/v8.0.4/gc-8.0.4.tar.gz
SOURCE_DIR ${CMAKE_BINARY_DIR}/bdwgc
CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/bdwgc/configure CFLAGS=-fPIC --enable-threads=posix --enable-cplusplus --enable-thread-local-alloc --enable-large-config --prefix=${CMAKE_BINARY_DIR}/bdwgc/build
BUILD_COMMAND make CFLAGS=-DHANDLE_FORK LDFLAGS=-static
CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/bdwgc/configure
CFLAGS=-fPIC
--enable-threads=posix
--enable-cplusplus
--enable-large-config
--enable-thread-local-alloc
--prefix=${CMAKE_BINARY_DIR}/bdwgc/build
BUILD_COMMAND $(MAKE) LDFLAGS=-static COMMAND $(MAKE) check
BUILD_IN_SOURCE ON
INSTALL_DIR ${CMAKE_BINARY_DIR}/bdwgc/build
INSTALL_COMMAND make install
LOG_DOWNLOAD ON
# LOG_CONFIGURE ON
# LOG_BUILD ON
# LOG_INSTALL ON
)
INSTALL_COMMAND $(MAKE) install
LOG_DOWNLOAD ON)
# --enable-handle-fork=yes --disable-shared --enable-static
ExternalProject_Get_Property(bdwgc install_dir)
set(BDWGC_DIR ${install_dir})

Expand All @@ -47,28 +49,35 @@ set(SEQRT_FILES runtime/lib.h
runtime/sw/ksw2_gg2_sse.cpp
runtime/sw/intersw.h
runtime/sw/intersw.cpp)
add_library(seqrt OBJECT ${SEQRT_FILES})
add_library(seqrt SHARED ${SEQRT_FILES})
add_dependencies(seqrt bdwgc)
target_include_directories(seqrt PRIVATE runtime ${BDWGC_DIR}/include)
set_property(TARGET seqrt PROPERTY POSITION_INDEPENDENT_CODE 1)
target_include_directories(seqrt PRIVATE ${BDWGC_DIR}/include runtime)
target_link_libraries(seqrt PUBLIC ${ZLIB_LIBRARIES} ${BDWGC_DIR}/lib/libgc.a Threads::Threads)
set_source_files_properties(runtime/sw/intersw.cpp PROPERTIES COMPILE_FLAGS "-march=native")
if(SEQ_THREADED)
find_package(OpenMP REQUIRED)
target_link_libraries(seqrt PUBLIC OpenMP::OpenMP_CXX)
target_compile_definitions(seqrt PRIVATE THREADED=1)
else()
target_compile_definitions(seqrt PRIVATE THREADED=0)
endif()


add_library(seqrt_shared SHARED $<TARGET_OBJECTS:seqrt>)
add_dependencies(seqrt_shared bdwgc)
target_link_libraries(seqrt_shared PUBLIC ${ZLIB_LIBRARIES} ${BDWGC_DIR}/lib/libgc.a Threads::Threads)
if (SEQ_THREADED)
find_package(OpenMP REQUIRED)
target_link_libraries(seqrt_shared PUBLIC OpenMP::OpenMP_CXX)
add_library(seqrt_static_only STATIC ${SEQRT_FILES})
add_dependencies(seqrt_static_only bdwgc)
target_include_directories(seqrt_static_only PRIVATE ${BDWGC_DIR}/include runtime)
set_source_files_properties(runtime/sw/intersw.cpp PROPERTIES COMPILE_FLAGS "-march=native")
if(SEQ_THREADED)
target_compile_definitions(seqrt_static_only PRIVATE THREADED=1)
else()
target_compile_definitions(seqrt_static_only PRIVATE THREADED=0)
endif()
add_library(seqrt_static STATIC $<TARGET_OBJECTS:seqrt>)
add_dependencies(seqrt_static bdwgc)
target_link_libraries(seqrt_static ${BDWGC_DIR}/lib/libgc.a)
set(SEQRT_STATIC ${CMAKE_BINARY_DIR}/libseqrt_static.a)
add_custom_target(seqrt_static
COMMAND ar -x $<TARGET_FILE:seqrt_static_only>
COMMAND ar -x ${BDWGC_DIR}/lib/libgc.a
COMMAND ar -qcs ${SEQRT_STATIC} *.o
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS seqrt_static_only)

# Seq parsing library
execute_process(COMMAND ocamlc -where
Expand All @@ -85,12 +94,10 @@ ExternalProject_Add(menhir
URL https://gitlab.inria.fr/fpottier/menhir/-/archive/20190924/menhir-20190924.tar.gz
SOURCE_DIR ${CMAKE_BINARY_DIR}/menhir
CONFIGURE_COMMAND ""
BUILD_COMMAND make -C src -j
BUILD_COMMAND $(MAKE) -C src -j
BUILD_IN_SOURCE ON
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
# LOG_BUILD ON
)
LOG_DOWNLOAD ON)
ExternalProject_Get_Property(menhir SOURCE_DIR)
set(MENHIR ${SOURCE_DIR}/src/_stage1/menhir.native)
set(MENHIR_LIB ${SOURCE_DIR}/src/_stage1)
Expand All @@ -100,10 +107,7 @@ ExternalProject_Add(seqparse_target
CONFIGURE_COMMAND cp -r ${CMAKE_SOURCE_DIR}/compiler/parser/ocaml ${CMAKE_BINARY_DIR}/seqparse
BINARY_DIR ${CMAKE_BINARY_DIR}/seqparse
BUILD_COMMAND make -C ocaml MENHIR=${MENHIR} MENHIR_LIB=${MENHIR_LIB}
INSTALL_COMMAND ""
# LOG_DOWNLOAD ON
# LOG_BUILD ON
)
INSTALL_COMMAND "")
ExternalProject_Get_Property(seqparse_target BINARY_DIR)
set(LIB_SEQPARSE ${BINARY_DIR}/ocaml/seqparser.o)
add_dependencies(seqparse_target menhir)
Expand Down Expand Up @@ -131,12 +135,11 @@ file(GLOB SEQ_CPPFILES compiler/lang/*.cpp
compiler/parser/ast/format/*.cpp
compiler/util/*.cpp
compiler/util/fmt/*.cpp)

add_library(seq SHARED ${SEQ_HPPFILES})
add_dependencies(seq seqparse_target)
add_dependencies(seq seqparse_target seqrt_static)
target_sources(seq PRIVATE ${LIB_SEQPARSE} ${SEQ_CPPFILES})
llvm_map_components_to_libnames(LLVM_LIBS support core passes irreader x86asmparser x86info x86codegen mcjit orcjit ipo coroutines)
target_link_libraries(seq ${LLVM_LIBS} seqrt_shared dl)
target_link_libraries(seq ${LLVM_LIBS} seqrt dl)

if(SEQ_JITBRIDGE)
add_library(seqjit SHARED compiler/util/jit.cpp)
Expand Down
2 changes: 1 addition & 1 deletion compiler/lang/seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#define SEQ_VERSION_MAJOR 0
#define SEQ_VERSION_MINOR 9
#define SEQ_VERSION_PATCH 8
#define SEQ_VERSION_PATCH 9

namespace seq {
namespace config {
Expand Down
70 changes: 41 additions & 29 deletions compiler/util/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#ifndef FMT_CHRONO_H_
#define FMT_CHRONO_H_

#include "format.h"
#include "locale.h"

#include <chrono>
#include <ctime>
#include <locale>
#include <sstream>

#include "format.h"
#include "locale.h"

FMT_BEGIN_NAMESPACE

// Enable safe chrono durations, unless explicitly disabled.
Expand Down Expand Up @@ -503,12 +503,12 @@ parse_chrono_format(const Char *begin, const Char *end, Handler &&handler) {
handler.on_text(ptr - 1, ptr);
break;
case 'n': {
const char newline[] = "\n";
const Char newline[] = {'\n'};
handler.on_text(newline, newline + 1);
break;
}
case 't': {
const char tab[] = "\t";
const Char tab[] = {'\t'};
handler.on_text(tab, tab + 1);
break;
}
Expand Down Expand Up @@ -771,21 +771,32 @@ get_milliseconds(std::chrono::duration<Rep, Period> d) {
return std::chrono::duration<Rep, std::milli>(static_cast<Rep>(ms));
}

template <typename Rep, typename OutputIt>
OutputIt format_chrono_duration_value(OutputIt out, Rep val, int precision) {
template <typename Char, typename Rep, typename OutputIt>
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
const Char pr_f[] = {'{', ':', '.', '{', '}', 'f', '}', 0};
if (precision >= 0)
return format_to(out, "{:.{}f}", val, precision);
return format_to(out, std::is_floating_point<Rep>::value ? "{:g}" : "{}",
return format_to(out, pr_f, val, precision);
const Char fp_f[] = {'{', ':', 'g', '}', 0};
const Char format[] = {'{', '}', 0};
return format_to(out, std::is_floating_point<Rep>::value ? fp_f : format,
val);
}

template <typename Period, typename OutputIt>
static OutputIt format_chrono_duration_unit(OutputIt out) {
if (const char *unit = get_units<Period>())
return format_to(out, "{}", unit);
template <typename Char, typename Period, typename OutputIt>
OutputIt format_duration_unit(OutputIt out) {
if (const char *unit = get_units<Period>()) {
string_view s(unit);
if (const_check(std::is_same<Char, wchar_t>())) {
utf8_to_utf16 u(s);
return std::copy(u.c_str(), u.c_str() + u.size(), out);
}
return std::copy(s.begin(), s.end(), out);
}
const Char num_f[] = {'[', '{', '}', ']', 's', 0};
if (Period::den == 1)
return format_to(out, "[{}]s", Period::num);
return format_to(out, "[{}/{}]s", Period::num, Period::den);
return format_to(out, num_f, Period::num);
const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};
return format_to(out, num_def_f, Period::num, Period::den);
}

template <typename FormatContext, typename OutputIt, typename Rep,
Expand Down Expand Up @@ -886,14 +897,14 @@ struct chrono_formatter {
void write_pinf() { std::copy_n("inf", 3, out); }
void write_ninf() { std::copy_n("-inf", 4, out); }

void format_localized(const tm &time, const char *format) {
void format_localized(const tm &time, char format, char modifier = 0) {
if (isnan(val))
return write_nan();
auto locale = context.locale().template get<std::locale>();
auto &facet = std::use_facet<std::time_put<char_type>>(locale);
std::basic_ostringstream<char_type> os;
os.imbue(locale);
facet.put(os, os, ' ', &time, format, format + std::strlen(format));
facet.put(os, os, ' ', &time, format, modifier);
auto str = os.str();
std::copy(str.begin(), str.end(), out);
}
Expand Down Expand Up @@ -925,7 +936,7 @@ struct chrono_formatter {
return write(hour(), 2);
auto time = tm();
time.tm_hour = to_nonnegative_int(hour(), 24);
format_localized(time, "%OH");
format_localized(time, 'H', 'O');
}

void on_12_hour(numeric_system ns) {
Expand All @@ -936,7 +947,7 @@ struct chrono_formatter {
return write(hour12(), 2);
auto time = tm();
time.tm_hour = to_nonnegative_int(hour12(), 12);
format_localized(time, "%OI");
format_localized(time, 'I', 'O');
}

void on_minute(numeric_system ns) {
Expand All @@ -947,7 +958,7 @@ struct chrono_formatter {
return write(minute(), 2);
auto time = tm();
time.tm_min = to_nonnegative_int(minute(), 60);
format_localized(time, "%OM");
format_localized(time, 'M', 'O');
}

void on_second(numeric_system ns) {
Expand All @@ -973,14 +984,13 @@ struct chrono_formatter {
}
auto time = tm();
time.tm_sec = to_nonnegative_int(second(), 60);
format_localized(time, "%OS");
format_localized(time, 'S', 'O');
}

void on_12_hour_time() {
if (handle_nan_inf())
return;

format_localized(time(), "%r");
format_localized(time(), 'r');
}

void on_24_hour_time() {
Expand All @@ -1006,17 +1016,19 @@ struct chrono_formatter {
void on_am_pm() {
if (handle_nan_inf())
return;
format_localized(time(), "%p");
format_localized(time(), 'p');
}

void on_duration_value() {
if (handle_nan_inf())
return;
write_sign();
out = format_chrono_duration_value(out, val, precision);
out = format_duration_value<char_type>(out, val, precision);
}

void on_duration_unit() { out = format_chrono_duration_unit<Period>(out); }
void on_duration_unit() {
out = format_duration_unit<char_type, Period>(out);
}
};
} // namespace internal

Expand Down Expand Up @@ -1051,7 +1063,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
}

void on_error(const char *msg) { FMT_THROW(format_error(msg)); }
void on_fill(Char fill) { f.specs.fill[0] = fill; }
void on_fill(basic_string_view<Char> fill) { f.specs.fill = fill; }
void on_align(align_t align) { f.specs.align = align; }
void on_width(int width) { f.specs.width = width; }
void on_precision(int _precision) { f.precision = _precision; }
Expand Down Expand Up @@ -1118,8 +1130,8 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
internal::handle_dynamic_spec<internal::precision_checker>(
precision, precision_ref, ctx);
if (begin == end || *begin == '}') {
out = internal::format_chrono_duration_value(out, d.count(), precision);
internal::format_chrono_duration_unit<Period>(out);
out = internal::format_duration_value<Char>(out, d.count(), precision);
internal::format_duration_unit<Char, Period>(out);
} else {
internal::chrono_formatter<FormatContext, decltype(out), Rep, Period> f(
ctx, out, d);
Expand Down
11 changes: 5 additions & 6 deletions compiler/util/fmt/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ template <typename Char> struct ansi_color_escape {

FMT_CONSTEXPR const Char *begin() const FMT_NOEXCEPT { return buffer; }
FMT_CONSTEXPR const Char *end() const FMT_NOEXCEPT {
return buffer + std::strlen(buffer);
return buffer + std::char_traits<Char>::length(buffer);
}

private:
Expand Down Expand Up @@ -495,10 +495,9 @@ void vformat_to(basic_memory_buffer<Char> &buf, const text_style &ts,
internal::make_background_color<Char>(ts.get_background());
buf.append(background.begin(), background.end());
}
vformat_to(buf, format_str, args);
if (has_style) {
internal::vformat_to(buf, format_str, args);
if (has_style)
internal::reset_color<Char>(buf);
}
}
} // namespace internal

Expand Down Expand Up @@ -544,7 +543,7 @@ void print(const text_style &ts, const S &format_str, const Args &... args) {
template <typename S, typename Char = char_t<S>>
inline std::basic_string<Char>
vformat(const text_style &ts, const S &format_str,
basic_format_args<buffer_context<Char>> args) {
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
basic_memory_buffer<Char> buf;
internal::vformat_to(buf, ts, to_string_view(format_str), args);
return fmt::to_string(buf);
Expand All @@ -566,7 +565,7 @@ template <typename S, typename... Args, typename Char = char_t<S>>
inline std::basic_string<Char> format(const text_style &ts, const S &format_str,
const Args &... args) {
return vformat(ts, to_string_view(format_str),
{internal::make_args_checked<Args...>(format_str, args...)});
internal::make_args_checked<Args...>(format_str, args...));
}

FMT_END_NAMESPACE
Expand Down
Loading

0 comments on commit 4ba42e5

Please sign in to comment.