How to use @webassemblyjs/wast-parser - 10 common examples

To help you get started, we’ve selected a few @webassemblyjs/wast-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xtuc / webassemblyjs / packages / helper-testsuite-runner / src / index.js View on Github external
function loadModule(type: string, filename: string): Instance {
  const internalInstanceOptions = {
    checkForI64InSignature: false,
    returnStackLocal: true
  };

  const importObject = {
    _internalInstanceOptions: internalInstanceOptions
  };

  if (type === "text") {
    const content = readFileSync(join(WASM_TEST_DIR, filename), "utf8");

    // we need a module in order to be compiled
    const ast = parse("(module " + content + ")");

    // TODO(sven): pass fakeCompiler here?
    const module = createCompiledModule(ast);

    return new Instance(module, importObject);
  } else if (type === "binary") {
    // $FlowIgnore
    const buff = readFileSync(join(WASM_TEST_DIR, filename), null);

    const ast = decode(buff, decoderOpts);
    const module = createCompiledModule(ast);
    return new Instance(module, importObject);
  } else {
    throw new Error("unsupported module type: " + type);
  }
}
github xtuc / webassemblyjs / packages / cli / src / wast-to-wasm-semantics.js View on Github external
// @flow

const wastIdentifierToIndex = require("@webassemblyjs/ast/lib/transform/wast-identifier-to-index");
const denormalizeTypeReferences = require("@webassemblyjs/ast/lib/transform/denormalize-type-references");
const { parse } = require("@webassemblyjs/wast-parser");
const { print } = require("@webassemblyjs/wast-printer");
const { readFileSync } = require("fs");

const filename = process.argv[2];

if (typeof filename === "undefined") {
  throw new Error("Missing file");
}

const content = readFileSync(filename, "utf8");
const ast = parse(content);

denormalizeTypeReferences.transform(ast);
wastIdentifierToIndex.transform(ast);

console.log(print(ast));
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
function replEval(input) {
    if (isVerbose === true) {
      console.log(input);
    }

    const ast = parse(input);
    const [node] = ast.body;

    // Empty input, skip this iteration
    if (node === undefined) {
      return;
    }

    if (node.type === "Instr") {
      if (node.id === "assert_invalid") {
        return assert_invalid(node);
      }

      if (node.id === "assert_return") {
        return assert_return(node);
      }
github xtuc / webassemblyjs / packages / cli / src / wastast.js View on Github external
#!/usr/bin/env node
// @flow

const { parseSource } = require("@webassemblyjs/wast-parser");
const { readFileSync } = require("fs");

const filename = process.argv[2];

if (typeof filename === "undefined") {
  throw new Error("Missing file");
}

const content = readFileSync(filename, "utf8");
const ast = parseSource(content);

console.log(JSON.stringify(ast, null, 2));
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
function replEval(input) {
    if (isVerbose === true) {
      onLog(input);
    }

    const ast = parse(input);
    const [node] = ast.body;

    // Empty input, skip this iteration
    if (node === undefined) {
      return;
    }

    if (node.type === "Instr") {
      if (node.id === "assert_invalid") {
        return assert_invalid(node);
      }

      if (node.id === "assert_return") {
        return assert_return(node);
      }
github xtuc / webassemblyjs / packages / ast / src / node-helpers.js View on Github external
} else {
    switch (instructionType) {
      case "i32": {
        return numberLiteral(parse32I(rawValue), String(original));
      }
      case "u32": {
        return numberLiteral(parseU32(rawValue), String(original));
      }
      case "i64": {
        return longNumberLiteral(parse64I(rawValue), String(original));
      }
      case "f32": {
        return floatLiteral(
          parse32F(rawValue),
          isNanLiteral(rawValue),
          isInfLiteral(rawValue),
          String(original)
        );
      }
      // f64
      default: {
        return floatLiteral(
          parse64F(rawValue),
          isNanLiteral(rawValue),
          isInfLiteral(rawValue),
          String(original)
        );
      }
    }
  }
}
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / ast / esm / node-helpers.js View on Github external
return numberLiteral(parse32I(rawValue), String(original));
        }

      case "u32":
        {
          return numberLiteral(parseU32(rawValue), String(original));
        }

      case "i64":
        {
          return longNumberLiteral(parse64I(rawValue), String(original));
        }

      case "f32":
        {
          return floatLiteral(parse32F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
        }
      // f64

      default:
        {
          return floatLiteral(parse64F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
        }
    }
  }
}
export function instruction(id) {
github xtuc / webassemblyjs / packages / ast / src / node-helpers.js View on Github external
return longNumberLiteral(parse64I(rawValue), String(original));
      }
      case "f32": {
        return floatLiteral(
          parse32F(rawValue),
          isNanLiteral(rawValue),
          isInfLiteral(rawValue),
          String(original)
        );
      }
      // f64
      default: {
        return floatLiteral(
          parse64F(rawValue),
          isNanLiteral(rawValue),
          isInfLiteral(rawValue),
          String(original)
        );
      }
    }
  }
}
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / ast / esm / node-helpers.js View on Github external
}

      case "i64":
        {
          return longNumberLiteral(parse64I(rawValue), String(original));
        }

      case "f32":
        {
          return floatLiteral(parse32F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
        }
      // f64

      default:
        {
          return floatLiteral(parse64F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
        }
    }
  }
}
export function instruction(id) {
github xtuc / webassemblyjs / packages / ast / src / node-helpers.js View on Github external
return numberLiteral(rawValue, String(original));
  } else {
    switch (instructionType) {
      case "i32": {
        return numberLiteral(parse32I(rawValue), String(original));
      }
      case "u32": {
        return numberLiteral(parseU32(rawValue), String(original));
      }
      case "i64": {
        return longNumberLiteral(parse64I(rawValue), String(original));
      }
      case "f32": {
        return floatLiteral(
          parse32F(rawValue),
          isNanLiteral(rawValue),
          isInfLiteral(rawValue),
          String(original)
        );
      }
      // f64
      default: {
        return floatLiteral(
          parse64F(rawValue),
          isNanLiteral(rawValue),
          isInfLiteral(rawValue),
          String(original)
        );
      }
    }
  }
}