1
// Derived from Inferno utils/6c/list.c
2
// http://code.google.com/p/inferno-os/source/browse/utils/6c/list.c
4
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
6
// Portions Copyright © 1997-1999 Vita Nuova Limited
7
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
8
// Portions Copyright © 2004,2006 Bruce Ellis
9
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
10
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
11
// Portions Copyright © 2009 The Go Authors. All rights reserved.
13
// Permission is hereby granted, free of charge, to any person obtaining a copy
14
// of this software and associated documentation files (the "Software"), to deal
15
// in the Software without restriction, including without limitation the rights
16
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
// copies of the Software, and to permit persons to whom the Software is
18
// furnished to do so, subject to the following conditions:
20
// The above copyright notice and this permission notice shall be included in
21
// all copies or substantial portions of the Software.
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40
fmtinstall('A', Aconv); // as
41
fmtinstall('P', Pconv); // Prog*
42
fmtinstall('D', Dconv); // Addr*
43
fmtinstall('R', Rconv); // reg
44
fmtinstall('Y', Yconv); // sconst
54
p = va_arg(fp->args, Prog*);
57
if(p->from.scale != 0 && (p->as == AGLOBL || p->as == ATEXT))
58
snprint(scale, sizeof scale, "%d,", p->from.scale);
61
snprint(str, sizeof(str), "%.4d (%L) %-7A %D,%s%D",
62
p->loc, p->lineno, p->as, &p->from, scale, &p->to);
66
sconsize = p->from.scale;
67
snprint(str, sizeof(str), "%.4d (%L) %-7A %D/%d,%D",
68
p->loc, p->lineno, p->as, &p->from, sconsize, &p->to);
72
snprint(str, sizeof(str), "%.4d (%L) %-7A %D,%s%lD",
73
p->loc, p->lineno, p->as, &p->from, scale, &p->to);
76
return fmtstrcpy(fp, str);
82
char str[STRINGSZ], s[STRINGSZ];
87
a = va_arg(fp->args, Addr*);
91
snprint(str, sizeof(str), "%lld(%R)", a->offset, i-D_INDIR);
93
snprint(str, sizeof(str), "(%R)", i-D_INDIR);
100
snprint(str, sizeof(str), "$%lld,%R", a->offset, i);
102
snprint(str, sizeof(str), "%R", i);
110
if(a->u.branch == nil)
111
snprint(str, sizeof(str), "<nil>");
113
snprint(str, sizeof(str), "%d", a->u.branch->loc);
117
snprint(str, sizeof(str), "%S+%lld(SB)", a->sym, a->offset);
121
snprint(str, sizeof(str), "%S<>+%lld(SB)", a->sym, a->offset);
125
snprint(str, sizeof(str), "%S+%lld(SP)", a->sym, a->offset);
129
snprint(str, sizeof(str), "%S+%lld(FP)", a->sym, a->offset);
133
if(fp->flags & FmtLong) {
134
d1 = a->offset & 0xffffffffLL;
135
d2 = (a->offset>>32) & 0xffffffffLL;
136
snprint(str, sizeof(str), "$%lud-%lud", (ulong)d1, (ulong)d2);
139
snprint(str, sizeof(str), "$%lld", a->offset);
143
snprint(str, sizeof(str), "$(%.17e)", a->u.dval);
147
snprint(str, sizeof(str), "$\"%Y\"", a->u.sval);
153
snprint(str, sizeof(str), "$%D", a);
159
if(a->index != D_NONE) {
160
snprint(s, sizeof(s), "(%R*%d)", (int)a->index, (int)a->scale);
166
fmtprint(fp, "{%s}", a->gotype->name);
170
static char* regstr[] =
253
"GDTR", /* [D_GDTR] */
254
"IDTR", /* [D_IDTR] */
255
"LDTR", /* [D_LDTR] */
257
"TASK", /* [D_TASK] */
294
"NONE", /* [D_NONE] */
303
r = va_arg(fp->args, int);
304
if(r < 0 || r >= nelem(regstr) || regstr[r] == nil) {
305
snprint(str, sizeof(str), "BAD_R(%d)", r);
306
return fmtstrcpy(fp, str);
308
return fmtstrcpy(fp, regstr[r]);
316
i = va_arg(fp->args, int);
317
return fmtstrcpy(fp, anames[i]);
325
char str[STRINGSZ], *p, *a;
327
a = va_arg(fp->args, char*);
329
for(i=0; i<sconsize; i++) {
331
if((c >= 'a' && c <= 'z') ||
332
(c >= 'A' && c <= 'Z') ||
333
(c >= '0' && c <= '9')) {
340
if(c < 040 || c >= 0177)
341
break; /* not portable */
359
*p++ = ((c>>3) & 7) + '0';
360
*p++ = (c & 7) + '0';
363
return fmtstrcpy(fp, str);