Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'br $labelName' cause CompileError 'invalid break depth' #14

Closed
JustinSDK opened this issue Sep 15, 2018 · 6 comments
Closed

'br $labelName' cause CompileError 'invalid break depth' #14

JustinSDK opened this issue Sep 15, 2018 · 6 comments
Labels

Comments

@JustinSDK
Copy link

JustinSDK commented Sep 15, 2018

When writing the code:

(module
	(import "env" "log" (func $log (param i32)))
	(func $main
		block $B0
			block $B1
			    br $B1
			    i32.const 3
			    call $log
			end
			i32.const 2
			call $log
		end
		i32.const 1
		call $log
	)
	(start $main)
)

After right-clicking the .wat file, 'Save as WebAssembly binary file' and saving a 'program.wasm' file, l use the html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
  </head>
  <body>
    <script>
    const importObj = {
        env: {
            log(n) {
                console.log(n);
            }
        }
    };
    WebAssembly.instantiateStreaming(fetch('program.wasm'), importObj);
    </script>
  </body>
</html>

And loading it by Chrome, it says:

Uncaught (in promise) CompileError: AsyncCompile: Compiling wasm function #1 failed: invalid break depth: 3228196 @+48
Promise.then (async)
(anonymous) @ (index):15

The same code is ok after assembling and downloading .wasm from WebAssembly Explorer.

@reklatsmasters
Copy link
Contributor

Seems like a bug in libwabt. I hope package https://www.npmjs.com/package/wabt will be updated. If not, i will use webassemblyjs again.

@dcodeIO
Copy link
Contributor

dcodeIO commented Sep 20, 2018

FYI: There are new versions of wabt.js now, preferrably v1.0.5-nightly.20180920. Note that the API to instantiate it has changed a little (WABT now uses Emscripten's MODULARIZE):

// old
var wabt = require("wabt");
// new
var wabt = require("wabt")();

@reklatsmasters
Copy link
Contributor

@dcodeIO Unfortunately, wast@latest and [email protected] compiled that code incorrectly. This is a generated wasm:

(module
  (type $t0 (func (param i32)))
  (type $t1 (func))
  (import "env" "log" (func $log (type $t0)))
  (func $main (type $t1)
    block $B0
      block $B1
        br 3228196 (; INVALID ;)
        i32.const 3
        call $log
      end
      i32.const 2
      call $log
    end
    i32.const 1
    call $log)
  (start 1))

Probably, it's a bug in original wabt?

@dcodeIO
Copy link
Contributor

dcodeIO commented Sep 23, 2018

Seems so, yeah, or somehow just in its JS build. Appears that br $LABEL always becomes br + some pointer value after parsing, as if a string wasn't correctly evaluated/printed.

@dcodeIO
Copy link
Contributor

dcodeIO commented Sep 24, 2018

For a likely solution to the issue, see: WebAssembly/wabt#915 (comment)

@reklatsmasters
Copy link
Contributor

Thanks @dcodeIO @binji for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants