cpuasm.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. {
  2. $Id$
  3. Copyright (c) 1999 by Florian Klaempfl
  4. Contains the assembler object for the PowerPC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cpuasm;
  19. interface
  20. uses
  21. cobjects,
  22. aasm,globals,verbose,
  23. cpubase;
  24. type
  25. pairegalloc = ^tairegalloc;
  26. tairegalloc = object(tai)
  27. allocation : boolean;
  28. reg : tregister;
  29. constructor alloc(r : tregister);
  30. constructor dealloc(r : tregister);
  31. end;
  32. pappc = ^tappc;
  33. tappc = object(tai)
  34. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  35. opcode : tasmop;
  36. ops : longint;
  37. condition : TasmCond;
  38. oper : array[0..4] of toper;
  39. constructor op_none(op : tasmop);
  40. constructor op_reg(op : tasmop;_op1 : tregister);
  41. constructor op_const(op : tasmop;_op1 : longint);
  42. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  43. constructor op_reg_ref(op : tasmop;_op1 : tregister;_op2 : preference);
  44. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  45. constructor op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  46. constructor op_const_const(op : tasmop;_op1,_op2 : longint);
  47. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  48. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  49. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: pasmsymbol;_op3ofs: longint);
  50. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  51. constructor op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  52. constructor op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  53. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  54. constructor op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  55. constructor op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  56. constructor op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  57. { this is for Jmp instructions }
  58. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : pasmsymbol);
  59. constructor op_const_const_sym(op : tasmop;_op1,_op2 : longint);
  60. constructor op_sym(op : tasmop;_op1 : pasmsymbol);
  61. constructor op_sym_ofs(op : tasmop;_op1 : pasmsymbol;_op1ofs:longint);
  62. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:pasmsymbol;_op2ofs : longint);
  63. destructor done;virtual;
  64. function getcopy:plinkedlist_item;virtual;
  65. private
  66. segprefix : tregister;
  67. procedure init(op : tasmop); { this need to be called by all constructor }
  68. end;
  69. implementation
  70. uses
  71. og386;
  72. {*****************************************************************************
  73. TaiRegAlloc
  74. *****************************************************************************}
  75. constructor tairegalloc.alloc(r : tregister);
  76. begin
  77. inherited init;
  78. typ:=ait_regalloc;
  79. allocation:=true;
  80. reg:=r;
  81. end;
  82. constructor tairegalloc.dealloc(r : tregister);
  83. begin
  84. inherited init;
  85. typ:=ait_regalloc;
  86. allocation:=false;
  87. reg:=r;
  88. end;
  89. {*****************************************************************************
  90. tappc Constructors
  91. *****************************************************************************}
  92. procedure tappc.init(op : tasmop);
  93. begin
  94. typ:=ait_instruction;
  95. is_jmp:=false;
  96. segprefix:=R_NO;
  97. opcode:=op;
  98. ops:=0;
  99. condition:=c_none;
  100. fillchar(oper,sizeof(oper),0);
  101. end;
  102. constructor tappc.op_none(op : tasmop);
  103. begin
  104. inherited init;
  105. init(op);
  106. end;
  107. constructor tappc.op_reg(op : tasmop;_op1 : tregister);
  108. begin
  109. inherited init;
  110. init(op);
  111. ops:=1;
  112. end;
  113. constructor tappc.op_const(op : tasmop;_op1 : longint);
  114. begin
  115. inherited init;
  116. init(op);
  117. ops:=1;
  118. end;
  119. constructor tappc.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  120. begin
  121. inherited init;
  122. init(op);
  123. ops:=2;
  124. end;
  125. constructor tappc.op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  126. begin
  127. inherited init;
  128. init(op);
  129. ops:=2;
  130. end;
  131. constructor op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  132. begin
  133. inherited init;
  134. init(op);
  135. ops:=2;
  136. end;
  137. constructor tappc.op_reg_ref(op : tasmop;_op1 : tregister;_op2 : preference);
  138. begin
  139. inherited init;
  140. init(op);
  141. ops:=2;
  142. end;
  143. constructor tappc.op_const_const(op : tasmop;_op1,_op2 : longint);
  144. begin
  145. inherited init;
  146. init(op);
  147. ops:=2;
  148. end;
  149. constructor tappc.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  150. begin
  151. inherited init;
  152. init(op);
  153. ops:=3;
  154. end;
  155. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  156. begin
  157. inherited init;
  158. init(op);
  159. ops:=3;
  160. end;
  161. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: pasmsymbol;_op3ofs: longint);
  162. begin
  163. inherited init;
  164. init(op);
  165. ops:=3;
  166. end;
  167. constructor tappc.op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  168. begin
  169. inherited init;
  170. init(op);
  171. ops:=3;
  172. end;
  173. constructor op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  174. begin
  175. inherited init;
  176. init(op);
  177. ops:=3;
  178. end;
  179. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  180. begin
  181. inherited init;
  182. init(op);
  183. ops:=4;
  184. end;
  185. constructor op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  186. begin
  187. inherited init;
  188. init(op);
  189. ops:=4;
  190. end;
  191. constructor op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  192. begin
  193. inherited init;
  194. init(op);
  195. ops:=4;
  196. end;
  197. constructor op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  198. begin
  199. inherited init;
  200. init(op);
  201. ops:=5;
  202. end;
  203. constructor tappc.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : pasmsymbol);
  204. begin
  205. inherited init;
  206. init(op);
  207. condition:=cond;
  208. ops:=1;
  209. end;
  210. constructor op_const_const_sym(op : tasmop;_op1,_op2 : longint);
  211. begin
  212. inherited init;
  213. init(op);
  214. condition:=cond;
  215. ops:=3;
  216. end;
  217. constructor tappc.op_sym(op : tasmop;_op1 : pasmsymbol);
  218. begin
  219. inherited init;
  220. init(op);
  221. ops:=1;
  222. end;
  223. constructor tappc.op_sym_ofs(op : tasmop;_op1 : pasmsymbol;_op1ofs:longint);
  224. begin
  225. inherited init;
  226. init(op);
  227. ops:=1;
  228. end;
  229. constructor tappc.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:pasmsymbol;_op2ofs : longint);
  230. begin
  231. inherited init;
  232. init(op);
  233. ops:=2;
  234. end;
  235. constructor tappc.op_sym_ofs_ref(op : tasmop;_op1 : pasmsymbol;_op1ofs:longint;_op2 : preference);
  236. begin
  237. inherited init;
  238. init(op);
  239. ops:=2;
  240. end;
  241. destructor tappc.done;
  242. var
  243. i : longint;
  244. begin
  245. for i:=1 to ops do
  246. if (oper[i-1].typ=top_ref) then
  247. dispose(oper[i-1].ref);
  248. inherited done;
  249. end;
  250. function tappc.getcopy:plinkedlist_item;
  251. var
  252. i : longint;
  253. p : plinkedlist_item;
  254. begin
  255. p:=inherited getcopy;
  256. { make a copy of the references }
  257. for i:=1 to ops do
  258. if (paalpha(p)^.oper[i-1].typ=top_ref) then
  259. begin
  260. new(paalpha(p)^.oper[i-1].ref);
  261. paalpha(p)^.oper[i-1].ref^:=oper[i-1].ref^;
  262. end;
  263. getcopy:=p;
  264. end;
  265. end.
  266. {
  267. $Log$
  268. Revision 1.1 1999-08-03 23:37:53 jonas
  269. + initial implementation for PowerPC based on the Alpha stuff
  270. }