node.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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;
  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. addn, {Represents the + operator.}
  38. muln, {Represents the * operator.}
  39. subn, {Represents the - operator.}
  40. divn, {Represents the div operator.}
  41. symdifn, {Represents the >< operator.}
  42. modn, {Represents the mod operator.}
  43. assignn, {Represents an assignment.}
  44. loadn, {Represents the use of a variabele.}
  45. rangen, {Represents a range (i.e. 0..9).}
  46. ltn, {Represents the < operator.}
  47. lten, {Represents the <= operator.}
  48. gtn, {Represents the > operator.}
  49. gten, {Represents the >= operator.}
  50. equaln, {Represents the = operator.}
  51. unequaln, {Represents the <> operator.}
  52. inn, {Represents the in operator.}
  53. orn, {Represents the or operator.}
  54. xorn, {Represents the xor operator.}
  55. shrn, {Represents the shr operator.}
  56. shln, {Represents the shl operator.}
  57. slashn, {Represents the / operator.}
  58. andn, {Represents the and operator.}
  59. subscriptn, {??? Field in a record/object?}
  60. derefn, {Dereferences a pointer.}
  61. addrn, {Represents the @ operator.}
  62. doubleaddrn, {Represents the @@ operator.}
  63. ordconstn, {Represents an ordinal value.}
  64. typeconvn, {Represents type-conversion/typecast.}
  65. calln, {Represents a call node.}
  66. callparan, {Represents a parameter.}
  67. realconstn, {Represents a real value.}
  68. unaryminusn, {Represents a sign change (i.e. -2).}
  69. asmn, {Represents an assembler node }
  70. vecn, {Represents array indexing.}
  71. pointerconstn,
  72. stringconstn, {Represents a string constant.}
  73. funcretn, {Represents the function result var.}
  74. selfn, {Represents the self parameter.}
  75. notn, {Represents the not operator.}
  76. inlinen, {Internal procedures (i.e. writeln).}
  77. niln, {Represents the nil pointer.}
  78. errorn, {This part of the tree could not be
  79. parsed because of a compiler error.}
  80. typen, {A type name. Used for i.e. typeof(obj).}
  81. hnewn, {The new operation, constructor call.}
  82. hdisposen, {The dispose operation with destructor call.}
  83. setelementn, {A set element(s) (i.e. [a,b] and also [a..b]).}
  84. setconstn, {A set constant (i.e. [1,2]).}
  85. blockn, {A block of statements.}
  86. statementn, {One statement in a block of nodes.}
  87. loopn, { used in genloopnode, must be converted }
  88. ifn, {An if statement.}
  89. breakn, {A break statement.}
  90. continuen, {A continue statement.}
  91. (* repeatn, {A repeat until block.}
  92. whilen, {A while do statement.}*)
  93. whilerepeatn, {A while or repeat statement.}
  94. forn, {A for loop.}
  95. exitn, {An exit statement.}
  96. withn, {A with statement.}
  97. casen, {A case statement.}
  98. labeln, {A label.}
  99. goton, {A goto statement.}
  100. tryexceptn, {A try except block.}
  101. raisen, {A raise statement.}
  102. tryfinallyn, {A try finally statement.}
  103. onn, {For an on statement in exception code.}
  104. isn, {Represents the is operator.}
  105. asn, {Represents the as typecast.}
  106. caretn, {Represents the ^ operator.}
  107. failn, {Represents the fail statement.}
  108. starstarn, {Represents the ** operator exponentiation }
  109. procinlinen, {Procedures that can be inlined }
  110. arrayconstructorn, {Construction node for [...] parsing}
  111. arrayconstructorrangen, {Range element to allow sets in array construction tree}
  112. tempn, { for temps in the result/firstpass }
  113. temprefn, { references to temps }
  114. { added for optimizations where we cannot suppress }
  115. addoptn,
  116. nothingn,
  117. loadvmtn,
  118. guidconstn,
  119. rttin {Rtti information so they can be accessed in result/firstpass.}
  120. );
  121. const
  122. nodetype2str : array[tnodetype] of string[20] = (
  123. 'addn',
  124. 'muln',
  125. 'subn',
  126. 'divn',
  127. 'symdifn',
  128. 'modn',
  129. 'assignn',
  130. 'loadn',
  131. 'rangen',
  132. 'ltn',
  133. 'lten',
  134. 'gtn',
  135. 'gten',
  136. 'equaln',
  137. 'unequaln',
  138. 'inn',
  139. 'orn',
  140. 'xorn',
  141. 'shrn',
  142. 'shln',
  143. 'slashn',
  144. 'andn',
  145. 'subscriptn',
  146. 'derefn',
  147. 'addrn',
  148. 'doubleaddrn',
  149. 'ordconstn',
  150. 'typeconvn',
  151. 'calln',
  152. 'callparan',
  153. 'realconstn',
  154. 'umminusn',
  155. 'asmn',
  156. 'vecn',
  157. 'pointerconstn',
  158. 'stringconstn',
  159. 'funcretn',
  160. 'selfn',
  161. 'notn',
  162. 'inlinen',
  163. 'niln',
  164. 'errorn',
  165. 'typen',
  166. 'hnewn',
  167. 'hdisposen',
  168. 'setelementn',
  169. 'setconstn',
  170. 'blockn',
  171. 'statementn',
  172. 'loopn',
  173. 'ifn',
  174. 'breakn',
  175. 'continuen',
  176. (* 'repeatn',
  177. 'whilen',*)
  178. 'whilerepeatn',
  179. 'forn',
  180. 'exitn',
  181. 'withn',
  182. 'casen',
  183. 'labeln',
  184. 'goton',
  185. 'tryexceptn',
  186. 'raisen',
  187. 'tryfinallyn',
  188. 'onn',
  189. 'isn',
  190. 'asn',
  191. 'caretn',
  192. 'failn',
  193. 'starstarn',
  194. 'procinlinen',
  195. 'arrayconstructn',
  196. 'arrayconstructrangen',
  197. 'tempn',
  198. 'temprefn',
  199. 'addoptn',
  200. 'nothingn',
  201. 'loadvmtn',
  202. 'guidconstn',
  203. 'rttin');
  204. type
  205. { all boolean field of ttree are now collected in flags }
  206. tnodeflags = (
  207. nf_needs_truefalselabel,
  208. nf_swapable, { tbinop operands can be swaped }
  209. nf_swaped, { tbinop operands are swaped }
  210. nf_error,
  211. { flags used by tcallnode }
  212. nf_return_value_used,
  213. nf_static_call,
  214. { flags used by tcallparanode }
  215. nf_varargs_para, { belongs this para to varargs }
  216. { flags used by loop nodes }
  217. nf_backward, { set if it is a for ... downto ... do loop }
  218. nf_varstate, { do we need to parse childs to set var state }
  219. nf_testatbegin,{ Do a test at the begin of the loop?}
  220. nf_checknegate,{ Negate the loop test?}
  221. { taddrnode }
  222. nf_procvarload,
  223. { tvecnode }
  224. nf_memindex,
  225. nf_memseg,
  226. nf_callunique,
  227. { twithnode }
  228. nf_islocal,
  229. { tloadnode }
  230. nf_absolute,
  231. nf_first,
  232. { tassignmentnode }
  233. nf_concat_string,
  234. { tfuncretnode }
  235. nf_is_first_funcret, { 20th }
  236. { tarrayconstructnode }
  237. nf_cargs,
  238. nf_cargswap,
  239. nf_forcevaria,
  240. nf_novariaallowed,
  241. { ttypeconvnode }
  242. nf_explizit,
  243. { tinlinenode }
  244. nf_inlineconst,
  245. { general }
  246. nf_isproperty,
  247. nf_varstateset,
  248. { tasmnode }
  249. nf_object_preserved,
  250. { taddnode }
  251. nf_use_strconcat
  252. );
  253. tnodeflagset = set of tnodeflags;
  254. const
  255. { contains the flags which must be equal for the equality }
  256. { of nodes }
  257. flagsequal : tnodeflagset = [nf_error,nf_static_call,nf_backward];
  258. type
  259. tnodelist = class
  260. end;
  261. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  262. tnode = class
  263. public
  264. { type of this node }
  265. nodetype : tnodetype;
  266. { type of the current code block, general/const/type }
  267. blocktype : tblock_type;
  268. { the location of the result of this node }
  269. location : tlocation;
  270. { the parent node of this is node }
  271. { this field is set by concattolist }
  272. parent : tnode;
  273. { there are some properties about the node stored }
  274. flags : tnodeflagset;
  275. { the number of registers needed to evalute the node }
  276. registers32,registersfpu : longint; { must be longint !!!! }
  277. {$ifdef SUPPORT_MMX}
  278. registersmmx,registerskni : longint;
  279. {$endif SUPPORT_MMX}
  280. resulttype : ttype;
  281. fileinfo : tfileposinfo;
  282. localswitches : tlocalswitches;
  283. {$ifdef extdebug}
  284. maxfirstpasscount,
  285. firstpasscount : longint;
  286. {$endif extdebug}
  287. {$ifdef TEMPS_NOT_PUSH}
  288. temp_offset: longint;
  289. {$endif TEMPS_NOT_PUSH}
  290. { list : taasmoutput; }
  291. constructor create(tt : tnodetype);
  292. { this constructor is only for creating copies of class }
  293. { the fields are copied by getcopy }
  294. constructor createforcopy;
  295. destructor destroy;override;
  296. { toggles the flag }
  297. procedure toggleflag(f : tnodeflags);
  298. { the 1.1 code generator may override pass_1 }
  299. { and it need not to implement det_* then }
  300. { 1.1: pass_1 returns a value<>0 if the node has been transformed }
  301. { 2.0: runs det_resulttype and det_temp }
  302. function pass_1 : tnode;virtual;abstract;
  303. { dermines the resulttype of the node }
  304. function det_resulttype : tnode;virtual;abstract;
  305. { dermines the number of necessary temp. locations to evaluate
  306. the node }
  307. {$ifdef state_tracking}
  308. { Does optimizations by keeping track of the variable states
  309. in a procedure }
  310. function track_state_pass(exec_known:boolean):boolean;virtual;
  311. {$endif}
  312. procedure det_temp;virtual;abstract;
  313. procedure pass_2;virtual;abstract;
  314. { comparing of nodes }
  315. function isequal(p : tnode) : boolean;
  316. { to implement comparisation, override this method }
  317. function docompare(p : tnode) : boolean;virtual;
  318. { gets a copy of the node }
  319. function getcopy : tnode;virtual;
  320. procedure insertintolist(l : tnodelist);virtual;
  321. {$ifdef EXTDEBUG}
  322. { writes a node for debugging purpose, shouldn't be called }
  323. { direct, because there is no test for nil, use writenode }
  324. { to write a complete tree }
  325. procedure dowrite;virtual;
  326. procedure dowritenodetype;virtual;
  327. {$endif EXTDEBUG}
  328. procedure concattolist(l : tlinkedlist);virtual;
  329. function ischild(p : tnode) : boolean;virtual;
  330. procedure set_file_line(from : tnode);
  331. procedure set_tree_filepos(const filepos : tfileposinfo);
  332. end;
  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. tparentnode = class(tnode)
  337. {$ifdef newcg}
  338. falselabel,truelabel : tasmlabel;
  339. {$endif newcg}
  340. end;
  341. tnodeclass = class of tnode;
  342. punarynode = ^tunarynode;
  343. tunarynode = class(tparentnode)
  344. left : tnode;
  345. constructor create(tt : tnodetype;l : tnode);
  346. destructor destroy;override;
  347. procedure concattolist(l : tlinkedlist);override;
  348. function ischild(p : tnode) : boolean;override;
  349. function docompare(p : tnode) : boolean;override;
  350. function getcopy : tnode;override;
  351. procedure insertintolist(l : tnodelist);override;
  352. procedure left_max;
  353. {$ifdef extdebug}
  354. procedure dowrite;override;
  355. {$endif extdebug}
  356. end;
  357. pbinarynode = ^tbinarynode;
  358. tbinarynode = class(tunarynode)
  359. right : tnode;
  360. constructor create(tt : tnodetype;l,r : tnode);
  361. destructor destroy;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. pbinopnode = ^tbinopnode;
  374. tbinopnode = class(tbinarynode)
  375. constructor create(tt : tnodetype;l,r : tnode);virtual;
  376. function docompare(p : tnode) : boolean;override;
  377. end;
  378. {$ifdef EXTDEBUG}
  379. var
  380. writenodeindention : string;
  381. procedure writenode(t:tnode);
  382. {$endif EXTDEBUG}
  383. {$ifdef tempregdebug}
  384. type
  385. pptree = ^tnode;
  386. var
  387. curptree: pptree;
  388. {$endif tempregdebug}
  389. implementation
  390. uses
  391. cutils;
  392. {****************************************************************************
  393. TNODE
  394. ****************************************************************************}
  395. constructor tnode.create(tt : tnodetype);
  396. begin
  397. inherited create;
  398. nodetype:=tt;
  399. blocktype:=block_type;
  400. { this allows easier error tracing }
  401. location.loc:=LOC_INVALID;
  402. { save local info }
  403. fileinfo:=aktfilepos;
  404. localswitches:=aktlocalswitches;
  405. resulttype.reset;
  406. registers32:=0;
  407. registersfpu:=0;
  408. {$ifdef SUPPORT_MMX}
  409. registersmmx:=0;
  410. {$endif SUPPORT_MMX}
  411. {$ifdef EXTDEBUG}
  412. maxfirstpasscount:=0;
  413. firstpasscount:=0;
  414. {$endif EXTDEBUG}
  415. flags:=[];
  416. end;
  417. constructor tnode.createforcopy;
  418. begin
  419. end;
  420. procedure tnode.toggleflag(f : tnodeflags);
  421. begin
  422. if f in flags then
  423. exclude(flags,f)
  424. else
  425. include(flags,f);
  426. end;
  427. destructor tnode.destroy;
  428. begin
  429. {$ifdef EXTDEBUG}
  430. if firstpasscount>maxfirstpasscount then
  431. maxfirstpasscount:=firstpasscount;
  432. {$endif EXTDEBUG}
  433. end;
  434. procedure tnode.concattolist(l : tlinkedlist);
  435. begin
  436. {$ifdef newcg}
  437. //!!!!!!! l^.concat(self);
  438. {$warning fixme}
  439. {$endif newcg}
  440. end;
  441. function tnode.ischild(p : tnode) : boolean;
  442. begin
  443. ischild:=false;
  444. end;
  445. {$ifdef EXTDEBUG}
  446. procedure tnode.dowrite;
  447. begin
  448. dowritenodetype;
  449. end;
  450. procedure tnode.dowritenodetype;
  451. begin
  452. write(writenodeindention,'(',nodetype2str[nodetype]);
  453. end;
  454. {$endif EXTDEBUG}
  455. function tnode.isequal(p : tnode) : boolean;
  456. begin
  457. isequal:=
  458. (not assigned(self) and not assigned(p)) or
  459. (assigned(self) and assigned(p) and
  460. { optimized subclasses have the same nodetype as their }
  461. { superclass (for compatibility), so also check the classtype (JM) }
  462. (p.classtype=classtype) and
  463. (p.nodetype=nodetype) and
  464. (flags*flagsequal=p.flags*flagsequal) and
  465. docompare(p));
  466. end;
  467. {$ifdef state_tracking}
  468. function Tnode.track_state_pass(exec_known:boolean):boolean;
  469. begin
  470. track_state_pass:=false;
  471. end;
  472. {$endif state_tracking}
  473. function tnode.docompare(p : tnode) : boolean;
  474. begin
  475. docompare:=true;
  476. end;
  477. function tnode.getcopy : tnode;
  478. var
  479. p : tnode;
  480. begin
  481. { this is quite tricky because we need a node of the current }
  482. { node type and not one of tnode! }
  483. p:=tnodeclass(classtype).createforcopy;
  484. p.nodetype:=nodetype;
  485. p.location:=location;
  486. p.parent:=parent;
  487. p.flags:=flags;
  488. p.registers32:=registers32;
  489. p.registersfpu:=registersfpu;
  490. {$ifdef SUPPORT_MMX}
  491. p.registersmmx:=registersmmx;
  492. p.registerskni:=registerskni;
  493. {$endif SUPPORT_MMX}
  494. p.resulttype:=resulttype;
  495. p.fileinfo:=fileinfo;
  496. p.localswitches:=localswitches;
  497. {$ifdef extdebug}
  498. p.firstpasscount:=firstpasscount;
  499. {$endif extdebug}
  500. { p.list:=list; }
  501. getcopy:=p;
  502. end;
  503. procedure tnode.insertintolist(l : tnodelist);
  504. begin
  505. end;
  506. procedure tnode.set_file_line(from : tnode);
  507. begin
  508. if assigned(from) then
  509. fileinfo:=from.fileinfo;
  510. end;
  511. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  512. begin
  513. fileinfo:=filepos;
  514. end;
  515. {****************************************************************************
  516. TUNARYNODE
  517. ****************************************************************************}
  518. constructor tunarynode.create(tt : tnodetype;l : tnode);
  519. begin
  520. inherited create(tt);
  521. left:=l;
  522. end;
  523. destructor tunarynode.destroy;
  524. begin
  525. left.free;
  526. inherited destroy;
  527. end;
  528. function tunarynode.docompare(p : tnode) : boolean;
  529. begin
  530. docompare:=(inherited docompare(p) and
  531. ((left=nil) or left.isequal(tunarynode(p).left))
  532. );
  533. end;
  534. function tunarynode.getcopy : tnode;
  535. var
  536. p : tunarynode;
  537. begin
  538. p:=tunarynode(inherited getcopy);
  539. if assigned(left) then
  540. p.left:=left.getcopy
  541. else
  542. p.left:=nil;
  543. getcopy:=p;
  544. end;
  545. procedure tunarynode.insertintolist(l : tnodelist);
  546. begin
  547. end;
  548. {$ifdef extdebug}
  549. procedure tunarynode.dowrite;
  550. begin
  551. inherited dowrite;
  552. writeln(',');
  553. writenodeindention:=writenodeindention+' ';
  554. writenode(left);
  555. write(')');
  556. delete(writenodeindention,1,4);
  557. end;
  558. {$endif}
  559. procedure tunarynode.left_max;
  560. begin
  561. registers32:=left.registers32;
  562. registersfpu:=left.registersfpu;
  563. {$ifdef SUPPORT_MMX}
  564. registersmmx:=left.registersmmx;
  565. {$endif SUPPORT_MMX}
  566. end;
  567. procedure tunarynode.concattolist(l : tlinkedlist);
  568. begin
  569. left.parent:=self;
  570. left.concattolist(l);
  571. inherited concattolist(l);
  572. end;
  573. function tunarynode.ischild(p : tnode) : boolean;
  574. begin
  575. ischild:=p=left;
  576. end;
  577. {****************************************************************************
  578. TBINARYNODE
  579. ****************************************************************************}
  580. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  581. begin
  582. inherited create(tt,l);
  583. right:=r
  584. end;
  585. destructor tbinarynode.destroy;
  586. begin
  587. right.free;
  588. inherited destroy;
  589. end;
  590. procedure tbinarynode.concattolist(l : tlinkedlist);
  591. begin
  592. { we could change that depending on the number of }
  593. { required registers }
  594. left.parent:=self;
  595. left.concattolist(l);
  596. left.parent:=self;
  597. left.concattolist(l);
  598. inherited concattolist(l);
  599. end;
  600. function tbinarynode.ischild(p : tnode) : boolean;
  601. begin
  602. ischild:=(p=right);
  603. end;
  604. function tbinarynode.docompare(p : tnode) : boolean;
  605. begin
  606. docompare:=(inherited docompare(p) and
  607. ((right=nil) or right.isequal(tbinarynode(p).right))
  608. );
  609. end;
  610. function tbinarynode.getcopy : tnode;
  611. var
  612. p : tbinarynode;
  613. begin
  614. p:=tbinarynode(inherited getcopy);
  615. if assigned(right) then
  616. p.right:=right.getcopy
  617. else
  618. p.right:=nil;
  619. getcopy:=p;
  620. end;
  621. procedure tbinarynode.insertintolist(l : tnodelist);
  622. begin
  623. end;
  624. procedure tbinarynode.swapleftright;
  625. var
  626. swapp : tnode;
  627. begin
  628. swapp:=right;
  629. right:=left;
  630. left:=swapp;
  631. if nf_swaped in flags then
  632. exclude(flags,nf_swaped)
  633. else
  634. include(flags,nf_swaped);
  635. end;
  636. procedure tbinarynode.left_right_max;
  637. begin
  638. if assigned(left) then
  639. begin
  640. if assigned(right) then
  641. begin
  642. registers32:=max(left.registers32,right.registers32);
  643. registersfpu:=max(left.registersfpu,right.registersfpu);
  644. {$ifdef SUPPORT_MMX}
  645. registersmmx:=max(left.registersmmx,right.registersmmx);
  646. {$endif SUPPORT_MMX}
  647. end
  648. else
  649. begin
  650. registers32:=left.registers32;
  651. registersfpu:=left.registersfpu;
  652. {$ifdef SUPPORT_MMX}
  653. registersmmx:=left.registersmmx;
  654. {$endif SUPPORT_MMX}
  655. end;
  656. end;
  657. end;
  658. {$ifdef extdebug}
  659. procedure tbinarynode.dowrite;
  660. begin
  661. inherited dowrite;
  662. writeln(',');
  663. writenodeindention:=writenodeindention+' ';
  664. writenode(right);
  665. write(')');
  666. delete(writenodeindention,1,4);
  667. end;
  668. {$endif}
  669. {****************************************************************************
  670. TBINOPYNODE
  671. ****************************************************************************}
  672. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  673. begin
  674. inherited create(tt,l,r);
  675. end;
  676. function tbinopnode.docompare(p : tnode) : boolean;
  677. begin
  678. docompare:=(inherited docompare(p)) or
  679. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  680. ((nf_swapable in flags) and
  681. left.isequal(tbinopnode(p).right) and
  682. right.isequal(tbinopnode(p).left));
  683. end;
  684. {****************************************************************************
  685. WRITENODE
  686. ****************************************************************************}
  687. {$ifdef EXTDEBUG}
  688. procedure writenode(t:tnode);
  689. begin
  690. if assigned(t) then
  691. t.dowrite
  692. else
  693. write(writenodeindention,'nil');
  694. if writenodeindention='' then
  695. writeln;
  696. end;
  697. {$endif EXTDEBUG}
  698. end.
  699. {
  700. $Log$
  701. Revision 1.33 2002-07-23 12:34:30 daniel
  702. * Readded old set code. To use it define 'oldset'. Activated by default
  703. for ppc.
  704. Revision 1.32 2002/07/22 11:48:04 daniel
  705. * Sets are now internally sets.
  706. Revision 1.31 2002/07/21 06:58:49 daniel
  707. * Changed booleans into flags
  708. Revision 1.30 2002/07/19 11:41:36 daniel
  709. * State tracker work
  710. * The whilen and repeatn are now completely unified into whilerepeatn. This
  711. allows the state tracker to change while nodes automatically into
  712. repeat nodes.
  713. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  714. 'not(a>b)' is optimized into 'a<=b'.
  715. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  716. by removing the notn and later switchting the true and falselabels. The
  717. same is done with 'repeat until not a'.
  718. Revision 1.29 2002/07/14 18:00:44 daniel
  719. + Added the beginning of a state tracker. This will track the values of
  720. variables through procedures and optimize things away.
  721. Revision 1.28 2002/07/01 18:46:24 peter
  722. * internal linker
  723. * reorganized aasm layer
  724. Revision 1.27 2002/05/18 13:34:10 peter
  725. * readded missing revisions
  726. Revision 1.26 2002/05/16 19:46:39 carl
  727. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  728. + try to fix temp allocation (still in ifdef)
  729. + generic constructor calls
  730. + start of tassembler / tmodulebase class cleanup
  731. Revision 1.24 2002/04/21 19:02:04 peter
  732. * removed newn and disposen nodes, the code is now directly
  733. inlined from pexpr
  734. * -an option that will write the secondpass nodes to the .s file, this
  735. requires EXTDEBUG define to actually write the info
  736. * fixed various internal errors and crashes due recent code changes
  737. Revision 1.23 2002/04/06 18:13:01 jonas
  738. * several powerpc-related additions and fixes
  739. Revision 1.22 2002/03/31 20:26:35 jonas
  740. + a_loadfpu_* and a_loadmm_* methods in tcg
  741. * register allocation is now handled by a class and is mostly processor
  742. independent (+rgobj.pas and i386/rgcpu.pas)
  743. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  744. * some small improvements and fixes to the optimizer
  745. * some register allocation fixes
  746. * some fpuvaroffset fixes in the unary minus node
  747. * push/popusedregisters is now called rg.save/restoreusedregisters and
  748. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  749. also better optimizable)
  750. * fixed and optimized register saving/restoring for new/dispose nodes
  751. * LOC_FPU locations now also require their "register" field to be set to
  752. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  753. - list field removed of the tnode class because it's not used currently
  754. and can cause hard-to-find bugs
  755. Revision 1.21 2002/01/19 11:52:32 peter
  756. * dynarr:=nil support added
  757. }