• 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/codegen/machine-type.h"
6 #include "src/utils/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:  // 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)24 std::ostream& operator<<(std::ostream& os, MachineRepresentation rep) {
25   return os << MachineReprToString(rep);
26 }
27 
MachineReprToString(MachineRepresentation rep)28 const 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     case MachineRepresentation::kMapWord:
59       return "kRepMapWord";
60     case MachineRepresentation::kSandboxedPointer:
61       return "kRepSandboxedPointer";
62   }
63   UNREACHABLE();
64 }
65 
operator <<(std::ostream & os,MachineSemantic type)66 std::ostream& operator<<(std::ostream& os, MachineSemantic type) {
67   switch (type) {
68     case MachineSemantic::kNone:
69       return os << "kMachNone";
70     case MachineSemantic::kBool:
71       return os << "kTypeBool";
72     case MachineSemantic::kInt32:
73       return os << "kTypeInt32";
74     case MachineSemantic::kUint32:
75       return os << "kTypeUint32";
76     case MachineSemantic::kInt64:
77       return os << "kTypeInt64";
78     case MachineSemantic::kUint64:
79       return os << "kTypeUint64";
80     case MachineSemantic::kNumber:
81       return os << "kTypeNumber";
82     case MachineSemantic::kAny:
83       return os << "kTypeAny";
84   }
85   UNREACHABLE();
86 }
87 
operator <<(std::ostream & os,MachineType type)88 std::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 }
99 
100 }  // namespace internal
101 }  // namespace v8
102