ncgcal.pas 80 KB

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