forked from tonk-labs/dappicom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add the ability to dump instruction speciic ops with script to…
… autoformat Noir tests Now that I have the actual trace, I can see INX is actually broken. We have some strange status register reads cropping up
- Loading branch information
1 parent
ac18cc2
commit 1f7f184
Showing
9 changed files
with
429 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const fs = require('fs'); | ||
|
||
function readJsonFile(filename) { | ||
const fileContent = fs.readFileSync(filename, 'utf-8'); | ||
return JSON.parse(fileContent); | ||
} | ||
|
||
function splitIntoSegments(data) { | ||
const segments = []; | ||
let currentSegment = []; | ||
|
||
for (const entry of data) { | ||
if (entry.etype === 'DELIMITER') { | ||
if (currentSegment.length) { | ||
updateAddrBasedOnEtype(currentSegment); | ||
segments.push(currentSegment); | ||
currentSegment = []; | ||
} | ||
} else { | ||
currentSegment.push(entry); | ||
} | ||
} | ||
|
||
// Add any remaining segment | ||
if (currentSegment.length) { | ||
updateAddrBasedOnEtype(currentSegment); | ||
segments.push(currentSegment); | ||
} | ||
|
||
return segments; | ||
} | ||
|
||
const etypeToAddrMapping = { | ||
'PC': 8203, | ||
'X': 8201, | ||
'Y': 8202, | ||
'A': 8200, | ||
'S': 8205, | ||
'SP': 8204 | ||
} | ||
|
||
function updateAddrBasedOnEtype(segment) { | ||
for (const entry of segment) { | ||
if (etypeToAddrMapping[entry.etype] !== undefined) { | ||
entry.addr = etypeToAddrMapping[entry.etype]; | ||
} | ||
} | ||
} | ||
|
||
function convertSegment(segment) { | ||
const step = [], addr = [], val = [], op_rw = []; | ||
for (const entry of segment) { | ||
step.push(entry.step); | ||
addr.push(entry.addr); | ||
val.push(entry.val); | ||
op_rw.push(entry.op_rw == 'Read' ? 0 : 1); | ||
} | ||
return { step, addr, val, op_rw }; | ||
} | ||
|
||
function templateSegment(segmentData, index) { | ||
return ` | ||
#[test] | ||
fn test_${index}() { | ||
main( | ||
1, | ||
[${segmentData.step.join(", ")}], | ||
[${segmentData.addr.join(", ")}], | ||
[${segmentData.val.join(", ")}], | ||
[${segmentData.op_rw.join(", ")}] | ||
) | ||
}`; | ||
} | ||
|
||
function main() { | ||
const filePath = process.argv[2]; | ||
const jsonData = readJsonFile(filePath); | ||
const segments = splitIntoSegments(jsonData); | ||
let output = ""; | ||
|
||
for (let i = 0; i < segments.length; i++) { | ||
const segmentData = convertSegment(segments[i]); | ||
output += templateSegment(segmentData, i); | ||
} | ||
|
||
console.log(output); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.