nbas.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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. { no temps over several statements }
  244. {$ifndef newra}
  245. rg.cleartempgen;
  246. {$endif}
  247. { left is the statement itself calln assignn or a complex one }
  248. firstpass(left);
  249. if codegenerror then
  250. exit;
  251. expectloc:=left.expectloc;
  252. registers32:=left.registers32;
  253. registersfpu:=left.registersfpu;
  254. {$ifdef SUPPORT_MMX}
  255. registersmmx:=left.registersmmx;
  256. {$endif SUPPORT_MMX}
  257. { right is the next in the list }
  258. if assigned(right) then
  259. firstpass(right);
  260. if codegenerror then
  261. exit;
  262. end;
  263. procedure tstatementnode.printnodetree(var t:text);
  264. begin
  265. printnodelist(t);
  266. end;
  267. {*****************************************************************************
  268. TBLOCKNODE
  269. *****************************************************************************}
  270. constructor tblocknode.create(l : tnode;releasetemp : boolean);
  271. begin
  272. inherited create(blockn,l);
  273. if releasetemp then
  274. include(flags,nf_releasetemps);
  275. end;
  276. function tblocknode.det_resulttype:tnode;
  277. var
  278. hp : tstatementnode;
  279. begin
  280. result:=nil;
  281. resulttype:=voidtype;
  282. hp:=tstatementnode(left);
  283. while assigned(hp) do
  284. begin
  285. if assigned(hp.left) then
  286. begin
  287. codegenerror:=false;
  288. resulttypepass(hp.left);
  289. if (not (cs_extsyntax in aktmoduleswitches)) and
  290. assigned(hp.left.resulttype.def) and
  291. not((hp.left.nodetype=calln) and
  292. { don't complain when funcretnode is set, because then the
  293. value is already used. And also not for constructors }
  294. (assigned(tcallnode(hp.left).funcretnode) or
  295. (tcallnode(hp.left).procdefinition.proctypeoption=potype_constructor))) and
  296. not(is_void(hp.left.resulttype.def)) then
  297. CGMessagePos(hp.left.fileinfo,cg_e_illegal_expression);
  298. { the resulttype of the block is the last type that is
  299. returned. Normally this is a voidtype. But when the
  300. compiler inserts a block of multiple statements then the
  301. last entry can return a value }
  302. resulttype:=hp.left.resulttype;
  303. end;
  304. hp:=tstatementnode(hp.right);
  305. end;
  306. end;
  307. function tblocknode.pass_1 : tnode;
  308. var
  309. hp : tstatementnode;
  310. count : longint;
  311. begin
  312. result:=nil;
  313. expectloc:=LOC_VOID;
  314. count:=0;
  315. hp:=tstatementnode(left);
  316. while assigned(hp) do
  317. begin
  318. if cs_regalloc in aktglobalswitches then
  319. begin
  320. { node transformations }
  321. { concat function result to exit }
  322. { this is wrong for string or other complex
  323. result types !!! }
  324. if {ret_in_acc(aktprocdef.rettype.def) and }
  325. (is_ordinal(aktprocdef.rettype.def) or
  326. is_smallset(aktprocdef.rettype.def)) and
  327. assigned(hp.right) and
  328. assigned(tstatementnode(hp.right).left) and
  329. (tstatementnode(hp.right).left.nodetype=exitn) and
  330. (hp.left.nodetype=assignn) and
  331. { !!!! this tbinarynode should be tassignmentnode }
  332. (tbinarynode(hp.left).left.nodetype=loadn) and
  333. (is_funcret_sym(tloadnode(tbinarynode(hp.left).left).symtableentry)) then
  334. begin
  335. if assigned(texitnode(tstatementnode(hp.right).left).left) then
  336. CGMessage(cg_n_inefficient_code)
  337. else
  338. begin
  339. texitnode(tstatementnode(hp.right).left).left:=tassignmentnode(hp.left).right;
  340. tassignmentnode(hp.left).right:=nil;
  341. hp.left.free;
  342. hp.left:=nil;
  343. end;
  344. end
  345. { warning if unreachable code occurs and elimate this }
  346. else if (hp.left.nodetype in
  347. [exitn,breakn,continuen,goton]) and
  348. { statement node (JM) }
  349. assigned(hp.right) and
  350. { kind of statement! (JM) }
  351. assigned(tstatementnode(hp.right).left) and
  352. (tstatementnode(hp.right).left.nodetype<>labeln) then
  353. begin
  354. { use correct line number }
  355. aktfilepos:=hp.right.fileinfo;
  356. hp.right.free;
  357. hp.right:=nil;
  358. CGMessage(cg_w_unreachable_code);
  359. { old lines }
  360. aktfilepos:=hp.left.fileinfo;
  361. end;
  362. end;
  363. if assigned(hp.left) then
  364. begin
  365. {$ifndef newra}
  366. rg.cleartempgen;
  367. {$endif}
  368. codegenerror:=false;
  369. firstpass(hp.left);
  370. hp.expectloc:=hp.left.expectloc;
  371. hp.registers32:=hp.left.registers32;
  372. hp.registersfpu:=hp.left.registersfpu;
  373. {$ifdef SUPPORT_MMX}
  374. hp.registersmmx:=hp.left.registersmmx;
  375. {$endif SUPPORT_MMX}
  376. end
  377. else
  378. hp.registers32:=0;
  379. if hp.registers32>registers32 then
  380. registers32:=hp.registers32;
  381. if hp.registersfpu>registersfpu then
  382. registersfpu:=hp.registersfpu;
  383. {$ifdef SUPPORT_MMX}
  384. if hp.registersmmx>registersmmx then
  385. registersmmx:=hp.registersmmx;
  386. {$endif}
  387. expectloc:=hp.expectloc;
  388. inc(count);
  389. hp:=tstatementnode(hp.right);
  390. end;
  391. end;
  392. {$ifdef state_tracking}
  393. function Tblocknode.track_state_pass(exec_known:boolean):boolean;
  394. var hp:Tstatementnode;
  395. begin
  396. track_state_pass:=false;
  397. hp:=Tstatementnode(left);
  398. while assigned(hp) do
  399. begin
  400. if hp.left.track_state_pass(exec_known) then
  401. track_state_pass:=true;
  402. hp:=Tstatementnode(hp.right);
  403. end;
  404. end;
  405. {$endif state_tracking}
  406. {*****************************************************************************
  407. TASMNODE
  408. *****************************************************************************}
  409. constructor tasmnode.create(p : taasmoutput);
  410. begin
  411. inherited create(asmn);
  412. p_asm:=p;
  413. end;
  414. destructor tasmnode.destroy;
  415. begin
  416. if assigned(p_asm) then
  417. p_asm.free;
  418. inherited destroy;
  419. end;
  420. constructor tasmnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  421. var
  422. hp : tai;
  423. begin
  424. inherited ppuload(t,ppufile);
  425. p_asm:=taasmoutput.create;
  426. repeat
  427. hp:=ppuloadai(ppufile);
  428. if hp=nil then
  429. break;
  430. p_asm.concat(hp);
  431. until false;
  432. end;
  433. procedure tasmnode.ppuwrite(ppufile:tcompilerppufile);
  434. var
  435. hp : tai;
  436. begin
  437. inherited ppuwrite(ppufile);
  438. hp:=tai(p_asm.first);
  439. while assigned(hp) do
  440. begin
  441. ppuwriteai(ppufile,hp);
  442. hp:=tai(hp.next);
  443. end;
  444. { end is marked by a nil }
  445. ppuwriteai(ppufile,nil);
  446. end;
  447. procedure tasmnode.derefimpl;
  448. var
  449. hp : tai;
  450. begin
  451. inherited derefimpl;
  452. hp:=tai(p_asm.first);
  453. while assigned(hp) do
  454. begin
  455. hp.derefimpl;
  456. hp:=tai(hp.next);
  457. end;
  458. end;
  459. function tasmnode.getcopy: tnode;
  460. var
  461. n: tasmnode;
  462. begin
  463. n := tasmnode(inherited getcopy);
  464. if assigned(p_asm) then
  465. begin
  466. n.p_asm:=taasmoutput.create;
  467. n.p_asm.concatlistcopy(p_asm);
  468. end
  469. else n.p_asm := nil;
  470. getcopy := n;
  471. end;
  472. function tasmnode.det_resulttype:tnode;
  473. begin
  474. result:=nil;
  475. resulttype:=voidtype;
  476. end;
  477. function tasmnode.pass_1 : tnode;
  478. begin
  479. result:=nil;
  480. expectloc:=LOC_VOID;
  481. procinfo.flags:=procinfo.flags or pi_uses_asm;
  482. end;
  483. function tasmnode.docompare(p: tnode): boolean;
  484. begin
  485. { comparing of asmlists is not implemented (JM) }
  486. docompare := false;
  487. end;
  488. {*****************************************************************************
  489. TEMPCREATENODE
  490. *****************************************************************************}
  491. constructor ttempcreatenode.create(const _restype: ttype; _size: longint; _persistent: boolean);
  492. begin
  493. inherited create(tempcreaten);
  494. size := _size;
  495. new(tempinfo);
  496. fillchar(tempinfo^,sizeof(tempinfo^),0);
  497. tempinfo^.restype := _restype;
  498. persistent := _persistent;
  499. end;
  500. function ttempcreatenode.getcopy: tnode;
  501. var
  502. n: ttempcreatenode;
  503. begin
  504. n := ttempcreatenode(inherited getcopy);
  505. n.size := size;
  506. n.persistent := persistent;
  507. new(n.tempinfo);
  508. fillchar(n.tempinfo^,sizeof(n.tempinfo^),0);
  509. n.tempinfo^.restype := tempinfo^.restype;
  510. { when the tempinfo has already a hookoncopy then it is not
  511. reset by a tempdeletenode }
  512. if assigned(tempinfo^.hookoncopy) then
  513. internalerror(200211262);
  514. { signal the temprefs that the temp they point to has been copied, }
  515. { so that if the refs get copied as well, they can hook themselves }
  516. { to the copy of the temp }
  517. tempinfo^.hookoncopy := n.tempinfo;
  518. tempinfo^.nextref_set_hookoncopy_nil := false;
  519. result := n;
  520. end;
  521. function ttempcreatenode.pass_1 : tnode;
  522. begin
  523. result := nil;
  524. expectloc:=LOC_VOID;
  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. equal_defs(ttempcreatenode(p).tempinfo^.restype.def,tempinfo^.restype.def);
  538. end;
  539. procedure ttempcreatenode.printnodedata(var t:text);
  540. begin
  541. inherited printnodedata(t);
  542. writeln(t,printnodeindention,'size = ',size);
  543. end;
  544. {*****************************************************************************
  545. TEMPREFNODE
  546. *****************************************************************************}
  547. constructor ttemprefnode.create(const temp: ttempcreatenode);
  548. begin
  549. inherited create(temprefn);
  550. tempinfo := temp.tempinfo;
  551. offset:=0;
  552. end;
  553. constructor ttemprefnode.create_offset(const temp: ttempcreatenode;aoffset:longint);
  554. begin
  555. self.create(temp);
  556. offset := aoffset;
  557. end;
  558. function ttemprefnode.getcopy: tnode;
  559. var
  560. n: ttemprefnode;
  561. begin
  562. n := ttemprefnode(inherited getcopy);
  563. n.offset := offset;
  564. if assigned(tempinfo^.hookoncopy) then
  565. { if the temp has been copied, assume it becomes a new }
  566. { temp which has to be hooked by the copied reference }
  567. begin
  568. { hook the ref to the copied temp }
  569. n.tempinfo := tempinfo^.hookoncopy;
  570. { if we passed a ttempdeletenode that changed the temp }
  571. { from a persistent one into a normal one, we must be }
  572. { the last reference (since our parent should free the }
  573. { temp (JM) }
  574. if (tempinfo^.nextref_set_hookoncopy_nil) then
  575. tempinfo^.hookoncopy := nil;
  576. end
  577. else
  578. { if the temp we refer to hasn't been copied, assume }
  579. { we're just a new reference to that temp }
  580. begin
  581. n.tempinfo := tempinfo;
  582. end;
  583. result := n;
  584. end;
  585. function ttemprefnode.pass_1 : tnode;
  586. begin
  587. expectloc:=LOC_REFERENCE;
  588. result := nil;
  589. end;
  590. function ttemprefnode.det_resulttype: tnode;
  591. begin
  592. { check if the temp is already resulttype passed }
  593. if not assigned(tempinfo^.restype.def) then
  594. internalerror(200108233);
  595. result := nil;
  596. resulttype := tempinfo^.restype;
  597. end;
  598. function ttemprefnode.docompare(p: tnode): boolean;
  599. begin
  600. result :=
  601. inherited docompare(p) and
  602. (ttemprefnode(p).tempinfo = tempinfo) and
  603. (ttemprefnode(p).offset = offset);
  604. end;
  605. procedure Ttemprefnode.mark_write;
  606. begin
  607. include(flags,nf_write);
  608. end;
  609. {*****************************************************************************
  610. TEMPDELETENODE
  611. *****************************************************************************}
  612. constructor ttempdeletenode.create(const temp: ttempcreatenode);
  613. begin
  614. inherited create(tempdeleten);
  615. tempinfo := temp.tempinfo;
  616. release_to_normal := false;
  617. end;
  618. constructor ttempdeletenode.create_normal_temp(const temp: ttempcreatenode);
  619. begin
  620. inherited create(tempdeleten);
  621. tempinfo := temp.tempinfo;
  622. release_to_normal := true;
  623. if not temp.persistent then
  624. internalerror(200204211);
  625. end;
  626. function ttempdeletenode.getcopy: tnode;
  627. var
  628. n: ttempdeletenode;
  629. begin
  630. n := ttempdeletenode(inherited getcopy);
  631. n.release_to_normal := release_to_normal;
  632. if assigned(tempinfo^.hookoncopy) then
  633. { if the temp has been copied, assume it becomes a new }
  634. { temp which has to be hooked by the copied deletenode }
  635. begin
  636. { hook the tempdeletenode to the copied temp }
  637. n.tempinfo := tempinfo^.hookoncopy;
  638. { the temp shall not be used, reset hookoncopy }
  639. { Only if release_to_normal is false, otherwise }
  640. { the temp can still be referenced once more (JM) }
  641. if (not release_to_normal) then
  642. tempinfo^.hookoncopy:=nil
  643. else
  644. tempinfo^.nextref_set_hookoncopy_nil := true;
  645. end
  646. else
  647. { if the temp we refer to hasn't been copied, we have a }
  648. { problem since that means we now have two delete nodes }
  649. { for one temp }
  650. internalerror(200108234);
  651. result := n;
  652. end;
  653. function ttempdeletenode.pass_1 : tnode;
  654. begin
  655. expectloc:=LOC_VOID;
  656. result := nil;
  657. end;
  658. function ttempdeletenode.det_resulttype: tnode;
  659. begin
  660. result := nil;
  661. resulttype := voidtype;
  662. end;
  663. function ttempdeletenode.docompare(p: tnode): boolean;
  664. begin
  665. result :=
  666. inherited docompare(p) and
  667. (ttemprefnode(p).tempinfo = tempinfo);
  668. end;
  669. destructor ttempdeletenode.destroy;
  670. begin
  671. dispose(tempinfo);
  672. end;
  673. begin
  674. cnothingnode:=tnothingnode;
  675. cerrornode:=terrornode;
  676. casmnode:=tasmnode;
  677. cstatementnode:=tstatementnode;
  678. cblocknode:=tblocknode;
  679. ctempcreatenode:=ttempcreatenode;
  680. ctemprefnode:=ttemprefnode;
  681. ctempdeletenode:=ttempdeletenode;
  682. end.
  683. {
  684. $Log$
  685. Revision 1.47 2003-04-25 20:59:33 peter
  686. * removed funcretn,funcretsym, function result is now in varsym
  687. and aliases for result and function name are added using absolutesym
  688. * vs_hidden parameter for funcret passed in parameter
  689. * vs_hidden fixes
  690. * writenode changed to printnode and released from extdebug
  691. * -vp option added to generate a tree.log with the nodetree
  692. * nicer printnode for statements, callnode
  693. Revision 1.46 2002/04/25 20:15:39 florian
  694. * block nodes within expressions shouldn't release the used registers,
  695. fixed using a flag till the new rg is ready
  696. Revision 1.45 2003/04/23 08:41:34 jonas
  697. * fixed ttemprefnode.compare and .getcopy to take offset field into
  698. account
  699. Revision 1.44 2003/04/22 23:50:22 peter
  700. * firstpass uses expectloc
  701. * checks if there are differences between the expectloc and
  702. location.loc from secondpass in EXTDEBUG
  703. Revision 1.43 2003/04/21 15:00:22 jonas
  704. * fixed tstatementnode.det_resulttype and tststatementnode.pass_1
  705. * fixed some getcopy issues with ttemp*nodes
  706. Revision 1.42 2003/04/17 07:50:24 daniel
  707. * Some work on interference graph construction
  708. Revision 1.41 2003/04/12 14:53:59 jonas
  709. * ttempdeletenode.create now sets the nodetype to tempdeleten instead of
  710. temprefn
  711. Revision 1.40 2003/03/17 20:30:46 peter
  712. * errornode.mark_write added
  713. Revision 1.39 2003/01/03 12:15:55 daniel
  714. * Removed ifdefs around notifications
  715. ifdefs around for loop optimizations remain
  716. Revision 1.38 2002/11/27 02:37:12 peter
  717. * case statement inlining added
  718. * fixed inlining of write()
  719. * switched statementnode left and right parts so the statements are
  720. processed in the correct order when getcopy is used. This is
  721. required for tempnodes
  722. Revision 1.37 2002/11/25 17:43:17 peter
  723. * splitted defbase in defutil,symutil,defcmp
  724. * merged isconvertable and is_equal into compare_defs(_ext)
  725. * made operator search faster by walking the list only once
  726. Revision 1.36 2002/10/05 15:15:19 peter
  727. * don't complain in X- mode for internal generated function calls
  728. with funcretrefnode set
  729. * give statement error at the correct line position instead of the
  730. block begin
  731. Revision 1.35 2002/09/01 08:01:16 daniel
  732. * Removed sets from Tcallnode.det_resulttype
  733. + Added read/write notifications of variables. These will be usefull
  734. for providing information for several optimizations. For example
  735. the value of the loop variable of a for loop does matter is the
  736. variable is read after the for loop, but if it's no longer used
  737. or written, it doesn't matter and this can be used to optimize
  738. the loop code generation.
  739. Revision 1.34 2002/08/18 20:06:23 peter
  740. * inlining is now also allowed in interface
  741. * renamed write/load to ppuwrite/ppuload
  742. * tnode storing in ppu
  743. * nld,ncon,nbas are already updated for storing in ppu
  744. Revision 1.33 2002/08/17 22:09:44 florian
  745. * result type handling in tcgcal.pass_2 overhauled
  746. * better tnode.printnodetree
  747. * some ppc stuff fixed
  748. Revision 1.32 2002/08/17 09:23:34 florian
  749. * first part of procinfo rewrite
  750. Revision 1.31 2002/08/15 19:10:35 peter
  751. * first things tai,tnode storing in ppu
  752. Revision 1.30 2002/07/20 11:57:53 florian
  753. * types.pas renamed to defbase.pas because D6 contains a types
  754. unit so this would conflicts if D6 programms are compiled
  755. + Willamette/SSE2 instructions to assembler added
  756. Revision 1.29 2002/07/19 11:41:35 daniel
  757. * State tracker work
  758. * The whilen and repeatn are now completely unified into whilerepeatn. This
  759. allows the state tracker to change while nodes automatically into
  760. repeat nodes.
  761. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  762. 'not(a>b)' is optimized into 'a<=b'.
  763. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  764. by removing the notn and later switchting the true and falselabels. The
  765. same is done with 'repeat until not a'.
  766. Revision 1.28 2002/07/14 18:00:43 daniel
  767. + Added the beginning of a state tracker. This will track the values of
  768. variables through procedures and optimize things away.
  769. Revision 1.27 2002/07/01 18:46:22 peter
  770. * internal linker
  771. * reorganized aasm layer
  772. Revision 1.26 2002/06/24 12:43:00 jonas
  773. * fixed errors found with new -CR code from Peter when cycling with -O2p3r
  774. Revision 1.25 2002/05/18 13:34:09 peter
  775. * readded missing revisions
  776. Revision 1.24 2002/05/16 19:46:37 carl
  777. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  778. + try to fix temp allocation (still in ifdef)
  779. + generic constructor calls
  780. + start of tassembler / tmodulebase class cleanup
  781. Revision 1.22 2002/04/23 19:16:34 peter
  782. * add pinline unit that inserts compiler supported functions using
  783. one or more statements
  784. * moved finalize and setlength from ninl to pinline
  785. Revision 1.21 2002/04/21 19:02:03 peter
  786. * removed newn and disposen nodes, the code is now directly
  787. inlined from pexpr
  788. * -an option that will write the secondpass nodes to the .s file, this
  789. requires EXTDEBUG define to actually write the info
  790. * fixed various internal errors and crashes due recent code changes
  791. Revision 1.20 2002/04/04 19:05:57 peter
  792. * removed unused units
  793. * use tlocation.size in cg.a_*loc*() routines
  794. Revision 1.19 2002/03/31 20:26:33 jonas
  795. + a_loadfpu_* and a_loadmm_* methods in tcg
  796. * register allocation is now handled by a class and is mostly processor
  797. independent (+rgobj.pas and i386/rgcpu.pas)
  798. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  799. * some small improvements and fixes to the optimizer
  800. * some register allocation fixes
  801. * some fpuvaroffset fixes in the unary minus node
  802. * push/popusedregisters is now called rg.save/restoreusedregisters and
  803. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  804. also better optimizable)
  805. * fixed and optimized register saving/restoring for new/dispose nodes
  806. * LOC_FPU locations now also require their "register" field to be set to
  807. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  808. - list field removed of the tnode class because it's not used currently
  809. and can cause hard-to-find bugs
  810. }