ncgcal.pas 77 KB

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