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/replace-ddr-host-route.ts

/** Isolated host-geometry alternative. Exact terminals, vias, net identities and
 * reference planes stay fixed; complete combined copper is rechecked. */
import {readFileSync,writeFileSync,mkdirSync} from 'node:fs'
import {resolve} from 'node:path'
import {createHash} from 'node:crypto'
import {verifyDdrCapture} from './ddr-capture-provenance'
import {verifyDdrSystemCopper} from './check-ddr-system-copper'
const [capture,integrated,donorPath,connectionName,out]=process.argv.slice(2)
if(!capture||!integrated||!donorPath||!connectionName||!out)throw Error('Usage: capture integrated-dir donor-bundle connection-name output-dir')
const read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),hash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex')
const {captureHash}=verifyDdrCapture(capture),circuit=read(resolve(integrated,'candidate.circuit.json')),host=read(resolve(integrated,'host-bundle.json')),report=read(resolve(integrated,'report.json')),donor=read(donorPath),connections=read(resolve(capture,'routing-input.json')).connections
if([host,report,donor].some(x=>x.captureHash!==captureHash)||host.layerSpace!=='physical'||donor.layerSpace!=='physical'||report.hostTracesSha256!==hash(host.traces))throw Error('Mismatched candidate provenance')
const target=host.traces.filter((t:any)=>t.connection_name===connectionName),replacement=donor.traces.filter((t:any)=>t.connection_name===connectionName)
if(target.length!==1||replacement.length!==1)throw Error('Requires one complete trace per net')
const a=target[0],b=replacement[0],point=(p:any)=>[p.x,p.y,p.layer],vias=(t:any)=>t.route.filter((p:any)=>p.route_type==='via')
if(hash(point(a.route[0]))!==hash(point(b.route[0]))||hash(point(a.route.at(-1)))!==hash(point(b.route.at(-1)))||hash(vias(a))!==hash(vias(b)))throw Error('Replacement changes exact terminal or via contract')
const traces=host.traces.map((t:any)=>t===a?{...t,route:structuredClone(b.route)}:t),ids=new Set(host.traces.map((t:any)=>t.pcb_trace_id)),fixed=circuit.filter((e:any)=>!ids.has(e.pcb_trace_id))
const physical=verifyDdrSystemCopper(fixed,traces,connections,{})
if(physical.errors.length||physical.violations.length||!physical.angles.valid||physical.joinedBends.length||report.physical.connectivity.filter((c:any)=>c.connected).some((c:any)=>!physical.connectivity.some(n=>n.name===c.name&&n.connected)))throw Error('Alternative loses verified geometry or connectivity')
mkdirSync(out,{recursive:true})
writeFileSync(resolve(out,'candidate.circuit.json'),JSON.stringify([...fixed,...traces],null,2)+'\n')
writeFileSync(resolve(out,'host-bundle.json'),JSON.stringify({captureHash,layerSpace:'physical',traces},null,2)+'\n')
writeFileSync(resolve(out,'report.json'),JSON.stringify({...report,hostTracesSha256:hash(traces),physical,routeReplacement:{connectionName,parentHostSha256:hash(host.traces),donorBundleSha256:hash(donor)},scope:'Geometric routing alternative; byte tuning deliberately deferred until remaining data routes are placed.'},null,2)+'\n')
console.log(JSON.stringify({connected:physical.connectivity.filter(c=>c.connected).length,errors:physical.errors.length,violations:physical.violations.length}))