1/*
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef LLIntData_h
27#define LLIntData_h
28
29#include "JSCJSValue.h"
30#include "Opcode.h"
31#include <wtf/Platform.h>
32
33namespace JSC {
34
35class VM;
36struct Instruction;
37
38#if ENABLE(LLINT_C_LOOP)
39typedef OpcodeID LLIntCode;
40#else
41typedef void (*LLIntCode)();
42#endif
43
44namespace LLInt {
45
46#if ENABLE(LLINT)
47
48class Data {
49public:
50    static void performAssertions(VM&);
51
52private:
53    static Instruction* s_exceptionInstructions;
54    static Opcode* s_opcodeMap;
55
56    friend void initialize();
57
58    friend Instruction* exceptionInstructions();
59    friend Opcode* opcodeMap();
60    friend Opcode getOpcode(OpcodeID);
61    friend void* getCodePtr(OpcodeID);
62};
63
64void initialize();
65
66inline Instruction* exceptionInstructions()
67{
68    return Data::s_exceptionInstructions;
69}
70
71inline Opcode* opcodeMap()
72{
73    return Data::s_opcodeMap;
74}
75
76inline Opcode getOpcode(OpcodeID id)
77{
78#if ENABLE(COMPUTED_GOTO_OPCODES)
79    return Data::s_opcodeMap[id];
80#else
81    return static_cast<Opcode>(id);
82#endif
83}
84
85ALWAYS_INLINE void* getCodePtr(OpcodeID id)
86{
87    return reinterpret_cast<void*>(getOpcode(id));
88}
89
90#else // !ENABLE(LLINT)
91
92#if COMPILER(CLANG)
93#pragma clang diagnostic push
94#pragma clang diagnostic ignored "-Wmissing-noreturn"
95#endif
96
97class Data {
98public:
99    static void performAssertions(VM&) { }
100};
101
102#if COMPILER(CLANG)
103#pragma clang diagnostic pop
104#endif
105
106#endif // !ENABLE(LLINT)
107
108ALWAYS_INLINE void* getOpcode(void llintOpcode())
109{
110    return bitwise_cast<void*>(llintOpcode);
111}
112
113ALWAYS_INLINE void* getCodePtr(void glueHelper())
114{
115    return bitwise_cast<void*>(glueHelper);
116}
117
118ALWAYS_INLINE void* getCodePtr(JSC::EncodedJSValue glueHelper())
119{
120    return bitwise_cast<void*>(glueHelper);
121}
122
123
124} } // namespace JSC::LLInt
125
126#endif // LLIntData_h
127
128