nbas.pas 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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. else
  580. ;
  581. end;
  582. end;
  583. end;
  584. function tblocknode.pass_typecheck:tnode;
  585. var
  586. hp : tstatementnode;
  587. begin
  588. result:=nil;
  589. resultdef:=voidtype;
  590. hp:=tstatementnode(left);
  591. while assigned(hp) do
  592. begin
  593. if assigned(hp.left) then
  594. begin
  595. codegenerror:=false;
  596. typecheckpass(hp.left);
  597. { the resultdef of the block is the last type that is
  598. returned. Normally this is a voidtype. But when the
  599. compiler inserts a block of multiple statements then the
  600. last entry can return a value }
  601. resultdef:=hp.left.resultdef;
  602. end;
  603. hp:=tstatementnode(hp.right);
  604. end;
  605. end;
  606. function tblocknode.pass_1 : tnode;
  607. var
  608. hp : tstatementnode;
  609. //count : longint;
  610. begin
  611. result:=nil;
  612. expectloc:=LOC_VOID;
  613. //count:=0;
  614. hp:=tstatementnode(left);
  615. while assigned(hp) do
  616. begin
  617. if assigned(hp.left) then
  618. begin
  619. codegenerror:=false;
  620. firstpass(hp.left);
  621. hp.expectloc:=hp.left.expectloc;
  622. end;
  623. expectloc:=hp.expectloc;
  624. //inc(count);
  625. hp:=tstatementnode(hp.right);
  626. end;
  627. end;
  628. {$ifdef state_tracking}
  629. function Tblocknode.track_state_pass(exec_known:boolean):boolean;
  630. var hp:Tstatementnode;
  631. begin
  632. track_state_pass:=false;
  633. hp:=Tstatementnode(left);
  634. while assigned(hp) do
  635. begin
  636. if hp.left.track_state_pass(exec_known) then
  637. track_state_pass:=true;
  638. hp:=Tstatementnode(hp.right);
  639. end;
  640. end;
  641. {$endif state_tracking}
  642. {*****************************************************************************
  643. TASMNODE
  644. *****************************************************************************}
  645. constructor tasmnode.create(p : TAsmList);
  646. begin
  647. inherited create(asmn);
  648. p_asm:=p;
  649. currenttai:=nil;
  650. end;
  651. constructor tasmnode.create_get_position;
  652. begin
  653. inherited create(asmn);
  654. p_asm:=nil;
  655. include(flags,nf_get_asm_position);
  656. currenttai:=nil;
  657. end;
  658. destructor tasmnode.destroy;
  659. begin
  660. if assigned(p_asm) then
  661. p_asm.free;
  662. inherited destroy;
  663. end;
  664. constructor tasmnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  665. var
  666. hp : tai;
  667. begin
  668. inherited ppuload(t,ppufile);
  669. if not(nf_get_asm_position in flags) then
  670. begin
  671. p_asm:=TAsmList.create;
  672. repeat
  673. hp:=ppuloadai(ppufile);
  674. if hp=nil then
  675. break;
  676. p_asm.concat(hp);
  677. if hp.typ=ait_section then
  678. inc(p_asm.section_count);
  679. until false;
  680. end
  681. else
  682. p_asm:=nil;
  683. currenttai:=nil;
  684. end;
  685. procedure tasmnode.ppuwrite(ppufile:tcompilerppufile);
  686. var
  687. hp : tai;
  688. begin
  689. inherited ppuwrite(ppufile);
  690. { TODO: FIXME Add saving of register sets}
  691. if not(nf_get_asm_position in flags) then
  692. begin
  693. hp:=tai(p_asm.first);
  694. while assigned(hp) do
  695. begin
  696. ppuwriteai(ppufile,hp);
  697. hp:=tai(hp.next);
  698. end;
  699. { end is marked by a nil }
  700. ppuwriteai(ppufile,nil);
  701. end;
  702. end;
  703. procedure tasmnode.buildderefimpl;
  704. var
  705. hp : tai;
  706. begin
  707. inherited buildderefimpl;
  708. if not(nf_get_asm_position in flags) then
  709. begin
  710. hp:=tai(p_asm.first);
  711. while assigned(hp) do
  712. begin
  713. hp.buildderefimpl;
  714. hp:=tai(hp.next);
  715. end;
  716. end;
  717. end;
  718. procedure tasmnode.derefimpl;
  719. var
  720. hp : tai;
  721. begin
  722. inherited derefimpl;
  723. if not(nf_get_asm_position in flags) then
  724. begin
  725. hp:=tai(p_asm.first);
  726. while assigned(hp) do
  727. begin
  728. hp.derefimpl;
  729. hp:=tai(hp.next);
  730. end;
  731. end;
  732. end;
  733. function tasmnode.dogetcopy: tnode;
  734. var
  735. n: tasmnode;
  736. begin
  737. n := tasmnode(inherited dogetcopy);
  738. if assigned(p_asm) then
  739. begin
  740. n.p_asm:=TAsmList.create;
  741. n.p_asm.concatlistcopy(p_asm);
  742. end
  743. else n.p_asm := nil;
  744. n.currenttai:=currenttai;
  745. n.has_registerlist:=has_registerlist;
  746. result:=n;
  747. end;
  748. function tasmnode.pass_typecheck:tnode;
  749. begin
  750. result:=nil;
  751. resultdef:=voidtype;
  752. if not(nf_get_asm_position in flags) then
  753. include(current_procinfo.flags,pi_has_assembler_block);
  754. end;
  755. function tasmnode.pass_1 : tnode;
  756. begin
  757. result:=nil;
  758. expectloc:=LOC_VOID;
  759. end;
  760. function tasmnode.docompare(p: tnode): boolean;
  761. begin
  762. { comparing of asmlists is not implemented (JM) }
  763. docompare := false;
  764. end;
  765. {*****************************************************************************
  766. TEMPBASENODE
  767. *****************************************************************************}
  768. class procedure ttempinfoaccessor.settempinfoflags(tempinfo: ptempinfo; const flags: ttempinfoflags);
  769. begin
  770. tempinfo^.flags:=flags;
  771. end;
  772. class function ttempinfoaccessor.gettempinfoflags(tempinfo: ptempinfo): ttempinfoflags;
  773. begin
  774. result:=tempinfo^.flags;
  775. end;
  776. {*****************************************************************************
  777. TEMPBASENODE
  778. *****************************************************************************}
  779. procedure ttempbasenode.settempinfoflags(const tempflags: ttempinfoflags);
  780. begin
  781. ctempinfoaccessor.settempinfoflags(tempinfo,tempflags);
  782. end;
  783. function ttempbasenode.gettempinfoflags: ttempinfoflags;
  784. begin
  785. result:=ctempinfoaccessor.gettempinfoflags(tempinfo);
  786. end;
  787. procedure ttempbasenode.includetempflag(flag: ttempinfoflag);
  788. begin
  789. { go through settempinfoflags() so it can filter out unsupported tempflags }
  790. settempinfoflags(gettempinfoflags+[flag])
  791. end;
  792. procedure ttempbasenode.excludetempflag(flag: ttempinfoflag);
  793. begin
  794. { go through settempinfoflags() so it can prevent required tempflags from
  795. being removed (if any) }
  796. settempinfoflags(gettempinfoflags-[flag])
  797. end;
  798. {*****************************************************************************
  799. TEMPCREATENODE
  800. *****************************************************************************}
  801. constructor ttempcreatenode.create(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean);
  802. begin
  803. inherited create(tempcreaten);
  804. size := _size;
  805. new(tempinfo);
  806. fillchar(tempinfo^,sizeof(tempinfo^),0);
  807. tempinfo^.typedef := _typedef;
  808. tempinfo^.temptype := _temptype;
  809. tempinfo^.owner := self;
  810. tempinfo^.withnode := nil;
  811. if allowreg and
  812. { temp must fit a single register }
  813. (tstoreddef(_typedef).is_fpuregable or
  814. (tstoreddef(_typedef).is_intregable and
  815. (_size<=TCGSize2Size[OS_64]))) and
  816. { size of register operations must be known }
  817. (def_cgsize(_typedef)<>OS_NO) and
  818. { no init/final needed }
  819. not is_managed_type(_typedef) then
  820. includetempflag(ti_may_be_in_reg);
  821. end;
  822. constructor ttempcreatenode.create_withnode(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg:boolean; withnode: tnode);
  823. begin
  824. self.create(_typedef,_size,_temptype,allowreg);
  825. tempinfo^.withnode:=withnode.getcopy;
  826. end;
  827. constructor ttempcreatenode.create_value(_typedef:tdef; _size: tcgint; _temptype: ttemptype;allowreg:boolean; templvalue: tnode);
  828. begin
  829. self.create(_typedef,_size,_temptype,allowreg);
  830. // store in ppuwrite
  831. ftemplvalue:=templvalue;
  832. // create from stored ftemplvalue in ppuload
  833. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  834. end;
  835. constructor ttempcreatenode.create_reference(_typedef: tdef; _size: tcgint; _temptype: ttemptype; allowreg: boolean; templvalue: tnode; readonly: boolean);
  836. begin
  837. // store in ppuwrite
  838. self.create(_typedef,_size,_temptype,allowreg);
  839. ftemplvalue:=templvalue;
  840. // no assignment node, just the tempvalue
  841. tempinfo^.tempinitcode:=ftemplvalue;
  842. includetempflag(ti_reference);
  843. if readonly then
  844. includetempflag(ti_readonly);
  845. end;
  846. function ttempcreatenode.dogetcopy: tnode;
  847. var
  848. n: ttempcreatenode;
  849. begin
  850. n := ttempcreatenode(inherited dogetcopy);
  851. n.size := size;
  852. new(n.tempinfo);
  853. fillchar(n.tempinfo^,sizeof(n.tempinfo^),0);
  854. n.tempinfo^.owner:=n;
  855. n.tempinfo^.typedef := tempinfo^.typedef;
  856. n.tempinfo^.temptype := tempinfo^.temptype;
  857. n.tempflags := tempflags * tempinfostoreflags;
  858. { when the tempinfo has already a hookoncopy then it is not
  859. reset by a tempdeletenode }
  860. if assigned(tempinfo^.hookoncopy) then
  861. internalerror(200211262);
  862. { signal the temprefs that the temp they point to has been copied, }
  863. { so that if the refs get copied as well, they can hook themselves }
  864. { to the copy of the temp }
  865. tempinfo^.hookoncopy := n.tempinfo;
  866. excludetempflag(ti_nextref_set_hookoncopy_nil);
  867. if assigned(tempinfo^.withnode) then
  868. n.tempinfo^.withnode := tempinfo^.withnode.getcopy
  869. else
  870. n.tempinfo^.withnode := nil;
  871. if assigned(tempinfo^.tempinitcode) then
  872. n.tempinfo^.tempinitcode := tempinfo^.tempinitcode.getcopy
  873. else
  874. n.tempinfo^.tempinitcode := nil;
  875. result := n;
  876. end;
  877. constructor ttempcreatenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  878. begin
  879. inherited ppuload(t,ppufile);
  880. size:=ppufile.getlongint;
  881. new(tempinfo);
  882. fillchar(tempinfo^,sizeof(tempinfo^),0);
  883. ppufile.getsmallset(tempinfo^.flags);
  884. ppufile.getderef(tempinfo^.typedefderef);
  885. tempinfo^.temptype := ttemptype(ppufile.getbyte);
  886. tempinfo^.owner:=self;
  887. tempinfo^.withnode:=ppuloadnode(ppufile);
  888. ftemplvalue:=ppuloadnode(ppufile);
  889. end;
  890. procedure ttempcreatenode.ppuwrite(ppufile:tcompilerppufile);
  891. begin
  892. inherited ppuwrite(ppufile);
  893. ppufile.putlongint(size);
  894. ppufile.putsmallset(tempinfo^.flags);
  895. ppufile.putderef(tempinfo^.typedefderef);
  896. ppufile.putbyte(byte(tempinfo^.temptype));
  897. ppuwritenode(ppufile,tempinfo^.withnode);
  898. ppuwritenode(ppufile,ftemplvalue);
  899. end;
  900. procedure ttempcreatenode.buildderefimpl;
  901. begin
  902. inherited buildderefimpl;
  903. tempinfo^.typedefderef.build(tempinfo^.typedef);
  904. if assigned(tempinfo^.withnode) then
  905. tempinfo^.withnode.buildderefimpl;
  906. if assigned(ftemplvalue) then
  907. ftemplvalue.buildderefimpl;
  908. end;
  909. procedure ttempcreatenode.derefimpl;
  910. begin
  911. inherited derefimpl;
  912. tempinfo^.typedef:=tdef(tempinfo^.typedefderef.resolve);
  913. if assigned(tempinfo^.withnode) then
  914. tempinfo^.withnode.derefimpl;
  915. if assigned(ftemplvalue) then
  916. begin
  917. ftemplvalue.derefimpl;
  918. tempinfo^.tempinitcode:=cassignmentnode.create(ctemprefnode.create(self),ftemplvalue);
  919. end;
  920. end;
  921. function ttempcreatenode.pass_1 : tnode;
  922. begin
  923. result := nil;
  924. expectloc:=LOC_VOID;
  925. { temps which are immutable do not need to be initialized/finalized }
  926. if (tempinfo^.typedef.needs_inittable) and not(ti_const in tempflags) then
  927. include(current_procinfo.flags,pi_needs_implicit_finally);
  928. if assigned(tempinfo^.withnode) then
  929. firstpass(tempinfo^.withnode);
  930. if assigned(tempinfo^.tempinitcode) then
  931. firstpass(tempinfo^.tempinitcode);
  932. inc(current_procinfo.estimatedtempsize,size);;
  933. end;
  934. function ttempcreatenode.pass_typecheck: tnode;
  935. begin
  936. result := nil;
  937. { a tempcreatenode doesn't have a resultdef, only temprefnodes do }
  938. resultdef := voidtype;
  939. if assigned(tempinfo^.withnode) then
  940. typecheckpass(tempinfo^.withnode);
  941. if assigned(tempinfo^.tempinitcode) then
  942. typecheckpass(tempinfo^.tempinitcode);
  943. end;
  944. function ttempcreatenode.docompare(p: tnode): boolean;
  945. begin
  946. result :=
  947. inherited docompare(p) and
  948. (ttempcreatenode(p).size = size) and
  949. (ttempcreatenode(p).tempflags*tempinfostoreflags=tempflags*tempinfostoreflags) and
  950. equal_defs(ttempcreatenode(p).tempinfo^.typedef,tempinfo^.typedef) and
  951. (ttempcreatenode(p).tempinfo^.withnode.isequal(tempinfo^.withnode)) and
  952. (ttempcreatenode(p).tempinfo^.tempinitcode.isequal(tempinfo^.tempinitcode));
  953. end;
  954. procedure ttempcreatenode.printnodedata(var t:text);
  955. begin
  956. inherited printnodedata(t);
  957. writeln(t,printnodeindention,'size = ',size,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  958. tempinfo^.typedef.GetTypeName,'", tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  959. writeln(t,printnodeindention,'tempinit =');
  960. printnode(t,tempinfo^.tempinitcode);
  961. end;
  962. {*****************************************************************************
  963. TEMPREFNODE
  964. *****************************************************************************}
  965. constructor ttemprefnode.create(const temp: ttempcreatenode);
  966. begin
  967. inherited create(temprefn);
  968. tempinfo := temp.tempinfo;
  969. end;
  970. function ttemprefnode.dogetcopy: tnode;
  971. var
  972. n: ttemprefnode;
  973. begin
  974. n := ttemprefnode(inherited dogetcopy);
  975. if assigned(tempinfo^.hookoncopy) then
  976. { if the temp has been copied, assume it becomes a new }
  977. { temp which has to be hooked by the copied reference }
  978. begin
  979. { hook the ref to the copied temp }
  980. n.tempinfo := tempinfo^.hookoncopy;
  981. { if we passed a ttempdeletenode that changed the temp }
  982. { from a persistent one into a normal one, we must be }
  983. { the last reference (since our parent should free the }
  984. { temp (JM) }
  985. if (ti_nextref_set_hookoncopy_nil in tempflags) then
  986. tempinfo^.hookoncopy := nil;
  987. end
  988. else
  989. { if the temp we refer to hasn't been copied, assume }
  990. { we're just a new reference to that temp }
  991. begin
  992. n.tempinfo := tempinfo;
  993. end;
  994. if not assigned(n.tempinfo) then
  995. internalerror(2005071901);
  996. result := n;
  997. end;
  998. constructor ttemprefnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  999. begin
  1000. inherited ppuload(t,ppufile);
  1001. tempidx:=ppufile.getlongint;
  1002. end;
  1003. procedure ttemprefnode.ppuwrite(ppufile:tcompilerppufile);
  1004. begin
  1005. inherited ppuwrite(ppufile);
  1006. ppufile.putlongint(tempinfo^.owner.ppuidx);
  1007. end;
  1008. procedure ttemprefnode.resolveppuidx;
  1009. var
  1010. temp : ttempcreatenode;
  1011. begin
  1012. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  1013. if temp.nodetype<>tempcreaten then
  1014. internalerror(200311075);
  1015. tempinfo:=temp.tempinfo;
  1016. end;
  1017. function ttemprefnode.pass_1 : tnode;
  1018. begin
  1019. expectloc := LOC_REFERENCE;
  1020. if not tempinfo^.typedef.needs_inittable and
  1021. (ti_may_be_in_reg in tempflags) then
  1022. begin
  1023. if tempinfo^.typedef.typ=floatdef then
  1024. begin
  1025. if not use_vectorfpu(tempinfo^.typedef) then
  1026. if (tempinfo^.temptype = tt_persistent) then
  1027. expectloc := LOC_CFPUREGISTER
  1028. else
  1029. expectloc := LOC_FPUREGISTER
  1030. else
  1031. if (tempinfo^.temptype = tt_persistent) then
  1032. expectloc := LOC_CMMREGISTER
  1033. else
  1034. expectloc := LOC_MMREGISTER
  1035. end
  1036. else
  1037. begin
  1038. if (tempinfo^.temptype = tt_persistent) then
  1039. expectloc := LOC_CREGISTER
  1040. else
  1041. expectloc := LOC_REGISTER;
  1042. end;
  1043. end;
  1044. result := nil;
  1045. end;
  1046. function ttemprefnode.pass_typecheck: tnode;
  1047. begin
  1048. { check if the temp is already resultdef passed }
  1049. if not assigned(tempinfo^.typedef) then
  1050. internalerror(200108233);
  1051. result := nil;
  1052. resultdef := tempinfo^.typedef;
  1053. end;
  1054. function ttemprefnode.docompare(p: tnode): boolean;
  1055. begin
  1056. result :=
  1057. inherited docompare(p) and
  1058. (ttemprefnode(p).tempinfo = tempinfo);
  1059. end;
  1060. procedure ttemprefnode.mark_write;
  1061. begin
  1062. include(flags,nf_write);
  1063. end;
  1064. procedure ttemprefnode.printnodedata(var t:text);
  1065. var
  1066. f : ttempinfoflag;
  1067. notfirst : Boolean;
  1068. begin
  1069. inherited printnodedata(t);
  1070. write(t,printnodeindention,'temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1071. tempinfo^.typedef.GetTypeName,'", (tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2),' flags = [');
  1072. notfirst:=false;
  1073. for f in tempinfo^.flags do
  1074. begin
  1075. if notfirst then
  1076. write(t,',');
  1077. write(t,f);
  1078. notfirst:=true;
  1079. end;
  1080. writeln(t,'])');
  1081. end;
  1082. {*****************************************************************************
  1083. TEMPDELETENODE
  1084. *****************************************************************************}
  1085. constructor ttempdeletenode.create(const temp: ttempcreatenode);
  1086. begin
  1087. inherited create(tempdeleten);
  1088. tempinfo := temp.tempinfo;
  1089. release_to_normal := false;
  1090. end;
  1091. constructor ttempdeletenode.create_normal_temp(const temp: ttempcreatenode);
  1092. begin
  1093. inherited create(tempdeleten);
  1094. tempinfo := temp.tempinfo;
  1095. release_to_normal := true;
  1096. if tempinfo^.temptype <> tt_persistent then
  1097. internalerror(200204211);
  1098. end;
  1099. function ttempdeletenode.dogetcopy: tnode;
  1100. var
  1101. n: ttempdeletenode;
  1102. begin
  1103. n:=ttempdeletenode(inherited dogetcopy);
  1104. n.release_to_normal:=release_to_normal;
  1105. if assigned(tempinfo^.hookoncopy) then
  1106. { if the temp has been copied, assume it becomes a new }
  1107. { temp which has to be hooked by the copied deletenode }
  1108. begin
  1109. { hook the tempdeletenode to the copied temp }
  1110. n.tempinfo:=tempinfo^.hookoncopy;
  1111. { the temp shall not be used, reset hookoncopy }
  1112. { Only if release_to_normal is false, otherwise }
  1113. { the temp can still be referenced once more (JM) }
  1114. if (not release_to_normal) then
  1115. tempinfo^.hookoncopy:=nil
  1116. else
  1117. includetempflag(ti_nextref_set_hookoncopy_nil);
  1118. end
  1119. else
  1120. { if the temp we refer to hasn't been copied, we have a }
  1121. { problem since that means we now have two delete nodes }
  1122. { for one temp }
  1123. internalerror(200108234);
  1124. result:=n;
  1125. end;
  1126. constructor ttempdeletenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1127. begin
  1128. inherited ppuload(t,ppufile);
  1129. tempidx:=ppufile.getlongint;
  1130. release_to_normal:=(ppufile.getbyte<>0);
  1131. end;
  1132. procedure ttempdeletenode.ppuwrite(ppufile:tcompilerppufile);
  1133. begin
  1134. inherited ppuwrite(ppufile);
  1135. ppufile.putlongint(tempinfo^.owner.ppuidx);
  1136. ppufile.putbyte(byte(release_to_normal));
  1137. end;
  1138. procedure ttempdeletenode.resolveppuidx;
  1139. var
  1140. temp : ttempcreatenode;
  1141. begin
  1142. temp:=ttempcreatenode(nodeppuidxget(tempidx));
  1143. if temp.nodetype<>tempcreaten then
  1144. internalerror(200311075);
  1145. tempinfo:=temp.tempinfo;
  1146. end;
  1147. function ttempdeletenode.pass_1 : tnode;
  1148. begin
  1149. expectloc:=LOC_VOID;
  1150. result := nil;
  1151. end;
  1152. function ttempdeletenode.pass_typecheck: tnode;
  1153. begin
  1154. result := nil;
  1155. resultdef := voidtype;
  1156. end;
  1157. function ttempdeletenode.docompare(p: tnode): boolean;
  1158. begin
  1159. result :=
  1160. inherited docompare(p) and
  1161. (ttemprefnode(p).tempinfo = tempinfo);
  1162. end;
  1163. destructor ttempdeletenode.destroy;
  1164. begin
  1165. tempinfo^.withnode.free;
  1166. tempinfo^.tempinitcode.free;
  1167. dispose(tempinfo);
  1168. inherited destroy;
  1169. end;
  1170. procedure ttempdeletenode.printnodedata(var t:text);
  1171. begin
  1172. inherited printnodedata(t);
  1173. writeln(t,printnodeindention,'release_to_normal: ',release_to_normal,', temptypedef = ',tempinfo^.typedef.typesymbolprettyname,' = "',
  1174. tempinfo^.typedef.GetTypeName,'", temptype = ',tempinfo^.temptype,', tempinfo = $',hexstr(ptrint(tempinfo),sizeof(ptrint)*2));
  1175. end;
  1176. end.