aasmcpu.pas 7.1 KB

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