aasmcpu.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  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. with oper[0]^ do
  424. case typ of
  425. top_const:
  426. result:=1+SlebSize(val);
  427. else
  428. Writeln('Warning! Not implemented opcode, pass1: ', opcode, ' ', typ);
  429. end;
  430. end;
  431. a_local_get,
  432. a_local_set,
  433. a_local_tee:
  434. begin
  435. if ops<>1 then
  436. internalerror(2021092001);
  437. with oper[0]^ do
  438. case typ of
  439. top_ref:
  440. begin
  441. if assigned(ref^.symbol) then
  442. internalerror(2021092005);
  443. if ref^.base<>NR_STACK_POINTER_REG then
  444. internalerror(2021092006);
  445. if ref^.index<>NR_NO then
  446. internalerror(2021092007);
  447. result:=1+UlebSize(ref^.offset);
  448. end;
  449. else
  450. internalerror(2021092008);
  451. end;
  452. end;
  453. else
  454. Writeln('Warning! Not implemented opcode, pass1: ', opcode);
  455. end;
  456. end;
  457. procedure taicpu.Pass2(objdata: TObjData);
  458. procedure WriteByte(b: byte);
  459. begin
  460. objdata.writebytes(b,1);
  461. end;
  462. procedure WriteSleb(v: tcgint);
  463. var
  464. b: byte;
  465. Done: Boolean=false;
  466. begin
  467. repeat
  468. b:=byte(v) and 127;
  469. v:=SarInt64(v,7);
  470. if ((v=0) and ((b and 64)=0)) or ((v=-1) and ((b and 64)<>0)) then
  471. Done:=true
  472. else
  473. b:=b or 128;
  474. objdata.writebytes(b,1);
  475. until Done;
  476. end;
  477. procedure WriteUleb(v: tcgint);
  478. var
  479. b: byte;
  480. begin
  481. repeat
  482. b:=byte(v) and 127;
  483. v:=v shr 7;
  484. if v<>0 then
  485. b:=b or 128;
  486. objdata.writebytes(b,1);
  487. until v=0;
  488. end;
  489. begin
  490. case opcode of
  491. a_unreachable:
  492. WriteByte($00);
  493. a_nop:
  494. WriteByte($01);
  495. a_return:
  496. WriteByte($0F);
  497. a_drop:
  498. WriteByte($1A);
  499. a_memory_size:
  500. begin
  501. WriteByte($3F);
  502. WriteByte($00);
  503. end;
  504. a_memory_grow:
  505. begin
  506. WriteByte($40);
  507. WriteByte($00);
  508. end;
  509. a_i32_eqz:
  510. WriteByte($45);
  511. a_i32_eq:
  512. WriteByte($46);
  513. a_i32_ne:
  514. WriteByte($47);
  515. a_i32_lt_s:
  516. WriteByte($48);
  517. a_i32_lt_u:
  518. WriteByte($49);
  519. a_i32_gt_s:
  520. WriteByte($4A);
  521. a_i32_gt_u:
  522. WriteByte($4B);
  523. a_i32_le_s:
  524. WriteByte($4C);
  525. a_i32_le_u:
  526. WriteByte($4D);
  527. a_i32_ge_s:
  528. WriteByte($4E);
  529. a_i32_ge_u:
  530. WriteByte($4F);
  531. a_i64_eqz:
  532. WriteByte($50);
  533. a_i64_eq:
  534. WriteByte($51);
  535. a_i64_ne:
  536. WriteByte($52);
  537. a_i64_lt_s:
  538. WriteByte($53);
  539. a_i64_lt_u:
  540. WriteByte($54);
  541. a_i64_gt_s:
  542. WriteByte($55);
  543. a_i64_gt_u:
  544. WriteByte($56);
  545. a_i64_le_s:
  546. WriteByte($57);
  547. a_i64_le_u:
  548. WriteByte($58);
  549. a_i64_ge_s:
  550. WriteByte($59);
  551. a_i64_ge_u:
  552. WriteByte($5A);
  553. a_f32_eq:
  554. WriteByte($5B);
  555. a_f32_ne:
  556. WriteByte($5C);
  557. a_f32_lt:
  558. WriteByte($5D);
  559. a_f32_gt:
  560. WriteByte($5E);
  561. a_f32_le:
  562. WriteByte($5F);
  563. a_f32_ge:
  564. WriteByte($60);
  565. a_f64_eq:
  566. WriteByte($61);
  567. a_f64_ne:
  568. WriteByte($62);
  569. a_f64_lt:
  570. WriteByte($63);
  571. a_f64_gt:
  572. WriteByte($64);
  573. a_f64_le:
  574. WriteByte($65);
  575. a_f64_ge:
  576. WriteByte($66);
  577. a_i32_clz:
  578. WriteByte($67);
  579. a_i32_ctz:
  580. WriteByte($68);
  581. a_i32_popcnt:
  582. WriteByte($69);
  583. a_i32_add:
  584. WriteByte($6A);
  585. a_i32_sub:
  586. WriteByte($6B);
  587. a_i32_mul:
  588. WriteByte($6C);
  589. a_i32_div_s:
  590. WriteByte($6D);
  591. a_i32_div_u:
  592. WriteByte($6E);
  593. a_i32_rem_s:
  594. WriteByte($6F);
  595. a_i32_rem_u:
  596. WriteByte($70);
  597. a_i32_and:
  598. WriteByte($71);
  599. a_i32_or:
  600. WriteByte($72);
  601. a_i32_xor:
  602. WriteByte($73);
  603. a_i32_shl:
  604. WriteByte($74);
  605. a_i32_shr_s:
  606. WriteByte($75);
  607. a_i32_shr_u:
  608. WriteByte($76);
  609. a_i32_rotl:
  610. WriteByte($77);
  611. a_i32_rotr:
  612. WriteByte($78);
  613. a_i64_clz:
  614. WriteByte($79);
  615. a_i64_ctz:
  616. WriteByte($7A);
  617. a_i64_popcnt:
  618. WriteByte($7B);
  619. a_i64_add:
  620. WriteByte($7C);
  621. a_i64_sub:
  622. WriteByte($7D);
  623. a_i64_mul:
  624. WriteByte($7E);
  625. a_i64_div_s:
  626. WriteByte($7F);
  627. a_i64_div_u:
  628. WriteByte($80);
  629. a_i64_rem_s:
  630. WriteByte($81);
  631. a_i64_rem_u:
  632. WriteByte($82);
  633. a_i64_and:
  634. WriteByte($83);
  635. a_i64_or:
  636. WriteByte($84);
  637. a_i64_xor:
  638. WriteByte($85);
  639. a_i64_shl:
  640. WriteByte($86);
  641. a_i64_shr_s:
  642. WriteByte($87);
  643. a_i64_shr_u:
  644. WriteByte($88);
  645. a_i64_rotl:
  646. WriteByte($89);
  647. a_i64_rotr:
  648. WriteByte($8A);
  649. a_f32_abs:
  650. WriteByte($8B);
  651. a_f32_neg:
  652. WriteByte($8C);
  653. a_f32_ceil:
  654. WriteByte($8D);
  655. a_f32_floor:
  656. WriteByte($8E);
  657. a_f32_trunc:
  658. WriteByte($8F);
  659. a_f32_nearest:
  660. WriteByte($90);
  661. a_f32_sqrt:
  662. WriteByte($91);
  663. a_f32_add:
  664. WriteByte($92);
  665. a_f32_sub:
  666. WriteByte($93);
  667. a_f32_mul:
  668. WriteByte($94);
  669. a_f32_div:
  670. WriteByte($95);
  671. a_f32_min:
  672. WriteByte($96);
  673. a_f32_max:
  674. WriteByte($97);
  675. a_f32_copysign:
  676. WriteByte($98);
  677. a_f64_abs:
  678. WriteByte($99);
  679. a_f64_neg:
  680. WriteByte($9A);
  681. a_f64_ceil:
  682. WriteByte($9B);
  683. a_f64_floor:
  684. WriteByte($9C);
  685. a_f64_trunc:
  686. WriteByte($9D);
  687. a_f64_nearest:
  688. WriteByte($9E);
  689. a_f64_sqrt:
  690. WriteByte($9F);
  691. a_f64_add:
  692. WriteByte($A0);
  693. a_f64_sub:
  694. WriteByte($A1);
  695. a_f64_mul:
  696. WriteByte($A2);
  697. a_f64_div:
  698. WriteByte($A3);
  699. a_f64_min:
  700. WriteByte($A4);
  701. a_f64_max:
  702. WriteByte($A5);
  703. a_f64_copysign:
  704. WriteByte($A6);
  705. a_i32_wrap_i64:
  706. WriteByte($A7);
  707. a_i32_trunc_f32_s:
  708. WriteByte($A8);
  709. a_i32_trunc_f32_u:
  710. WriteByte($A9);
  711. a_i32_trunc_f64_s:
  712. WriteByte($AA);
  713. a_i32_trunc_f64_u:
  714. WriteByte($AB);
  715. a_i64_extend_i32_s:
  716. WriteByte($AC);
  717. a_i64_extend_i32_u:
  718. WriteByte($AD);
  719. a_i64_trunc_f32_s:
  720. WriteByte($AE);
  721. a_i64_trunc_f32_u:
  722. WriteByte($AF);
  723. a_i64_trunc_f64_s:
  724. WriteByte($B0);
  725. a_i64_trunc_f64_u:
  726. WriteByte($B1);
  727. a_f32_convert_i32_s:
  728. WriteByte($B2);
  729. a_f32_convert_i32_u:
  730. WriteByte($B3);
  731. a_f32_convert_i64_s:
  732. WriteByte($B4);
  733. a_f32_convert_i64_u:
  734. WriteByte($B5);
  735. a_f32_demote_f64:
  736. WriteByte($B6);
  737. a_f64_convert_i32_s:
  738. WriteByte($B7);
  739. a_f64_convert_i32_u:
  740. WriteByte($B8);
  741. a_f64_convert_i64_s:
  742. WriteByte($B9);
  743. a_f64_convert_i64_u:
  744. WriteByte($BA);
  745. a_f64_promote_f32:
  746. WriteByte($BB);
  747. a_i32_reinterpret_f32:
  748. WriteByte($BC);
  749. a_i64_reinterpret_f64:
  750. WriteByte($BD);
  751. a_f32_reinterpret_i32:
  752. WriteByte($BE);
  753. a_f64_reinterpret_i64:
  754. WriteByte($BF);
  755. a_i32_extend8_s:
  756. WriteByte($C0);
  757. a_i32_extend16_s:
  758. WriteByte($C1);
  759. a_i64_extend8_s:
  760. WriteByte($C2);
  761. a_i64_extend16_s:
  762. WriteByte($C3);
  763. a_i64_extend32_s:
  764. WriteByte($C4);
  765. a_end_block,
  766. a_end_if,
  767. a_end_loop,
  768. a_end_try:
  769. WriteByte($0B);
  770. a_catch_all:
  771. WriteByte($19);
  772. a_i32_const,
  773. a_i64_const:
  774. begin
  775. case opcode of
  776. a_i32_const:
  777. WriteByte($41);
  778. a_i64_const:
  779. WriteByte($42);
  780. else
  781. internalerror(2021092002);
  782. end;
  783. if ops<>1 then
  784. internalerror(2021092001);
  785. with oper[0]^ do
  786. case typ of
  787. top_const:
  788. WriteSleb(val);
  789. else
  790. Writeln('Warning! Not implemented opcode, pass2: ', opcode, ' ', typ);
  791. end;
  792. end;
  793. a_local_get,
  794. a_local_set,
  795. a_local_tee:
  796. begin
  797. case opcode of
  798. a_local_get:
  799. WriteByte($20);
  800. a_local_set:
  801. WriteByte($21);
  802. a_local_tee:
  803. WriteByte($22);
  804. else
  805. internalerror(2021092003);
  806. end;
  807. if ops<>1 then
  808. internalerror(2021092004);
  809. with oper[0]^ do
  810. case typ of
  811. top_ref:
  812. begin
  813. if assigned(ref^.symbol) then
  814. internalerror(2021092005);
  815. if ref^.base<>NR_STACK_POINTER_REG then
  816. internalerror(2021092006);
  817. if ref^.index<>NR_NO then
  818. internalerror(2021092007);
  819. WriteUleb(ref^.offset);
  820. end;
  821. else
  822. internalerror(2021092008);
  823. end;
  824. end;
  825. else
  826. Writeln('Warning! Not implemented opcode, pass2: ', opcode);
  827. end;
  828. end;
  829. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  830. begin
  831. internalerror(2010122614);
  832. result:=nil;
  833. end;
  834. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  835. begin
  836. internalerror(2010122615);
  837. result:=nil;
  838. end;
  839. procedure InitAsm;
  840. begin
  841. end;
  842. procedure DoneAsm;
  843. begin
  844. end;
  845. initialization
  846. cai_cpu:=taicpu;
  847. cai_align:=tai_align;
  848. casmdata:=TAsmData;
  849. end.