ncgutil.pas 94 KB

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