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-codesign-replacements.ts
import{readFileSync,writeFileSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
const[parentDir,childDir]=process.argv.slice(2),read=(p:string)=>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`]}`,parent=read(resolve(parentDir,'candidate.circuit.json')),child=read(resolve(childDir,'candidate.circuit.json')),host=read(resolve(childDir,'host-bundle.json')),a=new Map(parent.map((e:any)=>[key(e),e])),b=new Map(child.map((e:any)=>[key(e),e]))
if(a.size!==parent.length||b.size!==child.length)throw Error('Duplicate object IDs')
const replacements=child.filter((e:any)=>a.has(key(e))&&hash(a.get(key(e)))!==hash(e)).map((e:any)=>({id:key(e),before:a.get(key(e)),after:e,beforeSha256:hash(a.get(key(e))),afterSha256:hash(e)})),removals=parent.filter((e:any)=>!b.has(key(e))),additions=child.filter((e:any)=>!a.has(key(e))),replay=new Map(a)
for(const w of replacements)replay.set(w.id,w.after);for(const e of removals)replay.delete(key(e));for(const e of additions)replay.set(key(e),e)
if(replay.size!==child.length||child.some((e:any)=>hash(replay.get(key(e)))!==hash(e)))throw Error('Replay mismatch')
writeFileSync(resolve(childDir,'original-copper-replacements.json'),JSON.stringify({captureHash:host.captureHash,parentDirectory:resolve(parentDir),parentCircuitSha256:hash(parent),candidateCircuitSha256:hash(child),replacements,removals,additions,allOtherElementsExact:true,scope:'Exact geometry co-design diff; no claim of full byte matching or complete DDR qualification.'},null,2))
console.log(JSON.stringify({replacements:replacements.length,removals:removals.length,additions:additions.length}))