Moving towards multiple register parsers, to handle more exotic register types
This commit is contained in:
@@ -74,12 +74,6 @@ export default function RegisterBrowser({ registers }: RegisterBrowserProps) {
|
||||
register.description.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
|
||||
const getDefaultActiveKey = (register: Register) => {
|
||||
if (register.common) return 'common';
|
||||
if (register.read) return 'read';
|
||||
if (register.write) return 'write';
|
||||
return '';
|
||||
};
|
||||
|
||||
return (
|
||||
<Container fluid>
|
||||
@@ -92,12 +86,9 @@ export default function RegisterBrowser({ registers }: RegisterBrowserProps) {
|
||||
/>
|
||||
</Form.Group>
|
||||
<Row>
|
||||
{filteredRegisters.map(register => {
|
||||
const defaultActiveKey = getDefaultActiveKey(register);
|
||||
return (
|
||||
<RegisterDetail key={register.hex_address} register={register} defaultActiveKey={defaultActiveKey} />
|
||||
);
|
||||
})}
|
||||
{filteredRegisters.map(register => (
|
||||
<RegisterDetail key={register.hex_address} register={register} />
|
||||
))}
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
|
||||
@@ -10,15 +10,12 @@ import * as Icon from 'react-bootstrap-icons';
|
||||
/**
|
||||
* A client-side component that displays the details of a single register.
|
||||
* @param register The register object to display.
|
||||
* @param defaultActiveKey The default active tab to display.
|
||||
* @returns A React component that displays the register details.
|
||||
*/
|
||||
export default function RegisterDetail({
|
||||
register,
|
||||
defaultActiveKey,
|
||||
}: {
|
||||
register: Register;
|
||||
defaultActiveKey?: string;
|
||||
}) {
|
||||
const [showSource, setShowSource] = useState(false);
|
||||
|
||||
@@ -27,9 +24,7 @@ export default function RegisterDetail({
|
||||
<Card>
|
||||
<Card.Header>
|
||||
<code>{register.hex_address}</code> ( {register.dec_address} )
|
||||
{/*<Link href={`https://wiki.specnext.dev/${encodeURIComponent((register.name).replace(' ','_'))}_Register`} className="text-decoration-none">*/}
|
||||
<strong>{register.name}</strong> {register.issue_4_only && <span className="badge bg-danger">Issue 4 Only</span>}
|
||||
{/*</Link>*/}
|
||||
<div className="float-end small text-muted">
|
||||
<Link href={`https://wiki.specnext.dev/${encodeURIComponent((register.name).replace(' ','_'))}_Register`} className="text-decoration-none btn btn-sm btn-primary" title="Open wiki">
|
||||
<Icon.Wikipedia />
|
||||
@@ -45,20 +40,27 @@ export default function RegisterDetail({
|
||||
</div>
|
||||
</Card.Header>
|
||||
<Card.Body>
|
||||
<Tabs defaultActiveKey={defaultActiveKey} id={`register-tabs-${register.hex_address}`}>
|
||||
{register.common && <Tab eventKey="common" title="Read/Write">{renderAccess(register.common)}</Tab>}
|
||||
{register.read && <Tab eventKey="read" title="Read">{renderAccess(register.read)}</Tab>}
|
||||
{register.write && <Tab eventKey="write" title="Write">{renderAccess(register.write)}</Tab>}
|
||||
</Tabs>
|
||||
{register.notes.map((note, index) => (
|
||||
<p key={index} className="small text-muted">{note.ref} {note.text}</p>
|
||||
{ register.modes.map((mode, idx) => (
|
||||
<div key={idx} className={idx > 0 ? 'mt-4' : ''}>
|
||||
{register.modes.length > 1 && (
|
||||
<h5 className="mb-3">Mode {idx + 1}</h5>
|
||||
)}
|
||||
<Tabs id={`register-tabs-${register.hex_address}-${idx}`}>
|
||||
{mode.common && <Tab eventKey="common" title="Read/Write">{renderAccess(mode.common)}</Tab>}
|
||||
{mode.read && <Tab eventKey="read" title="Read">{renderAccess(mode.read)}</Tab>}
|
||||
{mode.write && <Tab eventKey="write" title="Write">{renderAccess(mode.write)}</Tab>}
|
||||
</Tabs>
|
||||
{mode.notes && mode.notes.map((note, index) => (
|
||||
<p key={index} className="small text-muted">{note.ref} {note.text}</p>
|
||||
))}
|
||||
{mode.text && mode.text.length > 0 && (
|
||||
<div className="mt-3">
|
||||
<h6>Notes:</h6>
|
||||
<pre>{mode.text}</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{register.text && register.text.length > 0 && (
|
||||
<div className="mt-3">
|
||||
<h5>Notes:</h5>
|
||||
<pre>{register.text}</pre>
|
||||
</div>
|
||||
)}
|
||||
</Card.Body>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ export default async function RegisterDetailPage({ params }: { params: { hex: st
|
||||
|
||||
if (!register) return notFound();
|
||||
|
||||
const defaultActiveKey = register.common ? 'common' : (register.read ? 'read' : (register.write ? 'write' : undefined));
|
||||
|
||||
return (
|
||||
<Container fluid className="py-4">
|
||||
@@ -21,7 +20,7 @@ export default async function RegisterDetailPage({ params }: { params: { hex: st
|
||||
<Link href="/registers" className="btn btn-secondary">← Back to Registers</Link>
|
||||
</div>
|
||||
<Row>
|
||||
<RegisterDetail register={register} defaultActiveKey={defaultActiveKey} />
|
||||
<RegisterDetail register={register} />
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
|
||||
@@ -18,16 +18,21 @@ export interface RegisterAccess {
|
||||
operations: RegisterBitwiseOperation[];
|
||||
notes: Note[];
|
||||
}
|
||||
export interface Register {
|
||||
hex_address: string;
|
||||
dec_address: number | string;
|
||||
name: string;
|
||||
description: string;
|
||||
|
||||
export interface RegisterDetail {
|
||||
read?: RegisterAccess;
|
||||
write?: RegisterAccess;
|
||||
common?: RegisterAccess;
|
||||
text: string;
|
||||
notes: Note[];
|
||||
}
|
||||
|
||||
export interface Register {
|
||||
hex_address: string;
|
||||
dec_address: number | string;
|
||||
name: string;
|
||||
modes: RegisterDetail[];
|
||||
description: string;
|
||||
issue_4_only: boolean;
|
||||
source: string[];
|
||||
}
|
||||
@@ -84,8 +89,7 @@ export function processRegisterBlock(paragraph: string, registers: Register[]) {
|
||||
dec_address: dec,
|
||||
name: regName,
|
||||
description: description,
|
||||
notes: [],
|
||||
text: "",
|
||||
modes: [],
|
||||
issue_4_only: false,
|
||||
source: []
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
@@ -1,12 +1,13 @@
|
||||
|
||||
// Special-case parser for 0xF0 (XDEV CMD): treat headings beginning with '*' inside access blocks
|
||||
// as descriptive text instead of notes, so sub-modes become part of the section descriptions.
|
||||
import {Register, RegisterAccess} from "@/utils/register_parser";
|
||||
import {Register, RegisterAccess, RegisterDetail} from "@/utils/register_parser";
|
||||
|
||||
export const parseDescriptionF0 = (reg: Register, description: string) => {
|
||||
const descriptionLines = description.split('\n');
|
||||
let currentAccess: 'read' | 'write' | 'common' | null = null;
|
||||
let accessData: RegisterAccess = { operations: [], notes: [] };
|
||||
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;
|
||||
@@ -17,25 +18,25 @@ export const parseDescriptionF0 = (reg: Register, description: string) => {
|
||||
if (trimmedLine.startsWith('//')) continue;
|
||||
|
||||
if (trimmedLine.startsWith('(R)')) {
|
||||
if (currentAccess) reg[currentAccess] = accessData;
|
||||
if (currentAccess) 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;
|
||||
}
|
||||
@@ -79,20 +80,22 @@ export const parseDescriptionF0 = (reg: Register, description: string) => {
|
||||
}
|
||||
} else {
|
||||
if (trimmedLine.startsWith('*')) {
|
||||
// Outside access blocks, keep notes as-is
|
||||
// Outside access blocks, keep notes as-is but attach to detail now
|
||||
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;
|
||||
}
|
||||
reg.modes = reg.modes || [];
|
||||
reg.modes.push(detail);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user