nbas.pas 32 KB

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