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