enable pthread for AoT && update AOT current version to 2 (#311)
This commit is contained in:
@ -344,43 +344,12 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static AOTExportFunc *
|
||||
aot_create_export_funcs(const WASMModule *module,
|
||||
uint32 export_func_count)
|
||||
{
|
||||
AOTExportFunc *export_funcs;
|
||||
uint64 size;
|
||||
uint32 i, j = 0;
|
||||
|
||||
/* Allocate memory */
|
||||
size = sizeof(AOTExportFunc) * (uint64)export_func_count;
|
||||
if (size >= UINT32_MAX
|
||||
|| !(export_funcs = wasm_runtime_malloc((uint32)size))) {
|
||||
aot_set_last_error("allocate memory failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create each export function */
|
||||
for (i = 0; i < module->export_count; i++) {
|
||||
if (module->exports[i].kind == EXPORT_KIND_FUNC) {
|
||||
export_funcs[j].func_name = module->exports[i].name;
|
||||
export_funcs[j].func_index = module->exports[i].index;
|
||||
export_funcs[j].func_type =
|
||||
module->functions[module->exports[i].index
|
||||
- module->import_function_count]->func_type;
|
||||
/* Function pointer to be linked in JIT mode */
|
||||
export_funcs[j].func_ptr = NULL;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return export_funcs;
|
||||
}
|
||||
|
||||
AOTCompData*
|
||||
aot_create_comp_data(WASMModule *module)
|
||||
{
|
||||
AOTCompData *comp_data;
|
||||
uint32 import_global_data_size = 0, global_data_size = 0, i;
|
||||
uint32 import_global_data_size = 0, global_data_size = 0, i, j;
|
||||
uint64 size;
|
||||
|
||||
/* Allocate memory */
|
||||
if (!(comp_data = wasm_runtime_malloc(sizeof(AOTCompData)))) {
|
||||
@ -390,22 +359,49 @@ aot_create_comp_data(WASMModule *module)
|
||||
|
||||
memset(comp_data, 0, sizeof(AOTCompData));
|
||||
|
||||
/* Set memory page count */
|
||||
if (module->import_memory_count) {
|
||||
comp_data->num_bytes_per_page =
|
||||
module->import_memories[0].u.memory.num_bytes_per_page;
|
||||
comp_data->mem_init_page_count =
|
||||
module->import_memories[0].u.memory.init_page_count;
|
||||
comp_data->mem_max_page_count =
|
||||
module->import_memories[0].u.memory.max_page_count;
|
||||
comp_data->memory_count = module->import_memory_count + module->memory_count;
|
||||
|
||||
/* TODO: create import memories */
|
||||
|
||||
/* Allocate memory for memory array, reserve one AOTMemory space at least */
|
||||
if (!comp_data->memory_count)
|
||||
comp_data->memory_count = 1;
|
||||
|
||||
size = (uint64)comp_data->memory_count * sizeof(AOTMemory);
|
||||
if (size >= UINT32_MAX
|
||||
|| !(comp_data->memories = wasm_runtime_malloc((uint32)size))) {
|
||||
aot_set_last_error("create memories array failed.\n");
|
||||
goto fail;
|
||||
}
|
||||
else if (module->memory_count) {
|
||||
comp_data->num_bytes_per_page =
|
||||
module->memories[0].num_bytes_per_page;
|
||||
comp_data->mem_init_page_count =
|
||||
module->memories[0].init_page_count;
|
||||
comp_data->mem_max_page_count =
|
||||
module->memories[0].max_page_count;
|
||||
memset(comp_data->memories, 0, size);
|
||||
|
||||
/* Set memory page count */
|
||||
for (i = 0; i < module->import_memory_count + module->memory_count; i++) {
|
||||
if (i < module->import_memory_count) {
|
||||
comp_data->memories[i].memory_flags =
|
||||
module->import_memories[i].u.memory.flags;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->import_memories[i].u.memory.num_bytes_per_page;
|
||||
comp_data->memories[i].mem_init_page_count =
|
||||
module->import_memories[i].u.memory.init_page_count;
|
||||
comp_data->memories[i].mem_max_page_count =
|
||||
module->import_memories[i].u.memory.max_page_count;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->import_memories[i].u.memory.num_bytes_per_page;
|
||||
}
|
||||
else {
|
||||
j = i - module->import_memory_count;
|
||||
comp_data->memories[i].memory_flags =
|
||||
module->memories[j].flags;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->memories[j].num_bytes_per_page;
|
||||
comp_data->memories[i].mem_init_page_count =
|
||||
module->memories[j].init_page_count;
|
||||
comp_data->memories[i].mem_max_page_count =
|
||||
module->memories[j].max_page_count;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->memories[j].num_bytes_per_page;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create memory data segments */
|
||||
@ -415,11 +411,39 @@ aot_create_comp_data(WASMModule *module)
|
||||
aot_create_mem_init_data_list(module)))
|
||||
goto fail;
|
||||
|
||||
/* Set table size */
|
||||
if (module->import_table_count)
|
||||
comp_data->table_size = module->import_tables[0].u.table.init_size;
|
||||
else if (module->table_count)
|
||||
comp_data->table_size = module->tables[0].init_size;
|
||||
/* TODO: create import tables */
|
||||
|
||||
/* Create tables */
|
||||
comp_data->table_count = module->import_table_count + module->table_count;
|
||||
|
||||
if (comp_data->table_count > 0) {
|
||||
size = sizeof(AOTTable) * (uint64)comp_data->table_count;
|
||||
if (size >= UINT32_MAX
|
||||
|| !(comp_data->tables = wasm_runtime_malloc((uint32)size))) {
|
||||
aot_set_last_error("create memories array failed.\n");
|
||||
goto fail;
|
||||
}
|
||||
memset(comp_data->tables, 0, size);
|
||||
for (i = 0; i < comp_data->table_count; i++) {
|
||||
if (i < module->import_table_count) {
|
||||
comp_data->tables[i].elem_type =
|
||||
module->import_tables[i].u.table.elem_type;
|
||||
comp_data->tables[i].table_flags =
|
||||
module->import_tables[i].u.table.flags;
|
||||
comp_data->tables[i].table_init_size =
|
||||
module->import_tables[i].u.table.init_size;
|
||||
comp_data->tables[i].table_max_size =
|
||||
module->import_tables[i].u.table.max_size;
|
||||
}
|
||||
else {
|
||||
j = i - module->import_table_count;
|
||||
comp_data->tables[i].elem_type = module->tables[i].elem_type;
|
||||
comp_data->tables[i].table_flags = module->tables[i].flags;
|
||||
comp_data->tables[i].table_init_size = module->tables[i].init_size;
|
||||
comp_data->tables[i].table_max_size = module->tables[i].max_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Create table data segments */
|
||||
comp_data->table_init_data_count = module->table_seg_count;
|
||||
@ -463,15 +487,11 @@ aot_create_comp_data(WASMModule *module)
|
||||
&& !(comp_data->funcs = aot_create_funcs(module)))
|
||||
goto fail;
|
||||
|
||||
/* Create export functions */
|
||||
for (i = 0; i < module->export_count; i++)
|
||||
if (module->exports[i].kind == EXPORT_KIND_FUNC)
|
||||
comp_data->export_func_count++;
|
||||
|
||||
if (comp_data->export_func_count
|
||||
&& !(comp_data->export_funcs = aot_create_export_funcs
|
||||
(module, comp_data->export_func_count)))
|
||||
goto fail;
|
||||
/* Create llvm aux stack informations */
|
||||
comp_data->llvm_aux_stack_global_index = module->llvm_aux_stack_global_index;
|
||||
comp_data->llvm_aux_data_end = module->llvm_aux_data_end;
|
||||
comp_data->llvm_aux_stack_bottom = module->llvm_aux_stack_bottom;
|
||||
comp_data->llvm_aux_stack_size = module->llvm_aux_stack_size;
|
||||
|
||||
comp_data->start_func_index = module->start_function;
|
||||
comp_data->wasm_module = module;
|
||||
@ -490,10 +510,22 @@ aot_destroy_comp_data(AOTCompData *comp_data)
|
||||
if (!comp_data)
|
||||
return;
|
||||
|
||||
if (comp_data->import_memories)
|
||||
wasm_runtime_free(comp_data->import_memories);
|
||||
|
||||
if (comp_data->memories)
|
||||
wasm_runtime_free(comp_data->memories);
|
||||
|
||||
if (comp_data->mem_init_data_list)
|
||||
aot_destroy_mem_init_data_list(comp_data->mem_init_data_list,
|
||||
comp_data->mem_init_data_count);
|
||||
|
||||
if (comp_data->import_tables)
|
||||
wasm_runtime_free(comp_data->import_tables);
|
||||
|
||||
if (comp_data->tables)
|
||||
wasm_runtime_free(comp_data->tables);
|
||||
|
||||
if (comp_data->table_init_data_list)
|
||||
aot_destroy_table_init_data_list(comp_data->table_init_data_list,
|
||||
comp_data->table_init_data_count);
|
||||
@ -514,9 +546,6 @@ aot_destroy_comp_data(AOTCompData *comp_data)
|
||||
if (comp_data->funcs)
|
||||
aot_destroy_funcs(comp_data->funcs, comp_data->func_count);
|
||||
|
||||
if (comp_data->export_funcs)
|
||||
wasm_runtime_free(comp_data->export_funcs);
|
||||
|
||||
wasm_runtime_free(comp_data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user