Skip to content

Commit 3bcaf0c

Browse files
committed
fix typing issues in loadExtensions.ts
1 parent 61f0245 commit 3bcaf0c

File tree

3 files changed

+113
-67
lines changed

3 files changed

+113
-67
lines changed

src/lib/hardcodedData.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
export const extensionDescriptions: Record<string, string> = {
2+
I: "Base Integer",
3+
E: "Embedded Base",
4+
M: "Integer Multiply/Divide",
5+
A: "Atomic Instructions",
6+
F: "Single-Precision Floating Point",
7+
D: "Double-Precision Floating Point",
8+
Q: "Quad-Precision Floating Point",
9+
C: "Compressed Instructions",
10+
B: "Bit Manipulation",
11+
H: "Hypervisor",
12+
S: "Supervisor",
13+
V: "Vector",
14+
Sdext: "Supervisor Debug",
15+
Smdbltrp: "Supervisor Multiple Double Trap",
16+
Smrnmi: "Supervisor Recursive NMI",
17+
Svinval: "Supervisor Virtual Invalidation",
18+
Zaamo: "Atomics extensions",
19+
Zabha: "Byte/Halfword Atomics",
20+
Zacas: "Compare-and-Swap Atomics",
21+
Zalasr: "Atomic Logical Shift Right",
22+
Zalrsc: "Load-Reserved/Store-Conditional",
23+
Zawrs: "Wait-on-Reservation-Set",
24+
Zba: "Address Generation Bit-Manip",
25+
Zbb: "Basic Bit-Manip",
26+
Zbc: "Carry-Less Multiply",
27+
Zbkb: "Bit-Manip Crypto B",
28+
Zbkx: "Bit-Manip Crypto X",
29+
Zbs: "Single-Bit Manipulation",
30+
Zcb: "Compressed Bit-Manip",
31+
Zcd: "Compressed Double",
32+
Zcf: "Compressed Floating Point",
33+
Zcmop: "Compressed Micro-Operations",
34+
Zcmp: "Compressed Pair",
35+
Zfa: "Vector Atomic Floating",
36+
Zfbfmin: "Vector BF16 Min",
37+
Zfh: "Half-Precision Floating Point",
38+
Zicbom: "Cache Block Management",
39+
Zicboz: "Zero Cache Block",
40+
Zicfilp: "Fetch Line Prefetch",
41+
Zicfiss: "Instruction Streaming",
42+
Zicond: "Conditional Ops",
43+
Zicsr: "CSR Instructions",
44+
Zifencei: "Instruction-Fetch Fence",
45+
Zimop: "Integer Multiply and Division Ops",
46+
Zkn: "Scalar Cryptography",
47+
Zknd: "NIST Suite: AES Decryption",
48+
Zkne: "NIST Suite: AES Encryption",
49+
Zknh: "NIST Suite: Hash",
50+
Zks: "Scalar Crypto Suite",
51+
Zvbb: "Vector Bitwise",
52+
Zvbc: "Vector Carry-less Multiply",
53+
Zvfbfmin: "Vector BF16 Min",
54+
Zvfbfwma: "Vector BF16 Fused Multiply-Add",
55+
Zvkg: "Vector Galois Field",
56+
Zvkned: "Vector AES Decryption",
57+
Zvknha: "Vector Hash",
58+
Zvks: "Vector Crypto Suite",
59+
};

src/lib/loadExtensions.ts

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,35 @@
1+
import { InstructionInfo, ExtensionInfo } from "./sharedTypes.js";
2+
import { extensionDescriptions } from "./hardcodedData.js";
13
import loadInstructions from "./loadInstructions.js";
24

