<commit_before>cmake_minimum_required(VERSION 2.8)
project(wasmint)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${wasmint_SOURCE_DIR}/cmake")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_subdirectory(wasm-module)

###########################
#       Plugins           #
###########################

####################
#       SDL        #
####################

find_package(SDL2)
find_package(SDL2_Image)

if (SDL2_FOUND AND SDL2_IMAGE_FOUND)
    include_directories(${SDL2_INCLUDE_DIR})
    add_definitions(-DWASMINT_HAS_SDL)
endif()


###########################
#      Common code        #
###########################

include_directories(wasm-module/src)
include_directories (libwasmint)

add_library(libwasmint
    libwasmint/builtins/SpectestModule.cpp
    libwasmint/builtins/StdioModule.cpp
    libwasmint/builtins/SDLModule.cpp

    libwasmint/interpreter/at/thread/InterpreterThread.cpp
    libwasmint/interpreter/at/thread/FunctionState.cpp
    libwasmint/interpreter/at/thread/InstructionState.cpp
    libwasmint/interpreter/at/thread/ThreadMultiPatch.cpp
    libwasmint/interpreter/at/thread/StepResult.cpp
    libwasmint/interpreter/at/MachineState.cpp
    libwasmint/interpreter/at/InstructionExecutor.cpp

    libwasmint/interpreter/debugging/BreakpointEnvironment.cpp
    libwasmint/interpreter/debugging/Breakpoint.cpp
    libwasmint/interpreter/debugging/BreakpointHandler.cpp

    libwasmint/interpreter/heap/Heap.cpp
    libwasmint/interpreter/heap/patch/HeapPatch.cpp
    libwasmint/interpreter/heap/HeapObserver.cpp
    libwasmint/interpreter/heap/Interval.cpp
    libwasmint/interpreter/heap/patch/HeapPatchChunk.cpp

    libwasmint/interpreter/RegisterAllocator.cpp
    libwasmint/interpreter/ByteOpcodes.h
    libwasmint/interpreter/JITCompiler.cpp
    libwasmint/interpreter/ByteCode.cpp
    libwasmint/interpreter/VMThread.cpp
    libwasmint/interpreter/FunctionFrame.cpp
    libwasmint/interpreter/VMState.cpp
    libwasmint/interpreter/CompiledFunction.cpp
    libwasmint/interpreter/InstructionCounter.cpp
    libwasmint/interpreter/History.cpp
    libwasmint/interpreter/MachinePatch.cpp
    libwasmint/interpreter/WasmintVM.cpp
    libwasmint/interpreter/WasmintVMTester.cpp
    libwasmint/interpreter/ThreadPatch.cpp

    libwasmint/serialization/ByteOutputStream.cpp
    libwasmint/serialization/ByteInputStream.cpp
        libwasmint/interpreter/halting/HaltingProblemDetector.cpp libwasmint/interpreter/halting/HaltingProblemDetector.h libwasmint/builtins/RandomModule.cpp libwasmint/builtins/RandomModule.h)


###########################
#      Interpreter        #
###########################

add_executable(wasmint main.cpp)
target_link_libraries(wasmint libwasmint wasm-module)

if (SDL2_FOUND AND SDL2_IMAGE_FOUND)
    target_link_libraries(wasmint ${SDL2_LIBRARY}
                                  ${SDL2_IMAGE_LIBRARIES})
endif()

###########################
#        Tests            #
###########################
enable_testing()

option(wasmintCoverage "Enable coverage analysis with lcov" OFF)

if(wasmintCoverage)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs")
    configure_file(generateCoverage.template.sh generateCoverage.sh NEWLINE_STYLE UNIX)
endif()

option(wasmintUBSAN "Enable undefined behaviour sanitizer" OFF)

if(wasmintUBSAN)
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        # all flags beside -fsanitize=float-divide-by-zero which is defined behaviour and will happen during normal execution
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=alignment -fsanitize=bool -fsanitize=bounds -fsanitize=enum -fsanitize=float-cast-overflow -fsanitize=function -fsanitize=integer-divide-by-zero -fsanitize=nonnull-attribute -fsanitize=null -fsanitize=object-size -fsanitize=return -fsanitize=returns-nonnull-attribute -fsanitize=shift -fsanitize=signed-integer-overflow -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=vptr")
    else()
        # TODO wrong report for latest GCC. Check for GCC >= 4.9 here
        message(WARNING "Compiler doesn't support UBSAN")
    endif()
endif()

####################
#    Unit tests    #
####################

file(GLOB_RECURSE TEST_FILES "libwasmint/tests/*Test.cpp")
foreach(TEST_FILE ${TEST_FILES})
  file(RELATIVE_PATH BASENAME ${CMAKE_SOURCE_DIR}/libwasmint/tests/ ${TEST_FILE})
  STRING(REGEX REPLACE "/" "_" BASENAME ${BASENAME})
  STRING(REGEX REPLACE "\\\\" "_" BASENAME ${BASENAME})
  STRING(REGEX REPLACE ".cpp" "" BASENAME ${BASENAME})

  add_executable(${BASENAME} ${TEST_FILE})
  target_link_libraries(${BASENAME} libwasmint wasm-module)
  add_test(${BASENAME} ${BASENAME})
endforeach()

####################
#  Test programs   #
####################<commit_msg>Readded  -fno-sanitize-recover that test will fail due to UBSAN<commit_after>cmake_minimum_required(VERSION 2.8)
project(wasmint)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${wasmint_SOURCE_DIR}/cmake")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_subdirectory(wasm-module)

