|
<html> |
|
<head> |
|
<script> |
|
// Check for wasm support. |
|
if (!('WebAssembly' in window)) { |
|
alert('you need a browser with wasm support enabled :('); |
|
} |
|
|
|
// Loads a WebAssembly dynamic library, returns a promise. |
|
// imports is an optional imports object |
|
function loadWebAssembly(filename, imports) { |
|
// Fetch the file and compile it |
|
return fetch(filename) |
|
.then(response => response.arrayBuffer()) |
|
.then(buffer => WebAssembly.compile(buffer)) |
|
.then(module => { |
|
// Create the imports for the module, including the |
|
// standard dynamic library imports |
|
imports = imports || {}; |
|
imports.env = imports.env || {}; |
|
imports.env.memoryBase = imports.env.memoryBase || 0; |
|
imports.env.tableBase = imports.env.tableBase || 0; |
|
if (!imports.env.memory) { |
|
imports.env.memory = new WebAssembly.Memory({ initial: 256 }); |
|
} |
|
if (!imports.env.table) { |
|
imports.env.table = new WebAssembly.Table({ initial: 0, element: 'anyfunc' }); |
|
} |
|
// Create the instance. |
|
return new WebAssembly.Instance(module, imports); |
|
}); |
|
} |
|
|
|
// Main part of this example, loads the module and uses it. |
|
loadWebAssembly('hello_world.wasm') |
|
.then(instance => { |
|
var exports = instance.exports; // the exports of that instance |
|
var doubler = exports._doubler; // the "doubler" function (note "_" prefix) |
|
// now we are ready, set up the button so the user can run the code |
|
var button = document.getElementById('run'); |
|
button.value = 'Call a method in the WebAssembly module'; |
|
button.addEventListener('click', function() { |
|
var input = 21; |
|
alert(input + ' doubled is ' + doubler(input)); |
|
}, false); |
|
} |
|
); |
|
</script> |
|
</head> |
|
<body> |
|
<input type="button" id="run" value="(waiting for WebAssembly)"/> |
|
</body> |
|
</html> |
Hi,
I tried to get the debugging of c file in the browser using the following code.
'C' code:
int doubler(int x) {
return 2 * x;
}
compilation code:
emcc hello_world.c -g4 -s WASM=1 -s SIDE_MODULE=1 -s "EXPORTED_FUNCTIONS=['_doubler']" -o hello_world.wasm -g --source-map-base http://localhost:6931/
error:
Unknown option '--all-features'
shared:ERROR: 'D:/GitHub/emsdk/clang/e1.38.30_64bit/binaryen\bin\wasm-as hello_world.wast -o hello_world.wasm --all-features --disable-bulk-memory -g --source-map=hello_world.wasm.map --source-map-url=http://localhost:6931/hello_world.wasm.map' failed (1)
any help would be appreciated.
thanks