| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 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/. */ |
| 6 |
|
| 7 |
#ifndef jit_CalleeToken_h |
| 8 |
#define jit_CalleeToken_h |
| 9 |
|
| 10 |
#include "mozilla/Assertions.h" |
| 11 |
|
| 12 |
#include <stdint.h> |
| 13 |
|
| 14 |
#include "js/TypeDecls.h" |
| 15 |
|
| 16 |
class JS_PUBLIC_API JSTracer; |
| 17 |
|
| 18 |
namespace js::jit { |
| 19 |
|
| 20 |
using CalleeToken = void*; |
| 21 |
|
| 22 |
enum CalleeTokenTag { |
| 23 |
CalleeToken_Function = 0x0, // untagged |
| 24 |
CalleeToken_FunctionConstructing = 0x1, |
| 25 |
CalleeToken_Script = 0x2 |
| 26 |
}; |
| 27 |
|
| 28 |
// Any CalleeToken with this bit set must be CalleeToken_Script. |
| 29 |
static const uintptr_t CalleeTokenScriptBit = CalleeToken_Script; |
| 30 |
|
| 31 |
static const uintptr_t CalleeTokenMask = ~uintptr_t(0x3); |
| 32 |
|
| 33 |
static inline CalleeTokenTag GetCalleeTokenTag(CalleeToken token) { |
| 34 |
CalleeTokenTag tag = CalleeTokenTag(uintptr_t(token) & 0x3); |
| 35 |
MOZ_ASSERT(tag <= CalleeToken_Script); |
| 36 |
return tag; |
| 37 |
} |
| 38 |
static inline CalleeToken CalleeToToken(JSFunction* fun, bool constructing) { |
| 39 |
CalleeTokenTag tag = |
| 40 |
constructing ? CalleeToken_FunctionConstructing : CalleeToken_Function; |
| 41 |
return CalleeToken(uintptr_t(fun) | uintptr_t(tag)); |
| 42 |
} |
| 43 |
static inline CalleeToken CalleeToToken(JSScript* script) { |
| 44 |
return CalleeToken(uintptr_t(script) | uintptr_t(CalleeToken_Script)); |
| 45 |
} |
| 46 |
static inline bool CalleeTokenIsFunction(CalleeToken token) { |
| 47 |
CalleeTokenTag tag = GetCalleeTokenTag(token); |
| 48 |
return tag == CalleeToken_Function || tag == CalleeToken_FunctionConstructing; |
| 49 |
} |
| 50 |
static inline bool CalleeTokenIsConstructing(CalleeToken token) { |
| 51 |
return GetCalleeTokenTag(token) == CalleeToken_FunctionConstructing; |
| 52 |
} |
| 53 |
static inline JSFunction* CalleeTokenToFunction(CalleeToken token) { |
| 54 |
MOZ_ASSERT(CalleeTokenIsFunction(token)); |
| 55 |
return (JSFunction*)(uintptr_t(token) & CalleeTokenMask); |
| 56 |
} |
| 57 |
static inline JSScript* CalleeTokenToScript(CalleeToken token) { |
| 58 |
MOZ_ASSERT(GetCalleeTokenTag(token) == CalleeToken_Script); |
| 59 |
return (JSScript*)(uintptr_t(token) & CalleeTokenMask); |
| 60 |
} |
| 61 |
|
| 62 |
CalleeToken TraceCalleeToken(JSTracer* trc, CalleeToken token); |
| 63 |
|
| 64 |
} /* namespace js::jit */ |
| 65 |
|
| 66 |
#endif /* jit_CalleeToken_h */ |