How to use the @webassemblyjs/ast.func function in @webassemblyjs/ast

To help you get started, we’ve selected a few @webassemblyjs/ast 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 / dce / src / removal.js View on Github external
const t = require("@webassemblyjs/ast");

const emptyFunc = t.func(null, t.signature([], []), []);

module.exports = function removeFunc(moduleExport, ast) {
  const exportName = moduleExport.name;

  // TODO(sven): test if we actually want to delete a func
  const funcName = moduleExport.descr.id.value;

  // console.log(`Remove unused "${exportName}"`);

  t.traverse(ast, {
    Func(path) {
      if (path.node.name.value === funcName) {
        path.replaceWith(emptyFunc);
        // console.log('\t> remove func');
      }
    },
github maxdenaro / maxgraph-youtube-source / JS-плагины №7. Новое подключение swiper.js через npm / node_modules / @webassemblyjs / wast-parser / esm / grammar.js View on Github external
eatToken();
          typeRef = parseTypeReference();
        } else if (lookaheadAndCheck(tokens.name) === true || lookaheadAndCheck(tokens.valtype) === true || token.type === "keyword" // is any keyword
        ) {
            // Instruction
            fnBody.push(parseFuncInstr());
          } else {
          throw function () {
            return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Unexpected token in func body" + ", given " + tokenToString(token));
          }();
        }

        eatTokenOfType(tokens.closeParen);
      }

      return t.func(fnName, typeRef !== undefined ? typeRef : t.signature(fnParams, fnResult), fnBody);
    }
    /**
github xtuc / webassemblyjs / packages / wast-parser / src / grammar.js View on Github external
typeRef = parseTypeReference();
        } else if (
          lookaheadAndCheck(tokens.name) === true ||
          lookaheadAndCheck(tokens.valtype) === true ||
          token.type === "keyword" // is any keyword
        ) {
          // Instruction
          fnBody.push(parseFuncInstr());
        } else {
          throw createUnexpectedToken("Unexpected token in func body");
        }

        eatTokenOfType(tokens.closeParen);
      }

      return t.func(
        fnName,
        typeRef !== undefined ? typeRef : t.signature(fnParams, fnResult),
        fnBody
      );
    }
github maxdenaro / maxgraph-youtube-source / JS-плагины №7. Новое подключение swiper.js через npm / node_modules / @webassemblyjs / wasm-parser / esm / decoder.js View on Github external
if (func.isExternal === true) {
      return;
    }

    var decodedElementInCodeSection = state.elementsInCodeSection[funcIndex];

    if (opts.ignoreCodeSection === false) {
      if (typeof decodedElementInCodeSection === "undefined") {
        throw new CompileError("func " + toHex(funcIndex) + " code not found");
      }

      body = decodedElementInCodeSection.code;
    }

    funcIndex++;
    var funcNode = t.func(func.id, t.signature(params, result), body);

    if (func.isExternal === true) {
      funcNode.isExternal = func.isExternal;
    } // Add function position in the binary if possible


    if (opts.ignoreCodeSection === false) {
      var _startLoc23 = decodedElementInCodeSection.startLoc,
          endLoc = decodedElementInCodeSection.endLoc,
          bodySize = decodedElementInCodeSection.bodySize;
      funcNode = t.withLoc(funcNode, endLoc, _startLoc23);
      funcNode.metadata = {
        bodySize: bodySize
      };
    }
github flaviuse / mern-authentication / client / node_modules / webpack / lib / wasm / WebAssemblyGenerator.js View on Github external
if (typeof startAtFuncOffset === "number") {
		funcBody.push(t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset)));
	}

	for (const instr of additionalInitCode) {
		funcBody.push(instr);
	}

	funcBody.push(t.instruction("end"));

	const funcResults = [];

	// Code section
	const funcSignature = t.signature(funcParams, funcResults);
	const func = t.func(initFuncId, funcSignature, funcBody);

	// Type section
	const functype = t.typeInstruction(undefined, funcSignature);

	// Func section
	const funcindex = t.indexInFuncSection(nextTypeIndex);

	// Export section
	const moduleExport = t.moduleExport(
		initFuncId.value,
		t.moduleExportDescr("Func", nextFuncIndex)
	);

	return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]);
};
github johandb / svg-drawing-tool / node_modules / webpack / lib / wasm / WebAssemblyGenerator.js View on Github external
return [...acc, ...body];
	}, []);

	if (typeof startAtFuncOffset === "number") {
		funcBody.push(t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset)));
	}

	for (const instr of additionalInitCode) {
		funcBody.push(instr);
	}

	const funcResults = [];

	// Code section
	const funcSignature = t.signature(funcParams, funcResults);
	const func = t.func(initFuncId, funcSignature, funcBody);

	// Type section
	const functype = t.typeInstruction(undefined, funcSignature);

	// Func section
	const funcindex = t.indexInFuncSection(nextTypeIndex);

	// Export section
	const moduleExport = t.moduleExport(
		initFuncId.value,
		t.moduleExportDescr("Func", nextFuncIndex)
	);

	return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]);
};
github M0nica / React-Ladies / node_modules / webpack / lib / wasm / WebAssemblyGenerator.js View on Github external
return [...acc, ...body];
	}, []);

	if (typeof startAtFuncOffset === "number") {
		funcBody.push(t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset)));
	}

	for (const instr of additionalInitCode) {
		funcBody.push(instr);
	}

	const funcResults = [];

	// Code section
	const funcSignature = t.signature(funcParams, funcResults);
	const func = t.func(initFuncId, funcSignature, funcBody);

	// Type section
	const functype = t.typeInstruction(undefined, funcSignature);

	// Func section
	const funcindex = t.indexInFuncSection(nextTypeIndex);

	// Export section
	const moduleExport = t.moduleExport(
		initFuncId.value,
		t.moduleExportDescr("Func", nextFuncIndex)
	);

	return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]);
};
github xtuc / webassemblyjs / packages / helper-compiler / src / index.js View on Github external
export function listOfInstructionsToIr(instrs: Array): IR {
  const program = {};
  const funcTable = [];

  const module = new Module(tProgram([]));
  const fakeFunc = func(identifier("main"), [], instrs);

  module.beginFuncBody(fakeFunc);

  instrs.forEach(i => module.onFuncInstruction(i));

  const { name, instructions, startAt } = module.finalizeFunc(fakeFunc);

  funcTable.push({ name, startAt });

  instructions.forEach(instruction => {
    program[instruction.offset] = instruction.node;
  });

  return {
    // $FlowIgnore
    funcTable,
github tamb / domponent / node_modules / webpack / lib / wasm / WebAssemblyGenerator.js View on Github external
if (typeof startAtFuncOffset === "number") {
		funcBody.push(t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset)));
	}

	for (const instr of additionalInitCode) {
		funcBody.push(instr);
	}

	funcBody.push(t.instruction("end"));

	const funcResults = [];

	// Code section
	const funcSignature = t.signature(funcParams, funcResults);
	const func = t.func(initFuncId, funcSignature, funcBody);

	// Type section
	const functype = t.typeInstruction(undefined, funcSignature);

	// Func section
	const funcindex = t.indexInFuncSection(nextTypeIndex);

	// Export section
	const moduleExport = t.moduleExport(
		initFuncId.value,
		t.moduleExportDescr("Func", nextFuncIndex)
	);

	return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]);
};