cpugas.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. {
  2. $Id$
  3. Copyright (c) 1999-2003 by Florian Klaempfl
  4. This unit implements an asmoutput class for SPARC AT&T syntax
  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 cpugas;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. aasmtai,aasmcpu,assemble,aggas;
  24. type
  25. TGasSPARC=class(TGnuAssembler)
  26. procedure WriteInstruction(hp:Tai);override;
  27. end;
  28. implementation
  29. uses
  30. cutils,systems,
  31. verbose,itcpugas,cgbase,cgutils;
  32. function GetReferenceString(var ref:TReference):string;
  33. begin
  34. GetReferenceString:='';
  35. with ref do
  36. begin
  37. if (base=NR_NO) and (index=NR_NO) then
  38. begin
  39. if assigned(symbol) then
  40. GetReferenceString:=symbol.name;
  41. if offset>0 then
  42. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  43. else if offset<0 then
  44. GetReferenceString:=GetReferenceString+ToStr(offset);
  45. case refaddr of
  46. addr_hi:
  47. GetReferenceString:='%hi('+GetReferenceString+')';
  48. addr_lo:
  49. GetReferenceString:='%lo('+GetReferenceString+')';
  50. end;
  51. end
  52. else
  53. begin
  54. {$ifdef extdebug}
  55. if assigned(symbol) and
  56. not(refaddr in [addr_pic,addr_lo]) then
  57. internalerror(2003052601);
  58. {$endif extdebug}
  59. if base<>NR_NO then
  60. GetReferenceString:=GetReferenceString+gas_regname(base);
  61. if index=NR_NO then
  62. begin
  63. { if (Offset<simm13lo) or (Offset>simm13hi) then
  64. internalerror(2003053008); }
  65. if offset>0 then
  66. GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
  67. else if offset<0 then
  68. GetReferenceString:=GetReferenceString+ToStr(offset);
  69. {
  70. else if (offset=0) and not(assigned(symbol)) then
  71. GetReferenceString:=GetReferenceString+ToStr(offset);
  72. }
  73. if assigned(symbol) then
  74. begin
  75. if refaddr=addr_lo then
  76. GetReferenceString:='%lo('+symbol.name+')+'+GetReferenceString
  77. else
  78. GetReferenceString:=symbol.name+'+'+GetReferenceString;
  79. end;
  80. end
  81. else
  82. begin
  83. {$ifdef extdebug}
  84. if (Offset<>0) or assigned(symbol) then
  85. internalerror(2003052603);
  86. {$endif extdebug}
  87. GetReferenceString:=GetReferenceString+'+'+gas_regname(index);
  88. end;
  89. end;
  90. end;
  91. end;
  92. function getopstr(const Oper:TOper):string;
  93. begin
  94. with Oper do
  95. case typ of
  96. top_reg:
  97. getopstr:=gas_regname(reg);
  98. top_const:
  99. getopstr:=tostr(longint(val));
  100. top_ref:
  101. if (oper.ref^.refaddr in [addr_no,addr_pic]) or ((oper.ref^.refaddr=addr_lo) and ((oper.ref^.base<>NR_NO) or
  102. (oper.ref^.index<>NR_NO))) then
  103. getopstr:='['+getreferencestring(ref^)+']'
  104. else
  105. getopstr:=getreferencestring(ref^);
  106. else
  107. internalerror(10001);
  108. end;
  109. end;
  110. procedure TGasSPARC.WriteInstruction(hp:Tai);
  111. var
  112. Op:TAsmOp;
  113. s:String;
  114. i:Integer;
  115. begin
  116. if hp.typ<>ait_instruction then
  117. exit;
  118. op:=taicpu(hp).opcode;
  119. { translate pseudoops, this should be move to a separate pass later, so it's done before
  120. peephole optimization }
  121. case op of
  122. A_FABSd:
  123. begin
  124. if (taicpu(hp).ops<>2) or
  125. (taicpu(hp).oper[0]^.typ<>top_reg) or
  126. (taicpu(hp).oper[1]^.typ<>top_reg) then
  127. internalerror(200401045);
  128. { FABSs %f<even>,%f<even> }
  129. s:=#9+std_op2str[A_FABSs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  130. AsmWriteLn(s);
  131. { FMOVs %f<odd>,%f<odd> }
  132. inc(taicpu(hp).oper[0]^.reg);
  133. inc(taicpu(hp).oper[1]^.reg);
  134. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  135. dec(taicpu(hp).oper[0]^.reg);
  136. dec(taicpu(hp).oper[1]^.reg);
  137. AsmWriteLn(s);
  138. end;
  139. A_FMOVd:
  140. begin
  141. if (taicpu(hp).ops<>2) or
  142. (taicpu(hp).oper[0]^.typ<>top_reg) or
  143. (taicpu(hp).oper[1]^.typ<>top_reg) then
  144. internalerror(200401045);
  145. { FMOVs %f<even>,%f<even> }
  146. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  147. AsmWriteLn(s);
  148. { FMOVs %f<odd>,%f<odd> }
  149. inc(taicpu(hp).oper[0]^.reg);
  150. inc(taicpu(hp).oper[1]^.reg);
  151. s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
  152. dec(taicpu(hp).oper[0]^.reg);
  153. dec(taicpu(hp).oper[1]^.reg);
  154. AsmWriteLn(s);
  155. end
  156. else
  157. begin
  158. { call maybe not translated to call }
  159. s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
  160. if taicpu(hp).delayslot_annulled then
  161. s:=s+',a';
  162. if taicpu(hp).ops>0 then
  163. begin
  164. s:=s+#9+getopstr(taicpu(hp).oper[0]^);
  165. for i:=1 to taicpu(hp).ops-1 do
  166. s:=s+','+getopstr(taicpu(hp).oper[i]^);
  167. end;
  168. AsmWriteLn(s);
  169. end;
  170. end;
  171. end;
  172. const
  173. as_sparc_as_info : tasminfo =
  174. (
  175. id : as_gas;
  176. idtxt : 'AS';
  177. asmbin : 'as';
  178. asmcmd : '-o $OBJ $ASM';
  179. supported_target : system_any;
  180. flags : [af_allowdirect,af_needar,af_smartlink_sections];
  181. labelprefix : '.L';
  182. comment : '# ';
  183. );
  184. begin
  185. RegisterAssembler(as_SPARC_as_info,TGasSPARC);
  186. end.
  187. {
  188. $Log$
  189. Revision 1.32 2005-02-14 17:13:10 peter
  190. * truncate log
  191. Revision 1.31 2005/01/23 17:14:21 florian
  192. + optimized code generation on sparc
  193. + some stuff for pic code on sparc added
  194. }