aasmcpu.pas 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  1. {
  2. Copyright (c) 2019 by Free Pascal and Lazarus foundation
  3. Contains the assembler object for the WebAssembly
  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 aasmcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,globals,verbose,
  23. aasmbase,aasmtai,aasmdata,aasmsym,
  24. cgbase,cgutils,cpubase,cpuinfo,ogbase,
  25. widestr;
  26. { fake, there are no "mov reg,reg" instructions here }
  27. const
  28. { "mov reg,reg" source operand number }
  29. O_MOV_SOURCE = 0;
  30. { "mov reg,reg" source operand number }
  31. O_MOV_DEST = 0;
  32. type
  33. { taicpu }
  34. taicpu = class(tai_cpu_abstract_sym)
  35. constructor op_none(op : tasmop);
  36. constructor op_reg(op : tasmop;_op1 : tregister);
  37. constructor op_const(op : tasmop;_op1 : aint);
  38. constructor op_ref(op : tasmop;const _op1 : treference);
  39. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  40. constructor op_sym_const(op : tasmop;_op1 : tasmsymbol;_op2 : aint);
  41. constructor op_single(op : tasmop;_op1 : single);
  42. constructor op_double(op : tasmop;_op1 : double);
  43. constructor op_functype(op : tasmop; _op1: TWasmFuncType);
  44. procedure loadfunctype(opidx:longint;ft:TWasmFuncType);
  45. procedure loadsingle(opidx:longint;f:single);
  46. procedure loaddouble(opidx:longint;d:double);
  47. { register allocation }
  48. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  49. { register spilling code }
  50. function spilling_get_operation_type(opnr: longint): topertype;override;
  51. function Pass1(objdata:TObjData):longint;override;
  52. procedure Pass2(objdata:TObjData);override;
  53. end;
  54. tai_align = class(tai_align_abstract)
  55. { nothing to add }
  56. end;
  57. TImpExpType= (
  58. ie_Func, // functions
  59. ie_Table, // tables (arrays of methods)
  60. ie_Memory, // memory reference
  61. ie_Global // global variables
  62. );
  63. { tai_export_name }
  64. tai_export_name = class(tai)
  65. extname : ansistring; // external name
  66. intname : ansistring; // internal name
  67. symstype: TImpExpType;
  68. constructor create(const aextname, aintname: ansistring; asymtype: timpexptype);
  69. end;
  70. // local variable declaration
  71. { tai_local }
  72. tai_local = class(tai)
  73. bastyp: TWasmBasicType;
  74. name : string;
  75. first: boolean;
  76. last: boolean;
  77. constructor create(abasictype: TWasmBasicType; const aname: string = '');
  78. end;
  79. { tai_globaltype }
  80. tai_globaltype = class(tai)
  81. globalname: string;
  82. gtype: TWasmBasicType;
  83. immutable: boolean;
  84. constructor create(const aglobalname:string; atype: TWasmBasicType; aimmutable: boolean);
  85. end;
  86. { tai_functype }
  87. tai_functype = class(tai)
  88. funcname: string;
  89. functype: TWasmFuncType;
  90. constructor create(const afuncname: string; afunctype: TWasmFuncType);
  91. destructor destroy;override;
  92. end;
  93. { tai_tagtype }
  94. tai_tagtype = class(tai)
  95. tagname: string;
  96. params: TWasmResultType;
  97. constructor create(const atagname: string; aparams: TWasmResultType);
  98. end;
  99. { tai_import_module }
  100. tai_import_module = class(tai)
  101. symname: string;
  102. importmodule: string;
  103. constructor create(const asymname, aimportmodule: string);
  104. end;
  105. { tai_import_name }
  106. tai_import_name = class(tai)
  107. symname: string;
  108. importname: string;
  109. constructor create(const asymname, aimportname: string);
  110. end;
  111. procedure InitAsm;
  112. procedure DoneAsm;
  113. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  114. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  115. implementation
  116. uses
  117. ogwasm;
  118. { tai_globaltype }
  119. constructor tai_globaltype.create(const aglobalname: string; atype: TWasmBasicType; aimmutable: boolean);
  120. begin
  121. inherited Create;
  122. typ:=ait_globaltype;
  123. globalname:=aglobalname;
  124. gtype:=atype;
  125. immutable:=aimmutable;
  126. end;
  127. { tai_import_name }
  128. constructor tai_import_name.create(const asymname, aimportname: string);
  129. begin
  130. inherited Create;
  131. typ:=ait_import_name;
  132. symname:=asymname;
  133. importname:=aimportname;
  134. end;
  135. { tai_import_module }
  136. constructor tai_import_module.create(const asymname, aimportmodule: string);
  137. begin
  138. inherited Create;
  139. typ:=ait_import_module;
  140. symname:=asymname;
  141. importmodule:=aimportmodule;
  142. end;
  143. { tai_functype }
  144. constructor tai_functype.create(const afuncname: string; afunctype: TWasmFuncType);
  145. begin
  146. inherited Create;
  147. typ:=ait_functype;
  148. funcname:=afuncname;
  149. functype:=afunctype;
  150. end;
  151. destructor tai_functype.destroy;
  152. begin
  153. functype.free;
  154. inherited;
  155. end;
  156. { tai_tagtype }
  157. constructor tai_tagtype.create(const atagname: string; aparams: TWasmResultType);
  158. begin
  159. typ:=ait_tagtype;
  160. tagname:=atagname;
  161. params:=aparams;
  162. end;
  163. { tai_local }
  164. constructor tai_local.create(abasictype: TWasmBasicType; const aname: string);
  165. begin
  166. inherited Create;
  167. bastyp := abasictype;
  168. typ := ait_local;
  169. name := aname;
  170. end;
  171. { timpexp_ai }
  172. constructor tai_export_name.create(const aextname, aintname: ansistring;
  173. asymtype: timpexptype);
  174. begin
  175. inherited create;
  176. typ := ait_export_name;
  177. extname := aextname;
  178. intname := aintname;
  179. symstype:= asymtype;
  180. end;
  181. {*****************************************************************************
  182. taicpu Constructors
  183. *****************************************************************************}
  184. constructor taicpu.op_none(op : tasmop);
  185. begin
  186. inherited create(op);
  187. end;
  188. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  189. begin
  190. inherited create(op);
  191. ops:=1;
  192. {$ifdef EXTDEBUG}
  193. if getregtype(_op1)=R_INVALIDREGISTER then
  194. InternalError(2021011901);
  195. {$endif EXTDEBUG}
  196. loadreg(0,_op1);
  197. end;
  198. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  199. begin
  200. inherited create(op);
  201. ops:=1;
  202. loadref(0,_op1);
  203. if op in [a_local_get,a_local_set,a_local_tee] then
  204. begin
  205. if (_op1.base<>NR_LOCAL_STACK_POINTER_REG) or (_op1.index<>NR_NO) then
  206. internalerror(2021010201);
  207. end
  208. else
  209. begin
  210. if (_op1.base<>NR_NO) or (_op1.index<>NR_NO) then
  211. internalerror(2021010202);
  212. end;
  213. end;
  214. constructor taicpu.op_const(op : tasmop;_op1 : aint);
  215. begin
  216. inherited create(op);
  217. ops:=1;
  218. loadconst(0,_op1);
  219. end;
  220. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  221. begin
  222. inherited create(op);
  223. ops:=1;
  224. loadsymbol(0,_op1,0);
  225. end;
  226. constructor taicpu.op_sym_const(op: tasmop; _op1: tasmsymbol; _op2: aint);
  227. begin
  228. inherited create(op);
  229. ops:=2;
  230. loadsymbol(0,_op1,0);
  231. loadconst(1,_op2);
  232. end;
  233. constructor taicpu.op_single(op: tasmop; _op1: single);
  234. begin
  235. inherited create(op);
  236. ops:=1;
  237. loadsingle(0,_op1);
  238. end;
  239. constructor taicpu.op_double(op: tasmop; _op1: double);
  240. begin
  241. inherited create(op);
  242. ops:=1;
  243. loaddouble(0,_op1);
  244. end;
  245. constructor taicpu.op_functype(op: tasmop; _op1: TWasmFuncType);
  246. begin
  247. inherited create(op);
  248. ops:=1;
  249. loadfunctype(0,_op1);
  250. end;
  251. procedure taicpu.loadfunctype(opidx: longint; ft: TWasmFuncType);
  252. begin
  253. allocate_oper(opidx+1);
  254. with oper[opidx]^ do
  255. begin
  256. if typ<>top_functype then
  257. clearop(opidx);
  258. functype:=ft;
  259. typ:=top_functype;
  260. end;
  261. end;
  262. procedure taicpu.loadsingle(opidx:longint;f:single);
  263. begin
  264. allocate_oper(opidx+1);
  265. with oper[opidx]^ do
  266. begin
  267. if typ<>top_single then
  268. clearop(opidx);
  269. sval:=f;
  270. typ:=top_single;
  271. end;
  272. end;
  273. procedure taicpu.loaddouble(opidx: longint; d: double);
  274. begin
  275. allocate_oper(opidx+1);
  276. with oper[opidx]^ do
  277. begin
  278. if typ<>top_double then
  279. clearop(opidx);
  280. dval:=d;
  281. typ:=top_double;
  282. end;
  283. end;
  284. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  285. begin
  286. result:=false;
  287. end;
  288. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  289. begin
  290. if opcode in AsmOp_Store then
  291. result:=operand_write
  292. else
  293. result:=operand_read;
  294. end;
  295. function taicpu.Pass1(objdata: TObjData): longint;
  296. function SlebSize(v: tcgint): longint;
  297. begin
  298. result:=0;
  299. repeat
  300. v:=SarInt64(v,7);
  301. Inc(result);
  302. until ((v=0) and ((byte(v) and 64)=0)) or ((v=-1) and ((byte(v) and 64)<>0));
  303. end;
  304. function UlebSize(v: tcgint): longint;
  305. begin
  306. result:=0;
  307. repeat
  308. v:=v shr 7;
  309. Inc(result);
  310. until v=0;
  311. end;
  312. begin
  313. result:=0;
  314. case opcode of
  315. a_unreachable,
  316. a_nop,
  317. a_return,
  318. a_drop,
  319. a_i32_eqz,
  320. a_i32_eq,
  321. a_i32_ne,
  322. a_i32_lt_s,
  323. a_i32_lt_u,
  324. a_i32_gt_s,
  325. a_i32_gt_u,
  326. a_i32_le_s,
  327. a_i32_le_u,
  328. a_i32_ge_s,
  329. a_i32_ge_u,
  330. a_i64_eqz,
  331. a_i64_eq,
  332. a_i64_ne,
  333. a_i64_lt_s,
  334. a_i64_lt_u,
  335. a_i64_gt_s,
  336. a_i64_gt_u,
  337. a_i64_le_s,
  338. a_i64_le_u,
  339. a_i64_ge_s,
  340. a_i64_ge_u,
  341. a_f32_eq,
  342. a_f32_ne,
  343. a_f32_lt,
  344. a_f32_gt,
  345. a_f32_le,
  346. a_f32_ge,
  347. a_f64_eq,
  348. a_f64_ne,
  349. a_f64_lt,
  350. a_f64_gt,
  351. a_f64_le,
  352. a_f64_ge,
  353. a_i32_clz,
  354. a_i32_ctz,
  355. a_i32_popcnt,
  356. a_i32_add,
  357. a_i32_sub,
  358. a_i32_mul,
  359. a_i32_div_s,
  360. a_i32_div_u,
  361. a_i32_rem_s,
  362. a_i32_rem_u,
  363. a_i32_and,
  364. a_i32_or,
  365. a_i32_xor,
  366. a_i32_shl,
  367. a_i32_shr_s,
  368. a_i32_shr_u,
  369. a_i32_rotl,
  370. a_i32_rotr,
  371. a_i64_clz,
  372. a_i64_ctz,
  373. a_i64_popcnt,
  374. a_i64_add,
  375. a_i64_sub,
  376. a_i64_mul,
  377. a_i64_div_s,
  378. a_i64_div_u,
  379. a_i64_rem_s,
  380. a_i64_rem_u,
  381. a_i64_and,
  382. a_i64_or,
  383. a_i64_xor,
  384. a_i64_shl,
  385. a_i64_shr_s,
  386. a_i64_shr_u,
  387. a_i64_rotl,
  388. a_i64_rotr,
  389. a_f32_abs,
  390. a_f32_neg,
  391. a_f32_ceil,
  392. a_f32_floor,
  393. a_f32_trunc,
  394. a_f32_nearest,
  395. a_f32_sqrt,
  396. a_f32_add,
  397. a_f32_sub,
  398. a_f32_mul,
  399. a_f32_div,
  400. a_f32_min,
  401. a_f32_max,
  402. a_f32_copysign,
  403. a_f64_abs,
  404. a_f64_neg,
  405. a_f64_ceil,
  406. a_f64_floor,
  407. a_f64_trunc,
  408. a_f64_nearest,
  409. a_f64_sqrt,
  410. a_f64_add,
  411. a_f64_sub,
  412. a_f64_mul,
  413. a_f64_div,
  414. a_f64_min,
  415. a_f64_max,
  416. a_f64_copysign,
  417. a_i32_wrap_i64,
  418. a_i32_trunc_f32_s,
  419. a_i32_trunc_f32_u,
  420. a_i32_trunc_f64_s,
  421. a_i32_trunc_f64_u,
  422. a_i64_extend_i32_s,
  423. a_i64_extend_i32_u,
  424. a_i64_trunc_f32_s,
  425. a_i64_trunc_f32_u,
  426. a_i64_trunc_f64_s,
  427. a_i64_trunc_f64_u,
  428. a_f32_convert_i32_s,
  429. a_f32_convert_i32_u,
  430. a_f32_convert_i64_s,
  431. a_f32_convert_i64_u,
  432. a_f32_demote_f64,
  433. a_f64_convert_i32_s,
  434. a_f64_convert_i32_u,
  435. a_f64_convert_i64_s,
  436. a_f64_convert_i64_u,
  437. a_f64_promote_f32,
  438. a_i32_reinterpret_f32,
  439. a_i64_reinterpret_f64,
  440. a_f32_reinterpret_i32,
  441. a_f64_reinterpret_i64,
  442. a_i32_extend8_s,
  443. a_i32_extend16_s,
  444. a_i64_extend8_s,
  445. a_i64_extend16_s,
  446. a_i64_extend32_s,
  447. a_else,
  448. a_end_block,
  449. a_end_if,
  450. a_end_loop,
  451. a_end_try,
  452. a_catch_all:
  453. result:=1;
  454. a_memory_size,
  455. a_memory_grow:
  456. result:=2;
  457. a_memory_copy:
  458. result:=4;
  459. a_memory_fill,
  460. a_atomic_fence:
  461. result:=3;
  462. a_i32_const:
  463. begin
  464. if ops<>1 then
  465. internalerror(2021092001);
  466. with oper[0]^ do
  467. case typ of
  468. top_ref:
  469. begin
  470. if assigned(ref^.symbol) then
  471. result:=6
  472. else
  473. begin
  474. if assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) then
  475. internalerror(2021092018);
  476. result:=1+SlebSize(longint(ref^.offset));
  477. end;
  478. end;
  479. top_const:
  480. result:=1+SlebSize(longint(val));
  481. else
  482. internalerror(2021092615);
  483. end;
  484. end;
  485. a_i64_const:
  486. begin
  487. if ops<>1 then
  488. internalerror(2021092001);
  489. with oper[0]^ do
  490. case typ of
  491. top_ref:
  492. begin
  493. if assigned(ref^.symbol) then
  494. result:=6
  495. else
  496. begin
  497. if assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) then
  498. internalerror(2021092018);
  499. result:=1+SlebSize(int64(ref^.offset));
  500. end;
  501. end;
  502. top_const:
  503. result:=1+SlebSize(int64(val));
  504. else
  505. internalerror(2021092615);
  506. end;
  507. end;
  508. a_f32_const:
  509. result:=5;
  510. a_f64_const:
  511. result:=9;
  512. a_local_get,
  513. a_local_set,
  514. a_local_tee:
  515. begin
  516. if ops<>1 then
  517. internalerror(2021092001);
  518. with oper[0]^ do
  519. case typ of
  520. top_ref:
  521. begin
  522. if assigned(ref^.symbol) then
  523. internalerror(2021092005);
  524. if ref^.base<>NR_STACK_POINTER_REG then
  525. internalerror(2021092006);
  526. if ref^.index<>NR_NO then
  527. internalerror(2021092007);
  528. result:=1+UlebSize(ref^.offset);
  529. end;
  530. else
  531. internalerror(2021092008);
  532. end;
  533. end;
  534. a_global_get,
  535. a_global_set:
  536. begin
  537. if ops<>1 then
  538. internalerror(2021092010);
  539. with oper[0]^ do
  540. case typ of
  541. top_ref:
  542. begin
  543. if not assigned(ref^.symbol) then
  544. internalerror(2021092012);
  545. if (ref^.base<>NR_NO) or (ref^.index<>NR_NO) or (ref^.offset<>0) then
  546. internalerror(2021092013);
  547. result:=6;
  548. end;
  549. else
  550. internalerror(2021092011);
  551. end;
  552. end;
  553. a_end_function:
  554. result:=0;
  555. a_block,
  556. a_loop,
  557. a_if,
  558. a_try:
  559. begin
  560. if ops=0 then
  561. result:=2
  562. else
  563. begin
  564. if ops<>1 then
  565. internalerror(2021092015);
  566. with oper[0]^ do
  567. case typ of
  568. top_functype:
  569. begin
  570. if (length(functype.params)=0) and (length(functype.results)<=1) then
  571. result:=2
  572. else
  573. { more complex blocktypes are not yet implemented }
  574. internalerror(2021092621);
  575. end;
  576. else
  577. internalerror(2021092620);
  578. end;
  579. end;
  580. end;
  581. a_i32_load,
  582. a_i64_load,
  583. a_f32_load,
  584. a_f64_load,
  585. a_i32_load8_s,
  586. a_i32_load8_u,
  587. a_i32_load16_s,
  588. a_i32_load16_u,
  589. a_i64_load8_s,
  590. a_i64_load8_u,
  591. a_i64_load16_s,
  592. a_i64_load16_u,
  593. a_i64_load32_s,
  594. a_i64_load32_u,
  595. a_i32_store,
  596. a_i64_store,
  597. a_f32_store,
  598. a_f64_store,
  599. a_i32_store8,
  600. a_i32_store16,
  601. a_i64_store8,
  602. a_i64_store16,
  603. a_i64_store32:
  604. begin
  605. if ops<>1 then
  606. internalerror(2021092016);
  607. with oper[0]^ do
  608. case typ of
  609. top_ref:
  610. begin
  611. if assigned(ref^.symbol) then
  612. begin
  613. Result:=1+
  614. UlebSize(natural_alignment_for_load_store(opcode))+
  615. 5; { relocation, fixed size = 5 bytes }
  616. end
  617. else
  618. begin
  619. if assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) then
  620. internalerror(2021092018);
  621. Result:=1+
  622. UlebSize(natural_alignment_for_load_store(opcode))+
  623. UlebSize(ref^.offset);
  624. end;
  625. end;
  626. top_const:
  627. begin
  628. Result:=1+
  629. UlebSize(natural_alignment_for_load_store(opcode))+
  630. UlebSize(val);
  631. end;
  632. else
  633. internalerror(2021092017);
  634. end;
  635. end;
  636. a_call:
  637. begin
  638. if ops<>1 then
  639. internalerror(2021092021);
  640. with oper[0]^ do
  641. case typ of
  642. top_ref:
  643. begin
  644. if not assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) or (ref^.offset<>0) then
  645. internalerror(2021092023);
  646. result:=6;
  647. end;
  648. else
  649. internalerror(2021092022);
  650. end;
  651. end;
  652. a_call_indirect:
  653. begin
  654. if ops<>1 then
  655. internalerror(2021092610);
  656. with oper[0]^ do
  657. case typ of
  658. top_functype:
  659. begin
  660. TWasmObjData(objdata).AddFuncType(functype);
  661. result:=6+
  662. UlebSize(0);
  663. end;
  664. else
  665. internalerror(2021092611);
  666. end;
  667. end;
  668. a_br,
  669. a_br_if,
  670. a_rethrow,
  671. a_delegate:
  672. begin
  673. if ops<>1 then
  674. internalerror(2021092610);
  675. with oper[0]^ do
  676. case typ of
  677. top_const:
  678. result:=1+
  679. UlebSize(val);
  680. else
  681. internalerror(2021092625);
  682. end;
  683. end;
  684. a_catch,
  685. a_throw:
  686. begin
  687. if ops<>1 then
  688. internalerror(2021092709);
  689. with oper[0]^ do
  690. case typ of
  691. top_ref:
  692. begin
  693. if not assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) or (ref^.offset<>0) then
  694. internalerror(2021092711);
  695. result:=6;
  696. end;
  697. else
  698. internalerror(2021092710);
  699. end;
  700. end;
  701. else
  702. internalerror(2021092623);
  703. end;
  704. end;
  705. procedure taicpu.Pass2(objdata: TObjData);
  706. procedure WriteByte(b: byte);
  707. begin
  708. objdata.writebytes(b,1);
  709. end;
  710. {$ifdef FPC_LITTLE_ENDIAN}
  711. procedure WriteSingle(s: single);
  712. begin
  713. objdata.writebytes(s,4);
  714. end;
  715. procedure WriteDouble(d: double);
  716. begin
  717. objdata.writebytes(d,8);
  718. end;
  719. {$else FPC_LITTLE_ENDIAN}
  720. procedure WriteSingle(s: single);
  721. var
  722. l: longword;
  723. begin
  724. Move(s,l,4);
  725. l:=SwapEndian(l);
  726. objdata.writebytes(l,4);
  727. end;
  728. procedure WriteDouble(d: double);
  729. var
  730. q: qword;
  731. begin
  732. Move(d,q,8);
  733. q:=SwapEndian(q);
  734. objdata.writebytes(q,8);
  735. end;
  736. {$endif FPC_LITTLE_ENDIAN}
  737. procedure WriteSleb(v: tcgint);
  738. var
  739. b: byte;
  740. Done: Boolean=false;
  741. begin
  742. repeat
  743. b:=byte(v) and 127;
  744. v:=SarInt64(v,7);
  745. if ((v=0) and ((b and 64)=0)) or ((v=-1) and ((b and 64)<>0)) then
  746. Done:=true
  747. else
  748. b:=b or 128;
  749. objdata.writebytes(b,1);
  750. until Done;
  751. end;
  752. procedure WriteUleb(v: tcgint);
  753. var
  754. b: byte;
  755. begin
  756. repeat
  757. b:=byte(v) and 127;
  758. v:=v shr 7;
  759. if v<>0 then
  760. b:=b or 128;
  761. objdata.writebytes(b,1);
  762. until v=0;
  763. end;
  764. begin
  765. case opcode of
  766. a_unreachable:
  767. WriteByte($00);
  768. a_nop:
  769. WriteByte($01);
  770. a_return:
  771. WriteByte($0F);
  772. a_drop:
  773. WriteByte($1A);
  774. a_memory_size:
  775. begin
  776. WriteByte($3F);
  777. WriteByte($00);
  778. end;
  779. a_memory_grow:
  780. begin
  781. WriteByte($40);
  782. WriteByte($00);
  783. end;
  784. a_memory_copy:
  785. begin
  786. WriteByte($FC);
  787. WriteUleb(10);
  788. WriteByte($00);
  789. WriteByte($00);
  790. end;
  791. a_memory_fill:
  792. begin
  793. WriteByte($FC);
  794. WriteUleb(11);
  795. WriteByte($00);
  796. end;
  797. a_atomic_fence:
  798. begin
  799. WriteByte($FE);
  800. WriteByte($03);
  801. WriteByte($00);
  802. end;
  803. a_i32_eqz:
  804. WriteByte($45);
  805. a_i32_eq:
  806. WriteByte($46);
  807. a_i32_ne:
  808. WriteByte($47);
  809. a_i32_lt_s:
  810. WriteByte($48);
  811. a_i32_lt_u:
  812. WriteByte($49);
  813. a_i32_gt_s:
  814. WriteByte($4A);
  815. a_i32_gt_u:
  816. WriteByte($4B);
  817. a_i32_le_s:
  818. WriteByte($4C);
  819. a_i32_le_u:
  820. WriteByte($4D);
  821. a_i32_ge_s:
  822. WriteByte($4E);
  823. a_i32_ge_u:
  824. WriteByte($4F);
  825. a_i64_eqz:
  826. WriteByte($50);
  827. a_i64_eq:
  828. WriteByte($51);
  829. a_i64_ne:
  830. WriteByte($52);
  831. a_i64_lt_s:
  832. WriteByte($53);
  833. a_i64_lt_u:
  834. WriteByte($54);
  835. a_i64_gt_s:
  836. WriteByte($55);
  837. a_i64_gt_u:
  838. WriteByte($56);
  839. a_i64_le_s:
  840. WriteByte($57);
  841. a_i64_le_u:
  842. WriteByte($58);
  843. a_i64_ge_s:
  844. WriteByte($59);
  845. a_i64_ge_u:
  846. WriteByte($5A);
  847. a_f32_eq:
  848. WriteByte($5B);
  849. a_f32_ne:
  850. WriteByte($5C);
  851. a_f32_lt:
  852. WriteByte($5D);
  853. a_f32_gt:
  854. WriteByte($5E);
  855. a_f32_le:
  856. WriteByte($5F);
  857. a_f32_ge:
  858. WriteByte($60);
  859. a_f64_eq:
  860. WriteByte($61);
  861. a_f64_ne:
  862. WriteByte($62);
  863. a_f64_lt:
  864. WriteByte($63);
  865. a_f64_gt:
  866. WriteByte($64);
  867. a_f64_le:
  868. WriteByte($65);
  869. a_f64_ge:
  870. WriteByte($66);
  871. a_i32_clz:
  872. WriteByte($67);
  873. a_i32_ctz:
  874. WriteByte($68);
  875. a_i32_popcnt:
  876. WriteByte($69);
  877. a_i32_add:
  878. WriteByte($6A);
  879. a_i32_sub:
  880. WriteByte($6B);
  881. a_i32_mul:
  882. WriteByte($6C);
  883. a_i32_div_s:
  884. WriteByte($6D);
  885. a_i32_div_u:
  886. WriteByte($6E);
  887. a_i32_rem_s:
  888. WriteByte($6F);
  889. a_i32_rem_u:
  890. WriteByte($70);
  891. a_i32_and:
  892. WriteByte($71);
  893. a_i32_or:
  894. WriteByte($72);
  895. a_i32_xor:
  896. WriteByte($73);
  897. a_i32_shl:
  898. WriteByte($74);
  899. a_i32_shr_s:
  900. WriteByte($75);
  901. a_i32_shr_u:
  902. WriteByte($76);
  903. a_i32_rotl:
  904. WriteByte($77);
  905. a_i32_rotr:
  906. WriteByte($78);
  907. a_i64_clz:
  908. WriteByte($79);
  909. a_i64_ctz:
  910. WriteByte($7A);
  911. a_i64_popcnt:
  912. WriteByte($7B);
  913. a_i64_add:
  914. WriteByte($7C);
  915. a_i64_sub:
  916. WriteByte($7D);
  917. a_i64_mul:
  918. WriteByte($7E);
  919. a_i64_div_s:
  920. WriteByte($7F);
  921. a_i64_div_u:
  922. WriteByte($80);
  923. a_i64_rem_s:
  924. WriteByte($81);
  925. a_i64_rem_u:
  926. WriteByte($82);
  927. a_i64_and:
  928. WriteByte($83);
  929. a_i64_or:
  930. WriteByte($84);
  931. a_i64_xor:
  932. WriteByte($85);
  933. a_i64_shl:
  934. WriteByte($86);
  935. a_i64_shr_s:
  936. WriteByte($87);
  937. a_i64_shr_u:
  938. WriteByte($88);
  939. a_i64_rotl:
  940. WriteByte($89);
  941. a_i64_rotr:
  942. WriteByte($8A);
  943. a_f32_abs:
  944. WriteByte($8B);
  945. a_f32_neg:
  946. WriteByte($8C);
  947. a_f32_ceil:
  948. WriteByte($8D);
  949. a_f32_floor:
  950. WriteByte($8E);
  951. a_f32_trunc:
  952. WriteByte($8F);
  953. a_f32_nearest:
  954. WriteByte($90);
  955. a_f32_sqrt:
  956. WriteByte($91);
  957. a_f32_add:
  958. WriteByte($92);
  959. a_f32_sub:
  960. WriteByte($93);
  961. a_f32_mul:
  962. WriteByte($94);
  963. a_f32_div:
  964. WriteByte($95);
  965. a_f32_min:
  966. WriteByte($96);
  967. a_f32_max:
  968. WriteByte($97);
  969. a_f32_copysign:
  970. WriteByte($98);
  971. a_f64_abs:
  972. WriteByte($99);
  973. a_f64_neg:
  974. WriteByte($9A);
  975. a_f64_ceil:
  976. WriteByte($9B);
  977. a_f64_floor:
  978. WriteByte($9C);
  979. a_f64_trunc:
  980. WriteByte($9D);
  981. a_f64_nearest:
  982. WriteByte($9E);
  983. a_f64_sqrt:
  984. WriteByte($9F);
  985. a_f64_add:
  986. WriteByte($A0);
  987. a_f64_sub:
  988. WriteByte($A1);
  989. a_f64_mul:
  990. WriteByte($A2);
  991. a_f64_div:
  992. WriteByte($A3);
  993. a_f64_min:
  994. WriteByte($A4);
  995. a_f64_max:
  996. WriteByte($A5);
  997. a_f64_copysign:
  998. WriteByte($A6);
  999. a_i32_wrap_i64:
  1000. WriteByte($A7);
  1001. a_i32_trunc_f32_s:
  1002. WriteByte($A8);
  1003. a_i32_trunc_f32_u:
  1004. WriteByte($A9);
  1005. a_i32_trunc_f64_s:
  1006. WriteByte($AA);
  1007. a_i32_trunc_f64_u:
  1008. WriteByte($AB);
  1009. a_i64_extend_i32_s:
  1010. WriteByte($AC);
  1011. a_i64_extend_i32_u:
  1012. WriteByte($AD);
  1013. a_i64_trunc_f32_s:
  1014. WriteByte($AE);
  1015. a_i64_trunc_f32_u:
  1016. WriteByte($AF);
  1017. a_i64_trunc_f64_s:
  1018. WriteByte($B0);
  1019. a_i64_trunc_f64_u:
  1020. WriteByte($B1);
  1021. a_f32_convert_i32_s:
  1022. WriteByte($B2);
  1023. a_f32_convert_i32_u:
  1024. WriteByte($B3);
  1025. a_f32_convert_i64_s:
  1026. WriteByte($B4);
  1027. a_f32_convert_i64_u:
  1028. WriteByte($B5);
  1029. a_f32_demote_f64:
  1030. WriteByte($B6);
  1031. a_f64_convert_i32_s:
  1032. WriteByte($B7);
  1033. a_f64_convert_i32_u:
  1034. WriteByte($B8);
  1035. a_f64_convert_i64_s:
  1036. WriteByte($B9);
  1037. a_f64_convert_i64_u:
  1038. WriteByte($BA);
  1039. a_f64_promote_f32:
  1040. WriteByte($BB);
  1041. a_i32_reinterpret_f32:
  1042. WriteByte($BC);
  1043. a_i64_reinterpret_f64:
  1044. WriteByte($BD);
  1045. a_f32_reinterpret_i32:
  1046. WriteByte($BE);
  1047. a_f64_reinterpret_i64:
  1048. WriteByte($BF);
  1049. a_i32_extend8_s:
  1050. WriteByte($C0);
  1051. a_i32_extend16_s:
  1052. WriteByte($C1);
  1053. a_i64_extend8_s:
  1054. WriteByte($C2);
  1055. a_i64_extend16_s:
  1056. WriteByte($C3);
  1057. a_i64_extend32_s:
  1058. WriteByte($C4);
  1059. a_end_block,
  1060. a_end_if,
  1061. a_end_loop,
  1062. a_end_try:
  1063. WriteByte($0B);
  1064. a_catch_all:
  1065. WriteByte($19);
  1066. a_i32_const:
  1067. begin
  1068. WriteByte($41);
  1069. if ops<>1 then
  1070. internalerror(2021092001);
  1071. with oper[0]^ do
  1072. case typ of
  1073. top_ref:
  1074. begin
  1075. if assigned(ref^.symbol) then
  1076. objdata.writeReloc(ref^.offset,5,ObjData.symbolref(ref^.symbol),RELOC_MEMORY_ADDR_OR_TABLE_INDEX_SLEB)
  1077. else
  1078. begin
  1079. if assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) then
  1080. internalerror(2021092018);
  1081. WriteSleb(longint(ref^.offset));
  1082. end;
  1083. end;
  1084. top_const:
  1085. WriteSleb(longint(val));
  1086. else
  1087. internalerror(2021092615);
  1088. end;
  1089. end;
  1090. a_i64_const:
  1091. begin
  1092. WriteByte($42);
  1093. if ops<>1 then
  1094. internalerror(2021092001);
  1095. with oper[0]^ do
  1096. case typ of
  1097. top_ref:
  1098. begin
  1099. if assigned(ref^.symbol) then
  1100. objdata.writeReloc(ref^.offset,5,ObjData.symbolref(ref^.symbol),RELOC_MEMORY_ADDR_OR_TABLE_INDEX_SLEB)
  1101. else
  1102. begin
  1103. if assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) then
  1104. internalerror(2021092018);
  1105. WriteSleb(int64(ref^.offset));
  1106. end;
  1107. end;
  1108. top_const:
  1109. WriteSleb(int64(val));
  1110. else
  1111. internalerror(2021092615);
  1112. end;
  1113. end;
  1114. a_f32_const:
  1115. begin
  1116. if ops<>1 then
  1117. internalerror(2021092619);
  1118. WriteByte($43);
  1119. with oper[0]^ do
  1120. case typ of
  1121. top_single:
  1122. WriteSingle(sval);
  1123. else
  1124. internalerror(2021092618);
  1125. end;
  1126. end;
  1127. a_f64_const:
  1128. begin
  1129. if ops<>1 then
  1130. internalerror(2021092616);
  1131. WriteByte($44);
  1132. with oper[0]^ do
  1133. case typ of
  1134. top_double:
  1135. WriteDouble(dval);
  1136. else
  1137. internalerror(2021092617);
  1138. end;
  1139. end;
  1140. a_local_get,
  1141. a_local_set,
  1142. a_local_tee:
  1143. begin
  1144. case opcode of
  1145. a_local_get:
  1146. WriteByte($20);
  1147. a_local_set:
  1148. WriteByte($21);
  1149. a_local_tee:
  1150. WriteByte($22);
  1151. else
  1152. internalerror(2021092003);
  1153. end;
  1154. if ops<>1 then
  1155. internalerror(2021092004);
  1156. with oper[0]^ do
  1157. case typ of
  1158. top_ref:
  1159. begin
  1160. if assigned(ref^.symbol) then
  1161. internalerror(2021092005);
  1162. if ref^.base<>NR_STACK_POINTER_REG then
  1163. internalerror(2021092006);
  1164. if ref^.index<>NR_NO then
  1165. internalerror(2021092007);
  1166. WriteUleb(ref^.offset);
  1167. end;
  1168. else
  1169. internalerror(2021092008);
  1170. end;
  1171. end;
  1172. a_global_get,
  1173. a_global_set:
  1174. begin
  1175. case opcode of
  1176. a_global_get:
  1177. WriteByte($23);
  1178. a_global_set:
  1179. WriteByte($24);
  1180. else
  1181. internalerror(2021092009);
  1182. end;
  1183. if ops<>1 then
  1184. internalerror(2021092010);
  1185. with oper[0]^ do
  1186. case typ of
  1187. top_ref:
  1188. begin
  1189. if not assigned(ref^.symbol) then
  1190. internalerror(2021092012);
  1191. if (ref^.base<>NR_NO) or (ref^.index<>NR_NO) or (ref^.offset<>0) then
  1192. internalerror(2021092013);
  1193. objdata.writeReloc(0,5,TWasmObjData(ObjData).globalref(ref^.symbol),RELOC_GLOBAL_INDEX_LEB);
  1194. end;
  1195. else
  1196. internalerror(2021092011);
  1197. end;
  1198. end;
  1199. a_end_function:
  1200. ;
  1201. a_block,
  1202. a_loop,
  1203. a_if,
  1204. a_try:
  1205. begin
  1206. case opcode of
  1207. a_block:
  1208. WriteByte($02);
  1209. a_loop:
  1210. WriteByte($03);
  1211. a_if:
  1212. WriteByte($04);
  1213. a_try:
  1214. WriteByte($06);
  1215. else
  1216. internalerror(2021092626);
  1217. end;
  1218. if ops=0 then
  1219. WriteByte($40)
  1220. else
  1221. begin
  1222. if ops<>1 then
  1223. internalerror(2021092015);
  1224. with oper[0]^ do
  1225. case typ of
  1226. top_functype:
  1227. begin
  1228. if (length(functype.params)=0) and (length(functype.results)<=1) then
  1229. begin
  1230. if length(functype.results)=1 then
  1231. WriteByte(encode_wasm_basic_type(functype.results[0]))
  1232. else
  1233. WriteByte($40);
  1234. end
  1235. else
  1236. { more complex blocktypes are not yet implemented }
  1237. internalerror(2021092621);
  1238. end;
  1239. else
  1240. internalerror(2021092620);
  1241. end;
  1242. end;
  1243. end;
  1244. a_else:
  1245. WriteByte($05);
  1246. a_i32_load,
  1247. a_i64_load,
  1248. a_f32_load,
  1249. a_f64_load,
  1250. a_i32_load8_s,
  1251. a_i32_load8_u,
  1252. a_i32_load16_s,
  1253. a_i32_load16_u,
  1254. a_i64_load8_s,
  1255. a_i64_load8_u,
  1256. a_i64_load16_s,
  1257. a_i64_load16_u,
  1258. a_i64_load32_s,
  1259. a_i64_load32_u,
  1260. a_i32_store,
  1261. a_i64_store,
  1262. a_f32_store,
  1263. a_f64_store,
  1264. a_i32_store8,
  1265. a_i32_store16,
  1266. a_i64_store8,
  1267. a_i64_store16,
  1268. a_i64_store32:
  1269. begin
  1270. case opcode of
  1271. a_i32_load:
  1272. WriteByte($28);
  1273. a_i64_load:
  1274. WriteByte($29);
  1275. a_f32_load:
  1276. WriteByte($2A);
  1277. a_f64_load:
  1278. WriteByte($2B);
  1279. a_i32_load8_s:
  1280. WriteByte($2C);
  1281. a_i32_load8_u:
  1282. WriteByte($2D);
  1283. a_i32_load16_s:
  1284. WriteByte($2E);
  1285. a_i32_load16_u:
  1286. WriteByte($2F);
  1287. a_i64_load8_s:
  1288. WriteByte($30);
  1289. a_i64_load8_u:
  1290. WriteByte($31);
  1291. a_i64_load16_s:
  1292. WriteByte($32);
  1293. a_i64_load16_u:
  1294. WriteByte($33);
  1295. a_i64_load32_s:
  1296. WriteByte($34);
  1297. a_i64_load32_u:
  1298. WriteByte($35);
  1299. a_i32_store:
  1300. WriteByte($36);
  1301. a_i64_store:
  1302. WriteByte($37);
  1303. a_f32_store:
  1304. WriteByte($38);
  1305. a_f64_store:
  1306. WriteByte($39);
  1307. a_i32_store8:
  1308. WriteByte($3A);
  1309. a_i32_store16:
  1310. WriteByte($3B);
  1311. a_i64_store8:
  1312. WriteByte($3C);
  1313. a_i64_store16:
  1314. WriteByte($3D);
  1315. a_i64_store32:
  1316. WriteByte($3E);
  1317. else
  1318. internalerror(2021092019);
  1319. end;
  1320. if ops<>1 then
  1321. internalerror(2021092016);
  1322. with oper[0]^ do
  1323. case typ of
  1324. top_ref:
  1325. begin
  1326. if assigned(ref^.symbol) then
  1327. begin
  1328. WriteUleb(natural_alignment_for_load_store(opcode));
  1329. objdata.writeReloc(ref^.offset,5,ObjData.symbolref(ref^.symbol),RELOC_MEMORY_ADDR_LEB);
  1330. end
  1331. else
  1332. begin
  1333. if assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) then
  1334. internalerror(2021092018);
  1335. WriteUleb(natural_alignment_for_load_store(opcode));
  1336. WriteUleb(ref^.offset);
  1337. end;
  1338. end;
  1339. top_const:
  1340. begin
  1341. WriteUleb(natural_alignment_for_load_store(opcode));
  1342. WriteUleb(val);
  1343. end;
  1344. else
  1345. internalerror(2021092017);
  1346. end;
  1347. end;
  1348. a_call:
  1349. begin
  1350. if ops<>1 then
  1351. internalerror(2021092021);
  1352. with oper[0]^ do
  1353. case typ of
  1354. top_ref:
  1355. begin
  1356. if not assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) or (ref^.offset<>0) then
  1357. internalerror(2021092023);
  1358. WriteByte($10);
  1359. objdata.writeReloc(0,5,ObjData.symbolref(ref^.symbol),RELOC_FUNCTION_INDEX_LEB);
  1360. end;
  1361. else
  1362. internalerror(2021092022);
  1363. end;
  1364. end;
  1365. a_call_indirect:
  1366. begin
  1367. if ops<>1 then
  1368. internalerror(2021092610);
  1369. with oper[0]^ do
  1370. case typ of
  1371. top_functype:
  1372. begin
  1373. WriteByte($11);
  1374. objdata.writeReloc(TWasmObjData(objdata).AddFuncType(functype),5,nil,RELOC_TYPE_INDEX_LEB);
  1375. WriteUleb(0);
  1376. end;
  1377. else
  1378. internalerror(2021092611);
  1379. end;
  1380. end;
  1381. a_br,
  1382. a_br_if,
  1383. a_rethrow,
  1384. a_delegate:
  1385. begin
  1386. case opcode of
  1387. a_br:
  1388. WriteByte($0C);
  1389. a_br_if:
  1390. WriteByte($0D);
  1391. a_rethrow:
  1392. WriteByte($09);
  1393. a_delegate:
  1394. WriteByte($18);
  1395. else
  1396. internalerror(2021092622);
  1397. end;
  1398. if ops<>1 then
  1399. internalerror(2021092610);
  1400. with oper[0]^ do
  1401. case typ of
  1402. top_const:
  1403. WriteUleb(val);
  1404. else
  1405. internalerror(2021092625);
  1406. end;
  1407. end;
  1408. a_catch,
  1409. a_throw:
  1410. begin
  1411. case opcode of
  1412. a_catch:
  1413. WriteByte($07);
  1414. a_throw:
  1415. WriteByte($08);
  1416. else
  1417. internalerror(2021092708);
  1418. end;
  1419. if ops<>1 then
  1420. internalerror(2021092709);
  1421. with oper[0]^ do
  1422. case typ of
  1423. top_ref:
  1424. begin
  1425. if not assigned(ref^.symbol) or (ref^.base<>NR_NO) or (ref^.index<>NR_NO) or (ref^.offset<>0) then
  1426. internalerror(2021092711);
  1427. objdata.writeReloc(0,5,TWasmObjData(ObjData).ExceptionTagRef(ref^.symbol),RELOC_TAG_INDEX_LEB);
  1428. end;
  1429. else
  1430. internalerror(2021092710);
  1431. end;
  1432. end;
  1433. else
  1434. internalerror(2021092624);
  1435. end;
  1436. end;
  1437. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  1438. begin
  1439. internalerror(2010122614);
  1440. result:=nil;
  1441. end;
  1442. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  1443. begin
  1444. internalerror(2010122615);
  1445. result:=nil;
  1446. end;
  1447. procedure InitAsm;
  1448. begin
  1449. end;
  1450. procedure DoneAsm;
  1451. begin
  1452. end;
  1453. initialization
  1454. cai_cpu:=taicpu;
  1455. cai_align:=tai_align;
  1456. end.