问题描述
我猜想Wasm二进制文件通常是JIT编译到本机代码的,但是给定Wasm源代码,是否有工具可以查看实际生成的x86-64机器代码?
或以其他方式询问,是否存在使用Wasm并输出本机代码的工具?
I am guessing that a Wasm binary is usually JIT-compiled to native code, but given a Wasm source, is there a tool to see the actual generated x86-64 machine code?Or asked in a different way, is there a tool that consumes Wasm and outputs native code?
推荐答案
在线使用SpiderMonkey编译器将C代码同时编译为WebAssembly和FireFox x86。给出以下简单函数:
The online WasmExplorer compiles C code to both WebAssembly and FireFox x86, using the SpiderMonkey compiler. Given the following simple function:
int testFunction(int* input, int length) {
int sum = 0;
for (int i = 0; i < length; ++i) {
sum += input[i];
}
return sum;
}
这是x86输出:
wasm-function[0]:
sub rsp, 8 ; 0x000000 48 83 ec 08
cmp esi, 1 ; 0x000004 83 fe 01
jge 0x14 ; 0x000007 0f 8d 07 00 00 00
0x00000d:
xor eax, eax ; 0x00000d 33 c0
jmp 0x26 ; 0x00000f e9 12 00 00 00
0x000014:
xor eax, eax ; 0x000014 33 c0
0x000016: ; 0x000016 from: [0x000024]
mov ecx, dword ptr [r15 + rdi] ; 0x000016 41 8b 0c 3f
add eax, ecx ; 0x00001a 03 c1
add edi, 4 ; 0x00001c 83 c7 04
add esi, -1 ; 0x00001f 83 c6 ff
test esi, esi ; 0x000022 85 f6
jne 0x16 ; 0x000024 75 f0
0x000026:
nop ; 0x000026 66 90
add rsp, 8 ; 0x000028 48 83 c4 08
ret
您可以。
WasmExplorer通过服务将代码编译为wasm / x86-您可以看到-您应该能够使用这些脚本自己构建命令行工具。
WasmExplorer compiles code into wasm / x86 via a service - you can see the scripts that are run on Github - you should be able to use these to construct a command-line tool yourself.
这篇关于是否可以使用工具将WebAssembly“组装”为x86-64本机代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!