node.pas 25 KB

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