2
0

tracing.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. WScript.Flag("-trace:wasminout");
  7. var {i64ToString} = WScript.LoadScriptFile("./wasmutils.js");
  8. const buf = WebAssembly.wabt.convertWast2Wasm(`
  9. (module
  10. ;; Auxiliary definitions
  11. (func $const-i32 (export "const-i32") (result i32) (i32.const 0x132))
  12. (func $const-i64 (export "const-i64") (result i64) (i64.const 0x164))
  13. (func $const-f32 (export "const-f32") (result f32) (f32.const 0xf32))
  14. (func $const-f64 (export "const-f64") (result f64) (f64.const 0xf64))
  15. (func $id-i32 (export "id-i32") (param i32) (result i32) (get_local 0))
  16. (func $id-i64 (export "id-i64") (param i64) (result i64) (get_local 0))
  17. (func $id-f32 (export "id-f32") (param f32) (result f32) (get_local 0))
  18. (func $id-f64 (export "id-f64") (param f64) (result f64) (get_local 0))
  19. (func $f32-i32 (export "f32-i32") (param f32 i32) (result i32) (get_local 1))
  20. (func $i32-i64 (export "i32-i64") (param i32 i64) (result i64) (get_local 1))
  21. (func $f64-f32 (export "f64-f32") (param f64 f32) (result f32) (get_local 1))
  22. (func $i64-f64 (export "i64-f64") (param i64 f64) (result f64) (get_local 1))
  23. ;; Typing
  24. (func (export "type-i32") (result i32) (call $const-i32))
  25. (func (export "type-i64") (result i64) (call $const-i64))
  26. (func (export "type-f32") (result f32) (call $const-f32))
  27. (func (export "type-f64") (result f64) (call $const-f64))
  28. (func (export "type-first-i32") (param i32) (result i32) (call $id-i32 (get_local 0)))
  29. (func (export "type-first-i64") (param i64) (result i64) (call $id-i64 (get_local 0)))
  30. (func (export "type-first-f32") (param f32) (result f32) (call $id-f32 (get_local 0)))
  31. (func (export "type-first-f64") (param f64) (result f64) (call $id-f64 (get_local 0)))
  32. (func (export "type-second-i32") (param f32 i32) (result i32) (call $f32-i32 (get_local 0) (get_local 1)))
  33. (func (export "type-second-i64") (param i32 i64) (result i64) (call $i32-i64 (get_local 0) (get_local 1)))
  34. (func (export "type-second-f32") (param f64 f32) (result f32) (call $f64-f32 (get_local 0) (get_local 1)))
  35. (func (export "type-second-f64") (param i64 f64) (result f64) (call $i64-f64 (get_local 0) (get_local 1)))
  36. )`);
  37. WebAssembly.instantiate(buf)
  38. .then(({instance: {exports}}) => {
  39. for (const key in exports) {
  40. const res1 = exports[key](32.123, -5);
  41. const res2 = exports[key](3, -45.147);
  42. if (key.endsWith("i64")) {
  43. console.log(i64ToString(res1));
  44. console.log(i64ToString(res2));
  45. } else {
  46. console.log(res1);
  47. console.log(res2);
  48. }
  49. }
  50. return "Done";
  51. })
  52. .then(console.log, console.log)