cse.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. WScript.Flag("-wasmI64");
  6. function makeModule(type) {
  7. const funcName = `foo_${type}`;
  8. const mod = new WebAssembly.Module(WebAssembly.wabt.convertWast2Wasm(`
  9. (module
  10. (func (export "${funcName}") (param ${type}) (result ${type})
  11. (${type}.sub
  12. (${type}.add (get_local 0) (${type}.const 3))
  13. (${type}.add (get_local 0) (${type}.const 3))
  14. )
  15. )
  16. )`));
  17. const {exports} = new WebAssembly.Instance(mod);
  18. return exports[funcName];
  19. }
  20. const modules = {i32: makeModule("i32"), i64: makeModule("i64")};
  21. function test(type, value) {
  22. const foo = modules[type];
  23. let res = foo(value);
  24. if (type === "i64") {
  25. res = res.low + res.high;
  26. }
  27. if (res !== 0) {
  28. print(`Error: ${type} (${value} + 3) - (${value} + 3) == ${res} !== 0`);
  29. }
  30. }
  31. test("i32", 0);
  32. test("i32", 1);
  33. test("i64", 0);
  34. test("i64", 1);
  35. test("i64", 2 * 4294967296);
  36. print("PASSED");