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