Skip to content

Commit

Permalink
Add function-body target
Browse files Browse the repository at this point in the history
  • Loading branch information
acieroid committed Feb 13, 2024
1 parent 2fe3108 commit f59dabc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let () =
; "sizes", Utils.sizes
; "mem-imports", Utils.mem_imports
; "mem-exports", Utils.mem_exports
; "function-instructions", Utils.function_instructions
; "function-instruction-labels", Utils.function_instruction_labels
; "function-body", Utils.function_body
; "functions", Utils.functions
; "count", Utils.count

Expand Down
15 changes: 14 additions & 1 deletion utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ let mem_exports =
| _ -> false) in
Printf.printf "%d\n" count)

let function_instructions =
let function_instruction_labels =
Command.basic
~summary:"Returns the labels of instructions of a given function"
Command.Let_syntax.(
Expand All @@ -134,6 +134,19 @@ let function_instructions =
Instr.Label.Set.iter labels ~f:(fun label ->
Printf.printf "%s\n" (Instr.Label.to_string label)))

let function_body =
Command.basic
~summary:"Returns the body of a given function"
Command.Let_syntax.(
let%map_open file_in = anon ("in" %: string)
and fidx = anon ("fidx" %: int32) in
fun () ->
let wasm_mod = Wasm_module.of_file file_in in
List.iter
(List.find_exn wasm_mod.funcs ~f:(fun f -> Int32.(f.idx = fidx))).code.body
~f:(fun instr ->
Printf.printf "%s\n" (Instr.to_string instr)))

let functions =
Command.basic
~summary:"Returns the indices of functions of a WebAssembly modules, along with their name if they have one"
Expand Down

0 comments on commit f59dabc

Please sign in to comment.