dbgloc line [col]
This is implemented in a backwards-compatible manner.
---
all.h | 5 +++--
amd64/emit.c | 2 +-
arm64/emit.c | 2 +-
emit.c | 7 +++++--
ops.h | 2 +-
parse.c | 9 ++++++++-
rv64/emit.c | 2 +-
7 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/all.h b/all.h
index 4d36314..fdda1cf 100644
--- a/all.h
+++ b/all.h
@@ -203,7 +203,8 @@ enum {
Kw,
Kl,
Ks,
- Kd
+ Kd,
+ Ko /* optional argument */
};
#define KWIDE(k) ((k)&1)
@@ -569,7 +570,7 @@ void rega(Fn *);
void emitfnlnk(char *, Lnk *, FILE *);
void emitdat(Dat *, FILE *);
void emitdbgfile(char *, FILE *);
-void emitdbgloc(uint, FILE *);
+void emitdbgloc(uint, uint, FILE *);
int stashbits(void *, int);
void elf_emitfnfin(char *, FILE *);
void elf_emitfin(FILE *);
diff --git a/amd64/emit.c b/amd64/emit.c
index 297cc76..51d1a5c 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -548,7 +548,7 @@ emitins(Ins i, Fn *fn, FILE *f)
emitcopy(i.arg[1], TMP(XMM0+15), i.cls, fn, f);
break;
case Odbgloc:
- emitdbgloc(i.arg[0].val, f);
+ emitdbgloc(i.arg[0].val, i.arg[1].val, f);
break;
}
}
diff --git a/arm64/emit.c b/arm64/emit.c
index 78a0358..990d839 100644
--- a/arm64/emit.c
+++ b/arm64/emit.c
@@ -447,7 +447,7 @@ emitins(Ins *i, E *e)
emitf("mov %=, sp", i, e);
break;
case Odbgloc:
- emitdbgloc(i->arg[0].val, e->f);
+ emitdbgloc(i->arg[0].val, i->arg[1].val, e->f);
break;
}
}
diff --git a/emit.c b/emit.c
index b880d67..490628e 100644
--- a/emit.c
+++ b/emit.c
@@ -235,7 +235,10 @@ emitdbgfile(char *fn, FILE *f)
}
void
-emitdbgloc(uint loc, FILE *f)
+emitdbgloc(uint line, uint col, FILE *f)
{
- fprintf(f, "\t.loc %u %u\n", curfile, loc);
+ if (col != 0)
+ fprintf(f, "\t.loc %u %u %u\n", curfile, line, col);
+ else
+ fprintf(f, "\t.loc %u %u\n", curfile, line);
}
diff --git a/ops.h b/ops.h
index b6b148a..a43c7fd 100644
--- a/ops.h
+++ b/ops.h
@@ -122,7 +122,7 @@ O(vastart, T(m,e,e,e, x,e,e,e), 0) X(0, 0, 0) V(0)
O(copy, T(w,l,s,d, x,x,x,x), 0) X(0, 0, 1) V(0)
/* Debug */
-O(dbgloc, T(w,l,s,d, x,x,x,x), 0) X(0, 0, 1) V(0)
+O(dbgloc, T(w,l,s,d, o,o,o,o), 0) X(0, 0, 1) V(0)
/****************************************/
/* INTERNAL OPERATIONS (keep nop first) */
diff --git a/parse.c b/parse.c
index 33ed6ec..0976a50 100644
--- a/parse.c
+++ b/parse.c
@@ -669,6 +669,13 @@ parseline(PState ps)
arg[0] = INT(tokval.num);
if (arg[0].val != tokval.num)
err("line number too big");
+ if (peek() == Tcomma) {
+ expect(Tcomma);
+ expect(Tint);
+ arg[1] = INT(tokval.num);
+ if (arg[1].val != tokval.num)
+ err("line number too big");
+ };
goto Ins;
}
if (op == Tcall) {
@@ -833,7 +840,7 @@ typecheck(Fn *fn)
err("no %s operand expected in %s",
n == 1 ? "second" : "first",
optab[i->op].name);
- if (rtype(r) == -1 && k != Kx)
+ if (rtype(r) == -1 && k != Kx && k != Ko)
err("missing %s operand in %s",
n == 1 ? "second" : "first",
optab[i->op].name);
diff --git a/rv64/emit.c b/rv64/emit.c
index 23a8be8..a410ddf 100644
--- a/rv64/emit.c
+++ b/rv64/emit.c
@@ -406,7 +406,7 @@ emitins(Ins *i, Fn *fn, FILE *f)
emitf("mv %=, sp", i, fn, f);
break;
case Odbgloc:
- emitdbgloc(i->arg[0].val, f);
+ emitdbgloc(i->arg[0].val, i->arg[1].val, f);
break;
}
}
--
2.43.0