Moving towards multiple register parsers, to handle more exotic register types

This commit is contained in:
2025-10-10 13:46:21 +01:00
parent 5aa4c33059
commit 20764d74d3
6 changed files with 69 additions and 56 deletions

View File

@@ -1,9 +1,11 @@
import {Register, RegisterAccess} from "@/utils/register_parser";
import {Register, RegisterAccess, RegisterDetail} from "@/utils/register_parser";
export const parseDescriptionDefault = (reg: Register, description: string) => {
const descriptionLines = description.split('\n');
let currentAccess: 'read' | 'write' | 'common' | null = null;
let accessData: RegisterAccess = { operations: [], notes: [] };
// Prepare a new RegisterDetail for this description block
const detail: RegisterDetail = { read: undefined, write: undefined, common: undefined, text: '', notes: [] };
for (const line of descriptionLines) {
if (line.includes('Issue 4 Only')) reg.issue_4_only = true;
@@ -14,25 +16,34 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
if (trimmedLine.startsWith('//')) continue;
if (trimmedLine.startsWith('(R)')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
// finalize previous access block into detail
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = 'read';
continue;
}
if (trimmedLine.startsWith('(W)')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = 'write';
continue;
}
if (trimmedLine.startsWith('(R/W')) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = 'common';
continue;
}
if (line.startsWith(trimmedLine)) {
if (currentAccess) reg[currentAccess] = accessData;
if (currentAccess) {
detail[currentAccess] = accessData;
}
accessData = { operations: [], notes: [] };
currentAccess = null;
}
@@ -81,17 +92,20 @@ export const parseDescriptionDefault = (reg: Register, description: string) => {
if (trimmedLine.startsWith('*')) {
const noteMatch = trimmedLine.match(/^(\*+)\s*(.*)/);
if (noteMatch) {
reg.notes.push({
detail.notes.push({
ref: noteMatch[1],
text: noteMatch[2],
});
}
} else if (trimmedLine) {
reg.text += `${line}\n`;
detail.text += `${line}\n`;
}
}
}
if (currentAccess) {
reg[currentAccess] = accessData;
detail[currentAccess] = accessData;
}
// Push the parsed detail into modes
reg.modes = reg.modes || [];
reg.modes.push(detail);
};