cg386cal.pas 68 KB

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