v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
operator.cc
Go to the documentation of this file.
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
6
7#include <limits>
8
9namespace v8 {
10namespace internal {
11namespace compiler {
12
13namespace {
14
15template <typename N>
16V8_INLINE N CheckRange(size_t val) {
17 // The getters on Operator for input and output counts currently return int.
18 // Thus check that the given value fits in the integer range.
19 // TODO(titzer): Remove this check once the getters return size_t.
20 CHECK_LE(val, std::min(static_cast<size_t>(std::numeric_limits<N>::max()),
21 static_cast<size_t>(kMaxInt)));
22 return static_cast<N>(val);
23}
24
25} // namespace
26
27Operator::Operator(Opcode opcode, Properties properties, const char* mnemonic,
28 size_t value_in, size_t effect_in, size_t control_in,
29 size_t value_out, size_t effect_out, size_t control_out)
30 : mnemonic_(mnemonic),
31 opcode_(opcode),
32 properties_(properties),
33 value_in_(CheckRange<uint32_t>(value_in)),
34 effect_in_(CheckRange<uint32_t>(effect_in)),
35 control_in_(CheckRange<uint32_t>(control_in)),
36 value_out_(CheckRange<uint32_t>(value_out)),
37 effect_out_(CheckRange<uint8_t>(effect_out)),
38 control_out_(CheckRange<uint32_t>(control_out)) {}
39
40std::ostream& operator<<(std::ostream& os, const Operator& op) {
41 op.PrintTo(os);
42 return os;
43}
44
45void Operator::PrintToImpl(std::ostream& os, PrintVerbosity verbose) const {
46 os << mnemonic();
47}
48
49void Operator::PrintPropsTo(std::ostream& os) const {
50 std::string separator = "";
51
52#define PRINT_PROP_IF_SET(name) \
53 if (HasProperty(Operator::k##name)) { \
54 os << separator; \
55 os << #name; \
56 separator = ", "; \
57 }
59#undef PRINT_PROP_IF_SET
60}
61
62} // namespace compiler
63} // namespace internal
64} // namespace v8
const char * mnemonic() const
Definition operator.h:79
virtual void PrintToImpl(std::ostream &os, PrintVerbosity verbose) const
Definition operator.cc:45
void PrintPropsTo(std::ostream &os) const
Definition operator.cc:49
void PrintTo(std::ostream &os, PrintVerbosity verbose=PrintVerbosity::kVerbose) const
Definition operator.h:125
Operator(Opcode opcode, Properties properties, const char *mnemonic, size_t value_in, size_t effect_in, size_t control_in, size_t value_out, size_t effect_out, size_t control_out)
Definition operator.cc:27
ArchOpcode opcode_
std::ostream & operator<<(std::ostream &os, AccessMode access_mode)
constexpr int N
constexpr int kMaxInt
Definition globals.h:374
#define PRINT_PROP_IF_SET(name)
#define OPERATOR_PROPERTY_LIST(V)
Definition operator.h:56
#define CHECK_LE(lhs, rhs)
#define V8_INLINE
Definition v8config.h:500