ncgcal.pas 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate i386 assembler for in call nodes
  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 ncgcal;
  19. {$i fpcdefs.inc}
  20. interface
  21. { $define AnsiStrRef}
  22. uses
  23. cpubase,
  24. globtype,
  25. symdef,node,ncal;
  26. type
  27. tcgcallparanode = class(tcallparanode)
  28. procedure secondcallparan(push_from_left_to_right:boolean;calloption:tproccalloption;
  29. para_alignment,para_offset : longint);override;
  30. end;
  31. tcgcallnode = class(tcallnode)
  32. private
  33. procedure release_para_temps;
  34. procedure normal_pass_2;
  35. procedure inlined_pass_2;
  36. protected
  37. refcountedtemp : treference;
  38. procedure handle_return_value;
  39. {# This routine is used to push the current frame pointer
  40. on the stack. This is used in nested routines where the
  41. value of the frame pointer is always pushed as an extra
  42. parameter.
  43. The default handling is the standard handling used on
  44. most stack based machines, where the frame pointer is
  45. the first invisible parameter.
  46. }
  47. function align_parasize:longint;virtual;
  48. procedure pop_parasize(pop_size:longint);virtual;
  49. procedure push_framepointer;virtual;
  50. procedure free_pushed_framepointer;virtual;
  51. procedure extra_interrupt_code;virtual;
  52. public
  53. procedure pass_2;override;
  54. end;
  55. implementation
  56. uses
  57. systems,
  58. cutils,verbose,globals,
  59. symconst,symbase,symsym,symtable,defutil,paramgr,
  60. {$ifdef GDB}
  61. {$ifdef delphi}
  62. sysutils,
  63. {$else}
  64. strings,
  65. {$endif}
  66. gdb,
  67. {$endif GDB}
  68. cginfo,cgbase,pass_2,
  69. cpuinfo,aasmbase,aasmtai,aasmcpu,
  70. nbas,nmem,nld,ncnv,
  71. {$ifdef x86}
  72. cga,
  73. {$endif x86}
  74. {$ifdef cpu64bit}
  75. cg64f64,
  76. {$else cpu64bit}
  77. cg64f32,
  78. {$endif cpu64bit}
  79. ncgutil,cgobj,tgobj,regvars,rgobj,rgcpu;
  80. {*****************************************************************************
  81. TCGCALLPARANODE
  82. *****************************************************************************}
  83. procedure tcgcallparanode.secondcallparan(push_from_left_to_right:boolean;calloption:tproccalloption;para_alignment,para_offset : longint);
  84. var
  85. otlabel,
  86. oflabel : tasmlabel;
  87. tmpreg : tregister;
  88. href : treference;
  89. begin
  90. if not(assigned(paraitem.paratype.def) or
  91. assigned(paraitem.parasym)) then
  92. internalerror(200304242);
  93. { set default para_alignment to target_info.stackalignment }
  94. if para_alignment=0 then
  95. para_alignment:=aktalignment.paraalign;
  96. { push from left to right if specified }
  97. if push_from_left_to_right and assigned(right) then
  98. begin
  99. tcallparanode(right).secondcallparan(push_from_left_to_right,
  100. calloption,para_alignment,para_offset);
  101. end;
  102. otlabel:=truelabel;
  103. oflabel:=falselabel;
  104. objectlibrary.getlabel(truelabel);
  105. objectlibrary.getlabel(falselabel);
  106. secondpass(left);
  107. { allocate paraloc }
  108. paramanager.allocparaloc(exprasmlist,paraitem.callerparaloc);
  109. { handle varargs first, because defcoll is not valid }
  110. if (nf_varargs_para in flags) then
  111. begin
  112. if paramanager.push_addr_param(left.resulttype.def,calloption) then
  113. begin
  114. inc(pushedparasize,POINTER_SIZE);
  115. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  116. location_release(exprasmlist,left.location);
  117. end
  118. else
  119. push_value_para(exprasmlist,left,calloption,para_offset,para_alignment,paraitem.callerparaloc);
  120. end
  121. { hidden parameters }
  122. else if paraitem.is_hidden then
  123. begin
  124. { don't push a node that already generated a pointer type
  125. by address for implicit hidden parameters }
  126. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  127. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  128. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  129. begin
  130. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  131. internalerror(200305071);
  132. inc(pushedparasize,POINTER_SIZE);
  133. if calloption=pocall_inline then
  134. begin
  135. {$ifdef newra}
  136. tmpreg:=rg.getaddressregister(exprasmlist);
  137. {$else}
  138. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  139. {$endif}
  140. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  141. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  142. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  143. {$ifdef newra}
  144. rg.ungetregisterint(exprasmlist,tmpreg);
  145. {$else}
  146. cg.free_scratch_reg(exprasmlist,tmpreg);
  147. {$endif}
  148. end
  149. else
  150. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  151. location_release(exprasmlist,left.location);
  152. end
  153. else
  154. begin
  155. push_value_para(exprasmlist,left,calloption,
  156. para_offset,para_alignment,paraitem.callerparaloc);
  157. end;
  158. end
  159. { filter array of const c styled args }
  160. else if is_array_of_const(left.resulttype.def) and (nf_cargs in left.flags) then
  161. begin
  162. { nothing, everything is already pushed }
  163. end
  164. { in codegen.handleread.. paraitem.data is set to nil }
  165. else if assigned(paraitem.paratype.def) and
  166. (paraitem.paratype.def.deftype=formaldef) then
  167. begin
  168. { allow passing of a constant to a const formaldef }
  169. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  170. (left.location.loc=LOC_CONSTANT) then
  171. location_force_mem(exprasmlist,left.location);
  172. { allow @var }
  173. inc(pushedparasize,POINTER_SIZE);
  174. if (left.nodetype=addrn) and
  175. (not(nf_procvarload in left.flags)) then
  176. begin
  177. if calloption=pocall_inline then
  178. begin
  179. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  180. cg.a_load_loc_ref(exprasmlist,OS_ADDR,left.location,href);
  181. end
  182. else
  183. cg.a_param_loc(exprasmlist,left.location,paraitem.callerparaloc);
  184. location_release(exprasmlist,left.location);
  185. end
  186. else
  187. begin
  188. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  189. internalerror(200304235);
  190. if calloption=pocall_inline then
  191. begin
  192. {$ifdef newra}
  193. tmpreg:=rg.getaddressregister(exprasmlist);
  194. {$else}
  195. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  196. {$endif newra}
  197. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  198. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  199. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  200. {$ifdef newra}
  201. rg.ungetregisterint(exprasmlist,tmpreg);
  202. {$else}
  203. cg.free_scratch_reg(exprasmlist,tmpreg);
  204. {$endif}
  205. end
  206. else
  207. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  208. location_release(exprasmlist,left.location);
  209. end;
  210. end
  211. { handle call by reference parameter }
  212. else if (paraitem.paratyp in [vs_var,vs_out]) then
  213. begin
  214. if (left.location.loc<>LOC_REFERENCE) then
  215. begin
  216. { passing self to a var parameter is allowed in
  217. TP and delphi }
  218. if not((left.location.loc=LOC_CREFERENCE) and
  219. is_self_node(left)) then
  220. internalerror(200106041);
  221. end;
  222. if (paraitem.paratyp=vs_out) and
  223. assigned(paraitem.paratype.def) and
  224. not is_class(paraitem.paratype.def) and
  225. paraitem.paratype.def.needs_inittable then
  226. cg.g_finalize(exprasmlist,paraitem.paratype.def,left.location.reference,false);
  227. inc(pushedparasize,POINTER_SIZE);
  228. if calloption=pocall_inline then
  229. begin
  230. {$ifdef newra}
  231. tmpreg:=rg.getaddressregister(exprasmlist);
  232. {$else}
  233. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  234. {$endif}
  235. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  236. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  237. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  238. {$ifdef newra}
  239. rg.ungetregisterint(exprasmlist,tmpreg);
  240. {$else}
  241. cg.free_scratch_reg(exprasmlist,tmpreg);
  242. {$endif}
  243. end
  244. else
  245. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  246. location_release(exprasmlist,left.location);
  247. end
  248. else
  249. begin
  250. { don't push a node that already generated a pointer type
  251. by address for implicit hidden parameters }
  252. if (not(
  253. paraitem.is_hidden and
  254. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  255. ) and
  256. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  257. begin
  258. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  259. begin
  260. { allow passing nil to a procvardef (methodpointer) }
  261. if (left.nodetype=typeconvn) and
  262. (left.resulttype.def.deftype=procvardef) and
  263. (ttypeconvnode(left).left.nodetype=niln) then
  264. begin
  265. tg.GetTemp(exprasmlist,tcgsize2size[left.location.size],tt_normal,href);
  266. if not (left.location.size in [OS_64,OS_S64]) then
  267. cg.a_load_loc_ref(exprasmlist,left.location.size,left.location,href)
  268. else
  269. cg64.a_load64_loc_ref(exprasmlist,left.location,href);
  270. location_reset(left.location,LOC_REFERENCE,left.location.size);
  271. left.location.reference:=href;
  272. end
  273. else
  274. internalerror(200204011);
  275. end;
  276. inc(pushedparasize,POINTER_SIZE);
  277. if calloption=pocall_inline then
  278. begin
  279. {$ifdef newra}
  280. tmpreg:=rg.getaddressregister(exprasmlist);
  281. {$else}
  282. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  283. {$endif}
  284. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  285. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  286. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,tmpreg,href);
  287. {$ifdef newra}
  288. rg.ungetregisterint(exprasmlist,tmpreg);
  289. {$else}
  290. cg.free_scratch_reg(exprasmlist,tmpreg);
  291. {$endif}
  292. end
  293. else
  294. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.callerparaloc);
  295. location_release(exprasmlist,left.location);
  296. end
  297. else
  298. begin
  299. push_value_para(exprasmlist,left,calloption,
  300. para_offset,para_alignment,paraitem.callerparaloc);
  301. end;
  302. end;
  303. truelabel:=otlabel;
  304. falselabel:=oflabel;
  305. { update return location in callnode when this is the function
  306. result }
  307. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  308. begin
  309. location_copy(aktcallnode.location,left.location);
  310. end;
  311. { push from right to left }
  312. if not push_from_left_to_right and assigned(right) then
  313. begin
  314. tcallparanode(right).secondcallparan(push_from_left_to_right,
  315. calloption,para_alignment,para_offset);
  316. end;
  317. end;
  318. {*****************************************************************************
  319. TCGCALLNODE
  320. *****************************************************************************}
  321. procedure tcgcallnode.extra_interrupt_code;
  322. begin
  323. end;
  324. function tcgcallnode.align_parasize:longint;
  325. begin
  326. result:=0;
  327. end;
  328. procedure tcgcallnode.pop_parasize(pop_size:longint);
  329. begin
  330. end;
  331. procedure tcgcallnode.push_framepointer;
  332. var
  333. href : treference;
  334. hregister : tregister;
  335. begin
  336. { this routine is itself not nested }
  337. if current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel) then
  338. begin
  339. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.parent_framepointer_offset);
  340. cg.a_param_ref(exprasmlist,OS_ADDR,href,paramanager.getintparaloc(exprasmlist,1));
  341. end
  342. { one nesting level }
  343. else if (current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  344. begin
  345. cg.a_param_reg(exprasmlist,OS_ADDR,current_procinfo.framepointer,paramanager.getintparaloc(exprasmlist,1));
  346. end
  347. { very complex nesting level ... }
  348. else if (current_procinfo.procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  349. begin
  350. hregister:=rg.getaddressregister(exprasmlist);
  351. cg.g_load_parent_framepointer(exprasmlist,tprocdef(procdefinition).parast,hregister);
  352. cg.a_param_reg(exprasmlist,OS_ADDR,hregister,paramanager.getintparaloc(exprasmlist,1));
  353. rg.ungetaddressregister(exprasmlist,hregister);
  354. end;
  355. end;
  356. procedure tcgcallnode.free_pushed_framepointer;
  357. begin
  358. paramanager.freeintparaloc(exprasmlist,1);
  359. end;
  360. procedure tcgcallnode.handle_return_value;
  361. var
  362. cgsize : tcgsize;
  363. r,hregister : tregister;
  364. href: treference;
  365. tempnode: tnode;
  366. begin
  367. { structured results are easy to handle.... }
  368. { needed also when result_no_used !! }
  369. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  370. begin
  371. { Location should be setup by the funcret para }
  372. if location.loc<>LOC_REFERENCE then
  373. internalerror(200304241);
  374. end
  375. else
  376. { ansi/widestrings must be registered, so we can dispose them }
  377. if is_ansistring(resulttype.def) or
  378. is_widestring(resulttype.def) then
  379. begin
  380. r.enum:=R_INTREGISTER;
  381. r.number:=NR_FUNCTION_RETURN_REG;
  382. {$ifdef newra}
  383. { the FUNCTION_RESULT_REG is already allocated }
  384. rg.ungetregisterint(exprasmlist,r);
  385. {$else}
  386. cg.a_reg_alloc(exprasmlist,r);
  387. {$endif}
  388. if not assigned(funcretnode) then
  389. begin
  390. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  391. location.reference:=refcountedtemp;
  392. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,r,location.reference);
  393. {$ifndef newra}
  394. cg.a_reg_dealloc(exprasmlist,r);
  395. {$endif newra}
  396. end
  397. else
  398. begin
  399. {$ifndef newra}
  400. tg.gettemp(exprasmlist,pointer_size,tt_normal,href);
  401. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,r,href);
  402. cg.a_reg_dealloc(exprasmlist,r);
  403. {$else newra}
  404. hregister := rg.getaddressregister(exprasmlist);
  405. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,r,hregister);
  406. {$endif newra}
  407. { in case of a regular funcretnode with ret_in_param, the }
  408. { original funcretnode isn't touched -> make sure it's }
  409. { the same here (not sure if it's necessary) }
  410. tempnode := funcretnode.getcopy;
  411. tempnode.pass_2;
  412. location := tempnode.location;
  413. tempnode.free;
  414. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference, false);
  415. {$ifndef newra}
  416. cg.a_load_ref_ref(exprasmlist,OS_ADDR,OS_ADDR,href,location.reference);
  417. { since we used a normal temp, it won't be finalized or }
  418. { decref'd later -> no need to zero it }
  419. tg.ungettemp(exprasmlist,href);
  420. {$else newra}
  421. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  422. rg.ungetregisterint(exprasmlist,hregister);
  423. {$endif newra}
  424. end;
  425. end
  426. else
  427. { we have only to handle the result if it is used }
  428. if (nf_return_value_used in flags) then
  429. begin
  430. if (resulttype.def.deftype=floatdef) then
  431. begin
  432. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  433. {$ifdef cpufpemu}
  434. if cs_fp_emulation in aktmoduleswitches then
  435. location.register.enum := FUNCTION_RESULT_REG
  436. else
  437. {$endif cpufpemu}
  438. location.register.enum:=FPU_RESULT_REG;
  439. {$ifdef x86}
  440. inc(trgcpu(rg).fpuvaroffset);
  441. {$else x86}
  442. hregister := rg.getregisterfpu(exprasmlist,location.size);
  443. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  444. location.register := hregister;
  445. {$endif x86}
  446. end
  447. else
  448. begin
  449. cgsize:=def_cgsize(resulttype.def);
  450. { an object constructor is a function with pointer result }
  451. if (procdefinition.proctypeoption=potype_constructor) then
  452. cgsize:=OS_ADDR;
  453. if cgsize<>OS_NO then
  454. begin
  455. location_reset(location,LOC_REGISTER,cgsize);
  456. {$ifndef cpu64bit}
  457. if cgsize in [OS_64,OS_S64] then
  458. begin
  459. { Move the function result to free registers, preferably the
  460. FUNCTION_RESULT_REG/FUNCTION_RESULTHIGH_REG, so no move is necessary.}
  461. r.enum:=R_INTREGISTER;
  462. r.number:=NR_FUNCTION_RESULT64_LOW_REG;
  463. hregister.enum:=R_INTREGISTER;
  464. hregister.number:=NR_FUNCTION_RESULT64_HIGH_REG;
  465. {$ifdef newra}
  466. { the FUNCTION_RESULT_LOW_REG/FUNCTION_RESULT_HIGH_REG
  467. are already allocated }
  468. rg.ungetregisterint(exprasmlist,r);
  469. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  470. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,r,location.registerlow);
  471. rg.ungetregisterint(exprasmlist,hregister);
  472. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  473. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,hregister,location.registerhigh);
  474. {$else newra}
  475. if RS_FUNCTION_RESULT64_LOW_REG in rg.unusedregsint then
  476. location.registerlow:=rg.getexplicitregisterint(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG)
  477. else
  478. cg.a_reg_alloc(exprasmlist,r);
  479. if RS_FUNCTION_RESULT64_HIGH_REG in rg.unusedregsint then
  480. location.registerhigh:=rg.getexplicitregisterint(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG)
  481. else
  482. cg.a_reg_alloc(exprasmlist,hregister);
  483. { do this after both low,high are allocated, else it is possible that
  484. low will be loaded in the register that still contains high }
  485. if location.registerlow.number=NR_NO then
  486. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  487. if location.registerhigh.number=NR_NO then
  488. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  489. cg64.a_load64_reg_reg(exprasmlist,joinreg64(r,hregister),
  490. location.register64{$ifdef newra},false{$endif});
  491. {$endif newra}
  492. end
  493. else
  494. {$endif cpu64bit}
  495. begin
  496. {Move the function result to a free register, preferably the
  497. FUNCTION_RESULT_REG, so no move is necessary.}
  498. r.enum:=R_INTREGISTER;
  499. r.number:=NR_FUNCTION_RESULT_REG;
  500. {$ifdef newra}
  501. { the FUNCTION_RESULT_REG is already allocated }
  502. rg.ungetregisterint(exprasmlist,r);
  503. { change register size after the unget because the getregister
  504. was done for the full register }
  505. r:=rg.makeregsize(r,cgsize);
  506. location.register:=rg.getregisterint(exprasmlist,cgsize);
  507. {$else newra}
  508. r.enum:=R_INTREGISTER;
  509. r.number:=NR_FUNCTION_RESULT_REG;
  510. r:=rg.makeregsize(r,cgsize);
  511. cg.a_reg_alloc(exprasmlist,r);
  512. if RS_FUNCTION_RESULT_REG in rg.unusedregsint then
  513. begin
  514. location.register:=rg.makeregsize(rg.getexplicitregisterint(
  515. exprasmlist,NR_FUNCTION_RESULT_REG),cgsize);
  516. end
  517. else
  518. location.register:=rg.getregisterint(exprasmlist,cgsize);
  519. {$endif newra}
  520. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,r,location.register);
  521. end;
  522. end
  523. else
  524. begin
  525. if resulttype.def.size>0 then
  526. internalerror(200305131);
  527. end;
  528. end;
  529. end
  530. else
  531. begin
  532. {$ifdef newra}
  533. cgsize:=def_cgsize(resulttype.def);
  534. { an object constructor is a function with pointer result }
  535. if (procdefinition.proctypeoption=potype_constructor) then
  536. cgsize:=OS_ADDR;
  537. if cgsize<>OS_NO then
  538. {$ifndef cpu64bit}
  539. if cgsize in [OS_64,OS_S64] then
  540. begin
  541. r.enum:=R_INTREGISTER;
  542. r.number:=NR_FUNCTION_RESULT64_LOW_REG;
  543. hregister.enum:=R_INTREGISTER;
  544. hregister.number:=NR_FUNCTION_RESULT64_HIGH_REG;
  545. rg.ungetregisterint(exprasmlist,r);
  546. rg.ungetregisterint(exprasmlist,hregister);
  547. end
  548. else
  549. {$endif cpu64bit}
  550. begin
  551. r.enum:=R_INTREGISTER;
  552. r.number:=NR_FUNCTION_RESULT_REG;
  553. rg.ungetregisterint(exprasmlist,r);
  554. end;
  555. {$endif newra}
  556. location_reset(location,LOC_VOID,OS_NO);
  557. end;
  558. end;
  559. procedure tcgcallnode.release_para_temps;
  560. var
  561. hp : tnode;
  562. ppn : tcallparanode;
  563. begin
  564. { Release temps from parameters }
  565. ppn:=tcallparanode(left);
  566. while assigned(ppn) do
  567. begin
  568. if assigned(ppn.left) then
  569. begin
  570. { don't release the funcret temp }
  571. if not(vo_is_funcret in tvarsym(ppn.paraitem.parasym).varoptions) then
  572. begin
  573. {$ifdef callparatemp}
  574. { free call-by-reference temps }
  575. if (ppn.left.nodetype = typeconvn) and
  576. (ttypeconvnode(ppn.left).left.nodetype = derefn) and
  577. (tderefnode(ttypeconvnode(ppn.left).left).left.nodetype = temprefn) then
  578. location_freetemp(exprasmlist,tderefnode(ttypeconvnode(ppn.left).left).left.location)
  579. else
  580. {$endif callparatemp}
  581. location_freetemp(exprasmlist,ppn.left.location);
  582. end;
  583. { process also all nodes of an array of const }
  584. if ppn.left.nodetype=arrayconstructorn then
  585. begin
  586. if assigned(tarrayconstructornode(ppn.left).left) then
  587. begin
  588. hp:=ppn.left;
  589. while assigned(hp) do
  590. begin
  591. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  592. hp:=tarrayconstructornode(hp).right;
  593. end;
  594. end;
  595. end;
  596. end;
  597. ppn:=tcallparanode(ppn.right);
  598. end;
  599. end;
  600. procedure tcgcallnode.normal_pass_2;
  601. var
  602. regs_to_push_other : tregisterset;
  603. unusedstate: pointer;
  604. {$ifdef newra}
  605. i:Tsuperregister;
  606. regs_to_alloc,regs_to_free:Tsupregset;
  607. funcretloc: tparalocation;
  608. {$else}
  609. regs_to_push_int : Tsupregset;
  610. pushedint : tpushedsavedint;
  611. pushedregs : tmaybesave;
  612. {$endif}
  613. pushedother : tpushedsavedother;
  614. oldpushedparasize : longint;
  615. { adress returned from an I/O-error }
  616. iolabel : tasmlabel;
  617. { help reference pointer }
  618. href,helpref : treference;
  619. para_alignment,
  620. pop_size : longint;
  621. r,
  622. {$ifdef x86}
  623. accreg,
  624. {$endif x86}
  625. vmtreg,vmtreg2 : tregister;
  626. oldaktcallnode : tcallnode;
  627. procedure freeparas;
  628. var
  629. paraitem : tparaitem;
  630. begin
  631. { free the resources allocated for the parameters }
  632. paraitem:=tparaitem(procdefinition.para.first);
  633. while assigned(paraitem) do
  634. begin
  635. paramanager.freeparaloc(exprasmlist,paraitem.callerparaloc);
  636. paraitem:=tparaitem(paraitem.next);
  637. end;
  638. { free pushed base pointer }
  639. if (right=nil) and
  640. (current_procinfo.procdef.parast.symtablelevel>=normal_function_level) and
  641. assigned(tprocdef(procdefinition).parast) and
  642. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  643. free_pushed_framepointer;
  644. end;
  645. begin
  646. if not assigned(procdefinition) then
  647. internalerror(200305264);
  648. { calculate the parameter info for the procdef }
  649. if not procdefinition.has_paraloc_info then
  650. begin
  651. paramanager.create_paraloc_info(procdefinition,callerside);
  652. procdefinition.has_paraloc_info:=true;
  653. end;
  654. iolabel:=nil;
  655. rg.saveunusedstate(unusedstate);
  656. if not assigned(funcretnode) then
  657. begin
  658. { if we allocate the temp. location for ansi- or widestrings }
  659. { already here, we avoid later a push/pop }
  660. if is_widestring(resulttype.def) then
  661. begin
  662. tg.gettemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  663. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  664. end
  665. else if is_ansistring(resulttype.def) then
  666. begin
  667. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  668. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  669. end;
  670. end;
  671. if (procdefinition.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_stdcall]) then
  672. para_alignment:=4
  673. else
  674. para_alignment:=aktalignment.paraalign;
  675. { proc variables destroy all registers }
  676. if (right=nil) and
  677. { virtual methods too }
  678. not(po_virtualmethod in procdefinition.procoptions) then
  679. begin
  680. if (cs_check_io in aktlocalswitches) and
  681. (po_iocheck in procdefinition.procoptions) and
  682. not(po_iocheck in current_procinfo.procdef.procoptions) then
  683. begin
  684. objectlibrary.getaddrlabel(iolabel);
  685. cg.a_label(exprasmlist,iolabel);
  686. end
  687. else
  688. iolabel:=nil;
  689. {$ifdef newra}
  690. regs_to_alloc:=Tprocdef(procdefinition).usedintregisters;
  691. if (not is_void(resulttype.def)) and
  692. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  693. begin
  694. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  695. case funcretloc.loc of
  696. LOC_REGISTER,LOC_CREGISTER:
  697. begin
  698. {$ifndef cpu64bit}
  699. if funcretloc.size in [OS_S64,OS_64] then
  700. begin
  701. include(regs_to_alloc,funcretloc.registerlow.number shr 8);
  702. include(regs_to_alloc,funcretloc.registerhigh.number shr 8);
  703. end
  704. else
  705. {$endif cpu64bit}
  706. include(regs_to_alloc,funcretloc.register.number shr 8);
  707. end;
  708. end;
  709. end;
  710. {$else}
  711. { save all used registers and possible registers
  712. used for the return value }
  713. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  714. if (not is_void(resulttype.def)) and
  715. (not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  716. begin
  717. {$ifndef cpu64bit}
  718. if resulttype.def.deftype<>floatdef then
  719. if resulttype.def.size>sizeof(aword) then
  720. begin
  721. include(regs_to_push_int,RS_FUNCTION_RESULT64_LOW_REG);
  722. include(regs_to_push_int,RS_FUNCTION_RESULT64_HIGH_REG);
  723. end
  724. else
  725. {$endif cpu64bit}
  726. include(regs_to_push_int,RS_FUNCTION_RESULT_REG);
  727. end;
  728. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  729. {$endif}
  730. {$ifdef i386}
  731. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  732. {$else i386}
  733. regs_to_push_other := [];
  734. {$endif i386}
  735. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  736. { on the ppc, ever procedure saves the non-volatile registers it uses itself }
  737. { and must make sure it saves its volatile registers before doing a call }
  738. {$ifdef i386}
  739. { give used registers through }
  740. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  741. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  742. {$endif i386}
  743. end
  744. else
  745. begin
  746. {No procedure is allowed to destroy ebp.}
  747. {$ifdef newra}
  748. regs_to_alloc:=VOLATILE_INTREGISTERS;
  749. if (not is_void(resulttype.def)) and
  750. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  751. begin
  752. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  753. case funcretloc.loc of
  754. LOC_REGISTER,LOC_CREGISTER:
  755. begin
  756. {$ifndef cpu64bit}
  757. if funcretloc.size in [OS_S64,OS_64] then
  758. begin
  759. include(regs_to_alloc,funcretloc.registerlow.number shr 8);
  760. include(regs_to_alloc,funcretloc.registerhigh.number shr 8);
  761. end
  762. else
  763. {$endif cpu64bit}
  764. include(regs_to_alloc,funcretloc.register.number shr 8);
  765. end;
  766. end;
  767. end;
  768. {$else}
  769. regs_to_push_int := VOLATILE_INTREGISTERS;
  770. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  771. {$endif}
  772. {$ifdef i386}
  773. regs_to_push_other := all_registers;
  774. {$else i386}
  775. regs_to_push_other := [];
  776. {$endif i386}
  777. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  778. {$ifdef i386}
  779. rg.used_in_proc_other:=all_registers;
  780. {$endif i386}
  781. { no IO check for methods and procedure variables }
  782. iolabel:=nil;
  783. end;
  784. { Initialize for pushing the parameters }
  785. oldpushedparasize:=pushedparasize;
  786. pushedparasize:=0;
  787. { Align stack if required }
  788. pop_size:=align_parasize;
  789. { Push parameters }
  790. oldaktcallnode:=aktcallnode;
  791. aktcallnode:=self;
  792. {$ifndef i386}
  793. { process procvar. Done here already, because otherwise it may }
  794. { destroy registers containing a parameter for the actual }
  795. { function call (e.g. if it's a function, its result will }
  796. { overwrite r3, which contains the first parameter) (JM) }
  797. if assigned(right) then
  798. secondpass(right);
  799. if (po_virtualmethod in procdefinition.procoptions) and
  800. assigned(methodpointer) then
  801. begin
  802. secondpass(methodpointer);
  803. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  804. { virtual methods require an index }
  805. if tprocdef(procdefinition).extnumber=-1 then
  806. internalerror(200304021);
  807. { VMT should already be loaded in a register }
  808. if methodpointer.location.register.number=NR_NO then
  809. internalerror(200304022);
  810. { test validity of VMT }
  811. if not(is_interface(tprocdef(procdefinition)._class)) and
  812. not(is_cppclass(tprocdef(procdefinition)._class)) then
  813. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  814. end;
  815. {$endif not i386}
  816. if assigned(left) then
  817. begin
  818. {$ifndef newra}
  819. if assigned(right) then
  820. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  821. else
  822. if assigned(methodpointer) then
  823. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  824. {$endif}
  825. tcallparanode(left).secondcallparan(
  826. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  827. para_alignment,0);
  828. {$ifndef newra}
  829. if assigned(right) then
  830. maybe_restore(exprasmlist,right.location,pushedregs)
  831. else
  832. if assigned(methodpointer) then
  833. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  834. {$endif newra}
  835. end;
  836. aktcallnode:=oldaktcallnode;
  837. { procedure variable or normal function call ? }
  838. if (right=nil) then
  839. begin
  840. { push base pointer ?}
  841. if (current_procinfo.procdef.parast.symtablelevel>=normal_function_level) and
  842. assigned(tprocdef(procdefinition).parast) and
  843. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  844. push_framepointer;
  845. {$ifndef newra}
  846. rg.saveintregvars(exprasmlist,regs_to_push_int);
  847. {$endif}
  848. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  849. if (po_virtualmethod in procdefinition.procoptions) and
  850. assigned(methodpointer) then
  851. begin
  852. {$ifdef i386}
  853. secondpass(methodpointer);
  854. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  855. vmtreg:=methodpointer.location.register;
  856. { virtual methods require an index }
  857. if tprocdef(procdefinition).extnumber=-1 then
  858. internalerror(200304021);
  859. { VMT should already be loaded in a register }
  860. if vmtreg.number=NR_NO then
  861. internalerror(200304022);
  862. { test validity of VMT }
  863. if not(is_interface(tprocdef(procdefinition)._class)) and
  864. not(is_cppclass(tprocdef(procdefinition)._class)) then
  865. cg.g_maybe_testvmt(exprasmlist,vmtreg,tprocdef(procdefinition)._class);
  866. {$else}
  867. vmtreg:=methodpointer.location.register;
  868. {$endif}
  869. {$ifdef newra}
  870. { release self }
  871. rg.ungetaddressregister(exprasmlist,vmtreg);
  872. vmtreg2:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  873. rg.ungetregisterint(exprasmlist,vmtreg2);
  874. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,vmtreg,vmtreg2);
  875. {$endif newra}
  876. { free the resources allocated for the parameters }
  877. freeparas;
  878. {$ifdef newra}
  879. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  880. {$endif}
  881. { call method }
  882. reference_reset_base(href,{$ifdef newra}vmtreg2{$else}vmtreg{$endif},
  883. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  884. cg.a_call_ref(exprasmlist,href);
  885. {$ifndef newra}
  886. { release self }
  887. rg.ungetaddressregister(exprasmlist,vmtreg);
  888. {$endif}
  889. end
  890. else
  891. begin
  892. { free the resources allocated for the parameters }
  893. freeparas;
  894. {$ifdef newra}
  895. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  896. {$endif}
  897. { Calling interrupt from the same code requires some
  898. extra code }
  899. if (po_interrupt in procdefinition.procoptions) then
  900. extra_interrupt_code;
  901. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  902. end;
  903. end
  904. else
  905. { now procedure variable case }
  906. begin
  907. {$ifdef i386}
  908. secondpass(right);
  909. {$endif i386}
  910. {$ifdef newra}
  911. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  912. begin
  913. helpref:=right.location.reference;
  914. if (helpref.index.number<>NR_NO) and (helpref.index.number<>NR_FRAME_POINTER_REG) then
  915. begin
  916. rg.ungetregisterint(exprasmlist,helpref.index);
  917. helpref.index:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  918. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,
  919. right.location.reference.index,helpref.index);
  920. end;
  921. if (helpref.base.number<>NR_NO) and (helpref.base.number<>NR_FRAME_POINTER_REG) then
  922. begin
  923. rg.ungetregisterint(exprasmlist,helpref.base);
  924. helpref.base:=rg.getabtregisterint(exprasmlist,OS_ADDR);
  925. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,
  926. right.location.reference.base,helpref.base);
  927. end;
  928. end
  929. else
  930. rg.ungetregisterint(exprasmlist,right.location.register);
  931. reference_release(exprasmlist,helpref);
  932. location_freetemp(exprasmlist,right.location);
  933. {$endif newra}
  934. { free the resources allocated for the parameters }
  935. freeparas;
  936. {$ifdef newra}
  937. rg.allocexplicitregistersint(exprasmlist,regs_to_alloc);
  938. {$endif}
  939. { Calling interrupt from the same code requires some
  940. extra code }
  941. if (po_interrupt in procdefinition.procoptions) then
  942. extra_interrupt_code;
  943. {$ifndef newra}
  944. helpref:=right.location.reference;
  945. rg.saveintregvars(exprasmlist,VOLATILE_INTREGISTERS);
  946. {$endif}
  947. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  948. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  949. cg.a_call_ref(exprasmlist,helpref)
  950. else
  951. cg.a_call_reg(exprasmlist,right.location.register);
  952. { cg.a_call_loc(exprasmlist,right.location);}
  953. location_release(exprasmlist,right.location);
  954. location_freetemp(exprasmlist,right.location);
  955. end;
  956. { Need to remove the parameters from the stack? }
  957. if (po_clearstack in procdefinition.procoptions) then
  958. begin
  959. { the old pop_size was already included in pushedparasize }
  960. pop_size:=pushedparasize;
  961. { for Cdecl functions we don't need to pop the funcret when it
  962. was pushed by para }
  963. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  964. dec(pop_size,POINTER_SIZE);
  965. end;
  966. { Remove parameters/alignment from the stack }
  967. if pop_size>0 then
  968. pop_parasize(pop_size);
  969. { Reserve space for storing parameters that will be pushed }
  970. current_procinfo.allocate_push_parasize(pushedparasize);
  971. { Restore }
  972. pushedparasize:=oldpushedparasize;
  973. rg.restoreunusedstate(unusedstate);
  974. {$ifdef TEMPREGDEBUG}
  975. testregisters32;
  976. {$endif TEMPREGDEBUG}
  977. {$ifdef newra}
  978. regs_to_free:=regs_to_alloc;
  979. if (not is_void(resulttype.def)) and
  980. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  981. begin
  982. case funcretloc.loc of
  983. LOC_REGISTER,LOC_CREGISTER:
  984. begin
  985. {$ifndef cpu64bit}
  986. if funcretloc.size in [OS_S64,OS_64] then
  987. begin
  988. exclude(regs_to_free,funcretloc.registerlow.number shr 8);
  989. exclude(regs_to_free,funcretloc.registerhigh.number shr 8);
  990. end
  991. else
  992. {$endif cpu64bit}
  993. exclude(regs_to_free,funcretloc.register.number shr 8);
  994. end;
  995. end;
  996. end;
  997. rg.deallocexplicitregistersint(exprasmlist,regs_to_free);
  998. {$endif}
  999. { handle function results }
  1000. if (not is_void(resulttype.def)) then
  1001. handle_return_value
  1002. else
  1003. location_reset(location,LOC_VOID,OS_NO);
  1004. { perhaps i/o check ? }
  1005. if iolabel<>nil then
  1006. begin
  1007. reference_reset_symbol(href,iolabel,0);
  1008. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1009. paramanager.freeintparaloc(exprasmlist,1);
  1010. {$ifdef newra}
  1011. rg.allocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1012. {$endif newra}
  1013. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1014. {$ifdef newra}
  1015. rg.deallocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1016. {$endif newra}
  1017. end;
  1018. { restore registers }
  1019. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1020. {$ifndef newra}
  1021. rg.restoreusedintregisters(exprasmlist,pushedint);
  1022. {$endif}
  1023. { release temps of paras }
  1024. release_para_temps;
  1025. { if return value is not used }
  1026. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  1027. begin
  1028. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1029. begin
  1030. { data which must be finalized ? }
  1031. if (resulttype.def.needs_inittable) then
  1032. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1033. { release unused temp }
  1034. tg.ungetiftemp(exprasmlist,location.reference)
  1035. end
  1036. else if location.loc=LOC_FPUREGISTER then
  1037. begin
  1038. {$ifdef x86}
  1039. { release FPU stack }
  1040. accreg.enum:=FPU_RESULT_REG;
  1041. emit_reg(A_FSTP,S_NO,accreg);
  1042. {
  1043. dec(trgcpu(rg).fpuvaroffset);
  1044. do NOT decrement as the increment before
  1045. is not called for unused results PM }
  1046. {$endif x86}
  1047. end;
  1048. end;
  1049. end;
  1050. procedure tcgcallnode.inlined_pass_2;
  1051. var
  1052. regs_to_push_int : Tsupregset;
  1053. regs_to_push_other : tregisterset;
  1054. unusedstate: pointer;
  1055. pushedother : tpushedsavedother;
  1056. {$ifndef newra}
  1057. pushedint : tpushedsavedint;
  1058. pushedregs : tmaybesave;
  1059. {$endif}
  1060. funcretloc: tparalocation;
  1061. oldpushedparasize : longint;
  1062. { adress returned from an I/O-error }
  1063. iolabel : tasmlabel;
  1064. { help reference pointer }
  1065. href : treference;
  1066. {$ifdef x86}
  1067. accreg : tregister;
  1068. {$endif x86}
  1069. oldaktcallnode : tcallnode;
  1070. oldprocdef : tprocdef;
  1071. i : longint;
  1072. oldprocinfo : tprocinfo;
  1073. oldinlining_procedure : boolean;
  1074. inlineentrycode,inlineexitcode : TAAsmoutput;
  1075. oldregstate: pointer;
  1076. old_local_fixup,
  1077. old_para_fixup : longint;
  1078. usesacc,usesacchi,usesfpu : boolean;
  1079. pararef,
  1080. localsref : treference;
  1081. {$ifdef GDB}
  1082. startlabel,endlabel : tasmlabel;
  1083. pp : pchar;
  1084. mangled_length : longint;
  1085. {$endif GDB}
  1086. begin
  1087. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  1088. internalerror(200305262);
  1089. oldinlining_procedure:=inlining_procedure;
  1090. oldprocdef:=current_procinfo.procdef;
  1091. oldprocinfo:=current_procinfo;
  1092. { we're inlining a procedure }
  1093. inlining_procedure:=true;
  1094. { calculate the parameter info for the procdef }
  1095. if not procdefinition.has_paraloc_info then
  1096. begin
  1097. paramanager.create_paraloc_info(procdefinition,callerside);
  1098. procdefinition.has_paraloc_info:=true;
  1099. end;
  1100. { deallocate the registers used for the current procedure's regvars }
  1101. if assigned(current_procinfo.procdef.regvarinfo) then
  1102. begin
  1103. with pregvarinfo(current_procinfo.procdef.regvarinfo)^ do
  1104. for i := 1 to maxvarregs do
  1105. if assigned(regvars[i]) then
  1106. store_regvar(exprasmlist,regvars[i].reg);
  1107. rg.saveStateForInline(oldregstate);
  1108. { make sure the register allocator knows what the regvars in the }
  1109. { inlined code block are (JM) }
  1110. rg.resetusableregisters;
  1111. rg.clearregistercount;
  1112. {$ifndef newra}
  1113. rg.cleartempgen;
  1114. {$endif}
  1115. if assigned(tprocdef(procdefinition).regvarinfo) then
  1116. with pregvarinfo(tprocdef(procdefinition).regvarinfo)^ do
  1117. for i := 1 to maxvarregs do
  1118. if assigned(regvars[i]) then
  1119. begin
  1120. {Fix me!!}
  1121. {tmpreg:=rg.makeregsize(regvars[i].reg,OS_INT);
  1122. rg.makeregvar(tmpreg);}
  1123. internalerror(200301232);
  1124. end;
  1125. end;
  1126. { create temp procinfo }
  1127. current_procinfo:=cprocinfo.create(nil);
  1128. current_procinfo.procdef:=tprocdef(procdefinition);
  1129. { Localsymtable }
  1130. current_procinfo.procdef.localst.symtablelevel:=oldprocdef.localst.symtablelevel;
  1131. if current_procinfo.procdef.localst.datasize>0 then
  1132. begin
  1133. old_local_fixup:=current_procinfo.procdef.localst.address_fixup;
  1134. tg.GetTemp(exprasmlist,current_procinfo.procdef.localst.datasize,tt_persistent,localsref);
  1135. if tg.direction>0 then
  1136. current_procinfo.procdef.localst.address_fixup:=localsref.offset
  1137. else
  1138. current_procinfo.procdef.localst.address_fixup:=localsref.offset+current_procinfo.procdef.localst.datasize;
  1139. {$ifdef extdebug}
  1140. Comment(V_debug,'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup));
  1141. exprasmList.concat(tai_comment.Create(strpnew(
  1142. 'inlined local symtable ('+tostr(current_procinfo.procdef.localst.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.localst.address_fixup))));
  1143. {$endif extdebug}
  1144. end;
  1145. { Parasymtable }
  1146. current_procinfo.procdef.parast.symtablelevel:=oldprocdef.localst.symtablelevel;
  1147. if current_procinfo.procdef.parast.datasize>0 then
  1148. begin
  1149. old_para_fixup:=current_procinfo.procdef.parast.address_fixup;
  1150. tg.GetTemp(exprasmlist,current_procinfo.procdef.parast.datasize,tt_persistent,pararef);
  1151. current_procinfo.procdef.parast.address_fixup:=pararef.offset;
  1152. {$ifdef extdebug}
  1153. Comment(V_debug,'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup));
  1154. exprasmList.concat(tai_comment.Create(strpnew(
  1155. 'inlined para symtable ('+tostr(current_procinfo.procdef.parast.datasize)+' bytes) is at offset '+tostr(current_procinfo.procdef.parast.address_fixup))));
  1156. {$endif extdebug}
  1157. end;
  1158. exprasmList.concat(Tai_Marker.Create(InlineStart));
  1159. {$ifdef extdebug}
  1160. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  1161. {$endif extdebug}
  1162. {$ifdef GDB}
  1163. if (cs_debuginfo in aktmoduleswitches) then
  1164. begin
  1165. objectlibrary.getaddrlabel(startlabel);
  1166. objectlibrary.getaddrlabel(endlabel);
  1167. cg.a_label(exprasmlist,startlabel);
  1168. tprocdef(procdefinition).localst.symtabletype:=inlinelocalsymtable;
  1169. procdefinition.parast.symtabletype:=inlineparasymtable;
  1170. { Here we must include the para and local symtable info }
  1171. procdefinition.concatstabto(withdebuglist);
  1172. { set it back for safety }
  1173. tprocdef(procdefinition).localst.symtabletype:=localsymtable;
  1174. procdefinition.parast.symtabletype:=parasymtable;
  1175. mangled_length:=length(oldprocdef.mangledname);
  1176. getmem(pp,mangled_length+50);
  1177. strpcopy(pp,'192,0,0,'+startlabel.name);
  1178. if (target_info.use_function_relative_addresses) then
  1179. begin
  1180. strpcopy(strend(pp),'-');
  1181. strpcopy(strend(pp),oldprocdef.mangledname);
  1182. end;
  1183. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1184. end;
  1185. {$endif GDB}
  1186. iolabel:=nil;
  1187. rg.saveunusedstate(unusedstate);
  1188. { if we allocate the temp. location for ansi- or widestrings }
  1189. { already here, we avoid later a push/pop }
  1190. if is_widestring(resulttype.def) then
  1191. begin
  1192. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  1193. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1194. end
  1195. else if is_ansistring(resulttype.def) then
  1196. begin
  1197. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  1198. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  1199. end;
  1200. if (cs_check_io in aktlocalswitches) and
  1201. (po_iocheck in procdefinition.procoptions) and
  1202. not(po_iocheck in current_procinfo.procdef.procoptions) then
  1203. begin
  1204. objectlibrary.getaddrlabel(iolabel);
  1205. cg.a_label(exprasmlist,iolabel);
  1206. end
  1207. else
  1208. iolabel:=nil;
  1209. { save all used registers and possible registers
  1210. used for the return value }
  1211. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  1212. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  1213. if (not is_void(resulttype.def)) and
  1214. not(paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  1215. begin
  1216. funcretloc := paramanager.getfuncretparaloc(procdefinition);
  1217. case funcretloc.loc of
  1218. LOC_REGISTER,LOC_CREGISTER:
  1219. begin
  1220. {$ifndef cpu64bit}
  1221. if funcretloc.size in [OS_S64,OS_64] then
  1222. begin
  1223. include(regs_to_push_int,funcretloc.registerlow.number shr 8);
  1224. include(regs_to_push_int,funcretloc.registerhigh.number shr 8);
  1225. end
  1226. else
  1227. {$endif cpu64bit}
  1228. include(regs_to_push_int,funcretloc.register.number shr 8);
  1229. end;
  1230. end;
  1231. end;
  1232. {$ifndef newra}
  1233. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  1234. {$endif}
  1235. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  1236. {$ifdef i386}
  1237. { give used registers through }
  1238. rg.used_in_proc_int:=rg.used_in_proc_int + tprocdef(procdefinition).usedintregisters;
  1239. rg.used_in_proc_other:=rg.used_in_proc_other + tprocdef(procdefinition).usedotherregisters;
  1240. {$endif i386}
  1241. { Initialize for pushing the parameters }
  1242. oldpushedparasize:=pushedparasize;
  1243. pushedparasize:=0;
  1244. { Push parameters }
  1245. oldaktcallnode:=aktcallnode;
  1246. aktcallnode:=self;
  1247. if assigned(left) then
  1248. begin
  1249. {$ifndef newra}
  1250. if assigned(right) then
  1251. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  1252. else
  1253. if assigned(methodpointer) then
  1254. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  1255. {$endif}
  1256. { we push from right to left, so start with parameters at the end of
  1257. the parameter block }
  1258. tcallparanode(left).secondcallparan(
  1259. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  1260. 0,procdefinition.parast.address_fixup+procdefinition.parast.datasize);
  1261. {$ifndef newra}
  1262. if assigned(right) then
  1263. maybe_restore(exprasmlist,right.location,pushedregs)
  1264. else
  1265. if assigned(methodpointer) then
  1266. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  1267. {$endif newra}
  1268. end;
  1269. aktcallnode:=oldaktcallnode;
  1270. {$ifndef newra}
  1271. rg.saveintregvars(exprasmlist,regs_to_push_int);
  1272. {$endif}
  1273. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  1274. { takes care of local data initialization }
  1275. inlineentrycode:=TAAsmoutput.Create;
  1276. inlineexitcode:=TAAsmoutput.Create;
  1277. gen_initialize_code(inlineentrycode,true);
  1278. if po_assembler in current_procinfo.procdef.procoptions then
  1279. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  1280. exprasmList.concatlist(inlineentrycode);
  1281. { process the inline code }
  1282. secondpass(inlinecode);
  1283. { Reserve space for storing parameters that will be pushed }
  1284. current_procinfo.allocate_push_parasize(pushedparasize);
  1285. { Restore }
  1286. pushedparasize:=oldpushedparasize;
  1287. rg.restoreunusedstate(unusedstate);
  1288. {$ifdef TEMPREGDEBUG}
  1289. testregisters32;
  1290. {$endif TEMPREGDEBUG}
  1291. gen_finalize_code(inlineexitcode,true);
  1292. gen_load_return_value(inlineexitcode,usesacc,usesacchi,usesfpu);
  1293. if po_assembler in current_procinfo.procdef.procoptions then
  1294. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  1295. exprasmList.concatlist(inlineexitcode);
  1296. inlineentrycode.free;
  1297. inlineexitcode.free;
  1298. {$ifdef extdebug}
  1299. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  1300. {$endif extdebug}
  1301. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  1302. {we can free the local data now, reset also the fixup address }
  1303. if current_procinfo.procdef.localst.datasize>0 then
  1304. begin
  1305. tg.UnGetTemp(exprasmlist,localsref);
  1306. current_procinfo.procdef.localst.address_fixup:=old_local_fixup;
  1307. end;
  1308. {we can free the para data now, reset also the fixup address }
  1309. if current_procinfo.procdef.parast.datasize>0 then
  1310. begin
  1311. tg.UnGetTemp(exprasmlist,pararef);
  1312. current_procinfo.procdef.parast.address_fixup:=old_para_fixup;
  1313. end;
  1314. { free return reference }
  1315. if (resulttype.def.size>0) then
  1316. begin
  1317. { from now on the result can be freed normally }
  1318. // if assigned(funcretnode) and
  1319. // paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1320. // tg.ChangeTempType(exprasmlist,funcretnode.location.reference,tt_normal);
  1321. end;
  1322. { handle function results }
  1323. if (not is_void(resulttype.def)) then
  1324. handle_return_value
  1325. else
  1326. location_reset(location,LOC_VOID,OS_NO);
  1327. { perhaps i/o check ? }
  1328. if iolabel<>nil then
  1329. begin
  1330. reference_reset_symbol(href,iolabel,0);
  1331. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(exprasmlist,1));
  1332. paramanager.freeintparaloc(exprasmlist,1);
  1333. {$ifdef newra}
  1334. rg.allocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1335. {$endif newra}
  1336. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  1337. {$ifdef newra}
  1338. rg.deallocexplicitregistersint(exprasmlist,VOLATILE_INTREGISTERS);
  1339. {$endif newra}
  1340. end;
  1341. { restore registers }
  1342. rg.restoreusedotherregisters(exprasmlist,pushedother);
  1343. {$ifndef newra}
  1344. rg.restoreusedintregisters(exprasmlist,pushedint);
  1345. {$endif}
  1346. { release temps of paras }
  1347. release_para_temps;
  1348. { if return value is not used }
  1349. if (not is_void(resulttype.def)) and
  1350. (not(nf_return_value_used in flags)) then
  1351. begin
  1352. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  1353. begin
  1354. { data which must be finalized ? }
  1355. if (resulttype.def.needs_inittable) then
  1356. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  1357. { release unused temp }
  1358. tg.ungetiftemp(exprasmlist,location.reference)
  1359. end
  1360. else if location.loc=LOC_FPUREGISTER then
  1361. begin
  1362. {$ifdef x86}
  1363. { release FPU stack }
  1364. accreg.enum:=FPU_RESULT_REG;
  1365. emit_reg(A_FSTP,S_NO,accreg);
  1366. {
  1367. dec(trgcpu(rg).fpuvaroffset);
  1368. do NOT decrement as the increment before
  1369. is not called for unused results PM }
  1370. {$endif x86}
  1371. end;
  1372. end;
  1373. { release procinfo }
  1374. current_procinfo.free;
  1375. current_procinfo:=oldprocinfo;
  1376. {$ifdef GDB}
  1377. if (cs_debuginfo in aktmoduleswitches) then
  1378. begin
  1379. cg.a_label(exprasmlist,endlabel);
  1380. strpcopy(pp,'224,0,0,'+endlabel.name);
  1381. if (target_info.use_function_relative_addresses) then
  1382. begin
  1383. strpcopy(strend(pp),'-');
  1384. strpcopy(strend(pp),oldprocdef.mangledname);
  1385. end;
  1386. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1387. freemem(pp,mangled_length+50);
  1388. end;
  1389. {$endif GDB}
  1390. { restore }
  1391. current_procinfo.procdef:=oldprocdef;
  1392. inlining_procedure:=oldinlining_procedure;
  1393. { reallocate the registers used for the current procedure's regvars, }
  1394. { since they may have been used and then deallocated in the inlined }
  1395. { procedure (JM) }
  1396. if assigned(current_procinfo.procdef.regvarinfo) then
  1397. rg.restoreStateAfterInline(oldregstate);
  1398. end;
  1399. procedure tcgcallnode.pass_2;
  1400. begin
  1401. if assigned(inlinecode) then
  1402. inlined_pass_2
  1403. else
  1404. normal_pass_2;
  1405. end;
  1406. begin
  1407. ccallparanode:=tcgcallparanode;
  1408. ccallnode:=tcgcallnode;
  1409. end.
  1410. {
  1411. $Log$
  1412. Revision 1.103 2003-07-23 11:01:14 jonas
  1413. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  1414. pairs round calls to helpers
  1415. Revision 1.102 2003/07/21 13:51:50 jonas
  1416. * fixed 64bit int results with -dnewra (you can't free both registers and
  1417. then allocate two new ones, because then the registers could be reversed
  1418. afterwards -> you get something like "movl %eax, %edx; movl %edx,%eax")
  1419. Revision 1.101 2003/07/08 21:24:59 peter
  1420. * sparc fixes
  1421. Revision 1.100 2003/07/06 21:50:33 jonas
  1422. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  1423. so that it doesn't include ebp and esp anymore
  1424. Revision 1.99 2003/07/06 17:58:22 peter
  1425. * framepointer fixes for sparc
  1426. * parent framepointer code more generic
  1427. Revision 1.98 2003/07/06 15:31:20 daniel
  1428. * Fixed register allocator. *Lots* of fixes.
  1429. Revision 1.97 2003/07/05 20:21:26 jonas
  1430. * create_paraloc_info() is now called separately for the caller and
  1431. callee info
  1432. * fixed ppc cycle
  1433. Revision 1.96 2003/07/02 22:18:04 peter
  1434. * paraloc splitted in callerparaloc,calleeparaloc
  1435. * sparc calling convention updates
  1436. Revision 1.95 2003/06/17 16:34:44 jonas
  1437. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1438. * renamed all_intregisters to volatile_intregisters and made it
  1439. processor dependent
  1440. Revision 1.94 2003/06/15 16:52:02 jonas
  1441. * release function result registers if the functino result isn't used
  1442. * don't allocate function result register with -dnewra if there is none
  1443. * some optimizations for non-x86 processor (don't save any registers
  1444. before a call)
  1445. Revision 1.93 2003/06/13 21:19:30 peter
  1446. * current_procdef removed, use current_procinfo.procdef instead
  1447. Revision 1.92 2003/06/12 21:10:50 peter
  1448. * newra fixes
  1449. Revision 1.91 2003/06/12 18:38:45 jonas
  1450. * deallocate parameter registers in time for newra
  1451. * for non-i386, procvars and methodpointers always have to be processed
  1452. in advance, whether or not newra is defined
  1453. Revision 1.90 2003/06/09 14:54:26 jonas
  1454. * (de)allocation of registers for parameters is now performed properly
  1455. (and checked on the ppc)
  1456. - removed obsolete allocation of all parameter registers at the start
  1457. of a procedure (and deallocation at the end)
  1458. Revision 1.89 2003/06/09 12:23:29 peter
  1459. * init/final of procedure data splitted from genentrycode
  1460. * use asmnode getposition to insert final at the correct position
  1461. als for the implicit try...finally
  1462. Revision 1.88 2003/06/08 20:01:53 jonas
  1463. * optimized assignments with on the right side a function that returns
  1464. an ansi- or widestring
  1465. Revision 1.87 2003/06/08 18:21:47 jonas
  1466. * fixed weird error in the copyleft statement :)
  1467. Revision 1.86 2003/06/07 18:57:04 jonas
  1468. + added freeintparaloc
  1469. * ppc get/freeintparaloc now check whether the parameter regs are
  1470. properly allocated/deallocated (and get an extra list para)
  1471. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1472. * fixed lot of missing pi_do_call's
  1473. Revision 1.85 2003/06/04 06:43:36 jonas
  1474. * fixed double secondpassing of procvar loads
  1475. Revision 1.84 2003/06/03 21:11:09 peter
  1476. * cg.a_load_* get a from and to size specifier
  1477. * makeregsize only accepts newregister
  1478. * i386 uses generic tcgnotnode,tcgunaryminus
  1479. Revision 1.83 2003/06/03 20:27:02 daniel
  1480. * Restored original methodpointer code for non newra case
  1481. Revision 1.82 2003/06/03 13:01:59 daniel
  1482. * Register allocator finished
  1483. Revision 1.81 2003/06/01 21:38:06 peter
  1484. * getregisterfpu size parameter added
  1485. * op_const_reg size parameter added
  1486. * sparc updates
  1487. Revision 1.80 2003/05/31 15:05:28 peter
  1488. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1489. Revision 1.79 2003/05/31 00:59:44 peter
  1490. * typo in FUNCTION_RESULT_REG
  1491. Revision 1.78 2003/05/30 23:57:08 peter
  1492. * more sparc cleanup
  1493. * accumulator removed, splitted in function_return_reg (called) and
  1494. function_result_reg (caller)
  1495. Revision 1.77 2003/05/29 10:05:40 jonas
  1496. * free callparatemps created for call-by-reference parameters
  1497. Revision 1.76 2003/05/28 23:58:18 jonas
  1498. * added missing initialization of rg.usedintin,byproc
  1499. * ppc now also saves/restores used fpu registers
  1500. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1501. i386
  1502. Revision 1.75 2003/05/26 21:17:17 peter
  1503. * procinlinenode removed
  1504. * aktexit2label removed, fast exit removed
  1505. + tcallnode.inlined_pass_2 added
  1506. Revision 1.74 2003/05/25 11:34:17 peter
  1507. * methodpointer self pushing fixed
  1508. Revision 1.73 2003/05/25 08:59:16 peter
  1509. * inline fixes
  1510. Revision 1.72 2003/05/24 13:36:54 jonas
  1511. * save fpu results in a normal fpu register on non-x86 processors
  1512. Revision 1.71 2003/05/23 19:35:50 jonas
  1513. - undid previous commit, it was wrong
  1514. Revision 1.70 2003/05/23 19:11:58 jonas
  1515. * fixed tests for whether a certain int register is unused
  1516. Revision 1.69 2003/05/23 18:01:56 jonas
  1517. * fixed ppc compiler
  1518. Revision 1.68 2003/05/23 14:27:35 peter
  1519. * remove some unit dependencies
  1520. * current_procinfo changes to store more info
  1521. Revision 1.67 2003/05/17 13:30:08 jonas
  1522. * changed tt_persistant to tt_persistent :)
  1523. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1524. temps, but a ttemptype, so you can also create ansistring temps etc
  1525. Revision 1.66 2003/05/16 14:33:31 peter
  1526. * regvar fixes
  1527. Revision 1.65 2003/05/15 18:58:53 peter
  1528. * removed selfpointer_offset, vmtpointer_offset
  1529. * tvarsym.adjusted_address
  1530. * address in localsymtable is now in the real direction
  1531. * removed some obsolete globals
  1532. Revision 1.64 2003/05/14 19:36:54 jonas
  1533. * patch from Peter for int64 function results
  1534. Revision 1.63 2003/05/13 19:14:41 peter
  1535. * failn removed
  1536. * inherited result code check moven to pexpr
  1537. Revision 1.62 2003/05/13 15:18:18 peter
  1538. * generate code for procvar first before pushing parameters. Made
  1539. the already existing code for powerpc available for all platforms
  1540. Revision 1.61 2003/05/12 18:17:55 jonas
  1541. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1542. already-loaded parameter registers
  1543. Revision 1.60 2003/05/11 21:48:38 jonas
  1544. * fixed procvar bug on the ppc (load procvar before loading para's,
  1545. because the procvar may otherwise destroy the already loaded paras)
  1546. Revision 1.59 2003/05/09 17:47:02 peter
  1547. * self moved to hidden parameter
  1548. * removed hdisposen,hnewn,selfn
  1549. Revision 1.58 2003/05/05 14:53:16 peter
  1550. * vs_hidden replaced by is_hidden boolean
  1551. Revision 1.57 2003/04/30 20:53:32 florian
  1552. * error when address of an abstract method is taken
  1553. * fixed some x86-64 problems
  1554. * merged some more x86-64 and i386 code
  1555. Revision 1.56 2003/04/29 07:28:52 michael
  1556. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1557. Revision 1.55 2003/04/27 11:21:33 peter
  1558. * aktprocdef renamed to current_procinfo.procdef
  1559. * procinfo renamed to current_procinfo
  1560. * procinfo will now be stored in current_module so it can be
  1561. cleaned up properly
  1562. * gen_main_procsym changed to create_main_proc and release_main_proc
  1563. to also generate a tprocinfo structure
  1564. * fixed unit implicit initfinal
  1565. Revision 1.54 2003/04/27 07:29:50 peter
  1566. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  1567. a new procdef declaration
  1568. * aktprocsym removed
  1569. * lexlevel removed, use symtable.symtablelevel instead
  1570. * implicit init/final code uses the normal genentry/genexit
  1571. * funcret state checking updated for new funcret handling
  1572. Revision 1.53 2003/04/25 20:59:33 peter
  1573. * removed funcretn,funcretsym, function result is now in varsym
  1574. and aliases for result and function name are added using absolutesym
  1575. * vs_hidden parameter for funcret passed in parameter
  1576. * vs_hidden fixes
  1577. * writenode changed to printnode and released from extdebug
  1578. * -vp option added to generate a tree.log with the nodetree
  1579. * nicer printnode for statements, callnode
  1580. Revision 1.52 2003/04/25 08:25:26 daniel
  1581. * Ifdefs around a lot of calls to cleartempgen
  1582. * Fixed registers that are allocated but not freed in several nodes
  1583. * Tweak to register allocator to cause less spills
  1584. * 8-bit registers now interfere with esi,edi and ebp
  1585. Compiler can now compile rtl successfully when using new register
  1586. allocator
  1587. Revision 1.51 2003/04/22 23:50:22 peter
  1588. * firstpass uses expectloc
  1589. * checks if there are differences between the expectloc and
  1590. location.loc from secondpass in EXTDEBUG
  1591. Revision 1.50 2003/04/22 14:33:38 peter
  1592. * removed some notes/hints
  1593. Revision 1.49 2003/04/22 13:47:08 peter
  1594. * fixed C style array of const
  1595. * fixed C array passing
  1596. * fixed left to right with high parameters
  1597. Revision 1.48 2003/04/22 10:09:34 daniel
  1598. + Implemented the actual register allocator
  1599. + Scratch registers unavailable when new register allocator used
  1600. + maybe_save/maybe_restore unavailable when new register allocator used
  1601. Revision 1.47 2003/04/22 09:49:44 peter
  1602. * do not load self when calling a non-inherited class constructor
  1603. Revision 1.46 2003/04/21 20:03:32 peter
  1604. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1605. Revision 1.45 2003/04/21 13:53:16 jonas
  1606. - removed copying of all paras when secondpassing a callnode (this used
  1607. to be necessary for inlinign support, but currently the whole inlined
  1608. procedure is already copied in advance). Note that the compiler crashes
  1609. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1610. syntax errors), but that was also the case before this change.
  1611. Revision 1.44 2003/04/10 17:57:52 peter
  1612. * vs_hidden released
  1613. Revision 1.43 2003/04/06 21:11:23 olle
  1614. * changed newasmsymbol to newasmsymboldata for data symbols
  1615. Revision 1.42 2003/04/04 15:38:56 peter
  1616. * moved generic code from n386cal to ncgcal, i386 now also
  1617. uses the generic ncgcal
  1618. Revision 1.41 2003/03/28 19:16:56 peter
  1619. * generic constructor working for i386
  1620. * remove fixed self register
  1621. * esi added as address register for i386
  1622. Revision 1.40 2003/03/06 11:35:50 daniel
  1623. * Fixed internalerror 7843 issue
  1624. Revision 1.39 2003/02/19 22:00:14 daniel
  1625. * Code generator converted to new register notation
  1626. - Horribily outdated todo.txt removed
  1627. Revision 1.38 2003/02/15 22:17:38 carl
  1628. * bugfix of FPU emulation code
  1629. Revision 1.37 2003/02/12 22:10:07 carl
  1630. * load_frame_pointer is now generic
  1631. * change fpu emulation routine names
  1632. Revision 1.36 2003/01/30 21:46:57 peter
  1633. * self fixes for static methods (merged)
  1634. Revision 1.35 2003/01/22 20:45:15 mazen
  1635. * making math code in RTL compiling.
  1636. *NB : This does NOT mean necessary that it will generate correct code!
  1637. Revision 1.34 2003/01/17 12:03:45 daniel
  1638. * Optalign conditional code adapted to record Tregister
  1639. Revision 1.33 2003/01/08 18:43:56 daniel
  1640. * Tregister changed into a record
  1641. Revision 1.32 2002/12/15 22:50:00 florian
  1642. + some stuff for the new hidden parameter handling added
  1643. Revision 1.31 2002/12/15 21:30:12 florian
  1644. * tcallnode.paraitem introduced, all references to defcoll removed
  1645. Revision 1.30 2002/11/27 20:04:39 peter
  1646. * cdecl array of const fixes
  1647. Revision 1.29 2002/11/25 17:43:17 peter
  1648. * splitted defbase in defutil,symutil,defcmp
  1649. * merged isconvertable and is_equal into compare_defs(_ext)
  1650. * made operator search faster by walking the list only once
  1651. Revision 1.28 2002/11/18 17:31:54 peter
  1652. * pass proccalloption to ret_in_xxx and push_xxx functions
  1653. Revision 1.27 2002/11/16 15:34:30 florian
  1654. * generic location for float results
  1655. Revision 1.26 2002/11/15 01:58:51 peter
  1656. * merged changes from 1.0.7 up to 04-11
  1657. - -V option for generating bug report tracing
  1658. - more tracing for option parsing
  1659. - errors for cdecl and high()
  1660. - win32 import stabs
  1661. - win32 records<=8 are returned in eax:edx (turned off by default)
  1662. - heaptrc update
  1663. - more info for temp management in .s file with EXTDEBUG
  1664. Revision 1.25 2002/10/05 12:43:25 carl
  1665. * fixes for Delphi 6 compilation
  1666. (warning : Some features do not work under Delphi)
  1667. Revision 1.24 2002/09/30 07:00:45 florian
  1668. * fixes to common code to get the alpha compiler compiled applied
  1669. Revision 1.23 2002/09/17 18:54:02 jonas
  1670. * a_load_reg_reg() now has two size parameters: source and dest. This
  1671. allows some optimizations on architectures that don't encode the
  1672. register size in the register name.
  1673. Revision 1.22 2002/09/07 15:25:02 peter
  1674. * old logs removed and tabs fixed
  1675. Revision 1.21 2002/09/07 11:50:02 jonas
  1676. * fixed small regalloction info bug
  1677. Revision 1.20 2002/09/02 11:25:20 florian
  1678. * fixed generic procedure variable calling
  1679. Revision 1.19 2002/09/01 21:04:48 florian
  1680. * several powerpc related stuff fixed
  1681. Revision 1.18 2002/09/01 18:43:27 peter
  1682. * include FUNCTION_RETURN_REG in regs_to_push list
  1683. Revision 1.17 2002/09/01 12:13:00 peter
  1684. * use a_call_reg
  1685. * ungetiftemp for procvar of object temp
  1686. Revision 1.16 2002/08/25 19:25:18 peter
  1687. * sym.insert_in_data removed
  1688. * symtable.insertvardata/insertconstdata added
  1689. * removed insert_in_data call from symtable.insert, it needs to be
  1690. called separatly. This allows to deref the address calculation
  1691. * procedures now calculate the parast addresses after the procedure
  1692. directives are parsed. This fixes the cdecl parast problem
  1693. * push_addr_param has an extra argument that specifies if cdecl is used
  1694. or not
  1695. Revision 1.15 2002/08/23 16:14:48 peter
  1696. * tempgen cleanup
  1697. * tt_noreuse temp type added that will be used in genentrycode
  1698. Revision 1.14 2002/08/20 16:55:38 peter
  1699. * don't write (stabs)line info when inlining a procedure
  1700. Revision 1.13 2002/08/19 19:36:42 peter
  1701. * More fixes for cross unit inlining, all tnodes are now implemented
  1702. * Moved pocall_internconst to po_internconst because it is not a
  1703. calling type at all and it conflicted when inlining of these small
  1704. functions was requested
  1705. Revision 1.12 2002/08/18 20:06:23 peter
  1706. * inlining is now also allowed in interface
  1707. * renamed write/load to ppuwrite/ppuload
  1708. * tnode storing in ppu
  1709. * nld,ncon,nbas are already updated for storing in ppu
  1710. Revision 1.11 2002/08/17 22:09:44 florian
  1711. * result type handling in tcgcal.pass_2 overhauled
  1712. * better tnode.dowrite
  1713. * some ppc stuff fixed
  1714. Revision 1.10 2002/08/17 09:23:35 florian
  1715. * first part of procinfo rewrite
  1716. Revision 1.9 2002/08/13 21:40:55 florian
  1717. * more fixes for ppc calling conventions
  1718. Revision 1.8 2002/08/13 18:01:51 carl
  1719. * rename swatoperands to swapoperands
  1720. + m68k first compilable version (still needs a lot of testing):
  1721. assembler generator, system information , inline
  1722. assembler reader.
  1723. Revision 1.7 2002/08/12 15:08:39 carl
  1724. + stab register indexes for powerpc (moved from gdb to cpubase)
  1725. + tprocessor enumeration moved to cpuinfo
  1726. + linker in target_info is now a class
  1727. * many many updates for m68k (will soon start to compile)
  1728. - removed some ifdef or correct them for correct cpu
  1729. Revision 1.6 2002/08/11 14:32:26 peter
  1730. * renamed current_library to objectlibrary
  1731. Revision 1.5 2002/08/11 13:24:11 peter
  1732. * saving of asmsymbols in ppu supported
  1733. * asmsymbollist global is removed and moved into a new class
  1734. tasmlibrarydata that will hold the info of a .a file which
  1735. corresponds with a single module. Added librarydata to tmodule
  1736. to keep the library info stored for the module. In the future the
  1737. objectfiles will also be stored to the tasmlibrarydata class
  1738. * all getlabel/newasmsymbol and friends are moved to the new class
  1739. Revision 1.4 2002/08/06 20:55:20 florian
  1740. * first part of ppc calling conventions fix
  1741. Revision 1.3 2002/07/20 11:57:53 florian
  1742. * types.pas renamed to defbase.pas because D6 contains a types
  1743. unit so this would conflicts if D6 programms are compiled
  1744. + Willamette/SSE2 instructions to assembler added
  1745. Revision 1.2 2002/07/13 19:38:43 florian
  1746. * some more generic calling stuff fixed
  1747. }