ncgutil.pas 91 KB

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