blob: ae10348422cf3eeb71525c0e637225864e9fa52e [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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/compiler/operator.h"
6
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007#include <limits>
8
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009namespace v8 {
10namespace internal {
11namespace compiler {
12
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013namespace {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040014
15template <typename N>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016V8_INLINE N CheckRange(size_t val) {
17 CHECK_LE(val, std::numeric_limits<N>::max());
Emily Bernierd0a1eb72015-03-24 16:35:39 -040018 return static_cast<N>(val);
19}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000021} // namespace
22
23
24// static
25STATIC_CONST_MEMBER_DEFINITION const size_t Operator::kMaxControlOutputCount;
26
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028Operator::Operator(Opcode opcode, Properties properties, const char* mnemonic,
29 size_t value_in, size_t effect_in, size_t control_in,
30 size_t value_out, size_t effect_out, size_t control_out)
31 : opcode_(opcode),
32 properties_(properties),
33 mnemonic_(mnemonic),
34 value_in_(CheckRange<uint32_t>(value_in)),
35 effect_in_(CheckRange<uint16_t>(effect_in)),
36 control_in_(CheckRange<uint16_t>(control_in)),
37 value_out_(CheckRange<uint16_t>(value_out)),
38 effect_out_(CheckRange<uint8_t>(effect_out)),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039 control_out_(CheckRange<uint16_t>(control_out)) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040
41
Emily Bernierd0a1eb72015-03-24 16:35:39 -040042std::ostream& operator<<(std::ostream& os, const Operator& op) {
43 op.PrintTo(os);
44 return os;
45}
46
47
48void Operator::PrintTo(std::ostream& os) const { os << mnemonic(); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049
50} // namespace compiler
51} // namespace internal
52} // namespace v8