working on it ...

Filters

Explore Public Snippets

Sort by

Found 30 snippets matching: webassembly

    external by axic  4  0  1  0

    "Hello World" in Brainf* compiled to eWASM using https://github.com/axic/bf-compiler-webassembly/tree/ewasm

    "Hello World" in Brainf* compiled to eWASM using https://github.com/axic/bf-compiler-webassembly/tree/ewasm: hello.bf.wast
    ;; "Hello World" in Brainf* compiled to eWASM using https://github.com/axic/bf-compiler-webassembly/tree/ewasm
    
    (module
      
      (func $callDataCopy (import "ethereum" "callDataCopy") (param i32 i32 i32))
      (func $return (import "ethereum" "return") (param i32 i32))
      (global $writeptr (mut i32) (i32.const 1))
      (global $readptr (mut i32) (i32.const 0))
      (func $getchar
        (result i32)
        (call $callDataCopy (get_global $readptr) (i32.const 0) (i32.const 1))
        (set_global $readptr (i32.add (get_global $readptr) (i32.const 1)))
        (i32.load8_u (i32.const 0))
      )
      (func $putchar
        (param $value i32)
        (i32.store8 (get_global $writeptr) (get_local $value))
        (set_global $writeptr (i32.add (get_global $writeptr) (i32.const 1)))
        ;; verify we do not overwrite 256 bytes here..
      )
    
      (memory $0 (export "memory") 1 1)
    
      (func (export "main") (local $ptr i32) (set_local $ptr (i32.const 257))
        (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
            (set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; >
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; <
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
        (block ;; [
          (loop
            (br_if 1 (i32.eqz (i32.load8_s (get_local $ptr))))
            (i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; -
            (br 0)
          )
        ) ;; ]
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; +
        (i32.load8_s (get_local $ptr)) (call $putchar) ;; .
    
      (call $return (i32.const 1) (i32.sub (get_global $writeptr) (i32.const 1)))
        )
    )
    
    
    
    

    external by Seth Thompson  1581  3  3  0

    WebAssembly "Hello World" in V8

    WebAssembly "Hello World" in V8: e2e-wasm.md
    ## WebAssembly "Hello World" in V8
    
    :checkered_flag: This document aims to show the end-to-end WebAssembly toolchain working in the V8 engine, starting with a "hello world" C source file and ending with code executing at native speed in V8.
    
    > Note: instead of printing a string, our "hello world" program adds two integers.
    
    ### Prerequisites
    
    You will need `git`, `make`, `cmake`, `ninja`, and `python` (2.7) to build the full toolchain.
    
    On OSX, after installing Xcode and [Homebrew](http://brew.sh/) you can install the remaining dependencies with:
    
    ```
    $ brew install cmake ninja
    ```
    
    ### Building the toolchain
    
    1. Fetch LLVM and Clang:
    
    	```
    	# See: http://llvm.org/docs/GettingStarted.html
    	# LLVM is also distributed with Chrome, but it's not updated frequently enough for our purpose.
    	$ git clone http://llvm.org/git/llvm.git
    	$ cd llvm
    	$ git config branch.master.rebase true
    	$ cd tools
    	$ git clone http://llvm.org/git/clang.git
    	$ cd clang
    	$ git config branch.master.rebase true
    	$ cd ../../..
    	```
    
    2. Fetch the experimental [syntax-rewriter / fake-linker](https://github.com/WebAssembly/experimental/tree/master/prototype-wasmate):
    
    	```
    	$ git clone git@github.com:WebAssembly/experimental.git
    	```
    
    3. Fetch the [translator](https://github.com/WebAssembly/sexpr-wasm-prototype) from s-expressions to v8-native bytecode:
    
    	```
    	$ git clone git@github.com:WebAssembly/sexpr-wasm-prototype.git
    	$ cd sexpr-wasm-prototype
    	$ git submodule update --init
    	$ cd ..
    	```
    
    4. Build Clang:
    
    	```
    	$ mkdir out
    	$ cd out
    	# See: http://llvm.org/docs/CMake.html
    	# Build only the WebAssembly and x86 backends, none of the others. x86 is needed because some "generic" tests aren't so generic.
    	$ cmake -G Ninja ../llvm \
    	  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    	  -DCMAKE_C_COMPILER=gcc \
    	  -DCMAKE_CXX_COMPILER=g++ \
    	  -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="WebAssembly" \
    	  -DLLVM_TARGETS_TO_BUILD="X86"
    	$ ninja
    	$ cd ..
    	```
    
    5. Build the translator:
    
    	```
    	$ cd sexpr-wasm-prototype
    	$ make
    	$ scripts/build-d8.sh
    	$ cd ..
    	```
    
    ### Compiling & executing WebAssembly
    
    1. Create an `add.c` source file with the following contents:
    
    	```c
    	int add(int a, int b) {
    		return a+b;
    	}
    	```
    	
    2. Compile, rewrite, and translate `add.c`:
    
    	```
    	$ out/bin/clang -O2 -S --target=wasm32-unknown-unknown add.c -o add.wack
    	$ experimental/prototype-wasmate/wasmate.py add.wack > add.wast
    	$ sexpr-wasm-prototype/out/sexpr-wasm add.wast -o add.wasm
    	```
    
    3. Run your new WebAssembly module!
    
    	```
    	$ sexpr-wasm-prototype/third_party/v8-native-prototype/v8/v8/out/Release/d8 -e "print(WASM.instantiateModule(readbuffer('add.wasm'), {print:print}).add(42, 1337));"
    	```
    
    4. You should see the result `1379` printed to the console. Hooray! :tada: You've compiled and executed your first WebAssembly code.
    
    

    external by Michael Crilly  1139  3  3  0

    WebAssembly rant

    WebAssembly rant: webassembly-rant.md
    Why does WebAssembly feel as though we're going around in a big circle?
    
    Back when I used to play games like "Carmageddon" and "Command & Conquer: Red Alert" on my Windows 98 SE PC, which I do indeed consider to be "back in the day" (I'm sorry about your old age), I used to pop a CD into the optical drive and run the installer. After the installation had completed its tasks, I would run the executable that was the game/application and off I went, never to be heard from again for several hours, sometimes longer, and rarely for an entire weekend.
    
    Fast forward a few years and eventually I was downloading the installers/binaries from the vendor's website, instead of using a CD-ROM. The same process applied: install the game or application, then run the executable. The end results were the same, but the delivery method was different - the software came over the wire instead of some physical form. This made accessibility much better and easier (most of the time for most of the things), and it was a sign of things to come with regards to software delivery.
    
    Pressing our magical non-existent fast forward button again and we enter an age in which some software suites are delivered right in our browsers, such as Google Docs, Microsoft Office 365, Cloud9 IDE, and so on. Now there's no need to even run an installer. Instead you transparently download a large set of JavaScript files, static assests, etc, and the application executes directly in a VM fitted straight into the browser. This kind of behaviour and approach to delivery is excellent for certain types of work, because it simplifies a lot of the complex aspects about developing and delivering software, especially when you think about checking for and providing updates and patches.
    
    Now we come to today. I just read about a newly annouced effort at making web sites even faster again: WebAssembly (https://en.wikipedia.org/wiki/WebAssembly). This new technology allows developers to put there expensive CPU tasks, such as physics, graphics rendering, and so forth, into the browser in a binary format. This binary "code" can then be utilised from human readable JavaScript as a module, as if it were just like any other pure JavaScript module, thus allows developers to vastly improve the performance of critically slow parts of their application.
    
    Overall this is good news and innovation like this is always welcome - we experiment and deploy new ways of working, and just like natural selection, we select what works and what does not, and move forward. And this selection process isn't just an exclusive club for the engineers and developers involved in our industry: consumers have an incredibly powerful voice when it comes to telling us what does and does not work too, and we have no choice but to listen. I enjoy this process of theory to practice, iteration and reform, improvements, and evetnaully retirement as something better replaces what we currently have.
    
    That being said, I feel we're going around in a big circle here. What WebAssembly is now introducing to developers is another means of delivering a binary/executable to our systems and having us execute it, except it's an automatic process with regards to the download and the installation. Combined with JavaScript, WebAssembly cuts out the need to click "Next" fifteen times or even click "Download" on a vendor's website. That is, once a consumer visits our fancy new WebAssembly powered browser based game, they download a binary, it's installed locally, and then it is executed. The consumer then, well, consumes the end product. All that has changed is the need to click "Download", wait N minutes, "Next", "Next", "Finish."
    
    Instead of slowly creeping forwards (or is it backwards?) towards what I was doing back in 1998, but with an automated download and installation process, can we not simply jump to the good stuff: embed a URL address bar into my operating system of choice; allow me to type in a vendor's installation URL; this triggers a background download and an automated installation process; the software is installed on my SSD and then starts up, waiting for me to consume it. Wait, that sounds familiar...
    
    We already have the Apple iOS App Store; we already have the same thing on OSX; Microsoft have followed along; gaming consoles are doing the same thing, too. These systems allow a developer to write and distribute software on platforms with ease (I've never done it, to be fair, so I will admit I'm making some wild assumptions here), and the end user can install them with ease by searching for them, clicking a button, and then enjoying the automatically deployed software. Why isn't this route being utilised more, instead of these heavy browsers acting as bloated middlemen delivering half-arsed software that works in a half-arsed manner (unless you spent A LOT of money getting it right?) I want native binaries, even if they're written in JavaScript and use Electron, not a massive browser that is acting as a second operating system on top of my operating system.
    
    One possible answer is the fact JavaScript, and now WebAssembly, allows all these applications to be written in a single set of languages, but then deployed across multiple platforms. But we have efforts like Electron to allow a developer to write in JavaScript and deploy a more "native" application to the end user's system? Sure, that's just a WebView wrapped in a native "shell" or, if you like, a small micro-browser, but I would much rather have that delivered via an automated process, such as an App Store, than having to work within the restricted view port of my browser window with very little of the OS integration. I also don't want the GBs of RAM being (ab)used, neither.
    
    I don't like the idea of making browsers the place to launch complex applications. Google thought, and maybe still thinks, it's the way to go, but I don't see many ChromeOS devices at my place of work, at conferences, nor, well, anywhere frankly. They're rare because I feel very few people want the kind of limited experience ChromeOS offers: slow, clumsy, limited JavaScript based applications upgraded under your feet without your consent or desire.
    
    I think the future looks bright, and I'm confident we'll all get this right eventually. I also think it'll be interesting to see where this goes, which hopefully isn't back to 1998, because the music back then sucked.
    
    
    

    external by Benjamin C Meyer  115  7  2  0

    WebAssembly hello world

    WebAssembly hello world: helloworld.wast
    ;; WAST Hello World
    
    (module
      (memory 1 1
       (segment 0 "hello world!\n")
      )
      (import $__fwrite "env" "_fwrite" (param i32 i32 i32 i32) (result i32))
      (import $_get__stdout "env" "get__stdout" (param) (result i32))
    
      (func "main" (result i32)
        (local $stdout i32)
        (set_local $stdout (i32.load align=4 (call_import $_get__stdout)))
    
        (return (call_import $__fwrite
           (i32.const 0)        ;; void *ptr    => Address of 'Hello world!' string
           (i32.const 1)        ;; size_t size  => Data size
           (i32.const 13)       ;; size_t nmemb => 13 characters long
           (get_local $stdout)) ;; stream
        ))
      )
    )
    
    

    external by Mildred Ki'Lya  375  0  3  0

    WebAssembly Dynamic Linking

    WebAssembly Dynamic Linking: README.md
    WebAssembly Modules Virtual Memory and Dynamic Linking
    ======================================================
    
    A module can link to another module to access its functions. There are multiple ways to link modules together depending on how we want to share the virtual memory:
    
    - the importer and the imported share the same virtual memory
    - the importer and the imported don't share any virtual memory segment
    - the imported is loaded in the virtual memory of the importer but doesn't have access to it
    - the imported module have access to the importer virtual memory, but the importer don't have access to the imported memory
    
    Function calls work in each of these cases, but passing pointers ar argument or return values may not work in every case. Two strategies must be used to allow sharing blocks of data using pointers:
    
    - In case a module memory is mapped completely in another module memory, a translation operation must allow the container module to map a pointer from a modle to the other. Much like the way the linux kernel have an operation to map the  userspace pointers to kernel-space pointers.
    - In case a module wants to share a pointer with another module that don't have access to its memory, an operation must be defined to declare the memory segment that is to be shared with the other module securely, and the other module must have an operation to map the allowed memory segment somewhere in its virtual memory.
    
    Possible implementation
    -----------------------
    
    See https://github.com/WebAssembly/design/blob/master/FutureFeatures.md#finer-grained-control-over-memory
    
    
    

    external by ?????  38  0  1  0

    series on WebAssembly and what makes it fast超訳

    series on WebAssembly and what makes it fast超訳: a-cartoon-intro-to-webassembly.md
    ちゃんとしたところに上げられるほどちゃんと訳してないのでこっそりこの辺に。。。
    
    <!--
    # A cartoon intro to WebAssembly
    -->
    # 絵で見る WebAssembly ことはじめ
    
    <!--
    WebAssembly is fast. You’ve probably heard this. But what is it that makes WebAssembly fast?
    -->
    WebAssembly は速い。多分あなたはそう聞いたことがあるでしょう。ですがなぜ WebAssembly は速くなるのでしょうか?
    
    <!--
    In this series, I want to explain to you why WebAssembly is fast.
    -->
    このシリーズでは、WebAssembly がなぜ速いのかを解説したいと思います。
    
    <!--
    ## Wait, so what is WebAssembly?
    -->
    ## まってまって、そもそも WebAssembly って何?
    
    <!--
    WebAssembly is a way of taking code written in programming languages other than JavaScript and running that code in the browser. So when people say that WebAssembly is fast, what they are comparing it to is JavaScript.
    -->
    WebAssembly は JavaScript 以外のプログラミング言語でコードを書いてブラウザの中でそのコードを実行する方法です。WebAssembly は JavaScript と比べて速いと言われています。
    
    <!--
    Now, I don’t want to imply that it’s an either/or situation — that you’re either using WebAssembly or using JavaScript. In fact, we expect that developers will use both WebAssembly and JavaScript in the same application.
    -->
    現状、WebAssembly を使うか JavaScript を使うかといった二者択一の状況を暗示したくありません。もっと言えば、私たちは WebAssembly と JavaScript が同じアプリケーションの中でどちらも使われることを期待しています。
    
    <!--
    But it is useful to compare the two, so you can understand the potential impact that WebAssembly will have.
    -->
    しかし二つを比較することはWebAssembly がどれほどの潜在能力とインパクトを持つか理解するのに役立つでしょう。
    
    <!--
    ## A little performance history
    -->
    ## ちいさなパフォーマンスの歴史
    
    <!--
    JavaScript was created in 1995. It wasn’t designed to be fast, and for the first decade, it wasn’t fast.
    -->
    JavaScript は1995年に作られました。JavaScript は速いことを目指して設計されたわけではありませんでした。そして最初の十年間速くはありませんでした。
    
    <!--
    Then the browsers started getting more competitive.
    -->
    その後各ブラウザはさらなる競争を始めました。
    
    <!--
    In 2008, a period that people call the performance wars began. Multiple browsers added just-in-time compilers, also called JITs. As JavaScript was running, the JIT could see patterns and make the code run faster based on those patterns.
    -->
    2008年になると、パフォーマンス戦争と呼ばれる期間が始まりました。複数のブラウザがジャストインタイムコンパイラ (JITとも呼ばれる) を追加しました。JavaScript が実行されると、JIT はパターンを見てより速いコードを作って実行することができました。
    
    <!--
    The introduction of these JITs led to an inflection point in the performance of JavaScript. Execution of JS was 10x faster.
    -->
    これら JIT の導入が JavaScript のパフォーマンスが大きく進化するポイントにつながりました。JS の実行は10倍速くなったのです。
    
    ![](https://2r4s9p1yi1fa2jd7j43zph8r-wpengine.netdna-ssl.com/files/2017/02/01-01-perf_graph05.png)
    
    <!--
    With this improved performance, JavaScript started being used for things no one ever expected it to be used for, like server-side programming with Node.js. The performance improvement made it feasible to use JavaScript on a whole new class of problems.
    -->
    パフォーマンスが改善されたことで、JavaScript は Node.js を使ったサーバサイドプログラミングのような、それまで考えられなかったものに使われ始めました。パフォーマンスが向上したことで、JavaScript を新たな種類の問題に使える状態になりました。
    
    
    <!--
    We may be at another one of those inflection points now, with WebAssembly.
    -->
    私たちは今、WebAssembly によるもう一つの進化点にいるのかもしれません。
    
    ![](https://2r4s9p1yi1fa2jd7j43zph8r-wpengine.netdna-ssl.com/files/2017/02/01-02-perf_graph10.png)
    
    <!--
    So, let’s dive into the details to understand what makes WebAssembly fast.
    -->
    ですから、何がWebAssembly を速くしているのかを理解するために詳細を掘り下げていきましょう。
    
    <!--
    ### Background:
    -->
    ### 背景:
    
    *   [A crash course in just-in-time (JIT) compilers](https://hacks.mozilla.org/2017/02/a-crash-course-in-just-in-time-jit-compilers/)
    *   [A crash course in assembly](https://hacks.mozilla.org/2017/02/a-crash-course-in-assembly/)
    
    ### WebAssembly, the present:
    
    *   [Where is WebAssembly now and what’s next?](https://hacks.mozilla.org/?p=30522)
    
    
    
    
    
    

    external by David Ackerman  23  0  1  0

    An example of one potential textual representation for WebAssembly

    An example of one potential textual representation for WebAssembly: wasm-example-textual-format
    ;; Example from https://github.com/WebAssembly/spec/blob/05688003a4d5abf31781141f9b3fde588e454414/ml-proto/test/fac.wast
    (module
      ;; Recursive factorial
      (func (param i64) (result i64)
        (if (i64.eq (get_local 0) (i64.const 0))
          (i64.const 1)
          (i64.mul (get_local 0) (call 0 (i64.sub (get_local 0) (i64.const 1))))
        )
      )
    
      ;; Recursive factorial named
      (func $fac-rec (param $n i64) (result i64)
        (if (i64.eq (get_local $n) (i64.const 0))
          (i64.const 1)
          (i64.mul
            (get_local $n)
            (call $fac-rec (i64.sub (get_local $n) (i64.const 1)))
          )
        )
      )
    
      ;; Iterative factorial
      (func (param i64) (result i64)
        (local i64 i64)
        (set_local 1 (get_local 0))
        (set_local 2 (i64.const 1))
        (loop
          (if
            (i64.eq (get_local 1) (i64.const 0))
            (br 2)
            (block
              (set_local 2 (i64.mul (get_local 1) (get_local 2)))
              (set_local 1 (i64.sub (get_local 1) (i64.const 1)))
            )
          )
          (br 0)
        )
        (get_local 2)
      )
    
      ;; Iterative factorial named
      (func $fac-iter (param $n i64) (result i64)
        (local $i i64)
        (local $res i64)
        (set_local $i (get_local $n))
        (set_local $res (i64.const 1))
        (loop $done $loop
          (if
            (i64.eq (get_local $i) (i64.const 0))
            (br $done)
            (block
              (set_local $res (i64.mul (get_local $i) (get_local $res)))
              (set_local $i (i64.sub (get_local $i) (i64.const 1)))
            )
          )
          (br $loop)
        )
        (get_local $res)
      )
    
      ;; More-realistically optimized factorial.
      (func $fac-opt (param i64) (result i64)
        (local i64)
        (set_local 1 (i64.const 1))
        (block
          (br_if 0 (i64.lt_s (get_local 0) (i64.const 2)))
          (loop
            (set_local 1 (i64.mul (get_local 1) (get_local 0)))
            (set_local 0 (i64.add (get_local 0) (i64.const -1)))
            (br_if 0 (i64.gt_s (get_local 0) (i64.const 1)))
          )
        )
        (get_local 1)
      )
    
      (export "fac-rec" 0)
      (export "fac-iter" 2)
      (export "fac-rec-named" $fac-rec)
      (export "fac-iter-named" $fac-iter)
      (export "fac-opt" $fac-opt)
    )
    
    (assert_return (invoke "fac-rec" (i64.const 25)) (i64.const 7034535277573963776))
    (assert_return (invoke "fac-iter" (i64.const 25)) (i64.const 7034535277573963776))
    (assert_return (invoke "fac-rec-named" (i64.const 25)) (i64.const 7034535277573963776))
    (assert_return (invoke "fac-iter-named" (i64.const 25)) (i64.const 7034535277573963776))
    (assert_return (invoke "fac-opt" (i64.const 25)) (i64.const 7034535277573963776))
    (assert_trap (invoke "fac-rec" (i64.const 1073741824)) "call stack exhausted")
    
    

    external by Dmitriy Tsvettsikh  19  0  1  0

    WebAssembly perfomance benchmark using sha256 hash function (webcrypto vs wasm vs purejs)

    WebAssembly perfomance benchmark using sha256 hash function (webcrypto vs wasm vs purejs): readme.md
    ### EDGE 16
    ```
    web crypto, sha256, 100b => 1008.4497350333218 ms
    web crypto, sha256, 1kb  => 903.4996432100079 ms
    web crypto, sha256, 1mb, => 5014.709870780293 ms
    ```
    ```
    wasm, sha256, 100b => 132.54009608607643 ms
    wasm, sha256, 1kb => 179.85521845231761 ms
    wasm, sha256, 1mb => 8170.995884407639 ms
    ```
    ```
    purejs, sha256, 100b => 1200.030215533925528 ms
    purejs, sha256, 1kb => 11400.5952708283291 ms
    purejs, sha256, 1mb => 1121100.685450194661 ms
    ```
    
    ### FF56
    ```
    web crypto, sha256, 100b => 308.7900000000011 ms
    web crypto, sha256, 1kb  => 589.5950000000004 ms
    web crypto, sha256, 1mb, => 5989.394999999997 ms
    ```
    ```
    wasm, sha256, 100b => 34.25999999999996 ms
    wasm, sha256, 1kb => 124.39000000000024 ms
    wasm, sha256, 1mb => 9864.510000000007 ms
    ```
    ```
    purejs, sha256, 100b => 49.40999999999994 ms
    purejs, sha256, 1kb => 237.2100000000003 ms
    purejs, sha256, 1mb => 27529.24 ms
    ```
    
    ### Chrome 62
    ```
    web crypto, sha256, 100b => 696.8399999999992 ms
    web crypto, sha256, 1kb  => 684.0850000000047 ms
    web crypto, sha256, 1mb, => 2886.389999999997 ms
    ```
    
    ```
    wasm, sha256, 100b => 34.419999999999334 ms
    wasm, sha256, 1kb => 118.52499999999998 ms
    wasm, sha256, 1mb => 10195.230000000029 ms
    ```
    
    ```
    purejs, sha256, 100b => 62.655000000000825 ms
    purejs, sha256, 1kb => 200.8500000000004 ms
    purejs, sha256, 1mb => 17424.284999999974 ms
    ```
    
    ### node v8.9.0
    ```
    crypto, sha256, 100b => 23.939927399158478 ms
    crypto, sha256, 1kb  => 38.06257098913193 ms
    crypto, sha256, 1mb, => 2166.599143087864 ms
    ```
    ```
    wasm, sha256, 100b => 36.80856317281723 ms
    wasm, sha256, 1kb  => 119.95224261283875 ms
    wasm, sha256, 1mb, => 9653.785854697227 ms
    ```
    ```
    purejs, sha256, 100b => 53.89913809299469 ms
    purejs, sha256, 1kb => 178.37918442487717 ms
    purejs, sha256, 1mb => 17104.98959070444 ms
    ```
    
    ### iOS 11.1 (iPad Air)
    ```
    crypto, sha256, 100b => 2635 ms
    crypto, sha256, 1kb  => 2782.3 ms
    crypto, sha256, 1mb  => 2019.9 ms
    ```
    ```
    wasm, sha256, 100b => 255.7 ms
    wasm, sha256, 1kb  => 283.5 ms
    wasm, sha256, 1mb, => 17581.9 ms
    ```
    ```
    purejs, sha256, 100b => 194.3 ms
    purejs, sha256, 1kb => 530.1 ms
    purejs, sha256, 1mb => 45943.2 ms
    ```
    
    ### Android 6.0.1, Chrome 62 (Oneplus One)
    ```
    crypto, sha256, 100b => 2950.4 ms
    crypto, sha256, 1kb  => 2639.79 ms
    crypto, sha256, 1mb  => 31057 ms
    ```
    ```
    wasm, sha256, 100b => 365.27 ms
    wasm, sha256, 1kb  => 598.3 ms
    wasm, sha256, 1mb, => 30201.37 ms
    ```
    ```
    purejs, sha256, 100b => 535.41 ms
    purejs, sha256, 1kb  => 1377.27 ms
    purejs, sha256, 1mb, => 123466.925 ms
    ```
    
    ### Android 6.0.1, Firefox 56 (Oneplus One)
    ```
    crypto, sha256, 100b => 78700.525 ms
    crypto, sha256, 1kb  => 90700.2 ms
    crypto, sha256, 1mb  => 35100.38 ms
    ```
    ```
    wasm, sha256, 100b => 249.7 ms
    wasm, sha256, 1kb  => 449.65 ms
    wasm, sha256, 1mb, => 31828.92 ms
    ```
    ```
    purejs, sha256, 100b => 3200.96 ms
    purejs, sha256, 1kb  => 2100 ms
    purejs, sha256, 1mb, => 105200.48 ms
    ```
    
    

    external by mirkosertic  13  0  1  0

    WebAssembly call_indirect example

    WebAssembly call_indirect example: gistfile1.txt
    (module
       (type $_type (func (param f32) (param f32) (result f32))) ;; we need a signature for the indirect call
       (memory 256 256)
       
       (table 128 anyfunc) ;; Table with function pointers
       (elem (i32.const 0) $div) ;; function pointer with index 0 points to $div function
    
       (func $div (param $p1 f32) (param $p2 f32) (result f32)
            (f32.div
              (get_local $p1)
              (get_local $p2)
            )
       )
    
       (func $div2 (param $p1 f32) (param $p2 f32) (result f32)
         (call $div
           (get_local $p1)
           (get_local $p2)
         )
       )
    
       (func $div2 (param $p1 f32) (param $p2 f32) (result f32)
    	  (call_indirect $_type ;; we need the signature of the function for validation
    	       (get_local $p1)
    	       (get_local $p2)
    		     (i32.const 0) ;; this is the index into the table!!
    	  )
       )
    
        (global $STACKTOP (mut i32) (i32.const 0))
        (export "testdiv" (func $div))
        (export "testdivB" (func $div2))
    )
    
    
    

    external by Blind-Striker  13  0  1  0

    C++ example for WebAssembly

    C++ example for WebAssembly: fact.cpp
    int factorial(int n)
    {
        if(n > 1)
            return n * factorial(n - 1);
        else
            return 1;
    }
    
    
    • Public Snippets
    • Channels Snippets