node.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. destructor tnode.destroy;
  42. begin
  43. { reference info }
  44. if (location.loc in [LOC_MEM,LOC_REFERENCE]) and
  45. assigned(location.reference.symbol) then
  46. dispose(location.reference.symbol,done);
  47. {$ifdef EXTDEBUG}
  48. if firstpasscount>maxfirstpasscount then
  49. maxfirstpasscount:=firstpasscount;
  50. {$endif EXTDEBUG}
  51. end;
  52. function tnode.pass_1 : tnode;
  53. begin
  54. if not(assigned(resulttype)) then
  55. det_resulttype;
  56. det_temp;
  57. end;
  58. procedure tnode.concattolist(l : plinkedlist);
  59. begin
  60. {$ifdef newcg}
  61. l^.concat(self);
  62. {$endif newcg}
  63. end;
  64. function tnode.ischild(p : tnode) : boolean;
  65. begin
  66. ischild:=false;
  67. end;
  68. {$ifdef EXTDEBUG}
  69. procedure tnode.dowrite;
  70. const treetype2str : array[tnodetype] of string[20] = (
  71. 'addn',
  72. 'muln',
  73. 'subn',
  74. 'divn',
  75. 'symdifn',
  76. 'modn',
  77. 'assignn',
  78. 'loadn',
  79. 'rangen',
  80. 'ltn',
  81. 'lten',
  82. 'gtn',
  83. 'gten',
  84. 'equaln',
  85. 'unequaln',
  86. 'inn',
  87. 'orn',
  88. 'xorn',
  89. 'shrn',
  90. 'shln',
  91. 'slashn',
  92. 'andn',
  93. 'subscriptn',
  94. 'derefn',
  95. 'addrn',
  96. 'doubleaddrn',
  97. 'ordconstn',
  98. 'typeconvn',
  99. 'calln',
  100. 'callparan',
  101. 'realconstn',
  102. 'fixconstn',
  103. 'umminusn',
  104. 'asmn',
  105. 'vecn',
  106. 'stringconstn',
  107. 'funcretn',
  108. 'selfn',
  109. 'notn',
  110. 'inlinen',
  111. 'niln',
  112. 'errorn',
  113. 'typen',
  114. 'hnewn',
  115. 'hdisposen',
  116. 'newn',
  117. 'simpledisposen',
  118. 'setelementn',
  119. 'setconstn',
  120. 'blockn',
  121. 'statementn',
  122. 'loopn',
  123. 'ifn',
  124. 'breakn',
  125. 'continuen',
  126. 'repeatn',
  127. 'whilen',
  128. 'forn',
  129. 'exitn',
  130. 'withn',
  131. 'casen',
  132. 'labeln',
  133. 'goton',
  134. 'simplenewn',
  135. 'tryexceptn',
  136. 'raisen',
  137. 'switchesn',
  138. 'tryfinallyn',
  139. 'onn',
  140. 'isn',
  141. 'asn',
  142. 'caretn',
  143. 'failn',
  144. 'starstarn',
  145. 'procinlinen',
  146. 'arrayconstructn',
  147. 'arrayconstructrangen',
  148. 'nothingn',
  149. 'loadvmtn',
  150. 'pointerconstn');
  151. begin
  152. write(indention,'(',treetype2str[nodetype]);
  153. end;
  154. {$endif EXTDEBUG}
  155. function tnode.isequal(p : tnode) : boolean;
  156. begin
  157. isequal:=assigned(p) and (p.nodetype=nodetype) and
  158. (flags*flagsequal=p.flags*flagsequal) and
  159. docompare(p);
  160. end;
  161. function tnode.docompare(p : tnode) : boolean;
  162. begin
  163. docompare:=true;
  164. end;
  165. function tnode.getcopy : tnode;
  166. var
  167. p : tnode;
  168. begin
  169. { this is quite tricky because we need a node of the current }
  170. { node type and not one of tnode! }
  171. p:=tnode(classtype).createforcopy;
  172. p.nodetype:=nodetype;
  173. p.location:=location;
  174. p.parent:=parent;
  175. p.flags:=flags;
  176. p.registers32:=registers32;
  177. p.registersfpu:=registersfpu;
  178. {$ifdef SUPPORT_MMX}
  179. p.registersmmx:=registersmmx;
  180. p.registerskni:=registerskni;
  181. {$endif SUPPORT_MMX}
  182. p.resulttype:=resulttype;
  183. p.fileinfo:=fileinfo;
  184. p.localswitches:=localswitches;
  185. {$ifdef extdebug}
  186. p.firstpasscount:=firstpasscount;
  187. {$endif extdebug}
  188. p.list:=list;
  189. getcopy:=p;
  190. end;
  191. procedure tnode.set_file_line(from : tnode);
  192. begin
  193. if assigned(from) then
  194. fileinfo:=from.fileinfo;
  195. end;
  196. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  197. begin
  198. fileinfo:=filepos;
  199. end;
  200. {****************************************************************************
  201. TUNARYNODE
  202. ****************************************************************************}
  203. constructor tunarynode.create(tt : tnodetype;l : tnode);
  204. begin
  205. inherited create(tt);
  206. left:=l;
  207. end;
  208. function tunarynode.docompare(p : tnode) : boolean;
  209. begin
  210. docompare:=(inherited docompare(p)) and
  211. left.isequal(tunarynode(p).left);
  212. end;
  213. function tunarynode.getcopy : tnode;
  214. var
  215. p : tunarynode;
  216. begin
  217. p:=tunarynode(inherited getcopy);
  218. p.left:=left.getcopy;
  219. getcopy:=p;
  220. end;
  221. {$ifdef extdebug}
  222. procedure tunarynode.dowrite;
  223. begin
  224. inherited dowrite;
  225. writeln(',');
  226. writenode(left);
  227. writeln(')');
  228. dec(byte(indention[0]),2);
  229. end;
  230. {$endif}
  231. procedure tunarynode.left_max;
  232. begin
  233. registers32:=left.registers32;
  234. registersfpu:=left.registersfpu;
  235. {$ifdef SUPPORT_MMX}
  236. registersmmx:=left.registersmmx;
  237. {$endif SUPPORT_MMX}
  238. end;
  239. procedure tunarynode.concattolist(l : plinkedlist);
  240. begin
  241. left.parent:=self;
  242. left.concattolist(l);
  243. inherited concattolist(l);
  244. end;
  245. function tunarynode.ischild(p : tnode) : boolean;
  246. begin
  247. ischild:=p=left;
  248. end;
  249. procedure tunarynode.det_resulttype;
  250. begin
  251. left.det_resulttype;
  252. end;
  253. procedure tunarynode.det_temp;
  254. begin
  255. left.det_temp;
  256. end;
  257. {****************************************************************************
  258. TBINARYNODE
  259. ****************************************************************************}
  260. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  261. begin
  262. inherited create(tt,l);
  263. right:=r
  264. end;
  265. procedure tbinarynode.concattolist(l : plinkedlist);
  266. begin
  267. { we could change that depending on the number of }
  268. { required registers }
  269. left.parent:=self;
  270. left.concattolist(l);
  271. left.parent:=self;
  272. left.concattolist(l);
  273. inherited concattolist(l);
  274. end;
  275. function tbinarynode.ischild(p : tnode) : boolean;
  276. begin
  277. ischild:=(p=right) or (p=right);
  278. end;
  279. procedure tbinarynode.det_resulttype;
  280. begin
  281. left.det_resulttype;
  282. right.det_resulttype;
  283. end;
  284. procedure tbinarynode.det_temp;
  285. begin
  286. left.det_temp;
  287. right.det_temp;
  288. end;
  289. function tbinarynode.docompare(p : tnode) : boolean;
  290. begin
  291. docompare:=left.isequal(tbinarynode(p).left) and
  292. right.isequal(tbinarynode(p).right);
  293. end;
  294. function tbinarynode.getcopy : tnode;
  295. var
  296. p : tbinarynode;
  297. begin
  298. p:=tbinarynode(inherited getcopy);
  299. p.right:=right.getcopy;
  300. getcopy:=p;
  301. end;
  302. procedure tbinarynode.swapleftright;
  303. var
  304. swapp : tnode;
  305. begin
  306. swapp:=right;
  307. right:=left;
  308. left:=
  309. swapp;
  310. if nf_swaped in flags then
  311. exclude(flags,nf_swaped)
  312. else
  313. include(flags,nf_swaped);
  314. end;
  315. procedure tbinarynode.left_right_max;
  316. begin
  317. if assigned(left) then
  318. begin
  319. if assigned(right) then
  320. begin
  321. registers32:=max(left.registers32,right.registers32);
  322. registersfpu:=max(left.registersfpu,right.registersfpu);
  323. {$ifdef SUPPORT_MMX}
  324. registersmmx:=max(left.registersmmx,right.registersmmx);
  325. {$endif SUPPORT_MMX}
  326. end
  327. else
  328. begin
  329. registers32:=left.registers32;
  330. registersfpu:=left.registersfpu;
  331. {$ifdef SUPPORT_MMX}
  332. registersmmx:=left.registersmmx;
  333. {$endif SUPPORT_MMX}
  334. end;
  335. end;
  336. end;
  337. {****************************************************************************
  338. TBINOPYNODE
  339. ****************************************************************************}
  340. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  341. begin
  342. inherited create(tt,l,r);
  343. end;
  344. function tbinopnode.docompare(p : tnode) : boolean;
  345. begin
  346. docompare:=(inherited docompare(p)) or
  347. ((nf_swapable in flags) and
  348. left.isequal(tbinopnode(p).right) and
  349. right.isequal(tbinopnode(p).left));
  350. end;
  351. {
  352. $Log$
  353. Revision 1.8 2000-10-01 19:48:24 peter
  354. * lot of compile updates for cg11
  355. Revision 1.7 2000/09/29 15:45:23 florian
  356. * make cycle fixed
  357. Revision 1.6 2000/09/28 19:49:52 florian
  358. *** empty log message ***
  359. Revision 1.5 2000/09/27 18:14:31 florian
  360. * fixed a lot of syntax errors in the n*.pas stuff
  361. Revision 1.4 2000/09/26 20:06:13 florian
  362. * hmm, still a lot of work to get things compilable
  363. Revision 1.3 2000/09/22 21:45:36 florian
  364. * some updates e.g. getcopy added
  365. Revision 1.2 2000/09/20 21:52:38 florian
  366. * removed a lot of errors
  367. Revision 1.1 2000/08/26 12:27:17 florian
  368. * createial release
  369. }