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
8 changes: 5 additions & 3 deletions ATTRIBUTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ WAMR project reused some components from other open source project:
- **contiki-ng**: for the coap protocol implementation
- **freebsd libm**: used in core/shared/platform/alios/bh_math.c
- **littlevgl**: for the gui samples and wrapped the wasm graphic layer
- **llvm**. for the AOT/JIT compilation
- **wasm-c-api**. to implement the C-APIs of wasm. using headers and sameples
- **llvm**: for the AOT/JIT compilation
- **wasm-c-api**: to implement the C-APIs of wasm. using headers and sameples
- **wasmtime**: for the wasi libc implementation
- **zephyr**. for several platform specific examples
- **zephyr**: for several platform specific examples
- **WebAssembly debugging patch for LLDB**: for extending the ability of LLDB to support wasm debugging

The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location.

Expand All @@ -23,6 +24,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
| wasm-c-api | ac9b509f4df86e40e56e9b01f3f49afab0100037 | c9d31284651b975f05ac27cee0bab1377560b87e | https://github.com/WebAssembly/wasm-c-api | |
| wasmtime | unspecified | v0.26.0 | https://github.com/bytecodealliance/wasmtime | |
| zephyr | unspecified | v2.5.0 | https://www.zephyrproject.org/ | https://www.cvedetails.com/vendor/19255/Zephyrproject.html |
| WebAssembly debugging patch for LLDB | unspecified | unspecified | https://reviews.llvm.org/D78801 | |

## Licenses

Expand Down
28 changes: 27 additions & 1 deletion ci/coding_guidelines_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import shutil
import subprocess
import sys
import unittest

CLANG_FORMAT_CMD = "clang-format-12"
GIT_CLANG_FORMAT_CMD = "git-clang-format-12"
Expand Down Expand Up @@ -155,7 +156,7 @@ def run_aspell(file_path: pathlib, root: pathlib) -> bool:


def check_dir_name(path: pathlib, root: pathlib) -> bool:
m = re.search(INVALID_DIR_NAME_SEGMENT, str(path.relative_to(root)))
m = re.search(INVALID_DIR_NAME_SEGMENT, str(path.relative_to(root).parent))
if m:
print(f"--- found a character '_' in {m.groups()} in {path}")

Expand Down Expand Up @@ -271,5 +272,30 @@ def main() -> int:
return process_entire_pr(wamr_root, options.commits)


# run with python3 -m unitest ci/coding_guidelines_check.py
class TestCheck(unittest.TestCase):
def test_check_dir_name_failed(self):
root = pathlib.Path("/root/Workspace/")
new_file_path = root.joinpath("core/shared/platform/esp_idf/espid_memmap.c")
self.assertFalse(check_dir_name(new_file_path, root))

def test_check_dir_name_pass(self):
root = pathlib.Path("/root/Workspace/")
new_file_path = root.joinpath("core/shared/platform/esp-idf/espid_memmap.c")
self.assertTrue(check_dir_name(new_file_path, root))

def test_check_file_name_failed(self):
new_file_path = pathlib.Path(
"/root/Workspace/core/shared/platform/esp-idf/espid-memmap.c"
)
self.assertFalse(check_file_name(new_file_path))

def test_check_file_name_pass(self):
new_file_path = pathlib.Path(
"/root/Workspace/core/shared/platform/esp-idf/espid_memmap.c"
)
self.assertTrue(check_file_name(new_file_path))


if __name__ == "__main__":
sys.exit(0 if main() else 1)
9 changes: 9 additions & 0 deletions core/iwasm/aot/aot_intrinsic.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ static const aot_intrinsic g_intrinsic_mapping[] = {
{ "f64_promote_f32", "aot_intrinsic_f32_to_f64", AOT_INTRINSIC_FLAG_F32_TO_F64 },
{ "f32_cmp", "aot_intrinsic_f32_cmp", AOT_INTRINSIC_FLAG_F32_CMP },
{ "f64_cmp", "aot_intrinsic_f64_cmp", AOT_INTRINSIC_FLAG_F64_CMP },
{ "f32.const", NULL, AOT_INTRINSIC_FLAG_F32_CONST},
{ "f64.const", NULL, AOT_INTRINSIC_FLAG_F64_CONST},
};
/* clang-format on */

Expand Down Expand Up @@ -617,6 +619,13 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
add_f64_common_intrinsics(comp_ctx);
add_common_float_integer_convertion(comp_ctx);
}
else {
/*
* Use constant value table by default
*/
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST);
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST);
}
}

