node.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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. {$warning fixme}
  71. {$endif newcg}
  72. end;
  73. function tnode.ischild(p : tnode) : boolean;
  74. begin
  75. ischild:=false;
  76. end;
  77. {$ifdef EXTDEBUG}
  78. procedure tnode.dowrite;
  79. begin
  80. dowritenodetype;
  81. end;
  82. procedure tnode.dowritenodetype;
  83. const nodetype2str : array[tnodetype] of string[20] = (
  84. 'addn',
  85. 'muln',
  86. 'subn',
  87. 'divn',
  88. 'symdifn',
  89. 'modn',
  90. 'assignn',
  91. 'loadn',
  92. 'rangen',
  93. 'ltn',
  94. 'lten',
  95. 'gtn',
  96. 'gten',
  97. 'equaln',
  98. 'unequaln',
  99. 'inn',
  100. 'orn',
  101. 'xorn',
  102. 'shrn',
  103. 'shln',
  104. 'slashn',
  105. 'andn',
  106. 'subscriptn',
  107. 'derefn',
  108. 'addrn',
  109. 'doubleaddrn',
  110. 'ordconstn',
  111. 'typeconvn',
  112. 'calln',
  113. 'callparan',
  114. 'realconstn',
  115. 'fixconstn',
  116. 'umminusn',
  117. 'asmn',
  118. 'vecn',
  119. 'pointerconstn',
  120. 'stringconstn',
  121. 'funcretn',
  122. 'selfn',
  123. 'notn',
  124. 'inlinen',
  125. 'niln',
  126. 'errorn',
  127. 'typen',
  128. 'hnewn',
  129. 'hdisposen',
  130. 'newn',
  131. 'simpledisposen',
  132. 'setelementn',
  133. 'setconstn',
  134. 'blockn',
  135. 'statementn',
  136. 'loopn',
  137. 'ifn',
  138. 'breakn',
  139. 'continuen',
  140. 'repeatn',
  141. 'whilen',
  142. 'forn',
  143. 'exitn',
  144. 'withn',
  145. 'casen',
  146. 'labeln',
  147. 'goton',
  148. 'simplenewn',
  149. 'tryexceptn',
  150. 'raisen',
  151. 'switchesn',
  152. 'tryfinallyn',
  153. 'onn',
  154. 'isn',
  155. 'asn',
  156. 'caretn',
  157. 'failn',
  158. 'starstarn',
  159. 'procinlinen',
  160. 'arrayconstructn',
  161. 'arrayconstructrangen',
  162. 'addoptn',
  163. 'nothingn',
  164. 'loadvmtn');
  165. begin
  166. write(writenodeindention,'(',nodetype2str[nodetype]);
  167. end;
  168. {$endif EXTDEBUG}
  169. function tnode.isequal(p : tnode) : boolean;
  170. begin
  171. isequal:=
  172. (not assigned(self) and not assigned(p)) or
  173. (assigned(self) and assigned(p) and
  174. { optimized subclasses have the same nodetype as their }
  175. { superclass (for compatibility), so also check the classtype (JM) }
  176. (p.classtype=classtype) and
  177. (p.nodetype=nodetype) and
  178. (flags*flagsequal=p.flags*flagsequal) and
  179. docompare(p));
  180. end;
  181. function tnode.docompare(p : tnode) : boolean;
  182. begin
  183. docompare:=true;
  184. end;
  185. function tnode.getcopy : tnode;
  186. var
  187. p : tnode;
  188. begin
  189. { this is quite tricky because we need a node of the current }
  190. { node type and not one of tnode! }
  191. p:=tnodeclass(classtype).createforcopy;
  192. p.nodetype:=nodetype;
  193. p.location:=location;
  194. p.parent:=parent;
  195. p.flags:=flags;
  196. p.registers32:=registers32;
  197. p.registersfpu:=registersfpu;
  198. {$ifdef SUPPORT_MMX}
  199. p.registersmmx:=registersmmx;
  200. p.registerskni:=registerskni;
  201. {$endif SUPPORT_MMX}
  202. p.resulttype:=resulttype;
  203. p.fileinfo:=fileinfo;
  204. p.localswitches:=localswitches;
  205. {$ifdef extdebug}
  206. p.firstpasscount:=firstpasscount;
  207. {$endif extdebug}
  208. p.list:=list;
  209. getcopy:=p;
  210. end;
  211. procedure tnode.insertintolist(l : tnodelist);
  212. begin
  213. end;
  214. procedure tnode.set_file_line(from : tnode);
  215. begin
  216. if assigned(from) then
  217. fileinfo:=from.fileinfo;
  218. end;
  219. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  220. begin
  221. fileinfo:=filepos;
  222. end;
  223. {****************************************************************************
  224. TUNARYNODE
  225. ****************************************************************************}
  226. constructor tunarynode.create(tt : tnodetype;l : tnode);
  227. begin
  228. inherited create(tt);
  229. left:=l;
  230. end;
  231. destructor tunarynode.destroy;
  232. begin
  233. left.free;
  234. inherited destroy;
  235. end;
  236. function tunarynode.docompare(p : tnode) : boolean;
  237. begin
  238. docompare:=(inherited docompare(p)) and
  239. left.isequal(tunarynode(p).left);
  240. end;
  241. function tunarynode.getcopy : tnode;
  242. var
  243. p : tunarynode;
  244. begin
  245. p:=tunarynode(inherited getcopy);
  246. if assigned(left) then
  247. p.left:=left.getcopy
  248. else
  249. p.left:=nil;
  250. getcopy:=p;
  251. end;
  252. procedure tunarynode.insertintolist(l : tnodelist);
  253. begin
  254. end;
  255. {$ifdef extdebug}
  256. procedure tunarynode.dowrite;
  257. begin
  258. inherited dowrite;
  259. writeln(',');
  260. writenodeindention:=writenodeindention+' ';
  261. writenode(left);
  262. write(')');
  263. delete(writenodeindention,1,4);
  264. end;
  265. {$endif}
  266. procedure tunarynode.left_max;
  267. begin
  268. registers32:=left.registers32;
  269. registersfpu:=left.registersfpu;
  270. {$ifdef SUPPORT_MMX}
  271. registersmmx:=left.registersmmx;
  272. {$endif SUPPORT_MMX}
  273. end;
  274. procedure tunarynode.concattolist(l : plinkedlist);
  275. begin
  276. left.parent:=self;
  277. left.concattolist(l);
  278. inherited concattolist(l);
  279. end;
  280. function tunarynode.ischild(p : tnode) : boolean;
  281. begin
  282. ischild:=p=left;
  283. end;
  284. procedure tunarynode.det_resulttype;
  285. begin
  286. left.det_resulttype;
  287. end;
  288. procedure tunarynode.det_temp;
  289. begin
  290. left.det_temp;
  291. end;
  292. {****************************************************************************
  293. TBINARYNODE
  294. ****************************************************************************}
  295. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  296. begin
  297. inherited create(tt,l);
  298. right:=r
  299. end;
  300. destructor tbinarynode.destroy;
  301. begin
  302. right.free;
  303. inherited destroy;
  304. end;
  305. procedure tbinarynode.concattolist(l : plinkedlist);
  306. begin
  307. { we could change that depending on the number of }
  308. { required registers }
  309. left.parent:=self;
  310. left.concattolist(l);
  311. left.parent:=self;
  312. left.concattolist(l);
  313. inherited concattolist(l);
  314. end;
  315. function tbinarynode.ischild(p : tnode) : boolean;
  316. begin
  317. ischild:=(p=right) or (p=right);
  318. end;
  319. procedure tbinarynode.det_resulttype;
  320. begin
  321. left.det_resulttype;
  322. right.det_resulttype;
  323. end;
  324. procedure tbinarynode.det_temp;
  325. begin
  326. left.det_temp;
  327. right.det_temp;
  328. end;
  329. function tbinarynode.docompare(p : tnode) : boolean;
  330. begin
  331. docompare:=
  332. inherited docompare(p) and
  333. right.isequal(tbinarynode(p).right);
  334. end;
  335. function tbinarynode.getcopy : tnode;
  336. var
  337. p : tbinarynode;
  338. begin
  339. p:=tbinarynode(inherited getcopy);
  340. if assigned(right) then
  341. p.right:=right.getcopy
  342. else
  343. p.right:=nil;
  344. getcopy:=p;
  345. end;
  346. procedure tbinarynode.insertintolist(l : tnodelist);
  347. begin
  348. end;
  349. procedure tbinarynode.swapleftright;
  350. var
  351. swapp : tnode;
  352. begin
  353. swapp:=right;
  354. right:=left;
  355. left:=
  356. swapp;
  357. if nf_swaped in flags then
  358. exclude(flags,nf_swaped)
  359. else
  360. include(flags,nf_swaped);
  361. end;
  362. procedure tbinarynode.left_right_max;
  363. begin
  364. if assigned(left) then
  365. begin
  366. if assigned(right) then
  367. begin
  368. registers32:=max(left.registers32,right.registers32);
  369. registersfpu:=max(left.registersfpu,right.registersfpu);
  370. {$ifdef SUPPORT_MMX}
  371. registersmmx:=max(left.registersmmx,right.registersmmx);
  372. {$endif SUPPORT_MMX}
  373. end
  374. else
  375. begin
  376. registers32:=left.registers32;
  377. registersfpu:=left.registersfpu;
  378. {$ifdef SUPPORT_MMX}
  379. registersmmx:=left.registersmmx;
  380. {$endif SUPPORT_MMX}
  381. end;
  382. end;
  383. end;
  384. {$ifdef extdebug}
  385. procedure tbinarynode.dowrite;
  386. begin
  387. inherited dowrite;
  388. writeln(',');
  389. writenodeindention:=writenodeindention+' ';
  390. writenode(right);
  391. write(')');
  392. delete(writenodeindention,1,4);
  393. end;
  394. {$endif}
  395. {****************************************************************************
  396. TBINOPYNODE
  397. ****************************************************************************}
  398. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  399. begin
  400. inherited create(tt,l,r);
  401. end;
  402. function tbinopnode.docompare(p : tnode) : boolean;
  403. begin
  404. docompare:=(inherited docompare(p)) or
  405. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  406. ((nf_swapable in flags) and
  407. left.isequal(tbinopnode(p).right) and
  408. right.isequal(tbinopnode(p).left));
  409. end;
  410. {****************************************************************************
  411. WRITENODE
  412. ****************************************************************************}
  413. {$ifdef EXTDEBUG}
  414. procedure writenode(t:tnode);
  415. begin
  416. if assigned(t) then
  417. t.dowrite
  418. else
  419. write(writenodeindention,'nil');
  420. if writenodeindention='' then
  421. writeln;
  422. end;
  423. {$endif EXTDEBUG}
  424. {
  425. $Log$
  426. Revision 1.14 2000-12-31 11:14:11 jonas
  427. + implemented/fixed docompare() mathods for all nodes (not tested)
  428. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  429. and constant strings/chars together
  430. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  431. when adding
  432. Revision 1.13 2000/11/29 00:30:34 florian
  433. * unused units removed from uses clause
  434. * some changes for widestrings
  435. Revision 1.12 2000/11/04 13:10:15 jonas
  436. - removed check for self = nil in getcopy
  437. Revision 1.11 2000/10/21 18:16:11 florian
  438. * a lot of changes:
  439. - basic dyn. array support
  440. - basic C++ support
  441. - some work for interfaces done
  442. ....
  443. Revision 1.10 2000/10/14 21:52:55 peter
  444. * fixed memory leaks
  445. Revision 1.9 2000/10/14 10:14:51 peter
  446. * moehrendorf oct 2000 rewrite
  447. Revision 1.8 2000/10/01 19:48:24 peter
  448. * lot of compile updates for cg11
  449. Revision 1.7 2000/09/29 15:45:23 florian
  450. * make cycle fixed
  451. Revision 1.6 2000/09/28 19:49:52 florian
  452. *** empty log message ***
  453. Revision 1.5 2000/09/27 18:14:31 florian
  454. * fixed a lot of syntax errors in the n*.pas stuff
  455. Revision 1.4 2000/09/26 20:06:13 florian
  456. * hmm, still a lot of work to get things compilable
  457. Revision 1.3 2000/09/22 21:45:36 florian
  458. * some updates e.g. getcopy added
  459. Revision 1.2 2000/09/20 21:52:38 florian
  460. * removed a lot of errors
  461. Revision 1.1 2000/08/26 12:27:17 florian
  462. * createial release
  463. }