added parsing of sections
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 2 Jul 2021 19:40:11 +0000 (14:40 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 2 Jul 2021 19:40:11 +0000 (14:40 -0500)
src/main.onyx

index 8e1a0dc380fd023a0c07b4828dd60511d371ae03..48635c29c8c43e3d1f42a147a2b98d9fe9811e06 100644 (file)
@@ -7,10 +7,47 @@ main :: (args: [] cstr) {
     wasm_data := #file_contents "data/test.wasm";
     
     wasm_binary := wasm.load(wasm_data);
-    println("Loaded sections");
-    
-    for ^entry: wasm_binary.section_locations.entries {
-        printf("Section number: {}\nOffset: {}\n", entry.key, entry.value);
+    for ^entry: wasm_binary.sections.entries {
+        printf("Section: {}\nOffset: {}\n", entry.key, entry.value);
     }
+
+    wasm_sections := wasm.parse_sections(^wasm_binary, context.allocator);
+    printf("Types:\n{p}\n", wasm_sections.type_section);
+    printf("Imports:\n{p}\n", wasm_sections.import_section);
+    printf("Exports:\n{p}\n", wasm_sections.export_section);
+    printf("Code:\n{}\n", wasm_sections.code_section);
+
+    // type_section := wasm.parse_type_section(^wasm_binary);
+    // printf("Types:\n{}\n", type_section);
+
+    // import_section := wasm.parse_import_section(^wasm_binary);
+    // printf("Imports:\n{p}\n", import_section);
+
+    // export_section := wasm.parse_export_section(^wasm_binary);
+    // printf("Exports:\n{p}\n", export_section);
+
+    // function_section := wasm.parse_function_section(^wasm_binary);
+    // printf("Functions:\n{p}\n", function_section);
+
+    // start_function := wasm.parse_start_section(^wasm_binary);
+    // printf("Start function: {}\n", start_function);
+
+    // memory_section := wasm.parse_memory_section(^wasm_binary);
+    // printf("Memories:\n{p}\n", memory_section);
+
+    // table_section := wasm.parse_table_section(^wasm_binary);
+    // printf("Tables:\n{p}\n", table_section);
+
+    // global_section := wasm.parse_global_section(^wasm_binary);
+    // printf("Globals:\n{p}\n", global_section);
+
+    // element_section := wasm.parse_element_section(^wasm_binary);
+    // printf("Elements:\n{p}\n", element_section);
+
+    // data_section := wasm.parse_data_section(^wasm_binary);
+    // for e: data_section do printf("Data: {} {} {}\n", e.memory_index, e.offset, e.data.count);
+
+    // code_section := wasm.parse_code_section(^wasm_binary);
+    // printf("Code:\n{p}\n", code_section.count);
 }