~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to compiler/i386/n386mem.pas

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2004-08-12 16:29:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040812162937-moo8ulvysp1ln771
Tags: 1.9.4-5
fp-compiler: needs ld, adding dependency on binutils.  (Closes: #265265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
    $Id: n386mem.pas,v 1.60 2004/02/27 10:21:05 florian Exp $
 
3
    Copyright (c) 1998-2002 by Florian Klaempfl
 
4
 
 
5
    Generate i386 assembler for in memory related nodes
 
6
 
 
7
    This program is free software; you can redistribute it and/or modify
 
8
    it under the terms of the GNU General Public License as published by
 
9
    the Free Software Foundation; either version 2 of the License, or
 
10
    (at your option) any later version.
 
11
 
 
12
    This program is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU General Public License
 
18
    along with this program; if not, write to the Free Software
 
19
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 
 
21
 ****************************************************************************
 
22
}
 
23
unit n386mem;
 
24
 
 
25
{$i fpcdefs.inc}
 
26
 
 
27
interface
 
28
 
 
29
    uses
 
30
      cgbase,cpuinfo,cpubase,
 
31
      node,nmem,ncgmem;
 
32
 
 
33
    type
 
34
       ti386addrnode = class(tcgaddrnode)
 
35
          procedure pass_2;override;
 
36
       end;
 
37
 
 
38
       ti386derefnode = class(tcgderefnode)
 
39
          procedure pass_2;override;
 
40
       end;
 
41
 
 
42
       ti386vecnode = class(tcgvecnode)
 
43
          procedure update_reference_reg_mul(reg:tregister;l:aword);override;
 
44
          procedure pass_2;override;
 
45
       end;
 
46
 
 
47
implementation
 
48
 
 
49
    uses
 
50
{$ifdef delphi}
 
51
      sysutils,
 
52
{$endif}
 
53
      systems,
 
54
      cutils,verbose,
 
55
      symdef,paramgr,
 
56
      aasmtai,
 
57
      nld,ncon,nadd,
 
58
      cgutils,cgobj;
 
59
 
 
60
{*****************************************************************************
 
61
                             TI386ADDRNODE
 
62
*****************************************************************************}
 
63
 
 
64
    procedure ti386addrnode.pass_2;
 
65
 
 
66
      begin
 
67
        inherited pass_2;
 
68
        { for use of other segments }
 
69
        if left.location.reference.segment<>NR_NO then
 
70
          location.segment:=left.location.reference.segment;
 
71
      end;
 
72
 
 
73
 
 
74
{*****************************************************************************
 
75
                           TI386DEREFNODE
 
76
*****************************************************************************}
 
77
 
 
78
    procedure ti386derefnode.pass_2;
 
79
      begin
 
80
         inherited pass_2;
 
81
         if tpointerdef(left.resulttype.def).is_far then
 
82
           location.reference.segment:=NR_FS;
 
83
      end;
 
84
 
 
85
 
 
86
{*****************************************************************************
 
87
                             TI386VECNODE
 
88
*****************************************************************************}
 
89
 
 
90
     procedure ti386vecnode.update_reference_reg_mul(reg:tregister;l:aword);
 
91
       var
 
92
         l2 : integer;
 
93
         hreg : tregister;
 
94
       begin
 
95
         { Optimized for x86 to use the index register and scalefactor }
 
96
         if location.reference.index=NR_NO then
 
97
          begin
 
98
            { no preparations needed }
 
99
          end
 
100
         else if location.reference.base=NR_NO then
 
101
          begin
 
102
            case location.reference.scalefactor of
 
103
             2 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,1,location.reference.index);
 
104
             4 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,2,location.reference.index);
 
105
             8 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,3,location.reference.index);
 
106
            end;
 
107
            location.reference.base:=location.reference.index;
 
108
          end
 
109
         else
 
110
          begin
 
111
            cg.ungetreference(exprasmlist,location.reference);
 
112
            hreg := cg.getaddressregister(exprasmlist);
 
113
            cg.a_loadaddr_ref_reg(exprasmlist,location.reference,hreg);
 
114
            reference_reset_base(location.reference,hreg,0);
 
115
          end;
 
116
         { insert the new index register and scalefactor or
 
117
           do the multiplication manual }
 
118
         case l of
 
119
          1,2,4,8 : location.reference.scalefactor:=l;
 
120
         else
 
121
           begin
 
122
              if ispowerof2(l,l2) then
 
123
                cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,l2,reg)
 
124
              else
 
125
                cg.a_op_const_reg(exprasmlist,OP_IMUL,OS_ADDR,l,reg);
 
126
           end;
 
127
         end;
 
128
         location.reference.index:=reg;
 
129
       end;
 
130
 
 
131
 
 
132
    procedure ti386vecnode.pass_2;
 
133
      begin
 
134
        inherited pass_2;
 
135
        if nf_memseg in flags then
 
136
          location.reference.segment:=NR_FS;
 
