• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/machine-type.h"
6 #include "src/ostreams.h"
7 
8 namespace v8 {
9 namespace internal {
10 
IsSubtype(MachineRepresentation rep1,MachineRepresentation rep2)11 bool IsSubtype(MachineRepresentation rep1, MachineRepresentation rep2) {
12   if (rep1 == rep2) return true;
13   switch (rep1) {
14     case MachineRepresentation::kTaggedSigned:
15       return rep2 == MachineRepresentation::kTagged;
16     case MachineRepresentation ::kTaggedPointer:
17       return rep2 == MachineRepresentation ::kTagged;
18     default:
19       return false;
20   }
21 }
22 
operator <<(std::ostream & os,MachineRepresentation rep)23 std::ostream& operator<<(std::ostream& os, MachineRepresentation rep) {
24   return os << MachineReprToString(rep);
25 }
26 
MachineReprToString(MachineRepresentation rep)27 const char* MachineReprToString(MachineRepresentation rep) {
28   switch (rep) {
29     case MachineRepresentation::kNone:
30       return "kMachNone";
31     case MachineRepresentation::kBit:
32       return "kRepBit";
33     case MachineRepresentation::kWord8:
34       return "kRepWord8";
35     case MachineRepresentation::kWord16:
36       return "kRepWord16";
37     case MachineRepresentation::kWord32:
38       return "kRepWord32";
39     case MachineRepresentation::kWord64:
40       return "kRepWord64";
41     case MachineRepresentation::kFloat32:
42       return "kRepFloat32";
43     case MachineRepresentation::kFloat64:
44       return "kRepFloat64";
45     case MachineRepresentation::kSimd128:
46       return "kRepSimd128";
47     case MachineRepresentation::kTaggedSigned:
48       return "kRepTaggedSigned";
49     case MachineRepresentation::kTaggedPointer:
50       return "kRepTaggedPointer";
51     case MachineRepresentation::kTagged:
52       return "kRepTagged";
53   }
54   UNREACHABLE();
55 }
56 
operator <<(std::ostream & os,MachineSemantic type)57 std::ostream& operator<<(std::ostream& os, MachineSemantic type) {
58   switch (type) {
59     case MachineSemantic::kNone:
60       return os << "kMachNone";
61     case MachineSemantic::kBool:
62       return os << "kTypeBool";
63     case MachineSemantic::kInt32:
64       return os << "kTypeInt32";
65     case MachineSemantic::kUint32:
66       return os << "kTypeUint32";
67     case MachineSemantic::kInt64:
68       return os << "kTypeInt64";
69     case MachineSemantic::kUint64:
70       return os << "kTypeUint64";
71     case MachineSemantic::kNumber:
72       return os << "kTypeNumber";
73     case MachineSemantic::kAny:
74       return os << "kTypeAny";
75   }
76   UNREACHABLE();
77 }
78 
79 
operator <<(std::ostream & os,MachineType type)80 std::ostream& operator<<(std::ostream& os, MachineType type) {
81   if (type == MachineType::None()) {
82     return os;
83   } else if (type.representation() == MachineRepresentation::kNone) {
84     return os << type.semantic();
85   } else if (type.semantic() == MachineSemantic::kNone) {
86     return os << type.representation();
87   } else {
88     return os << type.representation() << "|" << type.semantic();
89   }
90   return os;
91 }
92 
93 }  // namespace internal
94 }  // namespace v8
95