@@ -2772,6 +2772,7 @@ class Program implements TopOpWriter {
27722772 s . finalize ( off )
27732773 off += s . size
27742774 }
2775+
27752776 const mask = BinFmt . BINARY_SIZE_ALIGN - 1
27762777 off = ( off + mask ) & ~ mask
27772778 const outp = new Uint8Array ( off )
@@ -2800,7 +2801,21 @@ class Program implements TopOpWriter {
28002801 const left = outp . length - off
28012802 assert ( 0 <= left && left < BinFmt . BINARY_SIZE_ALIGN )
28022803
2803- return outp
2804+ const dbg : DebugInfo = {
2805+ sizes : {
2806+ header : fixHeader . size + sectDescs . size ,
2807+ floats : floatData . size ,
2808+ strings : strData . size + strDesc . size ,
2809+ roles : roleData . size ,
2810+ align : left ,
2811+ } ,
2812+ roles : this . roles . list . map ( r => ( r as Role ) . debugInfo ( ) ) ,
2813+ functions : this . procs . map ( p => p . debugInfo ( ) ) ,
2814+ globals : this . globals . list . map ( r => r . debugInfo ( ) ) ,
2815+ source : this . _source ,
2816+ }
2817+
2818+ return { binary : outp , dbg }
28042819 }
28052820
28062821 getAssembly ( ) {
@@ -2855,18 +2870,12 @@ class Program implements TopOpWriter {
28552870 if ( this . numErrors == 0 )
28562871 this . host . write ( DEVS_ASSEMBLY_FILE , this . getAssembly ( ) )
28572872
2858- const b = this . serialize ( )
2859- const dbg : DebugInfo = {
2860- roles : this . roles . list . map ( r => ( r as Role ) . debugInfo ( ) ) ,
2861- functions : this . procs . map ( p => p . debugInfo ( ) ) ,
2862- globals : this . globals . list . map ( r => r . debugInfo ( ) ) ,
2863- source : this . _source ,
2864- }
2865- this . host . write ( DEVS_BYTECODE_FILE , b )
2873+ const { binary, dbg } = this . serialize ( )
2874+ this . host . write ( DEVS_BYTECODE_FILE , binary )
28662875 const progJson = {
28672876 text : this . _source ,
28682877 blocks : "" ,
2869- compiled : toHex ( b ) ,
2878+ compiled : toHex ( binary ) ,
28702879 }
28712880 this . host . write ( DEVS_BODY_FILE , JSON . stringify ( progJson , null , 4 ) )
28722881 this . host . write ( DEVS_DBG_FILE , JSON . stringify ( dbg , null , 4 ) )
@@ -2878,7 +2887,7 @@ class Program implements TopOpWriter {
28782887
28792888 if ( this . numErrors == 0 ) {
28802889 try {
2881- this . host ?. verifyBytecode ( b , dbg )
2890+ this . host ?. verifyBytecode ( binary , dbg )
28822891 } catch ( e ) {
28832892 this . reportError ( this . mainFile , e . message )
28842893 }
@@ -2912,7 +2921,7 @@ class Program implements TopOpWriter {
29122921
29132922 return {
29142923 success : this . numErrors == 0 ,
2915- binary : b ,
2924+ binary : binary ,
29162925 dbg : dbg ,
29172926 clientSpecs,
29182927 }
@@ -3030,9 +3039,22 @@ export function testCompiler(host: Host, code: string) {
30303039export function computeSizes ( dbg : DebugInfo ) {
30313040 const funs = dbg . functions . slice ( )
30323041 funs . sort ( ( a , b ) => a . size - b . size || strcmp ( a . name , b . name ) )
3042+ let ftotal = 0
3043+ for ( const f of funs ) {
3044+ ftotal += f . size
3045+ }
3046+ let dtotal = 0
3047+ for ( const v of Object . values ( dbg . sizes ) ) dtotal += v
30333048 return (
3049+ "## Data\n" +
3050+ Object . keys ( dbg . sizes )
3051+ . map ( k => `${ dbg . sizes [ k ] } \t${ k } \n` )
3052+ . join ( "" ) +
3053+ `${ dtotal } \tData TOTAL\n` +
30343054 "\n## Functions\n" +
3035- funs . map ( f => `${ f . size } \t${ f . name } \t${ locs2str ( f . users ) } \n` ) . join ( "" )
3055+ funs . map ( f => `${ f . size } \t${ f . name } \t${ locs2str ( f . users ) } \n` ) . join ( "" ) +
3056+ `${ ftotal } \tFunction TOTAL\n\n` +
3057+ `${ dtotal + ftotal } \tTOTAL\n`
30363058 )
30373059
30383060 function loc2str ( l : SrcLocation ) {
0 commit comments