ncgutil.pas 90 KB

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