Skip to content

Commit

Permalink
implement simple libdyntype (#106)
Browse files Browse the repository at this point in the history
* implement simple libdyntype
* pass validation tests for simple libdyntype

---------

Signed-off-by: Xu Jun <[email protected]>
  • Loading branch information
xujuntwt95329 authored Dec 18, 2023
1 parent 12f6345 commit 8b0998d
Show file tree
Hide file tree
Showing 29 changed files with 1,837 additions and 89 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ts2wasm_aot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
target: [
"X86_64", "X86_32"
]
simple_libdyntype: [
1, 0
]
# node-version: [10.x, 12.x, 14.x, 15.x, 16.x]
# Test the latest version of Node.js plus the last two LTS versions.
# node-version:
Expand Down Expand Up @@ -99,10 +102,10 @@ jobs:
- name: Build runtime
run: |
mkdir build && cd build
cmake .. -DWAMR_BUILD_TARGET=${{ matrix.target }} -DWAMR_GC_IN_EVERY_ALLOCATION=1 -DUSE_SANITIZER=1 && make -j$(nproc)
cmake .. -DWAMR_BUILD_TARGET=${{ matrix.target }} -DUSE_SIMPLE_LIBDYNTYPE=${{ matrix.simple_libdyntype }} -DWAMR_GC_IN_EVERY_ALLOCATION=1 -DUSE_SANITIZER=1 && make -j$(nproc)
working-directory: runtime-library/

- name: Validate execution
run:
AOT=1 TARGET_ARCH=${{ matrix.target }} npm start
SIMPLE_LIBDYNTYPE=${{ matrix.simple_libdyntype }} AOT=1 TARGET_ARCH=${{ matrix.target }} npm start
working-directory: tools/validate/wamr
7 changes: 5 additions & 2 deletions .github/workflows/ts2wasm_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ jobs:
target: [
"X86_64", "X86_32"
]
simple_libdyntype: [
1, 0
]

steps:
- uses: actions/checkout@v3
Expand All @@ -95,10 +98,10 @@ jobs:
- name: Build runtime
run: |
mkdir build && cd build
cmake .. -DWAMR_BUILD_TARGET=${{ matrix.target }} -DWAMR_GC_IN_EVERY_ALLOCATION=1 -DUSE_SANITIZER=1 && make -j$(nproc)
cmake .. -DWAMR_BUILD_TARGET=${{ matrix.target }} -DUSE_SIMPLE_LIBDYNTYPE=${{ matrix.simple_libdyntype }} -DWAMR_GC_IN_EVERY_ALLOCATION=1 -DUSE_SANITIZER=1 && make -j$(nproc)
working-directory: runtime-library/

- name: Validate execution
run:
npm start
SIMPLE_LIBDYNTYPE=${{ matrix.simple_libdyntype }} npm start
working-directory: tools/validate/wamr
37 changes: 22 additions & 15 deletions runtime-library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()

if (NOT DEFINED USE_SIMPLE_LIBDYNTYPE)
set(USE_SIMPLE_LIBDYNTYPE 0)
endif ()

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -ffunction-sections -Wall -Werror -Wformat")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")

Expand All @@ -31,15 +35,24 @@ include(${CMAKE_CURRENT_LIST_DIR}/wamr_config.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})

## quickjs
set(QUICKJS_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/quickjs)

include_directories(${QUICKJS_SRC_DIR})

set(QUICKJS_SOURCE
${QUICKJS_SRC_DIR}/cutils.c
${QUICKJS_SRC_DIR}/libregexp.c
${QUICKJS_SRC_DIR}/libunicode.c
${QUICKJS_SRC_DIR}/quickjs.c)
if (NOT USE_SIMPLE_LIBDYNTYPE EQUAL 1)
set(QUICKJS_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/quickjs)

include_directories(${QUICKJS_SRC_DIR})

set(QUICKJS_SOURCE
${QUICKJS_SRC_DIR}/cutils.c
${QUICKJS_SRC_DIR}/libregexp.c
${QUICKJS_SRC_DIR}/libunicode.c
${QUICKJS_SRC_DIR}/quickjs.c)

# Ignore warnings of QuickJS
set_source_files_properties(
${QUICKJS_SOURCE}
PROPERTIES
COMPILE_FLAGS "-w"
)
endif ()

## libdyntype
set(LIBDYNTYPE_DIR ${CMAKE_CURRENT_LIST_DIR}/libdyntype)
Expand Down Expand Up @@ -81,12 +94,6 @@ set(OBJECT_UTILS_SOURCE
set(WAMR_UTILS_SOURCE
${UTILS_DIR}/wamr_utils.c
)
# Ignore warnings of QuickJS
set_source_files_properties(
${QUICKJS_SOURCE}
PROPERTIES
COMPILE_FLAGS "-w"
)

include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
add_executable(iwasm_gc main.c
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions runtime-library/libdyntype/dynamic-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# libdyntype with simple implementation

This folder provides a simplified implementation of libdyntype without dependency to QuickJS, this may be useful especially on some resource constraint devices.

> Note: this simple implementation of libdyntype doesn't support these features:
> - Use JavaScript builtin object and their methods (such as JSON, JSON.stringify, Map, Map.prototype.get ...)
> - prototype
> - string encoding (all strings are stored as raw binary buffer without any encoding)
34 changes: 34 additions & 0 deletions runtime-library/libdyntype/dynamic-simple/context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "pure_dynamic.h"

/* We don't need a context for simple libdyntype implementation, but we return a
* non-zero value to make the system work */
static dyn_ctx_t g_dynamic_context = (dyn_ctx_t)(uintptr_t)0xffff;

/******************* Initialization and destroy *****************/

dyn_ctx_t
dynamic_context_init()
{
return g_dynamic_context;
}

dyn_ctx_t
dynamic_context_init_with_opt(dyn_options_t *options)
{
return g_dynamic_context;
}

void
dynamic_context_destroy(dyn_ctx_t ctx)
{}

dyn_ctx_t
dynamic_get_context()
{
return g_dynamic_context;
}
Loading

0 comments on commit 8b0998d

Please sign in to comment.