ncgutil.pas 91 KB

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