ncgutil.pas 92 KB

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