-
Notifications
You must be signed in to change notification settings - Fork 1
/
txemtbin.t
101 lines (82 loc) · 1.47 KB
/
txemtbin.t
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
! T3X/0 compiler: binary emitter module
! Nils M Holm, 2022, 2023
! Public Domain / 0BSD License
module txemit;
public findlab(id) return Labels[id];
public emits(v);
public totext();
public todata();
public demit(v) emit(v);
public demitw(v) emitw(v);
public demitaddr(v) emitw(v);
public dskip(a) gen(CG_SKIP, a);
hex(c) ie (numeric(c))
return c-'0';
else
return c-'a'+10;
byte(s) return 16*hex(s::0) + hex(s::1);
public rgen(s, v) do var n;
while (s::0) do
ie (s::0 = ',') do
ie (s::1 = 'w')
emitw(v);
else ie (s::1 = 'l')
emit(v);
else ie (s::1 = 'h')
emit(v+1);
else ie (s::1 = 'r')
emit(v-Tp-1);
else ie (s::1 = 'R')
emitw(v-Tp-2);
else ie (s::1 = '>') do
n := byte(s+4) << 8 | byte(s+2);
emitw(n-Tp-2);
s := s+4;
end
else
oops("rgen", 0);
end
else do
emit(byte(s));
end
s := s+2;
end
end
public droplab() do
commit();
return Tp;
end
public dropdlab() do
commit();
return Tp;
end
public resolve(id) do
commit();
Labels[id] := Tp;
end
public resolve_data(id) resolve(id);
public globaddr() do var l, i, g;
if (Gp >= Gtop) do
l := newlab();
gen(CG_RJUMP, findlab(l));
commit();
Gp := Tp;
for (i=0, CG.GPOOL_SIZE) emitw(0);
Gtop := Tp;
resolve(l);
end
g := Gp;
Gp := Gp+2;
return g;
end
public emitlib() do var i, j, k, lib;
lib := cg.library();
i := 0;
while (lib[i]) do
k := lib[i];
i := i+1;
for (j=0, k) emit(lib[i]::j);
i := i+1;
end
end
end