1 // Copyright 2014 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/codegen/machine-type.h" 6 #include "src/utils/ostreams.h" 7 8 namespace v8 { 9 namespace internal { 10 IsSubtype(MachineRepresentation rep1,MachineRepresentation rep2)11bool IsSubtype(MachineRepresentation rep1, MachineRepresentation rep2) { 12 if (rep1 == rep2) return true; 13 switch (rep1) { 14 case MachineRepresentation::kTaggedSigned: // Fall through. 15 case MachineRepresentation::kTaggedPointer: 16 return rep2 == MachineRepresentation::kTagged; 17 case MachineRepresentation::kCompressedPointer: 18 return rep2 == MachineRepresentation::kCompressed; 19 default: 20 return false; 21 } 22 } 23 operator <<(std::ostream & os,MachineRepresentation rep)24std::ostream& operator<<(std::ostream& os, MachineRepresentation rep) { 25 return os << MachineReprToString(rep); 26 } 27 MachineReprToString(MachineRepresentation rep)28const char* MachineReprToString(MachineRepresentation rep) { 29 switch (rep) { 30 case MachineRepresentation::kNone: 31 return "kMachNone"; 32 case MachineRepresentation::kBit: 33 return "kRepBit"; 34 case MachineRepresentation::kWord8: 35 return "kRepWord8"; 36 case MachineRepresentation::kWord16: 37 return "kRepWord16"; 38 case MachineRepresentation::kWord32: 39 return "kRepWord32"; 40 case MachineRepresentation::kWord64: 41 return "kRepWord64"; 42 case MachineRepresentation::kFloat32: 43 return "kRepFloat32"; 44 case MachineRepresentation::kFloat64: 45 return "kRepFloat64"; 46 case MachineRepresentation::kSimd128: 47 return "kRepSimd128"; 48 case MachineRepresentation::kTaggedSigned: 49 return "kRepTaggedSigned"; 50 case MachineRepresentation::kTaggedPointer: 51 return "kRepTaggedPointer"; 52 case MachineRepresentation::kTagged: 53 return "kRepTagged"; 54 case MachineRepresentation::kCompressedPointer: 55 return "kRepCompressedPointer"; 56 case MachineRepresentation::kCompressed: 57 return "kRepCompressed"; 58 } 59 UNREACHABLE(); 60 } 61 operator <<(std::ostream & os,MachineSemantic type)62std::ostream& operator<<(std::ostream& os, MachineSemantic type) { 63 switch (type) { 64 case MachineSemantic::kNone: 65 return os << "kMachNone"; 66 case MachineSemantic::kBool: 67 return os << "kTypeBool"; 68 case MachineSemantic::kInt32: 69 return os << "kTypeInt32"; 70 case MachineSemantic::kUint32: 71 return os << "kTypeUint32"; 72 case MachineSemantic::kInt64: 73 return os << "kTypeInt64"; 74 case MachineSemantic::kUint64: 75 return os << "kTypeUint64"; 76 case MachineSemantic::kNumber: 77 return os << "kTypeNumber"; 78 case MachineSemantic::kAny: 79 return os << "kTypeAny"; 80 } 81 UNREACHABLE(); 82 } 83 operator <<(std::ostream & os,MachineType type)84std::ostream& operator<<(std::ostream& os, MachineType type) { 85 if (type == MachineType::None()) { 86 return os; 87 } else if (type.representation() == MachineRepresentation::kNone) { 88 return os << type.semantic(); 89 } else if (type.semantic() == MachineSemantic::kNone) { 90 return os << type.representation(); 91 } else { 92 return os << type.representation() << "|" << type.semantic(); 93 } 94 return os; 95 } 96 97 } // namespace internal 98 } // namespace v8 99