cg386cal.pas 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Generate i386 assembler for in call nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cg386cal;
  19. interface
  20. { $define AnsiStrRef}
  21. uses
  22. symtable,tree;
  23. procedure secondcallparan(var p : ptree;defcoll : pparaitem;
  24. push_from_left_to_right,inlined,dword_align : boolean;para_offset : longint);
  25. procedure secondcalln(var p : ptree);
  26. procedure secondprocinline(var p : ptree);
  27. implementation
  28. uses
  29. globtype,systems,
  30. cobjects,verbose,globals,
  31. symconst,aasm,types,
  32. {$ifdef GDB}
  33. gdb,
  34. {$endif GDB}
  35. hcodegen,temp_gen,pass_2,
  36. cpubase,cpuasm,
  37. cgai386,tgeni386,cg386ld;
  38. {*****************************************************************************
  39. SecondCallParaN
  40. *****************************************************************************}
  41. procedure secondcallparan(var p : ptree;defcoll : pparaitem;
  42. push_from_left_to_right,inlined,dword_align : boolean;para_offset : longint);
  43. procedure maybe_push_high;
  44. begin
  45. { open array ? }
  46. { defcoll^.data can be nil for read/write }
  47. if assigned(defcoll^.paratype.def) and
  48. push_high_param(defcoll^.paratype.def) then
  49. begin
  50. if assigned(p^.hightree) then
  51. begin
  52. secondpass(p^.hightree);
  53. { this is a longint anyway ! }
  54. push_value_para(p^.hightree,inlined,para_offset,4);
  55. end
  56. else
  57. internalerror(432645);
  58. end;
  59. end;
  60. var
  61. otlabel,oflabel : pasmlabel;
  62. align : longint;
  63. { temporary variables: }
  64. tempdeftype : tdeftype;
  65. r : preference;
  66. begin
  67. { push from left to right if specified }
  68. if push_from_left_to_right and assigned(p^.right) then
  69. secondcallparan(p^.right,pparaitem(defcoll^.next),push_from_left_to_right,
  70. inlined,dword_align,para_offset);
  71. otlabel:=truelabel;
  72. oflabel:=falselabel;
  73. getlabel(truelabel);
  74. getlabel(falselabel);
  75. secondpass(p^.left);
  76. { filter array constructor with c styled args }
  77. if is_array_constructor(p^.left^.resulttype) and p^.left^.cargs then
  78. begin
  79. { nothing, everything is already pushed }
  80. end
  81. { in codegen.handleread.. defcoll^.data is set to nil }
  82. else if assigned(defcoll^.paratype.def) and
  83. (defcoll^.paratype.def^.deftype=formaldef) then
  84. begin
  85. { allow @var }
  86. inc(pushedparasize,4);
  87. if p^.left^.treetype=addrn then
  88. begin
  89. { always a register }
  90. if inlined then
  91. begin
  92. r:=new_reference(procinfo^.framepointer,para_offset-pushedparasize);
  93. emit_reg_ref(A_MOV,S_L,
  94. p^.left^.location.register,r);
  95. end
  96. else
  97. emit_reg(A_PUSH,S_L,p^.left^.location.register);
  98. ungetregister32(p^.left^.location.register);
  99. end
  100. else
  101. begin
  102. if not(p^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  103. CGMessage(type_e_mismatch)
  104. else
  105. begin
  106. if inlined then
  107. begin
  108. emit_ref_reg(A_LEA,S_L,
  109. newreference(p^.left^.location.reference),R_EDI);
  110. r:=new_reference(procinfo^.framepointer,para_offset-pushedparasize);
  111. emit_reg_ref(A_MOV,S_L,R_EDI,r);
  112. end
  113. else
  114. emitpushreferenceaddr(p^.left^.location.reference);
  115. del_reference(p^.left^.location.reference);
  116. end;
  117. end;
  118. end
  119. { handle call by reference parameter }
  120. else if (defcoll^.paratyp=vs_var) then
  121. begin
  122. if (p^.left^.location.loc<>LOC_REFERENCE) then
  123. CGMessage(cg_e_var_must_be_reference);
  124. maybe_push_high;
  125. inc(pushedparasize,4);
  126. if inlined then
  127. begin
  128. emit_ref_reg(A_LEA,S_L,
  129. newreference(p^.left^.location.reference),R_EDI);
  130. r:=new_reference(procinfo^.framepointer,para_offset-pushedparasize);
  131. emit_reg_ref(A_MOV,S_L,R_EDI,r);
  132. end
  133. else
  134. emitpushreferenceaddr(p^.left^.location.reference);
  135. del_reference(p^.left^.location.reference);
  136. end
  137. else
  138. begin
  139. tempdeftype:=p^.resulttype^.deftype;
  140. if tempdeftype=filedef then
  141. CGMessage(cg_e_file_must_call_by_reference);
  142. { open array must always push the address, this is needed to
  143. also push addr of small arrays (PFV) }
  144. if (assigned(defcoll^.paratype.def) and
  145. is_open_array(defcoll^.paratype.def)) or
  146. push_addr_param(p^.resulttype) then
  147. begin
  148. maybe_push_high;
  149. inc(pushedparasize,4);
  150. if inlined then
  151. begin
  152. emit_ref_reg(A_LEA,S_L,
  153. newreference(p^.left^.location.reference),R_EDI);
  154. r:=new_reference(procinfo^.framepointer,para_offset-pushedparasize);
  155. emit_reg_ref(A_MOV,S_L,
  156. R_EDI,r);
  157. end
  158. else
  159. emitpushreferenceaddr(p^.left^.location.reference);
  160. del_reference(p^.left^.location.reference);
  161. end
  162. else
  163. begin
  164. align:=target_os.stackalignment;
  165. if dword_align then
  166. align:=4;
  167. push_value_para(p^.left,inlined,para_offset,align);
  168. end;
  169. end;
  170. truelabel:=otlabel;
  171. falselabel:=oflabel;
  172. { push from right to left }
  173. if not push_from_left_to_right and assigned(p^.right) then
  174. secondcallparan(p^.right,pparaitem(defcoll^.next),push_from_left_to_right,
  175. inlined,dword_align,para_offset);
  176. end;
  177. {*****************************************************************************
  178. SecondCallN
  179. *****************************************************************************}
  180. procedure secondcalln(var p : ptree);
  181. var
  182. unusedregisters : tregisterset;
  183. usablecount : byte;
  184. pushed : tpushed;
  185. hr,funcretref : treference;
  186. hregister,hregister2 : tregister;
  187. oldpushedparasize : longint;
  188. { true if ESI must be loaded again after the subroutine }
  189. loadesi : boolean;
  190. { true if a virtual method must be called directly }
  191. no_virtual_call : boolean;
  192. { true if we produce a con- or destrutor in a call }
  193. is_con_or_destructor : boolean;
  194. { true if a constructor is called again }
  195. extended_new : boolean;
  196. { adress returned from an I/O-error }
  197. iolabel : pasmlabel;
  198. { lexlevel count }
  199. i : longint;
  200. { help reference pointer }
  201. r : preference;
  202. hp,
  203. pp,params : ptree;
  204. inlined : boolean;
  205. inlinecode : ptree;
  206. para_offset : longint;
  207. { instruction for alignement correction }
  208. { corr : paicpu;}
  209. { we must pop this size also after !! }
  210. { must_pop : boolean; }
  211. pop_size : longint;
  212. pop_allowed : boolean;
  213. label
  214. dont_call;
  215. begin
  216. reset_reference(p^.location.reference);
  217. extended_new:=false;
  218. iolabel:=nil;
  219. inlinecode:=nil;
  220. inlined:=false;
  221. loadesi:=true;
  222. no_virtual_call:=false;
  223. unusedregisters:=unused;
  224. usablecount:=usablereg32;
  225. if not assigned(p^.procdefinition) then
  226. exit;
  227. if (pocall_inline in p^.procdefinition^.proccalloptions) then
  228. begin
  229. inlined:=true;
  230. inlinecode:=p^.right;
  231. { set it to the same lexical level as the local symtable, becuase
  232. the para's are stored there }
  233. pprocdef(p^.procdefinition)^.parast^.symtablelevel:=aktprocsym^.definition^.localst^.symtablelevel;
  234. if assigned(p^.left) then
  235. inlinecode^.para_offset:=gettempofsizepersistant(inlinecode^.para_size);
  236. pprocdef(p^.procdefinition)^.parast^.address_fixup:=inlinecode^.para_offset;
  237. {$ifdef extdebug}
  238. Comment(V_debug,
  239. 'inlined parasymtable is at offset '
  240. +tostr(pprocdef(p^.procdefinition)^.parast^.address_fixup));
  241. exprasmlist^.concat(new(pai_asm_comment,init(
  242. strpnew('inlined parasymtable is at offset '
  243. +tostr(pprocdef(p^.procdefinition)^.parast^.address_fixup)))));
  244. {$endif extdebug}
  245. p^.right:=nil;
  246. { disable further inlining of the same proc
  247. in the args }
  248. {$ifdef INCLUDEOK}
  249. exclude(p^.procdefinition^.proccalloptions,pocall_inline);
  250. {$else}
  251. p^.procdefinition^.proccalloptions:=p^.procdefinition^.proccalloptions-[pocall_inline];
  252. {$endif}
  253. end;
  254. { only if no proc var }
  255. if not(assigned(p^.right)) then
  256. is_con_or_destructor:=(p^.procdefinition^.proctypeoption in [potype_constructor,potype_destructor]);
  257. { proc variables destroy all registers }
  258. if (p^.right=nil) and
  259. { virtual methods too }
  260. not(po_virtualmethod in p^.procdefinition^.procoptions) then
  261. begin
  262. if (cs_check_io in aktlocalswitches) and
  263. (po_iocheck in p^.procdefinition^.procoptions) and
  264. not(po_iocheck in aktprocsym^.definition^.procoptions) then
  265. begin
  266. getlabel(iolabel);
  267. emitlab(iolabel);
  268. end
  269. else
  270. iolabel:=nil;
  271. { save all used registers }
  272. pushusedregisters(pushed,pprocdef(p^.procdefinition)^.usedregisters);
  273. { give used registers through }
  274. usedinproc:=usedinproc or pprocdef(p^.procdefinition)^.usedregisters;
  275. end
  276. else
  277. begin
  278. pushusedregisters(pushed,$ff);
  279. usedinproc:=$ff;
  280. { no IO check for methods and procedure variables }
  281. iolabel:=nil;
  282. end;
  283. { generate the code for the parameter and push them }
  284. oldpushedparasize:=pushedparasize;
  285. pushedparasize:=0;
  286. pop_size:=0;
  287. { no inc esp for inlined procedure
  288. and for objects constructors PM }
  289. if inlined or
  290. ((p^.right=nil) and
  291. (p^.procdefinition^.proctypeoption=potype_constructor) and
  292. { quick'n'dirty check if it is a class or an object }
  293. (p^.resulttype^.deftype=orddef)) then
  294. pop_allowed:=false
  295. else
  296. pop_allowed:=true;
  297. if pop_allowed then
  298. begin
  299. { Old pushedsize aligned on 4 ? }
  300. i:=oldpushedparasize and 3;
  301. if i>0 then
  302. inc(pop_size,4-i);
  303. { This parasize aligned on 4 ? }
  304. i:=p^.procdefinition^.para_size and 3;
  305. if i>0 then
  306. inc(pop_size,4-i);
  307. { insert the opcode and update pushedparasize }
  308. { never push 4 or more !! }
  309. pop_size:=pop_size mod 4;
  310. if pop_size>0 then
  311. begin
  312. inc(pushedparasize,pop_size);
  313. emit_const_reg(A_SUB,S_L,pop_size,R_ESP);
  314. {$ifdef GDB}
  315. if (cs_debuginfo in aktmoduleswitches) and
  316. (exprasmlist^.first=exprasmlist^.last) then
  317. exprasmlist^.concat(new(pai_force_line,init));
  318. {$endif GDB}
  319. end;
  320. end;
  321. if (p^.resulttype<>pdef(voiddef)) and
  322. ret_in_param(p^.resulttype) then
  323. begin
  324. funcretref.symbol:=nil;
  325. {$ifdef test_dest_loc}
  326. if dest_loc_known and (dest_loc_tree=p) and
  327. (dest_loc.loc in [LOC_REFERENCE,LOC_MEM]) then
  328. begin
  329. funcretref:=dest_loc.reference;
  330. if assigned(dest_loc.reference.symbol) then
  331. funcretref.symbol:=stringdup(dest_loc.reference.symbol^);
  332. in_dest_loc:=true;
  333. end
  334. else
  335. {$endif test_dest_loc}
  336. if inlined then
  337. begin
  338. reset_reference(funcretref);
  339. funcretref.offset:=gettempofsizepersistant(p^.procdefinition^.rettype.def^.size);
  340. funcretref.base:=procinfo^.framepointer;
  341. end
  342. else
  343. gettempofsizereference(p^.procdefinition^.rettype.def^.size,funcretref);
  344. end;
  345. if assigned(p^.left) then
  346. begin
  347. { be found elsewhere }
  348. if inlined then
  349. para_offset:=pprocdef(p^.procdefinition)^.parast^.address_fixup+
  350. pprocdef(p^.procdefinition)^.parast^.datasize
  351. else
  352. para_offset:=0;
  353. if assigned(p^.right) then
  354. secondcallparan(p^.left,pparaitem(pabstractprocdef(p^.right^.resulttype)^.para^.first),
  355. (pocall_leftright in p^.procdefinition^.proccalloptions),
  356. inlined,
  357. (pocall_cdecl in p^.procdefinition^.proccalloptions) or
  358. (pocall_stdcall in p^.procdefinition^.proccalloptions),
  359. para_offset)
  360. else
  361. secondcallparan(p^.left,pparaitem(p^.procdefinition^.para^.first),
  362. (pocall_leftright in p^.procdefinition^.proccalloptions),
  363. inlined,
  364. (pocall_cdecl in p^.procdefinition^.proccalloptions) or
  365. (pocall_stdcall in p^.procdefinition^.proccalloptions),
  366. para_offset);
  367. end;
  368. params:=p^.left;
  369. p^.left:=nil;
  370. if inlined then
  371. inlinecode^.retoffset:=gettempofsizepersistant(4);
  372. if ret_in_param(p^.resulttype) then
  373. begin
  374. { This must not be counted for C code
  375. complex return address is removed from stack
  376. by function itself ! }
  377. {$ifdef OLD_C_STACK}
  378. inc(pushedparasize,4); { lets try without it PM }
  379. {$endif not OLD_C_STACK}
  380. if inlined then
  381. begin
  382. emit_ref_reg(A_LEA,S_L,
  383. newreference(funcretref),R_EDI);
  384. r:=new_reference(procinfo^.framepointer,inlinecode^.retoffset);
  385. emit_reg_ref(A_MOV,S_L,
  386. R_EDI,r);
  387. end
  388. else
  389. emitpushreferenceaddr(funcretref);
  390. end;
  391. { procedure variable ? }
  392. if (p^.right=nil) then
  393. begin
  394. { overloaded operator have no symtable }
  395. { push self }
  396. if assigned(p^.symtable) and
  397. (p^.symtable^.symtabletype=withsymtable) then
  398. begin
  399. { dirty trick to avoid the secondcall below }
  400. p^.methodpointer:=genzeronode(callparan);
  401. p^.methodpointer^.location.loc:=LOC_REGISTER;
  402. p^.methodpointer^.location.register:=R_ESI;
  403. { ARGHHH this is wrong !!!
  404. if we can init from base class for a child
  405. class that the wrong VMT will be
  406. transfered to constructor !! }
  407. p^.methodpointer^.resulttype:=
  408. ptree(pwithsymtable(p^.symtable)^.withnode)^.left^.resulttype;
  409. { change dispose type !! }
  410. p^.disposetyp:=dt_mbleft_and_method;
  411. { make a reference }
  412. new(r);
  413. reset_reference(r^);
  414. { if assigned(ptree(pwithsymtable(p^.symtable)^.withnode)^.pref) then
  415. begin
  416. r^:=ptree(pwithsymtable(p^.symtable)^.withnode)^.pref^;
  417. end
  418. else
  419. begin
  420. r^.offset:=p^.symtable^.datasize;
  421. r^.base:=procinfo^.framepointer;
  422. end; }
  423. r^:=ptree(pwithsymtable(p^.symtable)^.withnode)^.withreference^;
  424. if (not pwithsymtable(p^.symtable)^.direct_with) or
  425. pobjectdef(p^.methodpointer^.resulttype)^.is_class then
  426. emit_ref_reg(A_MOV,S_L,r,R_ESI)
  427. else
  428. emit_ref_reg(A_LEA,S_L,r,R_ESI);
  429. end;
  430. { push self }
  431. if assigned(p^.symtable) and
  432. ((p^.symtable^.symtabletype=objectsymtable) or
  433. (p^.symtable^.symtabletype=withsymtable)) then
  434. begin
  435. if assigned(p^.methodpointer) then
  436. begin
  437. {
  438. if p^.methodpointer^.resulttype=classrefdef then
  439. begin
  440. two possibilities:
  441. 1. constructor
  442. 2. class method
  443. end
  444. else }
  445. begin
  446. case p^.methodpointer^.treetype of
  447. typen:
  448. begin
  449. { direct call to inherited method }
  450. if (po_abstractmethod in p^.procdefinition^.procoptions) then
  451. begin
  452. CGMessage(cg_e_cant_call_abstract_method);
  453. goto dont_call;
  454. end;
  455. { generate no virtual call }
  456. no_virtual_call:=true;
  457. if (sp_static in p^.symtableprocentry^.symoptions) then
  458. begin
  459. { well lets put the VMT address directly into ESI }
  460. { it is kind of dirty but that is the simplest }
  461. { way to accept virtual static functions (PM) }
  462. loadesi:=true;
  463. { if no VMT just use $0 bug0214 PM }
  464. if not(oo_has_vmt in pobjectdef(p^.methodpointer^.resulttype)^.objectoptions) then
  465. emit_const_reg(A_MOV,S_L,0,R_ESI)
  466. else
  467. begin
  468. emit_sym_ofs_reg(A_MOV,S_L,
  469. newasmsymbol(pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname),
  470. 0,R_ESI);
  471. end;
  472. { emit_reg(A_PUSH,S_L,R_ESI);
  473. this is done below !! }
  474. end
  475. else
  476. { this is a member call, so ESI isn't modfied }
  477. loadesi:=false;
  478. { a class destructor needs a flag }
  479. if pobjectdef(p^.methodpointer^.resulttype)^.is_class and
  480. assigned(aktprocsym) and
  481. (aktprocsym^.definition^.proctypeoption=potype_destructor) then
  482. begin
  483. push_int(0);
  484. emit_reg(A_PUSH,S_L,R_ESI);
  485. end;
  486. if not(is_con_or_destructor and
  487. pobjectdef(p^.methodpointer^.resulttype)^.is_class and
  488. assigned(aktprocsym) and
  489. (aktprocsym^.definition^.proctypeoption in [potype_constructor,potype_destructor])
  490. ) then
  491. emit_reg(A_PUSH,S_L,R_ESI);
  492. { if an inherited con- or destructor should be }
  493. { called in a con- or destructor then a warning }
  494. { will be made }
  495. { con- and destructors need a pointer to the vmt }
  496. if is_con_or_destructor and
  497. not(pobjectdef(p^.methodpointer^.resulttype)^.is_class) and
  498. assigned(aktprocsym) then
  499. begin
  500. if not(aktprocsym^.definition^.proctypeoption in
  501. [potype_constructor,potype_destructor]) then
  502. CGMessage(cg_w_member_cd_call_from_method);
  503. end;
  504. { class destructors get there flag below }
  505. if is_con_or_destructor and
  506. not(pobjectdef(p^.methodpointer^.resulttype)^.is_class and
  507. assigned(aktprocsym) and
  508. (aktprocsym^.definition^.proctypeoption=potype_destructor)) then
  509. push_int(0);
  510. end;
  511. hnewn:
  512. begin
  513. { extended syntax of new }
  514. { ESI must be zero }
  515. emit_reg_reg(A_XOR,S_L,R_ESI,R_ESI);
  516. emit_reg(A_PUSH,S_L,R_ESI);
  517. { insert the vmt }
  518. emit_sym(A_PUSH,S_L,
  519. newasmsymbol(pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname));
  520. extended_new:=true;
  521. end;
  522. hdisposen:
  523. begin
  524. secondpass(p^.methodpointer);
  525. { destructor with extended syntax called from dispose }
  526. { hdisposen always deliver LOC_REFERENCE }
  527. emit_ref_reg(A_LEA,S_L,
  528. newreference(p^.methodpointer^.location.reference),R_ESI);
  529. del_reference(p^.methodpointer^.location.reference);
  530. emit_reg(A_PUSH,S_L,R_ESI);
  531. emit_sym(A_PUSH,S_L,
  532. newasmsymbol(pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname));
  533. end;
  534. else
  535. begin
  536. { call to an instance member }
  537. if (p^.symtable^.symtabletype<>withsymtable) then
  538. begin
  539. secondpass(p^.methodpointer);
  540. case p^.methodpointer^.location.loc of
  541. LOC_CREGISTER,
  542. LOC_REGISTER:
  543. begin
  544. emit_reg_reg(A_MOV,S_L,p^.methodpointer^.location.register,R_ESI);
  545. ungetregister32(p^.methodpointer^.location.register);
  546. end;
  547. else
  548. begin
  549. if (p^.methodpointer^.resulttype^.deftype=classrefdef) or
  550. ((p^.methodpointer^.resulttype^.deftype=objectdef) and
  551. pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  552. emit_ref_reg(A_MOV,S_L,
  553. newreference(p^.methodpointer^.location.reference),R_ESI)
  554. else
  555. emit_ref_reg(A_LEA,S_L,
  556. newreference(p^.methodpointer^.location.reference),R_ESI);
  557. del_reference(p^.methodpointer^.location.reference);
  558. end;
  559. end;
  560. end;
  561. { when calling a class method, we have to load ESI with the VMT !
  562. But, not for a class method via self }
  563. if not(po_containsself in p^.procdefinition^.procoptions) then
  564. begin
  565. if (po_classmethod in p^.procdefinition^.procoptions) and
  566. not(p^.methodpointer^.resulttype^.deftype=classrefdef) then
  567. begin
  568. { class method needs current VMT }
  569. new(r);
  570. reset_reference(r^);
  571. r^.base:=R_ESI;
  572. r^.offset:= pprocdef(p^.procdefinition)^._class^.vmt_offset;
  573. emit_ref_reg(A_MOV,S_L,r,R_ESI);
  574. end;
  575. { direct call to destructor: don't remove data! }
  576. if (p^.procdefinition^.proctypeoption=potype_destructor) and
  577. (p^.methodpointer^.resulttype^.deftype=objectdef) and
  578. (pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  579. emit_const(A_PUSH,S_L,1);
  580. { direct call to class constructor, don't allocate memory }
  581. if (p^.procdefinition^.proctypeoption=potype_constructor) and
  582. (p^.methodpointer^.resulttype^.deftype=objectdef) and
  583. (pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  584. emit_const(A_PUSH,S_L,0)
  585. else
  586. emit_reg(A_PUSH,S_L,R_ESI);
  587. end;
  588. if is_con_or_destructor then
  589. begin
  590. { classes don't get a VMT pointer pushed }
  591. if (p^.methodpointer^.resulttype^.deftype=objectdef) and
  592. not(pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  593. begin
  594. if (p^.procdefinition^.proctypeoption=potype_constructor) then
  595. begin
  596. { it's no bad idea, to insert the VMT }
  597. emit_sym(A_PUSH,S_L,newasmsymbol(
  598. pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname));
  599. end
  600. { destructors haven't to dispose the instance, if this is }
  601. { a direct call }
  602. else
  603. push_int(0);
  604. end;
  605. end;
  606. end;
  607. end;
  608. end;
  609. end
  610. else
  611. begin
  612. if (po_classmethod in p^.procdefinition^.procoptions) and
  613. not(
  614. assigned(aktprocsym) and
  615. (po_classmethod in aktprocsym^.definition^.procoptions)
  616. ) then
  617. begin
  618. { class method needs current VMT }
  619. new(r);
  620. reset_reference(r^);
  621. r^.base:=R_ESI;
  622. r^.offset:= pprocdef(p^.procdefinition)^._class^.vmt_offset;
  623. emit_ref_reg(A_MOV,S_L,r,R_ESI);
  624. end
  625. else
  626. begin
  627. { member call, ESI isn't modified }
  628. loadesi:=false;
  629. end;
  630. emit_reg(A_PUSH,S_L,R_ESI);
  631. { but a con- or destructor here would probably almost }
  632. { always be placed wrong }
  633. if is_con_or_destructor then
  634. begin
  635. CGMessage(cg_w_member_cd_call_from_method);
  636. push_int(0);
  637. end;
  638. end;
  639. end;
  640. { push base pointer ?}
  641. if (lexlevel>=normal_function_level) and assigned(pprocdef(p^.procdefinition)^.parast) and
  642. ((pprocdef(p^.procdefinition)^.parast^.symtablelevel)>normal_function_level) then
  643. begin
  644. { if we call a nested function in a method, we must }
  645. { push also SELF! }
  646. { THAT'S NOT TRUE, we have to load ESI via frame pointer }
  647. { access }
  648. {
  649. begin
  650. loadesi:=false;
  651. emit_reg(A_PUSH,S_L,R_ESI);
  652. end;
  653. }
  654. if lexlevel=(pprocdef(p^.procdefinition)^.parast^.symtablelevel) then
  655. begin
  656. new(r);
  657. reset_reference(r^);
  658. r^.offset:=procinfo^.framepointer_offset;
  659. r^.base:=procinfo^.framepointer;
  660. emit_ref(A_PUSH,S_L,r)
  661. end
  662. { this is only true if the difference is one !!
  663. but it cannot be more !! }
  664. else if (lexlevel=pprocdef(p^.procdefinition)^.parast^.symtablelevel-1) then
  665. begin
  666. emit_reg(A_PUSH,S_L,procinfo^.framepointer)
  667. end
  668. else if (lexlevel>pprocdef(p^.procdefinition)^.parast^.symtablelevel) then
  669. begin
  670. hregister:=getregister32;
  671. new(r);
  672. reset_reference(r^);
  673. r^.offset:=procinfo^.framepointer_offset;
  674. r^.base:=procinfo^.framepointer;
  675. emit_ref_reg(A_MOV,S_L,r,hregister);
  676. for i:=(pprocdef(p^.procdefinition)^.parast^.symtablelevel) to lexlevel-1 do
  677. begin
  678. new(r);
  679. reset_reference(r^);
  680. {we should get the correct frame_pointer_offset at each level
  681. how can we do this !!! }
  682. r^.offset:=procinfo^.framepointer_offset;
  683. r^.base:=hregister;
  684. emit_ref_reg(A_MOV,S_L,r,hregister);
  685. end;
  686. emit_reg(A_PUSH,S_L,hregister);
  687. ungetregister32(hregister);
  688. end
  689. else
  690. internalerror(25000);
  691. end;
  692. if (po_virtualmethod in p^.procdefinition^.procoptions) and
  693. not(no_virtual_call) then
  694. begin
  695. { static functions contain the vmt_address in ESI }
  696. { also class methods }
  697. { Here it is quite tricky because it also depends }
  698. { on the methodpointer PM }
  699. if assigned(aktprocsym) then
  700. begin
  701. if (((sp_static in aktprocsym^.symoptions) or
  702. (po_classmethod in aktprocsym^.definition^.procoptions)) and
  703. ((p^.methodpointer=nil) or (p^.methodpointer^.treetype=typen)))
  704. or
  705. (po_staticmethod in p^.procdefinition^.procoptions) or
  706. (p^.procdefinition^.proctypeoption=potype_constructor) or
  707. { ESI is loaded earlier }
  708. (po_classmethod in p^.procdefinition^.procoptions) then
  709. begin
  710. new(r);
  711. reset_reference(r^);
  712. r^.base:=R_ESI;
  713. end
  714. else
  715. begin
  716. new(r);
  717. reset_reference(r^);
  718. r^.base:=R_ESI;
  719. { this is one point where we need vmt_offset (PM) }
  720. r^.offset:= pprocdef(p^.procdefinition)^._class^.vmt_offset;
  721. emit_ref_reg(A_MOV,S_L,r,R_EDI);
  722. new(r);
  723. reset_reference(r^);
  724. r^.base:=R_EDI;
  725. end;
  726. end
  727. else
  728. { aktprocsym should be assigned, also in main program }
  729. internalerror(12345);
  730. {
  731. begin
  732. new(r);
  733. reset_reference(r^);
  734. r^.base:=R_ESI;
  735. emit_ref_reg(A_MOV,S_L,r,R_EDI);
  736. new(r);
  737. reset_reference(r^);
  738. r^.base:=R_EDI;
  739. end;
  740. }
  741. if pprocdef(p^.procdefinition)^.extnumber=-1 then
  742. internalerror(44584);
  743. r^.offset:=pprocdef(p^.procdefinition)^._class^.vmtmethodoffset(pprocdef(p^.procdefinition)^.extnumber);
  744. {$ifndef TESTOBJEXT}
  745. if (cs_check_range in aktlocalswitches) then
  746. begin
  747. emit_reg(A_PUSH,S_L,r^.base);
  748. emitcall('FPC_CHECK_OBJECT');
  749. end;
  750. {$else TESTOBJEXT}
  751. if (cs_check_range in aktlocalswitches) then
  752. begin
  753. emit_sym(A_PUSH,S_L,
  754. newasmsymbol(pprocdef(p^.procdefinition)^._class^.vmt_mangledname));
  755. emit_reg(A_PUSH,S_L,r^.base);
  756. emitcall('FPC_CHECK_OBJECT_EXT');
  757. end;
  758. {$endif TESTOBJEXT}
  759. emit_ref(A_CALL,S_NO,r);
  760. end
  761. else if not inlined then
  762. emitcall(pprocdef(p^.procdefinition)^.mangledname)
  763. else { inlined proc }
  764. { inlined code is in inlinecode }
  765. begin
  766. { set poinline again }
  767. {$ifdef INCLUDEOK}
  768. include(p^.procdefinition^.proccalloptions,pocall_inline);
  769. {$else}
  770. p^.procdefinition^.proccalloptions:=p^.procdefinition^.proccalloptions+[pocall_inline];
  771. {$endif}
  772. { process the inlinecode }
  773. secondpass(inlinecode);
  774. { free the args }
  775. ungetpersistanttemp(pprocdef(p^.procdefinition)^.parast^.address_fixup);
  776. end;
  777. end
  778. else
  779. { now procedure variable case }
  780. begin
  781. secondpass(p^.right);
  782. { procedure of object? }
  783. if (po_methodpointer in p^.procdefinition^.procoptions) then
  784. begin
  785. { method pointer can't be in a register }
  786. hregister:=R_NO;
  787. { do some hacking if we call a method pointer }
  788. { which is a class member }
  789. { else ESI is overwritten ! }
  790. if (p^.right^.location.reference.base=R_ESI) or
  791. (p^.right^.location.reference.index=R_ESI) then
  792. begin
  793. del_reference(p^.right^.location.reference);
  794. emit_ref_reg(A_MOV,S_L,
  795. newreference(p^.right^.location.reference),R_EDI);
  796. hregister:=R_EDI;
  797. end;
  798. { load self, but not if it's already explicitly pushed }
  799. if not(po_containsself in p^.procdefinition^.procoptions) then
  800. begin
  801. { load ESI }
  802. inc(p^.right^.location.reference.offset,4);
  803. emit_ref_reg(A_MOV,S_L,
  804. newreference(p^.right^.location.reference),R_ESI);
  805. dec(p^.right^.location.reference.offset,4);
  806. { push self pointer }
  807. emit_reg(A_PUSH,S_L,R_ESI);
  808. end;
  809. if hregister=R_NO then
  810. emit_ref(A_CALL,S_NO,newreference(p^.right^.location.reference))
  811. else
  812. emit_reg(A_CALL,S_NO,hregister);
  813. del_reference(p^.right^.location.reference);
  814. end
  815. else
  816. begin
  817. case p^.right^.location.loc of
  818. LOC_REGISTER,LOC_CREGISTER:
  819. begin
  820. emit_reg(A_CALL,S_NO,p^.right^.location.register);
  821. ungetregister32(p^.right^.location.register);
  822. end
  823. else
  824. emit_ref(A_CALL,S_NO,newreference(p^.right^.location.reference));
  825. del_reference(p^.right^.location.reference);
  826. end;
  827. end;
  828. end;
  829. { this was only for normal functions
  830. displaced here so we also get
  831. it to work for procvars PM }
  832. if (not inlined) and (pocall_clearstack in p^.procdefinition^.proccalloptions) then
  833. begin
  834. { consider the alignment with the rest (PM) }
  835. inc(pushedparasize,pop_size);
  836. pop_size:=0;
  837. { better than an add on all processors }
  838. if pushedparasize=4 then
  839. emit_reg(A_POP,S_L,R_EDI)
  840. { the pentium has two pipes and pop reg is pairable }
  841. { but the registers must be different! }
  842. else if (pushedparasize=8) and
  843. not(cs_littlesize in aktglobalswitches) and
  844. (aktoptprocessor=ClassP5) and
  845. (procinfo^._class=nil) then
  846. begin
  847. emit_reg(A_POP,S_L,R_EDI);
  848. emit_reg(A_POP,S_L,R_ESI);
  849. end
  850. else if pushedparasize<>0 then
  851. emit_const_reg(A_ADD,S_L,pushedparasize,R_ESP);
  852. end;
  853. dont_call:
  854. pushedparasize:=oldpushedparasize;
  855. unused:=unusedregisters;
  856. usablereg32:=usablecount;
  857. {$ifdef TEMPREGDEBUG}
  858. testregisters32;
  859. {$endif TEMPREGDEBUG}
  860. { a constructor could be a function with boolean result }
  861. { if calling constructor called fail we
  862. must jump directly to quickexitlabel PM
  863. but only if it is a call of an inherited constructor }
  864. if (p^.right=nil) and
  865. (p^.procdefinition^.proctypeoption=potype_constructor) and
  866. assigned(p^.methodpointer) and
  867. (p^.methodpointer^.treetype=typen) and
  868. (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  869. begin
  870. emitjmp(C_Z,faillabel);
  871. end;
  872. { handle function results }
  873. { structured results are easy to handle.... }
  874. { needed also when result_no_used !! }
  875. if (p^.resulttype<>pdef(voiddef)) and ret_in_param(p^.resulttype) then
  876. begin
  877. p^.location.loc:=LOC_MEM;
  878. p^.location.reference.symbol:=nil;
  879. p^.location.reference:=funcretref;
  880. end;
  881. { we have only to handle the result if it is used, but }
  882. { ansi/widestrings must be registered, so we can dispose them }
  883. if (p^.resulttype<>pdef(voiddef)) and (p^.return_value_used or
  884. is_ansistring(p^.resulttype) or is_widestring(p^.resulttype)) then
  885. begin
  886. { a contructor could be a function with boolean result }
  887. if (p^.right=nil) and
  888. (p^.procdefinition^.proctypeoption=potype_constructor) and
  889. { quick'n'dirty check if it is a class or an object }
  890. (p^.resulttype^.deftype=orddef) then
  891. begin
  892. { this fails if popsize > 0 PM }
  893. p^.location.loc:=LOC_FLAGS;
  894. p^.location.resflags:=F_NE;
  895. if extended_new then
  896. begin
  897. {$ifdef test_dest_loc}
  898. if dest_loc_known and (dest_loc_tree=p) then
  899. mov_reg_to_dest(p,S_L,R_EAX)
  900. else
  901. {$endif test_dest_loc}
  902. begin
  903. hregister:=getexplicitregister32(R_EAX);
  904. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  905. p^.location.register:=hregister;
  906. end;
  907. end;
  908. end
  909. { structed results are easy to handle.... }
  910. else if ret_in_param(p^.resulttype) then
  911. begin
  912. {p^.location.loc:=LOC_MEM;
  913. stringdispose(p^.location.reference.symbol);
  914. p^.location.reference:=funcretref;
  915. already done above (PM) }
  916. end
  917. else
  918. begin
  919. if (p^.resulttype^.deftype in [orddef,enumdef]) then
  920. begin
  921. p^.location.loc:=LOC_REGISTER;
  922. case p^.resulttype^.size of
  923. 4 :
  924. begin
  925. {$ifdef test_dest_loc}
  926. if dest_loc_known and (dest_loc_tree=p) then
  927. mov_reg_to_dest(p,S_L,R_EAX)
  928. else
  929. {$endif test_dest_loc}
  930. begin
  931. hregister:=getexplicitregister32(R_EAX);
  932. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  933. p^.location.register:=hregister;
  934. end;
  935. end;
  936. 1 :
  937. begin
  938. {$ifdef test_dest_loc}
  939. if dest_loc_known and (dest_loc_tree=p) then
  940. mov_reg_to_dest(p,S_B,R_AL)
  941. else
  942. {$endif test_dest_loc}
  943. begin
  944. hregister:=getexplicitregister32(R_EAX);
  945. emit_reg_reg(A_MOV,S_B,R_AL,reg32toreg8(hregister));
  946. p^.location.register:=reg32toreg8(hregister);
  947. end;
  948. end;
  949. 2 :
  950. begin
  951. {$ifdef test_dest_loc}
  952. if dest_loc_known and (dest_loc_tree=p) then
  953. mov_reg_to_dest(p,S_W,R_AX)
  954. else
  955. {$endif test_dest_loc}
  956. begin
  957. hregister:=getexplicitregister32(R_EAX);
  958. emit_reg_reg(A_MOV,S_W,R_AX,reg32toreg16(hregister));
  959. p^.location.register:=reg32toreg16(hregister);
  960. end;
  961. end;
  962. 8 :
  963. begin
  964. {$ifdef test_dest_loc}
  965. {$error Don't know what to do here}
  966. {$endif test_dest_loc}
  967. hregister:=getexplicitregister32(R_EAX);
  968. hregister2:=getexplicitregister32(R_EDX);
  969. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  970. emit_reg_reg(A_MOV,S_L,R_EDX,hregister2);
  971. p^.location.registerlow:=hregister;
  972. p^.location.registerhigh:=hregister2;
  973. end;
  974. else internalerror(7);
  975. end
  976. end
  977. else if (p^.resulttype^.deftype=floatdef) then
  978. case pfloatdef(p^.resulttype)^.typ of
  979. f32bit:
  980. begin
  981. p^.location.loc:=LOC_REGISTER;
  982. {$ifdef test_dest_loc}
  983. if dest_loc_known and (dest_loc_tree=p) then
  984. mov_reg_to_dest(p,S_L,R_EAX)
  985. else
  986. {$endif test_dest_loc}
  987. begin
  988. hregister:=getexplicitregister32(R_EAX);
  989. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  990. p^.location.register:=hregister;
  991. end;
  992. end;
  993. else
  994. begin
  995. p^.location.loc:=LOC_FPU;
  996. inc(fpuvaroffset);
  997. end;
  998. end
  999. else if is_ansistring(p^.resulttype) or
  1000. is_widestring(p^.resulttype) then
  1001. begin
  1002. hregister:=getexplicitregister32(R_EAX);
  1003. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  1004. gettempansistringreference(hr);
  1005. decrstringref(p^.resulttype,hr);
  1006. emit_reg_ref(A_MOV,S_L,hregister,
  1007. newreference(hr));
  1008. ungetregister32(hregister);
  1009. p^.location.loc:=LOC_MEM;
  1010. p^.location.reference:=hr;
  1011. end
  1012. else
  1013. begin
  1014. p^.location.loc:=LOC_REGISTER;
  1015. {$ifdef test_dest_loc}
  1016. if dest_loc_known and (dest_loc_tree=p) then
  1017. mov_reg_to_dest(p,S_L,R_EAX)
  1018. else
  1019. {$endif test_dest_loc}
  1020. begin
  1021. hregister:=getexplicitregister32(R_EAX);
  1022. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  1023. p^.location.register:=hregister;
  1024. end;
  1025. end;
  1026. end;
  1027. end;
  1028. { perhaps i/o check ? }
  1029. if iolabel<>nil then
  1030. begin
  1031. emit_sym(A_PUSH,S_L,iolabel);
  1032. emitcall('FPC_IOCHECK');
  1033. end;
  1034. if pop_size>0 then
  1035. emit_const_reg(A_ADD,S_L,pop_size,R_ESP);
  1036. { restore registers }
  1037. popusedregisters(pushed);
  1038. { at last, restore instance pointer (SELF) }
  1039. if loadesi then
  1040. maybe_loadesi;
  1041. pp:=params;
  1042. while assigned(pp) do
  1043. begin
  1044. if assigned(pp^.left) then
  1045. begin
  1046. if (pp^.left^.location.loc in [LOC_REFERENCE,LOC_MEM]) then
  1047. ungetiftemp(pp^.left^.location.reference);
  1048. { process also all nodes of an array of const }
  1049. if pp^.left^.treetype=arrayconstructn then
  1050. begin
  1051. if assigned(pp^.left^.left) then
  1052. begin
  1053. hp:=pp^.left;
  1054. while assigned(hp) do
  1055. begin
  1056. if (hp^.left^.location.loc in [LOC_REFERENCE,LOC_MEM]) then
  1057. ungetiftemp(hp^.left^.location.reference);
  1058. hp:=hp^.right;
  1059. end;
  1060. end;
  1061. end;
  1062. end;
  1063. pp:=pp^.right;
  1064. end;
  1065. if inlined then
  1066. ungetpersistanttemp(inlinecode^.retoffset);
  1067. disposetree(params);
  1068. { from now on the result can be freed normally }
  1069. if inlined and ret_in_param(p^.resulttype) then
  1070. persistanttemptonormal(funcretref.offset);
  1071. { if return value is not used }
  1072. if (not p^.return_value_used) and (p^.resulttype<>pdef(voiddef)) then
  1073. begin
  1074. if p^.location.loc in [LOC_MEM,LOC_REFERENCE] then
  1075. begin
  1076. { data which must be finalized ? }
  1077. if (p^.resulttype^.needs_inittable) and
  1078. ( (p^.resulttype^.deftype<>objectdef) or
  1079. not(pobjectdef(p^.resulttype)^.is_class)) then
  1080. finalize(p^.resulttype,p^.location.reference,ret_in_param(p^.resulttype));
  1081. { release unused temp }
  1082. ungetiftemp(p^.location.reference)
  1083. end
  1084. else if p^.location.loc=LOC_FPU then
  1085. begin
  1086. { release FPU stack }
  1087. emit_reg(A_FSTP,S_NO,R_ST0);
  1088. {
  1089. dec(fpuvaroffset);
  1090. do NOT decrement as the increment before
  1091. is not called for unused results PM }
  1092. end;
  1093. end;
  1094. end;
  1095. {*****************************************************************************
  1096. SecondProcInlineN
  1097. *****************************************************************************}
  1098. procedure secondprocinline(var p : ptree);
  1099. var st : psymtable;
  1100. oldprocsym : pprocsym;
  1101. para_size : longint;
  1102. oldprocinfo : pprocinfo;
  1103. oldinlining_procedure,
  1104. nostackframe,make_global : boolean;
  1105. proc_names : tstringcontainer;
  1106. inlineentrycode,inlineexitcode : paasmoutput;
  1107. oldexitlabel,oldexit2label,oldquickexitlabel:Pasmlabel;
  1108. begin
  1109. oldinlining_procedure:=inlining_procedure;
  1110. oldexitlabel:=aktexitlabel;
  1111. oldexit2label:=aktexit2label;
  1112. oldquickexitlabel:=quickexitlabel;
  1113. getlabel(aktexitlabel);
  1114. getlabel(aktexit2label);
  1115. oldprocsym:=aktprocsym;
  1116. { save old procinfo }
  1117. getmem(oldprocinfo,sizeof(tprocinfo));
  1118. move(procinfo^,oldprocinfo^,sizeof(tprocinfo));
  1119. { we're inlining a procedure }
  1120. inlining_procedure:=true;
  1121. { set the return value }
  1122. aktprocsym:=p^.inlineprocsym;
  1123. procinfo^.returntype:=aktprocsym^.definition^.rettype;
  1124. procinfo^.return_offset:=p^.retoffset;
  1125. { arg space has been filled by the parent secondcall }
  1126. st:=aktprocsym^.definition^.localst;
  1127. { set it to the same lexical level }
  1128. st^.symtablelevel:=oldprocsym^.definition^.localst^.symtablelevel;
  1129. if st^.datasize>0 then
  1130. begin
  1131. st^.address_fixup:=gettempofsizepersistant(st^.datasize);
  1132. {$ifdef extdebug}
  1133. Comment(V_debug,'local symtable is at offset '+tostr(st^.address_fixup));
  1134. exprasmlist^.concat(new(pai_asm_comment,init(strpnew(
  1135. 'local symtable is at offset '+tostr(st^.address_fixup)))));
  1136. {$endif extdebug}
  1137. end;
  1138. {$ifdef extdebug}
  1139. exprasmlist^.concat(new(pai_asm_comment,init(strpnew('Start of inlined proc'))));
  1140. {$endif extdebug}
  1141. { takes care of local data initialization }
  1142. inlineentrycode:=new(paasmoutput,init);
  1143. inlineexitcode:=new(paasmoutput,init);
  1144. proc_names.init;
  1145. para_size:=p^.para_size;
  1146. make_global:=false; { to avoid warning }
  1147. genentrycode(inlineentrycode,proc_names,make_global,0,para_size,nostackframe,true);
  1148. exprasmlist^.concatlist(inlineentrycode);
  1149. secondpass(p^.inlinetree);
  1150. genexitcode(inlineexitcode,0,false,true);
  1151. exprasmlist^.concatlist(inlineexitcode);
  1152. {$ifdef extdebug}
  1153. exprasmlist^.concat(new(pai_asm_comment,init(strpnew('End of inlined proc'))));
  1154. {$endif extdebug}
  1155. {we can free the local data now, reset also the fixup address }
  1156. if st^.datasize>0 then
  1157. begin
  1158. ungetpersistanttemp(st^.address_fixup);
  1159. st^.address_fixup:=0;
  1160. end;
  1161. { restore procinfo }
  1162. move(oldprocinfo^,procinfo^,sizeof(tprocinfo));
  1163. freemem(oldprocinfo,sizeof(tprocinfo));
  1164. { restore }
  1165. aktprocsym:=oldprocsym;
  1166. aktexitlabel:=oldexitlabel;
  1167. aktexit2label:=oldexit2label;
  1168. quickexitlabel:=oldquickexitlabel;
  1169. inlining_procedure:=oldinlining_procedure;
  1170. end;
  1171. end.
  1172. {
  1173. $Log$
  1174. Revision 1.114 2000-01-07 01:14:20 peter
  1175. * updated copyright to 2000
  1176. Revision 1.113 1999/12/22 01:01:46 peter
  1177. - removed freelabel()
  1178. * added undefined label detection in internal assembler, this prevents
  1179. a lot of ld crashes and wrong .o files
  1180. * .o files aren't written anymore if errors have occured
  1181. * inlining of assembler labels is now correct
  1182. Revision 1.112 1999/12/13 21:49:54 pierre
  1183. * bug in extdebugg code for inlined procedures
  1184. Revision 1.111 1999/11/30 10:40:42 peter
  1185. + ttype, tsymlist
  1186. Revision 1.110 1999/11/06 14:34:17 peter
  1187. * truncated log to 20 revs
  1188. Revision 1.109 1999/11/04 00:23:58 pierre
  1189. * fix for fpuvaroffset for unused return value
  1190. Revision 1.108 1999/10/26 12:30:40 peter
  1191. * const parameter is now checked
  1192. * better and generic check if a node can be used for assigning
  1193. * export fixes
  1194. * procvar equal works now (it never had worked at least from 0.99.8)
  1195. * defcoll changed to linkedlist with pparaitem so it can easily be
  1196. walked both directions
  1197. Revision 1.107 1999/10/08 15:40:47 pierre
  1198. * use and remember that C functions with complex data results use ret $4
  1199. Revision 1.106 1999/09/27 23:44:46 peter
  1200. * procinfo is now a pointer
  1201. * support for result setting in sub procedure
  1202. Revision 1.105 1999/09/26 13:26:02 florian
  1203. * exception patch of Romio nevertheless the excpetion handling
  1204. needs some corections regarding register saving
  1205. * gettempansistring is again a procedure
  1206. Revision 1.104 1999/09/16 11:34:46 pierre
  1207. * typo correction
  1208. Revision 1.103 1999/09/07 07:54:23 peter
  1209. * small array push to open array fixed, open array always needs addr
  1210. pushing
  1211. Revision 1.102 1999/08/25 11:59:39 jonas
  1212. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  1213. Revision 1.101 1999/08/23 23:38:18 pierre
  1214. + TEMPREGDEBUG code added
  1215. Revision 1.100 1999/08/19 13:08:45 pierre
  1216. * emit_??? used
  1217. Revision 1.99 1999/08/09 22:19:47 peter
  1218. * classes vmt changed to only positive addresses
  1219. * sharedlib creation is working
  1220. Revision 1.98 1999/08/09 10:37:55 peter
  1221. * fixed pushing of self with methodpointer
  1222. Revision 1.97 1999/08/04 13:45:18 florian
  1223. + floating point register variables !!
  1224. * pairegalloc is now generated for register variables
  1225. Revision 1.96 1999/08/04 00:22:41 florian
  1226. * renamed i386asm and i386base to cpuasm and cpubase
  1227. Revision 1.95 1999/08/03 22:02:34 peter
  1228. * moved bitmask constants to sets
  1229. * some other type/const renamings
  1230. Revision 1.94 1999/07/06 21:48:09 florian
  1231. * a lot bug fixes:
  1232. - po_external isn't any longer necessary for procedure compatibility
  1233. - m_tp_procvar is in -Sd now available
  1234. - error messages of procedure variables improved
  1235. - return values with init./finalization fixed
  1236. - data types with init./finalization aren't any longer allowed in variant
  1237. record
  1238. Revision 1.93 1999/06/22 13:31:24 peter
  1239. * merged
  1240. Revision 1.92 1999/06/16 09:32:45 peter
  1241. * merged
  1242. Revision 1.91 1999/06/14 17:47:47 peter
  1243. * merged
  1244. Revision 1.90.2.3 1999/06/22 13:30:08 peter
  1245. * fixed return with packenum
  1246. }