dasm: fixed macro line parsing, breakpoints

This commit is contained in:
Steven Hugg 2021-04-08 10:33:48 -05:00
parent 4ccf588c80
commit d97b0eb1c5
6 changed files with 46 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{
"name": "8bitworkshop",
"version": "3.7.1",
"version": "3.7.2",
"author": "Steven Hugg",
"description": "8bitworkshop.com",
"repository": {

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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};
}

View File

@ -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) {