Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tball/setting size config #10414

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pxtcompiler/emitter/backvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions pxtcompiler/emitter/hexfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
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