nbas.pas 47 KB

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