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