]> git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/ValueRecovery.cpp
JavaScriptCore-7600.1.4.11.8.tar.gz
[apple/javascriptcore.git] / bytecode / ValueRecovery.cpp
1 /*
2 * Copyright (C) 2011, 2013 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 #include "config.h"
27 #include "ValueRecovery.h"
28
29 #include "CodeBlock.h"
30 #include "JSCInlines.h"
31
32 namespace JSC {
33
34 JSValue ValueRecovery::recover(ExecState* exec) const
35 {
36 switch (technique()) {
37 case DisplacedInJSStack:
38 return exec->r(virtualRegister().offset()).jsValue();
39 case Int32DisplacedInJSStack:
40 return jsNumber(exec->r(virtualRegister().offset()).unboxedInt32());
41 case Int52DisplacedInJSStack:
42 return jsNumber(exec->r(virtualRegister().offset()).unboxedInt52());
43 case StrictInt52DisplacedInJSStack:
44 return jsNumber(exec->r(virtualRegister().offset()).unboxedStrictInt52());
45 case DoubleDisplacedInJSStack:
46 return jsNumber(exec->r(virtualRegister().offset()).unboxedDouble());
47 case CellDisplacedInJSStack:
48 return exec->r(virtualRegister().offset()).unboxedCell();
49 case BooleanDisplacedInJSStack:
50 #if USE(JSVALUE64)
51 return exec->r(virtualRegister().offset()).jsValue();
52 #else
53 return jsBoolean(exec->r(virtualRegister().offset()).unboxedBoolean());
54 #endif
55 case Constant:
56 return constant();
57 default:
58 RELEASE_ASSERT_NOT_REACHED();
59 return JSValue();
60 }
61 }
62
63 #if ENABLE(JIT)
64
65 void ValueRecovery::dumpInContext(PrintStream& out, DumpContext* context) const
66 {
67 switch (technique()) {
68 case InGPR:
69 out.print(gpr());
70 return;
71 case UnboxedInt32InGPR:
72 out.print("int32(", gpr(), ")");
73 return;
74 case UnboxedInt52InGPR:
75 out.print("int52(", gpr(), ")");
76 return;
77 case UnboxedStrictInt52InGPR:
78 out.print("strictInt52(", gpr(), ")");
79 return;
80 case UnboxedBooleanInGPR:
81 out.print("bool(", gpr(), ")");
82 return;
83 case UnboxedCellInGPR:
84 out.print("cell(", gpr(), ")");
85 return;
86 case InFPR:
87 out.print(fpr());
88 return;
89 #if USE(JSVALUE32_64)
90 case InPair:
91 out.print("pair(", tagGPR(), ", ", payloadGPR(), ")");
92 return;
93 #endif
94 case DisplacedInJSStack:
95 out.printf("*%d", virtualRegister().offset());
96 return;
97 case Int32DisplacedInJSStack:
98 out.printf("*int32(%d)", virtualRegister().offset());
99 return;
100 case Int52DisplacedInJSStack:
101 out.printf("*int52(%d)", virtualRegister().offset());
102 return;
103 case StrictInt52DisplacedInJSStack:
104 out.printf("*strictInt52(%d)", virtualRegister().offset());
105 return;
106 case DoubleDisplacedInJSStack:
107 out.printf("*double(%d)", virtualRegister().offset());
108 return;
109 case CellDisplacedInJSStack:
110 out.printf("*cell(%d)", virtualRegister().offset());
111 return;
112 case BooleanDisplacedInJSStack:
113 out.printf("*bool(%d)", virtualRegister().offset());
114 return;
115 case ArgumentsThatWereNotCreated:
116 out.printf("arguments");
117 return;
118 case Constant:
119 out.print("[", inContext(constant(), context), "]");
120 return;
121 case DontKnow:
122 out.printf("!");
123 return;
124 }
125 RELEASE_ASSERT_NOT_REACHED();
126 }
127
128 void ValueRecovery::dump(PrintStream& out) const
129 {
130 dumpInContext(out, 0);
131 }
132 #endif // ENABLE(JIT)
133
134 } // namespace JSC
135