cg386cal.pas 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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 : pdefcoll;
  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 : pdefcoll;
  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^.data) and
  48. push_high_param(defcoll^.data) 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,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^.data) and
  83. (defcoll^.data^.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^.data) and
  145. is_open_array(defcoll^.data)) 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. freelabel(truelabel);
  171. freelabel(falselabel);
  172. truelabel:=otlabel;
  173. falselabel:=oflabel;
  174. { push from right to left }
  175. if not push_from_left_to_right and assigned(p^.right) then
  176. secondcallparan(p^.right,defcoll^.next,push_from_left_to_right,
  177. inlined,dword_align,para_offset);
  178. end;
  179. {*****************************************************************************
  180. SecondCallN
  181. *****************************************************************************}
  182. procedure secondcalln(var p : ptree);
  183. var
  184. unusedregisters : tregisterset;
  185. usablecount : byte;
  186. pushed : tpushed;
  187. hr,funcretref : treference;
  188. hregister,hregister2 : tregister;
  189. oldpushedparasize : longint;
  190. { true if ESI must be loaded again after the subroutine }
  191. loadesi : boolean;
  192. { true if a virtual method must be called directly }
  193. no_virtual_call : boolean;
  194. { true if we produce a con- or destrutor in a call }
  195. is_con_or_destructor : boolean;
  196. { true if a constructor is called again }
  197. extended_new : boolean;
  198. { adress returned from an I/O-error }
  199. iolabel : pasmlabel;
  200. { lexlevel count }
  201. i : longint;
  202. { help reference pointer }
  203. r : preference;
  204. hp,
  205. pp,params : ptree;
  206. inlined : boolean;
  207. inlinecode : ptree;
  208. para_offset : longint;
  209. { instruction for alignement correction }
  210. { corr : paicpu;}
  211. { we must pop this size also after !! }
  212. { must_pop : boolean; }
  213. pop_size : longint;
  214. pop_allowed : boolean;
  215. label
  216. dont_call;
  217. begin
  218. reset_reference(p^.location.reference);
  219. extended_new:=false;
  220. iolabel:=nil;
  221. inlinecode:=nil;
  222. inlined:=false;
  223. loadesi:=true;
  224. no_virtual_call:=false;
  225. unusedregisters:=unused;
  226. usablecount:=usablereg32;
  227. if not assigned(p^.procdefinition) then
  228. exit;
  229. if (pocall_inline in p^.procdefinition^.proccalloptions) then
  230. begin
  231. inlined:=true;
  232. inlinecode:=p^.right;
  233. { set it to the same lexical level as the local symtable, becuase
  234. the para's are stored there }
  235. pprocdef(p^.procdefinition)^.parast^.symtablelevel:=aktprocsym^.definition^.localst^.symtablelevel;
  236. if assigned(p^.left) then
  237. inlinecode^.para_offset:=gettempofsizepersistant(inlinecode^.para_size);
  238. pprocdef(p^.procdefinition)^.parast^.address_fixup:=inlinecode^.para_offset;
  239. {$ifdef extdebug}
  240. Comment(V_debug,
  241. 'inlined parasymtable is at offset '
  242. +tostr(pprocdef(p^.procdefinition)^.parast^.address_fixup));
  243. exprasmlist^.concat(new(pai_asm_comment,init(
  244. strpnew('inlined parasymtable is at offset '
  245. +tostr(pprocdef(p^.procdefinition)^.parast^.address_fixup)))));
  246. {$endif extdebug}
  247. p^.right:=nil;
  248. { disable further inlining of the same proc
  249. in the args }
  250. {$ifdef INCLUDEOK}
  251. exclude(p^.procdefinition^.proccalloptions,pocall_inline);
  252. {$else}
  253. p^.procdefinition^.proccalloptions:=p^.procdefinition^.proccalloptions-[pocall_inline];
  254. {$endif}
  255. end;
  256. { only if no proc var }
  257. if not(assigned(p^.right)) then
  258. is_con_or_destructor:=(p^.procdefinition^.proctypeoption in [potype_constructor,potype_destructor]);
  259. { proc variables destroy all registers }
  260. if (p^.right=nil) and
  261. { virtual methods too }
  262. not(po_virtualmethod in p^.procdefinition^.procoptions) then
  263. begin
  264. if (cs_check_io in aktlocalswitches) and
  265. (po_iocheck in p^.procdefinition^.procoptions) and
  266. not(po_iocheck in aktprocsym^.definition^.procoptions) then
  267. begin
  268. getlabel(iolabel);
  269. emitlab(iolabel);
  270. end
  271. else
  272. iolabel:=nil;
  273. { save all used registers }
  274. pushusedregisters(pushed,pprocdef(p^.procdefinition)^.usedregisters);
  275. { give used registers through }
  276. usedinproc:=usedinproc or pprocdef(p^.procdefinition)^.usedregisters;
  277. end
  278. else
  279. begin
  280. pushusedregisters(pushed,$ff);
  281. usedinproc:=$ff;
  282. { no IO check for methods and procedure variables }
  283. iolabel:=nil;
  284. end;
  285. { generate the code for the parameter and push them }
  286. oldpushedparasize:=pushedparasize;
  287. pushedparasize:=0;
  288. pop_size:=0;
  289. { no inc esp for inlined procedure
  290. and for objects constructors PM }
  291. if inlined or
  292. ((p^.right=nil) and
  293. (p^.procdefinition^.proctypeoption=potype_constructor) and
  294. { quick'n'dirty check if it is a class or an object }
  295. (p^.resulttype^.deftype=orddef)) then
  296. pop_allowed:=false
  297. else
  298. pop_allowed:=true;
  299. if pop_allowed then
  300. begin
  301. { Old pushedsize aligned on 4 ? }
  302. i:=oldpushedparasize and 3;
  303. if i>0 then
  304. inc(pop_size,4-i);
  305. { This parasize aligned on 4 ? }
  306. i:=p^.procdefinition^.para_size and 3;
  307. if i>0 then
  308. inc(pop_size,4-i);
  309. { insert the opcode and update pushedparasize }
  310. { never push 4 or more !! }
  311. pop_size:=pop_size mod 4;
  312. if pop_size>0 then
  313. begin
  314. inc(pushedparasize,pop_size);
  315. emit_const_reg(A_SUB,S_L,pop_size,R_ESP);
  316. {$ifdef GDB}
  317. if (cs_debuginfo in aktmoduleswitches) and
  318. (exprasmlist^.first=exprasmlist^.last) then
  319. exprasmlist^.concat(new(pai_force_line,init));
  320. {$endif GDB}
  321. end;
  322. end;
  323. if (p^.resulttype<>pdef(voiddef)) and
  324. ret_in_param(p^.resulttype) then
  325. begin
  326. funcretref.symbol:=nil;
  327. {$ifdef test_dest_loc}
  328. if dest_loc_known and (dest_loc_tree=p) and
  329. (dest_loc.loc in [LOC_REFERENCE,LOC_MEM]) then
  330. begin
  331. funcretref:=dest_loc.reference;
  332. if assigned(dest_loc.reference.symbol) then
  333. funcretref.symbol:=stringdup(dest_loc.reference.symbol^);
  334. in_dest_loc:=true;
  335. end
  336. else
  337. {$endif test_dest_loc}
  338. if inlined then
  339. begin
  340. reset_reference(funcretref);
  341. funcretref.offset:=gettempofsizepersistant(p^.procdefinition^.retdef^.size);
  342. funcretref.base:=procinfo.framepointer;
  343. end
  344. else
  345. gettempofsizereference(p^.procdefinition^.retdef^.size,funcretref);
  346. end;
  347. if assigned(p^.left) then
  348. begin
  349. { be found elsewhere }
  350. if inlined then
  351. para_offset:=pprocdef(p^.procdefinition)^.parast^.address_fixup+
  352. pprocdef(p^.procdefinition)^.parast^.datasize
  353. else
  354. para_offset:=0;
  355. if assigned(p^.right) then
  356. secondcallparan(p^.left,pabstractprocdef(p^.right^.resulttype)^.para1,
  357. (pocall_leftright in p^.procdefinition^.proccalloptions),
  358. inlined,
  359. (pocall_cdecl in p^.procdefinition^.proccalloptions) or
  360. (pocall_stdcall in p^.procdefinition^.proccalloptions),
  361. para_offset)
  362. else
  363. secondcallparan(p^.left,p^.procdefinition^.para1,
  364. (pocall_leftright in p^.procdefinition^.proccalloptions),
  365. inlined,
  366. (pocall_cdecl in p^.procdefinition^.proccalloptions) or
  367. (pocall_stdcall in p^.procdefinition^.proccalloptions),
  368. para_offset);
  369. end;
  370. params:=p^.left;
  371. p^.left:=nil;
  372. if inlined then
  373. inlinecode^.retoffset:=gettempofsizepersistant(4);
  374. if ret_in_param(p^.resulttype) then
  375. begin
  376. inc(pushedparasize,4);
  377. if inlined then
  378. begin
  379. emit_ref_reg(A_LEA,S_L,
  380. newreference(funcretref),R_EDI);
  381. r:=new_reference(procinfo.framepointer,inlinecode^.retoffset);
  382. emit_reg_ref(A_MOV,S_L,
  383. R_EDI,r);
  384. end
  385. else
  386. emitpushreferenceaddr(funcretref);
  387. end;
  388. { procedure variable ? }
  389. if (p^.right=nil) then
  390. begin
  391. { overloaded operator have no symtable }
  392. { push self }
  393. if assigned(p^.symtable) and
  394. (p^.symtable^.symtabletype=withsymtable) then
  395. begin
  396. { dirty trick to avoid the secondcall below }
  397. p^.methodpointer:=genzeronode(callparan);
  398. p^.methodpointer^.location.loc:=LOC_REGISTER;
  399. p^.methodpointer^.location.register:=R_ESI;
  400. { ARGHHH this is wrong !!!
  401. if we can init from base class for a child
  402. class that the wrong VMT will be
  403. transfered to constructor !! }
  404. p^.methodpointer^.resulttype:=
  405. ptree(pwithsymtable(p^.symtable)^.withnode)^.left^.resulttype;
  406. { change dispose type !! }
  407. p^.disposetyp:=dt_mbleft_and_method;
  408. { make a reference }
  409. new(r);
  410. reset_reference(r^);
  411. { if assigned(ptree(pwithsymtable(p^.symtable)^.withnode)^.pref) then
  412. begin
  413. r^:=ptree(pwithsymtable(p^.symtable)^.withnode)^.pref^;
  414. end
  415. else
  416. begin
  417. r^.offset:=p^.symtable^.datasize;
  418. r^.base:=procinfo.framepointer;
  419. end; }
  420. r^:=ptree(pwithsymtable(p^.symtable)^.withnode)^.withreference^;
  421. if (not pwithsymtable(p^.symtable)^.direct_with) or
  422. pobjectdef(p^.methodpointer^.resulttype)^.is_class then
  423. emit_ref_reg(A_MOV,S_L,r,R_ESI)
  424. else
  425. emit_ref_reg(A_LEA,S_L,r,R_ESI);
  426. end;
  427. { push self }
  428. if assigned(p^.symtable) and
  429. ((p^.symtable^.symtabletype=objectsymtable) or
  430. (p^.symtable^.symtabletype=withsymtable)) then
  431. begin
  432. if assigned(p^.methodpointer) then
  433. begin
  434. {
  435. if p^.methodpointer^.resulttype=classrefdef then
  436. begin
  437. two possibilities:
  438. 1. constructor
  439. 2. class method
  440. end
  441. else }
  442. begin
  443. case p^.methodpointer^.treetype of
  444. typen:
  445. begin
  446. { direct call to inherited method }
  447. if (po_abstractmethod in p^.procdefinition^.procoptions) then
  448. begin
  449. CGMessage(cg_e_cant_call_abstract_method);
  450. goto dont_call;
  451. end;
  452. { generate no virtual call }
  453. no_virtual_call:=true;
  454. if (sp_static in p^.symtableprocentry^.symoptions) then
  455. begin
  456. { well lets put the VMT address directly into ESI }
  457. { it is kind of dirty but that is the simplest }
  458. { way to accept virtual static functions (PM) }
  459. loadesi:=true;
  460. { if no VMT just use $0 bug0214 PM }
  461. if not(oo_has_vmt in pobjectdef(p^.methodpointer^.resulttype)^.objectoptions) then
  462. emit_const_reg(A_MOV,S_L,0,R_ESI)
  463. else
  464. begin
  465. emit_sym_ofs_reg(A_MOV,S_L,
  466. newasmsymbol(pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname),
  467. 0,R_ESI);
  468. end;
  469. { emit_reg(A_PUSH,S_L,R_ESI);
  470. this is done below !! }
  471. end
  472. else
  473. { this is a member call, so ESI isn't modfied }
  474. loadesi:=false;
  475. { a class destructor needs a flag }
  476. if pobjectdef(p^.methodpointer^.resulttype)^.is_class and
  477. assigned(aktprocsym) and
  478. (aktprocsym^.definition^.proctypeoption=potype_destructor) then
  479. begin
  480. push_int(0);
  481. emit_reg(A_PUSH,S_L,R_ESI);
  482. end;
  483. if not(is_con_or_destructor and
  484. pobjectdef(p^.methodpointer^.resulttype)^.is_class and
  485. assigned(aktprocsym) and
  486. (aktprocsym^.definition^.proctypeoption in [potype_constructor,potype_destructor])
  487. ) then
  488. emit_reg(A_PUSH,S_L,R_ESI);
  489. { if an inherited con- or destructor should be }
  490. { called in a con- or destructor then a warning }
  491. { will be made }
  492. { con- and destructors need a pointer to the vmt }
  493. if is_con_or_destructor and
  494. not(pobjectdef(p^.methodpointer^.resulttype)^.is_class) and
  495. assigned(aktprocsym) then
  496. begin
  497. if not(aktprocsym^.definition^.proctypeoption in
  498. [potype_constructor,potype_destructor]) then
  499. CGMessage(cg_w_member_cd_call_from_method);
  500. end;
  501. { class destructors get there flag below }
  502. if is_con_or_destructor and
  503. not(pobjectdef(p^.methodpointer^.resulttype)^.is_class and
  504. assigned(aktprocsym) and
  505. (aktprocsym^.definition^.proctypeoption=potype_destructor)) then
  506. push_int(0);
  507. end;
  508. hnewn:
  509. begin
  510. { extended syntax of new }
  511. { ESI must be zero }
  512. emit_reg_reg(A_XOR,S_L,R_ESI,R_ESI);
  513. emit_reg(A_PUSH,S_L,R_ESI);
  514. { insert the vmt }
  515. emit_sym(A_PUSH,S_L,
  516. newasmsymbol(pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname));
  517. extended_new:=true;
  518. end;
  519. hdisposen:
  520. begin
  521. secondpass(p^.methodpointer);
  522. { destructor with extended syntax called from dispose }
  523. { hdisposen always deliver LOC_REFERENCE }
  524. emit_ref_reg(A_LEA,S_L,
  525. newreference(p^.methodpointer^.location.reference),R_ESI);
  526. del_reference(p^.methodpointer^.location.reference);
  527. emit_reg(A_PUSH,S_L,R_ESI);
  528. emit_sym(A_PUSH,S_L,
  529. newasmsymbol(pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname));
  530. end;
  531. else
  532. begin
  533. { call to an instance member }
  534. if (p^.symtable^.symtabletype<>withsymtable) then
  535. begin
  536. secondpass(p^.methodpointer);
  537. case p^.methodpointer^.location.loc of
  538. LOC_CREGISTER,
  539. LOC_REGISTER:
  540. begin
  541. emit_reg_reg(A_MOV,S_L,p^.methodpointer^.location.register,R_ESI);
  542. ungetregister32(p^.methodpointer^.location.register);
  543. end;
  544. else
  545. begin
  546. if (p^.methodpointer^.resulttype^.deftype=classrefdef) or
  547. ((p^.methodpointer^.resulttype^.deftype=objectdef) and
  548. pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  549. emit_ref_reg(A_MOV,S_L,
  550. newreference(p^.methodpointer^.location.reference),R_ESI)
  551. else
  552. emit_ref_reg(A_LEA,S_L,
  553. newreference(p^.methodpointer^.location.reference),R_ESI);
  554. del_reference(p^.methodpointer^.location.reference);
  555. end;
  556. end;
  557. end;
  558. { when calling a class method, we have to load ESI with the VMT !
  559. But, not for a class method via self }
  560. if not(po_containsself in p^.procdefinition^.procoptions) then
  561. begin
  562. if (po_classmethod in p^.procdefinition^.procoptions) and
  563. not(p^.methodpointer^.resulttype^.deftype=classrefdef) then
  564. begin
  565. { class method needs current VMT }
  566. new(r);
  567. reset_reference(r^);
  568. r^.base:=R_ESI;
  569. r^.offset:= pprocdef(p^.procdefinition)^._class^.vmt_offset;
  570. emit_ref_reg(A_MOV,S_L,r,R_ESI);
  571. end;
  572. { direct call to destructor: don't remove data! }
  573. if (p^.procdefinition^.proctypeoption=potype_destructor) and
  574. (p^.methodpointer^.resulttype^.deftype=objectdef) and
  575. (pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  576. emit_const(A_PUSH,S_L,1);
  577. { direct call to class constructor, don't allocate memory }
  578. if (p^.procdefinition^.proctypeoption=potype_constructor) and
  579. (p^.methodpointer^.resulttype^.deftype=objectdef) and
  580. (pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  581. emit_const(A_PUSH,S_L,0)
  582. else
  583. emit_reg(A_PUSH,S_L,R_ESI);
  584. end;
  585. if is_con_or_destructor then
  586. begin
  587. { classes don't get a VMT pointer pushed }
  588. if (p^.methodpointer^.resulttype^.deftype=objectdef) and
  589. not(pobjectdef(p^.methodpointer^.resulttype)^.is_class) then
  590. begin
  591. if (p^.procdefinition^.proctypeoption=potype_constructor) then
  592. begin
  593. { it's no bad idea, to insert the VMT }
  594. emit_sym(A_PUSH,S_L,newasmsymbol(
  595. pobjectdef(p^.methodpointer^.resulttype)^.vmt_mangledname));
  596. end
  597. { destructors haven't to dispose the instance, if this is }
  598. { a direct call }
  599. else
  600. push_int(0);
  601. end;
  602. end;
  603. end;
  604. end;
  605. end;
  606. end
  607. else
  608. begin
  609. if (po_classmethod in p^.procdefinition^.procoptions) and
  610. not(
  611. assigned(aktprocsym) and
  612. (po_classmethod in aktprocsym^.definition^.procoptions)
  613. ) then
  614. begin
  615. { class method needs current VMT }
  616. new(r);
  617. reset_reference(r^);
  618. r^.base:=R_ESI;
  619. r^.offset:= pprocdef(p^.procdefinition)^._class^.vmt_offset;
  620. emit_ref_reg(A_MOV,S_L,r,R_ESI);
  621. end
  622. else
  623. begin
  624. { member call, ESI isn't modified }
  625. loadesi:=false;
  626. end;
  627. emit_reg(A_PUSH,S_L,R_ESI);
  628. { but a con- or destructor here would probably almost }
  629. { always be placed wrong }
  630. if is_con_or_destructor then
  631. begin
  632. CGMessage(cg_w_member_cd_call_from_method);
  633. push_int(0);
  634. end;
  635. end;
  636. end;
  637. { push base pointer ?}
  638. if (lexlevel>=normal_function_level) and assigned(pprocdef(p^.procdefinition)^.parast) and
  639. ((pprocdef(p^.procdefinition)^.parast^.symtablelevel)>normal_function_level) then
  640. begin
  641. { if we call a nested function in a method, we must }
  642. { push also SELF! }
  643. { THAT'S NOT TRUE, we have to load ESI via frame pointer }
  644. { access }
  645. {
  646. begin
  647. loadesi:=false;
  648. emit_reg(A_PUSH,S_L,R_ESI);
  649. end;
  650. }
  651. if lexlevel=(pprocdef(p^.procdefinition)^.parast^.symtablelevel) then
  652. begin
  653. new(r);
  654. reset_reference(r^);
  655. r^.offset:=procinfo.framepointer_offset;
  656. r^.base:=procinfo.framepointer;
  657. emit_ref(A_PUSH,S_L,r)
  658. end
  659. { this is only true if the difference is one !!
  660. but it cannot be more !! }
  661. else if (lexlevel=pprocdef(p^.procdefinition)^.parast^.symtablelevel-1) then
  662. begin
  663. emit_reg(A_PUSH,S_L,procinfo.framepointer)
  664. end
  665. else if (lexlevel>pprocdef(p^.procdefinition)^.parast^.symtablelevel) then
  666. begin
  667. hregister:=getregister32;
  668. new(r);
  669. reset_reference(r^);
  670. r^.offset:=procinfo.framepointer_offset;
  671. r^.base:=procinfo.framepointer;
  672. emit_ref_reg(A_MOV,S_L,r,hregister);
  673. for i:=(pprocdef(p^.procdefinition)^.parast^.symtablelevel) to lexlevel-1 do
  674. begin
  675. new(r);
  676. reset_reference(r^);
  677. {we should get the correct frame_pointer_offset at each level
  678. how can we do this !!! }
  679. r^.offset:=procinfo.framepointer_offset;
  680. r^.base:=hregister;
  681. emit_ref_reg(A_MOV,S_L,r,hregister);
  682. end;
  683. emit_reg(A_PUSH,S_L,hregister);
  684. ungetregister32(hregister);
  685. end
  686. else
  687. internalerror(25000);
  688. end;
  689. if (po_virtualmethod in p^.procdefinition^.procoptions) and
  690. not(no_virtual_call) then
  691. begin
  692. { static functions contain the vmt_address in ESI }
  693. { also class methods }
  694. { Here it is quite tricky because it also depends }
  695. { on the methodpointer PM }
  696. if assigned(aktprocsym) then
  697. begin
  698. if (((sp_static in aktprocsym^.symoptions) or
  699. (po_classmethod in aktprocsym^.definition^.procoptions)) and
  700. ((p^.methodpointer=nil) or (p^.methodpointer^.treetype=typen)))
  701. or
  702. (po_staticmethod in p^.procdefinition^.procoptions) or
  703. (p^.procdefinition^.proctypeoption=potype_constructor) or
  704. { ESI is loaded earlier }
  705. (po_classmethod in p^.procdefinition^.procoptions) then
  706. begin
  707. new(r);
  708. reset_reference(r^);
  709. r^.base:=R_ESI;
  710. end
  711. else
  712. begin
  713. new(r);
  714. reset_reference(r^);
  715. r^.base:=R_ESI;
  716. { this is one point where we need vmt_offset (PM) }
  717. r^.offset:= pprocdef(p^.procdefinition)^._class^.vmt_offset;
  718. emit_ref_reg(A_MOV,S_L,r,R_EDI);
  719. new(r);
  720. reset_reference(r^);
  721. r^.base:=R_EDI;
  722. end;
  723. end
  724. else
  725. { aktprocsym should be assigned, also in main program }
  726. internalerror(12345);
  727. {
  728. begin
  729. new(r);
  730. reset_reference(r^);
  731. r^.base:=R_ESI;
  732. emit_ref_reg(A_MOV,S_L,r,R_EDI);
  733. new(r);
  734. reset_reference(r^);
  735. r^.base:=R_EDI;
  736. end;
  737. }
  738. if pprocdef(p^.procdefinition)^.extnumber=-1 then
  739. internalerror(44584);
  740. r^.offset:=pprocdef(p^.procdefinition)^._class^.vmtmethodoffset(pprocdef(p^.procdefinition)^.extnumber);
  741. {$ifndef TESTOBJEXT}
  742. if (cs_check_range in aktlocalswitches) then
  743. begin
  744. emit_reg(A_PUSH,S_L,r^.base);
  745. emitcall('FPC_CHECK_OBJECT');
  746. end;
  747. {$else TESTOBJEXT}
  748. if (cs_check_range in aktlocalswitches) then
  749. begin
  750. emit_sym(A_PUSH,S_L,
  751. newasmsymbol(pprocdef(p^.procdefinition)^._class^.vmt_mangledname));
  752. emit_reg(A_PUSH,S_L,r^.base);
  753. emitcall('FPC_CHECK_OBJECT_EXT');
  754. end;
  755. {$endif TESTOBJEXT}
  756. emit_ref(A_CALL,S_NO,r);
  757. end
  758. else if not inlined then
  759. emitcall(pprocdef(p^.procdefinition)^.mangledname)
  760. else { inlined proc }
  761. { inlined code is in inlinecode }
  762. begin
  763. { set poinline again }
  764. {$ifdef INCLUDEOK}
  765. include(p^.procdefinition^.proccalloptions,pocall_inline);
  766. {$else}
  767. p^.procdefinition^.proccalloptions:=p^.procdefinition^.proccalloptions+[pocall_inline];
  768. {$endif}
  769. { process the inlinecode }
  770. secondpass(inlinecode);
  771. { free the args }
  772. ungetpersistanttemp(pprocdef(p^.procdefinition)^.parast^.address_fixup);
  773. end;
  774. end
  775. else
  776. { now procedure variable case }
  777. begin
  778. secondpass(p^.right);
  779. { procedure of object? }
  780. if (po_methodpointer in p^.procdefinition^.procoptions) then
  781. begin
  782. { method pointer can't be in a register }
  783. hregister:=R_NO;
  784. { do some hacking if we call a method pointer }
  785. { which is a class member }
  786. { else ESI is overwritten ! }
  787. if (p^.right^.location.reference.base=R_ESI) or
  788. (p^.right^.location.reference.index=R_ESI) then
  789. begin
  790. del_reference(p^.right^.location.reference);
  791. emit_ref_reg(A_MOV,S_L,
  792. newreference(p^.right^.location.reference),R_EDI);
  793. hregister:=R_EDI;
  794. end;
  795. { load self, but not if it's already explicitly pushed }
  796. if not(po_containsself in p^.procdefinition^.procoptions) then
  797. begin
  798. { load ESI }
  799. inc(p^.right^.location.reference.offset,4);
  800. emit_ref_reg(A_MOV,S_L,
  801. newreference(p^.right^.location.reference),R_ESI);
  802. dec(p^.right^.location.reference.offset,4);
  803. { push self pointer }
  804. emit_reg(A_PUSH,S_L,R_ESI);
  805. end;
  806. if hregister=R_NO then
  807. emit_ref(A_CALL,S_NO,newreference(p^.right^.location.reference))
  808. else
  809. emit_reg(A_CALL,S_NO,hregister);
  810. del_reference(p^.right^.location.reference);
  811. end
  812. else
  813. begin
  814. case p^.right^.location.loc of
  815. LOC_REGISTER,LOC_CREGISTER:
  816. begin
  817. emit_reg(A_CALL,S_NO,p^.right^.location.register);
  818. ungetregister32(p^.right^.location.register);
  819. end
  820. else
  821. emit_ref(A_CALL,S_NO,newreference(p^.right^.location.reference));
  822. del_reference(p^.right^.location.reference);
  823. end;
  824. end;
  825. end;
  826. { this was only for normal functions
  827. displaced here so we also get
  828. it to work for procvars PM }
  829. if (not inlined) and (pocall_clearstack in p^.procdefinition^.proccalloptions) then
  830. begin
  831. { consider the alignment with the rest (PM) }
  832. inc(pushedparasize,pop_size);
  833. pop_size:=0;
  834. { better than an add on all processors }
  835. if pushedparasize=4 then
  836. emit_reg(A_POP,S_L,R_EDI)
  837. { the pentium has two pipes and pop reg is pairable }
  838. { but the registers must be different! }
  839. else if (pushedparasize=8) and
  840. not(cs_littlesize in aktglobalswitches) and
  841. (aktoptprocessor=ClassP5) and
  842. (procinfo._class=nil) then
  843. begin
  844. emit_reg(A_POP,S_L,R_EDI);
  845. emit_reg(A_POP,S_L,R_ESI);
  846. end
  847. else if pushedparasize<>0 then
  848. emit_const_reg(A_ADD,S_L,pushedparasize,R_ESP);
  849. end;
  850. dont_call:
  851. pushedparasize:=oldpushedparasize;
  852. unused:=unusedregisters;
  853. usablereg32:=usablecount;
  854. {$ifdef TEMPREGDEBUG}
  855. testregisters32;
  856. {$endif TEMPREGDEBUG}
  857. { a constructor could be a function with boolean result }
  858. { if calling constructor called fail we
  859. must jump directly to quickexitlabel PM
  860. but only if it is a call of an inherited constructor }
  861. if (p^.right=nil) and
  862. (p^.procdefinition^.proctypeoption=potype_constructor) and
  863. assigned(p^.methodpointer) and
  864. (p^.methodpointer^.treetype=typen) and
  865. (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  866. begin
  867. emitjmp(C_Z,faillabel);
  868. end;
  869. { handle function results }
  870. { structured results are easy to handle.... }
  871. { needed also when result_no_used !! }
  872. if (p^.resulttype<>pdef(voiddef)) and ret_in_param(p^.resulttype) then
  873. begin
  874. p^.location.loc:=LOC_MEM;
  875. p^.location.reference.symbol:=nil;
  876. p^.location.reference:=funcretref;
  877. end;
  878. { we have only to handle the result if it is used, but }
  879. { ansi/widestrings must be registered, so we can dispose them }
  880. if (p^.resulttype<>pdef(voiddef)) and (p^.return_value_used or
  881. is_ansistring(p^.resulttype) or is_widestring(p^.resulttype)) then
  882. begin
  883. { a contructor could be a function with boolean result }
  884. if (p^.right=nil) and
  885. (p^.procdefinition^.proctypeoption=potype_constructor) and
  886. { quick'n'dirty check if it is a class or an object }
  887. (p^.resulttype^.deftype=orddef) then
  888. begin
  889. { this fails if popsize > 0 PM }
  890. p^.location.loc:=LOC_FLAGS;
  891. p^.location.resflags:=F_NE;
  892. if extended_new then
  893. begin
  894. {$ifdef test_dest_loc}
  895. if dest_loc_known and (dest_loc_tree=p) then
  896. mov_reg_to_dest(p,S_L,R_EAX)
  897. else
  898. {$endif test_dest_loc}
  899. begin
  900. hregister:=getexplicitregister32(R_EAX);
  901. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  902. p^.location.register:=hregister;
  903. end;
  904. end;
  905. end
  906. { structed results are easy to handle.... }
  907. else if ret_in_param(p^.resulttype) then
  908. begin
  909. {p^.location.loc:=LOC_MEM;
  910. stringdispose(p^.location.reference.symbol);
  911. p^.location.reference:=funcretref;
  912. already done above (PM) }
  913. end
  914. else
  915. begin
  916. if (p^.resulttype^.deftype in [orddef,enumdef]) then
  917. begin
  918. p^.location.loc:=LOC_REGISTER;
  919. case p^.resulttype^.size of
  920. 4 :
  921. begin
  922. {$ifdef test_dest_loc}
  923. if dest_loc_known and (dest_loc_tree=p) then
  924. mov_reg_to_dest(p,S_L,R_EAX)
  925. else
  926. {$endif test_dest_loc}
  927. begin
  928. hregister:=getexplicitregister32(R_EAX);
  929. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  930. p^.location.register:=hregister;
  931. end;
  932. end;
  933. 1 :
  934. begin
  935. {$ifdef test_dest_loc}
  936. if dest_loc_known and (dest_loc_tree=p) then
  937. mov_reg_to_dest(p,S_B,R_AL)
  938. else
  939. {$endif test_dest_loc}
  940. begin
  941. hregister:=getexplicitregister32(R_EAX);
  942. emit_reg_reg(A_MOV,S_B,R_AL,reg32toreg8(hregister));
  943. p^.location.register:=reg32toreg8(hregister);
  944. end;
  945. end;
  946. 2 :
  947. begin
  948. {$ifdef test_dest_loc}
  949. if dest_loc_known and (dest_loc_tree=p) then
  950. mov_reg_to_dest(p,S_W,R_AX)
  951. else
  952. {$endif test_dest_loc}
  953. begin
  954. hregister:=getexplicitregister32(R_EAX);
  955. emit_reg_reg(A_MOV,S_W,R_AX,reg32toreg16(hregister));
  956. p^.location.register:=reg32toreg16(hregister);
  957. end;
  958. end;
  959. 8 :
  960. begin
  961. {$ifdef test_dest_loc}
  962. {$error Don't know what to do here}
  963. {$endif test_dest_loc}
  964. hregister:=getexplicitregister32(R_EAX);
  965. hregister2:=getexplicitregister32(R_EDX);
  966. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  967. emit_reg_reg(A_MOV,S_L,R_EDX,hregister2);
  968. p^.location.registerlow:=hregister;
  969. p^.location.registerhigh:=hregister2;
  970. end;
  971. else internalerror(7);
  972. end
  973. end
  974. else if (p^.resulttype^.deftype=floatdef) then
  975. case pfloatdef(p^.resulttype)^.typ of
  976. f32bit:
  977. begin
  978. p^.location.loc:=LOC_REGISTER;
  979. {$ifdef test_dest_loc}
  980. if dest_loc_known and (dest_loc_tree=p) then
  981. mov_reg_to_dest(p,S_L,R_EAX)
  982. else
  983. {$endif test_dest_loc}
  984. begin
  985. hregister:=getexplicitregister32(R_EAX);
  986. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  987. p^.location.register:=hregister;
  988. end;
  989. end;
  990. else
  991. begin
  992. p^.location.loc:=LOC_FPU;
  993. inc(fpuvaroffset);
  994. end;
  995. end
  996. else if is_ansistring(p^.resulttype) or
  997. is_widestring(p^.resulttype) then
  998. begin
  999. hregister:=getexplicitregister32(R_EAX);
  1000. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  1001. if gettempansistringreference(hr) then
  1002. decrstringref(p^.resulttype,hr);
  1003. emit_reg_ref(A_MOV,S_L,hregister,
  1004. newreference(hr));
  1005. ungetregister32(hregister);
  1006. p^.location.loc:=LOC_MEM;
  1007. p^.location.reference:=hr;
  1008. end
  1009. else
  1010. begin
  1011. p^.location.loc:=LOC_REGISTER;
  1012. {$ifdef test_dest_loc}
  1013. if dest_loc_known and (dest_loc_tree=p) then
  1014. mov_reg_to_dest(p,S_L,R_EAX)
  1015. else
  1016. {$endif test_dest_loc}
  1017. begin
  1018. hregister:=getexplicitregister32(R_EAX);
  1019. emit_reg_reg(A_MOV,S_L,R_EAX,hregister);
  1020. p^.location.register:=hregister;
  1021. end;
  1022. end;
  1023. end;
  1024. end;
  1025. { perhaps i/o check ? }
  1026. if iolabel<>nil then
  1027. begin
  1028. emit_sym(A_PUSH,S_L,iolabel);
  1029. emitcall('FPC_IOCHECK');
  1030. end;
  1031. if pop_size>0 then
  1032. emit_const_reg(A_ADD,S_L,pop_size,R_ESP);
  1033. { restore registers }
  1034. popusedregisters(pushed);
  1035. { at last, restore instance pointer (SELF) }
  1036. if loadesi then
  1037. maybe_loadesi;
  1038. pp:=params;
  1039. while assigned(pp) do
  1040. begin
  1041. if assigned(pp^.left) then
  1042. begin
  1043. if (pp^.left^.location.loc in [LOC_REFERENCE,LOC_MEM]) then
  1044. ungetiftemp(pp^.left^.location.reference);
  1045. { process also all nodes of an array of const }
  1046. if pp^.left^.treetype=arrayconstructn then
  1047. begin
  1048. if assigned(pp^.left^.left) then
  1049. begin
  1050. hp:=pp^.left;
  1051. while assigned(hp) do
  1052. begin
  1053. if (hp^.left^.location.loc in [LOC_REFERENCE,LOC_MEM]) then
  1054. ungetiftemp(hp^.left^.location.reference);
  1055. hp:=hp^.right;
  1056. end;
  1057. end;
  1058. end;
  1059. end;
  1060. pp:=pp^.right;
  1061. end;
  1062. if inlined then
  1063. ungetpersistanttemp(inlinecode^.retoffset);
  1064. disposetree(params);
  1065. { from now on the result can be freed normally }
  1066. if inlined and ret_in_param(p^.resulttype) then
  1067. persistanttemptonormal(funcretref.offset);
  1068. { if return value is not used }
  1069. if (not p^.return_value_used) and (p^.resulttype<>pdef(voiddef)) then
  1070. begin
  1071. if p^.location.loc in [LOC_MEM,LOC_REFERENCE] then
  1072. begin
  1073. { data which must be finalized ? }
  1074. if (p^.resulttype^.needs_inittable) and
  1075. ( (p^.resulttype^.deftype<>objectdef) or
  1076. not(pobjectdef(p^.resulttype)^.is_class)) then
  1077. finalize(p^.resulttype,p^.location.reference,ret_in_param(p^.resulttype));
  1078. { release unused temp }
  1079. ungetiftemp(p^.location.reference)
  1080. end
  1081. else if p^.location.loc=LOC_FPU then
  1082. begin
  1083. { release FPU stack }
  1084. emit_reg(A_FSTP,S_NO,R_ST0);
  1085. dec(fpuvaroffset);
  1086. end;
  1087. end;
  1088. end;
  1089. {*****************************************************************************
  1090. SecondProcInlineN
  1091. *****************************************************************************}
  1092. procedure secondprocinline(var p : ptree);
  1093. var st : psymtable;
  1094. oldprocsym : pprocsym;
  1095. para_size : longint;
  1096. oldprocinfo : tprocinfo;
  1097. { just dummies for genentrycode }
  1098. nostackframe,make_global : boolean;
  1099. proc_names : tstringcontainer;
  1100. inlineentrycode,inlineexitcode : paasmoutput;
  1101. oldexitlabel,oldexit2label,oldquickexitlabel:Pasmlabel;
  1102. begin
  1103. oldexitlabel:=aktexitlabel;
  1104. oldexit2label:=aktexit2label;
  1105. oldquickexitlabel:=quickexitlabel;
  1106. getlabel(aktexitlabel);
  1107. getlabel(aktexit2label);
  1108. oldprocsym:=aktprocsym;
  1109. oldprocinfo:=procinfo;
  1110. { set the return value }
  1111. aktprocsym:=p^.inlineprocsym;
  1112. procinfo.retdef:=aktprocsym^.definition^.retdef;
  1113. procinfo.retoffset:=p^.retoffset;
  1114. { arg space has been filled by the parent secondcall }
  1115. st:=aktprocsym^.definition^.localst;
  1116. { set it to the same lexical level }
  1117. st^.symtablelevel:=oldprocsym^.definition^.localst^.symtablelevel;
  1118. if st^.datasize>0 then
  1119. begin
  1120. st^.address_fixup:=gettempofsizepersistant(st^.datasize);
  1121. {$ifdef extdebug}
  1122. Comment(V_debug,'local symtable is at offset '+tostr(st^.address_fixup));
  1123. exprasmlist^.concat(new(pai_asm_comment,init(strpnew(
  1124. 'local symtable is at offset '+tostr(st^.address_fixup)))));
  1125. {$endif extdebug}
  1126. end;
  1127. {$ifdef extdebug}
  1128. exprasmlist^.concat(new(pai_asm_comment,init('Start of inlined proc')));
  1129. {$endif extdebug}
  1130. { takes care of local data initialization }
  1131. inlineentrycode:=new(paasmoutput,init);
  1132. inlineexitcode:=new(paasmoutput,init);
  1133. proc_names.init;
  1134. para_size:=p^.para_size;
  1135. make_global:=false; { to avoid warning }
  1136. genentrycode(inlineentrycode,proc_names,make_global,0,para_size,nostackframe,true);
  1137. exprasmlist^.concatlist(inlineentrycode);
  1138. secondpass(p^.inlinetree);
  1139. genexitcode(inlineexitcode,0,false,true);
  1140. exprasmlist^.concatlist(inlineexitcode);
  1141. {$ifdef extdebug}
  1142. exprasmlist^.concat(new(pai_asm_comment,init('End of inlined proc')));
  1143. {$endif extdebug}
  1144. {we can free the local data now, reset also the fixup address }
  1145. if st^.datasize>0 then
  1146. begin
  1147. ungetpersistanttemp(st^.address_fixup);
  1148. st^.address_fixup:=0;
  1149. end;
  1150. aktprocsym:=oldprocsym;
  1151. freelabel(aktexitlabel);
  1152. freelabel(aktexit2label);
  1153. aktexitlabel:=oldexitlabel;
  1154. aktexit2label:=oldexit2label;
  1155. quickexitlabel:=oldquickexitlabel;
  1156. procinfo:=oldprocinfo;
  1157. end;
  1158. end.
  1159. {
  1160. $Log$
  1161. Revision 1.103 1999-09-07 07:54:23 peter
  1162. * small array push to open array fixed, open array always needs addr
  1163. pushing
  1164. Revision 1.102 1999/08/25 11:59:39 jonas
  1165. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  1166. Revision 1.101 1999/08/23 23:38:18 pierre
  1167. + TEMPREGDEBUG code added
  1168. Revision 1.100 1999/08/19 13:08:45 pierre
  1169. * emit_??? used
  1170. Revision 1.99 1999/08/09 22:19:47 peter
  1171. * classes vmt changed to only positive addresses
  1172. * sharedlib creation is working
  1173. Revision 1.98 1999/08/09 10:37:55 peter
  1174. * fixed pushing of self with methodpointer
  1175. Revision 1.97 1999/08/04 13:45:18 florian
  1176. + floating point register variables !!
  1177. * pairegalloc is now generated for register variables
  1178. Revision 1.96 1999/08/04 00:22:41 florian
  1179. * renamed i386asm and i386base to cpuasm and cpubase
  1180. Revision 1.95 1999/08/03 22:02:34 peter
  1181. * moved bitmask constants to sets
  1182. * some other type/const renamings
  1183. Revision 1.94 1999/07/06 21:48:09 florian
  1184. * a lot bug fixes:
  1185. - po_external isn't any longer necessary for procedure compatibility
  1186. - m_tp_procvar is in -Sd now available
  1187. - error messages of procedure variables improved
  1188. - return values with init./finalization fixed
  1189. - data types with init./finalization aren't any longer allowed in variant
  1190. record
  1191. Revision 1.93 1999/06/22 13:31:24 peter
  1192. * merged
  1193. Revision 1.92 1999/06/16 09:32:45 peter
  1194. * merged
  1195. Revision 1.91 1999/06/14 17:47:47 peter
  1196. * merged
  1197. Revision 1.90.2.3 1999/06/22 13:30:08 peter
  1198. * fixed return with packenum
  1199. Revision 1.90.2.2 1999/06/16 09:30:44 peter
  1200. * fixed loading of ansistring when eax was already used
  1201. Revision 1.90.2.1 1999/06/14 17:24:42 peter
  1202. * fixed saving of registers with decr_ansistr
  1203. Revision 1.90 1999/06/02 10:11:40 florian
  1204. * make cycle fixed i.e. compilation with 0.99.10
  1205. * some fixes for qword
  1206. * start of register calling conventions
  1207. Revision 1.89 1999/05/28 15:59:46 pierre
  1208. * forgotten emitcall change in conditionnal
  1209. Revision 1.88 1999/05/28 11:00:49 peter
  1210. * removed ungettempoftype
  1211. Revision 1.87 1999/05/27 19:44:07 peter
  1212. * removed oldasm
  1213. * plabel -> pasmlabel
  1214. * -a switches to source writing automaticly
  1215. * assembler readers OOPed
  1216. * asmsymbol automaticly external
  1217. * jumptables and other label fixes for asm readers
  1218. Revision 1.86 1999/05/23 18:41:58 florian
  1219. * better error recovering in typed constants
  1220. * some problems with arrays of const fixed, some problems
  1221. due my previous
  1222. - the location type of array constructor is now LOC_MEM
  1223. - the pushing of high fixed
  1224. - parameter copying fixed
  1225. - zero temp. allocation removed
  1226. * small problem in the assembler writers fixed:
  1227. ref to nil wasn't written correctly
  1228. Revision 1.85 1999/05/21 13:54:44 peter
  1229. * NEWLAB for label as symbol
  1230. Revision 1.84 1999/05/18 22:34:26 pierre
  1231. * extedebug problem solved
  1232. Revision 1.83 1999/05/18 21:58:24 florian
  1233. * fixed some bugs related to temp. ansistrings and functions results
  1234. which return records/objects/arrays which need init/final.
  1235. Revision 1.82 1999/05/18 14:15:23 peter
  1236. * containsself fixes
  1237. * checktypes()
  1238. Revision 1.81 1999/05/18 09:52:17 peter
  1239. * procedure of object and addrn fixes
  1240. Revision 1.80 1999/05/17 23:51:37 peter
  1241. * with temp vars now use a reference with a persistant temp instead
  1242. of setting datasize
  1243. Revision 1.79 1999/05/17 21:56:59 florian
  1244. * new temporary ansistring handling
  1245. Revision 1.78 1999/05/01 13:24:02 peter
  1246. * merged nasm compiler
  1247. * old asm moved to oldasm/
  1248. Revision 1.77 1999/04/29 22:12:21 pierre
  1249. * fix for ID 388 removing real from stack was wrong
  1250. Revision 1.76 1999/04/25 22:33:19 pierre
  1251. * fix for TESTOBJEXT code
  1252. Revision 1.75 1999/04/19 09:45:46 pierre
  1253. + cdecl or stdcall push all args with longint size
  1254. * tempansi stuff cleaned up
  1255. Revision 1.74 1999/04/16 13:42:23 jonas
  1256. * more regalloc fixes (still not complete)
  1257. Revision 1.73 1999/04/16 10:26:56 pierre
  1258. * no add $0,%esp for cdecl functions without parameters
  1259. Revision 1.72 1999/04/09 08:41:48 peter
  1260. * define to get ansistring returns in ref instead of reg
  1261. Revision 1.71 1999/03/31 13:55:04 peter
  1262. * assembler inlining working for ag386bin
  1263. Revision 1.70 1999/03/24 23:16:46 peter
  1264. * fixed bugs 212,222,225,227,229,231,233
  1265. Revision 1.69 1999/02/25 21:02:21 peter
  1266. * ag386bin updates
  1267. + coff writer
  1268. Revision 1.68 1999/02/22 02:15:04 peter
  1269. * updates for ag386bin
  1270. Revision 1.67 1999/02/11 09:46:21 pierre
  1271. * fix for normal method calls inside static methods :
  1272. WARNING there were both parser and codegen errors !!
  1273. added static_call boolean to calln tree
  1274. Revision 1.66 1999/02/09 15:45:46 florian
  1275. + complex results for assembler functions, fixes bug0155
  1276. Revision 1.65 1999/02/08 11:29:04 pierre
  1277. * fix for bug0214
  1278. several problems where combined
  1279. search_class_member did not set srsymtable
  1280. => in do_member_read the call node got a wrong symtable
  1281. in cg386cal the vmt was pushed twice without chacking if it exists
  1282. now %esi is set to zero and pushed if not vmt
  1283. (not very efficient but should work !)
  1284. Revision 1.64 1999/02/04 10:49:39 florian
  1285. + range checking for ansi- and widestrings
  1286. * made it compilable with TP
  1287. Revision 1.63 1999/02/03 10:18:14 pierre
  1288. * conditionnal code for extended check of virtual methods
  1289. Revision 1.62 1999/02/02 23:52:32 florian
  1290. * problem with calls to method pointers in methods fixed
  1291. - double ansistrings temp management removed
  1292. Revision 1.61 1999/02/02 11:04:36 florian
  1293. * class destructors fixed, class instances weren't disposed correctly
  1294. Revision 1.60 1999/01/28 23:56:44 florian
  1295. * the reference in the result location of a function call wasn't resetted =>
  1296. problem with unallowed far pointer, is solved now
  1297. Revision 1.59 1999/01/27 00:13:52 florian
  1298. * "procedure of object"-stuff fixed
  1299. Revision 1.58 1999/01/21 22:10:35 peter
  1300. * fixed array of const
  1301. * generic platform independent high() support
  1302. Revision 1.57 1999/01/21 16:40:51 pierre
  1303. * fix for constructor inside with statements
  1304. Revision 1.56 1998/12/30 13:41:05 peter
  1305. * released valuepara
  1306. Revision 1.55 1998/12/22 13:10:58 florian
  1307. * memory leaks for ansistring type casts fixed
  1308. Revision 1.54 1998/12/19 00:23:41 florian
  1309. * ansistring memory leaks fixed
  1310. Revision 1.53 1998/12/11 00:02:47 peter
  1311. + globtype,tokens,version unit splitted from globals
  1312. Revision 1.52 1998/12/10 14:39:29 florian
  1313. * bug with p(const a : ansistring) fixed
  1314. * duplicate constant ansistrings were handled wrong, fixed
  1315. Revision 1.51 1998/12/10 09:47:15 florian
  1316. + basic operations with int64/qord (compiler with -dint64)
  1317. + rtti of enumerations extended: names are now written
  1318. Revision 1.50 1998/12/06 13:12:44 florian
  1319. * better code generation for classes which are passed as parameters to
  1320. subroutines
  1321. Revision 1.49 1998/11/30 09:43:00 pierre
  1322. * some range check bugs fixed (still not working !)
  1323. + added DLL writing support for win32 (also accepts variables)
  1324. + TempAnsi for code that could be used for Temporary ansi strings
  1325. handling
  1326. Revision 1.48 1998/11/27 14:50:30 peter
  1327. + open strings, $P switch support
  1328. Revision 1.47 1998/11/26 21:30:03 peter
  1329. * fix for valuepara
  1330. Revision 1.46 1998/11/26 14:39:10 peter
  1331. * ansistring -> pchar fixed
  1332. * ansistring constants fixed
  1333. * ansistring constants are now written once
  1334. Revision 1.45 1998/11/18 15:44:07 peter
  1335. * VALUEPARA for tp7 compatible value parameters
  1336. Revision 1.44 1998/11/16 15:35:36 peter
  1337. * rename laod/copystring -> load/copyshortstring
  1338. * fixed int-bool cnv bug
  1339. + char-ansistring conversion
  1340. Revision 1.43 1998/11/15 16:32:33 florian
  1341. * some stuff of Pavel implement (win32 dll creation)
  1342. * bug with ansistring function results fixed
  1343. Revision 1.42 1998/11/13 15:40:13 pierre
  1344. + added -Se in Makefile cvstest target
  1345. + lexlevel cleanup
  1346. normal_function_level main_program_level and unit_init_level defined
  1347. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  1348. (test added in code !)
  1349. * -Un option was wrong
  1350. * _FAIL and _SELF only keyword inside
  1351. constructors and methods respectively
  1352. Revision 1.41 1998/11/12 11:19:40 pierre
  1353. * fix for first line of function break
  1354. Revision 1.40 1998/11/10 10:09:08 peter
  1355. * va_list -> array of const
  1356. Revision 1.39 1998/11/09 11:44:33 peter
  1357. + va_list for printf support
  1358. Revision 1.38 1998/10/21 15:12:49 pierre
  1359. * bug fix for IOCHECK inside a procedure with iocheck modifier
  1360. * removed the GPF for unexistant overloading
  1361. (firstcall was called with procedinition=nil !)
  1362. * changed typen to what Florian proposed
  1363. gentypenode(p : pdef) sets the typenodetype field
  1364. and resulttype is only set if inside bt_type block !
  1365. Revision 1.37 1998/10/21 08:39:57 florian
  1366. + ansistring operator +
  1367. + $h and string[n] for n>255 added
  1368. * small problem with TP fixed
  1369. Revision 1.36 1998/10/20 08:06:39 pierre
  1370. * several memory corruptions due to double freemem solved
  1371. => never use p^.loc.location:=p^.left^.loc.location;
  1372. + finally I added now by default
  1373. that ra386dir translates global and unit symbols
  1374. + added a first field in tsymtable and
  1375. a nextsym field in tsym
  1376. (this allows to obtain ordered type info for
  1377. records and objects in gdb !)
  1378. Revision 1.35 1998/10/16 08:51:45 peter
  1379. + target_os.stackalignment
  1380. + stack can be aligned at 2 or 4 byte boundaries
  1381. Revision 1.34 1998/10/09 08:56:22 pierre
  1382. * several memory leaks fixed
  1383. Revision 1.33 1998/10/06 17:16:39 pierre
  1384. * some memory leaks fixed (thanks to Peter for heaptrc !)
  1385. Revision 1.32 1998/10/01 09:22:52 peter
  1386. * fixed value openarray
  1387. * ungettemp of arrayconstruct
  1388. Revision 1.31 1998/09/28 16:57:15 pierre
  1389. * changed all length(p^.value_str^) into str_length(p)
  1390. to get it work with and without ansistrings
  1391. * changed sourcefiles field of tmodule to a pointer
  1392. Revision 1.30 1998/09/26 15:03:02 florian
  1393. * small problems with DOM and excpetions fixed (code generation
  1394. of raise was wrong and self was sometimes destroyed :()
  1395. Revision 1.29 1998/09/25 00:04:00 florian
  1396. * problems when calling class methods fixed
  1397. Revision 1.28 1998/09/24 14:27:37 peter
  1398. * some better support for openarray
  1399. Revision 1.27 1998/09/24 09:02:13 peter
  1400. * rewritten isconvertable to use case
  1401. * array of .. and single variable are compatible
  1402. Revision 1.26 1998/09/21 08:45:06 pierre
  1403. + added vmt_offset in tobjectdef.write for fututre use
  1404. (first steps to have objects without vmt if no virtual !!)
  1405. + added fpu_used field for tabstractprocdef :
  1406. sets this level to 2 if the functions return with value in FPU
  1407. (is then set to correct value at parsing of implementation)
  1408. THIS MIGHT refuse some code with FPU expression too complex
  1409. that were accepted before and even in some cases
  1410. that don't overflow in fact
  1411. ( like if f : float; is a forward that finally in implementation
  1412. only uses one fpu register !!)
  1413. Nevertheless I think that it will improve security on
  1414. FPU operations !!
  1415. * most other changes only for UseBrowser code
  1416. (added symtable references for record and objects)
  1417. local switch for refs to args and local of each function
  1418. (static symtable still missing)
  1419. UseBrowser still not stable and probably broken by
  1420. the definition hash array !!
  1421. Revision 1.25 1998/09/20 12:26:35 peter
  1422. * merged fixes
  1423. Revision 1.24 1998/09/17 09:42:10 peter
  1424. + pass_2 for cg386
  1425. * Message() -> CGMessage() for pass_1/pass_2
  1426. Revision 1.23 1998/09/14 10:43:45 peter
  1427. * all internal RTL functions start with FPC_
  1428. Revision 1.22.2.1 1998/09/20 12:20:06 peter
  1429. * Fixed stack not on 4 byte boundary when doing a call
  1430. Revision 1.22 1998/09/04 08:41:37 peter
  1431. * updated some error CGMessages
  1432. Revision 1.21 1998/09/01 12:47:57 peter
  1433. * use pdef^.size instead of orddef^.typ
  1434. Revision 1.20 1998/08/31 12:22:15 peter
  1435. * secondinline moved to cg386inl
  1436. Revision 1.19 1998/08/31 08:52:03 peter
  1437. * fixed error 10 with succ() and pref()
  1438. Revision 1.18 1998/08/20 21:36:38 peter
  1439. * fixed 'with object do' bug
  1440. Revision 1.17 1998/08/19 16:07:36 jonas
  1441. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  1442. Revision 1.16 1998/08/18 09:24:36 pierre
  1443. * small warning position bug fixed
  1444. * support_mmx switches splitting was missing
  1445. * rhide error and warning output corrected
  1446. Revision 1.15 1998/08/13 11:00:09 peter
  1447. * fixed procedure<>procedure construct
  1448. Revision 1.14 1998/08/11 14:05:33 peter
  1449. * fixed sizeof(array of char)
  1450. Revision 1.13 1998/08/10 14:49:45 peter
  1451. + localswitches, moduleswitches, globalswitches splitting
  1452. Revision 1.12 1998/07/30 13:30:31 florian
  1453. * final implemenation of exception support, maybe it needs
  1454. some fixes :)
  1455. Revision 1.11 1998/07/24 22:16:52 florian
  1456. * internal error 10 together with array access fixed. I hope
  1457. that's the final fix.
  1458. Revision 1.10 1998/07/18 22:54:23 florian
  1459. * some ansi/wide/longstring support fixed:
  1460. o parameter passing
  1461. o returning as result from functions
  1462. Revision 1.9 1998/07/07 17:40:37 peter
  1463. * packrecords 4 works
  1464. * word aligning of parameters
  1465. Revision 1.8 1998/07/06 15:51:15 michael
  1466. Added length checking for string reading
  1467. Revision 1.7 1998/07/06 14:19:51 michael
  1468. + Added calls for reading/writing ansistrings
  1469. Revision 1.6 1998/07/01 15:28:48 peter
  1470. + better writeln/readln handling, now 100% like tp7
  1471. Revision 1.5 1998/06/25 14:04:17 peter
  1472. + internal inc/dec
  1473. Revision 1.4 1998/06/25 08:48:06 florian
  1474. * first version of rtti support
  1475. Revision 1.3 1998/06/09 16:01:33 pierre
  1476. + added procedure directive parsing for procvars
  1477. (accepted are popstack cdecl and pascal)
  1478. + added C vars with the following syntax
  1479. var C calias 'true_c_name';(can be followed by external)
  1480. reason is that you must add the Cprefix
  1481. which is target dependent
  1482. Revision 1.2 1998/06/08 13:13:29 pierre
  1483. + temporary variables now in temp_gen.pas unit
  1484. because it is processor independent
  1485. * mppc68k.bat modified to undefine i386 and support_mmx
  1486. (which are defaults for i386)
  1487. Revision 1.1 1998/06/05 17:44:10 peter
  1488. * splitted cgi386
  1489. }