ncgutil.pas 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867
  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,cgbase,
  25. aasmbase,aasmtai,aasmcpu,
  26. symconst,symbase,symdef,symsym,symtype,symtable
  27. {$ifndef cpu64bit}
  28. ,cg64f32
  29. {$endif cpu64bit}
  30. ;
  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. procedure location_force_mmregscalar(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  40. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  41. procedure gen_proc_symbol(list:Taasmoutput);
  42. procedure gen_proc_symbol_end(list:Taasmoutput);
  43. procedure gen_stackalloc_code(list:Taasmoutput);
  44. procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
  45. procedure gen_save_used_regs(list:TAAsmoutput);
  46. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tparalocation);
  47. procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean);
  48. procedure gen_finalize_code(list:TAAsmoutput;inlined:boolean);
  49. procedure gen_entry_code(list:TAAsmoutput);
  50. procedure gen_exit_code(list:TAAsmoutput);
  51. procedure gen_load_para_value(list:TAAsmoutput);
  52. procedure gen_load_return_value(list:TAAsmoutput; var uses_acc,uses_acchi,uses_fpu : boolean);
  53. (*
  54. procedure geninlineentrycode(list:TAAsmoutput;stackframe:longint);
  55. procedure geninlineexitcode(list:TAAsmoutput;inlined:boolean);
  56. *)
  57. {#
  58. Allocate the buffers for exception management and setjmp environment.
  59. Return a pointer to these buffers, send them to the utility routine
  60. so they are registered, and then call setjmp.
  61. Then compare the result of setjmp with 0, and if not equal
  62. to zero, then jump to exceptlabel.
  63. Also store the result of setjmp to a temporary space by calling g_save_exception_reason
  64. It is to note that this routine may be called *after* the stackframe of a
  65. routine has been called, therefore on machines where the stack cannot
  66. be modified, all temps should be allocated on the heap instead of the
  67. stack.
  68. }
  69. const
  70. EXCEPT_BUF_SIZE = 12;
  71. type
  72. texceptiontemps=record
  73. jmpbuf,
  74. envbuf,
  75. reasonbuf : treference;
  76. end;
  77. procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
  78. procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
  79. procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;exceptlabel:tasmlabel);
  80. procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;endexceptlabel:tasmlabel;onlyfree:boolean);
  81. procedure insertconstdata(sym : ttypedconstsym);
  82. procedure insertbssdata(sym : tvarsym);
  83. procedure gen_alloc_localst(list:TAAsmoutput;st:tlocalsymtable);
  84. procedure gen_free_localst(list:TAAsmoutput;st:tlocalsymtable);
  85. procedure gen_alloc_parast(list:TAAsmoutput;st:tparasymtable);
  86. procedure gen_alloc_inline_parast(list:TAAsmoutput;st:tparasymtable);
  87. procedure gen_free_parast(list:TAAsmoutput;st:tparasymtable);
  88. { rtti and init/final }
  89. procedure generate_rtti(p:Ttypesym);
  90. procedure generate_inittable(p:tsym);
  91. implementation
  92. uses
  93. {$ifdef Delphi}
  94. Sysutils,
  95. {$else}
  96. strings,
  97. {$endif}
  98. cutils,cclasses,
  99. globals,systems,verbose,
  100. ppu,defutil,
  101. procinfo,paramgr,fmodule,
  102. regvars,
  103. {$ifdef GDB}
  104. gdb,
  105. {$endif GDB}
  106. pass_1,pass_2,
  107. ncon,nld,nutils,
  108. tgobj,cgutils,cgobj;
  109. {*****************************************************************************
  110. Misc Helpers
  111. *****************************************************************************}
  112. { DO NOT RELY on the fact that the tnode is not yet swaped
  113. because of inlining code PM }
  114. procedure firstcomplex(p : tbinarynode);
  115. var
  116. hp : tnode;
  117. begin
  118. { always calculate boolean AND and OR from left to right }
  119. if (p.nodetype in [orn,andn]) and
  120. is_boolean(p.left.resulttype.def) then
  121. begin
  122. if nf_swaped in p.flags then
  123. internalerror(234234);
  124. end
  125. else
  126. if (
  127. (p.location.loc=LOC_FPUREGISTER) and
  128. (p.right.registersfpu > p.left.registersfpu)
  129. ) or
  130. (
  131. (
  132. (
  133. ((p.left.registersfpu = 0) and (p.right.registersfpu = 0)) or
  134. (p.location.loc<>LOC_FPUREGISTER)
  135. ) and
  136. (p.left.registersint<p.right.registersint)
  137. )
  138. ) then
  139. begin
  140. hp:=p.left;
  141. p.left:=p.right;
  142. p.right:=hp;
  143. if nf_swaped in p.flags then
  144. exclude(p.flags,nf_swaped)
  145. else
  146. include(p.flags,nf_swaped);
  147. end;
  148. end;
  149. procedure maketojumpbool(list:TAAsmoutput; p : tnode; loadregvars: tloadregvars);
  150. {
  151. produces jumps to true respectively false labels using boolean expressions
  152. depending on whether the loading of regvars is currently being
  153. synchronized manually (such as in an if-node) or automatically (most of
  154. the other cases where this procedure is called), loadregvars can be
  155. "lr_load_regvars" or "lr_dont_load_regvars"
  156. }
  157. var
  158. opsize : tcgsize;
  159. storepos : tfileposinfo;
  160. begin
  161. if nf_error in p.flags then
  162. exit;
  163. storepos:=aktfilepos;
  164. aktfilepos:=p.fileinfo;
  165. if is_boolean(p.resulttype.def) then
  166. begin
  167. {$ifdef OLDREGVARS}
  168. if loadregvars = lr_load_regvars then
  169. load_all_regvars(list);
  170. {$endif OLDREGVARS}
  171. if is_constboolnode(p) then
  172. begin
  173. if tordconstnode(p).value<>0 then
  174. cg.a_jmp_always(list,truelabel)
  175. else
  176. cg.a_jmp_always(list,falselabel)
  177. end
  178. else
  179. begin
  180. opsize:=def_cgsize(p.resulttype.def);
  181. case p.location.loc of
  182. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  183. begin
  184. {$ifdef OLDREGVARS}
  185. if (p.location.loc = LOC_CREGISTER) then
  186. load_regvar_reg(list,p.location.register);
  187. {$endif OLDREGVARS}
  188. cg.a_cmp_const_loc_label(list,opsize,OC_NE,
  189. 0,p.location,truelabel);
  190. { !!! should happen right after cmp (JM) }
  191. location_release(list,p.location);
  192. cg.a_jmp_always(list,falselabel);
  193. end;
  194. LOC_JUMP:
  195. ;
  196. {$ifdef cpuflags}
  197. LOC_FLAGS :
  198. begin
  199. cg.a_jmp_flags(list,p.location.resflags,
  200. truelabel);
  201. cg.a_jmp_always(list,falselabel);
  202. end;
  203. {$endif cpuflags}
  204. else
  205. begin
  206. printnode(output,p);
  207. internalerror(200308241);
  208. end;
  209. end;
  210. end;
  211. end
  212. else
  213. internalerror(200112305);
  214. aktfilepos:=storepos;
  215. end;
  216. (*
  217. This code needs fixing. It is not safe to use rgint; on the m68000 it
  218. would be rgaddr.
  219. procedure remove_non_regvars_from_loc(const t: tlocation; var regs:Tsuperregisterset);
  220. begin
  221. case t.loc of
  222. LOC_REGISTER:
  223. begin
  224. { can't be a regvar, since it would be LOC_CREGISTER then }
  225. exclude(regs,getsupreg(t.register));
  226. if t.registerhigh<>NR_NO then
  227. exclude(regs,getsupreg(t.registerhigh));
  228. end;
  229. LOC_CREFERENCE,LOC_REFERENCE:
  230. begin
  231. if not(cs_regvars in aktglobalswitches) or
  232. (getsupreg(t.reference.base) in cg.rgint.usableregs) then
  233. exclude(regs,getsupreg(t.reference.base));
  234. if not(cs_regvars in aktglobalswitches) or
  235. (getsupreg(t.reference.index) in cg.rgint.usableregs) then
  236. exclude(regs,getsupreg(t.reference.index));
  237. end;
  238. end;
  239. end;
  240. *)
  241. {*****************************************************************************
  242. EXCEPTION MANAGEMENT
  243. *****************************************************************************}
  244. procedure get_exception_temps(list:taasmoutput;var t:texceptiontemps);
  245. begin
  246. tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,t.envbuf);
  247. tg.GetTemp(list,JMP_BUF_SIZE,tt_persistent,t.jmpbuf);
  248. tg.GetTemp(list,sizeof(aword),tt_persistent,t.reasonbuf);
  249. end;
  250. procedure unget_exception_temps(list:taasmoutput;const t:texceptiontemps);
  251. begin
  252. tg.Ungettemp(list,t.jmpbuf);
  253. tg.ungettemp(list,t.envbuf);
  254. tg.ungettemp(list,t.reasonbuf);
  255. end;
  256. procedure new_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;exceptlabel:tasmlabel);
  257. var
  258. paraloc1,paraloc2,paraloc3 : tparalocation;
  259. begin
  260. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  261. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  262. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  263. paramanager.allocparaloc(list,paraloc3);
  264. cg.a_paramaddr_ref(list,t.envbuf,paraloc3);
  265. paramanager.allocparaloc(list,paraloc2);
  266. cg.a_paramaddr_ref(list,t.jmpbuf,paraloc2);
  267. { push type of exceptionframe }
  268. paramanager.allocparaloc(list,paraloc1);
  269. cg.a_param_const(list,OS_S32,1,paraloc1);
  270. paramanager.freeparaloc(list,paraloc3);
  271. paramanager.freeparaloc(list,paraloc2);
  272. paramanager.freeparaloc(list,paraloc1);
  273. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  274. cg.a_call_name(list,'FPC_PUSHEXCEPTADDR');
  275. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  276. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  277. paramanager.allocparaloc(list,paraloc1);
  278. cg.a_param_reg(list,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  279. paramanager.freeparaloc(list,paraloc1);
  280. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  281. cg.a_call_name(list,'FPC_SETJMP');
  282. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  283. cg.g_exception_reason_save(list, t.reasonbuf);
  284. cg.a_cmp_const_reg_label(list,OS_S32,OC_NE,0,cg.makeregsize(list,NR_FUNCTION_RESULT_REG,OS_S32),exceptlabel);
  285. end;
  286. procedure free_exception(list:TAAsmoutput;const t:texceptiontemps;a:aword;endexceptlabel:tasmlabel;onlyfree:boolean);
  287. begin
  288. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  289. cg.a_call_name(list,'FPC_POPADDRSTACK');
  290. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  291. if not onlyfree then
  292. begin
  293. cg.g_exception_reason_load(list, t.reasonbuf);
  294. cg.a_cmp_const_reg_label(list,OS_INT,OC_EQ,a,NR_FUNCTION_RESULT_REG,endexceptlabel);
  295. end;
  296. end;
  297. {*****************************************************************************
  298. TLocation
  299. *****************************************************************************}
  300. {$ifndef cpu64bit}
  301. { 32-bit version }
  302. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  303. var
  304. hregister,
  305. hregisterhi : tregister;
  306. hreg64 : tregister64;
  307. hl : tasmlabel;
  308. oldloc : tlocation;
  309. begin
  310. oldloc:=l;
  311. if dst_size=OS_NO then
  312. internalerror(200309144);
  313. { handle transformations to 64bit separate }
  314. if dst_size in [OS_64,OS_S64] then
  315. begin
  316. if not (l.size in [OS_64,OS_S64]) then
  317. begin
  318. { load a smaller size to OS_64 }
  319. if l.loc=LOC_REGISTER then
  320. begin
  321. hregister:=cg.makeregsize(list,l.registerlow,OS_32);
  322. cg.a_load_reg_reg(list,l.size,OS_32,l.registerlow,hregister);
  323. end
  324. else
  325. begin
  326. location_release(list,l);
  327. hregister:=cg.getintregister(list,OS_INT);
  328. end;
  329. { load value in low register }
  330. case l.loc of
  331. LOC_FLAGS :
  332. cg.g_flags2reg(list,OS_INT,l.resflags,hregister);
  333. LOC_JUMP :
  334. begin
  335. cg.a_label(list,truelabel);
  336. cg.a_load_const_reg(list,OS_INT,1,hregister);
  337. objectlibrary.getlabel(hl);
  338. cg.a_jmp_always(list,hl);
  339. cg.a_label(list,falselabel);
  340. cg.a_load_const_reg(list,OS_INT,0,hregister);
  341. cg.a_label(list,hl);
  342. end;
  343. else
  344. cg.a_load_loc_reg(list,OS_INT,l,hregister);
  345. end;
  346. { reset hi part, take care of the signed bit of the current value }
  347. hregisterhi:=cg.getintregister(list,OS_INT);
  348. if (dst_size=OS_S64) and
  349. (l.size in [OS_S8,OS_S16,OS_S32]) then
  350. begin
  351. if l.loc=LOC_CONSTANT then
  352. begin
  353. if (longint(l.value)<0) then
  354. cg.a_load_const_reg(list,OS_32,$ffffffff,hregisterhi)
  355. else
  356. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  357. end
  358. else
  359. begin
  360. cg.a_op_const_reg_reg(list,OP_SAR,OS_32,31,hregister,
  361. hregisterhi);
  362. end;
  363. end
  364. else
  365. cg.a_load_const_reg(list,OS_32,0,hregisterhi);
  366. location_reset(l,LOC_REGISTER,dst_size);
  367. l.registerlow:=hregister;
  368. l.registerhigh:=hregisterhi;
  369. end
  370. else
  371. begin
  372. { 64bit to 64bit }
  373. if (l.loc=LOC_REGISTER) or
  374. ((l.loc=LOC_CREGISTER) and maybeconst) then
  375. begin
  376. hregister:=l.registerlow;
  377. hregisterhi:=l.registerhigh;
  378. end
  379. else
  380. begin
  381. hregister:=cg.getintregister(list,OS_INT);
  382. hregisterhi:=cg.getintregister(list,OS_INT);
  383. location_release(list,l);
  384. end;
  385. hreg64.reglo:=hregister;
  386. hreg64.reghi:=hregisterhi;
  387. { load value in new register }
  388. cg64.a_load64_loc_reg(list,l,hreg64);
  389. location_reset(l,LOC_REGISTER,dst_size);
  390. l.registerlow:=hregister;
  391. l.registerhigh:=hregisterhi;
  392. end;
  393. end
  394. else
  395. begin
  396. {Do not bother to recycle the existing register. The register
  397. allocator eliminates unnecessary moves, so it's not needed
  398. and trying to recycle registers can cause problems because
  399. the registers changes size and may need aditional constraints.}
  400. location_release(list,l);
  401. hregister:=cg.getintregister(list,dst_size);
  402. { load value in new register }
  403. case l.loc of
  404. LOC_FLAGS :
  405. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  406. LOC_JUMP :
  407. begin
  408. cg.a_label(list,truelabel);
  409. cg.a_load_const_reg(list,dst_size,1,hregister);
  410. objectlibrary.getlabel(hl);
  411. cg.a_jmp_always(list,hl);
  412. cg.a_label(list,falselabel);
  413. cg.a_load_const_reg(list,dst_size,0,hregister);
  414. cg.a_label(list,hl);
  415. end;
  416. else
  417. begin
  418. { load_loc_reg can only handle size >= l.size, when the
  419. new size is smaller then we need to adjust the size
  420. of the orignal and maybe recalculate l.register for i386 }
  421. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  422. begin
  423. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  424. l.register:=cg.makeregsize(list,l.register,dst_size);
  425. { for big endian systems, the reference's offset must }
  426. { be increased in this case, since they have the }
  427. { MSB first in memory and e.g. byte(word_var) should }
  428. { return the second byte in this case (JM) }
  429. if (target_info.endian = ENDIAN_BIG) and
  430. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  431. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  432. {$ifdef x86}
  433. l.size:=dst_size;
  434. {$endif x86}
  435. end;
  436. cg.a_load_loc_reg(list,dst_size,l,hregister);
  437. {$ifndef x86}
  438. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  439. l.size:=dst_size;
  440. {$endif not x86}
  441. end;
  442. end;
  443. if (l.loc <> LOC_CREGISTER) or
  444. not maybeconst then
  445. location_reset(l,LOC_REGISTER,dst_size)
  446. else
  447. location_reset(l,LOC_CREGISTER,dst_size);
  448. l.register:=hregister;
  449. end;
  450. { Release temp when it was a reference }
  451. if oldloc.loc=LOC_REFERENCE then
  452. location_freetemp(list,oldloc);
  453. end;
  454. {$else cpu64bit}
  455. { 64-bit version }
  456. procedure location_force_reg(list:TAAsmoutput;var l:tlocation;dst_size:TCGSize;maybeconst:boolean);
  457. var
  458. hregister : tregister;
  459. hl : tasmlabel;
  460. oldloc : tlocation;
  461. begin
  462. {Do not bother to recycle the existing register. The register
  463. allocator eliminates unnecessary moves, so it's not needed
  464. and trying to recycle registers can cause problems because
  465. the registers changes size and may need aditional constraints.}
  466. location_release(list,l);
  467. hregister:=cg.getintregister(list,dst_size);
  468. { load value in new register }
  469. case l.loc of
  470. LOC_FLAGS :
  471. cg.g_flags2reg(list,dst_size,l.resflags,hregister);
  472. LOC_JUMP :
  473. begin
  474. cg.a_label(list,truelabel);
  475. cg.a_load_const_reg(list,dst_size,1,hregister);
  476. objectlibrary.getlabel(hl);
  477. cg.a_jmp_always(list,hl);
  478. cg.a_label(list,falselabel);
  479. cg.a_load_const_reg(list,dst_size,0,hregister);
  480. cg.a_label(list,hl);
  481. end;
  482. else
  483. begin
  484. { load_loc_reg can only handle size >= l.size, when the
  485. new size is smaller then we need to adjust the size
  486. of the orignal and maybe recalculate l.register for i386 }
  487. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  488. begin
  489. if (l.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  490. l.register:=cg.makeregsize(list,l.register,dst_size);
  491. { for big endian systems, the reference's offset must }
  492. { be increased in this case, since they have the }
  493. { MSB first in memory and e.g. byte(word_var) should }
  494. { return the second byte in this case (JM) }
  495. if (target_info.endian = ENDIAN_BIG) and
  496. (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  497. inc(l.reference.offset,TCGSize2Size[l.size]-TCGSize2Size[dst_size]);
  498. {$ifdef x86}
  499. l.size:=dst_size;
  500. {$endif x86}
  501. end;
  502. cg.a_load_loc_reg(list,dst_size,l,hregister);
  503. {$ifndef x86}
  504. if (TCGSize2Size[dst_size]<TCGSize2Size[l.size]) then
  505. l.size:=dst_size;
  506. {$endif not x86}
  507. end;
  508. end;
  509. if (l.loc <> LOC_CREGISTER) or
  510. not maybeconst then
  511. location_reset(l,LOC_REGISTER,dst_size)
  512. else
  513. location_reset(l,LOC_CREGISTER,dst_size);
  514. l.register:=hregister;
  515. { Release temp when it was a reference }
  516. if oldloc.loc=LOC_REFERENCE then
  517. location_freetemp(list,oldloc);
  518. end;
  519. {$endif cpu64bit}
  520. procedure location_force_fpureg(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  521. var
  522. reg : tregister;
  523. href : treference;
  524. begin
  525. if (l.loc<>LOC_FPUREGISTER) and
  526. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  527. begin
  528. { if it's in an mm register, store to memory first }
  529. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  530. begin
  531. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  532. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
  533. location_release(list,l);
  534. location_reset(l,LOC_REFERENCE,l.size);
  535. l.reference:=href;
  536. end;
  537. reg:=cg.getfpuregister(list,l.size);
  538. cg.a_loadfpu_loc_reg(list,l,reg);
  539. location_freetemp(list,l);
  540. location_release(list,l);
  541. location_reset(l,LOC_FPUREGISTER,l.size);
  542. l.register:=reg;
  543. end;
  544. end;
  545. procedure location_force_mmregscalar(list:TAAsmoutput;var l: tlocation;maybeconst:boolean);
  546. var
  547. reg : tregister;
  548. href : treference;
  549. begin
  550. if (l.loc<>LOC_MMREGISTER) and
  551. ((l.loc<>LOC_CMMREGISTER) or (not maybeconst)) then
  552. begin
  553. { if it's in an fpu register, store to memory first }
  554. if (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  555. begin
  556. tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
  557. cg.a_loadfpu_reg_ref(list,l.size,l.register,href);
  558. location_release(list,l);
  559. location_reset(l,LOC_REFERENCE,l.size);
  560. l.reference:=href;
  561. end;
  562. reg:=cg.getmmregister(list,l.size);
  563. cg.a_loadmm_loc_reg(list,l.size,l,reg,mms_movescalar);
  564. location_freetemp(list,l);
  565. location_release(list,l);
  566. location_reset(l,LOC_MMREGISTER,l.size);
  567. l.register:=reg;
  568. end;
  569. end;
  570. procedure location_force_mem(list:TAAsmoutput;var l:tlocation);
  571. var
  572. r : treference;
  573. begin
  574. case l.loc of
  575. LOC_FPUREGISTER,
  576. LOC_CFPUREGISTER :
  577. begin
  578. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  579. cg.a_loadfpu_reg_ref(list,l.size,l.register,r);
  580. location_release(list,l);
  581. location_reset(l,LOC_REFERENCE,l.size);
  582. l.reference:=r;
  583. end;
  584. LOC_MMREGISTER,
  585. LOC_CMMREGISTER:
  586. begin
  587. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  588. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  589. location_release(list,l);
  590. location_reset(l,LOC_REFERENCE,l.size);
  591. l.reference:=r;
  592. end;
  593. LOC_CONSTANT,
  594. LOC_REGISTER,
  595. LOC_CREGISTER :
  596. begin
  597. tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
  598. if l.size in [OS_64,OS_S64] then
  599. begin
  600. cg64.a_load64_loc_ref(list,l,r);
  601. location_release(list,l);
  602. end
  603. else
  604. begin
  605. location_release(list,l);
  606. cg.a_load_loc_ref(list,l.size,l,r);
  607. end;
  608. location_reset(l,LOC_REFERENCE,l.size);
  609. l.reference:=r;
  610. end;
  611. LOC_CREFERENCE,
  612. LOC_REFERENCE : ;
  613. else
  614. internalerror(200203219);
  615. end;
  616. end;
  617. {*****************************************************************************
  618. Maybe_Save
  619. *****************************************************************************}
  620. function maybe_pushfpu(list:taasmoutput;needed : byte;var l:tlocation) : boolean;
  621. begin
  622. {$ifdef i386}
  623. if (needed>=maxfpuregs) and
  624. (l.loc = LOC_FPUREGISTER) then
  625. begin
  626. location_force_mem(list,l);
  627. maybe_pushfpu:=true;
  628. end
  629. else
  630. maybe_pushfpu:=false;
  631. {$endif i386}
  632. end;
  633. {****************************************************************************
  634. Init/Finalize Code
  635. ****************************************************************************}
  636. procedure copyvalueparas(p : tnamedindexitem;arg:pointer);
  637. var
  638. href1,href2 : treference;
  639. list:TAAsmoutput;
  640. hsym : tvarsym;
  641. l : longint;
  642. loadref : boolean;
  643. localcopyloc : tparalocation;
  644. begin
  645. list:=taasmoutput(arg);
  646. if (tsym(p).typ=varsym) and
  647. (tvarsym(p).varspez=vs_value) and
  648. (paramanager.push_addr_param(tvarsym(p).varspez,tvarsym(p).vartype.def,current_procinfo.procdef.proccalloption)) then
  649. begin
  650. loadref:=true;
  651. case tvarsym(p).localloc.loc of
  652. LOC_REGISTER :
  653. begin
  654. reference_reset_base(href1,tvarsym(p).localloc.register,0);
  655. loadref:=false;
  656. end;
  657. LOC_REFERENCE :
  658. reference_reset_base(href1,tvarsym(p).localloc.reference.index,
  659. tvarsym(p).localloc.reference.offset);
  660. else
  661. internalerror(200309181);
  662. end;
  663. if is_open_array(tvarsym(p).vartype.def) or
  664. is_array_of_const(tvarsym(p).vartype.def) then
  665. begin
  666. { cdecl functions don't have a high pointer so it is not possible to generate
  667. a local copy }
  668. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  669. begin
  670. hsym:=tvarsym(tsym(p).owner.search('high'+p.name));
  671. if not assigned(hsym) then
  672. internalerror(200306061);
  673. case hsym.localloc.loc of
  674. LOC_REFERENCE :
  675. begin
  676. { this code is only executed before the code for the body and the entry/exit code is generated
  677. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  678. }
  679. include(current_procinfo.flags,pi_do_call);
  680. reference_reset_base(href2,hsym.localloc.reference.index,hsym.localloc.reference.offset);
  681. cg.g_copyvaluepara_openarray(list,href1,href2,tarraydef(tvarsym(p).vartype.def).elesize)
  682. end
  683. else
  684. internalerror(200309182);
  685. end;
  686. end;
  687. end
  688. else
  689. begin
  690. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  691. internalerror(200309183);
  692. { Allocate space for the local copy }
  693. l:=tvarsym(p).getvaluesize;
  694. localcopyloc.loc:=LOC_REFERENCE;
  695. localcopyloc.size:=int_cgsize(l);
  696. tg.GetLocal(list,l,tvarsym(p).vartype.def,localcopyloc.reference);
  697. { Copy data }
  698. reference_reset_base(href2,localcopyloc.reference.index,localcopyloc.reference.offset);
  699. if is_shortstring(tvarsym(p).vartype.def) then
  700. begin
  701. { this code is only executed before the code for the body and the entry/exit code is generated
  702. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  703. }
  704. include(current_procinfo.flags,pi_do_call);
  705. cg.g_copyshortstring(list,href1,href2,tstringdef(tvarsym(p).vartype.def).len,false,loadref)
  706. end
  707. else
  708. cg.g_concatcopy(list,href1,href2,tvarsym(p).vartype.def.size,true,loadref);
  709. { update localloc of varsym }
  710. tg.Ungetlocal(list,tvarsym(p).localloc.reference);
  711. tvarsym(p).localloc:=localcopyloc;
  712. end;
  713. end;
  714. end;
  715. { generates the code for initialisation of local data }
  716. procedure initialize_data(p : tnamedindexitem;arg:pointer);
  717. var
  718. oldexprasmlist : TAAsmoutput;
  719. hp : tnode;
  720. begin
  721. if (tsym(p).typ=varsym) and
  722. (tvarsym(p).refs>0) and
  723. not(is_class(tvarsym(p).vartype.def)) and
  724. tvarsym(p).vartype.def.needs_inittable then
  725. begin
  726. oldexprasmlist:=exprasmlist;
  727. exprasmlist:=taasmoutput(arg);
  728. hp:=initialize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  729. firstpass(hp);
  730. secondpass(hp);
  731. hp.free;
  732. exprasmlist:=oldexprasmlist;
  733. end;
  734. end;
  735. { generates the code for finalisation of local data }
  736. procedure finalize_data(p : tnamedindexitem;arg:pointer);
  737. var
  738. oldexprasmlist : TAAsmoutput;
  739. hp : tnode;
  740. dofinalize : boolean;
  741. begin
  742. dofinalize:=false;
  743. case tsym(p).typ of
  744. varsym :
  745. begin
  746. if (tvarsym(p).refs>0) and
  747. not(vo_is_funcret in tvarsym(p).varoptions) and
  748. not(is_class(tvarsym(p).vartype.def)) and
  749. tvarsym(p).vartype.def.needs_inittable then
  750. dofinalize:=true;
  751. end;
  752. typedconstsym :
  753. begin
  754. if ttypedconstsym(p).is_writable and
  755. ttypedconstsym(p).typedconsttype.def.needs_inittable then
  756. dofinalize:=true;
  757. end;
  758. end;
  759. if dofinalize then
  760. begin
  761. include(current_procinfo.flags,pi_needs_implicit_finally);
  762. oldexprasmlist:=exprasmlist;
  763. exprasmlist:=taasmoutput(arg);
  764. hp:=finalize_data_node(cloadnode.create(tsym(p),tsym(p).owner));
  765. firstpass(hp);
  766. secondpass(hp);
  767. hp.free;
  768. exprasmlist:=oldexprasmlist;
  769. end;
  770. end;
  771. { generates the code for incrementing the reference count of parameters and
  772. initialize out parameters }
  773. procedure init_paras(p : tnamedindexitem;arg:pointer);
  774. var
  775. href : treference;
  776. tmpreg : tregister;
  777. list:TAAsmoutput;
  778. begin
  779. list:=taasmoutput(arg);
  780. if (tsym(p).typ=varsym) and
  781. not is_class(tvarsym(p).vartype.def) and
  782. tvarsym(p).vartype.def.needs_inittable then
  783. begin
  784. case tvarsym(p).varspez of
  785. vs_value :
  786. begin
  787. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  788. internalerror(200309187);
  789. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  790. cg.g_incrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  791. end;
  792. vs_out :
  793. begin
  794. case tvarsym(p).localloc.loc of
  795. LOC_REFERENCE :
  796. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  797. else
  798. internalerror(2003091810);
  799. end;
  800. tmpreg:=cg.getaddressregister(list);
  801. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,tmpreg);
  802. reference_reset_base(href,tmpreg,0);
  803. cg.g_initialize(list,tvarsym(p).vartype.def,href,false);
  804. cg.ungetregister(list,tmpreg);
  805. end;
  806. end;
  807. end;
  808. end;
  809. { generates the code for decrementing the reference count of parameters }
  810. procedure final_paras(p : tnamedindexitem;arg:pointer);
  811. var
  812. href : treference;
  813. list:TAAsmoutput;
  814. begin
  815. list:=taasmoutput(arg);
  816. if (tsym(p).typ=varsym) and
  817. not is_class(tvarsym(p).vartype.def) and
  818. tvarsym(p).vartype.def.needs_inittable then
  819. begin
  820. if (tvarsym(p).varspez=vs_value) then
  821. begin
  822. include(current_procinfo.flags,pi_needs_implicit_finally);
  823. if tvarsym(p).localloc.loc<>LOC_REFERENCE then
  824. internalerror(200309188);
  825. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  826. cg.g_decrrefcount(list,tvarsym(p).vartype.def,href,is_open_array(tvarsym(p).vartype.def));
  827. end;
  828. end
  829. else if (tsym(p).typ=varsym) and
  830. (tvarsym(p).varspez=vs_value) and
  831. (is_open_array(tvarsym(p).vartype.def) or
  832. is_array_of_const(tvarsym(p).vartype.def)) then
  833. begin
  834. { cdecl functions don't have a high pointer so it is not possible to generate
  835. a local copy }
  836. if not(current_procinfo.procdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  837. begin
  838. reference_reset_base(href,tvarsym(p).localloc.reference.index,tvarsym(p).localloc.reference.offset);
  839. cg.g_releasevaluepara_openarray(list,href);
  840. end;
  841. end;
  842. end;
  843. { Initialize temp ansi/widestrings,interfaces }
  844. procedure inittempvariables(list:taasmoutput);
  845. var
  846. hp : ptemprecord;
  847. href : treference;
  848. begin
  849. hp:=tg.templist;
  850. while assigned(hp) do
  851. begin
  852. if assigned(hp^.def) and
  853. hp^.def.needs_inittable then
  854. begin
  855. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  856. cg.g_initialize(list,hp^.def,href,false);
  857. end;
  858. hp:=hp^.next;
  859. end;
  860. end;
  861. procedure finalizetempvariables(list:taasmoutput);
  862. var
  863. hp : ptemprecord;
  864. href : treference;
  865. paraloc1 : tparalocation;
  866. begin
  867. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  868. hp:=tg.templist;
  869. while assigned(hp) do
  870. begin
  871. if assigned(hp^.def) and
  872. hp^.def.needs_inittable then
  873. begin
  874. include(current_procinfo.flags,pi_needs_implicit_finally);
  875. reference_reset_base(href,current_procinfo.framepointer,hp^.pos);
  876. cg.g_finalize(list,hp^.def,href,false);
  877. end;
  878. hp:=hp^.next;
  879. end;
  880. end;
  881. procedure gen_load_return_value(list:TAAsmoutput; var uses_acc,uses_acchi,uses_fpu : boolean);
  882. var
  883. ressym : tvarsym;
  884. resloc : tlocation;
  885. href : treference;
  886. hreg : tregister;
  887. begin
  888. { Is the loading needed? }
  889. if is_void(current_procinfo.procdef.rettype.def) or
  890. (
  891. (po_assembler in current_procinfo.procdef.procoptions) and
  892. (not(assigned(current_procinfo.procdef.funcretsym)) or
  893. (tvarsym(current_procinfo.procdef.funcretsym).refs=0))
  894. ) then
  895. exit;
  896. { Constructors need to return self }
  897. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  898. begin
  899. cg.getexplicitregister(list,NR_FUNCTION_RETURN_REG);
  900. { return the self pointer }
  901. ressym:=tvarsym(current_procinfo.procdef.parast.search('self'));
  902. if not assigned(ressym) then
  903. internalerror(200305058);
  904. cg.ungetregister(list,NR_FUNCTION_RETURN_REG);
  905. // for the optimizer
  906. cg.a_reg_alloc(list,NR_FUNCTION_RETURN_REG);
  907. case ressym.localloc.loc of
  908. LOC_REFERENCE :
  909. begin
  910. reference_reset_base(href,ressym.localloc.reference.index,ressym.localloc.reference.offset);
  911. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_FUNCTION_RETURN_REG);
  912. end;
  913. LOC_REGISTER:
  914. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,ressym.localloc.register,NR_FUNCTION_RETURN_REG);
  915. else
  916. internalerror(2004020409);
  917. end;
  918. uses_acc:=true;
  919. exit;
  920. end;
  921. ressym := tvarsym(current_procinfo.procdef.funcretsym);
  922. if (ressym.refs>0) then
  923. begin
  924. case ressym.localloc.loc of
  925. LOC_FPUREGISTER,
  926. LOC_REGISTER :
  927. begin
  928. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  929. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  930. else
  931. if ressym.vartype.def.deftype = floatdef then
  932. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procinfo.procdef.rettype.def))
  933. else
  934. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  935. resloc.register:=ressym.localloc.register;
  936. end;
  937. LOC_REFERENCE :
  938. begin
  939. location_reset(resloc,LOC_REFERENCE,def_cgsize(current_procinfo.procdef.rettype.def));
  940. reference_reset_base(resloc.reference,ressym.localloc.reference.index,ressym.localloc.reference.offset);
  941. end;
  942. else
  943. internalerror(200309184);
  944. end;
  945. { Here, we return the function result. In most architectures, the value is
  946. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  947. function returns in a register and the caller receives it in an other one }
  948. case current_procinfo.procdef.rettype.def.deftype of
  949. orddef,
  950. enumdef :
  951. begin
  952. uses_acc:=true;
  953. {$ifndef cpu64bit}
  954. if resloc.size in [OS_64,OS_S64] then
  955. begin
  956. uses_acchi:=true;
  957. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  958. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  959. cg.ungetregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  960. cg.ungetregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  961. // for the optimizer
  962. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_LOW_REG);
  963. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_HIGH_REG);
  964. cg64.a_load64_loc_reg(list,resloc,joinreg64(NR_FUNCTION_RETURN64_LOW_REG,
  965. NR_FUNCTION_RETURN64_HIGH_REG));
  966. end
  967. else
  968. {$endif cpu64bit}
  969. begin
  970. cg.getexplicitregister(list,NR_FUNCTION_RETURN_REG);
  971. hreg:=cg.makeregsize(list,NR_FUNCTION_RETURN_REG,resloc.size);
  972. cg.ungetregister(list,hreg);
  973. // for the optimizer
  974. cg.a_reg_alloc(list,NR_FUNCTION_RETURN_REG);
  975. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  976. end;
  977. end;
  978. floatdef :
  979. begin
  980. uses_fpu := true;
  981. {$ifdef cpufpemu}
  982. if cs_fp_emulation in aktmoduleswitches then
  983. cg.a_loadfpu_loc_reg(list,resloc,NR_FUNCTION_RETURN_REG)
  984. else
  985. {$endif cpufpemu}
  986. cg.a_loadfpu_loc_reg(list,resloc,NR_FPU_RESULT_REG);
  987. end;
  988. else
  989. begin
  990. if not paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  991. begin
  992. uses_acc:=true;
  993. {$ifndef cpu64bit}
  994. { Win32 can return records in EAX:EDX }
  995. if resloc.size in [OS_64,OS_S64] then
  996. begin
  997. uses_acchi:=true;
  998. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  999. cg.getexplicitregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  1000. cg.ungetregister(list,NR_FUNCTION_RETURN64_LOW_REG);
  1001. cg.ungetregister(list,NR_FUNCTION_RETURN64_HIGH_REG);
  1002. // for the optimizer
  1003. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_LOW_REG);
  1004. cg.a_reg_alloc(list,NR_FUNCTION_RETURN64_HIGH_REG);
  1005. cg64.a_load64_loc_reg(list,resloc,joinreg64(NR_FUNCTION_RETURN64_LOW_REG,
  1006. NR_FUNCTION_RETURN64_HIGH_REG));
  1007. end
  1008. else
  1009. {$endif cpu64bit}
  1010. begin
  1011. cg.getexplicitregister(list,NR_FUNCTION_RETURN_REG);
  1012. hreg:=cg.makeregsize(list,NR_FUNCTION_RETURN_REG,resloc.size);
  1013. cg.ungetregister(list,hreg);
  1014. // for the optimizer
  1015. cg.a_reg_alloc(list,NR_FUNCTION_RETURN_REG);
  1016. cg.a_load_loc_reg(list,resloc.size,resloc,hreg);
  1017. end;
  1018. end
  1019. end;
  1020. end;
  1021. end;
  1022. end;
  1023. procedure gen_load_para_value(list:TAAsmoutput);
  1024. var
  1025. hp : tparaitem;
  1026. href : treference;
  1027. gotregvarparas : boolean;
  1028. begin
  1029. { Store register parameters in reference or in register variable }
  1030. if assigned(current_procinfo.procdef.parast) and
  1031. not (po_assembler in current_procinfo.procdef.procoptions) then
  1032. begin
  1033. { move register parameters which aren't regable into memory }
  1034. { we do this before init_paras because that one calls routines which may overwrite these }
  1035. { registers and it also expects the values to be in memory }
  1036. hp:=tparaitem(current_procinfo.procdef.para.first);
  1037. gotregvarparas := false;
  1038. while assigned(hp) do
  1039. begin
  1040. case tvarsym(hp.parasym).localloc.loc of
  1041. LOC_REGISTER,
  1042. LOC_MMREGISTER,
  1043. LOC_FPUREGISTER:
  1044. begin
  1045. gotregvarparas := true;
  1046. { cg.a_load_param_reg will first allocate and then deallocate paraloc }
  1047. { register (if the parameter resides in a register) and then allocate }
  1048. { the regvar (which is currently not allocated) }
  1049. cg.a_loadany_param_reg(list,hp.paraloc[calleeside],tvarsym(hp.parasym).localloc.register,nil);
  1050. end;
  1051. LOC_REFERENCE :
  1052. begin
  1053. if hp.paraloc[calleeside].loc<>LOC_REFERENCE then
  1054. begin
  1055. if getsupreg(hp.paraloc[calleeside].register)<first_int_imreg then
  1056. begin
  1057. {$ifndef cpu64bit}
  1058. if (hp.paraloc[calleeside].size in [OS_S64,OS_64]) then
  1059. begin
  1060. cg.getexplicitregister(list,hp.paraloc[calleeside].registerlow);
  1061. cg.getexplicitregister(list,hp.paraloc[calleeside].registerhigh);
  1062. end
  1063. else
  1064. {$endif cpu64bit}
  1065. cg.getexplicitregister(list,hp.paraloc[calleeside].register);
  1066. end;
  1067. { Release parameter register }
  1068. {$ifndef cpu64bit}
  1069. if (hp.paraloc[calleeside].size in [OS_S64,OS_64]) then
  1070. begin
  1071. cg.ungetregister(list,hp.paraloc[calleeside].registerlow);
  1072. cg.ungetregister(list,hp.paraloc[calleeside].registerhigh);
  1073. end
  1074. else
  1075. {$endif cpu64bit}
  1076. cg.ungetregister(list,hp.paraloc[calleeside].register);
  1077. reference_reset_base(href,tvarsym(hp.parasym).localloc.reference.index,tvarsym(hp.parasym).localloc.reference.offset);
  1078. cg.a_loadany_param_ref(list,hp.paraloc[calleeside],href,nil);
  1079. end;
  1080. end;
  1081. else
  1082. internalerror(200309185);
  1083. end;
  1084. hp:=tparaitem(hp.next);
  1085. end;
  1086. if gotregvarparas then
  1087. begin
  1088. { deallocate all register variables again }
  1089. hp:=tparaitem(current_procinfo.procdef.para.first);
  1090. while assigned(hp) do
  1091. begin
  1092. if (tvarsym(hp.parasym).localloc.loc=LOC_REGISTER) then
  1093. cg.ungetregister(list,tvarsym(hp.parasym).localloc.register);
  1094. hp:=tparaitem(hp.next);
  1095. end;
  1096. end;
  1097. end;
  1098. { generate copies of call by value parameters, must be done before
  1099. the initialization and body is parsed because the refcounts are
  1100. incremented using the local copies }
  1101. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1102. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1103. end;
  1104. procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean);
  1105. begin
  1106. { initialize local data like ansistrings }
  1107. case current_procinfo.procdef.proctypeoption of
  1108. potype_unitinit:
  1109. begin
  1110. { this is also used for initialization of variables in a
  1111. program which does not have a globalsymtable }
  1112. if assigned(current_module.globalsymtable) then
  1113. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1114. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1115. end;
  1116. { units have seperate code for initilization and finalization }
  1117. potype_unitfinalize: ;
  1118. { program init/final is generated in separate procedure }
  1119. potype_proginit: ;
  1120. else
  1121. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1122. end;
  1123. { initialisizes temp. ansi/wide string data }
  1124. inittempvariables(list);
  1125. { initialize ansi/widesstring para's }
  1126. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1127. {$ifdef OLDREGVARS}
  1128. load_regvars(list,nil);
  1129. {$endif OLDREGVARS}
  1130. end;
  1131. procedure gen_finalize_code(list:TAAsmoutput;inlined:boolean);
  1132. begin
  1133. {$ifdef OLDREGVARS}
  1134. cleanup_regvars(list);
  1135. {$endif OLDREGVARS}
  1136. { finalize temporary data }
  1137. finalizetempvariables(list);
  1138. { finalize local data like ansistrings}
  1139. case current_procinfo.procdef.proctypeoption of
  1140. potype_unitfinalize:
  1141. begin
  1142. { this is also used for initialization of variables in a
  1143. program which does not have a globalsymtable }
  1144. if assigned(current_module.globalsymtable) then
  1145. tsymtable(current_module.globalsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1146. tsymtable(current_module.localsymtable).foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1147. end;
  1148. { units/progs have separate code for initialization and finalization }
  1149. potype_unitinit: ;
  1150. { program init/final is generated in separate procedure }
  1151. potype_proginit: ;
  1152. else
  1153. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1154. end;
  1155. { finalize paras data }
  1156. if assigned(current_procinfo.procdef.parast) then
  1157. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1158. end;
  1159. procedure gen_entry_code(list:TAAsmoutput);
  1160. var
  1161. href : treference;
  1162. paraloc1,
  1163. paraloc2 : tparalocation;
  1164. hp : tused_unit;
  1165. begin
  1166. { the actual profile code can clobber some registers,
  1167. therefore if the context must be saved, do it before
  1168. the actual call to the profile code
  1169. }
  1170. if (cs_profile in aktmoduleswitches) and
  1171. not(po_assembler in current_procinfo.procdef.procoptions) then
  1172. begin
  1173. { non-win32 can call mcout even in main }
  1174. if not (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  1175. cg.g_profilecode(list)
  1176. else
  1177. { wdosx, and win32 should not call mcount before monstartup has been called }
  1178. if not (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1179. cg.g_profilecode(list);
  1180. end;
  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.newasmsymbol('etext',AB_EXTERNAL,AT_DATA),0);
  1189. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1190. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1191. paramanager.allocparaloc(list,paraloc2);
  1192. cg.a_paramaddr_ref(list,href,paraloc2);
  1193. reference_reset_symbol(href,objectlibrary.newasmsymbol('__image_base__',AB_EXTERNAL,AT_DATA),0);
  1194. paramanager.allocparaloc(list,paraloc1);
  1195. cg.a_paramaddr_ref(list,href,paraloc1);
  1196. paramanager.freeparaloc(list,paraloc2);
  1197. paramanager.freeparaloc(list,paraloc1);
  1198. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1199. cg.a_call_name(list,'_monstartup');
  1200. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_cdecl));
  1201. end;
  1202. { initialize units }
  1203. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1204. cg.a_call_name(list,'FPC_INITIALIZEUNITS');
  1205. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1206. {$ifdef GDB}
  1207. if (cs_debuginfo in aktmoduleswitches) then
  1208. begin
  1209. { include reference to all debuginfo sections of used units }
  1210. hp:=tused_unit(usedunits.first);
  1211. while assigned(hp) do
  1212. begin
  1213. If (hp.u.flags and uf_has_debuginfo)=uf_has_debuginfo then
  1214. current_procinfo.aktlocaldata.concat(Tai_const_symbol.Createname(make_mangledname('DEBUGINFO',hp.u.globalsymtable,''),AT_DATA,0));
  1215. hp:=tused_unit(hp.next);
  1216. end;
  1217. { include reference to debuginfo for this program }
  1218. current_procinfo.aktlocaldata.concat(Tai_const_symbol.Createname(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
  1219. end;
  1220. {$endif GDB}
  1221. end;
  1222. {$ifdef GDB}
  1223. if (cs_debuginfo in aktmoduleswitches) then
  1224. list.concat(Tai_force_line.Create);
  1225. {$endif GDB}
  1226. {$ifdef OLDREGVARS}
  1227. load_regvars(list,nil);
  1228. {$endif OLDREGVARS}
  1229. end;
  1230. procedure gen_exit_code(list:TAAsmoutput);
  1231. begin
  1232. { call __EXIT for main program }
  1233. if (not DLLsource) and
  1234. (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1235. cg.a_call_name(list,'FPC_DO_EXIT');
  1236. end;
  1237. {****************************************************************************
  1238. Entry/Exit
  1239. ****************************************************************************}
  1240. procedure gen_proc_symbol(list:Taasmoutput);
  1241. var
  1242. hs : string;
  1243. begin
  1244. { add symbol entry point as well as debug information }
  1245. { will be inserted in front of the rest of this list. }
  1246. { Insert alignment and assembler names }
  1247. { Align, gprof uses 16 byte granularity }
  1248. if (cs_profile in aktmoduleswitches) then
  1249. list.concat(Tai_align.create(16))
  1250. else
  1251. list.concat(Tai_align.create(aktalignment.procalign));
  1252. {$ifdef GDB}
  1253. if (cs_debuginfo in aktmoduleswitches) then
  1254. begin
  1255. if (po_public in current_procinfo.procdef.procoptions) then
  1256. Tprocsym(current_procinfo.procdef.procsym).is_global:=true;
  1257. current_procinfo.procdef.concatstabto(list);
  1258. Tprocsym(current_procinfo.procdef.procsym).isstabwritten:=true;
  1259. end;
  1260. {$endif GDB}
  1261. repeat
  1262. hs:=current_procinfo.procdef.aliasnames.getfirst;
  1263. if hs='' then
  1264. break;
  1265. {$ifdef GDB}
  1266. if (cs_debuginfo in aktmoduleswitches) and
  1267. target_info.use_function_relative_addresses then
  1268. list.concat(Tai_stab_function_name.create(strpnew(hs)));
  1269. {$endif GDB}
  1270. if (cs_profile in aktmoduleswitches) or
  1271. (po_public in current_procinfo.procdef.procoptions) then
  1272. list.concat(Tai_symbol.createname_global(hs,AT_FUNCTION,0))
  1273. else
  1274. list.concat(Tai_symbol.createname(hs,AT_FUNCTION,0));
  1275. until false;
  1276. end;
  1277. procedure gen_proc_symbol_end(list:Taasmoutput);
  1278. {$ifdef GDB}
  1279. var
  1280. stabsendlabel : tasmlabel;
  1281. mangled_length : longint;
  1282. p : pchar;
  1283. {$endif GDB}
  1284. begin
  1285. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1286. {$ifdef GDB}
  1287. if (cs_debuginfo in aktmoduleswitches) then
  1288. begin
  1289. objectlibrary.getlabel(stabsendlabel);
  1290. cg.a_label(list,stabsendlabel);
  1291. { define calling EBP as pseudo local var PM }
  1292. { this enables test if the function is a local one !! }
  1293. {if assigned(current_procinfo.parent) and
  1294. (current_procinfo.procdef.parast.symtablelevel>normal_function_level) then
  1295. list.concat(Tai_stabs.Create(strpnew(
  1296. '"parent_ebp:'+tstoreddef(voidpointertype.def).numberstring+'",'+
  1297. tostr(N_LSYM)+',0,0,'+tostr(current_procinfo.parent_framepointer_offset)))); }
  1298. if (not is_void(current_procinfo.procdef.rettype.def)) and
  1299. (tvarsym(current_procinfo.procdef.funcretsym).refs>0) then
  1300. begin
  1301. if tvarsym(current_procinfo.procdef.funcretsym).localloc.loc=LOC_REFERENCE then
  1302. begin
  1303. {$warning Need to add gdb support for ret in param register calling}
  1304. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1305. begin
  1306. list.concat(Tai_stabs.Create(strpnew(
  1307. '"'+current_procinfo.procdef.procsym.name+':X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1308. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1309. if (m_result in aktmodeswitches) then
  1310. list.concat(Tai_stabs.Create(strpnew(
  1311. '"RESULT:X*'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1312. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))))
  1313. end
  1314. else
  1315. begin
  1316. list.concat(Tai_stabs.Create(strpnew(
  1317. '"'+current_procinfo.procdef.procsym.name+':X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1318. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1319. if (m_result in aktmodeswitches) then
  1320. list.concat(Tai_stabs.Create(strpnew(
  1321. '"RESULT:X'+tstoreddef(current_procinfo.procdef.rettype.def).numberstring+'",'+
  1322. tostr(N_tsym)+',0,0,'+tostr(tvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset))));
  1323. end;
  1324. end;
  1325. end;
  1326. mangled_length:=length(current_procinfo.procdef.mangledname);
  1327. getmem(p,2*mangled_length+50);
  1328. strpcopy(p,'192,0,0,');
  1329. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1330. if (target_info.use_function_relative_addresses) then
  1331. begin
  1332. strpcopy(strend(p),'-');
  1333. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1334. end;
  1335. list.concat(Tai_stabn.Create(strnew(p)));
  1336. {List.concat(Tai_stabn.Create(strpnew('192,0,0,'
  1337. +current_procinfo.procdef.mangledname))));
  1338. p[0]:='2';p[1]:='2';p[2]:='4';
  1339. strpcopy(strend(p),'_end');}
  1340. strpcopy(p,'224,0,0,'+stabsendlabel.name);
  1341. if (target_info.use_function_relative_addresses) then
  1342. begin
  1343. strpcopy(strend(p),'-');
  1344. strpcopy(strend(p),current_procinfo.procdef.mangledname);
  1345. end;
  1346. list.concatlist(withdebuglist);
  1347. list.concat(Tai_stabn.Create(strnew(p)));
  1348. { strpnew('224,0,0,'
  1349. +current_procinfo.procdef.mangledname+'_end'))));}
  1350. freemem(p,2*mangled_length+50);
  1351. end;
  1352. {$endif GDB}
  1353. end;
  1354. procedure gen_stackalloc_code(list:Taasmoutput);
  1355. var
  1356. hitemp,
  1357. lotemp,
  1358. stackframe : longint;
  1359. check : boolean;
  1360. paraloc1 : tparalocation;
  1361. href : treference;
  1362. begin
  1363. check:=(cs_check_stack in aktlocalswitches) and (current_procinfo.procdef.proctypeoption<>potype_proginit);
  1364. if check then
  1365. begin
  1366. { Allocate tempspace to store register parameter than
  1367. is destroyed when calling stackchecking code }
  1368. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1369. if paraloc1.loc=LOC_REGISTER then
  1370. tg.GetTemp(list,POINTER_SIZE,tt_normal,href);
  1371. end;
  1372. { Calculate size of stackframe }
  1373. stackframe:=current_procinfo.calc_stackframe_size;
  1374. { All temps are know, write offsets used for information }
  1375. if (cs_asm_source in aktglobalswitches) then
  1376. begin
  1377. if tg.direction>0 then
  1378. begin
  1379. lotemp:=current_procinfo.tempstart;
  1380. hitemp:=tg.lasttemp;
  1381. end
  1382. else
  1383. begin
  1384. lotemp:=tg.lasttemp;
  1385. hitemp:=current_procinfo.tempstart;
  1386. end;
  1387. list.concat(Tai_comment.Create(strpnew('Temps allocated between '+std_regname(current_procinfo.framepointer)+
  1388. tostr_with_plus(lotemp)+' and '+std_regname(current_procinfo.framepointer)+tostr_with_plus(hitemp))));
  1389. end;
  1390. {$ifndef powerpc}
  1391. { at least for the ppc this applies always, so this code isn't usable (FK) }
  1392. { omit stack frame ? }
  1393. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1394. begin
  1395. CGmessage(cg_d_stackframe_omited);
  1396. if stackframe<>0 then
  1397. cg.g_stackpointer_alloc(list,stackframe);
  1398. end
  1399. else
  1400. {$endif powerpc}
  1401. begin
  1402. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1403. cg.g_interrupt_stackframe_entry(list);
  1404. cg.g_stackframe_entry(list,stackframe);
  1405. { Add stack checking code? }
  1406. if check then
  1407. begin
  1408. { The tempspace to store original register is already
  1409. allocated above before the stackframe size is calculated. }
  1410. if paraloc1.loc=LOC_REGISTER then
  1411. cg.a_load_reg_ref(list,OS_INT,OS_INT,paraloc1.register,href);
  1412. paramanager.allocparaloc(list,paraloc1);
  1413. cg.a_param_const(list,OS_INT,stackframe,paraloc1);
  1414. paramanager.freeparaloc(list,paraloc1);
  1415. { No register saving needed, saveregisters is used }
  1416. {$ifndef x86}
  1417. cg.allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1418. {$endif x86}
  1419. cg.a_call_name(list,'FPC_STACKCHECK');
  1420. {$ifndef x86}
  1421. cg.deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1422. {$endif x86}
  1423. if paraloc1.loc=LOC_REGISTER then
  1424. begin
  1425. cg.a_load_ref_reg(list,OS_INT,OS_INT,href,paraloc1.register);
  1426. tg.UnGetTemp(list,href);
  1427. end;
  1428. end;
  1429. end;
  1430. end;
  1431. procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
  1432. var
  1433. stacksize,
  1434. retsize : longint;
  1435. begin
  1436. {$ifndef powerpc}
  1437. { remove stackframe }
  1438. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1439. begin
  1440. stacksize:=current_procinfo.calc_stackframe_size;
  1441. if (stacksize<>0) then
  1442. cg.a_op_const_reg(list,OP_ADD,OS_ADDR,stacksize,current_procinfo.framepointer);
  1443. end
  1444. else
  1445. cg.g_restore_frame_pointer(list);
  1446. {$endif}
  1447. {$ifdef x86}
  1448. { at last, the return is generated }
  1449. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1450. cg.g_interrupt_stackframe_exit(list,usesacc,usesacchi)
  1451. else
  1452. {$endif x86}
  1453. begin
  1454. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1455. begin
  1456. retsize:=0;
  1457. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1458. inc(retsize,POINTER_SIZE);
  1459. end
  1460. else
  1461. retsize:=current_procinfo.para_stack_size;
  1462. cg.g_return_from_proc(list,retsize);
  1463. end;
  1464. {$ifndef cpu64bit}
  1465. if usesacchi then
  1466. begin
  1467. cg.a_reg_dealloc(list,NR_FUNCTION_RETURN64_LOW_REG);
  1468. cg.a_reg_dealloc(list,NR_FUNCTION_RETURN64_HIGH_REG);
  1469. end
  1470. else
  1471. {$endif cpu64bit}
  1472. if usesacc then
  1473. cg.a_reg_dealloc(list,NR_FUNCTION_RETURN_REG);
  1474. end;
  1475. procedure gen_save_used_regs(list:TAAsmoutput);
  1476. begin
  1477. { Pure assembler routines need to save the registers themselves }
  1478. if (po_assembler in current_procinfo.procdef.procoptions) then
  1479. exit;
  1480. { for the save all registers we can simply use a pusha,popa which
  1481. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1482. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1483. cg.g_save_all_registers(list)
  1484. else
  1485. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1486. cg.g_save_standard_registers(list);
  1487. end;
  1488. procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tparalocation);
  1489. begin
  1490. { Pure assembler routines need to save the registers themselves }
  1491. if (po_assembler in current_procinfo.procdef.procoptions) then
  1492. exit;
  1493. { for the save all registers we can simply use a pusha,popa which
  1494. push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
  1495. if (po_saveregisters in current_procinfo.procdef.procoptions) then
  1496. cg.g_restore_all_registers(list,funcretparaloc)
  1497. else
  1498. if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
  1499. cg.g_restore_standard_registers(list);
  1500. end;
  1501. {****************************************************************************
  1502. Inlining
  1503. ****************************************************************************}
  1504. (*
  1505. procedure load_inlined_return_value(list:TAAsmoutput);
  1506. var
  1507. ressym: tvarsym;
  1508. resloc: tlocation;
  1509. r,r2 : tregister;
  1510. begin
  1511. if not is_void(current_procinfo.procdef.rettype.def) then
  1512. begin
  1513. ressym := tvarsym(current_procinfo.procdef.funcretsym);
  1514. if ressym.reg.enum <> R_NO then
  1515. begin
  1516. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1517. location_reset(resloc,LOC_CREGISTER,OS_ADDR)
  1518. else
  1519. if ressym.vartype.def.deftype = floatdef then
  1520. location_reset(resloc,LOC_CFPUREGISTER,def_cgsize(current_procinfo.procdef.rettype.def))
  1521. else
  1522. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  1523. resloc.register := ressym.reg;
  1524. end
  1525. else
  1526. begin
  1527. location_reset(resloc,LOC_CREGISTER,def_cgsize(current_procinfo.procdef.rettype.def));
  1528. reference_reset_base(resloc.reference,current_procinfo.framepointer,tvarsym(current_procinfo.procdef.funcretsym).adjusted_address);
  1529. end;
  1530. { Here, we return the function result. In most architectures, the value is
  1531. passed into the FUNCTION_RETURN_REG, but in a windowed architecure like sparc a
  1532. function returns in a register and the caller receives it in an other one }
  1533. case current_procinfo.procdef.rettype.def.deftype of
  1534. orddef,
  1535. enumdef :
  1536. begin
  1537. {$ifndef cpu64bit}
  1538. if resloc.size in [OS_64,OS_S64] then
  1539. begin
  1540. r:=cg.getregisterint(list,OS_INT);
  1541. r2:=cg.getregisterint(list,OS_INT);
  1542. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2));
  1543. end
  1544. else
  1545. {$endif cpu64bit}
  1546. begin
  1547. r:=cg.getregisterint(list,resloc.size);
  1548. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1549. end;
  1550. end;
  1551. floatdef :
  1552. begin
  1553. {$ifdef cpufpemu}
  1554. if cs_fp_emulation in aktmoduleswitches then
  1555. r.enum := FUNCTION_RETURN_REG
  1556. else
  1557. {$endif cpufpemu}
  1558. r.enum:=FPU_RESULT_REG;
  1559. cg.a_loadfpu_loc_reg(list,resloc,r);
  1560. end;
  1561. else
  1562. begin
  1563. if not paramanager.ret_in_param(current_procinfo.procdef.rettype.def,current_procinfo.procdef.proccalloption) then
  1564. begin
  1565. {$ifndef cpu64bit}
  1566. { Win32 can return records in EAX:EDX }
  1567. if resloc.size in [OS_64,OS_S64] then
  1568. begin
  1569. r:=cg.getregisterint(list,OS_INT);
  1570. r2:=cg.getregisterint(list,OS_INT);
  1571. cg64.a_load64_loc_reg(list,resloc,joinreg64(r,r2));
  1572. end
  1573. else
  1574. {$endif cpu64bit}
  1575. begin
  1576. r:=cg.getregisterint(list,resloc.size);
  1577. cg.a_load_loc_reg(list,resloc.size,resloc,r);
  1578. end;
  1579. end
  1580. end;
  1581. end;
  1582. end;
  1583. end;
  1584. procedure geninlineentrycode(list:TAAsmoutput;stackframe:longint);
  1585. begin
  1586. { initialize return value }
  1587. initretvalue(list);
  1588. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}initialize_data,list);
  1589. { initialisizes temp. ansi/wide string data }
  1590. inittempvariables(list);
  1591. { initialize ansi/widesstring para's }
  1592. if assigned(current_procinfo.procdef.parast) then
  1593. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}init_paras,list);
  1594. { generate copies of call by value parameters }
  1595. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1596. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}copyvalueparas,list);
  1597. load_regvars(list,nil);
  1598. end;
  1599. procedure geninlineexitcode(list:TAAsmoutput;inlined:boolean);
  1600. var
  1601. usesacc,
  1602. usesacchi,
  1603. usesfpu : boolean;
  1604. begin
  1605. if aktexitlabel.is_used then
  1606. cg.a_label(list,aktexitlabel);
  1607. cleanup_regvars(list);
  1608. { finalize temporary data }
  1609. finalizetempvariables(list);
  1610. current_procinfo.procdef.localst.foreach_static({$ifndef TP}@{$endif}finalize_data,list);
  1611. { finalize paras data }
  1612. if assigned(current_procinfo.procdef.parast) then
  1613. current_procinfo.procdef.parast.foreach_static({$ifndef TP}@{$endif}final_paras,list);
  1614. { handle return value, this is not done for assembler routines when
  1615. they didn't reference the result variable }
  1616. if not(po_assembler in current_procinfo.procdef.procoptions) or
  1617. (assigned(current_procinfo.procdef.funcretsym) and
  1618. (tvarsym(current_procinfo.procdef.funcretsym).refcount>1)) then
  1619. begin
  1620. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  1621. internalerror(200305263);
  1622. // load_inlined_return_value(list);
  1623. load_return_value(list,usesacc,usesacchi,usesfpu)
  1624. end;
  1625. cleanup_regvars(list);
  1626. end;
  1627. *)
  1628. {****************************************************************************
  1629. Const Data
  1630. ****************************************************************************}
  1631. procedure insertconstdata(sym : ttypedconstsym);
  1632. { this does not affect the local stack space, since all
  1633. typed constansts and initialized variables are always
  1634. put in the .data / .rodata section
  1635. }
  1636. var
  1637. storefilepos : tfileposinfo;
  1638. curconstsegment : taasmoutput;
  1639. l : longint;
  1640. stabstr:Pchar;
  1641. begin
  1642. storefilepos:=aktfilepos;
  1643. aktfilepos:=sym.fileinfo;
  1644. if sym.is_writable then
  1645. curconstsegment:=datasegment
  1646. else
  1647. curconstsegment:=consts;
  1648. l:=sym.getsize;
  1649. { insert cut for smartlinking or alignment }
  1650. if (cs_create_smart in aktmoduleswitches) then
  1651. curconstSegment.concat(Tai_cut.Create);
  1652. curconstSegment.concat(Tai_align.create(const_align(l)));
  1653. if (sym.owner.symtabletype=globalsymtable) or
  1654. (cs_create_smart in aktmoduleswitches) or
  1655. (assigned(current_procinfo) and
  1656. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1657. DLLSource then
  1658. curconstSegment.concat(Tai_symbol.Createname_global(sym.mangledname,AT_DATA,l))
  1659. else
  1660. curconstSegment.concat(Tai_symbol.Createname(sym.mangledname,AT_DATA,l));
  1661. aktfilepos:=storefilepos;
  1662. end;
  1663. procedure insertbssdata(sym : tvarsym);
  1664. var
  1665. l,varalign : longint;
  1666. storefilepos : tfileposinfo;
  1667. stabstr:Pchar;
  1668. begin
  1669. storefilepos:=aktfilepos;
  1670. aktfilepos:=sym.fileinfo;
  1671. l:=sym.getvaluesize;
  1672. if (vo_is_thread_var in sym.varoptions) then
  1673. inc(l,pointer_size);
  1674. varalign:=var_align(l);
  1675. {
  1676. sym.address:=align(datasize,varalign);
  1677. datasize:=tvarsym(sym).address+l;
  1678. }
  1679. { insert cut for smartlinking or alignment }
  1680. if (cs_create_smart in aktmoduleswitches) then
  1681. bssSegment.concat(Tai_cut.Create);
  1682. bssSegment.concat(Tai_align.create(varalign));
  1683. if (sym.owner.symtabletype=globalsymtable) or
  1684. (cs_create_smart in aktmoduleswitches) or
  1685. DLLSource or
  1686. (assigned(current_procinfo) and
  1687. (current_procinfo.procdef.proccalloption=pocall_inline)) or
  1688. (vo_is_exported in sym.varoptions) or
  1689. (vo_is_C_var in sym.varoptions) then
  1690. bssSegment.concat(Tai_datablock.Create_global(sym.mangledname,l))
  1691. else
  1692. bssSegment.concat(Tai_datablock.Create(sym.mangledname,l));
  1693. aktfilepos:=storefilepos;
  1694. end;
  1695. procedure gen_alloc_localst(list:TAAsmoutput;st:tlocalsymtable);
  1696. var
  1697. sym : tsym;
  1698. begin
  1699. sym:=tsym(st.symindex.first);
  1700. while assigned(sym) do
  1701. begin
  1702. { Only allocate space for referenced locals }
  1703. if (sym.typ=varsym) and
  1704. (tvarsym(sym).refs>0) then
  1705. begin
  1706. with tvarsym(sym) do
  1707. begin
  1708. {$warning TODO Add support for register variables}
  1709. localloc.loc:=LOC_REFERENCE;
  1710. tg.GetLocal(list,getvaluesize,vartype.def,localloc.reference);
  1711. if cs_asm_source in aktglobalswitches then
  1712. list.concat(Tai_comment.Create(strpnew('Local '+realname+' located at '+
  1713. std_regname(localloc.reference.index)+tostr_with_plus(localloc.reference.offset))));
  1714. end;
  1715. end;
  1716. sym:=tsym(sym.indexnext);
  1717. end;
  1718. end;
  1719. procedure gen_free_localst(list:TAAsmoutput;st:tlocalsymtable);
  1720. var
  1721. sym : tsym;
  1722. begin
  1723. sym:=tsym(st.symindex.first);
  1724. while assigned(sym) do
  1725. begin
  1726. if (sym.typ=varsym) and
  1727. (tvarsym(sym).refs>0) then
  1728. begin
  1729. with tvarsym(sym) do
  1730. begin
  1731. { Note: We need to keep the data available in memory
  1732. for the sub procedures that can access local data
  1733. in the parent procedures }
  1734. case localloc.loc of
  1735. LOC_REFERENCE :
  1736. tg.Ungetlocal(list,localloc.reference);
  1737. LOC_REGISTER :
  1738. begin
  1739. {$ifndef cpu64bit}
  1740. if localloc.size in [OS_64,OS_S64] then
  1741. begin
  1742. cg.ungetregister(list,localloc.registerlow);
  1743. cg.ungetregister(list,localloc.registerhigh);
  1744. end
  1745. else
  1746. {$endif cpu64bit}
  1747. cg.ungetregister(list,localloc.register);
  1748. end;
  1749. end;
  1750. end;
  1751. end;
  1752. sym:=tsym(sym.indexnext);
  1753. end;
  1754. end;
  1755. procedure gen_alloc_parast(list:TAAsmoutput;st:tparasymtable);
  1756. var
  1757. sym : tsym;
  1758. begin
  1759. sym:=tsym(st.symindex.first);
  1760. while assigned(sym) do
  1761. begin
  1762. if sym.typ=varsym then
  1763. begin
  1764. with tvarsym(sym) do
  1765. begin
  1766. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1767. begin
  1768. case paraitem.paraloc[calleeside].loc of
  1769. LOC_MMREGISTER,
  1770. LOC_FPUREGISTER,
  1771. LOC_REGISTER:
  1772. begin
  1773. (*
  1774. if paraitem.paraloc[calleeside].register=NR_NO then
  1775. begin
  1776. paraitem.paraloc[calleeside].loc:=LOC_REGISTER;
  1777. paraitem.paraloc[calleeside].size:=paraitem.paraloc[calleeside].size;
  1778. {$ifndef cpu64bit}
  1779. if paraitem.paraloc[calleeside].size in [OS_64,OS_S64] then
  1780. begin
  1781. paraitem.paraloc[calleeside].registerlow:=cg.getregisterint(list,OS_32);
  1782. paraitem.paraloc[calleeside].registerhigh:=cg.getregisterint(list,OS_32);
  1783. end
  1784. else
  1785. {$endif cpu64bit}
  1786. paraitem.paraloc[calleeside].register:=cg.getregisterint(list,localloc.size);
  1787. end;
  1788. *)
  1789. (*
  1790. {$warning TODO Allocate register paras}
  1791. localloc.loc:=LOC_REGISTER;
  1792. localloc.size:=paraitem.paraloc[calleeside].size;
  1793. {$ifndef cpu64bit}
  1794. if localloc.size in [OS_64,OS_S64] then
  1795. begin
  1796. localloc.registerlow:=cg.getregisterint(list,OS_32);
  1797. localloc.registerhigh:=cg.getregisterint(list,OS_32);
  1798. end
  1799. else
  1800. {$endif cpu64bit}
  1801. localloc.register:=cg.getregisterint(list,localloc.size);
  1802. *)
  1803. localloc.loc:=LOC_REFERENCE;
  1804. localloc.size:=paraitem.paraloc[calleeside].size;
  1805. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1806. end
  1807. else
  1808. localloc:=paraitem.paraloc[calleeside];
  1809. end;
  1810. end
  1811. else
  1812. localloc:=paraitem.paraloc[calleeside];
  1813. if cs_asm_source in aktglobalswitches then
  1814. begin
  1815. case localloc.loc of
  1816. LOC_REFERENCE :
  1817. begin
  1818. list.concat(Tai_comment.Create(strpnew('Para '+realname+' located at '+
  1819. std_regname(localloc.reference.index)+tostr_with_plus(localloc.reference.offset))));
  1820. {$ifdef powerpc}
  1821. localloc.size:=paraitem.paraloc[calleeside].size;
  1822. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1823. {$endif powerpc}
  1824. end;
  1825. end;
  1826. end;
  1827. end;
  1828. end;
  1829. sym:=tsym(sym.indexnext);
  1830. end;
  1831. end;
  1832. procedure gen_alloc_inline_parast(list:TAAsmoutput;st:tparasymtable);
  1833. var
  1834. sym : tsym;
  1835. begin
  1836. sym:=tsym(st.symindex.first);
  1837. while assigned(sym) do
  1838. begin
  1839. if sym.typ=varsym then
  1840. begin
  1841. with tvarsym(sym) do
  1842. begin
  1843. {$warning TODO Allocate register paras}
  1844. localloc.loc:=LOC_REFERENCE;
  1845. localloc.size:=int_cgsize(paramanager.push_size(vs_value,vartype.def,pocall_inline));
  1846. tg.GetLocal(list,tcgsize2size[localloc.size],vartype.def,localloc.reference);
  1847. if cs_asm_source in aktglobalswitches then
  1848. begin
  1849. case localloc.loc of
  1850. LOC_REFERENCE :
  1851. list.concat(Tai_comment.Create(strpnew('Para '+realname+' allocated at '+
  1852. std_regname(localloc.reference.index)+tostr_with_plus(localloc.reference.offset))));
  1853. end;
  1854. end;
  1855. paraitem.paraloc[callerside]:=localloc;
  1856. paraitem.paraloc[calleeside]:=localloc;
  1857. end;
  1858. end;
  1859. sym:=tsym(sym.indexnext);
  1860. end;
  1861. end;
  1862. procedure gen_free_parast(list:TAAsmoutput;st:tparasymtable);
  1863. var
  1864. sym : tsym;
  1865. begin
  1866. sym:=tsym(st.symindex.first);
  1867. while assigned(sym) do
  1868. begin
  1869. if sym.typ=varsym then
  1870. begin
  1871. with tvarsym(sym) do
  1872. begin
  1873. { Note: We need to keep the data available in memory
  1874. for the sub procedures that can access local data
  1875. in the parent procedures }
  1876. case localloc.loc of
  1877. LOC_REFERENCE :
  1878. tg.UngetLocal(list,localloc.reference);
  1879. LOC_REGISTER :
  1880. begin
  1881. if localloc.register<>paraitem.paraloc[calleeside].register then
  1882. begin
  1883. {$ifndef cpu64bit}
  1884. if localloc.size in [OS_64,OS_S64] then
  1885. begin
  1886. cg.ungetregister(list,localloc.registerlow);
  1887. cg.ungetregister(list,localloc.registerhigh);
  1888. end
  1889. else
  1890. {$endif cpu64bit}
  1891. cg.ungetregister(list,localloc.register);
  1892. end;
  1893. end;
  1894. end;
  1895. end;
  1896. end;
  1897. sym:=tsym(sym.indexnext);
  1898. end;
  1899. end;
  1900. { persistent rtti generation }
  1901. procedure generate_rtti(p:Ttypesym);
  1902. var
  1903. rsym : trttisym;
  1904. def : tstoreddef;
  1905. begin
  1906. { rtti can only be generated for classes that are always typesyms }
  1907. def:=tstoreddef(ttypesym(p).restype.def);
  1908. { there is an error, skip rtti info }
  1909. if def.deftype=errordef then
  1910. exit;
  1911. { only create rtti once for each definition }
  1912. if not(df_has_rttitable in def.defoptions) then
  1913. begin
  1914. { definition should be in the same symtable as the symbol }
  1915. if p.owner<>def.owner then
  1916. internalerror(200108262);
  1917. { create rttisym }
  1918. rsym:=trttisym.create(p.name,fullrtti);
  1919. p.owner.insert(rsym);
  1920. { register rttisym in definition }
  1921. include(def.defoptions,df_has_rttitable);
  1922. def.rttitablesym:=rsym;
  1923. { write rtti data }
  1924. def.write_child_rtti_data(fullrtti);
  1925. if (cs_create_smart in aktmoduleswitches) then
  1926. rttiList.concat(Tai_cut.Create);
  1927. rttilist.concat(tai_align.create(const_align(pointer_size)));
  1928. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  1929. def.write_rtti_data(fullrtti);
  1930. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  1931. end;
  1932. end;
  1933. { persistent init table generation }
  1934. procedure generate_inittable(p:tsym);
  1935. var
  1936. rsym : trttisym;
  1937. def : tstoreddef;
  1938. begin
  1939. { anonymous types are also allowed for records that can be varsym }
  1940. case p.typ of
  1941. typesym :
  1942. def:=tstoreddef(ttypesym(p).restype.def);
  1943. varsym :
  1944. def:=tstoreddef(tvarsym(p).vartype.def);
  1945. else
  1946. internalerror(200108263);
  1947. end;
  1948. { only create inittable once for each definition }
  1949. if not(df_has_inittable in def.defoptions) then
  1950. begin
  1951. { definition should be in the same symtable as the symbol }
  1952. if p.owner<>def.owner then
  1953. internalerror(200108264);
  1954. { create rttisym }
  1955. rsym:=trttisym.create(p.name,initrtti);
  1956. p.owner.insert(rsym);
  1957. { register rttisym in definition }
  1958. include(def.defoptions,df_has_inittable);
  1959. def.inittablesym:=rsym;
  1960. { write inittable data }
  1961. def.write_child_rtti_data(initrtti);
  1962. if (cs_create_smart in aktmoduleswitches) then
  1963. rttiList.concat(Tai_cut.Create);
  1964. rttilist.concat(tai_align.create(const_align(pointer_size)));
  1965. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  1966. def.write_rtti_data(initrtti);
  1967. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  1968. end;
  1969. end;
  1970. end.
  1971. {
  1972. $Log$
  1973. Revision 1.201 2004-05-23 15:06:21 peter
  1974. * implicit_finally flag must be set in pass1
  1975. * add check whether the implicit frame is generated when expected
  1976. Revision 1.200 2004/05/22 23:34:28 peter
  1977. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1978. Revision 1.199 2004/05/19 21:16:12 peter
  1979. * add DEBUGINFO symbol to reference the .o file that includes the
  1980. stabs info for types and global/static variables
  1981. * debuginfo flag added to ppu to indicate whether debuginfo is
  1982. generated or not
  1983. Revision 1.198 2004/05/02 17:26:19 peter
  1984. * fix stabs for globals
  1985. Revision 1.197 2004/03/29 14:43:47 peter
  1986. * cleaner temp get/unget for exceptions
  1987. Revision 1.196 2004/03/03 22:02:52 peter
  1988. * use loadnode and finalize_data_node for init/final code to support
  1989. threadvars correctly
  1990. Revision 1.195 2004/03/02 00:36:33 olle
  1991. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1992. Revision 1.194 2004/02/27 10:21:05 florian
  1993. * top_symbol killed
  1994. + refaddr to treference added
  1995. + refsymbol to treference added
  1996. * top_local stuff moved to an extra record to save memory
  1997. + aint introduced
  1998. * tppufile.get/putint64/aint implemented
  1999. Revision 1.193 2004/02/22 18:27:21 florian
  2000. * fixed exception reason size for 64 bit systems
  2001. Revision 1.192 2004/02/08 17:48:59 jonas
  2002. * fixed regvars
  2003. Revision 1.191 2004/02/05 19:35:27 florian
  2004. * more x86-64 fixes
  2005. Revision 1.190 2004/02/05 01:24:08 florian
  2006. * several fixes to compile x86-64 system
  2007. Revision 1.189 2004/02/04 22:15:15 daniel
  2008. * Rtti generation moved to ncgutil
  2009. * Assmtai usage of symsym removed
  2010. * operator overloading cleanup up
  2011. Revision 1.188 2004/02/04 22:01:13 peter
  2012. * first try to get cpupara working for x86_64
  2013. Revision 1.187 2004/02/03 22:32:54 peter
  2014. * renamed xNNbittype to xNNinttype
  2015. * renamed registers32 to registersint
  2016. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  2017. Revision 1.186 2004/01/31 18:40:15 daniel
  2018. * Last steps before removal of aasmtai dependency in symsym can be
  2019. accomplished.
  2020. Revision 1.185 2004/01/31 17:45:17 peter
  2021. * Change several $ifdef i386 to x86
  2022. * Change several OS_32 to OS_INT/OS_ADDR
  2023. Revision 1.184 2004/01/21 21:01:34 peter
  2024. * fixed stackchecking for register calling
  2025. Revision 1.183 2004/01/17 15:55:10 jonas
  2026. * fixed allocation of parameters passed by reference for powerpc in
  2027. callee
  2028. Revision 1.182 2004/01/13 18:08:58 florian
  2029. * x86-64 compilation fixed
  2030. Revision 1.181 2004/01/12 22:11:38 peter
  2031. * use localalign info for alignment for locals and temps
  2032. * sparc fpu flags branching added
  2033. * moved powerpc copy_valye_openarray to generic
  2034. Revision 1.180 2003/12/28 21:57:43 jonas
  2035. * fixed procedures declared as "interrupt" for non-x86
  2036. Revision 1.179 2003/12/26 13:19:16 florian
  2037. * rtl and compiler compile with -Cfsse2
  2038. Revision 1.178 2003/12/26 00:32:21 florian
  2039. + fpu<->mm register conversion
  2040. Revision 1.177 2003/12/24 00:10:02 florian
  2041. - delete parameter in cg64 methods removed
  2042. Revision 1.176 2003/12/23 14:38:07 florian
  2043. + second_floataddsse implemented
  2044. Revision 1.175 2003/12/22 19:00:17 florian
  2045. * fixed some x86-64 issues
  2046. Revision 1.174 2003/12/07 16:28:30 jonas
  2047. * fixed typo found by Charlie
  2048. Revision 1.173 2003/12/06 01:15:22 florian
  2049. * reverted Peter's alloctemp patch; hopefully properly
  2050. Revision 1.172 2003/12/03 23:13:20 peter
  2051. * delayed paraloc allocation, a_param_*() gets extra parameter
  2052. if it needs to allocate temp or real paralocation
  2053. * optimized/simplified int-real loading
  2054. Revision 1.171 2003/11/30 19:35:29 florian
  2055. * fixed several arm related problems
  2056. Revision 1.170 2003/11/29 20:13:25 florian
  2057. * fixed several pi_do_call problems
  2058. Revision 1.169 2003/11/23 17:05:15 peter
  2059. * register calling is left-right
  2060. * parameter ordering
  2061. * left-right calling inserts result parameter last
  2062. Revision 1.168 2003/11/22 00:31:25 jonas
  2063. + extra allocations of function result regs for the optimiser
  2064. Revision 1.167 2003/11/11 21:10:12 peter
  2065. * remove temporary stdcall hack
  2066. Revision 1.166 2003/11/10 22:02:52 peter
  2067. * cross unit inlining fixed
  2068. Revision 1.165 2003/11/07 15:58:32 florian
  2069. * Florian's culmutative nr. 1; contains:
  2070. - invalid calling conventions for a certain cpu are rejected
  2071. - arm softfloat calling conventions
  2072. - -Sp for cpu dependend code generation
  2073. - several arm fixes
  2074. - remaining code for value open array paras on heap
  2075. Revision 1.164 2003/11/04 19:03:50 peter
  2076. * fixes for temp type patch
  2077. Revision 1.163 2003/11/04 15:35:13 peter
  2078. * fix for referencecounted temps
  2079. Revision 1.162 2003/10/25 11:34:02 florian
  2080. * fixed compilation of ppc system unit
  2081. Revision 1.161 2003/10/19 01:34:30 florian
  2082. * some ppc stuff fixed
  2083. * memory leak fixed
  2084. Revision 1.160 2003/10/17 15:08:34 peter
  2085. * commented out more obsolete constants
  2086. Revision 1.159 2003/10/17 14:38:32 peter
  2087. * 64k registers supported
  2088. * fixed some memory leaks
  2089. Revision 1.158 2003/10/10 17:48:13 peter
  2090. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  2091. * tregisteralloctor renamed to trgobj
  2092. * removed rgobj from a lot of units
  2093. * moved location_* and reference_* to cgobj
  2094. * first things for mmx register allocation
  2095. Revision 1.157 2003/10/09 21:31:37 daniel
  2096. * Register allocator splitted, ans abstract now
  2097. Revision 1.156 2003/10/07 18:18:16 peter
  2098. * fix register calling for assembler procedures
  2099. * fix result loading for assembler procedures
  2100. Revision 1.155 2003/10/07 15:17:07 peter
  2101. * inline supported again, LOC_REFERENCEs are used to pass the
  2102. parameters
  2103. * inlineparasymtable,inlinelocalsymtable removed
  2104. * exitlabel inserting fixed
  2105. Revision 1.154 2003/10/01 20:34:48 peter
  2106. * procinfo unit contains tprocinfo
  2107. * cginfo renamed to cgbase
  2108. * moved cgmessage to verbose
  2109. * fixed ppc and sparc compiles
  2110. Revision 1.153 2003/09/30 21:02:37 peter
  2111. * updates for inlining
  2112. Revision 1.152 2003/09/29 20:58:56 peter
  2113. * optimized releasing of registers
  2114. Revision 1.151 2003/09/28 21:47:18 peter
  2115. * register paras and local copies updates
  2116. Revision 1.150 2003/09/28 17:55:03 peter
  2117. * parent framepointer changed to hidden parameter
  2118. * tloadparentfpnode added
  2119. Revision 1.149 2003/09/28 13:39:38 peter
  2120. * optimized releasing of registers
  2121. Revision 1.148 2003/09/25 21:28:00 peter
  2122. * parameter fixes
  2123. Revision 1.147 2003/09/23 21:03:59 peter
  2124. * check for refs>0 in init/final local data
  2125. Revision 1.146 2003/09/23 17:56:05 peter
  2126. * locals and paras are allocated in the code generation
  2127. * tvarsym.localloc contains the location of para/local when
  2128. generating code for the current procedure
  2129. Revision 1.145 2003/09/16 16:17:01 peter
  2130. * varspez in calls to push_addr_param
  2131. Revision 1.144 2003/09/14 21:33:37 peter
  2132. * location_force_reg gives IE when size=OS_NO
  2133. Revision 1.143 2003/09/14 19:18:10 peter
  2134. * remove obsolete code already in comments
  2135. Revision 1.142 2003/09/11 11:54:59 florian
  2136. * improved arm code generation
  2137. * move some protected and private field around
  2138. * the temp. register for register parameters/arguments are now released
  2139. before the move to the parameter register is done. This improves
  2140. the code in a lot of cases.
  2141. Revision 1.141 2003/09/10 08:31:47 marco
  2142. * Patch from Peter for paraloc
  2143. Revision 1.140 2003/09/07 22:09:35 peter
  2144. * preparations for different default calling conventions
  2145. * various RA fixes
  2146. Revision 1.139 2003/09/03 15:55:01 peter
  2147. * NEWRA branch merged
  2148. Revision 1.138 2003/09/03 11:18:37 florian
  2149. * fixed arm concatcopy
  2150. + arm support in the common compiler sources added
  2151. * moved some generic cg code around
  2152. + tfputype added
  2153. * ...
  2154. Revision 1.137.2.4 2003/08/31 15:46:26 peter
  2155. * more updates for tregister
  2156. Revision 1.137.2.3 2003/08/29 17:28:59 peter
  2157. * next batch of updates
  2158. Revision 1.137.2.2 2003/08/28 18:35:08 peter
  2159. * tregister changed to cardinal
  2160. Revision 1.137.2.1 2003/08/27 19:55:54 peter
  2161. * first tregister patch
  2162. Revision 1.137 2003/08/20 20:29:06 daniel
  2163. * Some more R_NO changes
  2164. * Preventive code to loadref added
  2165. Revision 1.136 2003/08/20 17:48:49 peter
  2166. * fixed stackalloc to not allocate localst.datasize twice
  2167. * order of stackalloc code fixed for implicit init/final
  2168. Revision 1.135 2003/08/17 16:59:20 jonas
  2169. * fixed regvars so they work with newra (at least for ppc)
  2170. * fixed some volatile register bugs
  2171. + -dnotranslation option for -dnewra, which causes the registers not to
  2172. be translated from virtual to normal registers. Requires support in
  2173. the assembler writer as well, which is only implemented in aggas/
  2174. agppcgas currently
  2175. Revision 1.134 2003/08/11 21:18:20 peter
  2176. * start of sparc support for newra
  2177. Revision 1.133 2003/08/09 18:56:54 daniel
  2178. * cs_regalloc renamed to cs_regvars to avoid confusion with register
  2179. allocator
  2180. * Some preventive changes to i386 spillinh code
  2181. Revision 1.132 2003/08/03 14:09:50 daniel
  2182. * Fixed a register allocator bug
  2183. * Figured out why -dnewra generates superfluous "mov reg1,reg2"
  2184. statements: changes in location_force. These moves are now no longer
  2185. constrained so they are optimized away.
  2186. Revision 1.131 2003/07/23 11:04:15 jonas
  2187. * split en_exit_code into a part that may allocate a register and a part
  2188. that doesn't, so the former can be done before the register colouring
  2189. has been performed
  2190. Revision 1.130 2003/07/06 17:58:22 peter
  2191. * framepointer fixes for sparc
  2192. * parent framepointer code more generic
  2193. Revision 1.129 2003/07/06 15:31:20 daniel
  2194. * Fixed register allocator. *Lots* of fixes.
  2195. Revision 1.128 2003/07/02 22:18:04 peter
  2196. * paraloc splitted in callerparaloc,calleeparaloc
  2197. * sparc calling convention updates
  2198. Revision 1.127 2003/06/17 18:13:51 jonas
  2199. * fixed -dnewra compilation problems
  2200. Revision 1.126 2003/06/17 16:32:44 peter
  2201. * alloc register for function result
  2202. Revision 1.125 2003/06/13 21:19:30 peter
  2203. * current_procdef removed, use current_procinfo.procdef instead
  2204. Revision 1.124 2003/06/09 12:23:30 peter
  2205. * init/final of procedure data splitted from genentrycode
  2206. * use asmnode getposition to insert final at the correct position
  2207. als for the implicit try...finally
  2208. Revision 1.123 2003/06/07 18:57:04 jonas
  2209. + added freeintparaloc
  2210. * ppc get/freeintparaloc now check whether the parameter regs are
  2211. properly allocated/deallocated (and get an extra list para)
  2212. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  2213. * fixed lot of missing pi_do_call's
  2214. Revision 1.122 2003/06/06 14:43:02 peter
  2215. * g_copyopenarrayvalue gets length reference
  2216. * don't copy open arrays for cdecl
  2217. Revision 1.121 2003/06/03 21:11:09 peter
  2218. * cg.a_load_* get a from and to size specifier
  2219. * makeregsize only accepts newregister
  2220. * i386 uses generic tcgnotnode,tcgunaryminus
  2221. Revision 1.120 2003/06/03 15:49:49 jonas
  2222. * fixed ref/loc problems
  2223. Revision 1.119 2003/06/03 15:06:37 daniel
  2224. * fixed conflict marks
  2225. Revision 1.118 2003/06/03 13:01:59 daniel
  2226. * Register allocator finished
  2227. Revision 1.117 2003/06/02 21:42:05 jonas
  2228. * function results can now also be regvars
  2229. - removed tprocinfo.return_offset, never use it again since it's invalid
  2230. if the result is a regvar
  2231. Revision 1.116 2003/06/01 21:38:06 peter
  2232. * getregisterfpu size parameter added
  2233. * op_const_reg size parameter added
  2234. * sparc updates
  2235. Revision 1.115 2003/05/31 20:28:17 jonas
  2236. * changed copyvalueparas so it also supports register parameters
  2237. (except for copy_value_openarray, but that one is seriously broken
  2238. anyway, since it expects that the high parameter will always be in
  2239. memory right after the pointer to the array, while it could just as
  2240. will be in a register)
  2241. Revision 1.114 2003/05/31 15:05:28 peter
  2242. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  2243. Revision 1.113 2003/05/31 00:48:15 jonas
  2244. * fixed my previous commit
  2245. Revision 1.112 2003/05/30 23:57:08 peter
  2246. * more sparc cleanup
  2247. * accumulator removed, splitted in function_return_reg (called) and
  2248. function_result_reg (caller)
  2249. Revision 1.111 2003/05/30 23:49:18 jonas
  2250. * a_load_loc_reg now has an extra size parameter for the destination
  2251. register (properly fixes what I worked around in revision 1.106 of
  2252. ncgutil.pas)
  2253. Revision 1.110 2003/05/30 18:52:10 jonas
  2254. * fixed bug with intregvars
  2255. * locapara.loc can also be LOC_CFPUREGISTER -> also fixed
  2256. rcgppc.a_param_ref, which previously got bogus size values
  2257. Revision 1.109 2003/05/27 21:19:08 jonas
  2258. * fixed ppc cycle
  2259. Revision 1.108 2003/05/27 14:28:14 jonas
  2260. * patch from Peter for nested procedures
  2261. Revision 1.107 2003/05/26 21:17:17 peter
  2262. * procinlinenode removed
  2263. * aktexit2label removed, fast exit removed
  2264. + tcallnode.inlined_pass_2 added
  2265. Revision 1.106 2003/05/24 11:59:42 jonas
  2266. * fixed integer typeconversion problems
  2267. Revision 1.105 2003/05/23 14:27:35 peter
  2268. * remove some unit dependencies
  2269. * current_procinfo changes to store more info
  2270. Revision 1.104 2003/05/15 18:58:53 peter
  2271. * removed selfpointer_offset, vmtpointer_offset
  2272. * tvarsym.adjusted_address
  2273. * address in localsymtable is now in the real direction
  2274. * removed some obsolete globals
  2275. Revision 1.103 2003/05/14 19:37:25 jonas
  2276. * patch from Peter for int64 function results
  2277. Revision 1.102 2003/05/13 19:14:41 peter
  2278. * failn removed
  2279. * inherited result code check moven to pexpr
  2280. Revision 1.101 2003/05/13 15:16:13 peter
  2281. * removed ret_in_acc, it's the reverse of ret_in_param
  2282. * fixed ret_in_param for win32 cdecl array
  2283. Revision 1.100 2003/05/12 08:08:27 jonas
  2284. * fixed several initialization and finalization related bugs (missing
  2285. tg.direction's, wrong paralocation for decreasing refcount of
  2286. everything but ansistrings)
  2287. Revision 1.99 2003/05/11 21:37:03 peter
  2288. * moved implicit exception frame from ncgutil to psub
  2289. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2290. Revision 1.98 2003/05/11 14:45:12 peter
  2291. * tloadnode does not support objectsymtable,withsymtable anymore
  2292. * withnode cleanup
  2293. * direct with rewritten to use temprefnode
  2294. Revision 1.97 2003/05/10 13:20:23 jonas
  2295. * moved storing of register parameters to memory even earlier in the
  2296. entry code to fix problems with constructors
  2297. Revision 1.96 2003/05/09 17:47:02 peter
  2298. * self moved to hidden parameter
  2299. * removed hdisposen,hnewn,selfn
  2300. Revision 1.95 2003/04/29 07:28:52 michael
  2301. + Patch from peter to fix wrong pushing of ansistring function results in open array
  2302. Revision 1.94 2003/04/28 21:17:38 peter
  2303. * do not finalize function results
  2304. Revision 1.93 2003/04/27 16:30:34 jonas
  2305. * store register para's to memory before copying the valuepara's, because
  2306. that one requires them to be there already (and it calls subroutines ->
  2307. could overwrite those registers)
  2308. Revision 1.92 2003/04/27 11:21:33 peter
  2309. * aktprocdef renamed to current_procinfo.procdef
  2310. * procinfo renamed to current_procinfo
  2311. * procinfo will now be stored in current_module so it can be
  2312. cleaned up properly
  2313. * gen_main_procsym changed to create_main_proc and release_main_proc
  2314. to also generate a tprocinfo structure
  2315. * fixed unit implicit initfinal
  2316. Revision 1.91 2003/04/27 07:29:50 peter
  2317. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  2318. a new procdef declaration
  2319. * aktprocsym removed
  2320. * lexlevel removed, use symtable.symtablelevel instead
  2321. * implicit init/final code uses the normal genentry/genexit
  2322. * funcret state checking updated for new funcret handling
  2323. Revision 1.90 2003/04/26 17:21:08 florian
  2324. * fixed passing of fpu values by fpu register
  2325. Revision 1.89 2003/04/25 20:59:33 peter
  2326. * removed funcretn,funcretsym, function result is now in varsym
  2327. and aliases for result and function name are added using absolutesym
  2328. * vs_hidden parameter for funcret passed in parameter
  2329. * vs_hidden fixes
  2330. * writenode changed to printnode and released from extdebug
  2331. * -vp option added to generate a tree.log with the nodetree
  2332. * nicer printnode for statements, callnode
  2333. Revision 1.88 2003/04/23 12:35:34 florian
  2334. * fixed several issues with powerpc
  2335. + applied a patch from Jonas for nested function calls (PowerPC only)
  2336. * ...
  2337. Revision 1.87 2003/04/22 14:33:38 peter
  2338. * removed some notes/hints
  2339. Revision 1.86 2003/04/22 13:47:08 peter
  2340. * fixed C style array of const
  2341. * fixed C array passing
  2342. * fixed left to right with high parameters
  2343. Revision 1.85 2003/04/22 10:09:35 daniel
  2344. + Implemented the actual register allocator
  2345. + Scratch registers unavailable when new register allocator used
  2346. + maybe_save/maybe_restore unavailable when new register allocator used
  2347. Revision 1.84 2003/04/16 09:26:55 jonas
  2348. * assembler procedures now again get a stackframe if they have local
  2349. variables. No space is reserved for a function result however.
  2350. Also, the register parameters aren't automatically saved on the stack
  2351. anymore in assembler procedures.
  2352. Revision 1.83 2003/04/06 21:11:23 olle
  2353. * changed newasmsymbol to newasmsymboldata for data symbols
  2354. Revision 1.82 2003/03/30 20:59:07 peter
  2355. * fix classmethod from classmethod call
  2356. * move BeforeDestruction/AfterConstruction calls to
  2357. genentrycode/genexitcode instead of generating them on the fly
  2358. after a call to a constructor
  2359. Revision 1.81 2003/03/28 19:16:56 peter
  2360. * generic constructor working for i386
  2361. * remove fixed self register
  2362. * esi added as address register for i386
  2363. Revision 1.80 2003/03/17 15:52:20 peter
  2364. * fix range error
  2365. Revision 1.79 2003/03/11 21:46:24 jonas
  2366. * lots of new regallocator fixes, both in generic and ppc-specific code
  2367. (ppc compiler still can't compile the linux system unit though)
  2368. Revision 1.78 2003/02/26 21:15:43 daniel
  2369. * Fixed the optimizer
  2370. Revision 1.77 2003/02/19 22:00:14 daniel
  2371. * Code generator converted to new register notation
  2372. - Horribily outdated todo.txt removed
  2373. Revision 1.76 2003/02/15 22:17:38 carl
  2374. * bugfix of FPU emulation code
  2375. Revision 1.75 2003/01/09 22:00:53 florian
  2376. * fixed some PowerPC issues
  2377. Revision 1.74 2003/01/09 20:41:10 florian
  2378. * fixed broken PowerPC compiler
  2379. Revision 1.73 2003/01/08 18:43:56 daniel
  2380. * Tregister changed into a record
  2381. Revision 1.72 2002/12/29 23:51:43 florian
  2382. * web bug 2214 fixed: ie 10 in const array constructors
  2383. Revision 1.71 2002/12/24 15:56:50 peter
  2384. * stackpointer_alloc added for adjusting ESP. Win32 needs
  2385. this for the pageprotection
  2386. Revision 1.70 2002/12/05 14:39:21 florian
  2387. * added missing then, Carl did you really a make fullcycle :) ?
  2388. Revision 1.69 2002/12/03 22:13:39 carl
  2389. * bugfix of problems with profile code which clobbers some registers
  2390. Revision 1.68 2002/12/01 22:06:59 carl
  2391. * warning of portabilitiy problems with parasize / localsize
  2392. Revision 1.67 2002/11/30 18:44:57 carl
  2393. + profiling support for Win32
  2394. Revision 1.66 2002/11/30 14:39:15 carl
  2395. * try to fix profiling for win32
  2396. Revision 1.65 2002/11/28 23:28:14 florian
  2397. * push_value_para didn't release floatdef locations, fixes tw2045
  2398. Revision 1.64 2002/11/27 02:33:19 peter
  2399. * copy_value_on_stack method added for cdecl record passing
  2400. Revision 1.63 2002/11/25 17:43:18 peter
  2401. * splitted defbase in defutil,symutil,defcmp
  2402. * merged isconvertable and is_equal into compare_defs(_ext)
  2403. * made operator search faster by walking the list only once
  2404. Revision 1.62 2002/11/18 17:31:55 peter
  2405. * pass proccalloption to ret_in_xxx and push_xxx functions
  2406. Revision 1.61 2002/11/17 17:49:08 mazen
  2407. + 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
  2408. Revision 1.60 2002/11/17 16:31:56 carl
  2409. * memory optimization (3-4%) : cleanup of tai fields,
  2410. cleanup of tdef and tsym fields.
  2411. * make it work for m68k
  2412. Revision 1.59 2002/11/15 01:58:51 peter
  2413. * merged changes from 1.0.7 up to 04-11
  2414. - -V option for generating bug report tracing
  2415. - more tracing for option parsing
  2416. - errors for cdecl and high()
  2417. - win32 import stabs
  2418. - win32 records<=8 are returned in eax:edx (turned off by default)
  2419. - heaptrc update
  2420. - more info for temp management in .s file with EXTDEBUG
  2421. Revision 1.58 2002/11/10 19:07:45 mazen
  2422. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  2423. Revision 1.57 2002/11/03 20:22:40 mazen
  2424. * parameter handling updated
  2425. Revision 1.56 2002/10/16 19:01:43 peter
  2426. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  2427. implicit exception frames for procedures with initialized variables
  2428. and for constructors. The default is on for compatibility
  2429. Revision 1.55 2002/10/14 19:42:33 peter
  2430. * only use init tables for threadvars
  2431. Revision 1.54 2002/10/06 19:41:30 peter
  2432. * Add finalization of typed consts
  2433. * Finalization of globals in the main program
  2434. Revision 1.53 2002/10/05 15:18:42 carl
  2435. * fix heap leaks
  2436. Revision 1.52 2002/09/30 07:00:46 florian
  2437. * fixes to common code to get the alpha compiler compiled applied
  2438. Revision 1.51 2002/09/22 14:02:35 carl
  2439. * stack checking cannot be called before system unit is initialized
  2440. * MC68020 define
  2441. Revision 1.50 2002/09/17 18:54:03 jonas
  2442. * a_load_reg_reg() now has two size parameters: source and dest. This
  2443. allows some optimizations on architectures that don't encode the
  2444. register size in the register name.
  2445. Revision 1.49 2002/09/10 21:48:30 florian
  2446. * improved handling of procedures with register calling conventions
  2447. Revision 1.48 2002/09/07 15:25:03 peter
  2448. * old logs removed and tabs fixed
  2449. Revision 1.47 2002/09/02 18:44:48 peter
  2450. * fixed (not) pushing of empty parameters
  2451. * fixed implicit initialization/finalization generation
  2452. * fixed/optimized local copy of value arguments init/final
  2453. Revision 1.46 2002/09/01 19:27:34 peter
  2454. * use index register when available for generating a reference with
  2455. only a signle register. Using the base register could possibly
  2456. destroy the framepointer
  2457. Revision 1.45 2002/09/01 18:50:20 peter
  2458. * fixed maybe_save that did not support a reference with only
  2459. a index register. It now also updates the location with the new
  2460. base register only
  2461. Revision 1.44 2002/09/01 14:42:41 peter
  2462. * removevaluepara added to fix the stackpointer so restoring of
  2463. saved registers works
  2464. Revision 1.43 2002/08/25 19:25:18 peter
  2465. * sym.insert_in_data removed
  2466. * symtable.insertvardata/insertconstdata added
  2467. * removed insert_in_data call from symtable.insert, it needs to be
  2468. called separatly. This allows to deref the address calculation
  2469. * procedures now calculate the parast addresses after the procedure
  2470. directives are parsed. This fixes the cdecl parast problem
  2471. * push_addr_param has an extra argument that specifies if cdecl is used
  2472. or not
  2473. Revision 1.42 2002/08/24 18:38:26 peter
  2474. * really use tt_noreuse for exception frame buffers
  2475. Revision 1.41 2002/08/23 16:14:49 peter
  2476. * tempgen cleanup
  2477. * tt_noreuse temp type added that will be used in genentrycode
  2478. Revision 1.40 2002/08/18 10:42:37 florian
  2479. * remaining assembler writer bugs fixed, the errors in the
  2480. system unit are inline assembler problems
  2481. Revision 1.39 2002/08/17 09:23:36 florian
  2482. * first part of procinfo rewrite
  2483. Revision 1.38 2002/08/16 14:24:57 carl
  2484. * issameref() to test if two references are the same (then emit no opcodes)
  2485. + ret_in_reg to replace ret_in_acc
  2486. (fix some register allocation bugs at the same time)
  2487. + save_std_register now has an extra parameter which is the
  2488. usedinproc registers
  2489. Revision 1.37 2002/08/15 15:15:55 carl
  2490. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  2491. * more generic nodes for maths
  2492. * several fixes for better m68k support
  2493. Revision 1.36 2002/08/14 19:25:09 carl
  2494. * fix Florian's last commit for m68k compilation
  2495. Revision 1.35 2002/08/13 21:40:56 florian
  2496. * more fixes for ppc calling conventions
  2497. Revision 1.34 2002/08/12 15:08:39 carl
  2498. + stab register indexes for powerpc (moved from gdb to cpubase)
  2499. + tprocessor enumeration moved to cpuinfo
  2500. + linker in target_info is now a class
  2501. * many many updates for m68k (will soon start to compile)
  2502. - removed some ifdef or correct them for correct cpu
  2503. Revision 1.33 2002/08/11 14:32:27 peter
  2504. * renamed current_library to objectlibrary
  2505. Revision 1.32 2002/08/11 13:24:12 peter
  2506. * saving of asmsymbols in ppu supported
  2507. * asmsymbollist global is removed and moved into a new class
  2508. tasmlibrarydata that will hold the info of a .a file which
  2509. corresponds with a single module. Added librarydata to tmodule
  2510. to keep the library info stored for the module. In the future the
  2511. objectfiles will also be stored to the tasmlibrarydata class
  2512. * all getlabel/newasmsymbol and friends are moved to the new class
  2513. Revision 1.31 2002/08/09 19:16:57 carl
  2514. * stack allocation is now done separately (at the end) of genentrycode
  2515. so temps. can be allocated before.
  2516. * fix generic exception handling
  2517. Revision 1.30 2002/08/06 20:55:21 florian
  2518. * first part of ppc calling conventions fix
  2519. Revision 1.29 2002/08/04 19:09:22 carl
  2520. + added generic exception support (still does not work!)
  2521. + more documentation
  2522. Revision 1.28 2002/07/29 21:23:42 florian
  2523. * more fixes for the ppc
  2524. + wrappers for the tcnvnode.first_* stuff introduced
  2525. }