-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinfo.py
43 lines (36 loc) · 1.08 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Display some info about the WASM module, like imports and exports.
"""
from ppci import wasm
filename = 'rocket.wasm'
wasm_data = open(filename, 'rb').read()
wasm_module = wasm.Module(wasm_data)
print(f'WASM file {filename} is {len(wasm_data)/2**10:0.1f} KiB')
wasm_module.show_interface()
# types = wasm_module['type']
# imports = wasm_module['import']
# exports = wasm_module['export']
# functions = wasm_module['func']
#
#
# print('\nImports:')
# for c in imports:
# #c.show()
# assert c.kind == 'func' # we assume only func imports
# sig = types[c.info[0].index]
# print(f' {c.modname}.{c.name}:'.ljust(20), f'{sig.params} -> {sig.result}')
#
# print('\nExports:')
# for c in exports:
# # c.show()
# if c.kind == 'func':
# func = functions[c.ref.index - functions[0].id]
# sig = types[func.ref.index]
# print(f' {c.name}:'.ljust(20), f'{sig.params} -> {sig.result}')
# else:
# print(f' {c.kind} "{c.name}"')
#
#
# # Export it yto textual form
# with open('rocket.wat', 'wt') as f:
# f.write(wasm_module.to_string())