ncgutil.pas 92 KB

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