node.pas 26 KB

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