Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit a191c5f

Browse files
committed
better size info
1 parent 029d770 commit a191c5f

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

compiler/src/compiler.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
30303039
export 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) {

compiler/src/info.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export interface RoleDebugInfo extends CellDebugInfo {
2626
}
2727

2828
export interface DebugInfo {
29+
sizes: Record<string, number> & {
30+
header: number
31+
floats: number
32+
strings: number
33+
roles: number
34+
align: number
35+
}
2936
functions: FunctionDebugInfo[]
3037
roles: RoleDebugInfo[]
3138
globals: CellDebugInfo[]
@@ -34,6 +41,13 @@ export interface DebugInfo {
3441

3542
export function emptyDebugInfo(): DebugInfo {
3643
return {
44+
sizes: {
45+
header: 0,
46+
floats: 0,
47+
strings: 0,
48+
roles: 0,
49+
align: 0,
50+
},
3751
functions: [],
3852
globals: [],
3953
roles: [],

compiler/src/opwriter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class OpWriter {
184184
}
185185

186186
get size() {
187-
return this.binPtr
187+
return this.binPtr + this.desc.length
188188
}
189189

190190
finalizeDesc(off: number, numlocals: number, numargs: number) {

0 commit comments

Comments
 (0)