ncgutil.pas 92 KB

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