summaryrefslogtreecommitdiff
path: root/sparcbw/compiler/sparc/cpugas.pas
blob: 0f98c0b12d2a0dec96bea3c38e14650be82bfc59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
{
    $Id: cpugas.pas,v 1.32 2005/02/14 17:13:10 peter Exp $
    Copyright (c) 1999-2003 by Florian Klaempfl

    This unit implements an asmoutput class for SPARC AT&T syntax

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************
}
unit cpugas;

{$i fpcdefs.inc}

interface

    uses
      cpubase,
      aasmtai,aasmcpu,assemble,aggas;

    type
      TGasSPARC=class(TGnuAssembler)
        procedure WriteInstruction(hp:Tai);override;
      end;

implementation

    uses
      cutils,systems,
      verbose,itcpugas,cgbase,cgutils;


    function GetReferenceString(var ref:TReference):string;
      begin
        GetReferenceString:='';
        with ref do
          begin
            if (base=NR_NO) and (index=NR_NO) then
              begin
                 if assigned(symbol) then
                   GetReferenceString:=symbol.name;
                 if offset>0 then
                   GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
                 else if offset<0 then
                   GetReferenceString:=GetReferenceString+ToStr(offset);
                 case refaddr of
                   addr_hi:
                     GetReferenceString:='%hi('+GetReferenceString+')';
                   addr_lo:
                     GetReferenceString:='%lo('+GetReferenceString+')';
                 end;
              end
            else
              begin
{$ifdef extdebug}
                if assigned(symbol) and
                  not(refaddr in [addr_pic,addr_lo]) then
                  internalerror(2003052601);
{$endif extdebug}
                if base<>NR_NO then
                  GetReferenceString:=GetReferenceString+gas_regname(base);
                if index=NR_NO then
                  begin
                    { if (Offset<simm13lo) or (Offset>simm13hi) then
                      internalerror(2003053008); }
                    if offset>0 then
                      GetReferenceString:=GetReferenceString+'+'+ToStr(offset)
                    else if offset<0 then
                      GetReferenceString:=GetReferenceString+ToStr(offset);
                    {
                    else if (offset=0) and not(assigned(symbol)) then
                      GetReferenceString:=GetReferenceString+ToStr(offset);
                    }
                    if assigned(symbol) then
                      begin
                        if refaddr=addr_lo then
                          GetReferenceString:='%lo('+symbol.name+')+'+GetReferenceString
                        else
                          GetReferenceString:=symbol.name+'+'+GetReferenceString;
                      end;
                  end
                else
                  begin
{$ifdef extdebug}
                    if (Offset<>0) or assigned(symbol) then
                      internalerror(2003052603);
{$endif extdebug}
                    GetReferenceString:=GetReferenceString+'+'+gas_regname(index);
                  end;
              end;
          end;
      end;


    function getopstr(const Oper:TOper):string;
      begin
        with Oper do
          case typ of
            top_reg:
              getopstr:=gas_regname(reg);
            top_const:
              getopstr:=tostr(longint(val));
            top_ref:
              if (oper.ref^.refaddr in [addr_no,addr_pic]) or ((oper.ref^.refaddr=addr_lo) and ((oper.ref^.base<>NR_NO) or
                (oper.ref^.index<>NR_NO))) then
                getopstr:='['+getreferencestring(ref^)+']'
              else
                getopstr:=getreferencestring(ref^);
            else
              internalerror(10001);
          end;
        end;


    procedure TGasSPARC.WriteInstruction(hp:Tai);
      var
        Op:TAsmOp;
        s:String;
        i:Integer;
      begin
        if hp.typ<>ait_instruction then
          exit;
        op:=taicpu(hp).opcode;
        { translate pseudoops, this should be move to a separate pass later, so it's done before
          peephole optimization }
        case op of
          A_FABSd:
            begin
              if (taicpu(hp).ops<>2) or
                 (taicpu(hp).oper[0]^.typ<>top_reg) or
                 (taicpu(hp).oper[1]^.typ<>top_reg) then
                internalerror(200401045);
              { FABSs %f<even>,%f<even> }
              s:=#9+std_op2str[A_FABSs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
              AsmWriteLn(s);
              { FMOVs %f<odd>,%f<odd> }
              inc(taicpu(hp).oper[0]^.reg);
              inc(taicpu(hp).oper[1]^.reg);
              s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
              dec(taicpu(hp).oper[0]^.reg);
              dec(taicpu(hp).oper[1]^.reg);
              AsmWriteLn(s);
            end;
          A_FMOVd:
            begin
              if (taicpu(hp).ops<>2) or
                 (taicpu(hp).oper[0]^.typ<>top_reg) or
                 (taicpu(hp).oper[1]^.typ<>top_reg) then
                internalerror(200401045);
              { FMOVs %f<even>,%f<even> }
              s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
              AsmWriteLn(s);
              { FMOVs %f<odd>,%f<odd> }
              inc(taicpu(hp).oper[0]^.reg);
              inc(taicpu(hp).oper[1]^.reg);
              s:=#9+std_op2str[A_FMOVs]+#9+getopstr(taicpu(hp).oper[0]^)+','+getopstr(taicpu(hp).oper[1]^);
              dec(taicpu(hp).oper[0]^.reg);
              dec(taicpu(hp).oper[1]^.reg);
              AsmWriteLn(s);
            end
          else
            begin
              { call maybe not translated to call }
              s:=#9+std_op2str[op]+cond2str[taicpu(hp).condition];
              if taicpu(hp).delayslot_annulled then
                s:=s+',a';
              if taicpu(hp).ops>0 then
                begin
                  s:=s+#9+getopstr(taicpu(hp).oper[0]^);
                  for i:=1 to taicpu(hp).ops-1 do
                    s:=s+','+getopstr(taicpu(hp).oper[i]^);
                end;
              AsmWriteLn(s);
            end;
        end;
      end;


    const
      as_sparc_as_info : tasminfo =
         (
           id     : as_gas;
           idtxt  : 'AS';
           asmbin : 'as';
           asmcmd : '-o $OBJ $ASM';
           supported_target : system_any;
           flags : [af_allowdirect,af_needar,af_smartlink_sections];
           labelprefix : '.L';
           comment : '# ';
         );

begin
  RegisterAssembler(as_SPARC_as_info,TGasSPARC);
end.
{
    $Log: cpugas.pas,v $
    Revision 1.32  2005/02/14 17:13:10  peter
      * truncate log

    Revision 1.31  2005/01/23 17:14:21  florian
      + optimized code generation on sparc
      + some stuff for pic code on sparc added

}