1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsopcodeinlines.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef jsopcodeinlines_h 1.11 +#define jsopcodeinlines_h 1.12 + 1.13 +#include "jsopcode.h" 1.14 + 1.15 +#include "jsscript.h" 1.16 + 1.17 +namespace js { 1.18 + 1.19 +static inline unsigned 1.20 +GetDefCount(JSScript *script, unsigned offset) 1.21 +{ 1.22 + jsbytecode *pc = script->offsetToPC(offset); 1.23 + 1.24 + /* 1.25 + * Add an extra pushed value for OR/AND opcodes, so that they are included 1.26 + * in the pushed array of stack values for type inference. 1.27 + */ 1.28 + switch (JSOp(*pc)) { 1.29 + case JSOP_OR: 1.30 + case JSOP_AND: 1.31 + return 1; 1.32 + case JSOP_PICK: 1.33 + /* 1.34 + * Pick pops and pushes how deep it looks in the stack + 1 1.35 + * items. i.e. if the stack were |a b[2] c[1] d[0]|, pick 2 1.36 + * would pop b, c, and d to rearrange the stack to |a c[0] 1.37 + * d[1] b[2]|. 1.38 + */ 1.39 + return pc[1] + 1; 1.40 + default: 1.41 + return StackDefs(script, pc); 1.42 + } 1.43 +} 1.44 + 1.45 +static inline unsigned 1.46 +GetUseCount(JSScript *script, unsigned offset) 1.47 +{ 1.48 + jsbytecode *pc = script->offsetToPC(offset); 1.49 + 1.50 + if (JSOp(*pc) == JSOP_PICK) 1.51 + return pc[1] + 1; 1.52 + if (js_CodeSpec[*pc].nuses == -1) 1.53 + return StackUses(script, pc); 1.54 + return js_CodeSpec[*pc].nuses; 1.55 +} 1.56 + 1.57 +static inline JSOp 1.58 +ReverseCompareOp(JSOp op) 1.59 +{ 1.60 + switch (op) { 1.61 + case JSOP_GT: 1.62 + return JSOP_LT; 1.63 + case JSOP_GE: 1.64 + return JSOP_LE; 1.65 + case JSOP_LT: 1.66 + return JSOP_GT; 1.67 + case JSOP_LE: 1.68 + return JSOP_GE; 1.69 + case JSOP_EQ: 1.70 + case JSOP_NE: 1.71 + case JSOP_STRICTEQ: 1.72 + case JSOP_STRICTNE: 1.73 + return op; 1.74 + default: 1.75 + MOZ_ASSUME_UNREACHABLE("unrecognized op"); 1.76 + } 1.77 +} 1.78 + 1.79 +static inline JSOp 1.80 +NegateCompareOp(JSOp op) 1.81 +{ 1.82 + switch (op) { 1.83 + case JSOP_GT: 1.84 + return JSOP_LE; 1.85 + case JSOP_GE: 1.86 + return JSOP_LT; 1.87 + case JSOP_LT: 1.88 + return JSOP_GE; 1.89 + case JSOP_LE: 1.90 + return JSOP_GT; 1.91 + case JSOP_EQ: 1.92 + return JSOP_NE; 1.93 + case JSOP_NE: 1.94 + return JSOP_EQ; 1.95 + case JSOP_STRICTNE: 1.96 + return JSOP_STRICTEQ; 1.97 + case JSOP_STRICTEQ: 1.98 + return JSOP_STRICTNE; 1.99 + default: 1.100 + MOZ_ASSUME_UNREACHABLE("unrecognized op"); 1.101 + } 1.102 +} 1.103 + 1.104 +class BytecodeRange { 1.105 + public: 1.106 + BytecodeRange(JSContext *cx, JSScript *script) 1.107 + : script(cx, script), pc(script->code()), end(pc + script->length()) 1.108 + {} 1.109 + bool empty() const { return pc == end; } 1.110 + jsbytecode *frontPC() const { return pc; } 1.111 + JSOp frontOpcode() const { return JSOp(*pc); } 1.112 + size_t frontOffset() const { return script->pcToOffset(pc); } 1.113 + void popFront() { pc += GetBytecodeLength(pc); } 1.114 + 1.115 + private: 1.116 + RootedScript script; 1.117 + jsbytecode *pc, *end; 1.118 +}; 1.119 + 1.120 +} 1.121 + 1.122 +#endif /* jsopcodeinlines_h */