ncgutil.pas 92 KB

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