diff --git a/pxtcompiler/emitter/backvm.ts b/pxtcompiler/emitter/backvm.ts index 2b06e2ac4741..1df9c3a83fb7 100644 --- a/pxtcompiler/emitter/backvm.ts +++ b/pxtcompiler/emitter/backvm.ts @@ -340,7 +340,7 @@ _start_${name}: vmsource += "\n; The end.\n" bin.writeFile(BINARY_ASM, vmsource) - let res = assemble(opts.target, bin, vmsource) + let res = assemble(opts.target, bin, vmsource, cres) const srcmap = res.thumbFile.getSourceMap() const encodedSrcMap = encodeSourceMap(srcmap) diff --git a/pxtcompiler/emitter/hexfile.ts b/pxtcompiler/emitter/hexfile.ts index 333441581c39..d61990c349e9 100644 --- a/pxtcompiler/emitter/hexfile.ts +++ b/pxtcompiler/emitter/hexfile.ts @@ -1015,13 +1015,19 @@ ${hexfile.hexPrelude()} } let peepDbg = false - export function assemble(target: CompileTarget, bin: Binary, src: string) { + export function assemble(target: CompileTarget, bin: Binary, src: string, cres: CompileResult) { let b = mkProcessorFile(target) b.emit(src); + let settingsSizeDefault = cres.configData.find(ce => ce.name === "SETTINGS_SIZE_DEFL") + let settingsSize = cres.configData.find(ce => ce.name === "SETTINGS_SIZE") + let actualSettingsSize = settingsSize ? settingsSize.value : settingsSizeDefault ? settingsSizeDefault.value : 0 + + let flashUsableEnd = (target.flashUsableEnd ? target.flashUsableEnd : target.flashEnd) - actualSettingsSize + 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) @@ -1127,7 +1133,7 @@ __flash_checksums: } const prefix = opts.extinfo.outputPrefix || "" bin.writeFile(prefix + pxtc.BINARY_ASM, src) - const res = assemble(opts.target, bin, src) + const res = assemble(opts.target, bin, src, cres) if (res.thumbFile.commPtr) bin.commSize = res.thumbFile.commPtr - hexfile.getCommBase() if (res.src) diff --git a/pxtlib/emitter/assembler.ts b/pxtlib/emitter/assembler.ts index 6d131354c851..6de59bc30670 100644 --- a/pxtlib/emitter/assembler.ts +++ b/pxtlib/emitter/assembler.ts @@ -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 @@ -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",