From d97b0eb1c5258d7623fa56d1104c665ed7b947ab Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 8 Apr 2021 10:33:48 -0500 Subject: [PATCH] dasm: fixed macro line parsing, breakpoints --- package.json | 2 +- presets/verilog/Makefile | 2 +- src/common/workertypes.ts | 8 +++++-- src/ide/project.ts | 4 ++-- src/worker/workermain.ts | 45 +++++++++++++++++++++++++++++---------- test/cli/testworker.js | 4 ++-- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 93275bcb..056ea015 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "8bitworkshop", - "version": "3.7.1", + "version": "3.7.2", "author": "Steven Hugg", "description": "8bitworkshop.com", "repository": { diff --git a/presets/verilog/Makefile b/presets/verilog/Makefile index 39912cef..ad02bab3 100644 --- a/presets/verilog/Makefile +++ b/presets/verilog/Makefile @@ -7,7 +7,7 @@ deps.dot: grep \`include *.v | sed "s/:/ /g" | awk '{ print "\"" $1 "\" -> " $3 ";" }' %.bin: %.v - ~/yosys/yosys -p "synth_ice40 -blif $*.blif" $*.v + yosys -p "synth_ice40 -blif $*.blif" $*.v arachne-pnr -d 1k -p icestick.pcf $*.blif -o $*.asc icepack $*.asc $*.bin #iceprog $*.bin diff --git a/src/common/workertypes.ts b/src/common/workertypes.ts index 963a2ae8..b1aca757 100644 --- a/src/common/workertypes.ts +++ b/src/common/workertypes.ts @@ -31,8 +31,12 @@ export class SourceFile { this.line2offset = new Map(); for (var info of lines) { if (info.offset >= 0) { - this.offset2loc[info.offset] = info; - this.line2offset[info.line] = info.offset; + // first line wins (is assigned to offset) + // TODO: handle macros/includes w/ multiple offsets per line + if (!this.offset2loc[info.offset]) + this.offset2loc[info.offset] = info; + if (!this.line2offset[info.line]) + this.line2offset[info.line] = info.offset; } } } diff --git a/src/ide/project.ts b/src/ide/project.ts index dd533469..c27b3a43 100644 --- a/src/ide/project.ts +++ b/src/ide/project.ts @@ -384,8 +384,8 @@ export class CodeProject { // returns first listing in format [prefix].lst (TODO: could be better) getListingForFile(path: string) : CodeListing { // ignore include files (TODO) - if (path.toLowerCase().endsWith('.h') || path.toLowerCase().endsWith('.inc')) - return; + //if (path.toLowerCase().endsWith('.h') || path.toLowerCase().endsWith('.inc')) + //return; var fnprefix = getFilenamePrefix(this.stripLocalPath(path)); var listings = this.getListings(); var onlyfile = null; diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts index 81b2e628..7374beb4 100644 --- a/src/worker/workermain.ts +++ b/src/worker/workermain.ts @@ -715,23 +715,35 @@ function parseSourceLines(code:string, lineMatch, offsetMatch) { return lines; } -function parseDASMListing(code:string, listings:CodeListingMap, errors:WorkerError[], unresolved:{}) { +function parseDASMListing(lstpath:string, lsttext:string, listings:CodeListingMap, errors:WorkerError[], unresolved:{}) { // TODO: this gets very slow // 4 08ee a9 00 start lda #01workermain.js:23:5 var lineMatch = /\s*(\d+)\s+(\S+)\s+([0-9a-f]+)\s+([?0-9a-f][?0-9a-f ]+)?\s+(.+)?/i; var equMatch = /\bequ\b/i; - var macroMatch = /\bMAC\s+(.+)?/i; + var macroMatch = /\bMAC\s+(\S+)?/i; var lastline = 0; var macros = {}; - for (var line of code.split(re_crlf)) { - var linem = lineMatch.exec(line); - if (linem && linem[1]) { + var lstline = 0; + var lstlist = listings[lstpath]; + for (var line of lsttext.split(re_crlf)) { + lstline++; + var linem = lineMatch.exec(line + " "); + if (linem && linem[1] != null) { var linenum = parseInt(linem[1]); var filename = linem[2]; var offset = parseInt(linem[3], 16); var insns = linem[4]; var restline = linem[5]; if (insns && insns.startsWith('?')) insns = null; + // don't use listing yet + if (lstlist && lstlist.lines) { + lstlist.lines.push({ + line:lstline, + offset:offset, + insns:insns, + iscode:true, + }); + } // inside of a file? var lst = listings[filename]; if (lst) { @@ -753,16 +765,26 @@ function parseDASMListing(code:string, listings:CodeListingMap, errors:WorkerErr } else { // inside of macro? var mac = macros[filename.toLowerCase()]; - if (insns && mac) { - /* + // macro invocation in main file + if (mac && linenum == 0) { lines.push({ - path:mac.file, - line:mac.line+linenum, + line:lastline+1, offset:offset, insns:insns, iscode:true }); - */ + } + if (insns && mac) { + var maclst = listings[mac.file]; + if (maclst && maclst.lines) { + maclst.lines.push({ + path:mac.file, + line:mac.line+linenum, + offset:offset, + insns:insns, + iscode:true + }); + } // TODO: a listing file can't include other files } else { // inside of macro or include file @@ -846,10 +868,11 @@ function assembleDASM(step:BuildStep) { var alst = FS.readFile(lstpath, {'encoding':'utf8'}); // parse main listing, get errors and listings for each file var listings : CodeListingMap = {}; + //listings[lstpath] = {lines:[], text:alst}; for (let path of step.files) { listings[path] = {lines:[]}; } - parseDASMListing(alst, listings, errors, unresolved); + parseDASMListing(lstpath, alst, listings, errors, unresolved); if (errors.length) { return {errors:errors}; } diff --git a/test/cli/testworker.js b/test/cli/testworker.js index 0d5f4212..60f7ffd5 100644 --- a/test/cli/testworker.js +++ b/test/cli/testworker.js @@ -82,10 +82,10 @@ function doBuild(msgs, callback, outlen, nlines, nerrors, options) { describe('Worker', function() { it('should assemble DASM', function(done) { - compile('dasm', '\tprocessor 6502\n\torg $f000\nfoo lda #0\n', 'vcs.mame', done, 2, 1); + compile('dasm', '\tprocessor 6502\n\torg $f000\n MAC mack\n lda #0\n ENDM\nfoo: mack\n mack\n', 'vcs.mame', done, 4, 4); }); it('should NOT assemble DASM', function(done) { - compile('dasm', '\tprocessor 6502\n\torg $f000 ; this is a comment\nfoo asl a\n', 'vcs', done, 0, 0, 1); + compile('dasm', '\tprocessor 6502\n\torg $f000 ; this is a comment\nfoo asl a\n', 'vcs', done, 0, 0, 2); }); /* it('should assemble ACME', function(done) {