nbas.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. This unit implements some basic nodes
  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 nbas;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. aasmbase,aasmtai,aasmcpu,
  24. node,
  25. symtype,symppu;
  26. type
  27. tnothingnode = class(tnode)
  28. constructor create;virtual;
  29. function pass_1 : tnode;override;
  30. function det_resulttype:tnode;override;
  31. end;
  32. tnothingnodeclass = class of tnothingnode;
  33. terrornode = class(tnode)
  34. constructor create;virtual;
  35. function pass_1 : tnode;override;
  36. function det_resulttype:tnode;override;
  37. procedure mark_write;override;
  38. end;
  39. terrornodeclass = class of terrornode;
  40. tasmnode = class(tnode)
  41. p_asm : taasmoutput;
  42. constructor create(p : taasmoutput);virtual;
  43. destructor destroy;override;
  44. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  45. procedure ppuwrite(ppufile:tcompilerppufile);override;
  46. procedure derefimpl;override;
  47. function getcopy : tnode;override;
  48. function pass_1 : tnode;override;
  49. function det_resulttype:tnode;override;
  50. function docompare(p: tnode): boolean; override;
  51. end;
  52. tasmnodeclass = class of tasmnode;
  53. tstatementnode = class(tbinarynode)
  54. constructor create(l,r : tnode);virtual;
  55. function pass_1 : tnode;override;
  56. function det_resulttype:tnode;override;
  57. procedure printnodetree(var t:text);override;
  58. end;
  59. tstatementnodeclass = class of tstatementnode;
  60. tblocknode = class(tunarynode)
  61. constructor create(l : tnode;releasetemp : boolean);virtual;
  62. function pass_1 : tnode;override;
  63. function det_resulttype:tnode;override;
  64. {$ifdef state_tracking}
  65. function track_state_pass(exec_known:boolean):boolean;override;
  66. {$endif state_tracking}
  67. end;
  68. tblocknodeclass = class of tblocknode;
  69. { to allow access to the location by temp references even after the temp has }
  70. { already been disposed and to make sure the coherency between temps and }
  71. { temp references is kept after a getcopy }
  72. ptempinfo = ^ttempinfo;
  73. ttempinfo = record
  74. { set to the copy of a tempcreate pnode (if it gets copied) so that the }
  75. { refs and deletenode can hook to this copy once they get copied too }
  76. hookoncopy : ptempinfo;
  77. ref : treference;
  78. restype : ttype;
  79. valid : boolean;
  80. nextref_set_hookoncopy_nil : boolean;
  81. end;
  82. { a node which will create a (non)persistent temp of a given type with a given }
  83. { size (the size is separate to allow creating "void" temps with a custom size) }
  84. ttempcreatenode = class(tnode)
  85. size: longint;
  86. tempinfo: ptempinfo;
  87. persistent: boolean;
  88. { * persistent temps are used in manually written code where the temp }
  89. { be usable among different statements and where you can manually say }
  90. { when the temp has to be freed (using a ttempdeletenode) }
  91. { * non-persistent temps are mostly used in typeconversion helpers, }
  92. { where the node that receives the temp becomes responsible for }
  93. { freeing it. In this last case, you should use only one reference }
  94. { to it and *not* generate a ttempdeletenode }
  95. constructor create(const _restype: ttype; _size: longint; _persistent: boolean); virtual;
  96. function getcopy: tnode; override;
  97. function pass_1 : tnode; override;
  98. function det_resulttype: tnode; override;
  99. function docompare(p: tnode): boolean; override;
  100. procedure printnodedata(var t:text);override;
  101. end;
  102. ttempcreatenodeclass = class of ttempcreatenode;
  103. { a node which is a reference to a certain temp }
  104. ttemprefnode = class(tnode)
  105. constructor create(const temp: ttempcreatenode); virtual;
  106. constructor create_offset(const temp: ttempcreatenode;aoffset:longint);
  107. function getcopy: tnode; override;
  108. function pass_1 : tnode; override;
  109. function det_resulttype : tnode; override;
  110. procedure mark_write;override;
  111. function docompare(p: tnode): boolean; override;
  112. protected
  113. tempinfo: ptempinfo;
  114. offset : longint;
  115. end;
  116. ttemprefnodeclass = class of ttemprefnode;
  117. { a node which removes a temp }
  118. ttempdeletenode = class(tnode)
  119. constructor create(const temp: ttempcreatenode);
  120. { this will convert the persistant temp to a normal temp
  121. for returning to the other nodes }
  122. constructor create_normal_temp(const temp: ttempcreatenode);
  123. function getcopy: tnode; override;
  124. function pass_1: tnode; override;
  125. function det_resulttype: tnode; override;
  126. function docompare(p: tnode): boolean; override;
  127. destructor destroy; override;
  128. protected
  129. tempinfo: ptempinfo;
  130. release_to_normal : boolean;
  131. end;
  132. ttempdeletenodeclass = class of ttempdeletenode;
  133. var
  134. cnothingnode : tnothingnodeclass;
  135. cerrornode : terrornodeclass;
  136. casmnode : tasmnodeclass;
  137. cstatementnode : tstatementnodeclass;
  138. cblocknode : tblocknodeclass;
  139. ctempcreatenode : ttempcreatenodeclass;
  140. ctemprefnode : ttemprefnodeclass;
  141. ctempdeletenode : ttempdeletenodeclass;
  142. { Create a blocknode and statement node for multiple statements
  143. generated internally by the parser }
  144. function internalstatements(var laststatement:tstatementnode;releasetemp : boolean):tblocknode;
  145. procedure addstatement(var laststatement:tstatementnode;n:tnode);
  146. implementation
  147. uses
  148. cutils,
  149. verbose,globals,globtype,systems,
  150. symconst,symdef,symsym,symutil,defutil,defcmp,
  151. pass_1,
  152. nld,ncal,nflw,rgobj,cginfo,cgbase
  153. ;
  154. {*****************************************************************************
  155. Helpers
  156. *****************************************************************************}
  157. function internalstatements(var laststatement:tstatementnode;releasetemp : boolean):tblocknode;
  158. begin
  159. { create dummy initial statement }
  160. laststatement := cstatementnode.create(cnothingnode.create,nil);
  161. internalstatements := cblocknode.create(laststatement,releasetemp);
  162. end;
  163. procedure addstatement(var laststatement:tstatementnode;n:tnode);
  164. begin
  165. if assigned(laststatement.right) then
  166. internalerror(200204201);
  167. laststatement.right:=cstatementnode.create(n,nil);
  168. laststatement:=tstatementnode(laststatement.right);
  169. end;
  170. {*****************************************************************************
  171. TFIRSTNOTHING
  172. *****************************************************************************}
  173. constructor tnothingnode.create;
  174. begin
  175. inherited create(nothingn);
  176. end;
  177. function tnothingnode.det_resulttype:tnode;
  178. begin
  179. result:=nil;
  180. resulttype:=voidtype;
  181. end;
  182. function tnothingnode.pass_1 : tnode;
  183. begin
  184. result:=nil;
  185. expectloc:=LOC_VOID;
  186. end;
  187. {*****************************************************************************
  188. TFIRSTERROR
  189. *****************************************************************************}
  190. constructor terrornode.create;
  191. begin
  192. inherited create(errorn);
  193. end;
  194. function terrornode.det_resulttype:tnode;
  195. begin
  196. result:=nil;
  197. include(flags,nf_error);
  198. codegenerror:=true;
  199. resulttype:=generrortype;
  200. end;
  201. function terrornode.pass_1 : tnode;
  202. begin
  203. result:=nil;
  204. expectloc:=LOC_VOID;
  205. codegenerror:=true;
  206. end;
  207. procedure terrornode.mark_write;
  208. begin
  209. end;
  210. {*****************************************************************************
  211. TSTATEMENTNODE
  212. *****************************************************************************}
  213. constructor tstatementnode.create(l,r : tnode);
  214. begin
  215. inherited create(statementn,l,r);
  216. end;
  217. function tstatementnode.det_resulttype:tnode;
  218. begin
  219. result:=nil;
  220. resulttype:=voidtype;
  221. { left is the statement itself calln assignn or a complex one }
  222. resulttypepass(left);
  223. if (not (cs_extsyntax in aktmoduleswitches)) and
  224. assigned(left.resulttype.def) and
  225. not((left.nodetype=calln) and
  226. { don't complain when funcretrefnode is set, because then the
  227. value is already used. And also not for constructors }
  228. (assigned(tcallnode(left).funcretnode) or
  229. (tcallnode(left).procdefinition.proctypeoption=potype_constructor))) and
  230. not(is_void(left.resulttype.def)) then
  231. CGMessage(cg_e_illegal_expression);
  232. if codegenerror then
  233. exit;
  234. { right is the next statement in the list }
  235. if assigned(right) then
  236. resulttypepass(right);
  237. if codegenerror then
  238. exit;
  239. end;
  240. function tstatementnode.pass_1 : tnode;
  241. begin
  242. result:=nil;
  243. { left is the statement itself calln assignn or a complex one }
  244. firstpass(left);
  245. if codegenerror then
  246. exit;
  247. expectloc:=left.expectloc;
  248. registers32:=left.registers32;
  249. registersfpu:=left.registersfpu;
  250. {$ifdef SUPPORT_MMX}
  251. registersmmx:=left.registersmmx;
  252. {$endif SUPPORT_MMX}
  253. { right is the next in the list }
  254. if assigned(right) then
  255. firstpass(right);
  256. if codegenerror then
  257. exit;
  258. end;
  259. procedure tstatementnode.printnodetree(var t:text);
  260. begin
  261. printnodelist(t);
  262. end;
  263. {*****************************************************************************
  264. TBLOCKNODE
  265. *****************************************************************************}
  266. constructor tblocknode.create(l : tnode;releasetemp : boolean);
  267. begin
  268. inherited create(blockn,l);
  269. {$ifndef newra}
  270. if releasetemp then
  271. include(flags,nf_releasetemps);
  272. {$endif newra}
  273. end;
  274. function tblocknode.det_resulttype:tnode;
  275. var
  276. hp : tstatementnode;
  277. begin
  278. result:=nil;
  279. resulttype:=voidtype;
  280. hp:=tstatementnode(left);
  281. while assigned(hp) do
  282. begin
  283. if assigned(hp.left) then
  284. begin
  285. codegenerror:=false;
  286. resulttypepass(hp.left);
  287. if (not (cs_extsyntax in aktmoduleswitches)) and
  288. assigned(hp.left.resulttype.def) and
  289. not((hp.left.nodetype=calln) and
  290. { don't complain when funcretnode is set, because then the
  291. value is already used. And also not for constructors }
  292. (assigned(tcallnode(hp.left).funcretnode) or
  293. (tcallnode(hp.left).procdefinition.proctypeoption=potype_constructor))) and
  294. not(is_void(hp.left.resulttype.def)) then
  295. CGMessagePos(hp.left.fileinfo,cg_e_illegal_expression);
  296. { the resulttype of the block is the last type that is
  297. returned. Normally this is a voidtype. But when the
  298. compiler inserts a block of multiple statements then the
  299. last entry can return a value }
  300. resulttype:=hp.left.resulttype;
  301. end;
  302. hp:=tstatementnode(hp.right);
  303. end;
  304. end;
  305. function tblocknode.pass_1 : tnode;
  306. var
  307. hp : tstatementnode;
  308. count : longint;
  309. begin
  310. result:=nil;
  311. expectloc:=LOC_VOID;
  312. count:=0;
  313. hp:=tstatementnode(left);
  314. while assigned(hp) do
  315. begin
  316. if cs_regalloc in aktglobalswitches then
  317. begin
  318. { node transformations }
  319. { concat function result to exit }
  320. { this is wrong for string or other complex
  321. result types !!! }
  322. if {ret_in_acc(current_procdef.rettype.def) and }
  323. (is_ordinal(current_procdef.rettype.def) or
  324. is_smallset(current_procdef.rettype.def)) and
  325. assigned(hp.right) and
  326. assigned(tstatementnode(hp.right).left) and
  327. (tstatementnode(hp.right).left.nodetype=exitn) and
  328. (hp.left.nodetype=assignn) and
  329. { !!!! this tbinarynode should be tassignmentnode }
  330. (tbinarynode(hp.left).left.nodetype=loadn) and
  331. (is_funcret_sym(tloadnode(tbinarynode(hp.left).left).symtableentry)) then
  332. begin
  333. if assigned(texitnode(tstatementnode(hp.right).left).left) then
  334. CGMessage(cg_n_inefficient_code)
  335. else
  336. begin
  337. texitnode(tstatementnode(hp.right).left).left:=tassignmentnode(hp.left).right;
  338. tassignmentnode(hp.left).right:=nil;
  339. hp.left.free;
  340. hp.left:=nil;
  341. end;
  342. end
  343. { warning if unreachable code occurs and elimate this }
  344. else if (hp.left.nodetype in
  345. [exitn,breakn,continuen,goton]) and
  346. { statement node (JM) }
  347. assigned(hp.right) and
  348. { kind of statement! (JM) }
  349. assigned(tstatementnode(hp.right).left) and
  350. (tstatementnode(hp.right).left.nodetype<>labeln) then
  351. begin
  352. { use correct line number }
  353. aktfilepos:=hp.right.fileinfo;
  354. hp.right.free;
  355. hp.right:=nil;
  356. CGMessage(cg_w_unreachable_code);
  357. { old lines }
  358. aktfilepos:=hp.left.fileinfo;
  359. end;
  360. end;
  361. if assigned(hp.left) then
  362. begin
  363. codegenerror:=false;
  364. firstpass(hp.left);
  365. hp.expectloc:=hp.left.expectloc;
  366. hp.registers32:=hp.left.registers32;
  367. hp.registersfpu:=hp.left.registersfpu;
  368. {$ifdef SUPPORT_MMX}
  369. hp.registersmmx:=hp.left.registersmmx;
  370. {$endif SUPPORT_MMX}
  371. end
  372. else
  373. hp.registers32:=0;
  374. if hp.registers32>registers32 then
  375. registers32:=hp.registers32;
  376. if hp.registersfpu>registersfpu then
  377. registersfpu:=hp.registersfpu;
  378. {$ifdef SUPPORT_MMX}
  379. if hp.registersmmx>registersmmx then
  380. registersmmx:=hp.registersmmx;
  381. {$endif}
  382. expectloc:=hp.expectloc;
  383. inc(count);
  384. hp:=tstatementnode(hp.right);
  385. end;
  386. end;
  387. {$ifdef state_tracking}
  388. function Tblocknode.track_state_pass(exec_known:boolean):boolean;
  389. var hp:Tstatementnode;
  390. begin
  391. track_state_pass:=false;
  392. hp:=Tstatementnode(left);
  393. while assigned(hp) do
  394. begin
  395. if hp.left.track_state_pass(exec_known) then
  396. track_state_pass:=true;
  397. hp:=Tstatementnode(hp.right);
  398. end;
  399. end;
  400. {$endif state_tracking}
  401. {*****************************************************************************
  402. TASMNODE
  403. *****************************************************************************}
  404. constructor tasmnode.create(p : taasmoutput);
  405. begin
  406. inherited create(asmn);
  407. p_asm:=p;
  408. end;
  409. destructor tasmnode.destroy;
  410. begin
  411. if assigned(p_asm) then
  412. p_asm.free;
  413. inherited destroy;
  414. end;
  415. constructor tasmnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  416. var
  417. hp : tai;
  418. begin
  419. inherited ppuload(t,ppufile);
  420. p_asm:=taasmoutput.create;
  421. repeat
  422. hp:=ppuloadai(ppufile);
  423. if hp=nil then
  424. break;
  425. p_asm.concat(hp);
  426. until false;
  427. end;
  428. procedure tasmnode.ppuwrite(ppufile:tcompilerppufile);
  429. var
  430. hp : tai;
  431. begin
  432. inherited ppuwrite(ppufile);
  433. hp:=tai(p_asm.first);
  434. while assigned(hp) do
  435. begin
  436. ppuwriteai(ppufile,hp);
  437. hp:=tai(hp.next);
  438. end;
  439. { end is marked by a nil }
  440. ppuwriteai(ppufile,nil);
  441. end;
  442. procedure tasmnode.derefimpl;
  443. var
  444. hp : tai;
  445. begin
  446. inherited derefimpl;
  447. hp:=tai(p_asm.first);
  448. while assigned(hp) do
  449. begin
  450. hp.derefimpl;
  451. hp:=tai(hp.next);
  452. end;
  453. end;
  454. function tasmnode.getcopy: tnode;
  455. var
  456. n: tasmnode;
  457. begin
  458. n := tasmnode(inherited getcopy);
  459. if assigned(p_asm) then
  460. begin
  461. n.p_asm:=taasmoutput.create;
  462. n.p_asm.concatlistcopy(p_asm);
  463. end
  464. else n.p_asm := nil;
  465. getcopy := n;
  466. end;
  467. function tasmnode.det_resulttype:tnode;
  468. begin
  469. result:=nil;
  470. resulttype:=voidtype;
  471. end;
  472. function tasmnode.pass_1 : tnode;
  473. begin
  474. result:=nil;
  475. expectloc:=LOC_VOID;
  476. include(current_procinfo.flags,pi_uses_asm);
  477. end;
  478. function tasmnode.docompare(p: tnode): boolean;
  479. begin
  480. { comparing of asmlists is not implemented (JM) }
  481. docompare := false;
  482. end;
  483. {*****************************************************************************
  484. TEMPCREATENODE
  485. *****************************************************************************}
  486. constructor ttempcreatenode.create(const _restype: ttype; _size: longint; _persistent: boolean);
  487. begin
  488. inherited create(tempcreaten);
  489. size := _size;
  490. new(tempinfo);
  491. fillchar(tempinfo^,sizeof(tempinfo^),0);
  492. tempinfo^.restype := _restype;
  493. persistent := _persistent;
  494. end;
  495. function ttempcreatenode.getcopy: tnode;
  496. var
  497. n: ttempcreatenode;
  498. begin
  499. n := ttempcreatenode(inherited getcopy);
  500. n.size := size;
  501. n.persistent := persistent;
  502. new(n.tempinfo);
  503. fillchar(n.tempinfo^,sizeof(n.tempinfo^),0);
  504. n.tempinfo^.restype := tempinfo^.restype;
  505. { when the tempinfo has already a hookoncopy then it is not
  506. reset by a tempdeletenode }
  507. if assigned(tempinfo^.hookoncopy) then
  508. internalerror(200211262);
  509. { signal the temprefs that the temp they point to has been copied, }
  510. { so that if the refs get copied as well, they can hook themselves }
  511. { to the copy of the temp }
  512. tempinfo^.hookoncopy := n.tempinfo;
  513. tempinfo^.nextref_set_hookoncopy_nil := false;
  514. result := n;
  515. end;
  516. function ttempcreatenode.pass_1 : tnode;
  517. begin
  518. result := nil;
  519. expectloc:=LOC_VOID;
  520. end;
  521. function ttempcreatenode.det_resulttype: tnode;
  522. begin
  523. result := nil;
  524. { a tempcreatenode doesn't have a resulttype, only temprefnodes do }
  525. resulttype := voidtype;
  526. end;
  527. function ttempcreatenode.docompare(p: tnode): boolean;
  528. begin
  529. result :=
  530. inherited docompare(p) and
  531. (ttempcreatenode(p).size = size) and
  532. equal_defs(ttempcreatenode(p).tempinfo^.restype.def,tempinfo^.restype.def);
  533. end;
  534. procedure ttempcreatenode.printnodedata(var t:text);
  535. begin
  536. inherited printnodedata(t);
  537. writeln(t,printnodeindention,'size = ',size);
  538. end;
  539. {*****************************************************************************
  540. TEMPREFNODE
  541. *****************************************************************************}
  542. constructor ttemprefnode.create(const temp: ttempcreatenode);
  543. begin
  544. inherited create(temprefn);
  545. tempinfo := temp.tempinfo;
  546. offset:=0;
  547. end;
  548. constructor ttemprefnode.create_offset(const temp: ttempcreatenode;aoffset:longint);
  549. begin
  550. self.create(temp);
  551. offset := aoffset;
  552. end;
  553. function ttemprefnode.getcopy: tnode;
  554. var
  555. n: ttemprefnode;
  556. begin
  557. n := ttemprefnode(inherited getcopy);
  558. n.offset := offset;
  559. if assigned(tempinfo^.hookoncopy) then
  560. { if the temp has been copied, assume it becomes a new }
  561. { temp which has to be hooked by the copied reference }
  562. begin
  563. { hook the ref to the copied temp }
  564. n.tempinfo := tempinfo^.hookoncopy;
  565. { if we passed a ttempdeletenode that changed the temp }
  566. { from a persistent one into a normal one, we must be }
  567. { the last reference (since our parent should free the }
  568. { temp (JM) }
  569. if (tempinfo^.nextref_set_hookoncopy_nil) then
  570. tempinfo^.hookoncopy := nil;
  571. end
  572. else
  573. { if the temp we refer to hasn't been copied, assume }
  574. { we're just a new reference to that temp }
  575. begin
  576. n.tempinfo := tempinfo;
  577. end;
  578. result := n;
  579. end;
  580. function ttemprefnode.pass_1 : tnode;
  581. begin
  582. expectloc:=LOC_REFERENCE;
  583. result := nil;
  584. end;
  585. function ttemprefnode.det_resulttype: tnode;
  586. begin
  587. { check if the temp is already resulttype passed }
  588. if not assigned(tempinfo^.restype.def) then
  589. internalerror(200108233);
  590. result := nil;
  591. resulttype := tempinfo^.restype;
  592. end;
  593. function ttemprefnode.docompare(p: tnode): boolean;
  594. begin
  595. result :=
  596. inherited docompare(p) and
  597. (ttemprefnode(p).tempinfo = tempinfo) and
  598. (ttemprefnode(p).offset = offset);
  599. end;
  600. procedure Ttemprefnode.mark_write;
  601. begin
  602. include(flags,nf_write);
  603. end;
  604. {*****************************************************************************
  605. TEMPDELETENODE
  606. *****************************************************************************}
  607. constructor ttempdeletenode.create(const temp: ttempcreatenode);
  608. begin
  609. inherited create(tempdeleten);
  610. tempinfo := temp.tempinfo;
  611. release_to_normal := false;
  612. end;
  613. constructor ttempdeletenode.create_normal_temp(const temp: ttempcreatenode);
  614. begin
  615. inherited create(tempdeleten);
  616. tempinfo := temp.tempinfo;
  617. release_to_normal := true;
  618. if not temp.persistent then
  619. internalerror(200204211);
  620. end;
  621. function ttempdeletenode.getcopy: tnode;
  622. var
  623. n: ttempdeletenode;
  624. begin
  625. n := ttempdeletenode(inherited getcopy);
  626. n.release_to_normal := release_to_normal;
  627. if assigned(tempinfo^.hookoncopy) then
  628. { if the temp has been copied, assume it becomes a new }
  629. { temp which has to be hooked by the copied deletenode }
  630. begin
  631. { hook the tempdeletenode to the copied temp }
  632. n.tempinfo := tempinfo^.hookoncopy;
  633. { the temp shall not be used, reset hookoncopy }
  634. { Only if release_to_normal is false, otherwise }
  635. { the temp can still be referenced once more (JM) }
  636. if (not release_to_normal) then
  637. tempinfo^.hookoncopy:=nil
  638. else
  639. tempinfo^.nextref_set_hookoncopy_nil := true;
  640. end
  641. else
  642. { if the temp we refer to hasn't been copied, we have a }
  643. { problem since that means we now have two delete nodes }
  644. { for one temp }
  645. internalerror(200108234);
  646. result := n;
  647. end;
  648. function ttempdeletenode.pass_1 : tnode;
  649. begin
  650. expectloc:=LOC_VOID;
  651. result := nil;
  652. end;
  653. function ttempdeletenode.det_resulttype: tnode;
  654. begin
  655. result := nil;
  656. resulttype := voidtype;
  657. end;
  658. function ttempdeletenode.docompare(p: tnode): boolean;
  659. begin
  660. result :=
  661. inherited docompare(p) and
  662. (ttemprefnode(p).tempinfo = tempinfo);
  663. end;
  664. destructor ttempdeletenode.destroy;
  665. begin
  666. dispose(tempinfo);
  667. end;
  668. begin
  669. cnothingnode:=tnothingnode;
  670. cerrornode:=terrornode;
  671. casmnode:=tasmnode;
  672. cstatementnode:=tstatementnode;
  673. cblocknode:=tblocknode;
  674. ctempcreatenode:=ttempcreatenode;
  675. ctemprefnode:=ttemprefnode;
  676. ctempdeletenode:=ttempdeletenode;
  677. end.
  678. {
  679. $Log$
  680. Revision 1.50 2003-05-13 19:14:41 peter
  681. * failn removed
  682. * inherited result code check moven to pexpr
  683. Revision 1.49 2003/05/11 14:45:12 peter
  684. * tloadnode does not support objectsymtable,withsymtable anymore
  685. * withnode cleanup
  686. * direct with rewritten to use temprefnode
  687. Revision 1.48 2003/04/27 11:21:33 peter
  688. * aktprocdef renamed to current_procdef
  689. * procinfo renamed to current_procinfo
  690. * procinfo will now be stored in current_module so it can be
  691. cleaned up properly
  692. * gen_main_procsym changed to create_main_proc and release_main_proc
  693. to also generate a tprocinfo structure
  694. * fixed unit implicit initfinal
  695. Revision 1.47 2003/04/25 20:59:33 peter
  696. * removed funcretn,funcretsym, function result is now in varsym
  697. and aliases for result and function name are added using absolutesym
  698. * vs_hidden parameter for funcret passed in parameter
  699. * vs_hidden fixes
  700. * writenode changed to printnode and released from extdebug
  701. * -vp option added to generate a tree.log with the nodetree
  702. * nicer printnode for statements, callnode
  703. Revision 1.46 2002/04/25 20:15:39 florian
  704. * block nodes within expressions shouldn't release the used registers,
  705. fixed using a flag till the new rg is ready
  706. Revision 1.45 2003/04/23 08:41:34 jonas
  707. * fixed ttemprefnode.compare and .getcopy to take offset field into
  708. account
  709. Revision 1.44 2003/04/22 23:50:22 peter
  710. * firstpass uses expectloc
  711. * checks if there are differences between the expectloc and
  712. location.loc from secondpass in EXTDEBUG
  713. Revision 1.43 2003/04/21 15:00:22 jonas
  714. * fixed tstatementnode.det_resulttype and tststatementnode.pass_1
  715. * fixed some getcopy issues with ttemp*nodes
  716. Revision 1.42 2003/04/17 07:50:24 daniel
  717. * Some work on interference graph construction
  718. Revision 1.41 2003/04/12 14:53:59 jonas
  719. * ttempdeletenode.create now sets the nodetype to tempdeleten instead of
  720. temprefn
  721. Revision 1.40 2003/03/17 20:30:46 peter
  722. * errornode.mark_write added
  723. Revision 1.39 2003/01/03 12:15:55 daniel
  724. * Removed ifdefs around notifications
  725. ifdefs around for loop optimizations remain
  726. Revision 1.38 2002/11/27 02:37:12 peter
  727. * case statement inlining added
  728. * fixed inlining of write()
  729. * switched statementnode left and right parts so the statements are
  730. processed in the correct order when getcopy is used. This is
  731. required for tempnodes
  732. Revision 1.37 2002/11/25 17:43:17 peter
  733. * splitted defbase in defutil,symutil,defcmp
  734. * merged isconvertable and is_equal into compare_defs(_ext)
  735. * made operator search faster by walking the list only once
  736. Revision 1.36 2002/10/05 15:15:19 peter
  737. * don't complain in X- mode for internal generated function calls
  738. with funcretrefnode set
  739. * give statement error at the correct line position instead of the
  740. block begin
  741. Revision 1.35 2002/09/01 08:01:16 daniel
  742. * Removed sets from Tcallnode.det_resulttype
  743. + Added read/write notifications of variables. These will be usefull
  744. for providing information for several optimizations. For example
  745. the value of the loop variable of a for loop does matter is the
  746. variable is read after the for loop, but if it's no longer used
  747. or written, it doesn't matter and this can be used to optimize
  748. the loop code generation.
  749. Revision 1.34 2002/08/18 20:06:23 peter
  750. * inlining is now also allowed in interface
  751. * renamed write/load to ppuwrite/ppuload
  752. * tnode storing in ppu
  753. * nld,ncon,nbas are already updated for storing in ppu
  754. Revision 1.33 2002/08/17 22:09:44 florian
  755. * result type handling in tcgcal.pass_2 overhauled
  756. * better tnode.printnodetree
  757. * some ppc stuff fixed
  758. Revision 1.32 2002/08/17 09:23:34 florian
  759. * first part of procinfo rewrite
  760. Revision 1.31 2002/08/15 19:10:35 peter
  761. * first things tai,tnode storing in ppu
  762. Revision 1.30 2002/07/20 11:57:53 florian
  763. * types.pas renamed to defbase.pas because D6 contains a types
  764. unit so this would conflicts if D6 programms are compiled
  765. + Willamette/SSE2 instructions to assembler added
  766. Revision 1.29 2002/07/19 11:41:35 daniel
  767. * State tracker work
  768. * The whilen and repeatn are now completely unified into whilerepeatn. This
  769. allows the state tracker to change while nodes automatically into
  770. repeat nodes.
  771. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  772. 'not(a>b)' is optimized into 'a<=b'.
  773. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  774. by removing the notn and later switchting the true and falselabels. The
  775. same is done with 'repeat until not a'.
  776. Revision 1.28 2002/07/14 18:00:43 daniel
  777. + Added the beginning of a state tracker. This will track the values of
  778. variables through procedures and optimize things away.
  779. Revision 1.27 2002/07/01 18:46:22 peter
  780. * internal linker
  781. * reorganized aasm layer
  782. Revision 1.26 2002/06/24 12:43:00 jonas
  783. * fixed errors found with new -CR code from Peter when cycling with -O2p3r
  784. Revision 1.25 2002/05/18 13:34:09 peter
  785. * readded missing revisions
  786. Revision 1.24 2002/05/16 19:46:37 carl
  787. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  788. + try to fix temp allocation (still in ifdef)
  789. + generic constructor calls
  790. + start of tassembler / tmodulebase class cleanup
  791. Revision 1.22 2002/04/23 19:16:34 peter
  792. * add pinline unit that inserts compiler supported functions using
  793. one or more statements
  794. * moved finalize and setlength from ninl to pinline
  795. Revision 1.21 2002/04/21 19:02:03 peter
  796. * removed newn and disposen nodes, the code is now directly
  797. inlined from pexpr
  798. * -an option that will write the secondpass nodes to the .s file, this
  799. requires EXTDEBUG define to actually write the info
  800. * fixed various internal errors and crashes due recent code changes
  801. Revision 1.20 2002/04/04 19:05:57 peter
  802. * removed unused units
  803. * use tlocation.size in cg.a_*loc*() routines
  804. Revision 1.19 2002/03/31 20:26:33 jonas
  805. + a_loadfpu_* and a_loadmm_* methods in tcg
  806. * register allocation is now handled by a class and is mostly processor
  807. independent (+rgobj.pas and i386/rgcpu.pas)
  808. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  809. * some small improvements and fixes to the optimizer
  810. * some register allocation fixes
  811. * some fpuvaroffset fixes in the unary minus node
  812. * push/popusedregisters is now called rg.save/restoreusedregisters and
  813. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  814. also better optimizable)
  815. * fixed and optimized register saving/restoring for new/dispose nodes
  816. * LOC_FPU locations now also require their "register" field to be set to
  817. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  818. - list field removed of the tnode class because it's not used currently
  819. and can cause hard-to-find bugs
  820. }