nbas.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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(current_procdef.rettype.def) and }
  325. (is_ordinal(current_procdef.rettype.def) or
  326. is_smallset(current_procdef.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. include(current_procinfo.flags,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.48 2003-04-27 11:21:33 peter
  686. * aktprocdef renamed to current_procdef
  687. * procinfo renamed to current_procinfo
  688. * procinfo will now be stored in current_module so it can be
  689. cleaned up properly
  690. * gen_main_procsym changed to create_main_proc and release_main_proc
  691. to also generate a tprocinfo structure
  692. * fixed unit implicit initfinal
  693. Revision 1.47 2003/04/25 20:59:33 peter
  694. * removed funcretn,funcretsym, function result is now in varsym
  695. and aliases for result and function name are added using absolutesym
  696. * vs_hidden parameter for funcret passed in parameter
  697. * vs_hidden fixes
  698. * writenode changed to printnode and released from extdebug
  699. * -vp option added to generate a tree.log with the nodetree
  700. * nicer printnode for statements, callnode
  701. Revision 1.46 2002/04/25 20:15:39 florian
  702. * block nodes within expressions shouldn't release the used registers,
  703. fixed using a flag till the new rg is ready
  704. Revision 1.45 2003/04/23 08:41:34 jonas
  705. * fixed ttemprefnode.compare and .getcopy to take offset field into
  706. account
  707. Revision 1.44 2003/04/22 23:50:22 peter
  708. * firstpass uses expectloc
  709. * checks if there are differences between the expectloc and
  710. location.loc from secondpass in EXTDEBUG
  711. Revision 1.43 2003/04/21 15:00:22 jonas
  712. * fixed tstatementnode.det_resulttype and tststatementnode.pass_1
  713. * fixed some getcopy issues with ttemp*nodes
  714. Revision 1.42 2003/04/17 07:50:24 daniel
  715. * Some work on interference graph construction
  716. Revision 1.41 2003/04/12 14:53:59 jonas
  717. * ttempdeletenode.create now sets the nodetype to tempdeleten instead of
  718. temprefn
  719. Revision 1.40 2003/03/17 20:30:46 peter
  720. * errornode.mark_write added
  721. Revision 1.39 2003/01/03 12:15:55 daniel
  722. * Removed ifdefs around notifications
  723. ifdefs around for loop optimizations remain
  724. Revision 1.38 2002/11/27 02:37:12 peter
  725. * case statement inlining added
  726. * fixed inlining of write()
  727. * switched statementnode left and right parts so the statements are
  728. processed in the correct order when getcopy is used. This is
  729. required for tempnodes
  730. Revision 1.37 2002/11/25 17:43:17 peter
  731. * splitted defbase in defutil,symutil,defcmp
  732. * merged isconvertable and is_equal into compare_defs(_ext)
  733. * made operator search faster by walking the list only once
  734. Revision 1.36 2002/10/05 15:15:19 peter
  735. * don't complain in X- mode for internal generated function calls
  736. with funcretrefnode set
  737. * give statement error at the correct line position instead of the
  738. block begin
  739. Revision 1.35 2002/09/01 08:01:16 daniel
  740. * Removed sets from Tcallnode.det_resulttype
  741. + Added read/write notifications of variables. These will be usefull
  742. for providing information for several optimizations. For example
  743. the value of the loop variable of a for loop does matter is the
  744. variable is read after the for loop, but if it's no longer used
  745. or written, it doesn't matter and this can be used to optimize
  746. the loop code generation.
  747. Revision 1.34 2002/08/18 20:06:23 peter
  748. * inlining is now also allowed in interface
  749. * renamed write/load to ppuwrite/ppuload
  750. * tnode storing in ppu
  751. * nld,ncon,nbas are already updated for storing in ppu
  752. Revision 1.33 2002/08/17 22:09:44 florian
  753. * result type handling in tcgcal.pass_2 overhauled
  754. * better tnode.printnodetree
  755. * some ppc stuff fixed
  756. Revision 1.32 2002/08/17 09:23:34 florian
  757. * first part of procinfo rewrite
  758. Revision 1.31 2002/08/15 19:10:35 peter
  759. * first things tai,tnode storing in ppu
  760. Revision 1.30 2002/07/20 11:57:53 florian
  761. * types.pas renamed to defbase.pas because D6 contains a types
  762. unit so this would conflicts if D6 programms are compiled
  763. + Willamette/SSE2 instructions to assembler added
  764. Revision 1.29 2002/07/19 11:41:35 daniel
  765. * State tracker work
  766. * The whilen and repeatn are now completely unified into whilerepeatn. This
  767. allows the state tracker to change while nodes automatically into
  768. repeat nodes.
  769. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  770. 'not(a>b)' is optimized into 'a<=b'.
  771. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  772. by removing the notn and later switchting the true and falselabels. The
  773. same is done with 'repeat until not a'.
  774. Revision 1.28 2002/07/14 18:00:43 daniel
  775. + Added the beginning of a state tracker. This will track the values of
  776. variables through procedures and optimize things away.
  777. Revision 1.27 2002/07/01 18:46:22 peter
  778. * internal linker
  779. * reorganized aasm layer
  780. Revision 1.26 2002/06/24 12:43:00 jonas
  781. * fixed errors found with new -CR code from Peter when cycling with -O2p3r
  782. Revision 1.25 2002/05/18 13:34:09 peter
  783. * readded missing revisions
  784. Revision 1.24 2002/05/16 19:46:37 carl
  785. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  786. + try to fix temp allocation (still in ifdef)
  787. + generic constructor calls
  788. + start of tassembler / tmodulebase class cleanup
  789. Revision 1.22 2002/04/23 19:16:34 peter
  790. * add pinline unit that inserts compiler supported functions using
  791. one or more statements
  792. * moved finalize and setlength from ninl to pinline
  793. Revision 1.21 2002/04/21 19:02:03 peter
  794. * removed newn and disposen nodes, the code is now directly
  795. inlined from pexpr
  796. * -an option that will write the secondpass nodes to the .s file, this
  797. requires EXTDEBUG define to actually write the info
  798. * fixed various internal errors and crashes due recent code changes
  799. Revision 1.20 2002/04/04 19:05:57 peter
  800. * removed unused units
  801. * use tlocation.size in cg.a_*loc*() routines
  802. Revision 1.19 2002/03/31 20:26:33 jonas
  803. + a_loadfpu_* and a_loadmm_* methods in tcg
  804. * register allocation is now handled by a class and is mostly processor
  805. independent (+rgobj.pas and i386/rgcpu.pas)
  806. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  807. * some small improvements and fixes to the optimizer
  808. * some register allocation fixes
  809. * some fpuvaroffset fixes in the unary minus node
  810. * push/popusedregisters is now called rg.save/restoreusedregisters and
  811. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  812. also better optimizable)
  813. * fixed and optimized register saving/restoring for new/dispose nodes
  814. * LOC_FPU locations now also require their "register" field to be set to
  815. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  816. - list field removed of the tnode class because it's not used currently
  817. and can cause hard-to-find bugs
  818. }