Debian Codegraph @

js/src/jit/ABIArgGenerator.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef jit_ABIArgGenerator_h
8 #define jit_ABIArgGenerator_h
9
10 #include "mozilla/Assertions.h"
11
12 #include <stdint.h>
13
14 #include "jit/Assembler.h"
15 #include "jit/IonTypes.h"
16 #include "jit/RegisterSets.h"
17 #include "wasm/WasmFrame.h"
18
19 namespace js::jit {
20
21 static inline MIRType ToMIRType(MIRType t) { return t; }
22
23 static inline MIRType ToMIRType(ABIType argType) {
24 switch (argType) {
25 case ABIType::General:
26 return MIRType::Pointer;
27 case ABIType::Float64:
28 return MIRType::Double;
29 case ABIType::Float32:
30 return MIRType::Float32;
31 case ABIType::Int32:
32 return MIRType::Int32;
33 case ABIType::Int64:
34 return MIRType::Int64;
35 case ABIType::Void:
36 return MIRType::None;
37 default:
38 break;
39 }
40 MOZ_CRASH("unexpected argType");
41 }
42
43 template <class VecT, class ABIArgGeneratorT>
44 class ABIArgIterBase {
45 ABIArgGeneratorT gen_;
46 const VecT& types_;
47 unsigned i_;
48
49 void settle() {
50 if (!done()) gen_.next(ToMIRType(types_[i_]));
51 }
52
53 public:
54 explicit ABIArgIterBase(const VecT& types) : types_(types), i_(0) {
55 settle();
56 }
57 void operator++(int) {
58 MOZ_ASSERT(!done());
59 i_++;
60 settle();
61 }
62 bool done() const { return i_ == types_.length(); }
63
64 ABIArg* operator->() {
65 MOZ_ASSERT(!done());
66 return &gen_.current();
67 }
68 ABIArg& operator*() {
69 MOZ_ASSERT(!done());
70 return gen_.current();
71 }
72
73 unsigned index() const {
74 MOZ_ASSERT(!done());
75 return i_;
76 }
77 MIRType mirType() const {
78 MOZ_ASSERT(!done());
79 return ToMIRType(types_[i_]);
80 }
81 uint32_t stackBytesConsumedSoFar() const {
82 return gen_.stackBytesConsumedSoFar();
83 }
84 };
85
86 // This is not an alias because we want to allow class template argument
87 // deduction.
88 template <class VecT>
89 class ABIArgIter : public ABIArgIterBase<VecT, ABIArgGenerator> {
90 public:
91 explicit ABIArgIter(const VecT& types)
92 : ABIArgIterBase<VecT, ABIArgGenerator>(types) {}
93 };
94
95 class WasmABIArgGenerator : public ABIArgGenerator {
96 public:
97 WasmABIArgGenerator() {
98 increaseStackOffset(wasm::FrameWithInstances::sizeOfInstanceFields());
99 }
100 };
101
102 template <class VecT>
103 class WasmABIArgIter : public ABIArgIterBase<VecT, WasmABIArgGenerator> {
104 public:
105 explicit WasmABIArgIter(const VecT& types)
106 : ABIArgIterBase<VecT, WasmABIArgGenerator>(types) {}
107 };
108
109 } // namespace js::jit
110
111 #endif /* jit_ABIArgGenerator_h */