Skip to content
Merged
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
4 changes: 4 additions & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ if (WAMR_BUILD_GC EQUAL 1)
message(" GC testing enabled")
endif()
endif ()
if (WAMR_BUILD_GC_BINARYEN EQUAL 1)
add_definitions (-DWASM_ENABLE_GC_BINARYEN=1)
message (" GC binaryen compatible mode on")
endif ()
if (DEFINED WAMR_BH_VPRINTF)
add_definitions (-DBH_VPRINTF=${WAMR_BH_VPRINTF})
endif ()
Expand Down
4 changes: 4 additions & 0 deletions build-scripts/runtime_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ if (WAMR_BUILD_AOT EQUAL 1)
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
endif ()

if (WAMR_BUILD_GC_BINARYEN EQUAL 1)
set (WAMR_BUILD_GC 1)
endif ()

if (WAMR_BUILD_GC EQUAL 1)
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
# Enable the dependent feature if GC is enabled
Expand Down
5 changes: 5 additions & 0 deletions core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@
#define WASM_ENABLE_GC 0
#endif

/* GC binaryen compatible mode */
#ifndef WASM_ENABLE_GC_BINARYEN
#define WASM_ENABLE_GC_BINARYEN 0
#endif

#ifndef GC_REFTYPE_MAP_SIZE_DEFAULT
#define GC_REFTYPE_MAP_SIZE_DEFAULT 64
#endif
Expand Down
26 changes: 26 additions & 0 deletions core/iwasm/common/gc/gc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ wasm_array_obj_get_elem(WASMArrayObjectRef array_obj, uint32 elem_idx,
}
}

void
wasm_array_obj_copy(WASMArrayObjectRef dst_obj, uint32 dst_idx,
WASMArrayObjectRef src_obj, uint32 src_idx, uint32 len)
{
uint8 *dst_data = wasm_array_obj_elem_addr(dst_obj, dst_idx);
uint8 *src_data = wasm_array_obj_elem_addr(src_obj, src_idx);
uint32 elem_size = 1 << wasm_array_obj_elem_size_log(dst_obj);

bh_memmove_s(dst_data, elem_size * len, src_data, elem_size * len);
}

WASMFuncObjectRef
wasm_func_obj_new(void *heap_handle, WASMRttTypeRef rtt_type,
uint32 func_idx_bound)
Expand Down Expand Up @@ -311,6 +322,21 @@ wasm_externref_obj_new(WASMExecEnv *exec_env, void *heap_handle, void *host_obj)
return externref_obj;
}

WASMAnyrefObjectRef
wasm_anyref_obj_new(WASMExecEnv *exec_env, void *heap_handle, void *host_obj)
{
WASMAnyrefObjectRef anyref_obj;

if (!(anyref_obj = gc_obj_malloc(heap_handle, sizeof(WASMAnyrefObject)))) {
return NULL;
}

anyref_obj->header = WASM_OBJ_ANYREF_OBJ_FLAG;
anyref_obj->host_obj = host_obj;

return anyref_obj;
}

WASMObjectRef
wasm_externref_obj_to_internal_obj(WASMExternrefObjectRef externref_obj)
{
Expand Down
8 changes: 8 additions & 0 deletions core/iwasm/common/gc/gc_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ void
wasm_array_obj_get_elem(WASMArrayObjectRef array_obj, uint32 elem_idx,
bool sign_extend, WASMValue *value);

void
wasm_array_obj_copy(WASMArrayObjectRef dst_obj, uint32 dst_idx,
WASMArrayObjectRef src_obj, uint32 src_idx, uint32 len);

/**
* Return the logarithm of the size of array element.
*
Expand Down Expand Up @@ -218,6 +222,10 @@ WASMExternrefObjectRef
wasm_externref_obj_new(struct WASMExecEnv *exec_env, void *heap_handle,
void *host_obj);

WASMAnyrefObjectRef
wasm_anyref_obj_new(struct WASMExecEnv *exec_env, void *heap_handle,
void *host_obj);

/* Implementation of opcode extern.internalize */
WASMObjectRef
wasm_externref_obj_to_internal_obj(WASMExternrefObjectRef externref_obj);
Expand Down
5 changes: 3 additions & 2 deletions core/iwasm/common/gc/gc_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ wasm_is_reftype_supers_of_noextern(uint type)
static bool
wasm_type_is_supers_of(const WASMType *type1, const WASMType *type2)
{
uint32 i;
uint32 i, inherit_depth_diff;

if (type1 == type2)
return true;
Expand All @@ -802,7 +802,8 @@ wasm_type_is_supers_of(const WASMType *type1, const WASMType *type2)
&& type1->inherit_depth < type2->inherit_depth))
return false;

