Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Parse ( vector function index ) *
*/
var indicesu32 = readU32();
var indices = indicesu32.value;
eatBytes(indicesu32.nextIndex);
dump([indices], "num indices");
var indexValues = [];
for (var _i4 = 0; _i4 < indices; _i4++) {
var indexu32 = readU32();
var index = indexu32.value;
eatBytes(indexu32.nextIndex);
dump([index], "index");
indexValues.push(t.indexLiteral(index));
}
var endLoc = getPosition();
var elemNode = t.withLoc(t.elem(t.indexLiteral(tableindex), instr, indexValues), endLoc, startLoc);
elems.push(elemNode);
}
return elems;
} // https://webassembly.github.io/spec/core/binary/types.html#memory-types
function parseElem() {
var tableIndex = t.indexLiteral(0);
var offset = [];
var funcs = [];
if (token.type === tokens.identifier) {
tableIndex = identifierFromToken(token);
eatToken();
}
if (token.type === tokens.number) {
tableIndex = t.indexLiteral(token.value);
eatToken();
}
while (token.type !== tokens.closeParen) {
if (lookaheadAndCheck(tokens.openParen, keywords.offset)) {
eatToken(); // (
const getNextTypeIndex = ast => {
const typeSectionMetadata = t.getSectionMetadata(ast, "type");
if (typeSectionMetadata === undefined) {
return t.indexLiteral(0);
}
return t.indexLiteral(typeSectionMetadata.vectorOfSize.value);
};
function parseStart(): Start {
if (token.type === tokens.identifier) {
const index = identifierFromToken(token);
eatToken();
return t.start(index);
}
if (token.type === tokens.number) {
const index = t.indexLiteral(token.value);
eatToken();
return t.start(index);
}
throw new Error("Unknown start, token: " + tokenToString(token));
}
const getNextFuncIndex = (ast, countImportedFunc) => {
const funcSectionMetadata = t.getSectionMetadata(ast, "func");
if (funcSectionMetadata === undefined) {
return t.indexLiteral(0 + countImportedFunc);
}
const vectorOfSize = funcSectionMetadata.vectorOfSize.value;
return t.indexLiteral(vectorOfSize + countImportedFunc);
};
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];
}, []);
function parseElem(): Elem {
let tableIndex = t.indexLiteral(0);
const offset = [];
const funcs = [];
if (token.type === tokens.identifier) {
tableIndex = identifierFromToken(token);
eatToken();
}
if (token.type === tokens.number) {
tableIndex = t.indexLiteral(token.value);
eatToken();
}
while (token.type !== tokens.closeParen) {
if (lookaheadAndCheck(tokens.openParen, keywords.offset)) {
const initialGlobalidx = init.args[0];
node.init = [
createDefaultInitForGlobal(node.globalType),
t.instruction("end")
];
additionalInitCode.push(
/**
* get_global in global initilizer only work for imported globals.
* They have the same indices than 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();
}
});
function getNextTypeIndex(ast) {
const typeSectionMetadata = t.getSectionMetadata(ast, "type");
if (typeof typeSectionMetadata === "undefined") {
return t.indexLiteral(0);
}
return t.indexLiteral(typeSectionMetadata.vectorOfSize.value);
}