ncgutil.pas 90 KB

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