aasmcpu.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. {
  2. Copyright (c) 1999-2008 by Mazen Neifer and Florian Klaempfl
  3. Contains the assembler object for the AVR
  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. const
  26. { "mov reg,reg" source operand number }
  27. O_MOV_SOURCE = 1;
  28. { "mov reg,reg" source operand number }
  29. O_MOV_DEST = 0;
  30. type
  31. taicpu = class(tai_cpu_abstract_sym)
  32. constructor op_none(op : tasmop);
  33. constructor op_reg(op : tasmop;_op1 : tregister);
  34. constructor op_const(op : tasmop;_op1 : LongInt);
  35. constructor op_ref(op : tasmop;const _op1 : treference);
  36. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  37. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  38. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  39. constructor op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  40. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  41. { this is for Jmp instructions }
  42. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  43. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  44. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  45. procedure loadbool(opidx:longint;_b:boolean);
  46. { register allocation }
  47. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  48. { register spilling code }
  49. function spilling_get_operation_type(opnr: longint): topertype;override;
  50. end;
  51. tai_align = class(tai_align_abstract)
  52. { nothing to add }
  53. end;
  54. procedure InitAsm;
  55. procedure DoneAsm;
  56. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  57. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  58. implementation
  59. {*****************************************************************************
  60. taicpu Constructors
  61. *****************************************************************************}
  62. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  63. begin
  64. if opidx>=ops then
  65. ops:=opidx+1;
  66. with oper[opidx]^ do
  67. begin
  68. if typ=top_ref then
  69. dispose(ref);
  70. b:=_b;
  71. typ:=top_bool;
  72. end;
  73. end;
  74. constructor taicpu.op_none(op : tasmop);
  75. begin
  76. inherited create(op);
  77. end;
  78. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  79. begin
  80. inherited create(op);
  81. ops:=1;
  82. loadreg(0,_op1);
  83. end;
  84. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  85. begin
  86. inherited create(op);
  87. ops:=1;
  88. loadref(0,_op1);
  89. end;
  90. constructor taicpu.op_const(op : tasmop;_op1 : LongInt);
  91. begin
  92. inherited create(op);
  93. ops:=1;
  94. loadconst(0,_op1);
  95. end;
  96. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  97. begin
  98. inherited create(op);
  99. ops:=2;
  100. loadreg(0,_op1);
  101. loadreg(1,_op2);
  102. end;
  103. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  104. begin
  105. inherited create(op);
  106. ops:=2;
  107. loadreg(0,_op1);
  108. loadconst(1,_op2);
  109. end;
  110. constructor taicpu.op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  111. begin
  112. inherited create(op);
  113. ops:=2;
  114. loadconst(0,_op1);
  115. loadreg(1,_op2);
  116. end;
  117. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  118. begin
  119. inherited create(op);
  120. ops:=2;
  121. loadreg(0,_op1);
  122. loadref(1,_op2);
  123. end;
  124. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  125. begin
  126. inherited create(op);
  127. ops:=2;
  128. loadref(0,_op1);
  129. loadreg(1,_op2);
  130. end;
  131. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  132. begin
  133. inherited create(op);
  134. is_jmp:=op in jmp_instructions;
  135. condition:=cond;
  136. ops:=1;
  137. loadsymbol(0,_op1,0);
  138. end;
  139. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  140. begin
  141. inherited create(op);
  142. is_jmp:=op in jmp_instructions;
  143. ops:=1;
  144. loadsymbol(0,_op1,0);
  145. end;
  146. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  147. begin
  148. inherited create(op);
  149. ops:=1;
  150. loadsymbol(0,_op1,_op1ofs);
  151. end;
  152. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  153. begin
  154. result:=(
  155. ((opcode in [A_MOV,A_MOVW]) and (regtype = R_INTREGISTER))
  156. ) and
  157. (ops=2) and
  158. (oper[0]^.typ=top_reg) and
  159. (oper[1]^.typ=top_reg) and
  160. (oper[0]^.reg=oper[1]^.reg);
  161. end;
  162. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  163. begin
  164. result := operand_read;
  165. case opcode of
  166. A_CP,A_CPC,A_CPI :
  167. ;
  168. else
  169. begin
  170. if opnr=ops-1 then
  171. result := operand_write;
  172. end;
  173. end;
  174. end;
  175. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  176. begin
  177. case getregtype(r) of
  178. R_INTREGISTER :
  179. result:=taicpu.op_ref_reg(A_LD,ref,r);
  180. else
  181. internalerror(200401041);
  182. end;
  183. end;
  184. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  185. begin
  186. case getregtype(r) of
  187. R_INTREGISTER :
  188. result:=taicpu.op_reg_ref(A_ST,r,ref);
  189. else
  190. internalerror(200401041);
  191. end;
  192. end;
  193. procedure InitAsm;
  194. begin
  195. end;
  196. procedure DoneAsm;
  197. begin
  198. end;
  199. begin
  200. cai_cpu:=taicpu;
  201. cai_align:=tai_align;
  202. end.