Skip to content

(Placeholder) SLJIT support #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"

# [Optional] Uncomment this section to install additional packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends clangd shellcheck tcc \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
60 changes: 60 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "QuickJS-ng Devcontainer",
"build": {
"dockerfile": "Dockerfile"
},

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
"postCreateCommand": "git submodule update --init",

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"settings": {
"workbench.colorTheme": "Visual Studio Dark - C++",
"workbench.preferredDarkColorTheme": "Visual Studio Dark - C++",
"workbench.preferredHighContrastColorTheme": "Default High Contrast",
"workbench.preferredLightColorTheme": "Visual Studio Light - C++",
"window.autoDetectColorScheme": true,
"[cpp]": {
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.formatOnSave": true
}
},
"extensions": [
"bierner.markdown-preview-github-styles",
"cheshirekow.cmake-format",
"davidanson.vscode-markdownlint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"franneck94.vscode-c-cpp-dev-extension-pack",
"fredericbonnet.cmake-test-adapter",
"hbenl.vscode-test-explorer",
"josetr.cmake-language-support-vscode",
"llvm-vs-code-extensions.vscode-clangd",
"matepek.vscode-catch2-test-adapter",
"mhutchie.git-graph",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools-themes",
"ms-vscode.cpptools",
"ms-vscode.remote-explorer",
"ms-vscode.test-adapter-converter",
"redhat.vscode-yaml",
"solomonkinard.workspace-include-what-you-use",
"sr-team.vscode-clangd-cmake",
"streetsidesoftware.code-spell-checker",
"timonwong.shellcheck",
"vadimcn.vscode-lldb",
"xaver.clang-format"
]
}
}
}
59 changes: 59 additions & 0 deletions .devcontainer/reinstall-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e

CMAKE_VERSION=${1:-"none"}

if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi

# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT


echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)

echo "${TMP_DIR}"
cd "${TMP_DIR}"

curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O

sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license

ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ CMakeUserPresets.json
fuzz
.vscode/
microbench*.txt
.cache/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
url = https://github.com/tc39/test262
shallow = true
update = none
[submodule "sljit"]
path = sljit
url = https://github.com/zherczeg/sljit
[submodule "zydis"]
path = zydis
url = https://github.com/zyantific/zydis
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ xoption(QJS_ENABLE_ASAN "Enable AddressSanitizer (ASan)" OFF)
xoption(QJS_ENABLE_MSAN "Enable MemorySanitizer (MSan)" OFF)
xoption(QJS_ENABLE_TSAN "Enable ThreadSanitizer (TSan)" OFF)
xoption(QJS_ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
xoption(QJS_ENABLE_SLJIT "Enable sljit" ON)

if(QJS_ENABLE_ASAN)
message(STATUS "Building with ASan")
Expand Down Expand Up @@ -279,6 +280,39 @@ if(EMSCRIPTEN)
target_link_libraries(qjs_wasm m)
endif()

if (QJS_ENABLE_SLJIT)

if(CMAKE_BUILD_TYPE MATCHES "Debug")
xoption(QJS_SLJIT_DEBUG "sljit debug mode" ON)
xoption(QJS_SLJIT_VERBOSE "sljit verbose mode" ON)
else()
xoption(QJS_SLJIT_DEBUG "sljit debug mode" OFF)
xoption(QJS_SLJIT_VERBOSE "sljit verbose mode" OFF)
endif()

file(GLOB SLJIT_SRC
${CMAKE_CURRENT_SOURCE_DIR}/sljit/sljit_src/sljitLir.c
)

add_library(sljit ${SLJIT_SRC})
target_include_directories(sljit PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sljit/sljit_src>
$<INSTALL_INTERFACE:sljit/sljit_src>
)
target_link_libraries(qjs PRIVATE sljit)

if (QJS_SLJIT_DEBUG)
target_compile_definitions(sljit PUBLIC SLJIT_DEBUG=1)
endif()

if (QJS_SLJIT_VERBOSE)
target_compile_definitions(sljit PUBLIC SLJIT_VERBOSE=1)
add_subdirectory(zydis)
target_link_libraries(qjs PRIVATE Zydis::Zydis)
target_compile_options(Zycore PRIVATE -Wno-format-nonliteral)
endif()

endif()

# QuickJS bytecode compiler
#
Expand Down Expand Up @@ -441,4 +475,11 @@ if(NOT IOS)
install(EXPORT qjsConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/quickjs)
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(DIRECTORY examples DESTINATION ${CMAKE_INSTALL_DOCDIR})

if(QJS_ENABLE_SLJIT)
install(TARGETS sljit EXPORT qjsConfig
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()
Loading