###########################
#       Plugins           #
###########################

####################
#       SDL        #
####################

find_package(SDL2)
find_package(SDL2_Image)

if (SDL2_FOUND AND SDL2_IMAGE_FOUND)
    include_directories(${SDL2_INCLUDE_DIR})
    add_definitions(-DWASMINT_HAS_SDL)
endif()


###########################
#      Common code        #
###########################

include_directories(wasm-module/src)
include_directories (libwasmint)

add_library(libwasmint
    libwasmint/builtins/SpectestModule.cpp
    libwasmint/builtins/StdioModule.cpp
    libwasmint/builtins/SDLModule.cpp

    libwasmint/interpreter/at/thread/InterpreterThread.cpp
    libwasmint/interpreter/at/thread/FunctionState.cpp
    libwasmint/interpreter/at/thread/InstructionState.cpp
    libwasmint/interpreter/at/thread/ThreadMultiPatch.cpp
    libwasmint/interpreter/at/thread/StepResult.cpp
    libwasmint/interpreter/at/MachineState.cpp
    libwasmint/interpreter/at/InstructionExecutor.cpp

    libwasmint/interpreter/debugging/BreakpointEnvironment.cpp
    libwasmint/interpreter/debugging/Breakpoint.cpp
    libwasmint/interpreter/debugging/BreakpointHandler.cpp

    libwasmint/interpreter/heap/Heap.cpp
    libwasmint/interpreter/heap/patch/HeapPatch.cpp
    libwasmint/interpreter/heap/HeapObserver.cpp
    libwasmint/interpreter/heap/Interval.cpp
    libwasmint/interpreter/heap/patch/HeapPatchChunk.cpp

    libwasmint/interpreter/RegisterAllocator.cpp
    libwasmint/interpreter/ByteOpcodes.h
    libwasmint/interpreter/JITCompiler.cpp
    libwasmint/interpreter/ByteCode.cpp
    libwasmint/interpreter/VMThread.cpp
    libwasmint/interpreter/FunctionFrame.cpp
    libwasmint/interpreter/VMState.cpp
    libwasmint/interpreter/CompiledFunction.cpp
    libwasmint/interpreter/InstructionCounter.cpp
    libwasmint/interpreter/History.cpp
    libwasmint/interpreter/MachinePatch.cpp
    libwasmint/interpreter/WasmintVM.cpp
    libwasmint/interpreter/WasmintVMTester.cpp
    libwasmint/interpreter/ThreadPatch.cpp

    libwasmint/serialization/ByteOutputStream.cpp
    libwasmint/serialization/ByteInputStream.cpp
        libwasmint/interpreter/halting/HaltingProblemDetector.cpp libwasmint/interpreter/halting/HaltingProblemDetector.h libwasmint/builtins/RandomModule.cpp libwasmint/builtins/RandomModule.h)


###########################
#      Interpreter        #
###########################

add_executable(wasmint main.cpp)
target_link_libraries(wasmint libwasmint wasm-module)

if (SDL2_FOUND AND SDL2_IMAGE_FOUND)
    target_link_libraries(wasmint ${SDL2_LIBRARY}
                                  ${SDL2_IMAGE_LIBRARIES})
endif()

###########################
#        Tests            #
###########################
enable_testing()

option(wasmintCoverage "Enable coverage analysis with lcov" OFF)

if(wasmintCoverage)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs")
    configure_file(generateCoverage.template.sh generateCoverage.sh NEWLINE_STYLE UNIX)
endif()

option(wasmintUBSAN "Enable undefined behaviour sanitizer" OFF)

if(wasmintUBSAN)
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        # all flags beside -fsanitize=float-divide-by-zero which is defined behaviour and will happen during normal execution
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover -fsanitize=alignment -fsanitize=bool -fsanitize=bounds -fsanitize=enum -fsanitize=float-cast-overflow -fsanitize=function -fsanitize=integer-divide-by-zero -fsanitize=nonnull-attribute -fsanitize=null -fsanitize=object-size -fsanitize=return -fsanitize=returns-nonnull-attribute -fsanitize=shift -fsanitize=signed-integer-overflow -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=vptr")
    else()
        # TODO wrong report for latest GCC. Check for GCC >= 4.9 here
        message(WARNING "Compiler doesn't support UBSAN")
    endif()
endif()

####################
#    Unit tests    #
####################

file(GLOB_RECURSE TEST_FILES "libwasmint/tests/*Test.cpp")
foreach(TEST_FILE ${TEST_FILES})
  file(RELATIVE_PATH BASENAME ${CMAKE_SOURCE_DIR}/libwasmint/tests/ ${TEST_FILE})
  STRING(REGEX REPLACE "/" "_" BASENAME ${BASENAME})
  STRING(REGEX REPLACE "\\\\" "_" BASENAME ${BASENAME})
  STRING(REGEX REPLACE ".cpp" "" BASENAME ${BASENAME})

  add_executable(${BASENAME} ${TEST_FILE})
  target_link_libraries(${BASENAME} libwasmint wasm-module)
  add_test(${BASENAME} ${BASENAME})
endforeach()

####################
#  Test programs   #
####################
{'fraction_non_alphanumeric': 0.15969024696525744, 'fraction_numerical': 0.0031393888656341567, 'mean_word_length': 4.9323401613904405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3459669', 'n_tokens_mistral': 3284, 'n_tokens_neox': 3233, 'n_words': 399}