ncgutil.pas 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368
  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:cardinal);
  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.number:=(hregister.number and not $ff) or cgsize2subreg(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.number:=(l.register.number and not $ff) or cgsize2subreg(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,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.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,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,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,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,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. case cgsize of
  880. OS_8,OS_S8 :
  881. begin
  882. if alignment=4 then
  883. cgsize:=OS_32
  884. else
  885. cgsize:=OS_16;
  886. end;
  887. OS_16,OS_S16 :
  888. begin
  889. if alignment=4 then
  890. cgsize:=OS_32;
  891. end;
  892. end;
  893. { update register to use to match alignment }
  894. if p.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  895. begin
  896. if p.location.register.enum<>R_INTREGISTER then
  897. internalerror(200302024);
  898. hreg:=p.location.register;
  899. p.location.register.number:=(p.location.register.number and not $ff) or cgsize2subreg(cgsize);
  900. end;
  901. inc(pushedparasize,alignment);
  902. if calloption=pocall_inline then
  903. begin
  904. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  905. if p.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  906. begin
  907. size:=align(p.resulttype.def.size,alignment);
  908. cg.g_concatcopy(list,p.location.reference,href,size,false,false)
  909. end
  910. else
  911. cg.a_load_loc_ref(list,p.location,href);
  912. end
  913. else
  914. cg.a_param_loc(list,p.location,locpara);
  915. { restore old register }
  916. if p.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  917. p.location.register:=hreg;
  918. end;
  919. location_release(list,p.location);
  920. end;
  921. {$ifdef SUPPORT_MMX}
  922. LOC_MMXREGISTER,
  923. LOC_CMMXREGISTER:
  924. begin
  925. inc(pushedparasize,8);
  926. if calloption=pocall_inline then
  927. begin
  928. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  929. cg.a_loadmm_reg_ref(list,p.location.register,href);
  930. end
  931. else
  932. cg.a_parammm_reg(list,p.location.register);
  933. end;
  934. {$endif SUPPORT_MMX}
  935. else
  936. internalerror(200204241);
  937. end;
  938. end;
  939. end;
  940. end;
  941. {****************************************************************************
  942. Entry/Exit Code
  943. ****************************************************************************}
  944. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  945. var
  946. href1,href2 : treference;
  947. list : taasmoutput;
  948. loadref: boolean;
  949. begin
  950. list:=taasmoutput(arg);
  951. if (tsym(p).typ=varsym) and
  952. (tvarsym(p).varspez=vs_value) and
  953. (paramanager.push_addr_param(tvarsym(p).vartype.def,current_procinfo.procdef.proccalloption)) then
  954. begin
  955. loadref := tvarsym(p).reg.enum = R_NO;
  956. if (loadref) then
  957. reference_reset_base(href1,current_procinfo.framepointer,tvarsym(p).adjusted_address)
  958. else
  959. reference_reset_base(href1,tvarsym(p).reg,0);
  960. if is_open_array(tvarsym(p).vartype.def) or
  961. is_array_of_const(tvarsym(p).vartype.def) then
  962. if loadref then
  963. cg.g_copyvaluepara_openarray(list,href1,tarraydef(tvarsym(p).vartype.def).elesize)
  964. else
  965. internalerror(2003053101)
  966. else
  967. begin
  968. reference_reset_base(href2,current_procinfo.framepointer,tvarsym(p).localvarsym.adjusted_address);
  969. if is_shortstring(tvarsym(p).vartype.def) then
  970. cg.g_copyshortstring(list,href1,href2,tstringdef(tvarsym(p).vartype.def).len,false,loadref)
  971. else
  972. cg.g_concatcopy(list,href1,href2,tvarsym(p).vartype.def.size,true,loadref);
  973. end;
  974. end;
  975. end;
  976. { generates the code for initialisation of local data }
  977. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  978. var
  979. href : treference;
  980. list : taasmoutput;
  981. begin
  982. list:=taasmoutput(arg);
  983. if (tsym(p).typ=varsym) and
  984. not(vo_is_local_copy 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 (cs_implicit_exceptions in aktmoduleswitches) then
  990. include(current_procinfo.flags,pi_needs_implicit_finally);
  991. if tsym(p).owner.symtabletype in [localsymtable,inlinelocalsymtable] then
  992. reference_reset_base(href,current_procinfo.framepointer,tvarsym(p).adjusted_address)
  993. else
  994. reference_reset_symbol(href,objectlibrary.newasmsymboldata(tvarsym(p).mangledname),0);
  995. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  996. end;
  997. end;
  998. { generates the code for finalisation of local data }
  999. procedure finalize_data(p : tnamedindexitem;arg:pointer);
  1000. var
  1001. href : treference;
  1002. list : taasmoutput;
  1003. begin
  1004. list:=taasmoutput(arg);
  1005. case tsym(p).typ of
  1006. varsym :
  1007. begin
  1008. if not(vo_is_local_copy in tvarsym(p).varoptions) and
  1009. not(vo_is_funcret in tvarsym(p).varoptions) and
  1010. assigned(tvarsym(p).vartype.def) and
  1011. not(is_class(tvarsym(p).vartype.def)) and
  1012. tvarsym(p).vartype.def.needs_inittable then
  1013. begin
  1014. if tsym(p).owner.symtabletype in [localsymtable,inlinelocalsymtable] then
  1015. reference_reset_base(href,current_procinfo.framepointer,tvarsym(p).adjusted_address)
  1016. else
  1017. reference_reset_symbol(href,objectlibrary.newasmsymboldata(tvarsym(p).mangledname),0);
  1018. cg.g_finalize(list,tvarsym(p).vartype.def,href,false);
  1019. end;
  1020. end;
  1021. typedconstsym :
  1022. begin
  1023. if ttypedconstsym(p).is_writable and
  1024. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  1025. begin
  1026. reference_reset_symbol(href,objectlibrary.newasmsymboldata(ttypedconstsym(p).mangledname),0);
  1027. cg.g_finalize(list,ttypedconstsym(p).typedconsttype.def,href,false);
  1028. end;
  1029. end;
  1030. end;
  1031. end;
  1032. { generates the code for incrementing the reference count of parameters and
  1033. initialize out parameters }
  1034. procedure init_paras(p : tnamedindexitem;arg:pointer);
  1035. var
  1036. href : treference;
  1037. tmpreg : tregister;
  1038. list : taasmoutput;
  1039. begin
  1040. list:=taasmoutput(arg);
  1041. if (tsym(p).typ=varsym) and
  1042. not is_class(tvarsym(p).vartype.def) and
  1043. tvarsym(p).vartype.def.needs_inittable then
  1044. begin
  1045. case tvarsym(p).varspez of
  1046. vs_value :
  1047. begin
  1048. if (cs_implicit_exceptions in aktmoduleswitches) then
  1049. include(current_procinfo.flags,pi_needs_implicit_finally);
  1050. if assigned(tvarsym(p).localvarsym) then
  1051. reference_reset_base(href,current_procinfo.framepointer,tvarsym(p).localvarsym.adjusted_address)
  1052. else
  1053. reference_reset_base(href,current_procinfo.framepointer,tvarsym(p).adjusted_address);
  1054. cg.g_incrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  1055. end;
  1056. vs_out :
  1057. begin
  1058. reference_reset_base(href,current_procinfo.framepointer,tvarsym(p).adjusted_address);
  1059. {$ifdef newra}
  1060. tmpreg:=rg.getaddressregister(list);
  1061. {$else}
  1062. tmpreg:=cg.get_scratch_reg_address(list);
  1063. {$endif}
  1064. cg.a_load_ref_reg(list,OS_ADDR,href,tmpreg);
  1065. reference_reset_base(href,tmpreg,0);
  1066. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  1067. {$ifdef newra}
  1068. rg.ungetregisterint(list,tmpreg);
  1069. {$else}
  1070. cg.free_scratch_reg(list,tmpreg);
  1071. {$endif newra}
  1072. end;
  1073. end;
  1074. end;
  1075. end;
  1076. { generates the code for decrementing the reference count of parameters }
  1077. procedure final_paras(p : tnamedindexitem;arg:pointer);
  1078. var
  1079. href : treference;
  1080. list : taasmoutput;
  1081. begin
  1082. list:=taasmoutput(arg);
  1083. if (tsym(p).typ=varsym) and
  1084. not is_class(tvarsym(p).vartype.def) and
  1085. tvarsym(p).vartype.def.needs_inittable then
  1086. begin
  1087. if (tvarsym(p).varspez=vs_value) then
  1088. begin
  1089. if assigned(tvarsym(p).localvarsym) then
  1090. reference_reset_base(href,current_procinfo.framepointer,tvarsym(p).localvarsym.adjusted_address)
  1091. else
  1092. reference_reset_base(href,current_procinfo.framepointer,tvarsym(p).adjusted_address);
  1093. cg.g_decrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  1094. end;
  1095. end;
  1096. end;
  1097. { Initialize temp ansi/widestrings,interfaces }
  1098. procedure inittempvariables(list:taasmoutput);
  1099. var
  1100. hp : ptemprecord;
  1101. href : treference;
  1102. begin
  1103. hp:=tg.templist;
  1104. while assigned(hp) do
  1105. begin
  1106. if hp^.temptype in [tt_ansistring,tt_freeansistring,
  1107. tt_widestring,tt_freewidestring,
  1108. tt_interfacecom,tt_freeinterfacecom] then
  1109. begin
  1110. if (cs_implicit_exceptions in aktmoduleswitches) then
  1111. include(current_procinfo.flags,pi_needs_implicit_finally);
  1112. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1113. cg.a_load_const_ref(list,OS_ADDR,0,href);
  1114. end;
  1115. hp:=hp^.next;
  1116. end;
  1117. end;
  1118. procedure finalizetempvariables(list:taasmoutput);
  1119. var
  1120. hp : ptemprecord;
  1121. href : treference;
  1122. begin
  1123. hp:=tg.templist;
  1124. while assigned(hp) do
  1125. begin
  1126. case hp^.temptype of
  1127. tt_ansistring,
  1128. tt_freeansistring :
  1129. begin
  1130. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1131. cg.a_paramaddr_ref(list,href,paramanager.getintparaloc(1));
  1132. cg.a_call_name(list,'FPC_ANSISTR_DECR_REF');
  1133. end;
  1134. tt_widestring,
  1135. tt_freewidestring :
  1136. begin
  1137. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1138. cg.a_paramaddr_ref(list,href,paramanager.getintparaloc(1));
  1139. cg.a_call_name(list,'FPC_WIDESTR_DECR_REF');
  1140. end;
  1141. tt_interfacecom :
  1142. begin
  1143. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  1144. cg.a_paramaddr_ref(list,href,paramanager.getintparaloc(1));
  1145. cg.a_call_name(list,'FPC_INTF_DECR_REF');
  1146. end;
  1147. end;
  1148. hp:=hp^.next;
  1149. end;
  1150. end;
  1151. procedure initretvalue(list:taasmoutput);
  1152. var
  1153. paraloc : tparalocation;
  1154. href : treference;
  1155. begin
  1156. if not is_void(current_procdef.rettype.def) then
  1157. begin
  1158. { initialize return value }
  1159. if (current_procdef.rettype.def.needs_inittable) then
  1160. begin
  1161. {$ifdef powerpc}
  1162. if (po_assembler in current_procdef.procoptions) then
  1163. internalerror(200304161);
  1164. {$endif powerpc}
  1165. if (cs_implicit_exceptions in aktmoduleswitches) then
  1166. include(current_procinfo.flags,pi_needs_implicit_finally);
  1167. reference_reset_base(href,current_procinfo.framepointer,tvarsym(current_procdef.funcretsym).adjusted_address);
  1168. cg.g_initialize(list,current_procdef.rettype.def,href,paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption));
  1169. { load the pointer to the initialized retvalue in te register }
  1170. if (tvarsym(current_procdef.funcretsym).reg.enum <> R_NO) then
  1171. cg.a_load_ref_reg(list,OS_ADDR,href,tvarsym(current_procdef.funcretsym).reg);
  1172. end;
  1173. end;
  1174. end;
  1175. procedure load_return_value(list:TAAsmoutput; var uses_acc,uses_acchi,uses_fpu : boolean);
  1176. var
  1177. ressym: tvarsym;
  1178. resloc: tlocation;
  1179. hreg,r,r2 : tregister;
  1180. begin
  1181. if not is_void(current_procdef.rettype.def) then
  1182. begin
  1183. ressym := tvarsym(current_procdef.funcretsym);
  1184. if ressym.reg.enum <> R_NO then
  1185. begin
  1186. if paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption) then
  1187. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  1188. else
  1189. if ressym.vartype.def.deftype = floatdef then
  1190. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procdef.rettype.def))
  1191. else
  1192. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procdef.rettype.def));
  1193. resloc.register := ressym.reg;
  1194. end
  1195. else
  1196. begin
  1197. location_reset(resloc,LOC_REFERENCE,def_cgsize(current_procdef.rettype.def));
  1198. reference_reset_base(resloc.reference,current_procinfo.framepointer,tvarsym(current_procdef.funcretsym).adjusted_address);
  1199. end;
  1200. { Here, we return the function result. In most architectures, the value is
  1201. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1202. function returns in a register and the caller receives it in an other one }
  1203. case current_procdef.rettype.def.deftype of
  1204. orddef,
  1205. enumdef :
  1206. begin
  1207. uses_acc:=true;
  1208. {$ifndef cpu64bit}
  1209. if resloc.size in [OS_64,OS_S64] then
  1210. begin
  1211. uses_acchi:=true;
  1212. r.enum:=R_INTREGISTER;
  1213. r.number:=NR_FUNCTION_RETURN64_LOW_REG;
  1214. cg.a_reg_alloc(list,r);
  1215. r2.enum:=R_INTREGISTER;
  1216. r2.number:=NR_FUNCTION_RETURN64_HIGH_REG;
  1217. cg.a_reg_alloc(list,r2);
  1218. cg64.a_load64_ref_reg(list,resloc,joinreg64(r,r2){$ifdef newra},false{$endif});
  1219. end
  1220. else
  1221. {$endif cpu64bit}
  1222. begin
  1223. hreg.enum:=R_INTREGISTER;
  1224. hreg.number:=(RS_FUNCTION_RETURN_REG shl 8) or cgsize2subreg(resloc.size);
  1225. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  1226. end;
  1227. end;
  1228. floatdef :
  1229. begin
  1230. uses_fpu := true;
  1231. {$ifdef cpufpemu}
  1232. if cs_fp_emulation in aktmoduleswitches then
  1233. r.enum := FUNCTION_RETURN_REG
  1234. else
  1235. {$endif cpufpemu}
  1236. r.enum:=FPU_RESULT_REG;
  1237. cg.a_loadfpu_loc_reg(list,resloc,r);
  1238. end;
  1239. else
  1240. begin
  1241. if not paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption) then
  1242. begin
  1243. uses_acc:=true;
  1244. {$ifndef cpu64bit}
  1245. { Win32 can return records in EAX:EDX }
  1246. if resloc.size in [OS_64,OS_S64] then
  1247. begin
  1248. uses_acchi:=true;
  1249. r.enum:=R_INTREGISTER;
  1250. r.number:=NR_FUNCTION_RETURN64_LOW_REG;
  1251. cg.a_reg_alloc(list,r);
  1252. r2.enum:=R_INTREGISTER;
  1253. r2.number:=NR_FUNCTION_RETURN64_HIGH_REG;
  1254. cg.a_reg_alloc(list,r2);
  1255. cg64.a_load64_ref_reg(list,resloc,joinreg64(r,r2){$ifdef newra},false{$endif});
  1256. end
  1257. else
  1258. {$endif cpu64bit}
  1259. begin
  1260. hreg.enum:=R_INTREGISTER;
  1261. hreg.number:=(RS_FUNCTION_RETURN_REG shl 8) or cgsize2subreg(resloc.size);
  1262. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  1263. end;
  1264. end
  1265. end;
  1266. end;
  1267. end;
  1268. end;
  1269. procedure genentrycode(list:TAAsmoutput;inlined:boolean);
  1270. var
  1271. href : treference;
  1272. hp : tparaitem;
  1273. rsp : tregister;
  1274. begin
  1275. { the actual stack allocation code, symbol entry point and
  1276. gdb stabs information is generated AFTER the rest of this
  1277. code, since temp. allocation might occur before - carl
  1278. }
  1279. if assigned(current_procdef.parast) then
  1280. begin
  1281. if not (po_assembler in current_procdef.procoptions) then
  1282. begin
  1283. { move register parameters which aren't regable into memory }
  1284. { we do this before init_paras because that one calls routines which may overwrite these }
  1285. { registers and it also expects the values to be in memory }
  1286. hp:=tparaitem(current_procdef.para.first);
  1287. while assigned(hp) do
  1288. begin
  1289. if Tvarsym(hp.parasym).reg.enum>R_INTREGISTER then
  1290. internalerror(200301081);
  1291. if (tvarsym(hp.parasym).reg.enum<>R_NO) then
  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_reg(list,hp.paraloc.size,hp.paraloc.size,hp.paraloc.register,tvarsym(hp.parasym).reg)
  1297. else
  1298. internalerror(2003053011);
  1299. // cg64.a_load64_reg_reg(list,hp.paraloc.register64,tvarsym(hp.parasym).reg);
  1300. LOC_CFPUREGISTER,
  1301. LOC_FPUREGISTER:
  1302. cg.a_loadfpu_reg_reg(list,hp.paraloc.register,tvarsym(hp.parasym).reg);
  1303. LOC_REFERENCE,
  1304. LOC_CREFERENCE:
  1305. begin
  1306. reference_reset_base(href,current_procinfo.framepointer,tvarsym(hp.parasym).adjusted_address);
  1307. cg.a_load_ref_reg(list,hp.paraloc.size,href,tvarsym(hp.parasym).reg);
  1308. end;
  1309. else
  1310. internalerror(2003053010);
  1311. end
  1312. else if (hp.paraloc.loc in [LOC_REGISTER,LOC_FPUREGISTER,LOC_MMREGISTER,
  1313. LOC_CREGISTER,LOC_CFPUREGISTER,LOC_CMMREGISTER]) and
  1314. (tvarsym(hp.parasym).reg.enum=R_NO) then
  1315. begin
  1316. reference_reset_base(href,current_procinfo.framepointer,tvarsym(hp.parasym).adjusted_address);
  1317. case hp.paraloc.loc of
  1318. LOC_CREGISTER,
  1319. LOC_REGISTER:
  1320. if not(hp.paraloc.size in [OS_S64,OS_64]) then
  1321. cg.a_load_reg_ref(list,hp.paraloc.size,hp.paraloc.register,href)
  1322. else
  1323. cg64.a_load64_reg_ref(list,hp.paraloc.register64,href);
  1324. LOC_FPUREGISTER,
  1325. LOC_CFPUREGISTER:
  1326. cg.a_loadfpu_reg_ref(list,hp.paraloc.size,hp.paraloc.register,href);
  1327. else
  1328. internalerror(2002081302);
  1329. end;
  1330. end;
  1331. hp:=tparaitem(hp.next);
  1332. end;
  1333. end;
  1334. end;
  1335. { for the save all registers we can simply use a pusha,popa which
  1336. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1337. if (po_saveregisters in current_procdef.procoptions) then
  1338. cg.g_save_all_registers(list)
  1339. else
  1340. { should we save edi,esi,ebx like C ? }
  1341. if (po_savestdregs in current_procdef.procoptions) then
  1342. cg.g_save_standard_registers(list,current_procdef.usedintregisters);
  1343. { Save stackpointer value }
  1344. if not inlined and
  1345. (current_procinfo.framepointer.number<>NR_STACK_POINTER_REG) and
  1346. ((po_savestdregs in current_procdef.procoptions) or
  1347. (po_saveregisters in current_procdef.procoptions)) then
  1348. begin
  1349. tg.GetTemp(list,POINTER_SIZE,tt_noreuse,current_procinfo.save_stackptr_ref);
  1350. rsp.enum:=R_INTREGISTER;
  1351. rsp.number:=NR_STACK_POINTER_REG;
  1352. cg.a_load_reg_ref(list,OS_ADDR,rsp,current_procinfo.save_stackptr_ref);
  1353. end;
  1354. { the actual profile code can clobber some registers,
  1355. therefore if the context must be saved, do it before
  1356. the actual call to the profile code
  1357. }
  1358. if (cs_profile in aktmoduleswitches) and
  1359. not(po_assembler in current_procdef.procoptions) and
  1360. not(inlined) then
  1361. begin
  1362. { non-win32 can call mcout even in main }
  1363. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  1364. cg.g_profilecode(list)
  1365. else
  1366. { wdosx, and win32 should not call mcount before monstartup has been called }
  1367. if not (current_procdef.proctypeoption=potype_proginit) then
  1368. cg.g_profilecode(list);
  1369. end;
  1370. { initialize return value }
  1371. initretvalue(list);
  1372. { initialize local data like ansistrings }
  1373. case current_procdef.proctypeoption of
  1374. potype_unitinit:
  1375. begin
  1376. { this is also used for initialization of variables in a
  1377. program which does not have a globalsymtable }
  1378. if assigned(current_module.globalsymtable) then
  1379. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1380. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1381. end;
  1382. { units have seperate code for initilization and finalization }
  1383. potype_unitfinalize: ;
  1384. { program init/final is generated in separate procedure }
  1385. potype_proginit: ;
  1386. else
  1387. current_procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1388. end;
  1389. { initialisizes temp. ansi/wide string data }
  1390. inittempvariables(list);
  1391. { initialize ansi/widesstring para's }
  1392. if assigned(current_procdef.parast) then
  1393. begin
  1394. current_procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1395. end;
  1396. { generate copies of call by value parameters }
  1397. if not(po_assembler in current_procdef.procoptions) then
  1398. current_procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1399. if (not inlined) then
  1400. begin
  1401. { call startup helpers from main program }
  1402. if (current_procdef.proctypeoption=potype_proginit) then
  1403. begin
  1404. { initialize profiling for win32 }
  1405. if (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1406. (cs_profile in aktmoduleswitches) then
  1407. begin
  1408. reference_reset_symbol(href,objectlibrary.newasmsymboldata('etext'),0);
  1409. cg.a_paramaddr_ref(list,href,paramanager.getintparaloc(2));
  1410. reference_reset_symbol(href,objectlibrary.newasmsymboldata('__image_base__'),0);
  1411. cg.a_paramaddr_ref(list,href,paramanager.getintparaloc(2));
  1412. cg.a_call_name(list,'_monstartup');
  1413. end;
  1414. { initialize units }
  1415. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1416. end;
  1417. {$ifdef GDB}
  1418. if (cs_debuginfo in aktmoduleswitches) then
  1419. list.concat(Tai_force_line.Create);
  1420. {$endif GDB}
  1421. end;
  1422. if inlined then
  1423. load_regvars(list,nil);
  1424. end;
  1425. procedure gen_stackalloc_code(list:Taasmoutput;stackframe:cardinal);
  1426. var hs:string;
  1427. begin
  1428. {************************* Stack allocation **************************}
  1429. { and symbol entry point as well as debug information }
  1430. { will be inserted in front of the rest of this list. }
  1431. { Insert alignment and assembler names }
  1432. { Align, gprof uses 16 byte granularity }
  1433. if (cs_profile in aktmoduleswitches) then
  1434. list.concat(Tai_align.create(16))
  1435. else
  1436. list.concat(Tai_align.create(aktalignment.procalign));
  1437. {$ifdef GDB}
  1438. if (cs_debuginfo in aktmoduleswitches) then
  1439. begin
  1440. if (po_public in current_procdef.procoptions) then
  1441. Tprocsym(current_procdef.procsym).is_global:=true;
  1442. current_procdef.concatstabto(list);
  1443. Tprocsym(current_procdef.procsym).isstabwritten:=true;
  1444. end;
  1445. {$endif GDB}
  1446. repeat
  1447. hs:=current_procdef.aliasnames.getfirst;
  1448. if hs='' then
  1449. break;
  1450. {$ifdef GDB}
  1451. if (cs_debuginfo in aktmoduleswitches) and
  1452. target_info.use_function_relative_addresses then
  1453. list.concat(Tai_stab_function_name.create(strpnew(hs)));
  1454. {$endif GDB}
  1455. if (cs_profile in aktmoduleswitches) or
  1456. (po_public in current_procdef.procoptions) then
  1457. list.concat(Tai_symbol.createname_global(hs,0))
  1458. else
  1459. list.concat(Tai_symbol.createname(hs,0));
  1460. until false;
  1461. stackframe:=stackframe+tg.gettempsize;
  1462. {$ifndef m68k}
  1463. { give a warning if the limit of local variables is reached }
  1464. if stackframe>maxlocalsize then
  1465. message(cg_w_localsize_too_big);
  1466. {$endif}
  1467. {$ifndef powerpc}
  1468. { at least for the ppc this applies always, so this code isn't usable (FK) }
  1469. { omit stack frame ? }
  1470. if (current_procinfo.framepointer.number=NR_STACK_POINTER_REG) then
  1471. begin
  1472. CGmessage(cg_d_stackframe_omited);
  1473. if stackframe<>0 then
  1474. cg.g_stackpointer_alloc(list,stackframe);
  1475. end
  1476. else
  1477. {$endif powerpc}
  1478. begin
  1479. if (po_interrupt in current_procdef.procoptions) then
  1480. cg.g_interrupt_stackframe_entry(list);
  1481. cg.g_stackframe_entry(list,stackframe);
  1482. {Never call stack checking before the standard system unit
  1483. has been initialized.}
  1484. if (cs_check_stack in aktlocalswitches) and (current_procdef.proctypeoption<>potype_proginit) then
  1485. cg.g_stackcheck(list,stackframe);
  1486. end;
  1487. end;
  1488. procedure genexitcode(list : TAAsmoutput;inlined:boolean);
  1489. var
  1490. {$ifdef GDB}
  1491. stabsendlabel : tasmlabel;
  1492. mangled_length : longint;
  1493. p : pchar;
  1494. {$endif GDB}
  1495. okexitlabel : tasmlabel;
  1496. href : treference;
  1497. srsym : tsym;
  1498. usesacc,
  1499. usesacchi,
  1500. usesself,usesfpu : boolean;
  1501. pd : tprocdef;
  1502. rsp,tmpreg,r : Tregister;
  1503. retsize:cardinal;
  1504. nostackframe:boolean;
  1505. begin
  1506. { nostackframe:=current_procinfo.framepointer.number=NR_STACK_POINTER_REG;}
  1507. if aktexitlabel.is_used then
  1508. cg.a_label(list,aktexitlabel);
  1509. cleanup_regvars(list);
  1510. { finalize temporary data }
  1511. finalizetempvariables(list);
  1512. { finalize local data like ansistrings}
  1513. case current_procdef.proctypeoption of
  1514. potype_unitfinalize:
  1515. begin
  1516. { this is also used for initialization of variables in a
  1517. program which does not have a globalsymtable }
  1518. if assigned(current_module.globalsymtable) then
  1519. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1520. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1521. end;
  1522. { units/progs have separate code for initialization and finalization }
  1523. potype_unitinit: ;
  1524. { program init/final is generated in separate procedure }
  1525. potype_proginit: ;
  1526. else
  1527. current_procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1528. end;
  1529. { finalize paras data }
  1530. if assigned(current_procdef.parast) then
  1531. current_procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1532. { call __EXIT for main program }
  1533. if (not DLLsource) and
  1534. (not inlined) and
  1535. (current_procdef.proctypeoption=potype_proginit) then
  1536. begin
  1537. cg.a_call_name(list,'FPC_DO_EXIT');
  1538. end;
  1539. { handle return value, this is not done for assembler routines when
  1540. they didn't reference the result variable }
  1541. usesacc:=false;
  1542. usesacchi:=false;
  1543. if not(po_assembler in current_procdef.procoptions) or
  1544. (assigned(current_procdef.funcretsym) and
  1545. (tvarsym(current_procdef.funcretsym).refcount>1)) then
  1546. begin
  1547. if (current_procdef.proctypeoption=potype_constructor) then
  1548. begin
  1549. objectlibrary.getlabel(okexitlabel);
  1550. cg.a_jmp_always(list,okexitlabel);
  1551. { Success exit }
  1552. cg.a_label(list,okexitlabel);
  1553. r.enum:=R_INTREGISTER;
  1554. r.number:=NR_FUNCTION_RETURN_REG;
  1555. cg.a_reg_alloc(list,r);
  1556. { return the self pointer }
  1557. srsym:=tvarsym(current_procdef.parast.search('self'));
  1558. if not assigned(srsym) then
  1559. internalerror(200305058);
  1560. reference_reset_base(href,current_procinfo.framepointer,tvarsym(srsym).adjusted_address);
  1561. cg.a_load_ref_reg(list,OS_ADDR,href,r);
  1562. cg.a_reg_dealloc(list,r);
  1563. usesacc:=true;
  1564. end
  1565. else
  1566. load_return_value(list,usesacc,usesacchi,usesfpu)
  1567. end;
  1568. {$ifdef GDB}
  1569. if ((cs_debuginfo in aktmoduleswitches) and not inlined) then
  1570. begin
  1571. objectlibrary.getlabel(stabsendlabel);
  1572. cg.a_label(list,stabsendlabel);
  1573. end;
  1574. {$endif GDB}
  1575. { Restore stackpointer if it was saved }
  1576. if not inlined and
  1577. (current_procinfo.framepointer.number<>NR_STACK_POINTER_REG) and
  1578. ((po_savestdregs in current_procdef.procoptions) or
  1579. (po_saveregisters in current_procdef.procoptions)) then
  1580. begin
  1581. rsp.enum:=R_INTREGISTER;
  1582. rsp.number:=NR_STACK_POINTER_REG;
  1583. cg.a_load_ref_reg(list,OS_ADDR,current_procinfo.save_stackptr_ref,rsp);
  1584. tg.UngetTemp(list,current_procinfo.save_stackptr_ref);
  1585. end;
  1586. { for the save all registers we can simply use a pusha,popa which
  1587. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1588. if (po_saveregisters in current_procdef.procoptions) then
  1589. cg.g_restore_all_registers(list,usesacc,usesacchi)
  1590. else
  1591. { should we restore edi ? }
  1592. if (po_savestdregs in current_procdef.procoptions) then
  1593. cg.g_restore_standard_registers(list,current_procdef.usedintregisters);
  1594. {$ifndef powerpc}
  1595. { remove stackframe }
  1596. if not inlined then
  1597. begin
  1598. if (current_procinfo.framepointer.number=NR_STACK_POINTER_REG) then
  1599. begin
  1600. if (tg.gettempsize<>0) then
  1601. cg.a_op_const_reg(list,OP_ADD,OS_32,tg.gettempsize,current_procinfo.framepointer);
  1602. end
  1603. else
  1604. cg.g_restore_frame_pointer(list);
  1605. end;
  1606. {$endif}
  1607. { at last, the return is generated }
  1608. if not inlined then
  1609. begin
  1610. if (po_interrupt in current_procdef.procoptions) then
  1611. cg.g_interrupt_stackframe_exit(list,usesacc,usesacchi)
  1612. else
  1613. begin
  1614. if (po_clearstack in current_procdef.procoptions) then
  1615. begin
  1616. retsize:=0;
  1617. if paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption) then
  1618. inc(retsize,POINTER_SIZE);
  1619. end
  1620. else
  1621. begin
  1622. retsize:=current_procdef.parast.datasize;
  1623. if current_procdef.parast.address_fixup>target_info.first_parm_offset then
  1624. inc(retsize,current_procdef.parast.address_fixup-target_info.first_parm_offset);
  1625. end;
  1626. cg.g_return_from_proc(list,retsize);
  1627. end;
  1628. end;
  1629. if not inlined then
  1630. list.concat(Tai_symbol_end.Createname(current_procdef.mangledname));
  1631. {$ifdef GDB}
  1632. if (cs_debuginfo in aktmoduleswitches) and not inlined then
  1633. begin
  1634. { define calling EBP as pseudo local var PM }
  1635. { this enables test if the function is a local one !! }
  1636. if assigned(current_procinfo.parent) and
  1637. (current_procdef.parast.symtablelevel>normal_function_level) then
  1638. list.concat(Tai_stabs.Create(strpnew(
  1639. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1640. tostr(N_LSYM)+',0,0,'+tostr(current_procinfo.framepointer_offset))));
  1641. if (not is_void(current_procdef.rettype.def)) then
  1642. begin
  1643. if paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption) then
  1644. list.concat(Tai_stabs.Create(strpnew(
  1645. '"'+current_procdef.procsym.name+':X*'+tstoreddef(current_procdef.rettype.def).numberstring+'",'+
  1646. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procdef.funcretsym).adjusted_address))))
  1647. else
  1648. list.concat(Tai_stabs.Create(strpnew(
  1649. '"'+current_procdef.procsym.name+':X'+tstoreddef(current_procdef.rettype.def).numberstring+'",'+
  1650. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procdef.funcretsym).adjusted_address))));
  1651. if (m_result in aktmodeswitches) then
  1652. if paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption) then
  1653. list.concat(Tai_stabs.Create(strpnew(
  1654. '"RESULT:X*'+tstoreddef(current_procdef.rettype.def).numberstring+'",'+
  1655. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procdef.funcretsym).adjusted_address))))
  1656. else
  1657. list.concat(Tai_stabs.Create(strpnew(
  1658. '"RESULT:X'+tstoreddef(current_procdef.rettype.def).numberstring+'",'+
  1659. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procdef.funcretsym).adjusted_address))));
  1660. end;
  1661. mangled_length:=length(current_procdef.mangledname);
  1662. getmem(p,2*mangled_length+50);
  1663. strpcopy(p,'192,0,0,');
  1664. strpcopy(strend(p),current_procdef.mangledname);
  1665. if (target_info.use_function_relative_addresses) then
  1666. begin
  1667. strpcopy(strend(p),'-');
  1668. strpcopy(strend(p),current_procdef.mangledname);
  1669. end;
  1670. list.concat(Tai_stabn.Create(strnew(p)));
  1671. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1672. +current_procdef.mangledname))));
  1673. p[0]:='2';p[1]:='2';p[2]:='4';
  1674. strpcopy(strend(p),'_end');}
  1675. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1676. if (target_info.use_function_relative_addresses) then
  1677. begin
  1678. strpcopy(strend(p),'-');
  1679. strpcopy(strend(p),current_procdef.mangledname);
  1680. end;
  1681. list.concatlist(withdebuglist);
  1682. list.concat(Tai_stabn.Create(strnew(p)));
  1683. { strpnew('224,0,0,'
  1684. +current_procdef.mangledname+'_end'))));}
  1685. freemem(p,2*mangled_length+50);
  1686. end;
  1687. {$endif GDB}
  1688. if inlined then
  1689. cleanup_regvars(list);
  1690. end;
  1691. {****************************************************************************
  1692. Inlining
  1693. ****************************************************************************}
  1694. procedure load_inlined_return_value(list:TAAsmoutput);
  1695. var
  1696. ressym: tvarsym;
  1697. resloc: tlocation;
  1698. r,r2 : tregister;
  1699. begin
  1700. if not is_void(current_procdef.rettype.def) then
  1701. begin
  1702. ressym := tvarsym(current_procdef.funcretsym);
  1703. if ressym.reg.enum <> R_NO then
  1704. begin
  1705. if paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption) then
  1706. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  1707. else
  1708. if ressym.vartype.def.deftype = floatdef then
  1709. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procdef.rettype.def))
  1710. else
  1711. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procdef.rettype.def));
  1712. resloc.register := ressym.reg;
  1713. end
  1714. else
  1715. begin
  1716. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procdef.rettype.def));
  1717. reference_reset_base(resloc.reference,current_procinfo.framepointer,tvarsym(current_procdef.funcretsym).adjusted_address);
  1718. end;
  1719. { Here, we return the function result. In most architectures, the value is
  1720. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1721. function returns in a register and the caller receives it in an other one }
  1722. case current_procdef.rettype.def.deftype of
  1723. orddef,
  1724. enumdef :
  1725. begin
  1726. {$ifndef cpu64bit}
  1727. if resloc.size in [OS_64,OS_S64] then
  1728. begin
  1729. r:=rg.getregisterint(list,OS_INT);
  1730. r2:=rg.getregisterint(list,OS_INT);
  1731. cg64.a_load64_ref_reg(list,resloc,joinreg64(r,r2){$ifdef newra},false{$endif});
  1732. end
  1733. else
  1734. {$endif cpu64bit}
  1735. begin
  1736. r:=rg.getregisterint(list,resloc.size);
  1737. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1738. end;
  1739. end;
  1740. floatdef :
  1741. begin
  1742. {$ifdef cpufpemu}
  1743. if cs_fp_emulation in aktmoduleswitches then
  1744. r.enum := FUNCTION_RETURN_REG
  1745. else
  1746. {$endif cpufpemu}
  1747. r.enum:=FPU_RESULT_REG;
  1748. cg.a_loadfpu_loc_reg(list,resloc,r);
  1749. end;
  1750. else
  1751. begin
  1752. if not paramanager.ret_in_param(current_procdef.rettype.def,current_procdef.proccalloption) then
  1753. begin
  1754. {$ifndef cpu64bit}
  1755. { Win32 can return records in EAX:EDX }
  1756. if resloc.size in [OS_64,OS_S64] then
  1757. begin
  1758. r:=rg.getregisterint(list,OS_INT);
  1759. r2:=rg.getregisterint(list,OS_INT);
  1760. cg64.a_load64_ref_reg(list,resloc,joinreg64(r,r2){$ifdef newra},false{$endif});
  1761. end
  1762. else
  1763. {$endif cpu64bit}
  1764. begin
  1765. r:=rg.getregisterint(list,resloc.size);
  1766. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1767. end;
  1768. end
  1769. end;
  1770. end;
  1771. end;
  1772. end;
  1773. procedure geninlineentrycode(list : TAAsmoutput;stackframe:longint);
  1774. begin
  1775. { initialize return value }
  1776. initretvalue(list);
  1777. current_procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1778. { initialisizes temp. ansi/wide string data }
  1779. inittempvariables(list);
  1780. { initialize ansi/widesstring para's }
  1781. if assigned(current_procdef.parast) then
  1782. current_procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1783. { generate copies of call by value parameters }
  1784. if not(po_assembler in current_procdef.procoptions) then
  1785. current_procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1786. load_regvars(list,nil);
  1787. end;
  1788. procedure geninlineexitcode(list : TAAsmoutput;inlined:boolean);
  1789. var
  1790. usesacc,
  1791. usesacchi,
  1792. usesfpu : boolean;
  1793. begin
  1794. if aktexitlabel.is_used then
  1795. cg.a_label(list,aktexitlabel);
  1796. cleanup_regvars(list);
  1797. { finalize temporary data }
  1798. finalizetempvariables(list);
  1799. current_procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1800. { finalize paras data }
  1801. if assigned(current_procdef.parast) then
  1802. current_procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1803. { handle return value, this is not done for assembler routines when
  1804. they didn't reference the result variable }
  1805. if not(po_assembler in current_procdef.procoptions) or
  1806. (assigned(current_procdef.funcretsym) and
  1807. (tvarsym(current_procdef.funcretsym).refcount>1)) then
  1808. begin
  1809. if (current_procdef.proctypeoption=potype_constructor) then
  1810. internalerror(200305263);
  1811. // load_inlined_return_value(list);
  1812. load_return_value(list,usesacc,usesacchi,usesfpu)
  1813. end;
  1814. cleanup_regvars(list);
  1815. end;
  1816. end.
  1817. {
  1818. $Log$
  1819. Revision 1.119 2003-06-03 15:06:37 daniel
  1820. * fixed conflict marks
  1821. Revision 1.118 2003/06/03 13:01:59 daniel
  1822. * Register allocator finished
  1823. Revision 1.117 2003/06/02 21:42:05 jonas
  1824. * function results can now also be regvars
  1825. - removed tprocinfo.return_offset, never use it again since it's invalid
  1826. if the result is a regvar
  1827. Revision 1.116 2003/06/01 21:38:06 peter
  1828. * getregisterfpu size parameter added
  1829. * op_const_reg size parameter added
  1830. * sparc updates
  1831. Revision 1.115 2003/05/31 20:28:17 jonas
  1832. * changed copyvalueparas so it also supports register parameters
  1833. (except for copy_value_openarray, but that one is seriously broken
  1834. anyway, since it expects that the high parameter will always be in
  1835. memory right after the pointer to the array, while it could just as
  1836. will be in a register)
  1837. Revision 1.114 2003/05/31 15:05:28 peter
  1838. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1839. Revision 1.113 2003/05/31 00:48:15 jonas
  1840. * fixed my previous commit
  1841. Revision 1.112 2003/05/30 23:57:08 peter
  1842. * more sparc cleanup
  1843. * accumulator removed, splitted in function_return_reg (called) and
  1844. function_result_reg (caller)
  1845. Revision 1.111 2003/05/30 23:49:18 jonas
  1846. * a_load_loc_reg now has an extra size parameter for the destination
  1847. register (properly fixes what I worked around in revision 1.106 of
  1848. ncgutil.pas)
  1849. Revision 1.110 2003/05/30 18:52:10 jonas
  1850. * fixed bug with intregvars
  1851. * locapara.loc can also be LOC_CFPUREGISTER -> also fixed
  1852. rcgppc.a_param_ref, which previously got bogus size values
  1853. Revision 1.109 2003/05/27 21:19:08 jonas
  1854. * fixed ppc cycle
  1855. Revision 1.108 2003/05/27 14:28:14 jonas
  1856. * patch from Peter for nested procedures
  1857. Revision 1.107 2003/05/26 21:17:17 peter
  1858. * procinlinenode removed
  1859. * aktexit2label removed, fast exit removed
  1860. + tcallnode.inlined_pass_2 added
  1861. Revision 1.106 2003/05/24 11:59:42 jonas
  1862. * fixed integer typeconversion problems
  1863. Revision 1.105 2003/05/23 14:27:35 peter
  1864. * remove some unit dependencies
  1865. * current_procinfo changes to store more info
  1866. Revision 1.104 2003/05/15 18:58:53 peter
  1867. * removed selfpointer_offset, vmtpointer_offset
  1868. * tvarsym.adjusted_address
  1869. * address in localsymtable is now in the real direction
  1870. * removed some obsolete globals
  1871. Revision 1.103 2003/05/14 19:37:25 jonas
  1872. * patch from Peter for int64 function results
  1873. Revision 1.102 2003/05/13 19:14:41 peter
  1874. * failn removed
  1875. * inherited result code check moven to pexpr
  1876. Revision 1.101 2003/05/13 15:16:13 peter
  1877. * removed ret_in_acc, it's the reverse of ret_in_param
  1878. * fixed ret_in_param for win32 cdecl array
  1879. Revision 1.100 2003/05/12 08:08:27 jonas
  1880. * fixed several initialization and finalization related bugs (missing
  1881. tg.direction's, wrong paralocation for decreasing refcount of
  1882. everything but ansistrings)
  1883. Revision 1.99 2003/05/11 21:37:03 peter
  1884. * moved implicit exception frame from ncgutil to psub
  1885. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1886. Revision 1.98 2003/05/11 14:45:12 peter
  1887. * tloadnode does not support objectsymtable,withsymtable anymore
  1888. * withnode cleanup
  1889. * direct with rewritten to use temprefnode
  1890. Revision 1.97 2003/05/10 13:20:23 jonas
  1891. * moved storing of register parameters to memory even earlier in the
  1892. entry code to fix problems with constructors
  1893. Revision 1.96 2003/05/09 17:47:02 peter
  1894. * self moved to hidden parameter
  1895. * removed hdisposen,hnewn,selfn
  1896. Revision 1.95 2003/04/29 07:28:52 michael
  1897. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1898. Revision 1.94 2003/04/28 21:17:38 peter
  1899. * do not finalize function results
  1900. Revision 1.93 2003/04/27 16:30:34 jonas
  1901. * store register para's to memory before copying the valuepara's, because
  1902. that one requires them to be there already (and it calls subroutines ->
  1903. could overwrite those registers)
  1904. Revision 1.92 2003/04/27 11:21:33 peter
  1905. * aktprocdef renamed to current_procdef
  1906. * procinfo renamed to current_procinfo
  1907. * procinfo will now be stored in current_module so it can be
  1908. cleaned up properly
  1909. * gen_main_procsym changed to create_main_proc and release_main_proc
  1910. to also generate a tprocinfo structure
  1911. * fixed unit implicit initfinal
  1912. Revision 1.91 2003/04/27 07:29:50 peter
  1913. * current_procdef cleanup, current_procdef is now always nil when parsing
  1914. a new procdef declaration
  1915. * aktprocsym removed
  1916. * lexlevel removed, use symtable.symtablelevel instead
  1917. * implicit init/final code uses the normal genentry/genexit
  1918. * funcret state checking updated for new funcret handling
  1919. Revision 1.90 2003/04/26 17:21:08 florian
  1920. * fixed passing of fpu values by fpu register
  1921. Revision 1.89 2003/04/25 20:59:33 peter
  1922. * removed funcretn,funcretsym, function result is now in varsym
  1923. and aliases for result and function name are added using absolutesym
  1924. * vs_hidden parameter for funcret passed in parameter
  1925. * vs_hidden fixes
  1926. * writenode changed to printnode and released from extdebug
  1927. * -vp option added to generate a tree.log with the nodetree
  1928. * nicer printnode for statements, callnode
  1929. Revision 1.88 2003/04/23 12:35:34 florian
  1930. * fixed several issues with powerpc
  1931. + applied a patch from Jonas for nested function calls (PowerPC only)
  1932. * ...
  1933. Revision 1.87 2003/04/22 14:33:38 peter
  1934. * removed some notes/hints
  1935. Revision 1.86 2003/04/22 13:47:08 peter
  1936. * fixed C style array of const
  1937. * fixed C array passing
  1938. * fixed left to right with high parameters
  1939. Revision 1.85 2003/04/22 10:09:35 daniel
  1940. + Implemented the actual register allocator
  1941. + Scratch registers unavailable when new register allocator used
  1942. + maybe_save/maybe_restore unavailable when new register allocator used
  1943. Revision 1.84 2003/04/16 09:26:55 jonas
  1944. * assembler procedures now again get a stackframe if they have local
  1945. variables. No space is reserved for a function result however.
  1946. Also, the register parameters aren't automatically saved on the stack
  1947. anymore in assembler procedures.
  1948. Revision 1.83 2003/04/06 21:11:23 olle
  1949. * changed newasmsymbol to newasmsymboldata for data symbols
  1950. Revision 1.82 2003/03/30 20:59:07 peter
  1951. * fix classmethod from classmethod call
  1952. * move BeforeDestruction/AfterConstruction calls to
  1953. genentrycode/genexitcode instead of generating them on the fly
  1954. after a call to a constructor
  1955. Revision 1.81 2003/03/28 19:16:56 peter
  1956. * generic constructor working for i386
  1957. * remove fixed self register
  1958. * esi added as address register for i386
  1959. Revision 1.80 2003/03/17 15:52:20 peter
  1960. * fix range error
  1961. Revision 1.79 2003/03/11 21:46:24 jonas
  1962. * lots of new regallocator fixes, both in generic and ppc-specific code
  1963. (ppc compiler still can't compile the linux system unit though)
  1964. Revision 1.78 2003/02/26 21:15:43 daniel
  1965. * Fixed the optimizer
  1966. Revision 1.77 2003/02/19 22:00:14 daniel
  1967. * Code generator converted to new register notation
  1968. - Horribily outdated todo.txt removed
  1969. Revision 1.76 2003/02/15 22:17:38 carl
  1970. * bugfix of FPU emulation code
  1971. Revision 1.75 2003/01/09 22:00:53 florian
  1972. * fixed some PowerPC issues
  1973. Revision 1.74 2003/01/09 20:41:10 florian
  1974. * fixed broken PowerPC compiler
  1975. Revision 1.73 2003/01/08 18:43:56 daniel
  1976. * Tregister changed into a record
  1977. Revision 1.72 2002/12/29 23:51:43 florian
  1978. * web bug 2214 fixed: ie 10 in const array constructors
  1979. Revision 1.71 2002/12/24 15:56:50 peter
  1980. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1981. this for the pageprotection
  1982. Revision 1.70 2002/12/05 14:39:21 florian
  1983. * added missing then, Carl did you really a make fullcycle :) ?
  1984. Revision 1.69 2002/12/03 22:13:39 carl
  1985. * bugfix of problems with profile code which clobbers some registers
  1986. Revision 1.68 2002/12/01 22:06:59 carl
  1987. * warning of portabilitiy problems with parasize / localsize
  1988. Revision 1.67 2002/11/30 18:44:57 carl
  1989. + profiling support for Win32
  1990. Revision 1.66 2002/11/30 14:39:15 carl
  1991. * try to fix profiling for win32
  1992. Revision 1.65 2002/11/28 23:28:14 florian
  1993. * push_value_para didn't release floatdef locations, fixes tw2045
  1994. Revision 1.64 2002/11/27 02:33:19 peter
  1995. * copy_value_on_stack method added for cdecl record passing
  1996. Revision 1.63 2002/11/25 17:43:18 peter
  1997. * splitted defbase in defutil,symutil,defcmp
  1998. * merged isconvertable and is_equal into compare_defs(_ext)
  1999. * made operator search faster by walking the list only once
  2000. Revision 1.62 2002/11/18 17:31:55 peter
  2001. * pass proccalloption to ret_in_xxx and push_xxx functions
  2002. Revision 1.61 2002/11/17 17:49:08 mazen
  2003. + 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
  2004. Revision 1.60 2002/11/17 16:31:56 carl
  2005. * memory optimization (3-4%) : cleanup of tai fields,
  2006. cleanup of tdef and tsym fields.
  2007. * make it work for m68k
  2008. Revision 1.59 2002/11/15 01:58:51 peter
  2009. * merged changes from 1.0.7 up to 04-11
  2010. - -V option for generating bug report tracing
  2011. - more tracing for option parsing
  2012. - errors for cdecl and high()
  2013. - win32 import stabs
  2014. - win32 records<=8 are returned in eax:edx (turned off by default)
  2015. - heaptrc update
  2016. - more info for temp management in .s file with EXTDEBUG
  2017. Revision 1.58 2002/11/10 19:07:45 mazen
  2018. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  2019. Revision 1.57 2002/11/03 20:22:40 mazen
  2020. * parameter handling updated
  2021. Revision 1.56 2002/10/16 19:01:43 peter
  2022. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  2023. implicit exception frames for procedures with initialized variables
  2024. and for constructors. The default is on for compatibility
  2025. Revision 1.55 2002/10/14 19:42:33 peter
  2026. * only use init tables for threadvars
  2027. Revision 1.54 2002/10/06 19:41:30 peter
  2028. * Add finalization of typed consts
  2029. * Finalization of globals in the main program
  2030. Revision 1.53 2002/10/05 15:18:42 carl
  2031. * fix heap leaks
  2032. Revision 1.52 2002/09/30 07:00:46 florian
  2033. * fixes to common code to get the alpha compiler compiled applied
  2034. Revision 1.51 2002/09/22 14:02:35 carl
  2035. * stack checking cannot be called before system unit is initialized
  2036. * MC68020 define
  2037. Revision 1.50 2002/09/17 18:54:03 jonas
  2038. * a_load_reg_reg() now has two size parameters: source and dest. This
  2039. allows some optimizations on architectures that don't encode the
  2040. register size in the register name.
  2041. Revision 1.49 2002/09/10 21:48:30 florian
  2042. * improved handling of procedures with register calling conventions
  2043. Revision 1.48 2002/09/07 15:25:03 peter
  2044. * old logs removed and tabs fixed
  2045. Revision 1.47 2002/09/02 18:44:48 peter
  2046. * fixed (not) pushing of empty parameters
  2047. * fixed implicit initialization/finalization generation
  2048. * fixed/optimized local copy of value arguments init/final
  2049. Revision 1.46 2002/09/01 19:27:34 peter
  2050. * use index register when available for generating a reference with
  2051. only a signle register. Using the base register could possibly
  2052. destroy the framepointer
  2053. Revision 1.45 2002/09/01 18:50:20 peter
  2054. * fixed maybe_save that did not support a reference with only
  2055. a index register. It now also updates the location with the new
  2056. base register only
  2057. Revision 1.44 2002/09/01 14:42:41 peter
  2058. * removevaluepara added to fix the stackpointer so restoring of
  2059. saved registers works
  2060. Revision 1.43 2002/08/25 19:25:18 peter
  2061. * sym.insert_in_data removed
  2062. * symtable.insertvardata/insertconstdata added
  2063. * removed insert_in_data call from symtable.insert, it needs to be
  2064. called separatly. This allows to deref the address calculation
  2065. * procedures now calculate the parast addresses after the procedure
  2066. directives are parsed. This fixes the cdecl parast problem
  2067. * push_addr_param has an extra argument that specifies if cdecl is used
  2068. or not
  2069. Revision 1.42 2002/08/24 18:38:26 peter
  2070. * really use tt_noreuse for exception frame buffers
  2071. Revision 1.41 2002/08/23 16:14:49 peter
  2072. * tempgen cleanup
  2073. * tt_noreuse temp type added that will be used in genentrycode
  2074. Revision 1.40 2002/08/18 10:42:37 florian
  2075. * remaining assembler writer bugs fixed, the errors in the
  2076. system unit are inline assembler problems
  2077. Revision 1.39 2002/08/17 09:23:36 florian
  2078. * first part of procinfo rewrite
  2079. Revision 1.38 2002/08/16 14:24:57 carl
  2080. * issameref() to test if two references are the same (then emit no opcodes)
  2081. + ret_in_reg to replace ret_in_acc
  2082. (fix some register allocation bugs at the same time)
  2083. + save_std_register now has an extra parameter which is the
  2084. usedinproc registers
  2085. Revision 1.37 2002/08/15 15:15:55 carl
  2086. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  2087. * more generic nodes for maths
  2088. * several fixes for better m68k support
  2089. Revision 1.36 2002/08/14 19:25:09 carl
  2090. * fix Florian's last commit for m68k compilation
  2091. Revision 1.35 2002/08/13 21:40:56 florian
  2092. * more fixes for ppc calling conventions
  2093. Revision 1.34 2002/08/12 15:08:39 carl
  2094. + stab register indexes for powerpc (moved from gdb to cpubase)
  2095. + tprocessor enumeration moved to cpuinfo
  2096. + linker in target_info is now a class
  2097. * many many updates for m68k (will soon start to compile)
  2098. - removed some ifdef or correct them for correct cpu
  2099. Revision 1.33 2002/08/11 14:32:27 peter
  2100. * renamed current_library to objectlibrary
  2101. Revision 1.32 2002/08/11 13:24:12 peter
  2102. * saving of asmsymbols in ppu supported
  2103. * asmsymbollist global is removed and moved into a new class
  2104. tasmlibrarydata that will hold the info of a .a file which
  2105. corresponds with a single module. Added librarydata to tmodule
  2106. to keep the library info stored for the module. In the future the
  2107. objectfiles will also be stored to the tasmlibrarydata class
  2108. * all getlabel/newasmsymbol and friends are moved to the new class
  2109. Revision 1.31 2002/08/09 19:16:57 carl
  2110. * stack allocation is now done separately (at the end) of genentrycode
  2111. so temps. can be allocated before.
  2112. * fix generic exception handling
  2113. Revision 1.30 2002/08/06 20:55:21 florian
  2114. * first part of ppc calling conventions fix
  2115. Revision 1.29 2002/08/04 19:09:22 carl
  2116. + added generic exception support (still does not work!)
  2117. + more documentation
  2118. Revision 1.28 2002/07/29 21:23:42 florian
  2119. * more fixes for the ppc
  2120. + wrappers for the tcnvnode.first_* stuff introduced
  2121. }