1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef jsopcodeinlines_h
8 #define jsopcodeinlines_h
16 static inline unsigned
17 GetDefCount(JSScript
* script
, unsigned offset
)
19 jsbytecode
* pc
= script
->offsetToPC(offset
);
22 * Add an extra pushed value for OR/AND opcodes, so that they are included
23 * in the pushed array of stack values for type inference.
31 * Pick pops and pushes how deep it looks in the stack + 1
32 * items. i.e. if the stack were |a b[2] c[1] d[0]|, pick 2
33 * would pop b, c, and d to rearrange the stack to |a c[0]
38 return StackDefs(script
, pc
);
42 static inline unsigned
43 GetUseCount(JSScript
* script
, unsigned offset
)
45 jsbytecode
* pc
= script
->offsetToPC(offset
);
47 if (JSOp(*pc
) == JSOP_PICK
)
49 if (js_CodeSpec
[*pc
].nuses
== -1)
50 return StackUses(script
, pc
);
51 return js_CodeSpec
[*pc
].nuses
;
55 ReverseCompareOp(JSOp op
)
72 MOZ_CRASH("unrecognized op");
77 NegateCompareOp(JSOp op
)
97 MOZ_CRASH("unrecognized op");
101 class BytecodeRange
{
103 BytecodeRange(JSContext
* cx
, JSScript
* script
)
104 : script(cx
, script
), pc(script
->code()), end(pc
+ script
->length())
106 bool empty() const { return pc
== end
; }
107 jsbytecode
* frontPC() const { return pc
; }
108 JSOp
frontOpcode() const { return JSOp(*pc
); }
109 size_t frontOffset() const { return script
->pcToOffset(pc
); }
110 void popFront() { pc
+= GetBytecodeLength(pc
); }
114 jsbytecode
* pc
, *end
;
119 #endif /* jsopcodeinlines_h */