node.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. {
  2. $Id$
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. The implementation of the abstract nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {****************************************************************************
  19. TNODE
  20. ****************************************************************************}
  21. constructor tnode.create(tt : tnodetype);
  22. begin
  23. inherited create;
  24. nodetype:=tt;
  25. { this allows easier error tracing }
  26. location.loc:=LOC_INVALID;
  27. { save local info }
  28. fileinfo:=aktfilepos;
  29. localswitches:=aktlocalswitches;
  30. resulttype:=nil;
  31. registers32:=0;
  32. registersfpu:=0;
  33. {$ifdef SUPPORT_MMX}
  34. registersmmx:=0;
  35. {$endif SUPPORT_MMX}
  36. flags:=[];
  37. end;
  38. constructor tnode.createforcopy;
  39. begin
  40. end;
  41. procedure tnode.toggleflag(f : tnodeflags);
  42. begin
  43. if f in flags then
  44. exclude(flags,f)
  45. else
  46. include(flags,f);
  47. end;
  48. destructor tnode.destroy;
  49. begin
  50. { reference info }
  51. {if (location.loc in [LOC_MEM,LOC_REFERENCE]) and
  52. assigned(location.reference.symbol) then
  53. dispose(location.reference.symbol,done);}
  54. {$ifdef EXTDEBUG}
  55. if firstpasscount>maxfirstpasscount then
  56. maxfirstpasscount:=firstpasscount;
  57. {$endif EXTDEBUG}
  58. end;
  59. function tnode.pass_1 : tnode;
  60. begin
  61. pass_1:=nil;
  62. if not(assigned(resulttype)) then
  63. det_resulttype;
  64. det_temp;
  65. end;
  66. procedure tnode.concattolist(l : plinkedlist);
  67. begin
  68. {$ifdef newcg}
  69. l^.concat(self);
  70. {$endif newcg}
  71. end;
  72. function tnode.ischild(p : tnode) : boolean;
  73. begin
  74. ischild:=false;
  75. end;
  76. {$ifdef EXTDEBUG}
  77. procedure tnode.dowrite;
  78. begin
  79. dowritenodetype;
  80. end;
  81. procedure tnode.dowritenodetype;
  82. const nodetype2str : array[tnodetype] of string[20] = (
  83. 'addn',
  84. 'muln',
  85. 'subn',
  86. 'divn',
  87. 'symdifn',
  88. 'modn',
  89. 'assignn',
  90. 'loadn',
  91. 'rangen',
  92. 'ltn',
  93. 'lten',
  94. 'gtn',
  95. 'gten',
  96. 'equaln',
  97. 'unequaln',
  98. 'inn',
  99. 'orn',
  100. 'xorn',
  101. 'shrn',
  102. 'shln',
  103. 'slashn',
  104. 'andn',
  105. 'subscriptn',
  106. 'derefn',
  107. 'addrn',
  108. 'doubleaddrn',
  109. 'ordconstn',
  110. 'typeconvn',
  111. 'calln',
  112. 'callparan',
  113. 'realconstn',
  114. 'fixconstn',
  115. 'umminusn',
  116. 'asmn',
  117. 'vecn',
  118. 'pointerconstn',
  119. 'stringconstn',
  120. 'funcretn',
  121. 'selfn',
  122. 'notn',
  123. 'inlinen',
  124. 'niln',
  125. 'errorn',
  126. 'typen',
  127. 'hnewn',
  128. 'hdisposen',
  129. 'newn',
  130. 'simpledisposen',
  131. 'setelementn',
  132. 'setconstn',
  133. 'blockn',
  134. 'statementn',
  135. 'loopn',
  136. 'ifn',
  137. 'breakn',
  138. 'continuen',
  139. 'repeatn',
  140. 'whilen',
  141. 'forn',
  142. 'exitn',
  143. 'withn',
  144. 'casen',
  145. 'labeln',
  146. 'goton',
  147. 'simplenewn',
  148. 'tryexceptn',
  149. 'raisen',
  150. 'switchesn',
  151. 'tryfinallyn',
  152. 'onn',
  153. 'isn',
  154. 'asn',
  155. 'caretn',
  156. 'failn',
  157. 'starstarn',
  158. 'procinlinen',
  159. 'arrayconstructn',
  160. 'arrayconstructrangen',
  161. 'nothingn',
  162. 'loadvmtn');
  163. begin
  164. write(writenodeindention,'(',nodetype2str[nodetype]);
  165. end;
  166. {$endif EXTDEBUG}
  167. function tnode.isequal(p : tnode) : boolean;
  168. begin
  169. isequal:=assigned(p) and (p.nodetype=nodetype) and
  170. (flags*flagsequal=p.flags*flagsequal) and
  171. docompare(p);
  172. end;
  173. function tnode.docompare(p : tnode) : boolean;
  174. begin
  175. docompare:=true;
  176. end;
  177. function tnode.getcopy : tnode;
  178. var
  179. p : tnode;
  180. begin
  181. if not(assigned(self)) then
  182. begin
  183. getcopy:=nil;
  184. exit;
  185. end;
  186. { this is quite tricky because we need a node of the current }
  187. { node type and not one of tnode! }
  188. p:=tnodeclass(classtype).createforcopy;
  189. p.nodetype:=nodetype;
  190. p.location:=location;
  191. p.parent:=parent;
  192. p.flags:=flags;
  193. p.registers32:=registers32;
  194. p.registersfpu:=registersfpu;
  195. {$ifdef SUPPORT_MMX}
  196. p.registersmmx:=registersmmx;
  197. p.registerskni:=registerskni;
  198. {$endif SUPPORT_MMX}
  199. p.resulttype:=resulttype;
  200. p.fileinfo:=fileinfo;
  201. p.localswitches:=localswitches;
  202. {$ifdef extdebug}
  203. p.firstpasscount:=firstpasscount;
  204. {$endif extdebug}
  205. p.list:=list;
  206. getcopy:=p;
  207. end;
  208. procedure tnode.set_file_line(from : tnode);
  209. begin
  210. if assigned(from) then
  211. fileinfo:=from.fileinfo;
  212. end;
  213. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  214. begin
  215. fileinfo:=filepos;
  216. end;
  217. {****************************************************************************
  218. TUNARYNODE
  219. ****************************************************************************}
  220. constructor tunarynode.create(tt : tnodetype;l : tnode);
  221. begin
  222. inherited create(tt);
  223. left:=l;
  224. end;
  225. destructor tunarynode.destroy;
  226. begin
  227. left.free;
  228. inherited destroy;
  229. end;
  230. function tunarynode.docompare(p : tnode) : boolean;
  231. begin
  232. docompare:=(inherited docompare(p)) and
  233. left.isequal(tunarynode(p).left);
  234. end;
  235. function tunarynode.getcopy : tnode;
  236. var
  237. p : tunarynode;
  238. begin
  239. p:=tunarynode(inherited getcopy);
  240. if assigned(left) then
  241. p.left:=left.getcopy
  242. else
  243. p.left:=nil;
  244. getcopy:=p;
  245. end;
  246. {$ifdef extdebug}
  247. procedure tunarynode.dowrite;
  248. begin
  249. inherited dowrite;
  250. writeln(',');
  251. writenodeindention:=writenodeindention+' ';
  252. writenode(left);
  253. write(')');
  254. delete(writenodeindention,1,4);
  255. end;
  256. {$endif}
  257. procedure tunarynode.left_max;
  258. begin
  259. registers32:=left.registers32;
  260. registersfpu:=left.registersfpu;
  261. {$ifdef SUPPORT_MMX}
  262. registersmmx:=left.registersmmx;
  263. {$endif SUPPORT_MMX}
  264. end;
  265. procedure tunarynode.concattolist(l : plinkedlist);
  266. begin
  267. left.parent:=self;
  268. left.concattolist(l);
  269. inherited concattolist(l);
  270. end;
  271. function tunarynode.ischild(p : tnode) : boolean;
  272. begin
  273. ischild:=p=left;
  274. end;
  275. procedure tunarynode.det_resulttype;
  276. begin
  277. left.det_resulttype;
  278. end;
  279. procedure tunarynode.det_temp;
  280. begin
  281. left.det_temp;
  282. end;
  283. {****************************************************************************
  284. TBINARYNODE
  285. ****************************************************************************}
  286. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  287. begin
  288. inherited create(tt,l);
  289. right:=r
  290. end;
  291. destructor tbinarynode.destroy;
  292. begin
  293. right.free;
  294. inherited destroy;
  295. end;
  296. procedure tbinarynode.concattolist(l : plinkedlist);
  297. begin
  298. { we could change that depending on the number of }
  299. { required registers }
  300. left.parent:=self;
  301. left.concattolist(l);
  302. left.parent:=self;
  303. left.concattolist(l);
  304. inherited concattolist(l);
  305. end;
  306. function tbinarynode.ischild(p : tnode) : boolean;
  307. begin
  308. ischild:=(p=right) or (p=right);
  309. end;
  310. procedure tbinarynode.det_resulttype;
  311. begin
  312. left.det_resulttype;
  313. right.det_resulttype;
  314. end;
  315. procedure tbinarynode.det_temp;
  316. begin
  317. left.det_temp;
  318. right.det_temp;
  319. end;
  320. function tbinarynode.docompare(p : tnode) : boolean;
  321. begin
  322. docompare:=left.isequal(tbinarynode(p).left) and
  323. right.isequal(tbinarynode(p).right);
  324. end;
  325. function tbinarynode.getcopy : tnode;
  326. var
  327. p : tbinarynode;
  328. begin
  329. p:=tbinarynode(inherited getcopy);
  330. if assigned(right) then
  331. p.right:=right.getcopy
  332. else
  333. p.right:=nil;
  334. getcopy:=p;
  335. end;
  336. procedure tbinarynode.swapleftright;
  337. var
  338. swapp : tnode;
  339. begin
  340. swapp:=right;
  341. right:=left;
  342. left:=
  343. swapp;
  344. if nf_swaped in flags then
  345. exclude(flags,nf_swaped)
  346. else
  347. include(flags,nf_swaped);
  348. end;
  349. procedure tbinarynode.left_right_max;
  350. begin
  351. if assigned(left) then
  352. begin
  353. if assigned(right) then
  354. begin
  355. registers32:=max(left.registers32,right.registers32);
  356. registersfpu:=max(left.registersfpu,right.registersfpu);
  357. {$ifdef SUPPORT_MMX}
  358. registersmmx:=max(left.registersmmx,right.registersmmx);
  359. {$endif SUPPORT_MMX}
  360. end
  361. else
  362. begin
  363. registers32:=left.registers32;
  364. registersfpu:=left.registersfpu;
  365. {$ifdef SUPPORT_MMX}
  366. registersmmx:=left.registersmmx;
  367. {$endif SUPPORT_MMX}
  368. end;
  369. end;
  370. end;
  371. {$ifdef extdebug}
  372. procedure tbinarynode.dowrite;
  373. begin
  374. inherited dowrite;
  375. writeln(',');
  376. writenodeindention:=writenodeindention+' ';
  377. writenode(right);
  378. write(')');
  379. delete(writenodeindention,1,4);
  380. end;
  381. {$endif}
  382. {****************************************************************************
  383. TBINOPYNODE
  384. ****************************************************************************}
  385. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  386. begin
  387. inherited create(tt,l,r);
  388. end;
  389. function tbinopnode.docompare(p : tnode) : boolean;
  390. begin
  391. docompare:=(inherited docompare(p)) or
  392. ((nf_swapable in flags) and
  393. left.isequal(tbinopnode(p).right) and
  394. right.isequal(tbinopnode(p).left));
  395. end;
  396. {****************************************************************************
  397. WRITENODE
  398. ****************************************************************************}
  399. {$ifdef EXTDEBUG}
  400. procedure writenode(t:tnode);
  401. begin
  402. if assigned(t) then
  403. t.dowrite
  404. else
  405. write(writenodeindention,'nil');
  406. if writenodeindention='' then
  407. writeln;
  408. end;
  409. {$endif EXTDEBUG}
  410. {
  411. $Log$
  412. Revision 1.10 2000-10-14 21:52:55 peter
  413. * fixed memory leaks
  414. Revision 1.9 2000/10/14 10:14:51 peter
  415. * moehrendorf oct 2000 rewrite
  416. Revision 1.8 2000/10/01 19:48:24 peter
  417. * lot of compile updates for cg11
  418. Revision 1.7 2000/09/29 15:45:23 florian
  419. * make cycle fixed
  420. Revision 1.6 2000/09/28 19:49:52 florian
  421. *** empty log message ***
  422. Revision 1.5 2000/09/27 18:14:31 florian
  423. * fixed a lot of syntax errors in the n*.pas stuff
  424. Revision 1.4 2000/09/26 20:06:13 florian
  425. * hmm, still a lot of work to get things compilable
  426. Revision 1.3 2000/09/22 21:45:36 florian
  427. * some updates e.g. getcopy added
  428. Revision 1.2 2000/09/20 21:52:38 florian
  429. * removed a lot of errors
  430. Revision 1.1 2000/08/26 12:27:17 florian
  431. * createial release
  432. }