aasmcpu.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. {
  2. Copyright (c) 1999-2002 by Mazen Neifer
  3. Contains the assembler object for the JVM
  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. procedure InitAsm;
  58. procedure DoneAsm;
  59. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  60. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  61. implementation
  62. {*****************************************************************************
  63. taicpu Constructors
  64. *****************************************************************************}
  65. constructor taicpu.op_none(op : tasmop);
  66. begin
  67. inherited create(op);
  68. end;
  69. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  70. begin
  71. inherited create(op);
  72. ops:=1;
  73. loadreg(0,_op1);
  74. end;
  75. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  76. begin
  77. inherited create(op);
  78. ops:=1;
  79. loadref(0,_op1);
  80. end;
  81. constructor taicpu.op_const(op : tasmop;_op1 : aint);
  82. begin
  83. inherited create(op);
  84. ops:=1;
  85. loadconst(0,_op1);
  86. end;
  87. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  88. begin
  89. inherited create(op);
  90. ops:=1;
  91. is_jmp:=op in [a_if_acmpeq, a_if_acmpne, a_if_icmpeq, a_if_icmpge, a_if_icmpgt,
  92. a_if_icmple, a_if_icmplt, a_if_icmpne,
  93. a_ifeq, a_ifge, a_ifgt, a_ifle, a_iflt, a_ifne, a_ifnonnull, a_ifnull, a_goto];
  94. loadsymbol(0,_op1,0);
  95. end;
  96. constructor taicpu.op_sym_const(op: tasmop; _op1: tasmsymbol; _op2: aint);
  97. begin
  98. inherited create(op);
  99. ops:=2;
  100. loadsymbol(0,_op1,0);
  101. loadconst(1,_op2);
  102. end;
  103. constructor taicpu.op_single(op: tasmop; _op1: single);
  104. begin
  105. inherited create(op);
  106. ops:=1;
  107. loadsingle(0,_op1);
  108. end;
  109. constructor taicpu.op_double(op: tasmop; _op1: double);
  110. begin
  111. inherited create(op);
  112. ops:=1;
  113. loaddouble(0,_op1);
  114. end;
  115. constructor taicpu.op_string(op: tasmop; _op1len: aint; _op1: pchar);
  116. begin
  117. inherited create(op);
  118. ops:=1;
  119. loadstr(0,_op1len,_op1);
  120. end;
  121. constructor taicpu.op_wstring(op: tasmop; _op1: pcompilerwidestring);
  122. begin
  123. inherited create(op);
  124. ops:=1;
  125. loadpwstr(0,_op1);
  126. end;
  127. procedure taicpu.loadsingle(opidx:longint;f:single);
  128. begin
  129. allocate_oper(opidx+1);
  130. with oper[opidx]^ do
  131. begin
  132. if typ<>top_single then
  133. clearop(opidx);
  134. sval:=f;
  135. typ:=top_single;
  136. end;
  137. end;
  138. procedure taicpu.loaddouble(opidx: longint; d: double);
  139. begin
  140. allocate_oper(opidx+1);
  141. with oper[opidx]^ do
  142. begin
  143. if typ<>top_double then
  144. clearop(opidx);
  145. dval:=d;
  146. typ:=top_double;
  147. end;
  148. end;
  149. procedure taicpu.loadstr(opidx: longint; vallen: aint; pc: pchar);
  150. begin
  151. allocate_oper(opidx+1);
  152. with oper[opidx]^ do
  153. begin
  154. clearop(opidx);
  155. pcvallen:=vallen;
  156. getmem(pcval,vallen);
  157. move(pc^,pcval^,vallen);
  158. typ:=top_string;
  159. end;
  160. end;
  161. procedure taicpu.loadpwstr(opidx:longint;pwstr:pcompilerwidestring);
  162. begin
  163. allocate_oper(opidx+1);
  164. with oper[opidx]^ do
  165. begin
  166. clearop(opidx);
  167. initwidestring(pwstrval);
  168. copywidestring(pwstr,pwstrval);
  169. typ:=top_wstring;
  170. end;
  171. end;
  172. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  173. begin
  174. result:=false;
  175. end;
  176. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  177. begin
  178. case opcode of
  179. a_iinc:
  180. result:=operand_readwrite;
  181. a_aastore,
  182. a_astore,
  183. a_astore_0,
  184. a_astore_1,
  185. a_astore_2,
  186. a_astore_3,
  187. a_bastore,
  188. a_castore,
  189. a_dastore,
  190. a_dstore,
  191. a_dstore_0,
  192. a_dstore_1,
  193. a_dstore_2,
  194. a_dstore_3,
  195. a_fastore,
  196. a_fstore,
  197. a_fstore_0,
  198. a_fstore_1,
  199. a_fstore_2,
  200. a_fstore_3,
  201. a_iastore,
  202. a_istore,
  203. a_istore_0,
  204. a_istore_1,
  205. a_istore_2,
  206. a_istore_3,
  207. a_lastore,
  208. a_lstore,
  209. a_lstore_0,
  210. a_lstore_1,
  211. a_lstore_2,
  212. a_lstore_3,
  213. a_sastore:
  214. result:=operand_write;
  215. else
  216. result:=operand_read;
  217. end;
  218. end;
  219. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  220. begin
  221. internalerror(2010122614);
  222. result:=nil;
  223. end;
  224. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  225. begin
  226. internalerror(2010122615);
  227. result:=nil;
  228. end;
  229. procedure InitAsm;
  230. begin
  231. end;
  232. procedure DoneAsm;
  233. begin
  234. end;
  235. begin
  236. cai_cpu:=taicpu;
  237. cai_align:=tai_align;
  238. casmdata:=TAsmData;
  239. end.