node.pas 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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,symppu;
  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. emptynode, {No node (returns nil when loading from ppu)}
  38. addn, {Represents the + operator}
  39. muln, {Represents the * operator}
  40. subn, {Represents the - operator}
  41. divn, {Represents the div operator}
  42. symdifn, {Represents the >< operator}
  43. modn, {Represents the mod operator}
  44. assignn, {Represents an assignment}
  45. loadn, {Represents the use of a variabele}
  46. rangen, {Represents a range (i.e. 0..9)}
  47. ltn, {Represents the < operator}
  48. lten, {Represents the <= operator}
  49. gtn, {Represents the > operator}
  50. gten, {Represents the >= operator}
  51. equaln, {Represents the = operator}
  52. unequaln, {Represents the <> operator}
  53. inn, {Represents the in operator}
  54. orn, {Represents the or operator}
  55. xorn, {Represents the xor operator}
  56. shrn, {Represents the shr operator}
  57. shln, {Represents the shl operator}
  58. slashn, {Represents the / operator}
  59. andn, {Represents the and operator}
  60. subscriptn, {Field in a record/object}
  61. derefn, {Dereferences a pointer}
  62. addrn, {Represents the @ operator}
  63. doubleaddrn, {Represents the @@ operator}
  64. ordconstn, {Represents an ordinal value}
  65. typeconvn, {Represents type-conversion/typecast}
  66. calln, {Represents a call node}
  67. callparan, {Represents a parameter}
  68. realconstn, {Represents a real value}
  69. unaryminusn, {Represents a sign change (i.e. -2)}
  70. asmn, {Represents an assembler node }
  71. vecn, {Represents array indexing}
  72. pointerconstn, {Represents a pointer constant}
  73. stringconstn, {Represents a string constant}
  74. funcretn, {Represents the function result var}
  75. selfn, {Represents the self parameter}
  76. notn, {Represents the not operator}
  77. inlinen, {Internal procedures (i.e. writeln)}
  78. niln, {Represents the nil pointer}
  79. errorn, {This part of the tree could not be
  80. parsed because of a compiler error}
  81. typen, {A type name. Used for i.e. typeof(obj)}
  82. hnewn, {The new operation, constructor call}
  83. hdisposen, {The dispose operation with destructor call}
  84. setelementn, {A set element(s) (i.e. [a,b] and also [a..b])}
  85. setconstn, {A set constant (i.e. [1,2])}
  86. blockn, {A block of statements}
  87. statementn, {One statement in a block of nodes}
  88. ifn, {An if statement}
  89. breakn, {A break statement}
  90. continuen, {A continue statement}
  91. whilerepeatn, {A while or repeat statement}
  92. forn, {A for loop}
  93. exitn, {An exit statement}
  94. withn, {A with statement}
  95. casen, {A case statement}
  96. labeln, {A label}
  97. goton, {A goto statement}
  98. tryexceptn, {A try except block}
  99. raisen, {A raise statement}
  100. tryfinallyn, {A try finally statement}
  101. onn, {For an on statement in exception code}
  102. isn, {Represents the is operator}
  103. asn, {Represents the as typecast}
  104. caretn, {Represents the ^ operator}
  105. failn, {Represents the fail statement}
  106. starstarn, {Represents the ** operator exponentiation }
  107. procinlinen, {Procedures that can be inlined }
  108. arrayconstructorn, {Construction node for [...] parsing}
  109. arrayconstructorrangen, {Range element to allow sets in array construction tree}
  110. tempcreaten, { for temps in the result/firstpass }
  111. temprefn, { references to temps }
  112. tempdeleten, { for temps in the result/firstpass }
  113. addoptn, { added for optimizations where we cannot suppress }
  114. nothingn, {NOP, Do nothing}
  115. loadvmtn, {Load the address of the VMT of a class/object}
  116. guidconstn, {A GUID COM Interface constant }
  117. rttin {Rtti information so they can be accessed in result/firstpass}
  118. );
  119. const
  120. nodetype2str : array[tnodetype] of string[20] = (
  121. '<emptynode>',
  122. 'addn',
  123. 'muln',
  124. 'subn',
  125. 'divn',
  126. 'symdifn',
  127. 'modn',
  128. 'assignn',
  129. 'loadn',
  130. 'rangen',
  131. 'ltn',
  132. 'lten',
  133. 'gtn',
  134. 'gten',
  135. 'equaln',
  136. 'unequaln',
  137. 'inn',
  138. 'orn',
  139. 'xorn',
  140. 'shrn',
  141. 'shln',
  142. 'slashn',
  143. 'andn',
  144. 'subscriptn',
  145. 'derefn',
  146. 'addrn',
  147. 'doubleaddrn',
  148. 'ordconstn',
  149. 'typeconvn',
  150. 'calln',
  151. 'callparan',
  152. 'realconstn',
  153. 'unaryminusn',
  154. 'asmn',
  155. 'vecn',
  156. 'pointerconstn',
  157. 'stringconstn',
  158. 'funcretn',
  159. 'selfn',
  160. 'notn',
  161. 'inlinen',
  162. 'niln',
  163. 'errorn',
  164. 'typen',
  165. 'hnewn',
  166. 'hdisposen',
  167. 'setelementn',
  168. 'setconstn',
  169. 'blockn',
  170. 'statementn',
  171. 'ifn',
  172. 'breakn',
  173. 'continuen',
  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. 'tempcreaten',
  194. 'temprefn',
  195. 'tempdeleten',
  196. 'addoptn',
  197. 'nothingn',
  198. 'loadvmtn',
  199. 'guidconstn',
  200. 'rttin');
  201. type
  202. { all boolean field of ttree are now collected in flags }
  203. tnodeflags = (
  204. nf_needs_truefalselabel,
  205. nf_swapable, { tbinop operands can be swaped }
  206. nf_swaped, { tbinop operands are swaped }
  207. nf_error,
  208. nf_write, { Node is written to }
  209. { flags used by tcallnode }
  210. nf_return_value_used,
  211. nf_static_call,
  212. nf_anon_inherited,
  213. { flags used by tcallparanode }
  214. nf_varargs_para, { belongs this para to varargs }
  215. nf_hightree_generated, { has the hightree for thispara been generated }
  216. { taddrnode }
  217. nf_procvarload,
  218. { tvecnode }
  219. nf_memindex,
  220. nf_memseg,
  221. nf_callunique,
  222. { twithnode }
  223. nf_islocal,
  224. { tloadnode }
  225. nf_absolute,
  226. nf_first,
  227. { tassignmentnode }
  228. nf_concat_string,
  229. { tfuncretnode }
  230. nf_is_first_funcret,
  231. { tarrayconstructnode }
  232. nf_cargs, { 20th }
  233. nf_cargswap,
  234. nf_forcevaria,
  235. nf_novariaallowed,
  236. { ttypeconvnode }
  237. nf_explizit,
  238. { tinlinenode }
  239. nf_inlineconst,
  240. { general }
  241. nf_isproperty,
  242. nf_varstateset,
  243. { taddnode }
  244. nf_use_strconcat
  245. );
  246. tnodeflagset = set of tnodeflags;
  247. const
  248. { contains the flags which must be equal for the equality }
  249. { of nodes }
  250. flagsequal : tnodeflagset = [nf_error,nf_static_call];
  251. type
  252. tnodelist = class
  253. end;
  254. { later (for the newcg) tnode will inherit from tlinkedlist_item }
  255. tnode = class
  256. public
  257. { type of this node }
  258. nodetype : tnodetype;
  259. { type of the current code block, general/const/type }
  260. blocktype : tblock_type;
  261. { the location of the result of this node }
  262. location : tlocation;
  263. { the parent node of this is node }
  264. { this field is set by concattolist }
  265. parent : tnode;
  266. { there are some properties about the node stored }
  267. flags : tnodeflagset;
  268. { the number of registers needed to evalute the node }
  269. registers32,registersfpu : longint; { must be longint !!!! }
  270. {$ifdef SUPPORT_MMX}
  271. registersmmx,registerskni : longint;
  272. {$endif SUPPORT_MMX}
  273. resulttype : ttype;
  274. fileinfo : tfileposinfo;
  275. localswitches : tlocalswitches;
  276. {$ifdef extdebug}
  277. maxfirstpasscount,
  278. firstpasscount : longint;
  279. {$endif extdebug}
  280. constructor create(t:tnodetype);
  281. { this constructor is only for creating copies of class }
  282. { the fields are copied by getcopy }
  283. constructor createforcopy;
  284. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);virtual;
  285. destructor destroy;override;
  286. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  287. procedure derefimpl;virtual;
  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. function track_state_pass(exec_known:boolean):boolean;virtual;
  303. {$endif}
  304. { For a t1:=t2 tree, mark the part of the tree t1 that gets
  305. written to (normally the loadnode) as write access. }
  306. procedure mark_write;virtual;abstract;
  307. procedure det_temp;virtual;abstract;
  308. procedure pass_2;virtual;abstract;
  309. { comparing of nodes }
  310. function isequal(p : tnode) : boolean;
  311. { to implement comparisation, override this method }
  312. function docompare(p : tnode) : boolean;virtual;
  313. { gets a copy of the node }
  314. function getcopy : tnode;virtual;
  315. procedure insertintolist(l : tnodelist);virtual;
  316. {$ifdef EXTDEBUG}
  317. { writes a node for debugging purpose, shouldn't be called }
  318. { direct, because there is no test for nil, use writenode }
  319. { to write a complete tree }
  320. procedure dowrite;
  321. procedure dowritenodetype;virtual;
  322. procedure _dowrite;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. tnodeclass = class of tnode;
  330. tnodeclassarray = array[tnodetype] of tnodeclass;
  331. { this node is the anchestor for all nodes with at least }
  332. { one child, you have to use it if you want to use }
  333. { true- and falselabel }
  334. punarynode = ^tunarynode;
  335. tunarynode = class(tnode)
  336. left : tnode;
  337. constructor create(t:tnodetype;l : tnode);
  338. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  339. destructor destroy;override;
  340. procedure ppuwrite(ppufile:tcompilerppufile);override;
  341. procedure derefimpl;override;
  342. procedure concattolist(l : tlinkedlist);override;
  343. function ischild(p : tnode) : boolean;override;
  344. function docompare(p : tnode) : boolean;override;
  345. function getcopy : tnode;override;
  346. procedure insertintolist(l : tnodelist);override;
  347. procedure left_max;
  348. {$ifdef extdebug}
  349. procedure _dowrite;override;
  350. {$endif extdebug}
  351. end;
  352. pbinarynode = ^tbinarynode;
  353. tbinarynode = class(tunarynode)
  354. right : tnode;
  355. constructor create(t:tnodetype;l,r : tnode);
  356. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  357. destructor destroy;override;
  358. procedure ppuwrite(ppufile:tcompilerppufile);override;
  359. procedure derefimpl;override;
  360. procedure concattolist(l : tlinkedlist);override;
  361. function ischild(p : tnode) : boolean;override;
  362. function docompare(p : tnode) : boolean;override;
  363. procedure swapleftright;
  364. function getcopy : tnode;override;
  365. procedure insertintolist(l : tnodelist);override;
  366. procedure left_right_max;
  367. {$ifdef extdebug}
  368. procedure _dowrite;override;
  369. {$endif extdebug}
  370. end;
  371. tbinopnode = class(tbinarynode)
  372. constructor create(t:tnodetype;l,r : tnode);virtual;
  373. function docompare(p : tnode) : boolean;override;
  374. end;
  375. {$ifdef tempregdebug}
  376. type
  377. pptree = ^tnode;
  378. var
  379. curptree: pptree;
  380. {$endif tempregdebug}
  381. var
  382. { array with all class types for tnodes }
  383. nodeclass : tnodeclassarray;
  384. {$ifdef EXTDEBUG}
  385. { indention used when writing the tree to the screen }
  386. writenodeindention : string;
  387. {$endif EXTDEBUG}
  388. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  389. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  390. {$ifdef EXTDEBUG}
  391. procedure writenode(t:tnode);
  392. {$endif EXTDEBUG}
  393. implementation
  394. uses
  395. cutils,verbose;
  396. const
  397. ppunodemarker = 255;
  398. {****************************************************************************
  399. Helpers
  400. ****************************************************************************}
  401. function ppuloadnode(ppufile:tcompilerppufile):tnode;
  402. var
  403. b : byte;
  404. t : tnodetype;
  405. begin
  406. { marker }
  407. b:=ppufile.getbyte;
  408. if b<>ppunodemarker then
  409. internalerror(200208151);
  410. { load nodetype }
  411. t:=tnodetype(ppufile.getbyte);
  412. if t>high(tnodetype) then
  413. internalerror(200208152);
  414. if t<>emptynode then
  415. begin
  416. if not assigned(nodeclass[t]) then
  417. internalerror(200208153);
  418. //writeln('load: ',nodetype2str[t]);
  419. { generate node of the correct class }
  420. ppuloadnode:=nodeclass[t].ppuload(t,ppufile);
  421. end
  422. else
  423. ppuloadnode:=nil;
  424. end;
  425. procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
  426. begin
  427. { marker, read by ppuloadnode }
  428. ppufile.putbyte(ppunodemarker);
  429. { type, read by ppuloadnode }
  430. if assigned(n) then
  431. begin
  432. ppufile.putbyte(byte(n.nodetype));
  433. //writeln('write: ',nodetype2str[n.nodetype]);
  434. n.ppuwrite(ppufile);
  435. end
  436. else
  437. ppufile.putbyte(byte(emptynode));
  438. end;
  439. {$ifdef EXTDEBUG}
  440. procedure writenode(t:tnode);
  441. begin
  442. if assigned(t) then
  443. t.dowrite
  444. else
  445. write(writenodeindention,'nil');
  446. if writenodeindention='' then
  447. writeln;
  448. end;
  449. {$endif EXTDEBUG}
  450. {****************************************************************************
  451. TNODE
  452. ****************************************************************************}
  453. constructor tnode.create(t:tnodetype);
  454. begin
  455. inherited create;
  456. nodetype:=t;
  457. blocktype:=block_type;
  458. { this allows easier error tracing }
  459. location.loc:=LOC_INVALID;
  460. { save local info }
  461. fileinfo:=aktfilepos;
  462. localswitches:=aktlocalswitches;
  463. resulttype.reset;
  464. registers32:=0;
  465. registersfpu:=0;
  466. {$ifdef SUPPORT_MMX}
  467. registersmmx:=0;
  468. {$endif SUPPORT_MMX}
  469. {$ifdef EXTDEBUG}
  470. maxfirstpasscount:=0;
  471. firstpasscount:=0;
  472. {$endif EXTDEBUG}
  473. flags:=[];
  474. end;
  475. constructor tnode.createforcopy;
  476. begin
  477. end;
  478. constructor tnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  479. begin
  480. nodetype:=t;
  481. { tnode fields }
  482. blocktype:=tblock_type(ppufile.getbyte);
  483. ppufile.getposinfo(fileinfo);
  484. ppufile.getsmallset(localswitches);
  485. ppufile.gettype(resulttype);
  486. ppufile.getsmallset(flags);
  487. { updated by firstpass }
  488. location.loc:=LOC_INVALID;
  489. registers32:=0;
  490. registersfpu:=0;
  491. {$ifdef SUPPORT_MMX}
  492. registersmmx:=0;
  493. {$endif SUPPORT_MMX}
  494. {$ifdef EXTDEBUG}
  495. maxfirstpasscount:=0;
  496. firstpasscount:=0;
  497. {$endif EXTDEBUG}
  498. end;
  499. procedure tnode.ppuwrite(ppufile:tcompilerppufile);
  500. begin
  501. ppufile.putbyte(byte(block_type));
  502. ppufile.putposinfo(fileinfo);
  503. ppufile.putsmallset(localswitches);
  504. ppufile.puttype(resulttype);
  505. ppufile.putsmallset(flags);
  506. end;
  507. procedure tnode.derefimpl;
  508. begin
  509. resulttype.resolve;
  510. end;
  511. procedure tnode.toggleflag(f : tnodeflags);
  512. begin
  513. if f in flags then
  514. exclude(flags,f)
  515. else
  516. include(flags,f);
  517. end;
  518. destructor tnode.destroy;
  519. begin
  520. {$ifdef EXTDEBUG}
  521. if firstpasscount>maxfirstpasscount then
  522. maxfirstpasscount:=firstpasscount;
  523. {$endif EXTDEBUG}
  524. end;
  525. procedure tnode.concattolist(l : tlinkedlist);
  526. begin
  527. end;
  528. function tnode.ischild(p : tnode) : boolean;
  529. begin
  530. ischild:=false;
  531. end;
  532. {$ifdef EXTDEBUG}
  533. procedure tnode._dowrite;
  534. begin
  535. dowritenodetype;
  536. if assigned(resulttype.def) then
  537. write(',resulttype = "',resulttype.def.gettypename,'"')
  538. else
  539. write(',resulttype = <nil>');
  540. write(',location.loc = ',ord(location.loc));
  541. write(',registersint = ',registers32);
  542. write(',registersfpu = ',registersfpu);
  543. end;
  544. procedure tnode.dowritenodetype;
  545. begin
  546. write(nodetype2str[nodetype]);
  547. end;
  548. procedure tnode.dowrite;
  549. begin
  550. write(writenodeindention,'(');
  551. writenodeindention:=writenodeindention+' ';
  552. _dowrite;
  553. writeln;
  554. delete(writenodeindention,1,4);
  555. write(writenodeindention,')');
  556. end;
  557. {$endif EXTDEBUG}
  558. function tnode.isequal(p : tnode) : boolean;
  559. begin
  560. isequal:=
  561. (not assigned(self) and not assigned(p)) or
  562. (assigned(self) and assigned(p) and
  563. { optimized subclasses have the same nodetype as their }
  564. { superclass (for compatibility), so also check the classtype (JM) }
  565. (p.classtype=classtype) and
  566. (p.nodetype=nodetype) and
  567. (flags*flagsequal=p.flags*flagsequal) and
  568. docompare(p));
  569. end;
  570. {$ifdef state_tracking}
  571. function Tnode.track_state_pass(exec_known:boolean):boolean;
  572. begin
  573. track_state_pass:=false;
  574. end;
  575. {$endif state_tracking}
  576. function tnode.docompare(p : tnode) : boolean;
  577. begin
  578. docompare:=true;
  579. end;
  580. function tnode.getcopy : tnode;
  581. var
  582. p : tnode;
  583. begin
  584. { this is quite tricky because we need a node of the current }
  585. { node type and not one of tnode! }
  586. p:=tnodeclass(classtype).createforcopy;
  587. p.nodetype:=nodetype;
  588. p.location:=location;
  589. p.parent:=parent;
  590. p.flags:=flags;
  591. p.registers32:=registers32;
  592. p.registersfpu:=registersfpu;
  593. {$ifdef SUPPORT_MMX}
  594. p.registersmmx:=registersmmx;
  595. p.registerskni:=registerskni;
  596. {$endif SUPPORT_MMX}
  597. p.resulttype:=resulttype;
  598. p.fileinfo:=fileinfo;
  599. p.localswitches:=localswitches;
  600. {$ifdef extdebug}
  601. p.firstpasscount:=firstpasscount;
  602. {$endif extdebug}
  603. { p.list:=list; }
  604. getcopy:=p;
  605. end;
  606. { procedure tnode.mark_write;
  607. begin
  608. end;}
  609. procedure tnode.insertintolist(l : tnodelist);
  610. begin
  611. end;
  612. procedure tnode.set_file_line(from : tnode);
  613. begin
  614. if assigned(from) then
  615. fileinfo:=from.fileinfo;
  616. end;
  617. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  618. begin
  619. fileinfo:=filepos;
  620. end;
  621. {****************************************************************************
  622. TUNARYNODE
  623. ****************************************************************************}
  624. constructor tunarynode.create(t:tnodetype;l : tnode);
  625. begin
  626. inherited create(t);
  627. left:=l;
  628. end;
  629. constructor tunarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  630. begin
  631. inherited ppuload(t,ppufile);
  632. left:=ppuloadnode(ppufile);
  633. end;
  634. destructor tunarynode.destroy;
  635. begin
  636. left.free;
  637. inherited destroy;
  638. end;
  639. procedure tunarynode.ppuwrite(ppufile:tcompilerppufile);
  640. begin
  641. inherited ppuwrite(ppufile);
  642. ppuwritenode(ppufile,left);
  643. end;
  644. procedure tunarynode.derefimpl;
  645. begin
  646. inherited derefimpl;
  647. if assigned(left) then
  648. left.derefimpl;
  649. end;
  650. function tunarynode.docompare(p : tnode) : boolean;
  651. begin
  652. docompare:=(inherited docompare(p) and
  653. ((left=nil) or left.isequal(tunarynode(p).left))
  654. );
  655. end;
  656. function tunarynode.getcopy : tnode;
  657. var
  658. p : tunarynode;
  659. begin
  660. p:=tunarynode(inherited getcopy);
  661. if assigned(left) then
  662. p.left:=left.getcopy
  663. else
  664. p.left:=nil;
  665. getcopy:=p;
  666. end;
  667. procedure tunarynode.insertintolist(l : tnodelist);
  668. begin
  669. end;
  670. {$ifdef extdebug}
  671. procedure tunarynode._dowrite;
  672. begin
  673. inherited _dowrite;
  674. writeln(',');
  675. writenode(left);
  676. end;
  677. {$endif}
  678. procedure tunarynode.left_max;
  679. begin
  680. registers32:=left.registers32;
  681. registersfpu:=left.registersfpu;
  682. {$ifdef SUPPORT_MMX}
  683. registersmmx:=left.registersmmx;
  684. {$endif SUPPORT_MMX}
  685. end;
  686. procedure tunarynode.concattolist(l : tlinkedlist);
  687. begin
  688. left.parent:=self;
  689. left.concattolist(l);
  690. inherited concattolist(l);
  691. end;
  692. function tunarynode.ischild(p : tnode) : boolean;
  693. begin
  694. ischild:=p=left;
  695. end;
  696. {****************************************************************************
  697. TBINARYNODE
  698. ****************************************************************************}
  699. constructor tbinarynode.create(t:tnodetype;l,r : tnode);
  700. begin
  701. inherited create(t,l);
  702. right:=r
  703. end;
  704. constructor tbinarynode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  705. begin
  706. inherited ppuload(t,ppufile);
  707. right:=ppuloadnode(ppufile);
  708. end;
  709. destructor tbinarynode.destroy;
  710. begin
  711. right.free;
  712. inherited destroy;
  713. end;
  714. procedure tbinarynode.ppuwrite(ppufile:tcompilerppufile);
  715. begin
  716. inherited ppuwrite(ppufile);
  717. ppuwritenode(ppufile,right);
  718. end;
  719. procedure tbinarynode.derefimpl;
  720. begin
  721. inherited derefimpl;
  722. if assigned(right) then
  723. right.derefimpl;
  724. end;
  725. procedure tbinarynode.concattolist(l : tlinkedlist);
  726. begin
  727. { we could change that depending on the number of }
  728. { required registers }
  729. left.parent:=self;
  730. left.concattolist(l);
  731. left.parent:=self;
  732. left.concattolist(l);
  733. inherited concattolist(l);
  734. end;
  735. function tbinarynode.ischild(p : tnode) : boolean;
  736. begin
  737. ischild:=(p=right);
  738. end;
  739. function tbinarynode.docompare(p : tnode) : boolean;
  740. begin
  741. docompare:=(inherited docompare(p) and
  742. ((right=nil) or right.isequal(tbinarynode(p).right))
  743. );
  744. end;
  745. function tbinarynode.getcopy : tnode;
  746. var
  747. p : tbinarynode;
  748. begin
  749. p:=tbinarynode(inherited getcopy);
  750. if assigned(right) then
  751. p.right:=right.getcopy
  752. else
  753. p.right:=nil;
  754. getcopy:=p;
  755. end;
  756. procedure tbinarynode.insertintolist(l : tnodelist);
  757. begin
  758. end;
  759. procedure tbinarynode.swapleftright;
  760. var
  761. swapp : tnode;
  762. begin
  763. swapp:=right;
  764. right:=left;
  765. left:=swapp;
  766. if nf_swaped in flags then
  767. exclude(flags,nf_swaped)
  768. else
  769. include(flags,nf_swaped);
  770. end;
  771. procedure tbinarynode.left_right_max;
  772. begin
  773. if assigned(left) then
  774. begin
  775. if assigned(right) then
  776. begin
  777. registers32:=max(left.registers32,right.registers32);
  778. registersfpu:=max(left.registersfpu,right.registersfpu);
  779. {$ifdef SUPPORT_MMX}
  780. registersmmx:=max(left.registersmmx,right.registersmmx);
  781. {$endif SUPPORT_MMX}
  782. end
  783. else
  784. begin
  785. registers32:=left.registers32;
  786. registersfpu:=left.registersfpu;
  787. {$ifdef SUPPORT_MMX}
  788. registersmmx:=left.registersmmx;
  789. {$endif SUPPORT_MMX}
  790. end;
  791. end;
  792. end;
  793. {$ifdef extdebug}
  794. procedure tbinarynode._dowrite;
  795. begin
  796. inherited _dowrite;
  797. writeln(',');
  798. writenode(right);
  799. end;
  800. {$endif}
  801. {****************************************************************************
  802. TBINOPYNODE
  803. ****************************************************************************}
  804. constructor tbinopnode.create(t:tnodetype;l,r : tnode);
  805. begin
  806. inherited create(t,l,r);
  807. end;
  808. function tbinopnode.docompare(p : tnode) : boolean;
  809. begin
  810. docompare:=(inherited docompare(p)) or
  811. { if that's in the flags, is p then always a tbinopnode (?) (JM) }
  812. ((nf_swapable in flags) and
  813. left.isequal(tbinopnode(p).right) and
  814. right.isequal(tbinopnode(p).left));
  815. end;
  816. end.
  817. {
  818. $Log$
  819. Revision 1.51 2003-03-28 19:16:56 peter
  820. * generic constructor working for i386
  821. * remove fixed self register
  822. * esi added as address register for i386
  823. Revision 1.50 2003/03/17 16:54:41 peter
  824. * support DefaultHandler and anonymous inheritance fixed
  825. for message methods
  826. Revision 1.49 2003/01/04 15:54:03 daniel
  827. * Fixed mark_write for @ operator
  828. (can happen when compiling @procvar:=nil (Delphi mode construction))
  829. Revision 1.48 2003/01/03 21:03:02 peter
  830. * made mark_write dummy instead of abstract
  831. Revision 1.47 2003/01/03 12:15:56 daniel
  832. * Removed ifdefs around notifications
  833. ifdefs around for loop optimizations remain
  834. Revision 1.46 2002/12/26 18:24:33 jonas
  835. * fixed check for whether or not a high parameter was already generated
  836. * no type checking/conversions for invisible parameters
  837. Revision 1.45 2002/11/28 11:17:04 florian
  838. * loop node flags from node flags splitted
  839. Revision 1.44 2002/10/05 00:48:57 peter
  840. * support inherited; support for overload as it is handled by
  841. delphi. This is only for delphi mode as it is working is
  842. undocumented and hard to predict what is done
  843. Revision 1.43 2002/09/07 15:25:03 peter
  844. * old logs removed and tabs fixed
  845. Revision 1.42 2002/09/03 16:26:26 daniel
  846. * Make Tprocdef.defs protected
  847. Revision 1.41 2002/09/01 13:28:38 daniel
  848. - write_access fields removed in favor of a flag
  849. Revision 1.40 2002/09/01 08:01:16 daniel
  850. * Removed sets from Tcallnode.det_resulttype
  851. + Added read/write notifications of variables. These will be usefull
  852. for providing information for several optimizations. For example
  853. the value of the loop variable of a for loop does matter is the
  854. variable is read after the for loop, but if it's no longer used
  855. or written, it doesn't matter and this can be used to optimize
  856. the loop code generation.
  857. Revision 1.39 2002/08/22 11:21:45 florian
  858. + register32 is now written by tnode.dowrite
  859. * fixed write of value of tconstnode
  860. Revision 1.38 2002/08/19 19:36:44 peter
  861. * More fixes for cross unit inlining, all tnodes are now implemented
  862. * Moved pocall_internconst to po_internconst because it is not a
  863. calling type at all and it conflicted when inlining of these small
  864. functions was requested
  865. Revision 1.37 2002/08/18 20:06:24 peter
  866. * inlining is now also allowed in interface
  867. * renamed write/load to ppuwrite/ppuload
  868. * tnode storing in ppu
  869. * nld,ncon,nbas are already updated for storing in ppu
  870. Revision 1.36 2002/08/17 22:09:46 florian
  871. * result type handling in tcgcal.pass_2 overhauled
  872. * better tnode.dowrite
  873. * some ppc stuff fixed
  874. Revision 1.35 2002/08/15 19:10:35 peter
  875. * first things tai,tnode storing in ppu
  876. Revision 1.34 2002/08/09 19:15:41 carl
  877. - removed newcg define
  878. Revision 1.33 2002/07/23 12:34:30 daniel
  879. * Readded old set code. To use it define 'oldset'. Activated by default
  880. for ppc.
  881. Revision 1.32 2002/07/22 11:48:04 daniel
  882. * Sets are now internally sets.
  883. Revision 1.31 2002/07/21 06:58:49 daniel
  884. * Changed booleans into flags
  885. Revision 1.30 2002/07/19 11:41:36 daniel
  886. * State tracker work
  887. * The whilen and repeatn are now completely unified into whilerepeatn. This
  888. allows the state tracker to change while nodes automatically into
  889. repeat nodes.
  890. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  891. 'not(a>b)' is optimized into 'a<=b'.
  892. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  893. by removing the notn and later switchting the true and falselabels. The
  894. same is done with 'repeat until not a'.
  895. Revision 1.29 2002/07/14 18:00:44 daniel
  896. + Added the beginning of a state tracker. This will track the values of
  897. variables through procedures and optimize things away.
  898. Revision 1.28 2002/07/01 18:46:24 peter
  899. * internal linker
  900. * reorganized aasm layer
  901. Revision 1.27 2002/05/18 13:34:10 peter
  902. * readded missing revisions
  903. Revision 1.26 2002/05/16 19:46:39 carl
  904. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  905. + try to fix temp allocation (still in ifdef)
  906. + generic constructor calls
  907. + start of tassembler / tmodulebase class cleanup
  908. Revision 1.24 2002/04/21 19:02:04 peter
  909. * removed newn and disposen nodes, the code is now directly
  910. inlined from pexpr
  911. * -an option that will write the secondpass nodes to the .s file, this
  912. requires EXTDEBUG define to actually write the info
  913. * fixed various internal errors and crashes due recent code changes
  914. Revision 1.23 2002/04/06 18:13:01 jonas
  915. * several powerpc-related additions and fixes
  916. Revision 1.22 2002/03/31 20:26:35 jonas
  917. + a_loadfpu_* and a_loadmm_* methods in tcg
  918. * register allocation is now handled by a class and is mostly processor
  919. independent (+rgobj.pas and i386/rgcpu.pas)
  920. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  921. * some small improvements and fixes to the optimizer
  922. * some register allocation fixes
  923. * some fpuvaroffset fixes in the unary minus node
  924. * push/popusedregisters is now called rg.save/restoreusedregisters and
  925. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  926. also better optimizable)
  927. * fixed and optimized register saving/restoring for new/dispose nodes
  928. * LOC_FPU locations now also require their "register" field to be set to
  929. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  930. - list field removed of the tnode class because it's not used currently
  931. and can cause hard-to-find bugs
  932. }