ncgutil.pas 110 KB

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