ncgcal.pas 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate assembler for 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. uses
  22. cpubase,
  23. globtype,
  24. symdef,node,ncal;
  25. type
  26. tcgcallparanode = class(tcallparanode)
  27. private
  28. tempparaloc : tparalocation;
  29. procedure allocate_tempparaloc;
  30. procedure push_addr_para;
  31. procedure push_value_para;
  32. public
  33. procedure secondcallparan;override;
  34. end;
  35. tcgcallnode = class(tcallnode)
  36. private
  37. procedure release_para_temps;
  38. procedure normal_pass_2;
  39. procedure inlined_pass_2;
  40. protected
  41. { save the size of pushed parameter, needed po_clearstack
  42. and alignment }
  43. pushedparasize : longint;
  44. framepointer_paraloc : tparalocation;
  45. refcountedtemp : treference;
  46. procedure handle_return_value;
  47. {# This routine is used to push the current frame pointer
  48. on the stack. This is used in nested routines where the
  49. value of the frame pointer is always pushed as an extra
  50. parameter.
  51. The default handling is the standard handling used on
  52. most stack based machines, where the frame pointer is
  53. the first invisible parameter.
  54. }
  55. function align_parasize:longint;virtual;
  56. procedure pop_parasize(pop_size:longint);virtual;
  57. procedure extra_interrupt_code;virtual;
  58. public
  59. procedure pass_2;override;
  60. end;
  61. implementation
  62. uses
  63. systems,
  64. cutils,verbose,globals,
  65. symconst,symsym,symtable,defutil,paramgr,
  66. {$ifdef GDB}
  67. {$ifdef delphi}
  68. sysutils,
  69. {$else}
  70. strings,
  71. {$endif}
  72. gdb,
  73. {$endif GDB}
  74. cgbase,pass_2,
  75. cpuinfo,aasmbase,aasmtai,
  76. nbas,nmem,nld,ncnv,
  77. {$ifdef x86}
  78. cga,cgx86,
  79. {$endif x86}
  80. ncgutil,cgobj,tgobj,
  81. procinfo;
  82. {*****************************************************************************
  83. TCGCALLPARANODE
  84. *****************************************************************************}
  85. procedure tcgcallparanode.allocate_tempparaloc;
  86. begin
  87. { Allocate (temporary) paralocation }
  88. tempparaloc:=paraitem.paraloc[callerside];
  89. if tempparaloc.loc=LOC_REGISTER then
  90. paramanager.alloctempregs(exprasmlist,tempparaloc)
  91. else
  92. paramanager.allocparaloc(exprasmlist,tempparaloc);
  93. end;
  94. procedure tcgcallparanode.push_addr_para;
  95. begin
  96. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  97. internalerror(200304235);
  98. location_release(exprasmlist,left.location);
  99. allocate_tempparaloc;
  100. cg.a_paramaddr_ref(exprasmlist,left.location.reference,tempparaloc);
  101. inc(tcgcallnode(aktcallnode).pushedparasize,POINTER_SIZE);
  102. end;
  103. procedure tcgcallparanode.push_value_para;
  104. var
  105. href : treference;
  106. {$ifdef i386}
  107. tempreference : treference;
  108. sizetopush : longint;
  109. {$endif i386}
  110. size : longint;
  111. cgsize : tcgsize;
  112. begin
  113. { we've nothing to push when the size of the parameter is 0 }
  114. if left.resulttype.def.size=0 then
  115. exit;
  116. { Move flags and jump in register to make it less complex }
  117. if left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  118. location_force_reg(exprasmlist,left.location,def_cgsize(left.resulttype.def),false);
  119. { Handle Floating point types differently }
  120. if left.resulttype.def.deftype=floatdef then
  121. begin
  122. location_release(exprasmlist,left.location);
  123. allocate_tempparaloc;
  124. {$ifdef i386}
  125. case left.location.loc of
  126. LOC_FPUREGISTER,
  127. LOC_CFPUREGISTER:
  128. begin
  129. if tempparaloc.loc<>LOC_REFERENCE then
  130. internalerror(200309291);
  131. size:=align(tfloatdef(left.resulttype.def).size,tempparaloc.alignment);
  132. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  133. cg.g_stackpointer_alloc(exprasmlist,size);
  134. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  135. cg.a_loadfpu_reg_ref(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,href);
  136. end;
  137. LOC_REFERENCE,
  138. LOC_CREFERENCE :
  139. begin
  140. sizetopush:=align(left.resulttype.def.size,tempparaloc.alignment);
  141. tempreference:=left.location.reference;
  142. inc(tempreference.offset,sizetopush);
  143. while (sizetopush>0) do
  144. begin
  145. if (sizetopush>=4) or (tempparaloc.alignment>=4) then
  146. begin
  147. cgsize:=OS_32;
  148. inc(tcgcallnode(aktcallnode).pushedparasize,4);
  149. dec(tempreference.offset,4);
  150. dec(sizetopush,4);
  151. end
  152. else
  153. begin
  154. cgsize:=OS_16;
  155. inc(tcgcallnode(aktcallnode).pushedparasize,2);
  156. dec(tempreference.offset,2);
  157. dec(sizetopush,2);
  158. end;
  159. cg.a_param_ref(exprasmlist,cgsize,tempreference,tempparaloc);
  160. end;
  161. end;
  162. else
  163. internalerror(200204243);
  164. end;
  165. {$else i386}
  166. case left.location.loc of
  167. LOC_FPUREGISTER,
  168. LOC_CFPUREGISTER:
  169. cg.a_paramfpu_reg(exprasmlist,def_cgsize(left.resulttype.def),left.location.register,tempparaloc);
  170. LOC_REFERENCE,
  171. LOC_CREFERENCE :
  172. cg.a_paramfpu_ref(exprasmlist,def_cgsize(left.resulttype.def),left.location.reference,tempparaloc)
  173. else
  174. internalerror(200204243);
  175. end;
  176. {$endif i386}
  177. end
  178. else
  179. begin
  180. { copy the value on the stack or use normal parameter push?
  181. Check for varargs first because that has no paraitem }
  182. if not(nf_varargs_para in flags) and
  183. paramanager.copy_value_on_stack(paraitem.paratyp,left.resulttype.def,
  184. aktcallnode.procdefinition.proccalloption) then
  185. begin
  186. location_release(exprasmlist,left.location);
  187. allocate_tempparaloc;
  188. {$ifdef i386}
  189. if tempparaloc.loc<>LOC_REFERENCE then
  190. internalerror(200309292);
  191. if not (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  192. internalerror(200204241);
  193. { push on stack }
  194. size:=align(left.resulttype.def.size,tempparaloc.alignment);
  195. inc(tcgcallnode(aktcallnode).pushedparasize,size);
  196. cg.g_stackpointer_alloc(exprasmlist,size);
  197. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  198. cg.g_concatcopy(exprasmlist,left.location.reference,href,size,false,false);
  199. {$else i386}
  200. cg.a_param_copy_ref(exprasmlist,left.resulttype.def.size,left.location.reference,tempparaloc);
  201. {$endif i386}
  202. end
  203. else
  204. begin
  205. case left.location.loc of
  206. LOC_CONSTANT,
  207. LOC_REGISTER,
  208. LOC_CREGISTER,
  209. LOC_REFERENCE,
  210. LOC_CREFERENCE :
  211. begin
  212. cgsize:=def_cgsize(left.resulttype.def);
  213. if cgsize in [OS_64,OS_S64] then
  214. begin
  215. inc(tcgcallnode(aktcallnode).pushedparasize,8);
  216. allocate_tempparaloc;
  217. cg64.a_param64_loc(exprasmlist,left.location,tempparaloc);
  218. location_release(exprasmlist,left.location);
  219. end
  220. else
  221. begin
  222. location_release(exprasmlist,left.location);
  223. allocate_tempparaloc;
  224. inc(tcgcallnode(aktcallnode).pushedparasize,align(tcgsize2size[tempparaloc.size],tempparaloc.alignment));
  225. cg.a_param_loc(exprasmlist,left.location,tempparaloc);
  226. end;
  227. end;
  228. {$ifdef SUPPORT_MMX}
  229. LOC_MMXREGISTER,
  230. LOC_CMMXREGISTER:
  231. begin
  232. location_release(exprasmlist,left.location);
  233. allocate_tempparaloc;
  234. inc(tcgcallnode(aktcallnode).pushedparasize,8);
  235. cg.a_parammm_reg(exprasmlist,left.location.register);
  236. end;
  237. {$endif SUPPORT_MMX}
  238. else
  239. internalerror(200204241);
  240. end;
  241. end;
  242. end;
  243. end;
  244. procedure tcgcallparanode.secondcallparan;
  245. var
  246. otlabel,
  247. oflabel : tasmlabel;
  248. begin
  249. if not(assigned(paraitem)) or
  250. not(assigned(paraitem.paratype.def)) or
  251. not(assigned(paraitem.parasym) or
  252. (nf_varargs_para in flags)) then
  253. internalerror(200304242);
  254. { push from left to right if specified }
  255. if assigned(right) and
  256. (aktcallnode.procdefinition.proccalloption in pushleftright_pocalls) then
  257. tcallparanode(right).secondcallparan;
  258. { Skip nothingn nodes which are used after disabling
  259. a parameter }
  260. if (left.nodetype<>nothingn) then
  261. begin
  262. otlabel:=truelabel;
  263. oflabel:=falselabel;
  264. objectlibrary.getlabel(truelabel);
  265. objectlibrary.getlabel(falselabel);
  266. secondpass(left);
  267. { handle varargs first, because paraitem.parasym is not valid }
  268. if (nf_varargs_para in flags) then
  269. begin
  270. if paramanager.push_addr_param(vs_value,left.resulttype.def,
  271. aktcallnode.procdefinition.proccalloption) then
  272. push_addr_para
  273. else
  274. push_value_para;
  275. end
  276. { hidden parameters }
  277. else if paraitem.is_hidden then
  278. begin
  279. { don't push a node that already generated a pointer type
  280. by address for implicit hidden parameters }
  281. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  282. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  283. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  284. aktcallnode.procdefinition.proccalloption)) then
  285. push_addr_para
  286. else
  287. push_value_para;
  288. end
  289. { filter array of const c styled args }
  290. else if is_array_of_const(left.resulttype.def) and (nf_cargs in left.flags) then
  291. begin
  292. { nothing, everything is already pushed }
  293. end
  294. { formal def }
  295. else if (paraitem.paratype.def.deftype=formaldef) then
  296. begin
  297. { allow passing of a constant to a const formaldef }
  298. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  299. (left.location.loc=LOC_CONSTANT) then
  300. location_force_mem(exprasmlist,left.location);
  301. { allow @var }
  302. if (left.nodetype=addrn) and
  303. (not(nf_procvarload in left.flags)) then
  304. begin
  305. inc(tcgcallnode(aktcallnode).pushedparasize,POINTER_SIZE);
  306. location_release(exprasmlist,left.location);
  307. allocate_tempparaloc;
  308. cg.a_param_loc(exprasmlist,left.location,tempparaloc);
  309. end
  310. else
  311. push_addr_para;
  312. end
  313. { Normal parameter }
  314. else
  315. begin
  316. { don't push a node that already generated a pointer type
  317. by address for implicit hidden parameters }
  318. if (not(
  319. paraitem.is_hidden and
  320. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  321. ) and
  322. paramanager.push_addr_param(paraitem.paratyp,paraitem.paratype.def,
  323. aktcallnode.procdefinition.proccalloption)) then
  324. begin
  325. { Check for passing a constant to var,out parameter }
  326. if (paraitem.paratyp in [vs_var,vs_out]) and
  327. (left.location.loc<>LOC_REFERENCE) then
  328. begin
  329. { passing self to a var parameter is allowed in
  330. TP and delphi }
  331. if not((left.location.loc=LOC_CREFERENCE) and
  332. is_self_node(left)) then
  333. internalerror(200106041);
  334. end;
  335. { Force to be in memory }
  336. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  337. location_force_mem(exprasmlist,left.location);
  338. push_addr_para;
  339. end
  340. else
  341. push_value_para;
  342. end;
  343. truelabel:=otlabel;
  344. falselabel:=oflabel;
  345. { update return location in callnode when this is the function
  346. result }
  347. if assigned(paraitem.parasym) and
  348. (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  349. location_copy(aktcallnode.location,left.location);
  350. end;
  351. { push from right to left }
  352. if assigned(right) and
  353. not(aktcallnode.procdefinition.proccalloption in pushleftright_pocalls) then
  354. tcallparanode(right).secondcallparan;
  355. end;
  356. {*****************************************************************************
  357. TCGCALLNODE
  358. *****************************************************************************}
  359. procedure tcgcallnode.extra_interrupt_code;
  360. begin
  361. end;
  362. function tcgcallnode.align_parasize:longint;
  363. begin
  364. result:=0;
  365. end;
  366. procedure tcgcallnode.pop_parasize(pop_size:longint);
  367. begin
  368. end;
  369. procedure tcgcallnode.handle_return_value;
  370. var
  371. cgsize : tcgsize;
  372. hregister : tregister;
  373. tempnode: tnode;
  374. begin
  375. { structured results are easy to handle.... }
  376. { needed also when result_no_used !! }
  377. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  378. begin
  379. { Location should be setup by the funcret para }
  380. if location.loc<>LOC_REFERENCE then
  381. internalerror(200304241);
  382. end
  383. else
  384. { ansi/widestrings must be registered, so we can dispose them }
  385. if is_ansistring(resulttype.def) or
  386. is_widestring(resulttype.def) then
  387. begin
  388. { the FUNCTION_RESULT_REG is already allocated }
  389. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  390. if not assigned(funcretnode) then
  391. begin
  392. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  393. location.reference:=refcountedtemp;
  394. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,location.reference);
  395. end
  396. else
  397. begin
  398. hregister := cg.getaddressregister(exprasmlist);
  399. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,hregister);
  400. { in case of a regular funcretnode with ret_in_param, the }
  401. { original funcretnode isn't touched -> make sure it's }
  402. { the same here (not sure if it's necessary) }
  403. tempnode := funcretnode.getcopy;
  404. tempnode.pass_2;
  405. location := tempnode.location;
  406. tempnode.free;
  407. cg.g_decrrefcount(exprasmlist,resulttype.def,location.reference, false);
  408. cg.a_load_reg_ref(exprasmlist,OS_ADDR,OS_ADDR,hregister,location.reference);
  409. cg.ungetregister(exprasmlist,hregister);
  410. end;
  411. end
  412. else
  413. { we have only to handle the result if it is used }
  414. if (nf_return_value_used in flags) then
  415. begin
  416. if (resulttype.def.deftype=floatdef) then
  417. begin
  418. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  419. {$ifdef cpufpemu}
  420. if cs_fp_emulation in aktmoduleswitches then
  421. location.register:=NR_FUNCTION_RESULT_REG
  422. else
  423. {$endif cpufpemu}
  424. location.register:=NR_FPU_RESULT_REG;
  425. {$ifdef x86}
  426. tcgx86(cg).inc_fpu_stack;
  427. {$else x86}
  428. hregister := cg.getfpuregister(exprasmlist,location.size);
  429. cg.a_loadfpu_reg_reg(exprasmlist,location.size,location.register,hregister);
  430. location.register := hregister;
  431. {$endif x86}
  432. end
  433. else
  434. begin
  435. cgsize:=def_cgsize(resulttype.def);
  436. if cgsize<>OS_NO then
  437. begin
  438. location_reset(location,LOC_REGISTER,cgsize);
  439. {$ifndef cpu64bit}
  440. if cgsize in [OS_64,OS_S64] then
  441. begin
  442. { Move the function result to free registers, preferably the
  443. FUNCTION_RESULT_REG/FUNCTION_RESULTHIGH_REG, so no move is necessary.}
  444. { the FUNCTION_RESULT_LOW_REG/FUNCTION_RESULT_HIGH_REG
  445. are already allocated }
  446. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG);
  447. location.registerlow:=cg.getintregister(exprasmlist,OS_INT);
  448. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,NR_FUNCTION_RESULT64_LOW_REG,location.registerlow);
  449. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG);
  450. location.registerhigh:=cg.getintregister(exprasmlist,OS_INT);
  451. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,NR_FUNCTION_RESULT64_HIGH_REG,location.registerhigh);
  452. end
  453. else
  454. {$endif cpu64bit}
  455. begin
  456. {Move the function result to a free register, preferably the
  457. FUNCTION_RESULT_REG, so no move is necessary.}
  458. { the FUNCTION_RESULT_REG is already allocated }
  459. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  460. { change register size after the unget because the
  461. getregister was done for the full register }
  462. location.register:=cg.getintregister(exprasmlist,cgsize);
  463. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,cg.makeregsize(NR_FUNCTION_RESULT_REG,cgsize),location.register);
  464. end;
  465. end
  466. else
  467. begin
  468. if resulttype.def.size>0 then
  469. internalerror(200305131);
  470. end;
  471. end;
  472. end
  473. else
  474. begin
  475. cgsize:=def_cgsize(resulttype.def);
  476. { an object constructor is a function with pointer result }
  477. if (procdefinition.proctypeoption=potype_constructor) then
  478. cgsize:=OS_ADDR;
  479. if cgsize<>OS_NO then
  480. {$ifndef cpu64bit}
  481. if cgsize in [OS_64,OS_S64] then
  482. begin
  483. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_LOW_REG);
  484. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT64_HIGH_REG);
  485. end
  486. else
  487. {$endif cpu64bit}
  488. cg.ungetregister(exprasmlist,NR_FUNCTION_RESULT_REG);
  489. location_reset(location,LOC_VOID,OS_NO);
  490. end;
  491. end;
  492. procedure tcgcallnode.release_para_temps;
  493. var
  494. hp : tnode;
  495. ppn : tcallparanode;
  496. begin
  497. { Release temps from parameters }
  498. ppn:=tcallparanode(left);
  499. while assigned(ppn) do
  500. begin
  501. if assigned(ppn.left) then
  502. begin
  503. { don't release the funcret temp }
  504. if not(assigned(ppn.paraitem.parasym)) or
  505. not(vo_is_funcret in tvarsym(ppn.paraitem.parasym).varoptions) then
  506. location_freetemp(exprasmlist,ppn.left.location);
  507. { process also all nodes of an array of const }
  508. if ppn.left.nodetype=arrayconstructorn then
  509. begin
  510. if assigned(tarrayconstructornode(ppn.left).left) then
  511. begin
  512. hp:=ppn.left;
  513. while assigned(hp) do
  514. begin
  515. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  516. hp:=tarrayconstructornode(hp).right;
  517. end;
  518. end;
  519. end;
  520. end;
  521. ppn:=tcallparanode(ppn.right);
  522. end;
  523. end;
  524. procedure tcgcallnode.normal_pass_2;
  525. var
  526. regs_to_push_other : totherregisterset;
  527. regs_to_alloc,regs_to_free:Tsuperregisterset;
  528. oldpushedparasize : longint;
  529. { adress returned from an I/O-error }
  530. { help reference pointer }
  531. href : treference;
  532. pop_size : longint;
  533. pvreg,
  534. vmtreg : tregister;
  535. oldaktcallnode : tcallnode;
  536. procedure pushparas;
  537. var
  538. ppn : tcgcallparanode;
  539. begin
  540. { copy all resources to the allocated registers }
  541. ppn:=tcgcallparanode(left);
  542. while assigned(ppn) do
  543. begin
  544. if ppn.tempparaloc.loc=LOC_REGISTER then
  545. begin
  546. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  547. paramanager.allocparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  548. {$ifdef sparc}
  549. case ppn.tempparaloc.size of
  550. OS_F32 :
  551. ppn.tempparaloc.size:=OS_32;
  552. OS_F64 :
  553. ppn.tempparaloc.size:=OS_64;
  554. end;
  555. {$endif sparc}
  556. {$ifndef cpu64bit}
  557. if ppn.tempparaloc.size in [OS_64,OS_S64] then
  558. begin
  559. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerlow,
  560. ppn.paraitem.paraloc[callerside].registerlow);
  561. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,ppn.tempparaloc.registerhigh,
  562. ppn.paraitem.paraloc[callerside].registerhigh);
  563. end
  564. else
  565. {$endif cpu64bit}
  566. cg.a_load_reg_reg(exprasmlist,ppn.tempparaloc.size,ppn.tempparaloc.size,
  567. ppn.tempparaloc.register,ppn.paraitem.paraloc[callerside].register);
  568. end;
  569. ppn:=tcgcallparanode(ppn.right);
  570. end;
  571. end;
  572. procedure freeparas;
  573. var
  574. ppn : tcgcallparanode;
  575. begin
  576. { free the resources allocated for the parameters }
  577. ppn:=tcgcallparanode(left);
  578. while assigned(ppn) do
  579. begin
  580. if ppn.tempparaloc.loc=LOC_REGISTER then
  581. paramanager.freeparaloc(exprasmlist,ppn.tempparaloc);
  582. paramanager.freeparaloc(exprasmlist,ppn.paraitem.paraloc[callerside]);
  583. ppn:=tcgcallparanode(ppn.right);
  584. end;
  585. end;
  586. begin
  587. if not assigned(procdefinition) then
  588. internalerror(200305264);
  589. { calculate the parameter info for the procdef }
  590. if not procdefinition.has_paraloc_info then
  591. begin
  592. paramanager.create_paraloc_info(procdefinition,callerside);
  593. procdefinition.has_paraloc_info:=true;
  594. end;
  595. { calculate the parameter info for varargs }
  596. if assigned(varargsparas) then
  597. paramanager.create_varargs_paraloc_info(procdefinition,varargsparas);
  598. if not assigned(funcretnode) then
  599. begin
  600. { if we allocate the temp. location for ansi- or widestrings }
  601. { already here, we avoid later a push/pop }
  602. if is_widestring(resulttype.def) then
  603. begin
  604. tg.gettemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  605. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  606. end
  607. else if is_ansistring(resulttype.def) then
  608. begin
  609. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  610. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  611. end;
  612. end;
  613. regs_to_alloc:=paramanager.get_volatile_registers_int(procdefinition.proccalloption);
  614. regs_to_push_other:=paramanager.get_volatile_registers_fpu(procdefinition.proccalloption);
  615. { Include Function result registers }
  616. if (not is_void(resulttype.def)) then
  617. begin
  618. case procdefinition.funcret_paraloc[callerside].loc of
  619. LOC_REGISTER,LOC_CREGISTER:
  620. begin
  621. {$ifndef cpu64bit}
  622. if procdefinition.funcret_paraloc[callerside].size in [OS_S64,OS_64] then
  623. begin
  624. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].registerlow));
  625. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].registerhigh));
  626. end
  627. else
  628. {$endif cpu64bit}
  629. include(regs_to_alloc,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  630. end;
  631. end;
  632. end;
  633. { Save registers destroyed by the call }
  634. {$warning fime saveusedotherregisters.}
  635. { cg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);}
  636. { Initialize for pushing the parameters }
  637. oldpushedparasize:=pushedparasize;
  638. pushedparasize:=0;
  639. { Process parameters, register parameters will be loaded
  640. in imaginary registers. The actual load to the correct
  641. register is done just before the call }
  642. oldaktcallnode:=aktcallnode;
  643. aktcallnode:=self;
  644. if assigned(left) then
  645. tcallparanode(left).secondcallparan;
  646. aktcallnode:=oldaktcallnode;
  647. { Align stack if required }
  648. pop_size:=align_parasize;
  649. { procedure variable or normal function call ? }
  650. if (right=nil) then
  651. begin
  652. if (po_virtualmethod in procdefinition.procoptions) and
  653. assigned(methodpointer) then
  654. begin
  655. secondpass(methodpointer);
  656. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  657. { virtual methods require an index }
  658. if tprocdef(procdefinition).extnumber=-1 then
  659. internalerror(200304021);
  660. { VMT should already be loaded in a register }
  661. if methodpointer.location.register=NR_NO then
  662. internalerror(200304022);
  663. { test validity of VMT }
  664. if not(is_interface(tprocdef(procdefinition)._class)) and
  665. not(is_cppclass(tprocdef(procdefinition)._class)) then
  666. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  667. end;
  668. {$warning fixme regvars}
  669. { rg.saveotherregvars(exprasmlist,regs_to_push_other);}
  670. if (po_virtualmethod in procdefinition.procoptions) and
  671. assigned(methodpointer) then
  672. begin
  673. vmtreg:=methodpointer.location.register;
  674. { release self }
  675. cg.ungetregister(exprasmlist,vmtreg);
  676. pvreg:=cg.getabtintregister(exprasmlist,OS_ADDR);
  677. reference_reset_base(href,vmtreg,
  678. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  679. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,pvreg);
  680. { Load parameters that are in temporary registers in the
  681. correct parameter register }
  682. if assigned(left) then
  683. pushparas;
  684. { Release register containing procvar }
  685. cg.ungetregister(exprasmlist,pvreg);
  686. { free the resources allocated for the parameters }
  687. freeparas;
  688. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  689. cg.allocexplicitregisters(exprasmlist,R_SSEREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  690. { call method }
  691. cg.a_call_reg(exprasmlist,pvreg);
  692. end
  693. else
  694. begin
  695. { Load parameters that are in temporary registers in the
  696. correct parameter register }
  697. if assigned(left) then
  698. pushparas;
  699. { free the resources allocated for the parameters }
  700. freeparas;
  701. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  702. cg.allocexplicitregisters(exprasmlist,R_SSEREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  703. { Calling interrupt from the same code requires some
  704. extra code }
  705. if (po_interrupt in procdefinition.procoptions) then
  706. extra_interrupt_code;
  707. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  708. end;
  709. end
  710. else
  711. { now procedure variable case }
  712. begin
  713. secondpass(right);
  714. location_release(exprasmlist,right.location);
  715. pvreg:=cg.getabtintregister(exprasmlist,OS_ADDR);
  716. { Only load OS_ADDR from the reference }
  717. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  718. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,right.location.reference,pvreg)
  719. else
  720. cg.a_load_loc_reg(exprasmlist,OS_ADDR,right.location,pvreg);
  721. location_freetemp(exprasmlist,right.location);
  722. { Load parameters that are in temporary registers in the
  723. correct parameter register }
  724. if assigned(left) then
  725. pushparas;
  726. { Release register containing procvar }
  727. cg.ungetregister(exprasmlist,pvreg);
  728. { free the resources allocated for the parameters }
  729. freeparas;
  730. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_alloc);
  731. cg.allocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  732. { Calling interrupt from the same code requires some
  733. extra code }
  734. if (po_interrupt in procdefinition.procoptions) then
  735. extra_interrupt_code;
  736. {$warning fixme regvars.}
  737. { rg.saveotherregvars(exprasmlist,ALL_OTHERREGISTERS);}
  738. cg.a_call_reg(exprasmlist,pvreg);
  739. end;
  740. { Need to remove the parameters from the stack? }
  741. if (procdefinition.proccalloption in clearstack_pocalls) then
  742. begin
  743. { the old pop_size was already included in pushedparasize }
  744. pop_size:=pushedparasize;
  745. { for Cdecl functions we don't need to pop the funcret when it
  746. was pushed by para }
  747. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  748. dec(pop_size,POINTER_SIZE);
  749. end;
  750. { Remove parameters/alignment from the stack }
  751. if pop_size>0 then
  752. pop_parasize(pop_size);
  753. { Reserve space for storing parameters that will be pushed }
  754. current_procinfo.allocate_push_parasize(pushedparasize);
  755. { Restore }
  756. pushedparasize:=oldpushedparasize;
  757. { Release registers, but not the registers that contain the
  758. function result }
  759. regs_to_free:=regs_to_alloc;
  760. if (not is_void(resulttype.def)) then
  761. begin
  762. case procdefinition.funcret_paraloc[callerside].loc of
  763. LOC_REGISTER,LOC_CREGISTER:
  764. begin
  765. {$ifndef cpu64bit}
  766. if procdefinition.funcret_paraloc[callerside].size in [OS_S64,OS_64] then
  767. begin
  768. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].registerlow));
  769. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].registerhigh));
  770. end
  771. else
  772. {$endif cpu64bit}
  773. exclude(regs_to_free,getsupreg(procdefinition.funcret_paraloc[callerside].register));
  774. end;
  775. end;
  776. end;
  777. cg.deallocexplicitregisters(exprasmlist,R_MMREGISTER,paramanager.get_volatile_registers_mm(procdefinition.proccalloption));
  778. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,regs_to_free);
  779. { handle function results }
  780. if (not is_void(resulttype.def)) then
  781. handle_return_value
  782. else
  783. location_reset(location,LOC_VOID,OS_NO);
  784. { perhaps i/o check ? }
  785. if (cs_check_io in aktlocalswitches) and
  786. (po_iocheck in procdefinition.procoptions) and
  787. not(po_iocheck in current_procinfo.procdef.procoptions) and
  788. { no IO check for methods and procedure variables }
  789. (right=nil) and
  790. not(po_virtualmethod in procdefinition.procoptions) then
  791. begin
  792. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  793. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  794. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  795. end;
  796. { restore registers }
  797. {$warning fixme restoreusedotherregisters}
  798. { rg.restoreusedotherregisters(exprasmlist,pushedother);}
  799. { release temps of paras }
  800. release_para_temps;
  801. { if return value is not used }
  802. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  803. begin
  804. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  805. begin
  806. { data which must be finalized ? }
  807. if (resulttype.def.needs_inittable) then
  808. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  809. { release unused temp }
  810. tg.ungetiftemp(exprasmlist,location.reference)
  811. end
  812. else if location.loc=LOC_FPUREGISTER then
  813. begin
  814. {$ifdef x86}
  815. { release FPU stack }
  816. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  817. {$endif x86}
  818. end;
  819. end;
  820. end;
  821. procedure tcgcallnode.inlined_pass_2;
  822. var
  823. oldaktcallnode : tcallnode;
  824. oldprocinfo : tprocinfo;
  825. oldinlining_procedure : boolean;
  826. inlineentrycode,inlineexitcode : TAAsmoutput;
  827. usesacc,usesacchi,usesfpu : boolean;
  828. {$ifdef GDB}
  829. startlabel,endlabel : tasmlabel;
  830. pp : pchar;
  831. mangled_length : longint;
  832. {$endif GDB}
  833. begin
  834. if not(assigned(procdefinition) and (procdefinition.deftype=procdef)) then
  835. internalerror(200305262);
  836. oldinlining_procedure:=inlining_procedure;
  837. oldprocinfo:=current_procinfo;
  838. { we're inlining a procedure }
  839. inlining_procedure:=true;
  840. { calculate registers to pass the parameters }
  841. paramanager.create_inline_paraloc_info(procdefinition);
  842. { create temp procinfo }
  843. current_procinfo:=cprocinfo.create(nil);
  844. current_procinfo.procdef:=tprocdef(procdefinition);
  845. { Add inling start }
  846. exprasmList.concat(Tai_Marker.Create(InlineStart));
  847. {$ifdef extdebug}
  848. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  849. {$endif extdebug}
  850. { Allocate parameters and locals }
  851. gen_alloc_inline_parast(exprasmlist,tparasymtable(current_procinfo.procdef.parast));
  852. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  853. gen_alloc_localst(exprasmlist,tlocalsymtable(current_procinfo.procdef.localst));
  854. {$ifdef GDB}
  855. if (cs_debuginfo in aktmoduleswitches) then
  856. begin
  857. objectlibrary.getaddrlabel(startlabel);
  858. objectlibrary.getaddrlabel(endlabel);
  859. cg.a_label(exprasmlist,startlabel);
  860. { Here we must include the para and local symtable info }
  861. procdefinition.concatstabto(withdebuglist);
  862. mangled_length:=length(oldprocinfo.procdef.mangledname);
  863. getmem(pp,mangled_length+50);
  864. strpcopy(pp,'192,0,0,'+startlabel.name);
  865. if (target_info.use_function_relative_addresses) then
  866. begin
  867. strpcopy(strend(pp),'-');
  868. strpcopy(strend(pp),oldprocinfo.procdef.mangledname);
  869. end;
  870. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  871. end;
  872. {$endif GDB}
  873. { if we allocate the temp. location for ansi- or widestrings }
  874. { already here, we avoid later a push/pop }
  875. if is_widestring(resulttype.def) then
  876. begin
  877. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  878. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  879. end
  880. else if is_ansistring(resulttype.def) then
  881. begin
  882. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  883. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  884. end;
  885. { Push parameters }
  886. oldaktcallnode:=aktcallnode;
  887. aktcallnode:=self;
  888. if assigned(left) then
  889. tcallparanode(left).secondcallparan;
  890. aktcallnode:=oldaktcallnode;
  891. { takes care of local data initialization }
  892. inlineentrycode:=TAAsmoutput.Create;
  893. inlineexitcode:=TAAsmoutput.Create;
  894. gen_load_para_value(inlineentrycode);
  895. gen_initialize_code(inlineentrycode,true);
  896. if po_assembler in current_procinfo.procdef.procoptions then
  897. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  898. exprasmList.concatlist(inlineentrycode);
  899. { process the inline code }
  900. secondpass(inlinecode);
  901. gen_finalize_code(inlineexitcode,true);
  902. gen_load_return_value(inlineexitcode,usesacc,usesacchi,usesfpu);
  903. if po_assembler in current_procinfo.procdef.procoptions then
  904. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  905. exprasmlist.concatlist(inlineexitcode);
  906. inlineentrycode.free;
  907. inlineexitcode.free;
  908. {$ifdef extdebug}
  909. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  910. {$endif extdebug}
  911. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  912. { handle function results }
  913. if (not is_void(resulttype.def)) then
  914. handle_return_value
  915. else
  916. location_reset(location,LOC_VOID,OS_NO);
  917. { perhaps i/o check ? }
  918. if (cs_check_io in aktlocalswitches) and
  919. (po_iocheck in procdefinition.procoptions) and
  920. not(po_iocheck in current_procinfo.procdef.procoptions) and
  921. { no IO check for methods and procedure variables }
  922. (right=nil) and
  923. not(po_virtualmethod in procdefinition.procoptions) then
  924. begin
  925. cg.allocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  926. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  927. cg.deallocexplicitregisters(exprasmlist,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  928. end;
  929. { release temps of paras }
  930. release_para_temps;
  931. { if return value is not used }
  932. if (not is_void(resulttype.def)) and
  933. (not(nf_return_value_used in flags)) then
  934. begin
  935. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  936. begin
  937. { data which must be finalized ? }
  938. if (resulttype.def.needs_inittable) then
  939. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  940. { release unused temp }
  941. tg.ungetiftemp(exprasmlist,location.reference)
  942. end
  943. else if location.loc=LOC_FPUREGISTER then
  944. begin
  945. {$ifdef x86}
  946. { release FPU stack }
  947. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  948. {$endif x86}
  949. end;
  950. end;
  951. { Release parameters and locals }
  952. gen_free_parast(exprasmlist,tparasymtable(current_procinfo.procdef.parast));
  953. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  954. gen_free_localst(exprasmlist,tlocalsymtable(current_procinfo.procdef.localst));
  955. { release procinfo }
  956. current_procinfo.free;
  957. current_procinfo:=oldprocinfo;
  958. {$ifdef GDB}
  959. if (cs_debuginfo in aktmoduleswitches) then
  960. begin
  961. cg.a_label(exprasmlist,endlabel);
  962. strpcopy(pp,'224,0,0,'+endlabel.name);
  963. if (target_info.use_function_relative_addresses) then
  964. begin
  965. strpcopy(strend(pp),'-');
  966. strpcopy(strend(pp),oldprocinfo.procdef.mangledname);
  967. end;
  968. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  969. freemem(pp,mangled_length+50);
  970. end;
  971. {$endif GDB}
  972. { restore }
  973. current_procinfo:=oldprocinfo;
  974. inlining_procedure:=oldinlining_procedure;
  975. end;
  976. procedure tcgcallnode.pass_2;
  977. begin
  978. if assigned(inlinecode) then
  979. inlined_pass_2
  980. else
  981. normal_pass_2;
  982. end;
  983. begin
  984. ccallparanode:=tcgcallparanode;
  985. ccallnode:=tcgcallnode;
  986. end.
  987. {
  988. $Log$
  989. Revision 1.131 2003-10-17 01:22:08 florian
  990. * compilation of the powerpc compiler fixed
  991. Revision 1.130 2003/10/11 16:06:42 florian
  992. * fixed some MMX<->SSE
  993. * started to fix ppc, needs an overhaul
  994. + stabs info improve for spilling, not sure if it works correctly/completly
  995. - MMX_SUPPORT removed from Makefile.fpc
  996. Revision 1.129 2003/10/10 17:48:13 peter
  997. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  998. * tregisteralloctor renamed to trgobj
  999. * removed rgobj from a lot of units
  1000. * moved location_* and reference_* to cgobj
  1001. * first things for mmx register allocation
  1002. Revision 1.128 2003/10/10 09:21:53 marco
  1003. * typo fix from Wiktor
  1004. Revision 1.127 2003/10/09 21:31:37 daniel
  1005. * Register allocator splitted, ans abstract now
  1006. Revision 1.126 2003/10/07 15:17:07 peter
  1007. * inline supported again, LOC_REFERENCEs are used to pass the
  1008. parameters
  1009. * inlineparasymtable,inlinelocalsymtable removed
  1010. * exitlabel inserting fixed
  1011. Revision 1.125 2003/10/05 21:21:52 peter
  1012. * c style array of const generates callparanodes
  1013. * varargs paraloc fixes
  1014. Revision 1.124 2003/10/03 22:00:33 peter
  1015. * parameter alignment fixes
  1016. Revision 1.123 2003/10/01 20:34:48 peter
  1017. * procinfo unit contains tprocinfo
  1018. * cginfo renamed to cgbase
  1019. * moved cgmessage to verbose
  1020. * fixed ppc and sparc compiles
  1021. Revision 1.122 2003/09/30 21:02:37 peter
  1022. * updates for inlining
  1023. Revision 1.121 2003/09/30 19:55:19 peter
  1024. * remove abt reg for vmtreg
  1025. Revision 1.120 2003/09/29 20:58:55 peter
  1026. * optimized releasing of registers
  1027. Revision 1.119 2003/09/28 17:55:03 peter
  1028. * parent framepointer changed to hidden parameter
  1029. * tloadparentfpnode added
  1030. Revision 1.118 2003/09/28 13:54:43 peter
  1031. * removed a_call_ref
  1032. Revision 1.117 2003/09/25 21:28:00 peter
  1033. * parameter fixes
  1034. Revision 1.116 2003/09/23 17:56:05 peter
  1035. * locals and paras are allocated in the code generation
  1036. * tvarsym.localloc contains the location of para/local when
  1037. generating code for the current procedure
  1038. Revision 1.115 2003/09/16 16:17:01 peter
  1039. * varspez in calls to push_addr_param
  1040. Revision 1.114 2003/09/14 19:17:39 peter
  1041. * don't use a_call_ref because it can use a parameter register
  1042. as temp
  1043. Revision 1.113 2003/09/11 11:54:59 florian
  1044. * improved arm code generation
  1045. * move some protected and private field around
  1046. * the temp. register for register parameters/arguments are now released
  1047. before the move to the parameter register is done. This improves
  1048. the code in a lot of cases.
  1049. Revision 1.112 2003/09/10 08:31:47 marco
  1050. * Patch from Peter for paraloc
  1051. Revision 1.111 2003/09/07 22:09:35 peter
  1052. * preparations for different default calling conventions
  1053. * various RA fixes
  1054. Revision 1.110 2003/09/04 15:39:58 peter
  1055. * released useparatemp
  1056. Revision 1.109 2003/09/03 15:55:00 peter
  1057. * NEWRA branch merged
  1058. Revision 1.108.2.4 2003/09/01 21:02:55 peter
  1059. * sparc updates for new tregister
  1060. Revision 1.108.2.3 2003/08/31 21:07:44 daniel
  1061. * callparatemp ripped
  1062. Revision 1.108.2.2 2003/08/29 17:28:59 peter
  1063. * next batch of updates
  1064. Revision 1.108.2.1 2003/08/27 20:23:55 peter
  1065. * remove old ra code
  1066. Revision 1.108 2003/08/21 22:14:16 olle
  1067. - removed parameter from fpc_iocheck
  1068. Revision 1.107 2003/08/17 16:59:20 jonas
  1069. * fixed regvars so they work with newra (at least for ppc)
  1070. * fixed some volatile register bugs
  1071. + -dnotranslation option for -dnewra, which causes the registers not to
  1072. be translated from virtual to normal registers. Requires support in
  1073. the assembler writer as well, which is only implemented in aggas/
  1074. agppcgas currently
  1075. Revision 1.106 2003/08/16 18:56:40 marco
  1076. * fix from Jonas.
  1077. Revision 1.105 2003/08/11 21:18:20 peter
  1078. * start of sparc support for newra
  1079. Revision 1.104 2003/08/11 14:22:06 mazen
  1080. - dupplicated code removed
  1081. Revision 1.103 2003/07/23 11:01:14 jonas
  1082. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  1083. pairs round calls to helpers
  1084. Revision 1.102 2003/07/21 13:51:50 jonas
  1085. * fixed 64bit int results with -dnewra (you can't free both registers and
  1086. then allocate two new ones, because then the registers could be reversed
  1087. afterwards -> you get something like "movl %eax, %edx; movl %edx,%eax")
  1088. Revision 1.101 2003/07/08 21:24:59 peter
  1089. * sparc fixes
  1090. Revision 1.100 2003/07/06 21:50:33 jonas
  1091. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  1092. so that it doesn't include ebp and esp anymore
  1093. Revision 1.99 2003/07/06 17:58:22 peter
  1094. * framepointer fixes for sparc
  1095. * parent framepointer code more generic
  1096. Revision 1.98 2003/07/06 15:31:20 daniel
  1097. * Fixed register allocator. *Lots* of fixes.
  1098. Revision 1.97 2003/07/05 20:21:26 jonas
  1099. * create_paraloc_info() is now called separately for the caller and
  1100. callee info
  1101. * fixed ppc cycle
  1102. Revision 1.96 2003/07/02 22:18:04 peter
  1103. * paraloc splitted in paraloc[callerside],calleeparaloc
  1104. * sparc calling convention updates
  1105. Revision 1.95 2003/06/17 16:34:44 jonas
  1106. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1107. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  1108. processor dependent
  1109. Revision 1.94 2003/06/15 16:52:02 jonas
  1110. * release function result registers if the functino result isn't used
  1111. * don't allocate function result register with -dnewra if there is none
  1112. * some optimizations for non-x86 processor (don't save any registers
  1113. before a call)
  1114. Revision 1.93 2003/06/13 21:19:30 peter
  1115. * current_procdef removed, use current_procinfo.procdef instead
  1116. Revision 1.92 2003/06/12 21:10:50 peter
  1117. * newra fixes
  1118. Revision 1.91 2003/06/12 18:38:45 jonas
  1119. * deallocate parameter registers in time for newra
  1120. * for non-i386, procvars and methodpointers always have to be processed
  1121. in advance, whether or not newra is defined
  1122. Revision 1.90 2003/06/09 14:54:26 jonas
  1123. * (de)allocation of registers for parameters is now performed properly
  1124. (and checked on the ppc)
  1125. - removed obsolete allocation of all parameter registers at the start
  1126. of a procedure (and deallocation at the end)
  1127. Revision 1.89 2003/06/09 12:23:29 peter
  1128. * init/final of procedure data splitted from genentrycode
  1129. * use asmnode getposition to insert final at the correct position
  1130. als for the implicit try...finally
  1131. Revision 1.88 2003/06/08 20:01:53 jonas
  1132. * optimized assignments with on the right side a function that returns
  1133. an ansi- or widestring
  1134. Revision 1.87 2003/06/08 18:21:47 jonas
  1135. * fixed weird error in the copyleft statement :)
  1136. Revision 1.86 2003/06/07 18:57:04 jonas
  1137. + added freeintparaloc
  1138. * ppc get/freeintparaloc now check whether the parameter regs are
  1139. properly allocated/deallocated (and get an extra list para)
  1140. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1141. * fixed lot of missing pi_do_call's
  1142. Revision 1.85 2003/06/04 06:43:36 jonas
  1143. * fixed double secondpassing of procvar loads
  1144. Revision 1.84 2003/06/03 21:11:09 peter
  1145. * cg.a_load_* get a from and to size specifier
  1146. * makeregsize only accepts newregister
  1147. * i386 uses generic tcgnotnode,tcgunaryminus
  1148. Revision 1.83 2003/06/03 20:27:02 daniel
  1149. * Restored original methodpointer code for non newra case
  1150. Revision 1.82 2003/06/03 13:01:59 daniel
  1151. * Register allocator finished
  1152. Revision 1.81 2003/06/01 21:38:06 peter
  1153. * getregisterfpu size parameter added
  1154. * op_const_reg size parameter added
  1155. * sparc updates
  1156. Revision 1.80 2003/05/31 15:05:28 peter
  1157. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  1158. Revision 1.79 2003/05/31 00:59:44 peter
  1159. * typo in FUNCTION_RESULT_REG
  1160. Revision 1.78 2003/05/30 23:57:08 peter
  1161. * more sparc cleanup
  1162. * accumulator removed, splitted in function_return_reg (called) and
  1163. function_result_reg (caller)
  1164. Revision 1.77 2003/05/29 10:05:40 jonas
  1165. * free callparatemps created for call-by-reference parameters
  1166. Revision 1.76 2003/05/28 23:58:18 jonas
  1167. * added missing initialization of rg.usedintin,byproc
  1168. * ppc now also saves/restores used fpu registers
  1169. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  1170. i386
  1171. Revision 1.75 2003/05/26 21:17:17 peter
  1172. * procinlinenode removed
  1173. * aktexit2label removed, fast exit removed
  1174. + tcallnode.inlined_pass_2 added
  1175. Revision 1.74 2003/05/25 11:34:17 peter
  1176. * methodpointer self pushing fixed
  1177. Revision 1.73 2003/05/25 08:59:16 peter
  1178. * inline fixes
  1179. Revision 1.72 2003/05/24 13:36:54 jonas
  1180. * save fpu results in a normal fpu register on non-x86 processors
  1181. Revision 1.71 2003/05/23 19:35:50 jonas
  1182. - undid previous commit, it was wrong
  1183. Revision 1.70 2003/05/23 19:11:58 jonas
  1184. * fixed tests for whether a certain int register is unused
  1185. Revision 1.69 2003/05/23 18:01:56 jonas
  1186. * fixed ppc compiler
  1187. Revision 1.68 2003/05/23 14:27:35 peter
  1188. * remove some unit dependencies
  1189. * current_procinfo changes to store more info
  1190. Revision 1.67 2003/05/17 13:30:08 jonas
  1191. * changed tt_persistant to tt_persistent :)
  1192. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1193. temps, but a ttemptype, so you can also create ansistring temps etc
  1194. Revision 1.66 2003/05/16 14:33:31 peter
  1195. * regvar fixes
  1196. Revision 1.65 2003/05/15 18:58:53 peter
  1197. * removed selfpointer_offset, vmtpointer_offset
  1198. * tvarsym.adjusted_address
  1199. * address in localsymtable is now in the real direction
  1200. * removed some obsolete globals
  1201. Revision 1.64 2003/05/14 19:36:54 jonas
  1202. * patch from Peter for int64 function results
  1203. Revision 1.63 2003/05/13 19:14:41 peter
  1204. * failn removed
  1205. * inherited result code check moven to pexpr
  1206. Revision 1.62 2003/05/13 15:18:18 peter
  1207. * generate code for procvar first before pushing parameters. Made
  1208. the already existing code for powerpc available for all platforms
  1209. Revision 1.61 2003/05/12 18:17:55 jonas
  1210. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1211. already-loaded parameter registers
  1212. Revision 1.60 2003/05/11 21:48:38 jonas
  1213. * fixed procvar bug on the ppc (load procvar before loading para's,
  1214. because the procvar may otherwise destroy the already loaded paras)
  1215. Revision 1.59 2003/05/09 17:47:02 peter
  1216. * self moved to hidden parameter
  1217. * removed hdisposen,hnewn,selfn
  1218. Revision 1.58 2003/05/05 14:53:16 peter
  1219. * vs_hidden replaced by is_hidden boolean
  1220. Revision 1.57 2003/04/30 20:53:32 florian
  1221. * error when address of an abstract method is taken
  1222. * fixed some x86-64 problems
  1223. * merged some more x86-64 and i386 code
  1224. Revision 1.56 2003/04/29 07:28:52 michael
  1225. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1226. Revision 1.55 2003/04/27 11:21:33 peter
  1227. * aktprocdef renamed to current_procinfo.procdef
  1228. * procinfo renamed to current_procinfo
  1229. * procinfo will now be stored in current_module so it can be
  1230. cleaned up properly
  1231. * gen_main_procsym changed to create_main_proc and release_main_proc
  1232. to also generate a tprocinfo structure
  1233. * fixed unit implicit initfinal
  1234. Revision 1.54 2003/04/27 07:29:50 peter
  1235. * current_procinfo.procdef cleanup, current_procinfo.procdef is now always nil when parsing
  1236. a new procdef declaration
  1237. * aktprocsym removed
  1238. * lexlevel removed, use symtable.symtablelevel instead
  1239. * implicit init/final code uses the normal genentry/genexit
  1240. * funcret state checking updated for new funcret handling
  1241. Revision 1.53 2003/04/25 20:59:33 peter
  1242. * removed funcretn,funcretsym, function result is now in varsym
  1243. and aliases for result and function name are added using absolutesym
  1244. * vs_hidden parameter for funcret passed in parameter
  1245. * vs_hidden fixes
  1246. * writenode changed to printnode and released from extdebug
  1247. * -vp option added to generate a tree.log with the nodetree
  1248. * nicer printnode for statements, callnode
  1249. Revision 1.52 2003/04/25 08:25:26 daniel
  1250. * Ifdefs around a lot of calls to cleartempgen
  1251. * Fixed registers that are allocated but not freed in several nodes
  1252. * Tweak to register allocator to cause less spills
  1253. * 8-bit registers now interfere with esi,edi and ebp
  1254. Compiler can now compile rtl successfully when using new register
  1255. allocator
  1256. Revision 1.51 2003/04/22 23:50:22 peter
  1257. * firstpass uses expectloc
  1258. * checks if there are differences between the expectloc and
  1259. location.loc from secondpass in EXTDEBUG
  1260. Revision 1.50 2003/04/22 14:33:38 peter
  1261. * removed some notes/hints
  1262. Revision 1.49 2003/04/22 13:47:08 peter
  1263. * fixed C style array of const
  1264. * fixed C array passing
  1265. * fixed left to right with high parameters
  1266. Revision 1.48 2003/04/22 10:09:34 daniel
  1267. + Implemented the actual register allocator
  1268. + Scratch registers unavailable when new register allocator used
  1269. + maybe_save/maybe_restore unavailable when new register allocator used
  1270. Revision 1.47 2003/04/22 09:49:44 peter
  1271. * do not load self when calling a non-inherited class constructor
  1272. Revision 1.46 2003/04/21 20:03:32 peter
  1273. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1274. Revision 1.45 2003/04/21 13:53:16 jonas
  1275. - removed copying of all paras when secondpassing a callnode (this used
  1276. to be necessary for inlinign support, but currently the whole inlined
  1277. procedure is already copied in advance). Note that the compiler crashes
  1278. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1279. syntax errors), but that was also the case before this change.
  1280. Revision 1.44 2003/04/10 17:57:52 peter
  1281. * vs_hidden released
  1282. Revision 1.43 2003/04/06 21:11:23 olle
  1283. * changed newasmsymbol to newasmsymboldata for data symbols
  1284. Revision 1.42 2003/04/04 15:38:56 peter
  1285. * moved generic code from n386cal to ncgcal, i386 now also
  1286. uses the generic ncgcal
  1287. Revision 1.41 2003/03/28 19:16:56 peter
  1288. * generic constructor working for i386
  1289. * remove fixed self register
  1290. * esi added as address register for i386
  1291. Revision 1.40 2003/03/06 11:35:50 daniel
  1292. * Fixed internalerror 7843 issue
  1293. Revision 1.39 2003/02/19 22:00:14 daniel
  1294. * Code generator converted to new register notation
  1295. - Horribily outdated todo.txt removed
  1296. Revision 1.38 2003/02/15 22:17:38 carl
  1297. * bugfix of FPU emulation code
  1298. Revision 1.37 2003/02/12 22:10:07 carl
  1299. * load_frame_pointer is now generic
  1300. * change fpu emulation routine names
  1301. Revision 1.36 2003/01/30 21:46:57 peter
  1302. * self fixes for static methods (merged)
  1303. Revision 1.35 2003/01/22 20:45:15 mazen
  1304. * making math code in RTL compiling.
  1305. *NB : This does NOT mean necessary that it will generate correct code!
  1306. Revision 1.34 2003/01/17 12:03:45 daniel
  1307. * Optalign conditional code adapted to record Tregister
  1308. Revision 1.33 2003/01/08 18:43:56 daniel
  1309. * Tregister changed into a record
  1310. Revision 1.32 2002/12/15 22:50:00 florian
  1311. + some stuff for the new hidden parameter handling added
  1312. Revision 1.31 2002/12/15 21:30:12 florian
  1313. * tcallnode.paraitem introduced, all references to defcoll removed
  1314. Revision 1.30 2002/11/27 20:04:39 peter
  1315. * cdecl array of const fixes
  1316. Revision 1.29 2002/11/25 17:43:17 peter
  1317. * splitted defbase in defutil,symutil,defcmp
  1318. * merged isconvertable and is_equal into compare_defs(_ext)
  1319. * made operator search faster by walking the list only once
  1320. Revision 1.28 2002/11/18 17:31:54 peter
  1321. * pass proccalloption to ret_in_xxx and push_xxx functions
  1322. Revision 1.27 2002/11/16 15:34:30 florian
  1323. * generic location for float results
  1324. Revision 1.26 2002/11/15 01:58:51 peter
  1325. * merged changes from 1.0.7 up to 04-11
  1326. - -V option for generating bug report tracing
  1327. - more tracing for option parsing
  1328. - errors for cdecl and high()
  1329. - win32 import stabs
  1330. - win32 records<=8 are returned in eax:edx (turned off by default)
  1331. - heaptrc update
  1332. - more info for temp management in .s file with EXTDEBUG
  1333. Revision 1.25 2002/10/05 12:43:25 carl
  1334. * fixes for Delphi 6 compilation
  1335. (warning : Some features do not work under Delphi)
  1336. Revision 1.24 2002/09/30 07:00:45 florian
  1337. * fixes to common code to get the alpha compiler compiled applied
  1338. Revision 1.23 2002/09/17 18:54:02 jonas
  1339. * a_load_reg_reg() now has two size parameters: source and dest. This
  1340. allows some optimizations on architectures that don't encode the
  1341. register size in the register name.
  1342. Revision 1.22 2002/09/07 15:25:02 peter
  1343. * old logs removed and tabs fixed
  1344. Revision 1.21 2002/09/07 11:50:02 jonas
  1345. * fixed small regalloction info bug
  1346. Revision 1.20 2002/09/02 11:25:20 florian
  1347. * fixed generic procedure variable calling
  1348. Revision 1.19 2002/09/01 21:04:48 florian
  1349. * several powerpc related stuff fixed
  1350. Revision 1.18 2002/09/01 18:43:27 peter
  1351. * include FUNCTION_RETURN_REG in regs_to_push list
  1352. Revision 1.17 2002/09/01 12:13:00 peter
  1353. * use a_call_reg
  1354. * ungetiftemp for procvar of object temp
  1355. Revision 1.16 2002/08/25 19:25:18 peter
  1356. * sym.insert_in_data removed
  1357. * symtable.insertvardata/insertconstdata added
  1358. * removed insert_in_data call from symtable.insert, it needs to be
  1359. called separatly. This allows to deref the address calculation
  1360. * procedures now calculate the parast addresses after the procedure
  1361. directives are parsed. This fixes the cdecl parast problem
  1362. * push_addr_param has an extra argument that specifies if cdecl is used
  1363. or not
  1364. Revision 1.15 2002/08/23 16:14:48 peter
  1365. * tempgen cleanup
  1366. * tt_noreuse temp type added that will be used in genentrycode
  1367. Revision 1.14 2002/08/20 16:55:38 peter
  1368. * don't write (stabs)line info when inlining a procedure
  1369. Revision 1.13 2002/08/19 19:36:42 peter
  1370. * More fixes for cross unit inlining, all tnodes are now implemented
  1371. * Moved pocall_internconst to po_internconst because it is not a
  1372. calling type at all and it conflicted when inlining of these small
  1373. functions was requested
  1374. Revision 1.12 2002/08/18 20:06:23 peter
  1375. * inlining is now also allowed in interface
  1376. * renamed write/load to ppuwrite/ppuload
  1377. * tnode storing in ppu
  1378. * nld,ncon,nbas are already updated for storing in ppu
  1379. Revision 1.11 2002/08/17 22:09:44 florian
  1380. * result type handling in tcgcal.pass_2 overhauled
  1381. * better tnode.dowrite
  1382. * some ppc stuff fixed
  1383. Revision 1.10 2002/08/17 09:23:35 florian
  1384. * first part of procinfo rewrite
  1385. Revision 1.9 2002/08/13 21:40:55 florian
  1386. * more fixes for ppc calling conventions
  1387. Revision 1.8 2002/08/13 18:01:51 carl
  1388. * rename swatoperands to swapoperands
  1389. + m68k first compilable version (still needs a lot of testing):
  1390. assembler generator, system information , inline
  1391. assembler reader.
  1392. Revision 1.7 2002/08/12 15:08:39 carl
  1393. + stab register indexes for powerpc (moved from gdb to cpubase)
  1394. + tprocessor enumeration moved to cpuinfo
  1395. + linker in target_info is now a class
  1396. * many many updates for m68k (will soon start to compile)
  1397. - removed some ifdef or correct them for correct cpu
  1398. Revision 1.6 2002/08/11 14:32:26 peter
  1399. * renamed current_library to objectlibrary
  1400. Revision 1.5 2002/08/11 13:24:11 peter
  1401. * saving of asmsymbols in ppu supported
  1402. * asmsymbollist global is removed and moved into a new class
  1403. tasmlibrarydata that will hold the info of a .a file which
  1404. corresponds with a single module. Added librarydata to tmodule
  1405. to keep the library info stored for the module. In the future the
  1406. objectfiles will also be stored to the tasmlibrarydata class
  1407. * all getlabel/newasmsymbol and friends are moved to the new class
  1408. Revision 1.4 2002/08/06 20:55:20 florian
  1409. * first part of ppc calling conventions fix
  1410. Revision 1.3 2002/07/20 11:57:53 florian
  1411. * types.pas renamed to defbase.pas because D6 contains a types
  1412. unit so this would conflicts if D6 programms are compiled
  1413. + Willamette/SSE2 instructions to assembler added
  1414. Revision 1.2 2002/07/13 19:38:43 florian
  1415. * some more generic calling stuff fixed
  1416. }