Import app manager, samples and test-tools

This commit is contained in:
wenyongh
2019-05-17 17:15:25 +08:00
parent b6e29e2153
commit dd5b133fa5
164 changed files with 21123 additions and 496 deletions

View File

@ -0,0 +1,17 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
emcc -g -O3 *.c -s WASM=1 -s SIDE_MODULE=1 -s ASSERTIONS=1 -s STACK_OVERFLOW_CHECK=2 \
-s TOTAL_MEMORY=65536 -s TOTAL_STACK=4096 -o test.wasm
#./jeffdump -o ../test_wasm.h -n wasm_test_file test.wasm

View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
//User LED
#define LED_PORT "GPIOA"
#define LED 5
//User KEY
#define KEY_PORT "GPIOC"
#define KEY 13
/** GPIO pin to be input. */
#define GPIO_DIR_IN (0 << 0)
/** GPIO pin to be output. */
#define GPIO_DIR_OUT (1 << 0)
void *device_get_binding(const char *);
int gpio_pin_configure(void *, unsigned int, int);
int gpio_pin_read(void *, unsigned int, unsigned int *);
int gpio_pin_write(void *, unsigned int, unsigned int);
int main(int argc, char **argv)
{
unsigned int gpio_value;
unsigned char flag = 0;
struct device *dev, *key_dev;
dev = device_get_binding(LED_PORT);
/* Set LED pin as output */
gpio_pin_configure(dev, LED, GPIO_DIR_OUT);
key_dev = device_get_binding(KEY_PORT);
/* Set KEY pin as input */
gpio_pin_configure(key_dev, KEY, GPIO_DIR_IN);
while (1) {
gpio_pin_read(key_dev, KEY, &gpio_value);
if (!gpio_value) {
gpio_pin_write(dev, LED, 1);
if (!flag) {
printf("object detected\n");
flag = 1;
}
} else {
gpio_pin_write(dev, LED, 0);
flag = 0;
}
}
return 0;
}

View File

@ -71,7 +71,7 @@ uint16 htons(uint16 value)
uint16 ret;
if (is_little_endian()) {
ret = value;
swap16(&ret);
swap16((uint8 *)&ret);
return ret;
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "attr-container.h"
#include "attr_container.h"
#include "request.h"
#include "shared_utils.h"
#include "wasm_app.h"
@ -138,9 +138,9 @@ static bool register_url_handler(const char *url,
// tell app mgr to route this url to me
if (reg_type == Reg_Request)
wasm_register_resource(url);
wasm_register_resource((int32)url);
else
wasm_sub_event(url);
wasm_sub_event((int32)url);
return true;
}
@ -242,7 +242,7 @@ void api_send_request(request_t * request, response_handler_f response_handler,
}
}
wasm_post_request(buffer, size);
wasm_post_request((int32)buffer, size);
free_req_resp_packet(buffer);
}
@ -329,7 +329,7 @@ void api_response_send(response_t *response)
if (buffer == NULL)
return;
wasm_response_send(buffer, size);
wasm_response_send((int32)buffer, size);
free_req_resp_packet(buffer);
}
@ -339,11 +339,11 @@ bool api_publish_event(const char *url, int fmt, void *payload, int payload_len)
{
int size;
request_t request[1];
init_request(request, url, COAP_EVENT, fmt, payload, payload_len);
init_request(request, (char *)url, COAP_EVENT, fmt, payload, payload_len);
char * buffer = pack_request(request, &size);
if (buffer == NULL)
return false;
wasm_post_request(buffer, size);
wasm_post_request((int32)buffer, size);
free_req_resp_packet(buffer);

View File

@ -34,7 +34,7 @@
#include "native_interface.h"
#include "shared_utils.h"
#include "attr-container.h"
#include "attr_container.h"
#include "request.h"
#include "sensor.h"
#include "timer_wasm_app.h"

View File

@ -31,7 +31,7 @@ sensor_t sensor_open(const char* name, int index,
sensor_event_handler_f sensor_event_handler,
void *user_data)
{
uint32 id = wasm_sensor_open(name, index);
uint32 id = wasm_sensor_open((int32)name, index);
if (id == -1)
return NULL;
@ -66,7 +66,7 @@ bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg)
char *buffer = (char *)cfg;
int len = attr_container_get_serialize_length(cfg);
return wasm_sensor_config_with_attr_container(sensor->handle, buffer, len);
return wasm_sensor_config_with_attr_container(sensor->handle, (int32)buffer, len);
}
bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay)

View File

