ncgcal.pas 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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 bymethodpointer
  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. protected
  33. refcountedtemp : treference;
  34. procedure handle_return_value(inlined:boolean);
  35. {# This routine is used to push the current frame pointer
  36. on the stack. This is used in nested routines where the
  37. value of the frame pointer is always pushed as an extra
  38. parameter.
  39. The default handling is the standard handling used on
  40. most stack based machines, where the frame pointer is
  41. the first invisible parameter.
  42. }
  43. function align_parasize(parasize,para_alignment:longint):longint;virtual;
  44. procedure pop_parasize(pop_size:longint);virtual;
  45. procedure push_framepointer;virtual;
  46. procedure extra_interrupt_code;virtual;
  47. public
  48. procedure pass_2;override;
  49. end;
  50. tcgprocinlinenode = class(tprocinlinenode)
  51. procedure pass_2;override;
  52. end;
  53. implementation
  54. uses
  55. systems,
  56. cutils,verbose,globals,
  57. symconst,symbase,symsym,symtable,defutil,paramgr,
  58. {$ifdef GDB}
  59. {$ifdef delphi}
  60. sysutils,
  61. {$else}
  62. strings,
  63. {$endif}
  64. gdb,
  65. {$endif GDB}
  66. cginfo,cgbase,pass_2,
  67. cpuinfo,aasmbase,aasmtai,aasmcpu,
  68. nbas,nmem,nld,ncnv,
  69. {$ifdef x86}
  70. cga,
  71. {$endif x86}
  72. {$ifdef cpu64bit}
  73. cg64f64,
  74. {$else cpu64bit}
  75. cg64f32,
  76. {$endif cpu64bit}
  77. {$ifdef powerpc}
  78. cpupi,
  79. {$endif powerpc}
  80. ncgutil,cgobj,tgobj,regvars,rgobj,rgcpu;
  81. var
  82. { Current callnode, this is needed for having a link
  83. between the callparanodes and the callnode they belong to }
  84. aktcallnode : tcallnode;
  85. {*****************************************************************************
  86. TCGCALLPARANODE
  87. *****************************************************************************}
  88. procedure tcgcallparanode.secondcallparan(push_from_left_to_right:boolean;calloption:tproccalloption;para_alignment,para_offset : longint);
  89. var
  90. otlabel,
  91. oflabel : tasmlabel;
  92. tmpreg : tregister;
  93. href : treference;
  94. begin
  95. if not(assigned(paraitem.paratype.def) or
  96. assigned(paraitem.parasym)) then
  97. internalerror(200304242);
  98. { set default para_alignment to target_info.stackalignment }
  99. if para_alignment=0 then
  100. para_alignment:=aktalignment.paraalign;
  101. { push from left to right if specified }
  102. if push_from_left_to_right and assigned(right) then
  103. begin
  104. if (nf_varargs_para in flags) then
  105. tcallparanode(right).secondcallparan(push_from_left_to_right,
  106. calloption,para_alignment,para_offset)
  107. else
  108. tcallparanode(right).secondcallparan(push_from_left_to_right,
  109. calloption,para_alignment,para_offset);
  110. end;
  111. otlabel:=truelabel;
  112. oflabel:=falselabel;
  113. objectlibrary.getlabel(truelabel);
  114. objectlibrary.getlabel(falselabel);
  115. secondpass(left);
  116. { handle varargs first, because defcoll is not valid }
  117. if (nf_varargs_para in flags) then
  118. begin
  119. if paramanager.push_addr_param(left.resulttype.def,calloption) then
  120. begin
  121. inc(pushedparasize,POINTER_SIZE);
  122. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  123. location_release(exprasmlist,left.location);
  124. end
  125. else
  126. push_value_para(exprasmlist,left,calloption,para_offset,para_alignment,paraitem.paraloc);
  127. end
  128. { hidden parameters }
  129. else if paraitem.is_hidden then
  130. begin
  131. { don't push a node that already generated a pointer type
  132. by address for implicit hidden parameters }
  133. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) or
  134. (not(left.resulttype.def.deftype in [pointerdef,classrefdef]) and
  135. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  136. begin
  137. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  138. internalerror(200305071);
  139. inc(pushedparasize,POINTER_SIZE);
  140. if calloption=pocall_inline then
  141. begin
  142. {$ifdef newra}
  143. tmpreg:=rg.getaddressregister(exprasmlist);
  144. {$else}
  145. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  146. {$endif}
  147. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  148. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  149. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  150. {$ifdef newra}
  151. rg.ungetregisterint(exprasmlist,tmpreg);
  152. {$else}
  153. cg.free_scratch_reg(exprasmlist,tmpreg);
  154. {$endif}
  155. end
  156. else
  157. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  158. location_release(exprasmlist,left.location);
  159. end
  160. else
  161. begin
  162. push_value_para(exprasmlist,left,calloption,
  163. para_offset,para_alignment,paraitem.paraloc);
  164. end;
  165. end
  166. { filter array of const c styled args }
  167. else if is_array_of_const(left.resulttype.def) and (nf_cargs in left.flags) then
  168. begin
  169. { nothing, everything is already pushed }
  170. end
  171. { in codegen.handleread.. paraitem.data is set to nil }
  172. else if assigned(paraitem.paratype.def) and
  173. (paraitem.paratype.def.deftype=formaldef) then
  174. begin
  175. { allow passing of a constant to a const formaldef }
  176. if (tvarsym(paraitem.parasym).varspez=vs_const) and
  177. (left.location.loc=LOC_CONSTANT) then
  178. location_force_mem(exprasmlist,left.location);
  179. { allow @var }
  180. inc(pushedparasize,POINTER_SIZE);
  181. if (left.nodetype=addrn) and
  182. (not(nf_procvarload in left.flags)) then
  183. begin
  184. if calloption=pocall_inline then
  185. begin
  186. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  187. cg.a_load_loc_ref(exprasmlist,left.location,href);
  188. end
  189. else
  190. cg.a_param_loc(exprasmlist,left.location,paraitem.paraloc);
  191. location_release(exprasmlist,left.location);
  192. end
  193. else
  194. begin
  195. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  196. internalerror(200304235);
  197. if calloption=pocall_inline then
  198. begin
  199. {$ifdef newra}
  200. tmpreg:=rg.getaddressregister(exprasmlist);
  201. {$else}
  202. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  203. {$endif newra}
  204. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  205. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  206. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  207. {$ifdef newra}
  208. rg.ungetregisterint(exprasmlist,tmpreg);
  209. {$else}
  210. cg.free_scratch_reg(exprasmlist,tmpreg);
  211. {$endif}
  212. end
  213. else
  214. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  215. location_release(exprasmlist,left.location);
  216. end;
  217. end
  218. { handle call by reference parameter }
  219. else if (paraitem.paratyp in [vs_var,vs_out]) then
  220. begin
  221. if (left.location.loc<>LOC_REFERENCE) then
  222. begin
  223. { passing self to a var parameter is allowed in
  224. TP and delphi }
  225. if not((left.location.loc=LOC_CREFERENCE) and
  226. is_self_node(left)) then
  227. internalerror(200106041);
  228. end;
  229. if (paraitem.paratyp=vs_out) and
  230. assigned(paraitem.paratype.def) and
  231. not is_class(paraitem.paratype.def) and
  232. paraitem.paratype.def.needs_inittable then
  233. cg.g_finalize(exprasmlist,paraitem.paratype.def,left.location.reference,false);
  234. inc(pushedparasize,POINTER_SIZE);
  235. if calloption=pocall_inline then
  236. begin
  237. {$ifdef newra}
  238. tmpreg:=rg.getaddressregister(exprasmlist);
  239. {$else}
  240. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  241. {$endif}
  242. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  243. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  244. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  245. {$ifdef newra}
  246. rg.ungetregisterint(exprasmlist,tmpreg);
  247. {$else}
  248. cg.free_scratch_reg(exprasmlist,tmpreg);
  249. {$endif}
  250. end
  251. else
  252. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  253. location_release(exprasmlist,left.location);
  254. end
  255. else
  256. begin
  257. { don't push a node that already generated a pointer type
  258. by address for implicit hidden parameters }
  259. if (not(
  260. paraitem.is_hidden and
  261. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  262. ) and
  263. paramanager.push_addr_param(paraitem.paratype.def,calloption)) then
  264. begin
  265. if not(left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  266. begin
  267. { allow passing nil to a procvardef (methodpointer) }
  268. if (left.nodetype=typeconvn) and
  269. (left.resulttype.def.deftype=procvardef) and
  270. (ttypeconvnode(left).left.nodetype=niln) then
  271. begin
  272. tg.GetTemp(exprasmlist,tcgsize2size[left.location.size],tt_normal,href);
  273. if not (left.location.size in [OS_64,OS_S64]) then
  274. cg.a_load_loc_ref(exprasmlist,left.location,href)
  275. else
  276. cg64.a_load64_loc_ref(exprasmlist,left.location,href);
  277. location_reset(left.location,LOC_REFERENCE,left.location.size);
  278. left.location.reference:=href;
  279. end
  280. else
  281. internalerror(200204011);
  282. end;
  283. inc(pushedparasize,POINTER_SIZE);
  284. if calloption=pocall_inline then
  285. begin
  286. {$ifdef newra}
  287. tmpreg:=rg.getaddressregister(exprasmlist);
  288. {$else}
  289. tmpreg:=cg.get_scratch_reg_address(exprasmlist);
  290. {$endif}
  291. cg.a_loadaddr_ref_reg(exprasmlist,left.location.reference,tmpreg);
  292. reference_reset_base(href,current_procinfo.framepointer,para_offset-pushedparasize);
  293. cg.a_load_reg_ref(exprasmlist,OS_ADDR,tmpreg,href);
  294. {$ifdef newra}
  295. rg.ungetregisterint(exprasmlist,tmpreg);
  296. {$else}
  297. cg.free_scratch_reg(exprasmlist,tmpreg);
  298. {$endif}
  299. end
  300. else
  301. cg.a_paramaddr_ref(exprasmlist,left.location.reference,paraitem.paraloc);
  302. location_release(exprasmlist,left.location);
  303. end
  304. else
  305. begin
  306. push_value_para(exprasmlist,left,calloption,
  307. para_offset,para_alignment,paraitem.paraloc);
  308. end;
  309. end;
  310. truelabel:=otlabel;
  311. falselabel:=oflabel;
  312. { update return location in callnode when this is the function
  313. result }
  314. if (vo_is_funcret in tvarsym(paraitem.parasym).varoptions) then
  315. begin
  316. location_copy(aktcallnode.location,left.location);
  317. end;
  318. { push from right to left }
  319. if not push_from_left_to_right and assigned(right) then
  320. begin
  321. if (nf_varargs_para in flags) then
  322. tcallparanode(right).secondcallparan(push_from_left_to_right,
  323. calloption,para_alignment,para_offset)
  324. else
  325. tcallparanode(right).secondcallparan(push_from_left_to_right,
  326. calloption,para_alignment,para_offset);
  327. end;
  328. end;
  329. {*****************************************************************************
  330. TCGCALLNODE
  331. *****************************************************************************}
  332. procedure tcgcallnode.extra_interrupt_code;
  333. begin
  334. end;
  335. function tcgcallnode.align_parasize(parasize,para_alignment:longint):longint;
  336. begin
  337. result:=0;
  338. end;
  339. procedure tcgcallnode.pop_parasize(pop_size:longint);
  340. begin
  341. end;
  342. procedure tcgcallnode.push_framepointer;
  343. var
  344. href : treference;
  345. hregister : tregister;
  346. i : integer;
  347. begin
  348. { this routine is itself not nested }
  349. if current_procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel) then
  350. begin
  351. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  352. cg.a_param_ref(exprasmlist,OS_ADDR,href,paramanager.getintparaloc(1));
  353. end
  354. { one nesting level }
  355. else if (current_procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  356. begin
  357. cg.a_param_reg(exprasmlist,OS_ADDR,current_procinfo.framepointer,paramanager.getintparaloc(1));
  358. end
  359. { very complex nesting level ... }
  360. else if (current_procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  361. begin
  362. hregister:=rg.getaddressregister(exprasmlist);
  363. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  364. cg.a_load_ref_reg(exprasmlist,OS_ADDR,href,hregister);
  365. i:=current_procdef.parast.symtablelevel;
  366. while (i>tprocdef(procdefinition).parast.symtablelevel) do
  367. begin
  368. reference_reset_base(href,hregister,current_procinfo.framepointer_offset);
  369. cg.a_load_ref_reg(exprasmlist,OS_ADDR,href,hregister);
  370. dec(i);
  371. end;
  372. cg.a_param_reg(exprasmlist,OS_ADDR,hregister,paramanager.getintparaloc(1));
  373. rg.ungetaddressregister(exprasmlist,hregister);
  374. end;
  375. end;
  376. procedure tcgcallnode.handle_return_value(inlined:boolean);
  377. var
  378. cgsize : tcgsize;
  379. r,hregister : tregister;
  380. nr:Tnewregister;
  381. begin
  382. { structured results are easy to handle.... }
  383. { needed also when result_no_used !! }
  384. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  385. begin
  386. { Location should be setup by the funcret para }
  387. if location.loc<>LOC_REFERENCE then
  388. internalerror(200304241);
  389. end
  390. else
  391. { ansi/widestrings must be registered, so we can dispose them }
  392. if is_ansistring(resulttype.def) or
  393. is_widestring(resulttype.def) then
  394. begin
  395. location_reset(location,LOC_CREFERENCE,OS_ADDR);
  396. location.reference:=refcountedtemp;
  397. r.enum:=accumulator;
  398. cg.a_reg_alloc(exprasmlist,r);
  399. cg.a_load_reg_ref(exprasmlist,OS_ADDR,r,location.reference);
  400. cg.a_reg_dealloc(exprasmlist,r);
  401. end
  402. else
  403. { we have only to handle the result if it is used }
  404. if (nf_return_value_used in flags) then
  405. begin
  406. if (resulttype.def.deftype=floatdef) then
  407. begin
  408. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  409. {$ifdef cpufpemu}
  410. if cs_fp_emulation in aktmoduleswitches then
  411. location.register.enum := accumulator
  412. else
  413. {$endif cpufpemu}
  414. location.register.enum:=FPU_RESULT_REG;
  415. {$ifdef x86}
  416. inc(trgcpu(rg).fpuvaroffset);
  417. {$else x86}
  418. hregister := rg.getregisterfpu(exprasmlist);
  419. cg.a_loadfpu_reg_reg(exprasmlist,location.register,hregister);
  420. location.register := hregister;
  421. {$endif x86}
  422. end
  423. else
  424. begin
  425. cgsize:=def_cgsize(resulttype.def);
  426. { an object constructor is a function with pointer result }
  427. if (inlined or (right=nil)) and
  428. (procdefinition.proctypeoption=potype_constructor) then
  429. cgsize:=OS_ADDR;
  430. if cgsize<>OS_NO then
  431. begin
  432. location_reset(location,LOC_REGISTER,cgsize);
  433. {$ifndef cpu64bit}
  434. if cgsize in [OS_64,OS_S64] then
  435. begin
  436. {Move the function result to free registers, preferably the
  437. accumulator/accumulatorhigh, so no move is necessary.}
  438. r.enum:=R_INTREGISTER;
  439. r.number:=NR_ACCUMULATOR;
  440. hregister.enum:=R_INTREGISTER;
  441. hregister.number:=NR_ACCUMULATORHIGH;
  442. {$ifdef newra}
  443. rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATOR);
  444. rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATORHIGH);
  445. rg.ungetregisterint(exprasmlist,r);
  446. rg.ungetregisterint(exprasmlist,hregister);
  447. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  448. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  449. {$else newra}
  450. if RS_ACCUMULATOR in rg.unusedregsint then
  451. location.registerlow:=rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATOR)
  452. else
  453. cg.a_reg_alloc(exprasmlist,r);
  454. if RS_ACCUMULATORHIGH in rg.unusedregsint then
  455. location.registerhigh:=rg.getexplicitregisterint(exprasmlist,NR_ACCUMULATORHIGH)
  456. else
  457. cg.a_reg_alloc(exprasmlist,hregister);
  458. { do this after both low,high are allocated, else it is possible that
  459. low will be loaded in the register that still contains high }
  460. if location.registerlow.number=NR_NO then
  461. location.registerlow:=rg.getregisterint(exprasmlist,OS_INT);
  462. if location.registerhigh.number=NR_NO then
  463. location.registerhigh:=rg.getregisterint(exprasmlist,OS_INT);
  464. {$endif newra}
  465. cg64.a_load64_reg_reg(exprasmlist,joinreg64(r,hregister),
  466. location.register64);
  467. end
  468. else
  469. {$endif cpu64bit}
  470. begin
  471. {Move the function result to a free register, preferably the
  472. accumulator, so no move is necessary.}
  473. nr:=RS_ACCUMULATOR shl 8 or cgsize2subreg(cgsize);
  474. r.enum:=R_INTREGISTER;
  475. r.number:=nr;
  476. {$ifdef newra}
  477. rg.getexplicitregisterint(exprasmlist,nr);
  478. rg.ungetregisterint(exprasmlist,r);
  479. location.register:=rg.getregisterint(exprasmlist,cgsize);
  480. {$else newra}
  481. cg.a_reg_alloc(exprasmlist,r);
  482. if RS_ACCUMULATOR in rg.unusedregsint then
  483. location.register:=rg.getexplicitregisterint(exprasmlist,nr)
  484. else
  485. location.register:=rg.getregisterint(exprasmlist,cgsize);
  486. {$endif newra}
  487. cg.a_load_reg_reg(exprasmlist,cgsize,cgsize,r,location.register);
  488. end;
  489. end
  490. else
  491. begin
  492. if resulttype.def.size>0 then
  493. internalerror(200305131);
  494. end;
  495. end;
  496. end
  497. else
  498. location_reset(location,LOC_VOID,OS_NO);
  499. end;
  500. procedure tcgcallnode.pass_2;
  501. var
  502. regs_to_push_int : Tsupregset;
  503. regs_to_push_other : tregisterset;
  504. unusedstate: pointer;
  505. pushedother : tpushedsavedother;
  506. pushedint : tpushedsavedint;
  507. oldpushedparasize : longint;
  508. { adress returned from an I/O-error }
  509. iolabel : tasmlabel;
  510. { help reference pointer }
  511. href : treference;
  512. hp : tnode;
  513. pp : tcallparanode;
  514. inlined : boolean;
  515. inlinecode : tprocinlinenode;
  516. pushedregs : tmaybesave;
  517. store_parast_fixup,
  518. para_alignment,
  519. para_offset : longint;
  520. pop_size : longint;
  521. returnref,
  522. pararef : treference;
  523. accreg : tregister;
  524. oldaktcallnode : tcallnode;
  525. begin
  526. iolabel:=nil;
  527. inlinecode:=nil;
  528. inlined:=false;
  529. rg.saveunusedstate(unusedstate);
  530. { if we allocate the temp. location for ansi- or widestrings }
  531. { already here, we avoid later a push/pop }
  532. if is_widestring(resulttype.def) then
  533. begin
  534. tg.GetTemp(exprasmlist,pointer_size,tt_widestring,refcountedtemp);
  535. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  536. end
  537. else if is_ansistring(resulttype.def) then
  538. begin
  539. tg.GetTemp(exprasmlist,pointer_size,tt_ansistring,refcountedtemp);
  540. cg.g_decrrefcount(exprasmlist,resulttype.def,refcountedtemp,false);
  541. end;
  542. if (procdefinition.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_stdcall]) then
  543. para_alignment:=4
  544. else
  545. para_alignment:=aktalignment.paraalign;
  546. if not assigned(procdefinition) then
  547. exit;
  548. if (procdefinition.proccalloption=pocall_inline) then
  549. begin
  550. inlined:=true;
  551. inlinecode:=tprocinlinenode(right);
  552. right:=nil;
  553. { set it to the same lexical level as the local symtable, becuase
  554. the para's are stored there }
  555. tprocdef(procdefinition).parast.symtablelevel:=current_procdef.localst.symtablelevel;
  556. if assigned(left) then
  557. begin
  558. inlinecode.para_size:=tprocdef(procdefinition).para_size(para_alignment);
  559. tg.GetTemp(exprasmlist,inlinecode.para_size,tt_persistent,pararef);
  560. inlinecode.para_offset:=pararef.offset;
  561. end;
  562. store_parast_fixup:=tprocdef(procdefinition).parast.address_fixup;
  563. tprocdef(procdefinition).parast.address_fixup:=inlinecode.para_offset;
  564. {$ifdef extdebug}
  565. Comment(V_debug,
  566. 'inlined parasymtable is at offset '
  567. +tostr(tprocdef(procdefinition).parast.address_fixup));
  568. exprasmList.concat(tai_comment.Create(
  569. strpnew('inlined parasymtable is at offset '
  570. +tostr(tprocdef(procdefinition).parast.address_fixup))));
  571. {$endif extdebug}
  572. end;
  573. { proc variables destroy all registers }
  574. if (inlined or
  575. (right=nil)) and
  576. { virtual methods too }
  577. not(po_virtualmethod in procdefinition.procoptions) then
  578. begin
  579. if (cs_check_io in aktlocalswitches) and
  580. (po_iocheck in procdefinition.procoptions) and
  581. not(po_iocheck in current_procdef.procoptions) then
  582. begin
  583. objectlibrary.getaddrlabel(iolabel);
  584. cg.a_label(exprasmlist,iolabel);
  585. end
  586. else
  587. iolabel:=nil;
  588. { save all used registers and possible registers
  589. used for the return value }
  590. regs_to_push_int := tprocdef(procdefinition).usedintregisters;
  591. regs_to_push_other := tprocdef(procdefinition).usedotherregisters;
  592. if (not is_void(resulttype.def)) and
  593. (not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption)) then
  594. begin
  595. include(regs_to_push_int,RS_ACCUMULATOR);
  596. {$ifndef cpu64bit}
  597. if resulttype.def.size>sizeof(aword) then
  598. include(regs_to_push_int,RS_ACCUMULATORHIGH);
  599. {$endif cpu64bit}
  600. end;
  601. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  602. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  603. { give used registers through }
  604. rg.usedintinproc:=rg.usedintinproc + tprocdef(procdefinition).usedintregisters;
  605. rg.usedinproc:=rg.usedinproc + tprocdef(procdefinition).usedotherregisters;
  606. end
  607. else
  608. begin
  609. regs_to_push_int := all_intregisters;
  610. regs_to_push_other := all_registers;
  611. rg.saveusedintregisters(exprasmlist,pushedint,regs_to_push_int);
  612. rg.saveusedotherregisters(exprasmlist,pushedother,regs_to_push_other);
  613. rg.usedinproc:=all_registers;
  614. { no IO check for methods and procedure variables }
  615. iolabel:=nil;
  616. end;
  617. { Initialize for pushing the parameters }
  618. oldpushedparasize:=pushedparasize;
  619. pushedparasize:=0;
  620. pop_size:=0;
  621. { Align stack if required }
  622. if not inlined then
  623. pop_size:=align_parasize(oldpushedparasize,para_alignment);
  624. { Push parameters }
  625. oldaktcallnode:=aktcallnode;
  626. aktcallnode:=self;
  627. { process procvar. Done here already, because otherwise it may }
  628. { destroy registers containing a parameter for the actual }
  629. { function call (e.g. if it's a function, its result will }
  630. { overwrite r3, which contains the first parameter) (JM) }
  631. if not(inlined) and
  632. assigned(right) then
  633. secondpass(right);
  634. if inlined or
  635. (right = nil) then
  636. begin
  637. if (po_virtualmethod in procdefinition.procoptions) and
  638. assigned(methodpointer) then
  639. begin
  640. secondpass(methodpointer);
  641. location_force_reg(exprasmlist,methodpointer.location,OS_ADDR,false);
  642. { virtual methods require an index }
  643. if tprocdef(procdefinition).extnumber=-1 then
  644. internalerror(200304021);
  645. { VMT should already be loaded in a register }
  646. if methodpointer.location.register.number=NR_NO then
  647. internalerror(200304022);
  648. { test validity of VMT }
  649. if not(is_interface(tprocdef(procdefinition)._class)) and
  650. not(is_cppclass(tprocdef(procdefinition)._class)) then
  651. cg.g_maybe_testvmt(exprasmlist,methodpointer.location.register,tprocdef(procdefinition)._class);
  652. end;
  653. end;
  654. if assigned(left) then
  655. begin
  656. {$ifndef newra}
  657. if assigned(right) then
  658. maybe_save(exprasmlist,left.registers32,right.location,pushedregs)
  659. else
  660. if assigned(methodpointer) then
  661. maybe_save(exprasmlist,left.registers32,methodpointer.location,pushedregs);
  662. {$endif}
  663. { be found elsewhere }
  664. if inlined then
  665. para_offset:=tprocdef(procdefinition).parast.address_fixup+
  666. tprocdef(procdefinition).parast.datasize
  667. else
  668. para_offset:=0;
  669. if not(inlined) and
  670. assigned(right) then
  671. tcallparanode(left).secondcallparan(
  672. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  673. para_alignment,para_offset)
  674. else
  675. tcallparanode(left).secondcallparan(
  676. (po_leftright in procdefinition.procoptions),procdefinition.proccalloption,
  677. para_alignment,para_offset);
  678. {$ifndef newra}
  679. if assigned(right) then
  680. maybe_restore(exprasmlist,right.location,pushedregs)
  681. else
  682. if assigned(methodpointer) then
  683. maybe_restore(exprasmlist,methodpointer.location,pushedregs);
  684. {$endif newra}
  685. end;
  686. aktcallnode:=oldaktcallnode;
  687. { Allocate return value for inlined routines }
  688. if inlined and
  689. (resulttype.def.size>0) then
  690. begin
  691. tg.GetTemp(exprasmlist,Align(resulttype.def.size,aktalignment.paraalign),tt_persistent,returnref);
  692. inlinecode.retoffset:=returnref.offset;
  693. end;
  694. { procedure variable or normal function call ? }
  695. if inlined or
  696. (right=nil) then
  697. begin
  698. { push base pointer ?}
  699. { never when inlining, since if necessary, the base pointer }
  700. { can/will be gottten from the current procedure's symtable }
  701. { (JM) }
  702. if not inlined then
  703. if (current_procdef.parast.symtablelevel>=normal_function_level) and
  704. assigned(tprocdef(procdefinition).parast) and
  705. ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then
  706. push_framepointer;
  707. rg.saveintregvars(exprasmlist,regs_to_push_int);
  708. rg.saveotherregvars(exprasmlist,regs_to_push_other);
  709. if (po_virtualmethod in procdefinition.procoptions) and
  710. assigned(methodpointer) then
  711. begin
  712. { call method }
  713. reference_reset_base(href,methodpointer.location.register,
  714. tprocdef(procdefinition)._class.vmtmethodoffset(tprocdef(procdefinition).extnumber));
  715. cg.a_call_ref(exprasmlist,href);
  716. { release self }
  717. rg.ungetaddressregister(exprasmlist,methodpointer.location.register);
  718. end
  719. else
  720. begin
  721. if not inlined then
  722. begin
  723. { Calling interrupt from the same code requires some
  724. extra code }
  725. if (po_interrupt in procdefinition.procoptions) then
  726. extra_interrupt_code;
  727. cg.a_call_name(exprasmlist,tprocdef(procdefinition).mangledname);
  728. end
  729. else { inlined proc }
  730. begin
  731. { process the inlinecode }
  732. secondpass(tnode(inlinecode));
  733. { free the args }
  734. if tprocdef(procdefinition).parast.datasize>0 then
  735. tg.UnGetTemp(exprasmlist,pararef);
  736. end;
  737. end;
  738. end
  739. else
  740. { now procedure variable case }
  741. begin
  742. { Calling interrupt from the same code requires some
  743. extra code }
  744. if (po_interrupt in procdefinition.procoptions) then
  745. extra_interrupt_code;
  746. if (po_methodpointer in procdefinition.procoptions) then
  747. begin
  748. { push self }
  749. href:=right.location.reference;
  750. inc(href.offset,POINTER_SIZE);
  751. cg.a_param_ref(exprasmlist,OS_ADDR,href,paramanager.getintparaloc(1));
  752. rg.saveintregvars(exprasmlist,ALL_INTREGISTERS);
  753. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  754. cg.a_call_ref(exprasmlist,right.location.reference);
  755. reference_release(exprasmlist,right.location.reference);
  756. tg.Ungetiftemp(exprasmlist,right.location.reference);
  757. end
  758. else
  759. begin
  760. rg.saveintregvars(exprasmlist,ALL_INTREGISTERS);
  761. rg.saveotherregvars(exprasmlist,ALL_REGISTERS);
  762. cg.a_call_loc(exprasmlist,right.location);
  763. location_release(exprasmlist,right.location);
  764. location_freetemp(exprasmlist,right.location);
  765. end;
  766. end;
  767. { Need to remove the parameters from the stack? }
  768. if (not inlined) and (po_clearstack in procdefinition.procoptions) then
  769. begin
  770. { the old pop_size was already included in pushedparasize }
  771. pop_size:=pushedparasize;
  772. { for Cdecl functions we don't need to pop the funcret when it
  773. was pushed by para }
  774. if paramanager.ret_in_param(procdefinition.rettype.def,procdefinition.proccalloption) then
  775. dec(pop_size,POINTER_SIZE);
  776. end;
  777. { Remove parameters/alignment from the stack }
  778. if pop_size>0 then
  779. pop_parasize(pop_size);
  780. {$ifdef powerpc}
  781. { this calculation must be done in pass_1 anyway, so don't worry }
  782. if tppcprocinfo(current_procinfo).maxpushedparasize<pushedparasize then
  783. tppcprocinfo(current_procinfo).maxpushedparasize:=pushedparasize;
  784. {$endif powerpc}
  785. { Restore }
  786. pushedparasize:=oldpushedparasize;
  787. rg.restoreunusedstate(unusedstate);
  788. {$ifdef TEMPREGDEBUG}
  789. testregisters32;
  790. {$endif TEMPREGDEBUG}
  791. { handle function results }
  792. if (not is_void(resulttype.def)) then
  793. handle_return_value(inlined)
  794. else
  795. location_reset(location,LOC_VOID,OS_NO);
  796. { perhaps i/o check ? }
  797. if iolabel<>nil then
  798. begin
  799. reference_reset_symbol(href,iolabel,0);
  800. cg.a_paramaddr_ref(exprasmlist,href,paramanager.getintparaloc(1));
  801. cg.a_call_name(exprasmlist,'FPC_IOCHECK');
  802. end;
  803. { restore registers }
  804. rg.restoreusedotherregisters(exprasmlist,pushedother);
  805. rg.restoreusedintregisters(exprasmlist,pushedint);
  806. { Release temps from parameters }
  807. pp:=tcallparanode(left);
  808. while assigned(pp) do
  809. begin
  810. if assigned(pp.left) then
  811. begin
  812. { don't release the funcret temp }
  813. if not(vo_is_funcret in tvarsym(pp.paraitem.parasym).varoptions) then
  814. location_freetemp(exprasmlist,pp.left.location);
  815. { process also all nodes of an array of const }
  816. if pp.left.nodetype=arrayconstructorn then
  817. begin
  818. if assigned(tarrayconstructornode(pp.left).left) then
  819. begin
  820. hp:=pp.left;
  821. while assigned(hp) do
  822. begin
  823. location_freetemp(exprasmlist,tarrayconstructornode(hp).left.location);
  824. hp:=tarrayconstructornode(hp).right;
  825. end;
  826. end;
  827. end;
  828. end;
  829. pp:=tcallparanode(pp.right);
  830. end;
  831. if inlined then
  832. begin
  833. if (resulttype.def.size>0) then
  834. tg.UnGetTemp(exprasmlist,returnref);
  835. tprocdef(procdefinition).parast.address_fixup:=store_parast_fixup;
  836. right:=inlinecode;
  837. { from now on the result can be freed normally }
  838. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  839. tg.ChangeTempType(exprasmlist,funcretnode.location.reference,tt_normal);
  840. end;
  841. { if return value is not used }
  842. if (not(nf_return_value_used in flags)) and (not is_void(resulttype.def)) then
  843. begin
  844. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  845. begin
  846. { data which must be finalized ? }
  847. if (resulttype.def.needs_inittable) then
  848. cg.g_finalize(exprasmlist,resulttype.def,location.reference,false);
  849. { release unused temp }
  850. tg.ungetiftemp(exprasmlist,location.reference)
  851. end
  852. else if location.loc=LOC_FPUREGISTER then
  853. begin
  854. {$ifdef x86}
  855. { release FPU stack }
  856. accreg.enum:=FPU_RESULT_REG;
  857. emit_reg(A_FSTP,S_NO,accreg);
  858. {
  859. dec(trgcpu(rg).fpuvaroffset);
  860. do NOT decrement as the increment before
  861. is not called for unused results PM }
  862. {$endif x86}
  863. end;
  864. end;
  865. end;
  866. {*****************************************************************************
  867. TCGPROCINLINENODE
  868. *****************************************************************************}
  869. procedure tcgprocinlinenode.pass_2;
  870. var st : tsymtable;
  871. oldprocdef : tprocdef;
  872. ps, i : longint;
  873. oldprocinfo : tprocinfo;
  874. oldinlining_procedure,
  875. nostackframe,make_global : boolean;
  876. inlineentrycode,inlineexitcode : TAAsmoutput;
  877. oldexitlabel,oldexit2label:tasmlabel;
  878. oldregstate: pointer;
  879. localsref : treference;
  880. {$ifdef GDB}
  881. startlabel,endlabel : tasmlabel;
  882. pp : pchar;
  883. mangled_length : longint;
  884. {$endif GDB}
  885. begin
  886. { deallocate the registers used for the current procedure's regvars }
  887. if assigned(current_procdef.regvarinfo) then
  888. begin
  889. with pregvarinfo(current_procdef.regvarinfo)^ do
  890. for i := 1 to maxvarregs do
  891. if assigned(regvars[i]) then
  892. store_regvar(exprasmlist,regvars[i].reg);
  893. rg.saveStateForInline(oldregstate);
  894. { make sure the register allocator knows what the regvars in the }
  895. { inlined code block are (JM) }
  896. rg.resetusableregisters;
  897. rg.clearregistercount;
  898. {$ifndef newra}
  899. rg.cleartempgen;
  900. {$endif}
  901. if assigned(inlineprocdef.regvarinfo) then
  902. with pregvarinfo(inlineprocdef.regvarinfo)^ do
  903. for i := 1 to maxvarregs do
  904. if assigned(regvars[i]) then
  905. begin
  906. {Fix me!!}
  907. {tmpreg:=rg.makeregsize(regvars[i].reg,OS_INT);
  908. rg.makeregvar(tmpreg);}
  909. internalerror(200301232);
  910. end;
  911. end;
  912. oldinlining_procedure:=inlining_procedure;
  913. oldexitlabel:=aktexitlabel;
  914. oldexit2label:=aktexit2label;
  915. oldprocdef:=current_procdef;
  916. oldprocinfo:=current_procinfo;
  917. objectlibrary.getlabel(aktexitlabel);
  918. objectlibrary.getlabel(aktexit2label);
  919. { we're inlining a procedure }
  920. inlining_procedure:=true;
  921. current_procdef:=inlineprocdef;
  922. { clone procinfo, but not the asmlists }
  923. current_procinfo:=tprocinfo(cprocinfo.newinstance);
  924. move(pointer(oldprocinfo)^,pointer(current_procinfo)^,cprocinfo.InstanceSize);
  925. current_procinfo.aktentrycode:=nil;
  926. current_procinfo.aktexitcode:=nil;
  927. current_procinfo.aktproccode:=nil;
  928. current_procinfo.aktlocaldata:=nil;
  929. { set new procinfo }
  930. current_procinfo.return_offset:=retoffset;
  931. { arg space has been filled by the parent secondcall }
  932. st:=current_procdef.localst;
  933. { set it to the same lexical level }
  934. st.symtablelevel:=oldprocdef.localst.symtablelevel;
  935. if st.datasize>0 then
  936. begin
  937. tg.GetTemp(exprasmlist,st.datasize,tt_persistent,localsref);
  938. if tg.direction>0 then
  939. st.address_fixup:=localsref.offset
  940. else
  941. st.address_fixup:=localsref.offset+st.datasize;
  942. {$ifdef extdebug}
  943. Comment(V_debug,'local symtable is at offset '+tostr(st.address_fixup));
  944. exprasmList.concat(tai_comment.Create(strpnew(
  945. 'local symtable is at offset '+tostr(st.address_fixup))));
  946. {$endif extdebug}
  947. end;
  948. exprasmList.concat(Tai_Marker.Create(InlineStart));
  949. {$ifdef extdebug}
  950. exprasmList.concat(tai_comment.Create(strpnew('Start of inlined proc')));
  951. {$endif extdebug}
  952. {$ifdef GDB}
  953. if (cs_debuginfo in aktmoduleswitches) then
  954. begin
  955. objectlibrary.getaddrlabel(startlabel);
  956. objectlibrary.getaddrlabel(endlabel);
  957. cg.a_label(exprasmlist,startlabel);
  958. inlineprocdef.localst.symtabletype:=inlinelocalsymtable;
  959. inlineprocdef.parast.symtabletype:=inlineparasymtable;
  960. { Here we must include the para and local symtable info }
  961. inlineprocdef.concatstabto(withdebuglist);
  962. { set it back for safety }
  963. inlineprocdef.localst.symtabletype:=localsymtable;
  964. inlineprocdef.parast.symtabletype:=parasymtable;
  965. mangled_length:=length(oldprocdef.mangledname);
  966. getmem(pp,mangled_length+50);
  967. strpcopy(pp,'192,0,0,'+startlabel.name);
  968. if (target_info.use_function_relative_addresses) then
  969. begin
  970. strpcopy(strend(pp),'-');
  971. strpcopy(strend(pp),oldprocdef.mangledname);
  972. end;
  973. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  974. end;
  975. {$endif GDB}
  976. { takes care of local data initialization }
  977. inlineentrycode:=TAAsmoutput.Create;
  978. inlineexitcode:=TAAsmoutput.Create;
  979. ps:=para_size;
  980. genentrycode(inlineentrycode,0,ps,nostackframe,true);
  981. if po_assembler in current_procdef.procoptions then
  982. inlineentrycode.insert(Tai_marker.Create(asmblockstart));
  983. exprasmList.concatlist(inlineentrycode);
  984. secondpass(inlinetree);
  985. genexitcode(inlineexitcode,0,false,true);
  986. if po_assembler in current_procdef.procoptions then
  987. inlineexitcode.concat(Tai_marker.Create(asmblockend));
  988. exprasmList.concatlist(inlineexitcode);
  989. inlineentrycode.free;
  990. inlineexitcode.free;
  991. {$ifdef extdebug}
  992. exprasmList.concat(tai_comment.Create(strpnew('End of inlined proc')));
  993. {$endif extdebug}
  994. exprasmList.concat(Tai_Marker.Create(InlineEnd));
  995. {we can free the local data now, reset also the fixup address }
  996. if st.datasize>0 then
  997. begin
  998. tg.UnGetTemp(exprasmlist,localsref);
  999. st.address_fixup:=0;
  1000. end;
  1001. { restore procinfo }
  1002. current_procinfo.free;
  1003. current_procinfo:=oldprocinfo;
  1004. {$ifdef GDB}
  1005. if (cs_debuginfo in aktmoduleswitches) then
  1006. begin
  1007. cg.a_label(exprasmlist,endlabel);
  1008. strpcopy(pp,'224,0,0,'+endlabel.name);
  1009. if (target_info.use_function_relative_addresses) then
  1010. begin
  1011. strpcopy(strend(pp),'-');
  1012. strpcopy(strend(pp),oldprocdef.mangledname);
  1013. end;
  1014. withdebugList.concat(Tai_stabn.Create(strnew(pp)));
  1015. freemem(pp,mangled_length+50);
  1016. end;
  1017. {$endif GDB}
  1018. { restore }
  1019. current_procdef:=oldprocdef;
  1020. aktexitlabel:=oldexitlabel;
  1021. aktexit2label:=oldexit2label;
  1022. inlining_procedure:=oldinlining_procedure;
  1023. { reallocate the registers used for the current procedure's regvars, }
  1024. { since they may have been used and then deallocated in the inlined }
  1025. { procedure (JM) }
  1026. if assigned(current_procdef.regvarinfo) then
  1027. begin
  1028. rg.restoreStateAfterInline(oldregstate);
  1029. end;
  1030. end;
  1031. begin
  1032. ccallparanode:=tcgcallparanode;
  1033. ccallnode:=tcgcallnode;
  1034. cprocinlinenode:=tcgprocinlinenode;
  1035. end.
  1036. {
  1037. $Log$
  1038. Revision 1.72 2003-05-24 13:36:54 jonas
  1039. * save fpu results in a normal fpu register on non-x86 processors
  1040. Revision 1.71 2003/05/23 19:35:50 jonas
  1041. - undid previous commit, it was wrong
  1042. Revision 1.70 2003/05/23 19:11:58 jonas
  1043. * fixed tests for whether a certain int register is unused
  1044. Revision 1.69 2003/05/23 18:01:56 jonas
  1045. * fixed ppc compiler
  1046. Revision 1.68 2003/05/23 14:27:35 peter
  1047. * remove some unit dependencies
  1048. * current_procinfo changes to store more info
  1049. Revision 1.67 2003/05/17 13:30:08 jonas
  1050. * changed tt_persistant to tt_persistent :)
  1051. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1052. temps, but a ttemptype, so you can also create ansistring temps etc
  1053. Revision 1.66 2003/05/16 14:33:31 peter
  1054. * regvar fixes
  1055. Revision 1.65 2003/05/15 18:58:53 peter
  1056. * removed selfpointer_offset, vmtpointer_offset
  1057. * tvarsym.adjusted_address
  1058. * address in localsymtable is now in the real direction
  1059. * removed some obsolete globals
  1060. Revision 1.64 2003/05/14 19:36:54 jonas
  1061. * patch from Peter for int64 function results
  1062. Revision 1.63 2003/05/13 19:14:41 peter
  1063. * failn removed
  1064. * inherited result code check moven to pexpr
  1065. Revision 1.62 2003/05/13 15:18:18 peter
  1066. * generate code for procvar first before pushing parameters. Made
  1067. the already existing code for powerpc available for all platforms
  1068. Revision 1.61 2003/05/12 18:17:55 jonas
  1069. * moved fpc_check_object call earlier for the ppc, so it can't destroy
  1070. already-loaded parameter registers
  1071. Revision 1.60 2003/05/11 21:48:38 jonas
  1072. * fixed procvar bug on the ppc (load procvar before loading para's,
  1073. because the procvar may otherwise destroy the already loaded paras)
  1074. Revision 1.59 2003/05/09 17:47:02 peter
  1075. * self moved to hidden parameter
  1076. * removed hdisposen,hnewn,selfn
  1077. Revision 1.58 2003/05/05 14:53:16 peter
  1078. * vs_hidden replaced by is_hidden boolean
  1079. Revision 1.57 2003/04/30 20:53:32 florian
  1080. * error when address of an abstract method is taken
  1081. * fixed some x86-64 problems
  1082. * merged some more x86-64 and i386 code
  1083. Revision 1.56 2003/04/29 07:28:52 michael
  1084. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1085. Revision 1.55 2003/04/27 11:21:33 peter
  1086. * aktprocdef renamed to current_procdef
  1087. * procinfo renamed to current_procinfo
  1088. * procinfo will now be stored in current_module so it can be
  1089. cleaned up properly
  1090. * gen_main_procsym changed to create_main_proc and release_main_proc
  1091. to also generate a tprocinfo structure
  1092. * fixed unit implicit initfinal
  1093. Revision 1.54 2003/04/27 07:29:50 peter
  1094. * current_procdef cleanup, current_procdef is now always nil when parsing
  1095. a new procdef declaration
  1096. * aktprocsym removed
  1097. * lexlevel removed, use symtable.symtablelevel instead
  1098. * implicit init/final code uses the normal genentry/genexit
  1099. * funcret state checking updated for new funcret handling
  1100. Revision 1.53 2003/04/25 20:59:33 peter
  1101. * removed funcretn,funcretsym, function result is now in varsym
  1102. and aliases for result and function name are added using absolutesym
  1103. * vs_hidden parameter for funcret passed in parameter
  1104. * vs_hidden fixes
  1105. * writenode changed to printnode and released from extdebug
  1106. * -vp option added to generate a tree.log with the nodetree
  1107. * nicer printnode for statements, callnode
  1108. Revision 1.52 2003/04/25 08:25:26 daniel
  1109. * Ifdefs around a lot of calls to cleartempgen
  1110. * Fixed registers that are allocated but not freed in several nodes
  1111. * Tweak to register allocator to cause less spills
  1112. * 8-bit registers now interfere with esi,edi and ebp
  1113. Compiler can now compile rtl successfully when using new register
  1114. allocator
  1115. Revision 1.51 2003/04/22 23:50:22 peter
  1116. * firstpass uses expectloc
  1117. * checks if there are differences between the expectloc and
  1118. location.loc from secondpass in EXTDEBUG
  1119. Revision 1.50 2003/04/22 14:33:38 peter
  1120. * removed some notes/hints
  1121. Revision 1.49 2003/04/22 13:47:08 peter
  1122. * fixed C style array of const
  1123. * fixed C array passing
  1124. * fixed left to right with high parameters
  1125. Revision 1.48 2003/04/22 10:09:34 daniel
  1126. + Implemented the actual register allocator
  1127. + Scratch registers unavailable when new register allocator used
  1128. + maybe_save/maybe_restore unavailable when new register allocator used
  1129. Revision 1.47 2003/04/22 09:49:44 peter
  1130. * do not load self when calling a non-inherited class constructor
  1131. Revision 1.46 2003/04/21 20:03:32 peter
  1132. * forgot to copy vmtrefaddr to selfrefaddr when self=vmt
  1133. Revision 1.45 2003/04/21 13:53:16 jonas
  1134. - removed copying of all paras when secondpassing a callnode (this used
  1135. to be necessary for inlinign support, but currently the whole inlined
  1136. procedure is already copied in advance). Note that the compiler crashes
  1137. when compiling ucomplex with -dTEST_INLINE (also after fixing the
  1138. syntax errors), but that was also the case before this change.
  1139. Revision 1.44 2003/04/10 17:57:52 peter
  1140. * vs_hidden released
  1141. Revision 1.43 2003/04/06 21:11:23 olle
  1142. * changed newasmsymbol to newasmsymboldata for data symbols
  1143. Revision 1.42 2003/04/04 15:38:56 peter
  1144. * moved generic code from n386cal to ncgcal, i386 now also
  1145. uses the generic ncgcal
  1146. Revision 1.41 2003/03/28 19:16:56 peter
  1147. * generic constructor working for i386
  1148. * remove fixed self register
  1149. * esi added as address register for i386
  1150. Revision 1.40 2003/03/06 11:35:50 daniel
  1151. * Fixed internalerror 7843 issue
  1152. Revision 1.39 2003/02/19 22:00:14 daniel
  1153. * Code generator converted to new register notation
  1154. - Horribily outdated todo.txt removed
  1155. Revision 1.38 2003/02/15 22:17:38 carl
  1156. * bugfix of FPU emulation code
  1157. Revision 1.37 2003/02/12 22:10:07 carl
  1158. * load_frame_pointer is now generic
  1159. * change fpu emulation routine names
  1160. Revision 1.36 2003/01/30 21:46:57 peter
  1161. * self fixes for static methods (merged)
  1162. Revision 1.35 2003/01/22 20:45:15 mazen
  1163. * making math code in RTL compiling.
  1164. *NB : This does NOT mean necessary that it will generate correct code!
  1165. Revision 1.34 2003/01/17 12:03:45 daniel
  1166. * Optalign conditional code adapted to record Tregister
  1167. Revision 1.33 2003/01/08 18:43:56 daniel
  1168. * Tregister changed into a record
  1169. Revision 1.32 2002/12/15 22:50:00 florian
  1170. + some stuff for the new hidden parameter handling added
  1171. Revision 1.31 2002/12/15 21:30:12 florian
  1172. * tcallnode.paraitem introduced, all references to defcoll removed
  1173. Revision 1.30 2002/11/27 20:04:39 peter
  1174. * cdecl array of const fixes
  1175. Revision 1.29 2002/11/25 17:43:17 peter
  1176. * splitted defbase in defutil,symutil,defcmp
  1177. * merged isconvertable and is_equal into compare_defs(_ext)
  1178. * made operator search faster by walking the list only once
  1179. Revision 1.28 2002/11/18 17:31:54 peter
  1180. * pass proccalloption to ret_in_xxx and push_xxx functions
  1181. Revision 1.27 2002/11/16 15:34:30 florian
  1182. * generic location for float results
  1183. Revision 1.26 2002/11/15 01:58:51 peter
  1184. * merged changes from 1.0.7 up to 04-11
  1185. - -V option for generating bug report tracing
  1186. - more tracing for option parsing
  1187. - errors for cdecl and high()
  1188. - win32 import stabs
  1189. - win32 records<=8 are returned in eax:edx (turned off by default)
  1190. - heaptrc update
  1191. - more info for temp management in .s file with EXTDEBUG
  1192. Revision 1.25 2002/10/05 12:43:25 carl
  1193. * fixes for Delphi 6 compilation
  1194. (warning : Some features do not work under Delphi)
  1195. Revision 1.24 2002/09/30 07:00:45 florian
  1196. * fixes to common code to get the alpha compiler compiled applied
  1197. Revision 1.23 2002/09/17 18:54:02 jonas
  1198. * a_load_reg_reg() now has two size parameters: source and dest. This
  1199. allows some optimizations on architectures that don't encode the
  1200. register size in the register name.
  1201. Revision 1.22 2002/09/07 15:25:02 peter
  1202. * old logs removed and tabs fixed
  1203. Revision 1.21 2002/09/07 11:50:02 jonas
  1204. * fixed small regalloction info bug
  1205. Revision 1.20 2002/09/02 11:25:20 florian
  1206. * fixed generic procedure variable calling
  1207. Revision 1.19 2002/09/01 21:04:48 florian
  1208. * several powerpc related stuff fixed
  1209. Revision 1.18 2002/09/01 18:43:27 peter
  1210. * include accumulator in regs_to_push list
  1211. Revision 1.17 2002/09/01 12:13:00 peter
  1212. * use a_call_reg
  1213. * ungetiftemp for procvar of object temp
  1214. Revision 1.16 2002/08/25 19:25:18 peter
  1215. * sym.insert_in_data removed
  1216. * symtable.insertvardata/insertconstdata added
  1217. * removed insert_in_data call from symtable.insert, it needs to be
  1218. called separatly. This allows to deref the address calculation
  1219. * procedures now calculate the parast addresses after the procedure
  1220. directives are parsed. This fixes the cdecl parast problem
  1221. * push_addr_param has an extra argument that specifies if cdecl is used
  1222. or not
  1223. Revision 1.15 2002/08/23 16:14:48 peter
  1224. * tempgen cleanup
  1225. * tt_noreuse temp type added that will be used in genentrycode
  1226. Revision 1.14 2002/08/20 16:55:38 peter
  1227. * don't write (stabs)line info when inlining a procedure
  1228. Revision 1.13 2002/08/19 19:36:42 peter
  1229. * More fixes for cross unit inlining, all tnodes are now implemented
  1230. * Moved pocall_internconst to po_internconst because it is not a
  1231. calling type at all and it conflicted when inlining of these small
  1232. functions was requested
  1233. Revision 1.12 2002/08/18 20:06:23 peter
  1234. * inlining is now also allowed in interface
  1235. * renamed write/load to ppuwrite/ppuload
  1236. * tnode storing in ppu
  1237. * nld,ncon,nbas are already updated for storing in ppu
  1238. Revision 1.11 2002/08/17 22:09:44 florian
  1239. * result type handling in tcgcal.pass_2 overhauled
  1240. * better tnode.dowrite
  1241. * some ppc stuff fixed
  1242. Revision 1.10 2002/08/17 09:23:35 florian
  1243. * first part of procinfo rewrite
  1244. Revision 1.9 2002/08/13 21:40:55 florian
  1245. * more fixes for ppc calling conventions
  1246. Revision 1.8 2002/08/13 18:01:51 carl
  1247. * rename swatoperands to swapoperands
  1248. + m68k first compilable version (still needs a lot of testing):
  1249. assembler generator, system information , inline
  1250. assembler reader.
  1251. Revision 1.7 2002/08/12 15:08:39 carl
  1252. + stab register indexes for powerpc (moved from gdb to cpubase)
  1253. + tprocessor enumeration moved to cpuinfo
  1254. + linker in target_info is now a class
  1255. * many many updates for m68k (will soon start to compile)
  1256. - removed some ifdef or correct them for correct cpu
  1257. Revision 1.6 2002/08/11 14:32:26 peter
  1258. * renamed current_library to objectlibrary
  1259. Revision 1.5 2002/08/11 13:24:11 peter
  1260. * saving of asmsymbols in ppu supported
  1261. * asmsymbollist global is removed and moved into a new class
  1262. tasmlibrarydata that will hold the info of a .a file which
  1263. corresponds with a single module. Added librarydata to tmodule
  1264. to keep the library info stored for the module. In the future the
  1265. objectfiles will also be stored to the tasmlibrarydata class
  1266. * all getlabel/newasmsymbol and friends are moved to the new class
  1267. Revision 1.4 2002/08/06 20:55:20 florian
  1268. * first part of ppc calling conventions fix
  1269. Revision 1.3 2002/07/20 11:57:53 florian
  1270. * types.pas renamed to defbase.pas because D6 contains a types
  1271. unit so this would conflicts if D6 programms are compiled
  1272. + Willamette/SSE2 instructions to assembler added
  1273. Revision 1.2 2002/07/13 19:38:43 florian
  1274. * some more generic calling stuff fixed
  1275. }