Skip to content

Commit

Permalink
Tball/check size (#10404)
Browse files Browse the repository at this point in the history
* update check

* make sure to backstop flashusableend

* off by one
  • Loading branch information
tballmsft authored Mar 7, 2025
1 parent 5bf37d4 commit 3094ae4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pxtcompiler/emitter/hexfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,11 @@ ${hexfile.hexPrelude()}
let b = mkProcessorFile(target)
b.emit(src);

let flashUsableEnd = target.flashUsableEnd ? target.flashUsableEnd : target.flashEnd

src = `; Interface tables: ${bin.itFullEntries}/${bin.itEntries} (${Math.round(100 * bin.itFullEntries / bin.itEntries)}%)\n` +
`; Virtual methods: ${bin.numVirtMethods} / ${bin.numMethods}\n` +
b.getSource(!peepDbg, bin.numStmts, target.flashEnd);
b.getSource(!peepDbg, bin.numStmts, flashUsableEnd);

throwAssemblerErrors(b)

Expand Down
14 changes: 7 additions & 7 deletions pxtlib/emitter/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ namespace ts.pxtc.assembler {
return r
}

public getSource(clean: boolean, numStmts = 1, flashSize = 0) {
public getSource(clean: boolean, numStmts = 1, flashUsableEnd = 0) {
let lenPrev = 0
let size = (lbl: string) => {
let curr = this.labels[lbl] || lenPrev
Expand All @@ -1081,18 +1081,18 @@ namespace ts.pxtc.assembler {
let lenVtables = size("_vtables_end")
let lenLiterals = size("_literals_end")
let lenAllCode = lenPrev
let totalSize = (lenTotal + this.baseOffset) & 0xffffff
let totalEnd = (lenTotal + this.baseOffset) & 0xffffff

if (flashSize && totalSize > flashSize) {
const e = new Error(lf("program too big by {0} bytes!", totalSize - flashSize));
if (flashUsableEnd && totalEnd > flashUsableEnd) {
const e = new Error(lf("program too big by {0} bytes!", totalEnd - flashUsableEnd));
(e as any).ksErrorCode = 9283;
throw e;
}

flashSize = flashSize || 128 * 1024
flashUsableEnd = flashUsableEnd || 128 * 1024
let totalInfo = lf("; total bytes: {0} ({1}% of {2}k flash with {3} free)",
totalSize, (100 * totalSize / flashSize).toFixed(1), (flashSize / 1024).toFixed(1),
flashSize - totalSize)
totalEnd, (100 * totalEnd / flashUsableEnd).toFixed(1), (flashUsableEnd / 1024).toFixed(1),
flashUsableEnd - totalEnd)
let res =
// ARM-specific
lf("; generated code sizes (bytes): {0} (incl. {1} user, {2} helpers, {3} vtables, {4} lits); src size {5}\n",
Expand Down

0 comments on commit 3094ae4

Please sign in to comment.