node.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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 = array[0..31] of byte;
  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. { taddrnode }
  216. nf_procvarload,
  217. { tvecnode }
  218. nf_memindex,
  219. nf_memseg,
  220. nf_callunique,
  221. { twithnode }
  222. nf_islocal,
  223. { tloadnode }
  224. nf_absolute,
  225. nf_first,
  226. { tassignmentnode }
  227. nf_concat_string,
  228. { tfuncretnode }
  229. nf_is_first_funcret, { 20th }
  230. { tarrayconstructnode }
  231. nf_cargs,
  232. nf_cargswap,
  233. nf_forcevaria,
  234. nf_novariaallowed,
  235. { ttypeconvnode }
  236. nf_explizit,
  237. { tinlinenode }
  238. nf_inlineconst,
  239. { general }
  240. nf_isproperty,
  241. nf_varstateset,
  242. { tasmnode }
  243. nf_object_preserved,
  244. { taddnode }
  245. nf_use_strconcat
  246. );
  247. tnodeflagset = set of tnodeflags;
  248. const
  249. { contains the flags which must be equal for the equality }
  250. { of nodes }
  251. flagsequal : tnodeflagset = [nf_error,nf_static_call,nf_backward];
  252. type
  253. tnodelist = class
  254. end;
  255. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  256. tnode = class
  257. public
  258. { type of this node }
  259. nodetype : tnodetype;
  260. { type of the current code block, general/const/type }
  261. blocktype : tblock_type;
  262. { the location of the result of this node }
  263. location : tlocation;
  264. { the parent node of this is node }
  265. { this field is set by concattolist }
  266. parent : tnode;
  267. { there are some properties about the node stored }
  268. flags : tnodeflagset;
  269. { the number of registers needed to evalute the node }
  270. registers32,registersfpu : longint; { must be longint !!!! }
  271. {$ifdef SUPPORT_MMX}
  272. registersmmx,registerskni : longint;
  273. {$endif SUPPORT_MMX}
  274. resulttype : ttype;
  275. fileinfo : tfileposinfo;
  276. localswitches : tlocalswitches;
  277. {$ifdef extdebug}
  278. maxfirstpasscount,
  279. firstpasscount : longint;
  280. {$endif extdebug}
  281. {$ifdef TEMPS_NOT_PUSH}
  282. temp_offset: longint;
  283. {$endif TEMPS_NOT_PUSH}
  284. { list : taasmoutput; }
  285. constructor create(tt : tnodetype);
  286. { this constructor is only for creating copies of class }
  287. { the fields are copied by getcopy }
  288. constructor createforcopy;
  289. destructor destroy;override;
  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. procedure det_temp;virtual;abstract;
  307. procedure pass_2;virtual;abstract;
  308. { comparing of nodes }
  309. function isequal(p : tnode) : boolean;
  310. { to implement comparisation, override this method }
  311. function docompare(p : tnode) : boolean;virtual;
  312. { gets a copy of the node }
  313. function getcopy : tnode;virtual;
  314. procedure insertintolist(l : tnodelist);virtual;
  315. {$ifdef EXTDEBUG}
  316. { writes a node for debugging purpose, shouldn't be called }
  317. { direct, because there is no test for nil, use writenode }
  318. { to write a complete tree }
  319. procedure dowrite;virtual;
  320. procedure dowritenodetype;virtual;
  321. {$endif EXTDEBUG}
  322. procedure concattolist(l : tlinkedlist);virtual;
  323. function ischild(p : tnode) : boolean;virtual;
  324. procedure set_file_line(from : tnode);
  325. procedure set_tree_filepos(const filepos : tfileposinfo);
  326. end;
  327. { this node is the anchestor for all nodes with at least }
  328. { one child, you have to use it if you want to use }
  329. { true- and falselabel }
  330. tparentnode = class(tnode)
  331. {$ifdef newcg}
  332. falselabel,truelabel : tasmlabel;
  333. {$endif newcg}
  334. end;
  335. tnodeclass = class of tnode;
  336. punarynode = ^tunarynode;
  337. tunarynode = class(tparentnode)
  338. left : tnode;
  339. constructor create(tt : tnodetype;l : tnode);
  340. destructor destroy;override;
  341. procedure concattolist(l : tlinkedlist);override;
  342. function ischild(p : tnode) : boolean;override;
  343. function docompare(p : tnode) : boolean;override;
  344. function getcopy : tnode;override;
  345. procedure insertintolist(l : tnodelist);override;
  346. procedure left_max;
  347. {$ifdef extdebug}
  348. procedure dowrite;override;
  349. {$endif extdebug}
  350. end;
  351. pbinarynode = ^tbinarynode;
  352. tbinarynode = class(tunarynode)
  353. right : tnode;
  354. constructor create(tt : tnodetype;l,r : tnode);
  355. destructor destroy;override;
  356. procedure concattolist(l : tlinkedlist);override;
  357. function ischild(p : tnode) : boolean;override;
  358. function docompare(p : tnode) : boolean;override;
  359. procedure swapleftright;
  360. function getcopy : tnode;override;
  361. procedure insertintolist(l : tnodelist);override;
  362. procedure left_right_max;
  363. {$ifdef extdebug}
  364. procedure dowrite;override;
  365. {$endif extdebug}
  366. end;
  367. pbinopnode = ^tbinopnode;
  368. tbinopnode = class(tbinarynode)
  369. constructor create(tt : tnodetype;l,r : tnode);virtual;
  370. function docompare(p : tnode) : boolean;override;
  371. end;
  372. {$ifdef EXTDEBUG}
  373. var
  374. writenodeindention : string;
  375. procedure writenode(t:tnode);
  376. {$endif EXTDEBUG}
  377. {$ifdef tempregdebug}
  378. type
  379. pptree = ^tnode;
  380. var
  381. curptree: pptree;
  382. {$endif tempregdebug}
  383. implementation
  384. uses
  385. cutils;
  386. {****************************************************************************
  387. TNODE
  388. ****************************************************************************}
  389. constructor tnode.create(tt : tnodetype);
  390. begin
  391. inherited create;
  392. nodetype:=tt;
  393. blocktype:=block_type;
  394. { this allows easier error tracing }
  395. location.loc:=LOC_INVALID;
  396. { save local info }
  397. fileinfo:=aktfilepos;
  398. localswitches:=aktlocalswitches;
  399. resulttype.reset;
  400. registers32:=0;
  401. registersfpu:=0;
  402. {$ifdef SUPPORT_MMX}
  403. registersmmx:=0;
  404. {$endif SUPPORT_MMX}
  405. {$ifdef EXTDEBUG}
  406. maxfirstpasscount:=0;
  407. firstpasscount:=0;
  408. {$endif EXTDEBUG}
  409. flags:=[];
  410. end;
  411. constructor tnode.createforcopy;
  412. begin
  413. end;
  414. procedure tnode.toggleflag(f : tnodeflags);
  415. begin
  416. if f in flags then
  417. exclude(flags,f)
  418. else
  419. include(flags,f);
  420. end;
  421. destructor tnode.destroy;
  422. begin
  423. {$ifdef EXTDEBUG}
  424. if firstpasscount>maxfirstpasscount then
  425. maxfirstpasscount:=firstpasscount;
  426. {$endif EXTDEBUG}
  427. end;
  428. procedure tnode.concattolist(l : tlinkedlist);
  429. begin
  430. {$ifdef newcg}
  431. //!!!!!!! l^.concat(self);
  432. {$warning fixme}
  433. {$endif newcg}
  434. end;
  435. function tnode.ischild(p : tnode) : boolean;
  436. begin
  437. ischild:=false;
  438. end;
  439. {$ifdef EXTDEBUG}
  440. procedure tnode.dowrite;
  441. begin
  442. dowritenodetype;
  443. end;
  444. procedure tnode.dowritenodetype;
  445. begin
  446. write(writenodeindention,'(',nodetype2str[nodetype]);
  447. end;
  448. {$endif EXTDEBUG}
  449. function tnode.isequal(p : tnode) : boolean;
  450. begin
  451. isequal:=
  452. (not assigned(self) and not assigned(p)) or
  453. (assigned(self) and assigned(p) and
  454. { optimized subclasses have the same nodetype as their }
  455. { superclass (for compatibility), so also check the classtype (JM) }
  456. (p.classtype=classtype) and
  457. (p.nodetype=nodetype) and
  458. (flags*flagsequal=p.flags*flagsequal) and
  459. docompare(p));
  460. end;
  461. {$ifdef state_tracking}
  462. function Tnode.track_state_pass(exec_known:boolean):boolean;
  463. begin
  464. track_state_pass:=false;
  465. end;
  466. {$endif state_tracking}
  467. function tnode.docompare(p : tnode) : boolean;
  468. begin
  469. docompare:=true;
  470. end;
  471. function tnode.getcopy : tnode;
  472. var
  473. p : tnode;
  474. begin
  475. { this is quite tricky because we need a node of the current }
  476. { node type and not one of tnode! }
  477. p:=tnodeclass(classtype).createforcopy;
  478. p.nodetype:=nodetype;
  479. p.location:=location;
  480. p.parent:=parent;
  481. p.flags:=flags;
  482. p.registers32:=registers32;
  483. p.registersfpu:=registersfpu;
  484. {$ifdef SUPPORT_MMX}
  485. p.registersmmx:=registersmmx;
  486. p.registerskni:=registerskni;
  487. {$endif SUPPORT_MMX}
  488. p.resulttype:=resulttype;
  489. p.fileinfo:=fileinfo;
  490. p.localswitches:=localswitches;
  491. {$ifdef extdebug}
  492. p.firstpasscount:=firstpasscount;
  493. {$endif extdebug}
  494. { p.list:=list; }
  495. getcopy:=p;
  496. end;
  497. procedure tnode.insertintolist(l : tnodelist);
  498. begin
  499. end;
  500. procedure tnode.set_file_line(from : tnode);
  501. begin
  502. if assigned(from) then
  503. fileinfo:=from.fileinfo;
  504. end;
  505. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  506. begin
  507. fileinfo:=filepos;
  508. end;
  509. {****************************************************************************
  510. TUNARYNODE
  511. ****************************************************************************}
  512. constructor tunarynode.create(tt : tnodetype;l : tnode);
  513. begin
  514. inherited create(tt);
  515. left:=l;
  516. end;
  517. destructor tunarynode.destroy;
  518. begin
  519. left.free;
  520. inherited destroy;
  521. end;
  522. function tunarynode.docompare(p : tnode) : boolean;
  523. begin
  524. docompare:=(inherited docompare(p) and
  525. ((left=nil) or left.isequal(tunarynode(p).left))
  526. );
  527. end;
  528. function tunarynode.getcopy : tnode;
  529. var
  530. p : tunarynode;
  531. begin
  532. p:=tunarynode(inherited getcopy);
  533. if assigned(left) then
  534. p.left:=left.getcopy
  535. else
  536. p.left:=nil;
  537. getcopy:=p;
  538. end;
  539. procedure tunarynode.insertintolist(l : tnodelist);
  540. begin
  541. end;
  542. {$ifdef extdebug}
  543. procedure tunarynode.dowrite;
  544. begin
  545. inherited dowrite;
  546. writeln(',');
  547. writenodeindention:=writenodeindention+' ';
  548. writenode(left);
  549. write(')');
  550. delete(writenodeindention,1,4);
  551. end;
  552. {$endif}
  553. procedure tunarynode.left_max;
  554. begin
  555. registers32:=left.registers32;
  556. registersfpu:=left.registersfpu;
  557. {$ifdef SUPPORT_MMX}
  558. registersmmx:=left.registersmmx;
  559. {$endif SUPPORT_MMX}
  560. end;
  561. procedure tunarynode.concattolist(l : tlinkedlist);
  562. begin
  563. left.parent:=self;
  564. left.concattolist(l);
  565. inherited concattolist(l);
  566. end;
  567. function tunarynode.ischild(p : tnode) : boolean;
  568. begin
  569. ischild:=p=left;
  570. end;
  571. {****************************************************************************
  572. TBINARYNODE
  573. ****************************************************************************}
  574. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  575. begin
  576. inherited create(tt,l);
  577. right:=r
  578. end;
  579. destructor tbinarynode.destroy;
  580. begin
  581. right.free;
  582. inherited destroy;
  583. end;
  584. procedure tbinarynode.concattolist(l : tlinkedlist);
  585. begin
  586. { we could change that depending on the number of }
  587. { required registers }
  588. left.parent:=self;
  589. left.concattolist(l);
  590. left.parent:=self;
  591. left.concattolist(l);
  592. inherited concattolist(l);
  593. end;
  594. function tbinarynode.ischild(p : tnode) : boolean;
  595. begin
  596. ischild:=(p=right);
  597. end;
  598. function tbinarynode.docompare(p : tnode) : boolean;
  599. begin
  600. docompare:=(inherited docompare(p) and
  601. ((right=nil) or right.isequal(tbinarynode(p).right))
  602. );
  603. end;
  604. function tbinarynode.getcopy : tnode;
  605. var
  606. p : tbinarynode;
  607. begin
  608. p:=tbinarynode(inherited getcopy);
  609. if assigned(right) then
  610. p.right:=right.getcopy
  611. else
  612. p.right:=nil;
  613. getcopy:=p;
  614. end;
  615. procedure tbinarynode.insertintolist(l : tnodelist);
  616. begin
  617. end;
  618. procedure tbinarynode.swapleftright;
  619. var
  620. swapp : tnode;
  621. begin
  622. swapp:=right;
  623. right:=left;
  624. left:=swapp;
  625. if nf_swaped in flags then
  626. exclude(flags,nf_swaped)
  627. else
  628. include(flags,nf_swaped);
  629. end;
  630. procedure tbinarynode.left_right_max;
  631. begin
  632. if assigned(left) then
  633. begin
  634. if assigned(right) then
  635. begin
  636. registers32:=max(left.registers32,right.registers32);
  637. registersfpu:=max(left.registersfpu,right.registersfpu);
  638. {$ifdef SUPPORT_MMX}
  639. registersmmx:=max(left.registersmmx,right.registersmmx);
  640. {$endif SUPPORT_MMX}
  641. end
  642. else
  643. begin
  644. registers32:=left.registers32;
  645. registersfpu:=left.registersfpu;
  646. {$ifdef SUPPORT_MMX}
  647. registersmmx:=left.registersmmx;
  648. {$endif SUPPORT_MMX}
  649. end;
  650. end;
  651. end;
  652. {$ifdef extdebug}
  653. procedure tbinarynode.dowrite;
  654. begin
  655. inherited dowrite;
  656. writeln(',');
  657. writenodeindention:=writenodeindention+' ';
  658. writenode(right);
  659. write(')');
  660. delete(writenodeindention,1,4);
  661. end;
  662. {$endif}
  663. {****************************************************************************
  664. TBINOPYNODE
  665. ****************************************************************************}
  666. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  667. begin
  668. inherited create(tt,l,r);
  669. end;
  670. function tbinopnode.docompare(p : tnode) : boolean;
  671. begin
  672. docompare:=(inherited docompare(p)) or
  673. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  674. ((nf_swapable in flags) and
  675. left.isequal(tbinopnode(p).right) and
  676. right.isequal(tbinopnode(p).left));
  677. end;
  678. {****************************************************************************
  679. WRITENODE
  680. ****************************************************************************}
  681. {$ifdef EXTDEBUG}
  682. procedure writenode(t:tnode);
  683. begin
  684. if assigned(t) then
  685. t.dowrite
  686. else
  687. write(writenodeindention,'nil');
  688. if writenodeindention='' then
  689. writeln;
  690. end;
  691. {$endif EXTDEBUG}
  692. end.
  693. {
  694. $Log$
  695. Revision 1.30 2002-07-19 11:41:36 daniel
  696. * State tracker work
  697. * The whilen and repeatn are now completely unified into whilerepeatn. This
  698. allows the state tracker to change while nodes automatically into
  699. repeat nodes.
  700. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  701. 'not(a>b)' is optimized into 'a<=b'.
  702. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  703. by removing the notn and later switchting the true and falselabels. The
  704. same is done with 'repeat until not a'.
  705. Revision 1.29 2002/07/14 18:00:44 daniel
  706. + Added the beginning of a state tracker. This will track the values of
  707. variables through procedures and optimize things away.
  708. Revision 1.28 2002/07/01 18:46:24 peter
  709. * internal linker
  710. * reorganized aasm layer
  711. Revision 1.27 2002/05/18 13:34:10 peter
  712. * readded missing revisions
  713. Revision 1.26 2002/05/16 19:46:39 carl
  714. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  715. + try to fix temp allocation (still in ifdef)
  716. + generic constructor calls
  717. + start of tassembler / tmodulebase class cleanup
  718. Revision 1.24 2002/04/21 19:02:04 peter
  719. * removed newn and disposen nodes, the code is now directly
  720. inlined from pexpr
  721. * -an option that will write the secondpass nodes to the .s file, this
  722. requires EXTDEBUG define to actually write the info
  723. * fixed various internal errors and crashes due recent code changes
  724. Revision 1.23 2002/04/06 18:13:01 jonas
  725. * several powerpc-related additions and fixes
  726. Revision 1.22 2002/03/31 20:26:35 jonas
  727. + a_loadfpu_* and a_loadmm_* methods in tcg
  728. * register allocation is now handled by a class and is mostly processor
  729. independent (+rgobj.pas and i386/rgcpu.pas)
  730. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  731. * some small improvements and fixes to the optimizer
  732. * some register allocation fixes
  733. * some fpuvaroffset fixes in the unary minus node
  734. * push/popusedregisters is now called rg.save/restoreusedregisters and
  735. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  736. also better optimizable)
  737. * fixed and optimized register saving/restoring for new/dispose nodes
  738. * LOC_FPU locations now also require their "register" field to be set to
  739. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  740. - list field removed of the tnode class because it's not used currently
  741. and can cause hard-to-find bugs
  742. Revision 1.21 2002/01/19 11:52:32 peter
  743. * dynarr:=nil support added
  744. }