From a1afed19f88612d78419a9730f9fcfcc6a76aae1 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 2 Jul 2021 14:40:11 -0500 Subject: [PATCH] added parsing of sections --- src/main.onyx | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/main.onyx b/src/main.onyx index 8e1a0dc..48635c2 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -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); } -- 2.25.1