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/rebase-ddr-cpu-swap-latest.ts

/** Replay exact already-solved CPU swap onto a changed parent and verify every new conductor. */
import{readFileSync,writeFileSync,mkdirSync}from'node:fs';import{resolve}from'node:path';import{objectHash as hash}from'./improve-ddr-a9-power-launches';import{auditCompositeHostTopology}from'./ddr-composite-routing-context';import{auditDdrLocalEscapeContacts}from'./audit-ddr-local-escape-contacts';import{auditDdrTraceJunctions,verifyDdrSystemCopper}from'./check-ddr-system-copper';import{auditRouteAngles}from'./check-route-angles';
const[parentArg='dist/ddr-twenty-one-d15-connected',outArg='dist/ddr-latest-cpu-swapped']=process.argv.slice(2),parent=resolve(parentArg),out=resolve(outArg),read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),c=read(parent+'/candidate.circuit.json'),report=read(parent+'/report.json'),host=read(parent+'/host-bundle.json'),input=read(parent+'/routing-input.json'),proposal=read('dist/ddr-cpu-d11-d13-swap-aligned/combined-original-copper-replacements.json');if(hash(c)!==report.candidateCircuitSha256)throw Error('Parent changed')
for(const r of proposal.replacements)if(c.filter((e:any)=>hash(e)===r.beforeSha256).length!==1)throw Error('Replacement before witness differs');for(const r of proposal.removals)if(c.filter((e:any)=>hash(e)===hash(r)).length!==1)throw Error('Retired host differs');const candidate=c.filter((e:any)=>!proposal.removals.some((q:any)=>hash(q)===hash(e))).map((e:any)=>proposal.replacements.find((r:any)=>r.beforeSha256===hash(e))?.after??e),hosts=host.traces.filter((t:any)=>!proposal.removals.some((r:any)=>hash(r)===hash(t))),connections=input.connections.map((n:any)=>({...n,pointsToConnect:n.pointsToConnect.map((p:any)=>{const r=proposal.replacements.find((r:any)=>r.before.pcb_breakout_point_id===p.pointId);return r?{...p,x:r.after.x,y:r.after.y,layer:r.after.layer}:p})})),locals=proposal.replacements.filter((r:any)=>r.after.type==='pcb_trace').map((r:any)=>r.after),fresh=[...hosts,...locals],ids=new Set(fresh.map((t:any)=>t.pcb_trace_id)),physical=verifyDdrSystemCopper(candidate.filter((e:any)=>!ids.has(e.pcb_trace_id)),fresh,connections,{}),topology=auditCompositeHostTopology(candidate,hosts,connections),angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),joins=auditDdrTraceJunctions(candidate,connections),localContacts=locals.map((t:any)=>auditDdrLocalEscapeContacts(candidate,t,connections));mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(out+'/'+n,JSON.stringify(v,null,2)+'\n');write('diagnostic.json',{physical,topology,angles,joins,localContacts});if(physical.errors.length||physical.violations.length||!topology.valid||!angles.valid||!joins.valid||localContacts.some((a:any)=>!a.valid)||hosts.length!==host.traces.length-1)throw Error('Current CPU swap fails')
const manifest={...proposal,parentDirectory:parent,parentCircuitSha256:hash(c),candidateCircuitSha256:hash(candidate)};write('candidate.circuit.json',candidate);write('host-bundle.json',{...host,traces:hosts});write('routing-input.json',{...input,traces:hosts,connections});write('original-copper-replacements.json',manifest);write('report.json',{...report,candidateCircuitSha256:hash(candidate),hostTracesSha256:hash(hosts),hostBundleSha256:hash({...host,traces:hosts}),originalCopperReplacementsSha256:hash(manifest),connectedHostCount:hosts.length,preservedHostCount:hosts.length,physical,topology,allAngles:angles,allJunctions:joins,scope:'CPU K3/L3 swap proposal; D11 host explicitly retired. All other current hosts retained; D11 and D13 need routing.'});for(const n of ['ram-byte0-facing-progress.trace-paths.json','ram-byte1-facing-progress.trace-paths.json','source-provenance.json'])write(n,read(parent+'/'+n));for(const n of ['exit-contract.json','ram-byte1-exit-contract.json'])write(n,{...read(parent+'/'+n),candidateCircuitSha256:hash(candidate),cpuSwapManifestSha256:hash(manifest)});
for(const args of [['scripts/audit-ddr-global-power-launches.ts',out,'dist/ddr-system/host-taps-54af3e346b5e'],['scripts/audit-ddr-current-byte-budgets.ts','dist/ddr-system/host-taps-54af3e346b5e',out,out+'/current-byte-budgets.json']]){const p=Bun.spawn(['bun',...args],{stdout:'ignore',stderr:'inherit'});if(await p.exited!==0)throw Error('Fresh audit failed')}