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/export-ddr-ordered-facing-cache.ts

/** Export the full local RAM cache and explicit exit contract for an isolated candidate. */
import {readFileSync,writeFileSync} from 'node:fs'
import {resolve} from 'node:path'
import {verifyDdrCapture} from './ddr-capture-provenance'
import {buildFacingRamCache} from './assemble-ddr-facing-progress'
import {applyFacingExitReplacements} from './ddr-facing-context'
import {objectHash} from './improve-ddr-a9-power-launches'
const [capture,parentDir,out]=process.argv.slice(2)
if(!capture||!parentDir||!out)throw Error('Usage: frozen-capture parent-composite ordered-candidate')
const read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),write=(p:string,x:any)=>writeFileSync(resolve(out,p),JSON.stringify(x,null,2)+'\n')
const {captureHash,snapshot}=verifyDdrCapture(capture),parent=read(resolve(parentDir,'candidate.circuit.json')),candidate=read(resolve(out,'candidate.circuit.json')),report=read(resolve(out,'report.json')),changes=read(resolve(out,'replacements.json'))
if(report.captureHash!==captureHash||!report.accepted||objectHash(parent)!==report.parentCircuitSha256)throw Error('Candidate provenance mismatch')
const retired=new Set(changes.invalidatedHostTraces.map((t:any)=>t.pcb_trace_id))
for(const t of changes.invalidatedHostTraces)if(objectHash(parent.find((e:any)=>e.pcb_trace_id===t.pcb_trace_id))!==objectHash(t))throw Error('Retired host differs')
if(objectHash(applyFacingExitReplacements(parent.filter((e:any)=>!retired.has(e.pcb_trace_id)),changes))!==objectHash(candidate))throw Error('Actual candidate differs from replacement witness')
const find=(exitId:string)=>{const e=candidate.find((e:any)=>e.pcb_breakout_point_id===exitId);return candidate.find((t:any)=>t.type==='pcb_trace'&&t.source_trace_id===e.source_trace_id)}
const replacements=[{ball:'B7',trace:find('pcb_breakout_point_349')},{ball:'E7',trace:find('pcb_breakout_point_352')}],cache=buildFacingRamCache(snapshot,replacements),placement=snapshot.placements[0]
const exits=replacements.map(({ball,trace})=>{
 const end=trace.route.at(-1),previous=[...trace.route].reverse().find((p:any)=>p.route_type==='wire'&&p.layer===end.layer&&Math.hypot(end.x-p.x,end.y-p.y)>1e-7)
 if(!previous||end.x<=previous.x||end.layer!=='inner4')throw Error('Invalid outward exit')
 const dx=end.x-previous.x,dy=end.y-previous.y,d=Math.hypot(dx,dy),world={x:dx/d,y:dy/d},local={x:-world.x,y:-world.y}
 return {ball,terminal:ball==='B7'?'DM':'DQ7',worldSide:'right',localSide:'left',placementRotationDegrees:180,worldExit:{x:end.x,y:end.y,layer:end.layer},localExit:{x:placement.pcbX-end.x,y:placement.pcbY-end.y,layer:end.layer},tangent:{world,local},tangentDegrees:{world:Math.atan2(world.y,world.x)*180/Math.PI,local:Math.atan2(local.y,local.x)*180/Math.PI},logicalViaTransition:'top->inner4',physicalViaSpan:'all ten layers',traceWidthMm:.12}
})
write('ram-byte0-ordered-facing.trace-paths.json',cache.paths)
write('exit-contract.json',{captureHash,candidateCircuitSha256:objectHash(candidate),ramCacheSha256:objectHash(cache.paths),pathCount:72,changedBalls:['B7','E7'],unchangedPaths:70,physicalLayerCount:10,identityLayerMappingRequired:true,paddingChangeMm:0,paddingChangeBySideMm:{left:0,right:0,top:0,bottom:0},priorCenterlineBounds:cache.before,newCenterlineBounds:cache.after,exits,hostScope:{retainedGeometricallyConnected:10,knownTopologyInvalidSignal:'DDR_D12',topologyEligibleAfterRemovingKnownInvalidHost:9,oldDM0HostRetired:true,newDM0HostRouted:false},scope:'Experimental full RAM0 cache and explicit coordinate contract. Ten geometric host paths include known DQ12 topology failure; downstream routing must remove it and use the separately verified nine-path seed. No complete DDR qualification.'})
console.log(JSON.stringify({pathCount:72,unchangedPaths:70,paddingChangeMm:0,exits}))