Skip to content

Commit

Permalink
fixed: incorrect function mapping number
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanfh committed Jan 17, 2024
1 parent 86f4e60 commit 4c61be0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ compiler/onyx
runtime/onyx_runtime.so
runtime/onyx_runtime.dylib
runtime/onyx_runtime.dll
.clangd
1 change: 1 addition & 0 deletions compiler/include/wasm_emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ typedef struct OnyxWasmModule {

bh_arr(AstFunction *) procedures_with_tags;
bh_arr(AstMemRes *) globals_with_tags;
bh_arr(AstFunction *) all_procedures;

// NOTE: Used internally as a map from strings that represent function types,
// 0x7f 0x7f : 0x7f ( (i32, i32) -> i32 )
Expand Down
30 changes: 22 additions & 8 deletions compiler/src/wasm_emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -4470,14 +4470,7 @@ static i32 assign_function_index(OnyxWasmModule *mod, AstFunction *fd) {
i32 func_idx = (i32) mod->next_func_idx++;
bh_imap_put(&mod->index_map, (u64) fd, (u64) func_idx);

if (context.options->print_function_mappings) {
bh_printf("%d -> %s:%d:%d\n",
func_idx,
fd->token->pos.filename,
fd->token->pos.line,
fd->token->pos.column);
}

bh_arr_push(mod->all_procedures, fd);
return func_idx;
}

Expand Down Expand Up @@ -5249,6 +5242,7 @@ OnyxWasmModule onyx_wasm_module_create(bh_allocator alloc) {
bh_arr_new(global_heap_allocator, module.foreign_blocks, 4);
bh_arr_new(global_heap_allocator, module.procedures_with_tags, 4);
bh_arr_new(global_heap_allocator, module.globals_with_tags, 4);
bh_arr_new(global_heap_allocator, module.all_procedures, 4);
bh_arr_new(global_heap_allocator, module.data_patches, 4);
bh_arr_new(global_heap_allocator, module.code_patches, 4);

Expand Down Expand Up @@ -5281,6 +5275,7 @@ void emit_entity(Entity* ent) {
case Entity_Type_Foreign_Function_Header:
emit_foreign_function(module, ent->function);
bh_imap_put(&module->index_map, (u64) ent->function, module->next_foreign_func_idx++);
bh_arr_push(module->all_procedures, ent->function);

if (ent->function->tags != NULL) {
bh_arr_push(module->procedures_with_tags, ent->function);
Expand Down Expand Up @@ -5560,6 +5555,25 @@ void onyx_wasm_module_link(OnyxWasmModule *module, OnyxWasmLinkOptions *options)
*module->tls_size_ptr = module->next_tls_offset;
bh_align(*module->tls_size_ptr, 16);
}


if (context.options->print_function_mappings) {
bh_arr_each(AstFunction *, pfunc, module->all_procedures) {
AstFunction *func = *pfunc;

u64 func_idx = (u64) bh_imap_get(&module->index_map, (u64) func);

if (!func->is_foreign) {
func_idx += module->next_foreign_func_idx;
}

bh_printf("%d -> %s:%d:%d\n",
func_idx,
func->token->pos.filename,
func->token->pos.line,
func->token->pos.column);
}
}
}

void onyx_wasm_module_free(OnyxWasmModule* module) {
Expand Down

0 comments on commit 4c61be0

Please sign in to comment.