diff --git a/src/ide/project.ts b/src/ide/project.ts index 0c11974a..5bd7737d 100644 --- a/src/ide/project.ts +++ b/src/ide/project.ts @@ -407,6 +407,10 @@ export class CodeProject { var fnprefix = getFilenamePrefix(this.stripLocalPath(path)); var listings = this.getListings(); var onlyfile = null; + for (var lstfn in listings) { + if (lstfn == path) + return listings[lstfn]; + } for (var lstfn in listings) { onlyfile = lstfn; if (getFilenamePrefix(lstfn) == fnprefix) { diff --git a/src/ide/views/editors.ts b/src/ide/views/editors.ts index 7f922d73..513702c1 100644 --- a/src/ide/views/editors.ts +++ b/src/ide/views/editors.ts @@ -273,6 +273,7 @@ export class SourceEditor implements ProjectView { this.editor.clearGutter("gutter-clock"); var lstlines = this.sourcefile.lines || []; for (var info of lstlines) { + //if (info.path && info.path != this.path) continue; if (info.offset >= 0) { this.setGutter("gutter-offset", info.line-1, hex(info.offset&0xffff,4)); } @@ -574,7 +575,7 @@ export class ListingView extends DisassemblerView implements ProjectView { refreshListing() { // lookup corresponding assemblyfile for this file, using listing var lst = current_project.getListingForFile(this.path); - // TODO? + // TODO? this.assemblyfile = lst && (lst.assemblyfile || lst.sourcefile); } @@ -584,6 +585,7 @@ export class ListingView extends DisassemblerView implements ProjectView { if (!this.assemblyfile) return; var asmtext = this.assemblyfile.text; var disasmview = this.getDisasmView(); + // TODO: sometimes it picks one without a text file disasmview.setValue(asmtext); // go to PC if (!platform.saveState) return; diff --git a/src/worker/tools/cc65.ts b/src/worker/tools/cc65.ts index d90bbba4..8aff1e0d 100644 --- a/src/worker/tools/cc65.ts +++ b/src/worker/tools/cc65.ts @@ -1,5 +1,5 @@ -import { getRootBasePlatform } from "../../common/util"; +import { getFilenamePrefix, getRootBasePlatform } from "../../common/util"; import { CodeListingMap, WorkerError } from "../../common/workertypes"; import { re_crlf, BuildStepResult, anyTargetChanged, execMain, gatherFiles, msvcErrorMatcher, populateEntry, populateExtraFiles, populateFiles, print_fn, putWorkFile, setupFS, staleFiles, BuildStep, emglobal, loadNative, moduleInstFn, fixParamsWithDefines, store, makeErrorMatcher } from "../workermain"; import { EmscriptenModule } from "../workermain" @@ -18,14 +18,15 @@ import { EmscriptenModule } from "../workermain" 00B726 1 xx xx IBSECSZ: .res 2 00BA2F 1 2A 2B E8 2C HEX "2A2BE82C2D2E2F303132F0F133343536" */ -function parseCA65Listing(code: string, symbols, params, dbg: boolean) { +function parseCA65Listing(code: string, symbols, params, dbg: boolean, listings?: CodeListingMap) { var segofs = 0; var offset = 0; var dbgLineMatch = /^([0-9A-F]+)([r]?)\s+(\d+)\s+[.]dbg\s+(\w+), "([^"]+)", (.+)/; var funcLineMatch = /"(\w+)", (\w+), "(\w+)"/; var insnLineMatch = /^([0-9A-F]+)([r]?)\s{1,2}(\d+)\s{1,2}([0-9A-Frx ]{11})\s+(.*)/; var segMatch = /[.]segment\s+"(\w+)"/i; - var lines = []; + var origlines = []; + var lines = origlines; var linenum = 0; let curpath = ''; // TODO: only does .c functions, not all .s files @@ -35,6 +36,12 @@ function parseCA65Listing(code: string, symbols, params, dbg: boolean) { var dbgtype = dbgm[4]; offset = parseInt(dbgm[1], 16); curpath = dbgm[5]; + // new file? + if (curpath && listings) { + let l = listings[curpath]; + if (!l) l = listings[curpath] = {lines:[]}; + lines = l.lines; + } if (dbgtype == 'func') { var funcm = funcLineMatch.exec(dbgm[6]); if (funcm) { @@ -93,7 +100,7 @@ function parseCA65Listing(code: string, symbols, params, dbg: boolean) { } } } - return lines; + return origlines; } export function assembleCA65(step: BuildStep): BuildStepResult { @@ -220,13 +227,10 @@ export function linkLD65(step: BuildStep): BuildStepResult { var lstout = FS.readFile(fn, { encoding: 'utf8' }); lstout = lstout.split('\n\n')[1] || lstout; // remove header var asmlines = []; // TODO: parseCA65Listing(lstout, symbolmap, params, false); - var srclines = parseCA65Listing(lstout, symbolmap, params, true); + var srclines = parseCA65Listing(lstout, symbolmap, params, true, listings); putWorkFile(fn, lstout); - // TODO: multiple source files - // TODO: you have to get rid of all source lines to get asm listing listings[fn] = { - asmlines: srclines.length ? asmlines : null, - lines: srclines.length ? srclines : asmlines, + lines: [], text: lstout }; }