fixed: incorrect function mapping number
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 17 Jan 2024 18:55:16 +0000 (12:55 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 17 Jan 2024 18:55:16 +0000 (12:55 -0600)
.gitignore
compiler/include/wasm_emit.h
compiler/src/wasm_emit.c

index 83b48b219d5b0460ca1093731856c880bac2f894..ebe28ebfdc3fd317c2de2485b6d9d5b0b35115cc 100644 (file)
@@ -27,3 +27,4 @@ compiler/onyx
 runtime/onyx_runtime.so
 runtime/onyx_runtime.dylib
 runtime/onyx_runtime.dll
+.clangd
index cb671b0e991ff8df87f7fdefab4fa41a9cd337ca..c947ba396d56295e9483d0569880171a9e442223 100644 (file)
@@ -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 )
index 8b913745e414a513c30b0c7c72cd6146c3d67a62..f00a4e13b386420c235fdc224e094a74a5810f30 100644 (file)
@@ -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;
     }
 
@@ -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);
 
@@ -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);
@@ -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) {