nbas.pas 29 KB

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