How to use the @webassemblyjs/ast.instruction 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 maxdenaro / maxgraph-youtube-source / JS-плагины №7. Новое подключение swiper.js через npm / node_modules / @webassemblyjs / wast-parser / esm / grammar.js View on Github external
if (token.value !== "const") {
          throw new Error("constant expression required");
        }

        eatTokenOfType(tokens.name); // const

        var numberLiteral = t.numberLiteralFromRaw(token.value, "i32");
        offset = t.objectInstruction("const", "i32", [numberLiteral]);
        eatToken();
        eatTokenOfType(tokens.closeParen);
      } else {
        eatTokenOfType(tokens.name); // get_global

        var _numberLiteral = t.numberLiteralFromRaw(token.value, "i32");

        offset = t.instruction("get_global", [_numberLiteral]);
        eatToken();
        eatTokenOfType(tokens.closeParen);
      }

      var byteArray = parseString(token.value);
      eatToken(); // "string"

      return t.data(t.memIndexLiteral(memidx), offset, t.byteArray(byteArray));
    }
    /**
github M0nica / React-Ladies / node_modules / @webassemblyjs / wasm-parser / lib / decoder.js View on Github external
} else {
        for (var _i2 = 0; _i2 < instruction.numberOfArgs; _i2++) {
          var u32 = readU32();
          eatBytes(u32.nextIndex);
          dump([u32.value], "argument " + _i2);
          args.push(t.numberLiteralFromRaw(u32.value));
        }
      }

      if (instructionAlreadyCreated === false) {
        if (typeof instruction.object === "string") {
          code.push(t.objectInstruction(instruction.name, instruction.object, args));
        } else {
          var endLoc = getPosition();

          var _node = t.withLoc(t.instruction(instruction.name, args), endLoc, startLoc);

          code.push(_node);
        }
      }
    }
  } // https://webassembly.github.io/spec/core/binary/types.html#limits
github flaviuse / mern-authentication / client / node_modules / webpack / lib / wasm / WebAssemblyGenerator.js View on Github external
t.instruction("get_local", args),
			t.instruction("set_global", args)
		];

		return [...acc, ...body];
	}, []);

	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,
github tamb / domponent / node_modules / webpack / lib / wasm / WebAssemblyGenerator.js View on Github external
node.globalType.mutability = "var";

				const initialGlobalidx = init.args[0];

				node.init = [
					createDefaultInitForGlobal(node.globalType),
					t.instruction("end")
				];

				additionalInitCode.push(
					/**
					 * get_global in global initializer only works for imported globals.
					 * They have the same indices as the init params, so use the
					 * same index.
					 */
					t.instruction("get_local", [initialGlobalidx]),
					t.instruction("set_global", [t.indexLiteral(newGlobals.length)])
				);
			}

			newGlobals.push(node);

			path.remove();
		}
	});
github xtuc / webassemblyjs / packages / webassemblyjs / src / compiler / compile / module.js View on Github external
IfInstruction({ node }: NodePath) {
      node.test.push(t.instruction("end"));
      node.consequent.push(t.instruction("end"));
      node.alternate.push(t.instruction("end"));
    },
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
function addEndInstruction(body) {
  body.push(t.instruction("end"));
}
github tamb / domponent / node_modules / webpack / lib / wasm / WebAssemblyGenerator.js View on Github external
Global(path) {
			const { node } = path;
			const [init] = node.init;

			if (init.id === "get_global") {
				node.globalType.mutability = "var";

				const initialGlobalidx = init.args[0];

				node.init = [
					createDefaultInitForGlobal(node.globalType),
					t.instruction("end")
				];

				additionalInitCode.push(
					/**
					 * get_global in global initializer only works for imported globals.
					 * They have the same indices as the init params, so use the
					 * same index.
					 */
					t.instruction("get_local", [initialGlobalidx]),
					t.instruction("set_global", [t.indexLiteral(newGlobals.length)])
				);
			}

			newGlobals.push(node);

			path.remove();
github M0nica / React-Ladies / node_modules / @webassemblyjs / wasm-parser / lib / decoder.js View on Github external
code.unshift.apply(code, _toConsumableArray(locals.map(function (l) {
        return t.instruction("local", [t.valtypeLiteral(l)]);
      })));
      var endLoc = getPosition();