1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
20 * The Initial Developer of the Original Code is
21 * Brendan Eich <brendan@mozilla.org>
24 * David Anderson <danderson@mozilla.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #if !defined jsjaeger_inl_frame_asm_h__ && defined JS_METHODJIT && defined JS_MONOIC
41 #define jsjaeger_inl_frame_asm_h__
43 #include "assembler/assembler/MacroAssembler.h"
44 #include "assembler/assembler/CodeLocation.h"
45 #include "methodjit/MethodJIT.h"
46 #include "CodeGenIncludes.h"
51 struct AdjustedFrame
{
52 AdjustedFrame(uint32 baseOffset
)
53 : baseOffset(baseOffset
)
58 JSC::MacroAssembler::Address
addrOf(uint32 offset
) {
59 return JSC::MacroAssembler::Address(JSFrameReg
, baseOffset
+ offset
);
64 * This is used for emitting code to inline callee-side frame creation and
65 * should jit code equivalent to JSStackFrame::initCallFrameCallerHalf.
67 * Once finished, JSFrameReg is advanced to be the new fp.
69 class InlineFrameAssembler
{
70 typedef JSC::MacroAssembler::RegisterID RegisterID
;
71 typedef JSC::MacroAssembler::Address Address
;
72 typedef JSC::MacroAssembler::Imm32 Imm32
;
73 typedef JSC::MacroAssembler::ImmPtr ImmPtr
;
74 typedef JSC::MacroAssembler::DataLabelPtr DataLabelPtr
;
77 uint32 frameDepth
; // script->nfixed + stack depth at caller call site
78 uint32 argc
; // number of args being passed to the function
79 RegisterID funObjReg
; // register containing the function object (callee)
80 jsbytecode
*pc
; // bytecode location at the caller call site
81 uint32 flags
; // frame flags
85 * Register state, so consumers of this class can restrict which registers
86 * can and can't be clobbered.
90 InlineFrameAssembler(Assembler
&masm
, ic::CallICInfo
&ic
, uint32 flags
)
91 : masm(masm
), pc(ic
.pc
), flags(flags
)
93 frameDepth
= ic
.frameDepth
;
95 funObjReg
= ic
.funObjReg
;
96 tempRegs
.takeReg(ic
.funPtrReg
);
97 tempRegs
.takeReg(funObjReg
);
100 InlineFrameAssembler(Assembler
&masm
, Compiler::CallGenInfo
&gen
, uint32 flags
)
101 : masm(masm
), pc(gen
.pc
), flags(flags
)
103 frameDepth
= gen
.frameDepth
;
105 funObjReg
= gen
.funObjReg
;
106 tempRegs
.takeReg(funObjReg
);
109 DataLabelPtr
assemble(void *ncode
)
111 JS_ASSERT((flags
& ~JSFRAME_CONSTRUCTING
) == 0);
113 RegisterID t0
= tempRegs
.takeAnyReg();
115 AdjustedFrame
adj(sizeof(JSStackFrame
) + frameDepth
* sizeof(Value
));
116 masm
.store32(Imm32(JSFRAME_FUNCTION
| flags
), adj
.addrOf(JSStackFrame::offsetOfFlags()));
117 masm
.storePtr(JSFrameReg
, adj
.addrOf(JSStackFrame::offsetOfPrev()));
119 DataLabelPtr ncodePatch
=
120 masm
.storePtrWithPatch(ImmPtr(ncode
), adj
.addrOf(JSStackFrame::offsetOfncode()));
122 /* Adjust JSFrameReg. Callee fills in the rest. */
123 masm
.addPtr(Imm32(sizeof(JSStackFrame
) + sizeof(Value
) * frameDepth
), JSFrameReg
);
132 } /* namespace mjit */
135 #endif /* jsjaeger_inl_frame_asm_h__ */