Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return t.funcParam(importedGlobal.descr.valtype, id);
});
const funcBody = importedGlobals.reduce((acc, importedGlobal, index) => {
const args = [t.indexLiteral(index)];
const body = [
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);
}
var _instr2 = [];
parseInstructionBlock(_instr2); // preserve anonymous
var _label = t.withRaw(t.identifier(getUniqueName("block")), "");
var blockNode = t.blockInstruction(_label, _instr2, _blocktype2);
code.push(blockNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "call") {
var indexu32 = readU32();
var index = indexu32.value;
eatBytes(indexu32.nextIndex);
dump([index], "index");
var callNode = t.callInstruction(t.indexLiteral(index));
code.push(callNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "call_indirect") {
var indexU32 = readU32();
var typeindex = indexU32.value;
eatBytes(indexU32.nextIndex);
dump([typeindex], "type index");
var signature = state.typesInModule[typeindex];
if (typeof signature === "undefined") {
throw new CompileError("call_indirect signature not found (".concat(typeindex, ")"));
}
var _callNode = t.callIndirectInstruction(t.signature(signature.params, signature.result), []);
var flagU32 = readU32();
const instrArgs = [];
// Nested instruction
while (token.type === tokens.openParen) {
eatToken();
instrArgs.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
if (typeof index === "undefined") {
throw new Error("Missing argument in call instruciton");
}
if (instrArgs.length > 0) {
return t.callInstruction(index, instrArgs);
} else {
return t.callInstruction(index);
}
} else if (isKeyword(token, keywords.if)) {
eatToken(); // Keyword
return parseIf();
} else if (isKeyword(token, keywords.module) && hasPlugin("wast")) {
eatToken();
// In WAST you can have a module as an instruction's argument
// we will cast it into a instruction to not break the flow
// $FlowIgnore
const module: Instruction = parseModule();
return module;
}
var instrArgs = []; // Nested instruction
while (token.type === tokens.openParen) {
eatToken();
instrArgs.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
if (typeof index === "undefined") {
throw new Error("Missing argument in call instruciton");
}
if (instrArgs.length > 0) {
return t.callInstruction(index, instrArgs);
} else {
return t.callInstruction(index);
}
} else if (isKeyword(token, keywords.if)) {
eatToken(); // Keyword
return parseIf();
} else if (isKeyword(token, keywords.module) && hasPlugin("wast")) {
eatToken(); // In WAST you can have a module as an instruction's argument
// we will cast it into a instruction to not break the flow
// $FlowIgnore
var module = parseModule();
return module;
} else {
throw function () {
var instrArgs = []; // Nested instruction
while (token.type === tokens.openParen) {
eatToken();
instrArgs.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
if (typeof index === "undefined") {
throw new Error("Missing argument in call instruciton");
}
if (instrArgs.length > 0) {
return t.callInstruction(index, instrArgs);
} else {
return t.callInstruction(index);
}
} else if (isKeyword(token, keywords.if)) {
eatToken(); // Keyword
return parseIf();
} else if (isKeyword(token, keywords.module) && hasPlugin("wast")) {
eatToken(); // In WAST you can have a module as an instruction's argument
// we will cast it into a instruction to not break the flow
// $FlowIgnore
var module = parseModule();
return module;
} else {
throw function () {
return new Error("\n" + (0, _helperCodeFrame.codeFrameFromSource)(source, token.loc) + "\n" + "Unexpected instruction in function body" + ", given " + tokenToString(token));
}();
}
var _instr2 = [];
parseInstructionBlock(_instr2); // preserve anonymous
var _label = t.withRaw(t.identifier(getUniqueName("block")), "");
var blockNode = t.blockInstruction(_label, _instr2, _blocktype2);
code.push(blockNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "call") {
var indexu32 = readU32();
var index = indexu32.value;
eatBytes(indexu32.nextIndex);
dump([index], "index");
var callNode = t.callInstruction(t.indexLiteral(index));
code.push(callNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "call_indirect") {
var indexU32 = readU32();
var typeindex = indexU32.value;
eatBytes(indexU32.nextIndex);
dump([typeindex], "type index");
var signature = state.typesInModule[typeindex];
if (typeof signature === "undefined") {
throw new _helperApiError.CompileError("call_indirect signature not found (".concat(typeindex, ")"));
}
var _callNode = t.callIndirectInstruction(t.signature(signature.params, signature.result), []);
var flagU32 = readU32();
// Nested instruction
while (token.type === tokens.openParen) {
eatToken();
instrArgs.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
if (typeof index === "undefined") {
throw new Error("Missing argument in call instruciton");
}
if (instrArgs.length > 0) {
return t.callInstruction(index, instrArgs);
} else {
return t.callInstruction(index);
}
} else if (isKeyword(token, keywords.if)) {
eatToken(); // Keyword
return parseIf();
} else if (isKeyword(token, keywords.module) && hasPlugin("wast")) {
eatToken();
// In WAST you can have a module as an instruction's argument
// we will cast it into a instruction to not break the flow
// $FlowIgnore
const module: Instruction = parseModule();
return module;
} else {
throw createUnexpectedToken("Unexpected instruction in function body");
}
var instrArgs = []; // Nested instruction
while (token.type === tokens.openParen) {
eatToken();
instrArgs.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
if (typeof index === "undefined") {
throw new Error("Missing argument in call instruciton");
}
if (instrArgs.length > 0) {
return t.callInstruction(index, instrArgs);
} else {
return t.callInstruction(index);
}
} else if (isKeyword(token, keywords.if)) {
eatToken(); // Keyword
return parseIf();
} else if (isKeyword(token, keywords.module) && hasPlugin("wast")) {
eatToken(); // In WAST you can have a module as an instruction's argument
// we will cast it into a instruction to not break the flow
// $FlowIgnore
var module = parseModule();
return module;
} else {
throw function () {
replaceWith(path, instrName) {
if (this.index[instrName] === -1) {
this.index[instrName] = this.startIndex++;
}
const index = this.index[instrName];
path.replaceWith(callInstruction(numberLiteral(index, String(index))));
}
var callNode = function () {
var endLoc = getPosition();
return t.withLoc(t.callInstruction(t.indexLiteral(index)), endLoc, _startLoc6);
}();