@ -17,7 +17,7 @@
#ifndef _AEE_SENSOR_H_
#define _AEE_SENSOR_H_
#include "attr-container.h"
#include "attr_container.h"
#ifdef __cplusplus
extern "C" {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "attr-container.h"
#include "attr_container.h"
typedef union jvalue {
bool z;
@ -794,7 +794,7 @@ void attr_container_dump(const attr_container_t *attr_cont)
break;
case ATTR_TYPE_INT64:
bh_memcpy_s(&value.j, sizeof(uint64_t), p, sizeof(uint64_t));
attr_container_printf(", type: int64, value: 0x%llx\n", value.j);
attr_container_printf(", type: int64, value: 0x%llx\n", (long long unsigned int)(value.j));
p += 8;
break;
case ATTR_TYPE_BYTE:

View File

@ -109,7 +109,10 @@ request_t * unpack_request(char * packet, int size, request_t * request)
request->sender = ntohl(*((uint32*) (packet + 8)));
request->payload_len = payload_len;
request->url = REQUEST_PACKET_URL(packet);
request->payload = packet + REQUEST_PACKET_URL_OFFSET + url_len;
if (payload_len > 0)
request->payload = packet + REQUEST_PACKET_URL_OFFSET + url_len;
else
request->payload = NULL;
return request;
}
@ -150,7 +153,10 @@ response_t * unpack_response(char * packet, int size, response_t * response)
response->mid = ntohl(*((uint32*) (packet + 4)));
response->reciever = ntohl(*((uint32*) (packet + 8)));
response->payload_len = payload_len;
response->payload = packet + RESPONSE_PACKET_FIX_PART_LEN;
if (payload_len > 0)
response->payload = packet + RESPONSE_PACKET_FIX_PART_LEN;
else
response->payload = NULL;
return response;
}
@ -238,7 +244,7 @@ response_t * clone_response(response_t * response)
response_t * set_response(response_t * response, int status, int fmt,
const char *payload, int payload_len)
{
response->payload = payload;
response->payload = (void *)payload;
response->payload_len = payload_len;
response->status = status;
response->fmt = fmt;
@ -384,11 +390,9 @@ char * find_key_value(char * buffer, int buffer_len, char * key, char * value,
int value_len, char delimiter)
{
char * p = buffer;
int i = 0;
int remaining = buffer_len;
int key_len = strlen(key);
char * item_start = p;
while (*p != 0 && remaining > 0) {
while (*p == ' ' || *p == delimiter) {
p++;

View File

@ -17,10 +17,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib-export.h"
#include "lib_export.h"
#ifdef WASM_ENABLE_BASE_LIB
#include "base-lib-export.h"
#include "base_lib_export.h"
#endif
static NativeSymbol extended_native_symbol_defs[] = {

View File

@ -17,7 +17,7 @@
#ifndef _BASE_LIB_EXPORT_H_
#define _BASE_LIB_EXPORT_H_
#include "attr-container.h"
#include "attr_container.h"
#include "native_interface.h"
#endif /* end of _BASE_LIB_EXPORT_H_ */

View File

@ -15,11 +15,11 @@
*/
#include "native_interface.h"
#include "app-manager-export.h"
#include "app_manager_export.h"
#include "coap_ext.h"
#include "wasm-export.h"
#include "wasm_export.h"
extern void module_request_handler(request_t *request, uint32 register_id);
extern void module_request_handler(request_t *request, void *user_data);
bool wasm_response_send(int32 buffer_offset, int size)
{

View File

@ -15,7 +15,7 @@
*/
#include "runtime_timer.h"
#include "app-manager-export.h"
#include "app_manager_export.h"
#include "module_wasm_app.h"
#include "bh_list.h"
#include "bh_thread.h"

View File

@ -15,7 +15,7 @@
*/
#include "runtime_sensor.h"
#include "app-manager-export.h"
#include "app_manager_export.h"
#include "module_wasm_app.h"
#include "bh_thread.h"
#include "bh_time.h"
@ -168,7 +168,7 @@ uint32 wasm_sensor_open(int32 name_offset, int instance)
memset(client, 0, sizeof(sensor_client_t));
client->client_id = mod_id;
client->client_callback = wasm_sensor_callback;
client->client_callback = (void *)wasm_sensor_callback;
client->interval = s->default_interval;
client->next = s->clients;
s->clients = client;

View File

@ -18,7 +18,7 @@
#define LIB_EXTENSION_RUNTIME_SENSOR_H_
#include "bh_platform.h"
#include "attr-container.h"
#include "attr_container.h"
struct _sys_sensor;
typedef struct _sys_sensor* sensor_obj_t;

View File

@ -18,9 +18,9 @@
#include "bh_queue.h"
#include "bh_thread.h"
#include "runtime_sensor.h"
#include "attr-container.h"
#include "attr_container.h"
#include "module_wasm_app.h"
#include "wasm-export.h"
#include "wasm_export.h"
/*
*
@ -99,11 +99,10 @@ static attr_container_t * read_test_sensor(void * sensor)
static bool config_test_sensor(void * s, void * config)
{
return false;
}
static void * thread_sensor_check(void * arg)
static void thread_sensor_check(void * arg)
{
while (1) {
int ms_to_expiry = check_sensor_timers();
@ -120,6 +119,8 @@ static void cb_wakeup_thread()
vm_cond_signal(&cond);
}
void set_sensor_reshceduler(void (*callback)());
void init_sensor_framework()
{
// init the mutext and conditions
@ -138,7 +139,7 @@ void init_sensor_framework()
wasm_register_cleanup_callback(sensor_cleanup_callback);
vm_thread_create(&tid, thread_sensor_check, NULL,
vm_thread_create(&tid, (void *)thread_sensor_check, NULL,
BH_APPLET_PRESERVED_STACK_SIZE);
}

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
#include "wasm-native.h"
#include "wasm-export.h"
#include "wasm_native.h"
#include "wasm_export.h"
#include "wasm_log.h"
#include "wasm_platform_log.h"
@ -903,7 +903,9 @@ wasm_native_func_lookup(const char *module_name, const char *func_name)
while (func_def < func_def_end) {
if (!strcmp(func_def->module_name, module_name)
&& !strcmp(func_def->func_name, func_name))
&& (!strcmp(func_def->func_name, func_name)
|| (func_def->func_name[0] == '_'
&& !strcmp(func_def->func_name + 1, func_name))))
return (void*) (uintptr_t) func_def->func_ptr;
func_def++;
}

View File

@ -58,7 +58,7 @@ enable_language (ASM)
include (../../runtime/platform/${PLATFORM}/platform.cmake)
include (../../runtime/utils/utils.cmake)
include (../../runtime/vmcore_wasm/vmcore.cmake)
include (../../runtime/vmcore-wasm/vmcore.cmake)
include (../../lib/native/base/wasm_lib_base.cmake)
include (../../lib/native/libc/wasm_libc.cmake)
include (${SHARED_LIB_DIR}/platform/${PLATFORM}/shared_platform.cmake)
@ -68,12 +68,12 @@ add_library (vmlib
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_LIB_BASE_DIR}/base-lib-export.c
${WASM_LIB_BASE_DIR}/base_lib_export.c
${WASM_LIBC_SOURCE}
${PLATFORM_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE})
add_executable (iwasm main.c ext-lib-export.c)
add_executable (iwasm main.c ext_lib_export.c)
install (TARGETS iwasm DESTINATION bin)
@ -83,7 +83,7 @@ add_library (libiwasm SHARED
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_LIB_BASE_DIR}/base-lib-export.c
${WASM_LIB_BASE_DIR}/base_lib_export.c
${WASM_LIBC_SOURCE}
${PLATFORM_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE})

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
#include "lib-export.h"
#include "lib_export.h"
static NativeSymbol extended_native_symbol_defs[] = { };
#include "ext-lib-export.h"
#include "ext_lib_export.h"

View File

@ -24,7 +24,7 @@
#include "wasm_platform.h"
#include "wasm_platform_log.h"
#include "wasm_thread.h"
#include "wasm-export.h"
#include "wasm_export.h"
#include "wasm_memory.h"
#include "bh_memory.h"

View File

@ -27,7 +27,7 @@ set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib)
include_directories (${IWASM_ROOT}/runtime/include
${IWASM_ROOT}/runtime/platform/include
${IWASM_ROOT}/runtime/platform/zephyr
${IWASM_ROOT}/runtime/vmcore_wasm
${IWASM_ROOT}/runtime/vmcore-wasm
${SHARED_LIB_ROOT}/include
${SHARED_LIB_ROOT}/platform/include
${SHARED_LIB_ROOT}/platform/zephyr)
@ -37,14 +37,14 @@ set (IWASM_SRCS ${IWASM_ROOT}/runtime/utils/wasm_hashmap.c
${IWASM_ROOT}/runtime/utils/wasm_dlfcn.c
${IWASM_ROOT}/runtime/platform/zephyr/wasm_math.c
${IWASM_ROOT}/runtime/platform/zephyr/wasm_platform.c
${IWASM_ROOT}/runtime/platform/zephyr/wasm-native.c
${IWASM_ROOT}/runtime/vmcore_wasm/wasm-application.c
${IWASM_ROOT}/runtime/vmcore_wasm/wasm-interp.c
${IWASM_ROOT}/runtime/vmcore_wasm/wasm-loader.c
${IWASM_ROOT}/runtime/vmcore_wasm/wasm-runtime.c
${IWASM_ROOT}/runtime/vmcore_wasm/invokeNative_general.c
${IWASM_ROOT}/runtime/platform/zephyr/wasm_native.c
${IWASM_ROOT}/runtime/vmcore-wasm/wasm_application.c
${IWASM_ROOT}/runtime/vmcore-wasm/wasm_interp.c
${IWASM_ROOT}/runtime/vmcore-wasm/wasm_loader.c
${IWASM_ROOT}/runtime/vmcore-wasm/wasm_runtime.c
${IWASM_ROOT}/runtime/vmcore-wasm/invokeNative_general.c
${IWASM_ROOT}/lib/native/libc/libc_wrapper.c
${IWASM_ROOT}/lib/native/base/base-lib-export.c
${IWASM_ROOT}/lib/native/base/base_lib_export.c
${SHARED_LIB_ROOT}/platform/zephyr/bh_platform.c
${SHARED_LIB_ROOT}/platform/zephyr/bh_assert.c
${SHARED_LIB_ROOT}/platform/zephyr/bh_thread.c
@ -54,4 +54,4 @@ set (IWASM_SRCS ${IWASM_ROOT}/runtime/utils/wasm_hashmap.c
${SHARED_LIB_ROOT}/mem-alloc/ems/ems_alloc.c
${SHARED_LIB_ROOT}/mem-alloc/ems/ems_hmu.c)
target_sources(app PRIVATE ${IWASM_SRCS} src/main.c src/ext-lib-export.c)
target_sources(app PRIVATE ${IWASM_SRCS} src/main.c src/ext_lib_export.c)

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
#include "lib-export.h"
#include "lib_export.h"
static NativeSymbol extended_native_symbol_defs[] = { };
#include "ext-lib-export.h"
#include "ext_lib_export.h"

View File

@ -21,7 +21,7 @@
#include "wasm_platform.h"
#include "wasm_platform_log.h"
#include "wasm_thread.h"
#include "wasm-export.h"
#include "wasm_export.h"
#include "wasm_memory.h"
#include "bh_memory.h"
#include "test_wasm.h"

75
core/iwasm/readme.txt Normal file
View File

@ -0,0 +1,75 @@
1. How to build iwasm in Linux
cd products/linux/
mkdir build && cd build
cmake .. && make
2. How to build iwasm in Zephyr system
(1) clone zephyr source code
git clone https://github.com/zephyrproject-rtos/zephyr.git
(2) copy <iwasm_root_dir>/products/zephyr/simple directory to zephry/samples/
cd zephyr/samples/
cp -a <iwasm_root_dir>/products/zephyr/simple simple
cd simple
(3) create a link to <iwasm_root_dir> and rename it to iwasm
ln -s <iwasm_root_dir> iwasm
(4) create a link to <shared-lib_root_dir> and rename it to shared-lib
ln -s <shared-lib_root_dir> shared-lib
(5) build source code
mkdir build && cd build
source ../../../zephyr-env.sh
cmake -GNinja -DBOARD=qemu_x86 ..
ninja
(6) run simple
ninja run
3. How to build iwasm in AliOS-Things platform
(1) clone AliOS-Things source code
git clone https://github.com/alibaba/AliOS-Things.git
(2) copy <iwasm_root_dir>/products/alios-things directory to AliOS-Things/middleware,
and rename it as iwasm
cp -a <iwasm_root_dir>/products/alios-things middleware/iwasm
(3) create a link to <iwasm_root_dir> in middleware/iwasm/ and rename it to iwasm
ln -s <iwasm_root_dir> middleware/iwasm/iwasm
(4) create a link to <shared-lib_root_dir> in middleware/iwasm/ and rename it to shared-lib
ln -s <shared-lib_root_dir> middle/iwasm/shared-lib
(5) modify sample source code of AliOS-Things to call iwasm_init() function
modify file app/example/helloworld/helloworld.c, in the beginning of
function application_start(), add:
bool iwasm_init(void);
iwasm_init();
modify file app/example/helloworld/helloworld.mk, change
$(NAME)_COMPONENTS := yloop cli
to
$(NAME)_COMPONENTS := yloop cli iwasm
(6) build source code
aos make helloworld@linuxhost
(7) run source code
./out/helloworld@linuxhost/binary/helloworld@linuxhost.elf

View File

@ -17,7 +17,7 @@
#ifndef _EXT_LIB_EXPORT_H_
#define _EXT_LIB_EXPORT_H_
#include "lib-export.h"
#include "lib_export.h"
#ifdef __cplusplus
extern "C" {

View File

@ -20,8 +20,8 @@
* thread relative function.
*/
#ifndef _WASM_THREAD_H
#define _WASM_THREAD_H
#ifndef _WA_THREAD_H
#define _WA_THREAD_H
#ifdef __cplusplus
extern "C" {
@ -59,5 +59,5 @@ ws_mutex_init(korp_mutex *mutex, bool is_recursive)
}
#endif
#endif /* end of _WASM_THREAD_H */
#endif /* end of _WA_THREAD_H */

View File

@ -18,8 +18,8 @@
#define _GNU_SOURCE /* for O_DIRECT */
#endif
#include "wasm-native.h"
#include "wasm-runtime.h"
#include "wasm_native.h"
#include "wasm_runtime.h"
#include "wasm_log.h"
#include "wasm_memory.h"
#include "wasm_platform_log.h"

View File

@ -39,64 +39,64 @@ typedef uint32_t u_int32_t;
typedef uint64_t u_int64_t;
typedef union u32double_tag {
int *pint;
double *pdouble;
int *pint;
double *pdouble;
} U32DOUBLE;
static inline int *
pdouble2pint(double *pdouble)
{
U32DOUBLE u;
u.pdouble = pdouble;
return u.pint;
U32DOUBLE u;
u.pdouble = pdouble;
return u.pint;
}
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
struct
{
u_int64_t w;
} xparts;
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
struct
{
u_int64_t w;
} xparts;
} ieee_double_shape_type_little;
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
struct
{
u_int64_t w;
} xparts;
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
} parts;
struct
{
u_int64_t w;
} xparts;
} ieee_double_shape_type_big;
typedef union {
double d;
struct {
unsigned int manl :32;
unsigned int manh :20;
unsigned int exp :11;
unsigned int sign :1;
} bits;
double d;
struct {
unsigned int manl :32;
unsigned int manh :20;
unsigned int exp :11;
unsigned int sign :1;
} bits;
} IEEEd2bits_L;
typedef union {
double d;
struct {
unsigned int sign :1;
unsigned int exp :11;
unsigned int manh :20;
unsigned int manl :32;
} bits;
double d;
struct {
unsigned int sign :1;
unsigned int exp :11;
unsigned int manh :20;
unsigned int manl :32;
} bits;
} IEEEd2bits_B;
#define __HIL(x) *(1+pdouble2pint(&x))
@ -107,107 +107,107 @@ typedef union {
/* Get two 32 bit ints from a double. */
#define EXTRACT_WORDS_L(ix0,ix1,d) \
do { \
ieee_double_shape_type_little ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
do { \
ieee_double_shape_type_little ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
/* Set a double from two 32 bit ints. */
#define INSERT_WORDS_L(d,ix0,ix1) \
do { \
ieee_double_shape_type_little iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
do { \
ieee_double_shape_type_little iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
/* Get two 32 bit ints from a double. */
#define EXTRACT_WORDS_B(ix0,ix1,d) \
do { \
ieee_double_shape_type_big ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
do { \
ieee_double_shape_type_big ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
/* Set a double from two 32 bit ints. */
#define INSERT_WORDS_B(d,ix0,ix1) \
do { \
ieee_double_shape_type_big iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
do { \
ieee_double_shape_type_big iw_u; \
iw_u.parts.msw = (ix0); \
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
/* Get the more significant 32 bit int from a double. */
#define GET_HIGH_WORD_L(i,d) \
do { \
ieee_double_shape_type_little gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
do { \
ieee_double_shape_type_little gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
/* Get the more significant 32 bit int from a double. */
#define GET_HIGH_WORD_B(i,d) \
do { \
ieee_double_shape_type_big gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
do { \
ieee_double_shape_type_big gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
/* Set the more significant 32 bits of a double from an int. */
#define SET_HIGH_WORD_L(d,v) \
do { \
ieee_double_shape_type_little sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
do { \
ieee_double_shape_type_little sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
/* Set the more significant 32 bits of a double from an int. */
#define SET_HIGH_WORD_B(d,v) \
do { \
ieee_double_shape_type_big sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
do { \
ieee_double_shape_type_big sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
/* Macro wrappers. */
#define EXTRACT_WORDS(ix0,ix1,d) do { \
if (is_little_endian) \
EXTRACT_WORDS_L(ix0,ix1,d); \
else \
EXTRACT_WORDS_B(ix0,ix1,d); \
if (is_little_endian) \
EXTRACT_WORDS_L(ix0,ix1,d); \
else \
EXTRACT_WORDS_B(ix0,ix1,d); \
} while (0)
#define INSERT_WORDS(d,ix0,ix1) do { \
if (is_little_endian) \
INSERT_WORDS_L(d,ix0,ix1); \
else \
INSERT_WORDS_B(d,ix0,ix1); \
if (is_little_endian) \
INSERT_WORDS_L(d,ix0,ix1); \
else \
INSERT_WORDS_B(d,ix0,ix1); \
} while (0)
#define GET_HIGH_WORD(i,d) \
do { \
if (is_little_endian) \
GET_HIGH_WORD_L(i,d); \
else \
GET_HIGH_WORD_B(i,d); \
} while (0)
do { \
if (is_little_endian) \
GET_HIGH_WORD_L(i,d); \
else \
GET_HIGH_WORD_B(i,d); \
} while (0)
#define SET_HIGH_WORD(d,v) \
do { \
if (is_little_endian) \
SET_HIGH_WORD_L(d,v); \
else \
SET_HIGH_WORD_B(d,v); \
} while (0)
do { \
if (is_little_endian) \
SET_HIGH_WORD_L(d,v); \
else \
SET_HIGH_WORD_B(d,v); \
} while (0)
#define __HI(x) (is_little_endian ? __HIL(x) : __HIB(x))
@ -220,14 +220,14 @@ do { \
#define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval))
#else
#define STRICT_ASSIGN(type, lval, rval) do { \
volatile type __lval; \
\
if (sizeof(type) >= sizeof(long double)) \
(lval) = (rval); \
else { \
__lval = (rval); \
(lval) = __lval; \
} \
volatile type __lval; \
\
if (sizeof(type) >= sizeof(long double)) \
(lval) = (rval); \
else { \
__lval = (rval); \
(lval) = __lval; \
} \
} while (0)
#endif
@ -257,8 +257,8 @@ static const double
static double
#endif
TWO52[2]={
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
static double freebsd_sqrt(double x);
@ -270,312 +270,312 @@ static int freebsd_isnan(double x);
static double freebsd_sqrt(double x) /* wrapper sqrt */
{
double z;
int32_t sign = (int)0x80000000;
int32_t ix0,s0,q,m,t,i;
u_int32_t r,t1,s1,ix1,q1;
double z;
int32_t sign = (int)0x80000000;
int32_t ix0,s0,q,m,t,i;
u_int32_t r,t1,s1,ix1,q1;
EXTRACT_WORDS(ix0,ix1,x);
EXTRACT_WORDS(ix0,ix1,x);
/* take care of Inf and NaN */
if((ix0&0x7ff00000)==0x7ff00000) {
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
if((ix0&0x7ff00000)==0x7ff00000) {
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
sqrt(-inf)=sNaN */
}
}
/* take care of zero */
if(ix0<=0) {
if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
else if(ix0<0)
return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
}
if(ix0<=0) {
if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
else if(ix0<0)
return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
}
/* normalize x */
m = (ix0>>20);
if(m==0) { /* subnormal x */
while(ix0==0) {
m -= 21;
ix0 |= (ix1>>11); ix1 <<= 21;
}
for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
m -= i-1;
ix0 |= (ix1>>(32-i));
ix1 <<= i;
}
m -= 1023; /* unbias exponent */
ix0 = (ix0&0x000fffff)|0x00100000;
if(m&1){ /* odd m, double x to make it even */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
}
m >>= 1; /* m = [m/2] */
m = (ix0>>20);
if(m==0) { /* subnormal x */
while(ix0==0) {
m -= 21;
ix0 |= (ix1>>11); ix1 <<= 21;
}
for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
m -= i-1;
ix0 |= (ix1>>(32-i));
ix1 <<= i;
}
m -= 1023; /* unbias exponent */
ix0 = (ix0&0x000fffff)|0x00100000;
if(m&1){ /* odd m, double x to make it even */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
}
m >>= 1; /* m = [m/2] */
/* generate sqrt(x) bit by bit */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
r = 0x00200000; /* r = moving bit from right to left */
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
r = 0x00200000; /* r = moving bit from right to left */
while(r!=0) {
t = s0+r;
if(t<=ix0) {
s0 = t+r;
ix0 -= t;
q += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
while(r!=0) {
t = s0+r;
if(t<=ix0) {
s0 = t+r;
ix0 -= t;
q += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
r = sign;
while(r!=0) {
t1 = s1+r;
t = s0;
if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
s1 = t1+r;
if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
ix0 -= t;
if (ix1 < t1) ix0 -= 1;
ix1 -= t1;
q1 += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
r = sign;
while(r!=0) {
t1 = s1+r;
t = s0;
if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
s1 = t1+r;
if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
ix0 -= t;
if (ix1 < t1) ix0 -= 1;
ix1 -= t1;
q1 += r;
}
ix0 += ix0 + ((ix1&sign)>>31);
ix1 += ix1;
r>>=1;
}
/* use floating add to find out rounding direction */
if((ix0|ix1)!=0) {
z = one-tiny; /* trigger inexact flag */
if (z>=one) {
z = one+tiny;
if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
else if (z>one) {
if (q1==(u_int32_t)0xfffffffe) q+=1;
q1+=2;
} else
q1 += (q1&1);
}
}
ix0 = (q>>1)+0x3fe00000;
ix1 = q1>>1;
if ((q&1)==1) ix1 |= sign;
ix0 += (m <<20);
if((ix0|ix1)!=0) {
z = one-tiny; /* trigger inexact flag */
if (z>=one) {
z = one+tiny;
if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
else if (z>one) {
if (q1==(u_int32_t)0xfffffffe) q+=1;
q1+=2;
} else
q1 += (q1&1);
}
}
ix0 = (q>>1)+0x3fe00000;
ix1 = q1>>1;
if ((q&1)==1) ix1 |= sign;
ix0 += (m <<20);
INSERT_WORDS(z,ix0,ix1);
INSERT_WORDS(z,ix0,ix1);
return z;
return z;
}
static double freebsd_floor(double x)
{
int32_t i0,i1,j0;
u_int32_t i,j;
int32_t i0,i1,j0;
u_int32_t i,j;
EXTRACT_WORDS(i0,i1,x);
EXTRACT_WORDS(i0,i1,x);
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) { /* raise inexact if x != 0 */
if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
if(i0>=0) {i0=i1=0;}
else if(((i0&0x7fffffff)|i1)!=0)
{ i0=0xbff00000;i1=0;}
}
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0<0) i0 += (0x00100000)>>j0;
i0 &= (~i); i1=0;
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((u_int32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0<0) {
if(j0==20) i0+=1;
else {
j = i1+(1<<(52-j0));
if(j<i1) i0 +=1 ; /* got a carry */
i1=j;
}
}
i1 &= (~i);
}
}
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) { /* raise inexact if x != 0 */
if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
if(i0>=0) {i0=i1=0;}
else if(((i0&0x7fffffff)|i1)!=0)
{ i0=0xbff00000;i1=0;}
}
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0<0) i0 += (0x00100000)>>j0;
i0 &= (~i); i1=0;
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((u_int32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0<0) {
if(j0==20) i0+=1;
else {
j = i1+(1<<(52-j0));
if(j<i1) i0 +=1 ; /* got a carry */
i1=j;
}
}
i1 &= (~i);
}
}
INSERT_WORDS(x,i0,i1);
INSERT_WORDS(x,i0,i1);
return x;
return x;
}
static double freebsd_ceil(double x)
{
int32_t i0,i1,j0;
u_int32_t i,j;
EXTRACT_WORDS(i0,i1,x);
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) { /* raise inexact if x != 0 */
if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
if(i0<0) {i0=0x80000000;i1=0;}
else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
}
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0>0) i0 += (0x00100000)>>j0;
i0 &= (~i); i1=0;
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((u_int32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0>0) {
if(j0==20) i0+=1;
else {
j = i1 + (1<<(52-j0));
if(j<i1) i0+=1; /* got a carry */
i1 = j;
}
}
i1 &= (~i);
}
}
INSERT_WORDS(x,i0,i1);
return x;
int32_t i0,i1,j0;
u_int32_t i,j;
EXTRACT_WORDS(i0,i1,x);
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) { /* raise inexact if x != 0 */
if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
if(i0<0) {i0=0x80000000;i1=0;}
else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
}
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0>0) i0 += (0x00100000)>>j0;
i0 &= (~i); i1=0;
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((u_int32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0>0) {
if(j0==20) i0+=1;
else {
j = i1 + (1<<(52-j0));
if(j<i1) i0+=1; /* got a carry */
i1 = j;
}
}
i1 &= (~i);
}
}
INSERT_WORDS(x,i0,i1);
return x;
}
static double freebsd_rint(double x)
{
int32_t i0,j0,sx;
u_int32_t i,i1;
double w,t;
EXTRACT_WORDS(i0,i1,x);
sx = (i0>>31)&1;
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) {
if(((i0&0x7fffffff)|i1)==0) return x;
i1 |= (i0&0x0fffff);
i0 &= 0xfffe0000;
i0 |= ((i1|-i1)>>12)&0x80000;
SET_HIGH_WORD(x,i0);
STRICT_ASSIGN(double,w,TWO52[sx]+x);
t = w-TWO52[sx];
GET_HIGH_WORD(i0,t);
SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
return t;
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
i>>=1;
if(((i0&i)|i1)!=0) {
/*
* Some bit is set after the 0.5 bit. To avoid the
* possibility of errors from double rounding in
* w = TWO52[sx]+x, adjust the 0.25 bit to a lower
* guard bit. We do this for all j0<=51. The
* adjustment is trickiest for j0==18 and j0==19
* since then it spans the word boundary.
*/
if(j0==19) i1 = 0x40000000; else
if(j0==18) i1 = 0x80000000; else
i0 = (i0&(~i))|((0x20000)>>j0);
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((u_int32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
i>>=1;
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
}
INSERT_WORDS(x,i0,i1);
STRICT_ASSIGN(double,w,TWO52[sx]+x);
return w-TWO52[sx];
int32_t i0,j0,sx;
u_int32_t i,i1;
double w,t;
EXTRACT_WORDS(i0,i1,x);
sx = (i0>>31)&1;
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) {
if(((i0&0x7fffffff)|i1)==0) return x;
i1 |= (i0&0x0fffff);
i0 &= 0xfffe0000;
i0 |= ((i1|-i1)>>12)&0x80000;
SET_HIGH_WORD(x,i0);
STRICT_ASSIGN(double,w,TWO52[sx]+x);
t = w-TWO52[sx];
GET_HIGH_WORD(i0,t);
SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
return t;
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
i>>=1;
if(((i0&i)|i1)!=0) {
/*
* Some bit is set after the 0.5 bit. To avoid the
* possibility of errors from double rounding in
* w = TWO52[sx]+x, adjust the 0.25 bit to a lower
* guard bit. We do this for all j0<=51. The
* adjustment is trickiest for j0==18 and j0==19
* since then it spans the word boundary.
*/
if(j0==19) i1 = 0x40000000; else
if(j0==18) i1 = 0x80000000; else
i0 = (i0&(~i))|((0x20000)>>j0);
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((u_int32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
i>>=1;
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
}
INSERT_WORDS(x,i0,i1);
STRICT_ASSIGN(double,w,TWO52[sx]+x);
return w-TWO52[sx];
}
static int freebsd_isnan(double d)
{
if (is_little_endian) {
IEEEd2bits_L u;
u.d = d;
return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
}
else {
IEEEd2bits_B u;
u.d = d;
return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
}
if (is_little_endian) {
IEEEd2bits_L u;
u.d = d;
return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
}
else {
IEEEd2bits_B u;
u.d = d;
return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
}
}
static double freebsd_fabs(double x)
{
u_int32_t high;
GET_HIGH_WORD(high,x);
SET_HIGH_WORD(x,high&0x7fffffff);
return x;
u_int32_t high;
GET_HIGH_WORD(high,x);
SET_HIGH_WORD(x,high&0x7fffffff);
return x;
}
double sqrt(double x)
{
return freebsd_sqrt(x);
return freebsd_sqrt(x);
}
double floor(double x)
{
return freebsd_floor(x);
return freebsd_floor(x);
}
double ceil(double x)
{
return freebsd_ceil(x);
return freebsd_ceil(x);
}
double fmin(double x, double y)
{
return x < y ? x : y;
return x < y ? x : y;
}
double fmax(double x, double y)
{
return x > y ? x : y;
return x > y ? x : y;
}
double rint(double x)
{
return freebsd_rint(x);
return freebsd_rint(x);
}
double fabs(double x)
{
return freebsd_fabs(x);
return freebsd_fabs(x);
}
int isnan(double x)
{
return freebsd_isnan(x);
return freebsd_isnan(x);
}
double trunc(double x)
{
return (x > 0) ? freebsd_floor(x) : freebsd_ceil(x);
return (x > 0) ? freebsd_floor(x) : freebsd_ceil(x);
}
int signbit(double x)
{
return ((__HI(x) & 0x80000000) >> 31);
return ((__HI(x) & 0x80000000) >> 31);
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "wasm-native.h"
#include "wasm_native.h"
void*

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "wasm-runtime.h"
#include "wasm_runtime.h"
void invokeNative(uint32 argv[], uint32 argc, void (*native_code)())
{

View File

@ -18,9 +18,9 @@
#include <stdlib.h>
#include <string.h>
#include "wasm.h"
#include "wasm-interp.h"
#include "wasm-runtime.h"
#include "wasm-thread.h"
#include "wasm_interp.h"
#include "wasm_runtime.h"
#include "wasm_thread.h"
#include "wasm_assert.h"
#include "wasm_log.h"
#include "wasm_memory.h"

View File

@ -14,11 +14,11 @@
* limitations under the License.
*/
#include "wasm-interp.h"
#include "wasm-runtime.h"
#include "wasm-thread.h"
#include "wasm-opcode.h"
#include "wasm-loader.h"
#include "wasm_interp.h"
#include "wasm_runtime.h"
#include "wasm_thread.h"
#include "wasm_opcode.h"
#include "wasm_loader.h"
#include "wasm_log.h"
#include "wasm_memory.h"

View File

@ -14,11 +14,11 @@
* limitations under the License.
*/
#include "wasm-loader.h"
#include "wasm_loader.h"
#include "wasm.h"
#include "wasm-native.h"
#include "wasm-opcode.h"
#include "wasm-runtime.h"
#include "wasm_native.h"
#include "wasm_opcode.h"
#include "wasm_runtime.h"
#include "wasm_log.h"
#include "wasm_memory.h"
@ -373,7 +373,10 @@ resolve_sym(const char *module_name, const char *field_name)
return NULL;
if (field_name[0] == '_'
&& (sym = wasm_dlsym(NULL, field_name + 1)))
&& (sym = wasm_dlsym(NULL, field_name + 1)))
return sym;
if ((sym = wasm_dlsym(NULL, field_name)))
return sym;
return NULL;

View File

@ -14,11 +14,11 @@
* limitations under the License.
*/
#include "wasm-runtime.h"
#include "wasm-thread.h"
#include "wasm-loader.h"
#include "wasm-native.h"
#include "wasm-interp.h"
#include "wasm_runtime.h"
#include "wasm_thread.h"
#include "wasm_loader.h"
#include "wasm_native.h"
#include "wasm_interp.h"
#include "wasm_log.h"
#include "wasm_platform_log.h"
#include "wasm_memory.h"

View File

@ -18,7 +18,7 @@
#define _WASM_RUNTIME_H
#include "wasm.h"
#include "wasm-thread.h"
#include "wasm_thread.h"
#include "wasm_hashmap.h"
#ifdef __cplusplus

View File

@ -18,7 +18,7 @@
#define _WASM_RUNTIME_THREAD_H
#include "wasm_assert.h"
#include "wasm_thread.h"
#include "wa_thread.h"
#ifdef __cplusplus
extern "C" {