Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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));
}
/**
} 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
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,
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();
}
});
IfInstruction({ node }: NodePath) {
node.test.push(t.instruction("end"));
node.consequent.push(t.instruction("end"));
node.alternate.push(t.instruction("end"));
},
function addEndInstruction(body) {
body.push(t.instruction("end"));
}
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();
code.unshift.apply(code, _toConsumableArray(locals.map(function (l) {
return t.instruction("local", [t.valtypeLiteral(l)]);
})));
var endLoc = getPosition();
var localNode = function () {
var endLoc = getPosition();
return t.withLoc(t.instruction("local", args), endLoc, _startLoc5);
}();
var node = function () {
var endLoc = getPosition();
return t.withLoc(t.instruction(instruction.name), endLoc, _startLoc6);
}();