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/. */
7 #ifndef jit_CalleeToken_h
8 #define jit_CalleeToken_h
10 #include "mozilla/Assertions.h"
14 #include "js/TypeDecls.h"
16 class JS_PUBLIC_API JSTracer
;
20 using CalleeToken
= void*;
23 CalleeToken_Function
= 0x0, // untagged
24 CalleeToken_FunctionConstructing
= 0x1,
25 CalleeToken_Script
= 0x2
28 // Any CalleeToken with this bit set must be CalleeToken_Script.
29 static const uintptr_t CalleeTokenScriptBit
= CalleeToken_Script
;
31 static const uintptr_t CalleeTokenMask
= ~uintptr_t(0x3);
33 static inline CalleeTokenTag
GetCalleeTokenTag(CalleeToken token
) {
34 CalleeTokenTag tag
= CalleeTokenTag(uintptr_t(token
) & 0x3);
35 MOZ_ASSERT(tag
<= CalleeToken_Script
);
38 static inline CalleeToken
CalleeToToken(JSFunction
* fun
, bool constructing
) {
40 constructing
? CalleeToken_FunctionConstructing
: CalleeToken_Function
;
41 return CalleeToken(uintptr_t(fun
) | uintptr_t(tag
));
43 static inline CalleeToken
CalleeToToken(JSScript
* script
) {
44 return CalleeToken(uintptr_t(script
) | uintptr_t(CalleeToken_Script
));
46 static inline bool CalleeTokenIsFunction(CalleeToken token
) {
47 CalleeTokenTag tag
= GetCalleeTokenTag(token
);
48 return tag
== CalleeToken_Function
|| tag
== CalleeToken_FunctionConstructing
;
50 static inline bool CalleeTokenIsConstructing(CalleeToken token
) {
51 return GetCalleeTokenTag(token
) == CalleeToken_FunctionConstructing
;
53 static inline JSFunction
* CalleeTokenToFunction(CalleeToken token
) {
54 MOZ_ASSERT(CalleeTokenIsFunction(token
));
55 return (JSFunction
*)(uintptr_t(token
) & CalleeTokenMask
);
57 static inline JSScript
* CalleeTokenToScript(CalleeToken token
) {
58 MOZ_ASSERT(GetCalleeTokenTag(token
) == CalleeToken_Script
);
59 return (JSScript
*)(uintptr_t(token
) & CalleeTokenMask
);
62 CalleeToken
TraceCalleeToken(JSTracer
* trc
, CalleeToken token
);
64 } /* namespace js::jit */
66 #endif /* jit_CalleeToken_h */