aasmcpu.pas 26 KB

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