#endif /* WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 */
2 changes: 2 additions & 0 deletions core/iwasm/aot/aot_intrinsic.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern "C" {
#define AOT_INTRINSIC_FLAG_F32_TO_U64 AOT_INTRINSIC_FLAG(0, 23)
#define AOT_INTRINSIC_FLAG_F32_TO_F64 AOT_INTRINSIC_FLAG(0, 24)
#define AOT_INTRINSIC_FLAG_F32_CMP AOT_INTRINSIC_FLAG(0, 25)
#define AOT_INTRINSIC_FLAG_F32_CONST AOT_INTRINSIC_FLAG(0, 26)

#define AOT_INTRINSIC_FLAG_F64_FADD AOT_INTRINSIC_FLAG(1, 0)
#define AOT_INTRINSIC_FLAG_F64_FSUB AOT_INTRINSIC_FLAG(1, 1)
Expand Down Expand Up @@ -84,6 +85,7 @@ extern "C" {
#define AOT_INTRINSIC_FLAG_F64_TO_U64 AOT_INTRINSIC_FLAG(1, 23)
#define AOT_INTRINSIC_FLAG_F64_TO_F32 AOT_INTRINSIC_FLAG(1, 24)
#define AOT_INTRINSIC_FLAG_F64_CMP AOT_INTRINSIC_FLAG(1, 25)
#define AOT_INTRINSIC_FLAG_F64_CONST AOT_INTRINSIC_FLAG(1, 26)
/* clang-format on */

float32
Expand Down
46 changes: 39 additions & 7 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ get_native_symbol_by_name(const char *name)
return func;
}

static bool
str2uint32(const char *buf, uint32 *p_res);

static bool
str2uint64(const char *buf, uint64 *p_res);

static bool
load_native_symbol_section(const uint8 *buf, const uint8 *buf_end,
AOTModule *module, bool is_load_from_file_buf,
Expand All @@ -487,11 +493,39 @@ load_native_symbol_section(const uint8 *buf, const uint8 *buf_end,

for (i = cnt - 1; i >= 0; i--) {
read_string(p, p_end, symbol);
module->native_symbol_list[i] = get_native_symbol_by_name(symbol);
if (module->native_symbol_list[i] == NULL) {
set_error_buf_v(error_buf, error_buf_size,
"missing native symbol: %s", symbol);
goto fail;
if (!strncmp(symbol, "f32#", 4)) {
uint32 u32;
/* Resolve the raw int bits of f32 const */
if (!str2uint32(symbol + 4, &u32)) {
set_error_buf_v(error_buf, error_buf_size,
"resolve symbol %s failed", symbol);
goto fail;
}
*(uint32 *)(&module->native_symbol_list[i]) = u32;
}
else if (!strncmp(symbol, "f64#", 4)) {
uint64 u64;
/* Resolve the raw int bits of f64 const */
if (!str2uint64(symbol + 4, &u64)) {
set_error_buf_v(error_buf, error_buf_size,
"resolve symbol %s failed", symbol);
goto fail;
}
*(uint64 *)(&module->native_symbol_list[i]) = u64;
}
else if (!strncmp(symbol, "__ignore", 8)) {
/* Padding bytes to make f64 on 8-byte aligned address,
or it is the second 32-bit slot in 32-bit system */
continue;
}
else {
module->native_symbol_list[i] =
get_native_symbol_by_name(symbol);
if (module->native_symbol_list[i] == NULL) {
set_error_buf_v(error_buf, error_buf_size,
"missing native symbol: %s", symbol);
goto fail;
}
}
}
}
Expand Down Expand Up @@ -1711,7 +1745,6 @@ is_literal_relocation(const char *reloc_sec_name)
return !strcmp(reloc_sec_name, ".rela.literal");
}

#if defined(BH_PLATFORM_WINDOWS)
static bool
str2uint32(const char *buf, uint32 *p_res)
{
Expand Down Expand Up @@ -1757,7 +1790,6 @@ str2uint64(const char *buf, uint64 *p_res)
*p_res = res;
return true;
}
#endif

static bool
do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
bool ret;

if (argc < func_type->param_cell_num) {
char buf[128];
char buf[108];
snprintf(buf, sizeof(buf),
"invalid argument count %u, must be no smaller than %u", argc,
func_type->param_cell_num);
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/aot/arch/aot_reloc_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
if (error_buf != NULL)
snprintf(error_buf, error_buf_size,
"Load relocation section failed: "
"invalid relocation type %d.",
"invalid relocation type %" PRIu32 ".",
reloc_type);
return false;
}
Expand Down
26 changes: 4 additions & 22 deletions core/iwasm/common/wasm_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
char *endptr = NULL;
bh_assert(argv[i] != NULL);
if (argv[i][0] == '\0') {
snprintf(buf, sizeof(buf), "invalid input argument %d", i);
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32, i);
wasm_runtime_set_exception(module_inst, buf);
goto fail;
}
Expand Down Expand Up @@ -554,8 +554,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
break;
}
if (endptr && *endptr != '\0' && *endptr != '_') {
snprintf(buf, sizeof(buf), "invalid input argument %d: %s", i,
argv[i]);
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32 ": %s",
i, argv[i]);
wasm_runtime_set_exception(module_inst, buf);
goto fail;
}
Expand All @@ -573,7 +573,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
switch (type->types[type->param_count + j]) {
case VALUE_TYPE_I32:
{
os_printf("0x%x:i32", argv1[k]);
os_printf("0x%" PRIx32 ":i32", argv1[k]);
k++;
break;
}
Expand All @@ -586,16 +586,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
u.parts[0] = argv1[k];
u.parts[1] = argv1[k + 1];
k += 2;
#ifdef PRIx64
os_printf("0x%" PRIx64 ":i64", u.val);
#else
char buf[16];
if (sizeof(long) == 4)
snprintf(buf, sizeof(buf), "%s", "0x%llx:i64");
else
snprintf(buf, sizeof(buf), "%s", "0x%lx:i64");
os_printf(buf, u.val);
#endif
break;
}
case VALUE_TYPE_F32:
Expand Down Expand Up @@ -645,17 +636,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
case VALUE_TYPE_V128:
{
uint64 *v = (uint64 *)(argv1 + k);
#if defined(PRIx64)
os_printf("<0x%016" PRIx64 " 0x%016" PRIx64 ">:v128", *v,
*(v + 1));
#else
if (4 == sizeof(long)) {
os_printf("<0x%016llx 0x%016llx>:v128", *v, *(v + 1));
}
else {
os_printf("<0x%016lx 0x%016lx>:v128", *v, *(v + 1));
}
#endif /* PRIx64 */
k += 4;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/aot.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ typedef struct AOTCompData {

typedef struct AOTNativeSymbol {
bh_list_link link;
const char *symbol;
char symbol[32];
int32 index;
} AOTNativeSymbol;

Expand Down
5 changes: 3 additions & 2 deletions core/iwasm/compilation/aot_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ read_leb(const uint8 *buf, const uint8 *buf_end, uint32 *p_offset,
}
bcnt += 1;
}
if (bcnt > (((maxbits + 8) >> 3) - (maxbits + 8))) {
aot_set_last_error("read leb failed: unsigned leb overflow.");
if (bcnt > (maxbits + 6) / 7) {
aot_set_last_error("read leb failed: "
"integer representation too long");
return false;
}
if (sign && (shift < maxbits) && (byte & 0x40)) {
Expand Down
39 changes: 33 additions & 6 deletions core/iwasm/compilation/aot_emit_const.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "aot_emit_const.h"
#include "aot_intrinsic.h"

bool
aot_compile_op_i32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
Expand Down Expand Up @@ -36,9 +37,22 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef alloca, value;

if (!isnan(f32_const)) {
value = F32_CONST(f32_const);
CHECK_LLVM_CONST(value);
PUSH_F32(value);
if (comp_ctx->is_indirect_mode
&& aot_intrinsic_check_capability(comp_ctx, "f32.const")) {
WASMValue wasm_value;
memcpy(&wasm_value.f32, &f32_const, sizeof(float32));
value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol,
&wasm_value, VALUE_TYPE_F32);
if (!value) {
return false;
}
PUSH_F32(value);
}
else {
value = F32_CONST(f32_const);
CHECK_LLVM_CONST(value);
PUSH_F32(value);
}
}
else {
int32 i32_const;
Expand Down Expand Up @@ -77,9 +91,22 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef alloca, value;

if (!isnan(f64_const)) {
value = F64_CONST(f64_const);
CHECK_LLVM_CONST(value);
PUSH_F64(value);
if (comp_ctx->is_indirect_mode
&& aot_intrinsic_check_capability(comp_ctx, "f64.const")) {
WASMValue wasm_value;
memcpy(&wasm_value.f64, &f64_const, sizeof(float64));
value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol,
&wasm_value, VALUE_TYPE_F64);
if (!value) {
return false;
}
PUSH_F64(value);
}
else {
value = F64_CONST(f64_const);
CHECK_LLVM_CONST(value);
PUSH_F64(value);
}
}
else {
int64 i64_const;
Expand Down
Loading