Skip to content

Commit

Permalink
Fixed Opcode typo and added check to prevent future typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 4, 2020
1 parent f02c7db commit 15bb840
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/asm/src.ts/opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const _Opcodes: { [ name: string ]: _Opcode } = {
byte: { value: 0x1a, delta: 2, alpha: 1, doc: "v = byte(msbByteIndex, value)" },
shl: { value: 0x1b, delta: 2, alpha: 1, doc: "v = shl(shiftBits, value)" },
shr: { value: 0x1c, delta: 2, alpha: 1, doc: "v = shr(shiftBits, value)" },
sar: { value: 0x1c, delta: 2, alpha: 1, doc: "v = sar(shiftBits, value)" },
sar: { value: 0x1d, delta: 2, alpha: 1, doc: "v = sar(shiftBits, value)" },

// SHA3
sha3: { value: 0x20, delta: 2, alpha: 1, doc: "v = sha3(offset, length)" },
Expand Down Expand Up @@ -244,8 +244,16 @@ Object.keys(_Opcodes).forEach((mnemonic) => {
const info = _Opcodes[mnemonic];
const opcode = new Opcode(mnemonic.toUpperCase(), info.value, info.delta, info.alpha, info.doc);

OpcodeMap[opcode.mnemonic.toLowerCase()] = opcode;
Opcodes[opcode.value] = opcode;
const key = opcode.mnemonic.toLowerCase();
const value = opcode.value;

if (OpcodeMap[key] || Opcodes[value]) {
console.log(key, OpcodeMap[key], value, Opcodes[value]);
throw new Error("There is a type in the above table.");
}

OpcodeMap[key] = opcode;
Opcodes[value] = opcode;
});
Object.freeze(Opcodes);

Expand Down

0 comments on commit 15bb840

Please sign in to comment.