-
Notifications
You must be signed in to change notification settings - Fork 1
/
txemtsrc.t
143 lines (123 loc) · 1.77 KB
/
txemtsrc.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
! T3X/0 compiler: source code emitter module
! Nils M Holm, 2022, 2023
! Public Domain / 0BSD License
module txemit;
var Text;
public findlab(id) return id;
public emits(s) do
while (s::0) do
emit(s::0);
s := s+1;
end
end
public totext() do
if (Text) return;
emits(cg.textseg());
Text := %1;
end
public todata() do
if (\Text) return;
emits(cg.dataseg());
Text := 0;
end
public demit(v) do
todata();
emits(cg.defbyte());
ie (alphabetic(v)) do
emit('\'');
emit(v);
emit('\'');
end
else do
emits(ntoa(v));
end
emit('\n');
end
public demitw(v) do
todata();
emits(cg.defword());
emits(ntoa(v));
emit('\n');
end
public demitaddr(v) do
todata();
emits(cg.defaddr());
emits(ntoa(v));
emit('\n');
end
public dskip(a);
public rgen(p, v) do var s, n, i, j;
i := 0;
while (p[i]) do
s := p[i];
j := 0;
while (s::j) do
ie (s::j = '!') do
j := j+1;
ie (s::j = 'w')
emits(ntoa(v));
else ie (s::j = 'n')
emits(v);
else
oops("rgen", 0);
end
else do
emit(s::j);
end
j := j+1;
end
emit('\n');
i := i+1;
end
end
prlab(id) do
emit('L');
emits(ntoa(id));
emit(':');
emit('\n');
end
public droplab() do var k;
commit();
totext();
k := newlab();
prlab(k);
return k;
end
public dropdlab() do var k;
commit();
todata();
k := newlab();
prlab(k);
return k;
end
public resolve(id) do
commit();
prlab(id);
end
public resolve_data(id) do
todata();
prlab(id);
end
public globaddr() do var k;
k := dropdlab();
emits(cg.defglob());
return k;
end
public emitlib() do var i, j, lib, s;
lib := cg.library();
i := 0;
while (lib[i]) do
s := lib[i];
j := 0;
while (s[j]) do
emits(s[j]);
emit('\n');
j := j+1;
end
i := i+1;
end
end
do
Text := %1;
end
end