ncgutil.pas 92 KB

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