Bumping manifests a=b2g-bump
[gecko.git] / js / src / jsopcodeinlines.h
blob3825a0ac55e2e636be901909465e0a05e7c9be52
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
10 #include "jsopcode.h"
12 #include "jsscript.h"
14 namespace js {
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.
25 switch (JSOp(*pc)) {
26 case JSOP_OR:
27 case JSOP_AND:
28 return 1;
29 case JSOP_PICK:
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]
34 * d[1] b[2]|.
36 return pc[1] + 1;
37 default:
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)
48 return pc[1] + 1;
49 if (js_CodeSpec[*pc].nuses == -1)
50 return StackUses(script, pc);
51 return js_CodeSpec[*pc].nuses;
54 static inline JSOp
55 ReverseCompareOp(JSOp op)
57 switch (op) {
58 case JSOP_GT:
59 return JSOP_LT;
60 case JSOP_GE:
61 return JSOP_LE;
62 case JSOP_LT:
63 return JSOP_GT;
64 case JSOP_LE:
65 return JSOP_GE;
66 case JSOP_EQ:
67 case JSOP_NE:
68 case JSOP_STRICTEQ:
69 case JSOP_STRICTNE:
70 return op;
71 default:
72 MOZ_CRASH("unrecognized op");
76 static inline JSOp
77 NegateCompareOp(JSOp op)
79 switch (op) {
80 case JSOP_GT:
81 return JSOP_LE;
82 case JSOP_GE:
83 return JSOP_LT;
84 case JSOP_LT:
85 return JSOP_GE;
86 case JSOP_LE:
87 return JSOP_GT;
88 case JSOP_EQ:
89 return JSOP_NE;
90 case JSOP_NE:
91 return JSOP_EQ;
92 case JSOP_STRICTNE:
93 return JSOP_STRICTEQ;
94 case JSOP_STRICTEQ:
95 return JSOP_STRICTNE;
96 default:
97 MOZ_CRASH("unrecognized op");
101 class BytecodeRange {
102 public:
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); }
112 private:
113 RootedScript script;
114 jsbytecode* pc, *end;
119 #endif /* jsopcodeinlines_h */