1// Copyright 2013 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/v8.h"
6
7#if V8_TARGET_ARCH_ARM64
8
9#include "src/arm64/decoder-arm64.h"
10#include "src/globals.h"
11#include "src/utils.h"
12
13
14namespace v8 {
15namespace internal {
16
17
18void DispatchingDecoderVisitor::AppendVisitor(DecoderVisitor* new_visitor) {
19  visitors_.remove(new_visitor);
20  visitors_.push_back(new_visitor);
21}
22
23
24void DispatchingDecoderVisitor::PrependVisitor(DecoderVisitor* new_visitor) {
25  visitors_.remove(new_visitor);
26  visitors_.push_front(new_visitor);
27}
28
29
30void DispatchingDecoderVisitor::InsertVisitorBefore(
31    DecoderVisitor* new_visitor, DecoderVisitor* registered_visitor) {
32  visitors_.remove(new_visitor);
33  std::list<DecoderVisitor*>::iterator it;
34  for (it = visitors_.begin(); it != visitors_.end(); it++) {
35    if (*it == registered_visitor) {
36      visitors_.insert(it, new_visitor);
37      return;
38    }
39  }
40  // We reached the end of the list. The last element must be
41  // registered_visitor.
42  DCHECK(*it == registered_visitor);
43  visitors_.insert(it, new_visitor);
44}
45
46
47void DispatchingDecoderVisitor::InsertVisitorAfter(
48    DecoderVisitor* new_visitor, DecoderVisitor* registered_visitor) {
49  visitors_.remove(new_visitor);
50  std::list<DecoderVisitor*>::iterator it;
51  for (it = visitors_.begin(); it != visitors_.end(); it++) {
52    if (*it == registered_visitor) {
53      it++;
54      visitors_.insert(it, new_visitor);
55      return;
56    }
57  }
58  // We reached the end of the list. The last element must be
59  // registered_visitor.
60  DCHECK(*it == registered_visitor);
61  visitors_.push_back(new_visitor);
62}
63
64
65void DispatchingDecoderVisitor::RemoveVisitor(DecoderVisitor* visitor) {
66  visitors_.remove(visitor);
67}
68
69
70#define DEFINE_VISITOR_CALLERS(A)                                \
71  void DispatchingDecoderVisitor::Visit##A(Instruction* instr) { \
72    if (!(instr->Mask(A##FMask) == A##Fixed)) {                  \
73      DCHECK(instr->Mask(A##FMask) == A##Fixed);                 \
74    }                                                            \
75    std::list<DecoderVisitor*>::iterator it;                     \
76    for (it = visitors_.begin(); it != visitors_.end(); it++) {  \
77      (*it)->Visit##A(instr);                                    \
78    }                                                            \
79  }
80VISITOR_LIST(DEFINE_VISITOR_CALLERS)
81#undef DEFINE_VISITOR_CALLERS
82
83
84} }  // namespace v8::internal
85
86#endif  // V8_TARGET_ARCH_ARM64
87