ncgcal.pas 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate assembler for call nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncgcal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. globtype,
  24. symdef,node,ncal;
  25. type
  26. tcgcallparanode = class(tcallparanode)
  27. private
  28. tempparaloc : tparalocation;
  29. procedure allocate_tempparaloc;
  30. procedure push_addr_para;
  31. procedure push_value_para;
  32. public
  33. procedure secondcallparan;override;
  34. end;
  35. tcgcallnode = class(tcallnode)
  36. private
  37. procedure release_para_temps;
  38. procedure normal_pass_2;
  39. procedure inlined_pass_2;
  40. protected
  41. { save the size of pushed parameter, needed po_clearstack
  42. and alignment }
  43. pushedparasize : longint;
  44. framepointer_paraloc : tparalocation;
  45. refcountedtemp : treference;
  46. procedure handle_return_value;
  47. {# This routine is used to push the current frame pointer
  48. on the stack. This is used in nested routines where the
  49. value of the frame pointer is always pushed as an extra
  50. parameter.
  51. The default handling is the standard handling used on
  52. most stack based machines, where the frame pointer is
  53. the first invisible parameter.
  54. }
  55. function align_parasize:longint;virtual;
  56. procedure pop_parasize(pop_size:longint);virtual;
  57. procedure extra_interrupt_code;virtual;
  58. procedure extra_call_code;virtual;
  59. procedure do_syscall;virtual;abstract;
  60. public
  61. procedure pass_2;override;
  62. end;
  63. implementation
  64. uses
  65. systems,
  66. cutils,verbose,globals,
  67. symconst,symsym,symtable,defutil,paramgr,
  68. {$ifdef GDB}
  69. {$ifdef delphi}
  70. sysutils,
  71. {$else}
  72. strings,
  73. {$endif}
  74. gdb,
  75. {$endif GDB}
  76. cgbase,pass_2,
  77. cpuinfo,aasmbase,aasmtai,
  78. nbas,nmem,nld,ncnv,nutils,
  79. {$ifdef x86}
  80. cga,cgx86,
  81. {$endif x86}
  82. ncgutil,
  83. cgutils,cgobj,tgobj,
  84. procinfo;
  85. {*****************************************************************************
  86. TCGCALLPARANODE
  87. *****************************************************************************}
  88. procedure tcgcallparanode.allocate_tempparaloc;
  89. begin
  90. { Allocate (temporary) paralocation }
  91. tempparaloc:=paraitem.paraloc[callerside];
  92. case tempparaloc.loc of
  93. LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER:
  94. paramanager.alloctempregs(exprasmlist,tempparaloc);
  95. {$ifdef cputargethasfixedstack}
  96. LOC_REFERENCE:
  97. begin
  98. { currently, we copy the value always to a secure location }
  99. if not(assigned(aktcallnode.inlinecode)) then
  100. paramanager.alloctempparaloc(exprasmlist,aktcallnode.procdefinition.proccalloption,paraitem,tempparaloc);
  101. end;
  102. {$endif cputargethasfixedstack}
  103. end;
  104. end;
  105. procedure tcgcallparanode.push_addr_para;
  106. begin
  107. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  108. internalerror(200304235);
  109. location_release(exprasmlist,left.location);
  110. cg.a_paramaddr_ref(exprasmlist,left.location.reference,tempparaloc);
  111. inc(tcgcallnode(aktcallnode).pushedparasize,POINTER_SIZE);
  112. end;
  113. procedure tcgcallparanode.push_value_para;
  114. var
  115. href : treference;
  116. size : longint;
  117. cgsize : tcgsize;
  118. begin
  119. { we've nothing to push when the size of the parameter is 0 }
  120. if left.resulttype.def.size=0 then
  121. exit;
  122. { Move flags and jump in register to make it less complex }
  123. if left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  124. location_force_reg(exprasmlist,left.location,def_cgsize(left.resulttype.def),false);
  125. { Handle Floating point types differently }
  126. if left.resulttype.def.deftype=floatdef then
  127. begin
  128. location_release(exprasmlist,left.location);
  129. {$ifdef i386}
  130. if tempparaloc.loc<>LOC_REFERENCE then
  131. internalerror(200309291);
  132. case left.location.loc of
  133. LOC_FPUREGISTER,
  134. LOC_CFPUREGISTER:
  135. begin
  136. size:=align(TCGSize2Size[left.location.size],tempparaloc.alignment);
  137. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  138. if tempparaloc.reference.index=NR_STACK_POINTER_REG then
  139. begin
  140. cg.g_stackpointer_alloc(exprasmlist,size);
  141. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  142. end
  143. else
  144. reference_reset_base(href,tempparaloc.reference.index,tempparaloc.reference.offset);
  145. cg.a_loadfpu_reg_ref(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,href);
  146. end;
  147. LOC_MMREGISTER,
  148. LOC_CMMREGISTER:
  149. begin
  150. size:=align(tfloatdef(left.resulttype.def).size,tempparaloc.alignment);
  151. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  152. if tempparaloc.reference.index=NR_STACK_POINTER_REG then
  153. begin
  154. cg.g_stackpointer_alloc(exprasmlist,size);
  155. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  156. end
  157. else
  158. reference_reset_base(href,tempparaloc.reference.index,tempparaloc.reference.offset);
  159. cg.a_loadmm_reg_ref(exprasmlist,def_cgsize(left.resulttype.def),def_cgsize(left.resulttype.def),left.location.register,href,mms_movescalar);
  160. end;
  161. LOC_REFERENCE,
  162. LOC_CREFERENCE :
  163. begin
  164. size:=align(left.resulttype.def.size,tempparaloc.alignment);
  165. if tempparaloc.reference.index=NR_STACK_POINTER_REG then
  166. begin
  167. href:=left.location.reference;
  168. inc(href.offset,size);
  169. while (size>0) do
  170. begin
  171. if (size>=4) or (tempparaloc.alignment>=4) then
  172. begin
  173. cgsize:=OS_32;
  174. inc(tcgcallnode(aktcallnode).pushedparasize,4);
  175. dec(href.offset,4);
  176. dec(size,4);
  177. end
  178. else
  179. begin
  180. cgsize:=OS_16;
  181. inc(tcgcallnode(aktcallnode).pushedparasize,2);
  182. dec(href.offset,2);
  183. dec(size,2);
  184. end;
  185. cg.a_param_ref(exprasmlist,cgsize,href,tempparaloc);
  186. end;
  187. end
  188. else
  189. begin
  190. reference_reset_base(href,tempparaloc.reference.index,tempparaloc.reference.offset);
  191. cg.g_concatcopy(exprasmlist,left.location.reference,href,size,false,false);
  192. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  193. end;
  194. end;
  195. else
  196. internalerror(2002042430);
  197. end;
  198. {$else i386}
  199. case left.location.loc of
  200. LOC_MMREGISTER,
  201. LOC_CMMREGISTER:
  202. case tempparaloc.loc of
  203. LOC_REFERENCE,
  204. LOC_CREFERENCE,
  205. LOC_MMREGISTER,
  206. LOC_CMMREGISTER:
  207. cg.a_parammm_reg(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,tempparaloc,mms_movescalar);
  208. LOC_FPUREGISTER,
  209. LOC_CFPUREGISTER:
  210. begin
  211. location_force_fpureg(exprasmlist,left.location,false);
  212. cg.a_paramfpu_reg(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,tempparaloc);
  213. end;
  214. else
  215. internalerror(2002042433);
  216. end;
  217. LOC_FPUREGISTER,
  218. LOC_CFPUREGISTER:
  219. case tempparaloc.loc of
  220. LOC_MMREGISTER,
  221. LOC_CMMREGISTER:
  222. begin
  223. location_force_mmregscalar(exprasmlist,left.location,false);
  224. cg.a_parammm_reg(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,tempparaloc,mms_movescalar);
  225. end;
  226. {$ifdef sparc}
  227. { sparc pushes floats in normal registers }
  228. LOC_REGISTER,
  229. LOC_CREGISTER,
  230. {$endif sparc}
  231. LOC_REFERENCE,
  232. LOC_CREFERENCE,
  233. LOC_FPUREGISTER,
  234. LOC_CFPUREGISTER:
  235. cg.a_paramfpu_reg(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,tempparaloc);
  236. else
  237. internalerror(2002042433);
  238. end;
  239. LOC_REFERENCE,
  240. LOC_CREFERENCE:
  241. case tempparaloc.loc of
  242. LOC_MMREGISTER,
  243. LOC_CMMREGISTER:
  244. cg.a_parammm_ref(exprasmlist,def_cgsize(left.resulttype.def),left.location.reference,tempparaloc,mms_movescalar);
  245. {$ifdef sparc}
  246. { sparc pushes floats in normal registers }
  247. LOC_REGISTER,
  248. LOC_CREGISTER,
  249. {$endif sparc}
  250. LOC_REFERENCE,
  251. LOC_CREFERENCE,
  252. LOC_FPUREGISTER,
  253. LOC_CFPUREGISTER:
  254. cg.a_paramfpu_ref(exprasmlist,def_cgsize(left.resulttype.def),left.location.reference,tempparaloc);
  255. else
  256. internalerror(2002042431);
  257. end;
  258. else
  259. internalerror(2002042432);
  260. end;
  261. {$endif i386}
  262. end
  263. else
  264. begin
  265. { copy the value on the stack or use normal parameter push?
  266. Check for varargs first because that has no paraitem }
  267. if not(cpf_varargs_para in callparaflags) and
  268. paramanager.copy_value_on_stack(paraitem.paratyp,left.resulttype.def,
  269. aktcallnode.procdefinition.proccalloption) then
  270. begin
  271. location_release(exprasmlist,left.location);
  272. {$ifdef i386}
  273. if tempparaloc.loc<>LOC_REFERENCE then
  274. internalerror(200309292);
  275. if not (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  276. internalerror(200204241);
  277. { push on stack }
  278. size:=align(left.resulttype.def.size,tempparaloc.alignment);
  279. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  280. if tempparaloc.reference.index=NR_STACK_POINTER_REG then
  281. begin
  282. cg.g_stackpointer_alloc(exprasmlist,size);
  283. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  284. end
  285. else
  286. reference_reset_base(href,tempparaloc.reference.index,tempparaloc.reference.offset);
  287. cg.g_concatcopy(exprasmlist,left.location.reference,href,size,false,false);
  288. {$else i386}
  289. cg.a_param_copy_ref(exprasmlist,left.resulttype.def.size,left.location.reference,tempparaloc);
  290. {$endif i386}
  291. end
  292. else
  293. begin
  294. case left.location.loc of
  295. LOC_CONSTANT,
  296. LOC_REGISTER,
  297. LOC_CREGISTER,
  298. LOC_REFERENCE,
  299. LOC_CREFERENCE :
  300. begin
  301. cgsize:=def_cgsize(left.resulttype.def);
  302. if cgsize in [OS_64,OS_S64] then
  303. begin
  304. inc(tcgcallnode(aktcallnode).pushedparasize,8);
  305. cg64.a_param64_loc(exprasmlist,left.location,tempparaloc);
  306. location_release(exprasmlist,left.location);
  307. end
  308. else
  309. begin
  310. location_release(exprasmlist,left.location);
  311. inc(tcgcallnode(aktcallnode).pushedparasize,align(tcgsize2size[tempparaloc.size],tempparaloc.alignment));
  312. cg.a_param_loc(exprasmlist,left.location,tempparaloc);
  313. end;
  314. end;
  315. {$ifdef SUPPORT_MMX}
  316. LOC_MMXREGISTER,
  317. LOC_CMMXREGISTER:
  318. begin
  319. location_release(exprasmlist,left.location);
  320. inc(tcgcallnode(aktcallnode).pushedparasize,8);
  321. cg.a_parammm_reg(exprasmlist,left.location.register);
  322. end;
  323. {$endif SUPPORT_MMX}
  324. else
  325. internalerror(200204241);
  326. end;
  327. end;
  328. end;
  329. end;
  330. procedure tcgcallparanode.secondcallparan;
  331. var
  332. otlabel,
  333. oflabel : tasmlabel;
  334. hp : tnode;
  335. begin
  336. if not(assigned(paraitem)) or
  337. not(assigned(paraitem.paratype.def)) or
  338. not(assigned(paraitem.parasym) or
  339. (cpf_varargs_para in callparaflags)) then
  340. internalerror(200304242);
  341. { Skip nothingn nodes which are used after disabling
  342. a parameter }
  343. if (left.nodetype<>nothingn) then
  344. begin
  345. otlabel:=truelabel;
  346. oflabel:=falselabel;
  347. objectlibrary.getlabel(truelabel);
  348. objectlibrary.getlabel(falselabel);
  349. secondpass(left);
  350. allocate_tempparaloc;
  351. { handle varargs first, because paraitem.parasym is not valid }
  352. if (cpf_varargs_para in callparaflags) then
  353. begin
  354. if paramanager.push_addr_param(vs_value,left.resulttype.def,
  355. aktcallnode.procdefinition.proccalloption) then
  356. push_addr_para
  357. else
  358. push_value_para;
  359. end
  360. { hidden parameters }
  361. else if paraitem.is_hidden then
  362. begin
  363. { don't push a node that already generated a pointer type
  364. by address for implicit hidden parameters }
  365. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  366. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  367. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  368. aktcallnode.procdefinition.proccalloption)) then
  369. push_addr_para
  370. else
  371. push_value_para;
  372. end
  373. { formal def }
  374. else if (paraitem.paratype.def.deftype=formaldef) then
  375. begin
  376. { allow passing of a constant to a const formaldef }
  377. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  378. (left.location.loc=LOC_CONSTANT) then
  379. location_force_mem(exprasmlist,left.location);
  380. { allow (typecasted) @var }
  381. hp:=left;
  382. while (hp.nodetype=typeconvn) do
  383. hp:=ttypeconvnode(hp).left;
  384. if (hp.nodetype=addrn) and
  385. (not(nf_procvarload in hp.flags)) then
  386. begin
  387. inc(tcgcallnode(aktcallnode).pushedparasize,POINTER_SIZE);
  388. location_release(exprasmlist,left.location);
  389. cg.a_param_loc(exprasmlist,left.location,tempparaloc);
  390. end
  391. else
  392. push_addr_para;
  393. end
  394. { Normal parameter }
  395. else
  396. begin
  397. { don't push a node that already generated a pointer type
  398. by address for implicit hidden parameters }
  399. if (not(
  400. paraitem.is_hidden and
  401. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  402. ) and
  403. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  404. aktcallnode.procdefinition.proccalloption)) then
  405. begin
  406. { Check for passing a constant to var,out parameter }
  407. if (paraitem.paratyp in [vs_var,vs_out]) and
  408. (left.location.loc<>LOC_REFERENCE) then
  409. begin
  410. { passing self to a var parameter is allowed in
  411. TP and delphi }
  412. if not((left.location.loc=LOC_CREFERENCE) and
  413. is_self_node(left)) then
  414. internalerror(200106041);
  415. end;
  416. { Force to be in memory }
  417. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  418. location_force_mem(exprasmlist,left.location);
  419. push_addr_para;
  420. end
  421. else
  422. push_value_para;
  423. end;
  424. truelabel:=otlabel;
  425. falselabel:=oflabel;
  426. { update return location in callnode when this is the function
  427. result }
  428. if assigned(paraitem.parasym) and
  429. (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  430. location_copy(aktcallnode.location,left.location);
  431. end;
  432. { next parameter }
  433. if assigned(right) then
  434. tcallparanode(right).secondcallparan;
  435. end;
  436. {*****************************************************************************
  437. TCGCALLNODE
  438. *****************************************************************************}
  439. procedure tcgcallnode.extra_interrupt_code;
  440. begin
  441. end;
  442. procedure tcgcallnode.extra_call_code;
  443. begin
  444. end;
  445. function tcgcallnode.align_parasize:longint;
  446. begin
  447. result:=0;
  448. end;
  449. procedure tcgcallnode.pop_parasize(pop_size:longint);
  450. begin
  451. end;
  452. procedure tcgcallnode.handle_return_value;
  453. var
  454. cgsize : tcgsize;
  455. hregister : tregister;
  456. tempnode: tnode;
  457. begin
  458. { structured results are easy to handle.... }
  459. { needed also when result_no_used !! }
  460. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  461. begin
  462. { Location should be setup by the funcret para }
  463. if location.loc<>LOC_REFERENCE then
  464. internalerror(200304241);
  465. end
  466. else
  467. { ansi/widestrings must be registered, so we can dispose them }
  468. if resulttype.def.needs_inittable then
  469. begin
  470. { the FUNCTION_RESULT_REG is already allocated }
  471. if not assigned(funcretnode) then
  472. begin
  473. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  474. location.reference:=refcountedtemp;
  475. { a_load_reg_ref may allocate registers! }
  476. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,location.reference);
  477. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  478. end
  479. else
  480. begin
  481. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  482. hregister := cg.getaddressregister(exprasmlist);
  483. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,hregister);
  484. { in case of a regular funcretnode with ret_in_param, the }
  485. { original funcretnode isn't touched -> make sure it's }
  486. { the same here (not sure if it's necessary) }
  487. tempnode := funcretnode.getcopy;
  488. tempnode.pass_2;
  489. location := tempnode.location;
  490. tempnode.free;
  491. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference, false);
  492. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  493. cg.ungetregister(exprasmlist,hregister);
  494. end;
  495. end
  496. else
  497. { we have only to handle the result if it is used }
  498. if (cnf_return_value_used in callnodeflags) then
  499. begin
  500. if (resulttype.def.deftype=floatdef) then
  501. begin
  502. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  503. {$ifdef cpufpemu}
  504. if cs_fp_emulation in aktmoduleswitches then
  505. location.register:=NR_FUNCTION_RESULT_REG
  506. else
  507. {$endif cpufpemu}
  508. begin
  509. location.register:=NR_FPU_RESULT_REG;
  510. {$ifdef sparc}
  511. { Double are returned in F0:F1 }
  512. if location.size=OS_F64 then
  513. setsubreg(location.register,R_SUBFD);
  514. {$endif sparc}
  515. end;
  516. {$ifdef x86}
  517. tcgx86(cg).inc_fpu_stack;
  518. {$else x86}
  519. cg.ungetregister(exprasmlist,location.register);
  520. hregister := cg.getfpuregister(exprasmlist,location.size);
  521. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  522. location.register := hregister;
  523. {$endif x86}
  524. end
  525. else
  526. begin
  527. cgsize:=def_cgsize(resulttype.def);
  528. if cgsize<>OS_NO then
  529. begin
  530. location_reset(location,LOC_REGISTER,cgsize);
  531. {$ifndef cpu64bit}
  532. if cgsize in [OS_64,OS_S64] then
  533. begin
  534. { Move the function result to free registers, preferably the
  535. FUNCTION_RESULT_REG/FUNCTION_RESULTHIGH_REG, so no move is necessary.}
  536. { the FUNCTION_RESULT_LOW_REG/FUNCTION_RESULT_HIGH_REG
  537. are already allocated }
  538. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG);
  539. location.registerlow:=cg.getintregister(exprasmlist,OS_INT);
  540. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,NR_FUNCTION_RESULT64_LOW_REG,location.registerlow);
  541. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG);
  542. location.registerhigh:=cg.getintregister(exprasmlist,OS_INT);
  543. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,NR_FUNCTION_RESULT64_HIGH_REG,location.registerhigh);
  544. end
  545. else
  546. {$endif cpu64bit}
  547. begin
  548. {Move the function result to a free register, preferably the
  549. FUNCTION_RESULT_REG, so no move is necessary.}
  550. { the FUNCTION_RESULT_REG is already allocated }
  551. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  552. { change register size after the unget because the
  553. getregister was done for the full register }
  554. location.register:=cg.getintregister(exprasmlist,cgsize);
  555. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,cg.makeregsize(exprasmlist,NR_FUNCTION_RESULT_REG,cgsize),location.register);
  556. end;
  557. end
  558. else
  559. begin
  560. if resulttype.def.size>0 then
  561. internalerror(200305131);
  562. end;
  563. end;
  564. end
  565. else
  566. begin
  567. cgsize:=def_cgsize(resulttype.def);
  568. { an object constructor is a function with pointer result }
  569. if (procdefinition.proctypeoption=potype_constructor) then
  570. cgsize:=OS_ADDR;
  571. if cgsize<>OS_NO then
  572. {$ifndef cpu64bit}
  573. if cgsize in [OS_64,OS_S64] then
  574. begin
  575. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG);
  576. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG);
  577. end
  578. else
  579. {$endif cpu64bit}
  580. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  581. location_reset(location,LOC_VOID,OS_NO);
  582. end;
  583. end;
  584. procedure tcgcallnode.release_para_temps;
  585. var
  586. hp : tnode;
  587. ppn : tcallparanode;
  588. begin
  589. { Release temps from parameters }
  590. ppn:=tcallparanode(left);
  591. while assigned(ppn) do
  592. begin
  593. if assigned(ppn.left) then
  594. begin
  595. { don't release the funcret temp }
  596. if not(assigned(ppn.paraitem.parasym)) or
  597. not(vo_is_funcret in tvarsym(ppn.paraitem.parasym).varoptions) then
  598. location_freetemp(exprasmlist,ppn.left.location);
  599. { process also all nodes of an array of const }
  600. if ppn.left.nodetype=arrayconstructorn then
  601. begin
  602. if assigned(tarrayconstructornode(ppn.left).left) then
  603. begin
  604. hp:=ppn.left;
  605. while assigned(hp) do
  606. begin
  607. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  608. hp:=tarrayconstructornode(hp).right;
  609. end;
  610. end;
  611. end;
  612. end;
  613. ppn:=tcallparanode(ppn.right);
  614. end;
  615. end;
  616. procedure tcgcallnode.normal_pass_2;
  617. var
  618. regs_to_push_fpu,
  619. regs_to_alloc,
  620. regs_to_free : Tcpuregisterset;
  621. oldpushedparasize : longint;
  622. {$ifdef cputargethasfixedstack}
  623. href2,
  624. {$endif cputargethasfixedstack}
  625. href : treference;
  626. pop_size : longint;
  627. pvreg,
  628. vmtreg : tregister;
  629. oldaktcallnode : tcallnode;
  630. procedure pushparas;
  631. var
  632. ppn : tcgcallparanode;
  633. begin
  634. { copy all resources to the allocated registers }
  635. ppn:=tcgcallparanode(left);
  636. while assigned(ppn) do
  637. begin
  638. if (ppn.left.nodetype<>nothingn) then
  639. begin
  640. { better check for the real location of the parameter here, when stack passed parameters
  641. are saved temporary in registers, checking for the tempparaloc.loc is wrong
  642. }
  643. case ppn.paraitem.paraloc[callerside].loc of
  644. LOC_REGISTER:
  645. begin
  646. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  647. paramanager.allocparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  648. {$ifdef sparc}
  649. case ppn.tempparaloc.size of
  650. OS_F32 :
  651. ppn.tempparaloc.size:=OS_32;
  652. OS_F64 :
  653. ppn.tempparaloc.size:=OS_64;
  654. end;
  655. {$endif sparc}
  656. {$ifndef cpu64bit}
  657. if ppn.tempparaloc.size in [OS_64,OS_S64] then
  658. begin
  659. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerlow,
  660. ppn.paraitem.paraloc[callerside].registerlow);
  661. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerhigh,
  662. ppn.paraitem.paraloc[callerside].registerhigh);
  663. end
  664. else
  665. {$endif cpu64bit}
  666. cg.a_load_reg_reg(exprasmlist,ppn.tempparaloc.size,ppn.tempparaloc.size,
  667. ppn.tempparaloc.register,ppn.paraitem.paraloc[callerside].register);
  668. end;
  669. LOC_FPUREGISTER:
  670. begin
  671. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  672. paramanager.allocparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  673. cg.a_loadfpu_reg_reg(exprasmlist,ppn.tempparaloc.size,
  674. ppn.tempparaloc.register,ppn.paraitem.paraloc[callerside].register);
  675. end;
  676. LOC_MMREGISTER:
  677. begin
  678. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  679. paramanager.allocparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  680. cg.a_loadmm_reg_reg(exprasmlist,ppn.tempparaloc.size,
  681. ppn.tempparaloc.size,ppn.tempparaloc.register,ppn.paraitem.paraloc[callerside].register,mms_movescalar);
  682. end;
  683. LOC_REFERENCE:
  684. begin
  685. {$ifdef cputargethasfixedstack}
  686. { copy parameters in case they were moved to a temp. location because we've a fixed stack }
  687. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  688. paramanager.allocparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  689. case ppn.tempparaloc.loc of
  690. LOC_REFERENCE:
  691. begin
  692. reference_reset_base(href,ppn.tempparaloc.reference.index,ppn.tempparaloc.reference.offset);
  693. reference_reset_base(href2,ppn.paraitem.paraloc[callerside].reference.index,ppn.paraitem.paraloc[callerside].reference.offset);
  694. cg.g_concatcopy(exprasmlist,href,href2,ppn.paraitem.paratype.def.size,false,false);
  695. end;
  696. LOC_REGISTER:
  697. if ppn.tempparaloc.size in [OS_64,OS_S64] then
  698. begin
  699. reference_reset_base(href,ppn.paraitem.paraloc[callerside].reference.index,ppn.paraitem.paraloc[callerside].reference.offset);
  700. cg.a_load_reg_ref(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerlow,
  701. href);
  702. { we don't use a c64.load here because later (when fixed ;)) one dword could be on the stack and the
  703. other in a cpu register }
  704. reference_reset_base(href,ppn.paraitem.paraloc[callerside].reference.index,ppn.paraitem.paraloc[callerside].reference.offset+4);
  705. cg.a_load_reg_ref(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerhigh,
  706. href);
  707. end
  708. else
  709. cg.a_param_reg(exprasmlist,ppn.paraitem.paraloc[callerside].size,ppn.tempparaloc.register,ppn.paraitem.paraloc[callerside]);
  710. LOC_FPUREGISTER:
  711. cg.a_paramfpu_reg(exprasmlist,ppn.paraitem.paraloc[callerside].size,ppn.tempparaloc.register,ppn.paraitem.paraloc[callerside]);
  712. else
  713. internalerror(200402081);
  714. end;
  715. {$endif cputargethasfixedstack}
  716. end;
  717. else
  718. internalerror(200402091);
  719. end;
  720. end;
  721. ppn:=tcgcallparanode(ppn.right);
  722. end;
  723. end;
  724. procedure freeparas;
  725. var
  726. ppn : tcgcallparanode;
  727. begin
  728. { free the resources allocated for the parameters }
  729. ppn:=tcgcallparanode(left);
  730. while assigned(ppn) do
  731. begin
  732. paramanager.freeparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  733. ppn:=tcgcallparanode(ppn.right);
  734. end;
  735. end;
  736. begin
  737. if not assigned(procdefinition) or
  738. not procdefinition.has_paraloc_info then
  739. internalerror(200305264);
  740. if resulttype.def.needs_inittable and
  741. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) and
  742. not assigned(funcretnode) then
  743. begin
  744. tg.gettemptyped(exprasmlist,resulttype.def,tt_normal,refcountedtemp);
  745. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  746. end;
  747. regs_to_alloc:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  748. regs_to_push_fpu:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  749. { Include Function result registers }
  750. if (not is_void(resulttype.def)) then
  751. begin
  752. case procdefinition.funcret_paraloc[callerside].loc of
  753. LOC_REGISTER,LOC_CREGISTER:
  754. begin
  755. {$ifndef cpu64bit}
  756. if procdefinition.funcret_paraloc[callerside].size in [OS_S64,OS_64] then
  757. begin
  758. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].registerlow));
  759. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].registerhigh));
  760. end
  761. else
  762. {$endif cpu64bit}
  763. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  764. end;
  765. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  766. begin
  767. include(regs_to_push_fpu,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  768. end;
  769. LOC_MMREGISTER,LOC_CMMREGISTER:
  770. begin
  771. internalerror(2003102911);
  772. end;
  773. end;
  774. end;
  775. { Initialize for pushing the parameters }
  776. oldpushedparasize:=pushedparasize;
  777. pushedparasize:=0;
  778. { Process parameters, register parameters will be loaded
  779. in imaginary registers. The actual load to the correct
  780. register is done just before the call }
  781. oldaktcallnode:=aktcallnode;
  782. aktcallnode:=self;
  783. if assigned(left) then
  784. tcallparanode(left).secondcallparan;
  785. aktcallnode:=oldaktcallnode;
  786. { Align stack if required }
  787. pop_size:=align_parasize;
  788. { procedure variable or normal function call ? }
  789. if (right=nil) then
  790. begin
  791. if (po_virtualmethod in procdefinition.procoptions) and
  792. assigned(methodpointer) then
  793. begin
  794. secondpass(methodpointer);
  795. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  796. { virtual methods require an index }
  797. if tprocdef(procdefinition).extnumber=-1 then
  798. internalerror(200304021);
  799. { VMT should already be loaded in a register }
  800. if methodpointer.location.register=NR_NO then
  801. internalerror(200304022);
  802. { test validity of VMT }
  803. if not(is_interface(tprocdef(procdefinition)._class)) and
  804. not(is_cppclass(tprocdef(procdefinition)._class)) then
  805. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  806. end;
  807. {$warning fixme regvars}
  808. { rg.saveotherregvars(exprasmlist,regs_to_push_other);}
  809. if (po_virtualmethod in procdefinition.procoptions) and
  810. assigned(methodpointer) then
  811. begin
  812. vmtreg:=methodpointer.location.register;
  813. { release self }
  814. cg.ungetregister(exprasmlist,vmtreg);
  815. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  816. reference_reset_base(href,vmtreg,
  817. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  818. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,pvreg);
  819. { Load parameters that are in temporary registers in the
  820. correct parameter register }
  821. if assigned(left) then
  822. pushparas;
  823. { free the resources allocated for the parameters }
  824. freeparas;
  825. { Release register containing procvar }
  826. cg.ungetregister(exprasmlist,pvreg);
  827. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  828. if cg.uses_registers(R_FPUREGISTER) then
  829. cg.allocexplicitregisters(exprasmlist,R_FPUREGISTER,regs_to_push_fpu);
  830. if cg.uses_registers(R_MMREGISTER) then
  831. cg.allocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  832. { call method }
  833. extra_call_code;
  834. cg.a_call_reg(exprasmlist,pvreg);
  835. end
  836. else
  837. begin
  838. { Load parameters that are in temporary registers in the
  839. correct parameter register }
  840. if assigned(left) then
  841. pushparas;
  842. { free the resources allocated for the parameters }
  843. freeparas;
  844. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  845. if cg.uses_registers(R_FPUREGISTER) then
  846. cg.allocexplicitregisters(exprasmlist,R_FPUREGISTER,regs_to_push_fpu);
  847. if cg.uses_registers(R_MMREGISTER) then
  848. cg.allocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  849. if procdefinition.proccalloption=pocall_syscall then
  850. do_syscall
  851. else
  852. begin
  853. { Calling interrupt from the same code requires some
  854. extra code }
  855. if (po_interrupt in procdefinition.procoptions) then
  856. extra_interrupt_code;
  857. extra_call_code;
  858. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  859. end;
  860. end;
  861. end
  862. else
  863. { now procedure variable case }
  864. begin
  865. secondpass(right);
  866. location_release(exprasmlist,right.location);
  867. pvreg:=cg.getintregister(exprasmlist,OS_ADDR);
  868. { Only load OS_ADDR from the reference }
  869. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  870. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,right.location.reference,pvreg)
  871. else
  872. cg.a_load_loc_reg(exprasmlist,OS_ADDR,right.location,pvreg);
  873. location_freetemp(exprasmlist,right.location);
  874. { Load parameters that are in temporary registers in the
  875. correct parameter register }
  876. if assigned(left) then
  877. pushparas;
  878. { free the resources allocated for the parameters }
  879. freeparas;
  880. { Release register containing procvar }
  881. cg.ungetregister(exprasmlist,pvreg);
  882. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  883. if cg.uses_registers(R_FPUREGISTER) then
  884. cg.allocexplicitregisters(exprasmlist,R_FPUREGISTER,regs_to_push_fpu);
  885. if cg.uses_registers(R_MMREGISTER) then
  886. cg.allocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  887. { Calling interrupt from the same code requires some
  888. extra code }
  889. if (po_interrupt in procdefinition.procoptions) then
  890. extra_interrupt_code;
  891. {$warning fixme regvars.}
  892. { rg.saveotherregvars(exprasmlist,ALL_OTHERREGISTERS);}
  893. extra_call_code;
  894. cg.a_call_reg(exprasmlist,pvreg);
  895. end;
  896. { Need to remove the parameters from the stack? }
  897. if (procdefinition.proccalloption in clearstack_pocalls) then
  898. begin
  899. { the old pop_size was already included in pushedparasize }
  900. pop_size:=pushedparasize;
  901. { for Cdecl functions we don't need to pop the funcret when it
  902. was pushed by para }
  903. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  904. dec(pop_size,POINTER_SIZE);
  905. end;
  906. { Remove parameters/alignment from the stack }
  907. if pop_size>0 then
  908. pop_parasize(pop_size);
  909. { Reserve space for storing parameters that will be pushed }
  910. current_procinfo.allocate_push_parasize(pushedparasize);
  911. { Restore }
  912. pushedparasize:=oldpushedparasize;
  913. { Release registers, but not the registers that contain the
  914. function result }
  915. regs_to_free:=regs_to_alloc;
  916. if (not is_void(resulttype.def)) then
  917. begin
  918. case procdefinition.funcret_paraloc[callerside].loc of
  919. LOC_REGISTER,LOC_CREGISTER:
  920. begin
  921. {$ifndef cpu64bit}
  922. if procdefinition.funcret_paraloc[callerside].size in [OS_S64,OS_64] then
  923. begin
  924. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].registerlow));
  925. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].registerhigh));
  926. end
  927. else
  928. {$endif cpu64bit}
  929. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  930. end;
  931. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  932. begin
  933. exclude(regs_to_push_fpu,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  934. end;
  935. end;
  936. end;
  937. if cg.uses_registers(R_MMREGISTER) then
  938. cg.deallocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  939. if cg.uses_registers(R_FPUREGISTER) then
  940. cg.deallocexplicitregisters(exprasmlist,R_FPUREGISTER,regs_to_push_fpu);
  941. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_free);
  942. { handle function results }
  943. if (not is_void(resulttype.def)) then
  944. handle_return_value
  945. else
  946. location_reset(location,LOC_VOID,OS_NO);
  947. { perhaps i/o check ? }
  948. if (cs_check_io in aktlocalswitches) and
  949. (po_iocheck in procdefinition.procoptions) and
  950. not(po_iocheck in current_procinfo.procdef.procoptions) and
  951. { no IO check for methods and procedure variables }
  952. (right=nil) and
  953. not(po_virtualmethod in procdefinition.procoptions) then
  954. begin
  955. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  956. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  957. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  958. end;
  959. { release temps of paras }
  960. release_para_temps;
  961. { if return value is not used }
  962. if (not(cnf_return_value_used in callnodeflags)) and (not is_void(resulttype.def)) then
  963. begin
  964. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  965. begin
  966. { data which must be finalized ? }
  967. if (resulttype.def.needs_inittable) then
  968. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  969. { release unused temp }
  970. tg.ungetiftemp(exprasmlist,location.reference)
  971. end
  972. else if location.loc=LOC_FPUREGISTER then
  973. begin
  974. {$ifdef x86}
  975. { release FPU stack }
  976. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  977. {$endif x86}
  978. end;
  979. end;
  980. end;
  981. procedure tcgcallnode.inlined_pass_2;
  982. var
  983. oldaktcallnode : tcallnode;
  984. oldprocinfo : tprocinfo;
  985. oldinlining_procedure : boolean;
  986. inlineentrycode,inlineexitcode : TAAsmoutput;
  987. usesacc,usesacchi,usesfpu : boolean;
  988. {$ifdef GDB}
  989. startlabel,endlabel : tasmlabel;
  990. pp : pchar;
  991. mangled_length : longint;
  992. {$endif GDB}
  993. begin
  994. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  995. internalerror(200305262);
  996. oldinlining_procedure:=inlining_procedure;
  997. oldprocinfo:=current_procinfo;
  998. { we're inlining a procedure }
  999. inlining_procedure:=true;
  1000. { Add inling start }
  1001. {$ifdef GDB}
  1002. exprasmlist.concat(Tai_force_line.Create);
  1003. {$endif GDB}
  1004. exprasmList.concat(Tai_Marker.Create(InlineStart));
  1005. {$ifdef extdebug}
  1006. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc '+tprocdef(procdefinition).procsym.name)));
  1007. {$endif extdebug}
  1008. { calculate registers to pass the parameters }
  1009. paramanager.create_inline_paraloc_info(procdefinition);
  1010. { Allocate parameters and locals }
  1011. gen_alloc_inline_parast(exprasmlist,tparasymtable(procdefinition.parast));
  1012. if tprocdef(procdefinition).localst.symtabletype=localsymtable then
  1013. gen_alloc_localst(exprasmlist,tlocalsymtable(tprocdef(procdefinition).localst));
  1014. { if we allocate the temp. location for ansi- or widestrings }
  1015. { already here, we avoid later a push/pop }
  1016. if resulttype.def.needs_inittable and
  1017. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1018. begin
  1019. tg.gettemptyped(exprasmlist,resulttype.def,tt_normal,refcountedtemp);
  1020. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1021. end;
  1022. { Push parameters, still use the old current_procinfo. This
  1023. is required that have the correct information available like
  1024. _class and nested procedure }
  1025. oldaktcallnode:=aktcallnode;
  1026. aktcallnode:=self;
  1027. if assigned(left) then
  1028. tcallparanode(left).secondcallparan;
  1029. aktcallnode:=oldaktcallnode;
  1030. { create temp procinfo that will be used for the inlinecode tree }
  1031. current_procinfo:=cprocinfo.create(nil);
  1032. current_procinfo.procdef:=tprocdef(procdefinition);
  1033. current_procinfo.flags:=oldprocinfo.flags;
  1034. current_procinfo.aktlocaldata.destroy;
  1035. current_procinfo.aktlocaldata:=oldprocinfo.aktlocaldata;
  1036. { when the oldprocinfo is also being inlined reuse the
  1037. inlining_procinfo }
  1038. if assigned(oldprocinfo.inlining_procinfo) then
  1039. current_procinfo.inlining_procinfo:=oldprocinfo.inlining_procinfo
  1040. else
  1041. current_procinfo.inlining_procinfo:=oldprocinfo;
  1042. { takes care of local data initialization }
  1043. inlineentrycode:=TAAsmoutput.Create;
  1044. inlineexitcode:=TAAsmoutput.Create;
  1045. {$ifdef GDB}
  1046. if (cs_debuginfo in aktmoduleswitches) and
  1047. not(cs_gdb_valgrind in aktglobalswitches) then
  1048. begin
  1049. objectlibrary.getaddrlabel(startlabel);
  1050. objectlibrary.getaddrlabel(endlabel);
  1051. cg.a_label(exprasmlist,startlabel);
  1052. { Here we must include the para and local symtable info }
  1053. procdefinition.concatstabto(withdebuglist);
  1054. mangled_length:=length(current_procinfo.inlining_procinfo.procdef.mangledname);
  1055. getmem(pp,mangled_length+50);
  1056. strpcopy(pp,'192,0,0,'+startlabel.name);
  1057. if (target_info.use_function_relative_addresses) then
  1058. begin
  1059. strpcopy(strend(pp),'-');
  1060. strpcopy(strend(pp),current_procinfo.inlining_procinfo.procdef.mangledname);
  1061. end;
  1062. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1063. end;
  1064. {$endif GDB}
  1065. gen_load_para_value(inlineentrycode);
  1066. gen_initialize_code(inlineentrycode,true);
  1067. if po_assembler in current_procinfo.procdef.procoptions then
  1068. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  1069. exprasmList.concatlist(inlineentrycode);
  1070. { process the inline code }
  1071. secondpass(inlinecode);
  1072. cg.a_label(exprasmlist,current_procinfo.aktexitlabel);
  1073. gen_finalize_code(inlineexitcode,true);
  1074. gen_load_return_value(inlineexitcode,usesacc,usesacchi,usesfpu);
  1075. if po_assembler in current_procinfo.procdef.procoptions then
  1076. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  1077. exprasmlist.concatlist(inlineexitcode);
  1078. inlineentrycode.free;
  1079. inlineexitcode.free;
  1080. {$ifdef extdebug}
  1081. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  1082. {$endif extdebug}
  1083. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1084. { handle function results }
  1085. if (not is_void(resulttype.def)) then
  1086. handle_return_value
  1087. else
  1088. location_reset(location,LOC_VOID,OS_NO);
  1089. { perhaps i/o check ? }
  1090. if (cs_check_io in aktlocalswitches) and
  1091. (po_iocheck in procdefinition.procoptions) and
  1092. not(po_iocheck in current_procinfo.procdef.procoptions) and
  1093. { no IO check for methods and procedure variables }
  1094. (right=nil) and
  1095. not(po_virtualmethod in procdefinition.procoptions) then
  1096. begin
  1097. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1098. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1099. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1100. end;
  1101. { release temps of paras }
  1102. release_para_temps;
  1103. { if return value is not used }
  1104. if (not is_void(resulttype.def)) and
  1105. (not(cnf_return_value_used in callnodeflags)) then
  1106. begin
  1107. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1108. begin
  1109. { data which must be finalized ? }
  1110. if (resulttype.def.needs_inittable) then
  1111. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1112. { release unused temp }
  1113. tg.ungetiftemp(exprasmlist,location.reference)
  1114. end
  1115. else if location.loc=LOC_FPUREGISTER then
  1116. begin
  1117. {$ifdef x86}
  1118. { release FPU stack }
  1119. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  1120. {$endif x86}
  1121. end;
  1122. end;
  1123. { Release parameters and locals }
  1124. gen_free_parast(exprasmlist,tparasymtable(current_procinfo.procdef.parast));
  1125. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  1126. gen_free_localst(exprasmlist,tlocalsymtable(current_procinfo.procdef.localst));
  1127. {$ifdef GDB}
  1128. if (cs_debuginfo in aktmoduleswitches) and
  1129. not(cs_gdb_valgrind in aktglobalswitches) then
  1130. begin
  1131. cg.a_label(exprasmlist,endlabel);
  1132. strpcopy(pp,'224,0,0,'+endlabel.name);
  1133. if (target_info.use_function_relative_addresses) then
  1134. begin
  1135. strpcopy(strend(pp),'-');
  1136. strpcopy(strend(pp),current_procinfo.inlining_procinfo.procdef.mangledname);
  1137. end;
  1138. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1139. freemem(pp,mangled_length+50);
  1140. end;
  1141. {$endif GDB}
  1142. { restore }
  1143. current_procinfo.aktlocaldata:=nil;
  1144. current_procinfo.destroy;
  1145. current_procinfo:=oldprocinfo;
  1146. inlining_procedure:=oldinlining_procedure;
  1147. end;
  1148. procedure tcgcallnode.pass_2;
  1149. begin
  1150. if assigned(methodpointerinit) then
  1151. secondpass(methodpointerinit);
  1152. if assigned(inlinecode) then
  1153. inlined_pass_2
  1154. else
  1155. normal_pass_2;
  1156. if assigned(methodpointerdone) then
  1157. secondpass(methodpointerdone);
  1158. end;
  1159. begin
  1160. ccallparanode:=tcgcallparanode;
  1161. ccallnode:=tcgcallnode;
  1162. end.
  1163. {
  1164. $Log$
  1165. Revision 1.167 2004-05-23 18:28:41 peter
  1166. * methodpointer is loaded into a temp when it was a calln
  1167. Revision 1.166 2004/05/22 23:34:27 peter
  1168. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1169. Revision 1.165 2004/04/28 15:19:03 florian
  1170. + syscall directive support for MorphOS added
  1171. Revision 1.164 2004/03/14 20:10:56 peter
  1172. * disable some debuginfo info when valgrind support is used
  1173. Revision 1.163 2004/03/13 21:23:21 florian
  1174. * fixed inlining on arm
  1175. Revision 1.162 2004/03/09 16:28:31 peter
  1176. * fix for sparc that pushes floats in int registers
  1177. Revision 1.161 2004/03/09 13:04:12 mazen
  1178. + difference between three similar internal errors
  1179. Revision 1.160 2004/02/27 10:21:05 florian
  1180. * top_symbol killed
  1181. + refaddr to treference added
  1182. + refsymbol to treference added
  1183. * top_local stuff moved to an extra record to save memory
  1184. + aint introduced
  1185. * tppufile.get/putint64/aint implemented
  1186. Revision 1.159 2004/02/26 16:12:04 peter
  1187. * support typecasts for passing @var to formal const
  1188. Revision 1.158 2004/02/22 13:01:15 daniel
  1189. * Fixed memory leak
  1190. Revision 1.157 2004/02/22 12:04:04 florian
  1191. + nx86set added
  1192. * some more x86-64 fixes
  1193. Revision 1.156 2004/02/20 22:16:35 florian
  1194. * handling of float parameters passed in mm registers fixed
  1195. Revision 1.155 2004/02/20 21:55:59 peter
  1196. * procvar cleanup
  1197. Revision 1.154 2004/02/11 19:59:06 peter
  1198. * fix compilation without GDB
  1199. Revision 1.153 2004/02/09 22:48:45 florian
  1200. * several fixes to parameter handling on arm
  1201. Revision 1.152 2004/01/31 17:45:17 peter
  1202. * Change several $ifdef i386 to x86
  1203. * Change several OS_32 to OS_INT/OS_ADDR
  1204. Revision 1.151 2004/01/26 17:34:14 florian
  1205. * set aktlocaldata for inlined procedures correctly
  1206. Revision 1.150 2004/01/12 16:39:40 peter
  1207. * sparc updates, mostly float related
  1208. Revision 1.149 2003/12/28 22:09:12 florian
  1209. + setting of bit 6 of cr for c var args on ppc implemented
  1210. Revision 1.148 2003/12/26 13:19:16 florian
  1211. * rtl and compiler compile with -Cfsse2
  1212. Revision 1.147 2003/12/21 19:42:42 florian
  1213. * fixed ppc inlining stuff
  1214. * fixed wrong unit writing
  1215. + added some sse stuff
  1216. Revision 1.146 2003/12/15 21:25:48 peter
  1217. * reg allocations for imaginary register are now inserted just
  1218. before reg allocation
  1219. * tregister changed to enum to allow compile time check
  1220. * fixed several tregister-tsuperregister errors
  1221. Revision 1.145 2003/12/07 12:41:32 jonas
  1222. * fixed ansistring/widestring results: deallocate result reg only after
  1223. it has been stored to memory, as the storing itself may require extra
  1224. results (e.g. on ppc)
  1225. Revision 1.144 2003/12/06 01:15:22 florian
  1226. * reverted Peter's alloctemp patch; hopefully properly
  1227. Revision 1.143 2003/12/03 23:13:20 peter
  1228. * delayed paraloc allocation, a_param_*() gets extra parameter
  1229. if it needs to allocate temp or real paralocation
  1230. * optimized/simplified int-real loading
  1231. Revision 1.142 2003/12/02 21:23:34 peter
  1232. * exitlabel for inline procs
  1233. Revision 1.141 2003/11/23 17:39:33 peter
  1234. * removed obsolete nf_cargs flag
  1235. Revision 1.140 2003/11/23 17:05:15 peter
  1236. * register calling is left-right
  1237. * parameter ordering
  1238. * left-right calling inserts result parameter last
  1239. Revision 1.139 2003/11/10 22:02:52 peter
  1240. * cross unit inlining fixed
  1241. Revision 1.138 2003/11/07 15:58:32 florian
  1242. * Florian's culmutative nr. 1; contains:
  1243. - invalid calling conventions for a certain cpu are rejected
  1244. - arm softfloat calling conventions
  1245. - -Sp for cpu dependend code generation
  1246. - several arm fixes
  1247. - remaining code for value open array paras on heap
  1248. Revision 1.137 2003/11/04 19:03:54 peter
  1249. * fixes for temp type patch
  1250. Revision 1.136 2003/11/04 15:35:13 peter
  1251. * fix for referencecounted temps
  1252. Revision 1.135 2003/10/30 17:12:49 peter
  1253. * fixed rangecheck error
  1254. Revision 1.134 2003/10/29 21:24:14 jonas
  1255. + support for fpu temp parameters
  1256. + saving/restoring of fpu register before/after a procedure call
  1257. Revision 1.133 2003/10/20 19:28:17 peter
  1258. * fixed inlining float parameters for i386
  1259. Revision 1.132 2003/10/17 14:38:32 peter
  1260. * 64k registers supported
  1261. * fixed some memory leaks
  1262. Revision 1.131 2003/10/17 01:22:08 florian
  1263. * compilation of the powerpc compiler fixed
  1264. Revision 1.130 2003/10/11 16:06:42 florian
  1265. * fixed some MMX<->SSE
  1266. * started to fix ppc, needs an overhaul
  1267. + stabs info improve for spilling, not sure if it works correctly/completly
  1268. - MMX_SUPPORT removed from Makefile.fpc
  1269. Revision 1.129 2003/10/10 17:48:13 peter
  1270. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1271. * tregisteralloctor renamed to trgobj
  1272. * removed rgobj from a lot of units
  1273. * moved location_* and reference_* to cgobj
  1274. * first things for mmx register allocation
  1275. Revision 1.128 2003/10/10 09:21:53 marco
  1276. * typo fix from Wiktor
  1277. Revision 1.127 2003/10/09 21:31:37 daniel
  1278. * Register allocator splitted, ans abstract now
  1279. Revision 1.126 2003/10/07 15:17:07 peter
  1280. * inline supported again, LOC_REFERENCEs are used to pass the
  1281. parameters
  1282. * inlineparasymtable,inlinelocalsymtable removed
  1283. * exitlabel inserting fixed
  1284. Revision 1.125 2003/10/05 21:21:52 peter
  1285. * c style array of const generates callparanodes
  1286. * varargs paraloc fixes
  1287. Revision 1.124 2003/10/03 22:00:33 peter
  1288. * parameter alignment fixes
  1289. Revision 1.123 2003/10/01 20:34:48 peter
  1290. * procinfo unit contains tprocinfo
  1291. * cginfo renamed to cgbase
  1292. * moved cgmessage to verbose
  1293. * fixed ppc and sparc compiles
  1294. Revision 1.122 2003/09/30 21:02:37 peter
  1295. * updates for inlining
  1296. Revision 1.121 2003/09/30 19:55:19 peter
  1297. * remove abt reg for vmtreg
  1298. Revision 1.120 2003/09/29 20:58:55 peter
  1299. * optimized releasing of registers
  1300. Revision 1.119 2003/09/28 17:55:03 peter
  1301. * parent framepointer changed to hidden parameter
  1302. * tloadparentfpnode added
  1303. Revision 1.118 2003/09/28 13:54:43 peter
  1304. * removed a_call_ref
  1305. Revision 1.117 2003/09/25 21:28:00 peter
  1306. * parameter fixes
  1307. Revision 1.116 2003/09/23 17:56:05 peter
  1308. * locals and paras are allocated in the code generation
  1309. * tvarsym.localloc contains the location of para/local when
  1310. generating code for the current procedure
  1311. Revision 1.115 2003/09/16 16:17:01 peter
  1312. * varspez in calls to push_addr_param
  1313. Revision 1.114 2003/09/14 19:17:39 peter
  1314. * don't use a_call_ref because it can use a parameter register
  1315. as temp
  1316. Revision 1.113 2003/09/11 11:54:59 florian
  1317. * improved arm code generation
  1318. * move some protected and private field around
  1319. * the temp. register for register parameters/arguments are now released
  1320. before the move to the parameter register is done. This improves
  1321. the code in a lot of cases.
  1322. Revision 1.112 2003/09/10 08:31:47 marco
  1323. * Patch from Peter for paraloc
  1324. Revision 1.111 2003/09/07 22:09:35 peter
  1325. * preparations for different default calling conventions
  1326. * various RA fixes
  1327. Revision 1.110 2003/09/04 15:39:58 peter
  1328. * released useparatemp
  1329. Revision 1.109 2003/09/03 15:55:00 peter
  1330. * NEWRA branch merged
  1331. Revision 1.108.2.4 2003/09/01 21:02:55 peter
  1332. * sparc updates for new tregister
  1333. Revision 1.108.2.3 2003/08/31 21:07:44 daniel
  1334. * callparatemp ripped
  1335. Revision 1.108.2.2 2003/08/29 17:28:59 peter
  1336. * next batch of updates
  1337. Revision 1.108.2.1 2003/08/27 20:23:55 peter
  1338. * remove old ra code
  1339. Revision 1.108 2003/08/21 22:14:16 olle
  1340. - removed parameter from fpc_iocheck
  1341. Revision 1.107 2003/08/17 16:59:20 jonas
  1342. * fixed regvars so they work with newra (at least for ppc)
  1343. * fixed some volatile register bugs
  1344. + -dnotranslation option for -dnewra, which causes the registers not to
  1345. be translated from virtual to normal registers. Requires support in
  1346. the assembler writer as well, which is only implemented in aggas/
  1347. agppcgas currently
  1348. Revision 1.106 2003/08/16 18:56:40 marco
  1349. * fix from Jonas.
  1350. Revision 1.105 2003/08/11 21:18:20 peter
  1351. * start of sparc support for newra
  1352. Revision 1.104 2003/08/11 14:22:06 mazen
  1353. - dupplicated code removed
  1354. Revision 1.103 2003/07/23 11:01:14 jonas
  1355. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  1356. pairs round calls to helpers
  1357. Revision 1.102 2003/07/21 13:51:50 jonas
  1358. * fixed 64bit int results with -dnewra (you can't free both registers and
  1359. then allocate two new ones, because then the registers could be reversed
  1360. afterwards -> you get something like "movl %eax, %edx; movl %edx,%eax")
  1361. Revision 1.101 2003/07/08 21:24:59 peter
  1362. * sparc fixes
  1363. Revision 1.100 2003/07/06 21:50:33 jonas
  1364. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  1365. so that it doesn't include ebp and esp anymore
  1366. Revision 1.99 2003/07/06 17:58:22 peter
  1367. * framepointer fixes for sparc
  1368. * parent framepointer code more generic
  1369. Revision 1.98 2003/07/06 15:31:20 daniel
  1370. * Fixed register allocator. *Lots* of fixes.
  1371. Revision 1.97 2003/07/05 20:21:26 jonas
  1372. * create_paraloc_info() is now called separately for the caller and
  1373. callee info
  1374. * fixed ppc cycle
  1375. Revision 1.96 2003/07/02 22:18:04 peter
  1376. * paraloc splitted in paraloc[callerside],calleeparaloc
  1377. * sparc calling convention updates
  1378. Revision 1.95 2003/06/17 16:34:44 jonas
  1379. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1380. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  1381. processor dependent
  1382. Revision 1.94 2003/06/15 16:52:02 jonas
  1383. * release function result registers if the functino result isn't used
  1384. * don't allocate function result register with -dnewra if there is none
  1385. * some optimizations for non-x86 processor (don't save any registers
  1386. before a call)
  1387. Revision 1.93 2003/06/13 21:19:30 peter
  1388. * current_procdef removed, use current_procinfo.procdef instead
  1389. Revision 1.92 2003/06/12 21:10:50 peter
  1390. * newra fixes
  1391. Revision 1.91 2003/06/12 18:38:45 jonas
  1392. * deallocate parameter registers in time for newra
  1393. * for non-i386, procvars and methodpointers always have to be processed
  1394. in advance, whether or not newra is defined
  1395. Revision 1.90 2003/06/09 14:54:26 jonas
  1396. * (de)allocation of registers for parameters is now performed properly
  1397. (and checked on the ppc)
  1398. - removed obsolete allocation of all parameter registers at the start
  1399. of a procedure (and deallocation at the end)
  1400. Revision 1.89 2003/06/09 12:23:29 peter
  1401. * init/final of procedure data splitted from genentrycode
  1402. * use asmnode getposition to insert final at the correct position
  1403. als for the implicit try...finally
  1404. Revision 1.88 2003/06/08 20:01:53 jonas
  1405. * optimized assignments with on the right side a function that returns
  1406. an ansi- or widestring
  1407. Revision 1.87 2003/06/08 18:21:47 jonas
  1408. * fixed weird error in the copyleft statement :)
  1409. Revision 1.86 2003/06/07 18:57:04 jonas
  1410. + added freeintparaloc
  1411. * ppc get/freeintparaloc now check whether the parameter regs are
  1412. properly allocated/deallocated (and get an extra list para)
  1413. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1414. * fixed lot of missing pi_do_call's
  1415. Revision 1.85 2003/06/04 06:43:36 jonas
  1416. * fixed double secondpassing of procvar loads
  1417. Revision 1.84 2003/06/03 21:11:09 peter
  1418. * cg.a_load_* get a from and to size specifier
  1419. * makeregsize only accepts newregister
  1420. * i386 uses generic tcgnotnode,tcgunaryminus
  1421. Revision 1.83 2003/06/03 20:27:02 daniel
  1422. * Restored original methodpointer code for non newra case
  1423. Revision 1.82 2003/06/03 13:01:59 daniel
  1424. * Register allocator finished
  1425. Revision 1.81 2003/06/01 21:38:06 peter
  1426. * getregisterfpu size parameter added
  1427. * op_const_reg size parameter added
  1428. * sparc updates
  1429. Revision 1.80 2003/05/31 15:05:28 peter
  1430. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1431. Revision 1.79 2003/05/31 00:59:44 peter
  1432. * typo in FUNCTION_RESULT_REG
  1433. Revision 1.78 2003/05/30 23:57:08 peter
  1434. * more sparc cleanup
  1435. * accumulator removed, splitted in function_return_reg (called) and
  1436. function_result_reg (caller)
  1437. Revision 1.77 2003/05/29 10:05:40 jonas
  1438. * free callparatemps created for call-by-reference parameters
  1439. Revision 1.76 2003/05/28 23:58:18 jonas
  1440. * added missing initialization of rg.usedintin,byproc
  1441. * ppc now also saves/restores used fpu registers
  1442. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1443. i386
  1444. Revision 1.75 2003/05/26 21:17:17 peter
  1445. * procinlinenode removed
  1446. * aktexit2label removed, fast exit removed
  1447. + tcallnode.inlined_pass_2 added
  1448. Revision 1.74 2003/05/25 11:34:17 peter
  1449. * methodpointer self pushing fixed
  1450. Revision 1.73 2003/05/25 08:59:16 peter
  1451. * inline fixes
  1452. Revision 1.72 2003/05/24 13:36:54 jonas
  1453. * save fpu results in a normal fpu register on non-x86 processors
  1454. Revision 1.71 2003/05/23 19:35:50 jonas
  1455. - undid previous commit, it was wrong
  1456. Revision 1.70 2003/05/23 19:11:58 jonas
  1457. * fixed tests for whether a certain int register is unused
  1458. Revision 1.69 2003/05/23 18:01:56 jonas
  1459. * fixed ppc compiler
  1460. Revision 1.68 2003/05/23 14:27:35 peter
  1461. * remove some unit dependencies
  1462. * current_procinfo changes to store more info
  1463. Revision 1.67 2003/05/17 13:30:08 jonas
  1464. * changed tt_persistant to tt_persistent :)
  1465. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1466. temps, but a ttemptype, so you can also create ansistring temps etc
  1467. Revision 1.66 2003/05/16 14:33:31 peter
  1468. * regvar fixes
  1469. Revision 1.65 2003/05/15 18:58:53 peter
  1470. * removed selfpointer_offset, vmtpointer_offset
  1471. * tvarsym.adjusted_address
  1472. * address in localsymtable is now in the real direction
  1473. * removed some obsolete globals
  1474. Revision 1.64 2003/05/14 19:36:54 jonas
  1475. * patch from Peter for int64 function results
  1476. Revision 1.63 2003/05/13 19:14:41 peter
  1477. * failn removed
  1478. * inherited result code check moven to pexpr
  1479. Revision 1.62 2003/05/13 15:18:18 peter
  1480. * generate code for procvar first before pushing parameters. Made
  1481. the already existing code for powerpc available for all platforms
  1482. Revision 1.61 2003/05/12 18:17:55 jonas
  1483. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1484. already-loaded parameter registers
  1485. Revision 1.60 2003/05/11 21:48:38 jonas
  1486. * fixed procvar bug on the ppc (load procvar before loading para's,
  1487. because the procvar may otherwise destroy the already loaded paras)
  1488. Revision 1.59 2003/05/09 17:47:02 peter
  1489. * self moved to hidden parameter
  1490. * removed hdisposen,hnewn,selfn
  1491. Revision 1.58 2003/05/05 14:53:16 peter
  1492. * vs_hidden replaced by is_hidden boolean
  1493. Revision 1.57 2003/04/30 20:53:32 florian
  1494. * error when address of an abstract method is taken
  1495. * fixed some x86-64 problems
  1496. * merged some more x86-64 and i386 code
  1497. Revision 1.56 2003/04/29 07:28:52 michael
  1498. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1499. Revision 1.55 2003/04/27 11:21:33 peter
  1500. * aktprocdef renamed to current_procinfo.procdef
  1501. * procinfo renamed to current_procinfo
  1502. * procinfo will now be stored in current_module so it can be
  1503. cleaned up properly
  1504. * gen_main_procsym changed to create_main_proc and release_main_proc
  1505. to also generate a tprocinfo structure
  1506. * fixed unit implicit initfinal
  1507. Revision 1.54 2003/04/27 07:29:50 peter
  1508. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  1509. a new procdef declaration
  1510. * aktprocsym removed
  1511. * lexlevel removed, use symtable.symtablelevel instead
  1512. * implicit init/final code uses the normal genentry/genexit
  1513. * funcret state checking updated for new funcret handling
  1514. Revision 1.53 2003/04/25 20:59:33 peter
  1515. * removed funcretn,funcretsym, function result is now in varsym
  1516. and aliases for result and function name are added using absolutesym
  1517. * vs_hidden parameter for funcret passed in parameter
  1518. * vs_hidden fixes
  1519. * writenode changed to printnode and released from extdebug
  1520. * -vp option added to generate a tree.log with the nodetree
  1521. * nicer printnode for statements, callnode
  1522. Revision 1.52 2003/04/25 08:25:26 daniel
  1523. * Ifdefs around a lot of calls to cleartempgen
  1524. * Fixed registers that are allocated but not freed in several nodes
  1525. * Tweak to register allocator to cause less spills
  1526. * 8-bit registers now interfere with esi,edi and ebp
  1527. Compiler can now compile rtl successfully when using new register
  1528. allocator
  1529. Revision 1.51 2003/04/22 23:50:22 peter
  1530. * firstpass uses expectloc
  1531. * checks if there are differences between the expectloc and
  1532. location.loc from secondpass in EXTDEBUG
  1533. Revision 1.50 2003/04/22 14:33:38 peter
  1534. * removed some notes/hints
  1535. Revision 1.49 2003/04/22 13:47:08 peter
  1536. * fixed C style array of const
  1537. * fixed C array passing
  1538. * fixed left to right with high parameters
  1539. Revision 1.48 2003/04/22 10:09:34 daniel
  1540. + Implemented the actual register allocator
  1541. + Scratch registers unavailable when new register allocator used
  1542. + maybe_save/maybe_restore unavailable when new register allocator used
  1543. Revision 1.47 2003/04/22 09:49:44 peter
  1544. * do not load self when calling a non-inherited class constructor
  1545. Revision 1.46 2003/04/21 20:03:32 peter
  1546. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1547. Revision 1.45 2003/04/21 13:53:16 jonas
  1548. - removed copying of all paras when secondpassing a callnode (this used
  1549. to be necessary for inlinign support, but currently the whole inlined
  1550. procedure is already copied in advance). Note that the compiler crashes
  1551. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1552. syntax errors), but that was also the case before this change.
  1553. Revision 1.44 2003/04/10 17:57:52 peter
  1554. * vs_hidden released
  1555. Revision 1.43 2003/04/06 21:11:23 olle
  1556. * changed newasmsymbol to newasmsymboldata for data symbols
  1557. Revision 1.42 2003/04/04 15:38:56 peter
  1558. * moved generic code from n386cal to ncgcal, i386 now also
  1559. uses the generic ncgcal
  1560. Revision 1.41 2003/03/28 19:16:56 peter
  1561. * generic constructor working for i386
  1562. * remove fixed self register
  1563. * esi added as address register for i386
  1564. Revision 1.40 2003/03/06 11:35:50 daniel
  1565. * Fixed internalerror 7843 issue
  1566. Revision 1.39 2003/02/19 22:00:14 daniel
  1567. * Code generator converted to new register notation
  1568. - Horribily outdated todo.txt removed
  1569. Revision 1.38 2003/02/15 22:17:38 carl
  1570. * bugfix of FPU emulation code
  1571. Revision 1.37 2003/02/12 22:10:07 carl
  1572. * load_frame_pointer is now generic
  1573. * change fpu emulation routine names
  1574. Revision 1.36 2003/01/30 21:46:57 peter
  1575. * self fixes for static methods (merged)
  1576. Revision 1.35 2003/01/22 20:45:15 mazen
  1577. * making math code in RTL compiling.
  1578. *NB : This does NOT mean necessary that it will generate correct code!
  1579. Revision 1.34 2003/01/17 12:03:45 daniel
  1580. * Optalign conditional code adapted to record Tregister
  1581. Revision 1.33 2003/01/08 18:43:56 daniel
  1582. * Tregister changed into a record
  1583. Revision 1.32 2002/12/15 22:50:00 florian
  1584. + some stuff for the new hidden parameter handling added
  1585. Revision 1.31 2002/12/15 21:30:12 florian
  1586. * tcallnode.paraitem introduced, all references to defcoll removed
  1587. Revision 1.30 2002/11/27 20:04:39 peter
  1588. * cdecl array of const fixes
  1589. Revision 1.29 2002/11/25 17:43:17 peter
  1590. * splitted defbase in defutil,symutil,defcmp
  1591. * merged isconvertable and is_equal into compare_defs(_ext)
  1592. * made operator search faster by walking the list only once
  1593. Revision 1.28 2002/11/18 17:31:54 peter
  1594. * pass proccalloption to ret_in_xxx and push_xxx functions
  1595. Revision 1.27 2002/11/16 15:34:30 florian
  1596. * generic location for float results
  1597. Revision 1.26 2002/11/15 01:58:51 peter
  1598. * merged changes from 1.0.7 up to 04-11
  1599. - -V option for generating bug report tracing
  1600. - more tracing for option parsing
  1601. - errors for cdecl and high()
  1602. - win32 import stabs
  1603. - win32 records<=8 are returned in eax:edx (turned off by default)
  1604. - heaptrc update
  1605. - more info for temp management in .s file with EXTDEBUG
  1606. Revision 1.25 2002/10/05 12:43:25 carl
  1607. * fixes for Delphi 6 compilation
  1608. (warning : Some features do not work under Delphi)
  1609. Revision 1.24 2002/09/30 07:00:45 florian
  1610. * fixes to common code to get the alpha compiler compiled applied
  1611. Revision 1.23 2002/09/17 18:54:02 jonas
  1612. * a_load_reg_reg() now has two size parameters: source and dest. This
  1613. allows some optimizations on architectures that don't encode the
  1614. register size in the register name.
  1615. Revision 1.22 2002/09/07 15:25:02 peter
  1616. * old logs removed and tabs fixed
  1617. Revision 1.21 2002/09/07 11:50:02 jonas
  1618. * fixed small regalloction info bug
  1619. Revision 1.20 2002/09/02 11:25:20 florian
  1620. * fixed generic procedure variable calling
  1621. Revision 1.19 2002/09/01 21:04:48 florian
  1622. * several powerpc related stuff fixed
  1623. Revision 1.18 2002/09/01 18:43:27 peter
  1624. * include FUNCTION_RETURN_REG in regs_to_push list
  1625. Revision 1.17 2002/09/01 12:13:00 peter
  1626. * use a_call_reg
  1627. * ungetiftemp for procvar of object temp
  1628. Revision 1.16 2002/08/25 19:25:18 peter
  1629. * sym.insert_in_data removed
  1630. * symtable.insertvardata/insertconstdata added
  1631. * removed insert_in_data call from symtable.insert, it needs to be
  1632. called separatly. This allows to deref the address calculation
  1633. * procedures now calculate the parast addresses after the procedure
  1634. directives are parsed. This fixes the cdecl parast problem
  1635. * push_addr_param has an extra argument that specifies if cdecl is used
  1636. or not
  1637. Revision 1.15 2002/08/23 16:14:48 peter
  1638. * tempgen cleanup
  1639. * tt_noreuse temp type added that will be used in genentrycode
  1640. Revision 1.14 2002/08/20 16:55:38 peter
  1641. * don't write (stabs)line info when inlining a procedure
  1642. Revision 1.13 2002/08/19 19:36:42 peter
  1643. * More fixes for cross unit inlining, all tnodes are now implemented
  1644. * Moved pocall_internconst to po_internconst because it is not a
  1645. calling type at all and it conflicted when inlining of these small
  1646. functions was requested
  1647. Revision 1.12 2002/08/18 20:06:23 peter
  1648. * inlining is now also allowed in interface
  1649. * renamed write/load to ppuwrite/ppuload
  1650. * tnode storing in ppu
  1651. * nld,ncon,nbas are already updated for storing in ppu
  1652. Revision 1.11 2002/08/17 22:09:44 florian
  1653. * result type handling in tcgcal.pass_2 overhauled
  1654. * better tnode.dowrite
  1655. * some ppc stuff fixed
  1656. Revision 1.10 2002/08/17 09:23:35 florian
  1657. * first part of procinfo rewrite
  1658. Revision 1.9 2002/08/13 21:40:55 florian
  1659. * more fixes for ppc calling conventions
  1660. Revision 1.8 2002/08/13 18:01:51 carl
  1661. * rename swatoperands to swapoperands
  1662. + m68k first compilable version (still needs a lot of testing):
  1663. assembler generator, system information , inline
  1664. assembler reader.
  1665. Revision 1.7 2002/08/12 15:08:39 carl
  1666. + stab register indexes for powerpc (moved from gdb to cpubase)
  1667. + tprocessor enumeration moved to cpuinfo
  1668. + linker in target_info is now a class
  1669. * many many updates for m68k (will soon start to compile)
  1670. - removed some ifdef or correct them for correct cpu
  1671. Revision 1.6 2002/08/11 14:32:26 peter
  1672. * renamed current_library to objectlibrary
  1673. Revision 1.5 2002/08/11 13:24:11 peter
  1674. * saving of asmsymbols in ppu supported
  1675. * asmsymbollist global is removed and moved into a new class
  1676. tasmlibrarydata that will hold the info of a .a file which
  1677. corresponds with a single module. Added librarydata to tmodule
  1678. to keep the library info stored for the module. In the future the
  1679. objectfiles will also be stored to the tasmlibrarydata class
  1680. * all getlabel/newasmsymbol and friends are moved to the new class
  1681. Revision 1.4 2002/08/06 20:55:20 florian
  1682. * first part of ppc calling conventions fix
  1683. Revision 1.3 2002/07/20 11:57:53 florian
  1684. * types.pas renamed to defbase.pas because D6 contains a types
  1685. unit so this would conflicts if D6 programms are compiled
  1686. + Willamette/SSE2 instructions to assembler added
  1687. Revision 1.2 2002/07/13 19:38:43 florian
  1688. * some more generic calling stuff fixed
  1689. }