nbas.pas 33 KB

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