DEADSOFTWARE

Port, TODO
[bbcp.git] / new / Dev0 / Mod / CPH.txt
1 MODULE Dev0CPH;
3 (* THIS IS TEXT COPY OF CPH.odc *)
4 (* DO NOT EDIT *)
6 (**
7 project = "BlackBox"
8 organization = "www.oberon.ch"
9 contributors = "Oberon microsystems"
10 version = "System/Rsrc/AboutBB"
11 copyright = "System/Rsrc/AboutBB"
12 license = "Docu/BB-License"
13 references = "ftp://ftp.inf.ethz.ch/pub/software/Oberon/OberonV4/Docu/OP2.Paper.ps"
14 changes = ""
15 issues = ""
17 **)
19 IMPORT DevCPT := Dev0CPT;
21 CONST
22 (* UseCalls options *)
23 longMop* = 0; longDop* = 1; longConv* = 2; longOdd* = 3;
24 realMop* = 8; realDop* = 9; realConv* = 10;
25 intMulDiv* = 11;
26 force = 16; hide = 17;
28 (* nodes classes *)
29 Nvar = 0; Nvarpar = 1; Nfield = 2; Nderef = 3; Nindex = 4; Nguard = 5; Neguard = 6;
30 Nconst = 7; Ntype = 8; Nproc = 9; Nupto = 10; Nmop = 11; Ndop = 12; Ncall = 13;
31 Ninittd = 14; Nif = 15; Ncaselse = 16; Ncasedo = 17; Nenter = 18; Nassign = 19;
32 Nifelse =20; Ncase = 21; Nwhile = 22; Nrepeat = 23; Nloop = 24; Nexit = 25;
33 Nreturn = 26; Nwith = 27; Ntrap = 28; Ncomp = 30;
34 Ndrop = 50; Nlabel = 51; Ngoto = 52; Njsr = 53; Nret = 54; Ncmp = 55;
36 (*function number*)
37 assign = 0; newfn = 1; incfn = 13; decfn = 14;
38 inclfn = 15; exclfn = 16; copyfn = 18; assertfn = 32;
39 getfn = 24; putfn = 25; getrfn = 26; putrfn = 27; sysnewfn = 30; movefn = 31;
41 (* symbol values and ops *)
42 times = 1; slash = 2; div = 3; mod = 4;
43 and = 5; plus = 6; minus = 7; or = 8; eql = 9;
44 neq = 10; lss = 11; leq = 12; gtr = 13; geq = 14;
45 in = 15; is = 16; ash = 17; msk = 18; len = 19;
46 conv = 20; abs = 21; cap = 22; odd = 23; not = 33;
47 adr = 24; cc = 25; bit = 26; lsh = 27; rot = 28; val = 29;
48 min = 34; max = 35; typfn = 36;
49 thisrecfn = 45; thisarrfn = 46;
50 shl = 50; shr = 51; lshr = 52; xor = 53;
52 (* structure forms *)
53 Undef = 0; Byte = 1; Bool = 2; Char8 = 3; Int8 = 4; Int16 = 5; Int32 = 6;
54 Real32 = 7; Real64 = 8; Set = 9; String8 = 10; NilTyp = 11; NoTyp = 12;
55 Pointer = 13; ProcTyp = 14; Comp = 15;
56 Char16 = 16; String16 = 17; Int64 = 18;
57 VString16to8 = 29; VString8 = 30; VString16 = 31;
58 realSet = {Real32, Real64};
59 Basic = 1; Array = 2; DynArr = 3; Record = 4;
63 PROCEDURE UseThisCall (n: DevCPT.Node; IN name: ARRAY OF SHORTCHAR);
64 VAR mod, nm, moda: DevCPT.Name; mobj, obj: DevCPT.Object; done: BOOLEAN;
65 BEGIN
66 IF (n.typ.form = Real64) OR (n.left.typ.form = Real64) THEN mod := "Real"
67 ELSIF (n.typ.form = Real32) OR (n.left.typ.form = Real32) THEN mod := "SReal"
68 ELSIF (n.typ.form = Int64) OR (n.left.typ.form = Int64) THEN mod := "Long"
69 ELSE mod := "Int"
70 END;
71 moda := mod + "%";
72 DevCPT.Find(moda, mobj);
73 IF mobj = NIL THEN
74 DevCPT.Import(moda, mod, done);
75 IF done THEN DevCPT.Find(moda, mobj) END
76 END;
77 nm := name$; DevCPT.FindImport(nm, mobj, obj);
78 n.class := Ncall; n.subcl := 0; n.obj := obj.link;
79 n.left.link := n.right; n.right := n.left;
80 n.left := DevCPT.NewNode(Nproc);
81 n.left.obj := obj; n.left.typ := obj.typ;
82 ASSERT(n.typ.form = obj.typ.form)
83 END UseThisCall;
85 PROCEDURE Convert (n: DevCPT.Node; typ: DevCPT.Struct);
86 VAR new: DevCPT.Node; r: REAL;
87 BEGIN
88 IF n.class = Nconst THEN
89 ASSERT((n.typ.form IN {Int32, Int64}) & (typ = DevCPT.intrealtyp));
90 r := n.conval.realval + n.conval.intval;
91 IF r = n.conval.realval + n.conval.intval THEN
92 n.conval.realval := r; n.conval.intval := -1; n.typ := typ; n.obj := NIL
93 END
94 END;
95 IF (n.typ # typ)
96 & ((n.class # Nmop) OR (n.subcl # conv)
97 OR ~DevCPT.Includes(n.typ.form, n.left.typ.form) & ~DevCPT.Includes(n.typ.form, typ.form)) THEN
98 new := DevCPT.NewNode(0); new^ := n^;
99 n.class := Nmop; n.subcl := conv; n.left := new; n.right := NIL; n.obj := NIL
100 END;
101 n.typ := typ
102 END Convert;
104 PROCEDURE UseCallForComp (n: DevCPT.Node);
105 VAR new: DevCPT.Node;
106 BEGIN
107 new := DevCPT.NewNode(0);
108 new.left := n.left; new.right := n.right;
109 new.typ := DevCPT.int32typ;
110 UseThisCall(new, "Comp");
111 n.left := new;
112 n.right := DevCPT.NewNode(Nconst); n.right.conval := DevCPT.NewConst();
113 n.right.conval.intval := 0; n.right.conval.realval := 0; n.right.typ := DevCPT.int32typ;
114 END UseCallForComp;
116 PROCEDURE UseCallForConv (n: DevCPT.Node; opts: SET);
117 VAR f, g: INTEGER; typ: DevCPT.Struct;
118 BEGIN
119 typ := n.typ; f := typ.form; g := n.left.typ.form;
120 IF realConv IN opts THEN
121 IF f IN realSet THEN
122 IF g = Real32 THEN UseThisCall(n, "Long")
123 ELSIF g = Real64 THEN UseThisCall(n, "Short")
124 ELSIF g = Int64 THEN UseThisCall(n, "LFloat")
125 ELSIF g = Int32 THEN UseThisCall(n, "Float")
126 ELSE Convert(n.left, DevCPT.int32typ); UseThisCall(n, "Float")
127 END
128 ELSIF g IN realSet THEN
129 IF f = Int64 THEN UseThisCall(n, "LFloor")
130 ELSIF f = Int32 THEN UseThisCall(n, "Floor")
131 ELSE n.typ := DevCPT.int32typ; UseThisCall(n, "Floor"); Convert(n, typ)
132 END
133 END
134 END;
135 IF longConv IN opts THEN
136 IF f = Int64 THEN
137 IF g = Int32 THEN UseThisCall(n, "Long")
138 ELSIF ~(g IN realSet) THEN Convert(n.left, DevCPT.int32typ); UseThisCall(n, "IntToLong")
139 END
140 ELSIF g = Int64 THEN
141 IF f = Int32 THEN UseThisCall(n, "Short")
142 ELSIF ~(f IN realSet) THEN n.typ := DevCPT.int32typ; UseThisCall(n, "LongToInt"); Convert(n, typ)
143 END
144 END
145 END
146 END UseCallForConv;
148 PROCEDURE UseCallForMop (n: DevCPT.Node; opts: SET);
149 BEGIN
150 CASE n.subcl OF
151 | minus:
152 IF (realMop IN opts) & (n.typ.form IN realSet) OR (longMop IN opts) & (n.typ.form = Int64) THEN
153 UseThisCall(n, "Neg")
154 END
155 | abs:
156 IF (realMop IN opts) & (n.typ.form IN realSet) OR (longMop IN opts) & (n.typ.form = Int64) THEN
157 UseThisCall(n, "Abs")
158 END
159 | odd:
160 IF (longOdd IN opts) & (n.left.typ.form = Int64) THEN UseThisCall(n, "Odd") END
161 | conv:
162 UseCallForConv(n, opts)
163 ELSE
164 END
165 END UseCallForMop;
167 PROCEDURE UseCallForDop (n: DevCPT.Node; opts: SET);
168 BEGIN
169 IF (realDop IN opts) & (n.left.typ.form IN realSet)
170 OR (longDop IN opts) & (n.left.typ.form = Int64)
171 OR (intMulDiv IN opts) & (n.subcl IN {times, div, mod}) & (n.typ.form = Int32) THEN
172 CASE n.subcl OF
173 | times: UseThisCall(n, "Mul")
174 | slash: UseThisCall(n, "Div")
175 | div: UseThisCall(n, "Div")
176 | mod: UseThisCall(n, "Mod")
177 | plus: UseThisCall(n, "Add")
178 | minus: UseThisCall(n, "Sub")
179 | ash: UseThisCall(n, "Ash")
180 | min: UseThisCall(n, "Min")
181 | max: UseThisCall(n, "Max")
182 | eql..geq: UseCallForComp(n)
183 ELSE
184 END
185 END
186 END UseCallForDop;
188 PROCEDURE UseCallForMove (n: DevCPT.Node; typ: DevCPT.Struct; opts: SET);
189 VAR f, g: INTEGER;
190 BEGIN
191 f := n.typ.form; g := typ.form;
192 IF f # g THEN
193 IF (realConv IN opts) & ((f IN realSet) OR (g IN realSet))
194 OR (longConv IN opts) & ((f = Int64) OR (g = Int64)) THEN
195 Convert(n, typ);
196 UseCallForConv(n, opts)
197 END
198 END
199 END UseCallForMove;
201 PROCEDURE UseCallForAssign (n: DevCPT.Node; opts: SET);
202 BEGIN
203 IF n.subcl = assign THEN UseCallForMove(n.right, n.left.typ, opts) END
204 END UseCallForAssign;
206 PROCEDURE UseCallForReturn (n: DevCPT.Node; opts: SET);
207 BEGIN
208 IF (n.left # NIL) & (n.obj # NIL) THEN UseCallForMove(n.left, n.obj.typ, opts) END
209 END UseCallForReturn;
211 PROCEDURE UseCallForParam (n: DevCPT.Node; fp: DevCPT.Object; opts: SET);
212 BEGIN
213 WHILE n # NIL DO
214 UseCallForMove(n, fp.typ, opts);
215 n := n.link; fp := fp.link
216 END
217 END UseCallForParam;
219 PROCEDURE UseCalls* (n: DevCPT.Node; opts: SET);
220 BEGIN
221 WHILE n # NIL DO
222 CASE n.class OF
223 | Nmop:
224 UseCalls(n.left, opts); UseCallForMop(n, opts)
225 | Ndop:
226 UseCalls(n.left, opts); UseCalls(n.right, opts); UseCallForDop(n, opts)
227 | Ncase:
228 UseCalls(n.left, opts); UseCalls(n.right.left, opts); UseCalls(n.right.right, opts)
229 | Nassign:
230 UseCalls(n.left, opts); UseCalls(n.right, opts); UseCallForAssign(n, opts)
231 | Ncall:
232 UseCalls(n.left, opts); UseCalls(n.right, opts); UseCallForParam(n.right, n.obj, opts)
233 | Nreturn:
234 UseCalls(n.left, opts); UseCallForReturn(n, opts)
235 | Ncasedo:
236 UseCalls(n.right, opts)
237 | Ngoto, Ndrop, Nloop, Nfield, Nderef, Nguard:
238 UseCalls(n.left, opts)
239 | Nenter, Nifelse, Nif, Nwhile, Nrepeat, Nwith, Ncomp, Nupto, Nindex:
240 UseCalls(n.left, opts); UseCalls(n.right, opts)
241 | Njsr, Nret, Nlabel, Ntrap, Nexit, Ninittd, Ntype, Nproc, Nconst, Nvar, Nvarpar:
242 END;
243 n := n.link
244 END
245 END UseCalls;
248 PROCEDURE UseReals* (n: DevCPT.Node; opts: SET);
249 BEGIN
250 WHILE n # NIL DO
251 CASE n.class OF
252 | Nmop:
253 IF (longMop IN opts) & (n.typ.form = Int64) & ((n.subcl = abs) OR (n.subcl = minus)) THEN
254 UseReals(n.left, opts - {hide} + {force}); n.typ := DevCPT.intrealtyp
255 ELSIF n.subcl = conv THEN UseReals(n.left, opts - {force} + {hide})
256 ELSE UseReals(n.left, opts - {force, hide})
257 END
258 | Ndop:
259 IF (longDop IN opts) & (n.left.typ.form = Int64) THEN
260 UseReals(n.left, opts - {hide} + {force}); UseReals(n.right, opts - {hide} + {force});
261 IF n.typ.form = Int64 THEN n.typ := DevCPT.intrealtyp END
262 ELSE UseReals(n.left, opts - {force, hide}); UseReals(n.right, opts - {force, hide})
263 END
264 | Ncase:
265 UseReals(n.left, opts - {force, hide}); UseReals(n.right.left, opts - {force, hide});
266 UseReals(n.right.right, opts - {force, hide})
267 | Ncasedo:
268 UseReals(n.right, opts - {force, hide})
269 | Ngoto, Ndrop, Nloop, Nreturn, Nfield, Nderef, Nguard:
270 UseReals(n.left, opts - {force, hide})
271 | Nenter, Nassign, Ncall, Nifelse, Nif, Nwhile, Nrepeat, Nwith, Ncomp, Nupto, Nindex:
272 UseReals(n.left, opts - {force, hide}); UseReals(n.right, opts - {force, hide})
273 | Njsr, Nret, Nlabel, Ntrap, Nexit, Ninittd, Ntype, Nproc, Nconst, Nvar, Nvarpar:
274 END;
275 IF force IN opts THEN Convert(n, DevCPT.intrealtyp)
276 ELSIF ~(hide IN opts) & (n.typ = DevCPT.intrealtyp) THEN Convert(n, DevCPT.int64typ)
277 END;
278 n := n.link
279 END
280 END UseReals;
282 END Dev0CPH.
287 PROCEDURE Traverse (n: DevCPT.Node; opts: SET);
288 BEGIN
289 WHILE n # NIL DO
290 CASE n.class OF
291 | Ncase:
292 Traverse(n.left, opts); Traverse(n.right.left, opts); Traverse(n.right.right, opts)
293 | Ncasedo:
294 Traverse(n.right, opts)
295 | Ngoto, Ndrop, Nloop, Nreturn, Nmop, Nfield, Nderef, Nguard:
296 Traverse(n.left, opts)
297 | Nenter, Nassign, Ncall, Nifelse, Nif, Nwhile, Nrepeat, Nwith, Ncomp, Ndop, Nupto, Nindex:
298 Traverse(n.left, opts); Traverse(n.right, opts)
299 | Njsr, Nret, Nlabel, Ntrap, Nexit, Ninittd, Ntype, Nproc, Nconst, Nvar, Nvarpar:
300 END;
301 n := n.link
302 END
303 END Traverse;