1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const SLOT_INDEX_RE = /(?:LD|ST)(?:LOC|ARG|SFLD)(\d+)$/u;
const STLOC_RE = /^STLOC(?:\d+)?$/u;
const STARG_RE = /^STARG(?:\d+)?$/u;
const STSFLD_RE = /^STSFLD(?:\d+)?$/u;
const LDARG_RE = /^LDARG(?:\d+)?$/u;
const LDLOC_RE = /^LDLOC(?:\d+)?$/u;
const LDSFLD_RE = /^LDSFLD(?:\d+)?$/u;
export function slotIndex(mnemonic, instruction) {
const exact = SLOT_INDEX_RE.exec(mnemonic);
if (exact) {
return Number(exact[1]);
}
if (instruction.operand?.kind === "U8") {
return instruction.operand.value;
}
return null;
}
export function isStoreLocal(mnemonic) {
return STLOC_RE.test(mnemonic);
}
export function isStoreArgument(mnemonic) {
return STARG_RE.test(mnemonic);
}
export function isStoreStatic(mnemonic) {
return STSFLD_RE.test(mnemonic);
}
export function isLoadArgument(mnemonic) {
return LDARG_RE.test(mnemonic);
}
export function isLoadLocal(mnemonic) {
return LDLOC_RE.test(mnemonic);
}
export function isLoadStatic(mnemonic) {
return LDSFLD_RE.test(mnemonic);
}