@@ -3,7 +3,6 @@ import { readdirSync, readFileSync, writeFileSync } from "node:fs";
33import { Biome , Distribution } from "@biomejs/js-api" ;
44import { config , createResultFilePath , errorFilePath , finalResultPath , formatterErrorFilePath , resultsDirectory , resumeMode , shouldTakeABreath , startFilePath } from "./config" ;
55import { VirtualTypeScriptEnvironment } from "@typescript/vfs" ;
6- import ts from "typescript" ;
76import { inspect } from "node:util" ;
87import { join } from "node:path" ;
98
@@ -70,8 +69,38 @@ const extractAddress = (line: string) => {
7069}
7170
7271const sortMemoryLines = ( memoryLines : string ) => memoryLines . split ( '\n' )
73- . sort ( ( a , b ) => extractAddress ( a ) - extractAddress ( b ) )
74- . join ( '\n' ) ;
72+ . sort ( ( a , b ) => extractAddress ( a ) - extractAddress ( b ) )
73+ . join ( '\n' ) ;
74+
75+ const sortSections = ( data : string ) => {
76+ // find the lines between `\tmemory: {` and `\t{`
77+ const memoryLines = data . match ( / \t m e m o r y : { \r ? \n ( .* ?) \r ? \n \t } / s) ;
78+ if ( memoryLines ) {
79+ const old = memoryLines [ 1 ] ;
80+ if ( old . indexOf ( `"111111111` ) !== - 1 ) {
81+ writeFileSync ( errorFilePath , data , "utf-8" ) ;
82+ throw new Error ( `found an invalid memory address!` ) ;
83+ }
84+ const sorted = sortMemoryLines ( old ) ;
85+ data = data . replace ( old , sorted )
86+ }
87+
88+ const L1CacheLines = data . match ( / \t L 1 C a c h e : { \r ? \n ( .* ?) \r ? \n \t } / s) ;
89+ if ( L1CacheLines ) {
90+ const old = L1CacheLines [ 1 ] ;
91+ const sorted = sortMemoryLines ( old ) ;
92+ data = data . replace ( old , sorted )
93+ }
94+
95+ const activeLocalsLines = data . match ( / \t a c t i v e L o c a l s : { \r ? \n ( .* ?) \r ? \n \t } / s) ;
96+ if ( activeLocalsLines ) {
97+ const old = activeLocalsLines [ 1 ] ;
98+ const sorted = old . split ( '\n' ) . sort ( ) . join ( '\n' ) ;
99+ data = data . replace ( old , sorted )
100+ }
101+
102+ return data ;
103+ }
75104
76105export const fsWorker = {
77106 writeFile : (
@@ -95,16 +124,7 @@ export const fsWorker = {
95124 }
96125
97126 if ( kind === 'ts' ) {
98- // find the lines between `\tmemory: {` and `\t{`
99- const start = data . indexOf ( '\tmemory: {' ) ;
100- const end = data . indexOf ( '\t}' , start ) ;
101- const memoryLines = data . substring ( start , end ) ;
102- const sortedMemoryLines = sortMemoryLines ( memoryLines ) ;
103- data = data . replace ( memoryLines , sortedMemoryLines ) ;
104- if ( memoryLines . indexOf ( `"111111111` ) !== - 1 ) {
105- writeFileSync ( errorFilePath , data , "utf-8" ) ;
106- throw new Error ( `found an invalid memory address!` ) ;
107- }
127+ data = sortSections ( data ) ;
108128 }
109129
110130 writeFileSync ( filePath , data , "utf-8" ) ;
0 commit comments