Re-org platform APIs: move most platform APIs of iwasm to shared-lib (#45)

This commit is contained in:
wenyongh
2019-07-22 11:32:51 +08:00
committed by GitHub
parent 08ebc6c773
commit 1db5a2f697
39 changed files with 387 additions and 899 deletions

View File

@ -17,7 +17,7 @@
#ifndef _WASM_H_
#define _WASM_H_
#include "wasm_platform.h"
#include "bh_platform.h"
#include "wasm_hashmap.h"
#include "wasm_assert.h"

View File

@ -160,6 +160,13 @@ union ieee754_double {
} ieee;
};
static union {
int a;
char b;
} __ue = { .a = 1 };
#define is_little_endian() (__ue.b == 1)
bool
wasm_application_execute_func(WASMModuleInstance *module_inst,
char *name, int argc, char *argv[])
@ -222,7 +229,7 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
union ieee754_float u;
sig = strtoul(endptr + 1, &endptr, 0);
u.f = f32;
if (is_little_endian)
if (is_little_endian())
u.ieee.ieee_little_endian.mantissa = sig;
else
u.ieee.ieee_big_endian.mantissa = sig;
@ -245,7 +252,7 @@ wasm_application_execute_func(WASMModuleInstance *module_inst,
union ieee754_double ud;
sig = strtoull(endptr + 1, &endptr, 0);
ud.d = u.val;
if (is_little_endian) {
if (is_little_endian()) {
ud.ieee.ieee_little_endian.mantissa0 = sig >> 32;
ud.ieee.ieee_little_endian.mantissa1 = sig;
}

View File

@ -21,6 +21,7 @@
#include "wasm_runtime.h"
#include "wasm_log.h"
#include "wasm_memory.h"
#include "wasm_dlfcn.h"
/* Read a value of given type from the address pointed to by the given
pointer and increase the pointer to the position just after the
@ -1347,6 +1348,13 @@ exchange32(uint8* p_data)
*(p_data + 2) = value;
}
static union {
int a;
char b;
} __ue = { .a = 1 };
#define is_little_endian() (__ue.b == 1)
static bool
load(const uint8 *buf, uint32 size, WASMModule *module,
char *error_buf, uint32 error_buf_size)
@ -1358,7 +1366,7 @@ load(const uint8 *buf, uint32 size, WASMModule *module,
CHECK_BUF(p, p_end, sizeof(uint32));
magic_number = read_uint32(p);
if (!is_little_endian)
if (!is_little_endian())
exchange32((uint8*)&magic_number);
if (magic_number != WASM_MAGIC_NUMBER) {
@ -1368,7 +1376,7 @@ load(const uint8 *buf, uint32 size, WASMModule *module,
CHECK_BUF(p, p_end, sizeof(uint32));
version = read_uint32(p);
if (!is_little_endian)
if (!is_little_endian())
exchange32((uint8*)&version);
if (version != WASM_CURRENT_VERSION) {

View File

@ -35,7 +35,7 @@ set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
bool
wasm_runtime_init()
{
if (wasm_platform_init() != 0)
if (bh_platform_init() != 0)
return false;
if (wasm_log_init() != 0)