Browse Source

platforms/nuttx: Add support for custom name sections & configurable heap pool (#407)

Co-authored-by: Huang Qi <huangqi3@xiaomi.com>
Huang Qi 5 năm trước cách đây
mục cha
commit
78c525d21c
2 tập tin đã thay đổi với 22 bổ sung8 xóa
  1. 9 8
      product-mini/platforms/nuttx/main.c
  2. 13 0
      product-mini/platforms/nuttx/wamr.mk

+ 9 - 8
product-mini/platforms/nuttx/main.c

@@ -21,6 +21,7 @@ static char **app_argv;
 static int
 print_help()
 {
+    /* clang-format off */
     printf("Usage: iwasm [-options] wasm_file [args...]\n");
     printf("options:\n");
     printf("  -f|--function name     Specify a function name of the module to run rather\n"
@@ -46,6 +47,7 @@ print_help()
 #if WASM_ENABLE_LIB_PTHREAD != 0
     printf("  --max-threads=n        Set maximum thread number per cluster, default is 4\n");
 #endif
+    /* clang-format on */
     return 1;
 }
 
@@ -89,10 +91,8 @@ validate_env_str(char *env)
 }
 #endif
 
-#define USE_GLOBAL_HEAP_BUF 1
-
-#if USE_GLOBAL_HEAP_BUF != 0
-static char global_heap_buf[164 * 1024] = { 0 };
+#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
+static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE * BH_KB] = { 0 };
 #endif
 
 #if WASM_ENABLE_MULTI_MODULE != 0
@@ -105,12 +105,13 @@ handle_module_path(const char *module_path)
 
 static char *module_search_path = ".";
 static bool
-module_reader_callback(const char *module_name, uint8 **p_buffer,
+module_reader_callback(const char *module_name,
+                       uint8 **p_buffer,
                        uint32 *p_size)
 {
     const char *format = "%s/%s.wasm";
-    int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) +
-             strlen(".wasm") + 1;
+    int sz = strlen(module_search_path) + strlen("/") + strlen(module_name)
+             + strlen(".wasm") + 1;
     char *wasm_file_name = BH_MALLOC(sz);
     if (!wasm_file_name) {
         return false;
@@ -245,7 +246,7 @@ main(int argc, char *argv[])
 
     memset(&init_args, 0, sizeof(RuntimeInitArgs));
 
-#if USE_GLOBAL_HEAP_BUF != 0
+#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
     init_args.mem_alloc_type = Alloc_With_Pool;
     init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
     init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);

+ 13 - 0
product-mini/platforms/nuttx/wamr.mk

@@ -113,6 +113,19 @@ else
 CFLAGS += -DWASM_DISABLE_HW_BOUND_CHECK=0
 endif
 
+ifeq ($(CONFIG_INTERPRETERS_WAMR_CUSTOM_NAME_SECTIONS),y)
+CFLAGS += -DWASM_ENABLE_CUSTOM_NAME_SECTION=1
+else
+CFLAGS += -DWASM_ENABLE_CUSTOM_NAME_SECTION=0
+endif
+
+ifeq ($(CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL),y)
+CFLAGS += -DWASM_ENABLE_GLOBAL_HEAP_POOL=1
+CFLAGS += -DWASM_GLOBAL_HEAP_SIZE=$(CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL_SIZE)
+else
+CFLAGS += -DWASM_ENABLE_GLOBAL_HEAP_POOL=0
+endif
+
 CFLAGS += -DBH_ENABLE_MEMORY_PROFILING=0
 
 CFLAGS += -Wno-strict-prototypes -Wno-shadow -Wno-unused-variable