cpupi.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. {
  2. Copyright (c) 2002-2010 by Florian Klaempfl and Jonas Maebe
  3. This unit contains the CPU specific part of tprocinfo
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cpupi;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cutils,globtype,aasmdata,
  22. procinfo,cpuinfo, symtype,aasmbase,cgbase,
  23. psub, cclasses;
  24. type
  25. { tcpuprocinfo }
  26. tcpuprocinfo=class(tcgprocinfo)
  27. public
  28. { label to the nearest local exception handler }
  29. CurrRaiseLabel : tasmlabel;
  30. constructor create(aparent: tprocinfo); override;
  31. function calc_stackframe_size : longint;override;
  32. procedure setup_eh; override;
  33. procedure generate_exit_label(list: tasmlist); override;
  34. procedure postprocess_code; override;
  35. procedure set_first_temp_offset;override;
  36. end;
  37. implementation
  38. uses
  39. systems,verbose,globals,cpubase,tgcpu,aasmcpu,aasmtai,cgexcept,
  40. tgobj,paramgr,symconst,symdef,symtable,symcpu,cgutils,pass_2,parabase,
  41. fmodule,hlcgobj,hlcgcpu,defutil;
  42. {*****************************************************************************
  43. twasmexceptionstatehandler_noexceptions
  44. *****************************************************************************}
  45. type
  46. { twasmexceptionstatehandler_noexceptions }
  47. twasmexceptionstatehandler_noexceptions = class(tcgexceptionstatehandler)
  48. class procedure get_exception_temps(list:TAsmList;var t:texceptiontemps); override;
  49. class procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps); override;
  50. class procedure new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate); override;
  51. class procedure free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean); override;
  52. class procedure handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate); override;
  53. end;
  54. class procedure twasmexceptionstatehandler_noexceptions.get_exception_temps(list:TAsmList;var t:texceptiontemps);
  55. begin
  56. if not assigned(exceptionreasontype) then
  57. exceptionreasontype:=search_system_proc('fpc_setjmp').returndef;
  58. reference_reset(t.envbuf,0,[]);
  59. reference_reset(t.jmpbuf,0,[]);
  60. tg.gethltemp(list,exceptionreasontype,exceptionreasontype.size,tt_persistent,t.reasonbuf);
  61. end;
  62. class procedure twasmexceptionstatehandler_noexceptions.unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  63. begin
  64. tg.ungettemp(list,t.reasonbuf);
  65. end;
  66. class procedure twasmexceptionstatehandler_noexceptions.new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate);
  67. begin
  68. exceptstate.exceptionlabel:=nil;
  69. exceptstate.oldflowcontrol:=flowcontrol;
  70. exceptstate.finallycodelabel:=nil;
  71. flowcontrol:=[fc_inflowcontrol,fc_catching_exceptions];
  72. end;
  73. class procedure twasmexceptionstatehandler_noexceptions.free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean);
  74. begin
  75. end;
  76. class procedure twasmexceptionstatehandler_noexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
  77. begin
  78. list.Concat(tai_comment.Create(strpnew('TODO: handle_nested_exception')));
  79. end;
  80. {*****************************************************************************
  81. twasmexceptionstatehandler_jsexceptions
  82. *****************************************************************************}
  83. type
  84. twasmexceptionstatehandler_jsexceptions = class(tcgexceptionstatehandler)
  85. class procedure get_exception_temps(list:TAsmList;var t:texceptiontemps); override;
  86. class procedure unget_exception_temps(list:TAsmList;const t:texceptiontemps); override;
  87. class procedure new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate); override;
  88. class procedure free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean); override;
  89. class procedure handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate); override;
  90. end;
  91. class procedure twasmexceptionstatehandler_jsexceptions.get_exception_temps(list:TAsmList;var t:texceptiontemps);
  92. begin
  93. if not assigned(exceptionreasontype) then
  94. exceptionreasontype:=search_system_proc('fpc_setjmp').returndef;
  95. reference_reset(t.envbuf,0,[]);
  96. reference_reset(t.jmpbuf,0,[]);
  97. tg.gethltemp(list,exceptionreasontype,exceptionreasontype.size,tt_persistent,t.reasonbuf);
  98. end;
  99. class procedure twasmexceptionstatehandler_jsexceptions.unget_exception_temps(list:TAsmList;const t:texceptiontemps);
  100. begin
  101. tg.ungettemp(list,t.reasonbuf);
  102. end;
  103. class procedure twasmexceptionstatehandler_jsexceptions.new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate);
  104. begin
  105. exceptstate.exceptionlabel:=nil;
  106. exceptstate.oldflowcontrol:=flowcontrol;
  107. exceptstate.finallycodelabel:=nil;
  108. flowcontrol:=[fc_inflowcontrol,fc_catching_exceptions];
  109. end;
  110. class procedure twasmexceptionstatehandler_jsexceptions.free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean);
  111. begin
  112. end;
  113. class procedure twasmexceptionstatehandler_jsexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
  114. begin
  115. list.Concat(tai_comment.Create(strpnew('TODO: handle_nested_exception')));
  116. end;
  117. {*****************************************************************************
  118. twasmexceptionstatehandler_nativeexceptions
  119. *****************************************************************************}
  120. type
  121. { twasmexceptionstatehandler_nativeexceptions }
  122. twasmexceptionstatehandler_nativeexceptions = class(tcgexceptionstatehandler)
  123. class procedure new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate); override;
  124. class procedure free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean); override;
  125. class procedure handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate); override;
  126. { start of an "on" (catch) block }
  127. class procedure begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister); override;
  128. { end of an "on" (catch) block }
  129. class procedure end_catch(list: TAsmList); override;
  130. end;
  131. class procedure twasmexceptionstatehandler_nativeexceptions.new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate);
  132. begin
  133. exceptstate.exceptionlabel:=nil;
  134. exceptstate.oldflowcontrol:=flowcontrol;
  135. exceptstate.finallycodelabel:=nil;
  136. flowcontrol:=[fc_inflowcontrol,fc_catching_exceptions];
  137. end;
  138. class procedure twasmexceptionstatehandler_nativeexceptions.free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean);
  139. begin
  140. end;
  141. class procedure twasmexceptionstatehandler_nativeexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
  142. begin
  143. internalerror(2021100503);
  144. end;
  145. class procedure twasmexceptionstatehandler_nativeexceptions.begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister);
  146. var
  147. pd: tprocdef;
  148. href2: treference;
  149. fpc_catches_res,
  150. paraloc1: tcgpara;
  151. exceptloc: tlocation;
  152. indirect: boolean;
  153. otherunit: boolean;
  154. begin
  155. paraloc1.init;
  156. otherunit:=findunitsymtable(excepttype.owner).moduleid<>findunitsymtable(current_procinfo.procdef.owner).moduleid;
  157. indirect:=(tf_supports_packages in target_info.flags) and
  158. (target_info.system in systems_indirect_var_imports) and
  159. (cs_imported_data in current_settings.localswitches) and
  160. otherunit;
  161. { send the vmt parameter }
  162. pd:=search_system_proc('fpc_catches');
  163. reference_reset_symbol(href2, current_asmdata.RefAsmSymbol(excepttype.vmt_mangledname, AT_DATA, indirect), 0, sizeof(pint), []);
  164. if otherunit then
  165. current_module.add_extern_asmsym(excepttype.vmt_mangledname, AB_EXTERNAL, AT_DATA);
  166. paramanager.getcgtempparaloc(list, pd, 1, paraloc1);
  167. hlcg.a_loadaddr_ref_cgpara(list, excepttype.vmt_def, href2, paraloc1);
  168. paramanager.freecgpara(list, paraloc1);
  169. fpc_catches_res:=hlcg.g_call_system_proc(list, pd, [@paraloc1], nil);
  170. location_reset(exceptloc, LOC_REGISTER, def_cgsize(fpc_catches_res.def));
  171. exceptloc.register:=hlcg.getaddressregister(list, fpc_catches_res.def);
  172. hlcg.gen_load_cgpara_loc(list, fpc_catches_res.def, fpc_catches_res, exceptloc, true);
  173. { is it this catch? }
  174. thlcgwasm(hlcg).a_cmp_const_reg_stack(list, fpc_catches_res.def, OC_NE, 0, exceptloc.register);
  175. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if));
  176. thlcgwasm(hlcg).incblock;
  177. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  178. paraloc1.done;
  179. exceptlocdef:=fpc_catches_res.def;
  180. exceptlocreg:=exceptloc.register;
  181. end;
  182. class procedure twasmexceptionstatehandler_nativeexceptions.end_catch(list: TAsmList);
  183. begin
  184. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_if));
  185. thlcgwasm(hlcg).decblock;
  186. end;
  187. {*****************************************************************************
  188. twasmexceptionstatehandler_bfexceptions
  189. *****************************************************************************}
  190. type
  191. { twasmexceptionstatehandler_bfexceptions }
  192. twasmexceptionstatehandler_bfexceptions = class(tcgexceptionstatehandler)
  193. class procedure new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate); override;
  194. class procedure free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean); override;
  195. class procedure handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate); override;
  196. { start of an "on" (catch) block }
  197. class procedure begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister); override;
  198. { end of an "on" (catch) block }
  199. class procedure end_catch(list: TAsmList); override;
  200. end;
  201. class procedure twasmexceptionstatehandler_bfexceptions.new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate);
  202. begin
  203. exceptstate.exceptionlabel:=nil;
  204. exceptstate.oldflowcontrol:=flowcontrol;
  205. exceptstate.finallycodelabel:=nil;
  206. flowcontrol:=[fc_inflowcontrol,fc_catching_exceptions];
  207. end;
  208. class procedure twasmexceptionstatehandler_bfexceptions.free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean);
  209. begin
  210. end;
  211. class procedure twasmexceptionstatehandler_bfexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
  212. begin
  213. internalerror(2021100502);
  214. end;
  215. class procedure twasmexceptionstatehandler_bfexceptions.begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister);
  216. var
  217. pd: tprocdef;
  218. href2: treference;
  219. fpc_catches_res,
  220. paraloc1: tcgpara;
  221. exceptloc: tlocation;
  222. indirect: boolean;
  223. otherunit: boolean;
  224. begin
  225. paraloc1.init;
  226. otherunit:=findunitsymtable(excepttype.owner).moduleid<>findunitsymtable(current_procinfo.procdef.owner).moduleid;
  227. indirect:=(tf_supports_packages in target_info.flags) and
  228. (target_info.system in systems_indirect_var_imports) and
  229. (cs_imported_data in current_settings.localswitches) and
  230. otherunit;
  231. { send the vmt parameter }
  232. pd:=search_system_proc('fpc_catches');
  233. reference_reset_symbol(href2, current_asmdata.RefAsmSymbol(excepttype.vmt_mangledname, AT_DATA, indirect), 0, sizeof(pint), []);
  234. if otherunit then
  235. current_module.add_extern_asmsym(excepttype.vmt_mangledname, AB_EXTERNAL, AT_DATA);
  236. paramanager.getcgtempparaloc(list, pd, 1, paraloc1);
  237. hlcg.a_loadaddr_ref_cgpara(list, excepttype.vmt_def, href2, paraloc1);
  238. paramanager.freecgpara(list, paraloc1);
  239. fpc_catches_res:=hlcg.g_call_system_proc(list, pd, [@paraloc1], nil);
  240. location_reset(exceptloc, LOC_REGISTER, def_cgsize(fpc_catches_res.def));
  241. exceptloc.register:=hlcg.getaddressregister(list, fpc_catches_res.def);
  242. hlcg.gen_load_cgpara_loc(list, fpc_catches_res.def, fpc_catches_res, exceptloc, true);
  243. { is it this catch? }
  244. thlcgwasm(hlcg).a_cmp_const_reg_stack(list, fpc_catches_res.def, OC_NE, 0, exceptloc.register);
  245. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if));
  246. thlcgwasm(hlcg).incblock;
  247. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  248. paraloc1.done;
  249. exceptlocdef:=fpc_catches_res.def;
  250. exceptlocreg:=exceptloc.register;
  251. end;
  252. class procedure twasmexceptionstatehandler_bfexceptions.end_catch(list: TAsmList);
  253. begin
  254. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_if));
  255. thlcgwasm(hlcg).decblock;
  256. end;
  257. {*****************************************************************************
  258. tcpuprocinfo
  259. *****************************************************************************}
  260. constructor tcpuprocinfo.create(aparent: tprocinfo);
  261. begin
  262. inherited create(aparent);
  263. if ts_wasm_bf_exceptions in current_settings.targetswitches then
  264. current_asmdata.getjumplabel(CurrRaiseLabel);
  265. end;
  266. function tcpuprocinfo.calc_stackframe_size: longint;
  267. begin
  268. { the stack frame in WebAssembly should always have a 16-byte alignment }
  269. Result:=Align(inherited calc_stackframe_size,16);
  270. end;
  271. procedure tcpuprocinfo.setup_eh;
  272. begin
  273. if ts_wasm_native_exceptions in current_settings.targetswitches then
  274. cexceptionstatehandler:=twasmexceptionstatehandler_nativeexceptions
  275. else if ts_wasm_js_exceptions in current_settings.targetswitches then
  276. cexceptionstatehandler:=twasmexceptionstatehandler_jsexceptions
  277. else if ts_wasm_no_exceptions in current_settings.targetswitches then
  278. cexceptionstatehandler:=twasmexceptionstatehandler_noexceptions
  279. else if ts_wasm_bf_exceptions in current_settings.targetswitches then
  280. cexceptionstatehandler:=twasmexceptionstatehandler_bfexceptions
  281. else
  282. internalerror(2021091701);
  283. end;
  284. procedure tcpuprocinfo.generate_exit_label(list: tasmlist);
  285. begin
  286. list.concat(taicpu.op_none(a_end_block));
  287. thlcgwasm(hlcg).decblock;
  288. inherited generate_exit_label(list);
  289. if ts_wasm_bf_exceptions in current_settings.targetswitches then
  290. hlcg.a_label(list,CurrRaiseLabel);
  291. end;
  292. procedure tcpuprocinfo.postprocess_code;
  293. function findfirst_tai_functype(asmlist: TAsmList): tai_functype;
  294. var
  295. hp: tai;
  296. begin
  297. result:=nil;
  298. if not assigned(asmlist) then
  299. exit;
  300. hp:=tai(asmlist.first);
  301. while assigned(hp) do
  302. begin
  303. if hp.typ=ait_functype then
  304. begin
  305. result:=tai_functype(hp);
  306. exit;
  307. end;
  308. hp:=tai(hp.Next);
  309. end;
  310. end;
  311. procedure replace_local_frame_pointer(asmlist: TAsmList);
  312. var
  313. hp: tai;
  314. instr: taicpu;
  315. l: Integer;
  316. begin
  317. if not assigned(asmlist) then
  318. exit;
  319. hp:=tai(asmlist.first);
  320. while assigned(hp) do
  321. begin
  322. if hp.typ=ait_instruction then
  323. begin
  324. instr:=taicpu(hp);
  325. for l:=0 to instr.ops-1 do
  326. if (instr.oper[l]^.typ=top_reg) and (instr.oper[l]^.reg=NR_LOCAL_FRAME_POINTER_REG) then
  327. instr.loadref(l,tcpuprocdef(current_procinfo.procdef).frame_pointer_ref);
  328. end;
  329. hp:=tai(hp.Next);
  330. end;
  331. end;
  332. function FindNextInstruction(hp: tai): taicpu;
  333. begin
  334. result:=nil;
  335. if not assigned(hp) then
  336. exit;
  337. repeat
  338. hp:=tai(hp.next);
  339. until not assigned(hp) or (hp.typ=ait_instruction);
  340. if assigned(hp) then
  341. result:=taicpu(hp);
  342. end;
  343. procedure resolve_labels_pass1(asmlist: TAsmList);
  344. var
  345. hp: tai;
  346. lastinstr, nextinstr: taicpu;
  347. cur_nesting_depth: longint;
  348. lbl: tai_label;
  349. begin
  350. cur_nesting_depth:=0;
  351. lastinstr:=nil;
  352. hp:=tai(asmlist.first);
  353. while assigned(hp) do
  354. begin
  355. case hp.typ of
  356. ait_instruction:
  357. begin
  358. lastinstr:=taicpu(hp);
  359. case lastinstr.opcode of
  360. a_block,
  361. a_loop,
  362. a_if,
  363. a_try:
  364. inc(cur_nesting_depth);
  365. a_end_block,
  366. a_end_loop,
  367. a_end_if,
  368. a_end_try:
  369. begin
  370. dec(cur_nesting_depth);
  371. if cur_nesting_depth<0 then
  372. internalerror(2021102001);
  373. end;
  374. else
  375. ;
  376. end;
  377. end;
  378. ait_label:
  379. begin
  380. lbl:=tai_label(hp);
  381. lbl.labsym.nestingdepth:=-1;
  382. nextinstr:=FindNextInstruction(hp);
  383. if assigned(nextinstr) and (nextinstr.opcode in [a_end_block,a_end_try,a_end_if]) then
  384. lbl.labsym.nestingdepth:=cur_nesting_depth
  385. else if assigned(lastinstr) and (lastinstr.opcode=a_loop) then
  386. lbl.labsym.nestingdepth:=cur_nesting_depth
  387. else if assigned(lastinstr) and (lastinstr.opcode in [a_end_block,a_end_try,a_end_if]) then
  388. lbl.labsym.nestingdepth:=cur_nesting_depth+1
  389. else if assigned(nextinstr) and (nextinstr.opcode=a_loop) then
  390. lbl.labsym.nestingdepth:=cur_nesting_depth+1;
  391. end;
  392. else
  393. ;
  394. end;
  395. hp:=tai(hp.Next);
  396. end;
  397. if cur_nesting_depth<>0 then
  398. internalerror(2021102002);
  399. end;
  400. procedure resolve_labels_pass2(asmlist: TAsmList);
  401. var
  402. hp: tai;
  403. instr: taicpu;
  404. cur_nesting_depth: longint;
  405. begin
  406. cur_nesting_depth:=0;
  407. hp:=tai(asmlist.first);
  408. while assigned(hp) do
  409. begin
  410. if hp.typ=ait_instruction then
  411. begin
  412. instr:=taicpu(hp);
  413. case instr.opcode of
  414. a_block,
  415. a_loop,
  416. a_if,
  417. a_try:
  418. inc(cur_nesting_depth);
  419. a_end_block,
  420. a_end_loop,
  421. a_end_if,
  422. a_end_try:
  423. begin
  424. dec(cur_nesting_depth);
  425. if cur_nesting_depth<0 then
  426. internalerror(2021102003);
  427. end;
  428. a_br,
  429. a_br_if:
  430. begin
  431. if instr.ops<>1 then
  432. internalerror(2021102004);
  433. if instr.oper[0]^.typ=top_ref then
  434. begin
  435. if not assigned(instr.oper[0]^.ref^.symbol) then
  436. internalerror(2021102005);
  437. if (instr.oper[0]^.ref^.base<>NR_NO) or
  438. (instr.oper[0]^.ref^.index<>NR_NO) or
  439. (instr.oper[0]^.ref^.offset<>0) then
  440. internalerror(2021102006);
  441. if (instr.oper[0]^.ref^.symbol.nestingdepth<>-1) and
  442. (cur_nesting_depth>=instr.oper[0]^.ref^.symbol.nestingdepth) then
  443. instr.loadconst(0,cur_nesting_depth-instr.oper[0]^.ref^.symbol.nestingdepth)
  444. else
  445. begin
  446. {$ifndef EXTDEBUG}
  447. internalerror(2021102007);
  448. {$endif EXTDEBUG}
  449. end;
  450. end;
  451. end;
  452. else
  453. ;
  454. end;
  455. end;
  456. hp:=tai(hp.Next);
  457. end;
  458. if cur_nesting_depth<>0 then
  459. internalerror(2021102008);
  460. end;
  461. procedure resolve_labels(asmlist: TAsmList);
  462. begin
  463. if not assigned(asmlist) then
  464. exit;
  465. resolve_labels_pass1(asmlist);
  466. resolve_labels_pass2(asmlist);
  467. end;
  468. var
  469. templist : TAsmList;
  470. l : TWasmLocal;
  471. first: Boolean;
  472. local: tai_local;
  473. begin
  474. templist:=TAsmList.create;
  475. local:=nil;
  476. first:=true;
  477. l:=ttgwasm(tg).localvars.first;
  478. while Assigned(l) do
  479. begin
  480. local:=tai_local.create(l.typ);
  481. local.first:=first;
  482. first:=false;
  483. templist.Concat(local);
  484. l:=l.nextseq;
  485. end;
  486. if assigned(local) then
  487. local.last:=true;
  488. aktproccode.insertListAfter(findfirst_tai_functype(aktproccode),templist);
  489. templist.Free;
  490. replace_local_frame_pointer(aktproccode);
  491. resolve_labels(aktproccode);
  492. inherited postprocess_code;
  493. end;
  494. procedure tcpuprocinfo.set_first_temp_offset;
  495. var
  496. sz : integer;
  497. i : integer;
  498. sym: tsym;
  499. begin
  500. {
  501. Stackframe layout:
  502. sp:
  503. <incoming parameters>
  504. sp+first_temp_offset:
  505. <locals>
  506. <temp>
  507. }
  508. procdef.init_paraloc_info(calleeside);
  509. sz := procdef.calleeargareasize;
  510. tg.setfirsttemp(sz);
  511. end;
  512. initialization
  513. cprocinfo:=tcpuprocinfo;
  514. end.