ncgutil.pas 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Helper routines for all code generators
  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 ncgutil;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,cpuinfo,
  23. globtype,
  24. cpubase,
  25. aasmbase,aasmtai,aasmcpu,
  26. cginfo,symconst,symbase,symdef,symsym,symtype,symtable,
  27. {$ifndef cpu64bit}
  28. cg64f32,
  29. {$endif cpu64bit}
  30. rgobj;
  31. type
  32. tloadregvars = (lr_dont_load_regvars, lr_load_regvars);
  33. procedure firstcomplex(p : tbinarynode);
  34. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  35. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  36. procedure location_force_reg(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  37. procedure location_force_fpureg(list: TAAsmoutput;var l: tlocation;maybeconst:boolean);
  38. procedure location_force_mem(list: TAAsmoutput;var l:tlocation);
  39. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  40. procedure gen_proc_symbol(list:Taasmoutput);
  41. procedure gen_proc_symbol_end(list:Taasmoutput);
  42. procedure gen_stackalloc_code(list:Taasmoutput);
  43. procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
  44. procedure gen_save_used_regs(list : TAAsmoutput);
  45. procedure gen_restore_used_regs(list : TAAsmoutput;usesacc,usesacchi,usesfpu:boolean);
  46. procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean);
  47. procedure gen_finalize_code(list : TAAsmoutput;inlined:boolean);
  48. procedure gen_load_para_value(list:TAAsmoutput);
  49. procedure gen_load_return_value(list:TAAsmoutput; var uses_acc,uses_acchi,uses_fpu : boolean);
  50. (*
  51. procedure geninlineentrycode(list : TAAsmoutput;stackframe:longint);
  52. procedure geninlineexitcode(list : TAAsmoutput;inlined:boolean);
  53. *)
  54. {#
  55. Allocate the buffers for exception management and setjmp environment.
  56. Return a pointer to these buffers, send them to the utility routine
  57. so they are registered, and then call setjmp.
  58. Then compare the result of setjmp with 0, and if not equal
  59. to zero, then jump to exceptlabel.
  60. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  61. It is to note that this routine may be called *after* the stackframe of a
  62. routine has been called, therefore on machines where the stack cannot
  63. be modified, all temps should be allocated on the heap instead of the
  64. stack.
  65. }
  66. procedure new_exception(list : taasmoutput;const jmpbuf,envbuf, href : treference;
  67. a : aword; exceptlabel : tasmlabel);
  68. procedure free_exception(list : taasmoutput;const jmpbuf, envbuf, href : treference;
  69. a : aword ; endexceptlabel : tasmlabel; onlyfree : boolean);
  70. procedure insertconstdata(sym : ttypedconstsym);
  71. procedure insertbssdata(sym : tvarsym);
  72. procedure gen_alloc_localst(list: taasmoutput;st:tlocalsymtable);
  73. procedure gen_free_localst(list: taasmoutput;st:tlocalsymtable);
  74. procedure gen_alloc_parast(list: taasmoutput;st:tparasymtable);
  75. procedure gen_free_parast(list: taasmoutput;st:tparasymtable);
  76. implementation
  77. uses
  78. {$ifdef Delphi}
  79. Sysutils,
  80. {$else}
  81. strings,
  82. {$endif}
  83. cutils,cclasses,
  84. globals,systems,verbose,
  85. defutil,
  86. paramgr,fmodule,
  87. cgbase,regvars,
  88. {$ifdef GDB}
  89. gdb,
  90. {$endif GDB}
  91. ncon,
  92. tgobj,cgobj;
  93. const
  94. { Please leave this here, this module should NOT use
  95. exprasmlist, the lists are always passed as arguments.
  96. Declaring it as string here results in an error when compiling (PFV) }
  97. exprasmlist = 'error';
  98. {*****************************************************************************
  99. Misc Helpers
  100. *****************************************************************************}
  101. { DO NOT RELY on the fact that the tnode is not yet swaped
  102. because of inlining code PM }
  103. procedure firstcomplex(p : tbinarynode);
  104. var
  105. hp : tnode;
  106. begin
  107. { always calculate boolean AND and OR from left to right }
  108. if (p.nodetype in [orn,andn]) and
  109. is_boolean(p.left.resulttype.def) then
  110. begin
  111. if nf_swaped in p.flags then
  112. internalerror(234234);
  113. end
  114. else
  115. if (
  116. (p.location.loc=LOC_FPUREGISTER) and
  117. (p.right.registersfpu > p.left.registersfpu)
  118. ) or
  119. (
  120. (
  121. (
  122. ((p.left.registersfpu = 0) and (p.right.registersfpu = 0)) or
  123. (p.location.loc<>LOC_FPUREGISTER)
  124. ) and
  125. (p.left.registers32<p.right.registers32)
  126. ) and
  127. { the following check is appropriate, because all }
  128. { 4 registers are rarely used and it is thereby }
  129. { achieved that the extra code is being dropped }
  130. { by exchanging not commutative operators }
  131. (p.right.registers32<=c_countusableregsint)
  132. ) then
  133. begin
  134. hp:=p.left;
  135. p.left:=p.right;
  136. p.right:=hp;
  137. if nf_swaped in p.flags then
  138. exclude(p.flags,nf_swaped)
  139. else
  140. include(p.flags,nf_swaped);
  141. end;
  142. end;
  143. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  144. {
  145. produces jumps to true respectively false labels using boolean expressions
  146. depending on whether the loading of regvars is currently being
  147. synchronized manually (such as in an if-node) or automatically (most of
  148. the other cases where this procedure is called), loadregvars can be
  149. "lr_load_regvars" or "lr_dont_load_regvars"
  150. }
  151. var
  152. opsize : tcgsize;
  153. storepos : tfileposinfo;
  154. begin
  155. if nf_error in p.flags then
  156. exit;
  157. storepos:=aktfilepos;
  158. aktfilepos:=p.fileinfo;
  159. if is_boolean(p.resulttype.def) then
  160. begin
  161. if loadregvars = lr_load_regvars then
  162. load_all_regvars(list);
  163. if is_constboolnode(p) then
  164. begin
  165. if tordconstnode(p).value<>0 then
  166. cg.a_jmp_always(list,truelabel)
  167. else
  168. cg.a_jmp_always(list,falselabel)
  169. end
  170. else
  171. begin
  172. opsize:=def_cgsize(p.resulttype.def);
  173. case p.location.loc of
  174. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  175. begin
  176. if (p.location.loc = LOC_CREGISTER) then
  177. load_regvar_reg(list,p.location.register);
  178. cg.a_cmp_const_loc_label(list,opsize,OC_NE,
  179. 0,p.location,truelabel);
  180. { !!! should happen right after cmp (JM) }
  181. location_release(list,p.location);
  182. cg.a_jmp_always(list,falselabel);
  183. end;
  184. LOC_JUMP:
  185. ;
  186. {$ifdef cpuflags}
  187. LOC_FLAGS :
  188. begin
  189. cg.a_jmp_flags(list,p.location.resflags,
  190. truelabel);
  191. cg.a_jmp_always(list,falselabel);
  192. end;
  193. {$endif cpuflags}
  194. else
  195. internalerror(200308241);
  196. end;
  197. end;
  198. end
  199. else
  200. internalerror(200112305);
  201. aktfilepos:=storepos;
  202. end;
  203. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  204. begin
  205. case t.loc of
  206. LOC_REGISTER:
  207. begin
  208. { can't be a regvar, since it would be LOC_CREGISTER then }
  209. exclude(regs,getsupreg(t.register));
  210. if t.registerhigh<>NR_NO then
  211. exclude(regs,getsupreg(t.registerhigh));
  212. end;
  213. LOC_CREFERENCE,LOC_REFERENCE:
  214. begin
  215. if not(cs_regvars in aktglobalswitches) or
  216. (getsupreg(t.reference.base) in rg.usableregsint) then
  217. exclude(regs,getsupreg(t.reference.base));
  218. if not(cs_regvars in aktglobalswitches) or
  219. (getsupreg(t.reference.index) in rg.usableregsint) then
  220. exclude(regs,getsupreg(t.reference.index));
  221. end;
  222. end;
  223. end;
  224. {*****************************************************************************
  225. EXCEPTION MANAGEMENT
  226. *****************************************************************************}
  227. procedure new_exception(list : taasmoutput;const jmpbuf,envbuf, href : treference;
  228. a : aword; exceptlabel : tasmlabel);
  229. var
  230. paraloc1,paraloc2,paraloc3 : tparalocation;
  231. begin
  232. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  233. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  234. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  235. paramanager.allocparaloc(list,paraloc3);
  236. cg.a_paramaddr_ref(list,envbuf,paraloc3);
  237. paramanager.allocparaloc(list,paraloc2);
  238. cg.a_paramaddr_ref(list,jmpbuf,paraloc2);
  239. { push type of exceptionframe }
  240. paramanager.allocparaloc(list,paraloc1);
  241. cg.a_param_const(list,OS_S32,1,paraloc1);
  242. paramanager.freeparaloc(list,paraloc3);
  243. paramanager.freeparaloc(list,paraloc2);
  244. paramanager.freeparaloc(list,paraloc1);
  245. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  246. cg.a_call_name(list,'FPC_PUSHEXCEPTADDR');
  247. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  248. paramanager.allocparaloc(list,paraloc1);
  249. cg.a_param_reg(list,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  250. paramanager.freeparaloc(list,paraloc1);
  251. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  252. cg.a_call_name(list,'FPC_SETJMP');
  253. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  254. cg.g_exception_reason_save(list, href);
  255. cg.a_cmp_const_reg_label(list,OS_S32,OC_NE,0,NR_FUNCTION_RESULT_REG,exceptlabel);
  256. end;
  257. procedure free_exception(list : taasmoutput;const jmpbuf, envbuf, href : treference;
  258. a : aword ; endexceptlabel : tasmlabel; onlyfree : boolean);
  259. begin
  260. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  261. cg.a_call_name(list,'FPC_POPADDRSTACK');
  262. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  263. if not onlyfree then
  264. begin
  265. cg.g_exception_reason_load(list, href);
  266. cg.a_cmp_const_reg_label(list,OS_S32,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
  267. end;
  268. end;
  269. {*****************************************************************************
  270. TLocation
  271. *****************************************************************************}
  272. {$ifndef cpu64bit}
  273. { 32-bit version }
  274. procedure location_force_reg(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  275. var
  276. hregister,
  277. hregisterhi : tregister;
  278. hreg64 : tregister64;
  279. hl : tasmlabel;
  280. oldloc : tlocation;
  281. begin
  282. oldloc:=l;
  283. if dst_size=OS_NO then
  284. internalerror(200309144);
  285. { handle transformations to 64bit separate }
  286. if dst_size in [OS_64,OS_S64] then
  287. begin
  288. if not (l.size in [OS_64,OS_S64]) then
  289. begin
  290. { load a smaller size to OS_64 }
  291. if l.loc=LOC_REGISTER then
  292. begin
  293. hregister:=rg.makeregsize(l.registerlow,OS_32);
  294. cg.a_load_reg_reg(list,l.size,OS_32,l.registerlow,hregister);
  295. end
  296. else
  297. begin
  298. location_release(list,l);
  299. hregister:=rg.getregisterint(list,OS_INT);
  300. end;
  301. { load value in low register }
  302. case l.loc of
  303. LOC_FLAGS :
  304. cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
  305. LOC_JUMP :
  306. begin
  307. cg.a_label(list,truelabel);
  308. cg.a_load_const_reg(list,OS_INT,1,hregister);
  309. objectlibrary.getlabel(hl);
  310. cg.a_jmp_always(list,hl);
  311. cg.a_label(list,falselabel);
  312. cg.a_load_const_reg(list,OS_INT,0,hregister);
  313. cg.a_label(list,hl);
  314. end;
  315. else
  316. cg.a_load_loc_reg(list,OS_INT,l,hregister);
  317. end;
  318. { reset hi part, take care of the signed bit of the current value }
  319. hregisterhi:=rg.getregisterint(list,OS_INT);
  320. if (dst_size=OS_S64) and
  321. (l.size in [OS_S8,OS_S16,OS_S32]) then
  322. begin
  323. if l.loc=LOC_CONSTANT then
  324. begin
  325. if (longint(l.value)<0) then
  326. cg.a_load_const_reg(list,OS_32,$ffffffff,hregisterhi)
  327. else
  328. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  329. end
  330. else
  331. begin
  332. cg.a_op_const_reg_reg(list,OP_SAR,OS_32,31,hregister,
  333. hregisterhi);
  334. end;
  335. end
  336. else
  337. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  338. location_reset(l,LOC_REGISTER,dst_size);
  339. l.registerlow:=hregister;
  340. l.registerhigh:=hregisterhi;
  341. end
  342. else
  343. begin
  344. { 64bit to 64bit }
  345. if (l.loc=LOC_REGISTER) or
  346. ((l.loc=LOC_CREGISTER) and maybeconst) then
  347. begin
  348. hregister:=l.registerlow;
  349. hregisterhi:=l.registerhigh;
  350. end
  351. else
  352. begin
  353. hregister:=rg.getregisterint(list,OS_INT);
  354. hregisterhi:=rg.getregisterint(list,OS_INT);
  355. location_release(list,l);
  356. end;
  357. hreg64.reglo:=hregister;
  358. hreg64.reghi:=hregisterhi;
  359. { load value in new register }
  360. cg64.a_load64_loc_reg(list,l,hreg64,false);
  361. location_reset(l,LOC_REGISTER,dst_size);
  362. l.registerlow:=hregister;
  363. l.registerhigh:=hregisterhi;
  364. end;
  365. end
  366. else
  367. begin
  368. { transformations to 32bit or smaller }
  369. if (l.loc=LOC_REGISTER) and (l.size in [OS_64,OS_S64]) then
  370. { if the previous was 64bit release the high register }
  371. begin
  372. rg.ungetregisterint(list,l.registerhigh);
  373. l.registerhigh:=NR_NO;
  374. end;
  375. {Do not bother to recycle the existing register. The register
  376. allocator eliminates unnecessary moves, so it's not needed
  377. and trying to recycle registers can cause problems because
  378. the registers changes size and may need aditional constraints.}
  379. location_release(list,l);
  380. hregister:=rg.getregisterint(list,dst_size);
  381. { load value in new register }
  382. case l.loc of
  383. LOC_FLAGS :
  384. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  385. LOC_JUMP :
  386. begin
  387. cg.a_label(list,truelabel);
  388. cg.a_load_const_reg(list,dst_size,1,hregister);
  389. objectlibrary.getlabel(hl);
  390. cg.a_jmp_always(list,hl);
  391. cg.a_label(list,falselabel);
  392. cg.a_load_const_reg(list,dst_size,0,hregister);
  393. cg.a_label(list,hl);
  394. end;
  395. else
  396. begin
  397. { load_loc_reg can only handle size >= l.size, when the
  398. new size is smaller then we need to adjust the size
  399. of the orignal and maybe recalculate l.register for i386 }
  400. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  401. begin
  402. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  403. l.register:=rg.makeregsize(l.register,dst_size);
  404. { for big endian systems, the reference's offset must }
  405. { be increased in this case, since they have the }
  406. { MSB first in memory and e.g. byte(word_var) should }
  407. { return the second byte in this case (JM) }
  408. if (target_info.endian = ENDIAN_BIG) and
  409. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  410. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  411. {$ifdef i386}
  412. l.size:=dst_size;
  413. {$endif i386}
  414. end;
  415. cg.a_load_loc_reg(list,dst_size,l,hregister);
  416. {$ifndef i386}
  417. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  418. l.size:=dst_size;
  419. {$endif not i386}
  420. end;
  421. end;
  422. if (l.loc <> LOC_CREGISTER) or
  423. not maybeconst then
  424. location_reset(l,LOC_REGISTER,dst_size)
  425. else
  426. location_reset(l,LOC_CREGISTER,dst_size);
  427. l.register:=hregister;
  428. end;
  429. { Release temp when it was a reference }
  430. if oldloc.loc=LOC_REFERENCE then
  431. location_freetemp(list,oldloc);
  432. end;
  433. {$else cpu64bit}
  434. { 64-bit version }
  435. procedure location_force_reg(list: TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  436. var
  437. hregister : tregister;
  438. hl : tasmlabel;
  439. oldloc : tlocation;
  440. begin
  441. oldloc:=l;
  442. if dst_size=OS_NO then
  443. internalerror(200309144);
  444. { handle transformations to 64bit separate }
  445. if dst_size in [OS_64,OS_S64] then
  446. begin
  447. { load a smaller size to OS_64 }
  448. if l.loc=LOC_REGISTER then
  449. hregister:=rg.makeregsize(l.register,OS_INT)
  450. else
  451. begin
  452. location_release(list,l);
  453. hregister:=rg.getregisterint(list,OS_INT);
  454. end;
  455. { load value in low register }
  456. case l.loc of
  457. {$ifdef cpuflags}
  458. LOC_FLAGS :
  459. cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
  460. {$endif cpuflags}
  461. LOC_JUMP :
  462. begin
  463. cg.a_label(list,truelabel);
  464. cg.a_load_const_reg(list,OS_INT,1,hregister);
  465. objectlibrary.getlabel(hl);
  466. cg.a_jmp_always(list,hl);
  467. cg.a_label(list,falselabel);
  468. cg.a_load_const_reg(list,OS_INT,0,hregister);
  469. cg.a_label(list,hl);
  470. end;
  471. else
  472. cg.a_load_loc_reg(list,OS_INT,l,hregister);
  473. end;
  474. location_reset(l,LOC_REGISTER,dst_size);
  475. l.register:=hregister;
  476. end
  477. else
  478. begin
  479. { transformations to 32bit or smaller }
  480. if l.loc=LOC_REGISTER then
  481. begin
  482. hregister:=l.register;
  483. end
  484. else
  485. begin
  486. { get new register }
  487. if (l.loc=LOC_CREGISTER) and
  488. maybeconst and
  489. (TCGSize2Size[dst_size]=TCGSize2Size[l.size]) then
  490. hregister:=l.register
  491. else
  492. begin
  493. location_release(list,l);
  494. hregister:=rg.getregisterint(list,OS_INT);
  495. end;
  496. end;
  497. hregister:=rg.makeregsize(hregister,dst_size);
  498. { load value in new register }
  499. case l.loc of
  500. {$ifdef cpuflags}
  501. LOC_FLAGS :
  502. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  503. {$endif cpuflags}
  504. LOC_JUMP :
  505. begin
  506. cg.a_label(list,truelabel);
  507. cg.a_load_const_reg(list,dst_size,1,hregister);
  508. objectlibrary.getlabel(hl);
  509. cg.a_jmp_always(list,hl);
  510. cg.a_label(list,falselabel);
  511. cg.a_load_const_reg(list,dst_size,0,hregister);
  512. cg.a_label(list,hl);
  513. end;
  514. else
  515. begin
  516. { load_loc_reg can only handle size >= l.size, when the
  517. new size is smaller then we need to adjust the size
  518. of the orignal and maybe recalculate l.register for i386 }
  519. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  520. begin
  521. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  522. l.register:=rg.makeregsize(l.register,dst_size);
  523. { for big endian systems, the reference's offset must }
  524. { be increased in this case, since they have the }
  525. { MSB first in memory and e.g. byte(word_var) should }
  526. { return the second byte in this case (JM) }
  527. if (target_info.endian = ENDIAN_BIG) and
  528. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  529. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  530. {$ifdef i386}
  531. l.size:=dst_size;
  532. {$endif i386}
  533. end;
  534. cg.a_load_loc_reg(list,dst_size,l,hregister);
  535. {$ifndef i386}
  536. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  537. l.size:=dst_size;
  538. {$endif not i386}
  539. end;
  540. end;
  541. location_reset(l,LOC_REGISTER,dst_size);
  542. l.register:=hregister;
  543. end;
  544. { Release temp when it was a reference }
  545. if oldloc.loc=LOC_REFERENCE then
  546. location_freetemp(list,oldloc);
  547. end;
  548. {$endif cpu64bit}
  549. procedure location_force_fpureg(list: TAAsmoutput;var l: tlocation;maybeconst:boolean);
  550. var
  551. reg : tregister;
  552. begin
  553. if (l.loc<>LOC_FPUREGISTER) and
  554. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  555. begin
  556. reg:=rg.getregisterfpu(list,l.size);
  557. cg.a_loadfpu_loc_reg(list,l,reg);
  558. location_freetemp(list,l);
  559. location_release(list,l);
  560. location_reset(l,LOC_FPUREGISTER,l.size);
  561. l.register:=reg;
  562. end;
  563. end;
  564. procedure location_force_mem(list: TAAsmoutput;var l:tlocation);
  565. var
  566. r : treference;
  567. begin
  568. case l.loc of
  569. LOC_FPUREGISTER,
  570. LOC_CFPUREGISTER :
  571. begin
  572. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  573. cg.a_loadfpu_reg_ref(list,l.size,l.register,r);
  574. location_release(list,l);
  575. location_reset(l,LOC_REFERENCE,l.size);
  576. l.reference:=r;
  577. end;
  578. LOC_CONSTANT,
  579. LOC_REGISTER,
  580. LOC_CREGISTER :
  581. begin
  582. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  583. if l.size in [OS_64,OS_S64] then
  584. begin
  585. cg64.a_load64_loc_ref(list,l,r);
  586. location_release(list,l);
  587. end
  588. else
  589. begin
  590. location_release(list,l);
  591. cg.a_load_loc_ref(list,l.size,l,r);
  592. end;
  593. location_reset(l,LOC_REFERENCE,l.size);
  594. l.reference:=r;
  595. end;
  596. LOC_CREFERENCE,
  597. LOC_REFERENCE : ;
  598. else
  599. internalerror(200203219);
  600. end;
  601. end;
  602. {*****************************************************************************
  603. Maybe_Save
  604. *****************************************************************************}
  605. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  606. begin
  607. if (needed>=maxfpuregs) and
  608. (l.loc = LOC_FPUREGISTER) then
  609. begin
  610. location_force_mem(list,l);
  611. maybe_pushfpu:=true;
  612. end
  613. else
  614. maybe_pushfpu:=false;
  615. end;
  616. {****************************************************************************
  617. Init/Finalize Code
  618. ****************************************************************************}
  619. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  620. var
  621. href1,href2 : treference;
  622. list : taasmoutput;
  623. hsym : tvarsym;
  624. l : longint;
  625. loadref : boolean;
  626. localcopyloc : tparalocation;
  627. begin
  628. list:=taasmoutput(arg);
  629. if (tsym(p).typ=varsym) and
  630. (tvarsym(p).varspez=vs_value) and
  631. (paramanager.push_addr_param(tvarsym(p).varspez,tvarsym(p).vartype.def,current_procinfo.procdef.proccalloption)) then
  632. begin
  633. loadref:=true;
  634. case tvarsym(p).localloc.loc of
  635. LOC_REGISTER :
  636. begin
  637. reference_reset_base(href1,tvarsym(p).localloc.register,0);
  638. loadref:=false;
  639. end;
  640. LOC_REFERENCE :
  641. reference_reset_base(href1,tvarsym(p).localloc.reference.index,
  642. tvarsym(p).localloc.reference.offset);
  643. else
  644. internalerror(200309181);
  645. end;
  646. if is_open_array(tvarsym(p).vartype.def) or
  647. is_array_of_const(tvarsym(p).vartype.def) then
  648. begin
  649. { cdecl functions don't have a high pointer so it is not possible to generate
  650. a local copy }
  651. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  652. begin
  653. hsym:=tvarsym(tsym(p).owner.search('high'+p.name));
  654. if not assigned(hsym) then
  655. internalerror(200306061);
  656. case hsym.localloc.loc of
  657. LOC_REFERENCE :
  658. begin
  659. reference_reset_base(href2,hsym.localloc.reference.index,hsym.localloc.reference.offset);
  660. cg.g_copyvaluepara_openarray(list,href1,href2,tarraydef(tvarsym(p).vartype.def).elesize)
  661. end
  662. else
  663. internalerror(200309182);
  664. end;
  665. end;
  666. end
  667. else
  668. begin
  669. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  670. internalerror(200309183);
  671. { Allocate space for the local copy }
  672. l:=tvarsym(p).getvaluesize;
  673. localcopyloc.loc:=LOC_REFERENCE;
  674. localcopyloc.size:=int_cgsize(l);
  675. tg.GetLocal(list,l,localcopyloc.reference);
  676. { Copy data }
  677. reference_reset_base(href2,localcopyloc.reference.index,localcopyloc.reference.offset);
  678. if is_shortstring(tvarsym(p).vartype.def) then
  679. cg.g_copyshortstring(list,href1,href2,tstringdef(tvarsym(p).vartype.def).len,false,loadref)
  680. else
  681. cg.g_concatcopy(list,href1,href2,tvarsym(p).vartype.def.size,true,loadref);
  682. { update localloc of varsym }
  683. tg.Ungetlocal(list,tvarsym(p).localloc.reference);
  684. tvarsym(p).localloc:=localcopyloc;
  685. end;
  686. end;
  687. end;
  688. { generates the code for initialisation of local data }
  689. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  690. var
  691. href : treference;
  692. list : taasmoutput;
  693. begin
  694. list:=taasmoutput(arg);
  695. if (tsym(p).typ=varsym) and
  696. (tvarsym(p).refs>0) and
  697. assigned(tvarsym(p).vartype.def) and
  698. not(is_class(tvarsym(p).vartype.def)) and
  699. tvarsym(p).vartype.def.needs_inittable then
  700. begin
  701. if (cs_implicit_exceptions in aktmoduleswitches) then
  702. include(current_procinfo.flags,pi_needs_implicit_finally);
  703. if tvarsym(p).owner.symtabletype in [localsymtable,inlinelocalsymtable] then
  704. begin
  705. case tvarsym(p).localloc.loc of
  706. LOC_REFERENCE :
  707. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  708. else
  709. internalerror(2003091810);
  710. end;
  711. end
  712. else
  713. reference_reset_symbol(href,objectlibrary.newasmsymboldata(tvarsym(p).mangledname),0);
  714. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  715. end;
  716. end;
  717. { generates the code for finalisation of local data }
  718. procedure finalize_data(p : tnamedindexitem;arg:pointer);
  719. var
  720. href : treference;
  721. list : taasmoutput;
  722. begin
  723. list:=taasmoutput(arg);
  724. case tsym(p).typ of
  725. varsym :
  726. begin
  727. if (tvarsym(p).refs>0) and
  728. not(vo_is_funcret in tvarsym(p).varoptions) and
  729. assigned(tvarsym(p).vartype.def) and
  730. not(is_class(tvarsym(p).vartype.def)) and
  731. tvarsym(p).vartype.def.needs_inittable then
  732. begin
  733. if tvarsym(p).owner.symtabletype in [localsymtable,inlinelocalsymtable] then
  734. begin
  735. case tvarsym(p).localloc.loc of
  736. LOC_REFERENCE :
  737. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  738. else
  739. internalerror(2003091811);
  740. end;
  741. end
  742. else
  743. reference_reset_symbol(href,objectlibrary.newasmsymboldata(tvarsym(p).mangledname),0);
  744. cg.g_finalize(list,tvarsym(p).vartype.def,href,false);
  745. end;
  746. end;
  747. typedconstsym :
  748. begin
  749. if ttypedconstsym(p).is_writable and
  750. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  751. begin
  752. reference_reset_symbol(href,objectlibrary.newasmsymboldata(ttypedconstsym(p).mangledname),0);
  753. cg.g_finalize(list,ttypedconstsym(p).typedconsttype.def,href,false);
  754. end;
  755. end;
  756. end;
  757. end;
  758. { generates the code for incrementing the reference count of parameters and
  759. initialize out parameters }
  760. procedure init_paras(p : tnamedindexitem;arg:pointer);
  761. var
  762. href : treference;
  763. tmpreg : tregister;
  764. list : taasmoutput;
  765. begin
  766. list:=taasmoutput(arg);
  767. if (tsym(p).typ=varsym) and
  768. not is_class(tvarsym(p).vartype.def) and
  769. tvarsym(p).vartype.def.needs_inittable then
  770. begin
  771. case tvarsym(p).varspez of
  772. vs_value :
  773. begin
  774. if (cs_implicit_exceptions in aktmoduleswitches) then
  775. include(current_procinfo.flags,pi_needs_implicit_finally);
  776. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  777. internalerror(200309187);
  778. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  779. cg.g_incrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  780. end;
  781. vs_out :
  782. begin
  783. case tvarsym(p).localloc.loc of
  784. LOC_REFERENCE :
  785. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  786. else
  787. internalerror(2003091810);
  788. end;
  789. tmpreg:=rg.getaddressregister(list);
  790. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,tmpreg);
  791. reference_reset_base(href,tmpreg,0);
  792. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  793. rg.ungetregisterint(list,tmpreg);
  794. end;
  795. end;
  796. end;
  797. end;
  798. { generates the code for decrementing the reference count of parameters }
  799. procedure final_paras(p : tnamedindexitem;arg:pointer);
  800. var
  801. href : treference;
  802. list : taasmoutput;
  803. begin
  804. list:=taasmoutput(arg);
  805. if (tsym(p).typ=varsym) and
  806. not is_class(tvarsym(p).vartype.def) and
  807. tvarsym(p).vartype.def.needs_inittable then
  808. begin
  809. if (tvarsym(p).varspez=vs_value) then
  810. begin
  811. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  812. internalerror(200309188);
  813. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  814. cg.g_decrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  815. end;
  816. end;
  817. end;
  818. { Initialize temp ansi/widestrings,interfaces }
  819. procedure inittempvariables(list:taasmoutput);
  820. var
  821. hp : ptemprecord;
  822. href : treference;
  823. begin
  824. hp:=tg.templist;
  825. while assigned(hp) do
  826. begin
  827. if hp^.temptype in [tt_ansistring,tt_freeansistring,
  828. tt_widestring,tt_freewidestring,
  829. tt_interfacecom,tt_freeinterfacecom] then
  830. begin
  831. if (cs_implicit_exceptions in aktmoduleswitches) then
  832. include(current_procinfo.flags,pi_needs_implicit_finally);
  833. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  834. cg.a_load_const_ref(list,OS_ADDR,0,href);
  835. end;
  836. hp:=hp^.next;
  837. end;
  838. end;
  839. procedure finalizetempvariables(list:taasmoutput);
  840. var
  841. hp : ptemprecord;
  842. href : treference;
  843. paraloc1 : tparalocation;
  844. begin
  845. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  846. hp:=tg.templist;
  847. while assigned(hp) do
  848. begin
  849. case hp^.temptype of
  850. tt_ansistring,
  851. tt_freeansistring :
  852. begin
  853. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  854. paramanager.allocparaloc(list,paraloc1);
  855. cg.a_paramaddr_ref(list,href,paraloc1);
  856. paramanager.freeparaloc(list,paraloc1);
  857. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  858. cg.a_call_name(list,'FPC_ANSISTR_DECR_REF');
  859. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  860. end;
  861. tt_widestring,
  862. tt_freewidestring :
  863. begin
  864. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  865. paramanager.allocparaloc(list,paraloc1);
  866. cg.a_paramaddr_ref(list,href,paraloc1);
  867. paramanager.freeparaloc(list,paraloc1);
  868. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  869. cg.a_call_name(list,'FPC_WIDESTR_DECR_REF');
  870. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  871. end;
  872. tt_interfacecom :
  873. begin
  874. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  875. paramanager.allocparaloc(list,paraloc1);
  876. cg.a_paramaddr_ref(list,href,paraloc1);
  877. paramanager.freeparaloc(list,paraloc1);
  878. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  879. cg.a_call_name(list,'FPC_INTF_DECR_REF');
  880. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  881. end;
  882. end;
  883. hp:=hp^.next;
  884. end;
  885. end;
  886. procedure gen_load_return_value(list:TAAsmoutput; var uses_acc,uses_acchi,uses_fpu : boolean);
  887. var
  888. ressym : tvarsym;
  889. resloc : tlocation;
  890. href : treference;
  891. hreg,r,r2 : tregister;
  892. begin
  893. { Is the loading needed? }
  894. if is_void(current_procinfo.procdef.rettype.def) or
  895. (
  896. (po_assembler in current_procinfo.procdef.procoptions) and
  897. (not(assigned(current_procinfo.procdef.funcretsym)) or
  898. (tvarsym(current_procinfo.procdef.funcretsym).refcount=0))
  899. ) then
  900. exit;
  901. { Constructors need to return self }
  902. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  903. begin
  904. r:=rg.getexplicitregisterint(list,NR_FUNCTION_RETURN_REG);
  905. { return the self pointer }
  906. ressym:=tvarsym(current_procinfo.procdef.parast.search('self'));
  907. if not assigned(ressym) then
  908. internalerror(200305058);
  909. case ressym.localloc.loc of
  910. LOC_REFERENCE :
  911. reference_reset_base(href,ressym.localloc.reference.index,ressym.localloc.reference.offset);
  912. else
  913. internalerror(2003091810);
  914. end;
  915. rg.ungetregisterint(list,r);
  916. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,r);
  917. uses_acc:=true;
  918. exit;
  919. end;
  920. ressym := tvarsym(current_procinfo.procdef.funcretsym);
  921. if (ressym.refs>0) then
  922. begin
  923. case ressym.localloc.loc of
  924. LOC_FPUREGISTER,
  925. LOC_REGISTER :
  926. begin
  927. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  928. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  929. else
  930. if ressym.vartype.def.deftype = floatdef then
  931. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procinfo.procdef.rettype.def))
  932. else
  933. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  934. resloc.register:=ressym.localloc.register;
  935. end;
  936. LOC_REFERENCE :
  937. begin
  938. location_reset(resloc,LOC_REFERENCE,def_cgsize(current_procinfo.procdef.rettype.def));
  939. reference_reset_base(resloc.reference,ressym.localloc.reference.index,ressym.localloc.reference.offset);
  940. end;
  941. else
  942. internalerror(200309184);
  943. end;
  944. { Here, we return the function result. In most architectures, the value is
  945. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  946. function returns in a register and the caller receives it in an other one }
  947. case current_procinfo.procdef.rettype.def.deftype of
  948. orddef,
  949. enumdef :
  950. begin
  951. uses_acc:=true;
  952. {$ifndef cpu64bit}
  953. if resloc.size in [OS_64,OS_S64] then
  954. begin
  955. uses_acchi:=true;
  956. r:=rg.getexplicitregisterint(list,NR_FUNCTION_RETURN64_LOW_REG);
  957. r2:=rg.getexplicitregisterint(list,NR_FUNCTION_RETURN64_HIGH_REG);
  958. rg.ungetregisterint(list,r);
  959. rg.ungetregisterint(list,r2);
  960. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2),false);
  961. end
  962. else
  963. {$endif cpu64bit}
  964. begin
  965. hreg:=rg.getexplicitregisterint(list,NR_FUNCTION_RETURN_REG);
  966. hreg:=rg.makeregsize(hreg,resloc.size);
  967. rg.ungetregisterint(list,hreg);
  968. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  969. end;
  970. end;
  971. floatdef :
  972. begin
  973. uses_fpu := true;
  974. {$ifdef cpufpemu}
  975. if cs_fp_emulation in aktmoduleswitches then
  976. r:=NR_FUNCTION_RETURN_REG
  977. else
  978. {$endif cpufpemu}
  979. r:=NR_FPU_RESULT_REG;
  980. cg.a_loadfpu_loc_reg(list,resloc,r);
  981. end;
  982. else
  983. begin
  984. if not paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  985. begin
  986. uses_acc:=true;
  987. {$ifndef cpu64bit}
  988. { Win32 can return records in EAX:EDX }
  989. if resloc.size in [OS_64,OS_S64] then
  990. begin
  991. uses_acchi:=true;
  992. r:=rg.getexplicitregisterint(list,NR_FUNCTION_RETURN64_LOW_REG);
  993. r2:=rg.getexplicitregisterint(list,NR_FUNCTION_RETURN64_HIGH_REG);
  994. rg.ungetregisterint(list,r);
  995. rg.ungetregisterint(list,r2);
  996. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2),false);
  997. end
  998. else
  999. {$endif cpu64bit}
  1000. begin
  1001. hreg:=rg.getexplicitregisterint(list,NR_FUNCTION_RETURN_REG);
  1002. hreg:=rg.makeregsize(hreg,resloc.size);
  1003. rg.ungetregisterint(list,hreg);
  1004. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  1005. end;
  1006. end
  1007. end;
  1008. end;
  1009. end;
  1010. end;
  1011. procedure gen_load_para_value(list:TAAsmoutput);
  1012. var
  1013. hp : tparaitem;
  1014. href : treference;
  1015. gotregvarparas : boolean;
  1016. begin
  1017. { Store register parameters in reference or in register variable }
  1018. if assigned(current_procinfo.procdef.parast) and
  1019. not (po_assembler in current_procinfo.procdef.procoptions) then
  1020. begin
  1021. { move register parameters which aren't regable into memory }
  1022. { we do this before init_paras because that one calls routines which may overwrite these }
  1023. { registers and it also expects the values to be in memory }
  1024. hp:=tparaitem(current_procinfo.procdef.para.first);
  1025. gotregvarparas := false;
  1026. while assigned(hp) do
  1027. begin
  1028. case tvarsym(hp.parasym).localloc.loc of
  1029. LOC_REGISTER :
  1030. begin
  1031. gotregvarparas := true;
  1032. { cg.a_load_param_reg will first allocate and then deallocate paraloc }
  1033. { register (if the parameter resides in a register) and then allocate }
  1034. { the regvar (which is currently not allocated) }
  1035. cg.a_load_param_reg(list,hp.paraloc[calleeside],tvarsym(hp.parasym).localloc.register);
  1036. end;
  1037. LOC_REFERENCE :
  1038. begin
  1039. if hp.paraloc[calleeside].loc<>LOC_REFERENCE then
  1040. begin
  1041. reference_reset_base(href,tvarsym(hp.parasym).localloc.reference.index,tvarsym(hp.parasym).localloc.reference.offset);
  1042. cg.a_load_param_ref(list,hp.paraloc[calleeside],href);
  1043. end;
  1044. end;
  1045. else
  1046. internalerror(200309185);
  1047. end;
  1048. hp:=tparaitem(hp.next);
  1049. end;
  1050. if gotregvarparas then
  1051. begin
  1052. { deallocate all register variables again }
  1053. hp:=tparaitem(current_procinfo.procdef.para.first);
  1054. while assigned(hp) do
  1055. begin
  1056. if (tvarsym(hp.parasym).localloc.loc=LOC_REGISTER) then
  1057. rg.ungetregisterint(list,tvarsym(hp.parasym).localloc.register);
  1058. hp:=tparaitem(hp.next);
  1059. end;
  1060. end;
  1061. end;
  1062. { generate copies of call by value parameters, must be done before
  1063. the initialization and body is parsed because the refcounts are
  1064. incremented using the local copies }
  1065. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1066. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1067. end;
  1068. procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean);
  1069. var
  1070. href : treference;
  1071. paraloc1,
  1072. paraloc2 : tparalocation;
  1073. begin
  1074. { the actual profile code can clobber some registers,
  1075. therefore if the context must be saved, do it before
  1076. the actual call to the profile code
  1077. }
  1078. if (cs_profile in aktmoduleswitches) and
  1079. not(po_assembler in current_procinfo.procdef.procoptions) and
  1080. not(inlined) then
  1081. begin
  1082. { non-win32 can call mcout even in main }
  1083. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  1084. cg.g_profilecode(list)
  1085. else
  1086. { wdosx, and win32 should not call mcount before monstartup has been called }
  1087. if not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1088. cg.g_profilecode(list);
  1089. end;
  1090. { initialize local data like ansistrings }
  1091. case current_procinfo.procdef.proctypeoption of
  1092. potype_unitinit:
  1093. begin
  1094. { this is also used for initialization of variables in a
  1095. program which does not have a globalsymtable }
  1096. if assigned(current_module.globalsymtable) then
  1097. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1098. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1099. end;
  1100. { units have seperate code for initilization and finalization }
  1101. potype_unitfinalize: ;
  1102. { program init/final is generated in separate procedure }
  1103. potype_proginit: ;
  1104. else
  1105. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1106. end;
  1107. { initialisizes temp. ansi/wide string data }
  1108. inittempvariables(list);
  1109. { initialize ansi/widesstring para's }
  1110. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1111. if (not inlined) then
  1112. begin
  1113. { call startup helpers from main program }
  1114. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1115. begin
  1116. { initialize profiling for win32 }
  1117. if (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1118. (cs_profile in aktmoduleswitches) then
  1119. begin
  1120. reference_reset_symbol(href,objectlibrary.newasmsymboldata('etext'),0);
  1121. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1122. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1123. paramanager.allocparaloc(list,paraloc2);
  1124. cg.a_paramaddr_ref(list,href,paraloc2);
  1125. reference_reset_symbol(href,objectlibrary.newasmsymboldata('__image_base__'),0);
  1126. paramanager.allocparaloc(list,paraloc1);
  1127. cg.a_paramaddr_ref(list,href,paraloc1);
  1128. paramanager.freeparaloc(list,paraloc2);
  1129. paramanager.freeparaloc(list,paraloc1);
  1130. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_cdecl));
  1131. cg.a_call_name(list,'_monstartup');
  1132. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_cdecl));
  1133. end;
  1134. { initialize units }
  1135. rg.allocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  1136. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1137. rg.deallocexplicitregistersint(list,paramanager.get_volatile_registers_int(pocall_default));
  1138. end;
  1139. {$ifdef GDB}
  1140. if (cs_debuginfo in aktmoduleswitches) then
  1141. list.concat(Tai_force_line.Create);
  1142. {$endif GDB}
  1143. end;
  1144. load_regvars(list,nil);
  1145. end;
  1146. procedure gen_finalize_code(list : TAAsmoutput;inlined:boolean);
  1147. begin
  1148. cg.a_label(list,current_procinfo.aktexitlabel);
  1149. cleanup_regvars(list);
  1150. { finalize temporary data }
  1151. finalizetempvariables(list);
  1152. { finalize local data like ansistrings}
  1153. case current_procinfo.procdef.proctypeoption of
  1154. potype_unitfinalize:
  1155. begin
  1156. { this is also used for initialization of variables in a
  1157. program which does not have a globalsymtable }
  1158. if assigned(current_module.globalsymtable) then
  1159. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1160. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1161. end;
  1162. { units/progs have separate code for initialization and finalization }
  1163. potype_unitinit: ;
  1164. { program init/final is generated in separate procedure }
  1165. potype_proginit: ;
  1166. else
  1167. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1168. end;
  1169. { finalize paras data }
  1170. if assigned(current_procinfo.procdef.parast) then
  1171. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1172. { call __EXIT for main program }
  1173. if (not DLLsource) and
  1174. (not inlined) and
  1175. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1176. cg.a_call_name(list,'FPC_DO_EXIT');
  1177. cleanup_regvars(list);
  1178. end;
  1179. {****************************************************************************
  1180. Entry/Exit
  1181. ****************************************************************************}
  1182. procedure gen_proc_symbol(list:Taasmoutput);
  1183. var
  1184. hs : string;
  1185. begin
  1186. { add symbol entry point as well as debug information }
  1187. { will be inserted in front of the rest of this list. }
  1188. { Insert alignment and assembler names }
  1189. { Align, gprof uses 16 byte granularity }
  1190. if (cs_profile in aktmoduleswitches) then
  1191. list.concat(Tai_align.create(16))
  1192. else
  1193. list.concat(Tai_align.create(aktalignment.procalign));
  1194. {$ifdef GDB}
  1195. if (cs_debuginfo in aktmoduleswitches) then
  1196. begin
  1197. if (po_public in current_procinfo.procdef.procoptions) then
  1198. Tprocsym(current_procinfo.procdef.procsym).is_global:=true;
  1199. current_procinfo.procdef.concatstabto(list);
  1200. Tprocsym(current_procinfo.procdef.procsym).isstabwritten:=true;
  1201. end;
  1202. {$endif GDB}
  1203. repeat
  1204. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1205. if hs='' then
  1206. break;
  1207. {$ifdef GDB}
  1208. if (cs_debuginfo in aktmoduleswitches) and
  1209. target_info.use_function_relative_addresses then
  1210. list.concat(Tai_stab_function_name.create(strpnew(hs)));
  1211. {$endif GDB}
  1212. if (cs_profile in aktmoduleswitches) or
  1213. (po_public in current_procinfo.procdef.procoptions) then
  1214. list.concat(Tai_symbol.createname_global(hs,0))
  1215. else
  1216. list.concat(Tai_symbol.createname(hs,0));
  1217. until false;
  1218. end;
  1219. procedure gen_proc_symbol_end(list:Taasmoutput);
  1220. {$ifdef GDB}
  1221. var
  1222. stabsendlabel : tasmlabel;
  1223. mangled_length : longint;
  1224. p : pchar;
  1225. {$endif GDB}
  1226. begin
  1227. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1228. {$ifdef GDB}
  1229. if (cs_debuginfo in aktmoduleswitches) then
  1230. begin
  1231. objectlibrary.getlabel(stabsendlabel);
  1232. cg.a_label(list,stabsendlabel);
  1233. { define calling EBP as pseudo local var PM }
  1234. { this enables test if the function is a local one !! }
  1235. {if assigned(current_procinfo.parent) and
  1236. (current_procinfo.procdef.parast.symtablelevel>normal_function_level) then
  1237. list.concat(Tai_stabs.Create(strpnew(
  1238. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1239. tostr(N_LSYM)+',0,0,'+tostr(current_procinfo.parent_framepointer_offset)))); }
  1240. if (not is_void(current_procinfo.procdef.rettype.def)) and
  1241. (tvarsym(current_procinfo.procdef.funcretsym).refs>0) then
  1242. begin
  1243. if tvarsym(current_procinfo.procdef.funcretsym).localloc.loc<>LOC_REFERENCE then
  1244. internalerror(2003091812);
  1245. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1246. begin
  1247. list.concat(Tai_stabs.Create(strpnew(
  1248. '"'+current_procinfo.procdef.procsym.name+':X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1249. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1250. if (m_result in aktmodeswitches) then
  1251. list.concat(Tai_stabs.Create(strpnew(
  1252. '"RESULT:X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1253. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))))
  1254. end
  1255. else
  1256. begin
  1257. list.concat(Tai_stabs.Create(strpnew(
  1258. '"'+current_procinfo.procdef.procsym.name+':X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1259. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1260. if (m_result in aktmodeswitches) then
  1261. list.concat(Tai_stabs.Create(strpnew(
  1262. '"RESULT:X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1263. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1264. end;
  1265. end;
  1266. mangled_length:=length(current_procinfo.procdef.mangledname);
  1267. getmem(p,2*mangled_length+50);
  1268. strpcopy(p,'192,0,0,');
  1269. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1270. if (target_info.use_function_relative_addresses) then
  1271. begin
  1272. strpcopy(strend(p),'-');
  1273. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1274. end;
  1275. list.concat(Tai_stabn.Create(strnew(p)));
  1276. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1277. +current_procinfo.procdef.mangledname))));
  1278. p[0]:='2';p[1]:='2';p[2]:='4';
  1279. strpcopy(strend(p),'_end');}
  1280. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1281. if (target_info.use_function_relative_addresses) then
  1282. begin
  1283. strpcopy(strend(p),'-');
  1284. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1285. end;
  1286. list.concatlist(withdebuglist);
  1287. list.concat(Tai_stabn.Create(strnew(p)));
  1288. { strpnew('224,0,0,'
  1289. +current_procinfo.procdef.mangledname+'_end'))));}
  1290. freemem(p,2*mangled_length+50);
  1291. end;
  1292. {$endif GDB}
  1293. end;
  1294. procedure gen_stackalloc_code(list:Taasmoutput);
  1295. var
  1296. stackframe : longint;
  1297. begin
  1298. { Calculate size of stackframe }
  1299. stackframe:=current_procinfo.calc_stackframe_size;
  1300. {$ifndef powerpc}
  1301. { at least for the ppc this applies always, so this code isn't usable (FK) }
  1302. { omit stack frame ? }
  1303. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1304. begin
  1305. CGmessage(cg_d_stackframe_omited);
  1306. if stackframe<>0 then
  1307. cg.g_stackpointer_alloc(list,stackframe);
  1308. end
  1309. else
  1310. {$endif powerpc}
  1311. begin
  1312. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1313. cg.g_interrupt_stackframe_entry(list);
  1314. cg.g_stackframe_entry(list,stackframe);
  1315. {Never call stack checking before the standard system unit
  1316. has been initialized.}
  1317. if (cs_check_stack in aktlocalswitches) and (current_procinfo.procdef.proctypeoption<>potype_proginit) then
  1318. cg.g_stackcheck(list,stackframe);
  1319. end;
  1320. end;
  1321. procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
  1322. var
  1323. stacksize,
  1324. retsize : longint;
  1325. begin
  1326. {$ifndef powerpc}
  1327. { remove stackframe }
  1328. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1329. begin
  1330. stacksize:=current_procinfo.calc_stackframe_size;
  1331. if (stacksize<>0) then
  1332. cg.a_op_const_reg(list,OP_ADD,OS_32,stacksize,current_procinfo.framepointer);
  1333. end
  1334. else
  1335. cg.g_restore_frame_pointer(list);
  1336. {$endif}
  1337. { at last, the return is generated }
  1338. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1339. cg.g_interrupt_stackframe_exit(list,usesacc,usesacchi)
  1340. else
  1341. begin
  1342. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1343. begin
  1344. retsize:=0;
  1345. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1346. inc(retsize,POINTER_SIZE);
  1347. end
  1348. else
  1349. retsize:=current_procinfo.para_stack_size;
  1350. cg.g_return_from_proc(list,retsize);
  1351. end;
  1352. end;
  1353. procedure gen_save_used_regs(list : TAAsmoutput);
  1354. begin
  1355. { Pure assembler routines need to save the registers themselves }
  1356. if (po_assembler in current_procinfo.procdef.procoptions) then
  1357. exit;
  1358. { for the save all registers we can simply use a pusha,popa which
  1359. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1360. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1361. cg.g_save_all_registers(list)
  1362. else
  1363. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1364. cg.g_save_standard_registers(list,rg.used_in_proc_int);
  1365. end;
  1366. procedure gen_restore_used_regs(list : TAAsmoutput;usesacc,usesacchi,usesfpu:boolean);
  1367. begin
  1368. { Pure assembler routines need to save the registers themselves }
  1369. if (po_assembler in current_procinfo.procdef.procoptions) then
  1370. exit;
  1371. { for the save all registers we can simply use a pusha,popa which
  1372. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1373. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1374. cg.g_restore_all_registers(list,usesacc,usesacchi)
  1375. else
  1376. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1377. cg.g_restore_standard_registers(list,rg.used_in_proc_int);
  1378. end;
  1379. {****************************************************************************
  1380. Inlining
  1381. ****************************************************************************}
  1382. (*
  1383. procedure load_inlined_return_value(list:TAAsmoutput);
  1384. var
  1385. ressym: tvarsym;
  1386. resloc: tlocation;
  1387. r,r2 : tregister;
  1388. begin
  1389. if not is_void(current_procinfo.procdef.rettype.def) then
  1390. begin
  1391. ressym := tvarsym(current_procinfo.procdef.funcretsym);
  1392. if ressym.reg.enum <> R_NO then
  1393. begin
  1394. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1395. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  1396. else
  1397. if ressym.vartype.def.deftype = floatdef then
  1398. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procinfo.procdef.rettype.def))
  1399. else
  1400. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  1401. resloc.register := ressym.reg;
  1402. end
  1403. else
  1404. begin
  1405. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  1406. reference_reset_base(resloc.reference,current_procinfo.framepointer,tvarsym(current_procinfo.procdef.funcretsym).adjusted_address);
  1407. end;
  1408. { Here, we return the function result. In most architectures, the value is
  1409. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1410. function returns in a register and the caller receives it in an other one }
  1411. case current_procinfo.procdef.rettype.def.deftype of
  1412. orddef,
  1413. enumdef :
  1414. begin
  1415. {$ifndef cpu64bit}
  1416. if resloc.size in [OS_64,OS_S64] then
  1417. begin
  1418. r:=rg.getregisterint(list,OS_INT);
  1419. r2:=rg.getregisterint(list,OS_INT);
  1420. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2),false);
  1421. end
  1422. else
  1423. {$endif cpu64bit}
  1424. begin
  1425. r:=rg.getregisterint(list,resloc.size);
  1426. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1427. end;
  1428. end;
  1429. floatdef :
  1430. begin
  1431. {$ifdef cpufpemu}
  1432. if cs_fp_emulation in aktmoduleswitches then
  1433. r.enum := FUNCTION_RETURN_REG
  1434. else
  1435. {$endif cpufpemu}
  1436. r.enum:=FPU_RESULT_REG;
  1437. cg.a_loadfpu_loc_reg(list,resloc,r);
  1438. end;
  1439. else
  1440. begin
  1441. if not paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1442. begin
  1443. {$ifndef cpu64bit}
  1444. { Win32 can return records in EAX:EDX }
  1445. if resloc.size in [OS_64,OS_S64] then
  1446. begin
  1447. r:=rg.getregisterint(list,OS_INT);
  1448. r2:=rg.getregisterint(list,OS_INT);
  1449. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2),false);
  1450. end
  1451. else
  1452. {$endif cpu64bit}
  1453. begin
  1454. r:=rg.getregisterint(list,resloc.size);
  1455. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1456. end;
  1457. end
  1458. end;
  1459. end;
  1460. end;
  1461. end;
  1462. procedure geninlineentrycode(list : TAAsmoutput;stackframe:longint);
  1463. begin
  1464. { initialize return value }
  1465. initretvalue(list);
  1466. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1467. { initialisizes temp. ansi/wide string data }
  1468. inittempvariables(list);
  1469. { initialize ansi/widesstring para's }
  1470. if assigned(current_procinfo.procdef.parast) then
  1471. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1472. { generate copies of call by value parameters }
  1473. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1474. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1475. load_regvars(list,nil);
  1476. end;
  1477. procedure geninlineexitcode(list : TAAsmoutput;inlined:boolean);
  1478. var
  1479. usesacc,
  1480. usesacchi,
  1481. usesfpu : boolean;
  1482. begin
  1483. if aktexitlabel.is_used then
  1484. cg.a_label(list,aktexitlabel);
  1485. cleanup_regvars(list);
  1486. { finalize temporary data }
  1487. finalizetempvariables(list);
  1488. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1489. { finalize paras data }
  1490. if assigned(current_procinfo.procdef.parast) then
  1491. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1492. { handle return value, this is not done for assembler routines when
  1493. they didn't reference the result variable }
  1494. if not(po_assembler in current_procinfo.procdef.procoptions) or
  1495. (assigned(current_procinfo.procdef.funcretsym) and
  1496. (tvarsym(current_procinfo.procdef.funcretsym).refcount>1)) then
  1497. begin
  1498. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1499. internalerror(200305263);
  1500. // load_inlined_return_value(list);
  1501. load_return_value(list,usesacc,usesacchi,usesfpu)
  1502. end;
  1503. cleanup_regvars(list);
  1504. end;
  1505. *)
  1506. {****************************************************************************
  1507. Const Data
  1508. ****************************************************************************}
  1509. procedure insertconstdata(sym : ttypedconstsym);
  1510. { this does not affect the local stack space, since all
  1511. typed constansts and initialized variables are always
  1512. put in the .data / .rodata section
  1513. }
  1514. var
  1515. storefilepos : tfileposinfo;
  1516. curconstsegment : taasmoutput;
  1517. l : longint;
  1518. begin
  1519. storefilepos:=aktfilepos;
  1520. aktfilepos:=sym.fileinfo;
  1521. if sym.is_writable then
  1522. curconstsegment:=datasegment
  1523. else
  1524. curconstsegment:=consts;
  1525. l:=sym.getsize;
  1526. { insert cut for smartlinking or alignment }
  1527. if (cs_create_smart in aktmoduleswitches) then
  1528. curconstSegment.concat(Tai_cut.Create);
  1529. curconstSegment.concat(Tai_align.create(const_align(l)));
  1530. {$ifdef GDB}
  1531. if cs_debuginfo in aktmoduleswitches then
  1532. sym.concatstabto(curconstsegment);
  1533. {$endif GDB}
  1534. if (sym.owner.symtabletype=globalsymtable) or
  1535. (cs_create_smart in aktmoduleswitches) or
  1536. DLLSource then
  1537. curconstSegment.concat(Tai_symbol.Createdataname_global(sym.mangledname,l))
  1538. else
  1539. curconstSegment.concat(Tai_symbol.Createdataname(sym.mangledname,l));
  1540. aktfilepos:=storefilepos;
  1541. end;
  1542. procedure insertbssdata(sym : tvarsym);
  1543. var
  1544. l,varalign : longint;
  1545. storefilepos : tfileposinfo;
  1546. begin
  1547. storefilepos:=aktfilepos;
  1548. aktfilepos:=sym.fileinfo;
  1549. l:=sym.getvaluesize;
  1550. if (vo_is_thread_var in sym.varoptions) then
  1551. inc(l,pointer_size);
  1552. varalign:=var_align(l);
  1553. {
  1554. sym.address:=align(datasize,varalign);
  1555. datasize:=tvarsym(sym).address+l;
  1556. }
  1557. { insert cut for smartlinking or alignment }
  1558. if (cs_create_smart in aktmoduleswitches) then
  1559. bssSegment.concat(Tai_cut.Create);
  1560. bssSegment.concat(Tai_align.create(varalign));
  1561. {$ifdef GDB}
  1562. if cs_debuginfo in aktmoduleswitches then
  1563. sym.concatstabto(bsssegment);
  1564. {$endif GDB}
  1565. if (sym.owner.symtabletype=globalsymtable) or
  1566. (cs_create_smart in aktmoduleswitches) or
  1567. DLLSource or
  1568. (vo_is_exported in sym.varoptions) or
  1569. (vo_is_C_var in sym.varoptions) then
  1570. bssSegment.concat(Tai_datablock.Create_global(sym.mangledname,l))
  1571. else
  1572. bssSegment.concat(Tai_datablock.Create(sym.mangledname,l));
  1573. aktfilepos:=storefilepos;
  1574. end;
  1575. procedure gen_alloc_localst(list: taasmoutput;st:tlocalsymtable);
  1576. var
  1577. sym : tsym;
  1578. begin
  1579. sym:=tsym(st.symindex.first);
  1580. while assigned(sym) do
  1581. begin
  1582. { Only allocate space for referenced locals }
  1583. if (sym.typ=varsym) and
  1584. (tvarsym(sym).refs>0) then
  1585. begin
  1586. with tvarsym(sym) do
  1587. begin
  1588. {$warning TODO Add support for register variables}
  1589. localloc.loc:=LOC_REFERENCE;
  1590. tg.GetLocal(list,getvaluesize,localloc.reference);
  1591. end;
  1592. end;
  1593. sym:=tsym(sym.indexnext);
  1594. end;
  1595. end;
  1596. procedure gen_free_localst(list: taasmoutput;st:tlocalsymtable);
  1597. var
  1598. sym : tsym;
  1599. begin
  1600. sym:=tsym(st.symindex.first);
  1601. while assigned(sym) do
  1602. begin
  1603. if (sym.typ=varsym) and
  1604. (tvarsym(sym).refs>0) then
  1605. begin
  1606. with tvarsym(sym) do
  1607. begin
  1608. { Note: We need to keep the data available in memory
  1609. for the sub procedures that can access local data
  1610. in the parent procedures }
  1611. case localloc.loc of
  1612. LOC_REFERENCE :
  1613. tg.Ungetlocal(list,localloc.reference);
  1614. LOC_REGISTER :
  1615. begin
  1616. {$ifndef cpu64bit}
  1617. if localloc.size in [OS_64,OS_S64] then
  1618. begin
  1619. rg.ungetregister(list,localloc.registerlow);
  1620. rg.ungetregister(list,localloc.registerhigh);
  1621. end
  1622. else
  1623. {$endif cpu64bit}
  1624. rg.ungetregister(list,localloc.register);
  1625. end;
  1626. end;
  1627. end;
  1628. end;
  1629. sym:=tsym(sym.indexnext);
  1630. end;
  1631. end;
  1632. procedure gen_alloc_parast(list: taasmoutput;st:tparasymtable);
  1633. var
  1634. sym : tsym;
  1635. begin
  1636. sym:=tsym(st.symindex.first);
  1637. while assigned(sym) do
  1638. begin
  1639. if sym.typ=varsym then
  1640. begin
  1641. with tvarsym(sym) do
  1642. begin
  1643. { Allocate imaginary register for register parameters,
  1644. this is not required when the parameter is already an
  1645. imaginary register }
  1646. if (paraitem.paraloc[calleeside].loc=LOC_REGISTER) and
  1647. (getsupreg(paraitem.paraloc[calleeside].register)<first_int_imreg) then
  1648. begin
  1649. (*
  1650. {$warning TODO Allocate register paras}
  1651. localloc.loc:=LOC_REGISTER;
  1652. localloc.size:=paraitem.paraloc[calleeside].size;
  1653. {$ifndef cpu64bit}
  1654. if localloc.size in [OS_64,OS_S64] then
  1655. begin
  1656. localloc.registerlow:=rg.getregisterint(list,OS_32);
  1657. localloc.registerhigh:=rg.getregisterint(list,OS_32);
  1658. end
  1659. else
  1660. {$endif cpu64bit}
  1661. localloc.register:=rg.getregisterint(list,localloc.size);
  1662. *)
  1663. localloc.loc:=LOC_REFERENCE;
  1664. localloc.size:=paraitem.paraloc[calleeside].size;
  1665. tg.GetLocal(list,tcgsize2size[localloc.size],localloc.reference);
  1666. end
  1667. else
  1668. localloc:=paraitem.paraloc[calleeside];
  1669. end;
  1670. end;
  1671. sym:=tsym(sym.indexnext);
  1672. end;
  1673. end;
  1674. procedure gen_free_parast(list: taasmoutput;st:tparasymtable);
  1675. var
  1676. sym : tsym;
  1677. begin
  1678. sym:=tsym(st.symindex.first);
  1679. while assigned(sym) do
  1680. begin
  1681. if sym.typ=varsym then
  1682. begin
  1683. with tvarsym(sym) do
  1684. begin
  1685. { Note: We need to keep the data available in memory
  1686. for the sub procedures that can access local data
  1687. in the parent procedures }
  1688. case localloc.loc of
  1689. LOC_REFERENCE :
  1690. tg.UngetLocal(list,localloc.reference);
  1691. LOC_REGISTER :
  1692. begin
  1693. {$ifndef cpu64bit}
  1694. if localloc.size in [OS_64,OS_S64] then
  1695. begin
  1696. rg.ungetregister(list,localloc.registerlow);
  1697. rg.ungetregister(list,localloc.registerhigh);
  1698. end
  1699. else
  1700. {$endif cpu64bit}
  1701. rg.ungetregister(list,localloc.register);
  1702. end;
  1703. end;
  1704. end;
  1705. end;
  1706. sym:=tsym(sym.indexnext);
  1707. end;
  1708. end;
  1709. end.
  1710. {
  1711. $Log$
  1712. Revision 1.153 2003-09-30 21:02:37 peter
  1713. * updates for inlining
  1714. Revision 1.152 2003/09/29 20:58:56 peter
  1715. * optimized releasing of registers
  1716. Revision 1.151 2003/09/28 21:47:18 peter
  1717. * register paras and local copies updates
  1718. Revision 1.150 2003/09/28 17:55:03 peter
  1719. * parent framepointer changed to hidden parameter
  1720. * tloadparentfpnode added
  1721. Revision 1.149 2003/09/28 13:39:38 peter
  1722. * optimized releasing of registers
  1723. Revision 1.148 2003/09/25 21:28:00 peter
  1724. * parameter fixes
  1725. Revision 1.147 2003/09/23 21:03:59 peter
  1726. * check for refs>0 in init/final local data
  1727. Revision 1.146 2003/09/23 17:56:05 peter
  1728. * locals and paras are allocated in the code generation
  1729. * tvarsym.localloc contains the location of para/local when
  1730. generating code for the current procedure
  1731. Revision 1.145 2003/09/16 16:17:01 peter
  1732. * varspez in calls to push_addr_param
  1733. Revision 1.144 2003/09/14 21:33:37 peter
  1734. * location_force_reg gives IE when size=OS_NO
  1735. Revision 1.143 2003/09/14 19:18:10 peter
  1736. * remove obsolete code already in comments
  1737. Revision 1.142 2003/09/11 11:54:59 florian
  1738. * improved arm code generation
  1739. * move some protected and private field around
  1740. * the temp. register for register parameters/arguments are now released
  1741. before the move to the parameter register is done. This improves
  1742. the code in a lot of cases.
  1743. Revision 1.141 2003/09/10 08:31:47 marco
  1744. * Patch from Peter for paraloc
  1745. Revision 1.140 2003/09/07 22:09:35 peter
  1746. * preparations for different default calling conventions
  1747. * various RA fixes
  1748. Revision 1.139 2003/09/03 15:55:01 peter
  1749. * NEWRA branch merged
  1750. Revision 1.138 2003/09/03 11:18:37 florian
  1751. * fixed arm concatcopy
  1752. + arm support in the common compiler sources added
  1753. * moved some generic cg code around
  1754. + tfputype added
  1755. * ...
  1756. Revision 1.137.2.4 2003/08/31 15:46:26 peter
  1757. * more updates for tregister
  1758. Revision 1.137.2.3 2003/08/29 17:28:59 peter
  1759. * next batch of updates
  1760. Revision 1.137.2.2 2003/08/28 18:35:08 peter
  1761. * tregister changed to cardinal
  1762. Revision 1.137.2.1 2003/08/27 19:55:54 peter
  1763. * first tregister patch
  1764. Revision 1.137 2003/08/20 20:29:06 daniel
  1765. * Some more R_NO changes
  1766. * Preventive code to loadref added
  1767. Revision 1.136 2003/08/20 17:48:49 peter
  1768. * fixed stackalloc to not allocate localst.datasize twice
  1769. * order of stackalloc code fixed for implicit init/final
  1770. Revision 1.135 2003/08/17 16:59:20 jonas
  1771. * fixed regvars so they work with newra (at least for ppc)
  1772. * fixed some volatile register bugs
  1773. + -dnotranslation option for -dnewra, which causes the registers not to
  1774. be translated from virtual to normal registers. Requires support in
  1775. the assembler writer as well, which is only implemented in aggas/
  1776. agppcgas currently
  1777. Revision 1.134 2003/08/11 21:18:20 peter
  1778. * start of sparc support for newra
  1779. Revision 1.133 2003/08/09 18:56:54 daniel
  1780. * cs_regalloc renamed to cs_regvars to avoid confusion with register
  1781. allocator
  1782. * Some preventive changes to i386 spillinh code
  1783. Revision 1.132 2003/08/03 14:09:50 daniel
  1784. * Fixed a register allocator bug
  1785. * Figured out why -dnewra generates superfluous "mov reg1,reg2"
  1786. statements: changes in location_force. These moves are now no longer
  1787. constrained so they are optimized away.
  1788. Revision 1.131 2003/07/23 11:04:15 jonas
  1789. * split en_exit_code into a part that may allocate a register and a part
  1790. that doesn't, so the former can be done before the register colouring
  1791. has been performed
  1792. Revision 1.130 2003/07/06 17:58:22 peter
  1793. * framepointer fixes for sparc
  1794. * parent framepointer code more generic
  1795. Revision 1.129 2003/07/06 15:31:20 daniel
  1796. * Fixed register allocator. *Lots* of fixes.
  1797. Revision 1.128 2003/07/02 22:18:04 peter
  1798. * paraloc splitted in callerparaloc,calleeparaloc
  1799. * sparc calling convention updates
  1800. Revision 1.127 2003/06/17 18:13:51 jonas
  1801. * fixed -dnewra compilation problems
  1802. Revision 1.126 2003/06/17 16:32:44 peter
  1803. * alloc register for function result
  1804. Revision 1.125 2003/06/13 21:19:30 peter
  1805. * current_procdef removed, use current_procinfo.procdef instead
  1806. Revision 1.124 2003/06/09 12:23:30 peter
  1807. * init/final of procedure data splitted from genentrycode
  1808. * use asmnode getposition to insert final at the correct position
  1809. als for the implicit try...finally
  1810. Revision 1.123 2003/06/07 18:57:04 jonas
  1811. + added freeintparaloc
  1812. * ppc get/freeintparaloc now check whether the parameter regs are
  1813. properly allocated/deallocated (and get an extra list para)
  1814. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1815. * fixed lot of missing pi_do_call's
  1816. Revision 1.122 2003/06/06 14:43:02 peter
  1817. * g_copyopenarrayvalue gets length reference
  1818. * don't copy open arrays for cdecl
  1819. Revision 1.121 2003/06/03 21:11:09 peter
  1820. * cg.a_load_* get a from and to size specifier
  1821. * makeregsize only accepts newregister
  1822. * i386 uses generic tcgnotnode,tcgunaryminus
  1823. Revision 1.120 2003/06/03 15:49:49 jonas
  1824. * fixed ref/loc problems
  1825. Revision 1.119 2003/06/03 15:06:37 daniel
  1826. * fixed conflict marks
  1827. Revision 1.118 2003/06/03 13:01:59 daniel
  1828. * Register allocator finished
  1829. Revision 1.117 2003/06/02 21:42:05 jonas
  1830. * function results can now also be regvars
  1831. - removed tprocinfo.return_offset, never use it again since it's invalid
  1832. if the result is a regvar
  1833. Revision 1.116 2003/06/01 21:38:06 peter
  1834. * getregisterfpu size parameter added
  1835. * op_const_reg size parameter added
  1836. * sparc updates
  1837. Revision 1.115 2003/05/31 20:28:17 jonas
  1838. * changed copyvalueparas so it also supports register parameters
  1839. (except for copy_value_openarray, but that one is seriously broken
  1840. anyway, since it expects that the high parameter will always be in
  1841. memory right after the pointer to the array, while it could just as
  1842. will be in a register)
  1843. Revision 1.114 2003/05/31 15:05:28 peter
  1844. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1845. Revision 1.113 2003/05/31 00:48:15 jonas
  1846. * fixed my previous commit
  1847. Revision 1.112 2003/05/30 23:57:08 peter
  1848. * more sparc cleanup
  1849. * accumulator removed, splitted in function_return_reg (called) and
  1850. function_result_reg (caller)
  1851. Revision 1.111 2003/05/30 23:49:18 jonas
  1852. * a_load_loc_reg now has an extra size parameter for the destination
  1853. register (properly fixes what I worked around in revision 1.106 of
  1854. ncgutil.pas)
  1855. Revision 1.110 2003/05/30 18:52:10 jonas
  1856. * fixed bug with intregvars
  1857. * locapara.loc can also be LOC_CFPUREGISTER -> also fixed
  1858. rcgppc.a_param_ref, which previously got bogus size values
  1859. Revision 1.109 2003/05/27 21:19:08 jonas
  1860. * fixed ppc cycle
  1861. Revision 1.108 2003/05/27 14:28:14 jonas
  1862. * patch from Peter for nested procedures
  1863. Revision 1.107 2003/05/26 21:17:17 peter
  1864. * procinlinenode removed
  1865. * aktexit2label removed, fast exit removed
  1866. + tcallnode.inlined_pass_2 added
  1867. Revision 1.106 2003/05/24 11:59:42 jonas
  1868. * fixed integer typeconversion problems
  1869. Revision 1.105 2003/05/23 14:27:35 peter
  1870. * remove some unit dependencies
  1871. * current_procinfo changes to store more info
  1872. Revision 1.104 2003/05/15 18:58:53 peter
  1873. * removed selfpointer_offset, vmtpointer_offset
  1874. * tvarsym.adjusted_address
  1875. * address in localsymtable is now in the real direction
  1876. * removed some obsolete globals
  1877. Revision 1.103 2003/05/14 19:37:25 jonas
  1878. * patch from Peter for int64 function results
  1879. Revision 1.102 2003/05/13 19:14:41 peter
  1880. * failn removed
  1881. * inherited result code check moven to pexpr
  1882. Revision 1.101 2003/05/13 15:16:13 peter
  1883. * removed ret_in_acc, it's the reverse of ret_in_param
  1884. * fixed ret_in_param for win32 cdecl array
  1885. Revision 1.100 2003/05/12 08:08:27 jonas
  1886. * fixed several initialization and finalization related bugs (missing
  1887. tg.direction's, wrong paralocation for decreasing refcount of
  1888. everything but ansistrings)
  1889. Revision 1.99 2003/05/11 21:37:03 peter
  1890. * moved implicit exception frame from ncgutil to psub
  1891. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1892. Revision 1.98 2003/05/11 14:45:12 peter
  1893. * tloadnode does not support objectsymtable,withsymtable anymore
  1894. * withnode cleanup
  1895. * direct with rewritten to use temprefnode
  1896. Revision 1.97 2003/05/10 13:20:23 jonas
  1897. * moved storing of register parameters to memory even earlier in the
  1898. entry code to fix problems with constructors
  1899. Revision 1.96 2003/05/09 17:47:02 peter
  1900. * self moved to hidden parameter
  1901. * removed hdisposen,hnewn,selfn
  1902. Revision 1.95 2003/04/29 07:28:52 michael
  1903. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1904. Revision 1.94 2003/04/28 21:17:38 peter
  1905. * do not finalize function results
  1906. Revision 1.93 2003/04/27 16:30:34 jonas
  1907. * store register para's to memory before copying the valuepara's, because
  1908. that one requires them to be there already (and it calls subroutines ->
  1909. could overwrite those registers)
  1910. Revision 1.92 2003/04/27 11:21:33 peter
  1911. * aktprocdef renamed to current_procinfo.procdef
  1912. * procinfo renamed to current_procinfo
  1913. * procinfo will now be stored in current_module so it can be
  1914. cleaned up properly
  1915. * gen_main_procsym changed to create_main_proc and release_main_proc
  1916. to also generate a tprocinfo structure
  1917. * fixed unit implicit initfinal
  1918. Revision 1.91 2003/04/27 07:29:50 peter
  1919. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  1920. a new procdef declaration
  1921. * aktprocsym removed
  1922. * lexlevel removed, use symtable.symtablelevel instead
  1923. * implicit init/final code uses the normal genentry/genexit
  1924. * funcret state checking updated for new funcret handling
  1925. Revision 1.90 2003/04/26 17:21:08 florian
  1926. * fixed passing of fpu values by fpu register
  1927. Revision 1.89 2003/04/25 20:59:33 peter
  1928. * removed funcretn,funcretsym, function result is now in varsym
  1929. and aliases for result and function name are added using absolutesym
  1930. * vs_hidden parameter for funcret passed in parameter
  1931. * vs_hidden fixes
  1932. * writenode changed to printnode and released from extdebug
  1933. * -vp option added to generate a tree.log with the nodetree
  1934. * nicer printnode for statements, callnode
  1935. Revision 1.88 2003/04/23 12:35:34 florian
  1936. * fixed several issues with powerpc
  1937. + applied a patch from Jonas for nested function calls (PowerPC only)
  1938. * ...
  1939. Revision 1.87 2003/04/22 14:33:38 peter
  1940. * removed some notes/hints
  1941. Revision 1.86 2003/04/22 13:47:08 peter
  1942. * fixed C style array of const
  1943. * fixed C array passing
  1944. * fixed left to right with high parameters
  1945. Revision 1.85 2003/04/22 10:09:35 daniel
  1946. + Implemented the actual register allocator
  1947. + Scratch registers unavailable when new register allocator used
  1948. + maybe_save/maybe_restore unavailable when new register allocator used
  1949. Revision 1.84 2003/04/16 09:26:55 jonas
  1950. * assembler procedures now again get a stackframe if they have local
  1951. variables. No space is reserved for a function result however.
  1952. Also, the register parameters aren't automatically saved on the stack
  1953. anymore in assembler procedures.
  1954. Revision 1.83 2003/04/06 21:11:23 olle
  1955. * changed newasmsymbol to newasmsymboldata for data symbols
  1956. Revision 1.82 2003/03/30 20:59:07 peter
  1957. * fix classmethod from classmethod call
  1958. * move BeforeDestruction/AfterConstruction calls to
  1959. genentrycode/genexitcode instead of generating them on the fly
  1960. after a call to a constructor
  1961. Revision 1.81 2003/03/28 19:16:56 peter
  1962. * generic constructor working for i386
  1963. * remove fixed self register
  1964. * esi added as address register for i386
  1965. Revision 1.80 2003/03/17 15:52:20 peter
  1966. * fix range error
  1967. Revision 1.79 2003/03/11 21:46:24 jonas
  1968. * lots of new regallocator fixes, both in generic and ppc-specific code
  1969. (ppc compiler still can't compile the linux system unit though)
  1970. Revision 1.78 2003/02/26 21:15:43 daniel
  1971. * Fixed the optimizer
  1972. Revision 1.77 2003/02/19 22:00:14 daniel
  1973. * Code generator converted to new register notation
  1974. - Horribily outdated todo.txt removed
  1975. Revision 1.76 2003/02/15 22:17:38 carl
  1976. * bugfix of FPU emulation code
  1977. Revision 1.75 2003/01/09 22:00:53 florian
  1978. * fixed some PowerPC issues
  1979. Revision 1.74 2003/01/09 20:41:10 florian
  1980. * fixed broken PowerPC compiler
  1981. Revision 1.73 2003/01/08 18:43:56 daniel
  1982. * Tregister changed into a record
  1983. Revision 1.72 2002/12/29 23:51:43 florian
  1984. * web bug 2214 fixed: ie 10 in const array constructors
  1985. Revision 1.71 2002/12/24 15:56:50 peter
  1986. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1987. this for the pageprotection
  1988. Revision 1.70 2002/12/05 14:39:21 florian
  1989. * added missing then, Carl did you really a make fullcycle :) ?
  1990. Revision 1.69 2002/12/03 22:13:39 carl
  1991. * bugfix of problems with profile code which clobbers some registers
  1992. Revision 1.68 2002/12/01 22:06:59 carl
  1993. * warning of portabilitiy problems with parasize / localsize
  1994. Revision 1.67 2002/11/30 18:44:57 carl
  1995. + profiling support for Win32
  1996. Revision 1.66 2002/11/30 14:39:15 carl
  1997. * try to fix profiling for win32
  1998. Revision 1.65 2002/11/28 23:28:14 florian
  1999. * push_value_para didn't release floatdef locations, fixes tw2045
  2000. Revision 1.64 2002/11/27 02:33:19 peter
  2001. * copy_value_on_stack method added for cdecl record passing
  2002. Revision 1.63 2002/11/25 17:43:18 peter
  2003. * splitted defbase in defutil,symutil,defcmp
  2004. * merged isconvertable and is_equal into compare_defs(_ext)
  2005. * made operator search faster by walking the list only once
  2006. Revision 1.62 2002/11/18 17:31:55 peter
  2007. * pass proccalloption to ret_in_xxx and push_xxx functions
  2008. Revision 1.61 2002/11/17 17:49:08 mazen
  2009. + return_result_reg and FUNCTION_RESULT_REG are now used, in all plateforms, to pass functions result between called function and its caller. See the explanation of each one
  2010. Revision 1.60 2002/11/17 16:31:56 carl
  2011. * memory optimization (3-4%) : cleanup of tai fields,
  2012. cleanup of tdef and tsym fields.
  2013. * make it work for m68k
  2014. Revision 1.59 2002/11/15 01:58:51 peter
  2015. * merged changes from 1.0.7 up to 04-11
  2016. - -V option for generating bug report tracing
  2017. - more tracing for option parsing
  2018. - errors for cdecl and high()
  2019. - win32 import stabs
  2020. - win32 records<=8 are returned in eax:edx (turned off by default)
  2021. - heaptrc update
  2022. - more info for temp management in .s file with EXTDEBUG
  2023. Revision 1.58 2002/11/10 19:07:45 mazen
  2024. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  2025. Revision 1.57 2002/11/03 20:22:40 mazen
  2026. * parameter handling updated
  2027. Revision 1.56 2002/10/16 19:01:43 peter
  2028. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  2029. implicit exception frames for procedures with initialized variables
  2030. and for constructors. The default is on for compatibility
  2031. Revision 1.55 2002/10/14 19:42:33 peter
  2032. * only use init tables for threadvars
  2033. Revision 1.54 2002/10/06 19:41:30 peter
  2034. * Add finalization of typed consts
  2035. * Finalization of globals in the main program
  2036. Revision 1.53 2002/10/05 15:18:42 carl
  2037. * fix heap leaks
  2038. Revision 1.52 2002/09/30 07:00:46 florian
  2039. * fixes to common code to get the alpha compiler compiled applied
  2040. Revision 1.51 2002/09/22 14:02:35 carl
  2041. * stack checking cannot be called before system unit is initialized
  2042. * MC68020 define
  2043. Revision 1.50 2002/09/17 18:54:03 jonas
  2044. * a_load_reg_reg() now has two size parameters: source and dest. This
  2045. allows some optimizations on architectures that don't encode the
  2046. register size in the register name.
  2047. Revision 1.49 2002/09/10 21:48:30 florian
  2048. * improved handling of procedures with register calling conventions
  2049. Revision 1.48 2002/09/07 15:25:03 peter
  2050. * old logs removed and tabs fixed
  2051. Revision 1.47 2002/09/02 18:44:48 peter
  2052. * fixed (not) pushing of empty parameters
  2053. * fixed implicit initialization/finalization generation
  2054. * fixed/optimized local copy of value arguments init/final
  2055. Revision 1.46 2002/09/01 19:27:34 peter
  2056. * use index register when available for generating a reference with
  2057. only a signle register. Using the base register could possibly
  2058. destroy the framepointer
  2059. Revision 1.45 2002/09/01 18:50:20 peter
  2060. * fixed maybe_save that did not support a reference with only
  2061. a index register. It now also updates the location with the new
  2062. base register only
  2063. Revision 1.44 2002/09/01 14:42:41 peter
  2064. * removevaluepara added to fix the stackpointer so restoring of
  2065. saved registers works
  2066. Revision 1.43 2002/08/25 19:25:18 peter
  2067. * sym.insert_in_data removed
  2068. * symtable.insertvardata/insertconstdata added
  2069. * removed insert_in_data call from symtable.insert, it needs to be
  2070. called separatly. This allows to deref the address calculation
  2071. * procedures now calculate the parast addresses after the procedure
  2072. directives are parsed. This fixes the cdecl parast problem
  2073. * push_addr_param has an extra argument that specifies if cdecl is used
  2074. or not
  2075. Revision 1.42 2002/08/24 18:38:26 peter
  2076. * really use tt_noreuse for exception frame buffers
  2077. Revision 1.41 2002/08/23 16:14:49 peter
  2078. * tempgen cleanup
  2079. * tt_noreuse temp type added that will be used in genentrycode
  2080. Revision 1.40 2002/08/18 10:42:37 florian
  2081. * remaining assembler writer bugs fixed, the errors in the
  2082. system unit are inline assembler problems
  2083. Revision 1.39 2002/08/17 09:23:36 florian
  2084. * first part of procinfo rewrite
  2085. Revision 1.38 2002/08/16 14:24:57 carl
  2086. * issameref() to test if two references are the same (then emit no opcodes)
  2087. + ret_in_reg to replace ret_in_acc
  2088. (fix some register allocation bugs at the same time)
  2089. + save_std_register now has an extra parameter which is the
  2090. usedinproc registers
  2091. Revision 1.37 2002/08/15 15:15:55 carl
  2092. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  2093. * more generic nodes for maths
  2094. * several fixes for better m68k support
  2095. Revision 1.36 2002/08/14 19:25:09 carl
  2096. * fix Florian's last commit for m68k compilation
  2097. Revision 1.35 2002/08/13 21:40:56 florian
  2098. * more fixes for ppc calling conventions
  2099. Revision 1.34 2002/08/12 15:08:39 carl
  2100. + stab register indexes for powerpc (moved from gdb to cpubase)
  2101. + tprocessor enumeration moved to cpuinfo
  2102. + linker in target_info is now a class
  2103. * many many updates for m68k (will soon start to compile)
  2104. - removed some ifdef or correct them for correct cpu
  2105. Revision 1.33 2002/08/11 14:32:27 peter
  2106. * renamed current_library to objectlibrary
  2107. Revision 1.32 2002/08/11 13:24:12 peter
  2108. * saving of asmsymbols in ppu supported
  2109. * asmsymbollist global is removed and moved into a new class
  2110. tasmlibrarydata that will hold the info of a .a file which
  2111. corresponds with a single module. Added librarydata to tmodule
  2112. to keep the library info stored for the module. In the future the
  2113. objectfiles will also be stored to the tasmlibrarydata class
  2114. * all getlabel/newasmsymbol and friends are moved to the new class
  2115. Revision 1.31 2002/08/09 19:16:57 carl
  2116. * stack allocation is now done separately (at the end) of genentrycode
  2117. so temps. can be allocated before.
  2118. * fix generic exception handling
  2119. Revision 1.30 2002/08/06 20:55:21 florian
  2120. * first part of ppc calling conventions fix
  2121. Revision 1.29 2002/08/04 19:09:22 carl
  2122. + added generic exception support (still does not work!)
  2123. + more documentation
  2124. Revision 1.28 2002/07/29 21:23:42 florian
  2125. * more fixes for the ppc
  2126. + wrappers for the tcnvnode.first_* stuff introduced
  2127. }