137
      end;
 
138
 
 
139
 
 
140
begin
 
141
   caddrnode:=ti386addrnode;
 
142
   cderefnode:=ti386derefnode;
 
143
   cvecnode:=ti386vecnode;
 
144
end.
 
145
{
 
146
  $Log: n386mem.pas,v $
 
147
  Revision 1.60  2004/02/27 10:21:05  florian
 
148
    * top_symbol killed
 
149
    + refaddr to treference added
 
150
    + refsymbol to treference added
 
151
    * top_local stuff moved to an extra record to save memory
 
152
    + aint introduced
 
153
    * tppufile.get/putint64/aint implemented
 
154
 
 
155
  Revision 1.59  2003/10/21 15:13:27  peter
 
156
    * fix vecnode code that caused to much register conflicts
 
157
 
 
158
  Revision 1.58  2003/10/10 17:48:14  peter
 
159
    * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
 
160
    * tregisteralloctor renamed to trgobj
 
161
    * removed rgobj from a lot of units
 
162
    * moved location_* and reference_* to cgobj
 
163
    * first things for mmx register allocation
 
164
 
 
165
  Revision 1.57  2003/10/09 21:31:37  daniel
 
166
    * Register allocator splitted, ans abstract now
 
167
 
 
168
  Revision 1.56  2003/10/01 20:34:49  peter
 
169
    * procinfo unit contains tprocinfo
 
170
    * cginfo renamed to cgbase
 
171
    * moved cgmessage to verbose
 
172
    * fixed ppc and sparc compiles
 
173
 
 
174
  Revision 1.55  2003/09/29 20:58:56  peter
 
175
    * optimized releasing of registers
 
176
 
 
177
  Revision 1.54  2003/09/03 15:55:01  peter
 
178
    * NEWRA branch merged
 
179
 
 
180
  Revision 1.53.2.2  2003/08/31 15:46:26  peter
 
181
    * more updates for tregister
 
182
 
 
183
  Revision 1.53.2.1  2003/08/29 17:29:00  peter
 
184
    * next batch of updates
 
185
 
 
186
  Revision 1.53  2003/06/01 21:38:06  peter
 
187
    * getregisterfpu size parameter added
 
188
    * op_const_reg size parameter added
 
189
    * sparc updates
 
190
 
 
191
  Revision 1.52  2003/04/22 14:33:38  peter
 
192
    * removed some notes/hints
 
193
 
 
194
  Revision 1.51  2003/03/28 19:16:57  peter
 
195
    * generic constructor working for i386
 
196
    * remove fixed self register
 
197
    * esi added as address register for i386
 
198
 
 
199
  Revision 1.50  2003/02/19 22:00:15  daniel
 
200
    * Code generator converted to new register notation
 
201
    - Horribily outdated todo.txt removed
 
202
 
 
203
  Revision 1.49  2003/01/13 18:37:44  daniel
 
204
    * Work on register conversion
 
205
 
 
206
  Revision 1.48  2003/01/08 18:43:57  daniel
 
207
   * Tregister changed into a record
 
208
 
 
209
  Revision 1.47  2002/12/03 22:14:12  carl
 
210
     + use FPC_CHECKPOINTER once again
 
211
 
 
212
  Revision 1.46  2002/11/25 17:43:27  peter
 
213
    * splitted defbase in defutil,symutil,defcmp
 
214
    * merged isconvertable and is_equal into compare_defs(_ext)
 
215
    * made operator search faster by walking the list only once
 
216
 
 
217
  Revision 1.45  2002/11/23 22:50:09  carl
 
218
    * some small speed optimizations
 
219
    + added several new warnings/hints
 
220
 
 
221
  Revision 1.44  2002/09/07 15:25:11  peter
 
222
    * old logs removed and tabs fixed
 
223
 
 
224
  Revision 1.43  2002/09/01 19:27:35  peter
 
225
    * use index register when available for generating a reference with
 
226
      only a signle register. Using the base register could possibly
 
227
      destroy the framepointer
 
228
 
 
229
  Revision 1.42  2002/09/01 18:46:01  peter
 
230
    * fixed generic tcgvecnode
 
231
    * move code that updates a reference with index register and multiplier
 
232
      to separate method so it can be overriden for scaled indexing
 
233
    * i386 uses generic tcgvecnode
 
234
 
 
235
  Revision 1.41  2002/08/11 14:32:30  peter
 
236
    * renamed current_library to objectlibrary
 
237
 
 
238
  Revision 1.40  2002/08/11 13:24:17  peter
 
239
    * saving of asmsymbols in ppu supported
 
240
    * asmsymbollist global is removed and moved into a new class
 
241
      tasmlibrarydata that will hold the info of a .a file which
 
242
      corresponds with a single module. Added librarydata to tmodule
 
243
      to keep the library info stored for the module. In the future the
 
244
      objectfiles will also be stored to the tasmlibrarydata class
 
245
    * all getlabel/newasmsymbol and friends are moved to the new class
 
246
 
 
247
  Revision 1.39  2002/07/28 21:34:31  florian
 
248
    * more powerpc fixes
 
249
    + dummy tcgvecnode
 
250
 
 
251
  Revision 1.38  2002/07/20 11:58:04  florian
 
252
    * types.pas renamed to defbase.pas because D6 contains a types
 
253
      unit so this would conflicts if D6 programms are compiled
 
254
    + Willamette/SSE2 instructions to assembler added
 
255
 
 
256
  Revision 1.37  2002/07/11 14:41:33  florian
 
257
    * start of the new generic parameter handling
 
258
 
 
259
  Revision 1.36  2002/07/07 09:52:34  florian
 
260
    * powerpc target fixed, very simple units can be compiled
 
261
    * some basic stuff for better callparanode handling, far from being finished
 
262
 
 
263
  Revision 1.35  2002/07/01 18:46:33  peter
 
264
    * internal linker
 
265
    * reorganized aasm layer
 
266
 
 
267
  Revision 1.34  2002/06/24 12:43:01  jonas
 
268
    * fixed errors found with new -CR code from Peter when cycling with -O2p3r
 
269
 
 
270
  Revision 1.33  2002/05/18 13:34:25  peter
 
271
    * readded missing revisions
 
272
 
 
273
  Revision 1.32  2002/05/16 19:46:51  carl
 
274
  + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
 
275
  + try to fix temp allocation (still in ifdef)
 
276
  + generic constructor calls
 
277
  + start of tassembler / tmodulebase class cleanup
 
278
 
 
279
  Revision 1.30  2002/05/13 19:54:38  peter
 
280
    * removed n386ld and n386util units
 
281
    * maybe_save/maybe_restore added instead of the old maybe_push
 
282
 
 
283
  Revision 1.29  2002/05/12 16:53:17  peter
 
284
    * moved entry and exitcode to ncgutil and cgobj
 
285
    * foreach gets extra argument for passing local data to the
 
286
      iterator function
 
287
    * -CR checks also class typecasts at runtime by changing them
 
288
      into as
 
289
    * fixed compiler to cycle with the -CR option
 
290
    * fixed stabs with elf writer, finally the global variables can
 
291
      be watched
 
292
    * removed a lot of routines from cga unit and replaced them by
 
293
      calls to cgobj
 
294
    * u32bit-s32bit updates for and,or,xor nodes. When one element is
 
295
      u32bit then the other is typecasted also to u32bit without giving
 
296
      a rangecheck warning/error.
 
297
    * fixed pascal calling method with reversing also the high tree in
 
298
      the parast, detected by tcalcst3 test
 
299
 
 
300
  Revision 1.28  2002/04/21 19:02:07  peter
 
301
    * removed newn and disposen nodes, the code is now directly
 
302
      inlined from pexpr
 
303
    * -an option that will write the secondpass nodes to the .s file, this
 
304
      requires EXTDEBUG define to actually write the info
 
305
    * fixed various internal errors and crashes due recent code changes
 
306
 
 
307
  Revision 1.27  2002/04/20 21:37:07  carl
 
308
  + generic FPC_CHECKPOINTER
 
309
  + first parameter offset in stack now portable
 
310
  * rename some constants
 
311
  + move some cpu stuff to other units
 
312
  - remove unused constents
 
313
  * fix stacksize for some targets
 
314
  * fix generic size problems which depend now on EXTEND_SIZE constant
 
315
  * removing frame pointer in routines is only available for : i386,m68k and vis targets
 
316
 
 
317
  Revision 1.26  2002/04/19 15:39:35  peter
 
318
    * removed some more routines from cga
 
319
    * moved location_force_reg/mem to ncgutil
 
320
    * moved arrayconstructnode secondpass to ncgld
 
321
 
 
322
  Revision 1.25  2002/04/15 19:12:09  carl
 
323
  + target_info.size_of_pointer -> pointer_size
 
324
  + some cleanup of unused types/variables
 
325
  * move several constants from cpubase to their specific units
 
326
    (where they are used)
 
327
  + att_Reg2str -> gas_reg2str
 
328
  + int_reg2str -> std_reg2str
 
329
 
 
330
  Revision 1.24  2002/04/04 19:06:12  peter
 
331
    * removed unused units
 
332
    * use tlocation.size in cg.a_*loc*() routines
 
333
 
 
334
  Revision 1.23  2002/04/02 17:11:36  peter
 
335
    * tlocation,treference update
 
336
    * LOC_CONSTANT added for better constant handling
 
337
    * secondadd splitted in multiple routines
 
338
    * location_force_reg added for loading a location to a register
 
339
      of a specified size
 
340
    * secondassignment parses now first the right and then the left node
 
341
      (this is compatible with Kylix). This saves a lot of push/pop especially
 
342
      with string operations
 
343
    * adapted some routines to use the new cg methods
 
344
 
 
345
}