aasmcpu.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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. // the actual use is defined by the assembly section used
  64. { timpexp_ai }
  65. tai_impexp = class(tai)
  66. extname : ansistring; // external name
  67. intname : ansistring; // internal name
  68. extmodule : ansistring; // external unit name
  69. symstype: TImpExpType;
  70. constructor create(const aextname, aintname: ansistring; asymtype: timpexptype); overload;
  71. constructor create(const aextmodule, aextname, aintname: ansistring; asymtype: timpexptype); overload;
  72. end;
  73. // local variable declaration
  74. { tai_local }
  75. tai_local = class(tai)
  76. bastyp: TWasmBasicType;
  77. name : string;
  78. first: boolean;
  79. last: boolean;
  80. constructor create(abasictype: TWasmBasicType; const aname: string = '');
  81. end;
  82. { tai_functype }
  83. tai_functype = class(tai)
  84. funcname: string;
  85. functype: TWasmFuncType;
  86. constructor create(const afuncname: string; afunctype: TWasmFuncType);
  87. destructor destroy;override;
  88. end;
  89. { tai_tagtype }
  90. tai_tagtype = class(tai)
  91. tagname: string;
  92. params: TWasmResultType;
  93. constructor create(const atagname: string; aparams: TWasmResultType);
  94. end;
  95. procedure InitAsm;
  96. procedure DoneAsm;
  97. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  98. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  99. implementation
  100. { tai_functype }
  101. constructor tai_functype.create(const afuncname: string; afunctype: TWasmFuncType);
  102. begin
  103. inherited Create;
  104. typ:=ait_functype;
  105. funcname:=afuncname;
  106. functype:=afunctype;
  107. end;
  108. destructor tai_functype.destroy;
  109. begin
  110. functype.free;
  111. inherited;
  112. end;
  113. { tai_tagtype }
  114. constructor tai_tagtype.create(const atagname: string; aparams: TWasmResultType);
  115. begin
  116. typ:=ait_tagtype;
  117. tagname:=atagname;
  118. params:=aparams;
  119. end;
  120. { tai_local }
  121. constructor tai_local.create(abasictype: TWasmBasicType; const aname: string);
  122. begin
  123. inherited Create;
  124. bastyp := abasictype;
  125. typ := ait_local;
  126. name := aname;
  127. end;
  128. { timpexp_ai }
  129. constructor tai_impexp.create(const aextname, aintname: ansistring;
  130. asymtype: timpexptype);
  131. begin
  132. create('', aextname, aintname, asymtype);;
  133. end;
  134. constructor tai_impexp.create(const aextmodule, aextname, aintname: ansistring; asymtype: timpexptype);
  135. begin
  136. inherited create;
  137. typ := ait_importexport;
  138. extmodule := aextmodule;
  139. extname := aextname;
  140. intname := aintname;
  141. symstype:= asymtype;
  142. end;
  143. {*****************************************************************************
  144. taicpu Constructors
  145. *****************************************************************************}
  146. constructor taicpu.op_none(op : tasmop);
  147. begin
  148. inherited create(op);
  149. end;
  150. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  151. begin
  152. inherited create(op);
  153. ops:=1;
  154. {$ifdef EXTDEBUG}
  155. if getregtype(_op1)=R_INVALIDREGISTER then
  156. InternalError(2021011901);
  157. {$endif EXTDEBUG}
  158. loadreg(0,_op1);
  159. end;
  160. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  161. begin
  162. inherited create(op);
  163. ops:=1;
  164. loadref(0,_op1);
  165. if op in [a_local_get,a_local_set,a_local_tee] then
  166. begin
  167. if (_op1.base<>NR_LOCAL_STACK_POINTER_REG) or (_op1.index<>NR_NO) then
  168. internalerror(2021010201);
  169. end
  170. else
  171. begin
  172. if (_op1.base<>NR_NO) or (_op1.index<>NR_NO) then
  173. internalerror(2021010202);
  174. end;
  175. end;
  176. constructor taicpu.op_const(op : tasmop;_op1 : aint);
  177. begin
  178. inherited create(op);
  179. ops:=1;
  180. loadconst(0,_op1);
  181. end;
  182. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  183. begin
  184. inherited create(op);
  185. ops:=1;
  186. loadsymbol(0,_op1,0);
  187. end;
  188. constructor taicpu.op_sym_const(op: tasmop; _op1: tasmsymbol; _op2: aint);
  189. begin
  190. inherited create(op);
  191. ops:=2;
  192. loadsymbol(0,_op1,0);
  193. loadconst(1,_op2);
  194. end;
  195. constructor taicpu.op_single(op: tasmop; _op1: single);
  196. begin
  197. inherited create(op);
  198. ops:=1;
  199. loadsingle(0,_op1);
  200. end;
  201. constructor taicpu.op_double(op: tasmop; _op1: double);
  202. begin
  203. inherited create(op);
  204. ops:=1;
  205. loaddouble(0,_op1);
  206. end;
  207. constructor taicpu.op_functype(op: tasmop; _op1: TWasmFuncType);
  208. begin
  209. inherited create(op);
  210. ops:=1;
  211. loadfunctype(0,_op1);
  212. end;
  213. procedure taicpu.loadfunctype(opidx: longint; ft: TWasmFuncType);
  214. begin
  215. allocate_oper(opidx+1);
  216. with oper[opidx]^ do
  217. begin
  218. if typ<>top_functype then
  219. clearop(opidx);
  220. functype:=ft;
  221. typ:=top_functype;
  222. end;
  223. end;
  224. procedure taicpu.loadsingle(opidx:longint;f:single);
  225. begin
  226. allocate_oper(opidx+1);
  227. with oper[opidx]^ do
  228. begin
  229. if typ<>top_single then
  230. clearop(opidx);
  231. sval:=f;
  232. typ:=top_single;
  233. end;
  234. end;
  235. procedure taicpu.loaddouble(opidx: longint; d: double);
  236. begin
  237. allocate_oper(opidx+1);
  238. with oper[opidx]^ do
  239. begin
  240. if typ<>top_double then
  241. clearop(opidx);
  242. dval:=d;
  243. typ:=top_double;
  244. end;
  245. end;
  246. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  247. begin
  248. result:=false;
  249. end;
  250. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  251. begin
  252. if opcode in AsmOp_Store then
  253. result:=operand_write
  254. else
  255. result:=operand_read;
  256. end;
  257. function taicpu.Pass1(objdata: TObjData): longint;
  258. function SlebSize(v: tcgint): longint;
  259. begin
  260. result:=0;
  261. repeat
  262. v:=SarInt64(v,7);
  263. Inc(result);
  264. until ((v=0) and ((byte(v) and 64)=0)) or ((v=-1) and ((byte(v) and 64)<>0));
  265. end;
  266. function UlebSize(v: tcgint): longint;
  267. begin
  268. result:=0;
  269. repeat
  270. v:=v shr 7;
  271. Inc(result);
  272. until v=0;
  273. end;
  274. begin
  275. result:=0;
  276. case opcode of
  277. a_unreachable,
  278. a_nop,
  279. a_return,
  280. a_drop,
  281. a_i32_eqz,
  282. a_i32_eq,
  283. a_i32_ne,
  284. a_i32_lt_s,
  285. a_i32_lt_u,
  286. a_i32_gt_s,
  287. a_i32_gt_u,
  288. a_i32_le_s,
  289. a_i32_le_u,
  290. a_i32_ge_s,
  291. a_i32_ge_u,
  292. a_i64_eqz,
  293. a_i64_eq,
  294. a_i64_ne,
  295. a_i64_lt_s,
  296. a_i64_lt_u,
  297. a_i64_gt_s,
  298. a_i64_gt_u,
  299. a_i64_le_s,
  300. a_i64_le_u,
  301. a_i64_ge_s,
  302. a_i64_ge_u,
  303. a_f32_eq,
  304. a_f32_ne,
  305. a_f32_lt,
  306. a_f32_gt,
  307. a_f32_le,
  308. a_f32_ge,
  309. a_f64_eq,
  310. a_f64_ne,
  311. a_f64_lt,
  312. a_f64_gt,
  313. a_f64_le,
  314. a_f64_ge,
  315. a_i32_clz,
  316. a_i32_ctz,
  317. a_i32_popcnt,
  318. a_i32_add,
  319. a_i32_sub,
  320. a_i32_mul,
  321. a_i32_div_s,
  322. a_i32_div_u,
  323. a_i32_rem_s,
  324. a_i32_rem_u,
  325. a_i32_and,
  326. a_i32_or,
  327. a_i32_xor,
  328. a_i32_shl,
  329. a_i32_shr_s,
  330. a_i32_shr_u,
  331. a_i32_rotl,
  332. a_i32_rotr,
  333. a_i64_clz,
  334. a_i64_ctz,
  335. a_i64_popcnt,
  336. a_i64_add,
  337. a_i64_sub,
  338. a_i64_mul,
  339. a_i64_div_s,
  340. a_i64_div_u,
  341. a_i64_rem_s,
  342. a_i64_rem_u,
  343. a_i64_and,
  344. a_i64_or,
  345. a_i64_xor,
  346. a_i64_shl,
  347. a_i64_shr_s,
  348. a_i64_shr_u,
  349. a_i64_rotl,
  350. a_i64_rotr,
  351. a_f32_abs,
  352. a_f32_neg,
  353. a_f32_ceil,
  354. a_f32_floor,
  355. a_f32_trunc,
  356. a_f32_nearest,
  357. a_f32_sqrt,
  358. a_f32_add,
  359. a_f32_sub,
  360. a_f32_mul,
  361. a_f32_div,
  362. a_f32_min,
  363. a_f32_max,
  364. a_f32_copysign,
  365. a_f64_abs,
  366. a_f64_neg,
  367. a_f64_ceil,
  368. a_f64_floor,
  369. a_f64_trunc,
  370. a_f64_nearest,
  371. a_f64_sqrt,
  372. a_f64_add,
  373. a_f64_sub,
  374. a_f64_mul,
  375. a_f64_div,
  376. a_f64_min,
  377. a_f64_max,
  378. a_f64_copysign,
  379. a_i32_wrap_i64,
  380. a_i32_trunc_f32_s,
  381. a_i32_trunc_f32_u,
  382. a_i32_trunc_f64_s,
  383. a_i32_trunc_f64_u,
  384. a_i64_extend_i32_s,
  385. a_i64_extend_i32_u,
  386. a_i64_trunc_f32_s,
  387. a_i64_trunc_f32_u,
  388. a_i64_trunc_f64_s,
  389. a_i64_trunc_f64_u,
  390. a_f32_convert_i32_s,
  391. a_f32_convert_i32_u,
  392. a_f32_convert_i64_s,
  393. a_f32_convert_i64_u,
  394. a_f32_demote_f64,
  395. a_f64_convert_i32_s,
  396. a_f64_convert_i32_u,
  397. a_f64_convert_i64_s,
  398. a_f64_convert_i64_u,
  399. a_f64_promote_f32,
  400. a_i32_reinterpret_f32,
  401. a_i64_reinterpret_f64,
  402. a_f32_reinterpret_i32,
  403. a_f64_reinterpret_i64,
  404. a_i32_extend8_s,
  405. a_i32_extend16_s,
  406. a_i64_extend8_s,
  407. a_i64_extend16_s,
  408. a_i64_extend32_s,
  409. a_end_block,
  410. a_end_if,
  411. a_end_loop,
  412. a_end_try,
  413. a_catch_all:
  414. result:=1;
  415. a_memory_size,
  416. a_memory_grow:
  417. result:=2;
  418. a_i32_const,
  419. a_i64_const:
  420. begin
  421. if ops<>1 then
  422. internalerror(2021092001);
  423. case oper[0]^.typ of
  424. top_const:
  425. result:=1+SlebSize(oper[0]^.val);
  426. else
  427. Writeln('Warning! Not implemented opcode, pass1: ', opcode, ' ', oper[0]^.typ);
  428. end;
  429. end;
  430. a_local_get,
  431. a_local_set,
  432. a_local_tee:
  433. begin
  434. if ops<>1 then
  435. internalerror(2021092001);
  436. with oper[0]^ do
  437. case typ of
  438. top_ref:
  439. begin
  440. if assigned(ref^.symbol) then
  441. internalerror(2021092005);
  442. if ref^.base<>NR_STACK_POINTER_REG then
  443. internalerror(2021092006);
  444. if ref^.index<>NR_NO then
  445. internalerror(2021092007);
  446. result:=1+UlebSize(ref^.offset);
  447. end;
  448. else
  449. internalerror(2021092008);
  450. end;
  451. end;
  452. else
  453. Writeln('Warning! Not implemented opcode, pass1: ', opcode);
  454. end;
  455. end;
  456. procedure taicpu.Pass2(objdata: TObjData);
  457. procedure WriteByte(b: byte);
  458. begin
  459. objdata.writebytes(b,1);
  460. end;
  461. procedure WriteSleb(v: tcgint);
  462. var
  463. b: byte;
  464. Done: Boolean=false;
  465. begin
  466. repeat
  467. b:=byte(v) and 127;
  468. v:=SarInt64(v,7);
  469. if ((v=0) and ((b and 64)=0)) or ((v=-1) and ((b and 64)<>0)) then
  470. Done:=true
  471. else
  472. b:=b or 128;
  473. objdata.writebytes(b,1);
  474. until Done;
  475. end;
  476. procedure WriteUleb(v: tcgint);
  477. var
  478. b: byte;
  479. begin
  480. repeat
  481. b:=byte(v) and 127;
  482. v:=v shr 7;
  483. if v<>0 then
  484. b:=b or 128;
  485. objdata.writebytes(b,1);
  486. until v=0;
  487. end;
  488. begin
  489. case opcode of
  490. a_unreachable:
  491. WriteByte($00);
  492. a_nop:
  493. WriteByte($01);
  494. a_return:
  495. WriteByte($0F);
  496. a_drop:
  497. WriteByte($1A);
  498. a_memory_size:
  499. begin
  500. WriteByte($3F);
  501. WriteByte($00);
  502. end;
  503. a_memory_grow:
  504. begin
  505. WriteByte($40);
  506. WriteByte($00);
  507. end;
  508. a_i32_eqz:
  509. WriteByte($45);
  510. a_i32_eq:
  511. WriteByte($46);
  512. a_i32_ne:
  513. WriteByte($47);
  514. a_i32_lt_s:
  515. WriteByte($48);
  516. a_i32_lt_u:
  517. WriteByte($49);
  518. a_i32_gt_s:
  519. WriteByte($4A);
  520. a_i32_gt_u:
  521. WriteByte($4B);
  522. a_i32_le_s:
  523. WriteByte($4C);
  524. a_i32_le_u:
  525. WriteByte($4D);
  526. a_i32_ge_s:
  527. WriteByte($4E);
  528. a_i32_ge_u:
  529. WriteByte($4F);
  530. a_i64_eqz:
  531. WriteByte($50);
  532. a_i64_eq:
  533. WriteByte($51);
  534. a_i64_ne:
  535. WriteByte($52);
  536. a_i64_lt_s:
  537. WriteByte($53);
  538. a_i64_lt_u:
  539. WriteByte($54);
  540. a_i64_gt_s:
  541. WriteByte($55);
  542. a_i64_gt_u:
  543. WriteByte($56);
  544. a_i64_le_s:
  545. WriteByte($57);
  546. a_i64_le_u:
  547. WriteByte($58);
  548. a_i64_ge_s:
  549. WriteByte($59);
  550. a_i64_ge_u:
  551. WriteByte($5A);
  552. a_f32_eq:
  553. WriteByte($5B);
  554. a_f32_ne:
  555. WriteByte($5C);
  556. a_f32_lt:
  557. WriteByte($5D);
  558. a_f32_gt:
  559. WriteByte($5E);
  560. a_f32_le:
  561. WriteByte($5F);
  562. a_f32_ge:
  563. WriteByte($60);
  564. a_f64_eq:
  565. WriteByte($61);
  566. a_f64_ne:
  567. WriteByte($62);
  568. a_f64_lt:
  569. WriteByte($63);
  570. a_f64_gt:
  571. WriteByte($64);
  572. a_f64_le:
  573. WriteByte($65);
  574. a_f64_ge:
  575. WriteByte($66);
  576. a_i32_clz:
  577. WriteByte($67);
  578. a_i32_ctz:
  579. WriteByte($68);
  580. a_i32_popcnt:
  581. WriteByte($69);
  582. a_i32_add:
  583. WriteByte($6A);
  584. a_i32_sub:
  585. WriteByte($6B);
  586. a_i32_mul:
  587. WriteByte($6C);
  588. a_i32_div_s:
  589. WriteByte($6D);
  590. a_i32_div_u:
  591. WriteByte($6E);
  592. a_i32_rem_s:
  593. WriteByte($6F);
  594. a_i32_rem_u:
  595. WriteByte($70);
  596. a_i32_and:
  597. WriteByte($71);
  598. a_i32_or:
  599. WriteByte($72);
  600. a_i32_xor:
  601. WriteByte($73);
  602. a_i32_shl:
  603. WriteByte($74);
  604. a_i32_shr_s:
  605. WriteByte($75);
  606. a_i32_shr_u:
  607. WriteByte($76);
  608. a_i32_rotl:
  609. WriteByte($77);
  610. a_i32_rotr:
  611. WriteByte($78);
  612. a_i64_clz:
  613. WriteByte($79);
  614. a_i64_ctz:
  615. WriteByte($7A);
  616. a_i64_popcnt:
  617. WriteByte($7B);
  618. a_i64_add:
  619. WriteByte($7C);
  620. a_i64_sub:
  621. WriteByte($7D);
  622. a_i64_mul:
  623. WriteByte($7E);
  624. a_i64_div_s:
  625. WriteByte($7F);
  626. a_i64_div_u:
  627. WriteByte($80);
  628. a_i64_rem_s:
  629. WriteByte($81);
  630. a_i64_rem_u:
  631. WriteByte($82);
  632. a_i64_and:
  633. WriteByte($83);
  634. a_i64_or:
  635. WriteByte($84);
  636. a_i64_xor:
  637. WriteByte($85);
  638. a_i64_shl:
  639. WriteByte($86);
  640. a_i64_shr_s:
  641. WriteByte($87);
  642. a_i64_shr_u:
  643. WriteByte($88);
  644. a_i64_rotl:
  645. WriteByte($89);
  646. a_i64_rotr:
  647. WriteByte($8A);
  648. a_f32_abs:
  649. WriteByte($8B);
  650. a_f32_neg:
  651. WriteByte($8C);
  652. a_f32_ceil:
  653. WriteByte($8D);
  654. a_f32_floor:
  655. WriteByte($8E);
  656. a_f32_trunc:
  657. WriteByte($8F);
  658. a_f32_nearest:
  659. WriteByte($90);
  660. a_f32_sqrt:
  661. WriteByte($91);
  662. a_f32_add:
  663. WriteByte($92);
  664. a_f32_sub:
  665. WriteByte($93);
  666. a_f32_mul:
  667. WriteByte($94);
  668. a_f32_div:
  669. WriteByte($95);
  670. a_f32_min:
  671. WriteByte($96);
  672. a_f32_max:
  673. WriteByte($97);
  674. a_f32_copysign:
  675. WriteByte($98);
  676. a_f64_abs:
  677. WriteByte($99);
  678. a_f64_neg:
  679. WriteByte($9A);
  680. a_f64_ceil:
  681. WriteByte($9B);
  682. a_f64_floor:
  683. WriteByte($9C);
  684. a_f64_trunc:
  685. WriteByte($9D);
  686. a_f64_nearest:
  687. WriteByte($9E);
  688. a_f64_sqrt:
  689. WriteByte($9F);
  690. a_f64_add:
  691. WriteByte($A0);
  692. a_f64_sub:
  693. WriteByte($A1);
  694. a_f64_mul:
  695. WriteByte($A2);
  696. a_f64_div:
  697. WriteByte($A3);
  698. a_f64_min:
  699. WriteByte($A4);
  700. a_f64_max:
  701. WriteByte($A5);
  702. a_f64_copysign:
  703. WriteByte($A6);
  704. a_i32_wrap_i64:
  705. WriteByte($A7);
  706. a_i32_trunc_f32_s:
  707. WriteByte($A8);
  708. a_i32_trunc_f32_u:
  709. WriteByte($A9);
  710. a_i32_trunc_f64_s:
  711. WriteByte($AA);
  712. a_i32_trunc_f64_u:
  713. WriteByte($AB);
  714. a_i64_extend_i32_s:
  715. WriteByte($AC);
  716. a_i64_extend_i32_u:
  717. WriteByte($AD);
  718. a_i64_trunc_f32_s:
  719. WriteByte($AE);
  720. a_i64_trunc_f32_u:
  721. WriteByte($AF);
  722. a_i64_trunc_f64_s:
  723. WriteByte($B0);
  724. a_i64_trunc_f64_u:
  725. WriteByte($B1);
  726. a_f32_convert_i32_s:
  727. WriteByte($B2);
  728. a_f32_convert_i32_u:
  729. WriteByte($B3);
  730. a_f32_convert_i64_s:
  731. WriteByte($B4);
  732. a_f32_convert_i64_u:
  733. WriteByte($B5);
  734. a_f32_demote_f64:
  735. WriteByte($B6);
  736. a_f64_convert_i32_s:
  737. WriteByte($B7);
  738. a_f64_convert_i32_u:
  739. WriteByte($B8);
  740. a_f64_convert_i64_s:
  741. WriteByte($B9);
  742. a_f64_convert_i64_u:
  743. WriteByte($BA);
  744. a_f64_promote_f32:
  745. WriteByte($BB);
  746. a_i32_reinterpret_f32:
  747. WriteByte($BC);
  748. a_i64_reinterpret_f64:
  749. WriteByte($BD);
  750. a_f32_reinterpret_i32:
  751. WriteByte($BE);
  752. a_f64_reinterpret_i64:
  753. WriteByte($BF);
  754. a_i32_extend8_s:
  755. WriteByte($C0);
  756. a_i32_extend16_s:
  757. WriteByte($C1);
  758. a_i64_extend8_s:
  759. WriteByte($C2);
  760. a_i64_extend16_s:
  761. WriteByte($C3);
  762. a_i64_extend32_s:
  763. WriteByte($C4);
  764. a_end_block,
  765. a_end_if,
  766. a_end_loop,
  767. a_end_try:
  768. WriteByte($0B);
  769. a_catch_all:
  770. WriteByte($19);
  771. a_i32_const,
  772. a_i64_const:
  773. begin
  774. case opcode of
  775. a_i32_const:
  776. WriteByte($41);
  777. a_i64_const:
  778. WriteByte($42);
  779. else
  780. internalerror(2021092002);
  781. end;
  782. if ops<>1 then
  783. internalerror(2021092001);
  784. case oper[0]^.typ of
  785. top_const:
  786. WriteSleb(oper[0]^.val);
  787. else
  788. Writeln('Warning! Not implemented opcode, pass2: ', opcode, ' ', oper[0]^.typ);
  789. end;
  790. end;
  791. a_local_get,
  792. a_local_set,
  793. a_local_tee:
  794. begin
  795. case opcode of
  796. a_local_get:
  797. WriteByte($20);
  798. a_local_set:
  799. WriteByte($21);
  800. a_local_tee:
  801. WriteByte($22);
  802. else
  803. internalerror(2021092003);
  804. end;
  805. if ops<>1 then
  806. internalerror(2021092004);
  807. with oper[0]^ do
  808. case typ of
  809. top_ref:
  810. begin
  811. if assigned(ref^.symbol) then
  812. internalerror(2021092005);
  813. if ref^.base<>NR_STACK_POINTER_REG then
  814. internalerror(2021092006);
  815. if ref^.index<>NR_NO then
  816. internalerror(2021092007);
  817. WriteUleb(ref^.offset);
  818. end;
  819. else
  820. internalerror(2021092008);
  821. end;
  822. end;
  823. else
  824. Writeln('Warning! Not implemented opcode, pass2: ', opcode);
  825. end;
  826. end;
  827. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  828. begin
  829. internalerror(2010122614);
  830. result:=nil;
  831. end;
  832. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  833. begin
  834. internalerror(2010122615);
  835. result:=nil;
  836. end;
  837. procedure InitAsm;
  838. begin
  839. end;
  840. procedure DoneAsm;
  841. begin
  842. end;
  843. initialization
  844. cai_cpu:=taicpu;
  845. cai_align:=tai_align;
  846. casmdata:=TAsmData;
  847. end.