2
0

node.pas 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. Basic node handling
  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. unit node;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. globtype,globals,
  24. cpubase,
  25. aasmbase,
  26. symtype,symppu;
  27. type
  28. pconstset = ^tconstset;
  29. {$ifdef oldset}
  30. tconstset = array[0..31] of byte;
  31. pconst32bitset = ^tconst32bitset;
  32. tconst32bitset = array[0..7] of longint;
  33. {$else}
  34. tconstset = set of 0..255;
  35. {$endif}
  36. tnodetype = (
  37. emptynode, {No node (returns nil when loading from ppu)}
  38. addn, {Represents the + operator}
  39. muln, {Represents the * operator}
  40. subn, {Represents the - operator}
  41. divn, {Represents the div operator}
  42. symdifn, {Represents the >< operator}
  43. modn, {Represents the mod operator}
  44. assignn, {Represents an assignment}
  45. loadn, {Represents the use of a variabele}
  46. rangen, {Represents a range (i.e. 0..9)}
  47. ltn, {Represents the < operator}
  48. lten, {Represents the <= operator}
  49. gtn, {Represents the > operator}
  50. gten, {Represents the >= operator}
  51. equaln, {Represents the = operator}
  52. unequaln, {Represents the <> operator}
  53. inn, {Represents the in operator}
  54. orn, {Represents the or operator}
  55. xorn, {Represents the xor operator}
  56. shrn, {Represents the shr operator}
  57. shln, {Represents the shl operator}
  58. slashn, {Represents the / operator}
  59. andn, {Represents the and operator}
  60. subscriptn, {Field in a record/object}
  61. derefn, {Dereferences a pointer}
  62. addrn, {Represents the @ operator}
  63. doubleaddrn, {Represents the @@ operator}
  64. ordconstn, {Represents an ordinal value}
  65. typeconvn, {Represents type-conversion/typecast}
  66. calln, {Represents a call node}
  67. callparan, {Represents a parameter}
  68. realconstn, {Represents a real value}
  69. unaryminusn, {Represents a sign change (i.e. -2)}
  70. asmn, {Represents an assembler node }
  71. vecn, {Represents array indexing}
  72. pointerconstn, {Represents a pointer constant}
  73. stringconstn, {Represents a string constant}
  74. funcretn, {Represents the function result var}
  75. selfn, {Represents the self parameter}
  76. notn, {Represents the not operator}
  77. inlinen, {Internal procedures (i.e. writeln)}
  78. niln, {Represents the nil pointer}
  79. errorn, {This part of the tree could not be
  80. parsed because of a compiler error}
  81. typen, {A type name. Used for i.e. typeof(obj)}
  82. hnewn, {The new operation, constructor call}
  83. hdisposen, {The dispose operation with destructor call}
  84. setelementn, {A set element(s) (i.e. [a,b] and also [a..b])}
  85. setconstn, {A set constant (i.e. [1,2])}
  86. blockn, {A block of statements}
  87. statementn, {One statement in a block of nodes}
  88. ifn, {An if statement}
  89. breakn, {A break statement}
  90. continuen, {A continue statement}
  91. whilerepeatn, {A while or repeat statement}
  92. forn, {A for loop}
  93. exitn, {An exit statement}
  94. withn, {A with statement}
  95. casen, {A case statement}
  96. labeln, {A label}
  97. goton, {A goto statement}
  98. tryexceptn, {A try except block}
  99. raisen, {A raise statement}
  100. tryfinallyn, {A try finally statement}
  101. onn, {For an on statement in exception code}
  102. isn, {Represents the is operator}
  103. asn, {Represents the as typecast}
  104. caretn, {Represents the ^ operator}
  105. failn, {Represents the fail statement}
  106. starstarn, {Represents the ** operator exponentiation }
  107. procinlinen, {Procedures that can be inlined }
  108. arrayconstructorn, {Construction node for [...] parsing}
  109. arrayconstructorrangen, {Range element to allow sets in array construction tree}
  110. tempcreaten, { for temps in the result/firstpass }
  111. temprefn, { references to temps }
  112. tempdeleten, { for temps in the result/firstpass }
  113. addoptn, { added for optimizations where we cannot suppress }
  114. nothingn, {NOP, Do nothing}
  115. loadvmtn, {Load the address of the VMT of a class/object}
  116. guidconstn, {A GUID COM Interface constant }
  117. rttin {Rtti information so they can be accessed in result/firstpass}
  118. );
  119. const
  120. nodetype2str : array[tnodetype] of string[20] = (
  121. '<emptynode>',
  122. 'addn',
  123. 'muln',
  124. 'subn',
  125. 'divn',
  126. 'symdifn',
  127. 'modn',
  128. 'assignn',
  129. 'loadn',
  130. 'rangen',
  131. 'ltn',
  132. 'lten',
  133. 'gtn',
  134. 'gten',
  135. 'equaln',
  136. 'unequaln',
  137. 'inn',
  138. 'orn',
  139. 'xorn',
  140. 'shrn',
  141. 'shln',
  142. 'slashn',
  143. 'andn',
  144. 'subscriptn',
  145. 'derefn',
  146. 'addrn',
  147. 'doubleaddrn',
  148. 'ordconstn',
  149. 'typeconvn',
  150. 'calln',
  151. 'callparan',
  152. 'realconstn',
  153. 'unaryminusn',
  154. 'asmn',
  155. 'vecn',
  156. 'pointerconstn',
  157. 'stringconstn',
  158. 'funcretn',
  159. 'selfn',
  160. 'notn',
  161. 'inlinen',
  162. 'niln',
  163. 'errorn',
  164. 'typen',
  165. 'hnewn',
  166. 'hdisposen',
  167. 'setelementn',
  168. 'setconstn',
  169. 'blockn',
  170. 'statementn',
  171. 'ifn',
  172. 'breakn',
  173. 'continuen',
  174. 'whilerepeatn',
  175. 'forn',
  176. 'exitn',
  177. 'withn',
  178. 'casen',
  179. 'labeln',
  180. 'goton',
  181. 'tryexceptn',
  182. 'raisen',
  183. 'tryfinallyn',
  184. 'onn',
  185. 'isn',
  186. 'asn',
  187. 'caretn',
  188. 'failn',
  189. 'starstarn',
  190. 'procinlinen',
  191. 'arrayconstructn',
  192. 'arrayconstructrangen',
  193. 'tempcreaten',
  194. 'temprefn',
  195. 'tempdeleten',
  196. 'addoptn',
  197. 'nothingn',
  198. 'loadvmtn',
  199. 'guidconstn',
  200. 'rttin');
  201. type
  202. { all boolean field of ttree are now collected in flags }
  203. tnodeflags = (
  204. nf_needs_truefalselabel,
  205. nf_swapable, { tbinop operands can be swaped }
  206. nf_swaped, { tbinop operands are swaped }
  207. nf_error,
  208. nf_write, { Node is written to }
  209. { flags used by tcallnode }
  210. nf_return_value_used,
  211. nf_static_call,
  212. nf_auto_inherited,
  213. { flags used by tcallparanode }
  214. nf_varargs_para, { belongs this para to varargs }
  215. nf_hightree_generated, { has the hightree for thispara been generated }
  216. { taddrnode }
  217. nf_procvarload,
  218. { tvecnode }
  219. nf_memindex,
  220. nf_memseg,
  221. nf_callunique,
  222. { twithnode }
  223. nf_islocal,
  224. { tloadnode }
  225. nf_absolute,
  226. nf_first,
  227. { tassignmentnode }
  228. nf_concat_string,
  229. { tfuncretnode }
  230. nf_is_first_funcret,
  231. { tarrayconstructnode }
  232. nf_cargs, { 20th }
  233. nf_cargswap,
  234. nf_forcevaria,
  235. nf_novariaallowed,
  236. { ttypeconvnode }
  237. nf_explizit,
  238. { tinlinenode }
  239. nf_inlineconst,
  240. { general }
  241. nf_isproperty,
  242. nf_varstateset,
  243. { tasmnode }
  244. nf_object_preserved, { 30th }
  245. { taddnode }
  246. nf_use_strconcat
  247. );
  248. tnodeflagset = set of tnodeflags;
  249. const
  250. { contains the flags which must be equal for the equality }
  251. { of nodes }
  252. flagsequal : tnodeflagset = [nf_error,nf_static_call];
  253. type
  254. tnodelist = class
  255. end;
  256. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  257. tnode = class
  258. public
  259. { type of this node }
  260. nodetype : tnodetype;
  261. { type of the current code block, general/const/type }
  262. blocktype : tblock_type;
  263. { the location of the result of this node }
  264. location : tlocation;
  265. { the parent node of this is node }
  266. { this field is set by concattolist }
  267. parent : tnode;
  268. { there are some properties about the node stored }
  269. flags : tnodeflagset;
  270. { the number of registers needed to evalute the node }
  271. registers32,registersfpu : longint; { must be longint !!!! }
  272. {$ifdef SUPPORT_MMX}
  273. registersmmx,registerskni : longint;
  274. {$endif SUPPORT_MMX}
  275. resulttype : ttype;
  276. fileinfo : tfileposinfo;
  277. localswitches : tlocalswitches;
  278. {$ifdef extdebug}
  279. maxfirstpasscount,
  280. firstpasscount : longint;
  281. {$endif extdebug}
  282. constructor create(t:tnodetype);
  283. { this constructor is only for creating copies of class }
  284. { the fields are copied by getcopy }
  285. constructor createforcopy;
  286. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);virtual;
  287. destructor destroy;override;
  288. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  289. procedure derefimpl;virtual;
  290. { toggles the flag }
  291. procedure toggleflag(f : tnodeflags);
  292. { the 1.1 code generator may override pass_1 }
  293. { and it need not to implement det_* then }
  294. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  295. { 2.0: runs det_resulttype and det_temp }
  296. function pass_1 : tnode;virtual;abstract;
  297. { dermines the resulttype of the node }
  298. function det_resulttype : tnode;virtual;abstract;
  299. { dermines the number of necessary temp. locations to evaluate
  300. the node }
  301. {$ifdef state_tracking}
  302. { Does optimizations by keeping track of the variable states
  303. in a procedure }
  304. function track_state_pass(exec_known:boolean):boolean;virtual;
  305. {$endif}
  306. { For a t1:=t2 tree, mark the part of the tree t1 that gets
  307. written to (normally the loadnode) as write access. }
  308. procedure mark_write;virtual;
  309. procedure det_temp;virtual;abstract;
  310. procedure pass_2;virtual;abstract;
  311. { comparing of nodes }
  312. function isequal(p : tnode) : boolean;
  313. { to implement comparisation, override this method }
  314. function docompare(p : tnode) : boolean;virtual;
  315. { gets a copy of the node }
  316. function getcopy : tnode;virtual;
  317. procedure insertintolist(l : tnodelist);virtual;
  318. {$ifdef EXTDEBUG}
  319. { writes a node for debugging purpose, shouldn't be called }
  320. { direct, because there is no test for nil, use writenode }
  321. { to write a complete tree }
  322. procedure dowrite;
  323. procedure dowritenodetype;virtual;
  324. procedure _dowrite;virtual;
  325. {$endif EXTDEBUG}
  326. procedure concattolist(l : tlinkedlist);virtual;
  327. function ischild(p : tnode) : boolean;virtual;
  328. procedure set_file_line(from : tnode);
  329. procedure set_tree_filepos(const filepos : tfileposinfo);
  330. end;
  331. tnodeclass = class of tnode;
  332. tnodeclassarray = array[tnodetype] of tnodeclass;
  333. { this node is the anchestor for all nodes with at least }
  334. { one child, you have to use it if you want to use }
  335. { true- and falselabel }
  336. punarynode = ^tunarynode;
  337. tunarynode = class(tnode)
  338. left : tnode;
  339. constructor create(t:tnodetype;l : tnode);
  340. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  341. destructor destroy;override;
  342. procedure ppuwrite(ppufile:tcompilerppufile);override;
  343. procedure derefimpl;override;
  344. procedure concattolist(l : tlinkedlist);override;
  345. function ischild(p : tnode) : boolean;override;
  346. function docompare(p : tnode) : boolean;override;
  347. function getcopy : tnode;override;
  348. procedure insertintolist(l : tnodelist);override;
  349. procedure left_max;
  350. {$ifdef extdebug}
  351. procedure _dowrite;override;
  352. {$endif extdebug}
  353. end;
  354. pbinarynode = ^tbinarynode;
  355. tbinarynode = class(tunarynode)
  356. right : tnode;
  357. constructor create(t:tnodetype;l,r : tnode);
  358. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  359. destructor destroy;override;
  360. procedure ppuwrite(ppufile:tcompilerppufile);override;
  361. procedure derefimpl;override;
  362. procedure concattolist(l : tlinkedlist);override;
  363. function ischild(p : tnode) : boolean;override;
  364. function docompare(p : tnode) : boolean;override;
  365. procedure swapleftright;
  366. function getcopy : tnode;override;
  367. procedure insertintolist(l : tnodelist);override;
  368. procedure left_right_max;
  369. {$ifdef extdebug}
  370. procedure _dowrite;override;
  371. {$endif extdebug}
  372. end;
  373. tbinopnode = class(tbinarynode)
  374. constructor create(t:tnodetype;l,r : tnode);virtual;
  375. function docompare(p : tnode) : boolean;override;
  376. end;
  377. {$ifdef tempregdebug}
  378. type
  379. pptree = ^tnode;
  380. var
  381. curptree: pptree;
  382. {$endif tempregdebug}
  383. var
  384. { array with all class types for tnodes }
  385. nodeclass : tnodeclassarray;
  386. {$ifdef EXTDEBUG}
  387. { indention used when writing the tree to the screen }
  388. writenodeindention : string;
  389. {$endif EXTDEBUG}
  390. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  391. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  392. {$ifdef EXTDEBUG}
  393. procedure writenode(t:tnode);
  394. {$endif EXTDEBUG}
  395. implementation
  396. uses
  397. cutils,verbose;
  398. const
  399. ppunodemarker = 255;
  400. {****************************************************************************
  401. Helpers
  402. ****************************************************************************}
  403. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  404. var
  405. b : byte;
  406. t : tnodetype;
  407. begin
  408. { marker }
  409. b:=ppufile.getbyte;
  410. if b<>ppunodemarker then
  411. internalerror(200208151);
  412. { load nodetype }
  413. t:=tnodetype(ppufile.getbyte);
  414. if t>high(tnodetype) then
  415. internalerror(200208152);
  416. if t<>emptynode then
  417. begin
  418. if not assigned(nodeclass[t]) then
  419. internalerror(200208153);
  420. //writeln('load: ',nodetype2str[t]);
  421. { generate node of the correct class }
  422. ppuloadnode:=nodeclass[t].ppuload(t,ppufile);
  423. end
  424. else
  425. ppuloadnode:=nil;
  426. end;
  427. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  428. begin
  429. { marker, read by ppuloadnode }
  430. ppufile.putbyte(ppunodemarker);
  431. { type, read by ppuloadnode }
  432. if assigned(n) then
  433. begin
  434. ppufile.putbyte(byte(n.nodetype));
  435. //writeln('write: ',nodetype2str[n.nodetype]);
  436. n.ppuwrite(ppufile);
  437. end
  438. else
  439. ppufile.putbyte(byte(emptynode));
  440. end;
  441. {$ifdef EXTDEBUG}
  442. procedure writenode(t:tnode);
  443. begin
  444. if assigned(t) then
  445. t.dowrite
  446. else
  447. write(writenodeindention,'nil');
  448. if writenodeindention='' then
  449. writeln;
  450. end;
  451. {$endif EXTDEBUG}
  452. {****************************************************************************
  453. TNODE
  454. ****************************************************************************}
  455. constructor tnode.create(t:tnodetype);
  456. begin
  457. inherited create;
  458. nodetype:=t;
  459. blocktype:=block_type;
  460. { this allows easier error tracing }
  461. location.loc:=LOC_INVALID;
  462. { save local info }
  463. fileinfo:=aktfilepos;
  464. localswitches:=aktlocalswitches;
  465. resulttype.reset;
  466. registers32:=0;
  467. registersfpu:=0;
  468. {$ifdef SUPPORT_MMX}
  469. registersmmx:=0;
  470. {$endif SUPPORT_MMX}
  471. {$ifdef EXTDEBUG}
  472. maxfirstpasscount:=0;
  473. firstpasscount:=0;
  474. {$endif EXTDEBUG}
  475. flags:=[];
  476. end;
  477. constructor tnode.createforcopy;
  478. begin
  479. end;
  480. constructor tnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  481. begin
  482. nodetype:=t;
  483. { tnode fields }
  484. blocktype:=tblock_type(ppufile.getbyte);
  485. ppufile.getposinfo(fileinfo);
  486. ppufile.getsmallset(localswitches);
  487. ppufile.gettype(resulttype);
  488. ppufile.getsmallset(flags);
  489. { updated by firstpass }
  490. location.loc:=LOC_INVALID;
  491. registers32:=0;
  492. registersfpu:=0;
  493. {$ifdef SUPPORT_MMX}
  494. registersmmx:=0;
  495. {$endif SUPPORT_MMX}
  496. {$ifdef EXTDEBUG}
  497. maxfirstpasscount:=0;
  498. firstpasscount:=0;
  499. {$endif EXTDEBUG}
  500. end;
  501. procedure tnode.ppuwrite(ppufile:tcompilerppufile);
  502. begin
  503. ppufile.putbyte(byte(block_type));
  504. ppufile.putposinfo(fileinfo);
  505. ppufile.putsmallset(localswitches);
  506. ppufile.puttype(resulttype);
  507. ppufile.putsmallset(flags);
  508. end;
  509. procedure tnode.derefimpl;
  510. begin
  511. resulttype.resolve;
  512. end;
  513. procedure tnode.toggleflag(f : tnodeflags);
  514. begin
  515. if f in flags then
  516. exclude(flags,f)
  517. else
  518. include(flags,f);
  519. end;
  520. destructor tnode.destroy;
  521. begin
  522. {$ifdef EXTDEBUG}
  523. if firstpasscount>maxfirstpasscount then
  524. maxfirstpasscount:=firstpasscount;
  525. {$endif EXTDEBUG}
  526. end;
  527. procedure tnode.concattolist(l : tlinkedlist);
  528. begin
  529. end;
  530. function tnode.ischild(p : tnode) : boolean;
  531. begin
  532. ischild:=false;
  533. end;
  534. {$ifdef EXTDEBUG}
  535. procedure tnode._dowrite;
  536. begin
  537. dowritenodetype;
  538. if assigned(resulttype.def) then
  539. write(',resulttype = "',resulttype.def.gettypename,'"')
  540. else
  541. write(',resulttype = <nil>');
  542. write(',location.loc = ',ord(location.loc));
  543. write(',registersint = ',registers32);
  544. write(',registersfpu = ',registersfpu);
  545. end;
  546. procedure tnode.dowritenodetype;
  547. begin
  548. write(nodetype2str[nodetype]);
  549. end;
  550. procedure tnode.dowrite;
  551. begin
  552. write(writenodeindention,'(');
  553. writenodeindention:=writenodeindention+' ';
  554. _dowrite;
  555. writeln;
  556. delete(writenodeindention,1,4);
  557. write(writenodeindention,')');
  558. end;
  559. {$endif EXTDEBUG}
  560. function tnode.isequal(p : tnode) : boolean;
  561. begin
  562. isequal:=
  563. (not assigned(self) and not assigned(p)) or
  564. (assigned(self) and assigned(p) and
  565. { optimized subclasses have the same nodetype as their }
  566. { superclass (for compatibility), so also check the classtype (JM) }
  567. (p.classtype=classtype) and
  568. (p.nodetype=nodetype) and
  569. (flags*flagsequal=p.flags*flagsequal) and
  570. docompare(p));
  571. end;
  572. {$ifdef state_tracking}
  573. function Tnode.track_state_pass(exec_known:boolean):boolean;
  574. begin
  575. track_state_pass:=false;
  576. end;
  577. {$endif state_tracking}
  578. function tnode.docompare(p : tnode) : boolean;
  579. begin
  580. docompare:=true;
  581. end;
  582. function tnode.getcopy : tnode;
  583. var
  584. p : tnode;
  585. begin
  586. { this is quite tricky because we need a node of the current }
  587. { node type and not one of tnode! }
  588. p:=tnodeclass(classtype).createforcopy;
  589. p.nodetype:=nodetype;
  590. p.location:=location;
  591. p.parent:=parent;
  592. p.flags:=flags;
  593. p.registers32:=registers32;
  594. p.registersfpu:=registersfpu;
  595. {$ifdef SUPPORT_MMX}
  596. p.registersmmx:=registersmmx;
  597. p.registerskni:=registerskni;
  598. {$endif SUPPORT_MMX}
  599. p.resulttype:=resulttype;
  600. p.fileinfo:=fileinfo;
  601. p.localswitches:=localswitches;
  602. {$ifdef extdebug}
  603. p.firstpasscount:=firstpasscount;
  604. {$endif extdebug}
  605. { p.list:=list; }
  606. getcopy:=p;
  607. end;
  608. procedure tnode.mark_write;
  609. begin
  610. end;
  611. procedure tnode.insertintolist(l : tnodelist);
  612. begin
  613. end;
  614. procedure tnode.set_file_line(from : tnode);
  615. begin
  616. if assigned(from) then
  617. fileinfo:=from.fileinfo;
  618. end;
  619. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  620. begin
  621. fileinfo:=filepos;
  622. end;
  623. {****************************************************************************
  624. TUNARYNODE
  625. ****************************************************************************}
  626. constructor tunarynode.create(t:tnodetype;l : tnode);
  627. begin
  628. inherited create(t);
  629. left:=l;
  630. end;
  631. constructor tunarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  632. begin
  633. inherited ppuload(t,ppufile);
  634. left:=ppuloadnode(ppufile);
  635. end;
  636. destructor tunarynode.destroy;
  637. begin
  638. left.free;
  639. inherited destroy;
  640. end;
  641. procedure tunarynode.ppuwrite(ppufile:tcompilerppufile);
  642. begin
  643. inherited ppuwrite(ppufile);
  644. ppuwritenode(ppufile,left);
  645. end;
  646. procedure tunarynode.derefimpl;
  647. begin
  648. inherited derefimpl;
  649. if assigned(left) then
  650. left.derefimpl;
  651. end;
  652. function tunarynode.docompare(p : tnode) : boolean;
  653. begin
  654. docompare:=(inherited docompare(p) and
  655. ((left=nil) or left.isequal(tunarynode(p).left))
  656. );
  657. end;
  658. function tunarynode.getcopy : tnode;
  659. var
  660. p : tunarynode;
  661. begin
  662. p:=tunarynode(inherited getcopy);
  663. if assigned(left) then
  664. p.left:=left.getcopy
  665. else
  666. p.left:=nil;
  667. getcopy:=p;
  668. end;
  669. procedure tunarynode.insertintolist(l : tnodelist);
  670. begin
  671. end;
  672. {$ifdef extdebug}
  673. procedure tunarynode._dowrite;
  674. begin
  675. inherited _dowrite;
  676. writeln(',');
  677. writenode(left);
  678. end;
  679. {$endif}
  680. procedure tunarynode.left_max;
  681. begin
  682. registers32:=left.registers32;
  683. registersfpu:=left.registersfpu;
  684. {$ifdef SUPPORT_MMX}
  685. registersmmx:=left.registersmmx;
  686. {$endif SUPPORT_MMX}
  687. end;
  688. procedure tunarynode.concattolist(l : tlinkedlist);
  689. begin
  690. left.parent:=self;
  691. left.concattolist(l);
  692. inherited concattolist(l);
  693. end;
  694. function tunarynode.ischild(p : tnode) : boolean;
  695. begin
  696. ischild:=p=left;
  697. end;
  698. {****************************************************************************
  699. TBINARYNODE
  700. ****************************************************************************}
  701. constructor tbinarynode.create(t:tnodetype;l,r : tnode);
  702. begin
  703. inherited create(t,l);
  704. right:=r
  705. end;
  706. constructor tbinarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  707. begin
  708. inherited ppuload(t,ppufile);
  709. right:=ppuloadnode(ppufile);
  710. end;
  711. destructor tbinarynode.destroy;
  712. begin
  713. right.free;
  714. inherited destroy;
  715. end;
  716. procedure tbinarynode.ppuwrite(ppufile:tcompilerppufile);
  717. begin
  718. inherited ppuwrite(ppufile);
  719. ppuwritenode(ppufile,right);
  720. end;
  721. procedure tbinarynode.derefimpl;
  722. begin
  723. inherited derefimpl;
  724. if assigned(right) then
  725. right.derefimpl;
  726. end;
  727. procedure tbinarynode.concattolist(l : tlinkedlist);
  728. begin
  729. { we could change that depending on the number of }
  730. { required registers }
  731. left.parent:=self;
  732. left.concattolist(l);
  733. left.parent:=self;
  734. left.concattolist(l);
  735. inherited concattolist(l);
  736. end;
  737. function tbinarynode.ischild(p : tnode) : boolean;
  738. begin
  739. ischild:=(p=right);
  740. end;
  741. function tbinarynode.docompare(p : tnode) : boolean;
  742. begin
  743. docompare:=(inherited docompare(p) and
  744. ((right=nil) or right.isequal(tbinarynode(p).right))
  745. );
  746. end;
  747. function tbinarynode.getcopy : tnode;
  748. var
  749. p : tbinarynode;
  750. begin
  751. p:=tbinarynode(inherited getcopy);
  752. if assigned(right) then
  753. p.right:=right.getcopy
  754. else
  755. p.right:=nil;
  756. getcopy:=p;
  757. end;
  758. procedure tbinarynode.insertintolist(l : tnodelist);
  759. begin
  760. end;
  761. procedure tbinarynode.swapleftright;
  762. var
  763. swapp : tnode;
  764. begin
  765. swapp:=right;
  766. right:=left;
  767. left:=swapp;
  768. if nf_swaped in flags then
  769. exclude(flags,nf_swaped)
  770. else
  771. include(flags,nf_swaped);
  772. end;
  773. procedure tbinarynode.left_right_max;
  774. begin
  775. if assigned(left) then
  776. begin
  777. if assigned(right) then
  778. begin
  779. registers32:=max(left.registers32,right.registers32);
  780. registersfpu:=max(left.registersfpu,right.registersfpu);
  781. {$ifdef SUPPORT_MMX}
  782. registersmmx:=max(left.registersmmx,right.registersmmx);
  783. {$endif SUPPORT_MMX}
  784. end
  785. else
  786. begin
  787. registers32:=left.registers32;
  788. registersfpu:=left.registersfpu;
  789. {$ifdef SUPPORT_MMX}
  790. registersmmx:=left.registersmmx;
  791. {$endif SUPPORT_MMX}
  792. end;
  793. end;
  794. end;
  795. {$ifdef extdebug}
  796. procedure tbinarynode._dowrite;
  797. begin
  798. inherited _dowrite;
  799. writeln(',');
  800. writenode(right);
  801. end;
  802. {$endif}
  803. {****************************************************************************
  804. TBINOPYNODE
  805. ****************************************************************************}
  806. constructor tbinopnode.create(t:tnodetype;l,r : tnode);
  807. begin
  808. inherited create(t,l,r);
  809. end;
  810. function tbinopnode.docompare(p : tnode) : boolean;
  811. begin
  812. docompare:=(inherited docompare(p)) or
  813. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  814. ((nf_swapable in flags) and
  815. left.isequal(tbinopnode(p).right) and
  816. right.isequal(tbinopnode(p).left));
  817. end;
  818. end.
  819. {
  820. $Log$
  821. Revision 1.48 2003-01-03 21:03:02 peter
  822. * made mark_write dummy instead of abstract
  823. Revision 1.47 2003/01/03 12:15:56 daniel
  824. * Removed ifdefs around notifications
  825. ifdefs around for loop optimizations remain
  826. Revision 1.46 2002/12/26 18:24:33 jonas
  827. * fixed check for whether or not a high parameter was already generated
  828. * no type checking/conversions for invisible parameters
  829. Revision 1.45 2002/11/28 11:17:04 florian
  830. * loop node flags from node flags splitted
  831. Revision 1.44 2002/10/05 00:48:57 peter
  832. * support inherited; support for overload as it is handled by
  833. delphi. This is only for delphi mode as it is working is
  834. undocumented and hard to predict what is done
  835. Revision 1.43 2002/09/07 15:25:03 peter
  836. * old logs removed and tabs fixed
  837. Revision 1.42 2002/09/03 16:26:26 daniel
  838. * Make Tprocdef.defs protected
  839. Revision 1.41 2002/09/01 13:28:38 daniel
  840. - write_access fields removed in favor of a flag
  841. Revision 1.40 2002/09/01 08:01:16 daniel
  842. * Removed sets from Tcallnode.det_resulttype
  843. + Added read/write notifications of variables. These will be usefull
  844. for providing information for several optimizations. For example
  845. the value of the loop variable of a for loop does matter is the
  846. variable is read after the for loop, but if it's no longer used
  847. or written, it doesn't matter and this can be used to optimize
  848. the loop code generation.
  849. Revision 1.39 2002/08/22 11:21:45 florian
  850. + register32 is now written by tnode.dowrite
  851. * fixed write of value of tconstnode
  852. Revision 1.38 2002/08/19 19:36:44 peter
  853. * More fixes for cross unit inlining, all tnodes are now implemented
  854. * Moved pocall_internconst to po_internconst because it is not a
  855. calling type at all and it conflicted when inlining of these small
  856. functions was requested
  857. Revision 1.37 2002/08/18 20:06:24 peter
  858. * inlining is now also allowed in interface
  859. * renamed write/load to ppuwrite/ppuload
  860. * tnode storing in ppu
  861. * nld,ncon,nbas are already updated for storing in ppu
  862. Revision 1.36 2002/08/17 22:09:46 florian
  863. * result type handling in tcgcal.pass_2 overhauled
  864. * better tnode.dowrite
  865. * some ppc stuff fixed
  866. Revision 1.35 2002/08/15 19:10:35 peter
  867. * first things tai,tnode storing in ppu
  868. Revision 1.34 2002/08/09 19:15:41 carl
  869. - removed newcg define
  870. Revision 1.33 2002/07/23 12:34:30 daniel
  871. * Readded old set code. To use it define 'oldset'. Activated by default
  872. for ppc.
  873. Revision 1.32 2002/07/22 11:48:04 daniel
  874. * Sets are now internally sets.
  875. Revision 1.31 2002/07/21 06:58:49 daniel
  876. * Changed booleans into flags
  877. Revision 1.30 2002/07/19 11:41:36 daniel
  878. * State tracker work
  879. * The whilen and repeatn are now completely unified into whilerepeatn. This
  880. allows the state tracker to change while nodes automatically into
  881. repeat nodes.
  882. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  883. 'not(a>b)' is optimized into 'a<=b'.
  884. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  885. by removing the notn and later switchting the true and falselabels. The
  886. same is done with 'repeat until not a'.
  887. Revision 1.29 2002/07/14 18:00:44 daniel
  888. + Added the beginning of a state tracker. This will track the values of
  889. variables through procedures and optimize things away.
  890. Revision 1.28 2002/07/01 18:46:24 peter
  891. * internal linker
  892. * reorganized aasm layer
  893. Revision 1.27 2002/05/18 13:34:10 peter
  894. * readded missing revisions
  895. Revision 1.26 2002/05/16 19:46:39 carl
  896. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  897. + try to fix temp allocation (still in ifdef)
  898. + generic constructor calls
  899. + start of tassembler / tmodulebase class cleanup
  900. Revision 1.24 2002/04/21 19:02:04 peter
  901. * removed newn and disposen nodes, the code is now directly
  902. inlined from pexpr
  903. * -an option that will write the secondpass nodes to the .s file, this
  904. requires EXTDEBUG define to actually write the info
  905. * fixed various internal errors and crashes due recent code changes
  906. Revision 1.23 2002/04/06 18:13:01 jonas
  907. * several powerpc-related additions and fixes
  908. Revision 1.22 2002/03/31 20:26:35 jonas
  909. + a_loadfpu_* and a_loadmm_* methods in tcg
  910. * register allocation is now handled by a class and is mostly processor
  911. independent (+rgobj.pas and i386/rgcpu.pas)
  912. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  913. * some small improvements and fixes to the optimizer
  914. * some register allocation fixes
  915. * some fpuvaroffset fixes in the unary minus node
  916. * push/popusedregisters is now called rg.save/restoreusedregisters and
  917. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  918. also better optimizable)
  919. * fixed and optimized register saving/restoring for new/dispose nodes
  920. * LOC_FPU locations now also require their "register" field to be set to
  921. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  922. - list field removed of the tnode class because it's not used currently
  923. and can cause hard-to-find bugs
  924. }