Skip to content

Commit

Permalink
feat(wasm): add reserved bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed Apr 6, 2018
1 parent a348ea6 commit ad4481c
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions packages/wasm-parser/src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,13 @@ export function decode(ab: ArrayBuffer, opts: DecoderOpts): Program {
[]
);

eatBytes(1); // 0x00 - reserved byte
const flagU32 = readU32();
const flag = flagU32.value; // 0x00 - reserved byte
eatBytes(flagU32.nextIndex);

if (flag !== 0) {
throw new CompileError("zero flag expected");
}

code.push(callNode);
instructionAlreadyCreated = true;
Expand All @@ -788,17 +794,33 @@ export function decode(ab: ArrayBuffer, opts: DecoderOpts): Program {
/**
* Memory instructions
*/
const aligun32 = readU32();
const align = aligun32.value;
eatBytes(aligun32.nextIndex);

dump([align], "align");
if (
instruction.name === "grow_memory" ||
instruction.name === "current_memory"
) {
const indexU32 = readU32();
const index = indexU32.value;
eatBytes(indexU32.nextIndex);

if (index !== 0) {
throw new Error("zero flag expected");
}

dump([index], "index");
} else {
const aligun32 = readU32();
const align = aligun32.value;
eatBytes(aligun32.nextIndex);

const offsetu32 = readU32();
const offset = offsetu32.value;
eatBytes(offsetu32.nextIndex);
dump([align], "align");

dump([offset], "offset");
const offsetu32 = readU32();
const offset = offsetu32.value;
eatBytes(offsetu32.nextIndex);

dump([offset], "offset");
}
} else if (instructionByte >= 0x41 && instructionByte <= 0x44) {
/**
* Numeric instructions
Expand Down

0 comments on commit ad4481c

Please sign in to comment.