wabt icon indicating copy to clipboard operation
wabt copied to clipboard

Can we get opcode count for each function?

Open AchalaSB opened this issue 4 years ago • 1 comments

Hi, The wasm-opcodecnt tool gives me the opcode count of whole binary file. But I wanted to know the opcode count for each function. Is there any way to get that info? Ex:

(module
  (type $t0 (func (param f64 f64) (result f64)))
  (func $sum (type $t0) (param $p0 f64) (param $p1 f64) (result f64)
    local.get $p0
    local.get $p1
    f64.add)
  (func $sub (type $t0) (param $p0 f64) (param $p1 f64) (result f64)
    local.get $p0
    local.get $p1
    f64.sub)
  (table $T0 1 1 funcref)
  (memory $memory 16)
  (global $g0 (mut i32) (i32.const 1048576))
  (global $__data_end i32 (i32.const 1048576))
  (global $__heap_base i32 (i32.const 1048576))
  (export "memory" (memory 0))
  (export "sum" (func $sum))
  (export "sub" (func $sub))
  (export "__data_end" (global 1))
  (export "__heap_base" (global 2)))

For the above code it gives me opcode count as

Total opcodes: 8
Opcode counts:
local.get: 4
end: 2
f64.add: 1
f64.sub: 1

Instead, I wanted something like

Opcode counts for sum :
local.get: 2
end: 1
f64.add: 1

Opcode counts for sub:
local.get: 2
end: 1
f64.sub: 1

AchalaSB avatar Sep 09 '20 04:09 AchalaSB

This isn't currently implemented, but it should be possible to add it without too much additional code. If you'd like to give it a try, feel free to send a PR!

binji avatar Sep 10 '20 17:09 binji