nbas.pas 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. This unit implements some basic nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nbas;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cgbase,cgutils,
  23. aasmtai,aasmdata,aasmcpu,
  24. node,
  25. symtype;
  26. type
  27. tnothingnode = class(tnode)
  28. constructor create;virtual;
  29. function pass_1 : tnode;override;
  30. function pass_typecheck: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 pass_typecheck:tnode;override;
  37. procedure mark_write;override;
  38. end;
  39. terrornodeclass = class of terrornode;
  40. tspecializenode = class(tunarynode)
  41. sym:tsym;
  42. getaddr:boolean;
  43. inheriteddef:tdef;
  44. constructor create(l:tnode;g:boolean;s:tsym);virtual;
  45. constructor create_inherited(l:tnode;g:boolean;s:tsym;i:tdef);virtual;
  46. function pass_1:tnode;override;
  47. function pass_typecheck:tnode;override;
  48. end;
  49. tspecializenodeclass = class of tspecializenode;
  50. tfinalizetempsnode = class(tnode)
  51. constructor create;virtual;
  52. function pass_1 : tnode;override;
  53. function pass_typecheck:tnode;override;
  54. function docompare(p: tnode): boolean; override;
  55. end;
  56. tfinalizetempsnodeclass = class of tfinalizetempsnode;
  57. tasmnode = class(tnode)
  58. p_asm : TAsmList;
  59. currenttai : tai;
  60. { Used registers in assembler block }
  61. has_registerlist : boolean;
  62. constructor create(p : TAsmList);virtual;
  63. constructor create_get_position;
  64. destructor destroy;override;
  65. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  66. procedure ppuwrite(ppufile:tcompilerppufile);override;
  67. procedure buildderefimpl;override;
  68. procedure derefimpl;override;
  69. function dogetcopy : tnode;override;
  70. function pass_1 : tnode;override;
  71. function pass_typecheck:tnode;override;
  72. function docompare(p: tnode): boolean; override;
  73. end;
  74. tasmnodeclass = class of tasmnode;
  75. tstatementnode = class(tbinarynode)
  76. constructor create(l,r : tnode);virtual;
  77. function simplify(forinline : boolean) : tnode; override;
  78. function pass_1 : tnode;override;
  79. function pass_typecheck:tnode;override;
  80. procedure printnodetree(var t:text);override;
  81. property statement : tnode read left write left;
  82. property next : tnode read right write right;
  83. end;
  84. tstatementnodeclass = class of tstatementnode;
  85. tblocknode = class(tunarynode)
  86. constructor create(l : tnode);virtual;
  87. destructor destroy; override;
  88. function simplify(forinline : boolean) : tnode; override;
  89. function pass_1 : tnode;override;
  90. function pass_typecheck:tnode;override;
  91. {$ifdef state_tracking}
  92. function track_state_pass(exec_known:boolean):boolean;override;
  93. {$endif state_tracking}
  94. property statements : tnode read left write left;
  95. end;
  96. tblocknodeclass = class of tblocknode;
  97. ttempcreatenode = class;
  98. ttempinfoflag = (
  99. { temp can be kept in a register as far as the original creator is
  100. concerned }
  101. ti_may_be_in_reg,
  102. { the ttempcreatenode has been process and the temp's location is
  103. valid (-> the ttempdeletenode has not yet been processed, or
  104. in case it's a "create_to_normal()" one, the final ttemprefnode
  105. has not yet been processed) }
  106. ti_valid,
  107. { when performing a getcopy of a nodetree, we have to hook up the
  108. copies of ttemprefnodes and ttempdestroynode to the copied
  109. ttempinfo. this is done by setting hookoncopy in the original
  110. ttempinfo to point to the new one. if the temp is deleted via a
  111. regular ttempdeletenode, the hookoncopy is simply set to nil once
  112. it's processed. otherwise, it sets the ti_nextref_set_hookoncopy_nil
  113. and after processing the final ttemprefnode, hookoncopy is set to nil
  114. }
  115. ti_nextref_set_hookoncopy_nil,
  116. { the address of this temp is taken (-> cannot be kept in a register,
  117. even if the creator didn't mind)
  118. }
  119. ti_addr_taken,
  120. { temps can get an extra node tree that contains the value to which
  121. they should be initialised when they are created. this initialisation
  122. has to be performed right before the first reference to the temp.
  123. this flag indicates that the ttempcreatenode has been
  124. processed by pass_generate_code, but that the first ttemprefnode
  125. hasn't yet and hence will have to perform the initialisation
  126. }
  127. ti_executeinitialisation,
  128. { in case an expression like "inc(x[func()],1)" is translated into
  129. a regular addition, you have to create a temp to hold the address
  130. representing x[func()], since otherwise func() will be called twice
  131. and that can spell trouble in case it has side effects. on platforms
  132. without pointers, we cannot just take the address though. this flag
  133. has to be combined with ti_executeinitialisation above and will,
  134. rather than loading the value at the calculated location and store
  135. it in the temp, keep a copy of the calculated location if possible
  136. and required (not possible for regvars, because SSA may change their
  137. register, but not required for them either since calculating their
  138. location has no side-effects
  139. }
  140. ti_reference,
  141. { this temp only allows reading (makes it possible to safely use as
  142. reference under more circumstances)
  143. }
  144. ti_readonly,
  145. { if this is a managed temp, it doesn't have to be finalised before use
  146. }
  147. ti_nofini,
  148. { the value described by this temp. node is const/immutable, this is important for
  149. managed types like ansistrings where temp. refs are pointers to the actual value
  150. -- in this case, assignments to the temp do not increase the
  151. reference count, and if the assigned value was a temp itself then
  152. that temp is not deallocated until this temp is deleted (since
  153. otherwise the assigned value may be freed before the last use of
  154. the temp) }
  155. ti_const,
  156. { the temp. needs no final sync instruction if it is located in a register,
  157. so there are no loops involved in the usage of the temp.
  158. }
  159. ti_no_final_regsync,
  160. { this applied only to delete nodes: the single purpose of the temp. delete node is to clean up memory. In case
  161. of cse it might happen that the tempcreate node is optimized away so tempinfo is never initialized properly but
  162. the allocated memory must be disposed
  163. If a temp. node has this flag set, the life time of the temp. data must be determined by reg. life, the temp.
  164. location (in the sense of stack space/register) is never release }
  165. ti_cleanup_only
  166. );
  167. ttempinfoflags = set of ttempinfoflag;
  168. const
  169. tempinfostoreflags = [ti_may_be_in_reg,ti_addr_taken,ti_reference,ti_readonly,ti_no_final_regsync];
  170. type
  171. { to allow access to the location by temp references even after the temp has }
  172. { already been disposed and to make sure the coherency between temps and }
  173. { temp references is kept after a getcopy }
  174. ptempinfo = ^ttempinfo;
  175. ttempinfo = object
  176. private
  177. flags : ttempinfoflags;
  178. public
  179. { set to the copy of a tempcreate pnode (if it gets copied) so that the }
  180. { refs and deletenode can hook to this copy once they get copied too }
  181. hookoncopy : ptempinfo;
  182. typedef : tdef;
  183. typedefderef : tderef;
  184. temptype : ttemptype;
  185. owner : ttempcreatenode;
  186. withnode : tnode;
  187. location : tlocation;
  188. tempinitcode : tnode;
  189. end;
  190. ttempinfoaccessor = class
  191. class procedure settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags); virtual;
  192. class function gettempinfoflags(tempinfo: ptempinfo): ttempinfoflags; static; inline;
  193. end;
  194. ttempinfoaccessorclass = class of ttempinfoaccessor;
  195. ttempbasenode = class(tnode)
  196. protected
  197. class var tempinfoaccessor: ttempinfoaccessorclass;
  198. protected
  199. procedure settempinfoflags(const tempflags: ttempinfoflags); inline;
  200. function gettempinfoflags: ttempinfoflags; inline;
  201. public
  202. tempinfo: ptempinfo;
  203. procedure includetempflag(flag: ttempinfoflag); inline;
  204. procedure excludetempflag(flag: ttempinfoflag); inline;
  205. property tempflags: ttempinfoflags read gettempinfoflags write settempinfoflags;
  206. end;
  207. { a node which will create a (non)persistent temp of a given type with a given }
  208. { size (the size is separate to allow creating "void" temps with a custom size) }
  209. ttempcreatenode = class(ttempbasenode)
  210. size: tcgint;
  211. ftemplvalue : tnode;
  212. { * persistent temps are used in manually written code where the temp }
  213. { be usable among different statements and where you can manually say }
  214. { when the temp has to be freed (using a ttempdeletenode) }
  215. { * non-persistent temps are mostly used in typeconversion helpers, }
  216. { where the node that receives the temp becomes responsible for }
  217. { freeing it. In this last case, you must use only one reference }
  218. { to it and *not* generate a ttempdeletenode }
  219. constructor create(_typedef: tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean); virtual;
  220. constructor create_withnode(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg:boolean; withnode: tnode); virtual;
  221. constructor create_value(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode);
  222. constructor create_reference(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode; readonly: boolean);
  223. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  224. procedure ppuwrite(ppufile:tcompilerppufile);override;
  225. procedure buildderefimpl;override;
  226. procedure derefimpl;override;
  227. function dogetcopy: tnode; override;
  228. function pass_1 : tnode; override;
  229. function pass_typecheck: tnode; override;
  230. function docompare(p: tnode): boolean; override;
  231. procedure printnodedata(var t:text);override;
  232. end;
  233. ttempcreatenodeclass = class of ttempcreatenode;
  234. { a node which is a reference to a certain temp }
  235. ttemprefnode = class(ttempbasenode)
  236. constructor create(const temp: ttempcreatenode); virtual;
  237. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  238. procedure ppuwrite(ppufile:tcompilerppufile);override;
  239. procedure resolveppuidx;override;
  240. function dogetcopy: tnode; override;
  241. function pass_1 : tnode; override;
  242. function pass_typecheck : tnode; override;
  243. procedure mark_write;override;
  244. function docompare(p: tnode): boolean; override;
  245. procedure printnodedata(var t:text);override;
  246. private
  247. tempidx : longint;
  248. end;
  249. ttemprefnodeclass = class of ttemprefnode;
  250. { a node which removes a temp }
  251. ttempdeletenode = class(ttempbasenode)
  252. constructor create(const temp: ttempcreatenode); virtual;
  253. { this will convert the persistant temp to a normal temp
  254. for returning to the other nodes }
  255. constructor create_normal_temp(const temp: ttempcreatenode);
  256. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  257. procedure ppuwrite(ppufile:tcompilerppufile);override;
  258. procedure resolveppuidx;override;
  259. function dogetcopy: tnode; override;
  260. function pass_1: tnode; override;
  261. function pass_typecheck: tnode; override;
  262. function docompare(p: tnode): boolean; override;
  263. destructor destroy; override;
  264. procedure printnodedata(var t:text);override;
  265. protected
  266. release_to_normal : boolean;
  267. private
  268. tempidx : longint;
  269. end;
  270. ttempdeletenodeclass = class of ttempdeletenode;
  271. var
  272. cnothingnode : tnothingnodeclass = tnothingnode;
  273. cerrornode : terrornodeclass = terrornode;
  274. cspecializenode : tspecializenodeclass = tspecializenode;
  275. cfinalizetempsnode: tfinalizetempsnodeclass = tfinalizetempsnode;
  276. casmnode : tasmnodeclass = tasmnode;
  277. cstatementnode : tstatementnodeclass = tstatementnode;
  278. cblocknode : tblocknodeclass = tblocknode;
  279. ctempinfoaccessor : ttempinfoaccessorclass = ttempinfoaccessor;
  280. ctempcreatenode : ttempcreatenodeclass = ttempcreatenode;
  281. ctemprefnode : ttemprefnodeclass = ttemprefnode;
  282. ctempdeletenode : ttempdeletenodeclass = ttempdeletenode;
  283. { Create a blocknode and statement node for multiple statements
  284. generated internally by the parser }
  285. function internalstatements(out laststatement:tstatementnode):tblocknode;
  286. function laststatement(block:tblocknode):tstatementnode;
  287. procedure addstatement(var laststatement:tstatementnode;n:tnode);
  288. { if the complexity of n is "high", creates a reference temp to n's
  289. location and replace n with a ttemprefnode referring to that location }
  290. function maybereplacewithtempref(var n: tnode; var block: tblocknode; var stat: tstatementnode; size: ASizeInt; readonly: boolean): ttempcreatenode;
  291. implementation
  292. uses
  293. verbose,globals,systems,
  294. symconst,symdef,defutil,defcmp,
  295. pass_1,
  296. nutils,nld,
  297. procinfo
  298. ;
  299. {*****************************************************************************
  300. Helpers
  301. *****************************************************************************}
  302. function internalstatements(out laststatement:tstatementnode):tblocknode;
  303. begin
  304. { create dummy initial statement }
  305. laststatement := cstatementnode.create(cnothingnode.create,nil);
  306. internalstatements := cblocknode.create(laststatement);
  307. end;
  308. function laststatement(block:tblocknode):tstatementnode;
  309. begin
  310. result:=tstatementnode(block.left);
  311. while assigned(result) and assigned(result.right) do
  312. result:=tstatementnode(result.right);
  313. end;
  314. procedure addstatement(var laststatement:tstatementnode;n:tnode);
  315. begin
  316. if assigned(laststatement.right) then
  317. internalerror(200204201);
  318. laststatement.right:=cstatementnode.create(n,nil);
  319. laststatement:=tstatementnode(laststatement.right);
  320. end;
  321. function maybereplacewithtempref(var n: tnode; var block: tblocknode; var stat: tstatementnode; size: ASizeInt; readonly: boolean): ttempcreatenode;
  322. begin
  323. result:=nil;
  324. if node_complexity(n) > 4 then
  325. begin
  326. result:=ctempcreatenode.create_reference(n.resultdef,size,tt_persistent,true,n,readonly);
  327. typecheckpass(tnode(result));
  328. n:=ctemprefnode.create(result);
  329. typecheckpass(n);
  330. if not assigned(stat) then
  331. block:=internalstatements(stat);
  332. addstatement(stat,result)
  333. end;
  334. end;
  335. {*****************************************************************************
  336. TFIRSTNOTHING
  337. *****************************************************************************}
  338. constructor tnothingnode.create;
  339. begin
  340. inherited create(nothingn);
  341. end;
  342. function tnothingnode.pass_typecheck:tnode;
  343. begin
  344. result:=nil;
  345. resultdef:=voidtype;
  346. end;
  347. function tnothingnode.pass_1 : tnode;
  348. begin
  349. result:=nil;
  350. expectloc:=LOC_VOID;
  351. end;
  352. {*****************************************************************************
  353. TFIRSTERROR
  354. *****************************************************************************}
  355. constructor terrornode.create;
  356. begin
  357. inherited create(errorn);
  358. end;
  359. function terrornode.pass_typecheck:tnode;
  360. begin
  361. result:=nil;
  362. include(flags,nf_error);
  363. codegenerror:=true;
  364. resultdef:=generrordef;
  365. end;
  366. function terrornode.pass_1 : tnode;
  367. begin
  368. result:=nil;
  369. expectloc:=LOC_VOID;
  370. codegenerror:=true;
  371. end;
  372. procedure terrornode.mark_write;
  373. begin
  374. end;
  375. {*****************************************************************************
  376. TSPECIALIZENODE
  377. *****************************************************************************}
  378. constructor tspecializenode.create(l:tnode;g:boolean;s:tsym);
  379. begin
  380. inherited create(specializen,l);
  381. sym:=s;
  382. getaddr:=g;
  383. end;
  384. constructor tspecializenode.create_inherited(l:tnode;g:boolean;s:tsym;i:tdef);
  385. begin
  386. create(l,g,s);
  387. inheriteddef:=i;
  388. end;
  389. function tspecializenode.pass_typecheck:tnode;
  390. begin
  391. result:=nil;
  392. resultdef:=cundefinedtype;
  393. end;
  394. function tspecializenode.pass_1:tnode;
  395. begin
  396. { such a node should not reach pass_1 }
  397. internalerror(2015071704);
  398. result:=nil;
  399. expectloc:=LOC_VOID;
  400. codegenerror:=true;
  401. end;
  402. {*****************************************************************************
  403. TFINALIZETEMPSNODE
  404. *****************************************************************************}
  405. constructor tfinalizetempsnode.create;
  406. begin
  407. inherited create(finalizetempsn);
  408. end;
  409. function tfinalizetempsnode.pass_1: tnode;
  410. begin
  411. result:=nil;
  412. expectloc:=LOC_VOID;
  413. end;
  414. function tfinalizetempsnode.pass_typecheck: tnode;
  415. begin
  416. resultdef:=voidtype;
  417. result:=nil;
  418. end;
  419. function tfinalizetempsnode.docompare(p: tnode): boolean;
  420. begin
  421. { these nodes should never be coalesced }
  422. result:=false;
  423. end;
  424. {*****************************************************************************
  425. TSTATEMENTNODE
  426. *****************************************************************************}
  427. constructor tstatementnode.create(l,r : tnode);
  428. begin
  429. inherited create(statementn,l,r);
  430. end;
  431. function is_exit_statement(var n: tnode; arg: pointer): foreachnoderesult;
  432. begin
  433. if (n.nodetype<>exitn) then
  434. result:=fen_false
  435. else
  436. result:=fen_norecurse_true;
  437. end;
  438. function no_exit_statement_in_block(n: tnode): boolean;
  439. begin
  440. result:=not foreachnodestatic(n,@is_exit_statement,nil);
  441. end;
  442. function tstatementnode.simplify(forinline: boolean) : tnode;
  443. begin
  444. result:=nil;
  445. { these "optimizations" are only to make it more easy to recognise }
  446. { blocknodes which at the end of inlining only contain one single }
  447. { statement. Simplifying inside blocknode.simplify could be dangerous }
  448. { because if the main blocknode which makes up a procedure/function }
  449. { body were replaced with a statementn/nothingn, this could cause }
  450. { problems elsewhere in the compiler which expects a blocknode }
  451. { remove next statement if it's a nothing-statement (since if it's }
  452. { the last, it won't remove itself -- see next simplification) }
  453. while assigned(right) and
  454. (tstatementnode(right).left.nodetype = nothingn) do
  455. begin
  456. result:=tstatementnode(right).right;
  457. tstatementnode(right).right:=nil;
  458. right.free;
  459. right:=result;
  460. result:=nil;
  461. end;
  462. { Remove initial nothingn if there are other statements. If there }
  463. { are no other statements, returning nil doesn't help (will be }
  464. { interpreted as "can't be simplified") and replacing the }
  465. { statementnode with a nothingnode cannot be done (because it's }
  466. { possible this statementnode is a child of a blocknode, and }
  467. { blocknodes are expected to only contain statementnodes) }
  468. if (left.nodetype = nothingn) and
  469. assigned(right) then
  470. begin
  471. result:=right;
  472. right:=nil;
  473. exit;
  474. end;
  475. { if the current statement contains a block with one statement,
  476. replace the current statement with that block's statement
  477. (but only if the block does not have nf_block_with_exit set
  478. or has no exit statement, because otherwise it needs an own
  479. exit label, see tests/test/tinline10)
  480. Further, it might not be the user code entry
  481. }
  482. if (left.nodetype = blockn) and
  483. ((left.flags*[nf_block_with_exit,nf_usercode_entry]=[]) or
  484. ((left.flags*[nf_block_with_exit,nf_usercode_entry]=[nf_block_with_exit]) and no_exit_statement_in_block(left))) and
  485. assigned(tblocknode(left).left) and
  486. not assigned(tstatementnode(tblocknode(left).left).right) then
  487. begin
  488. result:=tblocknode(left).left;
  489. tstatementnode(result).right:=right;
  490. right:=nil;
  491. tblocknode(left).left:=nil;
  492. exit;
  493. end;
  494. end;
  495. function tstatementnode.pass_typecheck:tnode;
  496. begin
  497. result:=nil;
  498. resultdef:=voidtype;
  499. { left is the statement itself calln assignn or a complex one }
  500. typecheckpass(left);
  501. if codegenerror then
  502. exit;
  503. { right is the next statement in the list }
  504. if assigned(right) then
  505. typecheckpass(right);
  506. if codegenerror then
  507. exit;
  508. end;
  509. function tstatementnode.pass_1 : tnode;
  510. begin
  511. result:=nil;
  512. { left is the statement itself calln assignn or a complex one }
  513. firstpass(left);
  514. if codegenerror then
  515. exit;
  516. expectloc:=left.expectloc;
  517. { right is the next in the list }
  518. if assigned(right) then
  519. firstpass(right);
  520. if codegenerror then
  521. exit;
  522. end;
  523. procedure tstatementnode.printnodetree(var t:text);
  524. begin
  525. printnodelist(t);
  526. end;
  527. {*****************************************************************************
  528. TBLOCKNODE
  529. *****************************************************************************}
  530. constructor tblocknode.create(l : tnode);
  531. begin
  532. inherited create(blockn,l);
  533. end;
  534. destructor tblocknode.destroy;
  535. var
  536. hp, next: tstatementnode;
  537. begin
  538. hp := tstatementnode(left);
  539. left := nil;
  540. while assigned(hp) do
  541. begin
  542. next := tstatementnode(hp.right);
  543. hp.right := nil;
  544. hp.free;
  545. hp := next;
  546. end;
  547. inherited destroy;
  548. end;
  549. function tblocknode.simplify(forinline : boolean): tnode;
  550. begin
  551. result := nil;
  552. { Warning: never replace a blocknode with another node type, }
  553. { since the block may be the main block of a procedure/function/ }
  554. { main program body, and those nodes should always be blocknodes }
  555. { since that's what the compiler expects elsewhere. }
  556. if assigned(left) and
  557. not assigned(tstatementnode(left).right) then
  558. begin
  559. case tstatementnode(left).left.nodetype of
  560. blockn:
  561. begin
  562. { if the current block contains only one statement, and
  563. this one statement only contains another block, replace
  564. this block with that other block. }
  565. result:=tstatementnode(left).left;
  566. tstatementnode(left).left:=nil;
  567. { make sure the nf_block_with_exit flag is safeguarded }
  568. result.flags:=result.flags+(flags*[nf_block_with_exit,nf_usercode_entry]);
  569. exit;
  570. end;
  571. nothingn:
  572. begin
  573. { if the block contains only a statement with a nothing node,
  574. get rid of the statement }
  575. left.Free;
  576. left:=nil;
  577. exit;
  578. end;
  579. end;
  580. end;
  581. end;
  582. function tblocknode.pass_typecheck:tnode;
  583. var
  584. hp : tstatementnode;
  585. begin
  586. result:=nil;
  587. resultdef:=voidtype;
  588. hp:=tstatementnode(left);
  589. while assigned(hp) do
  590. begin
  591. if assigned(hp.left) then
  592. begin
  593. codegenerror:=false;
  594. typecheckpass(hp.left);
  595. { the resultdef of the block is the last type that is
  596. returned. Normally this is a voidtype. But when the
  597. compiler inserts a block of multiple statements then the
  598. last entry can return a value }
  599. resultdef:=hp.left.resultdef;
  600. end;
  601. hp:=tstatementnode(hp.right);
  602. end;
  603. end;
  604. function tblocknode.pass_1 : tnode;
  605. var
  606. hp : tstatementnode;
  607. //count : longint;
  608. begin
  609. result:=nil;
  610. expectloc:=LOC_VOID;
  611. //count:=0;
  612. hp:=tstatementnode(left);
  613. while assigned(hp) do
  614. begin
  615. if assigned(hp.left) then
  616. begin
  617. codegenerror:=false;
  618. firstpass(hp.left);
  619. hp.expectloc:=hp.left.expectloc;
  620. end;
  621. expectloc:=hp.expectloc;
  622. //inc(count);
  623. hp:=tstatementnode(hp.right);
  624. end;
  625. end;
  626. {$ifdef state_tracking}
  627. function Tblocknode.track_state_pass(exec_known:boolean):boolean;
  628. var hp:Tstatementnode;
  629. begin
  630. track_state_pass:=false;
  631. hp:=Tstatementnode(left);
  632. while assigned(hp) do
  633. begin
  634. if hp.left.track_state_pass(exec_known) then
  635. track_state_pass:=true;
  636. hp:=Tstatementnode(hp.right);
  637. end;
  638. end;
  639. {$endif state_tracking}
  640. {*****************************************************************************
  641. TASMNODE
  642. *****************************************************************************}
  643. constructor tasmnode.create(p : TAsmList);
  644. begin
  645. inherited create(asmn);
  646. p_asm:=p;
  647. currenttai:=nil;
  648. end;
  649. constructor tasmnode.create_get_position;
  650. begin
  651. inherited create(asmn);
  652. p_asm:=nil;
  653. include(flags,nf_get_asm_position);
  654. currenttai:=nil;
  655. end;
  656. destructor tasmnode.destroy;
  657. begin
  658. if assigned(p_asm) then
  659. p_asm.free;
  660. inherited destroy;
  661. end;
  662. constructor tasmnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  663. var
  664. hp : tai;
  665. begin
  666. inherited ppuload(t,ppufile);
  667. if not(nf_get_asm_position in flags) then
  668. begin
  669. p_asm:=TAsmList.create;
  670. repeat
  671. hp:=ppuloadai(ppufile);
  672. if hp=nil then
  673. break;
  674. p_asm.concat(hp);
  675. if hp.typ=ait_section then
  676. inc(p_asm.section_count);
  677. until false;
  678. end
  679. else
  680. p_asm:=nil;
  681. currenttai:=nil;
  682. end;
  683. procedure tasmnode.ppuwrite(ppufile:tcompilerppufile);
  684. var
  685. hp : tai;
  686. begin
  687. inherited ppuwrite(ppufile);
  688. { TODO: FIXME Add saving of register sets}
  689. if not(nf_get_asm_position in flags) then
  690. begin
  691. hp:=tai(p_asm.first);
  692. while assigned(hp) do
  693. begin
  694. ppuwriteai(ppufile,hp);
  695. hp:=tai(hp.next);
  696. end;
  697. { end is marked by a nil }
  698. ppuwriteai(ppufile,nil);
  699. end;
  700. end;
  701. procedure tasmnode.buildderefimpl;
  702. var
  703. hp : tai;
  704. begin
  705. inherited buildderefimpl;
  706. if not(nf_get_asm_position in flags) then
  707. begin
  708. hp:=tai(p_asm.first);
  709. while assigned(hp) do
  710. begin
  711. hp.buildderefimpl;
  712. hp:=tai(hp.next);
  713. end;
  714. end;
  715. end;
  716. procedure tasmnode.derefimpl;
  717. var
  718. hp : tai;
  719. begin
  720. inherited derefimpl;
  721. if not(nf_get_asm_position in flags) then
  722. begin
  723. hp:=tai(p_asm.first);
  724. while assigned(hp) do
  725. begin
  726. hp.derefimpl;
  727. hp:=tai(hp.next);
  728. end;
  729. end;
  730. end;
  731. function tasmnode.dogetcopy: tnode;
  732. var
  733. n: tasmnode;
  734. begin
  735. n := tasmnode(inherited dogetcopy);
  736. if assigned(p_asm) then
  737. begin
  738. n.p_asm:=TAsmList.create;
  739. n.p_asm.concatlistcopy(p_asm);
  740. end
  741. else n.p_asm := nil;
  742. n.currenttai:=currenttai;
  743. n.has_registerlist:=has_registerlist;
  744. result:=n;
  745. end;
  746. function tasmnode.pass_typecheck:tnode;
  747. begin
  748. result:=nil;
  749. resultdef:=voidtype;
  750. if not(nf_get_asm_position in flags) then
  751. include(current_procinfo.flags,pi_has_assembler_block);
  752. end;
  753. function tasmnode.pass_1 : tnode;
  754. begin
  755. result:=nil;
  756. expectloc:=LOC_VOID;
  757. end;
  758. function tasmnode.docompare(p: tnode): boolean;
  759. begin
  760. { comparing of asmlists is not implemented (JM) }
  761. docompare := false;
  762. end;
  763. {*****************************************************************************
  764. TEMPBASENODE
  765. *****************************************************************************}
  766. class procedure ttempinfoaccessor.settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags);
  767. begin
  768. tempinfo^.flags:=flags;
  769. end;
  770. class function ttempinfoaccessor.gettempinfoflags(tempinfo: ptempinfo): ttempinfoflags;
  771. begin
  772. result:=tempinfo^.flags;
  773. end;
  774. {*****************************************************************************
  775. TEMPBASENODE
  776. *****************************************************************************}
  777. procedure ttempbasenode.settempinfoflags(const tempflags: ttempinfoflags);
  778. begin
  779. ctempinfoaccessor.settempinfoflags(tempinfo,tempflags);
  780. end;
  781. function ttempbasenode.gettempinfoflags: ttempinfoflags;
  782. begin
  783. result:=ctempinfoaccessor.gettempinfoflags(tempinfo);
  784. end;
  785. procedure ttempbasenode.includetempflag(flag: ttempinfoflag);
  786. begin
  787. { go through settempinfoflags() so it can filter out unsupported tempflags }
  788. settempinfoflags(gettempinfoflags+[flag])
  789. end;
  790. procedure ttempbasenode.excludetempflag(flag: ttempinfoflag);
  791. begin
  792. { go through settempinfoflags() so it can prevent required tempflags from
  793. being removed (if any) }
  794. settempinfoflags(gettempinfoflags-[flag])
  795. end;
  796. {*****************************************************************************
  797. TEMPCREATENODE
  798. *****************************************************************************}
  799. constructor ttempcreatenode.create(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean);
  800. begin
  801. inherited create(tempcreaten);
  802. size := _size;
  803. new(tempinfo);
  804. fillchar(tempinfo^,sizeof(tempinfo^),0);
  805. tempinfo^.typedef := _typedef;
  806. tempinfo^.temptype := _temptype;
  807. tempinfo^.owner := self;
  808. tempinfo^.withnode := nil;
  809. if allowreg and
  810. { temp must fit a single register }
  811. (tstoreddef(_typedef).is_fpuregable or
  812. (tstoreddef(_typedef).is_intregable and
  813. (_size<=TCGSize2Size[OS_64]))) and
  814. { size of register operations must be known }
  815. (def_cgsize(_typedef)<>OS_NO) and
  816. { no init/final needed }
  817. not is_managed_type(_typedef) then
  818. includetempflag(ti_may_be_in_reg);
  819. end;
  820. constructor ttempcreatenode.create_withnode(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg:boolean; withnode: tnode);
  821. begin
  822. self.create(_typedef,_size,_temptype,allowreg);
  823. tempinfo^.withnode:=withnode.getcopy;
  824. end;
  825. constructor ttempcreatenode.create_value(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode);
  826. begin
  827. self.create(_typedef,_size,_temptype,allowreg);
  828. // store in ppuwrite
  829. ftemplvalue:=templvalue;
  830. // create from stored ftemplvalue in ppuload
  831. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  832. end;
  833. constructor ttempcreatenode.create_reference(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg: boolean; templvalue: tnode; readonly: boolean);
  834. begin
  835. // store in ppuwrite
  836. self.create(_typedef,_size,_temptype,allowreg);
  837. ftemplvalue:=templvalue;
  838. // no assignment node, just the tempvalue
  839. tempinfo^.tempinitcode:=ftemplvalue;
  840. includetempflag(ti_reference);
  841. if readonly then
  842. includetempflag(ti_readonly);
  843. end;
  844. function ttempcreatenode.dogetcopy: tnode;
  845. var
  846. n: ttempcreatenode;
  847. begin
  848. n := ttempcreatenode(inherited dogetcopy);
  849. n.size := size;
  850. new(n.tempinfo);
  851. fillchar(n.tempinfo^,sizeof(n.tempinfo^),0);
  852. n.tempinfo^.owner:=n;
  853. n.tempinfo^.typedef := tempinfo^.typedef;
  854. n.tempinfo^.temptype := tempinfo^.temptype;
  855. n.tempflags := tempflags * tempinfostoreflags;
  856. { when the tempinfo has already a hookoncopy then it is not
  857. reset by a tempdeletenode }
  858. if assigned(tempinfo^.hookoncopy) then
  859. internalerror(200211262);
  860. { signal the temprefs that the temp they point to has been copied, }
  861. { so that if the refs get copied as well, they can hook themselves }
  862. { to the copy of the temp }
  863. tempinfo^.hookoncopy := n.tempinfo;
  864. excludetempflag(ti_nextref_set_hookoncopy_nil);
  865. if assigned(tempinfo^.withnode) then
  866. n.tempinfo^.withnode := tempinfo^.withnode.getcopy
  867. else
  868. n.tempinfo^.withnode := nil;
  869. if assigned(tempinfo^.tempinitcode) then
  870. n.tempinfo^.tempinitcode := tempinfo^.tempinitcode.getcopy
  871. else
  872. n.tempinfo^.tempinitcode := nil;
  873. result := n;
  874. end;
  875. constructor ttempcreatenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  876. begin
  877. inherited ppuload(t,ppufile);
  878. size:=ppufile.getlongint;
  879. new(tempinfo);
  880. fillchar(tempinfo^,sizeof(tempinfo^),0);
  881. ppufile.getsmallset(tempinfo^.flags);
  882. ppufile.getderef(tempinfo^.typedefderef);
  883. tempinfo^.temptype := ttemptype(ppufile.getbyte);
  884. tempinfo^.owner:=self;
  885. tempinfo^.withnode:=ppuloadnode(ppufile);
  886. ftemplvalue:=ppuloadnode(ppufile);
  887. end;
  888. procedure ttempcreatenode.ppuwrite(ppufile:tcompilerppufile);
  889. begin
  890. inherited ppuwrite(ppufile);
  891. ppufile.putlongint(size);
  892. ppufile.putsmallset(tempinfo^.flags);
  893. ppufile.putderef(tempinfo^.typedefderef);
  894. ppufile.putbyte(byte(tempinfo^.temptype));
  895. ppuwritenode(ppufile,tempinfo^.withnode);
  896. ppuwritenode(ppufile,ftemplvalue);
  897. end;
  898. procedure ttempcreatenode.buildderefimpl;
  899. begin
  900. inherited buildderefimpl;
  901. tempinfo^.typedefderef.build(tempinfo^.typedef);
  902. if assigned(tempinfo^.withnode) then
  903. tempinfo^.withnode.buildderefimpl;
  904. if assigned(ftemplvalue) then
  905. ftemplvalue.buildderefimpl;
  906. end;
  907. procedure ttempcreatenode.derefimpl;
  908. begin
  909. inherited derefimpl;
  910. tempinfo^.typedef:=tdef(tempinfo^.typedefderef.resolve);
  911. if assigned(tempinfo^.withnode) then
  912. tempinfo^.withnode.derefimpl;
  913. if assigned(ftemplvalue) then
  914. begin
  915. ftemplvalue.derefimpl;
  916. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  917. end;
  918. end;
  919. function ttempcreatenode.pass_1 : tnode;
  920. begin
  921. result := nil;
  922. expectloc:=LOC_VOID;
  923. { temps which are immutable do not need to be initialized/finalized }
  924. if (tempinfo^.typedef.needs_inittable) and not(ti_const in tempflags) then
  925. include(current_procinfo.flags,pi_needs_implicit_finally);
  926. if assigned(tempinfo^.withnode) then
  927. firstpass(tempinfo^.withnode);
  928. if assigned(tempinfo^.tempinitcode) then
  929. firstpass(tempinfo^.tempinitcode);
  930. inc(current_procinfo.estimatedtempsize,size);;
  931. end;
  932. function ttempcreatenode.pass_typecheck: tnode;
  933. begin
  934. result := nil;
  935. { a tempcreatenode doesn't have a resultdef, only temprefnodes do }
  936. resultdef := voidtype;
  937. if assigned(tempinfo^.withnode) then
  938. typecheckpass(tempinfo^.withnode);
  939. if assigned(tempinfo^.tempinitcode) then
  940. typecheckpass(tempinfo^.tempinitcode);
  941. end;
  942. function ttempcreatenode.docompare(p: tnode): boolean;
  943. begin
  944. result :=
  945. inherited docompare(p) and
  946. (ttempcreatenode(p).size = size) and
  947. (ttempcreatenode(p).tempflags*tempinfostoreflags=tempflags*tempinfostoreflags) and
  948. equal_defs(ttempcreatenode(p).tempinfo^.typedef,tempinfo^.typedef) and
  949. (ttempcreatenode(p).tempinfo^.withnode.isequal(tempinfo^.withnode)) and
  950. (ttempcreatenode(p).tempinfo^.tempinitcode.isequal(tempinfo^.tempinitcode));
  951. end;
  952. procedure ttempcreatenode.printnodedata(var t:text);
  953. begin
  954. inherited printnodedata(t);
  955. writeln(t,printnodeindention,'size = ',size,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  956. tempinfo^.typedef.GetTypeName,'", tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  957. writeln(t,printnodeindention,'tempinit =');
  958. printnode(t,tempinfo^.tempinitcode);
  959. end;
  960. {*****************************************************************************
  961. TEMPREFNODE
  962. *****************************************************************************}
  963. constructor ttemprefnode.create(const temp: ttempcreatenode);
  964. begin
  965. inherited create(temprefn);
  966. tempinfo := temp.tempinfo;
  967. end;
  968. function ttemprefnode.dogetcopy: tnode;
  969. var
  970. n: ttemprefnode;
  971. begin
  972. n := ttemprefnode(inherited dogetcopy);
  973. if assigned(tempinfo^.hookoncopy) then
  974. { if the temp has been copied, assume it becomes a new }
  975. { temp which has to be hooked by the copied reference }
  976. begin
  977. { hook the ref to the copied temp }
  978. n.tempinfo := tempinfo^.hookoncopy;
  979. { if we passed a ttempdeletenode that changed the temp }
  980. { from a persistent one into a normal one, we must be }
  981. { the last reference (since our parent should free the }
  982. { temp (JM) }
  983. if (ti_nextref_set_hookoncopy_nil in tempflags) then
  984. tempinfo^.hookoncopy := nil;
  985. end
  986. else
  987. { if the temp we refer to hasn't been copied, assume }
  988. { we're just a new reference to that temp }
  989. begin
  990. n.tempinfo := tempinfo;
  991. end;
  992. if not assigned(n.tempinfo) then
  993. internalerror(2005071901);
  994. result := n;
  995. end;
  996. constructor ttemprefnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  997. begin
  998. inherited ppuload(t,ppufile);
  999. tempidx:=ppufile.getlongint;
  1000. end;
  1001. procedure ttemprefnode.ppuwrite(ppufile:tcompilerppufile);
  1002. begin
  1003. inherited ppuwrite(ppufile);
  1004. ppufile.putlongint(tempinfo^.owner.ppuidx);
  1005. end;
  1006. procedure ttemprefnode.resolveppuidx;
  1007. var
  1008. temp : ttempcreatenode;
  1009. begin
  1010. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  1011. if temp.nodetype<>tempcreaten then
  1012. internalerror(200311075);
  1013. tempinfo:=temp.tempinfo;
  1014. end;
  1015. function ttemprefnode.pass_1 : tnode;
  1016. begin
  1017. expectloc := LOC_REFERENCE;
  1018. if not tempinfo^.typedef.needs_inittable and
  1019. (ti_may_be_in_reg in tempflags) then
  1020. begin
  1021. if tempinfo^.typedef.typ=floatdef then
  1022. begin
  1023. if not use_vectorfpu(tempinfo^.typedef) then
  1024. if (tempinfo^.temptype = tt_persistent) then
  1025. expectloc := LOC_CFPUREGISTER
  1026. else
  1027. expectloc := LOC_FPUREGISTER
  1028. else
  1029. if (tempinfo^.temptype = tt_persistent) then
  1030. expectloc := LOC_CMMREGISTER
  1031. else
  1032. expectloc := LOC_MMREGISTER
  1033. end
  1034. else
  1035. begin
  1036. if (tempinfo^.temptype = tt_persistent) then
  1037. expectloc := LOC_CREGISTER
  1038. else
  1039. expectloc := LOC_REGISTER;
  1040. end;
  1041. end;
  1042. result := nil;
  1043. end;
  1044. function ttemprefnode.pass_typecheck: tnode;
  1045. begin
  1046. { check if the temp is already resultdef passed }
  1047. if not assigned(tempinfo^.typedef) then
  1048. internalerror(200108233);
  1049. result := nil;
  1050. resultdef := tempinfo^.typedef;
  1051. end;
  1052. function ttemprefnode.docompare(p: tnode): boolean;
  1053. begin
  1054. result :=
  1055. inherited docompare(p) and
  1056. (ttemprefnode(p).tempinfo = tempinfo);
  1057. end;
  1058. procedure ttemprefnode.mark_write;
  1059. begin
  1060. include(flags,nf_write);
  1061. end;
  1062. procedure ttemprefnode.printnodedata(var t:text);
  1063. var
  1064. f : ttempinfoflag;
  1065. notfirst : Boolean;
  1066. begin
  1067. inherited printnodedata(t);
  1068. write(t,printnodeindention,'temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1069. tempinfo^.typedef.GetTypeName,'", (tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2),' flags = [');
  1070. notfirst:=false;
  1071. for f in tempinfo^.flags do
  1072. begin
  1073. if notfirst then
  1074. write(t,',');
  1075. write(t,f);
  1076. notfirst:=true;
  1077. end;
  1078. writeln(t,'])');
  1079. end;
  1080. {*****************************************************************************
  1081. TEMPDELETENODE
  1082. *****************************************************************************}
  1083. constructor ttempdeletenode.create(const temp: ttempcreatenode);
  1084. begin
  1085. inherited create(tempdeleten);
  1086. tempinfo := temp.tempinfo;
  1087. release_to_normal := false;
  1088. end;
  1089. constructor ttempdeletenode.create_normal_temp(const temp: ttempcreatenode);
  1090. begin
  1091. inherited create(tempdeleten);
  1092. tempinfo := temp.tempinfo;
  1093. release_to_normal := true;
  1094. if tempinfo^.temptype <> tt_persistent then
  1095. internalerror(200204211);
  1096. end;
  1097. function ttempdeletenode.dogetcopy: tnode;
  1098. var
  1099. n: ttempdeletenode;
  1100. begin
  1101. n:=ttempdeletenode(inherited dogetcopy);
  1102. n.release_to_normal:=release_to_normal;
  1103. if assigned(tempinfo^.hookoncopy) then
  1104. { if the temp has been copied, assume it becomes a new }
  1105. { temp which has to be hooked by the copied deletenode }
  1106. begin
  1107. { hook the tempdeletenode to the copied temp }
  1108. n.tempinfo:=tempinfo^.hookoncopy;
  1109. { the temp shall not be used, reset hookoncopy }
  1110. { Only if release_to_normal is false, otherwise }
  1111. { the temp can still be referenced once more (JM) }
  1112. if (not release_to_normal) then
  1113. tempinfo^.hookoncopy:=nil
  1114. else
  1115. includetempflag(ti_nextref_set_hookoncopy_nil);
  1116. end
  1117. else
  1118. { if the temp we refer to hasn't been copied, we have a }
  1119. { problem since that means we now have two delete nodes }
  1120. { for one temp }
  1121. internalerror(200108234);
  1122. result:=n;
  1123. end;
  1124. constructor ttempdeletenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1125. begin
  1126. inherited ppuload(t,ppufile);
  1127. tempidx:=ppufile.getlongint;
  1128. release_to_normal:=(ppufile.getbyte<>0);
  1129. end;
  1130. procedure ttempdeletenode.ppuwrite(ppufile:tcompilerppufile);
  1131. begin
  1132. inherited ppuwrite(ppufile);
  1133. ppufile.putlongint(tempinfo^.owner.ppuidx);
  1134. ppufile.putbyte(byte(release_to_normal));
  1135. end;
  1136. procedure ttempdeletenode.resolveppuidx;
  1137. var
  1138. temp : ttempcreatenode;
  1139. begin
  1140. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  1141. if temp.nodetype<>tempcreaten then
  1142. internalerror(200311075);
  1143. tempinfo:=temp.tempinfo;
  1144. end;
  1145. function ttempdeletenode.pass_1 : tnode;
  1146. begin
  1147. expectloc:=LOC_VOID;
  1148. result := nil;
  1149. end;
  1150. function ttempdeletenode.pass_typecheck: tnode;
  1151. begin
  1152. result := nil;
  1153. resultdef := voidtype;
  1154. end;
  1155. function ttempdeletenode.docompare(p: tnode): boolean;
  1156. begin
  1157. result :=
  1158. inherited docompare(p) and
  1159. (ttemprefnode(p).tempinfo = tempinfo);
  1160. end;
  1161. destructor ttempdeletenode.destroy;
  1162. begin
  1163. tempinfo^.withnode.free;
  1164. tempinfo^.tempinitcode.free;
  1165. dispose(tempinfo);
  1166. inherited destroy;
  1167. end;
  1168. procedure ttempdeletenode.printnodedata(var t:text);
  1169. begin
  1170. inherited printnodedata(t);
  1171. writeln(t,printnodeindention,'release_to_normal: ',release_to_normal,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1172. tempinfo^.typedef.GetTypeName,'", temptype = ',tempinfo^.temptype,', tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  1173. end;
  1174. end.