How to use the @webassemblyjs/wast-parser.parse function in @webassemblyjs/wast-parser

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 / 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 / webassemblyjs / src / index.js View on Github external
instantiateFromSource(
    content: string,
    importObject: ImportObject = {}
  ): Instance {
    const ast = parse(content);
    const module = createCompiledModule(ast);

    console.warn("using deprecated instantiateFromSource");

    return new Instance(module, importObject);
  },
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
function parseQuoteModule(node /*: QuoteModule */) {
    const raw = node.string.join("");
    parse(raw);
  }