-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasm.c
50 lines (47 loc) · 836 Bytes
/
asm.c
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
#include "yo.h"
char* instname[] = {
[INOP] = "nop",
[IADDW] = "addw",
[ISUBW] = "subw",
[IMULW] = "mulw",
[IRET] = "ret",
[IMOVW] = "movw",
[IMOVM] = "movm",
[ILEA] = "lea",
[ICALL] = "call",
[IJMP] = "jmp",
[PCALL] = "pcall",
[IFRAME] = "frame",
[IARRAY] = "array",
[ISLICE] = "slice",
[ILEN] = "len",
[IBEQW] = "beqw",
[IBNEQW] = "bneqw",
[ILTW] = "lt",
[ILEQW] = "leq",
[IEQW] = "eq",
[INEQW] = "neq",
};
void
asminst(FILE *f, Inst *in)
{
for(; in; in=in->next)
instconv(f, in);
}
void
asmexport(FILE *f, Sym *pkg, Decl **arr, int n)
{
fprintf(f, "\n\tpackage\t");
fprintf(f, "%s\n", pkg->name);
fprintf(f, "\tfn %d\n", n);
for(int i = 0; i < n; ++i){
Decl *d = arr[i];
switch(d->store){
default:
break;
case Dfn:
fprintf(f, "\tfn\t%s,%d,\n",d->sym->name, d->pc->pc);
break;
}
}
}