Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / eval / eval-cogen-inlines.h
blobbc4d46b3928b646244d9d7738becb750189cd4fc
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2008
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * 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 // This file is included into eval.h
41 namespace avmplus {
42 namespace RTC {
44 inline bool Ctx::mustPushThis() { return tag == CTX_ClassMethod || tag == CTX_Program; }
45 inline bool Ctx::mustPushScopeReg() { return tag == CTX_With || tag == CTX_Catch || tag == CTX_Activation; }
47 inline uint32_t FinallyCtx::addReturnLabel(Label* l)
49 returnLabels.addAtEnd(l);
50 return nextLabel++;
53 inline uint32_t Cogen::emitInt(int32_t i) { return abc->addInt(i); }
54 inline uint32_t Cogen::emitUInt(uint32_t u) { return abc->addUInt(u); }
55 inline uint32_t Cogen::emitDouble(double d) { return abc->addDouble(d); }
56 inline uint32_t Cogen::emitString(Str* str) { return abc->addString(str); }
57 inline uint32_t Cogen::emitSlotTrait(uint32_t name, uint32_t type) { return traits->addTrait(ALLOC(ABCSlotTrait, (name, type, TRAIT_Slot))); }
58 inline uint32_t Cogen::emitConstTrait(uint32_t name, uint32_t type) { return traits->addTrait(ALLOC(ABCSlotTrait, (name, type, TRAIT_Const))); }
59 inline uint32_t Cogen::emitMethodTrait(uint32_t name, uint32_t method) { return traits->addTrait(ALLOC(ABCMethodTrait, (name, method))); }
60 inline uint32_t Cogen::emitNamespace(uint32_t name) { return abc->addNamespace(CONSTANT_Namespace, name); }
62 inline uint32_t Cogen::getTemp()
64 return temp_counter++;
67 inline uint32_t Cogen::getMaxStack() const { return max_stack_depth; }
68 inline uint32_t Cogen::getMaxScope() const { return scope_depth; }
69 inline uint32_t Cogen::getLocalCount() const { return temp_counter; }
70 inline uint32_t Cogen::getCodeLength() const { return code.size(); }
72 inline void Cogen::startCatch()
74 stack_depth = 1;
75 if (stack_depth > max_stack_depth)
76 max_stack_depth = stack_depth;
79 inline uint8_t Cogen::getFlags() const
81 return traits->getCount() > 0 ? abcMethod_NEED_ACTIVATION : 0;
84 inline AbcOpcode Cogen::binopToOpcode(Binop op, bool* isNegated)
86 *isNegated = binopMapping[op].isNegated;
87 return (AbcOpcode)(binopMapping[op].abcOpcode);
90 inline void Cogen::I_add() { emitOp(OP_add); }
91 inline void Cogen::I_add_i() { emitOp(OP_add_i); }
92 inline void Cogen::I_astype(uint32_t index) { emitOpU30(OP_astype, index); }
93 inline void Cogen::I_astypelate() { emitOp(OP_astypelate); }
94 inline void Cogen::I_bitand() { emitOp(OP_bitand); }
95 inline void Cogen::I_bitnot() { emitOp(OP_bitnot); }
96 inline void Cogen::I_bitor() { emitOp(OP_bitor); }
97 inline void Cogen::I_bitxor() { emitOp(OP_bitxor); }
98 inline void Cogen::I_checkfilter() { emitOp(OP_checkfilter); }
99 inline void Cogen::I_coerce(uint32_t index) { emitOpU30(OP_coerce, index); }
100 inline void Cogen::I_coerce_a() { emitOp(OP_coerce_a); }
101 inline void Cogen::I_coerce_s() { emitOp(OP_coerce_s); }
102 inline void Cogen::I_coerce_b() { emitOp(OP_coerce_b); }
103 inline void Cogen::I_coerce_d() { emitOp(OP_coerce_d); }
104 inline void Cogen::I_coerce_i() { emitOp(OP_coerce_i); }
105 inline void Cogen::I_coerce_u() { emitOp(OP_coerce_u); }
106 inline void Cogen::I_convert_o() { emitOp(OP_convert_o); }
107 inline void Cogen::I_convert_s() { emitOp(OP_convert_s); }
108 inline void Cogen::I_declocal(uint32_t reg) { emitOpU30(OP_declocal, reg); }
109 inline void Cogen::I_declocal_i(uint32_t reg) { emitOpU30(OP_declocal_i, reg); }
110 inline void Cogen::I_decrement() { emitOp(OP_decrement); }
111 inline void Cogen::I_decrement_i() { emitOp(OP_decrement_i); }
112 inline void Cogen::I_divide() { emitOp(OP_divide); }
113 inline void Cogen::I_dup() { emitOp(OP_dup); }
114 inline void Cogen::I_dxns(uint32_t index) { emitOpU30(OP_dxns, index); }
115 inline void Cogen::I_dxnslate() { sets_dxns=true; emitOp(OP_dxnslate); }
116 inline void Cogen::I_equals() { emitOp(OP_equals); }
117 inline void Cogen::I_esc_xattr() { emitOp(OP_esc_xattr); }
118 inline void Cogen::I_esc_xelem() { emitOp(OP_esc_xelem); }
119 inline void Cogen::I_getglobalscope() { emitOp(OP_getglobalscope); }
120 inline void Cogen::I_getglobalslot(uint32_t index) { emitOpU30(OP_getglobalslot, index); }
121 inline void Cogen::I_getlex(uint32_t index) { emitOpU30(OP_getlex, index); }
122 inline void Cogen::I_getouterscope(uint32_t index) { emitOpU30(OP_getouterscope, index); }
123 inline void Cogen::I_getscopeobject(uint32_t index) { emitOpU30(OP_getscopeobject, index); }
124 inline void Cogen::I_getslot(uint32_t index) { emitOpU30(OP_getslot, index); }
125 inline void Cogen::I_greaterequals() { emitOp(OP_greaterequals); }
126 inline void Cogen::I_greaterthan() { emitOp(OP_greaterthan); }
127 inline void Cogen::I_hasnext() { emitOp(OP_hasnext); }
128 inline void Cogen::I_ifeq(Label* label) { emitJump(OP_ifeq, label); }
129 inline void Cogen::I_iffalse(Label* label) { emitJump(OP_iffalse, label); }
130 inline void Cogen::I_ifge(Label* label) { emitJump(OP_ifge, label); }
131 inline void Cogen::I_ifgt(Label* label) { emitJump(OP_ifgt, label); }
132 inline void Cogen::I_ifle(Label* label) { emitJump(OP_ifle, label); }
133 inline void Cogen::I_iflt(Label* label) { emitJump(OP_iflt, label); }
134 inline void Cogen::I_ifne(Label* label) { emitJump(OP_ifne, label); }
135 inline void Cogen::I_ifnge(Label* label) { emitJump(OP_ifnge, label); }
136 inline void Cogen::I_ifngt(Label* label) { emitJump(OP_ifngt, label); }
137 inline void Cogen::I_ifnle(Label* label) { emitJump(OP_ifnle, label); }
138 inline void Cogen::I_ifnlt(Label* label) { emitJump(OP_ifnlt, label); }
139 inline void Cogen::I_ifstricteq(Label* label) { emitJump(OP_ifstricteq, label); }
140 inline void Cogen::I_ifstrictne(Label* label) { emitJump(OP_ifstrictne, label); }
141 inline void Cogen::I_iftrue(Label* label) { emitJump(OP_iftrue, label); }
142 inline void Cogen::I_in() { emitOp(OP_in); }
143 inline void Cogen::I_inclocal(uint32_t reg) { emitOpU30(OP_inclocal, reg); }
144 inline void Cogen::I_inclocal_i(uint32_t reg) { emitOpU30(OP_inclocal_i, reg); }
145 inline void Cogen::I_increment() { emitOp(OP_increment); }
146 inline void Cogen::I_increment_i() { emitOp(OP_increment_i); }
147 inline void Cogen::I_instanceof() { emitOp(OP_instanceof); }
148 inline void Cogen::I_istype(uint32_t index) { emitOpU30(OP_istype, index); }
149 inline void Cogen::I_istypelate() { emitOp(OP_istypelate); }
150 inline void Cogen::I_jump(Label* label) { emitJump(OP_jump, label); }
151 inline void Cogen::I_kill(uint32_t index) { emitOpU30(OP_kill, index); }
152 inline void Cogen::I_lessequals() { emitOp(OP_lessequals); }
153 inline void Cogen::I_lessthan() { emitOp(OP_lessthan); }
154 inline void Cogen::I_lshift() { emitOp(OP_lshift); }
155 inline void Cogen::I_modulo() { emitOp(OP_modulo); }
156 inline void Cogen::I_multiply() { emitOp(OP_multiply); }
157 inline void Cogen::I_multiply_i() { emitOp(OP_multiply_i); }
158 inline void Cogen::I_negate() { emitOp(OP_negate); }
159 inline void Cogen::I_negate_i() { emitOp(OP_negate_i); }
160 inline void Cogen::I_newactivation() { need_activation=true; emitOp(OP_newactivation); }
161 inline void Cogen::I_newcatch(uint32_t index) { emitOpU30(OP_newcatch, index); }
162 inline void Cogen::I_newclass(uint32_t index) { emitOpU30(OP_newclass, index); }
163 inline void Cogen::I_newfunction(uint32_t index) { emitOpU30(OP_newfunction, index); }
164 inline void Cogen::I_nextname() { emitOp(OP_nextname); }
165 inline void Cogen::I_nextvalue() { emitOp(OP_nextvalue); }
166 inline void Cogen::I_nop() { emitOp(OP_nop); }
167 inline void Cogen::I_not() { emitOp(OP_not); }
168 inline void Cogen::I_pop() { emitOp(OP_pop); }
169 inline void Cogen::I_popscope() { emitOp(OP_popscope); }
170 inline void Cogen::I_pushdouble(uint32_t index) { emitOpU30(OP_pushdouble, index); }
171 inline void Cogen::I_pushfalse() { emitOp(OP_pushfalse); }
172 inline void Cogen::I_pushint(uint32_t index) { emitOpU30(OP_pushint, index); }
173 inline void Cogen::I_pushnamespace(uint32_t index) { emitOpU30(OP_pushnamespace, index); }
174 inline void Cogen::I_pushnan() { emitOp(OP_pushnan); }
175 inline void Cogen::I_pushnull() { emitOp(OP_pushnull); }
176 inline void Cogen::I_pushscope() { scope_depth++; emitOp(OP_pushscope); }
177 inline void Cogen::I_pushshort(int16_t v) { emitOpS16(OP_pushshort, v); }
178 inline void Cogen::I_pushstring(uint32_t index) { emitOpU30(OP_pushstring, index); }
179 inline void Cogen::I_pushtrue() { emitOp(OP_pushtrue); }
180 inline void Cogen::I_pushuint(uint32_t index) { emitOpU30(OP_pushuint, index); }
181 inline void Cogen::I_pushundefined() { emitOp(OP_pushundefined); }
182 inline void Cogen::I_pushwith() { scope_depth++; emitOp(OP_pushwith); }
183 inline void Cogen::I_returnvalue() { emitOp(OP_returnvalue); }
184 inline void Cogen::I_returnvoid() { emitOp(OP_returnvoid); }
185 inline void Cogen::I_rshift() { emitOp(OP_rshift); }
186 inline void Cogen::I_setglobalslot(uint32_t index) { emitOpU30(OP_setglobalslot, index); }
187 inline void Cogen::I_strictequals() { emitOp(OP_strictequals); }
188 inline void Cogen::I_subtract() { emitOp(OP_subtract); }
189 inline void Cogen::I_subtract_i() { emitOp(OP_subtract_i); }
190 inline void Cogen::I_swap() { emitOp(OP_swap); }
191 inline void Cogen::I_throw() { emitOp(OP_throw); }
192 inline void Cogen::I_typeof() { emitOp(OP_typeof); }
193 inline void Cogen::I_urshift() { emitOp(OP_urshift); }
195 inline void Cogen::I_call(uint32_t nargs) { emitOpU30(OP_call, nargs); }
196 inline void Cogen::I_construct(uint32_t nargs) { emitOpU30(OP_construct, nargs); }
197 inline void Cogen::I_constructsuper(uint32_t nargs) { emitOpU30(OP_constructsuper, nargs); }
199 inline void Cogen::I_callmethod(uint32_t index, uint32_t nargs) { emitOpU30U30(OP_callmethod, index, nargs); }
200 inline void Cogen::I_callstatic(uint32_t index, uint32_t nargs) { emitOpU30U30(OP_callstatic, index, nargs); }
202 inline void Cogen::I_callsuper(uint32_t index, uint32_t nargs) { callMN(OP_callsuper, index, nargs); }
203 inline void Cogen::I_callproperty(uint32_t index, uint32_t nargs) { callMN(OP_callproperty, index, nargs); }
204 inline void Cogen::I_constructprop(uint32_t index, uint32_t nargs) { callMN(OP_constructprop, index, nargs); }
205 inline void Cogen::I_callproplex(uint32_t index, uint32_t nargs) { callMN(OP_callproplex, index, nargs); }
206 inline void Cogen::I_callsupervoid(uint32_t index, uint32_t nargs) { callMN(OP_callsupervoid, index, nargs); }
207 inline void Cogen::I_callpropvoid(uint32_t index, uint32_t nargs) { callMN(OP_callpropvoid, index, nargs); }
209 inline void Cogen::I_deleteproperty(uint32_t index) { propU30(OP_deleteproperty, index); }
210 inline void Cogen::I_getdescendants(uint32_t index) { propU30(OP_getdescendants, index); }
211 inline void Cogen::I_getproperty(uint32_t index) { propU30(OP_getproperty, index);; }
212 inline void Cogen::I_getsuper(uint32_t index) { propU30(OP_getsuper, index);; }
213 inline void Cogen::I_findproperty(uint32_t index) { propU30(OP_findproperty, index); }
214 inline void Cogen::I_findpropstrict(uint32_t index) { propU30(OP_findpropstrict, index); }
215 inline void Cogen::I_initproperty(uint32_t index) { propU30(OP_initproperty, index); }
216 inline void Cogen::I_setproperty(uint32_t index) { propU30(OP_setproperty, index); }
217 inline void Cogen::I_setsuper(uint32_t index) { propU30(OP_setsuper, index); }
219 inline void Cogen::I_hasnext2(uint32_t object_reg, uint32_t index_reg) { emitOpU30U30(OP_hasnext2, object_reg, index_reg); }
221 inline void Cogen::I_newarray(uint32_t nargs) { emitOpU30Special(OP_newarray, nargs, nargs); }
222 inline void Cogen::I_newobject(uint32_t nargs) { emitOpU30Special(OP_newobject, nargs, 2*nargs); }
224 inline void Cogen::I_pushbyte(int8_t b) { emitOpS8(OP_pushbyte, b); }
226 inline void Cogen::I_setslot(uint32_t index) { emitOpU30(OP_setslot, index); }
227 inline void Cogen::I_opcode(AbcOpcode opcode) { emitOp(opcode); }