0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
scripts/assemble-ddr-dq2-dq6.ts
/** Exact common-parent assembly of independent DQ2 replacement and DQ6 addition. */
import{readFileSync,writeFileSync,mkdirSync,copyFileSync}from'node:fs';import{resolve}from'node:path';import{createHash}from'node:crypto';import{spawnSync}from'node:child_process';import{objectHash as hash}from'./improve-ddr-a9-power-launches';import{mergeDdrSignalAntipads}from'./merge-ddr-signal-antipads';import{auditCompositeHostTopology}from'./ddr-composite-routing-context';import{auditRouteAngles}from'./check-route-angles';import{auditDdrTraceJunctions}from'./check-ddr-system-copper';import{checkHostTerminalContract}from'./route-ddr-sequential';import{refreshDdrPlaneContacts}from'./ddr-plane-contact-audit';
const parent=resolve('dist/ddr-twelve-dq1-partial-timing'),out=resolve('dist/ddr-thirteen-dq2-dq6'),capture=resolve('dist/ddr-system/host-taps-54af3e346b5e'),inputs=new Map<string,string>(),fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{inputs.set(p,fh(p));return JSON.parse(readFileSync(p,'utf8'))},c=read(parent+'/candidate.circuit.json'),prior=read(parent+'/report.json'),oldhost=read(parent+'/host-bundle.json'),input=read(parent+'/routing-input.json'),oldManifest=read(parent+'/original-copper-replacements.json'),oldPower=read(parent+'/ram-power-launch-audit.json'),dq2Manifest=read(resolve('dist/ddr-dq2-ram-side-host/original-copper-replacements.json')),dq6Report=read(resolve('dist/ddr-dq6-pocket-host/report.json')),dq6Rows=read(resolve('dist/ddr-dq6-pocket-host/raw-traces.json')),dq2Raw=read(resolve('dist/ddr-dq2-after-dq6-host/raw-traces.json')),dq2Report=read(resolve('dist/ddr-dq2-after-dq6-host/report.json')),dq2Prefix=read(resolve('dist/ddr-dq2-north-prefix/transition-plan.json')),dq2Before=oldhost.traces.find((t:any)=>t.source_trace_id==='source_trace_577'),dq2={id:dq2Before.pcb_trace_id,before:dq2Before,after:dq2Raw[0],beforeSha256:hash(dq2Before),afterSha256:hash(dq2Raw[0]),reason:'ExistingwindingDQ2reroute withactualDQ6reserved; exact oldhostretired.'},dq6=dq6Rows[0];
if(!dq2Report.accepted||dq2Raw.length!==1||dq2.after.source_trace_id!=='source_trace_577'||hash(c)!==prior.candidateCircuitSha256||dq2Manifest.parentCircuitSha256!==hash(c)||!dq6Report.accepted||dq6Rows.length!==1||dq6.source_trace_id!=='source_trace_581'||hash(c.find((e:any)=>e.pcb_trace_id===dq2.before.pcb_trace_id))!==dq2.beforeSha256)throw Error('Commonparent/sourcewitness failed');
const vias=[dq2.after,dq6].flatMap(t=>t.route.filter((p:any)=>p.route_type==='via').map((p:any)=>({x:p.x,y:p.y}))),plan={planes:read(resolve('dist/ddr-dq2-north-prefix/planes.json')),changes:dq2Prefix.accepted[0].addedAntipads},planeMap=new Map(plan.planes.map((p:any)=>[p.pcb_copper_pour_id,p])),candidate=[...c.map((e:any)=>e.pcb_trace_id===dq2.before.pcb_trace_id?dq2.after:e.type==='pcb_copper_pour'?planeMap.get(e.pcb_copper_pour_id):e),dq6],host={...oldhost,traces:[...oldhost.traces.map((t:any)=>t.pcb_trace_id===dq2.before.pcb_trace_id?dq2.after:t),dq6]},topology=auditCompositeHostTopology(candidate,host.traces,input.connections),angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),joins=auditDdrTraceJunctions(candidate,input.connections),terminal=checkHostTerminalContract(host.traces,input.connections.filter((n:any)=>host.traces.some((t:any)=>t.connection_name===n.name))),planeAudit=refreshDdrPlaneContacts(prior.planeAudit,plan.planes,candidate);
mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(out+'/'+n,JSON.stringify(v,null,2)+'\n');write('combined-audit.json',{topology,angles,joins,terminal,planeAudit,planeChanges:plan.changes});if(!topology.valid||!angles.valid||!joins.valid||!terminal.valid||topology.physical.connectivity.filter((n:any)=>n.connected).length!==13)throw Error('Combined copper/topology invalid; diagnostic only');
const replacements=[dq2,...c.filter((e:any)=>e.type==='pcb_copper_pour').map((p:any)=>({id:p.pcb_copper_pour_id,before:p,after:planeMap.get(p.pcb_copper_pour_id),beforeSha256:hash(p),afterSha256:hash(planeMap.get(p.pcb_copper_pour_id)),reason:'Booleanmerged adjacent DQ2/DQ6 signalantipads; alloriginalvoids retained.'}))],manifest={captureHash:prior.captureHash,parentDirectory:parent,parentCircuitSha256:hash(c),candidateCircuitSha256:hash(candidate),inputHashes:Object.fromEntries(inputs),parentManifestSha256:hash(oldManifest),replacements,additions:[{after:dq6,afterSha256:hash(dq6),reason:'New completeDQ6host from existingwinding solver.'}]},report={...prior,accepted:true,candidateCircuitSha256:hash(candidate),supportCircuitSha256:hash(candidate),hostTracesSha256:hash(host.traces),hostBundleSha256:hash(host),originalCopperReplacementsSha256:hash(manifest),parentAssemblyManifestSha256:hash(oldManifest),parentReportSha256:hash(prior),planeAudit,planeChanges:plan.changes,physical:topology.physical,topology,fullCandidateAngles:angles,fixedJunctionAudit:joins,terminalContract:terminal,connectedHostCount:13,preservedHostCount:11,modifiedHostCount:1,addedHostCount:1,inputFileHashes:Object.fromEntries(inputs),supportValidation:{valid:true,method:'Candidate constructed by exactcommonparent arraymap: replaceDQ2 and3planes,appendDQ6 only; allotherobjects retained byidentity.'},scope:'Thirteen actualhosts after exactDQ2replacement andDQ6addition. Nearby signalvoids Booleanmerged withminimumweb andoneoutercomponent. Newdatawithin nominalbudget butnot yetDQSmatched;fullDDRsignoffincomplete.'};
write('candidate.circuit.json',candidate);write('host-bundle.json',host);write('routing-input.json',{...input,traces:host.traces});write('original-copper-replacements.json',manifest);write('report.json',report);write('host-route-report.json',{captureHash:prior.captureHash,accepted:true,topology,physical:topology.physical,allAngles:angles,allJunctions:joins,allTerminal:terminal});for(const n of['source-provenance.json','ram-byte0-facing-progress.trace-paths.json'])copyFileSync(parent+'/'+n,out+'/'+n);for(const n of['report.json','original-copper-replacements.json','routing-input.json','exit-contract.json'])copyFileSync(parent+'/'+n,out+'/parent-'+n);const ec=read(parent+'/exit-contract.json');write('exit-contract.json',{...ec,...('candidateCircuitSha256'in ec?{candidateCircuitSha256:hash(candidate)}:{})});
for(const script of['audit-ddr-global-power-launches.ts','audit-ddr-host-reference-coverage.ts']){const run=spawnSync(process.execPath,[resolve('scripts/'+script),out,...(script.includes('power')?[capture]:[])],{encoding:'utf8'});if(run.status!==0)throw Error(run.stderr)}const power=JSON.parse(readFileSync(out+'/ram-power-launch-audit.json','utf8'));if(power.launchQualified!==56||power.planeConnected!==56||oldPower.rows.some((r:any)=>r.launchWithin1524Mm&&!power.rows.some((n:any)=>n.byte===r.byte&&n.ball===r.ball&&n.launchWithin1524Mm)))throw Error('Powerlaunchchanged');Object.assign(report,{launchQualified:56,sourceProvenance:{inheritedFile:'source-provenance.json',inheritedFileSha256:fh(out+'/source-provenance.json'),currentReplacementManifestSha256:hash(manifest),parentCircuitSha256:hash(c),candidateCircuitSha256:hash(candidate)},supportValidationMethod:'Exact parent object map with explicit DQ2 replacement, DQ6 addition and Boolean plane replacement; fresh13host and56launch audits.',supportValidationChain:{parent:prior.supportValidationChain,currentManifestSha256:hash(manifest)},exitContractProvenance:{parentSha256:hash(ec),updatedFields:'candidateCircuitSha256'in ec?['candidateCircuitSha256']:[]},routingInputProvenance:{parentSha256:hash(input),currentSha256:hash({...input,traces:host.traces}),updatedFields:['traces']},dq2Evidence:{fullPlanarMm:dq2Report.fullPlanarMm,sourceReportSha256:hash(dq2Report)},dq6Evidence:{fullPlanarMm:dq6Report.fullPlanarMm,sourceReportSha256:hash(dq6Report)},unchangedPlanesSha256:undefined,launchAuditSha256:hash(power),hostReferenceCoverageSha256:hash(JSON.parse(readFileSync(out+'/host-reference-coverage.json','utf8')))});write('report.json',report);for(const[p,h]of inputs)if(fh(p)!==h)throw Error('Inputmutated');console.log(JSON.stringify({out,candidateSha:hash(candidate),hosts:13,power:56,planeChanges:plan.changes}))