ncgutil.pas 89 KB

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