3-
export default () => {
4-
const instructions = loadInstructions();
5-
const descriptions = {
6-
I: "Base Integer",
7-
E: "Embedded Base",
8-
M: "Integer Multiply/Divide",
9-
A: "Atomic Instructions",
10-
F: "Single-Precision Floating Point",
11-
D: "Double-Precision Floating Point",
12-
Q: "Quad-Precision Floating Point",
13-
C: "Compressed Instructions",
14-
B: "Bit Manipulation",
15-
H: "Hypervisor",
16-
S: "Supervisor",
17-
V: "Vector",
18-
Sdext: "Supervisor Debug",
19-
Smdbltrp: "Supervisor Multiple Double Trap",
20-
Smrnmi: "Supervisor Recursive NMI",
21-
Svinval: "Supervisor Virtual Invalidation",
22-
Zaamo: "Atomics extensions",
23-
Zabha: "Byte/Halfword Atomics",
24-
Zacas: "Compare-and-Swap Atomics",
25-
Zalasr: "Atomic Logical Shift Right",
26-
Zalrsc: "Load-Reserved/Store-Conditional",
27-
Zawrs: "Wait-on-Reservation-Set",
28-
Zba: "Address Generation Bit-Manip",
29-
Zbb: "Basic Bit-Manip",
30-
Zbc: "Carry-Less Multiply",
31-
Zbkb: "Bit-Manip Crypto B",
32-
Zbkx: "Bit-Manip Crypto X",
33-
Zbs: "Single-Bit Manipulation",
34-
Zcb: "Compressed Bit-Manip",
35-
Zcd: "Compressed Double",
36-
Zcf: "Compressed Floating Point",
37-
Zcmop: "Compressed Micro-Operations",
38-
Zcmp: "Compressed Pair",
39-
Zfa: "Vector Atomic Floating",
40-
Zfbfmin: "Vector BF16 Min",
41-
Zfh: "Half-Precision Floating Point",
42-
Zicbom: "Cache Block Management",
43-
Zicboz: "Zero Cache Block",
44-
Zicfilp: "Fetch Line Prefetch",
45-
Zicfiss: "Instruction Streaming",
46-
Zicond: "Conditional Ops",
47-
Zicsr: "CSR Instructions",
48-
Zifencei: "Instruction-Fetch Fence",
49-
Zimop: "Integer Multiply and Division Ops",
50-
Zkn: "Scalar Cryptography",
51-
Zknd: "NIST Suite: AES Decryption",
52-
Zkne: "NIST Suite: AES Encryption",
53-
Zknh: "NIST Suite: Hash",
54-
Zks: "Scalar Crypto Suite",
55-
Zvbb: "Vector Bitwise",
56-
Zvbc: "Vector Carry-less Multiply",
57-
Zvfbfmin: "Vector BF16 Min",
58-
Zvfbfwma: "Vector BF16 Fused Multiply-Add",
59-
Zvkg: "Vector Galois Field",
60-
Zvkned: "Vector AES Decryption",
61-
Zvknha: "Vector Hash",
62-
Zvks: "Vector Crypto Suite",
63-
};
64-
const byExtension = new Map();
655

6+
export default (): ExtensionInfo[] => {
7+
const instructions: InstructionInfo[] = loadInstructions();
8+
const byExtension = new Map<string, ExtensionInfo>();
9+
10+
// Group instructions by their extension and create ExtensionInfo objects
6611
for (const inst of instructions) {
6712
const name = inst.extension || "unknown";
6813
const slug = inst.extensionSlug || "unknown";
6914
if (!byExtension.has(name)) {
7015
byExtension.set(name, {
71-
name,
72-
slug,
73-
description: descriptions[name] || null,
16+
name, slug,
17+
description: extensionDescriptions[name] || null,
7418
instructions: [],
7519
});
7620
}
77-
byExtension.get(name).instructions.push(inst);
21+
byExtension.get(name)!.instructions.push(inst);
7822
}
7923

24+
// Sort instructions within each extension and count them
8025
const list = Array.from(byExtension.values());
8126
for (const entry of list) {
82-
entry.instructions.sort((a, b) => a.name.localeCompare(b.name));
27+
entry.instructions.sort((a: InstructionInfo, b: InstructionInfo) =>
28+
a.name.localeCompare(b.name));
8329
entry.count = entry.instructions.length;
8430
}
8531

32+
// Sort extensions alphabetically by name
8633
list.sort((a, b) => a.name.localeCompare(b.name));
8734
return list;
8835
};

src/lib/sharedTypes.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
export interface Field {
2+
label: string;
3+
from: number;
4+
to: number;
5+
width: number;
6+
kind: "var" | "const";
7+
segments?: { from: number; to: number }[];
8+
}
9+
10+
11+
export interface InstructionInfo {
12+
name: string;
13+
longName: string;
14+
description: string;
15+
definedBy: string;
16+
definedByRaw: any;
17+
base: number;
18+
syntax: string;
19+
encodingType?: string;
20+
encoding: {
21+
match: string | null;
22+
variables: any[];
23+
fields: Field[];
24+
opcode?: string;
25+
funct3?: string;
26+
funct7?: string;
27+
};
28+
extension: string;
29+
extensionSlug: string;
30+
bitfieldSVG: string;
31+
}
32+
33+
34+
export interface ExtensionInfo {
35+
name: string;
36+
slug: string;
37+
description: string | null;
38+
instructions: InstructionInfo[];
39+
count?: number;
40+
}

0 commit comments

Comments
 (0)