1/*
2 * Copyright (C) 2011-2019 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
32namespace JSC {
33
34JSValue ValueRecovery::recover(CallFrame* callFrame) const
35{
36 switch (technique()) {
37 case DisplacedInJSStack:
38 return callFrame->r(virtualRegister().offset()).jsValue();
39 case Int32DisplacedInJSStack:
40 return jsNumber(callFrame->r(virtualRegister().offset()).unboxedInt32());
41 case Int52DisplacedInJSStack:
42 return jsNumber(callFrame->r(virtualRegister().offset()).unboxedInt52());
43 case StrictInt52DisplacedInJSStack:
44 return jsNumber(callFrame->r(virtualRegister().offset()).unboxedStrictInt52());
45 case DoubleDisplacedInJSStack:
46 return jsNumber(purifyNaN(callFrame->r(virtualRegister().offset()).unboxedDouble()));
47 case CellDisplacedInJSStack:
48 return callFrame->r(virtualRegister().offset()).unboxedCell();
49 case BooleanDisplacedInJSStack:
50#if USE(JSVALUE64)
51 return callFrame->r(virtualRegister().offset()).jsValue();
52#else
53 return jsBoolean(callFrame->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
65void 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 case UnboxedDoubleInFPR:
90 out.print("double(", fpr(), ")");
91 return;
92#if USE(JSVALUE32_64)
93 case InPair:
94 out.print("pair(", tagGPR(), ", ", payloadGPR(), ")");
95 return;
96#endif
97 case DisplacedInJSStack:
98 out.print("*", virtualRegister());
99 return;
100 case Int32DisplacedInJSStack:
101 out.print("*int32(", virtualRegister(), ")");
102 return;
103 case Int52DisplacedInJSStack:
104 out.print("*int52(", virtualRegister(), ")");
105 return;
106 case StrictInt52DisplacedInJSStack:
107 out.print("*strictInt52(", virtualRegister(), ")");
108 return;
109 case DoubleDisplacedInJSStack:
110 out.print("*double(", virtualRegister(), ")");
111 return;
112 case CellDisplacedInJSStack:
113 out.print("*cell(", virtualRegister(), ")");
114 return;
115 case BooleanDisplacedInJSStack:
116 out.print("*bool(", virtualRegister(), ")");
117 return;
118 case DirectArgumentsThatWereNotCreated:
119 out.print("DirectArguments(", nodeID(), ")");
120 return;
121 case ClonedArgumentsThatWereNotCreated:
122 out.print("ClonedArguments(", nodeID(), ")");
123 return;
124 case Constant:
125 out.print("[", inContext(constant(), context), "]");
126 return;
127 case DontKnow:
128 out.printf("!");
129 return;
130 }
131 RELEASE_ASSERT_NOT_REACHED();
132}
133
134void ValueRecovery::dump(PrintStream& out) const
135{
136 dumpInContext(out, 0);
137}
138#endif // ENABLE(JIT)
139
140} // namespace JSC
141
142