1/*
2 * Copyright (C) 2013-2015 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 "FTLExitValue.h"
28
29#if ENABLE(FTL_JIT)
30
31#include "FTLExitTimeObjectMaterialization.h"
32#include "JSCInlines.h"
33#include "TrackedReferences.h"
34
35namespace JSC { namespace FTL {
36
37ExitValue ExitValue::materializeNewObject(ExitTimeObjectMaterialization* data)
38{
39 ExitValue result;
40 result.m_kind = ExitValueMaterializeNewObject;
41 result.u.newObjectMaterializationData = data;
42 return result;
43}
44
45ExitValue ExitValue::withLocalsOffset(int offset) const
46{
47 if (!isInJSStackSomehow())
48 return *this;
49 if (!virtualRegister().isLocal())
50 return *this;
51 return withVirtualRegister(virtualRegister() + offset);
52}
53
54DataFormat ExitValue::dataFormat() const
55{
56 switch (kind()) {
57 case InvalidExitValue:
58 RELEASE_ASSERT_NOT_REACHED();
59 return DataFormatNone;
60
61 case ExitValueDead:
62 case ExitValueConstant:
63 case ExitValueInJSStack:
64 case ExitValueMaterializeNewObject:
65 return DataFormatJS;
66
67 case ExitValueArgument:
68 return exitArgument().format();
69
70 case ExitValueInJSStackAsInt32:
71 return DataFormatInt32;
72
73 case ExitValueInJSStackAsInt52:
74 return DataFormatInt52;
75
76 case ExitValueInJSStackAsDouble:
77 return DataFormatDouble;
78 }
79
80 RELEASE_ASSERT_NOT_REACHED();
81}
82
83void ExitValue::dumpInContext(PrintStream& out, DumpContext* context) const
84{
85 switch (kind()) {
86 case InvalidExitValue:
87 out.print("Invalid");
88 return;
89 case ExitValueDead:
90 out.print("Dead");
91 return;
92 case ExitValueArgument:
93 out.print("Argument(", exitArgument(), ")");
94 return;
95 case ExitValueConstant:
96 out.print("Constant(", inContext(constant(), context), ")");
97 return;
98 case ExitValueInJSStack:
99 out.print("InJSStack:", virtualRegister());
100 return;
101 case ExitValueInJSStackAsInt32:
102 out.print("InJSStackAsInt32:", virtualRegister());
103 return;
104 case ExitValueInJSStackAsInt52:
105 out.print("InJSStackAsInt52:", virtualRegister());
106 return;
107 case ExitValueInJSStackAsDouble:
108 out.print("InJSStackAsDouble:", virtualRegister());
109 return;
110 case ExitValueMaterializeNewObject:
111 out.print("Materialize(", WTF::RawPointer(objectMaterialization()), ")");
112 return;
113 }
114
115 RELEASE_ASSERT_NOT_REACHED();
116}
117
118void ExitValue::dump(PrintStream& out) const
119{
120 dumpInContext(out, 0);
121}
122
123void ExitValue::validateReferences(const TrackedReferences& trackedReferences) const
124{
125 if (isConstant())
126 trackedReferences.check(constant());
127}
128
129} } // namespace JSC::FTL
130
131#endif // ENABLE(FTL_JIT)
132
133