11cb0ef41Sopenharmony_ci// Copyright 2014 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/compiler/operator.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include <limits>
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_cinamespace v8 {
101cb0ef41Sopenharmony_cinamespace internal {
111cb0ef41Sopenharmony_cinamespace compiler {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cinamespace {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_citemplate <typename N>
161cb0ef41Sopenharmony_ciV8_INLINE N CheckRange(size_t val) {
171cb0ef41Sopenharmony_ci  // The getters on Operator for input and output counts currently return int.
181cb0ef41Sopenharmony_ci  // Thus check that the given value fits in the integer range.
191cb0ef41Sopenharmony_ci  // TODO(titzer): Remove this check once the getters return size_t.
201cb0ef41Sopenharmony_ci  CHECK_LE(val, std::min(static_cast<size_t>(std::numeric_limits<N>::max()),
211cb0ef41Sopenharmony_ci                         static_cast<size_t>(kMaxInt)));
221cb0ef41Sopenharmony_ci  return static_cast<N>(val);
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci}  // namespace
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciOperator::Operator(Opcode opcode, Properties properties, const char* mnemonic,
281cb0ef41Sopenharmony_ci                   size_t value_in, size_t effect_in, size_t control_in,
291cb0ef41Sopenharmony_ci                   size_t value_out, size_t effect_out, size_t control_out)
301cb0ef41Sopenharmony_ci    : mnemonic_(mnemonic),
311cb0ef41Sopenharmony_ci      opcode_(opcode),
321cb0ef41Sopenharmony_ci      properties_(properties),
331cb0ef41Sopenharmony_ci      value_in_(CheckRange<uint32_t>(value_in)),
341cb0ef41Sopenharmony_ci      effect_in_(CheckRange<uint32_t>(effect_in)),
351cb0ef41Sopenharmony_ci      control_in_(CheckRange<uint32_t>(control_in)),
361cb0ef41Sopenharmony_ci      value_out_(CheckRange<uint32_t>(value_out)),
371cb0ef41Sopenharmony_ci      effect_out_(CheckRange<uint8_t>(effect_out)),
381cb0ef41Sopenharmony_ci      control_out_(CheckRange<uint32_t>(control_out)) {}
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cistd::ostream& operator<<(std::ostream& os, const Operator& op) {
411cb0ef41Sopenharmony_ci  op.PrintTo(os);
421cb0ef41Sopenharmony_ci  return os;
431cb0ef41Sopenharmony_ci}
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_civoid Operator::PrintToImpl(std::ostream& os, PrintVerbosity verbose) const {
461cb0ef41Sopenharmony_ci  os << mnemonic();
471cb0ef41Sopenharmony_ci}
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_civoid Operator::PrintPropsTo(std::ostream& os) const {
501cb0ef41Sopenharmony_ci  std::string separator = "";
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci#define PRINT_PROP_IF_SET(name)         \
531cb0ef41Sopenharmony_ci  if (HasProperty(Operator::k##name)) { \
541cb0ef41Sopenharmony_ci    os << separator;                    \
551cb0ef41Sopenharmony_ci    os << #name;                        \
561cb0ef41Sopenharmony_ci    separator = ", ";                   \
571cb0ef41Sopenharmony_ci  }
581cb0ef41Sopenharmony_ci  OPERATOR_PROPERTY_LIST(PRINT_PROP_IF_SET)
591cb0ef41Sopenharmony_ci#undef PRINT_PROP_IF_SET
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci}  // namespace compiler
631cb0ef41Sopenharmony_ci}  // namespace internal
641cb0ef41Sopenharmony_ci}  // namespace v8
65