ncgutil.pas 92 KB

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