【问题标题】:Compilation to the web编译到网络
【发布时间】:2017-09-20 09:47:09
【问题描述】:

WebAssembly 将代码编译成什么格式?

来自官方网站:

WebAssembly or wasm is a new portable, size- and load-time-efficient format 
suitable for compilation to the web.

【问题讨论】:

    标签: web compilation webassembly


    【解决方案1】:

    WebAssembly 被编译为二进制格式,并且通常以二进制格式分发。

    例如,这是一个简单的 C 函数:

    int increment(int input) {
      return ++input;
    }
    

    编译如下:

    00000000: 0061 736d 0100 0000 0106 0160 017f 017f  .asm.......`....
    00000010: 0302 0100 0404 0170 0000 0503 0100 0107  .......p........
    00000020: 1602 066d 656d 6f72 7902 0009 696e 6372  ...memory...incr
    00000030: 656d 656e 7400 000a 0901 0700 2000 4101  ement....... .A.
    00000040: 6a0b   
    

    您可以在WebAssembly design documents 中找到此二进制编码的规范。

    但是,如果您想查看编译后的输出,可以使用wasm2wast 工具将其转换为更易读的文本格式(S 表达式)。这是相同的代码:

    (module
     (table 0 anyfunc)
     (memory $0 1)
     (export "memory" (memory $0))
     (export "increment" (func $increment))
     (func $increment (param $0 i32) (result i32)
      (i32.add
       (get_local $0)
       (i32.const 1)
      )
     )
    )
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 2019-07-13
    相关资源
    最近更新 更多