aasmcpu.pas 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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,
  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_string(op : tasmop;_op1len : aint;_op1 : pchar);
  44. //constructor op_wstring(op : tasmop;_op1 : pcompilerwidestring);
  45. procedure loadsingle(opidx:longint;f:single);
  46. procedure loaddouble(opidx:longint;d:double);
  47. //procedure loadstr(opidx:longint;vallen: aint;pc: pchar);
  48. //procedure loadpwstr(opidx:longint;pwstr:pcompilerwidestring);
  49. { register allocation }
  50. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  51. { register spilling code }
  52. function spilling_get_operation_type(opnr: longint): topertype;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. symstype: TImpExpType;
  69. constructor create(const aextname, aintname: ansistring; asymtype: timpexptype);
  70. end;
  71. procedure InitAsm;
  72. procedure DoneAsm;
  73. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  74. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  75. implementation
  76. { timpexp_ai }
  77. constructor tai_impexp.create(const aextname, aintname: ansistring;
  78. asymtype: timpexptype);
  79. begin
  80. inherited create;
  81. typ := ait_importexport;
  82. extname := aextname;
  83. intname := aintname;
  84. end;
  85. {*****************************************************************************
  86. taicpu Constructors
  87. *****************************************************************************}
  88. constructor taicpu.op_none(op : tasmop);
  89. begin
  90. inherited create(op);
  91. end;
  92. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  93. begin
  94. inherited create(op);
  95. ops:=1;
  96. loadreg(0,_op1);
  97. end;
  98. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  99. begin
  100. inherited create(op);
  101. ops:=1;
  102. loadref(0,_op1);
  103. end;
  104. constructor taicpu.op_const(op : tasmop;_op1 : aint);
  105. begin
  106. inherited create(op);
  107. ops:=1;
  108. loadconst(0,_op1);
  109. end;
  110. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  111. begin
  112. inherited create(op);
  113. ops:=1;
  114. //is_jmp:=op in [a_if_acmpeq, a_if_acmpne, a_if_icmpeq, a_if_icmpge, a_if_icmpgt,
  115. // a_if_icmple, a_if_icmplt, a_if_icmpne,
  116. // a_ifeq, a_ifge, a_ifgt, a_ifle, a_iflt, a_ifne, a_ifnonnull, a_ifnull, a_goto];
  117. loadsymbol(0,_op1,0);
  118. end;
  119. constructor taicpu.op_sym_const(op: tasmop; _op1: tasmsymbol; _op2: aint);
  120. begin
  121. inherited create(op);
  122. ops:=2;
  123. loadsymbol(0,_op1,0);
  124. loadconst(1,_op2);
  125. end;
  126. constructor taicpu.op_single(op: tasmop; _op1: single);
  127. begin
  128. inherited create(op);
  129. ops:=1;
  130. loadsingle(0,_op1);
  131. end;
  132. constructor taicpu.op_double(op: tasmop; _op1: double);
  133. begin
  134. inherited create(op);
  135. ops:=1;
  136. loaddouble(0,_op1);
  137. end;
  138. {constructor taicpu.op_string(op: tasmop; _op1len: aint; _op1: pchar);
  139. begin
  140. inherited create(op);
  141. ops:=1;
  142. loadstr(0,_op1len,_op1);
  143. end;
  144. constructor taicpu.op_wstring(op: tasmop; _op1: pcompilerwidestring);
  145. begin
  146. inherited create(op);
  147. ops:=1;
  148. loadpwstr(0,_op1);
  149. end;}
  150. procedure taicpu.loadsingle(opidx:longint;f:single);
  151. begin
  152. allocate_oper(opidx+1);
  153. with oper[opidx]^ do
  154. begin
  155. if typ<>top_single then
  156. clearop(opidx);
  157. sval:=f;
  158. typ:=top_single;
  159. end;
  160. end;
  161. procedure taicpu.loaddouble(opidx: longint; d: double);
  162. begin
  163. allocate_oper(opidx+1);
  164. with oper[opidx]^ do
  165. begin
  166. if typ<>top_double then
  167. clearop(opidx);
  168. dval:=d;
  169. typ:=top_double;
  170. end;
  171. end;
  172. {procedure taicpu.loadstr(opidx: longint; vallen: aint; pc: pchar);
  173. begin
  174. allocate_oper(opidx+1);
  175. with oper[opidx]^ do
  176. begin
  177. clearop(opidx);
  178. pcvallen:=vallen;
  179. getmem(pcval,vallen);
  180. move(pc^,pcval^,vallen);
  181. typ:=top_string;
  182. end;
  183. end;
  184. procedure taicpu.loadpwstr(opidx:longint;pwstr:pcompilerwidestring);
  185. begin
  186. allocate_oper(opidx+1);
  187. with oper[opidx]^ do
  188. begin
  189. clearop(opidx);
  190. initwidestring(pwstrval);
  191. copywidestring(pwstr,pwstrval);
  192. typ:=top_wstring;
  193. end;
  194. end;}
  195. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  196. begin
  197. result:=false;
  198. end;
  199. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  200. begin
  201. if opcode in AsmOp_Store then
  202. result:=operand_write
  203. else
  204. result:=operand_read;
  205. end;
  206. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  207. begin
  208. internalerror(2010122614);
  209. result:=nil;
  210. end;
  211. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  212. begin
  213. internalerror(2010122615);
  214. result:=nil;
  215. end;
  216. procedure InitAsm;
  217. begin
  218. end;
  219. procedure DoneAsm;
  220. begin
  221. end;
  222. initialization
  223. cai_cpu:=taicpu;
  224. cai_align:=tai_align;
  225. casmdata:=TAsmData;
  226. end.