operator.cc 1.96 KB
Newer Older
1 2 3 4 5 6
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/compiler/operator.h"

7 8
#include <limits>

9 10 11 12
namespace v8 {
namespace internal {
namespace compiler {

13
namespace {
14

15
template <typename N>
16
V8_INLINE N CheckRange(size_t val) {
17 18 19 20 21
  // The getters on Operator for input and output counts currently return int.
  // Thus check that the given value fits in the integer range.
  // TODO(titzer): Remove this check once the getters return size_t.
  CHECK_LE(val, std::min(static_cast<size_t>(std::numeric_limits<N>::max()),
                         static_cast<size_t>(kMaxInt)));
22
  return static_cast<N>(val);
23 24
}

25 26
}  // namespace

27 28 29
Operator::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)
30 31
    : mnemonic_(mnemonic),
      opcode_(opcode),
32 33
      properties_(properties),
      value_in_(CheckRange<uint32_t>(value_in)),
34 35
      effect_in_(CheckRange<uint32_t>(effect_in)),
      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

40 41 42
std::ostream& operator<<(std::ostream& os, const Operator& op) {
  op.PrintTo(os);
  return os;
43 44
}

45 46 47
void Operator::PrintToImpl(std::ostream& os, PrintVerbosity verbose) const {
  os << mnemonic();
}
48

49 50 51 52 53 54 55 56 57 58 59 60 61
void Operator::PrintPropsTo(std::ostream& os) const {
  std::string separator = "";

#define PRINT_PROP_IF_SET(name)         \
  if (HasProperty(Operator::k##name)) { \
    os << separator;                    \
    os << #name;                        \
    separator = ", ";                   \
  }
  OPERATOR_PROPERTY_LIST(PRINT_PROP_IF_SET)
#undef PRINT_PROP_IF_SET
}

62 63 64
}  // namespace compiler
}  // namespace internal
}  // namespace v8