ncgutil.pas 93 KB

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