ncgutil.pas 99 KB

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