From 146eecb28a54509bcfd278dfec8d2a615b52d2d4 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Wed, 12 Jun 2024 12:10:09 +0200 Subject: [PATCH] fix binary_to_text order of fields --- src/binary_to_text/binary_to_text.ml | 6 ++++++ test/wasm2wat/dune | 2 +- test/wasm2wat/from_c.c | 6 ++++++ test/wasm2wat/from_c.t | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/wasm2wat/from_c.c create mode 100644 test/wasm2wat/from_c.t diff --git a/src/binary_to_text/binary_to_text.ml b/src/binary_to_text/binary_to_text.ml index 0ad58aca4..b07b90b60 100644 --- a/src/binary_to_text/binary_to_text.ml +++ b/src/binary_to_text/binary_to_text.ml @@ -104,6 +104,7 @@ let from_global (global : (Binary.global, binary global_type) Runtime.t Named.t) let desc = Import_global (assigned_name, convert_global_type desc) in MImport { modul; name; desc } :: acc ) global [] + |> List.rev let from_table (table : (binary table, binary table_type) Runtime.t Named.t) : Text.module_field list = @@ -117,6 +118,7 @@ let from_table (table : (binary table, binary table_type) Runtime.t Named.t) : let desc = Import_table (assigned_name, convert_table_type desc) in MImport { modul; name; desc } :: acc ) table [] + |> List.rev let from_mem (mem : (mem, limits) Runtime.t Named.t) : Text.module_field list = Named.fold @@ -127,6 +129,7 @@ let from_mem (mem : (mem, limits) Runtime.t Named.t) : Text.module_field list = let desc = Import_mem (assigned_name, desc) in MImport { modul; name; desc } :: acc ) mem [] + |> List.rev let from_func (func : (binary func, binary block_type) Runtime.t Named.t) : Text.module_field list = @@ -143,6 +146,7 @@ let from_func (func : (binary func, binary block_type) Runtime.t Named.t) : let desc = Import_func (assigned_name, convert_block_type desc) in MImport { modul; name; desc } :: acc ) func [] + |> List.rev let from_elem (elem : Binary.elem Named.t) : Text.module_field list = Named.fold @@ -150,6 +154,7 @@ let from_elem (elem : Binary.elem Named.t) : Text.module_field list = let elem = convert_elem elem in MElem elem :: acc ) elem [] + |> List.rev let from_data (data : Binary.data Named.t) : Text.module_field list = Named.fold @@ -157,6 +162,7 @@ let from_data (data : Binary.data Named.t) : Text.module_field list = let data = convert_data data in MData data :: acc ) data [] + |> List.rev let from_exports (exports : Binary.exports) : Text.module_field list = let global = diff --git a/test/wasm2wat/dune b/test/wasm2wat/dune index 6a5ae85be..96c266db1 100644 --- a/test/wasm2wat/dune +++ b/test/wasm2wat/dune @@ -1,2 +1,2 @@ (cram - (deps %{bin:owi} done.wasm m.wasm locals.wasm locals_drop.wasm)) + (deps %{bin:owi} done.wasm from_c.c m.wasm locals.wasm locals_drop.wasm)) diff --git a/test/wasm2wat/from_c.c b/test/wasm2wat/from_c.c new file mode 100644 index 000000000..d496bdb7f --- /dev/null +++ b/test/wasm2wat/from_c.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + owi_assert(1); + return 0; +} diff --git a/test/wasm2wat/from_c.t b/test/wasm2wat/from_c.t new file mode 100644 index 000000000..c88838765 --- /dev/null +++ b/test/wasm2wat/from_c.t @@ -0,0 +1,5 @@ + $ owi c from_c.c + All OK + $ owi wasm2wat a.out.wasm > a.out.wat + $ owi sym a.out.wat + All OK