node.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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. end;
  338. tnodeclass = class of tnode;
  339. punarynode = ^tunarynode;
  340. tunarynode = class(tparentnode)
  341. left : tnode;
  342. constructor create(tt : tnodetype;l : tnode);
  343. destructor destroy;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(tt : tnodetype;l,r : tnode);
  358. destructor destroy;override;
  359. procedure concattolist(l : tlinkedlist);override;
  360. function ischild(p : tnode) : boolean;override;
  361. function docompare(p : tnode) : boolean;override;
  362. procedure swapleftright;
  363. function getcopy : tnode;override;
  364. procedure insertintolist(l : tnodelist);override;
  365. procedure left_right_max;
  366. {$ifdef extdebug}
  367. procedure dowrite;override;
  368. {$endif extdebug}
  369. end;
  370. pbinopnode = ^tbinopnode;
  371. tbinopnode = class(tbinarynode)
  372. constructor create(tt : tnodetype;l,r : tnode);virtual;
  373. function docompare(p : tnode) : boolean;override;
  374. end;
  375. {$ifdef EXTDEBUG}
  376. var
  377. writenodeindention : string;
  378. procedure writenode(t:tnode);
  379. {$endif EXTDEBUG}
  380. {$ifdef tempregdebug}
  381. type
  382. pptree = ^tnode;
  383. var
  384. curptree: pptree;
  385. {$endif tempregdebug}
  386. implementation
  387. uses
  388. cutils;
  389. {****************************************************************************
  390. TNODE
  391. ****************************************************************************}
  392. constructor tnode.create(tt : tnodetype);
  393. begin
  394. inherited create;
  395. nodetype:=tt;
  396. blocktype:=block_type;
  397. { this allows easier error tracing }
  398. location.loc:=LOC_INVALID;
  399. { save local info }
  400. fileinfo:=aktfilepos;
  401. localswitches:=aktlocalswitches;
  402. resulttype.reset;
  403. registers32:=0;
  404. registersfpu:=0;
  405. {$ifdef SUPPORT_MMX}
  406. registersmmx:=0;
  407. {$endif SUPPORT_MMX}
  408. {$ifdef EXTDEBUG}
  409. maxfirstpasscount:=0;
  410. firstpasscount:=0;
  411. {$endif EXTDEBUG}
  412. flags:=[];
  413. end;
  414. constructor tnode.createforcopy;
  415. begin
  416. end;
  417. procedure tnode.toggleflag(f : tnodeflags);
  418. begin
  419. if f in flags then
  420. exclude(flags,f)
  421. else
  422. include(flags,f);
  423. end;
  424. destructor tnode.destroy;
  425. begin
  426. {$ifdef EXTDEBUG}
  427. if firstpasscount>maxfirstpasscount then
  428. maxfirstpasscount:=firstpasscount;
  429. {$endif EXTDEBUG}
  430. end;
  431. procedure tnode.concattolist(l : tlinkedlist);
  432. begin
  433. end;
  434. function tnode.ischild(p : tnode) : boolean;
  435. begin
  436. ischild:=false;
  437. end;
  438. {$ifdef EXTDEBUG}
  439. procedure tnode.dowrite;
  440. begin
  441. dowritenodetype;
  442. end;
  443. procedure tnode.dowritenodetype;
  444. begin
  445. write(writenodeindention,'(',nodetype2str[nodetype]);
  446. end;
  447. {$endif EXTDEBUG}
  448. function tnode.isequal(p : tnode) : boolean;
  449. begin
  450. isequal:=
  451. (not assigned(self) and not assigned(p)) or
  452. (assigned(self) and assigned(p) and
  453. { optimized subclasses have the same nodetype as their }
  454. { superclass (for compatibility), so also check the classtype (JM) }
  455. (p.classtype=classtype) and
  456. (p.nodetype=nodetype) and
  457. (flags*flagsequal=p.flags*flagsequal) and
  458. docompare(p));
  459. end;
  460. {$ifdef state_tracking}
  461. function Tnode.track_state_pass(exec_known:boolean):boolean;
  462. begin
  463. track_state_pass:=false;
  464. end;
  465. {$endif state_tracking}
  466. function tnode.docompare(p : tnode) : boolean;
  467. begin
  468. docompare:=true;
  469. end;
  470. function tnode.getcopy : tnode;
  471. var
  472. p : tnode;
  473. begin
  474. { this is quite tricky because we need a node of the current }
  475. { node type and not one of tnode! }
  476. p:=tnodeclass(classtype).createforcopy;
  477. p.nodetype:=nodetype;
  478. p.location:=location;
  479. p.parent:=parent;
  480. p.flags:=flags;
  481. p.registers32:=registers32;
  482. p.registersfpu:=registersfpu;
  483. {$ifdef SUPPORT_MMX}
  484. p.registersmmx:=registersmmx;
  485. p.registerskni:=registerskni;
  486. {$endif SUPPORT_MMX}
  487. p.resulttype:=resulttype;
  488. p.fileinfo:=fileinfo;
  489. p.localswitches:=localswitches;
  490. {$ifdef extdebug}
  491. p.firstpasscount:=firstpasscount;
  492. {$endif extdebug}
  493. { p.list:=list; }
  494. getcopy:=p;
  495. end;
  496. procedure tnode.insertintolist(l : tnodelist);
  497. begin
  498. end;
  499. procedure tnode.set_file_line(from : tnode);
  500. begin
  501. if assigned(from) then
  502. fileinfo:=from.fileinfo;
  503. end;
  504. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  505. begin
  506. fileinfo:=filepos;
  507. end;
  508. {****************************************************************************
  509. TUNARYNODE
  510. ****************************************************************************}
  511. constructor tunarynode.create(tt : tnodetype;l : tnode);
  512. begin
  513. inherited create(tt);
  514. left:=l;
  515. end;
  516. destructor tunarynode.destroy;
  517. begin
  518. left.free;
  519. inherited destroy;
  520. end;
  521. function tunarynode.docompare(p : tnode) : boolean;
  522. begin
  523. docompare:=(inherited docompare(p) and
  524. ((left=nil) or left.isequal(tunarynode(p).left))
  525. );
  526. end;
  527. function tunarynode.getcopy : tnode;
  528. var
  529. p : tunarynode;
  530. begin
  531. p:=tunarynode(inherited getcopy);
  532. if assigned(left) then
  533. p.left:=left.getcopy
  534. else
  535. p.left:=nil;
  536. getcopy:=p;
  537. end;
  538. procedure tunarynode.insertintolist(l : tnodelist);
  539. begin
  540. end;
  541. {$ifdef extdebug}
  542. procedure tunarynode.dowrite;
  543. begin
  544. inherited dowrite;
  545. writeln(',');
  546. writenodeindention:=writenodeindention+' ';
  547. writenode(left);
  548. write(')');
  549. delete(writenodeindention,1,4);
  550. end;
  551. {$endif}
  552. procedure tunarynode.left_max;
  553. begin
  554. registers32:=left.registers32;
  555. registersfpu:=left.registersfpu;
  556. {$ifdef SUPPORT_MMX}
  557. registersmmx:=left.registersmmx;
  558. {$endif SUPPORT_MMX}
  559. end;
  560. procedure tunarynode.concattolist(l : tlinkedlist);
  561. begin
  562. left.parent:=self;
  563. left.concattolist(l);
  564. inherited concattolist(l);
  565. end;
  566. function tunarynode.ischild(p : tnode) : boolean;
  567. begin
  568. ischild:=p=left;
  569. end;
  570. {****************************************************************************
  571. TBINARYNODE
  572. ****************************************************************************}
  573. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  574. begin
  575. inherited create(tt,l);
  576. right:=r
  577. end;
  578. destructor tbinarynode.destroy;
  579. begin
  580. right.free;
  581. inherited destroy;
  582. end;
  583. procedure tbinarynode.concattolist(l : tlinkedlist);
  584. begin
  585. { we could change that depending on the number of }
  586. { required registers }
  587. left.parent:=self;
  588. left.concattolist(l);
  589. left.parent:=self;
  590. left.concattolist(l);
  591. inherited concattolist(l);
  592. end;
  593. function tbinarynode.ischild(p : tnode) : boolean;
  594. begin
  595. ischild:=(p=right);
  596. end;
  597. function tbinarynode.docompare(p : tnode) : boolean;
  598. begin
  599. docompare:=(inherited docompare(p) and
  600. ((right=nil) or right.isequal(tbinarynode(p).right))
  601. );
  602. end;
  603. function tbinarynode.getcopy : tnode;
  604. var
  605. p : tbinarynode;
  606. begin
  607. p:=tbinarynode(inherited getcopy);
  608. if assigned(right) then
  609. p.right:=right.getcopy
  610. else
  611. p.right:=nil;
  612. getcopy:=p;
  613. end;
  614. procedure tbinarynode.insertintolist(l : tnodelist);
  615. begin
  616. end;
  617. procedure tbinarynode.swapleftright;
  618. var
  619. swapp : tnode;
  620. begin
  621. swapp:=right;
  622. right:=left;
  623. left:=swapp;
  624. if nf_swaped in flags then
  625. exclude(flags,nf_swaped)
  626. else
  627. include(flags,nf_swaped);
  628. end;
  629. procedure tbinarynode.left_right_max;
  630. begin
  631. if assigned(left) then
  632. begin
  633. if assigned(right) then
  634. begin
  635. registers32:=max(left.registers32,right.registers32);
  636. registersfpu:=max(left.registersfpu,right.registersfpu);
  637. {$ifdef SUPPORT_MMX}
  638. registersmmx:=max(left.registersmmx,right.registersmmx);
  639. {$endif SUPPORT_MMX}
  640. end
  641. else
  642. begin
  643. registers32:=left.registers32;
  644. registersfpu:=left.registersfpu;
  645. {$ifdef SUPPORT_MMX}
  646. registersmmx:=left.registersmmx;
  647. {$endif SUPPORT_MMX}
  648. end;
  649. end;
  650. end;
  651. {$ifdef extdebug}
  652. procedure tbinarynode.dowrite;
  653. begin
  654. inherited dowrite;
  655. writeln(',');
  656. writenodeindention:=writenodeindention+' ';
  657. writenode(right);
  658. write(')');
  659. delete(writenodeindention,1,4);
  660. end;
  661. {$endif}
  662. {****************************************************************************
  663. TBINOPYNODE
  664. ****************************************************************************}
  665. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  666. begin
  667. inherited create(tt,l,r);
  668. end;
  669. function tbinopnode.docompare(p : tnode) : boolean;
  670. begin
  671. docompare:=(inherited docompare(p)) or
  672. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  673. ((nf_swapable in flags) and
  674. left.isequal(tbinopnode(p).right) and
  675. right.isequal(tbinopnode(p).left));
  676. end;
  677. {****************************************************************************
  678. WRITENODE
  679. ****************************************************************************}
  680. {$ifdef EXTDEBUG}
  681. procedure writenode(t:tnode);
  682. begin
  683. if assigned(t) then
  684. t.dowrite
  685. else
  686. write(writenodeindention,'nil');
  687. if writenodeindention='' then
  688. writeln;
  689. end;
  690. {$endif EXTDEBUG}
  691. end.
  692. {
  693. $Log$
  694. Revision 1.34 2002-08-09 19:15:41 carl
  695. - removed newcg define
  696. Revision 1.33 2002/07/23 12:34:30 daniel
  697. * Readded old set code. To use it define 'oldset'. Activated by default
  698. for ppc.
  699. Revision 1.32 2002/07/22 11:48:04 daniel
  700. * Sets are now internally sets.
  701. Revision 1.31 2002/07/21 06:58:49 daniel
  702. * Changed booleans into flags
  703. Revision 1.30 2002/07/19 11:41:36 daniel
  704. * State tracker work
  705. * The whilen and repeatn are now completely unified into whilerepeatn. This
  706. allows the state tracker to change while nodes automatically into
  707. repeat nodes.
  708. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  709. 'not(a>b)' is optimized into 'a<=b'.
  710. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  711. by removing the notn and later switchting the true and falselabels. The
  712. same is done with 'repeat until not a'.
  713. Revision 1.29 2002/07/14 18:00:44 daniel
  714. + Added the beginning of a state tracker. This will track the values of
  715. variables through procedures and optimize things away.
  716. Revision 1.28 2002/07/01 18:46:24 peter
  717. * internal linker
  718. * reorganized aasm layer
  719. Revision 1.27 2002/05/18 13:34:10 peter
  720. * readded missing revisions
  721. Revision 1.26 2002/05/16 19:46:39 carl
  722. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  723. + try to fix temp allocation (still in ifdef)
  724. + generic constructor calls
  725. + start of tassembler / tmodulebase class cleanup
  726. Revision 1.24 2002/04/21 19:02:04 peter
  727. * removed newn and disposen nodes, the code is now directly
  728. inlined from pexpr
  729. * -an option that will write the secondpass nodes to the .s file, this
  730. requires EXTDEBUG define to actually write the info
  731. * fixed various internal errors and crashes due recent code changes
  732. Revision 1.23 2002/04/06 18:13:01 jonas
  733. * several powerpc-related additions and fixes
  734. Revision 1.22 2002/03/31 20:26:35 jonas
  735. + a_loadfpu_* and a_loadmm_* methods in tcg
  736. * register allocation is now handled by a class and is mostly processor
  737. independent (+rgobj.pas and i386/rgcpu.pas)
  738. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  739. * some small improvements and fixes to the optimizer
  740. * some register allocation fixes
  741. * some fpuvaroffset fixes in the unary minus node
  742. * push/popusedregisters is now called rg.save/restoreusedregisters and
  743. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  744. also better optimizable)
  745. * fixed and optimized register saving/restoring for new/dispose nodes
  746. * LOC_FPU locations now also require their "register" field to be set to
  747. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  748. - list field removed of the tnode class because it's not used currently
  749. and can cause hard-to-find bugs
  750. Revision 1.21 2002/01/19 11:52:32 peter
  751. * dynarr:=nil support added
  752. }