Skip to content

Commit

Permalink
fix binary_to_text order of fields
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Jun 12, 2024
1 parent 22409f8 commit 146eecb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/binary_to_text/binary_to_text.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand All @@ -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 =
Expand All @@ -143,20 +146,23 @@ 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
(fun _i (elem : Binary.elem) acc ->
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
(fun _i (data : Binary.data) acc ->
let data = convert_data data in
MData data :: acc )
data []
|> List.rev

let from_exports (exports : Binary.exports) : Text.module_field list =
let global =
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2wat/dune
Original file line number Diff line number Diff line change
@@ -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))
6 changes: 6 additions & 0 deletions test/wasm2wat/from_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <owi.h>

int main(void) {
owi_assert(1);
return 0;
}
5 changes: 5 additions & 0 deletions test/wasm2wat/from_c.t
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 146eecb

Please sign in to comment.