2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef MacroAssembler_h
27 #define MacroAssembler_h
32 #include "MacroAssemblerARMv7.h"
33 namespace JSC
{ typedef MacroAssemblerARMv7 MacroAssemblerBase
; };
35 #elif CPU(ARM_TRADITIONAL)
36 #include "MacroAssemblerARM.h"
37 namespace JSC
{ typedef MacroAssemblerARM MacroAssemblerBase
; };
40 #include "MacroAssemblerMIPS.h"
42 typedef MacroAssemblerMIPS MacroAssemblerBase
;
46 #include "MacroAssemblerX86.h"
47 namespace JSC
{ typedef MacroAssemblerX86 MacroAssemblerBase
; };
50 #include "MacroAssemblerX86_64.h"
51 namespace JSC
{ typedef MacroAssemblerX86_64 MacroAssemblerBase
; };
54 #error "The MacroAssembler is not supported on this platform."
60 class MacroAssembler
: public MacroAssemblerBase
{
63 using MacroAssemblerBase::pop
;
64 using MacroAssemblerBase::jump
;
65 using MacroAssemblerBase::branch32
;
66 using MacroAssemblerBase::branch16
;
68 using MacroAssemblerBase::branchPtr
;
69 using MacroAssemblerBase::branchTestPtr
;
73 // Platform agnostic onvenience functions,
74 // described in terms of other macro assembly methods.
77 addPtr(Imm32(sizeof(void*)), stackPointerRegister
);
80 void peek(RegisterID dest
, int index
= 0)
82 loadPtr(Address(stackPointerRegister
, (index
* sizeof(void*))), dest
);
85 void poke(RegisterID src
, int index
= 0)
87 storePtr(src
, Address(stackPointerRegister
, (index
* sizeof(void*))));
90 void poke(Imm32 value
, int index
= 0)
92 store32(value
, Address(stackPointerRegister
, (index
* sizeof(void*))));
95 void poke(ImmPtr imm
, int index
= 0)
97 storePtr(imm
, Address(stackPointerRegister
, (index
* sizeof(void*))));
101 // Backwards banches, these are currently all implemented using existing forwards branch mechanisms.
102 void branchPtr(Condition cond
, RegisterID op1
, ImmPtr imm
, Label target
)
104 branchPtr(cond
, op1
, imm
).linkTo(target
, this);
107 void branch32(Condition cond
, RegisterID op1
, RegisterID op2
, Label target
)
109 branch32(cond
, op1
, op2
).linkTo(target
, this);
112 void branch32(Condition cond
, RegisterID op1
, Imm32 imm
, Label target
)
114 branch32(cond
, op1
, imm
).linkTo(target
, this);
117 void branch32(Condition cond
, RegisterID left
, Address right
, Label target
)
119 branch32(cond
, left
, right
).linkTo(target
, this);
122 void branch16(Condition cond
, BaseIndex left
, RegisterID right
, Label target
)
124 branch16(cond
, left
, right
).linkTo(target
, this);
127 void branchTestPtr(Condition cond
, RegisterID reg
, Label target
)
129 branchTestPtr(cond
, reg
).linkTo(target
, this);
132 void jump(Label target
)
134 jump().linkTo(target
, this);
139 // On 32-bit platforms (i.e. x86), these methods directly map onto their 32-bit equivalents.
140 // FIXME: should this use a test for 32-bitness instead of this specific exception?
142 void addPtr(RegisterID src
, RegisterID dest
)
147 void addPtr(Imm32 imm
, RegisterID srcDest
)
152 void addPtr(ImmPtr imm
, RegisterID dest
)
154 add32(Imm32(imm
), dest
);
157 void addPtr(Imm32 imm
, RegisterID src
, RegisterID dest
)
159 add32(imm
, src
, dest
);
162 void andPtr(RegisterID src
, RegisterID dest
)
167 void andPtr(Imm32 imm
, RegisterID srcDest
)
172 void orPtr(RegisterID src
, RegisterID dest
)
177 void orPtr(ImmPtr imm
, RegisterID dest
)
179 or32(Imm32(imm
), dest
);
182 void orPtr(Imm32 imm
, RegisterID dest
)
187 void subPtr(RegisterID src
, RegisterID dest
)
192 void subPtr(Imm32 imm
, RegisterID dest
)
197 void subPtr(ImmPtr imm
, RegisterID dest
)
199 sub32(Imm32(imm
), dest
);
202 void xorPtr(RegisterID src
, RegisterID dest
)
207 void xorPtr(Imm32 imm
, RegisterID srcDest
)
213 void loadPtr(ImplicitAddress address
, RegisterID dest
)
215 load32(address
, dest
);
218 void loadPtr(BaseIndex address
, RegisterID dest
)
220 load32(address
, dest
);
223 void loadPtr(void* address
, RegisterID dest
)
225 load32(address
, dest
);
228 DataLabel32
loadPtrWithAddressOffsetPatch(Address address
, RegisterID dest
)
230 return load32WithAddressOffsetPatch(address
, dest
);
233 void setPtr(Condition cond
, RegisterID left
, Imm32 right
, RegisterID dest
)
235 set32(cond
, left
, right
, dest
);
238 void storePtr(RegisterID src
, ImplicitAddress address
)
240 store32(src
, address
);
243 void storePtr(RegisterID src
, BaseIndex address
)
245 store32(src
, address
);
248 void storePtr(RegisterID src
, void* address
)
250 store32(src
, address
);
253 void storePtr(ImmPtr imm
, ImplicitAddress address
)
255 store32(Imm32(imm
), address
);
258 void storePtr(ImmPtr imm
, void* address
)
260 store32(Imm32(imm
), address
);
263 DataLabel32
storePtrWithAddressOffsetPatch(RegisterID src
, Address address
)
265 return store32WithAddressOffsetPatch(src
, address
);
269 Jump
branchPtr(Condition cond
, RegisterID left
, RegisterID right
)
271 return branch32(cond
, left
, right
);
274 Jump
branchPtr(Condition cond
, RegisterID left
, ImmPtr right
)
276 return branch32(cond
, left
, Imm32(right
));
279 Jump
branchPtr(Condition cond
, RegisterID left
, Address right
)
281 return branch32(cond
, left
, right
);
284 Jump
branchPtr(Condition cond
, Address left
, RegisterID right
)
286 return branch32(cond
, left
, right
);
289 Jump
branchPtr(Condition cond
, AbsoluteAddress left
, RegisterID right
)
291 return branch32(cond
, left
, right
);
294 Jump
branchPtr(Condition cond
, Address left
, ImmPtr right
)
296 return branch32(cond
, left
, Imm32(right
));
299 Jump
branchPtr(Condition cond
, AbsoluteAddress left
, ImmPtr right
)
301 return branch32(cond
, left
, Imm32(right
));
304 Jump
branchTestPtr(Condition cond
, RegisterID reg
, RegisterID mask
)
306 return branchTest32(cond
, reg
, mask
);
309 Jump
branchTestPtr(Condition cond
, RegisterID reg
, Imm32 mask
= Imm32(-1))
311 return branchTest32(cond
, reg
, mask
);
314 Jump
branchTestPtr(Condition cond
, Address address
, Imm32 mask
= Imm32(-1))
316 return branchTest32(cond
, address
, mask
);
319 Jump
branchTestPtr(Condition cond
, BaseIndex address
, Imm32 mask
= Imm32(-1))
321 return branchTest32(cond
, address
, mask
);
325 Jump
branchAddPtr(Condition cond
, RegisterID src
, RegisterID dest
)
327 return branchAdd32(cond
, src
, dest
);
330 Jump
branchSubPtr(Condition cond
, Imm32 imm
, RegisterID dest
)
332 return branchSub32(cond
, imm
, dest
);
334 using MacroAssemblerBase::branchTest8
;
335 Jump
branchTest8(Condition cond
, ExtendedAddress address
, Imm32 mask
= Imm32(-1))
337 return MacroAssemblerBase::branchTest8(cond
, Address(address
.base
, address
.offset
), mask
);
345 #endif // ENABLE(ASSEMBLER)
347 #endif // MacroAssembler_h