1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include "lib9.h"
#include "isa.h"
#include "interp.h"
#include "mathi.h"
enum
{
TOKI0,
TOKI1,
TOKI2,
TOKI3,
TOKSB,
TOKFP
};
#include "tab.h"
typedef struct Addr Addr;
struct Addr
{
uchar mode;
Adr a;
};
#pragma varargck type "a" Addr*
char* opnam[256];
int iconv(Fmt*);
int aconv(Fmt*);
int
aconv(Fmt *f)
{
Addr *a;
char buf[64];
a = va_arg(f->args, Addr*);
if(a == nil)
return fmtstrcpy(f, "AZ");
switch(a->mode & AMASK) {
case AFP: sprint(buf, "%d(fp)", a->a.ind); break;
case AMP: sprint(buf, "%d(mp)", a->a.ind); break;
case AIMM: sprint(buf, "$%d", a->a.imm); break;
case AIND|AFP: sprint(buf, "%d(%d(fp))", a->a.i.s, a->a.i.f); break;
case AIND|AMP: sprint(buf, "%d(%d(mp))", a->a.i.s, a->a.i.f); break;
}
return fmtstrcpy(f, buf);
}
int
Dconv(Fmt *f)
{
int j;
Inst *i;
Addr s, d;
char buf[128];
static int init;
if(init == 0) {
for(j = 0; keywds[j].name != nil; j++)
opnam[keywds[j].op] = keywds[j].name;
fmtinstall('a', aconv);
init = 1;
}
i = va_arg(f->args, Inst*);
if(i == nil)
return fmtstrcpy(f, "IZ");
switch(keywds[i->op].terminal) {
case TOKI0:
sprint(buf, "%s", opnam[i->op]);
break;
case TOKI1:
d.a = i->d;
d.mode = UDST(i->add);
sprint(buf, "%s\t%a", opnam[i->op], &d);
break;
case TOKI3:
d.a = i->d;
d.mode = UDST(i->add);
s.a = i->s;
s.mode = USRC(i->add);
switch(i->add&ARM) {
default:
sprint(buf, "%s\t%a, %a", opnam[i->op], &s, &d);
break;
case AXIMM:
sprint(buf, "%s\t%a, $%d, %a", opnam[i->op], &s, i->reg, &d);
break;
case AXINF:
sprint(buf, "%s\t%a, %d(fp), %a", opnam[i->op], &s, i->reg, &d);
break;
case AXINM:
sprint(buf, "%s\t%a, %d(mp), %a", opnam[i->op], &s, i->reg, &d);
break;
}
break;
case TOKI2:
d.a = i->d;
d.mode = UDST(i->add);
s.a = i->s;
s.mode = USRC(i->add);
sprint(buf, "%s\t%a, %a", opnam[i->op], &s, &d);
break;
}
return fmtstrcpy(f, buf);
}
|