aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-19 09:49:50 +0200
committerlemon <lsof@mailbox.org>2023-06-19 09:49:50 +0200
commit43abf782b12e883fdf3b15402b7fa09546acb9af (patch)
tree9b22685742cc99484592059072620bbea2291dfc
parent7a6b76f519695d686c378f2450658504448c75f6 (diff)
add %y symbol printing
-rw-r--r--io.c12
-rw-r--r--irdump.c6
2 files changed, 14 insertions, 4 deletions
diff --git a/io.c b/io.c
index 5c15600..eb29ca7 100644
--- a/io.c
+++ b/io.c
@@ -361,6 +361,7 @@ vbfmt(struct wbuf *out, const char *fmt, va_list ap)
n += bwriteS(buf, "(null)");
break;
}
+ QuotedStr:
n += bputc(buf, '"');
if (lmod) /* lower */
for (; *s; ++s) n += putquoted(buf, aisalpha(*s) ? *s|32 : *s, '"', s[1]);
@@ -388,6 +389,17 @@ vbfmt(struct wbuf *out, const char *fmt, va_list ap)
n += i;
}
break;
+ case 'y': /* symbol: print string literally if valid identifier, or quote it */
+ s = va_arg(ap, const char *);
+ assert(s && "%y null");
+ for (i = 0; s[i]; ++i) {
+ if (aisalpha(s[i]) || s[i] == '_' || (i > 0 && aisdigit(s[i])))
+ continue;
+ goto QuotedStr;
+ }
+ /* valid identifier */
+ while (*s) n += bputc(buf, *s++);
+ break;
case 'd': /* decimal */
base = 10;
Int:
diff --git a/irdump.c b/irdump.c
index 2d0dbf4..5ea7d48 100644
--- a/irdump.c
+++ b/irdump.c
@@ -2,12 +2,10 @@
static int nextdat;
-#define aisprint(c) in_range(c, ' ', '~')
-
static void
pridat(const struct irdat *dat)
{
- efmt("%s %'s(align %d, size %d):\n\t", dat->mut ? "dat" : "rodat", dat->name, dat->align, dat->siz);
+ efmt("%s %y(align %d, size %d):\n\t", dat->mut ? "dat" : "rodat", dat->name, dat->align, dat->siz);
assert(!dat->syms);
if (dat->siz <= 8) {
efmt("b ");
@@ -91,7 +89,7 @@ dumpref(enum op o, union ref ref)
case RXCON:
con = &conht[ref.i];
if (con->deref) efmt("*[");
- if (con->issym || con->isdat) efmt("$%s", xcon2sym(ref.i));
+ if (con->issym || con->isdat) efmt("$%y", xcon2sym(ref.i));
else switch (con->cls) {
case KI4: efmt("%d", (int)con->i); break;
case KI8: efmt("%ld", con->i); break;