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-fourteen-data.ts
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
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[baseDir,jointDir,out,capture]=process.argv.slice(2),bound:Record<string,string>={},fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{p=resolve(p);bound[p]=fh(p);return JSON.parse(readFileSync(p,'utf8'))},hash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex'),key=(e:any)=>`${e.type}:${e[`${e.type}_id`]}`
const base=read(resolve(baseDir,'candidate.circuit.json')),prior=read(resolve(baseDir,'report.json')),host=read(resolve(baseDir,'host-bundle.json')),input=read(resolve(baseDir,'routing-input.json')),joint=read(resolve(jointDir,'candidate.circuit.json')),jm=read(resolve(jointDir,'original-copper-replacements.json')),jp=read(resolve(jm.parentDirectory,'candidate.circuit.json')),jr=read(resolve(jointDir,'report.json'))
if(hash(base)!==prior.candidateCircuitSha256||hash(joint)!==jm.candidateCircuitSha256||hash(jp)!==jm.parentCircuitSha256||jm.captureHash!==prior.captureHash||!jr.accepted||host.traces.length!==13)throw Error('Input hashes differ')
const replay=new Map(jp.map((e:any)=>[key(e),e]));for(const w of jm.replacements){if(hash(replay.get(key(w.before)))!==w.beforeSha256||hash(w.after)!==w.afterSha256)throw Error('Joint replacement differs');replay.delete(key(w.before));replay.set(key(w.after),w.after)}for(const w of jm.additions){if(hash(w.after)!==w.afterSha256||replay.has(key(w.after)))throw Error('Joint addition differs');replay.set(key(w.after),w.after)}if(replay.size!==joint.length||joint.some((e:any)=>hash(replay.get(key(e)))!==hash(e)))throw Error('Joint undeclared changes')
const dq2=jm.replacements.find((w:any)=>w.after.type==='pcb_trace').after,dq6=jm.additions[0].after,old=host.traces.find((t:any)=>t.source_trace_id==='source_trace_577'),dq4=host.traces.find((t:any)=>t.source_trace_id==='source_trace_579');if(!old||dq6.source_trace_id!=='source_trace_581'||!dq4)throw Error('Unexpected net selection')
const plan=mergeDdrSignalAntipads(joint.filter((e:any)=>e.type==='pcb_copper_pour'),dq4.route.filter((p:any)=>p.route_type==='via').map((p:any)=>({x:p.x,y:p.y}))),pm=new Map(plan.planes.map((e:any)=>[e.pcb_copper_pour_id,e])),candidate=[...base.map((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===old.pcb_trace_id?dq2:e.type==='pcb_copper_pour'?pm.get(e.pcb_copper_pour_id):e),dq6],traces=[...host.traces.map((t:any)=>t===old?dq2:t),dq6],newHost={...host,traces}
const topology=auditCompositeHostTopology(candidate,traces,input.connections),angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),junctions=auditDdrTraceJunctions(candidate,input.connections),terminals=checkHostTerminalContract(traces,input.connections.filter((c:any)=>traces.some((t:any)=>t.connection_name===c.name))),planeAudit=refreshDdrPlaneContacts(prior.planeAudit,plan.planes,candidate),accepted=topology.valid&&angles.valid&&junctions.valid&&terminals.valid&&topology.physical.connectivity.filter(c=>c.connected).length===14
mkdirSync(out,{recursive:true});const write=(n:string,x:any)=>writeFileSync(resolve(out,n),JSON.stringify(x,null,2)+'\n');write('combined-audit.json',{accepted,topology,angles,junctions,terminals,planeAudit,planeChanges:plan.changes});if(!accepted)throw Error('Combined14 failed actual geometry')
const replacements=[{before:old,after:dq2},...base.filter((e:any)=>e.type==='pcb_copper_pour').map((e:any)=>({before:e,after:pm.get(e.pcb_copper_pour_id)}))].map(w=>({...w,id:key(w.before),beforeSha256:hash(w.before),afterSha256:hash(w.after)})),manifest={captureHash:prior.captureHash,parentDirectory:resolve(baseDir),parentCircuitSha256:hash(base),candidateCircuitSha256:hash(candidate),replacements,additions:[dq6],inputHashes:bound,allOtherElementsExact:true},report={...prior,candidateCircuitSha256:hash(candidate),supportCircuitSha256:hash(candidate),hostTracesSha256:hash(traces),hostBundleSha256:hash(newHost),connectedHostCount:14,physical:topology.physical,topology,fullCandidateAngles:angles,fixedJunctionAudit:junctions,terminalContract:terminals,planeAudit,originalCopperReplacementsSha256:hash(manifest),inputFileHashes:bound,lengths:undefined,scope:'Fourteen geometrically connected hosts; joint DQ2/DQ6 plus DQ4/DQ5/DM1. Byte lengths not yet matched; electrical DDR qualification and remaining36nets/fourpowerlaunches unresolved.'}
write('candidate.circuit.json',candidate);write('host-bundle.json',newHost);write('routing-input.json',{...input,traces,obstacles:undefined});write('original-copper-replacements.json',manifest);write('report.json',report);write('source-provenance.json',{captureHash:prior.captureHash,inputHashes:bound,baseReportSha256:hash(prior),jointManifest:jm});for(const n of['ram-byte0-facing-progress.trace-paths.json','ram-byte1-facing-progress.trace-paths.json'])write(n,read(resolve(baseDir,n)));for(const n of['exit-contract.json','ram-byte1-exit-contract.json'])write(n,{...read(resolve(baseDir,n)),candidateCircuitSha256:hash(candidate),scope:report.scope})
for(const script of['audit-ddr-global-power-launches.ts','audit-ddr-host-reference-coverage.ts']){const p=Bun.spawn(['bun',`scripts/${script}`,resolve(out),resolve(capture)],{stdout:'inherit',stderr:'inherit'});if(await p.exited)throw Error(`Audit failed ${script}`)}const power=read(resolve(out,'ram-power-launch-audit.json'));if(power.launchQualified!==56)throw Error('Power changed');for(const[p,h]of Object.entries(bound))if(fh(p)!==h)throw Error('Input changed');write('report.json',{...report,launchQualified:56,launchAuditSha256:hash(power)});console.log(JSON.stringify({accepted,hosts:14,power:56,candidateCircuitSha256:hash(candidate)}))