for (i = 0; i < type2->inherit_depth - type1->inherit_depth; i++) {
inherit_depth_diff = type2->inherit_depth - type1->inherit_depth;
for (i = 0; i < inherit_depth_diff; i++) {
type2 = type2->parent_type;
if (type2 == type1)
return true;
Expand Down
8 changes: 7 additions & 1 deletion core/iwasm/common/wasm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ compare_type_with_signautre(uint8 type, const char signature)
}

#if WASM_ENABLE_REF_TYPES != 0
if ('r' == signature && type == VALUE_TYPE_EXTERNREF)
if ('r' == signature
#if WASM_ENABLE_GC != 0
&& (type >= REF_TYPE_NULLREF && type <= REF_TYPE_FUNCREF)
#else
&& type == VALUE_TYPE_EXTERNREF
#endif
)
return true;
#endif

Expand Down
98 changes: 98 additions & 0 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3581,6 +3581,20 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
for (i = 0; i < func_type->param_count; i++) {
switch (func_type->types[i]) {
case VALUE_TYPE_I32:
#if WASM_ENABLE_GC != 0
case REF_TYPE_FUNCREF:
case REF_TYPE_EXTERNREF:
case REF_TYPE_ANYREF:
case REF_TYPE_EQREF:
case REF_TYPE_HT_NULLABLE:
case REF_TYPE_HT_NON_NULLABLE:
case REF_TYPE_I31REF:
case REF_TYPE_NULLFUNCREF:
case REF_TYPE_NULLEXTERNREF:
case REF_TYPE_STRUCTREF:
case REF_TYPE_ARRAYREF:
case REF_TYPE_NULLREF:
#endif
#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
case VALUE_TYPE_FUNCREF:
case VALUE_TYPE_EXTERNREF:
Expand Down Expand Up @@ -3725,6 +3739,20 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
for (i = 0; i < func_type->param_count; i++) {
switch (func_type->types[i]) {
case VALUE_TYPE_I32:
#if WASM_ENABLE_GC != 0
case REF_TYPE_FUNCREF:
case REF_TYPE_EXTERNREF:
case REF_TYPE_ANYREF:
case REF_TYPE_EQREF:
case REF_TYPE_HT_NULLABLE:
case REF_TYPE_HT_NON_NULLABLE:
case REF_TYPE_I31REF:
case REF_TYPE_NULLFUNCREF:
case REF_TYPE_NULLEXTERNREF:
case REF_TYPE_STRUCTREF:
case REF_TYPE_ARRAYREF:
case REF_TYPE_NULLREF:
#endif
#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
case VALUE_TYPE_FUNCREF:
#endif
Expand Down Expand Up @@ -3930,6 +3958,20 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
else {
switch (func_type->types[func_type->param_count]) {
case VALUE_TYPE_I32:
#if WASM_ENABLE_GC != 0
case REF_TYPE_FUNCREF:
case REF_TYPE_EXTERNREF:
case REF_TYPE_ANYREF:
case REF_TYPE_EQREF:
case REF_TYPE_HT_NULLABLE:
case REF_TYPE_HT_NON_NULLABLE:
case REF_TYPE_I31REF:
case REF_TYPE_NULLFUNCREF:
case REF_TYPE_NULLEXTERNREF:
case REF_TYPE_STRUCTREF:
case REF_TYPE_ARRAYREF:
case REF_TYPE_NULLREF:
#endif
#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
case VALUE_TYPE_FUNCREF:
#endif
Expand Down Expand Up @@ -4062,6 +4104,20 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
for (i = 0; i < func_type->param_count; i++) {
switch (func_type->types[i]) {
case VALUE_TYPE_I32:
#if WASM_ENABLE_GC != 0
case REF_TYPE_FUNCREF:
case REF_TYPE_EXTERNREF:
case REF_TYPE_ANYREF:
case REF_TYPE_EQREF:
case REF_TYPE_HT_NULLABLE:
case REF_TYPE_HT_NON_NULLABLE:
case REF_TYPE_I31REF:
case REF_TYPE_NULLFUNCREF:
case REF_TYPE_NULLEXTERNREF:
case REF_TYPE_STRUCTREF:
case REF_TYPE_ARRAYREF:
case REF_TYPE_NULLREF:
#endif
#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
case VALUE_TYPE_FUNCREF:
#endif
Expand Down Expand Up @@ -4148,6 +4204,20 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
else {
switch (func_type->types[func_type->param_count]) {
case VALUE_TYPE_I32:
#if WASM_ENABLE_GC != 0
case REF_TYPE_FUNCREF:
case REF_TYPE_EXTERNREF:
case REF_TYPE_ANYREF:
case REF_TYPE_EQREF:
case REF_TYPE_HT_NULLABLE:
case REF_TYPE_HT_NON_NULLABLE:
case REF_TYPE_I31REF:
case REF_TYPE_NULLFUNCREF:
case REF_TYPE_NULLEXTERNREF:
case REF_TYPE_STRUCTREF:
case REF_TYPE_ARRAYREF:
case REF_TYPE_NULLREF:
#endif
#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
case VALUE_TYPE_FUNCREF:
#endif
Expand Down Expand Up @@ -4387,6 +4457,20 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
break;
}
case VALUE_TYPE_I64:
#if WASM_ENABLE_GC != 0
case REF_TYPE_FUNCREF:
case REF_TYPE_EXTERNREF:
case REF_TYPE_ANYREF:
case REF_TYPE_EQREF:
case REF_TYPE_HT_NULLABLE:
case REF_TYPE_HT_NON_NULLABLE:
case REF_TYPE_I31REF:
case REF_TYPE_NULLFUNCREF:
case REF_TYPE_NULLEXTERNREF:
case REF_TYPE_STRUCTREF:
case REF_TYPE_ARRAYREF:
case REF_TYPE_NULLREF:
#endif
if (n_ints < MAX_REG_INTS)
ints[n_ints++] = *(uint64 *)argv_src;
else
Expand Down Expand Up @@ -4476,6 +4560,20 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
(uint32)invokeNative_Int32(func_ptr, argv1, n_stacks);
break;
case VALUE_TYPE_I64:
#if WASM_ENABLE_GC != 0
case REF_TYPE_FUNCREF:
case REF_TYPE_EXTERNREF:
case REF_TYPE_ANYREF:
case REF_TYPE_EQREF:
case REF_TYPE_HT_NULLABLE:
case REF_TYPE_HT_NON_NULLABLE:
case REF_TYPE_I31REF:
case REF_TYPE_NULLFUNCREF:
case REF_TYPE_NULLEXTERNREF:
case REF_TYPE_STRUCTREF:
case REF_TYPE_ARRAYREF:
case REF_TYPE_NULLREF:
#endif
PUT_I64_TO_ADDR(argv_ret,
invokeNative_Int64(func_ptr, argv1, n_stacks));
break;
Expand Down
40 changes: 40 additions & 0 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,46 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
&array_elem);
HANDLE_OP_END();
}
#if WASM_ENABLE_GC_BINARYEN != 0
case WASM_OP_ARRAY_COPY:
{
uint32 dst_offset, src_offset, len, src_type_index;
WASMArrayObjectRef src_obj, dst_obj;

read_leb_uint32(frame_ip, frame_ip_end, type_index);
read_leb_uint32(frame_ip, frame_ip_end, src_type_index);

len = POP_I32();
src_offset = POP_I32();
src_obj = POP_REF();
dst_offset = POP_I32();
dst_obj = POP_REF();

if (!src_obj || !dst_obj) {
wasm_set_exception(module, "null array object");
goto got_exception;
}

if (len > 0) {
if ((dst_offset > UINT32_MAX - len)
|| (dst_offset + len
> wasm_array_obj_length(dst_obj))
|| (src_offset > UINT32_MAX - len)
|| (src_offset + len
> wasm_array_obj_length(src_obj))) {
wasm_set_exception(module,
"array index out of bounds");
goto got_exception;
}

wasm_array_obj_copy(dst_obj, dst_offset, src_obj,
src_offset, len);
}

(void)src_type_index;
HANDLE_OP_END();
}
#endif
case WASM_OP_ARRAY_LEN:
{
uint32 array_len;
Expand Down
40 changes: 40 additions & 0 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,46 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
&array_elem);
HANDLE_OP_END();
}
#if WASM_ENABLE_GC_BINARYEN != 0
case WASM_OP_ARRAY_COPY:
{
uint32 dst_offset, src_offset, len, src_type_index;
WASMArrayObjectRef src_obj, dst_obj;

type_idx = read_uint32(frame_ip);
src_type_index = read_uint32(frame_ip);

len = POP_I32();
src_offset = POP_I32();
src_obj = POP_REF();
dst_offset = POP_I32();
dst_obj = POP_REF();

if (!src_obj || !dst_obj) {
wasm_set_exception(module, "null array object");
goto got_exception;
}

if (len > 0) {
if ((dst_offset > UINT32_MAX - len)
|| (dst_offset + len
> wasm_array_obj_length(dst_obj))
|| (src_offset > UINT32_MAX - len)
|| (src_offset + len
> wasm_array_obj_length(src_obj))) {
wasm_set_exception(module,
"array index out of bounds");
goto got_exception;
}

wasm_array_obj_copy(dst_obj, dst_offset, src_obj,
src_offset, len);
}

(void)src_type_index;
HANDLE_OP_END();
}
#endif
case WASM_OP_ARRAY_LEN:
{
uint32 array_len;
Expand Down
Loading